]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
KVM: SVM: Don't BUG if setting up the MSR intercept bitmaps fails
authorSean Christopherson <seanjc@google.com>
Tue, 10 Jun 2025 22:57:08 +0000 (15:57 -0700)
committerSean Christopherson <seanjc@google.com>
Fri, 20 Jun 2025 20:05:40 +0000 (13:05 -0700)
WARN and reject module loading if there is a problem with KVM's MSR
interception bitmaps.  Panicking the host in this situation is inexcusable
since it is trivially easy to propagate the error up the stack.

Link: https://lore.kernel.org/r/20250610225737.156318-4-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/svm/svm.c

index 6ce35f01d410e51a5c92be983fb61e46b2ca26bd..29c90b90bc32f496e45e46a963134d4da37c3ef5 100644 (file)
@@ -939,7 +939,7 @@ static void svm_msr_filter_changed(struct kvm_vcpu *vcpu)
        }
 }
 
-static void add_msr_offset(u32 offset)
+static int add_msr_offset(u32 offset)
 {
        int i;
 
@@ -947,7 +947,7 @@ static void add_msr_offset(u32 offset)
 
                /* Offset already in list? */
                if (msrpm_offsets[i] == offset)
-                       return;
+                       return 0;
 
                /* Slot used by another offset? */
                if (msrpm_offsets[i] != MSR_INVALID)
@@ -956,17 +956,13 @@ static void add_msr_offset(u32 offset)
                /* Add offset to list */
                msrpm_offsets[i] = offset;
 
-               return;
+               return 0;
        }
 
-       /*
-        * If this BUG triggers the msrpm_offsets table has an overflow. Just
-        * increase MSRPM_OFFSETS in this case.
-        */
-       BUG();
+       return -ENOSPC;
 }
 
-static void init_msrpm_offsets(void)
+static int init_msrpm_offsets(void)
 {
        int i;
 
@@ -976,10 +972,13 @@ static void init_msrpm_offsets(void)
                u32 offset;
 
                offset = svm_msrpm_offset(direct_access_msrs[i].index);
-               BUG_ON(offset == MSR_INVALID);
+               if (WARN_ON(offset == MSR_INVALID))
+                       return -EIO;
 
-               add_msr_offset(offset);
+               if (WARN_ON_ONCE(add_msr_offset(offset)))
+                       return -EIO;
        }
+       return 0;
 }
 
 void svm_copy_lbrs(struct vmcb *to_vmcb, struct vmcb *from_vmcb)
@@ -5494,7 +5493,9 @@ static __init int svm_hardware_setup(void)
        }
        kvm_enable_efer_bits(EFER_NX);
 
-       init_msrpm_offsets();
+       r = init_msrpm_offsets();
+       if (r)
+               return r;
 
        kvm_caps.supported_xcr0 &= ~(XFEATURE_MASK_BNDREGS |
                                     XFEATURE_MASK_BNDCSR);