[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <d69b2da1-efc4-47da-a74d-c18d0b50db74@linux.intel.com>
Date: Fri, 15 Aug 2025 10:37:51 +0800
From: Binbin Wu <binbin.wu@...ux.intel.com>
To: Sagi Shahar <sagis@...gle.com>
Cc: linux-kselftest@...r.kernel.org, Paolo Bonzini <pbonzini@...hat.com>,
Shuah Khan <shuah@...nel.org>, Sean Christopherson <seanjc@...gle.com>,
Ackerley Tng <ackerleytng@...gle.com>, Ryan Afranji <afranji@...gle.com>,
Andrew Jones <ajones@...tanamicro.com>,
Isaku Yamahata <isaku.yamahata@...el.com>,
Erdem Aktas <erdemaktas@...gle.com>,
Rick Edgecombe <rick.p.edgecombe@...el.com>,
Roger Wang <runanwang@...gle.com>, Oliver Upton <oliver.upton@...ux.dev>,
"Pratik R. Sampat" <pratikrajesh.sampat@....com>,
Reinette Chatre <reinette.chatre@...el.com>, Ira Weiny
<ira.weiny@...el.com>, linux-kernel@...r.kernel.org, kvm@...r.kernel.org
Subject: Re: [PATCH v8 23/30] KVM: selftests: Add functions to allow mapping
as shared
On 8/8/2025 4:16 AM, Sagi Shahar wrote:
> From: Ackerley Tng <ackerleytng@...gle.com>
>
> virt_map() enforces a private mapping for private memory. Introduce
> virt_map_shared() that creates a shared mapping for private as
> well as shared memory. This way, the TD does not have to remap its
> page tables at runtime.
>
> Signed-off-by: Ackerley Tng <ackerleytng@...gle.com>
> Signed-off-by: Sagi Shahar <sagis@...gle.com>
> ---
> .../testing/selftests/kvm/include/kvm_util.h | 23 +++++++++++++
> tools/testing/selftests/kvm/lib/kvm_util.c | 34 +++++++++++++++++++
> .../testing/selftests/kvm/lib/x86/processor.c | 15 ++++++--
> 3 files changed, 70 insertions(+), 2 deletions(-)
>
[...]
>
> -void __virt_pg_map(struct kvm_vm *vm, uint64_t vaddr, uint64_t paddr, int level)
> +static void ___virt_pg_map(struct kvm_vm *vm, uint64_t vaddr, uint64_t paddr,
> + int level, bool protected)
> {
> const uint64_t pg_size = PG_LEVEL_SIZE(level);
> uint64_t *pml4e, *pdpe, *pde;
> @@ -231,17 +232,27 @@ void __virt_pg_map(struct kvm_vm *vm, uint64_t vaddr, uint64_t paddr, int level)
> * Neither SEV nor TDX supports shared page tables, so only the final
> * leaf PTE needs manually set the C/S-bit.
> */
> - if (vm_is_gpa_protected(vm, paddr))
Since the original code has already create shared/private mapping based on the
paddr, why not just use virt_map() and shared GPA as paddr, then no need to
duplicate the code?
> + if (protected)
> *pte |= vm->arch.c_bit;
> else
> *pte |= vm->arch.s_bit;
> }
>
> +void __virt_pg_map(struct kvm_vm *vm, uint64_t vaddr, uint64_t paddr, int level)
> +{
> + ___virt_pg_map(vm, vaddr, paddr, level, vm_is_gpa_protected(vm, paddr));
> +}
> +
> void virt_arch_pg_map(struct kvm_vm *vm, uint64_t vaddr, uint64_t paddr)
> {
> __virt_pg_map(vm, vaddr, paddr, PG_LEVEL_4K);
> }
>
> +void virt_arch_pg_map_shared(struct kvm_vm *vm, uint64_t vaddr, uint64_t paddr)
> +{
> + ___virt_pg_map(vm, vaddr, paddr, PG_LEVEL_4K, false);
> +}
> +
> void virt_map_level(struct kvm_vm *vm, uint64_t vaddr, uint64_t paddr,
> uint64_t nr_bytes, int level)
> {
Powered by blists - more mailing lists