Skip to contentSkip to conversation

INVD intercept change to skip instruction

PATCH In review Tom Lendacky 3 participants 5 messages Sep 24, 2020 – Sep 25, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover INVD intercept change to skip instruction

From: Tom Lendacky <[email protected]>

This series updates the INVD intercept support for both SVM and VMX to skip the instruction rather than emulating it, since emulation of this instruction is just a NOP.

For SVM, it requires creating a dedicated INVD intercept routine that invokes kvm_skip_emulated_instruction(). The current support uses the common emulate_on_interception() routine, which does not work for SEV guests, and so a Fixes: tag is added.

For VMX, which already has a dedicated INVD intercept routine, it changes kvm_emulate_instruction() into a call to kvm_skip_emulated_instruction().

Tom Lendacky (2):
KVM: SVM: Add a dedicated INVD intercept routine
KVM: VMX: Do not perform emulation for INVD intercept

 arch/x86/kvm/svm/svm.c | 8 +++++++-
 arch/x86/kvm/vmx/vmx.c | 3 ++-
 2 files changed, 9 insertions(+), 2 deletions(-)
Signature · 1 line
2.28.0
#1 lore raw

PATCH v2 1/2 KVM: SVM: Add a dedicated INVD intercept routine

From: Tom Lendacky <[email protected]>

The INVD instruction intercept performs emulation. Emulation can't be done on an SEV guest because the guest memory is encrypted.

Provide a dedicated intercept routine for the INVD intercept. And since the instruction is emulated as a NOP, just skip it instead.

Fixes 1654efcbc431 ("KVM: SVM: Add KVM_SEV_INIT command")
---
 arch/x86/kvm/svm/svm.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
arch/x86/kvm/svm/svm.c +7 -1
index c91acabf18d0..66d225899781 100644
@@ -2183,6 +2183,12 @@ static int iret_interception(struct vcpu_svm *svm)
 	return 1;
 }
 
+static int invd_interception(struct vcpu_svm *svm)
+{
+	/* Treat an INVD instruction as a NOP and just skip it. */
+	return kvm_skip_emulated_instruction(&svm->vcpu);
+}
+
 static int invlpg_interception(struct vcpu_svm *svm)
 {
 	if (!static_cpu_has(X86_FEATURE_DECODEASSISTS))
@@ -2774,7 +2780,7 @@ static int (*const svm_exit_handlers[])(struct vcpu_svm *svm) = {
 	[SVM_EXIT_RDPMC]			= rdpmc_interception,
 	[SVM_EXIT_CPUID]			= cpuid_interception,
 	[SVM_EXIT_IRET]                         = iret_interception,
-	[SVM_EXIT_INVD]                         = emulate_on_interception,
+	[SVM_EXIT_INVD]                         = invd_interception,
 	[SVM_EXIT_PAUSE]			= pause_interception,
 	[SVM_EXIT_HLT]				= halt_interception,
 	[SVM_EXIT_INVLPG]			= invlpg_interception,
Signature · 1 line
2.28.0
#2 lore raw

PATCH v2 2/2 KVM: VMX: Do not perform emulation for INVD intercept

In reply to Tom Lendacky

From: Tom Lendacky <[email protected]>

The INVD instruction is emulated as a NOP, just skip the instruction instead.

---
 arch/x86/kvm/vmx/vmx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/kvm/vmx/vmx.c +2 -1
index 8646a797b7a8..f8075d3acf9c 100644
@@ -5148,7 +5148,8 @@ static int handle_vmcall(struct kvm_vcpu *vcpu)
 
 static int handle_invd(struct kvm_vcpu *vcpu)
 {
-	return kvm_emulate_instruction(vcpu, 0);
+	/* Treat an INVD instruction as a NOP and just skip it. */
+	return kvm_skip_emulated_instruction(vcpu);
 }
 
 static int handle_invlpg(struct kvm_vcpu *vcpu)
Signature · 1 line
2.28.0
#3 lore raw
In reply to Tom Lendacky
Quoted 6 lines · Tom Lendacky

From: Tom Lendacky <[email protected]>

This series updates the INVD intercept support for both SVM and VMX to skip the instruction rather than emulating it, since emulation of this instruction is just a NOP.

Isn't INVD a serializing instruction, whereas NOP isn't? IIRC, Intel doesn't architect VM-entry or VM-exit as serializing, though they probably are in practice. I'm not sure what AMD's stance on this is.

maintainer
#4 lore raw
Quoted 11 lines · Jim Mattson
Quoted 6 lines · Tom Lendacky

From: Tom Lendacky <[email protected]>

This series updates the INVD intercept support for both SVM and VMX to skip the instruction rather than emulating it, since emulation of this instruction is just a NOP.

Isn't INVD a serializing instruction, whereas NOP isn't? IIRC, Intel doesn't architect VM-entry or VM-exit as serializing, though they probably are in practice. I'm not sure what AMD's stance on this is.

Of course that isn't changed by this patch, though.

Queuing both, but a clarification would be useful. The same applies even to CPUID.

Paolo