Skip to contentSkip to conversation

kvm_host: unify VM_STAT and VCPU_STAT definitions in a single place

PATCH In review Emanuele Giuseppe Esposito 4 participants 5 messages Apr 14, 2020 – Apr 15, 2020

Subsystems (11)
x86 KVM PowerPC MIPS +7 more subsystems
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 kvm_host: unify VM_STAT and VCPU_STAT definitions in a single place

The macros VM_STAT and VCPU_STAT are redundantly implemented in multiple files, each used by a different architecure to initialize the debugfs entries for statistics. Since they all have the same purpose, they can be unified in a single common definition in include/linux/kvm_host.h

---
 arch/arm64/kvm/guest.c    |  23 ++---
 arch/mips/kvm/mips.c      |  61 ++++++------
 arch/powerpc/kvm/book3s.c |  61 ++++++------
 arch/powerpc/kvm/booke.c  |  41 ++++----
 arch/s390/kvm/kvm-s390.c  | 203 +++++++++++++++++++-------------------
 arch/x86/kvm/x86.c        |  80 +++++++--------
 include/linux/kvm_host.h  |   5 +
 7 files changed, 231 insertions(+), 243 deletions(-)
arch/arm64/kvm/guest.c +10 -13
index 23ebe51410f0..8417b200bec9 100644
@@ -29,20 +29,17 @@
 
 #include "trace.h"
 
-#define VM_STAT(x) { #x, offsetof(struct kvm, stat.x), KVM_STAT_VM }
-#define VCPU_STAT(x) { #x, offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU }
-
 struct kvm_stats_debugfs_item debugfs_entries[] = {
-	VCPU_STAT(halt_successful_poll),
-	VCPU_STAT(halt_attempted_poll),
-	VCPU_STAT(halt_poll_invalid),
-	VCPU_STAT(halt_wakeup),
-	VCPU_STAT(hvc_exit_stat),
-	VCPU_STAT(wfe_exit_stat),
-	VCPU_STAT(wfi_exit_stat),
-	VCPU_STAT(mmio_exit_user),
-	VCPU_STAT(mmio_exit_kernel),
-	VCPU_STAT(exits),
+	VCPU_STAT("halt_successful_poll", halt_successful_poll),
+	VCPU_STAT("halt_attempted_poll", halt_attempted_poll),
+	VCPU_STAT("halt_poll_invalid", halt_poll_invalid),
+	VCPU_STAT("halt_wakeup", halt_wakeup),
+	VCPU_STAT("hvc_exit_stat", hvc_exit_stat),
+	VCPU_STAT("wfe_exit_stat", wfe_exit_stat),
+	VCPU_STAT("wfi_exit_stat", wfi_exit_stat),
+	VCPU_STAT("mmio_exit_user", mmio_exit_user),
+	VCPU_STAT("mmio_exit_kernel", mmio_exit_kernel),
+	VCPU_STAT("exits", exits),
 	{ NULL }
 };
 
arch/mips/kvm/mips.c +30 -31

70 lines not on this page · raw message

arch/powerpc/kvm/book3s.c +29 -32

70 lines not on this page · raw message

arch/powerpc/kvm/booke.c +19 -22

48 lines not on this page · raw message

arch/s390/kvm/kvm-s390.c +100 -103

210 lines not on this page · raw message

arch/x86/kvm/x86.c +38 -42

92 lines not on this page · raw message

include/linux/kvm_host.h +5 -0
index 6d58beb65454..2e6ead872957 100644
@@ -1130,6 +1130,11 @@ struct kvm_stats_debugfs_item {
 #define KVM_DBGFS_GET_MODE(dbgfs_item)                                         \
 	((dbgfs_item)->mode ? (dbgfs_item)->mode : 0644)
 
+#define VM_STAT(n, x, ...) 													   \
+	{ n, offsetof(struct kvm, stat.x), KVM_STAT_VM, ## __VA_ARGS__ }
+#define VCPU_STAT(n, x, ...)												   \
+	{ n, offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU, ## __VA_ARGS__ }
+
 extern struct kvm_stats_debugfs_item debugfs_entries[];
 extern struct dentry *kvm_debugfs_dir;
 
Signature · 1 line
2.25.2
Reviewed-by on v2 1/1
#1 lore raw
Quoted 40 lines · Emanuele Giuseppe Esposito

The macros VM_STAT and VCPU_STAT are redundantly implemented in multiple files, each used by a different architecure to initialize the debugfs entries for statistics. Since they all have the same purpose, they can be unified in a single common definition in include/linux/kvm_host.h

---
 arch/arm64/kvm/guest.c    |  23 ++---
 arch/mips/kvm/mips.c      |  61 ++++++------
 arch/powerpc/kvm/book3s.c |  61 ++++++------
 arch/powerpc/kvm/booke.c  |  41 ++++----
 arch/s390/kvm/kvm-s390.c  | 203 +++++++++++++++++++-------------------
 arch/x86/kvm/x86.c        |  80 +++++++--------
 include/linux/kvm_host.h  |   5 +
 7 files changed, 231 insertions(+), 243 deletions(-)
arch/arm64/kvm/guest.c +2 -13
index 23ebe51410f0..8417b200bec9 100644
@@ -29,20 +29,17 @@
 
 #include "trace.h"
 
-#define VM_STAT(x) { #x, offsetof(struct kvm, stat.x), KVM_STAT_VM }
-#define VCPU_STAT(x) { #x, offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU }
-
 struct kvm_stats_debugfs_item debugfs_entries[] = {
-	VCPU_STAT(halt_successful_poll),
-	VCPU_STAT(halt_attempted_poll),
-	VCPU_STAT(halt_poll_invalid),
-	VCPU_STAT(halt_wakeup),
-	VCPU_STAT(hvc_exit_stat),
-	VCPU_STAT(wfe_exit_stat),
-	VCPU_STAT(wfi_exit_stat),
-	VCPU_STAT(mmio_exit_user),
-	VCPU_STAT(mmio_exit_kernel),
-	VCPU_STAT(exits),
+	VCPU_STAT("halt_successful_poll", halt_successful_poll),
+	VCPU_STAT("halt_attempted_poll", halt_attempted_poll),

arch/arm64/kvm/guest.c line 44

Quoted 10 lines
arch/arm64/kvm/guest.c +8 -0
+	VCPU_STAT("halt_poll_invalid", halt_poll_invalid),
+	VCPU_STAT("halt_wakeup", halt_wakeup),
+	VCPU_STAT("hvc_exit_stat", hvc_exit_stat),
+	VCPU_STAT("wfe_exit_stat", wfe_exit_stat),
+	VCPU_STAT("wfi_exit_stat", wfi_exit_stat),
+	VCPU_STAT("mmio_exit_user", mmio_exit_user),
+	VCPU_STAT("mmio_exit_kernel", mmio_exit_kernel),
+	VCPU_STAT("exits", exits),
 	{ NULL }
 };

Patch easily reviewed with --word-diff.

[...]

include/linux/kvm_host.h struct kvm_stats_debugfs_item { · line 1135

Quoted 11 lines
include/linux/kvm_host.h +3 -0
index 6d58beb65454..2e6ead872957 100644
@@ -1130,6 +1130,11 @@ struct kvm_stats_debugfs_item {
 #define KVM_DBGFS_GET_MODE(dbgfs_item)                                         \
 	((dbgfs_item)->mode ? (dbgfs_item)->mode : 0644)
 
+#define VM_STAT(n, x, ...) 													   \
+	{ n, offsetof(struct kvm, stat.x), KVM_STAT_VM, ## __VA_ARGS__ }
+#define VCPU_STAT(n, x, ...)												   \

Not sure while you use so many whitespaces here... (maybe Paolo can strip some when applying?).

Otherwise it looks nicer that v1, thanks.

Quoted 6 lines
include/linux/kvm_host.h +2 -0
+	{ n, offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU, ## __VA_ARGS__ }
+
 extern struct kvm_stats_debugfs_item debugfs_entries[];
 extern struct dentry *kvm_debugfs_dir;
 
#2 lore raw
Quoted 63 lines · Philippe Mathieu-Daudé
Quoted 40 lines · Emanuele Giuseppe Esposito

The macros VM_STAT and VCPU_STAT are redundantly implemented in multiple files, each used by a different architecure to initialize the debugfs entries for statistics. Since they all have the same purpose, they can be unified in a single common definition in include/linux/kvm_host.h

---
  arch/arm64/kvm/guest.c    |  23 ++---
  arch/mips/kvm/mips.c      |  61 ++++++------
  arch/powerpc/kvm/book3s.c |  61 ++++++------
  arch/powerpc/kvm/booke.c  |  41 ++++----
  arch/s390/kvm/kvm-s390.c  | 203 +++++++++++++++++++-------------------
  arch/x86/kvm/x86.c        |  80 +++++++--------
  include/linux/kvm_host.h  |   5 +
  7 files changed, 231 insertions(+), 243 deletions(-)
arch/arm64/kvm/guest.c +2 -13
index 23ebe51410f0..8417b200bec9 100644
@@ -29,20 +29,17 @@
 
  #include "trace.h"
 
-#define VM_STAT(x) { #x, offsetof(struct kvm, stat.x), KVM_STAT_VM }
-#define VCPU_STAT(x) { #x, offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU }
-
  struct kvm_stats_debugfs_item debugfs_entries[] = {
-	VCPU_STAT(halt_successful_poll),
-	VCPU_STAT(halt_attempted_poll),
-	VCPU_STAT(halt_poll_invalid),
-	VCPU_STAT(halt_wakeup),
-	VCPU_STAT(hvc_exit_stat),
-	VCPU_STAT(wfe_exit_stat),
-	VCPU_STAT(wfi_exit_stat),
-	VCPU_STAT(mmio_exit_user),
-	VCPU_STAT(mmio_exit_kernel),
-	VCPU_STAT(exits),
+	VCPU_STAT("halt_successful_poll", halt_successful_poll),
+	VCPU_STAT("halt_attempted_poll", halt_attempted_poll),

arch/arm64/kvm/guest.c line 44

Quoted 10 lines
arch/arm64/kvm/guest.c +8 -0
+	VCPU_STAT("halt_poll_invalid", halt_poll_invalid),
+	VCPU_STAT("halt_wakeup", halt_wakeup),
+	VCPU_STAT("hvc_exit_stat", hvc_exit_stat),
+	VCPU_STAT("wfe_exit_stat", wfe_exit_stat),
+	VCPU_STAT("wfi_exit_stat", wfi_exit_stat),
+	VCPU_STAT("mmio_exit_user", mmio_exit_user),
+	VCPU_STAT("mmio_exit_kernel", mmio_exit_kernel),
+	VCPU_STAT("exits", exits),
  	{ NULL }
  };

Patch easily reviewed with --word-diff.

[...]

Quoted 8 lines
include/linux/kvm_host.h +0 -0
index 6d58beb65454..2e6ead872957 100644
@@ -1130,6 +1130,11 @@ struct kvm_stats_debugfs_item {
  #define KVM_DBGFS_GET_MODE(dbgfs_item)                                         \
  	((dbgfs_item)->mode ? (dbgfs_item)->mode : 0644)
 
Quoted 6 lines

include/linux/kvm_host.h struct kvm_stats_debugfs_item { · line 1135

Quoted 3 lines
include/linux/kvm_host.h +3 -0
+#define VM_STAT(n, x, ...) 													   \
+	{ n, offsetof(struct kvm, stat.x), KVM_STAT_VM, ## __VA_ARGS__ }
+#define VCPU_STAT(n, x, ...)												   \

Not sure while you use so many whitespaces here... (maybe Paolo can strip some when applying?).

I honestly am not sure why it added few more spaces than I wanted, but the idea was to follow the KVM_DBGFS_GET_MODE macro above and put the backslash at the end of the line (80th char).

Quoted 12 lines

Otherwise it looks nicer that v1, thanks.

Quoted 6 lines
include/linux/kvm_host.h +2 -0
+	{ n, offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU, ## __VA_ARGS__ }
+
  extern struct kvm_stats_debugfs_item debugfs_entries[];
  extern struct dentry *kvm_debugfs_dir;
 
maintainer Reviewed-by
#3 lore raw
Quoted 75 lines · On Wed, 15 Apr 2020 10:30:06 +0200 Emanuele Giuseppe Esposito…
Quoted 64 lines · Philippe Mathieu-Daudé
Quoted 41 lines · Emanuele Giuseppe Esposito

The macros VM_STAT and VCPU_STAT are redundantly implemented in multiple files, each used by a different architecure to initialize the debugfs entries for statistics. Since they all have the same purpose, they can be unified in a single common definition in include/linux/kvm_host.h

---
  arch/arm64/kvm/guest.c    |  23 ++---
  arch/mips/kvm/mips.c      |  61 ++++++------
  arch/powerpc/kvm/book3s.c |  61 ++++++------
  arch/powerpc/kvm/booke.c  |  41 ++++----
  arch/s390/kvm/kvm-s390.c  | 203
+++++++++++++++++++------------------- arch/x86/kvm/x86.c        |
 80 +++++++-------- include/linux/kvm_host.h  |   5 +
  7 files changed, 231 insertions(+), 243 deletions(-)
arch/arm64/kvm/guest.c +0 -1
index 23ebe51410f0..8417b200bec9 100644
@@ -29,20 +29,17 @@
 
  #include "trace.h"
 
-#define VM_STAT(x) { #x, offsetof(struct kvm, stat.x),

KVM_STAT_VM } -#define VCPU_STAT(x) { #x, offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU } -
struct kvm_stats_debugfs_item debugfs_entries[] = {

arch/arm64/kvm/guest.c +2 -10
-	VCPU_STAT(halt_successful_poll),
-	VCPU_STAT(halt_attempted_poll),
-	VCPU_STAT(halt_poll_invalid),
-	VCPU_STAT(halt_wakeup),
-	VCPU_STAT(hvc_exit_stat),
-	VCPU_STAT(wfe_exit_stat),
-	VCPU_STAT(wfi_exit_stat),
-	VCPU_STAT(mmio_exit_user),
-	VCPU_STAT(mmio_exit_kernel),
-	VCPU_STAT(exits),
+	VCPU_STAT("halt_successful_poll", halt_successful_poll),
+	VCPU_STAT("halt_attempted_poll", halt_attempted_poll),

arch/arm64/kvm/guest.c line 44

Quoted 10 lines
arch/arm64/kvm/guest.c +8 -0
+	VCPU_STAT("halt_poll_invalid", halt_poll_invalid),
+	VCPU_STAT("halt_wakeup", halt_wakeup),
+	VCPU_STAT("hvc_exit_stat", hvc_exit_stat),
+	VCPU_STAT("wfe_exit_stat", wfe_exit_stat),
+	VCPU_STAT("wfi_exit_stat", wfi_exit_stat),
+	VCPU_STAT("mmio_exit_user", mmio_exit_user),
+	VCPU_STAT("mmio_exit_kernel", mmio_exit_kernel),
+	VCPU_STAT("exits", exits),
  	{ NULL }
  };  

Patch easily reviewed with --word-diff.

[...]

Quoted 8 lines
include/linux/kvm_host.h +0 -0
index 6d58beb65454..2e6ead872957 100644
@@ -1130,6 +1130,11 @@ struct kvm_stats_debugfs_item {
  #define KVM_DBGFS_GET_MODE(dbgfs_item)
              \ ((dbgfs_item)->mode ? (dbgfs_item)->mode : 0644)
 
Quoted 9 lines

include/linux/kvm_host.h struct kvm_stats_debugfs_item { · line 1137

Quoted 6 lines
include/linux/kvm_host.h +2 -0
+#define VM_STAT(n, x, ...)
 									   \
+	{ n, offsetof(struct kvm, stat.x), KVM_STAT_VM, ##
 __VA_ARGS__ } +#define VCPU_STAT(n, x, ...)
 									   \

Not sure while you use so many whitespaces here... (maybe Paolo can strip some when applying?).

Quoted 3 lines

I honestly am not sure why it added few more spaces than I wanted, but the idea was to follow the KVM_DBGFS_GET_MODE macro above and put the backslash at the end of the line (80th char).

once the whitespace issues are fixed, you can also add

Quoted 13 lines
Quoted 12 lines

Otherwise it looks nicer that v1, thanks.

Quoted 6 lines
include/linux/kvm_host.h +1 -0
+	{ n, offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU, ##

__VA_ARGS__ } +
extern struct kvm_stats_debugfs_item debugfs_entries[]; extern struct dentry *kvm_debugfs_dir;

Acked-by on v2 1/1
#4 lore raw
In reply to Emanuele Giuseppe Esposito
Quoted 6 lines · On Tue, 14 Apr 2020 17:56:25 +0200 Emanuele Giuseppe Esposito…

The macros VM_STAT and VCPU_STAT are redundantly implemented in multiple files, each used by a different architecure to initialize the debugfs entries for statistics. Since they all have the same purpose, they can be unified in a single common definition in include/linux/kvm_host.h

Quoted 9 lines
---
 arch/arm64/kvm/guest.c    |  23 ++---
 arch/mips/kvm/mips.c      |  61 ++++++------
 arch/powerpc/kvm/book3s.c |  61 ++++++------
 arch/powerpc/kvm/booke.c  |  41 ++++----
 arch/s390/kvm/kvm-s390.c  | 203 +++++++++++++++++++-------------------
 arch/x86/kvm/x86.c        |  80 +++++++--------
 include/linux/kvm_host.h  |   5 +
 7 files changed, 231 insertions(+), 243 deletions(-)

Adds a bit of churn, but the end result does look nicer. Looks sane, but did not review in detail.