From: David Edmondson <david.edmondson@oracle.com>
To: linux-kernel@vger.kernel.org
Cc: kvm@vger.kernel.org, Paolo Bonzini <pbonzini@redhat.com>,
Vitaly Kuznetsov <vkuznets@redhat.com>,
"H. Peter Anvin" <hpa@zytor.com>,
x86@kernel.org, Sean Christopherson <seanjc@google.com>,
Thomas Gleixner <tglx@linutronix.de>,
Joerg Roedel <joro@8bytes.org>,
Wanpeng Li <wanpengli@tencent.com>,
Borislav Petkov <bp@alien8.de>, Jim Mattson <jmattson@google.com>,
Ingo Molnar <mingo@redhat.com>,
Joao Martins <joao.m.martins@oracle.com>,
David Edmondson <david.edmondson@oracle.com>
Subject: [PATCH 6/6] KVM: VMX: pass a proper reason in kvm_emulate_instruction()
Date: Mon, 12 Apr 2021 14:09:37 +0100 [thread overview]
Message-ID: <20210412130938.68178-7-david.edmondson@oracle.com> (raw)
In-Reply-To: <20210412130938.68178-1-david.edmondson@oracle.com>
From: Joao Martins <joao.m.martins@oracle.com>
Declare various causes of emulation and use them as appropriate.
Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
Signed-off-by: David Edmondson <david.edmondson@oracle.com>
---
arch/x86/include/asm/kvm_host.h | 5 +++++
arch/x86/kvm/vmx/vmx.c | 17 +++++++++--------
2 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index e1284680cbdc..f401e7c79ded 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -1541,6 +1541,11 @@ enum {
EMULREASON_SVM_CR,
EMULREASON_SVM_DR,
EMULREASON_SVM_AVIC_UNACCEL,
+ EMULREASON_VMX_APIC_ACCESS,
+ EMULREASON_VMX_EPT_VIOLATION,
+ EMULREASON_VMX_DESC,
+ EMULREASON_VMX_INV_GUEST,
+ EMULREASON_VMX_RMODE_EX,
};
int kvm_emulate_instruction(struct kvm_vcpu *vcpu, int emulation_type,
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index 037b01b5a54b..799eb0713b76 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -1600,7 +1600,7 @@ static int skip_emulated_instruction(struct kvm_vcpu *vcpu)
#endif
kvm_rip_write(vcpu, rip);
} else {
- if (!kvm_emulate_instruction(vcpu, EMULTYPE_SKIP, 0))
+ if (!kvm_emulate_instruction(vcpu, EMULTYPE_SKIP, EMULREASON_SKIP))
return 0;
}
@@ -4738,7 +4738,7 @@ static int handle_rmode_exception(struct kvm_vcpu *vcpu,
* Cause the #SS fault with 0 error code in VM86 mode.
*/
if (((vec == GP_VECTOR) || (vec == SS_VECTOR)) && err_code == 0) {
- if (kvm_emulate_instruction(vcpu, 0, 0)) {
+ if (kvm_emulate_instruction(vcpu, 0, EMULREASON_VMX_RMODE_EX)) {
if (vcpu->arch.halt_request) {
vcpu->arch.halt_request = 0;
return kvm_vcpu_halt(vcpu);
@@ -4816,7 +4816,8 @@ static int handle_exception_nmi(struct kvm_vcpu *vcpu)
kvm_queue_exception_e(vcpu, GP_VECTOR, error_code);
return 1;
}
- return kvm_emulate_instruction(vcpu, EMULTYPE_VMWARE_GP, 0);
+ return kvm_emulate_instruction(vcpu, EMULTYPE_VMWARE_GP,
+ EMULREASON_GP);
}
/*
@@ -4930,7 +4931,7 @@ static int handle_io(struct kvm_vcpu *vcpu)
++vcpu->stat.io_exits;
if (string)
- return kvm_emulate_instruction(vcpu, 0, 0);
+ return kvm_emulate_instruction(vcpu, 0, EMULREASON_IO);
port = exit_qualification >> 16;
size = (exit_qualification & 7) + 1;
@@ -5004,7 +5005,7 @@ static int handle_set_cr4(struct kvm_vcpu *vcpu, unsigned long val)
static int handle_desc(struct kvm_vcpu *vcpu)
{
WARN_ON(!(vcpu->arch.cr4 & X86_CR4_UMIP));
- return kvm_emulate_instruction(vcpu, 0, 0);
+ return kvm_emulate_instruction(vcpu, 0, EMULREASON_VMX_DESC);
}
static int handle_cr(struct kvm_vcpu *vcpu)
@@ -5244,7 +5245,7 @@ static int handle_apic_access(struct kvm_vcpu *vcpu)
return kvm_skip_emulated_instruction(vcpu);
}
}
- return kvm_emulate_instruction(vcpu, 0, 0);
+ return kvm_emulate_instruction(vcpu, 0, EMULREASON_VMX_APIC_ACCESS);
}
static int handle_apic_eoi_induced(struct kvm_vcpu *vcpu)
@@ -5375,7 +5376,7 @@ static int handle_ept_violation(struct kvm_vcpu *vcpu)
* reconstruct the page fault error code.
*/
if (unlikely(allow_smaller_maxphyaddr && kvm_vcpu_is_illegal_gpa(vcpu, gpa)))
- return kvm_emulate_instruction(vcpu, 0, 0);
+ return kvm_emulate_instruction(vcpu, 0, EMULREASON_VMX_EPT_VIOLATION);
return kvm_mmu_page_fault(vcpu, gpa, error_code, NULL, 0);
}
@@ -5424,7 +5425,7 @@ static int handle_invalid_guest_state(struct kvm_vcpu *vcpu)
if (kvm_test_request(KVM_REQ_EVENT, vcpu))
return 1;
- if (!kvm_emulate_instruction(vcpu, 0, 0))
+ if (!kvm_emulate_instruction(vcpu, 0, EMULREASON_VMX_INV_GUEST))
return 0;
if (vmx->emulation_required && !vmx->rmode.vm86_active &&
--
2.30.2
next prev parent reply other threads:[~2021-04-12 13:10 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-12 13:09 [PATCH 0/6] KVM: x86: Make the cause of instruction emulation available to user-space David Edmondson
2021-04-12 13:09 ` [PATCH 1/6] KVM: x86: add an emulation_reason to x86_emulate_instruction() David Edmondson
2021-04-12 13:09 ` [PATCH 2/6] KVM: x86: pass emulation_reason to handle_emulation_failure() David Edmondson
2021-04-12 13:09 ` [PATCH 3/6] KVM: x86: add emulation_reason to kvm_emulate_instruction() David Edmondson
2021-04-12 13:09 ` [PATCH 4/6] KVM: x86: pass a proper reason " David Edmondson
2021-04-12 13:09 ` [PATCH 5/6] KVM: SVM: pass a proper reason in kvm_emulate_instruction() David Edmondson
2021-04-12 16:04 ` Sean Christopherson
2021-04-13 10:53 ` David Edmondson
2021-04-13 18:45 ` Aaron Lewis
2021-04-14 12:25 ` David Edmondson
2021-04-12 13:09 ` David Edmondson [this message]
2021-04-12 18:34 ` [PATCH 0/6] KVM: x86: Make the cause of instruction emulation available to user-space Jim Mattson
2021-04-13 10:54 ` David Edmondson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210412130938.68178-7-david.edmondson@oracle.com \
--to=david.edmondson@oracle.com \
--cc=bp@alien8.de \
--cc=hpa@zytor.com \
--cc=jmattson@google.com \
--cc=joao.m.martins@oracle.com \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=tglx@linutronix.de \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).