Skip to content

Commit 4d31d9e

Browse files
sean-jcbonzini
authored andcommitted
KVM: x86: Pass emulation type to can_emulate_instruction()
Pass the emulation type to kvm_x86_ops.can_emulate_insutrction() so that a future commit can harden KVM's SEV support to WARN on emulation scenarios that should never happen. No functional change intended. Signed-off-by: Sean Christopherson <[email protected]> Reviewed-by: Liam Merwick <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent c532f29 commit 4d31d9e

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

arch/x86/include/asm/kvm_host.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,8 @@ struct kvm_x86_ops {
14821482

14831483
int (*get_msr_feature)(struct kvm_msr_entry *entry);
14841484

1485-
bool (*can_emulate_instruction)(struct kvm_vcpu *vcpu, void *insn, int insn_len);
1485+
bool (*can_emulate_instruction)(struct kvm_vcpu *vcpu, int emul_type,
1486+
void *insn, int insn_len);
14861487

14871488
bool (*apic_init_signal_blocked)(struct kvm_vcpu *vcpu);
14881489
int (*enable_direct_tlbflush)(struct kvm_vcpu *vcpu);

arch/x86/kvm/svm/svm.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4258,7 +4258,8 @@ static void svm_enable_smi_window(struct kvm_vcpu *vcpu)
42584258
}
42594259
}
42604260

4261-
static bool svm_can_emulate_instruction(struct kvm_vcpu *vcpu, void *insn, int insn_len)
4261+
static bool svm_can_emulate_instruction(struct kvm_vcpu *vcpu, int emul_type,
4262+
void *insn, int insn_len)
42624263
{
42634264
bool smep, smap, is_user;
42644265
unsigned long cr4;

arch/x86/kvm/vmx/vmx.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,11 +1487,12 @@ static int vmx_rtit_ctl_check(struct kvm_vcpu *vcpu, u64 data)
14871487
return 0;
14881488
}
14891489

1490-
static bool vmx_can_emulate_instruction(struct kvm_vcpu *vcpu, void *insn, int insn_len)
1490+
static bool vmx_can_emulate_instruction(struct kvm_vcpu *vcpu, int emul_type,
1491+
void *insn, int insn_len)
14911492
{
14921493
/*
14931494
* Emulation of instructions in SGX enclaves is impossible as RIP does
1494-
* not point tthe failing instruction, and even if it did, the code
1495+
* not point at the failing instruction, and even if it did, the code
14951496
* stream is inaccessible. Inject #UD instead of exiting to userspace
14961497
* so that guest userspace can't DoS the guest simply by triggering
14971498
* emulation (enclaves are CPL3 only).
@@ -5425,7 +5426,7 @@ static int handle_ept_misconfig(struct kvm_vcpu *vcpu)
54255426
{
54265427
gpa_t gpa;
54275428

5428-
if (!vmx_can_emulate_instruction(vcpu, NULL, 0))
5429+
if (!vmx_can_emulate_instruction(vcpu, EMULTYPE_PF, NULL, 0))
54295430
return 1;
54305431

54315432
/*

arch/x86/kvm/x86.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6810,14 +6810,21 @@ int kvm_write_guest_virt_system(struct kvm_vcpu *vcpu, gva_t addr, void *val,
68106810
}
68116811
EXPORT_SYMBOL_GPL(kvm_write_guest_virt_system);
68126812

6813+
static int kvm_can_emulate_insn(struct kvm_vcpu *vcpu, int emul_type,
6814+
void *insn, int insn_len)
6815+
{
6816+
return static_call(kvm_x86_can_emulate_instruction)(vcpu, emul_type,
6817+
insn, insn_len);
6818+
}
6819+
68136820
int handle_ud(struct kvm_vcpu *vcpu)
68146821
{
68156822
static const char kvm_emulate_prefix[] = { __KVM_EMULATE_PREFIX };
68166823
int emul_type = EMULTYPE_TRAP_UD;
68176824
char sig[5]; /* ud2; .ascii "kvm" */
68186825
struct x86_exception e;
68196826

6820-
if (unlikely(!static_call(kvm_x86_can_emulate_instruction)(vcpu, NULL, 0)))
6827+
if (unlikely(!kvm_can_emulate_insn(vcpu, emul_type, NULL, 0)))
68216828
return 1;
68226829

68236830
if (force_emulation_prefix &&
@@ -8193,7 +8200,7 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa,
81938200
bool writeback = true;
81948201
bool write_fault_to_spt;
81958202

8196-
if (unlikely(!static_call(kvm_x86_can_emulate_instruction)(vcpu, insn, insn_len)))
8203+
if (unlikely(!kvm_can_emulate_insn(vcpu, emulation_type, insn, insn_len)))
81978204
return 1;
81988205

81998206
vcpu->arch.l1tf_flush_l1d = true;

0 commit comments

Comments
 (0)