From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.197 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793922456; b=ai5IavUBf1srBfnqwwSazuvgLT9snto8CeLY2ZAeBspfTLOjChsAerEUAD2gs1rAh+we pRUHPl5ia4hNBdQo+at1fr1m/+B2dTSigpgpXZevAbtK82lDwmIW2b23BIXSfqEsLxWfv WFTUR7iAhNOwOuHwAdAIfqc1o0eiFa2zKFmnppA/9EmJ4diP0dLEHOwQleSFJa08Npsyw uqLLO1vsrr6p5LnbVqmp6OmuZhQuarogwD61M33hlsDZrHrRUX6mtbTDMKkw0pDEhab9m /WuMJC82cX6/IrWsm/szaYUPNbOF3T2mkZ6L68rW9G13OEJIefoEqoSO4cC0bOqfvwg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793922456; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Developer-Key:X-Developer-Signature: X-Mailer:Message-ID:Subject:From:To:Cc:Content-Type; bh=HSVxAxPHxLWJb+QPPocaz3W4kDp/YO8WZ+4Cex73wUQ=; b=CXj00BoqBXA7kQo3nUSB4dUmaq0GrIqj5bcQ5njqxVMvcaIqLEQzwPhGANQmqnztwHCT TqxsMwg+v51fyh0ca1OGQ3My4YfSx7vk3KLczdR8Zyx0683XWQP5VWCk+fCzVePdsBdWf 3i+gqNxgFKt0D+BP4oIPny++ECObJYSGEEFzmNsQ8ueRvEJSWihg7S5NLC2EHi4fOyDLA 7gQ88SUl3Mu1nqxECEpXy3jnA89OBLMXJ7dwCdnCnJklHKgoLZcNtDgSFdTf2PRkbPCN8 m9BSCipzEOrIrE32/gMlp93D6Z+JP+W5IT7m4CcvdZk43WSJGr8+tnsuxeGE4lcAj+w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--wyihan.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b="d+5tXgr/"; arc=none smtp.remote-ip=209.85.215.197 Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B4D26606A33E for ; Thu, 5 Nov 2026 23:47:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B4D26606A33E Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--wyihan.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=d+5tXgr/ Received: by mail-pg1-f197.google.com with SMTP id 41be03b00d2f7-cd65285537aso28565a12.1 for ; Thu, 05 Nov 2026 15:47:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1793922455; x=1794527255; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=HSVxAxPHxLWJb+QPPocaz3W4kDp/YO8WZ+4Cex73wUQ=; b=d+5tXgr/pwbnJE/4WlePeztTsJz7ADyEAjtrGCSdBBBNcbk1cX8jnol/CPK32N9rGL mHKkV+c4+FwDgokVCUeUitMj9A8Q1qR0+eEYu0jzMGuwuKOkSVj/HOn43j+KZVKByyDM ezI2J2qRtJxS16fg+TdYrf1Eph8Ba9qtuHsYq9qpW66lsWokesoowkhnc1b4Y8MY128X 7sqhQKSAQYYQagKNje3ucoul+NnMlfOKINgjl60ScGJ30Z2iXHxZ5ruf/Jh9Vob01ffK NpIc7lOR0y1VFJXSJnwCGUjzqV9TGjMY38ywnZhg2OIB3H3YLqnBHzv/GP6gNDoVgQv7 G5aQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793922455; x=1794527255; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=HSVxAxPHxLWJb+QPPocaz3W4kDp/YO8WZ+4Cex73wUQ=; b=MGFYmlCSxKfp4gAdmFzbfna1uQkraJsit1yaExMYdwk7ibubv6xSowLVWbqCY/5GrO 7ric69X06Leqhj0p3rvMQ46iemJps4NJr6ok/izqJob7jh5cYSC/z1OUDEjHu39u54ZZ SMpC3PiHPEoIymakMOPf+3OoXz98fjdHn50PPxah1dGrcgb4UGMw7K+EfkWLdpdVyE49 z2s6rcIAoH1CD9MNA8FrS10PK6SqtFz54WDoFVsevo3Snq2SdG2monpgNLO9fia5gGd8 z4ULsERvjNXY76rpByPYHClAB4K22gqoGN7vCcLOGqJlQvjo62mqadhB33ewC4X5QHxp MCLg== X-Forwarded-Encrypted: i=1; AKwUvBzdzCeFoZEwTwo+ktVW4mv9J3j0u0HsxbGgKXSCkrvHmHhdAbEReXC0/CnZym4fSpMUvdYDhqC9OQuDApE=@vger.kernel.org X-Gm-Message-State: APuU4Z/Iw5NMqM4lmSedERG4REjNKh9+js1i1tEjPUDU5UD/CggH2UGl loBHa5TT3CTKObUAQugGwXMJi9Q4S7AVUB/XOh43qcOW1u3nK0vvZorPN5Ef6ItALoAJbpiHVZ6 SmUUd9A== X-Received: from pgdu12.prod.google.com ([2002:a05:6a02:2f4c:b0:cdb:58e2:7cb7]) (user=wyihan job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3b8f:b0:3a0:b312:1fbe with SMTP id 98e67ed59e1d1-3b0db6c99a4mr578689a91.23.1793922454815; Thu, 05 Nov 2026 15:47:34 -0800 (PST) Date: Thu, 05 Nov 2026 23:46:46 +0000 In-Reply-To: <20261105-tdx-selftests-v16-0-2024e8fa517a@google.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261105-tdx-selftests-v16-0-2024e8fa517a@google.com> X-Developer-Key: i=wyihan@google.com; a=ed25519; pk=cRi0fKzS5BMxlHyHY2pJv3w/1zcgfYKr6EYGYppdMYc= X-Developer-Signature: v=1; a=ed25519-sha256; t=1793922452; l=2831; i=wyihan@google.com; s=20260319; h=from:subject:message-id; bh=TsmjAstaSjFYixQhUYbJbOkD7vAXJprj3EzMr2Dw2cA=; b=v+qqqNmrw6MMK/e1gCj/lL1NXgXSnN2daUTFtgMasIYlyr9pv1EkxsDPEdCOygMDueOA2GoPI lOq7jE2xRQNDXan3XM0CV7U61a7ubrgmr7yreT7TB9VfkU0sqfxfFEr X-Mailer: b4 0.14.3 Message-ID: <20261105-tdx-selftests-v16-2-2024e8fa517a@google.com> Subject: [PATCH v16 02/20] KVM: selftests: Update kvm_init_vm_address_properties() for TDX From: Lisa Wang To: Andrew Jones , Ackerley Tng , Binbin Wu , Chao Gao , Chenyi Qiang , Dave Hansen , Erdem Aktas , Ira Weiny , Isaku Yamahata , Kiryl Shutsemau , linux-kselftest@vger.kernel.org, Paolo Bonzini , "Pratik R. Sampat" , Reinette Chatre , Rick Edgecombe , Roger Wang , Ryan Afranji , Sagi Shahar , Sean Christopherson , Shuah Khan , Xiaoyao Li , Oliver Upton Cc: Jeremiah McReynolds , kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, x86@kernel.org, Lisa Wang , Adrian Hunter , Ira Weiny Content-Type: text/plain; charset="utf-8" From: Isaku Yamahata 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. Co-developed-by: Adrian Hunter Signed-off-by: Adrian Hunter Co-developed-by: Sagi Shahar Signed-off-by: Sagi Shahar Signed-off-by: Isaku Yamahata Signed-off-by: Lisa Wang Reviewed-by: Binbin Wu Reviewed-by: Ira Weiny Reviewed-by: Xiaoyao Li --- 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 + +#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 8374afd08baf..d705e9269a41 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 @@ -1337,12 +1338,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.56.0.455.g6c5a503b38-goog