From: Isaku Yamahata <[email protected]> Initialize the TDX S-bit and the GPA tag mask in kvm_init_vm_address_properties() for TDX VMs, similar to how the C-bit is initialized for SEV VMs.
The TDX S-bit is used to distinguish between shared and private guest physical addresses. Its position is determined by the guest physical address width, which is either 48 or 52 bits for current TDX implementations. Reviewed-by: Binbin Wu <[email protected]> Co-developed-by: Adrian Hunter <[email protected]> Signed-off-by: Adrian Hunter <[email protected]> Signed-off-by: Isaku Yamahata <[email protected]> Co-developed-by: Sagi Shahar <[email protected]> Signed-off-by: Sagi Shahar <[email protected]> Reviewed-by: Ira Weiny <[email protected]> Signed-off-by: Lisa Wang <[email protected]> --- tools/testing/selftests/kvm/include/x86/tdx/tdx_util.h | 14 ++++++++++++++ tools/testing/selftests/kvm/lib/x86/processor.c | 12 ++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86/tdx/tdx_util.h b/tools/testing/selftests/kvm/include/x86/tdx/tdx_util.h new file mode 100644 index 000000000000..f647e6ca6b34 --- /dev/null +++ b/tools/testing/selftests/kvm/include/x86/tdx/tdx_util.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef SELFTESTS_TDX_TDX_UTIL_H +#define SELFTESTS_TDX_TDX_UTIL_H + +#include <stdbool.h> + +#include "kvm_util.h" + +static inline bool is_tdx_vm(struct kvm_vm *vm) +{ + return vm->type == KVM_X86_TDX_VM; +} + +#endif /* SELFTESTS_TDX_TDX_UTIL_H */ diff --git a/tools/testing/selftests/kvm/lib/x86/processor.c b/tools/testing/selftests/kvm/lib/x86/processor.c index b51467d70f6e..b68ad1dc7e02 100644 --- a/tools/testing/selftests/kvm/lib/x86/processor.c +++ b/tools/testing/selftests/kvm/lib/x86/processor.c @@ -11,6 +11,7 @@ #include "smm.h" #include "svm_util.h" #include "sev.h" +#include "tdx/tdx_util.h" #include "vmx.h" #ifndef NUM_INTERRUPTS @@ -1311,12 +1312,19 @@ void kvm_get_cpu_address_width(unsigned int *pa_bits, unsigned int *va_bits) void kvm_init_vm_address_properties(struct kvm_vm *vm) { + u32 gpa_bits = kvm_cpu_property(X86_PROPERTY_GUEST_MAX_PHY_ADDR); + + vm->arch.sev_fd = -1; + if (is_sev_vm(vm)) { vm->arch.sev_fd = open_sev_dev_path_or_exit(); vm->arch.c_bit = BIT_ULL(this_cpu_property(X86_PROPERTY_SEV_C_BIT)); vm->gpa_tag_mask = vm->arch.c_bit; - } else { - vm->arch.sev_fd = -1; + } else if (is_tdx_vm(vm)) { + TEST_ASSERT(gpa_bits == 48 || gpa_bits == 52, + "TDX: bad X86_PROPERTY_GUEST_MAX_PHY_ADDR value: %u", gpa_bits); + vm->arch.s_bit = BIT_ULL(gpa_bits - 1); + vm->gpa_tag_mask = vm->arch.s_bit; } } -- 2.54.0.746.g67dd491aae-goog

