Messages in this thread Patch in this message | | | Date | Mon, 14 Nov 2022 18:16:32 +0000 | Subject | [PATCH] KVM: x86/xen: Make number of event channels defines less magical | From | Sean Christopherson <> |
| |
Use BITS_PER_BYTE and sizeof_field() to compute the number of Xen event channels. The compat version at least uses sizeof_field(), but the regular version open codes sizeof_field(), BITS_PER_BYTE, and combines literals in the process, which makes it far too difficult to understand relatively straightforward code.
No functional change intended.
Cc: David Woodhouse <dwmw2@infradead.org> Cc: Paul Durrant <paul@xen.org> Signed-off-by: Sean Christopherson <seanjc@google.com> --- arch/x86/kvm/xen.h | 8 +++++--- include/xen/interface/event_channel.h | 6 ++++-- 2 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/arch/x86/kvm/xen.h b/arch/x86/kvm/xen.h index 532a535a9e99..c771fbed7058 100644 --- a/arch/x86/kvm/xen.h +++ b/arch/x86/kvm/xen.h @@ -9,6 +9,8 @@ #ifndef __ARCH_X86_KVM_XEN_H__ #define __ARCH_X86_KVM_XEN_H__ +#include <linux/bits.h> + #ifdef CONFIG_KVM_XEN #include <linux/jump_label_ratelimit.h> @@ -198,9 +200,9 @@ struct compat_shared_info { struct compat_arch_shared_info arch; }; -#define COMPAT_EVTCHN_2L_NR_CHANNELS (8 * \ - sizeof_field(struct compat_shared_info, \ - evtchn_pending)) +#define COMPAT_EVTCHN_2L_NR_CHANNELS \ + (sizeof_field(struct compat_shared_info, evtchn_pending) * BITS_PER_BYTE) + struct compat_vcpu_runstate_info { int state; uint64_t state_entry_time; diff --git a/include/xen/interface/event_channel.h b/include/xen/interface/event_channel.h index 5f8da466e8a9..c7b97c206226 100644 --- a/include/xen/interface/event_channel.h +++ b/include/xen/interface/event_channel.h @@ -10,6 +10,8 @@ #ifndef __XEN_PUBLIC_EVENT_CHANNEL_H__ #define __XEN_PUBLIC_EVENT_CHANNEL_H__ +#include <linux/bits.h> + #include <xen/interface/xen.h> typedef uint32_t evtchn_port_t; @@ -244,8 +246,8 @@ DEFINE_GUEST_HANDLE_STRUCT(evtchn_op); /* * 2-level ABI */ - -#define EVTCHN_2L_NR_CHANNELS (sizeof(xen_ulong_t) * sizeof(xen_ulong_t) * 64) +#define EVTCHN_2L_NR_CHANNELS \ + (sizeof_field(struct shared_info, evtchn_pending) * BITS_PER_BYTE) /* * FIFO ABI base-commit: d663b8a285986072428a6a145e5994bc275df994 -- 2.38.1.431.g37b22c650d-goog
| |