Skip to contentSkip to conversation

tools lib traceevent: update KVM plugin

PATCH In review Paolo Bonzini 4 participants 12 messages Oct 1, 2015 – Oct 22, 2015 KVM

lore
Share & tools
lore

Paolo Bonzini

author maintainer
#0 lore raw

PATCH 1/1 tools lib traceevent: update KVM plugin

The format of the role word has changed through the years and the plugin was never updated; some VMX exit reasons were missing too.

---
 tools/lib/traceevent/plugin_kvm.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)
tools/lib/traceevent/plugin_kvm.c +17 -8
index 88fe83dff7cd..18536f756577 100644
@@ -124,7 +124,10 @@ static const char *disassemble(unsigned char *insn, int len, uint64_t rip,
 	_ER(WBINVD,		 54)		\
 	_ER(XSETBV,		 55)		\
 	_ER(APIC_WRITE,		 56)		\
-	_ER(INVPCID,		 58)
+	_ER(INVPCID,		 58)		\
+	_ER(PML_FULL,		 62)		\
+	_ER(XSAVES,		 63)		\
+	_ER(XRSTORS,		 64)
 
 #define SVM_EXIT_REASONS \
 	_ER(EXIT_READ_CR0,	0x000)		\
@@ -352,15 +355,18 @@ static int kvm_nested_vmexit_handler(struct trace_seq *s, struct pevent_record *
 union kvm_mmu_page_role {
 	unsigned word;
 	struct {
-		unsigned glevels:4;
 		unsigned level:4;
+		unsigned cr4_pae:1;
 		unsigned quadrant:2;
-		unsigned pad_for_nice_hex_output:6;
 		unsigned direct:1;
 		unsigned access:3;
 		unsigned invalid:1;
-		unsigned cr4_pge:1;
 		unsigned nxe:1;
+		unsigned cr0_wp:1;
+		unsigned smep_and_not_wp:1;
+		unsigned smap_and_not_wp:1;
+		unsigned pad_for_nice_hex_output:8;
+		unsigned smm:8;
 	};
 };
 
@@ -385,15 +391,18 @@ static int kvm_mmu_print_role(struct trace_seq *s, struct pevent_record *record,
 	if (pevent_is_file_bigendian(event->pevent) ==
 	    pevent_is_host_bigendian(event->pevent)) {
 
-		trace_seq_printf(s, "%u/%u q%u%s %s%s %spge %snxe",
+		trace_seq_printf(s, "%u q%u%s %s%s %spae %snxe %swp%s%s%s",
 				 role.level,
-				 role.glevels,
 				 role.quadrant,
 				 role.direct ? " direct" : "",
 				 access_str[role.access],
 				 role.invalid ? " invalid" : "",
-				 role.cr4_pge ? "" : "!",
-				 role.nxe ? "" : "!");
+				 role.cr4_pae ? "" : "!",
+				 role.nxe ? "" : "!",
+				 role.cr0_wp ? "" : "!",
+				 role.smep_and_not_wp ? " smep" : "",
+				 role.smap_and_not_wp ? " smap" : "",
+				 role.smm ? " smm" : "");
 	} else
 		trace_seq_printf(s, "WORD: %08x", role.word);
 
Signature · 1 line
2.5.0
author maintainer
#1 lore raw
Quoted 60 lines · Paolo Bonzini

The format of the role word has changed through the years and the plugin was never updated; some VMX exit reasons were missing too.

---
 tools/lib/traceevent/plugin_kvm.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)
tools/lib/traceevent/plugin_kvm.c +11 -7
index 88fe83dff7cd..18536f756577 100644
@@ -124,7 +124,10 @@ static const char *disassemble(unsigned char *insn, int len, uint64_t rip,
 	_ER(WBINVD,		 54)		\
 	_ER(XSETBV,		 55)		\
 	_ER(APIC_WRITE,		 56)		\
-	_ER(INVPCID,		 58)
+	_ER(INVPCID,		 58)		\
+	_ER(PML_FULL,		 62)		\
+	_ER(XSAVES,		 63)		\
+	_ER(XRSTORS,		 64)
 
 #define SVM_EXIT_REASONS \
 	_ER(EXIT_READ_CR0,	0x000)		\
@@ -352,15 +355,18 @@ static int kvm_nested_vmexit_handler(struct trace_seq *s, struct pevent_record *
 union kvm_mmu_page_role {
 	unsigned word;
 	struct {
-		unsigned glevels:4;
 		unsigned level:4;
+		unsigned cr4_pae:1;
 		unsigned quadrant:2;
-		unsigned pad_for_nice_hex_output:6;
 		unsigned direct:1;
 		unsigned access:3;
 		unsigned invalid:1;
-		unsigned cr4_pge:1;
 		unsigned nxe:1;
+		unsigned cr0_wp:1;
+		unsigned smep_and_not_wp:1;
+		unsigned smap_and_not_wp:1;
+		unsigned pad_for_nice_hex_output:8;
+		unsigned smm:8;
 	};
 };
 
@@ -385,15 +391,18 @@ static int kvm_mmu_print_role(struct trace_seq *s, struct pevent_record *record,
 	if (pevent_is_file_bigendian(event->pevent) ==
 	    pevent_is_host_bigendian(event->pevent)) {
 
-		trace_seq_printf(s, "%u/%u q%u%s %s%s %spge %snxe",
+		trace_seq_printf(s, "%u q%u%s %s%s %spae %snxe %swp%s%s%s",
 				 role.level,
-				 role.glevels,
 				 role.quadrant,
 				 role.direct ? " direct" : "",
 				 access_str[role.access],
 				 role.invalid ? " invalid" : "",
-				 role.cr4_pge ? "" : "!",

tools/lib/traceevent/plugin_kvm.c static int kvm_mmu_print_role(struct trace_seq *s, struct pevent_record *record, · line 408

Quoted 10 lines
tools/lib/traceevent/plugin_kvm.c +6 -1
-				 role.nxe ? "" : "!");
+				 role.cr4_pae ? "" : "!",
+				 role.nxe ? "" : "!",
+				 role.cr0_wp ? "" : "!",
+				 role.smep_and_not_wp ? " smep" : "",
+				 role.smap_and_not_wp ? " smap" : "",
+				 role.smm ? " smm" : "");
 	} else
 		trace_seq_printf(s, "WORD: %08x", role.word);
 

Ping? Arnaldo, ok to include this patch in my tree?

Paolo

#2 lore raw

Em Fri, Oct 09, 2015 at 10:10:13PM +0200, Paolo Bonzini escreveu:

Quoted 65 lines · Paolo Bonzini
Quoted 64 lines

The format of the role word has changed through the years and the plugin was never updated; some VMX exit reasons were missing too.

---
 tools/lib/traceevent/plugin_kvm.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)
tools/lib/traceevent/plugin_kvm.c +15 -8
index 88fe83dff7cd..18536f756577 100644
@@ -124,7 +124,10 @@ static const char *disassemble(unsigned char *insn, int len, uint64_t rip,
 	_ER(WBINVD,		 54)		\
 	_ER(XSETBV,		 55)		\
 	_ER(APIC_WRITE,		 56)		\
-	_ER(INVPCID,		 58)
+	_ER(INVPCID,		 58)		\
+	_ER(PML_FULL,		 62)		\
+	_ER(XSAVES,		 63)		\
+	_ER(XRSTORS,		 64)
 
 #define SVM_EXIT_REASONS \
 	_ER(EXIT_READ_CR0,	0x000)		\
@@ -352,15 +355,18 @@ static int kvm_nested_vmexit_handler(struct trace_seq *s, struct pevent_record *
 union kvm_mmu_page_role {
 	unsigned word;
 	struct {
-		unsigned glevels:4;
 		unsigned level:4;
+		unsigned cr4_pae:1;
 		unsigned quadrant:2;
-		unsigned pad_for_nice_hex_output:6;
 		unsigned direct:1;
 		unsigned access:3;
 		unsigned invalid:1;
-		unsigned cr4_pge:1;
 		unsigned nxe:1;
+		unsigned cr0_wp:1;
+		unsigned smep_and_not_wp:1;
+		unsigned smap_and_not_wp:1;
+		unsigned pad_for_nice_hex_output:8;
+		unsigned smm:8;
 	};
 };
 
@@ -385,15 +391,18 @@ static int kvm_mmu_print_role(struct trace_seq *s, struct pevent_record *record,
 	if (pevent_is_file_bigendian(event->pevent) ==
 	    pevent_is_host_bigendian(event->pevent)) {
 
-		trace_seq_printf(s, "%u/%u q%u%s %s%s %spge %snxe",
+		trace_seq_printf(s, "%u q%u%s %s%s %spae %snxe %swp%s%s%s",
 				 role.level,
-				 role.glevels,
 				 role.quadrant,
 				 role.direct ? " direct" : "",
 				 access_str[role.access],
 				 role.invalid ? " invalid" : "",
-				 role.cr4_pge ? "" : "!",
-				 role.nxe ? "" : "!");
+				 role.cr4_pae ? "" : "!",
+				 role.nxe ? "" : "!",
+				 role.cr0_wp ? "" : "!",
+				 role.smep_and_not_wp ? " smep" : "",
Quoted 8 lines

tools/lib/traceevent/plugin_kvm.c static int kvm_mmu_print_role(struct trace_seq *s, struct pevent_record *record, · line 408

Quoted 6 lines
tools/lib/traceevent/plugin_kvm.c +2 -0
+				 role.smap_and_not_wp ? " smap" : "",
+				 role.smm ? " smm" : "");
 	} else
 		trace_seq_printf(s, "WORD: %08x", role.word);
 

Ping? Arnaldo, ok to include this patch in my tree?

Applying, I saw it before, but lost track, perhaps was waiting for Steven Rostedt to chime in, but now I noticed he wasn't CCed, he is now.

- Arnaldo

#3 lore raw
Quoted 4 lines · On Tue, 20 Oct 2015 12:32:44 -0200 Arnaldo Carvalho de Melo <[email protected]>…
Quoted 1 line

Ping? Arnaldo, ok to include this patch in my tree?

Applying, I saw it before, but lost track, perhaps was waiting for Steven Rostedt to chime in, but now I noticed he wasn't CCed, he is now.

What happens if you run new perf on an older kernel. Is this new plugin going to be screwed up? Plugins should be backward compatible.

Is the plugin even still needed? I'm looking at some of the kvm events and they seem to be mostly self sufficient. What ones need a plugin today?

-- Steve

author maintainer
#4 lore raw
Quoted 2 lines · Steven Rostedt

What happens if you run new perf on an older kernel. Is this new plugin going to be screwed up? Plugins should be backward compatible.

If you run new perf on older kernel, the new plugin will print the "role" field (see kvm_mmu_print_role) slightly incorrectly. That said, the existing plugin was _also_ printing the role in a wildly wrong format, like 2.6.35 vintage; the glevels field was removed by commit 5b7e0102ae74, "KVM: MMU: Replace role.glevels with role.cr4_pae", in April 2010.

Going forward it's really unlikely that the role will change apart from adding new bits. These can be added to the plugin while keeping it backwards-compatible. Addition to the role happen when you implement new virtual MMU features such as SMEP, SMAP or SMM. That's once per year or less.

Quoted 3 lines

Is the plugin even still needed? I'm looking at some of the kvm events and they seem to be mostly self sufficient. What ones need a plugin today?

Yes, most of them are. It's only needed for kvm_mmu_get_page, kvm_mmu_prepare_zap_page and kvm_emulate_insn. The latter is only interesting if you install the disassembler library, and I wouldn't really care if it went away.

kvm_mmu_get_page and kvm_mmu_prepare_zap_page, however, have output like

    kvm_mmu_get_page: [FAILED TO PARSE] mmu_valid_gen=0x2 gfn=786432 role=1923 root_count=0 unsync=0 created=1

without the plugin vs.

kvm_mmu_get_page: new sp gfn c0000 3 q0 direct rwx !pae !nxe !wp root 0 sync

with the plugin.

Paolo

#5 lore raw
Quoted 6 lines · On Tue, 20 Oct 2015 17:19:12 +0200 Paolo Bonzini <[email protected]> wrote:
Quoted 2 lines · Steven Rostedt

What happens if you run new perf on an older kernel. Is this new plugin going to be screwed up? Plugins should be backward compatible.

Quoted 6 lines

If you run new perf on older kernel, the new plugin will print the "role" field (see kvm_mmu_print_role) slightly incorrectly. That said, the existing plugin was _also_ printing the role in a wildly wrong format, like 2.6.35 vintage; the glevels field was removed by commit 5b7e0102ae74, "KVM: MMU: Replace role.glevels with role.cr4_pae", in April 2010.

Can we add a check if glevels field exists, and do the old format if it does? I'm very strict on making sure event-parse works with all incarnations of kernels.

Quoted 18 lines

Going forward it's really unlikely that the role will change apart from adding new bits. These can be added to the plugin while keeping it backwards-compatible. Addition to the role happen when you implement new virtual MMU features such as SMEP, SMAP or SMM. That's once per year or less.

Quoted 3 lines

Is the plugin even still needed? I'm looking at some of the kvm events and they seem to be mostly self sufficient. What ones need a plugin today?

Yes, most of them are. It's only needed for kvm_mmu_get_page, kvm_mmu_prepare_zap_page and kvm_emulate_insn. The latter is only interesting if you install the disassembler library, and I wouldn't really care if it went away.

kvm_mmu_get_page and kvm_mmu_prepare_zap_page, however, have output like

Quoted 7 lines
    kvm_mmu_get_page: [FAILED TO PARSE] mmu_valid_gen=0x2 gfn=786432 role=1923 root_count=0 unsync=0 created=1

without the plugin vs.

kvm_mmu_get_page: new sp gfn c0000 3 q0 direct rwx !pae !nxe !wp root 0 sync

with the plugin.

Thanks for the update.

-- Steve

author maintainer
#6 lore raw
Quoted 10 lines · Steven Rostedt
Quoted 9 lines
Quoted 2 lines
Quoted 2 lines

What happens if you run new perf on an older kernel. Is this new plugin going to be screwed up? Plugins should be backward compatible.

If you run new perf on older kernel, the new plugin will print the "role" field (see kvm_mmu_print_role) slightly incorrectly. That said, the existing plugin was _also_ printing the role in a wildly wrong format, like 2.6.35 vintage; the glevels field was removed by commit 5b7e0102ae74, "KVM: MMU: Replace role.glevels with role.cr4_pae", in April 2010.

Quoted 3 lines

Can we add a check if glevels field exists, and do the old format if it does? I'm very strict on making sure event-parse works with all incarnations of kernels.

Note that this is not a glevels _tracepoint_ field. The tracepoint field is "role" and it is a 64-bit integer. The plugin interprets the bitfields of that integer, and the position/meaning of the bitfields has changed.

I guess I could use the mmu_valid_gen field as a proxy (it was introduced after glevels was removed), and only provide the "very old" (up to 2.6.34) and "new" (4.2+) formats. The "old" format (2.6.35-4.1) was never implemented in the plugin; it may well remain that way.

However, it frankly seems a bit academic. The parsing _will_ work, apart from printing a nonsensical role just like it has always done for the past four years.

Paolo

#7 lore raw
Quoted 3 lines · On Tue, 20 Oct 2015 17:37:43 +0200 Paolo Bonzini <[email protected]> wrote:

However, it frankly seems a bit academic. The parsing _will_ work, apart from printing a nonsensical role just like it has always done for the past four years.

I'm not going to be too picky about it. But things like this may seem academic, but it's also what we forget about, and people still use 2.6.32 kernels, and this may come back and bite us later.

But it's more likely to bite you than me, so if you don't think it's worth while, then I'm not going to push it.

-- Steve

author maintainer
#8 lore raw
Quoted 7 lines · Steven Rostedt
Quoted 3 lines · On Tue, 20 Oct 2015 17:37:43 +0200 Paolo Bonzini <[email protected]> wrote:

However, it frankly seems a bit academic. The parsing _will_ work, apart from printing a nonsensical role just like it has always done for the past four years.

Quoted 6 lines

I'm not going to be too picky about it. But things like this may seem academic, but it's also what we forget about, and people still use 2.6.32 kernels, and this may come back and bite us later.

But it's more likely to bite you than me, so if you don't think it's worth while, then I'm not going to push it.

Thanks. The role is not going to matter except in really weird cases and hopefully those are just not there in 2.6.32 kernels. Thanks also for educating me so I won't get it wrong in the future!

Paolo

#9 lore raw

Em Tue, Oct 20, 2015 at 05:49:22PM +0200, Paolo Bonzini escreveu:

Quoted 14 lines · Steven Rostedt
Quoted 11 lines
Quoted 3 lines · On Tue, 20 Oct 2015 17:37:43 +0200 Paolo Bonzini <[email protected]> wrote:

However, it frankly seems a bit academic. The parsing _will_ work, apart from printing a nonsensical role just like it has always done for the past four years.

I'm not going to be too picky about it. But things like this may seem academic, but it's also what we forget about, and people still use 2.6.32 kernels, and this may come back and bite us later.

Quoted 6 lines
Quoted 2 lines

But it's more likely to bite you than me, so if you don't think it's worth while, then I'm not going to push it.

Thanks. The role is not going to matter except in really weird cases and hopefully those are just not there in 2.6.32 kernels. Thanks also for educating me so I won't get it wrong in the future!

Cool, Steven, can I take that as an Acked-by for this patch?

- Arnaldo

#11 lore raw
In reply to Paolo Bonzini
tools lib traceevent: update KVM plugin
Commit-ID:  2f465deef7ce8c722121b782dd91c284f5ae80ca
Gitweb:     http://git.kernel.org/tip/2f465deef7ce8c722121b782dd91c284f5ae80ca
Author:     Paolo Bonzini <[email protected]>
AuthorDate: Thu, 1 Oct 2015 12:28:11 +0200
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Tue, 20 Oct 2015 15:54:14 -0300

tools lib traceevent: update KVM plugin

The format of the role word has changed through the years and the plugin was never updated; some VMX exit reasons were missing too.

---
 tools/lib/traceevent/plugin_kvm.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)
tools/lib/traceevent/plugin_kvm.c +17 -8
index 88fe83d..18536f7 100644
@@ -124,7 +124,10 @@ static const char *disassemble(unsigned char *insn, int len, uint64_t rip,
 	_ER(WBINVD,		 54)		\
 	_ER(XSETBV,		 55)		\
 	_ER(APIC_WRITE,		 56)		\
-	_ER(INVPCID,		 58)
+	_ER(INVPCID,		 58)		\
+	_ER(PML_FULL,		 62)		\
+	_ER(XSAVES,		 63)		\
+	_ER(XRSTORS,		 64)
 
 #define SVM_EXIT_REASONS \
 	_ER(EXIT_READ_CR0,	0x000)		\
@@ -352,15 +355,18 @@ static int kvm_nested_vmexit_handler(struct trace_seq *s, struct pevent_record *
 union kvm_mmu_page_role {
 	unsigned word;
 	struct {
-		unsigned glevels:4;
 		unsigned level:4;
+		unsigned cr4_pae:1;
 		unsigned quadrant:2;
-		unsigned pad_for_nice_hex_output:6;
 		unsigned direct:1;
 		unsigned access:3;
 		unsigned invalid:1;
-		unsigned cr4_pge:1;
 		unsigned nxe:1;
+		unsigned cr0_wp:1;
+		unsigned smep_and_not_wp:1;
+		unsigned smap_and_not_wp:1;
+		unsigned pad_for_nice_hex_output:8;
+		unsigned smm:8;
 	};
 };
 
@@ -385,15 +391,18 @@ static int kvm_mmu_print_role(struct trace_seq *s, struct pevent_record *record,
 	if (pevent_is_file_bigendian(event->pevent) ==
 	    pevent_is_host_bigendian(event->pevent)) {
 
-		trace_seq_printf(s, "%u/%u q%u%s %s%s %spge %snxe",
+		trace_seq_printf(s, "%u q%u%s %s%s %spae %snxe %swp%s%s%s",
 				 role.level,
-				 role.glevels,
 				 role.quadrant,
 				 role.direct ? " direct" : "",
 				 access_str[role.access],
 				 role.invalid ? " invalid" : "",
-				 role.cr4_pge ? "" : "!",
-				 role.nxe ? "" : "!");
+				 role.cr4_pae ? "" : "!",
+				 role.nxe ? "" : "!",
+				 role.cr0_wp ? "" : "!",
+				 role.smep_and_not_wp ? " smep" : "",
+				 role.smap_and_not_wp ? " smap" : "",
+				 role.smm ? " smm" : "");
 	} else
 		trace_seq_printf(s, "WORD: %08x", role.word);