Skip to content

Commit 3d3a908

Browse files
neerajupadhyasean-jc
authored andcommitted
x86/apic: KVM: Move lapic get/set helpers to common code
Move the apic_get_reg(), apic_set_reg(), apic_get_reg64() and apic_set_reg64() helper functions to apic.h in order to reuse them in the Secure AVIC guest APIC driver in later patches to read/write registers from/to the APIC backing page. No functional change intended. Signed-off-by: Neeraj Upadhyay <Neeraj.Upadhyay@amd.com> Acked-by: Sean Christopherson <seanjc@google.com> Link: https://lore.kernel.org/r/20250709033242.267892-12-Neeraj.Upadhyay@amd.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 39e8163 commit 3d3a908

File tree

3 files changed

+24
-22
lines changed

3 files changed

+24
-22
lines changed

arch/x86/include/asm/apic.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,28 @@ static inline int apic_find_highest_vector(void *bitmap)
525525
return -1;
526526
}
527527

528+
static inline u32 apic_get_reg(void *regs, int reg_off)
529+
{
530+
return *((u32 *) (regs + reg_off));
531+
}
532+
533+
static inline void apic_set_reg(void *regs, int reg_off, u32 val)
534+
{
535+
*((u32 *) (regs + reg_off)) = val;
536+
}
537+
538+
static __always_inline u64 apic_get_reg64(void *regs, int reg)
539+
{
540+
BUILD_BUG_ON(reg != APIC_ICR);
541+
return *((u64 *) (regs + reg));
542+
}
543+
544+
static __always_inline void apic_set_reg64(void *regs, int reg, u64 val)
545+
{
546+
BUILD_BUG_ON(reg != APIC_ICR);
547+
*((u64 *) (regs + reg)) = val;
548+
}
549+
528550
/*
529551
* Warm reset vector position:
530552
*/

arch/x86/kvm/lapic.c

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -77,33 +77,16 @@ module_param(lapic_timer_advance, bool, 0444);
7777
static int kvm_lapic_msr_read(struct kvm_lapic *apic, u32 reg, u64 *data);
7878
static int kvm_lapic_msr_write(struct kvm_lapic *apic, u32 reg, u64 data);
7979

80-
static inline void apic_set_reg(void *regs, int reg_off, u32 val)
81-
{
82-
*((u32 *) (regs + reg_off)) = val;
83-
}
84-
8580
static inline void kvm_lapic_set_reg(struct kvm_lapic *apic, int reg_off, u32 val)
8681
{
8782
apic_set_reg(apic->regs, reg_off, val);
8883
}
8984

90-
static __always_inline u64 apic_get_reg64(void *regs, int reg)
91-
{
92-
BUILD_BUG_ON(reg != APIC_ICR);
93-
return *((u64 *) (regs + reg));
94-
}
95-
9685
static __always_inline u64 kvm_lapic_get_reg64(struct kvm_lapic *apic, int reg)
9786
{
9887
return apic_get_reg64(apic->regs, reg);
9988
}
10089

101-
static __always_inline void apic_set_reg64(void *regs, int reg, u64 val)
102-
{
103-
BUILD_BUG_ON(reg != APIC_ICR);
104-
*((u64 *) (regs + reg)) = val;
105-
}
106-
10790
static __always_inline void kvm_lapic_set_reg64(struct kvm_lapic *apic,
10891
int reg, u64 val)
10992
{

arch/x86/kvm/lapic.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#include <kvm/iodev.h>
66

7+
#include <asm/apic.h>
8+
79
#include <linux/kvm_host.h>
810

911
#include "hyperv.h"
@@ -165,11 +167,6 @@ static inline void kvm_lapic_set_irr(int vec, struct kvm_lapic *apic)
165167
apic->irr_pending = true;
166168
}
167169

168-
static inline u32 apic_get_reg(void *regs, int reg_off)
169-
{
170-
return *((u32 *) (regs + reg_off));
171-
}
172-
173170
static inline u32 kvm_lapic_get_reg(struct kvm_lapic *apic, int reg_off)
174171
{
175172
return apic_get_reg(apic->regs, reg_off);

0 commit comments

Comments
 (0)