From: Nicolas Saenz Julienne <nsaenz@amazon.com>
To: <linux-kernel@vger.kernel.org>, <kvm@vger.kernel.org>
Cc: <pbonzini@redhat.com>, <seanjc@google.com>, <vkuznets@redhat.com>,
<linux-doc@vger.kernel.org>, <linux-hyperv@vger.kernel.org>,
<linux-arch@vger.kernel.org>,
<linux-trace-kernel@vger.kernel.org>, <graf@amazon.de>,
<dwmw2@infradead.org>, <paul@amazon.com>, <nsaenz@amazon.com>,
<mlevitsk@redhat.com>, <jgowans@amazon.com>, <corbet@lwn.net>,
<decui@microsoft.com>, <tglx@linutronix.de>, <mingo@redhat.com>,
<bp@alien8.de>, <dave.hansen@linux.intel.com>, <x86@kernel.org>,
<amoorthy@google.com>
Subject: [PATCH 11/18] KVM: x86: Pass the instruction length on memory fault user-space exits
Date: Sun, 9 Jun 2024 15:49:40 +0000 [thread overview]
Message-ID: <20240609154945.55332-12-nsaenz@amazon.com> (raw)
In-Reply-To: <20240609154945.55332-1-nsaenz@amazon.com>
In order to simplify Hyper-V VSM secure memory intercept generation in
user-space (it avoids the need of implementing an x86 instruction
decoder and the actual decoding). Pass the instruction length being run
at the time of the guest exit as part of the memory fault exit
information.
The presence of this additional information is indicated by a new
capability, KVM_CAP_FAULT_EXIT_INSN_LEN.
Signed-off-by: Nicolas Saenz Julienne <nsaenz@amazon.com>
---
Documentation/virt/kvm/api.rst | 6 +++++-
arch/x86/kvm/mmu/mmu_internal.h | 2 +-
arch/x86/kvm/x86.c | 1 +
include/linux/kvm_host.h | 3 ++-
include/uapi/linux/kvm.h | 2 ++
5 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst
index 761b99987cf1a..18ddea9c4c58a 100644
--- a/Documentation/virt/kvm/api.rst
+++ b/Documentation/virt/kvm/api.rst
@@ -7021,11 +7021,15 @@ spec refer, https://github.com/riscv/riscv-sbi-doc.
__u64 flags;
__u64 gpa;
__u64 size;
+ __u8 insn_len;
} memory_fault;
KVM_EXIT_MEMORY_FAULT indicates the vCPU has encountered a memory fault that
could not be resolved by KVM. The 'gpa' and 'size' (in bytes) describe the
-guest physical address range [gpa, gpa + size) of the fault. The 'flags' field
+guest physical address range [gpa, gpa + size) of the fault. The
+'insn_len' field describes the size (in bytes) of the instruction
+that caused the fault. It is only available if the underlying HW exposes that
+information on guest exit, otherwise it's set to 0. The 'flags' field
describes properties of the faulting access that are likely pertinent:
- KVM_MEMORY_EXIT_FLAG_READ/WRITE/EXEC - When set, indicates that the memory
diff --git a/arch/x86/kvm/mmu/mmu_internal.h b/arch/x86/kvm/mmu/mmu_internal.h
index a0cde1a0e39b0..4f5c4c8af9941 100644
--- a/arch/x86/kvm/mmu/mmu_internal.h
+++ b/arch/x86/kvm/mmu/mmu_internal.h
@@ -285,7 +285,7 @@ static inline void kvm_mmu_prepare_memory_fault_exit(struct kvm_vcpu *vcpu,
{
kvm_prepare_memory_fault_exit(vcpu, fault->gfn << PAGE_SHIFT,
PAGE_SIZE, fault->write, fault->exec,
- fault->is_private);
+ fault->is_private, fault->insn_len);
}
static inline int kvm_mmu_do_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa,
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index a6e2312ccb68f..d2b8b74cb48bf 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -4704,6 +4704,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
case KVM_CAP_VM_DISABLE_NX_HUGE_PAGES:
case KVM_CAP_IRQFD_RESAMPLE:
case KVM_CAP_MEMORY_FAULT_INFO:
+ case KVM_CAP_FAULT_EXIT_INSN_LEN:
r = 1;
break;
case KVM_CAP_EXIT_HYPERCALL:
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 59f687985ba24..4fa16c4772269 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -2391,11 +2391,12 @@ static inline void kvm_account_pgtable_pages(void *virt, int nr)
static inline void kvm_prepare_memory_fault_exit(struct kvm_vcpu *vcpu,
gpa_t gpa, gpa_t size,
bool is_write, bool is_exec,
- bool is_private)
+ bool is_private, u8 insn_len)
{
vcpu->run->exit_reason = KVM_EXIT_MEMORY_FAULT;
vcpu->run->memory_fault.gpa = gpa;
vcpu->run->memory_fault.size = size;
+ vcpu->run->memory_fault.insn_len = insn_len;
vcpu->run->memory_fault.flags = 0;
diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
index d6d8b17bfa9a7..516d39910f9ab 100644
--- a/include/uapi/linux/kvm.h
+++ b/include/uapi/linux/kvm.h
@@ -441,6 +441,7 @@ struct kvm_run {
__u64 flags;
__u64 gpa;
__u64 size;
+ __u8 insn_len;
} memory_fault;
/* Fix the size of the union. */
char padding[256];
@@ -927,6 +928,7 @@ struct kvm_enable_cap {
#define KVM_CAP_MEMORY_ATTRIBUTES 233
#define KVM_CAP_GUEST_MEMFD 234
#define KVM_CAP_VM_TYPES 235
+#define KVM_CAP_FAULT_EXIT_INSN_LEN 236
struct kvm_irq_routing_irqchip {
__u32 irqchip;
--
2.40.1
next prev parent reply other threads:[~2024-06-09 15:56 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-09 15:49 [PATCH 00/18] Introducing Core Building Blocks for Hyper-V VSM Emulation Nicolas Saenz Julienne
2024-06-09 15:49 ` [PATCH 01/18] KVM: x86: hyper-v: Introduce XMM output support Nicolas Saenz Julienne
2024-07-08 14:59 ` Vitaly Kuznetsov
2024-07-17 14:12 ` Nicolas Saenz Julienne
2024-07-29 13:53 ` Vitaly Kuznetsov
2024-08-05 14:08 ` Nicolas Saenz Julienne
2024-06-09 15:49 ` [PATCH 02/18] KVM: x86: hyper-v: Introduce helpers to check if VSM is exposed to guest Nicolas Saenz Julienne
2024-06-09 15:49 ` [PATCH 03/18] hyperv-tlfs: Update struct hv_send_ipi{_ex}'s declarations Nicolas Saenz Julienne
2024-06-09 15:49 ` [PATCH 04/18] KVM: x86: hyper-v: Introduce VTL awareness to Hyper-V's PV-IPIs Nicolas Saenz Julienne
2024-09-13 18:02 ` Sean Christopherson
2024-09-16 14:52 ` Nicolas Saenz Julienne
2024-06-09 15:49 ` [PATCH 05/18] KVM: x86: hyper-v: Introduce MP_STATE_HV_INACTIVE_VTL Nicolas Saenz Julienne
2024-09-13 19:01 ` Sean Christopherson
2024-09-16 15:33 ` Nicolas Saenz Julienne
2024-09-18 7:56 ` Sean Christopherson
2024-06-09 15:49 ` [PATCH 06/18] KVM: x86: hyper-v: Exit on Get/SetVpRegisters hcall Nicolas Saenz Julienne
2024-06-09 15:49 ` [PATCH 07/18] KVM: x86: hyper-v: Exit on TranslateVirtualAddress hcall Nicolas Saenz Julienne
2024-06-09 15:49 ` [PATCH 08/18] KVM: x86: hyper-v: Exit on StartVirtualProcessor and GetVpIndexFromApicId hcalls Nicolas Saenz Julienne
2024-06-09 15:49 ` [PATCH 09/18] KVM: Define and communicate KVM_EXIT_MEMORY_FAULT RWX flags to userspace Nicolas Saenz Julienne
2024-06-09 15:49 ` [PATCH 10/18] KVM: x86: Keep track of instruction length during faults Nicolas Saenz Julienne
2024-09-13 19:10 ` Sean Christopherson
2024-06-09 15:49 ` Nicolas Saenz Julienne [this message]
2024-09-13 19:11 ` [PATCH 11/18] KVM: x86: Pass the instruction length on memory fault user-space exits Sean Christopherson
2024-09-16 15:53 ` Nicolas Saenz Julienne
2024-06-09 15:49 ` [PATCH 12/18] KVM: x86/mmu: Introduce infrastructure to handle non-executable mappings Nicolas Saenz Julienne
2024-06-09 15:49 ` [PATCH 13/18] KVM: x86/mmu: Avoid warning when installing non-private memory attributes Nicolas Saenz Julienne
2024-09-13 19:13 ` Sean Christopherson
2024-06-09 15:49 ` [PATCH 14/18] KVM: x86/mmu: Init memslot if memory attributes available Nicolas Saenz Julienne
2024-06-09 15:49 ` [PATCH 15/18] KVM: Introduce RWX memory attributes Nicolas Saenz Julienne
2024-06-09 15:49 ` [PATCH 16/18] KVM: x86: Take mem attributes into account when faulting memory Nicolas Saenz Julienne
2024-08-22 15:21 ` Nicolas Saenz Julienne
2024-08-22 16:58 ` Sean Christopherson
2024-09-13 18:26 ` Nicolas Saenz Julienne
2024-06-09 15:49 ` [PATCH 17/18] KVM: Introduce traces to track memory attributes modification Nicolas Saenz Julienne
2024-06-09 15:49 ` [PATCH 18/18] KVM: x86: hyper-v: Handle VSM hcalls in user-space Nicolas Saenz Julienne
2024-07-03 9:55 ` [PATCH 00/18] Introducing Core Building Blocks for Hyper-V VSM Emulation Nicolas Saenz Julienne
2024-07-03 12:48 ` Vitaly Kuznetsov
2024-07-03 13:18 ` Nicolas Saenz Julienne
2024-09-13 19:19 ` Sean Christopherson
2024-09-16 16:32 ` Nicolas Saenz Julienne
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=20240609154945.55332-12-nsaenz@amazon.com \
--to=nsaenz@amazon.com \
--cc=amoorthy@google.com \
--cc=bp@alien8.de \
--cc=corbet@lwn.net \
--cc=dave.hansen@linux.intel.com \
--cc=decui@microsoft.com \
--cc=dwmw2@infradead.org \
--cc=graf@amazon.de \
--cc=jgowans@amazon.com \
--cc=kvm@vger.kernel.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-hyperv@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=mlevitsk@redhat.com \
--cc=paul@amazon.com \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=tglx@linutronix.de \
--cc=vkuznets@redhat.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).