From: Isaku Yamahata <[email protected]>
Hello. I've updated the patch series based on the feedback. Here are the
discussion points.
- 06/11 KVM: x86: Introduce PFERR_GUEST_ENC_MASK to indicate fault is private
Michael has his own opinion on how to indicate private fault.
- 09/11 KVM: Add new members to struct kvm_gfn_range to operate on
- 10/11 KVM: x86: Add gmem hook for initializing private memory
SNP needs the callback. TDX won't use this one.
- 11/11 KVM: x86: Add gmem hook for invalidating private memory
SNP needs the callback. TDX doesn't use this one at the moment, but would
use it.
- VM type:
I didn't rename KVM_X86_PROTECTED_VM to KVM_X86_SW_PROTECTED_VM in this patch
series. It's easy to rename it if desired.
Thanks,
This is an RFC patch series based on KVM gmem [1] and [2] for the common use of
TDX and SEV-SNP.
[1] KVM gmem patches
https://github.com/sean-jc/linux/tree/x86/kvm_gmem_solo
[2] Add AMD Secure Nested Paging (SEV-SNP) Hypervisor Support
https://lore.kernel.org/lkml/[email protected]/
---
v3:
- Imported common patches from Michael Roth which can be useful for both SNP
and TDX. And reorder patches.
- Update struct kvm_gfn_range to drop flag, and add add only_private, and
only_shared
- Update kvm_arch_set_memory_attributes() and added a x86 vendor callback for
it.
v2:
https://lore.kernel.org/all/[email protected]/
v1:
https://lore.kernel.org/all/[email protected]/
Brijesh Singh (1):
KVM: x86: Export the kvm_zap_gfn_range() for the SNP use
Isaku Yamahata (8):
KVM: selftests: Fix test_add_overlapping_private_memory_regions()
KVM: selftests: Fix guest_memfd()
KVM: selftests: x86: typo in private_mem_conversions_test.c
KVM: x86: Add is_vm_type_supported callback
KVM: x86/mmu: Pass around full 64-bit error code for the KVM page
fault
KVM: x86: Introduce PFERR_GUEST_ENC_MASK to indicate fault is private
KVM: Fix set_mem_attr ioctl when error case
KVM: Add new members to struct kvm_gfn_range to operate on
Michael Roth (2):
KVM: x86: Add gmem hook for initializing private memory
KVM: x86: Add gmem hook for invalidating private memory
arch/x86/include/asm/kvm-x86-ops.h | 4 ++
arch/x86/include/asm/kvm_host.h | 12 +++++
arch/x86/include/uapi/asm/kvm.h | 1 +
arch/x86/kvm/mmu.h | 2 -
arch/x86/kvm/mmu/mmu.c | 51 ++++++++++++++-----
arch/x86/kvm/mmu/mmu_internal.h | 20 ++++++--
arch/x86/kvm/mmu/mmutrace.h | 2 +-
arch/x86/kvm/mmu/paging_tmpl.h | 2 +-
arch/x86/kvm/svm/svm.c | 7 +++
arch/x86/kvm/vmx/vmx.c | 6 +++
arch/x86/kvm/x86.c | 16 +++++-
arch/x86/kvm/x86.h | 2 +
include/linux/kvm_host.h | 16 ++++--
.../testing/selftests/kvm/guest_memfd_test.c | 4 +-
.../selftests/kvm/set_memory_region_test.c | 16 +++++-
.../kvm/x86_64/private_mem_conversions_test.c | 2 +-
virt/kvm/guest_mem.c | 50 +++++++++++++++++-
virt/kvm/kvm_main.c | 24 +++++----
18 files changed, 192 insertions(+), 45 deletions(-)
base-commit: be8abcec83c87d4e15ae04816b685fe260c4bcfd
--
2.25.1
From: Isaku Yamahata <[email protected]>
Some test cases should succeed. Check !ret instead of ret.
Fixes: 36eedd5b91e3 ("KVM: selftests: Add basic selftest for guest_memfd()")
Signed-off-by: Isaku Yamahata <[email protected]>
---
Changes v2 -> v3:
- no change
Changes v1 -> v2:
- no change
---
tools/testing/selftests/kvm/guest_memfd_test.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/kvm/guest_memfd_test.c b/tools/testing/selftests/kvm/guest_memfd_test.c
index 3b6532b833b2..f3b99c1e5464 100644
--- a/tools/testing/selftests/kvm/guest_memfd_test.c
+++ b/tools/testing/selftests/kvm/guest_memfd_test.c
@@ -72,11 +72,11 @@ static void test_fallocate(int fd, size_t page_size, size_t total_size)
ret = fallocate(fd, FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE,
total_size, page_size);
- TEST_ASSERT(ret, "fallocate(PUNCH_HOLE) at total_size should be fine (no-op)");
+ TEST_ASSERT(!ret, "fallocate(PUNCH_HOLE) at total_size should be fine (no-op)");
ret = fallocate(fd, FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE,
total_size + page_size, page_size);
- TEST_ASSERT(ret, "fallocate(PUNCH_HOLE) after total_size should be fine (no-op)");
+ TEST_ASSERT(!ret, "fallocate(PUNCH_HOLE) after total_size should be fine (no-op)");
ret = fallocate(fd, FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE,
page_size, page_size - 1);
--
2.25.1
From: Brijesh Singh <[email protected]>
While resolving the RMP page fault, there may be cases where the page
level between the RMP entry and TDP does not match and the 2M RMP entry
must be split into 4K RMP entries. Or a 2M TDP page need to be broken
into multiple of 4K pages.
To keep the RMP and TDP page level in sync, zap the gfn range after
splitting the pages in the RMP entry. The zap should force the TDP to
gets rebuilt with the new page level.
Signed-off-by: Brijesh Singh <[email protected]>
Signed-off-by: Ashish Kalra <[email protected]>
Signed-off-by: Michael Roth <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
---
Changes v2 -> v3:
- Newly added
---
arch/x86/include/asm/kvm_host.h | 2 ++
arch/x86/kvm/mmu.h | 2 --
arch/x86/kvm/mmu/mmu.c | 1 +
3 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 831bfd1e719a..bdf507797c73 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -1842,6 +1842,8 @@ void kvm_mmu_slot_leaf_clear_dirty(struct kvm *kvm,
void kvm_mmu_zap_all(struct kvm *kvm);
void kvm_mmu_invalidate_mmio_sptes(struct kvm *kvm, u64 gen);
void kvm_mmu_change_mmu_pages(struct kvm *kvm, unsigned long kvm_nr_mmu_pages);
+void kvm_zap_gfn_range(struct kvm *kvm, gfn_t gfn_start, gfn_t gfn_end);
+
int load_pdptrs(struct kvm_vcpu *vcpu, unsigned long cr3);
diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h
index 92d5a1924fc1..963c734642f6 100644
--- a/arch/x86/kvm/mmu.h
+++ b/arch/x86/kvm/mmu.h
@@ -235,8 +235,6 @@ static inline u8 permission_fault(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu,
return -(u32)fault & errcode;
}
-void kvm_zap_gfn_range(struct kvm *kvm, gfn_t gfn_start, gfn_t gfn_end);
-
int kvm_arch_write_log_dirty(struct kvm_vcpu *vcpu);
int kvm_mmu_post_init_vm(struct kvm *kvm);
diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index 464c70b35383..5a80ec49bdcd 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -6727,6 +6727,7 @@ static bool kvm_mmu_zap_collapsible_spte(struct kvm *kvm,
return need_tlb_flush;
}
+EXPORT_SYMBOL_GPL(kvm_zap_gfn_range);
static void kvm_rmap_zap_collapsible_sptes(struct kvm *kvm,
const struct kvm_memory_slot *slot)
--
2.25.1
On Wed, Jun 28, 2023, [email protected] wrote:
> Isaku Yamahata (8):
> KVM: selftests: Fix test_add_overlapping_private_memory_regions()
> KVM: selftests: Fix guest_memfd()
> KVM: selftests: x86: typo in private_mem_conversions_test.c
Folded these fixes into the guest_memfd RFC[*].
> KVM: Fix set_mem_attr ioctl when error case
And this one too.
> KVM: Add new members to struct kvm_gfn_range to operate on
And also included patches that achieve this (and will also post them separately
as non-RFC, mainly to coordinate with MGLRU).
[*] https://lore.kernel.org/all/[email protected]