Skip to content

Commit 39e8163

Browse files
neerajupadhyasean-jc
authored andcommitted
x86/apic: KVM: Move apic_find_highest_vector() to a common header
In preparation for using apic_find_highest_vector() in Secure AVIC guest APIC driver, move it and associated macros to apic.h. No functional change intended. Acked-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Neeraj Upadhyay <Neeraj.Upadhyay@amd.com> Link: https://lore.kernel.org/r/20250709033242.267892-11-Neeraj.Upadhyay@amd.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent b5f8980 commit 39e8163

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

arch/x86/include/asm/apic.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,28 @@ static inline bool is_vector_pending(unsigned int vector)
503503
return lapic_vector_set_in_irr(vector) || pi_pending_this_cpu(vector);
504504
}
505505

506+
#define MAX_APIC_VECTOR 256
507+
#define APIC_VECTORS_PER_REG 32
508+
509+
/*
510+
* Vector states are maintained by APIC in 32-bit registers that are
511+
* 16 bytes aligned. The status of each vector is kept in a single
512+
* bit.
513+
*/
514+
static inline int apic_find_highest_vector(void *bitmap)
515+
{
516+
int vec;
517+
u32 *reg;
518+
519+
for (vec = MAX_APIC_VECTOR - APIC_VECTORS_PER_REG; vec >= 0; vec -= APIC_VECTORS_PER_REG) {
520+
reg = bitmap + APIC_VECTOR_TO_REG_OFFSET(vec);
521+
if (*reg)
522+
return __fls(*reg) + vec;
523+
}
524+
525+
return -1;
526+
}
527+
506528
/*
507529
* Warm reset vector position:
508530
*/

arch/x86/kvm/lapic.c

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <linux/export.h>
2828
#include <linux/math64.h>
2929
#include <linux/slab.h>
30+
#include <asm/apic.h>
3031
#include <asm/processor.h>
3132
#include <asm/mce.h>
3233
#include <asm/msr.h>
@@ -55,9 +56,6 @@
5556
/* 14 is the version for Xeon and Pentium 8.4.8*/
5657
#define APIC_VERSION 0x14UL
5758
#define LAPIC_MMIO_LENGTH (1 << 12)
58-
/* followed define is not in apicdef.h */
59-
#define MAX_APIC_VECTOR 256
60-
#define APIC_VECTORS_PER_REG 32
6159

6260
/*
6361
* Enable local APIC timer advancement (tscdeadline mode only) with adaptive
@@ -616,20 +614,6 @@ static const unsigned int apic_lvt_mask[KVM_APIC_MAX_NR_LVT_ENTRIES] = {
616614
[LVT_CMCI] = LVT_MASK | APIC_MODE_MASK
617615
};
618616

619-
static int apic_find_highest_vector(void *bitmap)
620-
{
621-
int vec;
622-
u32 *reg;
623-
624-
for (vec = MAX_APIC_VECTOR - APIC_VECTORS_PER_REG; vec >= 0; vec -= APIC_VECTORS_PER_REG) {
625-
reg = bitmap + APIC_VECTOR_TO_REG_OFFSET(vec);
626-
if (*reg)
627-
return __fls(*reg) + vec;
628-
}
629-
630-
return -1;
631-
}
632-
633617
static u8 count_vectors(void *bitmap)
634618
{
635619
int vec;

0 commit comments

Comments
 (0)