Perf kvm commands bug fix
v2 cover Perf kvm commands bug fix
his patch-set fixes perf kvm commands issues, like missed memory allocation check/free, out of range memory access and especially the issue that fails to sample guest with "perf kvm record/top" commands on Intel platforms.
The commit 634d36f82517 ("perf record: Just use "cycles:P" as the
default event") changes to use PEBS event to do sampling by default
including guest sampling. This breaks host to sample guest with commands "perf kvm record/top" on Intel platforms.
Since the change "KVM: x86/pmu: Add basic support to enable guest PEBS
via DS"[1] starts, host loses the capability to sample guest with PEBS
since all PEBS related MSRs are switched to guest value after vm-entry, like IA32_DS_AREA MSR is switched to guest GVA at vm-entry. This leads to PEBS events can't be used to sample guest by host, otherwise no guest PEBS records can be really sampled. The patches 5-6/6 fix this issue by using "cycles" event instead of PEBS event "cycles:P" to sample guest on Intel platforms.
Changes:
v1 -> v2:
* Free memory allocated by strdup().
* Check "--pfm-events" in kvm_add_default_arch_event() as well.
* Opportunistically fix the missed memory allocation and free issue in builtin-kwork.
* Comments refine.
Tests:
* Run command "perf kvm record -a && perf kvm report" and "perf kvm top" on Intel Sapphire Rapids platform, guest records can be captured successfully.
* Since no powerpc platforms on hand, doesn't check the patches on powerpc. Any test on powerpc is appreciated.
Ref:
[1] https://lore.kernel.org/all/[email protected]/
Dapeng Mi (6):
perf tools kvm: Add missed memory allocation check and free perf tools kwork: Add missed memory allocation check and free perf tools kvm: Fix the potential out of range memory access issue perf tools: Add helper x86__is_intel_cpu()
perf tools kvm: Use "cycles" to sample guest for "kvm record" on Intel perf tools kvm: Use "cycles" to sample guest for "kvm top" on Intel
tools/perf/arch/x86/util/kvm-stat.c | 51 +++++++++++ tools/perf/builtin-kvm.c | 130 ++++++++++++++++++++-------- tools/perf/builtin-kwork.c | 27 ++++-- tools/perf/util/env.c | 22 +++++ tools/perf/util/env.h | 2 + tools/perf/util/kvm-stat.h | 10 +++ 6 files changed, 203 insertions(+), 39 deletions(-)
base-commit: 6235ce77749f45cac27f630337e2fdf04e8a6c73
Signature · 1 line
2.34.1
PATCH v2 1/6 perf tools kvm: Add missed memory allocation check and free
Current code allocates rec_argv[] array, but doesn't check if the allocation is successful and explicitly free the rec_argv[] array.
Add them back.
--- tools/perf/builtin-kvm.c | 81 ++++++++++++++++++++++++++++------------ 1 file changed, 58 insertions(+), 23 deletions(-)
tools/perf/builtin-kvm.c +58 -23
@@ -1638,9 +1638,11 @@ static int kvm_events_report_vcpu(struct perf_kvm_stat *kvm)#define STRDUP_FAIL_EXIT (s) \ ({ char *_p; \ - _p = strdup(s); \ - if (!_p) \ - return -ENOMEM; \ + _p = strdup(s); \ + if (!_p) { \ + ret = -ENOMEM; \ + goto EXIT; \ + } \ _p; \ })
@@ -1688,7 +1690,7 @@ kvm_events_record(struct perf_kvm_stat *kvm, int argc, const char **argv) rec_argv[i] =STRDUP_FAIL_EXIT (record_args[i]);for (j =0 ; j < events_tp_size; j++) { - rec_argv[i++] ="-e" ; + rec_argv[i++] =STRDUP_FAIL_EXIT ("-e" ); rec_argv[i++] =STRDUP_FAIL_EXIT (kvm_events_tp[j]); }
@@ -1696,7 +1698,7 @@ kvm_events_record(struct perf_kvm_stat *kvm, int argc, const char **argv) rec_argv[i++] =STRDUP_FAIL_EXIT (kvm->file_name);for (j =1 ; j < (unsigned int )argc; j++, i++) - rec_argv[i] = argv[j]; + rec_argv[i] =STRDUP_FAIL_EXIT (argv[j]);set_option_flag (record_options,'e' ,"event" ,PARSE_OPT_HIDDEN );set_option_flag (record_options,0 ,"filter" ,PARSE_OPT_HIDDEN );
@@ -1719,7 +1721,13 @@ kvm_events_record(struct perf_kvm_stat *kvm, int argc, const char **argv)set_option_flag (record_options,0 ,"transaction" ,PARSE_OPT_DISABLED ); record_usage = kvm_stat_record_usage; -return cmd_record (i, rec_argv); + ret =cmd_record (i, rec_argv); + +EXIT: +for (i =0 ; i < rec_argc; i++) +free ((void *)rec_argv[i]); +free (rec_argv); +return ret; } static int
@@ -2006,52 +2014,79 @@ static int __cmd_record(const char *file_name, int argc, const char **argv) rec_argc = argc +2 ; rec_argv =calloc (rec_argc +1 ,sizeof (char *)); - rec_argv[i++] =strdup ("record" ); - rec_argv[i++] =strdup ("-o" ); - rec_argv[i++] =strdup (file_name); +if (!rec_argv) +return -ENOMEM ; + + rec_argv[i++] =STRDUP_FAIL_EXIT ("record" ); + rec_argv[i++] =STRDUP_FAIL_EXIT ("-o" ); + rec_argv[i++] =STRDUP_FAIL_EXIT (file_name);for (j =1 ; j < argc; j++, i++) - rec_argv[i] = argv[j]; + rec_argv[i] =STRDUP_FAIL_EXIT (argv[j]);BUG_ON (i != rec_argc); -return cmd_record (i, rec_argv); + ret =cmd_record (i, rec_argv); + +EXIT: +for (i =0 ; i < rec_argc; i++) +free ((void *)rec_argv[i]); +free (rec_argv); +return ret; }static int __cmd_report (const char *file_name,int argc,const char **argv) { -int rec_argc, i =0 , j; +int rec_argc, i =0 , j, ret;const char **rec_argv; rec_argc = argc +2 ; rec_argv =calloc (rec_argc +1 ,sizeof (char *)); - rec_argv[i++] =strdup ("report" ); - rec_argv[i++] =strdup ("-i" ); - rec_argv[i++] =strdup (file_name); +if (!rec_argv) +return -ENOMEM ; + + rec_argv[i++] =STRDUP_FAIL_EXIT ("report" ); + rec_argv[i++] =STRDUP_FAIL_EXIT ("-i" ); + rec_argv[i++] =STRDUP_FAIL_EXIT (file_name);for (j =1 ; j < argc; j++, i++) - rec_argv[i] = argv[j]; + rec_argv[i] =STRDUP_FAIL_EXIT (argv[j]);BUG_ON (i != rec_argc); -return cmd_report (i, rec_argv); + ret =cmd_report (i, rec_argv); + +EXIT: +for (i =0 ; i < rec_argc; i++) +free ((void *)rec_argv[i]); +free (rec_argv); +return ret; }static int __cmd_buildid_list (const char *file_name,int argc,const char **argv) { -int rec_argc, i =0 , j; +int rec_argc, i =0 , j, ret;const char **rec_argv; rec_argc = argc +2 ; rec_argv =calloc (rec_argc +1 ,sizeof (char *)); - rec_argv[i++] =strdup ("buildid-list" ); - rec_argv[i++] =strdup ("-i" ); - rec_argv[i++] =strdup (file_name); +if (!rec_argv) +return -ENOMEM ; + + rec_argv[i++] =STRDUP_FAIL_EXIT ("buildid-list" ); + rec_argv[i++] =STRDUP_FAIL_EXIT ("-i" ); + rec_argv[i++] =STRDUP_FAIL_EXIT (file_name);for (j =1 ; j < argc; j++, i++) - rec_argv[i] = argv[j]; + rec_argv[i] =STRDUP_FAIL_EXIT (argv[j]);BUG_ON (i != rec_argc); -return cmd_buildid_list (i, rec_argv); + ret =cmd_buildid_list (i, rec_argv); + +EXIT: +for (i =0 ; i < rec_argc; i++) +free ((void *)rec_argv[i]); +free (rec_argv); +return ret; }int cmd_kvm (int argc,const char **argv)
Signature · 1 line
2.34.1
PATCH v2 2/6 perf tools kwork: Add missed memory allocation check and free
In reply to Dapeng MiSame with previous builtin-kvm code, perf_kwork__record() doesn't check the memory allocation and explicitly free the allocated memory. Just fix it.
--- tools/perf/builtin-kwork.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-)
tools/perf/builtin-kwork.c +22 -5
@@ -2273,12 +2273,23 @@ static void setup_event_list(struct perf_kwork *kwork,pr_debug ("\n" ); } +#define STRDUP_FAIL_EXIT (s) \ + ({ char *_p; \ + _p = strdup(s); \ + if (!_p) { \ + ret = -ENOMEM; \ + goto EXIT; \ + } \ + _p; \ + }) +static int perf_kwork__record (struct perf_kwork *kwork,int argc,const char **argv) {const char **rec_argv;unsigned int rec_argc, i, j;struct kwork_class *class; +int ret;const char *const record_args[] = {"record" ,
@@ -2298,17 +2309,17 @@ static int perf_kwork__record(struct perf_kwork *kwork,return -ENOMEM ;for (i =0 ; i <ARRAY_SIZE (record_args); i++) - rec_argv[i] =strdup (record_args[i]); + rec_argv[i] =STRDUP_FAIL_EXIT (record_args[i]);list_for_each_entry (class, &kwork->class_list, list) {for (j =0 ; j < class->nr_tracepoints; j++) { - rec_argv[i++] =strdup ("-e" ); - rec_argv[i++] =strdup (class->tp_handlers[j].name); + rec_argv[i++] =STRDUP_FAIL_EXIT ("-e" ); + rec_argv[i++] =STRDUP_FAIL_EXIT (class->tp_handlers[j].name); } }for (j =1 ; j < (unsigned int )argc; j++, i++) - rec_argv[i] = argv[j]; + rec_argv[i] =STRDUP_FAIL_EXIT (argv[j]);BUG_ON (i != rec_argc);
@@ -2317,7 +2328,13 @@ static int perf_kwork__record(struct perf_kwork *kwork,pr_debug ("%s " , rec_argv[j]);pr_debug ("\n" ); -return cmd_record (i, rec_argv); + ret =cmd_record (i, rec_argv); + +EXIT: +for (i =0 ; i < rec_argc; i++) +free ((void *)rec_argv[i]); +free (rec_argv); +return ret; }int cmd_kwork (int argc,const char **argv)
Signature · 1 line
2.34.1
PATCH v2 3/6 perf tools kvm: Fix the potential out of range memory access issue
In reply to Dapeng Mikvm_add_default_arch_event() helper may add 2 extra options but it directly modifies the original argv[] array. This may cause out of range memory access. Fix this issue.
--- tools/perf/builtin-kvm.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
tools/perf/builtin-kvm.c +10 -5
@@ -2008,11 +2008,12 @@ static int __cmd_record(const char *file_name, int argc, const char **argv)int rec_argc, i =0 , j, ret;const char **rec_argv; - ret =kvm_add_default_arch_event (&argc, argv); -if (ret) -return -EINVAL ; - - rec_argc = argc +2 ; +/* +* Besides the 2 more options "-o" and "filename", +* kvm_add_default_arch_event() may add 2 extra options, +* so allocate 4 more items. +*/ + rec_argc = argc +2 +2 ; rec_argv =calloc (rec_argc +1 ,sizeof (char *));if (!rec_argv)return -ENOMEM ;
@@ -2025,6 +2026,10 @@ static int __cmd_record(const char *file_name, int argc, const char **argv)BUG_ON (i != rec_argc); + ret =kvm_add_default_arch_event (&i, rec_argv); +if (ret) + goto EXIT; + ret =cmd_record (i, rec_argv); EXIT:
Signature · 1 line
2.34.1
PATCH v2 4/6 perf tools: Add helper x86__is_intel_cpu()
In reply to Dapeng MiAdd helper x86__is_intel_cpu() to indicate if it's a x86 intel platform.
--- tools/perf/util/env.c | 22 ++++++++++++++++++++++ tools/perf/util/env.h | 2 ++ 2 files changed, 24 insertions(+)
tools/perf/util/env.c +22 -0
@@ -802,3 +802,25 @@ bool x86__is_amd_cpu(void)return is_amd; } + +bool perf_env__is_x86_intel_cpu (struct perf_env *env) +{ +static int is_intel;/* 0: Uninitialized, 1: Yes, -1: No */ + +if (is_intel ==0 ) + is_intel = env->cpuid &&strstarts (env->cpuid,"GenuineIntel" ) ?1 :-1 ; + +return is_intel >=1 ? true : false; +} + +bool x86__is_intel_cpu (void ) +{ +struct perf_env env = { .total_mem =0 , }; +bool is_intel; + +perf_env__cpuid (&env); + is_intel =perf_env__is_x86_intel_cpu (&env); +perf_env__exit (&env); + +return is_intel; +}
tools/perf/util/env.h +2 -0
@@ -201,5 +201,7 @@ void perf_env__find_br_cntr_info(struct perf_env *env,bool x86__is_amd_cpu (void );bool perf_env__is_x86_amd_cpu (struct perf_env *env); +bool x86__is_intel_cpu (void ); +bool perf_env__is_x86_intel_cpu (struct perf_env *env);#endif /* __PERF_ENV_H */
Signature · 1 line
2.34.1
PATCH v2 5/6 perf tools kvm: Use "cycles" to sample guest for "kvm record" on Intel
In reply to Dapeng MiAfter KVM supports PEBS for guest on Intel platforms
(https://lore.kernel.org/all/[email protected]/),
host loses the capability to sample guest with PEBS since all PEBS related MSRs are switched to guest value after vm-entry, like IA32_DS_AREA MSR is switched to guest GVA at vm-entry. This would lead to "perf kvm record" fails to sample guest on Intel platforms since "cycles:P" event is used to sample guest by default as below case shows.
sudo perf kvm record -a
^C[ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.787 MB perf.data.guest ]
So to ensure guest record can be sampled successfully, use "cycles" instead of "cycles:P" to sample guest record by default on Intel platforms. With this patch, the guest record can be sampled successfully.
sudo perf kvm record -a
^C[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.783 MB perf.data.guest (23 samples) ]
--- tools/perf/arch/x86/util/kvm-stat.c | 51 +++++++++++++++++++++++++++++ tools/perf/builtin-kvm.c | 10 ------ tools/perf/util/kvm-stat.h | 10 ++++++ 3 files changed, 61 insertions(+), 10 deletions(-)
tools/perf/arch/x86/util/kvm-stat.c +51 -0
@@ -3,9 +3,11 @@#include <string.h> #include "../../../util/kvm-stat.h" #include "../../../util/evsel.h" +#include "../../../util/env.h" #include <asm/svm.h> #include <asm/vmx.h> #include <asm/kvm.h> +#include <subcmd/parse-options.h> define_exit_reasons_table (vmx_exit_reasons,VMX_EXIT_REASONS );define_exit_reasons_table (svm_exit_reasons,SVM_EXIT_REASONS );
@@ -211,3 +213,52 @@ int cpu_isa_init(struct perf_kvm_stat *kvm, const char *cpuid)return 0 ; } + +/* +* After KVM supports PEBS for guest on Intel platforms +* (https://lore.kernel.org/all/[email protected]/), +* host loses the capability to sample guest with PEBS since all PEBS related +* MSRs are switched to guest value after vm-entry, like IA32_DS_AREA MSR is +* switched to guest GVA at vm-entry. This would lead to "perf kvm record" +* fails to sample guest on Intel platforms since "cycles:P" event is used to +* sample guest by default. +* +* So, to avoid this issue explicitly use "cycles" instead of "cycles:P" event +* by default to sample guest on Intel platforms. +*/ +int kvm_add_default_arch_event (int *argc,const char **argv) +{ +const char **tmp; +bool event = false; +int ret =0 , i, j = *argc; + +const struct option event_options[] = { +OPT_BOOLEAN ('e' ,"event" , &event,NULL ), +OPT_BOOLEAN (0 ,"pfm-events" , &event,NULL ), +OPT_END () + }; + +if (!x86__is_intel_cpu ()) +return 0 ; + + tmp =calloc (j +1 ,sizeof (char *)); +if (!tmp) +return -ENOMEM ; + +for (i =0 ; i < j; i++) + tmp[i] = argv[i]; + +parse_options (j, tmp, event_options,NULL ,PARSE_OPT_KEEP_UNKNOWN ); +if (!event) { + argv[j++] =STRDUP_FAIL_EXIT ("-e" ); + argv[j++] =STRDUP_FAIL_EXIT ("cycles" ); + *argc +=2 ; + } + +free (tmp); +return 0 ; + +EXIT: +free (tmp); +return ret; +}
tools/perf/builtin-kvm.c +0 -10
@@ -1636,16 +1636,6 @@ static int kvm_events_report_vcpu(struct perf_kvm_stat *kvm)return ret; } -#define STRDUP_FAIL_EXIT (s) \ - ({ char *_p; \ - _p = strdup(s); \ - if (!_p) { \ - ret = -ENOMEM; \ - goto EXIT; \ - } \ - _p; \ - }) -int __weak setup_kvm_events_tp (struct perf_kvm_stat *kvm__maybe_unused ) {return 0 ;
tools/perf/util/kvm-stat.h +10 -0
@@ -190,5 +190,15 @@ static inline struct kvm_info *kvm_info__new(void)#define kvm_info__zput (ki) do { } while (0)#endif /* HAVE_KVM_STAT_SUPPORT */ +#define STRDUP_FAIL_EXIT (s) \ + ({ char *_p; \ + _p = strdup(s); \ + if (!_p) { \ + ret = -ENOMEM; \ + goto EXIT; \ + } \ + _p; \ + }) +extern int kvm_add_default_arch_event (int *argc,const char **argv);#endif /* __PERF_KVM_STAT_H */
Signature · 1 line
2.34.1
PATCH v2 6/6 perf tools kvm: Use "cycles" to sample guest for "kvm top" on Intel
In reply to Dapeng MiAs same reason with previous patch, use "cyles" instead of "cycles:P" event by default to sample guest for "perf kvm top" command on Intel platforms.
--- tools/perf/builtin-kvm.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-)
tools/perf/builtin-kvm.c +33 -1
@@ -2084,6 +2084,38 @@ __cmd_buildid_list(const char *file_name, int argc, const char **argv)return ret; } +static int __cmd_top (int argc,const char **argv) +{ +int rec_argc, i =0 , ret; +const char **rec_argv; + +/* +* kvm_add_default_arch_event() may add 2 extra options, so +* allocate 2 more pointers in adavance. +*/ + rec_argc = argc +2 ; + rec_argv =calloc (rec_argc +1 ,sizeof (char *)); +if (!rec_argv) +return -ENOMEM ; + +for (i =0 ; i < argc; i++) + rec_argv[i] =STRDUP_FAIL_EXIT (argv[i]); + +BUG_ON (i != argc); + + ret =kvm_add_default_arch_event (&i, rec_argv); +if (ret) + goto EXIT; + + ret =cmd_top (i, rec_argv); + +EXIT: +for (i =0 ; i < rec_argc; i++) +free ((void *)rec_argv[i]); +free (rec_argv); +return ret; +} +int cmd_kvm (int argc,const char **argv) {const char *file_name =NULL ;
@@ -2144,7 +2176,7 @@ int cmd_kvm(int argc, const char **argv)else if (strlen (argv[0 ]) >2 &&strstarts ("diff" , argv[0 ]))return cmd_diff (argc, argv);else if (!strcmp (argv[0 ],"top" )) -return cmd_top (argc, argv); +return __cmd_top (argc, argv);else if (strlen (argv[0 ]) >2 &&strstarts ("buildid-list" , argv[0 ]))return __cmd_buildid_list (file_name, argc, argv);#if defined(HAVE_KVM_STAT_SUPPORT ) && defined(HAVE_LIBTRACEEVENT )
Signature · 1 line
2.34.1
Quoted 39 lines · Dapeng Mi
his patch-set fixes perf kvm commands issues, like missed memory allocation check/free, out of range memory access and especially the issue that fails to sample guest with "perf kvm record/top" commands on Intel platforms.
The commit
634d36f82517("perf record: Just use "cycles:P" as the
default event") changes to use PEBS event to do sampling by default
including guest sampling. This breaks host to sample guest with commands "perf kvm record/top" on Intel platforms.Since the change "KVM: x86/pmu: Add basic support to enable guest PEBS
via DS"[1] starts, host loses the capability to sample guest with PEBS
since all PEBS related MSRs are switched to guest value after vm-entry, likeIA32_DS_AREAMSR is switched to guest GVA at vm-entry. This leads to PEBS events can't be used to sample guest by host, otherwise no guest PEBS records can be really sampled. The patches 5-6/6 fix this issue by using "cycles" event instead of PEBS event "cycles:P" to sample guest on Intel platforms.Changes:
v1 -> v2:
* Free memory allocated bystrdup().
* Check "--pfm-events" inkvm_add_default_arch_event()as well.
* Opportunistically fix the missed memory allocation and free issue in builtin-kwork.
* Comments refine.Tests:
* Run command "perf kvm record -a && perf kvm report" and "perf kvm top" on Intel Sapphire Rapids platform, guest records can be captured successfully.
* Since no powerpc platforms on hand, doesn't check the patches on powerpc. Any test on powerpc is appreciated.
Quoted 7 lines
Dapeng Mi (6):
perf tools kvm: Add missed memory allocation check and free perf tools kwork: Add missed memory allocation check and free perf tools kvm: Fix the potential out of range memory access issue perf tools: Add helperx86__is_intel_cpu()
perf tools kvm: Use "cycles" to sample guest for "kvm record" on Intel perf tools kvm: Use "cycles" to sample guest for "kvm top" on Intel
Thanks,
Namhyung
Quoted 14 lines
tools/perf/arch/x86/util/kvm-stat.c | 51 +++++++++++ tools/perf/builtin-kvm.c | 130 ++++++++++++++++++++-------- tools/perf/builtin-kwork.c | 27 ++++-- tools/perf/util/env.c | 22 +++++ tools/perf/util/env.h | 2 + tools/perf/util/kvm-stat.h | 10 +++ 6 files changed, 203 insertions(+), 39 deletions(-)base-commit:
6235ce77749f45cac27f630337e2fdf04e8a6c73Signature · 1 line
2.34.1
Quoted 40 lines · Namhyung Kim
Quoted 39 lines · Dapeng Mi
his patch-set fixes perf kvm commands issues, like missed memory allocation check/free, out of range memory access and especially the issue that fails to sample guest with "perf kvm record/top" commands on Intel platforms.
The commit
634d36f82517("perf record: Just use "cycles:P" as the
default event") changes to use PEBS event to do sampling by default
including guest sampling. This breaks host to sample guest with commands "perf kvm record/top" on Intel platforms.Since the change "KVM: x86/pmu: Add basic support to enable guest PEBS
via DS"[1] starts, host loses the capability to sample guest with PEBS
since all PEBS related MSRs are switched to guest value after vm-entry, likeIA32_DS_AREAMSR is switched to guest GVA at vm-entry. This leads to PEBS events can't be used to sample guest by host, otherwise no guest PEBS records can be really sampled. The patches 5-6/6 fix this issue by using "cycles" event instead of PEBS event "cycles:P" to sample guest on Intel platforms.Changes:
v1 -> v2:
* Free memory allocated bystrdup().
* Check "--pfm-events" inkvm_add_default_arch_event()as well.
* Opportunistically fix the missed memory allocation and free issue in builtin-kwork.
* Comments refine.Tests:
* Run command "perf kvm record -a && perf kvm report" and "perf kvm top" on Intel Sapphire Rapids platform, guest records can be captured successfully.
* Since no powerpc platforms on hand, doesn't check the patches on powerpc. Any test on powerpc is appreciated.
Quoted 8 lines
Quoted 7 lines
Dapeng Mi (6):
perf tools kvm: Add missed memory allocation check and free perf tools kwork: Add missed memory allocation check and free perf tools kvm: Fix the potential out of range memory access issue perf tools: Add helperx86__is_intel_cpu()
perf tools kvm: Use "cycles" to sample guest for "kvm record" on Intel perf tools kvm: Use "cycles" to sample guest for "kvm top" on IntelAcked-by Namhyung Kim <[email protected]>
Namhyung, thanks for your ack. Do you think is it good to be queued or still need other acks?
Quoted 17 lines
Thanks,
NamhyungQuoted 13 lines
tools/perf/arch/x86/util/kvm-stat.c | 51 +++++++++++ tools/perf/builtin-kvm.c | 130 ++++++++++++++++++++-------- tools/perf/builtin-kwork.c | 27 ++++-- tools/perf/util/env.c | 22 +++++ tools/perf/util/env.h | 2 + tools/perf/util/kvm-stat.h | 10 +++ 6 files changed, 203 insertions(+), 39 deletions(-)base-commit:
6235ce77749f45cac27f630337e2fdf04e8a6c73Signature · 1 line
2.34.1
Quoted 10 lines · Namhyung Kim
Quoted 7 lines · Dapeng Mi
Dapeng Mi (6):
perf tools kvm: Add missed memory allocation check and free perf tools kwork: Add missed memory allocation check and free perf tools kvm: Fix the potential out of range memory access issue perf tools: Add helperx86__is_intel_cpu()
perf tools kvm: Use "cycles" to sample guest for "kvm record" on Intel perf tools kvm: Use "cycles" to sample guest for "kvm top" on IntelAcked-by Namhyung Kim <[email protected]>
Thanks, applied to perf-tools-next,
- Arnaldo
Ian Rogers
reviewerQuoted 10 lines · Dapeng Mi
his patch-set fixes perf kvm commands issues, like missed memory allocation check/free, out of range memory access and especially the issue that fails to sample guest with "perf kvm record/top" commands on Intel platforms.
The commit
634d36f82517("perf record: Just use "cycles:P" as the
default event") changes to use PEBS event to do sampling by default
including guest sampling. This breaks host to sample guest with commands "perf kvm record/top" on Intel platforms.
Huh? That change is:
``` $ git show 634d36f82517 commit 634d36f82517eb5c6a9b9ec7fe3ba19dbbcb7809 Author: Namhyung Kim <[email protected]> Date: Tue Oct 15 23:23:58 2024 -0700 perf record: Just use "cycles:P" as the default event The fallback logic can add ":u" modifier if needed. ... - bool can_profile_kernel = perf_event_paranoid_check(1); - - err = parse_event(rec->evlist, can_profile_kernel ? "cycles:P" : "cycles:Pu"); + err = parse_event(rec->evlist, "cycles:P"); ... ```
isn't the precision the same before and after? I think you've blamed the wrong patch.
The change to use cycles:P looks to come from commit 7b100989b4f6 ("perf evlist: Remove __evlist__add_default") but the old code was doing things like "evsel->precise_max = true;" so I think I was just carrying forward behavior. The use of precise_max comes from commit 4e8a5c155137 ("perf evsel: Fix max perf_event_attr.precise_ip detection") from over 6 years ago, and the behavior before that also appears to have been to use the maximum supported precision.
Apart from the blame and commit message being off I think the change is okay, delta my usual complaint that weak symbols are the devil's work.
Thanks,
Ian
Quoted 50 lines
Since the change "KVM: x86/pmu: Add basic support to enable guest PEBS
via DS"[1] starts, host loses the capability to sample guest with PEBS
since all PEBS related MSRs are switched to guest value after vm-entry, likeIA32_DS_AREAMSR is switched to guest GVA at vm-entry. This leads to PEBS events can't be used to sample guest by host, otherwise no guest PEBS records can be really sampled. The patches 5-6/6 fix this issue by using "cycles" event instead of PEBS event "cycles:P" to sample guest on Intel platforms.Changes:
v1 -> v2:
* Free memory allocated bystrdup().
* Check "--pfm-events" inkvm_add_default_arch_event()as well.
* Opportunistically fix the missed memory allocation and free issue in builtin-kwork.
* Comments refine.Tests:
* Run command "perf kvm record -a && perf kvm report" and "perf kvm top" on Intel Sapphire Rapids platform, guest records can be captured successfully.
* Since no powerpc platforms on hand, doesn't check the patches on powerpc. Any test on powerpc is appreciated.Ref:
[1] https://lore.kernel.org/all/[email protected]/Dapeng Mi (6):
perf tools kvm: Add missed memory allocation check and free perf tools kwork: Add missed memory allocation check and free perf tools kvm: Fix the potential out of range memory access issue perf tools: Add helperx86__is_intel_cpu()
perf tools kvm: Use "cycles" to sample guest for "kvm record" on Intel perf tools kvm: Use "cycles" to sample guest for "kvm top" on Inteltools/perf/arch/x86/util/kvm-stat.c | 51 +++++++++++ tools/perf/builtin-kvm.c | 130 ++++++++++++++++++++-------- tools/perf/builtin-kwork.c | 27 ++++-- tools/perf/util/env.c | 22 +++++ tools/perf/util/env.h | 2 + tools/perf/util/kvm-stat.h | 10 +++ 6 files changed, 203 insertions(+), 39 deletions(-)base-commit:
6235ce77749f45cac27f630337e2fdf04e8a6c73--
2.34.1
Quoted 39 lines · Ian Rogers
Quoted 9 lines · Dapeng Mi
his patch-set fixes perf kvm commands issues, like missed memory allocation check/free, out of range memory access and especially the issue that fails to sample guest with "perf kvm record/top" commands on Intel platforms.
The commit
634d36f82517("perf record: Just use "cycles:P" as the
default event") changes to use PEBS event to do sampling by default
including guest sampling. This breaks host to sample guest with commands "perf kvm record/top" on Intel platforms.Huh? That change is:
```$ git show 634d36f82517 commit 634d36f82517eb5c6a9b9ec7fe3ba19dbbcb7809 Author: Namhyung Kim <[email protected]> Date: Tue Oct 15 23:23:58 2024 -0700perf record: Just use "cycles:P" as the default event
The fallback logic can add ":u" modifier if needed.
...(quoted diff) +0
-3- bool can_profile_kernel = perf_event_paranoid_check(1); - - err = parse_event(rec->evlist, can_profile_kernel ?"cycles:P" : "cycles:Pu");
+ err =parse_event(rec->evlist, "cycles:P");
...
```
isn't the precision the same before and after? I think you've blamed the wrong patch.The change to use cycles:P looks to come from commit
7b100989b4f6("perf evlist: Remove__evlist__add_default") but the old code was doing things like "evsel->precise_max= true;" so I think I was just carrying forward behavior. The use ofprecise_maxcomes from commit4e8a5c155137("perf evsel: Fix max perf_event_attr.precise_ip detection") from over 6 years ago, and the behavior before that also appears to have been to use the maximum supported precision.
Quoted 3 lines
Apart from the blame and commit message being off I think the change is okay, delta my usual complaint that weak symbols are the devil's work.
Hmm, yeah, you're right. Thanks for correcting this.
Quoted 54 lines
Thanks,
IanQuoted 50 lines
Since the change "KVM: x86/pmu: Add basic support to enable guest PEBS
via DS"[1] starts, host loses the capability to sample guest with PEBS
since all PEBS related MSRs are switched to guest value after vm-entry, likeIA32_DS_AREAMSR is switched to guest GVA at vm-entry. This leads to PEBS events can't be used to sample guest by host, otherwise no guest PEBS records can be really sampled. The patches 5-6/6 fix this issue by using "cycles" event instead of PEBS event "cycles:P" to sample guest on Intel platforms.Changes:
v1 -> v2:
* Free memory allocated bystrdup().
* Check "--pfm-events" inkvm_add_default_arch_event()as well.
* Opportunistically fix the missed memory allocation and free issue in builtin-kwork.
* Comments refine.Tests:
* Run command "perf kvm record -a && perf kvm report" and "perf kvm top" on Intel Sapphire Rapids platform, guest records can be captured successfully.
* Since no powerpc platforms on hand, doesn't check the patches on powerpc. Any test on powerpc is appreciated.Ref:
[1] https://lore.kernel.org/all/[email protected]/Dapeng Mi (6):
perf tools kvm: Add missed memory allocation check and free perf tools kwork: Add missed memory allocation check and free perf tools kvm: Fix the potential out of range memory access issue perf tools: Add helperx86__is_intel_cpu()
perf tools kvm: Use "cycles" to sample guest for "kvm record" on Intel perf tools kvm: Use "cycles" to sample guest for "kvm top" on Inteltools/perf/arch/x86/util/kvm-stat.c | 51 +++++++++++ tools/perf/builtin-kvm.c | 130 ++++++++++++++++++++-------- tools/perf/builtin-kwork.c | 27 ++++-- tools/perf/util/env.c | 22 +++++ tools/perf/util/env.h | 2 + tools/perf/util/kvm-stat.h | 10 +++ 6 files changed, 203 insertions(+), 39 deletions(-)base-commit:
6235ce77749f45cac27f630337e2fdf04e8a6c73--
2.34.1
Arnaldo Carvalho de Melo
maintainerQuoted 40 lines · Dapeng
Quoted 39 lines · Ian Rogers
Quoted 9 lines · Dapeng Mi
his patch-set fixes perf kvm commands issues, like missed memory allocation check/free, out of range memory access and especially the issue that fails to sample guest with "perf kvm record/top" commands on Intel platforms.
The commit
634d36f82517("perf record: Just use "cycles:P" as the
default event") changes to use PEBS event to do sampling by default
including guest sampling. This breaks host to sample guest with commands "perf kvm record/top" on Intel platforms.Huh? That change is:
```$ git show 634d36f82517 commit 634d36f82517eb5c6a9b9ec7fe3ba19dbbcb7809 Author: Namhyung Kim <[email protected]> Date: Tue Oct 15 23:23:58 2024 -0700perf record: Just use "cycles:P" as the default event
The fallback logic can add ":u" modifier if needed.
...(quoted diff) +0
-3- bool can_profile_kernel = perf_event_paranoid_check(1); - - err = parse_event(rec->evlist, can_profile_kernel ?"cycles:P" : "cycles:Pu");
+ err =parse_event(rec->evlist, "cycles:P");
...
```
isn't the precision the same before and after? I think you've blamed the wrong patch.The change to use cycles:P looks to come from commit
7b100989b4f6("perf evlist: Remove__evlist__add_default") but the old code was doing things like "evsel->precise_max= true;" so I think I was just carrying forward behavior. The use ofprecise_maxcomes from commit4e8a5c155137("perf evsel: Fix max perf_event_attr.precise_ip detection") from over 6 years ago, and the behavior before that also appears to have been to use the maximum supported precision.
Quoted 5 lines
Quoted 3 lines
Apart from the blame and commit message being off I think the change is okay, delta my usual complaint that weak symbols are the devil's work.
Hmm, yeah, you're right. Thanks for correcting this.
Hi Dapeng,
Can you please fix the patch descriptions and Fixes references
and resubmit?
- Arnaldo
Quoted 41 lines · Arnaldo Carvalho de Melo
Quoted 40 lines · Dapeng
Quoted 39 lines · Ian Rogers
Quoted 9 lines · Dapeng Mi
his patch-set fixes perf kvm commands issues, like missed memory allocation check/free, out of range memory access and especially the issue that fails to sample guest with "perf kvm record/top" commands on Intel platforms.
The commit
634d36f82517("perf record: Just use "cycles:P" as the
default event") changes to use PEBS event to do sampling by default
including guest sampling. This breaks host to sample guest with commands "perf kvm record/top" on Intel platforms.Huh? That change is:
```$ git show 634d36f82517 commit 634d36f82517eb5c6a9b9ec7fe3ba19dbbcb7809 Author: Namhyung Kim <[email protected]> Date: Tue Oct 15 23:23:58 2024 -0700perf record: Just use "cycles:P" as the default event
The fallback logic can add ":u" modifier if needed.
...(quoted diff) +0
-3- bool can_profile_kernel = perf_event_paranoid_check(1); - - err = parse_event(rec->evlist, can_profile_kernel ?"cycles:P" : "cycles:Pu");
+ err =parse_event(rec->evlist, "cycles:P");
...
```
isn't the precision the same before and after? I think you've blamed the wrong patch.The change to use cycles:P looks to come from commit
7b100989b4f6("perf evlist: Remove__evlist__add_default") but the old code was doing things like "evsel->precise_max= true;" so I think I was just carrying forward behavior. The use ofprecise_maxcomes from commit4e8a5c155137("perf evsel: Fix max perf_event_attr.precise_ip detection") from over 6 years ago, and the behavior before that also appears to have been to use the maximum supported precision.
Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
Apart from the blame and commit message being off I think the change is okay, delta my usual complaint that weak symbols are the devil's work.
Hmm, yeah, you're right. Thanks for correcting this.
Hi Dapeng,
Can you please fix the patch descriptions and Fixes references
and resubmit?
Sure. would do. Thanks.
Quoted 2 lines
- Arnaldo