[PATCH v3 0/4] misc fixes to PV extentions code

2019-07-01 Thread Zhenzhong Duan
Hi,

In virtualization environment, PV extensions (drivers, interrupts,
timers, etc) are enabled in the majority of use cases which is the
best option.

However, in some cases (kexec not fully working, benchmarking, etc)
we want to disable PV extensions. We have xen_nopv for that purpose
but only for XEN. For a consistent admin experience a common command
line parameter set across all PV guest implementations is a better
choice.

To achieve this introduce a new 'nopv' parameter which is usable by
most of PV guest implementation. Due to the limitation of some PV
guests(XEN PV, XEN PVH and jailhouse), 'nopv' is ignored for XEN PV
, jailhouse and XEN PVH if booting via Xen-PVH boot entry. If booting
via normal boot entry(like grub2), PVH guest has to panic itself
currently.

While analyzing the PV guest code one bug were found and fixed.
(Patches 1). It can be applied independent of the functional
changes, but is kept in the series as the functional changes
depend on them.

As I didn't got further comments from Jgross about remove 'xen_nopv',
so I presume he has no objection to that. In fact, I think no product
environment will use 'xen_nopv' for performance. Jgross, if you changed
mind to preserve it finally, just let me know.

I didn't get env to test with jailhouse and Hyperv, the others work
as expected.

v3:
Remove some unrelated patches from patchset as suggested by Tglx

PATCH1 unchanged
PATCH2 add Reviewed-by
PATCH3 add Reviewed-by
PATCH4 rewrite the patch as Jgross found an issue in old patch,
description is also updated.



v2:
PATCH3 use 'ignore_nopv' for PVH/PV guest as suggested by Jgross.
PATCH5 new added one, specifically for HVM guest

Thanks
Zhenzhong


[PATCH v3 3/4] Revert "xen: Introduce 'xen_nopv' to disable PV extensions for HVM guests."

2019-07-01 Thread Zhenzhong Duan
This reverts commit 8d693b911bb9c57009c24cb1772d205b84c7985c.

Instead we use an unified parameter 'nopv' for all the hypervisor
platforms.

Signed-off-by: Zhenzhong Duan 
Reviewed-by: Juergen Gross 
Cc: Boris Ostrovsky 
Cc: Juergen Gross 
Cc: Stefano Stabellini 
Cc: Thomas Gleixner 
Cc: Ingo Molnar 
Cc: Borislav Petkov 
---
 Documentation/admin-guide/kernel-parameters.txt |  4 
 arch/x86/xen/enlighten_hvm.c| 12 +---
 2 files changed, 1 insertion(+), 15 deletions(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt 
b/Documentation/admin-guide/kernel-parameters.txt
index 21e08af..d5c3dcc 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -5251,10 +5251,6 @@
Disables the ticketlock slowpath using Xen PV
optimizations.
 
-   xen_nopv[X86]
-   Disables the PV optimizations forcing the HVM guest to
-   run as generic HVM guest with no PV drivers.
-
xen_scrub_pages=[XEN]
Boolean option to control scrubbing pages before giving 
them back
to Xen, for use by other domains. Can be also changed 
at runtime
diff --git a/arch/x86/xen/enlighten_hvm.c b/arch/x86/xen/enlighten_hvm.c
index ac4943c..7fcb4ea 100644
--- a/arch/x86/xen/enlighten_hvm.c
+++ b/arch/x86/xen/enlighten_hvm.c
@@ -210,18 +210,8 @@ static void __init xen_hvm_guest_init(void)
 #endif
 }
 
-static bool xen_nopv;
-static __init int xen_parse_nopv(char *arg)
-{
-   xen_nopv = true;
-   return 0;
-}
-early_param("xen_nopv", xen_parse_nopv);
-
 bool __init xen_hvm_need_lapic(void)
 {
-   if (xen_nopv)
-   return false;
if (xen_pv_domain())
return false;
if (!xen_hvm_domain())
@@ -233,7 +223,7 @@ bool __init xen_hvm_need_lapic(void)
 
 static uint32_t __init xen_platform_hvm(void)
 {
-   if (xen_pv_domain() || xen_nopv)
+   if (xen_pv_domain())
return 0;
 
return xen_cpuid_base();
-- 
1.8.3.1



[PATCH v3 4/4] x86/xen: Add 'nopv' support for HVM guest

2019-07-01 Thread Zhenzhong Duan
PVH guest needs PV extentions to work, so 'nopv' parameter should be
ignored for PVH but not for HVM guest.

If PVH guest boots up via the Xen-PVH boot entry, xen_pvh is set early,
we know it's PVH guest and ignore 'nopv' parameter directly.

If PVH guest boots up via the normal boot entry same as HVM guest, it's
hard to distinguish PVH and HVM guest at that time.

To handle that case, add a new function xen_hvm_nopv_guest_late_init()
to detect PVH at a late time and panic itself if 'nopv' enabled for a
PVH guest.

Signed-off-by: Zhenzhong Duan 
Cc: Boris Ostrovsky 
Cc: Juergen Gross 
Cc: Stefano Stabellini 
Cc: Thomas Gleixner 
Cc: Ingo Molnar 
Cc: Borislav Petkov 
---
 arch/x86/xen/enlighten_hvm.c | 27 +++
 1 file changed, 27 insertions(+)

diff --git a/arch/x86/xen/enlighten_hvm.c b/arch/x86/xen/enlighten_hvm.c
index 7fcb4ea..340dff8 100644
--- a/arch/x86/xen/enlighten_hvm.c
+++ b/arch/x86/xen/enlighten_hvm.c
@@ -25,6 +25,7 @@
 #include "mmu.h"
 #include "smp.h"
 
+extern bool nopv;
 static unsigned long shared_info_pfn;
 
 void xen_hvm_init_shared_info(void)
@@ -221,11 +222,36 @@ bool __init xen_hvm_need_lapic(void)
return true;
 }
 
+static __init void xen_hvm_nopv_guest_late_init(void)
+{
+#ifdef CONFIG_XEN_PVH
+   if (x86_platform.legacy.rtc || !x86_platform.legacy.no_vga)
+   return;
+
+   /* PVH detected. */
+   xen_pvh = true;
+
+   panic("nopv parameter isn't supported in PVH guest.");
+#endif
+}
+
+
 static uint32_t __init xen_platform_hvm(void)
 {
if (xen_pv_domain())
return 0;
 
+   if (xen_pvh_domain() && nopv) {
+   /* Guest booting via the Xen-PVH boot entry goes here */
+   pr_info("nopv parameter is ignored in PVH guest\n");
+   } else if (nopv) {
+   /*
+* Guest booting via normal boot entry (like via grub2) goes
+* here.
+*/
+   x86_init.hyper.guest_late_init = xen_hvm_nopv_guest_late_init;
+   return 0;
+   }
return xen_cpuid_base();
 }
 
@@ -258,4 +284,5 @@ static __init void xen_hvm_guest_late_init(void)
.init.init_mem_mapping  = xen_hvm_init_mem_mapping,
.init.guest_late_init   = xen_hvm_guest_late_init,
.runtime.pin_vcpu   = xen_pin_vcpu,
+   .ignore_nopv= true,
 };
-- 
1.8.3.1



[PATCH v3 1/4] x86/xen: Mark xen_hvm_need_lapic() and xen_x2apic_para_available() as __init

2019-07-01 Thread Zhenzhong Duan
.. as they are only called at early bootup stage. In fact, other
functions in x86_hyper_xen_hvm.init.* are all marked as __init.

Unexport xen_hvm_need_lapic as it's never used outside.

Signed-off-by: Zhenzhong Duan 
Reviewed-by: Juergen Gross 
Cc: Boris Ostrovsky 
Cc: Stefano Stabellini 
Cc: Thomas Gleixner 
Cc: Ingo Molnar 
Cc: Borislav Petkov 
---
 arch/x86/include/asm/xen/hypervisor.h | 6 +++---
 arch/x86/xen/enlighten_hvm.c  | 3 +--
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/arch/x86/include/asm/xen/hypervisor.h 
b/arch/x86/include/asm/xen/hypervisor.h
index 39171b3..42e1245 100644
--- a/arch/x86/include/asm/xen/hypervisor.h
+++ b/arch/x86/include/asm/xen/hypervisor.h
@@ -44,14 +44,14 @@ static inline uint32_t xen_cpuid_base(void)
 }
 
 #ifdef CONFIG_XEN
-extern bool xen_hvm_need_lapic(void);
+extern bool __init xen_hvm_need_lapic(void);
 
-static inline bool xen_x2apic_para_available(void)
+static inline bool __init xen_x2apic_para_available(void)
 {
return xen_hvm_need_lapic();
 }
 #else
-static inline bool xen_x2apic_para_available(void)
+static inline bool __init xen_x2apic_para_available(void)
 {
return (xen_cpuid_base() != 0);
 }
diff --git a/arch/x86/xen/enlighten_hvm.c b/arch/x86/xen/enlighten_hvm.c
index 0e75642..ac4943c 100644
--- a/arch/x86/xen/enlighten_hvm.c
+++ b/arch/x86/xen/enlighten_hvm.c
@@ -218,7 +218,7 @@ static __init int xen_parse_nopv(char *arg)
 }
 early_param("xen_nopv", xen_parse_nopv);
 
-bool xen_hvm_need_lapic(void)
+bool __init xen_hvm_need_lapic(void)
 {
if (xen_nopv)
return false;
@@ -230,7 +230,6 @@ bool xen_hvm_need_lapic(void)
return false;
return true;
 }
-EXPORT_SYMBOL_GPL(xen_hvm_need_lapic);
 
 static uint32_t __init xen_platform_hvm(void)
 {
-- 
1.8.3.1



[PATCH 05/43] perf intel-pt: Decoder to output CBR changes immediately

2019-07-01 Thread Arnaldo Carvalho de Melo
From: Adrian Hunter 

The core-to-bus ratio (CBR) provides the CPU frequency. With branches
enabled, the decoder was outputting CBR changes only when there was a
branch. That loses the correct time of the change if the trace is not in
context (e.g. not tracing kernel space). Change to output the CBR change
immediately.

Signed-off-by: Adrian Hunter 
Cc: Jiri Olsa 
Link: http://lkml.kernel.org/r/20190622093248.581-2-adrian.hun...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 .../util/intel-pt-decoder/intel-pt-decoder.c | 16 ++--
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c 
b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index f8b71bf2bb4c..3d2255f284f4 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -2015,16 +2015,8 @@ static int intel_pt_walk_trace(struct intel_pt_decoder 
*decoder)
 
case INTEL_PT_CBR:
intel_pt_calc_cbr(decoder);
-   if (!decoder->branch_enable &&
-   decoder->cbr != decoder->cbr_seen) {
-   decoder->cbr_seen = decoder->cbr;
-   decoder->state.type = INTEL_PT_CBR_CHG;
-   decoder->state.from_ip = decoder->ip;
-   decoder->state.to_ip = 0;
-   decoder->state.cbr_payload =
-   decoder->packet.payload;
+   if (decoder->cbr != decoder->cbr_seen)
return 0;
-   }
break;
 
case INTEL_PT_MODE_EXEC:
@@ -2626,8 +2618,12 @@ const struct intel_pt_state *intel_pt_decode(struct 
intel_pt_decoder *decoder)
decoder->sample_tot_cyc_cnt = decoder->tot_cyc_cnt;
} else {
decoder->state.err = 0;
-   if (decoder->cbr != decoder->cbr_seen && decoder->state.type) {
+   if (decoder->cbr != decoder->cbr_seen) {
decoder->cbr_seen = decoder->cbr;
+   if (!decoder->state.type) {
+   decoder->state.from_ip = decoder->ip;
+   decoder->state.to_ip = 0;
+   }
decoder->state.type |= INTEL_PT_CBR_CHG;
decoder->state.cbr_payload = decoder->cbr_payload;
}
-- 
2.20.1



[PATCH 06/43] perf intel-pt: Cater for CBR change in PSB+

2019-07-01 Thread Arnaldo Carvalho de Melo
From: Adrian Hunter 

PSB+ provides status information only so the core-to-bus ratio (CBR) in
PSB+ will not have changed from its previous value. However, cater for
the possibility of a another CBR change that gets caught up in the PSB+
anyway.

Signed-off-by: Adrian Hunter 
Cc: Jiri Olsa 
Link: http://lkml.kernel.org/r/20190622093248.581-3-adrian.hun...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c 
b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index 3d2255f284f4..5eb792cc5d3a 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -1975,6 +1975,13 @@ static int intel_pt_walk_trace(struct intel_pt_decoder 
*decoder)
goto next;
if (err)
return err;
+   /*
+* PSB+ CBR will not have changed but cater for the
+* possibility of another CBR change that gets caught up
+* in the PSB+.
+*/
+   if (decoder->cbr != decoder->cbr_seen)
+   return 0;
break;
 
case INTEL_PT_PIP:
-- 
2.20.1



[GIT PULL] perf/core improvements and fixes

2019-07-01 Thread Arnaldo Carvalho de Melo
Hi Ingo,

Please consider pulling,

Best regards,

- Arnaldo

Test results at the end of this message, as usual.

The following changes since commit fd7d55172d1e2e501e6da0a5c1de25f06612dc2e:

  perf/cgroups: Don't rotate events for cgroups unnecessarily (2019-06-24 
19:30:04 +0200)

are available in the Git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git 
tags/perf-core-for-mingo-5.3-20190701

for you to fetch changes up to 06c642c0e9fceafd16b1a4c80d44b1c09e282215:

  perf jevents: Use nonlocal include statements in pmu-events.c (2019-07-01 
22:50:42 -0300)


perf/core improvements and fixes:

perf annotate:

  Mao Han:

  - Add support for the csky processor architecture.

perf stat:

  Andi Kleen:

  - Fix metrics with --no-merge.

  - Don't merge events in the same PMU.

  - Fix group lookup for metric group.

Intel PT:

  Adrian Hunter:

  - Improve CBR (Core to Bus Ratio) packets support.

  - Fix thread stack return from kernel for kernel only case.

  - Export power and ptwrite events to sqlite and postgresql.

core libraries:

  Arnaldo Carvalho de Melo:

  - Find routines in tools/perf/util/ that have implementations in the kernel
libraries (lib/*.c), such as strreplace(), strim(), skip_spaces() and reuse
them after making a copy into tools/lib and tools/include/.

This continues the effort of having tools/ code looking as much as possible
like kernel source code, to help encourage people to work on both the kernel
and in tools hosted in the kernel sources.

That in turn will help moving stuff that uses those routines to
tools/lib/perf/ where they will be made available for use in other tools.

In the process ditch old cruft, remove unused variables and add missing
include directives for headers providing things used in places that were
building by sheer luck.

  Kyle Meyer:

  - Bump MAX_NR_CPUS and MAX_CACHES to get these tools to work on more machines.

Signed-off-by: Arnaldo Carvalho de Melo 


Adrian Hunter (9):
  perf thread-stack: Fix thread stack return from kernel for kernel-only 
case
  perf thread-stack: Eliminate code duplicating thread_stack__pop_ks()
  perf intel-pt: Decoder to output CBR changes immediately
  perf intel-pt: Cater for CBR change in PSB+
  perf intel-pt: Add CBR value to decoder state
  perf intel-pt: Synthesize CBR events when last seen value changes
  perf db-export: Export synth events
  perf scripts python: export-to-sqlite.py: Export Intel PT power and 
ptwrite events
  perf scripts python: export-to-postgresql.py: Export Intel PT power and 
ptwrite events

Andi Kleen (4):
  perf stat: Make metric event lookup more robust
  perf stat: Don't merge events in the same PMU
  perf stat: Fix group lookup for metric group
  perf stat: Fix metrics with --no-merge

Arnaldo Carvalho de Melo (26):
  perf ctype: Remove unused 'graph_line' variable
  perf ui stdio: No need to use 'spaces' to left align
  perf ctype: Remove now unused 'spaces' variable
  perf string: Move 'dots' and 'graph_dotted_line' out of sane_ctype.h
  tools x86 machine: Add missing util.h to pick up 'page_size'
  perf kallsyms: Adopt hex2u64 from tools/perf/util/util.h
  perf symbols: We need util.h in symbol-elf.c for zfree()
  perf tools: Remove old baggage that is util/include/linux/ctype.h
  perf tools: Add missing util.h to pick up 'page_size' variable
  tools perf: Move from sane_ctype.h obtained from git to the Linux's 
original
  perf tools: Use linux/ctype.h in more places
  tools lib: Adopt skip_spaces() from the kernel sources
  perf stat: Use recently introduced skip_spaces()
  perf header: Use skip_spaces() in __write_cpudesc()
  perf time-utils: Use skip_spaces()
  perf probe: Use skip_spaces() for argv handling
  perf strfilter: Use skip_spaces()
  perf metricgroup: Use strsep()
  perf report: Use skip_spaces()
  perf tools: Ditch rtrim(), use skip_spaces() to get closer to the kernel
  tools lib: Adopt strim() from the kernel
  perf tools: Remove trim() implementation, use tools/lib's strim()
  perf tools: Ditch rtrim(), use strim() from tools/lib
  tools lib: Adopt strreplace() from the kernel
  perf tools: Drop strxfrchar(), use strreplace() equivalent from kernel
  tools lib: Move argv_{split,free} from tools/perf/util/

Kyle Meyer (1):
  perf tools: Increase MAX_NR_CPUS and MAX_CACHES

Luke Mujica (1):
  perf jevents: Use nonlocal include statements in pmu-events.c

Mao Han (1):
  perf annotate: Add csky support

Numfor Mbiziwo-Tiapo (1):
  perf tools: Fix cache.h include directive

 tools/include/linux/ctype.

[PATCH 01/43] perf tools: Fix cache.h include directive

2019-07-01 Thread Arnaldo Carvalho de Melo
From: Numfor Mbiziwo-Tiapo 

Change the include path so that progress.c can find cache.h since it was
previously searching in the wrong directory.

Committer notes:

  $ ls -la tools/perf/ui/../cache.h
  ls: cannot access 'tools/perf/ui/../cache.h': No such file or directory

So it really should include ../../util/cache.h, or plain cache.h, since
we have -Iutil in INC_FLAGS in tools/perf/Makefile.config

Signed-off-by: Numfor Mbiziwo-Tiapo 
Cc: Jiri Olsa ,
Cc: Luke Mujica ,
Cc: Stephane Eranian 
To: Ian Rogers 
Link: https://lkml.kernel.org/n/tip-pud8usyutvd2npg2vpsyg...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/progress.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/ui/progress.c b/tools/perf/ui/progress.c
index bbfbc91a0fa4..8cd3b64c6893 100644
--- a/tools/perf/ui/progress.c
+++ b/tools/perf/ui/progress.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 #include 
-#include "../cache.h"
+#include "../util/cache.h"
 #include "progress.h"
 
 static void null_progress__update(struct ui_progress *p __maybe_unused)
-- 
2.20.1



[PATCH 03/43] perf thread-stack: Eliminate code duplicating thread_stack__pop_ks()

2019-07-01 Thread Arnaldo Carvalho de Melo
From: Adrian Hunter 

Use new function thread_stack__pop_ks() in place of equivalent code.

Signed-off-by: Adrian Hunter 
Cc: Jiri Olsa 
Link: http://lkml.kernel.org/r/20190619064429.14940-3-adrian.hun...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/thread-stack.c | 18 ++
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/tools/perf/util/thread-stack.c b/tools/perf/util/thread-stack.c
index 4c826a2e08d8..6ff1ff4d4ce7 100644
--- a/tools/perf/util/thread-stack.c
+++ b/tools/perf/util/thread-stack.c
@@ -664,12 +664,9 @@ static int thread_stack__no_call_return(struct thread 
*thread,
 
if (ip >= ks && addr < ks) {
/* Return to userspace, so pop all kernel addresses */
-   while (thread_stack__in_kernel(ts)) {
-   err = thread_stack__call_return(thread, ts, --ts->cnt,
-   tm, ref, true);
-   if (err)
-   return err;
-   }
+   err = thread_stack__pop_ks(thread, ts, sample, ref);
+   if (err)
+   return err;
 
/* If the stack is empty, push the userspace address */
if (!ts->cnt) {
@@ -679,12 +676,9 @@ static int thread_stack__no_call_return(struct thread 
*thread,
}
} else if (thread_stack__in_kernel(ts) && ip < ks) {
/* Return to userspace, so pop all kernel addresses */
-   while (thread_stack__in_kernel(ts)) {
-   err = thread_stack__call_return(thread, ts, --ts->cnt,
-   tm, ref, true);
-   if (err)
-   return err;
-   }
+   err = thread_stack__pop_ks(thread, ts, sample, ref);
+   if (err)
+   return err;
}
 
if (ts->cnt)
-- 
2.20.1



[PATCH 08/43] perf intel-pt: Synthesize CBR events when last seen value changes

2019-07-01 Thread Arnaldo Carvalho de Melo
From: Adrian Hunter 

The first core-to-bus ratio (CBR) event will not be shown if --itrace
's' option (skip initial number of events) is used, nor if time
intervals are specified that do not include the start of tracing. Change
the logic to record the last CBR value seen by the user, and synthesize
CBR events whenever that changes.

Signed-off-by: Adrian Hunter 
Cc: Jiri Olsa 
Link: http://lkml.kernel.org/r/20190622093248.581-5-adrian.hun...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/intel-pt.c | 65 --
 1 file changed, 41 insertions(+), 24 deletions(-)

diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index 550db6e77968..470aaae9d930 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -171,6 +171,7 @@ struct intel_pt_queue {
u64 last_in_cyc_cnt;
u64 last_br_insn_cnt;
u64 last_br_cyc_cnt;
+   unsigned int cbr_seen;
char insn[INTEL_PT_INSN_BUF_SZ];
 };
 
@@ -1052,6 +1053,8 @@ static int intel_pt_setup_queue(struct intel_pt *pt,
ptq->cpu = queue->cpu;
ptq->tid = queue->tid;
 
+   ptq->cbr_seen = UINT_MAX;
+
if (pt->sampling_mode && !pt->snapshot_mode &&
pt->timeless_decoding)
ptq->step_through_buffers = true;
@@ -1184,6 +1187,17 @@ static inline bool intel_pt_skip_event(struct intel_pt 
*pt)
   pt->num_events++ < pt->synth_opts.initial_skip;
 }
 
+/*
+ * Cannot count CBR as skipped because it won't go away until cbr == cbr_seen.
+ * Also ensure CBR is first non-skipped event by allowing for 4 more samples
+ * from this decoder state.
+ */
+static inline bool intel_pt_skip_cbr_event(struct intel_pt *pt)
+{
+   return pt->synth_opts.initial_skip &&
+  pt->num_events + 4 < pt->synth_opts.initial_skip;
+}
+
 static void intel_pt_prep_a_sample(struct intel_pt_queue *ptq,
   union perf_event *event,
   struct perf_sample *sample)
@@ -1429,9 +1443,11 @@ static int intel_pt_synth_cbr_sample(struct 
intel_pt_queue *ptq)
struct perf_synth_intel_cbr raw;
u32 flags;
 
-   if (intel_pt_skip_event(pt))
+   if (intel_pt_skip_cbr_event(pt))
return 0;
 
+   ptq->cbr_seen = ptq->state->cbr;
+
intel_pt_prep_p_sample(pt, ptq, event, &sample);
 
sample.id = ptq->pt->cbr_id;
@@ -1868,8 +1884,7 @@ static inline bool intel_pt_is_switch_ip(struct 
intel_pt_queue *ptq, u64 ip)
 }
 
 #define INTEL_PT_PWR_EVT (INTEL_PT_MWAIT_OP | INTEL_PT_PWR_ENTRY | \
- INTEL_PT_EX_STOP | INTEL_PT_PWR_EXIT | \
- INTEL_PT_CBR_CHG)
+ INTEL_PT_EX_STOP | INTEL_PT_PWR_EXIT)
 
 static int intel_pt_sample(struct intel_pt_queue *ptq)
 {
@@ -1901,31 +1916,33 @@ static int intel_pt_sample(struct intel_pt_queue *ptq)
return err;
}
 
-   if (pt->sample_pwr_events && (state->type & INTEL_PT_PWR_EVT)) {
-   if (state->type & INTEL_PT_CBR_CHG) {
+   if (pt->sample_pwr_events) {
+   if (ptq->state->cbr != ptq->cbr_seen) {
err = intel_pt_synth_cbr_sample(ptq);
if (err)
return err;
}
-   if (state->type & INTEL_PT_MWAIT_OP) {
-   err = intel_pt_synth_mwait_sample(ptq);
-   if (err)
-   return err;
-   }
-   if (state->type & INTEL_PT_PWR_ENTRY) {
-   err = intel_pt_synth_pwre_sample(ptq);
-   if (err)
-   return err;
-   }
-   if (state->type & INTEL_PT_EX_STOP) {
-   err = intel_pt_synth_exstop_sample(ptq);
-   if (err)
-   return err;
-   }
-   if (state->type & INTEL_PT_PWR_EXIT) {
-   err = intel_pt_synth_pwrx_sample(ptq);
-   if (err)
-   return err;
+   if (state->type & INTEL_PT_PWR_EVT) {
+   if (state->type & INTEL_PT_MWAIT_OP) {
+   err = intel_pt_synth_mwait_sample(ptq);
+   if (err)
+   return err;
+   }
+   if (state->type & INTEL_PT_PWR_ENTRY) {
+   err = intel_pt_synth_pwre_sample(ptq);
+   if (err)
+   return err;
+   }
+   if (state->type & INTEL_PT_EX_STOP) {
+   err = intel_pt_synth_exstop_sample(ptq);
+   if (err)
+   

[PATCH 12/43] perf ctype: Remove unused 'graph_line' variable

2019-07-01 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

Not being used at all anywhere.

Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-1e567f8tn8m4ii7dy1w9d...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/ctype.c  | 4 
 tools/perf/util/sane_ctype.h | 1 -
 2 files changed, 5 deletions(-)

diff --git a/tools/perf/util/ctype.c b/tools/perf/util/ctype.c
index ee4c1e8ed54b..8d90bf8d0d70 100644
--- a/tools/perf/util/ctype.c
+++ b/tools/perf/util/ctype.c
@@ -31,10 +31,6 @@ unsigned char sane_ctype[256] = {
/* Nothing in the 128.. range */
 };
 
-const char *graph_line =
-   "_"
-   "_"
-   "_";
 const char *graph_dotted_line =
"-"
"-"
diff --git a/tools/perf/util/sane_ctype.h b/tools/perf/util/sane_ctype.h
index c2b42ff9ff32..894594fdedfb 100644
--- a/tools/perf/util/sane_ctype.h
+++ b/tools/perf/util/sane_ctype.h
@@ -2,7 +2,6 @@
 #ifndef _PERF_SANE_CTYPE_H
 #define _PERF_SANE_CTYPE_H
 
-extern const char *graph_line;
 extern const char *graph_dotted_line;
 extern const char *spaces;
 extern const char *dots;
-- 
2.20.1



[PATCH 09/43] perf db-export: Export synth events

2019-07-01 Thread Arnaldo Carvalho de Melo
From: Adrian Hunter 

Synthesized events are samples but with architecture-specific data
stored in sample->raw_data. They are identified by attribute type
PERF_TYPE_SYNTH.  Add a function to export them.

Signed-off-by: Adrian Hunter 
Cc: Jiri Olsa 
Link: http://lkml.kernel.org/r/20190622093248.581-6-adrian.hun...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 .../scripting-engines/trace-event-python.c| 46 ++-
 1 file changed, 44 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/scripting-engines/trace-event-python.c 
b/tools/perf/util/scripting-engines/trace-event-python.c
index 6acb379b53ec..112bed65232f 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -112,6 +112,7 @@ struct tables {
PyObject*sample_handler;
PyObject*call_path_handler;
PyObject*call_return_handler;
+   PyObject*synth_handler;
booldb_export_mode;
 };
 
@@ -947,6 +948,12 @@ static int tuple_set_string(PyObject *t, unsigned int pos, 
const char *s)
return PyTuple_SetItem(t, pos, _PyUnicode_FromString(s));
 }
 
+static int tuple_set_bytes(PyObject *t, unsigned int pos, void *bytes,
+  unsigned int sz)
+{
+   return PyTuple_SetItem(t, pos, _PyBytes_FromStringAndSize(bytes, sz));
+}
+
 static int python_export_evsel(struct db_export *dbe, struct perf_evsel *evsel)
 {
struct tables *tables = container_of(dbe, struct tables, dbe);
@@ -1105,8 +1112,8 @@ static int python_export_branch_type(struct db_export 
*dbe, u32 branch_type,
return 0;
 }
 
-static int python_export_sample(struct db_export *dbe,
-   struct export_sample *es)
+static void python_export_sample_table(struct db_export *dbe,
+  struct export_sample *es)
 {
struct tables *tables = container_of(dbe, struct tables, dbe);
PyObject *t;
@@ -1141,6 +1148,33 @@ static int python_export_sample(struct db_export *dbe,
call_object(tables->sample_handler, t, "sample_table");
 
Py_DECREF(t);
+}
+
+static void python_export_synth(struct db_export *dbe, struct export_sample 
*es)
+{
+   struct tables *tables = container_of(dbe, struct tables, dbe);
+   PyObject *t;
+
+   t = tuple_new(3);
+
+   tuple_set_u64(t, 0, es->db_id);
+   tuple_set_u64(t, 1, es->evsel->attr.config);
+   tuple_set_bytes(t, 2, es->sample->raw_data, es->sample->raw_size);
+
+   call_object(tables->synth_handler, t, "synth_data");
+
+   Py_DECREF(t);
+}
+
+static int python_export_sample(struct db_export *dbe,
+   struct export_sample *es)
+{
+   struct tables *tables = container_of(dbe, struct tables, dbe);
+
+   python_export_sample_table(dbe, es);
+
+   if (es->evsel->attr.type == PERF_TYPE_SYNTH && tables->synth_handler)
+   python_export_synth(dbe, es);
 
return 0;
 }
@@ -1477,6 +1511,14 @@ static void set_table_handlers(struct tables *tables)
SET_TABLE_HANDLER(sample);
SET_TABLE_HANDLER(call_path);
SET_TABLE_HANDLER(call_return);
+
+   /*
+* Synthesized events are samples but with architecture-specific data
+* stored in sample->raw_data. They are exported via
+* python_export_sample() and consequently do not need a separate export
+* callback.
+*/
+   tables->synth_handler = get_handler("synth_data");
 }
 
 #if PY_MAJOR_VERSION < 3
-- 
2.20.1



[PATCH 04/43] perf tools: Increase MAX_NR_CPUS and MAX_CACHES

2019-07-01 Thread Arnaldo Carvalho de Melo
From: Kyle Meyer 

Attempting to profile 1024 or more CPUs with perf causes two errors:

  perf record -a
  [ perf record: Woken up X times to write data ]
  way too many cpu caches..
  [ perf record: Captured and wrote X MB perf.data (X samples) ]

  perf report -C 1024
  Error: failed to set  cpu bitmap
  Requested CPU 1024 too large. Consider raising MAX_NR_CPUS

  Increasing MAX_NR_CPUS from 1024 to 2048 and redefining MAX_CACHES as
  MAX_NR_CPUS * 4 returns normal functionality to perf:

  perf record -a
  [ perf record: Woken up X times to write data ]
  [ perf record: Captured and wrote X MB perf.data (X samples) ]

  perf report -C 1024
  ...

Signed-off-by: Kyle Meyer 
Cc: Alexander Shishkin 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/20190620193630.154025-1-mey...@stormcage.eag.rdlabs.hpecorp.net
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/perf.h| 2 +-
 tools/perf/util/header.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/perf.h b/tools/perf/perf.h
index 711e009381ec..74d0124d38f3 100644
--- a/tools/perf/perf.h
+++ b/tools/perf/perf.h
@@ -26,7 +26,7 @@ static inline unsigned long long rdclock(void)
 }
 
 #ifndef MAX_NR_CPUS
-#define MAX_NR_CPUS1024
+#define MAX_NR_CPUS2048
 #endif
 
 extern const char *input_name;
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 06ddb6618ef3..abc9c2145efe 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1121,7 +1121,7 @@ static int build_caches(struct cpu_cache_level caches[], 
u32 size, u32 *cntp)
return 0;
 }
 
-#define MAX_CACHES 2000
+#define MAX_CACHES (MAX_NR_CPUS * 4)
 
 static int write_cache(struct feat_fd *ff,
   struct perf_evlist *evlist __maybe_unused)
-- 
2.20.1



[PATCH 11/43] perf scripts python: export-to-postgresql.py: Export Intel PT power and ptwrite events

2019-07-01 Thread Arnaldo Carvalho de Melo
From: Adrian Hunter 

The format of synthesized events is determined by the attribute config.
For the formats for Intel PT power and ptwrite events, create tables and
populate them when the synth_data handler is called. If the tables
remain empty, drop them at the end.

The tables and views, including a combined power_events_view, will
display automatically from the tables menu of the exported
exported-sql-viewer.py script.

Note, currently only Atoms since Gemini Lake have support for ptwrite
and mwait, pwre, exstop and pwrx, but all Intel PT implementations
support cbr.

Signed-off-by: Adrian Hunter 
Cc: Jiri Olsa 
Link: http://lkml.kernel.org/r/20190622093248.581-8-adrian.hun...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 .../scripts/python/export-to-postgresql.py| 251 ++
 1 file changed, 251 insertions(+)

diff --git a/tools/perf/scripts/python/export-to-postgresql.py 
b/tools/perf/scripts/python/export-to-postgresql.py
index 93225c02117e..4447f0d7c754 100644
--- a/tools/perf/scripts/python/export-to-postgresql.py
+++ b/tools/perf/scripts/python/export-to-postgresql.py
@@ -447,6 +447,38 @@ if perf_db_export_calls:
'insn_count bigint,'
'cyc_count  bigint)')
 
+do_query(query, 'CREATE TABLE ptwrite ('
+   'id bigint  NOT NULL,'
+   'payloadbigint,'
+   'exact_ip   boolean)')
+
+do_query(query, 'CREATE TABLE cbr ('
+   'id bigint  NOT NULL,'
+   'cbrinteger,'
+   'mhzinteger,'
+   'percentinteger)')
+
+do_query(query, 'CREATE TABLE mwait ('
+   'id bigint  NOT NULL,'
+   'hints  integer,'
+   'extensions integer)')
+
+do_query(query, 'CREATE TABLE pwre ('
+   'id bigint  NOT NULL,'
+   'cstate integer,'
+   'subcstate  integer,'
+   'hw boolean)')
+
+do_query(query, 'CREATE TABLE exstop ('
+   'id bigint  NOT NULL,'
+   'exact_ip   boolean)')
+
+do_query(query, 'CREATE TABLE pwrx ('
+   'id bigint  NOT NULL,'
+   'deepest_cstate integer,'
+   'last_cstateinteger,'
+   'wake_reasoninteger)')
+
 do_query(query, 'CREATE VIEW machines_view AS '
'SELECT '
'id,'
@@ -561,6 +593,104 @@ do_query(query, 'CREATE VIEW samples_view AS '
'CASE WHEN cyc_count=0 THEN CAST(0 AS NUMERIC(20, 2)) ELSE 
CAST((CAST(insn_count AS FLOAT) / cyc_count) AS NUMERIC(20, 2)) END AS IPC'
' FROM samples')
 
+do_query(query, 'CREATE VIEW ptwrite_view AS '
+   'SELECT '
+   'ptwrite.id,'
+   'time,'
+   'cpu,'
+   'to_hex(payload) AS payload_hex,'
+   'CASE WHEN exact_ip=FALSE THEN \'False\' ELSE \'True\' END AS 
exact_ip'
+   ' FROM ptwrite'
+   ' INNER JOIN samples ON samples.id = ptwrite.id')
+
+do_query(query, 'CREATE VIEW cbr_view AS '
+   'SELECT '
+   'cbr.id,'
+   'time,'
+   'cpu,'
+   'cbr,'
+   'mhz,'
+   'percent'
+   ' FROM cbr'
+   ' INNER JOIN samples ON samples.id = cbr.id')
+
+do_query(query, 'CREATE VIEW mwait_view AS '
+   'SELECT '
+   'mwait.id,'
+   'time,'
+   'cpu,'
+   'to_hex(hints) AS hints_hex,'
+   'to_hex(extensions) AS extensions_hex'
+   ' FROM mwait'
+   ' INNER JOIN samples ON samples.id = mwait.id')
+
+do_query(query, 'CREATE VIEW pwre_view AS '
+   'SELECT '
+   'pwre.id,'
+   'time,'
+   'cpu,'
+   'cstate,'
+   'subcstate,'
+   'CASE WHEN hw=FALSE THEN \'False\' ELSE \'True\' END AS hw'
+   ' FROM pwre'
+   ' INNER JOIN samples ON samples.id = pwre.id')
+
+do_query(query, 'CREATE VIEW exstop_view AS '
+   'SELECT '
+   'exstop.id,'
+   'time,'
+   'cpu,'
+   'CASE WHEN exact_ip=FALSE THEN \'False\' ELSE \'True\' END AS 
exact_ip'
+   ' FROM exstop'
+   ' INNER JOIN samples ON samples.id = exstop.id')
+
+do_query(query, 'CREATE VIEW pwrx_view AS '
+   'SELECT '
+   'pwrx.id,'
+   'time,'
+   'cpu,'
+   'deepest_cstate,'
+   'last_cstate,'
+   'CASE WHEN wake_reason=1 THEN \'Interrupt\''
+   ' WHEN wake_reason=2 THEN \'Timer Deadline\''
+   ' WHEN wake_reason=4 THEN \'Monitored Address\''
+   ' WHEN wake_reason=8 THEN \'HW\''
+   ' ELSE CAST ( wake_reason AS VARCHAR(2) )'
+   'END AS wake_reason'
+   ' FROM pwrx'
+   ' INNER JOIN samples ON samples.id = pwrx.id')
+
+do_query(query, 'CREATE VIEW power_events_view AS '
+   'SELECT '
+   'sample

[PATCH 07/43] perf intel-pt: Add CBR value to decoder state

2019-07-01 Thread Arnaldo Carvalho de Melo
From: Adrian Hunter 

For convenience, add the core-to-bus ratio (CBR) value to the decoder
state.

Signed-off-by: Adrian Hunter 
Cc: Jiri Olsa 
Link: http://lkml.kernel.org/r/20190622093248.581-4-adrian.hun...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 1 +
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.h | 1 +
 2 files changed, 2 insertions(+)

diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c 
b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index 5eb792cc5d3a..4d14e78c5927 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -2633,6 +2633,7 @@ const struct intel_pt_state *intel_pt_decode(struct 
intel_pt_decoder *decoder)
}
decoder->state.type |= INTEL_PT_CBR_CHG;
decoder->state.cbr_payload = decoder->cbr_payload;
+   decoder->state.cbr = decoder->cbr;
}
if (intel_pt_sample_time(decoder->pkt_state)) {
intel_pt_update_sample_time(decoder);
diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h 
b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h
index 9957f2ccdca8..e289e463d635 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h
@@ -213,6 +213,7 @@ struct intel_pt_state {
uint64_t pwre_payload;
uint64_t pwrx_payload;
uint64_t cbr_payload;
+   uint32_t cbr;
uint32_t flags;
enum intel_pt_insn_op insn_op;
int insn_len;
-- 
2.20.1



[PATCH 13/43] perf ui stdio: No need to use 'spaces' to left align

2019-07-01 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

We can just use the 'field width' for the %s used to print the
alignment, this way we'll get the same result without requiring having a
variable with just lots of space chars.

No way to do that for the dots tho, we still need that variable filled
with dot chars.

  # perf report --stdio --hierarchy > before
  # perf report --stdio --hierarchy > after
  # diff before after
  #

I.e. it continues as:

  # perf report --stdio --hierarchy | head -15
  # To display the perf.data header info, please use --header/--header-only 
options.
  #
  #
  # Total Lost Samples: 0
  #
  # Samples: 107  of event 'cycles'
  # Event count (approx.): 31378313
  #
  #   Overhead  Command / Shared Object / Symbol
  # ..  
  #
  80.13%swapper
 72.29%[kernel.vmlinux]
49.85%[k] intel_idle
 9.05%[k] tick_nohz_next_event
  #

Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-9s1dxik37waveor7c84hq...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/stdio/hist.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c
index a60f2993d390..4c97e3cdf173 100644
--- a/tools/perf/ui/stdio/hist.c
+++ b/tools/perf/ui/stdio/hist.c
@@ -566,10 +566,14 @@ static int hist_entry__fprintf(struct hist_entry *he, 
size_t size,
 static int print_hierarchy_indent(const char *sep, int indent,
  const char *line, FILE *fp)
 {
+   int width;
+
if (sep != NULL || indent < 2)
return 0;
 
-   return fprintf(fp, "%-.*s", (indent - 2) * HIERARCHY_INDENT, line);
+   width = (indent - 2) * HIERARCHY_INDENT;
+
+   return fprintf(fp, "%-*.*s", width, width, line);
 }
 
 static int hists__fprintf_hierarchy_headers(struct hists *hists,
@@ -587,7 +591,7 @@ static int hists__fprintf_hierarchy_headers(struct hists 
*hists,
indent = hists->nr_hpp_node;
 
/* preserve max indent depth for column headers */
-   print_hierarchy_indent(sep, indent, spaces, fp);
+   print_hierarchy_indent(sep, indent, " ", fp);
 
/* the first hpp_list_node is for overhead columns */
fmt_node = list_first_entry(&hists->hpp_formats,
@@ -816,7 +820,7 @@ size_t hists__fprintf(struct hists *hists, bool 
show_header, int max_rows,
if (!h->leaf && !hist_entry__has_hierarchy_children(h, 
min_pcnt)) {
int depth = hists->nr_hpp_node + h->depth + 1;
 
-   print_hierarchy_indent(sep, depth, spaces, fp);
+   print_hierarchy_indent(sep, depth, " ", fp);
fprintf(fp, "%*sno entry >= %.2f%%\n", indent, "", 
min_pcnt);
 
if (max_rows && ++nr_rows >= max_rows)
-- 
2.20.1



[PATCH 27/43] perf probe: Use skip_spaces() for argv handling

2019-07-01 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

The skip_sep() routine has the same implementation as skip_spaces(),
recently adopted from the kernel, sources, switch to it.

Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Masami Hiramatsu 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-0ix211a81z2016dl5nmtd...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/string.c | 16 ++--
 1 file changed, 2 insertions(+), 14 deletions(-)

diff --git a/tools/perf/util/string.c b/tools/perf/util/string.c
index 084c3e4e9400..d28e723e2790 100644
--- a/tools/perf/util/string.c
+++ b/tools/perf/util/string.c
@@ -69,18 +69,6 @@ s64 perf_atoll(const char *str)
return -1;
 }
 
-/*
- * Helper function for splitting a string into an argv-like array.
- * originally copied from lib/argv_split.c
- */
-static const char *skip_sep(const char *cp)
-{
-   while (*cp && isspace(*cp))
-   cp++;
-
-   return cp;
-}
-
 static const char *skip_arg(const char *cp)
 {
while (*cp && !isspace(*cp))
@@ -94,7 +82,7 @@ static int count_argc(const char *str)
int count = 0;
 
while (*str) {
-   str = skip_sep(str);
+   str = skip_spaces(str);
if (*str) {
count++;
str = skip_arg(str);
@@ -148,7 +136,7 @@ char **argv_split(const char *str, int *argcp)
argvp = argv;
 
while (*str) {
-   str = skip_sep(str);
+   str = skip_spaces(str);
 
if (*str) {
const char *p = str;
-- 
2.20.1



[PATCH 23/43] tools lib: Adopt skip_spaces() from the kernel sources

2019-07-01 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

Same implementation, will be used to replace ad-hoc equivalent code in
tools/.

Cc: Adrian Hunter 
Cc: André Goddard Rosa 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-dig691cg9ripvoiprpidt...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/include/linux/string.h |  4 +++-
 tools/lib/string.c   | 14 ++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/tools/include/linux/string.h b/tools/include/linux/string.h
index 6c3e2cc274c5..cee239350a6b 100644
--- a/tools/include/linux/string.h
+++ b/tools/include/linux/string.h
@@ -29,4 +29,6 @@ static inline bool strstarts(const char *str, const char 
*prefix)
return strncmp(str, prefix, strlen(prefix)) == 0;
 }
 
-#endif /* _LINUX_STRING_H_ */
+extern char * __must_check skip_spaces(const char *);
+
+#endif /* _TOOLS_LINUX_STRING_H_ */
diff --git a/tools/lib/string.c b/tools/lib/string.c
index 93b3d4b6feac..50d400822bb3 100644
--- a/tools/lib/string.c
+++ b/tools/lib/string.c
@@ -17,6 +17,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 /**
@@ -106,3 +107,16 @@ size_t __weak strlcpy(char *dest, const char *src, size_t 
size)
}
return ret;
 }
+
+/**
+ * skip_spaces - Removes leading whitespace from @str.
+ * @str: The string to be stripped.
+ *
+ * Returns a pointer to the first non-whitespace character in @str.
+ */
+char *skip_spaces(const char *str)
+{
+   while (isspace(*str))
+   ++str;
+   return (char *)str;
+}
-- 
2.20.1



[PATCH 22/43] perf tools: Use linux/ctype.h in more places

2019-07-01 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

There were a few places where we still were using the libc version of
ctype.h, switch to the one in tools/lib/ctype.c that the rest of perf
uses.

Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-wa4nz4kt61eze88eprk20...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/arch/s390/util/header.c | 2 +-
 tools/perf/util/metricgroup.c  | 2 +-
 tools/perf/util/time-utils.c   | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/perf/arch/s390/util/header.c 
b/tools/perf/arch/s390/util/header.c
index 3db85cd2069e..a25896135abe 100644
--- a/tools/perf/arch/s390/util/header.c
+++ b/tools/perf/arch/s390/util/header.c
@@ -11,7 +11,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 
 #include "../../util/header.h"
 #include "../../util/util.h"
diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c
index 699e020737d9..a0cf3cd95ced 100644
--- a/tools/perf/util/metricgroup.c
+++ b/tools/perf/util/metricgroup.c
@@ -17,7 +17,7 @@
 #include "pmu-events/pmu-events.h"
 #include "strlist.h"
 #include 
-#include 
+#include 
 
 struct metric_event *metricgroup__lookup(struct rblist *metric_events,
 struct perf_evsel *evsel,
diff --git a/tools/perf/util/time-utils.c b/tools/perf/util/time-utils.c
index 2b48816a2d2e..369fa19dd596 100644
--- a/tools/perf/util/time-utils.c
+++ b/tools/perf/util/time-utils.c
@@ -7,7 +7,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 
 #include "perf.h"
 #include "debug.h"
-- 
2.20.1



[PATCH 26/43] perf time-utils: Use skip_spaces()

2019-07-01 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

No change in behaviour intended.

Cc: Adrian Hunter 
Cc: David Ahern 
Cc: Jin Yao 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-cpugv7qd5vzhbtvnlydo9...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/time-utils.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/tools/perf/util/time-utils.c b/tools/perf/util/time-utils.c
index 369fa19dd596..c2abc259b51d 100644
--- a/tools/perf/util/time-utils.c
+++ b/tools/perf/util/time-utils.c
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -141,10 +142,7 @@ static int perf_time__parse_strs(struct perf_time_interval 
*ptime,
for (i = 0, p = str; i < num - 1; i++) {
arg = p;
/* Find next comma, there must be one */
-   p = strchr(p, ',') + 1;
-   /* Skip white space */
-   while (isspace(*p))
-   p++;
+   p = skip_spaces(strchr(p, ',') + 1);
/* Skip the value, must not contain space or comma */
while (*p && !isspace(*p)) {
if (*p++ == ',') {
-- 
2.20.1



[PATCH 14/43] perf ctype: Remove now unused 'spaces' variable

2019-07-01 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

We can left justify just fine using the 'field width' modifier in %s
printf, ditch this variable.

Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-2td8u86mia7143lbr5ttl...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/ctype.c  | 4 
 tools/perf/util/sane_ctype.h | 1 -
 2 files changed, 5 deletions(-)

diff --git a/tools/perf/util/ctype.c b/tools/perf/util/ctype.c
index 8d90bf8d0d70..75c0da59c230 100644
--- a/tools/perf/util/ctype.c
+++ b/tools/perf/util/ctype.c
@@ -35,10 +35,6 @@ const char *graph_dotted_line =
"-"
"-"
"-";
-const char *spaces =
-   " "
-   " "
-   " ";
 const char *dots =
"."
"."
diff --git a/tools/perf/util/sane_ctype.h b/tools/perf/util/sane_ctype.h
index 894594fdedfb..a2bb3890864f 100644
--- a/tools/perf/util/sane_ctype.h
+++ b/tools/perf/util/sane_ctype.h
@@ -3,7 +3,6 @@
 #define _PERF_SANE_CTYPE_H
 
 extern const char *graph_dotted_line;
-extern const char *spaces;
 extern const char *dots;
 
 /* Sane ctype - no locale, and works with signed chars */
-- 
2.20.1



[PATCH 25/43] perf header: Use skip_spaces() in __write_cpudesc()

2019-07-01 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

No change in behaviour.

Cc: Stephane Eranian 
Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-0dbfpi70aa66s6mtd8z6p...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/header.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index fca9dbaf61ae..1eb15f7517b0 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -416,10 +417,8 @@ static int __write_cpudesc(struct feat_fd *ff, const char 
*cpuinfo_proc)
while (*p) {
if (isspace(*p)) {
char *r = p + 1;
-   char *q = r;
+   char *q = skip_spaces(r);
*p = ' ';
-   while (*q && isspace(*q))
-   q++;
if (q != (p+1))
while ((*r++ = *q++));
}
-- 
2.20.1



[PATCH 24/43] perf stat: Use recently introduced skip_spaces()

2019-07-01 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

No change in behaviour.

Cc: Andi Kleen 
Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-ncpvp4eelf8fqhuy29uv5...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/stat-display.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c
index 992e327bce85..ce993d29cca5 100644
--- a/tools/perf/util/stat-display.c
+++ b/tools/perf/util/stat-display.c
@@ -1,5 +1,6 @@
 #include 
 #include 
+#include 
 #include 
 #include 
 #include "color.h"
@@ -215,9 +216,7 @@ static void print_metric_csv(struct perf_stat_config 
*config __maybe_unused,
while (isdigit(*ends) || *ends == '.')
ends++;
*ends = 0;
-   while (isspace(*unit))
-   unit++;
-   fprintf(out, "%s%s%s%s", config->csv_sep, vals, config->csv_sep, unit);
+   fprintf(out, "%s%s%s%s", config->csv_sep, vals, config->csv_sep, 
skip_spaces(unit));
 }
 
 /* Filter out some columns that don't work well in metrics only mode */
-- 
2.20.1



[PATCH 16/43] tools x86 machine: Add missing util.h to pick up 'page_size'

2019-07-01 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

We're getting it by sheer luck, add that util.h to get the 'page_size'
definition.

Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-347078mgj3d2jfygtxs4n...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/arch/x86/util/machine.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/perf/arch/x86/util/machine.c 
b/tools/perf/arch/x86/util/machine.c
index 4520ac53caa9..0e508f26f83a 100644
--- a/tools/perf/arch/x86/util/machine.c
+++ b/tools/perf/arch/x86/util/machine.c
@@ -3,6 +3,7 @@
 #include 
 #include 
 
+#include "../../util/util.h"
 #include "../../util/machine.h"
 #include "../../util/map.h"
 #include "../../util/symbol.h"
-- 
2.20.1



[PATCH 15/43] perf string: Move 'dots' and 'graph_dotted_line' out of sane_ctype.h

2019-07-01 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

Those are not in that file in the git repo, lets move it from there so
that we get that sane ctype code fully isolated to allow getting it in
sync either with the git sources or better with the kernel sources
(include/linux/ctype.h + lib/ctype.h), that way we can use
check_headers.h to get notified when changes are made in the original
code so that we can cherry-pick.

Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-ioh5sghn3943j0rxg6lb2...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-kmem.c| 1 +
 tools/perf/builtin-sched.c   | 1 +
 tools/perf/builtin-top.c | 1 +
 tools/perf/util/ctype.c  | 9 -
 tools/perf/util/evsel.c  | 1 +
 tools/perf/util/sane_ctype.h | 3 ---
 tools/perf/util/string.c | 9 +
 tools/perf/util/string2.h| 3 +++
 8 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index b80eee455111..b833b03d7195 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -21,6 +21,7 @@
 #include "util/cpumap.h"
 
 #include "util/debug.h"
+#include "util/string2.h"
 
 #include 
 #include 
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 275f2d92a7bf..79577b67c898 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -15,6 +15,7 @@
 #include "util/thread_map.h"
 #include "util/color.h"
 #include "util/stat.h"
+#include "util/string2.h"
 #include "util/callchain.h"
 #include "util/time-utils.h"
 
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 12b6b15a9675..4ef02e6888ff 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -40,6 +40,7 @@
 #include "util/cpumap.h"
 #include "util/xyarray.h"
 #include "util/sort.h"
+#include "util/string2.h"
 #include "util/term.h"
 #include "util/intlist.h"
 #include "util/parse-branch-options.h"
diff --git a/tools/perf/util/ctype.c b/tools/perf/util/ctype.c
index 75c0da59c230..f84ecd9e5329 100644
--- a/tools/perf/util/ctype.c
+++ b/tools/perf/util/ctype.c
@@ -30,12 +30,3 @@ unsigned char sane_ctype[256] = {
A, A, A, A, A, A, A, A, A, A, A, R, R, P, P, 0, /* 112..127 */
/* Nothing in the 128.. range */
 };
-
-const char *graph_dotted_line =
-   "-"
-   "-"
-   "-";
-const char *dots =
-   "."
-   "."
-   ".";
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 04c4ed1573cb..4b175166d264 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -35,6 +35,7 @@
 #include "debug.h"
 #include "trace-event.h"
 #include "stat.h"
+#include "string2.h"
 #include "memswap.h"
 #include "util/parse-branch-options.h"
 
diff --git a/tools/perf/util/sane_ctype.h b/tools/perf/util/sane_ctype.h
index a2bb3890864f..c4dce9e3001b 100644
--- a/tools/perf/util/sane_ctype.h
+++ b/tools/perf/util/sane_ctype.h
@@ -2,9 +2,6 @@
 #ifndef _PERF_SANE_CTYPE_H
 #define _PERF_SANE_CTYPE_H
 
-extern const char *graph_dotted_line;
-extern const char *dots;
-
 /* Sane ctype - no locale, and works with signed chars */
 #undef isascii
 #undef isspace
diff --git a/tools/perf/util/string.c b/tools/perf/util/string.c
index d8bfd0c4d2cb..b18884bd673b 100644
--- a/tools/perf/util/string.c
+++ b/tools/perf/util/string.c
@@ -6,6 +6,15 @@
 
 #include "sane_ctype.h"
 
+const char *graph_dotted_line =
+   "-"
+   "-"
+   "-";
+const char *dots =
+   "."
+   "."
+   ".";
+
 #define K 1024LL
 /*
  * perf_atoll()
diff --git a/tools/perf/util/string2.h b/tools/perf/util/string2.h
index 4c68a09b97e8..07fd37568543 100644
--- a/tools/perf/util/string2.h
+++ b/tools/perf/util/string2.h
@@ -6,6 +6,9 @@
 #include 
 #include 
 
+extern const char *graph_dotted_line;
+extern const char *dots;
+
 s64 perf_atoll(const char *str);
 char **argv_split(const char *str, int *argcp);
 void argv_free(char **argv);
-- 
2.20.1



[PATCH 19/43] perf tools: Remove old baggage that is util/include/linux/ctype.h

2019-07-01 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

It was just including a ../util.h that wasn't even there:

  $ cat tools/perf/util/include/linux/../util.h
  cat: tools/perf/util/include/linux/../util.h: No such file or directory
  $

This would make kallsyms.h get util.h somehow and then files including
it would get util.h defined stuff, a mess, fix it.

Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-wlzwken4psiat4zvfbvao...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/lib/symbol/kallsyms.h   | 1 -
 tools/perf/util/include/linux/ctype.h | 1 -
 2 files changed, 2 deletions(-)
 delete mode 100644 tools/perf/util/include/linux/ctype.h

diff --git a/tools/lib/symbol/kallsyms.h b/tools/lib/symbol/kallsyms.h
index bd988f7b18d4..2b238f181d97 100644
--- a/tools/lib/symbol/kallsyms.h
+++ b/tools/lib/symbol/kallsyms.h
@@ -3,7 +3,6 @@
 #define __TOOLS_KALLSYMS_H_ 1
 
 #include 
-#include 
 #include 
 
 #ifndef KSYM_NAME_LEN
diff --git a/tools/perf/util/include/linux/ctype.h 
b/tools/perf/util/include/linux/ctype.h
deleted file mode 100644
index a53d4ee1e0b7..
--- a/tools/perf/util/include/linux/ctype.h
+++ /dev/null
@@ -1 +0,0 @@
-#include "../util.h"
-- 
2.20.1



[PATCH 20/43] perf tools: Add missing util.h to pick up 'page_size' variable

2019-07-01 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

Not to depend of getting it indirectly.

Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-tirjsmvu4ektw0k7lm8k9...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/arch/arm/util/cs-etm.c | 1 +
 tools/perf/arch/x86/tests/intel-cqm.c | 1 +
 tools/perf/arch/x86/util/intel-pt.c   | 1 +
 tools/perf/perf.c | 1 +
 tools/perf/util/machine.c | 1 +
 tools/perf/util/python.c  | 1 +
 6 files changed, 6 insertions(+)

diff --git a/tools/perf/arch/arm/util/cs-etm.c 
b/tools/perf/arch/arm/util/cs-etm.c
index c6f1ab5499b5..2b83cc8e4796 100644
--- a/tools/perf/arch/arm/util/cs-etm.c
+++ b/tools/perf/arch/arm/util/cs-etm.c
@@ -22,6 +22,7 @@
 #include "../../util/pmu.h"
 #include "../../util/thread_map.h"
 #include "../../util/cs-etm.h"
+#include "../../util/util.h"
 
 #include 
 #include 
diff --git a/tools/perf/arch/x86/tests/intel-cqm.c 
b/tools/perf/arch/x86/tests/intel-cqm.c
index 90a4a8c58a62..94aa0b673b7f 100644
--- a/tools/perf/arch/x86/tests/intel-cqm.c
+++ b/tools/perf/arch/x86/tests/intel-cqm.c
@@ -6,6 +6,7 @@
 #include "evlist.h"
 #include "evsel.h"
 #include "arch-tests.h"
+#include "util.h"
 
 #include 
 #include 
diff --git a/tools/perf/arch/x86/util/intel-pt.c 
b/tools/perf/arch/x86/util/intel-pt.c
index 1869f62a10cd..9804098dcefb 100644
--- a/tools/perf/arch/x86/util/intel-pt.c
+++ b/tools/perf/arch/x86/util/intel-pt.c
@@ -25,6 +25,7 @@
 #include "../../util/auxtrace.h"
 #include "../../util/tsc.h"
 #include "../../util/intel-pt.h"
+#include "../../util/util.h"
 
 #define KiB(x) ((x) * 1024)
 #define MiB(x) ((x) * 1024 * 1024)
diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index 72df4b6fa36f..2123b3cc4dcf 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -18,6 +18,7 @@
 #include "util/bpf-loader.h"
 #include "util/debug.h"
 #include "util/event.h"
+#include "util/util.h"
 #include 
 #include 
 #include 
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 17eec39e775e..a0bb05dd008f 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -15,6 +15,7 @@
 #include "strlist.h"
 #include "thread.h"
 #include "vdso.h"
+#include "util.h"
 #include 
 #include 
 #include 
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index 6aa7e2352e16..1e5b6718dcea 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -12,6 +12,7 @@
 #include "print_binary.h"
 #include "thread_map.h"
 #include "mmap.h"
+#include "util.h"
 
 #if PY_MAJOR_VERSION < 3
 #define _PyUnicode_FromString(arg) \
-- 
2.20.1



[PATCH 17/43] perf kallsyms: Adopt hex2u64 from tools/perf/util/util.h

2019-07-01 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

Just removing more stuff from tools/perf/, this is mostly used in the
kallsyms parsing and in places in perf where kallsyms is involved, so we
get it for free there.

With this we reduce a bit more util.h.

Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-5mc1zg0jqdwgkn8c358ka...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/lib/symbol/kallsyms.c | 13 +
 tools/lib/symbol/kallsyms.h |  2 ++
 tools/perf/util/util.c  | 13 -
 tools/perf/util/util.h  |  1 -
 4 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/tools/lib/symbol/kallsyms.c b/tools/lib/symbol/kallsyms.c
index 96d830545bbb..7501611abee4 100644
--- a/tools/lib/symbol/kallsyms.c
+++ b/tools/lib/symbol/kallsyms.c
@@ -16,6 +16,19 @@ bool kallsyms__is_function(char symbol_type)
return symbol_type == 'T' || symbol_type == 'W';
 }
 
+/*
+ * While we find nice hex chars, build a long_val.
+ * Return number of chars processed.
+ */
+int hex2u64(const char *ptr, u64 *long_val)
+{
+   char *p;
+
+   *long_val = strtoull(ptr, &p, 16);
+
+   return p - ptr;
+}
+
 int kallsyms__parse(const char *filename, void *arg,
int (*process_symbol)(void *arg, const char *name,
  char type, u64 start))
diff --git a/tools/lib/symbol/kallsyms.h b/tools/lib/symbol/kallsyms.h
index 72ab9870454b..bd988f7b18d4 100644
--- a/tools/lib/symbol/kallsyms.h
+++ b/tools/lib/symbol/kallsyms.h
@@ -18,6 +18,8 @@ static inline u8 kallsyms2elf_binding(char type)
return isupper(type) ? STB_GLOBAL : STB_LOCAL;
 }
 
+int hex2u64(const char *ptr, u64 *long_val);
+
 u8 kallsyms2elf_type(char type);
 
 bool kallsyms__is_function(char symbol_type);
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index d388f80d8703..a61535cf1bca 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -434,19 +434,6 @@ size_t hex_width(u64 v)
return n;
 }
 
-/*
- * While we find nice hex chars, build a long_val.
- * Return number of chars processed.
- */
-int hex2u64(const char *ptr, u64 *long_val)
-{
-   char *p;
-
-   *long_val = strtoull(ptr, &p, 16);
-
-   return p - ptr;
-}
-
 int perf_event_paranoid(void)
 {
int value;
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 09c1b0f91f65..125e215dd3d8 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -43,7 +43,6 @@ ssize_t readn(int fd, void *buf, size_t n);
 ssize_t writen(int fd, const void *buf, size_t n);
 
 size_t hex_width(u64 v);
-int hex2u64(const char *ptr, u64 *val);
 
 extern unsigned int page_size;
 int __pure cacheline_size(void);
-- 
2.20.1



[PATCH 35/43] tools lib: Adopt strreplace() from the kernel

2019-07-01 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

We'll use it to further reduce the size of tools/perf/util/string.c,
replacing the strxfrchar() equivalent function we have there.

Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-x3r61ikjrso1buygxwke8...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/include/linux/string.h |  2 ++
 tools/lib/string.c   | 16 
 2 files changed, 18 insertions(+)

diff --git a/tools/include/linux/string.h b/tools/include/linux/string.h
index e436f8037c87..a76d4df10435 100644
--- a/tools/include/linux/string.h
+++ b/tools/include/linux/string.h
@@ -19,6 +19,8 @@ extern size_t strlcpy(char *dest, const char *src, size_t 
size);
 
 char *str_error_r(int errnum, char *buf, size_t buflen);
 
+char *strreplace(char *s, char old, char new);
+
 /**
  * strstarts - does @str start with @prefix?
  * @str: string to examine
diff --git a/tools/lib/string.c b/tools/lib/string.c
index 80472e6b3829..f2ae1b87c719 100644
--- a/tools/lib/string.c
+++ b/tools/lib/string.c
@@ -145,3 +145,19 @@ char *strim(char *s)
 
return skip_spaces(s);
 }
+
+/**
+ * strreplace - Replace all occurrences of character in string.
+ * @s: The string to operate on.
+ * @old: The character being replaced.
+ * @new: The character @old is replaced with.
+ *
+ * Returns pointer to the nul byte at the end of @s.
+ */
+char *strreplace(char *s, char old, char new)
+{
+   for (; *s; ++s)
+   if (*s == old)
+   *s = new;
+   return s;
+}
-- 
2.20.1



[PATCH 29/43] perf metricgroup: Use strsep()

2019-07-01 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

No change in behaviour intended, trivial optimization done by avoiding
looking for spaces in 'g' right after setting it to "No_group".

Cc: Adrian Hunter 
Cc: Andi Kleen 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-f2siadtp3hb5o0l1w7bvd...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/metricgroup.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c
index a0cf3cd95ced..90cd84e2a503 100644
--- a/tools/perf/util/metricgroup.c
+++ b/tools/perf/util/metricgroup.c
@@ -308,10 +308,9 @@ void metricgroup__print(bool metrics, bool metricgroups, 
char *filter,
struct mep *me;
char *s;
 
+   g = skip_spaces(g);
if (*g == 0)
g = "No_group";
-   while (isspace(*g))
-   g++;
if (filter && !strstr(g, filter))
continue;
if (raw)
-- 
2.20.1



[PATCH 34/43] perf tools: Ditch rtrim(), use strim() from tools/lib

2019-07-01 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

Cleaning up a bit more tools/perf/util/ by using things we got from the
kernel and have in tools/lib/

Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-7hluuoveryoicvkclshzj...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browsers/hists.c |  3 ++-
 tools/perf/util/annotate.c |  3 ++-
 tools/perf/util/header.c   |  6 +++---
 tools/perf/util/pmu.c  |  2 +-
 tools/perf/util/python-ext-sources |  1 +
 tools/perf/util/srcline.c  |  3 ++-
 tools/perf/util/string.c   | 23 ---
 tools/perf/util/string2.h  |  2 --
 tools/perf/util/thread_map.c   |  3 ++-
 9 files changed, 13 insertions(+), 33 deletions(-)

diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index 10243408f3dc..33e67aa91347 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -2071,7 +2071,8 @@ static int hist_browser__fprintf_hierarchy_entry(struct 
hist_browser *browser,
advance_hpp(&hpp, ret);
}
 
-   printed += fprintf(fp, "%s\n", rtrim(s));
+   strim(s);
+   printed += fprintf(fp, "%s\n", s);
 
if (he->leaf && folded_sign == '-') {
printed += hist_browser__fprintf_callchain(browser, he, fp,
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 783e2628cc8e..2d08c4b62c63 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -35,6 +35,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 /* FIXME: For the HE_COLORSET */
@@ -1495,7 +1496,7 @@ static int symbol__parse_objdump_line(struct symbol *sym, 
FILE *file,
return -1;
 
line_ip = -1;
-   parsed_line = rtrim(line);
+   parsed_line = strim(line);
 
/* /filename:linenr ? Save line number and ignore. */
if (regexec(&file_lineno, parsed_line, 2, match, 0) == 0) {
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 1eb15f7517b0..bf26dc85eaaa 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1048,7 +1048,7 @@ static int cpu_cache_level__read(struct cpu_cache_level 
*cache, u32 cpu, u16 lev
return -1;
 
cache->type[len] = 0;
-   cache->type = rtrim(cache->type);
+   cache->type = strim(cache->type);
 
scnprintf(file, PATH_MAX, "%s/size", path);
if (sysfs__read_str(file, &cache->size, &len)) {
@@ -1057,7 +1057,7 @@ static int cpu_cache_level__read(struct cpu_cache_level 
*cache, u32 cpu, u16 lev
}
 
cache->size[len] = 0;
-   cache->size = rtrim(cache->size);
+   cache->size = strim(cache->size);
 
scnprintf(file, PATH_MAX, "%s/shared_cpu_list", path);
if (sysfs__read_str(file, &cache->map, &len)) {
@@ -1067,7 +1067,7 @@ static int cpu_cache_level__read(struct cpu_cache_level 
*cache, u32 cpu, u16 lev
}
 
cache->map[len] = 0;
-   cache->map = rtrim(cache->map);
+   cache->map = strim(cache->map);
return 0;
 }
 
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 38dc0c6e28b8..8139a1f3ed39 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -395,7 +395,7 @@ static int perf_pmu__new_alias(struct list_head *list, char 
*dir, char *name, FI
buf[ret] = 0;
 
/* Remove trailing newline from sysfs file */
-   rtrim(buf);
+   strim(buf);
 
return __perf_pmu__new_alias(list, dir, name, NULL, buf, NULL, NULL, 
NULL,
 NULL, NULL, NULL);
diff --git a/tools/perf/util/python-ext-sources 
b/tools/perf/util/python-ext-sources
index 648bcd80b475..2237bac9fadb 100644
--- a/tools/perf/util/python-ext-sources
+++ b/tools/perf/util/python-ext-sources
@@ -16,6 +16,7 @@ util/namespaces.c
 ../lib/bitmap.c
 ../lib/find_bit.c
 ../lib/hweight.c
+../lib/string.c
 ../lib/vsprintf.c
 util/thread_map.c
 util/util.c
diff --git a/tools/perf/util/srcline.c b/tools/perf/util/srcline.c
index 10ca1533937e..1824cabe3512 100644
--- a/tools/perf/util/srcline.c
+++ b/tools/perf/util/srcline.c
@@ -5,6 +5,7 @@
 #include 
 
 #include 
+#include 
 
 #include "util/dso.h"
 #include "util/util.h"
@@ -464,7 +465,7 @@ static struct inline_node *addr2inlines(const char 
*dso_name, u64 addr,
char *srcline;
struct symbol *inline_sym;
 
-   rtrim(funcname);
+   strim(funcname);
 
if (getline(&filename, &filelen, fp) == -1)
goto out;
diff --git a/tools/perf/util/string.c b/tools/perf/util/string.c
index 99a555ea4a9f..93a5340424df 100644
--- a/tools/perf/util/string.c
+++ b/tools/perf/util/string.c
@@ -318,29 +318,6 @@ char *strxfrchar(char *s, char from, char to)
return s;
 }
 
-/**
- * rtrim - Removes trailing whitespace from @s.
- * @s: The string to be stripped.
- *
- * Note that the first trailing whitespace 

[PATCH 37/43] tools lib: Move argv_{split,free} from tools/perf/util/

2019-07-01 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

This came from the kernel lib/argv_split.c, so move it to
tools/lib/argv_split.c, to get it closer to the kernel structure.

We need to audit the usage of argv_split() to figure out if it is really
necessary to do have one allocation per argv[] entry, looking at one of
its users I guess that is not the case and we probably are even leaking
those allocations by not using argv_free() judiciously, for later.

With this we further remove stuff from tools/perf/util/, reducing the
perf specific codebase and encouraging other tools/ code to use these
routines so as to keep the style and constructs used with the kernel.

Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Masami Hiramatsu 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-j479s1ive9h75w5lfg16j...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/include/linux/string.h |   3 ++
 tools/lib/argv_split.c   | 100 +++
 tools/perf/MANIFEST  |   1 +
 tools/perf/util/Build|   5 ++
 tools/perf/util/string.c |  91 ---
 tools/perf/util/string2.h|   2 -
 6 files changed, 109 insertions(+), 93 deletions(-)
 create mode 100644 tools/lib/argv_split.c

diff --git a/tools/include/linux/string.h b/tools/include/linux/string.h
index a76d4df10435..980cb9266718 100644
--- a/tools/include/linux/string.h
+++ b/tools/include/linux/string.h
@@ -7,6 +7,9 @@
 
 void *memdup(const void *src, size_t len);
 
+char **argv_split(const char *str, int *argcp);
+void argv_free(char **argv);
+
 int strtobool(const char *s, bool *res);
 
 /*
diff --git a/tools/lib/argv_split.c b/tools/lib/argv_split.c
new file mode 100644
index ..0a58ccf3f761
--- /dev/null
+++ b/tools/lib/argv_split.c
@@ -0,0 +1,100 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Helper function for splitting a string into an argv-like array.
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+static const char *skip_arg(const char *cp)
+{
+   while (*cp && !isspace(*cp))
+   cp++;
+
+   return cp;
+}
+
+static int count_argc(const char *str)
+{
+   int count = 0;
+
+   while (*str) {
+   str = skip_spaces(str);
+   if (*str) {
+   count++;
+   str = skip_arg(str);
+   }
+   }
+
+   return count;
+}
+
+/**
+ * argv_free - free an argv
+ * @argv - the argument vector to be freed
+ *
+ * Frees an argv and the strings it points to.
+ */
+void argv_free(char **argv)
+{
+   char **p;
+   for (p = argv; *p; p++) {
+   free(*p);
+   *p = NULL;
+   }
+
+   free(argv);
+}
+
+/**
+ * argv_split - split a string at whitespace, returning an argv
+ * @str: the string to be split
+ * @argcp: returned argument count
+ *
+ * Returns an array of pointers to strings which are split out from
+ * @str.  This is performed by strictly splitting on white-space; no
+ * quote processing is performed.  Multiple whitespace characters are
+ * considered to be a single argument separator.  The returned array
+ * is always NULL-terminated.  Returns NULL on memory allocation
+ * failure.
+ */
+char **argv_split(const char *str, int *argcp)
+{
+   int argc = count_argc(str);
+   char **argv = calloc(argc + 1, sizeof(*argv));
+   char **argvp;
+
+   if (argv == NULL)
+   goto out;
+
+   if (argcp)
+   *argcp = argc;
+
+   argvp = argv;
+
+   while (*str) {
+   str = skip_spaces(str);
+
+   if (*str) {
+   const char *p = str;
+   char *t;
+
+   str = skip_arg(str);
+
+   t = strndup(p, str-p);
+   if (t == NULL)
+   goto fail;
+   *argvp++ = t;
+   }
+   }
+   *argvp = NULL;
+
+out:
+   return argv;
+
+fail:
+   argv_free(argv);
+   return NULL;
+}
diff --git a/tools/perf/MANIFEST b/tools/perf/MANIFEST
index aac4c755d81b..6a5de44b2de9 100644
--- a/tools/perf/MANIFEST
+++ b/tools/perf/MANIFEST
@@ -7,6 +7,7 @@ tools/lib/traceevent
 tools/lib/api
 tools/lib/bpf
 tools/lib/subcmd
+tools/lib/argv_split.c
 tools/lib/ctype.c
 tools/lib/hweight.c
 tools/lib/rbtree.c
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index b4dc6112138f..d3408a463060 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -20,6 +20,7 @@ perf-y += parse-events.o
 perf-y += perf_regs.o
 perf-y += path.o
 perf-y += print_binary.o
+perf-y += argv_split.o
 perf-y += rbtree.o
 perf-y += libstring.o
 perf-y += bitmap.o
@@ -209,6 +210,10 @@ $(OUTPUT)util/kallsyms.o: ../lib/symbol/kallsyms.c FORCE
$(call rule_mkdir)
$(call if_changed_dep,cc_o_c)
 
+$(OUTPUT)util/argv_split.o: ../lib/argv_split.c FORCE
+   $(call rule_mkdir)
+   $(call if_changed_dep,cc_o_c)
+
 $(OUTPUT)util/bitmap.o: ../lib/bitmap.c FORCE

[PATCH 31/43] perf tools: Ditch rtrim(), use skip_spaces() to get closer to the kernel

2019-07-01 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

No change in behaviour, just using the same kernel idiom for such
operation.

Cc: Adrian Hunter 
Cc: André Goddard Rosa 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-a85lkptkt0ru40irpga8y...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-script.c| 12 ++--
 tools/perf/ui/browser.c|  2 +-
 tools/perf/ui/browsers/hists.c |  2 +-
 tools/perf/ui/gtk/hists.c  |  4 ++--
 tools/perf/ui/stdio/hist.c |  2 +-
 tools/perf/util/annotate.c | 10 +-
 tools/perf/util/event.c|  4 +---
 tools/perf/util/pmu.c  |  3 ++-
 tools/perf/util/stat-display.c |  4 ++--
 tools/perf/util/string.c   | 14 --
 tools/perf/util/string2.h  |  4 ++--
 11 files changed, 23 insertions(+), 38 deletions(-)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 0131f7a0d48d..520e5b6b9ef9 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -2880,7 +2880,7 @@ static int read_script_info(struct script_desc *desc, 
const char *filename)
return -1;
 
while (fgets(line, sizeof(line), fp)) {
-   p = ltrim(line);
+   p = skip_spaces(line);
if (strlen(p) == 0)
continue;
if (*p != '#')
@@ -2889,19 +2889,19 @@ static int read_script_info(struct script_desc *desc, 
const char *filename)
if (strlen(p) && *p == '!')
continue;
 
-   p = ltrim(p);
+   p = skip_spaces(p);
if (strlen(p) && p[strlen(p) - 1] == '\n')
p[strlen(p) - 1] = '\0';
 
if (!strncmp(p, "description:", strlen("description:"))) {
p += strlen("description:");
-   desc->half_liner = strdup(ltrim(p));
+   desc->half_liner = strdup(skip_spaces(p));
continue;
}
 
if (!strncmp(p, "args:", strlen("args:"))) {
p += strlen("args:");
-   desc->args = strdup(ltrim(p));
+   desc->args = strdup(skip_spaces(p));
continue;
}
}
@@ -3008,7 +3008,7 @@ static int check_ev_match(char *dir_name, char 
*scriptname,
return -1;
 
while (fgets(line, sizeof(line), fp)) {
-   p = ltrim(line);
+   p = skip_spaces(line);
if (*p == '#')
continue;
 
@@ -3018,7 +3018,7 @@ static int check_ev_match(char *dir_name, char 
*scriptname,
break;
 
p += 2;
-   p = ltrim(p);
+   p = skip_spaces(p);
len = strcspn(p, " \t");
if (!len)
break;
diff --git a/tools/perf/ui/browser.c b/tools/perf/ui/browser.c
index 8812c1564995..55ff05a46e0b 100644
--- a/tools/perf/ui/browser.c
+++ b/tools/perf/ui/browser.c
@@ -594,7 +594,7 @@ static int ui_browser__color_config(const char *var, const 
char *value,
break;
 
*bg = '\0';
-   bg = ltrim(++bg);
+   bg = skip_spaces(bg + 1);
ui_browser__colorsets[i].bg = bg;
ui_browser__colorsets[i].fg = fg;
return 0;
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index 59483bdb0027..04a56114df92 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -1470,7 +1470,7 @@ static int hist_browser__show_hierarchy_entry(struct 
hist_browser *browser,
int i = 0;
 
width -= fmt->entry(fmt, &hpp, entry);
-   ui_browser__printf(&browser->b, "%s", ltrim(s));
+   ui_browser__printf(&browser->b, "%s", 
skip_spaces(s));
 
while (isspace(s[i++]))
width++;
diff --git a/tools/perf/ui/gtk/hists.c b/tools/perf/ui/gtk/hists.c
index 0c08890f006a..6341c421a8f7 100644
--- a/tools/perf/ui/gtk/hists.c
+++ b/tools/perf/ui/gtk/hists.c
@@ -459,7 +459,7 @@ static void perf_gtk__add_hierarchy_entries(struct hists 
*hists,
advance_hpp(hpp, ret + 2);
}
 
-   gtk_tree_store_set(store, &iter, col_idx, ltrim(rtrim(bf)), -1);
+   gtk_tree_store_set(store, &iter, col_idx, trim(bf), -1);
 
if (!he->leaf) {
hpp->buf = bf;
@@ -555,7 +555,7 @@ static void perf_gtk__show_hierarchy(GtkWidget *window, 
struct hists *hists,
first_col = false;
 
fmt->header(fmt, &hpp, hists, 0, NULL);
-   strcat(buf, ltrim(rtrim(hpp.buf

[PATCH 36/43] perf tools: Drop strxfrchar(), use strreplace() equivalent from kernel

2019-07-01 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

No change in behaviour intended, just reducing the codebase and using
something available in tools/lib/.

Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-oyi6zif3810nwi4uu85od...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/dso.c |  3 ++-
 tools/perf/util/string.c  | 18 --
 tools/perf/util/string2.h |  1 -
 3 files changed, 2 insertions(+), 20 deletions(-)

diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index 1fb18292c2d3..c7fde04400f7 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -394,7 +395,7 @@ int __kmod_path__parse(struct kmod_path *m, const char 
*path,
return -ENOMEM;
}
 
-   strxfrchar(m->name, '-', '_');
+   strreplace(m->name, '-', '_');
}
 
return 0;
diff --git a/tools/perf/util/string.c b/tools/perf/util/string.c
index 93a5340424df..9b7fbb0cbecd 100644
--- a/tools/perf/util/string.c
+++ b/tools/perf/util/string.c
@@ -300,24 +300,6 @@ int strtailcmp(const char *s1, const char *s2)
return 0;
 }
 
-/**
- * strxfrchar - Locate and replace character in @s
- * @s:The string to be searched/changed.
- * @from: Source character to be replaced.
- * @to:   Destination character.
- *
- * Return pointer to the changed string.
- */
-char *strxfrchar(char *s, char from, char to)
-{
-   char *p = s;
-
-   while ((p = strchr(p, from)) != NULL)
-   *p++ = to;
-
-   return s;
-}
-
 char *asprintf_expr_inout_ints(const char *var, bool in, size_t nints, int 
*ints)
 {
/*
diff --git a/tools/perf/util/string2.h b/tools/perf/util/string2.h
index 6da835ad8f5b..2696c3fcd780 100644
--- a/tools/perf/util/string2.h
+++ b/tools/perf/util/string2.h
@@ -21,7 +21,6 @@ static inline bool strisglob(const char *str)
return strpbrk(str, "*?[") != NULL;
 }
 int strtailcmp(const char *s1, const char *s2);
-char *strxfrchar(char *s, char from, char to);
 
 char *asprintf_expr_inout_ints(const char *var, bool in, size_t nints, int 
*ints);
 
-- 
2.20.1



[PATCH 30/43] perf report: Use skip_spaces()

2019-07-01 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

No change in behaviour intended.

Cc: Adrian Hunter 
Cc: Andi Kleen 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-lcywlfqbi37nhegmhl1ar...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-report.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 91a3762b4211..aef59f318a67 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -941,8 +941,7 @@ parse_time_quantum(const struct option *opt, const char 
*arg,
pr_err("time quantum cannot be 0");
return -1;
}
-   while (isspace(*end))
-   end++;
+   end = skip_spaces(end);
if (*end == 0)
return 0;
if (!strcmp(end, "s")) {
-- 
2.20.1



[PATCH 38/43] perf stat: Make metric event lookup more robust

2019-07-01 Thread Arnaldo Carvalho de Melo
From: Andi Kleen 

After setting up metric groups through the event parser, the metricgroup
code looks them up again in the event list.

Make sure we only look up events that haven't been used by some other
metric. The data structures currently cannot handle more than one metric
per event. This avoids problems with multiple events partially
overlapping.

Signed-off-by: Andi Kleen 
Acked-by: Jiri Olsa 
Cc: Kan Liang 
Link: http://lkml.kernel.org/r/20190624193711.35241-2-a...@firstfloor.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/stat-shadow.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c
index 027b09aaa4cf..3f8fd127d31e 100644
--- a/tools/perf/util/stat-shadow.c
+++ b/tools/perf/util/stat-shadow.c
@@ -304,7 +304,7 @@ static struct perf_evsel *perf_stat__find_event(struct 
perf_evlist *evsel_list,
struct perf_evsel *c2;
 
evlist__for_each_entry (evsel_list, c2) {
-   if (!strcasecmp(c2->name, name))
+   if (!strcasecmp(c2->name, name) && !c2->collect_stat)
return c2;
}
return NULL;
@@ -343,7 +343,8 @@ void perf_stat__collect_metric_expr(struct perf_evlist 
*evsel_list)
if (leader) {
/* Search in group */
for_each_group_member (oc, leader) {
-   if (!strcasecmp(oc->name, 
metric_names[i])) {
+   if (!strcasecmp(oc->name, 
metric_names[i]) &&
+   !oc->collect_stat) {
found = true;
break;
}
-- 
2.20.1



[PATCH 32/43] tools lib: Adopt strim() from the kernel

2019-07-01 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

Since we're working on moving stuff out of tools/perf/util/ to
tools/lib/, take the opportunity to adopt routines from the kernel that
are equivalent, so that tools/ code look more like the kernel.

Cc: Adrian Hunter 
Cc: André Goddard Rosa 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-zqy1zdu2ok17qvi0ytk8z...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/include/linux/string.h |  2 ++
 tools/lib/string.c   | 25 +
 2 files changed, 27 insertions(+)

diff --git a/tools/include/linux/string.h b/tools/include/linux/string.h
index cee239350a6b..e436f8037c87 100644
--- a/tools/include/linux/string.h
+++ b/tools/include/linux/string.h
@@ -31,4 +31,6 @@ static inline bool strstarts(const char *str, const char 
*prefix)
 
 extern char * __must_check skip_spaces(const char *);
 
+extern char *strim(char *);
+
 #endif /* _TOOLS_LINUX_STRING_H_ */
diff --git a/tools/lib/string.c b/tools/lib/string.c
index 50d400822bb3..80472e6b3829 100644
--- a/tools/lib/string.c
+++ b/tools/lib/string.c
@@ -120,3 +120,28 @@ char *skip_spaces(const char *str)
++str;
return (char *)str;
 }
+
+/**
+ * strim - Removes leading and trailing whitespace from @s.
+ * @s: The string to be stripped.
+ *
+ * Note that the first trailing whitespace is replaced with a %NUL-terminator
+ * in the given string @s. Returns a pointer to the first non-whitespace
+ * character in @s.
+ */
+char *strim(char *s)
+{
+   size_t size;
+   char *end;
+
+   size = strlen(s);
+   if (!size)
+   return s;
+
+   end = s + size - 1;
+   while (end >= s && isspace(*end))
+   end--;
+   *(end + 1) = '\0';
+
+   return skip_spaces(s);
+}
-- 
2.20.1



[PATCH 28/43] perf strfilter: Use skip_spaces()

2019-07-01 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

No change in behaviour.

Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Masami Hiramatsu 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-p9rtamq7lvre9zhti70az...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/strfilter.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/strfilter.c b/tools/perf/util/strfilter.c
index 2c3a2904ebcd..90ea2b209cbb 100644
--- a/tools/perf/util/strfilter.c
+++ b/tools/perf/util/strfilter.c
@@ -5,6 +5,7 @@
 
 #include 
 #include 
+#include 
 
 /* Operators */
 static const char *OP_and  = "&";  /* Logical AND */
@@ -37,8 +38,7 @@ static const char *get_token(const char *s, const char **e)
 {
const char *p;
 
-   while (isspace(*s)) /* Skip spaces */
-   s++;
+   s = skip_spaces(s);
 
if (*s == '\0') {
p = s;
-- 
2.20.1



[PATCH 33/43] perf tools: Remove trim() implementation, use tools/lib's strim()

2019-07-01 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

Moving more stuff out of tools/perf/util/ and using the kernel idiom.

Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-wpj8rktj62yse5dq6ckny...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/tests/builtin-test.c | 3 ++-
 tools/perf/ui/browsers/hists.c  | 3 ++-
 tools/perf/ui/gtk/hists.c   | 5 +++--
 tools/perf/ui/stdio/hist.c  | 2 +-
 tools/perf/util/string2.h   | 5 -
 5 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index cd72ff0f7658..66a82badc1d1 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -22,6 +22,7 @@
 #include "string2.h"
 #include "symbol.h"
 #include 
+#include 
 #include 
 
 static bool dont_fork;
@@ -438,7 +439,7 @@ static const char *shell_test__description(char 
*description, size_t size,
description = fgets(description, size, fp);
fclose(fp);
 
-   return description ? trim(description + 1) : NULL;
+   return description ? strim(description + 1) : NULL;
 }
 
 #define for_each_shell_test(dir, base, ent)\
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index 04a56114df92..10243408f3dc 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -6,6 +6,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -1686,7 +1687,7 @@ static int 
hists_browser__scnprintf_hierarchy_headers(struct hist_browser *brows
ret = fmt->header(fmt, &dummy_hpp, hists, 0, NULL);
dummy_hpp.buf[ret] = '\0';
 
-   start = trim(dummy_hpp.buf);
+   start = strim(dummy_hpp.buf);
ret = strlen(start);
 
if (start != dummy_hpp.buf)
diff --git a/tools/perf/ui/gtk/hists.c b/tools/perf/ui/gtk/hists.c
index 6341c421a8f7..3955ed1d1bd9 100644
--- a/tools/perf/ui/gtk/hists.c
+++ b/tools/perf/ui/gtk/hists.c
@@ -9,6 +9,7 @@
 #include "../string2.h"
 #include "gtk.h"
 #include 
+#include 
 
 #define MAX_COLUMNS32
 
@@ -459,7 +460,7 @@ static void perf_gtk__add_hierarchy_entries(struct hists 
*hists,
advance_hpp(hpp, ret + 2);
}
 
-   gtk_tree_store_set(store, &iter, col_idx, trim(bf), -1);
+   gtk_tree_store_set(store, &iter, col_idx, strim(bf), -1);
 
if (!he->leaf) {
hpp->buf = bf;
@@ -555,7 +556,7 @@ static void perf_gtk__show_hierarchy(GtkWidget *window, 
struct hists *hists,
first_col = false;
 
fmt->header(fmt, &hpp, hists, 0, NULL);
-   strcat(buf, trim(hpp.buf));
+   strcat(buf, strim(hpp.buf));
}
}
 
diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c
index 594e56628904..9eb0131c3ade 100644
--- a/tools/perf/ui/stdio/hist.c
+++ b/tools/perf/ui/stdio/hist.c
@@ -620,7 +620,7 @@ static int hists__fprintf_hierarchy_headers(struct hists 
*hists,
 
fmt->header(fmt, hpp, hists, 0, NULL);
 
-   header_width += fprintf(fp, "%s", trim(hpp->buf));
+   header_width += fprintf(fp, "%s", strim(hpp->buf));
}
}
 
diff --git a/tools/perf/util/string2.h b/tools/perf/util/string2.h
index db02059e31c5..5bc3fea52cdc 100644
--- a/tools/perf/util/string2.h
+++ b/tools/perf/util/string2.h
@@ -25,11 +25,6 @@ char *strxfrchar(char *s, char from, char to);
 
 char *rtrim(char *s);
 
-static inline char *trim(char *s)
-{
-   return skip_spaces(rtrim(s));
-}
-
 char *asprintf_expr_inout_ints(const char *var, bool in, size_t nints, int 
*ints);
 
 static inline char *asprintf_expr_in_ints(const char *var, size_t nints, int 
*ints)
-- 
2.20.1



[PATCH 18/43] perf symbols: We need util.h in symbol-elf.c for zfree()

2019-07-01 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

Continuing to untangle the headers, we're about to remove the old odd
baggage that is tools/perf/util/include/linux/ctype.h.

Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-gapezcq3p8bzrsi96vdtq...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/symbol-elf.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
index fdc5bd7dbb90..f04ef851ae86 100644
--- a/tools/perf/util/symbol-elf.c
+++ b/tools/perf/util/symbol-elf.c
@@ -14,6 +14,7 @@
 #include "machine.h"
 #include "vdso.h"
 #include "debug.h"
+#include "util.h"
 #include "sane_ctype.h"
 #include 
 
-- 
2.20.1



[PATCH 21/43] tools perf: Move from sane_ctype.h obtained from git to the Linux's original

2019-07-01 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

We got the sane_ctype.h headers from git and kept using it so far, but
since that code originally came from the kernel sources to the git
sources, perhaps its better to just use the one in the kernel, so that
we can leverage tools/perf/check_headers.sh to be notified when our copy
gets out of sync, i.e. when fixes or goodies are added to the code we've
copied.

This will help with things like tools/lib/string.c where we want to have
more things in common with the kernel, such as strim(), skip_spaces(),
etc so as to go on removing the things that we have in tools/perf/util/
and instead using the code in the kernel, indirectly and removing things
like EXPORT_SYMBOL(), etc, getting notified when fixes and improvements
are made to the original code.

Hopefully this also should help with reducing the difference of code
hosted in tools/ to the one in the kernel proper.

Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-7k9868l713wqtgo01xxyg...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/include/linux/ctype.h | 75 +
 tools/lib/ctype.c   | 35 ++
 tools/lib/symbol/kallsyms.c |  1 -
 tools/lib/symbol/kallsyms.h |  1 +
 tools/perf/MANIFEST |  1 +
 tools/perf/arch/x86/util/machine.c  |  2 +-
 tools/perf/builtin-kmem.c   |  2 +-
 tools/perf/builtin-report.c |  2 +-
 tools/perf/builtin-sched.c  |  2 +-
 tools/perf/builtin-script.c |  2 +-
 tools/perf/builtin-stat.c   |  2 +-
 tools/perf/builtin-top.c|  2 +-
 tools/perf/builtin-trace.c  |  2 +-
 tools/perf/check-headers.sh |  2 +
 tools/perf/tests/code-reading.c |  2 +-
 tools/perf/ui/browser.c |  2 +-
 tools/perf/ui/browsers/hists.c  |  2 +-
 tools/perf/ui/browsers/map.c|  2 +-
 tools/perf/ui/stdio/hist.c  |  2 +-
 tools/perf/util/Build   |  4 ++
 tools/perf/util/annotate.c  |  2 +-
 tools/perf/util/auxtrace.c  |  2 +-
 tools/perf/util/build-id.c  |  2 +-
 tools/perf/util/config.c|  2 +-
 tools/perf/util/cpumap.c|  2 +-
 tools/perf/util/ctype.c | 32 
 tools/perf/util/data-convert-bt.c   |  2 +-
 tools/perf/util/debug.c |  2 +-
 tools/perf/util/demangle-java.c |  2 +-
 tools/perf/util/env.c   |  2 +-
 tools/perf/util/event.c |  2 +-
 tools/perf/util/evsel.c |  2 +-
 tools/perf/util/header.c|  2 +-
 tools/perf/util/jitdump.c   |  2 +-
 tools/perf/util/machine.c   |  2 +-
 tools/perf/util/print_binary.c  |  2 +-
 tools/perf/util/probe-event.c   |  2 +-
 tools/perf/util/probe-finder.h  |  2 +-
 tools/perf/util/python-ext-sources  |  2 +-
 tools/perf/util/sane_ctype.h| 47 --
 tools/perf/util/stat-display.c  |  2 +-
 tools/perf/util/strfilter.c |  2 +-
 tools/perf/util/string.c|  2 +-
 tools/perf/util/symbol-elf.c|  2 +-
 tools/perf/util/symbol.c|  2 +-
 tools/perf/util/trace-event-parse.c |  2 +-
 46 files changed, 155 insertions(+), 117 deletions(-)
 create mode 100644 tools/include/linux/ctype.h
 create mode 100644 tools/lib/ctype.c
 delete mode 100644 tools/perf/util/ctype.c
 delete mode 100644 tools/perf/util/sane_ctype.h

diff --git a/tools/include/linux/ctype.h b/tools/include/linux/ctype.h
new file mode 100644
index ..310090b4c474
--- /dev/null
+++ b/tools/include/linux/ctype.h
@@ -0,0 +1,75 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_CTYPE_H
+#define _LINUX_CTYPE_H
+
+/*
+ * NOTE! This ctype does not handle EOF like the standard C
+ * library is required to.
+ */
+
+#define _U 0x01/* upper */
+#define _L 0x02/* lower */
+#define _D 0x04/* digit */
+#define _C 0x08/* cntrl */
+#define _P 0x10/* punct */
+#define _S 0x20/* white space (space/lf/tab) */
+#define _X 0x40/* hex digit */
+#define _SP0x80/* hard space (0x20) */
+
+extern const unsigned char _ctype[];
+
+#define __ismask(x) (_ctype[(int)(unsigned char)(x)])
+
+#define isalnum(c) ((__ismask(c)&(_U|_L|_D)) != 0)
+#define isalpha(c) ((__ismask(c)&(_U|_L)) != 0)
+#define iscntrl(c) ((__ismask(c)&(_C)) != 0)
+static inline int __isdigit(int c)
+{
+   return '0' <= c && c <= '9';
+}
+#define isdigit(c) __isdigit(c)
+#define isgraph(c) ((__ismask(c)&(_P|_U|_L|_D)) != 0)
+#define islower(c) ((__ismask(c)&(_L)) != 0)
+#define isprint(c) ((__ismask(c)&(_P|_U|_L|_D|_SP)) != 0)
+#define ispunct(c) ((__ismask(c)&(_P)) != 0)
+/* Note: isspace() must return false for %NUL-terminator */
+#define isspace(c) ((__ismask(c)&(_S)) != 0)
+#define isupper(c) ((__ismask(c)&(_U)) != 0)
+#define isxdigit(c)((__ismask(c)&(_D|_X)) != 0)
+
+#define isascii(c) (((unsigned c

[PATCH 10/43] perf scripts python: export-to-sqlite.py: Export Intel PT power and ptwrite events

2019-07-01 Thread Arnaldo Carvalho de Melo
From: Adrian Hunter 

The format of synthesized events is determined by the attribute config.
For the formats for Intel PT power and ptwrite events, create tables and
populate them when the synth_data handler is called. If the tables
remain empty, drop them at the end.

The tables and views, including a combined power_events_view, will
display automatically from the tables menu of the exported
exported-sql-viewer.py script.

Note, currently only Atoms since Gemini Lake have support for ptwrite
and mwait, pwre, exstop and pwrx, but all Intel PT implementations
support cbr.

Signed-off-by: Adrian Hunter 
Cc: Jiri Olsa 
Link: http://lkml.kernel.org/r/20190622093248.581-7-adrian.hun...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/scripts/python/export-to-sqlite.py | 239 ++
 1 file changed, 239 insertions(+)

diff --git a/tools/perf/scripts/python/export-to-sqlite.py 
b/tools/perf/scripts/python/export-to-sqlite.py
index 4542ce89034b..3222a83f4184 100644
--- a/tools/perf/scripts/python/export-to-sqlite.py
+++ b/tools/perf/scripts/python/export-to-sqlite.py
@@ -271,6 +271,38 @@ if perf_db_export_calls:
'insn_count bigint,'
'cyc_count  bigint)')
 
+do_query(query, 'CREATE TABLE ptwrite ('
+   'id integer NOT NULLPRIMARY KEY,'
+   'payloadbigint,'
+   'exact_ip   integer)')
+
+do_query(query, 'CREATE TABLE cbr ('
+   'id integer NOT NULLPRIMARY KEY,'
+   'cbrinteger,'
+   'mhzinteger,'
+   'percentinteger)')
+
+do_query(query, 'CREATE TABLE mwait ('
+   'id integer NOT NULLPRIMARY KEY,'
+   'hints  integer,'
+   'extensions integer)')
+
+do_query(query, 'CREATE TABLE pwre ('
+   'id integer NOT NULLPRIMARY KEY,'
+   'cstate integer,'
+   'subcstate  integer,'
+   'hw integer)')
+
+do_query(query, 'CREATE TABLE exstop ('
+   'id integer NOT NULLPRIMARY KEY,'
+   'exact_ip   integer)')
+
+do_query(query, 'CREATE TABLE pwrx ('
+   'id integer NOT NULLPRIMARY KEY,'
+   'deepest_cstate integer,'
+   'last_cstateinteger,'
+   'wake_reasoninteger)')
+
 # printf was added to sqlite in version 3.8.3
 sqlite_has_printf = False
 try:
@@ -399,6 +431,102 @@ do_query(query, 'CREATE VIEW samples_view AS '
'CASE WHEN cyc_count=0 THEN CAST(0 AS FLOAT) ELSE 
ROUND(CAST(insn_count AS FLOAT) / cyc_count, 2) END AS IPC'
' FROM samples')
 
+do_query(query, 'CREATE VIEW ptwrite_view AS '
+   'SELECT '
+   'ptwrite.id,'
+   'time,'
+   'cpu,'
+   + emit_to_hex('payload') + ' AS payload_hex,'
+   'CASE WHEN exact_ip=0 THEN \'False\' ELSE \'True\' END AS 
exact_ip'
+   ' FROM ptwrite'
+   ' INNER JOIN samples ON samples.id = ptwrite.id')
+
+do_query(query, 'CREATE VIEW cbr_view AS '
+   'SELECT '
+   'cbr.id,'
+   'time,'
+   'cpu,'
+   'cbr,'
+   'mhz,'
+   'percent'
+   ' FROM cbr'
+   ' INNER JOIN samples ON samples.id = cbr.id')
+
+do_query(query, 'CREATE VIEW mwait_view AS '
+   'SELECT '
+   'mwait.id,'
+   'time,'
+   'cpu,'
+   + emit_to_hex('hints') + ' AS hints_hex,'
+   + emit_to_hex('extensions') + ' AS extensions_hex'
+   ' FROM mwait'
+   ' INNER JOIN samples ON samples.id = mwait.id')
+
+do_query(query, 'CREATE VIEW pwre_view AS '
+   'SELECT '
+   'pwre.id,'
+   'time,'
+   'cpu,'
+   'cstate,'
+   'subcstate,'
+   'CASE WHEN hw=0 THEN \'False\' ELSE \'True\' END AS hw'
+   ' FROM pwre'
+   ' INNER JOIN samples ON samples.id = pwre.id')
+
+do_query(query, 'CREATE VIEW exstop_view AS '
+   'SELECT '
+   'exstop.id,'
+   'time,'
+   'cpu,'
+   'CASE WHEN exact_ip=0 THEN \'False\' ELSE \'True\' END AS 
exact_ip'
+   ' FROM exstop'
+   ' INNER JOIN samples ON samples.id = exstop.id')
+
+do_query(query, 'CREATE VIEW pwrx_view AS '
+   'SELECT '
+   'pwrx.id,'
+   'time,'
+   'cpu,'
+   'deepest_cstate,'
+   'last_cstate,'
+   'CASE WHEN wake_reason=1 THEN \'Interrupt\''
+   ' WHEN wake_reason=2 THEN \'Timer Deadline\''
+   ' WHEN wake_reason=4 THEN \'Monitored Address\''
+   ' WHEN wake_reason=8 THEN \'HW\''
+   ' EL

[PATCH 41/43] perf stat: Fix metrics with --no-merge

2019-07-01 Thread Arnaldo Carvalho de Melo
From: Andi Kleen 

Since Fixes: 8c5421c016a4 ("perf pmu: Display pmu name when printing
unmerged events in stat") using --no-merge adds the PMU name to the
evsel name.

This breaks the metric value lookup because the parser doesn't know
about this.

Remove the extra postfixes for the metric evaluation.

Signed-off-by: Andi Kleen 
Acked-by: Jiri Olsa 
Cc: Agustin Vega-Frias 
Cc: Kan Liang 
Fixes: 8c5421c016a4 ("perf pmu: Display pmu name when printing unmerged events 
in stat")
Link: http://lkml.kernel.org/r/20190624193711.35241-5-a...@firstfloor.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/stat-shadow.c | 18 +-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c
index 3f8fd127d31e..cb891e5c2969 100644
--- a/tools/perf/util/stat-shadow.c
+++ b/tools/perf/util/stat-shadow.c
@@ -724,6 +724,7 @@ static void generic_metric(struct perf_stat_config *config,
double ratio;
int i;
void *ctxp = out->ctx;
+   char *n, *pn;
 
expr__ctx_init(&pctx);
expr__add_id(&pctx, name, avg);
@@ -743,7 +744,19 @@ static void generic_metric(struct perf_stat_config *config,
stats = &v->stats;
scale = 1.0;
}
-   expr__add_id(&pctx, metric_events[i]->name, 
avg_stats(stats)*scale);
+
+   n = strdup(metric_events[i]->name);
+   if (!n)
+   return;
+   /*
+* This display code with --no-merge adds [cpu] postfixes.
+* These are not supported by the parser. Remove everything
+* after the space.
+*/
+   pn = strchr(n, ' ');
+   if (pn)
+   *pn = 0;
+   expr__add_id(&pctx, n, avg_stats(stats)*scale);
}
if (!metric_events[i]) {
const char *p = metric_expr;
@@ -760,6 +773,9 @@ static void generic_metric(struct perf_stat_config *config,
 (metric_name ? metric_name : name) : "", 
0);
} else
print_metric(config, ctxp, NULL, NULL, "", 0);
+
+   for (i = 1; i < pctx.num_ids; i++)
+   free((void *)pctx.ids[i].name);
 }
 
 void perf_stat__print_shadow_stats(struct perf_stat_config *config,
-- 
2.20.1



[PATCH 39/43] perf stat: Don't merge events in the same PMU

2019-07-01 Thread Arnaldo Carvalho de Melo
From: Andi Kleen 

Event merging is mainly to collapse similar events in lots of different
duplicated PMUs.

It can break metric displaying. It's possible for two metrics to have
the same event, and when the two events happen in a row the second
wouldn't be displayed.  This would also not show the second metric.

To avoid this don't merge events in the same PMU. This makes sense, if
we have multiple events in the same PMU there is likely some reason for
it (e.g. using multiple groups) and we better not merge them.

While in theory it would be possible to construct metrics that have
events with the same name in different PMU no current metrics have this
problem.

This is the fix for perf stat -M UPI,IPC (needs also another bug fix to
completely work)

Signed-off-by: Andi Kleen 
Acked-by: Jiri Olsa 
Cc: Kan Liang 
Fixes: 430daf2dc7af ("perf stat: Collapse identically named events")
Link: http://lkml.kernel.org/r/20190624193711.35241-3-a...@firstfloor.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/stat-display.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c
index 90df41169113..58df6a0dbb9f 100644
--- a/tools/perf/util/stat-display.c
+++ b/tools/perf/util/stat-display.c
@@ -554,7 +554,8 @@ static void collect_all_aliases(struct perf_stat_config 
*config, struct perf_evs
alias->scale != counter->scale ||
alias->cgrp != counter->cgrp ||
strcmp(alias->unit, counter->unit) ||
-   perf_evsel__is_clock(alias) != 
perf_evsel__is_clock(counter))
+   perf_evsel__is_clock(alias) != 
perf_evsel__is_clock(counter) ||
+   !strcmp(alias->pmu_name, counter->pmu_name))
break;
alias->merged_stat = true;
cb(config, alias, data, false);
-- 
2.20.1



[PATCH 40/43] perf stat: Fix group lookup for metric group

2019-07-01 Thread Arnaldo Carvalho de Melo
From: Andi Kleen 

The metric group code tries to find a group it added earlier in the
evlist. Fix the lookup to handle groups with partially overlaps
correctly. When a sub string match fails and we reset the match, we have
to compare the first element again.

I also renamed the find_evsel function to find_evsel_group to make its
purpose clearer.

With the earlier changes this fixes:

Before:

  % perf stat -M UPI,IPC sleep 1
  ...
 1,032,922  uops_retired.retire_slots #  1.1 UPI
 1,896,096  inst_retired.any
 1,896,096  inst_retired.any
 1,177,254  cpu_clk_unhalted.thread

After:

  % perf stat -M UPI,IPC sleep 1
  ...
1,013,193  uops_retired.retire_slots #  1.1 UPI
   932,033  inst_retired.any
   932,033  inst_retired.any  #  0.9 IPC
 1,091,245  cpu_clk_unhalted.thread

Signed-off-by: Andi Kleen 
Acked-by: Jiri Olsa 
Cc: Kan Liang 
Fixes: b18f3e365019 ("perf stat: Support JSON metrics in perf stat")
Link: http://lkml.kernel.org/r/20190624193711.35241-4-a...@firstfloor.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/metricgroup.c | 47 ++-
 1 file changed, 35 insertions(+), 12 deletions(-)

diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c
index 90cd84e2a503..bc25995255ab 100644
--- a/tools/perf/util/metricgroup.c
+++ b/tools/perf/util/metricgroup.c
@@ -85,26 +85,49 @@ struct egroup {
const char *metric_expr;
 };
 
-static struct perf_evsel *find_evsel(struct perf_evlist *perf_evlist,
-const char **ids,
-int idnum,
-struct perf_evsel **metric_events)
+static bool record_evsel(int *ind, struct perf_evsel **start,
+int idnum,
+struct perf_evsel **metric_events,
+struct perf_evsel *ev)
+{
+   metric_events[*ind] = ev;
+   if (*ind == 0)
+   *start = ev;
+   if (++*ind == idnum) {
+   metric_events[*ind] = NULL;
+   return true;
+   }
+   return false;
+}
+
+static struct perf_evsel *find_evsel_group(struct perf_evlist *perf_evlist,
+  const char **ids,
+  int idnum,
+  struct perf_evsel **metric_events)
 {
struct perf_evsel *ev, *start = NULL;
int ind = 0;
 
evlist__for_each_entry (perf_evlist, ev) {
+   if (ev->collect_stat)
+   continue;
if (!strcmp(ev->name, ids[ind])) {
-   metric_events[ind] = ev;
-   if (ind == 0)
-   start = ev;
-   if (++ind == idnum) {
-   metric_events[ind] = NULL;
+   if (record_evsel(&ind, &start, idnum,
+metric_events, ev))
return start;
-   }
} else {
+   /*
+* We saw some other event that is not
+* in our list of events. Discard
+* the whole match and start again.
+*/
ind = 0;
start = NULL;
+   if (!strcmp(ev->name, ids[ind])) {
+   if (record_evsel(&ind, &start, idnum,
+metric_events, ev))
+   return start;
+   }
}
}
/*
@@ -134,8 +157,8 @@ static int metricgroup__setup_events(struct list_head 
*groups,
ret = -ENOMEM;
break;
}
-   evsel = find_evsel(perf_evlist, eg->ids, eg->idnum,
-  metric_events);
+   evsel = find_evsel_group(perf_evlist, eg->ids, eg->idnum,
+metric_events);
if (!evsel) {
pr_debug("Cannot resolve %s: %s\n",
eg->metric_name, eg->metric_expr);
-- 
2.20.1



[PATCH 42/43] perf annotate: Add csky support

2019-07-01 Thread Arnaldo Carvalho de Melo
From: Mao Han 

This patch add basic arch initialization and instruction associate
support for the csky CPU architecture.

E.g.:

  $ perf annotate --stdio2
  Samples: 161  of event 'cpu-clock:pppH', 4000 Hz, Event count (approx.):
  4025, [percent: local period]
  test_4() /usr/lib/perf-test/callchain_test
  Percent

  Disassembly of section .text:

  8420 :
test_4():
subi  sp, sp, 4
st.w  r8, (sp, 0x0)
mov   r8, sp
subi  sp, sp, 8
subi  r3, r8, 4
movi  r2, 0
st.w  r2, (r3, 0x0)
  ↓ br2e
  100.00  14:   subi  r3, r8, 4
ld.w  r2, (r3, 0x0)
subi  r3, r8, 8
st.w  r2, (r3, 0x0)
subi  r3, r8, 4
ld.w  r3, (r3, 0x0)
addi  r2, r3, 1
subi  r3, r8, 4
st.w  r2, (r3, 0x0)
  2e:   subi  r3, r8, 4
ld.w  r2, (r3, 0x0)
lrw   r3, 0x98967f// 8598 
cmplt r3, r2
  ↑ bf14
mov   r0, r0
mov   r0, r0
mov   sp, r8
ld.w  r8, (sp, 0x0)
addi  sp, sp, 4
  ← rts

Signed-off-by: Mao Han 
Acked-by: Guo Ren 
Cc: Alexander Shishkin 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: linux-c...@vger.kernel.org
Link: 
http://lkml.kernel.org/r/d874d7782d9acdad5d98f2f5c4a6fb26fbe41c5d.1561531557.git.han_...@c-sky.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/arch/csky/annotate/instructions.c | 48 
 tools/perf/util/annotate.c   |  5 ++
 2 files changed, 53 insertions(+)
 create mode 100644 tools/perf/arch/csky/annotate/instructions.c

diff --git a/tools/perf/arch/csky/annotate/instructions.c 
b/tools/perf/arch/csky/annotate/instructions.c
new file mode 100644
index ..5337bfb7d5fc
--- /dev/null
+++ b/tools/perf/arch/csky/annotate/instructions.c
@@ -0,0 +1,48 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2019 Hangzhou C-SKY Microsystems co.,ltd.
+
+#include 
+
+static struct ins_ops *csky__associate_ins_ops(struct arch *arch,
+  const char *name)
+{
+   struct ins_ops *ops = NULL;
+
+   /* catch all kind of jumps */
+   if (!strcmp(name, "bt") ||
+   !strcmp(name, "bf") ||
+   !strcmp(name, "bez") ||
+   !strcmp(name, "bnez") ||
+   !strcmp(name, "bnezad") ||
+   !strcmp(name, "bhsz") ||
+   !strcmp(name, "bhz") ||
+   !strcmp(name, "blsz") ||
+   !strcmp(name, "blz") ||
+   !strcmp(name, "br") ||
+   !strcmp(name, "jmpi") ||
+   !strcmp(name, "jmp"))
+   ops = &jump_ops;
+
+   /* catch function call */
+   if (!strcmp(name, "bsr") ||
+   !strcmp(name, "jsri") ||
+   !strcmp(name, "jsr"))
+   ops = &call_ops;
+
+   /* catch function return */
+   if (!strcmp(name, "rts"))
+   ops = &ret_ops;
+
+   if (ops)
+   arch__associate_ins_ops(arch, name, ops);
+   return ops;
+}
+
+static int csky__annotate_init(struct arch *arch, char *cpuid __maybe_unused)
+{
+   arch->initialized = true;
+   arch->objdump.comment_char = '/';
+   arch->associate_instruction_ops = csky__associate_ins_ops;
+
+   return 0;
+}
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 2d08c4b62c63..ec7aaf31c2b2 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -145,6 +145,7 @@ static int arch__associate_ins_ops(struct arch* arch, const 
char *name, struct i
 #include "arch/arc/annotate/instructions.c"
 #include "arch/arm/annotate/instructions.c"
 #include "arch/arm64/annotate/instructions.c"
+#include "arch/csky/annotate/instructions.c"
 #include "arch/x86/annotate/instructions.c"
 #include "arch/powerpc/annotate/instructions.c"
 #include "arch/s390/annotate/instructions.c"
@@ -163,6 +164,10 @@ static struct arch architectures[] = {
.name = "arm64",
.init = arm64__annotate_init,
},
+   {
+   .name = "csky",
+   .init = csky__annotate_init,
+   },
{
.name = "x86",
.init = x86__annotate_init,
-- 
2.20.1



[PATCH 43/43] perf jevents: Use nonlocal include statements in pmu-events.c

2019-07-01 Thread Arnaldo Carvalho de Melo
From: Luke Mujica 

Change pmu-events.c to not use local include statements. The code that
creates the include statements for pmu-events.c is in jevents.c.

pmu-events.c is a generated file, and for build systems that put
generated files in a separate directory, include statements with local
pathing cannot find non-generated files.

Signed-off-by: Luke Mujica 
Cc: Ian Rogers 
Cc: Jiri Olsa 
Cc: Numfor Mbiziwo-Tiapo 
Cc: Stephane Eranian 
Link: https://lkml.kernel.org/n/tip-prgnwmaoo1pv9zz4vnv1b...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/pmu-events/jevents.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/pmu-events/jevents.c b/tools/perf/pmu-events/jevents.c
index 58f77fd0f59f..a1184ea64cc6 100644
--- a/tools/perf/pmu-events/jevents.c
+++ b/tools/perf/pmu-events/jevents.c
@@ -841,7 +841,7 @@ static void create_empty_mapping(const char *output_file)
_Exit(1);
}
 
-   fprintf(outfp, "#include \"../../pmu-events/pmu-events.h\"\n");
+   fprintf(outfp, "#include \"pmu-events/pmu-events.h\"\n");
print_mapping_table_prefix(outfp);
print_mapping_table_suffix(outfp);
fclose(outfp);
@@ -1096,7 +1096,7 @@ int main(int argc, char *argv[])
}
 
/* Include pmu-events.h first */
-   fprintf(eventsfp, "#include \"../../pmu-events/pmu-events.h\"\n");
+   fprintf(eventsfp, "#include \"pmu-events/pmu-events.h\"\n");
 
/*
 * The mapfile allows multiple CPUids to point to the same JSON file,
-- 
2.20.1



Re: [PATCH] net: ethernet: broadcom: bcm63xx_enet: Remove unneeded memset

2019-07-01 Thread David Miller
From: Hariprasad Kelam 
Date: Sun, 30 Jun 2019 19:59:49 +0530

> Remove unneeded memset as alloc_etherdev is using kvzalloc which uses
> __GFP_ZERO flag
> 
> Signed-off-by: Hariprasad Kelam 

Applied to net-next, thanks.


[PATCH 02/43] perf thread-stack: Fix thread stack return from kernel for kernel-only case

2019-07-01 Thread Arnaldo Carvalho de Melo
From: Adrian Hunter 

Commit f08046cb3082 ("perf thread-stack: Represent jmps to the start of a
different symbol") had the side-effect of introducing more stack entries
before return from kernel space.

When user space is also traced, those entries are popped before entry to
user space, but when user space is not traced, they get stuck at the
bottom of the stack, making the stack grow progressively larger.

Fix by detecting a return-from-kernel branch type, and popping kernel
addresses from the stack then.

Note, the problem and fix affect the exported Call Graph / Tree but not
the callindent option used by "perf script --call-trace".

Example:

  perf-with-kcore record example -e intel_pt//k -- ls
  perf-with-kcore script example --itrace=bep -s 
~/libexec/perf-core/scripts/python/export-to-sqlite.py example.db branches calls
  ~/libexec/perf-core/scripts/python/exported-sql-viewer.py example.db

  Menu option: Reports -> Context-Sensitive Call Graph

  Before: (showing Call Path column only)

Call Path
▶ perf
▼ ls
  ▼ 12111:12111
▶ setup_new_exec
▶ __task_pid_nr_ns
▶ perf_event_pid_type
▶ perf_event_comm_output
▶ perf_iterate_ctx
▶ perf_iterate_sb
▶ perf_event_comm
▶ __set_task_comm
▶ load_elf_binary
▶ search_binary_handler
▶ __do_execve_file.isra.41
▶ __x64_sys_execve
▶ do_syscall_64
▼ entry_SYSCALL_64_after_hwframe
  ▼ swapgs_restore_regs_and_return_to_usermode
▼ native_iret
  ▶ error_entry
  ▶ do_page_fault
  ▼ error_exit
▼ retint_user
  ▶ prepare_exit_to_usermode
  ▼ native_iret
▶ error_entry
▶ do_page_fault
▼ error_exit
  ▼ retint_user
▶ prepare_exit_to_usermode
▼ native_iret
  ▶ error_entry
  ▶ do_page_fault
  ▼ error_exit
▼ retint_user
  ▶ prepare_exit_to_usermode
  ▶ native_iret

  After: (showing Call Path column only)

Call Path
▶ perf
▼ ls
  ▼ 12111:12111
▶ setup_new_exec
▶ __task_pid_nr_ns
▶ perf_event_pid_type
▶ perf_event_comm_output
▶ perf_iterate_ctx
▶ perf_iterate_sb
▶ perf_event_comm
▶ __set_task_comm
▶ load_elf_binary
▶ search_binary_handler
▶ __do_execve_file.isra.41
▶ __x64_sys_execve
▶ do_syscall_64
▶ entry_SYSCALL_64_after_hwframe
▶ page_fault
▼ entry_SYSCALL_64
  ▼ do_syscall_64
▶ __x64_sys_brk
▶ __x64_sys_access
▶ __x64_sys_openat
▶ __x64_sys_newfstat
▶ __x64_sys_mmap
▶ __x64_sys_close
▶ __x64_sys_read
▶ __x64_sys_mprotect
▶ __x64_sys_arch_prctl
▶ __x64_sys_munmap
▶ exit_to_usermode_loop
▶ __x64_sys_set_tid_address
▶ __x64_sys_set_robust_list
▶ __x64_sys_rt_sigaction
▶ __x64_sys_rt_sigprocmask
▶ __x64_sys_prlimit64
▶ __x64_sys_statfs
▶ __x64_sys_ioctl
▶ __x64_sys_getdents64
▶ __x64_sys_write
▶ __x64_sys_exit_group

Committer notes:

The first arg to the perf-with-kcore needs to be the same for the
'record' and 'script' lines, otherwise we'll record the perf.data file
and kcore_dir/ files in one directory ('example') to then try to use it
from the 'bep' directory, fix the instructions above it so that both use
'example'.

Signed-off-by: Adrian Hunter 
Tested-by: Arnaldo Carvalho de Melo 
Cc: Jiri Olsa 
Cc: sta...@vger.kernel.org
Fixes: f08046cb3082 ("perf thread-stack: Represent jmps to the start of a 
different symbol")
Link: http://lkml.kernel.org/r/20190619064429.14940-2-adrian.hun...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/thread-stack.c | 30 +-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/thread-stack.c b/tools/perf/util/thread-stack.c
index c485186a8b6d..4c826a2e08d8 100644
--- a/tools/perf/util/thread-stack.c
+++ b/tools/perf/util/thread-stack.c
@@ -628,6 +628,23 @@ static int thread_stack__bottom(struct thread_stack *ts,
 true, false);
 }
 
+static int thread_stack__pop_ks(struct thread *thread, struct thread_stack *ts,
+   struct perf_sample *sample, u64 ref)
+{
+   u64 tm = sample->time;
+   int err;
+
+   /* Return to userspace, so pop all kernel addresses */
+   while (thread_stack__in_kernel(ts)) {
+   err = thread_stack__call_return(thread, ts, --ts->cnt,
+  

Re: WARNING: refcount bug in kobject_add_internal

2019-07-01 Thread Benjamin Herrenschmidt
Munchun, is this what your patch fixes ?


On Mon, 2019-07-01 at 16:27 -0700, syzbot wrote:
> syzbot has bisected this bug to:
> 
> commit 726e41097920a73e4c7c33385dcc0debb1281e18
> Author: Benjamin Herrenschmidt 
> Date:   Tue Jul 10 00:29:10 2018 +
> 
>  drivers: core: Remove glue dirs from sysfs earlier
> 
> bisection log:  
> https://syzkaller.appspot.com/x/bisect.txt?x=140d6739a0
> start commit:   6fbc7275 Linux 5.2-rc7
> git tree:   upstream
> final crash:
> https://syzkaller.appspot.com/x/report.txt?x=160d6739a0
> console output: 
> https://syzkaller.appspot.com/x/log.txt?x=120d6739a0
> kernel config:  
> https://syzkaller.appspot.com/x/.config?x=bff6583efcfaed3f
> dashboard link: 
> https://syzkaller.appspot.com/bug?extid=32259bb9bc1a487ad206
> syz repro:  
> https://syzkaller.appspot.com/x/repro.syz?x=115bad39a0
> C reproducer:   
> https://syzkaller.appspot.com/x/repro.c?x=1241bdd5a0
> 
> Reported-by: syzbot+32259bb9bc1a487ad...@syzkaller.appspotmail.com
> Fixes: 726e41097920 ("drivers: core: Remove glue dirs from sysfs
> earlier")
> 
> For information about bisection process see: 
> https://goo.gl/tpsmEJ#bisection



Re: [PATCH 3.16 08/10] tcp: tcp_fragment() should apply sane memory limits

2019-07-01 Thread Florian Fainelli
Hi Ben,

On 6/18/2019 7:28 AM, Ben Hutchings wrote:
> 3.16.69-rc1 review patch.  If anyone has any objections, please let me know.
> 
> --
> 
> From: Eric Dumazet 
> 
> commit f070ef2ac66716357066b683fb0baf55f8191a2e upstream.
> 
> Jonathan Looney reported that a malicious peer can force a sender
> to fragment its retransmit queue into tiny skbs, inflating memory
> usage and/or overflow 32bit counters.
> 
> TCP allows an application to queue up to sk_sndbuf bytes,
> so we need to give some allowance for non malicious splitting
> of retransmit queue.
> 
> A new SNMP counter is added to monitor how many times TCP
> did not allow to split an skb if the allowance was exceeded.
> 
> Note that this counter might increase in the case applications
> use SO_SNDBUF socket option to lower sk_sndbuf.
> 
> CVE-2019-11478 : tcp_fragment, prevent fragmenting a packet when the
>   socket is already using more than half the allowed space
> 
> Signed-off-by: Eric Dumazet 
> Reported-by: Jonathan Looney 
> Acked-by: Neal Cardwell 
> Acked-by: Yuchung Cheng 
> Reviewed-by: Tyler Hicks 
> Cc: Bruce Curtis 
> Cc: Jonathan Lemon 
> Signed-off-by: David S. Miller 
> [Salvatore Bonaccorso: Adjust context for backport to 4.9.168]
> [bwh: Backported to 3.16: adjust context]
> Signed-off-by: Ben Hutchings 

Don't we also need this patch to be backported:

https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=b6653b3629e5b88202be3c9abc44713973f5c4b4

Thanks!
-- 
Florian


Re: WARNING: refcount bug in kobject_add_internal

2019-07-01 Thread Muchun Song
Hi Ben,

Benjamin Herrenschmidt  于2019年7月2日周二 上午10:44写道:
>
> Munchun, is this what your patch fixes ?
>
 Yes, this is what my patch fixes.

The patchs can reference to:
[PATCH v1 OPT1] driver core: Fix use-after-free and double
free on glue directory
[PATCH v4 OPT2] driver core: Fix use-after-free and double
free on glue directory

And waiting for Greg chose which solution he prefered.

Yours,
Muchun


linux-next: manual merge of the mlx5-next tree with Linus' tree

2019-07-01 Thread Stephen Rothwell
Hi all,

Today's linux-next merge of the mlx5-next tree got conflicts in:

  drivers/net/ethernet/mellanox/mlx5/core/eswitch.c

between commits:

  02f3afd97556 ("net/mlx5: E-Switch, Correct type to u16 for vport_num and int 
for vport_index")

from Linus' tree and commit:

  5f5d2536be8d ("net/mlx5: E-Switch, Use correct flags when configuring vlan")

from the mlx5-next tree.

I fixed it up (see below) and can carry the fix as necessary. This
is now fixed as far as linux-next is concerned, but any non trivial
conflicts should be mentioned to your upstream maintainer when your tree
is submitted for merging.  You may also want to consider cooperating
with the maintainer of the conflicting tree to minimise any particularly
complex conflicts.

-- 
Cheers,
Stephen Rothwell

diff --cc drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
index 67e76979bb42,89f52370e770..
--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
@@@ -1552,7 -1552,8 +1552,8 @@@ static void node_guid_gen_from_mac(u64 
  static void esw_apply_vport_conf(struct mlx5_eswitch *esw,
 struct mlx5_vport *vport)
  {
 -  int vport_num = vport->vport;
 +  u16 vport_num = vport->vport;
+   int flags;
  
if (esw->manager_vport == vport_num)
return;


pgpT6RKqHLN62.pgp
Description: OpenPGP digital signature


linux-next: manual merge of the mlx5-next tree with Linus' tree

2019-07-01 Thread Stephen Rothwell
Hi all,

Today's linux-next merge of the mlx5-next tree got a conflict in:

  drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c

between commit:

  955858009708 ("net/mlx5e: Fix number of vports for ingress ACL configuration")

from Linus' tree and commit:

  062f4bf4aab5 ("net/mlx5: E-Switch, Consolidate eswitch function number of 
VFs")

from the mlx5-next tree.

I fixed it up (I just used the latter version) and can carry the fix as
necessary. This is now fixed as far as linux-next is concerned, but any
non trivial conflicts should be mentioned to your upstream maintainer
when your tree is submitted for merging.  You may also want to consider
cooperating with the maintainer of the conflicting tree to minimise any
particularly complex conflicts.

-- 
Cheers,
Stephen Rothwell


pgpb1NuzKkZlv.pgp
Description: OpenPGP digital signature


Re: [PATCH v10 03/12] dt-binding: gce: add binding for gce client reg property

2019-07-01 Thread Bibby Hsieh
Hi, Rob,

Sorry to bother you, could you please review this patch when you are
available? Thanks.

On Mon, 2019-07-01 at 15:48 +0800, Bibby Hsieh wrote:
> cmdq driver provide a function that get the relationship
> of sub system number from device node for client.
> add specification for #subsys-cells, mediatek,gce-client-reg.
> 
> Signed-off-by: Bibby Hsieh 
> ---
>  .../devicetree/bindings/mailbox/mtk-gce.txt| 18 ++
>  1 file changed, 14 insertions(+), 4 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/mailbox/mtk-gce.txt 
> b/Documentation/devicetree/bindings/mailbox/mtk-gce.txt
> index 1f7f8f2a3f49..d48282d6b02d 100644
> --- a/Documentation/devicetree/bindings/mailbox/mtk-gce.txt
> +++ b/Documentation/devicetree/bindings/mailbox/mtk-gce.txt
> @@ -21,12 +21,21 @@ Required properties:
>   priority: Priority of GCE thread.
>   atomic_exec: GCE processing continuous packets of commands in atomic
>   way.
> +- #subsys-cells: Should be 3.
> + <&phandle subsys_number start_offset size>
> + phandle: Label name of a gce node.
> + subsys_number: specify the sub-system id which is corresponding
> +to the register address.
> + start_offset: the start offset of register address that GCE can access.
> + size: the total size of register address that GCE can access.
>  
>  Required properties for a client device:
>  - mboxes: Client use mailbox to communicate with GCE, it should have this
>property and list of phandle, mailbox specifiers.
> -- mediatek,gce-subsys: u32, specify the sub-system id which is corresponding
> -  to the register address.
> +Optional properties for a client device:
> +- mediatek,gce-client-reg: Specify the sub-system id which is corresponding
> +  to the register address, it should have this property and list of phandle,
> +  sub-system specifiers.
>  
>  Some vaules of properties are defined in 'dt-bindings/gce/mt8173-gce.h'
>  or 'dt-binding/gce/mt8183-gce.h'. Such as sub-system ids, thread priority, 
> event ids.
> @@ -40,6 +49,7 @@ Example:
>   clocks = <&infracfg CLK_INFRA_GCE>;
>   clock-names = "gce";
>   #mbox-cells = <3>;
> + #subsys-cells = <3>;
>   };
>  
>  Example for a client device:
> @@ -48,9 +58,9 @@ Example for a client device:
>   compatible = "mediatek,mt8173-mmsys";
>   mboxes = <&gce 0 CMDQ_THR_PRIO_LOWEST 1>,
><&gce 1 CMDQ_THR_PRIO_LOWEST 1>;
> - mediatek,gce-subsys = ;
>   mutex-event-eof =CMDQ_EVENT_MUTEX1_STREAM_EOF>;
> -
> + mediatek,gce-client-reg = <&gce SUBSYS_1400 0x3000 0x1000>,
> +   <&gce SUBSYS_1401 0x2000 0x100>;
>   ...
>   };

-- 
Bibby



Re: [Question] Should direct reclaim time be bounded?

2019-07-01 Thread Mike Kravetz
On 7/1/19 1:59 AM, Mel Gorman wrote:
> On Fri, Jun 28, 2019 at 11:20:42AM -0700, Mike Kravetz wrote:
>> On 4/24/19 7:35 AM, Vlastimil Babka wrote:
>>> On 4/23/19 6:39 PM, Mike Kravetz wrote:
> That being said, I do not think __GFP_RETRY_MAYFAIL is wrong here. It
> looks like there is something wrong in the reclaim going on.

 Ok, I will start digging into that.  Just wanted to make sure before I got
 into it too deep.

 BTW - This is very easy to reproduce.  Just try to allocate more huge pages
 than will fit into memory.  I see this 'reclaim taking forever' behavior on
 v5.1-rc5-mmotm-2019-04-19-14-53.  Looks like it was there in v5.0 as well.
>>>
>>> I'd suspect this in should_continue_reclaim():
>>>
>>> /* Consider stopping depending on scan and reclaim activity */
>>> if (sc->gfp_mask & __GFP_RETRY_MAYFAIL) {
>>> /*
>>>  * For __GFP_RETRY_MAYFAIL allocations, stop reclaiming if 
>>> the
>>>  * full LRU list has been scanned and we are still failing
>>>  * to reclaim pages. This full LRU scan is potentially
>>>  * expensive but a __GFP_RETRY_MAYFAIL caller really wants 
>>> to succeed
>>>  */
>>> if (!nr_reclaimed && !nr_scanned)
>>> return false;
>>>
>>> And that for some reason, nr_scanned never becomes zero. But it's hard
>>> to figure out through all the layers of functions :/
>>
>> I got back to looking into the direct reclaim/compaction stalls when
>> trying to allocate huge pages.  As previously mentioned, the code is
>> looping for a long time in shrink_node().  The routine
>> should_continue_reclaim() returns true perhaps more often than it should.
>>
>> As Vlastmil guessed, my debug code output below shows nr_scanned is remaining
>> non-zero for quite a while.  This was on v5.2-rc6.
>>
> 
> I think it would be reasonable to have should_continue_reclaim allow an
> exit if scanning at higher priority than DEF_PRIORITY - 2, nr_scanned is
> less than SWAP_CLUSTER_MAX and no pages are being reclaimed.

Thanks Mel,

I added such a check to should_continue_reclaim.  However, it does not
address the issue I am seeing.  In that do-while loop in shrink_node,
the scan priority is not raised (priority--).  We can enter the loop
with priority == DEF_PRIORITY and continue to loop for minutes as seen
in my previous debug output.

-- 
Mike Kravetz


[PATCH 3/3] arm64: dts: add rtc nodes for MT2712

2019-07-01 Thread Ran Bi
This patch add device node for MT2712 rtc.

Signed-off-by: Ran Bi 
---
 arch/arm64/boot/dts/mediatek/mt2712e.dtsi | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/arch/arm64/boot/dts/mediatek/mt2712e.dtsi 
b/arch/arm64/boot/dts/mediatek/mt2712e.dtsi
index 43307bad3f0d..31166c17c39a 100644
--- a/arch/arm64/boot/dts/mediatek/mt2712e.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt2712e.dtsi
@@ -303,6 +303,12 @@
status = "disabled";
};
 
+   rtc: rtc@10011000 {
+   compatible = "mediatek,mt2712-rtc";
+   reg = <0 0x10011000 0 0x1000>;
+   interrupts = ;
+   };
+
spis1: spi@10013000 {
compatible = "mediatek,mt2712-spi-slave";
reg = <0 0x10013000 0 0x100>;
-- 
2.18.0



[PATCH 2/3] rtc: Add support for the MediaTek MT2712 RTC

2019-07-01 Thread Ran Bi
This add support for the MediaTek MT2712 RTC. It was SoC based RTC, but
had different architecture compared with MT7622 RTC.

Signed-off-by: Ran Bi 
---
 drivers/rtc/Kconfig  |  10 +
 drivers/rtc/Makefile |   1 +
 drivers/rtc/rtc-mt2712.c | 495 +++
 3 files changed, 506 insertions(+)
 create mode 100644 drivers/rtc/rtc-mt2712.c

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 7b8e156dbf38..87c601dba673 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1762,6 +1762,16 @@ config RTC_DRV_MOXART
   This driver can also be built as a module. If so, the module
   will be called rtc-moxart
 
+config RTC_DRV_MT2712
+   tristate "MediaTek MT2712 SoC based RTC"
+   depends on ARCH_MEDIATEK || COMPILE_TEST
+   help
+ This enables support for the real time clock built in the MediaTek
+ SoCs for MT2712.
+
+ This drive can also be built as a module. If so, the module
+ will be called rtc-mt2712.
+
 config RTC_DRV_MT6397
tristate "MediaTek PMIC based RTC"
depends on MFD_MT6397 || (COMPILE_TEST && IRQ_DOMAIN)
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 9d997faa2c26..1ef202af9033 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -107,6 +107,7 @@ obj-$(CONFIG_RTC_DRV_MESON) += rtc-meson.o
 obj-$(CONFIG_RTC_DRV_MOXART)   += rtc-moxart.o
 obj-$(CONFIG_RTC_DRV_MPC5121)  += rtc-mpc5121.o
 obj-$(CONFIG_RTC_DRV_MSM6242)  += rtc-msm6242.o
+obj-$(CONFIG_RTC_DRV_MT2712)   += rtc-mt2712.o
 obj-$(CONFIG_RTC_DRV_MT6397)   += rtc-mt6397.o
 obj-$(CONFIG_RTC_DRV_MT7622)   += rtc-mt7622.o
 obj-$(CONFIG_RTC_DRV_MV)   += rtc-mv.o
diff --git a/drivers/rtc/rtc-mt2712.c b/drivers/rtc/rtc-mt2712.c
new file mode 100644
index ..f98f0ab114c5
--- /dev/null
+++ b/drivers/rtc/rtc-mt2712.c
@@ -0,0 +1,495 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2019 MediaTek Inc.
+ * Author: Ran Bi 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define MTK_RTC_DEVKBUILD_MODNAME
+
+#define RTC_BBPU   0x
+#define RTC_BBPU_CLRPKY(1U << 4)
+#define RTC_BBPU_RELOAD(1U << 5)
+#define RTC_BBPU_CBUSY (1U << 6)
+#define RTC_BBPU_KEY   (0x43 << 8)
+
+#define RTC_IRQ_STA0x0004
+#define RTC_IRQ_STA_AL (1U << 0)
+#define RTC_IRQ_STA_TC (1U << 1)
+
+#define RTC_IRQ_EN 0x0008
+#define RTC_IRQ_EN_AL  (1U << 0)
+#define RTC_IRQ_EN_TC  (1U << 1)
+#define RTC_IRQ_EN_ONESHOT (1U << 2)
+#define RTC_IRQ_EN_ONESHOT_AL  (RTC_IRQ_EN_ONESHOT | RTC_IRQ_EN_AL)
+
+#define RTC_CII_EN 0x000c
+
+#define RTC_AL_MASK0x0010
+#define RTC_AL_MASK_DOW(1U << 4)
+
+#define RTC_TC_SEC 0x0014
+#define RTC_TC_MIN 0x0018
+#define RTC_TC_HOU 0x001c
+#define RTC_TC_DOM 0x0020
+#define RTC_TC_DOW 0x0024
+#define RTC_TC_MTH 0x0028
+#define RTC_TC_YEA 0x002c
+
+#define RTC_AL_SEC 0x0030
+#define RTC_AL_MIN 0x0034
+#define RTC_AL_HOU 0x0038
+#define RTC_AL_DOM 0x003c
+#define RTC_AL_DOW 0x0040
+#define RTC_AL_MTH 0x0044
+#define RTC_AL_YEA 0x0048
+
+#define RTC_SEC_MASK   0x003f
+#define RTC_MIN_MASK   0x003f
+#define RTC_HOU_MASK   0x001f
+#define RTC_DOM_MASK   0x001f
+#define RTC_DOW_MASK   0x0007
+#define RTC_MTH_MASK   0x000f
+#define RTC_YEA_MASK   0x007f
+
+#define RTC_POWERKEY1  0x004c
+#define RTC_POWERKEY2  0x0050
+#define RTC_POWERKEY1_KEY  0xa357
+#define RTC_POWERKEY2_KEY  0x67d2
+
+#define RTC_CON0   0x005c
+#define RTC_CON1   0x0060
+
+#define RTC_PROT   0x0070
+#define RTC_PROT_UNLOCK1   0x9136
+#define RTC_PROT_UNLOCK2   0x586a
+
+#define RTC_WRTGR  0x0078
+
+/* we map HW YEAR 0 to 1968 not 1970 because 2000 is the leap year */
+#define RTC_MIN_YEAR   1968
+#define RTC_BASE_YEAR  1900
+#define RTC_MIN_YEAR_OFFSET(RTC_MIN_YEAR - RTC_BASE_YEAR)
+
+#define RTC_DEFAULT_YEA2010
+#define RTC_DEFAULT_MTH1
+#define RTC_DEFAULT_DOM1
+
+struct mt2712_rtc {
+   struct device   *dev;
+   struct rtc_device   *rtc_dev;
+   void __iomem*base;
+   struct mutexlock;
+   int irq;
+   u8  irq_wake_enabled;
+};
+
+static inline u32 rtc_readl(struct mt2712_rtc *rtc, u32 reg)
+{
+   return readl(rtc->base + reg);
+}
+
+static inline void rtc_writel(struct mt2712_rtc *rtc, u32 reg, u32 val)
+{
+   writel(val, rtc->base + reg);
+}
+
+static void rtc_write_trigger(struct mt2712_rtc *rtc)
+{
+   unsigned l

[PATCH 0/3] Add Support for MediaTek MT2712 RTC

2019-07-01 Thread Ran Bi
This patchset add support to MT2712 RTC. MT2712 RTC is a SoC based RTC
with different architecture compared to MT7622 RTC.

Ran Bi (3):
  bindings: rtc: add bindings for MT2712 RTC
  rtc: Add support for the MediaTek MT2712 RTC
  arm64: dts: add rtc nodes for MT2712

 .../devicetree/bindings/rtc/rtc-mt2712.txt|  14 +
 arch/arm64/boot/dts/mediatek/mt2712e.dtsi |   6 +
 drivers/rtc/Kconfig   |  10 +
 drivers/rtc/Makefile  |   1 +
 drivers/rtc/rtc-mt2712.c  | 495 ++
 5 files changed, 526 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/rtc/rtc-mt2712.txt
 create mode 100644 drivers/rtc/rtc-mt2712.c

-- 
2.18.0



[PATCH 1/3] bindings: rtc: add bindings for MT2712 RTC

2019-07-01 Thread Ran Bi
Document the binding for MT2712 RTC implemented by rtc-mt2712.

Signed-off-by: Ran Bi 
---
 .../devicetree/bindings/rtc/rtc-mt2712.txt | 14 ++
 1 file changed, 14 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/rtc/rtc-mt2712.txt

diff --git a/Documentation/devicetree/bindings/rtc/rtc-mt2712.txt 
b/Documentation/devicetree/bindings/rtc/rtc-mt2712.txt
new file mode 100644
index ..c33d87e5e753
--- /dev/null
+++ b/Documentation/devicetree/bindings/rtc/rtc-mt2712.txt
@@ -0,0 +1,14 @@
+Device-Tree bindings for MediaTek SoC based RTC
+
+Required properties:
+- compatible   : Should be "mediatek,mt2712-rtc" : for MT2712 SoC
+- reg  : Specifies base physical address and size of the registers;
+- interrupts   : Should contain the interrupt for RTC alarm;
+
+Example:
+
+rtc: rtc@10011000 {
+   compatible = "mediatek,mt2712-rtc";
+   reg = <0 0x10011000 0 0x1000>;
+   interrupts = ;
+};
-- 
2.18.0



Re: [PATCH v3 2/4] of/platform: Add functional dependency link from DT bindings

2019-07-01 Thread Saravana Kannan
On Mon, Jul 1, 2019 at 6:32 PM Rob Herring  wrote:
>
> On Mon, Jul 1, 2019 at 6:48 PM Saravana Kannan  wrote:
> >
> > Add device-links after the devices are created (but before they are
> > probed) by looking at common DT bindings like clocks and
> > interconnects.
> >
> > Automatically adding device-links for functional dependencies at the
> > framework level provides the following benefits:
> >
> > - Optimizes device probe order and avoids the useless work of
> >   attempting probes of devices that will not probe successfully
> >   (because their suppliers aren't present or haven't probed yet).
> >
> >   For example, in a commonly available mobile SoC, registering just
> >   one consumer device's driver at an initcall level earlier than the
> >   supplier device's driver causes 11 failed probe attempts before the
> >   consumer device probes successfully. This was with a kernel with all
> >   the drivers statically compiled in. This problem gets a lot worse if
> >   all the drivers are loaded as modules without direct symbol
> >   dependencies.
> >
> > - Supplier devices like clock providers, interconnect providers, etc
> >   need to keep the resources they provide active and at a particular
> >   state(s) during boot up even if their current set of consumers don't
> >   request the resource to be active. This is because the rest of the
> >   consumers might not have probed yet and turning off the resource
> >   before all the consumers have probed could lead to a hang or
> >   undesired user experience.
> >
> >   Some frameworks (Eg: regulator) handle this today by turning off
> >   "unused" resources at late_initcall_sync and hoping all the devices
> >   have probed by then. This is not a valid assumption for systems with
> >   loadable modules. Other frameworks (Eg: clock) just don't handle
> >   this due to the lack of a clear signal for when they can turn off
> >   resources. This leads to downstream hacks to handle cases like this
> >   that can easily be solved in the upstream kernel.
> >
> >   By linking devices before they are probed, we give suppliers a clear
> >   count of the number of dependent consumers. Once all of the
> >   consumers are active, the suppliers can turn off the unused
> >   resources without making assumptions about the number of consumers.
> >
> > By default we just add device-links to track "driver presence" (probe
> > succeeded) of the supplier device. If any other functionality provided
> > by device-links are needed, it is left to the consumer/supplier
> > devices to change the link when they probe.
> >
> > Signed-off-by: Saravana Kannan 
> > ---
> >  drivers/of/Kconfig|  9 
> >  drivers/of/platform.c | 52 +++
> >  2 files changed, 61 insertions(+)
> >
> > diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
> > index 37c2ccbefecd..7c7fa7394b4c 100644
> > --- a/drivers/of/Kconfig
> > +++ b/drivers/of/Kconfig
> > @@ -103,4 +103,13 @@ config OF_OVERLAY
> >  config OF_NUMA
> > bool
> >
> > +config OF_DEVLINKS
>
> I'd prefer this not be a config option. After all, we want one kernel
> build that works for all platforms.

We need a lot more changes before one kernel build can work for all
platforms. At least until then, I think we need this. Lot less chance
of breaking existing platforms before all the missing pieces are
created.

> A kernel command line option to disable might be useful for debugging.

Or we can have a command line to enable this for platforms that want
to use it and have it default off.

> > +   bool "Device links from DT bindings"
> > +   help
> > + Common DT bindings like clocks, interconnects, etc represent a
> > + consumer device's dependency on suppliers devices. This option
> > + creates device links from these common bindings so that consumers 
> > are
> > + probed only after all their suppliers are active and suppliers can
> > + tell when all their consumers are active.
> > +
> >  endif # OF
> > diff --git a/drivers/of/platform.c b/drivers/of/platform.c
> > index 04ad312fd85b..a53717168aca 100644
> > --- a/drivers/of/platform.c
> > +++ b/drivers/of/platform.c
> > @@ -61,6 +61,57 @@ struct platform_device *of_find_device_by_node(struct 
> > device_node *np)
> >  EXPORT_SYMBOL(of_find_device_by_node);
> >
> >  #ifdef CONFIG_OF_ADDRESS
> > +static int of_link_binding(struct device *dev, char *binding, char *cell)
>
> Under CONFIG_OF_ADDRESS seems like a strange location.

Yeah, but the rest of the file seems to be under this. So I'm not
touching that. I can probably move this function further down (close
to platform populate) if you want that.
>
> > +{
> > +   struct of_phandle_args sup_args;
> > +   struct platform_device *sup_dev;
> > +   unsigned int i = 0, links = 0;
> > +   u32 dl_flags = DL_FLAG_AUTOPROBE_CONSUMER;
> > +
> > +   while (!of_parse_phandle_with_args(dev->of_node, binding, cell, i,
> > +   

Re: [PATCH] filesystem-dax: Disable PMD support

2019-07-01 Thread Matthew Wilcox
On Sun, Jun 30, 2019 at 02:37:32PM -0700, Dan Williams wrote:
> On Sun, Jun 30, 2019 at 8:23 AM Matthew Wilcox  wrote:
> > I think my theory was slightly mistaken, but your fix has the effect of
> > fixing the actual problem too.
> >
> > The xas->xa_index for a PMD is going to be PMD-aligned (ie a multiple of
> > 512), but xas_find_conflict() does _not_ adjust xa_index (... which I
> > really should have mentioned in the documentation).  So we go to sleep
> > on the PMD-aligned index instead of the index of the PTE.  Your patch
> > fixes this by using the PMD-aligned index for PTEs too.
> >
> > I'm trying to come up with a clean fix for this.  Clearly we
> > shouldn't wait for a PTE entry if we're looking for a PMD entry.
> > But what should get_unlocked_entry() return if it detects that case?
> > We could have it return an error code encoded as an internal entry,
> > like grab_mapping_entry() does.  Or we could have it return the _locked_
> > PTE entry, and have callers interpret that.
> >
> > At least get_unlocked_entry() is static, but it's got quite a few callers.
> > Trying to discern which ones might ask for a PMD entry is a bit tricky.
> > So this seems like a large patch which might have bugs.
> >
> > Thoughts?
> 
> ...but if it was a problem of just mismatched waitqueue's I would have
> expected it to trigger prior to commit b15cd800682f "dax: Convert page
> fault handlers to XArray".

That commit converts grab_mapping_entry() (called by dax_iomap_pmd_fault())
from calling get_unlocked_mapping_entry() to calling get_unlocked_entry().
get_unlocked_mapping_entry() (eventually) called __radix_tree_lookup()
instead of dax_find_conflict().

> This hunk, if I'm reading it correctly,
> looks suspicious: @index in this case is coming directly from
> vm->pgoff without pmd alignment adjustment whereas after the
> conversion it's always pmd aligned from the xas->xa_index. So perhaps
> the issue is that the lock happens at pte granularity. I expect it
> would cause the old put_locked_mapping_entry() to WARN, but maybe that
> avoids the lockup and was missed in the bisect.

I don't think that hunk is the problem.  The __radix_tree_lookup()
is going to return a 'slot' which points to the canonical slot, no
matter which of the 512 indices corresponding to that slot is chosen.
So I think it's going to do essentially the same thing.

> @@ -884,21 +711,18 @@ static void *dax_insert_entry(struct
> address_space *mapping,
>  * existing entry is a PMD, we will just leave the PMD in the
>  * tree and dirty it if necessary.
>  */
> -   struct radix_tree_node *node;
> -   void **slot;
> -   void *ret;
> -
> -   ret = __radix_tree_lookup(pages, index, &node, &slot);
> -   WARN_ON_ONCE(ret != entry);
> -   __radix_tree_replace(pages, node, slot,
> -new_entry, NULL);
> +   void *old = dax_lock_entry(xas, new_entry);
> +   WARN_ON_ONCE(old != xa_mk_value(xa_to_value(entry) |
> +   DAX_LOCKED));
> entry = new_entry;
> +   } else {
> +   xas_load(xas);  /* Walk the xa_state */
> }
> 
> if (dirty)
> -   radix_tree_tag_set(pages, index, PAGECACHE_TAG_DIRTY);
> +   xas_set_mark(xas, PAGECACHE_TAG_DIRTY);
> 
> -   xa_unlock_irq(pages);
> +   xas_unlock_irq(xas);
> return entry;
>  }


[PATCH 1/2] serial/8250: Add support for NI-Serial PXI/PXIe+485 devices.

2019-07-01 Thread jeyentam
Add support for NI-Serial PXIe-RS232, PXI-RS485 and PXIe-RS485 devices.

Signed-off-by: jeyentam 
---
 drivers/tty/serial/8250/8250_pci.c | 879 +++--
 1 file changed, 582 insertions(+), 297 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_pci.c 
b/drivers/tty/serial/8250/8250_pci.c
index df41397de478..0a711b895b33 100644
--- a/drivers/tty/serial/8250/8250_pci.c
+++ b/drivers/tty/serial/8250/8250_pci.c
@@ -1,10 +1,10 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- *  Probe module for 8250/16550-type PCI serial ports.
+ * Probe module for 8250/16550-type PCI serial ports.
  *
- *  Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o.
+ * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o.
  *
- *  Copyright (C) 2001 Russell King, All Rights Reserved.
+ * Copyright (C) 2001 Russell King, All Rights Reserved.
  */
 #undef DEBUG
 #include 
@@ -26,9 +26,9 @@
 
 /*
  * init function returns:
- *  > 0 - number of ports
- *  = 0 - use board->num_ports
- *  < 0 - error
+ * > 0 - number of ports
+ * = 0 - use board->num_ports
+ * < 0 - error
  */
 struct pci_serial_quirk {
u32 vendor;
@@ -59,13 +59,13 @@ static int pci_default_setup(struct serial_private*,
 static void moan_device(const char *str, struct pci_dev *dev)
 {
dev_err(&dev->dev,
-  "%s: %s\n"
-  "Please send the output of lspci -vv, this\n"
-  "message (0x%04x,0x%04x,0x%04x,0x%04x), the\n"
-  "manufacturer and name of serial board or\n"
-  "modem board to .\n",
-  pci_name(dev), str, dev->vendor, dev->device,
-  dev->subsystem_vendor, dev->subsystem_device);
+  "%s: %s\n"
+  "Please send the output of lspci -vv, this\n"
+  "message (0x%04x,0x%04x,0x%04x,0x%04x), the\n"
+  "manufacturer and name of serial board or\n"
+  "modem board to .\n",
+  pci_name(dev), str, dev->vendor, dev->device,
+  dev->subsystem_vendor, dev->subsystem_device);
 }
 
 static int
@@ -128,7 +128,7 @@ static int addidata_apci7800_setup(struct serial_private 
*priv,
  */
 static int
 afavlab_setup(struct serial_private *priv, const struct pciserial_board *board,
- struct uart_8250_port *port, int idx)
+ struct uart_8250_port *port, int idx)
 {
unsigned int bar, offset = board->first_offset;
 
@@ -144,9 +144,9 @@ afavlab_setup(struct serial_private *priv, const struct 
pciserial_board *board,
 }
 
 /*
- * HP's Remote Management Console.  The Diva chip came in several
- * different versions.  N-class, L2000 and A500 have two Diva chips, each
- * with 3 UARTs (the third UART on the second chip is unused).  Superdome
+ * HP's Remote Management Console. The Diva chip came in several
+ * different versions. N-class, L2000 and A500 have two Diva chips, each
+ * with 3 UARTs (the third UART on the second chip is unused). Superdome
  * and Keystone have one Diva chip with 3 UARTs.  Some later machines have
  * one Diva chip, but it has been expanded to 5 UARTs.
  */
@@ -245,11 +245,11 @@ static int pci_plx9050_init(struct pci_dev *dev)
 
irq_config = 0x41;
if (dev->vendor == PCI_VENDOR_ID_PANACOM ||
-   dev->subsystem_vendor == PCI_SUBVENDOR_ID_EXSYS)
+   dev->subsystem_vendor == PCI_SUBVENDOR_ID_EXSYS)
irq_config = 0x43;
 
if ((dev->vendor == PCI_VENDOR_ID_PLX) &&
-   (dev->device == PCI_DEVICE_ID_PLX_ROMULUS))
+   (dev->device == PCI_DEVICE_ID_PLX_ROMULUS))
/*
 * As the megawolf cards have the int pins active
 * high, and have 2 UART chips, both ints must be
@@ -317,7 +317,7 @@ static void pci_ni8420_exit(struct pci_dev *dev)
 
/* Disable the CPU Interrupt */
writel(readl(p + NI8420_INT_ENABLE_REG) & ~(NI8420_INT_ENABLE_BIT),
-  p + NI8420_INT_ENABLE_REG);
+  p + NI8420_INT_ENABLE_REG);
iounmap(p);
 }
 
@@ -426,15 +426,15 @@ static void sbs_exit(struct pci_dev *dev)
  * hope) because it doesn't touch EEPROM settings to prevent conflicts
  * with other OSes (like M$ DOS).
  *
- *  SIIG support added by Andrey Panin , 10/1999
+ * SIIG support added by Andrey Panin , 10/1999
  *
  * There is two family of SIIG serial cards with different PCI
  * interface chip and different configuration methods:
- * - 10x cards have control registers in IO and/or memory space;
- * - 20x cards have control registers in standard PCI configuration space.
+ *- 10x cards have control registers in IO and/or memory space;
+ *- 20x cards have control registers in standard PCI configuration 
space.
  *
  * Note: all 10x cards have PCI device ids 0x10..
- *   all 20x cards have PCI device ids 0x20..
+ *  all 20x cards have PCI device ids 0x20..
  *
  * There are also Quar

Re: [RFC 1/2] arm64/mm: Change THP helpers to comply with generic MM semantics

2019-07-01 Thread Anshuman Khandual


On 06/28/2019 03:50 PM, Catalin Marinas wrote:
> Hi Anshuman,

Hello Catalin,

> 
> On Thu, Jun 27, 2019 at 06:18:15PM +0530, Anshuman Khandual wrote:
>> pmd_present() and pmd_trans_huge() are expected to behave in the following
>> manner during various phases of a given PMD. It is derived from a previous
>> detailed discussion on this topic [1] and present THP documentation [2].
>>
>> pmd_present(pmd):
>>
>> - Returns true if pmd refers to system RAM with a valid pmd_page(pmd)
>> - Returns false if pmd does not refer to system RAM - Invalid pmd_page(pmd)
>>
>> pmd_trans_huge(pmd):
>>
>> - Returns true if pmd refers to system RAM and is a trans huge mapping
>>
>> -
>> |PMD states  |   pmd_present |   pmd_trans_huge  |
>> -
>> |Mapped  |   Yes |   Yes |
>> -
>> |Splitting   |   Yes |   Yes |
>> -
>> |Migration/Swap  |   No  |   No  |
>> -
> 
> Before we actually start fixing this, I would strongly suggest that you
> add a boot selftest (see lib/Kconfig.debug for other similar cases)
> which checks the consistency of the page table macros w.r.t. the
> expected mm semantics. Once the mm maintainers agreed with the
> semantics, it will really help architecture maintainers in implementing
> them correctly.

Sure and it will help all architectures to be in sync wrt semantics.

> 
> You wouldn't need actual page tables, just things like assertions on
> pmd_trans_huge(pmd_mkhuge(pmd)) == true. You could go further and have
> checks on pmdp_invalidate(&dummy_vma, dummy_addr, &dummy_pmd) with the
> dummy_* variables on the stack.

Hmm. I guess macros which operate directly on a page table entry will be
okay but the ones which check on specific states for VMA or MM might be
bit tricky. Try to emulate VMA/MM states while on stack ?. But sure, will
explore adding such a test.

> 
>> The problem:
>>
>> PMD is first invalidated with pmdp_invalidate() before it's splitting. This
>> invalidation clears PMD_SECT_VALID as below.
>>
>> PMD Split -> pmdp_invalidate() -> pmd_mknotpresent -> Clears PMD_SECT_VALID
>>
>> Once PMD_SECT_VALID gets cleared, it results in pmd_present() return false
>> on the PMD entry.
> 
> I think that's an inconsistency in the expected semantics here. Do you
> mean that pmd_present(pmd_mknotpresent(pmd)) should be true? If not, do

Actually that is true (more so if we are using generic pmdp_invalidate). Else
in general pmd_present(pmdp_invalidate(pmd)) needs to be true to successfully
represent a splitting THP. That is what Andrea explained back on this thread
(https://lkml.org/lkml/2018/10/17/231).

Extracting relevant sections from that thread -

"pmd_present never meant the real present bit in the pte was set, it just means
the pmd points to RAM. It means it doesn't point to swap or migration entry and
you can do pmd_to_page and it works fine."

"The clear of the real present bit during pmd (virtual) splitting is done with
pmdp_invalidate, that is created specifically to keeps pmd_trans_huge=true,
pmd_present=true despite the present bit is not set. So you could imagine
_PAGE_PSE as the real present bit."

pmd_present() and pmd_mknotpresent() are not exact inverse.

Problem is all platforms using generic pmdp_invalidate() calls 
pmd_mknotpresent()
which invariably across platforms remove the valid or present bit from the 
entry.
The point to note here is that pmd_mknotpresent() invalidates the entry from MMU
point of view but pmd_present() does not check for a MMU valid PMD entry. Hence
pmd_present(pmd_mknotpresent(pmd)) can still be true.

In absence of a positive section mapping bit on arm64, PTE_SPECIAL is being set
temporarily to remember that it was a mapped PMD which got invalidated recently
but which still points to memory. Hence pmd_present() must evaluate true.

pmd_mknotpresent() does not make !pmd_present() it just invalidates the entry.

> we need to implement our own pmdp_invalidate() or change the generic one
> to set a "special" bit instead of just a pmd_mknotpresent?

Though arm64 can subscribe __HAVE_ARCH_PMDP_INVALIDATE and implement it's own
pmdp_invalidate() in order to not call pmd_mknotpresent() and instead operate
on the invalid and special bits directly. But its not going to alter relevant
semantics here. AFAICS it might be bit better as it saves pmd_mknotpresent()
from putting in that special bit in there which it is not supposed do.

IFAICS there is no compelling reason for generic pmdp_invalidate() to change
either. It calls pmd_mknotpresent() which invalidates the entry throug

[PATCH 2/2] PCI: Add NI-Serial PXI/PXIe+485 device IDs

2019-07-01 Thread jeyentam
Add NI PXIe-RS232, PXI-RS485 and PXIe-RS485 device IDs.

Signed-off-by: jeyentam 
---
 include/linux/pci_ids.h | 62 -
 1 file changed, 37 insertions(+), 25 deletions(-)

diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h
index 70e86148cb1e..cc1f61575eb4 100644
--- a/include/linux/pci_ids.h
+++ b/include/linux/pci_ids.h
@@ -1027,31 +1027,43 @@
 #define PCI_DEVICE_ID_SUN_TOMATILLO0xa801
 #define PCI_DEVICE_ID_SUN_CASSINI  0xabba
 
-#define PCI_VENDOR_ID_NI   0x1093
-#define PCI_DEVICE_ID_NI_PCI2322   0xd130
-#define PCI_DEVICE_ID_NI_PCI2324   0xd140
-#define PCI_DEVICE_ID_NI_PCI2328   0xd150
-#define PCI_DEVICE_ID_NI_PXI8422_2322  0xd190
-#define PCI_DEVICE_ID_NI_PXI8422_2324  0xd1a0
-#define PCI_DEVICE_ID_NI_PXI8420_2322  0xd1d0
-#define PCI_DEVICE_ID_NI_PXI8420_2324  0xd1e0
-#define PCI_DEVICE_ID_NI_PXI8420_2328  0xd1f0
-#define PCI_DEVICE_ID_NI_PXI8420_23216 0xd1f1
-#define PCI_DEVICE_ID_NI_PCI2322I  0xd250
-#define PCI_DEVICE_ID_NI_PCI2324I  0xd270
-#define PCI_DEVICE_ID_NI_PCI23216  0xd2b0
-#define PCI_DEVICE_ID_NI_PXI8430_2322  0x7080
-#define PCI_DEVICE_ID_NI_PCI8430_2322  0x70db
-#define PCI_DEVICE_ID_NI_PXI8430_2324  0x70dd
-#define PCI_DEVICE_ID_NI_PCI8430_2324  0x70df
-#define PCI_DEVICE_ID_NI_PXI8430_2328  0x70e2
-#define PCI_DEVICE_ID_NI_PCI8430_2328  0x70e4
-#define PCI_DEVICE_ID_NI_PXI8430_23216 0x70e6
-#define PCI_DEVICE_ID_NI_PCI8430_23216 0x70e7
-#define PCI_DEVICE_ID_NI_PXI8432_2322  0x70e8
-#define PCI_DEVICE_ID_NI_PCI8432_2322  0x70ea
-#define PCI_DEVICE_ID_NI_PXI8432_2324  0x70ec
-#define PCI_DEVICE_ID_NI_PCI8432_2324  0x70ee
+/* NI-Serial Device IDs */
+#define PCI_VENDOR_ID_NI 0x1093
+/* NI PXI(e) RS-232 Devices */
+#define PCI_DEVICE_ID_NI_PCI2322 0xd130
+#define PCI_DEVICE_ID_NI_PCI2324 0xd140
+#define PCI_DEVICE_ID_NI_PCI2328 0xd150
+#define PCI_DEVICE_ID_NI_PXI8422_23220xd190
+#define PCI_DEVICE_ID_NI_PXI8422_23240xd1a0
+#define PCI_DEVICE_ID_NI_PXI8420_23220xd1d0
+#define PCI_DEVICE_ID_NI_PXI8420_23240xd1e0
+#define PCI_DEVICE_ID_NI_PXI8420_23280xd1f0
+#define PCI_DEVICE_ID_NI_PXI8420_23216   0xd1f1
+#define PCI_DEVICE_ID_NI_PCI2322I0xd250
+#define PCI_DEVICE_ID_NI_PCI2324I0xd270
+#define PCI_DEVICE_ID_NI_PCI232160xd2b0
+#define PCI_DEVICE_ID_NI_PXI8430_23220x7080
+#define PCI_DEVICE_ID_NI_PCI8430_23220x70db
+#define PCI_DEVICE_ID_NI_PXI8430_23240x70dd
+#define PCI_DEVICE_ID_NI_PCI8430_23240x70df
+#define PCI_DEVICE_ID_NI_PXI8430_23280x70e2
+#define PCI_DEVICE_ID_NI_PCI8430_23280x70e4
+#define PCI_DEVICE_ID_NI_PXI8430_23216   0x70e6
+#define PCI_DEVICE_ID_NI_PCI8430_23216   0x70e7
+#define PCI_DEVICE_ID_NI_PXI8432_23220x70e8
+#define PCI_DEVICE_ID_NI_PCI8432_23220x70ea
+#define PCI_DEVICE_ID_NI_PXI8432_23240x70ec
+#define PCI_DEVICE_ID_NI_PCI8432_23240x70ee
+#define PCIE_DEVICE_ID_NI_PXIE8430_2328   0x74C2
+#define PCIE_DEVICE_ID_NI_PXIE8430_23216  0x74C1
+/* NI PXI(e) RS-485 Devices */
+#define PCI_DEVICE_ID_NI_PXI8431_4852 0x7081
+#define PCI_DEVICE_ID_NI_PXI8431_4854 0x70DE
+#define PCI_DEVICE_ID_NI_PXI8431_4858 0x70E3
+#define PCI_DEVICE_ID_NI_PXI8433_4852 0x70E9
+#define PCI_DEVICE_ID_NI_PXI8433_4854 0x70ED
+#define PCIE_DEVICE_ID_NI_PXIE8431_4858   0x74C4
+#define PCIE_DEVICE_ID_NI_PXIE8431_48516  0x74C3
 
 #define PCI_VENDOR_ID_CMD  0x1095
 #define PCI_DEVICE_ID_CMD_643  0x0643
-- 
2.17.1



Re: [PATCH v3 4/4] driver core: Add edit_links() callback for drivers

2019-07-01 Thread Saravana Kannan
On Mon, Jul 1, 2019 at 6:46 PM Rob Herring  wrote:
>
> On Mon, Jul 1, 2019 at 6:48 PM Saravana Kannan  wrote:
> >
> > The driver core/bus adding dependencies by default makes sure that
> > suppliers don't sync the hardware state with software state before all the
> > consumers have their drivers loaded (if they are modules) and are probed.
> >
> > However, when the bus incorrectly adds dependencies that it shouldn't have
> > added, the devices might never probe.
> >
> > For example, if device-C is a consumer of device-S and they have phandles
> > to each other in DT, the following could happen:
> >
> > 1.  Device-S get added first.
> > 2.  The bus add_links() callback will (incorrectly) try to link it as
> > a consumer of device-C.
> > 3.  Since device-C isn't present, device-S will be put in
> > "waiting-for-supplier" list.
> > 4.  Device-C gets added next.
> > 5.  All devices in "waiting-for-supplier" list are retried for linking.
> > 6.  Device-S gets linked as consumer to Device-C.
> > 7.  The bus add_links() callback will (correctly) try to link it as
> > a consumer of device-S.
> > 8.  This isn't allowed because it would create a cyclic device links.
> >
> > So neither devices will get probed since the supplier is dependent on a
> > consumer that'll never probe (because it can't get resources from the
> > supplier).
> >
> > Without this patch, things stay in this broken state. However, with this
> > patch, the execution will continue like this:
> >
> > 9.  Device-C's driver is loaded.
> > 10. Device-C's driver removes Device-S as a consumer of Device-C.
> > 11. Device-C's driver adds Device-C as a consumer of Device-S.
> > 12. Device-S probes.
> > 13. Device-S sync_state() isn't called because Device-C hasn't probed yet.
> > 14. Device-C probes.
> > 15. Device-S's sync_state() callback is called.
>
> We already have some DT unittests around platform devices. It would be
> nice to extend them to demonstrate this problem. Could be a follow-up
> patch though.
>
> In the case a driver hasn't been updated, couldn't the driver core
> just remove all the links of C to S and S to C so that progress can be
> made and we retain the status quo of what we have today?

The problem is knowing which of those links to delete and when.

If a link between S and C fails, how do we know and keep track of
which of the other 100 links in the system are causing a cycle? It can
get unwieldy real quick. We could delete all the links to fall back to
status quo, but how do we tell at what point in time we can delete
them all?

> That would
> lessen the chances of breaking platforms and reduce the immediate need
> to fix them.

Which is why I think we need to have a commandline/config option to
turn this series on. Keep in mind that once this patch is merged, the
API for the supplier drivers would be the same whether the feature is
enabled or not. They just fallback to status quo behavior (do their
stuff in late_initcall_sync() like they do today).

This patch series has a huge impact on the behavior and I don't think
there's a sound reason to force it on everyone right away. This is
something that needs incremental changes to bring in more and more
platforms/drivers into the new scheme. At a minimum Qualcomm seems
pretty interested in using this to solve their "when do I change/turn
off this clock/interconnect after boot?" question.

-Saravana


[PATCH 1/3] selftests/x86: Test SYSCALL and SYSENTER manually with TF set

2019-07-01 Thread Andy Lutomirski
Make sure that we exercise both variants of the nasty
TF-in-compat-syscall regardless of what vendor's CPU is running the
tests.

Also change the intentional signal after SYSCALL to use ud2, which
is a lot more comprehensible.

This crashes the kernel due to an FSGSBASE bug right now.

This test *also* detects a bug in KVM when run on an Intel host.
KVM people, feel free to use it to help debug.  There's a bunch of
code in this test to warn instead of infinite looping when the bug
gets triggered.

Reported-by: Vegard Nossum 
Cc: "Bae, Chang Seok" 
Cc: Paolo Bonzini 
Cc: k...@vger.kernel.org
Signed-off-by: Andy Lutomirski 
---
 tools/testing/selftests/x86/Makefile  |   5 +-
 .../testing/selftests/x86/syscall_arg_fault.c | 112 +-
 2 files changed, 110 insertions(+), 7 deletions(-)

diff --git a/tools/testing/selftests/x86/Makefile 
b/tools/testing/selftests/x86/Makefile
index 186520198de7..fa07d526fe39 100644
--- a/tools/testing/selftests/x86/Makefile
+++ b/tools/testing/selftests/x86/Makefile
@@ -12,8 +12,9 @@ CAN_BUILD_WITH_NOPIE := $(shell ./check_cc.sh $(CC) 
trivial_program.c -no-pie)
 
 TARGETS_C_BOTHBITS := single_step_syscall sysret_ss_attrs syscall_nt 
test_mremap_vdso \
check_initial_reg_state sigreturn iopl mpx-mini-test 
ioperm \
-   protection_keys test_vdso test_vsyscall mov_ss_trap
-TARGETS_C_32BIT_ONLY := entry_from_vm86 syscall_arg_fault test_syscall_vdso 
unwind_vdso \
+   protection_keys test_vdso test_vsyscall mov_ss_trap \
+   syscall_arg_fault
+TARGETS_C_32BIT_ONLY := entry_from_vm86 test_syscall_vdso unwind_vdso \
test_FCMOV test_FCOMI test_FISTTP \
vdso_restorer
 TARGETS_C_64BIT_ONLY := fsgsbase sysret_rip
diff --git a/tools/testing/selftests/x86/syscall_arg_fault.c 
b/tools/testing/selftests/x86/syscall_arg_fault.c
index 4e25d38c8bbd..bc0ecc2e862e 100644
--- a/tools/testing/selftests/x86/syscall_arg_fault.c
+++ b/tools/testing/selftests/x86/syscall_arg_fault.c
@@ -15,9 +15,30 @@
 #include 
 #include 
 
+#ifdef __x86_64__
+# define WIDTH "q"
+#else
+# define WIDTH "l"
+#endif
+
 /* Our sigaltstack scratch space. */
 static unsigned char altstack_data[SIGSTKSZ];
 
+static unsigned long get_eflags(void)
+{
+   unsigned long eflags;
+   asm volatile ("pushf" WIDTH "\n\tpop" WIDTH " %0" : "=rm" (eflags));
+   return eflags;
+}
+
+static void set_eflags(unsigned long eflags)
+{
+   asm volatile ("push" WIDTH " %0\n\tpopf" WIDTH
+ : : "rm" (eflags) : "flags");
+}
+
+#define X86_EFLAGS_TF (1UL << 8)
+
 static void sethandler(int sig, void (*handler)(int, siginfo_t *, void *),
   int flags)
 {
@@ -35,13 +56,22 @@ static sigjmp_buf jmpbuf;
 
 static volatile sig_atomic_t n_errs;
 
+#ifdef __x86_64__
+#define REG_AX REG_RAX
+#define REG_IP REG_RIP
+#else
+#define REG_AX REG_EAX
+#define REG_IP REG_EIP
+#endif
+
 static void sigsegv_or_sigbus(int sig, siginfo_t *info, void *ctx_void)
 {
ucontext_t *ctx = (ucontext_t*)ctx_void;
+   long ax = (long)ctx->uc_mcontext.gregs[REG_AX];
 
-   if (ctx->uc_mcontext.gregs[REG_EAX] != -EFAULT) {
-   printf("[FAIL]\tAX had the wrong value: 0x%x\n",
-  ctx->uc_mcontext.gregs[REG_EAX]);
+   if (ax != -EFAULT && ax != -ENOSYS) {
+   printf("[FAIL]\tAX had the wrong value: 0x%lx\n",
+  (unsigned long)ax);
n_errs++;
} else {
printf("[OK]\tSeems okay\n");
@@ -50,9 +80,42 @@ static void sigsegv_or_sigbus(int sig, siginfo_t *info, void 
*ctx_void)
siglongjmp(jmpbuf, 1);
 }
 
+static volatile sig_atomic_t sigtrap_consecutive_syscalls;
+
+static void sigtrap(int sig, siginfo_t *info, void *ctx_void)
+{
+   /*
+* KVM has some bugs that can cause us to stop making progress.
+* detect them and complain, but don't infinite loop or fail the
+* test.
+*/
+
+   ucontext_t *ctx = (ucontext_t*)ctx_void;
+   unsigned short *ip = (unsigned short *)ctx->uc_mcontext.gregs[REG_IP];
+
+   if (*ip == 0x340f || *ip == 0x050f) {
+   /* The trap was on SYSCALL or SYSENTER */
+   sigtrap_consecutive_syscalls++;
+   if (sigtrap_consecutive_syscalls > 3) {
+   printf("[WARN]\tGot stuck single-stepping -- you 
probably have a KVM bug\n");
+   siglongjmp(jmpbuf, 1);
+   }
+   } else {
+   sigtrap_consecutive_syscalls = 0;
+   }
+}
+
 static void sigill(int sig, siginfo_t *info, void *ctx_void)
 {
-   printf("[SKIP]\tIllegal instruction\n");
+   ucontext_t *ctx = (ucontext_t*)ctx_void;
+   unsigned short *ip = (unsigned short *)ctx->uc_mcontext.gregs[REG_IP];
+
+   if (*ip == 0x0b0f) {
+   /* one of the ud2 instructions faulted */
+   printf("[OK]\tSYSCALL returne

[PATCH 2/3] x86/entry/64: Don't compile ignore_sysret if 32-bit emulation is enabled

2019-07-01 Thread Andy Lutomirski
It's only used if !CONFIG_IA32_EMULATION, so disable it in normal
configs.  This will save a few bytes of text and reduce confusion.

Cc: "Bae, Chang Seok" 
Signed-off-by: Andy Lutomirski 
---
 arch/x86/entry/entry_64.S | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
index 7f9f5119d6b1..54b1b0468b2b 100644
--- a/arch/x86/entry/entry_64.S
+++ b/arch/x86/entry/entry_64.S
@@ -1743,11 +1743,17 @@ nmi_restore:
iretq
 END(nmi)
 
+#ifndef CONFIG_IA32_EMULATION
+/*
+ * This handles SYSCALL from 32-bit code.  There is no way to program
+ * MSRs to fully disable 32-bit SYSCALL.
+ */
 ENTRY(ignore_sysret)
UNWIND_HINT_EMPTY
mov $-ENOSYS, %eax
sysret
 END(ignore_sysret)
+#endif
 
 ENTRY(rewind_stack_do_exit)
UNWIND_HINT_FUNC
-- 
2.21.0



[PATCH 0/3] FSGSBASE fix, test, and a semi-related cleanup

2019-07-01 Thread Andy Lutomirski
In -tip, if FSGSBASE and PTI are on, the kernel crashes if SYSENTER
happens with TF set.  It also crashes under if a non-NMI paranoid
entry happens for any other reason from kernel mode with user GSBASE
and user CR3, e.g. due to MOV SS shenanigans.

This series fixes the bug.  It also adds another test to make sure
we exercise SYSENTER with TF set regardless of what vendor's CPU
we're on, although the test isn't needed to detect the bug: the
single_step_syscall_32 and mov_ss_trap_* tests also trigger it.  And
it compiles ignore_sysret out on IA32_EMULATION kernels -- I wasted
a couple minutes while debugging this wondering whether I was
accidentally triggering ignore_sysret.

Andy Lutomirski (3):
  selftests/x86: Test SYSCALL and SYSENTER manually with TF set
  x86/entry/64: Don't compile ignore_sysret if 32-bit emulation is
enabled
  x86/entry/64: Fix and clean up paranoid_exit

 arch/x86/entry/entry_64.S |  39 +++---
 tools/testing/selftests/x86/Makefile  |   5 +-
 .../testing/selftests/x86/syscall_arg_fault.c | 112 +-
 3 files changed, 133 insertions(+), 23 deletions(-)

-- 
2.21.0



[PATCH 3/3] x86/entry/64: Fix and clean up paranoid_exit

2019-07-01 Thread Andy Lutomirski
paranoid_exit needs to restore CR3 before GSBASE.  Doing it in the
opposite order crashes if the exception came from a context with
user GSBASE and user CR3 -- RESTORE_CR3 cannot resture user CR3 if
run with user GSBASE.  This results in infinitely recursing
exceptions if user code does SYSENTER with TF set if both FSGSBASE
and PTI are enabled.

The old code worked if user code just set TF without SYSENTER
because #DB from user mode is special cased in idtentry and
paranoid_exit doesn't run.

Fix it by cleaning up the spaghetti code.  All that paranoid_exit
needs to do is to disable IRQs, handle IRQ tracing, then restore
CR3, and restore GSBASE.  Simply do those actions in that order.

Fixes: 708078f65721 ("x86/entry/64: Handle FSGSBASE enabled paranoid 
entry/exit")
Reported-by: Vegard Nossum 
Signed-off-by: Chang S. Bae 
Cc: Thomas Gleixner 
Cc: H. Peter Anvin 
Cc: Andi Kleen 
Cc: Ravi Shankar 
Cc: "Bae, Chang Seok" 
Signed-off-by: Andy Lutomirski 
---
 arch/x86/entry/entry_64.S | 33 +
 1 file changed, 17 insertions(+), 16 deletions(-)

diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
index 54b1b0468b2b..670306f588bf 100644
--- a/arch/x86/entry/entry_64.S
+++ b/arch/x86/entry/entry_64.S
@@ -1256,31 +1256,32 @@ END(paranoid_entry)
 ENTRY(paranoid_exit)
UNWIND_HINT_REGS
DISABLE_INTERRUPTS(CLBR_ANY)
-   TRACE_IRQS_OFF_DEBUG
 
-   /* Handle GS depending on FSGSBASE availability */
-   ALTERNATIVE "jmp .Lparanoid_exit_checkgs", "nop",X86_FEATURE_FSGSBASE
+   /*
+* The order of operations is important.  IRQ tracing requires
+* kernel GSBASE and CR3.  RESTORE_CR3 requires kernel GS base.
+*
+* NB to anyone to tries to optimize this code: this code does
+* not execute at all for exceptions coming from user mode.  Those
+* exceptions go through error_exit instead.
+*/
+   TRACE_IRQS_IRETQ_DEBUG
+   RESTORE_CR3 scratch_reg=%rax save_reg=%r14
+
+   /* Handle the three GSBASE cases. */
+   ALTERNATIVE "jmp .Lparanoid_exit_checkgs", "", X86_FEATURE_FSGSBASE
 
/* With FSGSBASE enabled, unconditionally restore GSBASE */
wrgsbase%rbx
-   jmp .Lparanoid_exit_no_swapgs;
+   jmp restore_regs_and_return_to_kernel
 
 .Lparanoid_exit_checkgs:
/* On non-FSGSBASE systems, conditionally do SWAPGS */
testl   %ebx, %ebx
-   jnz .Lparanoid_exit_no_swapgs
-   TRACE_IRQS_IRETQ
-   /* Always restore stashed CR3 value (see paranoid_entry) */
-   RESTORE_CR3 scratch_reg=%rbx save_reg=%r14
-   SWAPGS_UNSAFE_STACK
-   jmp .Lparanoid_exit_restore
-
-.Lparanoid_exit_no_swapgs:
-   TRACE_IRQS_IRETQ_DEBUG
-   /* Always restore stashed CR3 value (see paranoid_entry) */
-   RESTORE_CR3 scratch_reg=%rbx save_reg=%r14
+   jnz restore_regs_and_return_to_kernel
 
-.Lparanoid_exit_restore:
+   /* We are returning to a context with user GSBASE. */
+   SWAPGS_UNSAFE_STACK
jmp restore_regs_and_return_to_kernel
 END(paranoid_exit)
 
-- 
2.21.0



Re: [RFC 1/3] rcu: Expedite the rcu quiescent state reporting if help needed

2019-07-01 Thread Paul E. McKenney
On Mon, Jul 01, 2019 at 12:04:13AM -0400, Joel Fernandes (Google) wrote:
> The t->rcu_read_unlock_special union's need_qs bit can be set by the
> scheduler tick (in rcu_flavor_sched_clock_irq) to indicate that help is
> needed from the rcu_read_unlock path. When this help arrives however, we
> can do better to speed up the quiescent state reporting which if
> rcu_read_unlock_special::need_qs is set might be quite urgent. Make use
> of this information in deciding when to do heavy-weight softirq raising
> where possible.
> 
> Signed-off-by: Joel Fernandes (Google) 

Cute thought, but I am going to have to pass on this one.  The reason
is that by the time that ->rcu_read_unlock_special.b.need_qs gets set,
the grace period is already one full second old.  At that point, the
extra tick of waiting is down in the noise.

Right now, we do the extra work if we really are blocking an expedited
grace period (the first two lines of the original condition) or we are
running on a nohz_full CPU (which might never execute a scheduling clock
tick, thus potentially delaying forever).  And expedited grace periods
are supposed to complete in tens or maybe hundreds of microseconds,
assuming the RCU readers are being cooperative, which is a whole
different level of urgent.

Nevertheless, thank you for looking into this!

Thanx, Paul

> ---
>  kernel/rcu/tree_plugin.h | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
> index c588ef98efd3..bff6410fac06 100644
> --- a/kernel/rcu/tree_plugin.h
> +++ b/kernel/rcu/tree_plugin.h
> @@ -622,7 +622,8 @@ static void rcu_read_unlock_special(struct task_struct *t)
>   t->rcu_read_unlock_special.b.exp_hint = false;
>   exp = (t->rcu_blocked_node && t->rcu_blocked_node->exp_tasks) ||
> (rdp->grpmask & rnp->expmask) ||
> -   tick_nohz_full_cpu(rdp->cpu);
> +   tick_nohz_full_cpu(rdp->cpu)  ||
> +   t->rcu_read_unlock_special.b.need_qs;
>   // Need to defer quiescent state until everything is enabled.
>   if (irqs_were_disabled && use_softirq &&
>   (in_interrupt() ||
> -- 
> 2.22.0.410.gd8fdbe21b5-goog
> 



Re: [PATCH v3 3/4] Revert "xen: Introduce 'xen_nopv' to disable PV extensions for HVM guests."

2019-07-01 Thread Boris Ostrovsky
On Mon, Jul 01, 2019 at 10:20:27AM +0800, Zhenzhong Duan wrote:
> This reverts commit 8d693b911bb9c57009c24cb1772d205b84c7985c.
> 
> Instead we use an unified parameter 'nopv' for all the hypervisor
> platforms.
> 
> Signed-off-by: Zhenzhong Duan 
> Reviewed-by: Juergen Gross 
> Cc: Boris Ostrovsky 
> Cc: Juergen Gross 
> Cc: Stefano Stabellini 
> Cc: Thomas Gleixner 
> Cc: Ingo Molnar 
> Cc: Borislav Petkov 
> ---
>  Documentation/admin-guide/kernel-parameters.txt |  4 
>  arch/x86/xen/enlighten_hvm.c| 12 +---
>  2 files changed, 1 insertion(+), 15 deletions(-)
> 
> diff --git a/Documentation/admin-guide/kernel-parameters.txt 
> b/Documentation/admin-guide/kernel-parameters.txt
> index 21e08af..d5c3dcc 100644
> --- a/Documentation/admin-guide/kernel-parameters.txt
> +++ b/Documentation/admin-guide/kernel-parameters.txt
> @@ -5251,10 +5251,6 @@
>   Disables the ticketlock slowpath using Xen PV
>   optimizations.
>  
> - xen_nopv[X86]
> - Disables the PV optimizations forcing the HVM guest to
> - run as generic HVM guest with no PV drivers.
> -


So someone upgrades the kernel and suddenly things work differently?

At least there should be a warning that the option has been replaced
with 'nopv' (but I would actually keep this option working as well).

-boris



>   xen_scrub_pages=[XEN]
>   Boolean option to control scrubbing pages before giving 
> them back
>   to Xen, for use by other domains. Can be also changed 
> at runtime
> diff --git a/arch/x86/xen/enlighten_hvm.c b/arch/x86/xen/enlighten_hvm.c
> index ac4943c..7fcb4ea 100644
> --- a/arch/x86/xen/enlighten_hvm.c
> +++ b/arch/x86/xen/enlighten_hvm.c
> @@ -210,18 +210,8 @@ static void __init xen_hvm_guest_init(void)
>  #endif
>  }
>  
> -static bool xen_nopv;
> -static __init int xen_parse_nopv(char *arg)
> -{
> -   xen_nopv = true;
> -   return 0;
> -}
> -early_param("xen_nopv", xen_parse_nopv);
> -
>  bool __init xen_hvm_need_lapic(void)
>  {
> - if (xen_nopv)
> - return false;
>   if (xen_pv_domain())
>   return false;
>   if (!xen_hvm_domain())
> @@ -233,7 +223,7 @@ bool __init xen_hvm_need_lapic(void)
>  
>  static uint32_t __init xen_platform_hvm(void)
>  {
> - if (xen_pv_domain() || xen_nopv)
> + if (xen_pv_domain())
>   return 0;
>  
>   return xen_cpuid_base();
> -- 
> 1.8.3.1
> 


linux-next: build warning after merge of the amdgpu tree

2019-07-01 Thread Stephen Rothwell
Hi all,

After merging the amdgpu tree, today's linux-next build (x86_64
allmodcnofig) produced this warning:

drivers/gpu/drm/amd/amdgpu/../amdkfd/kfd_device.c: In function 'kgd2kfd_probe':
drivers/gpu/drm/amd/amdgpu/../amdkfd/kfd_device.c:490:6: warning: unused 
variable 'ret' [-Wunused-variable]
  int ret;
  ^~~

Introduced by commit

  aabf3a951c4e ("drm/amdkfd: remove duplicated PCIE atomics request")

-- 
Cheers,
Stephen Rothwell


pgp24WOcp41NI.pgp
Description: OpenPGP digital signature


Re: [PATCH 0/3] FSGSBASE fix, test, and a semi-related cleanup

2019-07-01 Thread Andy Lutomirski
On Mon, Jul 1, 2019 at 8:43 PM Andy Lutomirski  wrote:
>
> In -tip, if FSGSBASE and PTI are on, the kernel crashes if SYSENTER
> happens with TF set.  It also crashes under if a non-NMI paranoid
> entry happens for any other reason from kernel mode with user GSBASE
> and user CR3, e.g. due to MOV SS shenanigans.
>
> This series fixes the bug.  It also adds another test to make sure
> we exercise SYSENTER with TF set regardless of what vendor's CPU
> we're on, although the test isn't needed to detect the bug: the
> single_step_syscall_32 and mov_ss_trap_* tests also trigger it.  And
> it compiles ignore_sysret out on IA32_EMULATION kernels -- I wasted
> a couple minutes while debugging this wondering whether I was
> accidentally triggering ignore_sysret.

I forgot to mention: even with this applied, the x86/cpu tree is not
ready for prime time.  The fsgsbase test case fails on released
kernels and crashes on x86/cpu.  I haven't gotten to the bottom of it
yet.  The test code looks a bit dubious, but that doesn't necessarily
mean the kernel is okay.


Re: [PATCH RESEND] Revert "x86/paravirt: Set up the virt_spin_lock_key after static keys get initialized"

2019-07-01 Thread Boris Ostrovsky
On Thu, Jun 27, 2019 at 11:24:41PM +0200, Thomas Gleixner wrote:
> On Wed, 26 Jun 2019, Zhenzhong Duan wrote:
> 
> > This reverts commit ca5d376e17072c1b60c3fee66f3be58ef018952d.
> > 
> > Commit 8990cac6e5ea ("x86/jump_label: Initialize static branching
> > early") adds jump_label_init() call in setup_arch() to make static
> > keys initialized early, so we could use the original simpler code
> > again.
> > 
> > Signed-off-by: Zhenzhong Duan 
> > Cc: Waiman Long 
> > Cc: Peter Zijlstra (Intel) 
> > Cc: Thomas Gleixner 
> > Cc: Ingo Molnar 
> > Cc: Borislav Petkov 
> > Cc: Boris Ostrovsky 
> 
> Boris,
> 
> want you to pick that up or should I?
> 
> In case you take it:
> 
> Reviewed-by: Thomas Gleixner 


We will take it via Xen tree, thanks.

-boris


Re: linux-next: manual merge of the mlx5-next tree with Linus' tree

2019-07-01 Thread Leon Romanovsky
On Tue, Jul 02, 2019 at 01:13:27PM +1000, Stephen Rothwell wrote:
> Hi all,
>
> Today's linux-next merge of the mlx5-next tree got a conflict in:
>
>   drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
>
> between commit:
>
>   955858009708 ("net/mlx5e: Fix number of vports for ingress ACL 
> configuration")
>
> from Linus' tree and commit:
>
>   062f4bf4aab5 ("net/mlx5: E-Switch, Consolidate eswitch function number of 
> VFs")
>
> from the mlx5-next tree.
>
> I fixed it up (I just used the latter version) and can carry the fix as
> necessary. This is now fixed as far as linux-next is concerned, but any
> non trivial conflicts should be mentioned to your upstream maintainer
> when your tree is submitted for merging.  You may also want to consider
> cooperating with the maintainer of the conflicting tree to minimise any
> particularly complex conflicts.

Thanks Stephen,

I expect this conflict will vanish once both rdma and netdev pull
mlx5-next branch, which is based on -rc2.

Thanks

>
> --
> Cheers,
> Stephen Rothwell




Re: linux-next: Fixes tag needs some work in the mlx5-next tree

2019-07-01 Thread Leon Romanovsky
On Tue, Jul 02, 2019 at 10:05:33AM +1000, Stephen Rothwell wrote:
> Hi all,
>
> In commit
>
>   16fff98a7e82 ("net/mlx5: E-Switch, Reg/unreg function changed event at 
> correct stage")
>
> Fixes tag
>
>   Fixes: 61fc880839e6 ("net/mlx5: E-Switch, Handle representors creation in 
> handler context")
>
> has these problem(s):
>
>   - Target SHA1 does not exist
>
> Did you mean
>
> Fixes: ac35dcd6e4bd ("net/mlx5: E-Switch, Handle representors creation in 
> handler context")

Right, unfortunately this commit was already merged.

Thanks

>
> --
> Cheers,
> Stephen Rothwell




Re: [PATCH v2 1/3] mm: Trigger bug on if a section is not found in __section_nr

2019-07-01 Thread Alastair D'Silva
On Mon, 2019-07-01 at 12:46 +0200, Michal Hocko wrote:
> On Fri 28-06-19 10:46:28, Alastair D'Silva wrote:
> [...]
> > Given that there is already a VM_BUG_ON in the code, how do you
> > feel
> > about broadening the scope from 'VM_BUG_ON(!root)' to
> > 'VM_BUG_ON(!root
> > > > (root_nr == NR_SECTION_ROOTS))'?
> 
> As far as I understand the existing VM_BUG_ON will hit when the
> mem_section tree gets corrupted. This is a different situation to an
> incorrect section given so I wouldn't really mix those two. And I
> still
> do not see much point to protect from unexpected input parameter as
> this
> is internal function as already pointed out.
> 

Hi Michael,

I was able to hit this problem as the system firmware had assigned the
prototype pmem device an address range above the 128TB limit that we
originally supported. This has since been lifted to 2PB with patch
4ffe713b7587b14695c9bec26a000fc88ef54895.

As it stands, we cannot move this range lower as the high bits are
dictated by the location the card is connected.

Since the physical address of the memory is not controlled by the
kernel, I believe we should catch (or at least make it easy to debug)
the sitution where external firmware allocates physical addresses
beyond that which the kernel supports.

-- 
Alastair D'Silva   mob: 0423 762 819
skype: alastair_dsilva
Twitter: @EvilDeece
blog: http://alastair.d-silva.org




Re: [PATCH v2 1/5] PM: ACPI/PCI: Resume all devices during hibernation

2019-07-01 Thread Robert R. Howell
On 7/1/19 4:44 AM, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki 
> 
> Both the PCI bus type and the ACPI PM domain avoid resuming
> runtime-suspended devices with DPM_FLAG_SMART_SUSPEND set during
> hibernation (before creating the snapshot image of system memory),
> but that turns out to be a mistake.  It leads to functional issues
> and adds complexity that's hard to justify.
> 
> For this reason, resume all runtime-suspended PCI devices and all
> devices in the ACPI PM domains before creating a snapshot image of
> system memory during hibernation.
> 
> Fixes: 05087360fd7a (ACPI / PM: Take SMART_SUSPEND driver flag into account)
> Fixes: c4b65157aeef (PCI / PM: Take SMART_SUSPEND driver flag into account)
> Link: 
> https://lore.kernel.org/linux-acpi/917d4399-2e22-67b1-9d54-808561f90...@uwyo.edu/T/#maf065fe6e4974f2a9d79f332ab99dfaba635f64c
> Reported-by: Robert R. Howell 
> Tested-by: Robert R. Howell 
> Signed-off-by: Rafael J. Wysocki 
> ---
> 
> -> v2: No changes.

I've tested your v2 patch set on my ASUS T100TA, applying just those 5 patches 
to the 
5.2-rc7 kernel, and they do fix the hibernation problem.  The i2c_designware 
timeout errors are now gone and sound does now work after resume from both 
suspend and hibernate.  

As before I still see the "i2c_designware 80860F41:00: Transfer while 
suspended" error 
on the first resume from either suspend or hibernate, but also as before that 
particular error doesn't seem to cause a persistent problem and the system 
works 
normally after the resume.

Bob Howell


RE: linux-next: Fixes tag needs some work in the wireless-drivers-next tree

2019-07-01 Thread dundi
Hi Stephen,

You are correct, Its
Fixes: ba94c753ccb4 ("ath10k: add QMI message handshake for wcn3990 client")

My bad, I added last 12 digits instead of first 12 digits of SHA1.

Regards,
Dundi

-Original Message-
From: Stephen Rothwell  
Sent: Tuesday, July 2, 2019 3:03 AM
To: Kalle Valo ; Wireless

Cc: Linux Next Mailing List ; Linux Kernel
Mailing List ; Dundi Raviteja

Subject: linux-next: Fixes tag needs some work in the wireless-drivers-next
tree

Hi all,

In commit

  c709df58832c ("ath10k: Fix memory leak in qmi")

Fixes tag

  Fixes: fda6fee0001e ("ath10k: add QMI message handshake for wcn3990
client")

has these problem(s):

  - Target SHA1 does not exist

Did you mean

Fixes: ba94c753ccb4 ("ath10k: add QMI message handshake for wcn3990 client")

-- 
Cheers,
Stephen Rothwell



Re

2019-07-01 Thread Smadar Barber-Tsadik
Sorry to break into your privacy in this manner, 
I'm Smadar Barber-Tsadik, Deputy Chief Executive Officer 
of First International Bank of Israel Ltd (FIBI). 
I am getting in touch with you regarding an extremely 
important and urgent matter. If you would oblige me the 
opportunity, I shall provide you with details upon your 
response.

Faithfully,
Smadar Barber-Tsadik


[PATCH 2/2] opp: Manage empty OPP tables with clk handle

2019-07-01 Thread Rajendra Nayak
With OPP core now supporting DVFS for IO devices, we have instances of
IO devices (same IP block) with require an OPP on some platforms/SoCs
while just needing to scale the clock on some others.
In order to avoid conditional code in every driver, (to check for 
availability of OPPs and then deciding to do either dev_pm_opp_set_rate()
or clk_set_rate()) add support to manage empty OPP tables with a clk handle.
This makes dev_pm_opp_set_rate() equivalent of a clk_set_rate() for devices
with just a clk and no OPPs specified.

Signed-off-by: Rajendra Nayak 
---
 drivers/opp/core.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/drivers/opp/core.c b/drivers/opp/core.c
index ae033bb1e5b7..fa7d4d6d37b3 100644
--- a/drivers/opp/core.c
+++ b/drivers/opp/core.c
@@ -801,6 +801,11 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long 
target_freq)
goto put_opp_table;
}
 
+   if (!_get_opp_count(opp_table)) {
+   ret = _generic_set_opp_clk_only(dev, clk, freq);
+   goto put_opp_table;
+   }
+
temp_freq = old_freq;
old_opp = _find_freq_ceil(opp_table, &temp_freq);
if (IS_ERR(old_opp)) {
-- 
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation



[PATCH 1/2] opp: Export dev_pm_opp_set_genpd_virt_dev()

2019-07-01 Thread Rajendra Nayak
Export dev_pm_opp_set_genpd_virt_dev() so loadable modules can use it.

Signed-off-by: Rajendra Nayak 
---
 drivers/opp/core.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/opp/core.c b/drivers/opp/core.c
index 8fbdbedc009c..ae033bb1e5b7 100644
--- a/drivers/opp/core.c
+++ b/drivers/opp/core.c
@@ -1797,6 +1797,7 @@ struct opp_table *dev_pm_opp_set_genpd_virt_dev(struct 
device *dev,
 
return opp_table;
 }
+EXPORT_SYMBOL_GPL(dev_pm_opp_set_genpd_virt_dev);
 
 /**
  * dev_pm_opp_put_genpd_virt_dev() - Releases resources blocked for genpd 
device.
-- 
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation



[PATCH] MAINTAINERS: Add FSI subsystem

2019-07-01 Thread Joel Stanley
The subsystem was merged some time ago but we did not have a maintainers
entry.

Signed-off-by: Joel Stanley 
---
 MAINTAINERS | 13 +
 1 file changed, 13 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 01a52fc964da..2a5df9c20ecb 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -6498,6 +6498,19 @@ F:   fs/crypto/
 F: include/linux/fscrypt*.h
 F: Documentation/filesystems/fscrypt.rst
 
+FSI SUBSYSTEM
+M: Jeremy Kerr 
+M: Joel Stanley 
+R: Alistar Popple 
+R: Eddie James 
+L: linux-...@lists.ozlabs.org
+T: git git://git.kernel.org/pub/scm/joel/fsi.git
+Q: http://patchwork.ozlabs.org/project/linux-fsi/list/
+S: Supported
+F: drivers/fsi/
+F: include/linux/fsi*.h
+F: include/trace/events/fsi*.h
+
 FSI-ATTACHED I2C DRIVER
 M: Eddie James 
 L: linux-...@vger.kernel.org
-- 
2.20.1



Re: [PATCH v3 3/4] Revert "xen: Introduce 'xen_nopv' to disable PV extensions for HVM guests."

2019-07-01 Thread Zhenzhong Duan



On 2019/7/2 11:48, Boris Ostrovsky wrote:

On Mon, Jul 01, 2019 at 10:20:27AM +0800, Zhenzhong Duan wrote:

This reverts commit 8d693b911bb9c57009c24cb1772d205b84c7985c.

Instead we use an unified parameter 'nopv' for all the hypervisor
platforms.

Signed-off-by: Zhenzhong Duan
Reviewed-by: Juergen Gross
Cc: Boris Ostrovsky
Cc: Juergen Gross
Cc: Stefano Stabellini
Cc: Thomas Gleixner
Cc: Ingo Molnar
Cc: Borislav Petkov
---
  Documentation/admin-guide/kernel-parameters.txt |  4 
  arch/x86/xen/enlighten_hvm.c| 12 +---
  2 files changed, 1 insertion(+), 15 deletions(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt 
b/Documentation/admin-guide/kernel-parameters.txt
index 21e08af..d5c3dcc 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -5251,10 +5251,6 @@
Disables the ticketlock slowpath using Xen PV
optimizations.
  
-	xen_nopv	[X86]

-   Disables the PV optimizations forcing the HVM guest to
-   run as generic HVM guest with no PV drivers.
-

So someone upgrades the kernel and suddenly things work differently?

At least there should be a warning that the option has been replaced
with 'nopv' (but I would actually keep this option working as well).


OK, I'll add new patch to map xen_nopv to nopv. So if 'xen_nopv' is 
used, we go


to the path for 'nopv'. I will be same effect.

Thanks

Zhenzhong



Re: [PATCH] MAINTAINERS: Add FSI subsystem

2019-07-01 Thread Jeremy Kerr
Hi Joel,

> The subsystem was merged some time ago but we did not have a
> maintainers
> entry.

Acked-by: Jeremy Kerr 

Cheers,


Jeremy




Re: [PATCH v3 1/4] media: venus: Add codec data table

2019-07-01 Thread amasule

Hi Stan,

On 2019-07-01 17:13, Stanimir Varbanov wrote:

On 6/25/19 7:27 PM, Aniket Masule wrote:

Add vpp cycles for for different types of codec
It indicates the cycles required by video hardware
to process each macroblock. Initialize the codec
data with core resources.

Signed-off-by: Aniket Masule 
---
 drivers/media/platform/qcom/venus/core.c| 13 +
 drivers/media/platform/qcom/venus/core.h| 15 +++
 drivers/media/platform/qcom/venus/helpers.c | 30 
+

 drivers/media/platform/qcom/venus/helpers.h |  1 +
 drivers/media/platform/qcom/venus/vdec.c|  4 
 drivers/media/platform/qcom/venus/venc.c|  4 
 6 files changed, 67 insertions(+)

diff --git a/drivers/media/platform/qcom/venus/core.c 
b/drivers/media/platform/qcom/venus/core.c

index 7393667..f1597d6 100644
--- a/drivers/media/platform/qcom/venus/core.c
+++ b/drivers/media/platform/qcom/venus/core.c
@@ -473,9 +473,22 @@ static __maybe_unused int 
venus_runtime_resume(struct device *dev)

{  244800, 1 }, /* 1920x1080@30 */
 };

+static struct codec_freq_data sdm845_codec_freq_data[] =  {
+   { V4L2_PIX_FMT_H264, VIDC_SESSION_TYPE_ENC, 675 },
+   { V4L2_PIX_FMT_HEVC, VIDC_SESSION_TYPE_ENC, 675 },
+   { V4L2_PIX_FMT_VP8, VIDC_SESSION_TYPE_ENC, 675 },
+   { V4L2_PIX_FMT_MPEG2, VIDC_SESSION_TYPE_DEC, 200 },
+   { V4L2_PIX_FMT_H264, VIDC_SESSION_TYPE_DEC, 200 },
+   { V4L2_PIX_FMT_HEVC, VIDC_SESSION_TYPE_DEC, 200 },
+   { V4L2_PIX_FMT_VP8, VIDC_SESSION_TYPE_DEC, 200 },
+   { V4L2_PIX_FMT_VP9, VIDC_SESSION_TYPE_DEC, 200 },
+};
+
 static const struct venus_resources sdm845_res = {
.freq_tbl = sdm845_freq_table,
.freq_tbl_size = ARRAY_SIZE(sdm845_freq_table),
+   .codec_freq_data = sdm845_codec_freq_data,
+   .codec_freq_data_size = ARRAY_SIZE(sdm845_codec_freq_data),
.clks = {"core", "iface", "bus" },
.clks_num = 3,
.max_load = 2563200,
diff --git a/drivers/media/platform/qcom/venus/core.h 
b/drivers/media/platform/qcom/venus/core.h

index 7a3feb5..2ed6496 100644
--- a/drivers/media/platform/qcom/venus/core.h
+++ b/drivers/media/platform/qcom/venus/core.h
@@ -35,12 +35,20 @@ struct reg_val {
u32 value;
 };

+struct codec_freq_data {
+   u32 pixfmt;
+   u32 session_type;
+   unsigned int vpp_freq;


isn't unsigned long more suitable?


The hard-coded values for this vpp will be in few hundreds.
So, unsigned int would be fine.

+};
+
 struct venus_resources {
u64 dma_mask;
const struct freq_tbl *freq_tbl;
unsigned int freq_tbl_size;
const struct reg_val *reg_tbl;
unsigned int reg_tbl_size;
+   const struct codec_freq_data *codec_freq_data;
+   unsigned int codec_freq_data_size;
const char * const clks[VIDC_CLKS_NUM_MAX];
unsigned int clks_num;
enum hfi_version hfi_version;
@@ -216,6 +224,12 @@ struct venus_buffer {
struct list_head ref_list;
 };

+struct clock_data {
+   u32 core_id;
+   unsigned long freq;
+   struct codec_freq_data *codec_freq_data;
+};
+
 #define to_venus_buffer(ptr)	container_of(ptr, struct venus_buffer, 
vb)


 /**
@@ -275,6 +289,7 @@ struct venus_inst {
struct list_head list;
struct mutex lock;
struct venus_core *core;
+   struct clock_data clk_data;
struct list_head dpbbufs;
struct list_head internalbufs;
struct list_head registeredbufs;
diff --git a/drivers/media/platform/qcom/venus/helpers.c 
b/drivers/media/platform/qcom/venus/helpers.c

index 5cad601..f7f724b 100644
--- a/drivers/media/platform/qcom/venus/helpers.c
+++ b/drivers/media/platform/qcom/venus/helpers.c
@@ -715,6 +715,36 @@ int venus_helper_set_core_usage(struct venus_inst 
*inst, u32 usage)

 }
 EXPORT_SYMBOL_GPL(venus_helper_set_core_usage);

+int venus_helper_init_codec_data(struct venus_inst *inst)
+{
+   const struct codec_data *codec_data;


Something is wrong here, there is no prototype of struct codec_data.

Something went wrong during git rebase, will correct this.


Regards,
Aniket


Re: [PATCH v2] mdev: Send uevents around parent device registration

2019-07-01 Thread Kirti Wankhede



On 7/2/2019 1:34 AM, Alex Williamson wrote:
> On Mon, 1 Jul 2019 23:20:35 +0530
> Kirti Wankhede  wrote:
> 
>> On 7/1/2019 10:54 PM, Alex Williamson wrote:
>>> On Mon, 1 Jul 2019 22:43:10 +0530
>>> Kirti Wankhede  wrote:
>>>   
 On 7/1/2019 8:24 PM, Alex Williamson wrote:  
> This allows udev to trigger rules when a parent device is registered
> or unregistered from mdev.
>
> Signed-off-by: Alex Williamson 
> ---
>
> v2: Don't remove the dev_info(), Kirti requested they stay and
> removing them is only tangential to the goal of this change.
> 

 Thanks.

  
>  drivers/vfio/mdev/mdev_core.c |8 
>  1 file changed, 8 insertions(+)
>
> diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c
> index ae23151442cb..7fb268136c62 100644
> --- a/drivers/vfio/mdev/mdev_core.c
> +++ b/drivers/vfio/mdev/mdev_core.c
> @@ -146,6 +146,8 @@ int mdev_register_device(struct device *dev, const 
> struct mdev_parent_ops *ops)
>  {
>   int ret;
>   struct mdev_parent *parent;
> + char *env_string = "MDEV_STATE=registered";
> + char *envp[] = { env_string, NULL };
>  
>   /* check for mandatory ops */
>   if (!ops || !ops->create || !ops->remove || !ops->supported_type_groups)
> @@ -197,6 +199,8 @@ int mdev_register_device(struct device *dev, const 
> struct mdev_parent_ops *ops)
>   mutex_unlock(&parent_list_lock);
>  
>   dev_info(dev, "MDEV: Registered\n");
> + kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp);
> +
>   return 0;
>  
>  add_dev_err:
> @@ -220,6 +224,8 @@ EXPORT_SYMBOL(mdev_register_device);
>  void mdev_unregister_device(struct device *dev)
>  {
>   struct mdev_parent *parent;
> + char *env_string = "MDEV_STATE=unregistered";
> + char *envp[] = { env_string, NULL };
>  
>   mutex_lock(&parent_list_lock);
>   parent = __find_parent_device(dev);
> @@ -243,6 +249,8 @@ void mdev_unregister_device(struct device *dev)
>   up_write(&parent->unreg_sem);
>  
>   mdev_put_parent(parent);
> +
> + kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp);

 mdev_put_parent() calls put_device(dev). If this is the last instance
 holding device, then on put_device(dev) dev would get freed.

 This event should be before mdev_put_parent()  
>>>
>>> So you're suggesting the vendor driver is calling
>>> mdev_unregister_device() without a reference to the struct device that
>>> it's passing to unregister?  Sounds bogus to me.  We take a
>>> reference to the device so that it can't disappear out from under us,
>>> the caller cannot rely on our reference and the caller provided the
>>> struct device.  Thanks,
>>>   
>>
>> 1. Register uevent is sent after mdev holding reference to device, then
>> ideally, unregister path should be mirror of register path, send uevent
>> and then release the reference to device.
> 
> I don't see the relevance here.  We're marking an event, not unwinding
> state of the device from the registration process.  Additionally, the
> event we're trying to mark is the completion of each process, so the
> notion that we need to mirror the ordering between the two is invalid.
> 
>> 2. I agree that vendor driver shouldn't call mdev_unregister_device()
>> without holding reference to device. But to be on safer side, if ever
>> such case occur, to avoid any segmentation fault in kernel, better to
>> send event before mdev release the reference to device.
> 
> I know that get_device() and put_device() are GPL symbols and that's a
> bit of an issue, but I don't think we should be kludging the code for a
> vendor driver that might have problems with that.  A) we're using the
> caller provided device  for the uevent, B) we're only releasing our own
> reference to the device that was acquired during registration, the
> vendor driver must have other references,

Are you going to assume that someone/vendor driver is always going to do
right thing?

> C) the parent device
> generally lives on a bus, with a vendor driver, there's an entire
> ecosystem of references to the device below mdev.  Is this a paranoia
> request or are you really concerned that your PCI device suddenly
> disappears when mdev's reference to it disappears. 

mdev infrastructure is not always used by PCI devices. It is designed to
be generic, so that other devices (other than PCI devices) can also use
this framework.
If there is a assumption that user of mdev framework or vendor drivers
are always going to use mdev in right way, then there is no need for
mdev core to held reference of the device?
This is not a "paranoia request". This is more of a ideal scenario, mdev
should use device by holding its reference rather than assuming (or
relying on) someone else holding the reference of device.

Thanks,
Kirti


Re: [PATCH v3 2/4] media: venus: Update clock scaling

2019-07-01 Thread amasule

Hi Stan,

On 2019-07-01 18:41, Stanimir Varbanov wrote:

On 6/25/19 7:27 PM, Aniket Masule wrote:

Current clock scaling calculations are same for vpu4 and
previous versions. For vpu4, Clock scaling calculations
are updated with cycles/mb. This helps in getting precise
clock required.

Signed-off-by: Aniket Masule 
---
 drivers/media/platform/qcom/venus/helpers.c | 111 


 drivers/media/platform/qcom/venus/helpers.h |   2 +-
 drivers/media/platform/qcom/venus/vdec.c|   2 +-
 drivers/media/platform/qcom/venus/venc.c|   2 +-
 4 files changed, 99 insertions(+), 18 deletions(-)

diff --git a/drivers/media/platform/qcom/venus/helpers.c 
b/drivers/media/platform/qcom/venus/helpers.c

index f7f724b..e1a0247 100644
--- a/drivers/media/platform/qcom/venus/helpers.c
+++ b/drivers/media/platform/qcom/venus/helpers.c
@@ -348,8 +348,9 @@ static u32 load_per_type(struct venus_core *core, 
u32 session_type)

return mbs_per_sec;
 }

-static int load_scale_clocks(struct venus_core *core)
+static int scale_clocks(struct venus_inst *inst)
 {
+   struct venus_core *core = inst->core;
const struct freq_tbl *table = core->res->freq_tbl;
unsigned int num_rows = core->res->freq_tbl_size;
unsigned long freq = table[0].freq;
@@ -398,6 +399,86 @@ static int load_scale_clocks(struct venus_core 
*core)

return ret;
 }

+static unsigned long calculate_vpp_freq(struct venus_inst *inst)
+{
+   unsigned long vpp_freq = 0;
+   u32 mbs_per_sec;
+
+   mbs_per_sec = load_per_instance(inst);
+   vpp_freq = mbs_per_sec * inst->clk_data.codec_freq_data->vpp_freq;
+   /* 21 / 20 is overhead factor */
+   vpp_freq += vpp_freq / 20;
+
+   return vpp_freq;
+}
+
+static int scale_clocks_v4(struct venus_inst *inst)
+{
+   struct venus_core *core = inst->core;
+   const struct freq_tbl *table = core->res->freq_tbl;
+   unsigned int num_rows = core->res->freq_tbl_size;
+


please remove this blank line.


+   struct clk *clk = core->clks[0];
+   struct device *dev = core->dev;
+   unsigned int i;
+   unsigned long freq = 0, freq_core0 = 0, freq_core1 = 0;


could you count the cores as it is done for VIDC_CORE_ID_ ?
i.e. start counting from one.


Sure, I was aligning it with clock handle name in core, but
aligning it with VIDC_CORE_ID_ would give good readability.

+   int ret;
+
+   freq = calculate_vpp_freq(inst);
+
+   if (freq > table[0].freq)
+   goto err;


if the goto is triggered the error message will be wrong. Infact the
dev_err message is targeted for clk_set_rate failure.


I will add separate exit for this.

+
+   for (i = 0; i < num_rows; i++) {
+   if (freq > table[i].freq)
+   break;
+   freq = table[i].freq;
+   }
+
+   inst->clk_data.freq = freq;
+
+   mutex_lock(&core->lock);
+   list_for_each_entry(inst, &core->instances, list) {
+   if (inst->clk_data.core_id == VIDC_CORE_ID_1) {
+   freq_core0 += inst->clk_data.freq;
+   } else if (inst->clk_data.core_id == VIDC_CORE_ID_2) {
+   freq_core1 += inst->clk_data.freq;
+   } else if (inst->clk_data.core_id == VIDC_CORE_ID_3) {
+   freq_core0 += inst->clk_data.freq;
+   freq_core1 += inst->clk_data.freq;
+   }
+   }
+   mutex_unlock(&core->lock);
+
+   freq = max(freq_core0, freq_core1);
+
+   ret = clk_set_rate(clk, freq);
+   if (ret)
+   goto err;
+
+   ret = clk_set_rate(core->core0_clk, freq);
+   if (ret)
+   goto err;
+
+   ret = clk_set_rate(core->core1_clk, freq);
+   if (ret)
+   goto err;
+
+   return 0;
+
+err:
+   dev_err(dev, "failed to set clock rate %lu (%d)\n", freq, ret);
+   return ret;
+}
+
+static int load_scale_clocks(struct venus_inst *inst)
+{
+   if (IS_V4(inst->core))
+   return scale_clocks_v4(inst);
+
+   return scale_clocks(inst);
+}
+
 static void fill_buffer_desc(const struct venus_buffer *buf,
 struct hfi_buffer_desc *bd, bool response)
 {
@@ -715,35 +796,36 @@ int venus_helper_set_core_usage(struct 
venus_inst *inst, u32 usage)

 }
 EXPORT_SYMBOL_GPL(venus_helper_set_core_usage);

-int venus_helper_init_codec_data(struct venus_inst *inst)
+int venus_helper_init_codec_freq_data(struct venus_inst *inst)
 {
-   const struct codec_data *codec_data;
-   unsigned int i, codec_data_size;


those deletions shouldn't exist once you fix the git rebase issue.


+   const struct codec_freq_data *codec_freq_data;
+   unsigned int i, codec_freq_data_size;


could you rename the variables to shorter?


Yes

u32 pixfmt;
int ret = 0;

if (!IS_V4(inst->core))
return 0;

-   codec_data = inst->core->res->codec_data;
-   codec_data_size

Re: [PATCH v3 4/4] media: venus: Update core selection

2019-07-01 Thread amasule

Hi Stan,

On 2019-07-01 19:28, Stanimir Varbanov wrote:

Hi,

On 6/25/19 7:27 PM, Aniket Masule wrote:

Present core assignment is static. Introduced load balancing
across the cores. Load on earch core is calculated and core
with minimum load is assigned to given instance.

Signed-off-by: Aniket Masule 
---
 drivers/media/platform/qcom/venus/helpers.c | 52 
+

 drivers/media/platform/qcom/venus/helpers.h |  2 +-
 drivers/media/platform/qcom/venus/vdec.c|  2 +-
 drivers/media/platform/qcom/venus/venc.c|  2 +-
 4 files changed, 49 insertions(+), 9 deletions(-)

diff --git a/drivers/media/platform/qcom/venus/helpers.c 
b/drivers/media/platform/qcom/venus/helpers.c

index b79e83a..ef35fd8 100644
--- a/drivers/media/platform/qcom/venus/helpers.c
+++ b/drivers/media/platform/qcom/venus/helpers.c
@@ -498,6 +498,16 @@ static int load_scale_clocks(struct venus_inst 
*inst)

return scale_clocks(inst);
 }

+int set_core_usage(struct venus_inst *inst, u32 usage)
+{
+   const u32 ptype = HFI_PROPERTY_CONFIG_VIDEOCORES_USAGE;
+   struct hfi_videocores_usage_type cu;
+
+   cu.video_core_enable_mask = usage;
+
+   return hfi_session_set_property(inst, ptype, &cu);
+}
+
 static void fill_buffer_desc(const struct venus_buffer *buf,
 struct hfi_buffer_desc *bd, bool response)
 {
@@ -801,19 +811,49 @@ int venus_helper_set_work_mode(struct venus_inst 
*inst, u32 mode)

 }
 EXPORT_SYMBOL_GPL(venus_helper_set_work_mode);

-int venus_helper_set_core_usage(struct venus_inst *inst, u32 usage)
+int venus_helper_set_core(struct venus_inst *inst)
 {
-   const u32 ptype = HFI_PROPERTY_CONFIG_VIDEOCORES_USAGE;
-   struct hfi_videocores_usage_type cu;
+   struct venus_core *core = inst->core;
+   u32 min_core_id = 0, core0_load = 0, core1_load = 0;


the same comment, please use the same counting scheme as for 
VIDC_CORE_ID_



Yes, I will align this with VIDC_CORE_ID_.

+   unsigned long min_load, max_freq, cur_inst_load;
+   u32 cores_max;
+   int ret;

if (!IS_V4(inst->core))
return 0;

-   cu.video_core_enable_mask = usage;
+   core0_load = load_per_core(core, VIDC_CORE_ID_1);
+   core1_load = load_per_core(core, VIDC_CORE_ID_2);

-   return hfi_session_set_property(inst, ptype, &cu);
+	min_core_id = core0_load < core1_load ? VIDC_CORE_ID_1 : 
VIDC_CORE_ID_2;

+   min_load = min(core0_load, core1_load);
+   cores_max = core_num_max(inst);
+
+   if (cores_max < VIDC_CORE_ID_2) {
+   min_core_id = VIDC_CORE_ID_1;
+   min_load = core0_load;
+   }
+
+   cur_inst_load = load_per_instance(inst) *
+   inst->clk_data.codec_freq_data->vpp_freq;
+   max_freq = core->res->freq_tbl[0].freq;
+
+   if ((cur_inst_load + min_load)  > max_freq) {
+   dev_warn(core->dev, "HW is overloaded, needed: %lu max: %lu\n",
+cur_inst_load, max_freq);
+   return -EINVAL;
+   }
+
+   ret = set_core_usage(inst, min_core_id);
+


please, delete this blank line


+   if (ret)
+   return ret;
+
+   inst->clk_data.core_id = min_core_id;
+
+   return 0;
 }
-EXPORT_SYMBOL_GPL(venus_helper_set_core_usage);
+EXPORT_SYMBOL_GPL(venus_helper_set_core);

 int venus_helper_init_codec_freq_data(struct venus_inst *inst)
 {
diff --git a/drivers/media/platform/qcom/venus/helpers.h 
b/drivers/media/platform/qcom/venus/helpers.h

index 2c13245..1034111 100644
--- a/drivers/media/platform/qcom/venus/helpers.h
+++ b/drivers/media/platform/qcom/venus/helpers.h
@@ -42,7 +42,7 @@ int venus_helper_set_output_resolution(struct 
venus_inst *inst,

   u32 buftype);
 int venus_helper_set_work_mode(struct venus_inst *inst, u32 mode);
 int venus_helper_init_codec_freq_data(struct venus_inst *inst);
-int venus_helper_set_core_usage(struct venus_inst *inst, u32 usage);
+int venus_helper_set_core(struct venus_inst *inst);
 int venus_helper_set_num_bufs(struct venus_inst *inst, unsigned int 
input_bufs,

  unsigned int output_bufs,
  unsigned int output2_bufs);
diff --git a/drivers/media/platform/qcom/venus/vdec.c 
b/drivers/media/platform/qcom/venus/vdec.c

index d037f80..620e060 100644
--- a/drivers/media/platform/qcom/venus/vdec.c
+++ b/drivers/media/platform/qcom/venus/vdec.c
@@ -551,7 +551,7 @@ static int vdec_output_conf(struct venus_inst 
*inst)

if (ret)
return ret;

-   ret = venus_helper_set_core_usage(inst, VIDC_CORE_ID_1);
+   ret = venus_helper_set_core(inst);
if (ret)
return ret;

diff --git a/drivers/media/platform/qcom/venus/venc.c 
b/drivers/media/platform/qcom/venus/venc.c

index cdddc82..28e76cc 100644
--- a/drivers/media/platform/qcom/venus/venc.c
+++ b/drivers/media/platform/qcom/venus/venc.c
@@ -660,7 +660,7 @@ static int venc_set_prope

RE: [PATCH v2 09/11] firmware: xilinx: Add SDIO Tap Delay APIs

2019-07-01 Thread Manish Narani
Hi Jolly,


> -Original Message-
> From: Jolly Shah
> Sent: Monday, July 1, 2019 11:36 PM
> To: Manish Narani ; ulf.hans...@linaro.org;
> robh...@kernel.org; mark.rutl...@arm.com; he...@sntech.de; Michal Simek
> ; adrian.hun...@intel.com;
> christoph.muell...@theobroma-systems.com; philipp.tomsich@theobroma-
> systems.com; viresh.ku...@linaro.org; scott.bran...@broadcom.com;
> ay...@soulik.info; ker...@esmil.dk; tony@rock-chips.com; Rajan Vaja
> ; Nava kishore Manne ;
> m...@kernel.org; Manish Narani ; o...@lixom.net
> Cc: linux-...@vger.kernel.org; devicet...@vger.kernel.org; linux-
> ker...@vger.kernel.org; linux-arm-ker...@lists.infradead.org; linux-
> rockc...@lists.infradead.org
> Subject: RE: [PATCH v2 09/11] firmware: xilinx: Add SDIO Tap Delay APIs
> 
> Hi Manish,
> 
> > -Original Message-
> > From: Manish Narani 
> > Sent: Sunday, June 30, 2019 10:30 PM
> > To: ulf.hans...@linaro.org; robh...@kernel.org; mark.rutl...@arm.com;
> > he...@sntech.de; Michal Simek ;
> > adrian.hun...@intel.com; christoph.muell...@theobroma-systems.com;
> > philipp.toms...@theobroma-systems.com; viresh.ku...@linaro.org;
> > scott.bran...@broadcom.com; ay...@soulik.info; ker...@esmil.dk;
> > tony@rock-chips.com; Rajan Vaja ; Jolly Shah
> > ; Nava kishore Manne ;
> > m...@kernel.org; Manish Narani ; o...@lixom.net
> > Cc: linux-...@vger.kernel.org; devicet...@vger.kernel.org; linux-
> > ker...@vger.kernel.org; linux-arm-ker...@lists.infradead.org; linux-
> > rockc...@lists.infradead.org
> > Subject: [PATCH v2 09/11] firmware: xilinx: Add SDIO Tap Delay APIs
> >
> > Add APIs for setting SDIO Tap Delays on ZynqMP platform.
> >
> > Signed-off-by: Manish Narani 
> > ---
> >  drivers/firmware/xilinx/zynqmp.c | 48
> > 
> >  include/linux/firmware/xlnx-zynqmp.h | 15 ++-
> >  2 files changed, 62 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/firmware/xilinx/zynqmp.c
> b/drivers/firmware/xilinx/zynqmp.c
> > index fd3d837..b81f1be 100644
> > --- a/drivers/firmware/xilinx/zynqmp.c
> > +++ b/drivers/firmware/xilinx/zynqmp.c
> > @@ -664,6 +664,52 @@ static int zynqmp_pm_set_requirement(const u32
> > node, const u32 capabilities,
> >qos, ack, NULL);
> >  }
> >
> > +/**
> > + * zynqmp_pm_sdio_out_setphase() - PM call to set clock output delays for
> SD
> > + * @device_id: Device ID of the SD controller
> > + * @tap_delay: Tap Delay value for output clock
> > + *
> > + * This API function is to be used for setting the clock output delays for 
> > SD
> > + * clock.
> > + *
> > + * Return: Returns status, either success or error+reason
> > + */
> > +static int zynqmp_pm_sdio_out_setphase(u32 device_id, u8 tap_delay)
> > +{
> > +   u32 node_id = (!device_id) ? NODE_SD_0 : NODE_SD_1;
> > +   int ret;
> > +
> > +   ret = zynqmp_pm_ioctl(node_id, IOCTL_SET_SD_TAPDELAY,
> > + PM_TAPDELAY_OUTPUT, tap_delay, NULL);
> > +   if (ret)
> > +   pr_err("Error setting Output Tap Delay\n");
> > +
> > +   return ret;
> > +}
> > +
> > +/**
> > + * zynqmp_pm_sdio_in_setphase() - PM call to set clock input delays for SD
> > + * @device_id: Device ID of the SD controller
> > + * @tap_delay: Tap Delay value for input clock
> > + *
> > + * This API function is to be used for setting the clock input delays for 
> > SD
> > + * clock.
> > + *
> > + * Return: Returns status, either success or error+reason
> > + */
> > +static int zynqmp_pm_sdio_in_setphase(u32 device_id, u8 tap_delay)
> > +{
> > +   u32 node_id = (!device_id) ? NODE_SD_0 : NODE_SD_1;
> > +   int ret;
> > +
> > +   ret = zynqmp_pm_ioctl(node_id, IOCTL_SET_SD_TAPDELAY,
> > + PM_TAPDELAY_INPUT, tap_delay, NULL);
> > +   if (ret)
> > +   pr_err("Error setting Input Tap Delay\n");
> > +
> > +   return ret;
> > +}
> > +
> >  static const struct zynqmp_eemi_ops eemi_ops = {
> > .get_api_version = zynqmp_pm_get_api_version,
> > .get_chipid = zynqmp_pm_get_chipid,
> > @@ -687,6 +733,8 @@ static const struct zynqmp_eemi_ops eemi_ops = {
> > .set_requirement = zynqmp_pm_set_requirement,
> > .fpga_load = zynqmp_pm_fpga_load,
> > .fpga_get_status = zynqmp_pm_fpga_get_status,
> > +   .sdio_out_setphase = zynqmp_pm_sdio_out_setphase,
> > +   .sdio_in_setphase = zynqmp_pm_sdio_in_setphase,
> 
> Are these eemi APIs? You are using ioctl eemi api to set the delay.

Yes, I am making these eemi APIs and calling ioctl API from these. This is to 
make the SD driver code more readable.

Thanks,
Manish


Reminder: 1 open syzbot bug in hid subsystem

2019-07-01 Thread Eric Biggers
[This email was generated by a script.  Let me know if you have any suggestions
to make it better, or if you want it re-generated with the latest status.]

Of the currently open syzbot reports against the upstream kernel, I've manually
marked 1 of them as possibly being a bug in the hid subsystem.

If you believe this bug is no longer valid, please close the syzbot report by
sending a '#syz fix', '#syz dup', or '#syz invalid' command in reply to the
original thread, as explained at https://goo.gl/tpsmEJ#status

If you believe I misattributed this bug to the hid subsystem, please let me
know, and if possible forward the report to the correct people or mailing list.

Here is the bug:


Title:  INFO: task hung in fsnotify_connector_destroy_workfn (2)
Last occurred:  10 days ago
Reported:   290 days ago
Branches:   Mainline and others
Dashboard link: 
https://syzkaller.appspot.com/bug?id=d6011f00f49a2253c15a60ac102b2ea79e3ee8de
Original thread:
https://lkml.kernel.org/lkml/6364200575dfc...@google.com/T/#u

This bug has a syzkaller reproducer only.

The original thread for this bug received 7 replies; the last was 279 days ago.

If you fix this bug, please add the following tag to the commit:
Reported-by: syzbot+6fb572170402d311d...@syzkaller.appspotmail.com

If you send any email or patch for this bug, please consider replying to the
original thread.  For the git send-email command to use, or tips on how to reply
if the thread isn't in your mailbox, see the "Reply instructions" at
https://lkml.kernel.org/r/6364200575dfc...@google.com



Reminder: 1 open syzbot bug in rtc subsystem

2019-07-01 Thread Eric Biggers
[This email was generated by a script.  Let me know if you have any suggestions
to make it better, or if you want it re-generated with the latest status.]

Of the currently open syzbot reports against the upstream kernel, I've manually
marked 1 of them as possibly being a bug in the rtc subsystem.

If you believe this bug is no longer valid, please close the syzbot report by
sending a '#syz fix', '#syz dup', or '#syz invalid' command in reply to the
original thread, as explained at https://goo.gl/tpsmEJ#status

If you believe I misattributed this bug to the rtc subsystem, please let me
know, and if possible forward the report to the correct people or mailing list.

Here is the bug:


Title:  BUG: workqueue lockup (4)
Last occurred:  19 days ago
Reported:   267 days ago
Branches:   Mainline and others
Dashboard link: 
https://syzkaller.appspot.com/bug?id=0041bf1423916e9ae458b08b760e269a33c14960
Original thread:
https://lkml.kernel.org/lkml/5764090577a27...@google.com/T/#u

This bug has a C reproducer.

The original thread for this bug received 4 replies; the last was 20 days ago.

If you fix this bug, please add the following tag to the commit:
Reported-by: syzbot+08116743f8ad6f9a6...@syzkaller.appspotmail.com

If you send any email or patch for this bug, please consider replying to the
original thread.  For the git send-email command to use, or tips on how to reply
if the thread isn't in your mailbox, see the "Reply instructions" at
https://lkml.kernel.org/r/5764090577a27...@google.com



Reminder: 1 open syzbot bug in "security/smack" subsystem

2019-07-01 Thread Eric Biggers
[This email was generated by a script.  Let me know if you have any suggestions
to make it better, or if you want it re-generated with the latest status.]

Of the currently open syzbot reports against the upstream kernel, I've manually
marked 1 of them as possibly being a bug in the "security/smack" subsystem.

If you believe this bug is no longer valid, please close the syzbot report by
sending a '#syz fix', '#syz dup', or '#syz invalid' command in reply to the
original thread, as explained at https://goo.gl/tpsmEJ#status

If you believe I misattributed this bug to the "security/smack" subsystem,
please let me know, and if possible forward the report to the correct people or
mailing list.

Here is the bug:


Title:  possible deadlock in ext4_evict_inode
Last occurred:  259 days ago
Reported:   298 days ago
Branches:   Mainline
Dashboard link: 
https://syzkaller.appspot.com/bug?id=9eda6092f146cb23cb9109f675a2e2cb743ee48b
Original thread:
https://lkml.kernel.org/lkml/91615e0575368...@google.com/T/#u

This bug has a syzkaller reproducer only.

The original thread for this bug received 2 replies; the last was 298 days ago.

If you fix this bug, please add the following tag to the commit:
Reported-by: syzbot+0eefc1e06a77d327a...@syzkaller.appspotmail.com

If you send any email or patch for this bug, please consider replying to the
original thread.  For the git send-email command to use, or tips on how to reply
if the thread isn't in your mailbox, see the "Reply instructions" at
https://lkml.kernel.org/r/91615e0575368...@google.com



Re: [PATCH v3] rcu: Change return type of rcu_spawn_one_boost_kthread()

2019-07-01 Thread Byungchul Park
On Mon, Jul 01, 2019 at 01:12:16PM -0700, Paul E. McKenney wrote:
> On Mon, Jul 01, 2019 at 09:40:39AM +0900, Byungchul Park wrote:
> > Hello,
> > 
> > I tested again if the WARN_ON_ONCE() is fired with my box.
> > 
> > And it was OK.
> > 
> > Thanks,
> > Byungchul
> 
> And it now applies just fine, so I have queued it, thank you!
> 
> In the future, could you please use something like "git send-email"
> to email a proper patch?  When you do it this way, after I do "git am",
> I have to hand-edit the commit to remove this preamble.

Oh! Sorry to hear that. I've been always using "git send-email" with
scissors in the body expecting you do "git am -c". Do you mean it's not
a good way, right? I won't use the scissors again.

> But while I was doing the hand-editing, I updated the commit log as
> follows:
> 
>   rcu: Change return type of rcu_spawn_one_boost_kthread()
> 
>   The return value of rcu_spawn_one_boost_kthread() is not used
>   any longer.  This commit therefore changes its return type from
>   int to void, and removes the cast to void from its callers.
> 
> Does that work for you?

Sure. Thank you.

Thanks,
Byungchul

>   Thanx, Paul
> 
> > Changes from v2
> > -. Port the patch to a1af11a24cb0 (Paul's request)
> > -. Add a few new lines for a better look
> > 
> > Changes from v1
> > -. WARN_ON_ONCE() on failing to create rcu_boost_kthread.
> > -. Changed title and commit message a bit.
> > 
> > ---8<---
> > >From 20c934c5657a7a0f13ebb050ffd350d4174965d0 Mon Sep 17 00:00:00 2001
> > From: Byungchul Park 
> > Date: Mon, 1 Jul 2019 09:27:15 +0900
> > Subject: [PATCH v3] rcu: Change return type of rcu_spawn_one_boost_kthread()
> > 
> > The return value of rcu_spawn_one_boost_kthread() is not used any
> > longer. Change return type of that function from int to void.
> > 
> > Signed-off-by: Byungchul Park 
> > ---
> >  kernel/rcu/tree_plugin.h | 20 +++-
> >  1 file changed, 11 insertions(+), 9 deletions(-)
> > 
> > diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
> > index c588ef9..b8eea22 100644
> > --- a/kernel/rcu/tree_plugin.h
> > +++ b/kernel/rcu/tree_plugin.h
> > @@ -1119,7 +1119,7 @@ static void rcu_preempt_boost_start_gp(struct 
> > rcu_node *rnp)
> >   * already exist.  We only create this kthread for preemptible RCU.
> >   * Returns zero if all is well, a negated errno otherwise.
> >   */
> > -static int rcu_spawn_one_boost_kthread(struct rcu_node *rnp)
> > +static void rcu_spawn_one_boost_kthread(struct rcu_node *rnp)
> >  {
> > int rnp_index = rnp - rcu_get_root();
> > unsigned long flags;
> > @@ -1127,25 +1127,27 @@ static int rcu_spawn_one_boost_kthread(struct 
> > rcu_node *rnp)
> > struct task_struct *t;
> >  
> > if (!IS_ENABLED(CONFIG_PREEMPT_RCU))
> > -   return 0;
> > +   return;
> >  
> > if (!rcu_scheduler_fully_active || rcu_rnp_online_cpus(rnp) == 0)
> > -   return 0;
> > +   return;
> >  
> > rcu_state.boost = 1;
> > +
> > if (rnp->boost_kthread_task != NULL)
> > -   return 0;
> > +   return;
> > +
> > t = kthread_create(rcu_boost_kthread, (void *)rnp,
> >"rcub/%d", rnp_index);
> > -   if (IS_ERR(t))
> > -   return PTR_ERR(t);
> > +   if (WARN_ON_ONCE(IS_ERR(t)))
> > +   return;
> > +
> > raw_spin_lock_irqsave_rcu_node(rnp, flags);
> > rnp->boost_kthread_task = t;
> > raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
> > sp.sched_priority = kthread_prio;
> > sched_setscheduler_nocheck(t, SCHED_FIFO, &sp);
> > wake_up_process(t); /* get to TASK_INTERRUPTIBLE quickly. */
> > -   return 0;
> >  }
> >  
> >  /*
> > @@ -1186,7 +1188,7 @@ static void __init rcu_spawn_boost_kthreads(void)
> > struct rcu_node *rnp;
> >  
> > rcu_for_each_leaf_node(rnp)
> > -   (void)rcu_spawn_one_boost_kthread(rnp);
> > +   rcu_spawn_one_boost_kthread(rnp);
> >  }
> >  
> >  static void rcu_prepare_kthreads(int cpu)
> > @@ -1196,7 +1198,7 @@ static void rcu_prepare_kthreads(int cpu)
> >  
> > /* Fire up the incoming CPU's kthread and leaf rcu_node kthread. */
> > if (rcu_scheduler_fully_active)
> > -   (void)rcu_spawn_one_boost_kthread(rnp);
> > +   rcu_spawn_one_boost_kthread(rnp);
> >  }
> >  
> >  #else /* #ifdef CONFIG_RCU_BOOST */
> > -- 
> > 1.9.1
> > 


Reminder: 2 open syzbot bugs in "security/tomoyo" subsystem

2019-07-01 Thread Eric Biggers
[This email was generated by a script.  Let me know if you have any suggestions
to make it better, or if you want it re-generated with the latest status.]

Of the currently open syzbot reports against the upstream kernel, I've manually
marked 2 of them as possibly being bugs in the "security/tomoyo" subsystem. 
I've listed these reports below, sorted by an algorithm that tries to list first
the reports most likely to be still valid, important, and actionable.

If you believe a bug is no longer valid, please close the syzbot report by
sending a '#syz fix', '#syz dup', or '#syz invalid' command in reply to the
original thread, as explained at https://goo.gl/tpsmEJ#status

If you believe I misattributed a bug to the "security/tomoyo" subsystem, please
let me know, and if possible forward the report to the correct people or mailing
list.

Here are the bugs:


Title:  KASAN: use-after-free Read in tomoyo_realpath_from_path
Last occurred:  6 days ago
Reported:   26 days ago
Branches:   Mainline and others
Dashboard link: 
https://syzkaller.appspot.com/bug?id=73d590010454403d55164cca23bd0565b1eb3b74
Original thread:
https://lkml.kernel.org/lkml/4f43fa058a97f...@google.com/T/#u

This bug has a syzkaller reproducer only.

The original thread for this bug has received 7 replies; the last was 9 days
ago.

If you fix this bug, please add the following tag to the commit:
Reported-by: syzbot+0341f6a4d729d4e0a...@syzkaller.appspotmail.com

If you send any email or patch for this bug, please reply to the original
thread, which had activity only 9 days ago.  For the git send-email command to
use, or tips on how to reply if the thread isn't in your mailbox, see the "Reply
instructions" at 
https://lkml.kernel.org/r/4f43fa058a97f...@google.com


Title:  KASAN: invalid-free in tomoyo_realpath_from_path
Last occurred:  35 days ago
Reported:   34 days ago
Branches:   net-next
Dashboard link: 
https://syzkaller.appspot.com/bug?id=e9e5a1d41c3fb5d0f79aeea0e4cd535f160a6702
Original thread:
https://lkml.kernel.org/lkml/785e9d0589ec3...@google.com/T/#u

Unfortunately, this bug does not have a reproducer.

The original thread for this bug has received 1 reply, 34 days ago.

If you fix this bug, please add the following tag to the commit:
Reported-by: syzbot+9742b1c6c7aedf18b...@syzkaller.appspotmail.com

If you send any email or patch for this bug, please consider replying to the
original thread.  For the git send-email command to use, or tips on how to reply
if the thread isn't in your mailbox, see the "Reply instructions" at
https://lkml.kernel.org/r/785e9d0589ec3...@google.com



Reminder: 2 open syzbot bugs in vhost subsystem

2019-07-01 Thread Eric Biggers
[This email was generated by a script.  Let me know if you have any suggestions
to make it better, or if you want it re-generated with the latest status.]

Of the currently open syzbot reports against the upstream kernel, I've manually
marked 2 of them as possibly being bugs in the vhost subsystem.  I've listed
these reports below, sorted by an algorithm that tries to list first the reports
most likely to be still valid, important, and actionable.

Of these 2 bugs, 1 was seen in mainline in the last week.

If you believe a bug is no longer valid, please close the syzbot report by
sending a '#syz fix', '#syz dup', or '#syz invalid' command in reply to the
original thread, as explained at https://goo.gl/tpsmEJ#status

If you believe I misattributed a bug to the vhost subsystem, please let me know,
and if possible forward the report to the correct people or mailing list.

Here are the bugs:


Title:  memory leak in vhost_net_ioctl
Last occurred:  0 days ago
Reported:   26 days ago
Branches:   Mainline
Dashboard link: 
https://syzkaller.appspot.com/bug?id=12ba349d7e26ccfe95317bc376e812ebbae2ee0f
Original thread:
https://lkml.kernel.org/lkml/188da1058a9c2...@google.com/T/#u

This bug has a C reproducer.

The original thread for this bug has received 4 replies; the last was 17 days
ago.

If you fix this bug, please add the following tag to the commit:
Reported-by: syzbot+0789f0c7e45efd7bb...@syzkaller.appspotmail.com

If you send any email or patch for this bug, please consider replying to the
original thread.  For the git send-email command to use, or tips on how to reply
if the thread isn't in your mailbox, see the "Reply instructions" at
https://lkml.kernel.org/r/188da1058a9c2...@google.com


Title:  INFO: task hung in vhost_init_device_iotlb
Last occurred:  125 days ago
Reported:   153 days ago
Branches:   Mainline and others
Dashboard link: 
https://syzkaller.appspot.com/bug?id=cb1ea8daf03a5942c2ab314679148cf6e128ef58
Original thread:
https://lkml.kernel.org/lkml/7e86fd0580955...@google.com/T/#u

Unfortunately, this bug does not have a reproducer.

The original thread for this bug received 2 replies; the last was 152 days ago.

If you fix this bug, please add the following tag to the commit:
Reported-by: syzbot+40e28a8bd59d10ed0...@syzkaller.appspotmail.com

If you send any email or patch for this bug, please consider replying to the
original thread.  For the git send-email command to use, or tips on how to reply
if the thread isn't in your mailbox, see the "Reply instructions" at
https://lkml.kernel.org/r/7e86fd0580955...@google.com



[PATCH v4 1/5] x86/xen: Mark xen_hvm_need_lapic() and xen_x2apic_para_available() as __init

2019-07-01 Thread Zhenzhong Duan
.. as they are only called at early bootup stage. In fact, other
functions in x86_hyper_xen_hvm.init.* are all marked as __init.

Unexport xen_hvm_need_lapic as it's never used outside.

Signed-off-by: Zhenzhong Duan 
Reviewed-by: Juergen Gross 
Cc: Boris Ostrovsky 
Cc: Stefano Stabellini 
Cc: Thomas Gleixner 
Cc: Ingo Molnar 
Cc: Borislav Petkov 
---
 arch/x86/include/asm/xen/hypervisor.h | 6 +++---
 arch/x86/xen/enlighten_hvm.c  | 3 +--
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/arch/x86/include/asm/xen/hypervisor.h 
b/arch/x86/include/asm/xen/hypervisor.h
index 39171b3..42e1245 100644
--- a/arch/x86/include/asm/xen/hypervisor.h
+++ b/arch/x86/include/asm/xen/hypervisor.h
@@ -44,14 +44,14 @@ static inline uint32_t xen_cpuid_base(void)
 }
 
 #ifdef CONFIG_XEN
-extern bool xen_hvm_need_lapic(void);
+extern bool __init xen_hvm_need_lapic(void);
 
-static inline bool xen_x2apic_para_available(void)
+static inline bool __init xen_x2apic_para_available(void)
 {
return xen_hvm_need_lapic();
 }
 #else
-static inline bool xen_x2apic_para_available(void)
+static inline bool __init xen_x2apic_para_available(void)
 {
return (xen_cpuid_base() != 0);
 }
diff --git a/arch/x86/xen/enlighten_hvm.c b/arch/x86/xen/enlighten_hvm.c
index 0e75642..ac4943c 100644
--- a/arch/x86/xen/enlighten_hvm.c
+++ b/arch/x86/xen/enlighten_hvm.c
@@ -218,7 +218,7 @@ static __init int xen_parse_nopv(char *arg)
 }
 early_param("xen_nopv", xen_parse_nopv);
 
-bool xen_hvm_need_lapic(void)
+bool __init xen_hvm_need_lapic(void)
 {
if (xen_nopv)
return false;
@@ -230,7 +230,6 @@ bool xen_hvm_need_lapic(void)
return false;
return true;
 }
-EXPORT_SYMBOL_GPL(xen_hvm_need_lapic);
 
 static uint32_t __init xen_platform_hvm(void)
 {
-- 
1.8.3.1



[PATCH v4 0/5] misc fixes to PV extentions code

2019-07-01 Thread Zhenzhong Duan
Hi,

In virtualization environment, PV extensions (drivers, interrupts,
timers, etc) are enabled in the majority of use cases which is the
best option.

However, in some cases (kexec not fully working, benchmarking, etc)
we want to disable PV extensions. We have xen_nopv for that purpose
but only for XEN. For a consistent admin experience a common command
line parameter set across all PV guest implementations is a better
choice.

To achieve this introduce a new 'nopv' parameter which is usable by
most of PV guest implementation. Due to the limitation of some PV
guests(XEN PV, XEN PVH and jailhouse), 'nopv' is ignored for XEN PV
, jailhouse and XEN PVH if booting via Xen-PVH boot entry. If booting
via normal boot entry(like grub2), PVH guest has to panic itself
currently.

While analyzing the PV guest code one bug were found and fixed.
(Patches 1). It can be applied independent of the functional
changes, but is kept in the series as the functional changes
depend on them.

As I see there is an issue with xen_nopv when booting PVH guest, so
I revert 'xen_nopv' in one patch and map it back to 'nopv' in the
following patch. This is the easier way to fix the issue and easy
for review.

I didn't get env to test with jailhouse and Hyperv, the others work
as expected.

v4:
PATCH5 a new patch to add 'xen_nopv' back per Boris

v3:
Remove some unrelated patches from patchset as suggested by Tglx

PATCH1 unchanged
PATCH2 add Reviewed-by
PATCH3 add Reviewed-by
PATCH4 rewrite the patch as Jgross found an issue in old patch,
description is also updated.



v2:
PATCH3 use 'ignore_nopv' for PVH/PV guest as suggested by Jgross.
PATCH5 new added one, specifically for HVM guest

Thanks
Zhenzhong


[PATCH v4 4/5] x86/xen: Add 'nopv' support for HVM guest

2019-07-01 Thread Zhenzhong Duan
PVH guest needs PV extentions to work, so 'nopv' parameter should be
ignored for PVH but not for HVM guest.

If PVH guest boots up via the Xen-PVH boot entry, xen_pvh is set early,
we know it's PVH guest and ignore 'nopv' parameter directly.

If PVH guest boots up via the normal boot entry same as HVM guest, it's
hard to distinguish PVH and HVM guest at that time.

To handle that case, add a new function xen_hvm_nopv_guest_late_init()
to detect PVH at a late time and panic itself if 'nopv' enabled for a
PVH guest.

Signed-off-by: Zhenzhong Duan 
Cc: Boris Ostrovsky 
Cc: Juergen Gross 
Cc: Stefano Stabellini 
Cc: Thomas Gleixner 
Cc: Ingo Molnar 
Cc: Borislav Petkov 
---
 arch/x86/xen/enlighten_hvm.c | 27 +++
 1 file changed, 27 insertions(+)

diff --git a/arch/x86/xen/enlighten_hvm.c b/arch/x86/xen/enlighten_hvm.c
index 7fcb4ea..340dff8 100644
--- a/arch/x86/xen/enlighten_hvm.c
+++ b/arch/x86/xen/enlighten_hvm.c
@@ -25,6 +25,7 @@
 #include "mmu.h"
 #include "smp.h"
 
+extern bool nopv;
 static unsigned long shared_info_pfn;
 
 void xen_hvm_init_shared_info(void)
@@ -221,11 +222,36 @@ bool __init xen_hvm_need_lapic(void)
return true;
 }
 
+static __init void xen_hvm_nopv_guest_late_init(void)
+{
+#ifdef CONFIG_XEN_PVH
+   if (x86_platform.legacy.rtc || !x86_platform.legacy.no_vga)
+   return;
+
+   /* PVH detected. */
+   xen_pvh = true;
+
+   panic("nopv parameter isn't supported in PVH guest.");
+#endif
+}
+
+
 static uint32_t __init xen_platform_hvm(void)
 {
if (xen_pv_domain())
return 0;
 
+   if (xen_pvh_domain() && nopv) {
+   /* Guest booting via the Xen-PVH boot entry goes here */
+   pr_info("nopv parameter is ignored in PVH guest\n");
+   } else if (nopv) {
+   /*
+* Guest booting via normal boot entry (like via grub2) goes
+* here.
+*/
+   x86_init.hyper.guest_late_init = xen_hvm_nopv_guest_late_init;
+   return 0;
+   }
return xen_cpuid_base();
 }
 
@@ -258,4 +284,5 @@ static __init void xen_hvm_guest_late_init(void)
.init.init_mem_mapping  = xen_hvm_init_mem_mapping,
.init.guest_late_init   = xen_hvm_guest_late_init,
.runtime.pin_vcpu   = xen_pin_vcpu,
+   .ignore_nopv= true,
 };
-- 
1.8.3.1



  1   2   3   4   5   6   7   8   9   >