]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
x86/apic: KVM: Move apic_find_highest_vector() to a common header
authorNeeraj Upadhyay <Neeraj.Upadhyay@amd.com>
Wed, 9 Jul 2025 03:32:17 +0000 (09:02 +0530)
committerSean Christopherson <seanjc@google.com>
Thu, 10 Jul 2025 16:44:41 +0000 (09:44 -0700)
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>
arch/x86/include/asm/apic.h
arch/x86/kvm/lapic.c

index c84d4e86fe4ed60adb23efacc94cdd4e8fedc808..c7355bcbfd603ef741419d97b71bfb91f55f789f 100644 (file)
@@ -503,6 +503,28 @@ static inline bool is_vector_pending(unsigned int vector)
        return lapic_vector_set_in_irr(vector) || pi_pending_this_cpu(vector);
 }
 
+#define MAX_APIC_VECTOR                        256
+#define APIC_VECTORS_PER_REG           32
+
+/*
+ * Vector states are maintained by APIC in 32-bit registers that are
+ * 16 bytes aligned. The status of each vector is kept in a single
+ * bit.
+ */
+static inline int apic_find_highest_vector(void *bitmap)
+{
+       int vec;
+       u32 *reg;
+
+       for (vec = MAX_APIC_VECTOR - APIC_VECTORS_PER_REG; vec >= 0; vec -= APIC_VECTORS_PER_REG) {
+               reg = bitmap + APIC_VECTOR_TO_REG_OFFSET(vec);
+               if (*reg)
+                       return __fls(*reg) + vec;
+       }
+
+       return -1;
+}
+
 /*
  * Warm reset vector position:
  */
index 27cc8dc1514e0eedd1814c15f9330545e23be89c..ace2530b24b81754471c1901eb29f953f018c6a4 100644 (file)
@@ -27,6 +27,7 @@
 #include <linux/export.h>
 #include <linux/math64.h>
 #include <linux/slab.h>
+#include <asm/apic.h>
 #include <asm/processor.h>
 #include <asm/mce.h>
 #include <asm/msr.h>
@@ -55,9 +56,6 @@
 /* 14 is the version for Xeon and Pentium 8.4.8*/
 #define APIC_VERSION                   0x14UL
 #define LAPIC_MMIO_LENGTH              (1 << 12)
-/* followed define is not in apicdef.h */
-#define MAX_APIC_VECTOR                        256
-#define APIC_VECTORS_PER_REG           32
 
 /*
  * 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] = {
        [LVT_CMCI] = LVT_MASK | APIC_MODE_MASK
 };
 
-static int apic_find_highest_vector(void *bitmap)
-{
-       int vec;
-       u32 *reg;
-
-       for (vec = MAX_APIC_VECTOR - APIC_VECTORS_PER_REG; vec >= 0; vec -= APIC_VECTORS_PER_REG) {
-               reg = bitmap + APIC_VECTOR_TO_REG_OFFSET(vec);
-               if (*reg)
-                       return __fls(*reg) + vec;
-       }
-
-       return -1;
-}
-
 static u8 count_vectors(void *bitmap)
 {
        int vec;