[RFC PATCH v7 12/37] x86/apic: KVM: Move lapic get/set_reg() helpers to common code

Neeraj Upadhyay posted 37 patches 4 months ago
There is a newer version of this series
[RFC PATCH v7 12/37] x86/apic: KVM: Move lapic get/set_reg() helpers to common code
Posted by Neeraj Upadhyay 4 months ago
Move the apic_get_reg() and apic_set_reg() helper functions to
apic.h in order to reuse them in the Secure AVIC guest apic driver
in later patches to read/write 32-bit registers from/to the APIC
backing page.

No functional change intended.

Signed-off-by: Neeraj Upadhyay <Neeraj.Upadhyay@amd.com>
---
Changes since v6:

 - Moved function renames outside of this patch.

 arch/x86/include/asm/apic.h | 10 ++++++++++
 arch/x86/kvm/lapic.c        |  5 -----
 arch/x86/kvm/lapic.h        |  7 ++-----
 3 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
index c7355bcbfd60..904029f6530c 100644
--- a/arch/x86/include/asm/apic.h
+++ b/arch/x86/include/asm/apic.h
@@ -525,6 +525,16 @@ static inline int apic_find_highest_vector(void *bitmap)
 	return -1;
 }
 
+static inline u32 apic_get_reg(void *regs, int reg_off)
+{
+	return *((u32 *) (regs + reg_off));
+}
+
+static inline void apic_set_reg(void *regs, int reg_off, u32 val)
+{
+	*((u32 *) (regs + reg_off)) = val;
+}
+
 /*
  * Warm reset vector position:
  */
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index f94adcdf242c..b27f111a2634 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -77,11 +77,6 @@ module_param(lapic_timer_advance, bool, 0444);
 static int kvm_lapic_msr_read(struct kvm_lapic *apic, u32 reg, u64 *data);
 static int kvm_lapic_msr_write(struct kvm_lapic *apic, u32 reg, u64 data);
 
-static inline void apic_set_reg(void *regs, int reg_off, u32 val)
-{
-	*((u32 *) (regs + reg_off)) = val;
-}
-
 static inline void kvm_lapic_set_reg(struct kvm_lapic *apic, int reg_off, u32 val)
 {
 	apic_set_reg(apic->regs, reg_off, val);
diff --git a/arch/x86/kvm/lapic.h b/arch/x86/kvm/lapic.h
index c7babae8af83..174df6996404 100644
--- a/arch/x86/kvm/lapic.h
+++ b/arch/x86/kvm/lapic.h
@@ -4,6 +4,8 @@
 
 #include <kvm/iodev.h>
 
+#include <asm/apic.h>
+
 #include <linux/kvm_host.h>
 
 #include "hyperv.h"
@@ -165,11 +167,6 @@ static inline void kvm_lapic_set_irr(int vec, struct kvm_lapic *apic)
 	apic->irr_pending = true;
 }
 
-static inline u32 apic_get_reg(void *regs, int reg_off)
-{
-	return *((u32 *) (regs + reg_off));
-}
-
 static inline u32 kvm_lapic_get_reg(struct kvm_lapic *apic, int reg_off)
 {
 	return apic_get_reg(apic->regs, reg_off);
-- 
2.34.1
Re: [RFC PATCH v7 12/37] x86/apic: KVM: Move lapic get/set_reg() helpers to common code
Posted by Sean Christopherson 3 months, 2 weeks ago
On Tue, Jun 10, 2025, Neeraj Upadhyay wrote:
> Move the apic_get_reg() and apic_set_reg() helper functions to
> apic.h in order to reuse them in the Secure AVIC guest apic driver
> in later patches to read/write 32-bit registers from/to the APIC
> backing page.

Please squash this with the next patch that moves apic_{g,s}et_reg64().  Calling
out the need to access 32-bit registers is weird and confusing, and gives the
impression that the kernel doesn't need the 64-bit accessors, which is obviously
not true.