Skip to contentSkip to conversation

tools/kvm_stat: Fix kvm_exit filter name

PATCH Applied Gavin Shan 3 participants 7 messages Dec 10, 2019 – Jan 19, 2020 KVM

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore

Gavin Shan

author
#0 lore raw

PATCH 1/1 tools/kvm_stat: Fix kvm_exit filter name

The filter name is fixed to "exit_reason" for some kvm_exit events, no matter what architect we have. Actually, the filter name ("exit_reason") is only applicable to x86, meaning it's broken on other architects including aarch64.

This fixes the issue by providing various kvm_exit filter names, depending on architect we're on. Afterwards, the variable filter name is picked and applied through ioctl(fd, SET_FILTER).

---
 tools/kvm/kvm_stat/kvm_stat | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
tools/kvm/kvm_stat/kvm_stat +6 -2
index ad1b9e646c49..f9273614b7e3 100755
@@ -270,6 +270,7 @@ class ArchX86(Arch):
     def __init__(self, exit_reasons):
         self.sc_perf_evt_open = 298
         self.ioctl_numbers = IOCTL_NUMBERS
+        self.exit_field = 'exit_reason'
         self.exit_reasons = exit_reasons
 
     def debugfs_is_child(self, field):
@@ -289,6 +290,7 @@ class ArchPPC(Arch):
         # numbers depend on the wordsize.
         char_ptr_size = ctypes.sizeof(ctypes.c_char_p)
         self.ioctl_numbers['SET_FILTER'] = 0x80002406 | char_ptr_size << 16
+        self.exit_field = 'exit_nr'
         self.exit_reasons = {}
 
     def debugfs_is_child(self, field):
@@ -300,6 +302,7 @@ class ArchA64(Arch):
     def __init__(self):
         self.sc_perf_evt_open = 241
         self.ioctl_numbers = IOCTL_NUMBERS
+        self.exit_field = 'ret'
         self.exit_reasons = AARCH64_EXIT_REASONS
 
     def debugfs_is_child(self, field):
@@ -311,6 +314,7 @@ class ArchS390(Arch):
     def __init__(self):
         self.sc_perf_evt_open = 331
         self.ioctl_numbers = IOCTL_NUMBERS
+        self.exit_field = None
         self.exit_reasons = None
 
     def debugfs_is_child(self, field):
@@ -541,8 +545,8 @@ class TracepointProvider(Provider):
         """
         filters = {}
         filters['kvm_userspace_exit'] = ('reason', USERSPACE_EXIT_REASONS)
-        if ARCH.exit_reasons:
-            filters['kvm_exit'] = ('exit_reason', ARCH.exit_reasons)
+        if ARCH.exit_field and ARCH.exit_reasons:
+            filters['kvm_exit'] = (ARCH.exit_field, ARCH.exit_reasons)
         return filters
 
     def _get_available_fields(self):
Signature · 1 line
2.23.0
#1 lore raw
Quoted 8 lines · Gavin Shan

The filter name is fixed to "exit_reason" for some kvm_exit events, no matter what architect we have. Actually, the filter name ("exit_reason") is only applicable to x86, meaning it's broken on other architects including aarch64.

This fixes the issue by providing various kvm_exit filter names, depending on architect we're on. Afterwards, the variable filter name is picked and applied through ioctl(fd, SET_FILTER).

Would it actually make sense to standardize (to certain extent) kvm_exit tracepoints instead?

Quoted 12 lines
---
 tools/kvm/kvm_stat/kvm_stat | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
tools/kvm/kvm_stat/kvm_stat +0 -0
index ad1b9e646c49..f9273614b7e3 100755

tools/kvm/kvm_stat/kvm_stat class ArchX86(Arch): · line 273

Quoted 4 lines
tools/kvm/kvm_stat/kvm_stat +1 -0
@@ -270,6 +270,7 @@ class ArchX86(Arch):
     def __init__(self, exit_reasons):
         self.sc_perf_evt_open = 298
         self.ioctl_numbers = IOCTL_NUMBERS
+        self.exit_field = 'exit_reason'

Also, 'exit_field' name is confusing (probably because I'm thinking of VMCS fields)

Quoted 12 lines
tools/kvm/kvm_stat/kvm_stat +1 -0
         self.exit_reasons = exit_reasons
 
     def debugfs_is_child(self, field):
@@ -289,6 +290,7 @@ class ArchPPC(Arch):
         # numbers depend on the wordsize.
         char_ptr_size = ctypes.sizeof(ctypes.c_char_p)
         self.ioctl_numbers['SET_FILTER'] = 0x80002406 | char_ptr_size << 16
+        self.exit_field = 'exit_nr'
         self.exit_reasons = {}
 
     def debugfs_is_child(self, field):

tools/kvm/kvm_stat/kvm_stat class ArchA64(Arch): · line 305

Quoted 4 lines
tools/kvm/kvm_stat/kvm_stat +1 -0
@@ -300,6 +302,7 @@ class ArchA64(Arch):
     def __init__(self):
         self.sc_perf_evt_open = 241
         self.ioctl_numbers = IOCTL_NUMBERS
+        self.exit_field = 'ret'

And this is the most confusing part. Why do we have 'ret' as an exit reason in the first place?

Quoted 22 lines
tools/kvm/kvm_stat/kvm_stat +3 -2
         self.exit_reasons = AARCH64_EXIT_REASONS
 
     def debugfs_is_child(self, field):
@@ -311,6 +314,7 @@ class ArchS390(Arch):
     def __init__(self):
         self.sc_perf_evt_open = 331
         self.ioctl_numbers = IOCTL_NUMBERS
+        self.exit_field = None
         self.exit_reasons = None
 
     def debugfs_is_child(self, field):
@@ -541,8 +545,8 @@ class TracepointProvider(Provider):
         """
         filters = {}
         filters['kvm_userspace_exit'] = ('reason', USERSPACE_EXIT_REASONS)
-        if ARCH.exit_reasons:
-            filters['kvm_exit'] = ('exit_reason', ARCH.exit_reasons)
+        if ARCH.exit_field and ARCH.exit_reasons:
+            filters['kvm_exit'] = (ARCH.exit_field, ARCH.exit_reasons)
         return filters
 
     def _get_available_fields(self):
Signature · 1 line
Vitaly
author
#2 lore raw
Quoted 7 lines · Vitaly Kuznetsov
Quoted 5 lines · Gavin Shan

The filter name is fixed to "exit_reason" for some kvm_exit events, no matter what architect we have. Actually, the filter name ("exit_reason") is only applicable to x86, meaning it's broken on other architects including aarch64.

Quoted 7 lines
Quoted 3 lines

This fixes the issue by providing various kvm_exit filter names, depending on architect we're on. Afterwards, the variable filter name is picked and applied through ioctl(fd, SET_FILTER).

Would it actually make sense to standardize (to certain extent) kvm_exit tracepoints instead?

Yes, It makes sense, but it's something for future if you agree. Besides, It seems that other kvm tracepoints need standardization either.

Quoted 7 lines
Quoted 7 lines
---
  tools/kvm/kvm_stat/kvm_stat | 8 ++++++--
  1 file changed, 6 insertions(+), 2 deletions(-)
Quoted 13 lines

tools/kvm/kvm_stat/kvm_stat class ArchX86(Arch): · line 273

Quoted 9 lines
tools/kvm/kvm_stat/kvm_stat +1 -0
index ad1b9e646c49..f9273614b7e3 100755
@@ -270,6 +270,7 @@ class ArchX86(Arch):
      def __init__(self, exit_reasons):
          self.sc_perf_evt_open = 298
          self.ioctl_numbers = IOCTL_NUMBERS
+        self.exit_field = 'exit_reason'

Also, 'exit_field' name is confusing (probably because I'm thinking of VMCS fields)

Ok. How about to have 'exit_reason_field' or 'exit_filter_name'?

Quoted 10 lines
Quoted 10 lines
tools/kvm/kvm_stat/kvm_stat +1 -0
          self.exit_reasons = exit_reasons
 
      def debugfs_is_child(self, field):
@@ -289,6 +290,7 @@ class ArchPPC(Arch):
          # numbers depend on the wordsize.
          char_ptr_size = ctypes.sizeof(ctypes.c_char_p)
          self.ioctl_numbers['SET_FILTER'] = 0x80002406 | char_ptr_size << 16
+        self.exit_field = 'exit_nr'
          self.exit_reasons = {}
 
Quoted 10 lines

tools/kvm/kvm_stat/kvm_stat class ArchA64(Arch): · line 305

Quoted 6 lines
tools/kvm/kvm_stat/kvm_stat +1 -0
      def debugfs_is_child(self, field):
@@ -300,6 +302,7 @@ class ArchA64(Arch):
      def __init__(self):
          self.sc_perf_evt_open = 241
          self.ioctl_numbers = IOCTL_NUMBERS
+        self.exit_field = 'ret'

And this is the most confusing part. Why do we have 'ret' as an exit reason in the first place?

ah, it turns to be 'esr_ec', which is the class code from ESR_EL2. Will fix in v2. The field name isn't meaningful and it's to be sorted out in future standardization by the way :)

Quoted 21 lines
Quoted 21 lines
tools/kvm/kvm_stat/kvm_stat +3 -2
          self.exit_reasons = AARCH64_EXIT_REASONS
 
      def debugfs_is_child(self, field):
@@ -311,6 +314,7 @@ class ArchS390(Arch):
      def __init__(self):
          self.sc_perf_evt_open = 331
          self.ioctl_numbers = IOCTL_NUMBERS
+        self.exit_field = None
          self.exit_reasons = None
 
      def debugfs_is_child(self, field):
@@ -541,8 +545,8 @@ class TracepointProvider(Provider):
          """
          filters = {}
          filters['kvm_userspace_exit'] = ('reason', USERSPACE_EXIT_REASONS)
-        if ARCH.exit_reasons:
-            filters['kvm_exit'] = ('exit_reason', ARCH.exit_reasons)
+        if ARCH.exit_field and ARCH.exit_reasons:
+            filters['kvm_exit'] = (ARCH.exit_field, ARCH.exit_reasons)
          return filters
 
Quoted 2 lines

tools/kvm/kvm_stat/kvm_stat class TracepointProvider(Provider): · line 552

Quoted 1 line
tools/kvm/kvm_stat/kvm_stat +0 -0
      def _get_available_fields(self):

Regards,
Gavin

#3 lore raw
Quoted 12 lines · Gavin Shan
Quoted 11 lines · Vitaly Kuznetsov
Quoted 8 lines · Gavin Shan

The filter name is fixed to "exit_reason" for some kvm_exit events, no matter what architect we have. Actually, the filter name ("exit_reason") is only applicable to x86, meaning it's broken on other architects including aarch64.

This fixes the issue by providing various kvm_exit filter names, depending on architect we're on. Afterwards, the variable filter name is picked and applied through ioctl(fd, SET_FILTER).

Quoted 6 lines
Quoted 3 lines

Would it actually make sense to standardize (to certain extent) kvm_exit tracepoints instead?

Yes, It makes sense, but it's something for future if you agree. Besides, It seems that other kvm tracepoints need standardization either.

If we change kvm_stat the way you suggest we'll have reverse issues after changing tracepoints fields: updated kvm_stat won't work with the fixed kernel. I understand that kvm_stat doesn't have to work with anything but the corresponding kernel tree and so we can change it back in the same series, but wouldn't it be an unnecessary churn?

I'd suggest we standardize 'exit_reason' field name now just to fix the immediate issue, it shouldn't be a big change, probably the same size as this patch. Changing other tracepoints to match can be left for future generations :-) What do you say?

Signature · 1 line
Vitaly
author
#4 lore raw
Quoted 27 lines · Vitaly Kuznetsov
Quoted 12 lines · Gavin Shan
Quoted 11 lines · Vitaly Kuznetsov
Quoted 8 lines · Gavin Shan

The filter name is fixed to "exit_reason" for some kvm_exit events, no matter what architect we have. Actually, the filter name ("exit_reason") is only applicable to x86, meaning it's broken on other architects including aarch64.

This fixes the issue by providing various kvm_exit filter names, depending on architect we're on. Afterwards, the variable filter name is picked and applied through ioctl(fd, SET_FILTER).

Quoted 6 lines
Quoted 3 lines

Would it actually make sense to standardize (to certain extent) kvm_exit tracepoints instead?

Yes, It makes sense, but it's something for future if you agree. Besides, It seems that other kvm tracepoints need standardization either.

If we change kvm_stat the way you suggest we'll have reverse issues after changing tracepoints fields: updated kvm_stat won't work with the fixed kernel. I understand that kvm_stat doesn't have to work with anything but the corresponding kernel tree and so we can change it back in the same series, but wouldn't it be an unnecessary churn?

Quoted 5 lines

I'd suggest we standardize 'exit_reason' field name now just to fix the immediate issue, it shouldn't be a big change, probably the same size as this patch. Changing other tracepoints to match can be left for future generations :-) What do you say?

Fair enough. A series of patches ("Standardize kvm exit reason field") has been posted for review.

Regards,
Gavin

maintainer Applied
#5 lore raw
In reply to Gavin Shan
Quoted 53 lines · Gavin Shan

The filter name is fixed to "exit_reason" for some kvm_exit events, no matter what architect we have. Actually, the filter name ("exit_reason") is only applicable to x86, meaning it's broken on other architects including aarch64.

This fixes the issue by providing various kvm_exit filter names, depending on architect we're on. Afterwards, the variable filter name is picked and applied through ioctl(fd, SET_FILTER).

---
 tools/kvm/kvm_stat/kvm_stat | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
tools/kvm/kvm_stat/kvm_stat +4 -0
index ad1b9e646c49..f9273614b7e3 100755
@@ -270,6 +270,7 @@ class ArchX86(Arch):
     def __init__(self, exit_reasons):
         self.sc_perf_evt_open = 298
         self.ioctl_numbers = IOCTL_NUMBERS
+        self.exit_field = 'exit_reason'
         self.exit_reasons = exit_reasons
 
     def debugfs_is_child(self, field):
@@ -289,6 +290,7 @@ class ArchPPC(Arch):
         # numbers depend on the wordsize.
         char_ptr_size = ctypes.sizeof(ctypes.c_char_p)
         self.ioctl_numbers['SET_FILTER'] = 0x80002406 | char_ptr_size << 16
+        self.exit_field = 'exit_nr'
         self.exit_reasons = {}
 
     def debugfs_is_child(self, field):
@@ -300,6 +302,7 @@ class ArchA64(Arch):
     def __init__(self):
         self.sc_perf_evt_open = 241
         self.ioctl_numbers = IOCTL_NUMBERS
+        self.exit_field = 'ret'
         self.exit_reasons = AARCH64_EXIT_REASONS
 
     def debugfs_is_child(self, field):
@@ -311,6 +314,7 @@ class ArchS390(Arch):
     def __init__(self):
         self.sc_perf_evt_open = 331
         self.ioctl_numbers = IOCTL_NUMBERS
+        self.exit_field = None
         self.exit_reasons = None
 
     def debugfs_is_child(self, field):

tools/kvm/kvm_stat/kvm_stat class TracepointProvider(Provider): · line 552

Quoted 10 lines
tools/kvm/kvm_stat/kvm_stat +2 -2
@@ -541,8 +545,8 @@ class TracepointProvider(Provider):
         """
         filters = {}
         filters['kvm_userspace_exit'] = ('reason', USERSPACE_EXIT_REASONS)
-        if ARCH.exit_reasons:
-            filters['kvm_exit'] = ('exit_reason', ARCH.exit_reasons)
+        if ARCH.exit_field and ARCH.exit_reasons:
+            filters['kvm_exit'] = (ARCH.exit_field, ARCH.exit_reasons)
         return filters
 
     def _get_available_fields(self):

Queued, thanks.

Paolo

author
#6 lore raw
Quoted 62 lines · Paolo Bonzini
Quoted 61 lines · Gavin Shan

The filter name is fixed to "exit_reason" for some kvm_exit events, no matter what architect we have. Actually, the filter name ("exit_reason") is only applicable to x86, meaning it's broken on other architects including aarch64.

This fixes the issue by providing various kvm_exit filter names, depending on architect we're on. Afterwards, the variable filter name is picked and applied through ioctl(fd, SET_FILTER).

---
  tools/kvm/kvm_stat/kvm_stat | 8 ++++++--
  1 file changed, 6 insertions(+), 2 deletions(-)
tools/kvm/kvm_stat/kvm_stat +6 -2
index ad1b9e646c49..f9273614b7e3 100755
@@ -270,6 +270,7 @@ class ArchX86(Arch):
      def __init__(self, exit_reasons):
          self.sc_perf_evt_open = 298
          self.ioctl_numbers = IOCTL_NUMBERS
+        self.exit_field = 'exit_reason'
          self.exit_reasons = exit_reasons
 
      def debugfs_is_child(self, field):
@@ -289,6 +290,7 @@ class ArchPPC(Arch):
          # numbers depend on the wordsize.
          char_ptr_size = ctypes.sizeof(ctypes.c_char_p)
          self.ioctl_numbers['SET_FILTER'] = 0x80002406 | char_ptr_size << 16
+        self.exit_field = 'exit_nr'
          self.exit_reasons = {}
 
      def debugfs_is_child(self, field):
@@ -300,6 +302,7 @@ class ArchA64(Arch):
      def __init__(self):
          self.sc_perf_evt_open = 241
          self.ioctl_numbers = IOCTL_NUMBERS
+        self.exit_field = 'ret'
          self.exit_reasons = AARCH64_EXIT_REASONS
 
      def debugfs_is_child(self, field):
@@ -311,6 +314,7 @@ class ArchS390(Arch):
      def __init__(self):
          self.sc_perf_evt_open = 331
          self.ioctl_numbers = IOCTL_NUMBERS
+        self.exit_field = None
          self.exit_reasons = None
 
      def debugfs_is_child(self, field):
@@ -541,8 +545,8 @@ class TracepointProvider(Provider):
          """
          filters = {}
          filters['kvm_userspace_exit'] = ('reason', USERSPACE_EXIT_REASONS)
-        if ARCH.exit_reasons:
-            filters['kvm_exit'] = ('exit_reason', ARCH.exit_reasons)
+        if ARCH.exit_field and ARCH.exit_reasons:
+            filters['kvm_exit'] = (ARCH.exit_field, ARCH.exit_reasons)
          return filters
 
Quoted 7 lines

tools/kvm/kvm_stat/kvm_stat class TracepointProvider(Provider): · line 552

Quoted 2 lines
tools/kvm/kvm_stat/kvm_stat +0 -0
      def _get_available_fields(self):

Queued, thanks.

Paolo

Paolo, actually the v2 instead of this v1 patch needs to be merged:

https://www.spinics.net/lists/kvm/msg202841.html

Thanks,
Gavin