Skip to content

Commit 80d0f52

Browse files
committed
KVM: SVM: Require nrips support for SEV guests (and beyond)
Disallow SEV (and beyond) if nrips is disabled via module param, as KVM can't read guest memory to partially emulate and skip an instruction. All CPUs that support SEV support NRIPS, i.e. this is purely stopping the user from shooting themselves in the foot. Cc: Tom Lendacky <thomas.lendacky@amd.com> Link: https://lore.kernel.org/r/20230825013621.2845700-3-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent cb49631 commit 80d0f52

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

arch/x86/kvm/svm/sev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2185,7 +2185,7 @@ void __init sev_hardware_setup(void)
21852185
bool sev_es_supported = false;
21862186
bool sev_supported = false;
21872187

2188-
if (!sev_enabled || !npt_enabled)
2188+
if (!sev_enabled || !npt_enabled || !nrips)
21892189
goto out;
21902190

21912191
/*

arch/x86/kvm/svm/svm.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ static int nested = true;
203203
module_param(nested, int, S_IRUGO);
204204

205205
/* enable/disable Next RIP Save */
206-
static int nrips = true;
206+
int nrips = true;
207207
module_param(nrips, int, 0444);
208208

209209
/* enable/disable Virtual VMLOAD VMSAVE */
@@ -5156,9 +5156,11 @@ static __init int svm_hardware_setup(void)
51565156

51575157
svm_adjust_mmio_mask();
51585158

5159+
nrips = nrips && boot_cpu_has(X86_FEATURE_NRIPS);
5160+
51595161
/*
51605162
* Note, SEV setup consumes npt_enabled and enable_mmio_caching (which
5161-
* may be modified by svm_adjust_mmio_mask()).
5163+
* may be modified by svm_adjust_mmio_mask()), as well as nrips.
51625164
*/
51635165
sev_hardware_setup();
51645166

@@ -5170,11 +5172,6 @@ static __init int svm_hardware_setup(void)
51705172
goto err;
51715173
}
51725174

5173-
if (nrips) {
5174-
if (!boot_cpu_has(X86_FEATURE_NRIPS))
5175-
nrips = false;
5176-
}
5177-
51785175
enable_apicv = avic = avic && avic_hardware_setup();
51795176

51805177
if (!enable_apicv) {

arch/x86/kvm/svm/svm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#define MSRPM_OFFSETS 32
3434
extern u32 msrpm_offsets[MSRPM_OFFSETS] __read_mostly;
3535
extern bool npt_enabled;
36+
extern int nrips;
3637
extern int vgif;
3738
extern bool intercept_smi;
3839
extern bool x2avic_enabled;

0 commit comments

Comments
 (0)