Skip to content

Commit 5ebd737

Browse files
committed
KVM: SVM: Don't BUG if setting up the MSR intercept bitmaps fails
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>
1 parent fb96d5c commit 5ebd737

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

arch/x86/kvm/svm/svm.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -939,15 +939,15 @@ static void svm_msr_filter_changed(struct kvm_vcpu *vcpu)
939939
}
940940
}
941941

942-
static void add_msr_offset(u32 offset)
942+
static int add_msr_offset(u32 offset)
943943
{
944944
int i;
945945

946946
for (i = 0; i < MSRPM_OFFSETS; ++i) {
947947

948948
/* Offset already in list? */
949949
if (msrpm_offsets[i] == offset)
950-
return;
950+
return 0;
951951

952952
/* Slot used by another offset? */
953953
if (msrpm_offsets[i] != MSR_INVALID)
@@ -956,17 +956,13 @@ static void add_msr_offset(u32 offset)
956956
/* Add offset to list */
957957
msrpm_offsets[i] = offset;
958958

959-
return;
959+
return 0;
960960
}
961961

962-
/*
963-
* If this BUG triggers the msrpm_offsets table has an overflow. Just
964-
* increase MSRPM_OFFSETS in this case.
965-
*/
966-
BUG();
962+
return -ENOSPC;
967963
}
968964

969-
static void init_msrpm_offsets(void)
965+
static int init_msrpm_offsets(void)
970966
{
971967
int i;
972968

@@ -976,10 +972,13 @@ static void init_msrpm_offsets(void)
976972
u32 offset;
977973

978974
offset = svm_msrpm_offset(direct_access_msrs[i].index);
979-
BUG_ON(offset == MSR_INVALID);
975+
if (WARN_ON(offset == MSR_INVALID))
976+
return -EIO;
980977

981-
add_msr_offset(offset);
978+
if (WARN_ON_ONCE(add_msr_offset(offset)))
979+
return -EIO;
982980
}
981+
return 0;
983982
}
984983

985984
void svm_copy_lbrs(struct vmcb *to_vmcb, struct vmcb *from_vmcb)
@@ -5494,7 +5493,9 @@ static __init int svm_hardware_setup(void)
54945493
}
54955494
kvm_enable_efer_bits(EFER_NX);
54965495

5497-
init_msrpm_offsets();
5496+
r = init_msrpm_offsets();
5497+
if (r)
5498+
return r;
54985499

54995500
kvm_caps.supported_xcr0 &= ~(XFEATURE_MASK_BNDREGS |
55005501
XFEATURE_MASK_BNDCSR);

0 commit comments

Comments
 (0)