From: Nikolas Wipper <nikwip@amazon.de>
To: Paolo Bonzini <pbonzini@redhat.com>,
Sean Christopherson <seanjc@google.com>,
Vitaly Kuznetsov <vkuznets@redhat.com>
Cc: Nicolas Saenz Julienne <nsaenz@amazon.com>,
Alexander Graf <graf@amazon.de>,
James Gowans <jgowans@amazon.com>, <nh-open-source@amazon.com>,
Thomas Gleixner <tglx@linutronix.de>,
"Ingo Molnar" <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
<linux-kernel@vger.kernel.org>, <kvm@vger.kernel.org>,
<x86@kernel.org>, <linux-doc@vger.kernel.org>,
<linux-kselftest@vger.kernel.org>, <kvmarm@lists.linux.dev>,
<kvm-riscv@lists.infradead.org>,
Nikolas Wipper <nikwip@amazon.de>
Subject: [PATCH 12/15] KVM: Introduce KVM_TRANSLATE2
Date: Tue, 10 Sep 2024 15:22:04 +0000 [thread overview]
Message-ID: <20240910152207.38974-13-nikwip@amazon.de> (raw)
In-Reply-To: <20240910152207.38974-1-nikwip@amazon.de>
Introduce a new ioctl that extends the functionality of KVM_TRANSLATE. It
allows the caller to specify an access mode that must be upheld throughout
the entire page walk. Additionally, it provides control over whether the
accessed/dirty bits in the page table should be set at all, and whether
they should be set if the walk fails. Lastly, if the page walk fails, it
returns the exact error code which caused the failure.
KVM_TRANSLATE lacks information about executability of the translated page
and doesn't provide control over the accessed/dirty page table bits at
all. Because it lacks any sort of input flags, it cannot simply be
expanded without breaking backwards compatibility. Additionally, in the
x86 implementation the 'writable' and 'usermode' are currently hardcoded
to 1 and 0 respectively, which is behaviour that might be relied upon.
The ioctl will be implemented for x86 in following commits.
Signed-off-by: Nikolas Wipper <nikwip@amazon.de>
---
include/linux/kvm_host.h | 4 ++++
include/uapi/linux/kvm.h | 33 +++++++++++++++++++++++++++++++++
2 files changed, 37 insertions(+)
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index b23c6d48392f..c78017fd2907 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -84,6 +84,10 @@
#define KVM_MAX_NR_ADDRESS_SPACES 1
#endif
+#define KVM_TRANSLATE_FLAGS_ALL \
+ (KVM_TRANSLATE_FLAGS_SET_ACCESSED | \
+ KVM_TRANSLATE_FLAGS_SET_DIRTY | \
+ KVM_TRANSLATE_FLAGS_FORCE_SET_ACCESSED)
/*
* For the normal pfn, the highest 12 bits should be zero,
* so we can mask bit 62 ~ bit 52 to indicate the error pfn,
diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
index 637efc055145..602323e734cc 100644
--- a/include/uapi/linux/kvm.h
+++ b/include/uapi/linux/kvm.h
@@ -512,6 +512,37 @@ struct kvm_translation {
__u8 pad[5];
};
+/* for KVM_TRANSLATE2 */
+struct kvm_translation2 {
+ /* in */
+ __u64 linear_address;
+#define KVM_TRANSLATE_FLAGS_SET_ACCESSED (1 << 0)
+#define KVM_TRANSLATE_FLAGS_SET_DIRTY (1 << 1)
+#define KVM_TRANSLATE_FLAGS_FORCE_SET_ACCESSED (1 << 2)
+ __u16 flags;
+#define KVM_TRANSLATE_ACCESS_WRITE (1 << 0)
+#define KVM_TRANSLATE_ACCESS_USER (1 << 1)
+#define KVM_TRANSLATE_ACCESS_EXEC (1 << 2)
+#define KVM_TRANSLATE_ACCESS_ALL \
+ (KVM_TRANSLATE_ACCESS_WRITE | \
+ KVM_TRANSLATE_ACCESS_USER | \
+ KVM_TRANSLATE_ACCESS_EXEC)
+ __u16 access;
+ __u8 padding[4];
+
+ /* out */
+ __u64 physical_address;
+ __u8 valid;
+#define KVM_TRANSLATE_FAULT_NOT_PRESENT 1
+#define KVM_TRANSLATE_FAULT_PRIVILEGE_VIOLATION 2
+#define KVM_TRANSLATE_FAULT_RESERVED_BITS 3
+#define KVM_TRANSLATE_FAULT_INVALID_GVA 4
+#define KVM_TRANSLATE_FAULT_INVALID_GPA 5
+ __u16 error_code;
+ __u8 set_bits_succeeded;
+ __u8 padding2[4];
+};
+
/* for KVM_INTERRUPT */
struct kvm_interrupt {
/* in */
@@ -933,6 +964,7 @@ struct kvm_enable_cap {
#define KVM_CAP_PRE_FAULT_MEMORY 236
#define KVM_CAP_X86_APIC_BUS_CYCLES_NS 237
#define KVM_CAP_X86_GUEST_MODE 238
+#define KVM_CAP_TRANSLATE2 239
struct kvm_irq_routing_irqchip {
__u32 irqchip;
@@ -1269,6 +1301,7 @@ struct kvm_vfio_spapr_tce {
#define KVM_SET_SREGS _IOW(KVMIO, 0x84, struct kvm_sregs)
#define KVM_TRANSLATE _IOWR(KVMIO, 0x85, struct kvm_translation)
#define KVM_INTERRUPT _IOW(KVMIO, 0x86, struct kvm_interrupt)
+#define KVM_TRANSLATE2 _IOWR(KVMIO, 0x87, struct kvm_translation2)
#define KVM_GET_MSRS _IOWR(KVMIO, 0x88, struct kvm_msrs)
#define KVM_SET_MSRS _IOW(KVMIO, 0x89, struct kvm_msrs)
#define KVM_SET_CPUID _IOW(KVMIO, 0x8a, struct kvm_cpuid)
--
2.40.1
Amazon Web Services Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B
Sitz: Berlin
Ust-ID: DE 365 538 597
next prev parent reply other threads:[~2024-09-10 15:25 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-10 15:21 [PATCH 00/15] KVM: x86: Introduce new ioctl KVM_TRANSLATE2 Nikolas Wipper
2024-09-10 15:21 ` [PATCH 01/15] KVM: Add API documentation for KVM_TRANSLATE2 Nikolas Wipper
2024-09-10 15:21 ` [PATCH 02/15] KVM: x86/mmu: Abort page walk if permission checks fail Nikolas Wipper
2024-09-10 15:21 ` [PATCH 03/15] KVM: x86/mmu: Introduce exception flag for unmapped GPAs Nikolas Wipper
2024-09-10 15:21 ` [PATCH 04/15] KVM: x86/mmu: Store GPA in exception if applicable Nikolas Wipper
2024-09-10 15:21 ` [PATCH 05/15] KVM: x86/mmu: Introduce flags parameter to page walker Nikolas Wipper
2024-09-10 15:21 ` [PATCH 06/15] KVM: x86/mmu: Implement PWALK_SET_ACCESSED in " Nikolas Wipper
2024-09-10 15:21 ` [PATCH 07/15] KVM: x86/mmu: Implement PWALK_SET_DIRTY " Nikolas Wipper
2024-09-10 15:22 ` [PATCH 08/15] KVM: x86/mmu: Implement PWALK_FORCE_SET_ACCESSED " Nikolas Wipper
2024-09-10 15:22 ` [PATCH 09/15] KVM: x86/mmu: Introduce status parameter to " Nikolas Wipper
2024-09-10 15:22 ` [PATCH 10/15] KVM: x86/mmu: Implement PWALK_STATUS_READ_ONLY_PTE_GPA in " Nikolas Wipper
2024-09-10 15:22 ` [PATCH 11/15] KVM: x86: Introduce generic gva to gpa translation function Nikolas Wipper
2024-09-10 15:22 ` Nikolas Wipper [this message]
2024-09-10 15:22 ` [PATCH 13/15] KVM: Add KVM_TRANSLATE2 stub Nikolas Wipper
2024-09-10 15:22 ` [PATCH 14/15] KVM: x86: Implement KVM_TRANSLATE2 Nikolas Wipper
2024-12-11 22:06 ` Sean Christopherson
2024-09-10 15:22 ` [PATCH 15/15] KVM: selftests: Add test for KVM_TRANSLATE2 Nikolas Wipper
2024-10-04 10:44 ` [PATCH 00/15] KVM: x86: Introduce new ioctl KVM_TRANSLATE2 Nikolas Wipper
2024-12-11 22:05 ` Sean Christopherson
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=20240910152207.38974-13-nikwip@amazon.de \
--to=nikwip@amazon.de \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=graf@amazon.de \
--cc=jgowans@amazon.com \
--cc=kvm-riscv@lists.infradead.org \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=nh-open-source@amazon.com \
--cc=nsaenz@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