From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7F5F539A815 for ; Wed, 24 Jun 2026 23:50:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782345017; cv=none; b=L+xxg0+D3rcb1728R87DUaYgqz+cNWmhOqu1fGPxDOo3TnoIGnsXSuM3bbH45HeTn8sffj9pnpRZy+nPMoySjsLSJZgz61yB5J+j83XwgIrYKUV/AFOXOZp87gaBse+zzj6Wm8dkJU2D4suVkrPqSUinkVuBU7LOfvTdZ+OIeeo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782345017; c=relaxed/simple; bh=jFwTgMVyvPSe2l2h8xYHy/RhaF5bRwpBGbC2LGmMwX8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=o0EGD9yTnfb109fdxFYlNweOv1YKVqmWAQf060pGM7hbjBXLBG3ne+He0vhpDTZI9YW87ZHVGSsINvuBomRKjEgPb8Z6AubXGhBpYt51WZcStmdJRH9rdheowakBYch3EQ6CTFnVx5Gv4q1MsmaIz910hwL6CLac690cOdpKx2o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=T+e+0WEb; arc=none smtp.client-ip=209.85.214.169 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=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="T+e+0WEb" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-2c6b7bd4e8dso21355ad.0 for ; Wed, 24 Jun 2026 16:50:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1782345015; x=1782949815; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=re80BiDMtfSQEgMKbr3zmDreG+eTyRX3VIJM0LJKtgI=; b=T+e+0WEbglhMLvcp1R3B6LVjYkz65SF5Zzgyfqo7Uj2JJAXsd17y5vlkoZJSaRk/bj vpX7kGr8yDyGH9CqeJ9G++WLVSDut4VmfbH85Zkyo4aa3OVo6ggKrNc3Hbbs3vEDd/BJ ncotSJ3kS2ltCsy0AzFrQSjZ07z1tcfPlkcJH1bDveSibn58QApgSJ7CUdOI5Sis+Dsl apDwoUHMPqhLSi6NBlhB9iGm2wsTmyrWKdSS+9aWvcfT/4S9NUrqpQyeIhx+ihGQDZC9 3RrflyKZx90q4iNGb3Ym9Z15425ITP96GOPdi2UHp1RY0cNcyPvo5qsbOJRURU23on+7 3Y0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782345015; x=1782949815; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=re80BiDMtfSQEgMKbr3zmDreG+eTyRX3VIJM0LJKtgI=; b=dXO4zV/Xpyo2iBVjtaVBpDV5M6d6RLDnQsybCQN81L0anecV2PGSRCDuYcKvrOthDf C3jyi14kApv2kMAKT1Uuf66bAhkOLZbFaMZWypuqPKZRAewQhq74AOMtlL2ysNc7b54Y 0cXaimNc73WvJgO6m3g1hHmnrYJLHRa6TjSIaZtNyCGCiEdm6wKESfVULb67yjO1F+nV 2aaaL+TEoS7XQBp3jj8pG3Fw0N19Wb/q9vagM6R2yp4LmPBCIsN6fI8LrRyOjBEtTAuu /g9os9TWO/q7m+rrgIiQQ5Zt7LGjXNtbVukCrACGuCK+4zVclmzosZFhObbnragCU9gD 28ag== X-Forwarded-Encrypted: i=1; AHgh+RrA3naj8QeS8uJaYSgS/3go/5blytk/U2HgOSvM2WlJB8ubiZa4K3598opA00qR3vLu6Id3kLOwxeWNRGo=@vger.kernel.org X-Gm-Message-State: AOJu0YyNH4gWvmCSyFRXQPF49RfP6OzL4wVdj1QS+Ki5+ycb0/K/7ECx fOMs1xm4mhLCA/vAhDHiRKOgtpdgRNLeEH7gz7W47fqk4ol+y4KakeeTwTqJG6a7lQ== X-Gm-Gg: AfdE7ckYTSoC0WB8mn55YXG9L2sr29aFB2rSQXF8biFEOxiXcbe/XdMwI7pZeNwTjPv oofzgaK767HNwstDcBpJDOVo/BMJsLbF3BvfwkRJ+y15Kh4gmd9zc03RfNxXF2j90gBqT14BLUS rdCzbUIHXkEUGShxUCUuo08H21D3pYUuzeoKe24BSpjIO8r0M+xSxmIggZG6WUkkbrvTtCmU9G8 A1vM6+WiecTK92jf8BNW1vmBunFMQJ9R7A/xHbTBchrGW9IgThwndB5ev2eBMWgx4J599QlVb1t hJBPbtXT/4m3/HqKI+ngWaYqYjjL+bACjC3q+HIFG56ejvxR+Tb1L9vNUmRQmqSAcHpsVAdwNOe xOcrIBj2vKz9tH6uuaPHF4L2SmsS3HU8gy3fXlOVRt9NEaVtYAAOI57DC0tHjEHljy5BHxIaeQV dJlwdP2vwty3HgqHP//xVXV+8ThPtzBCeK8CHw64kVywk= X-Received: by 2002:a17:902:f687:b0:2bf:193b:a195 with SMTP id d9443c01a7336-2c7fae6b840mr507585ad.11.1782345014009; Wed, 24 Jun 2026 16:50:14 -0700 (PDT) Received: from google.com (74.67.83.34.bc.googleusercontent.com. [34.83.67.74]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c92bc1df037sm546294a12.17.2026.06.24.16.50.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2026 16:50:13 -0700 (PDT) Date: Wed, 24 Jun 2026 23:50:09 +0000 From: Lisa Wang To: Xiaoyao Li Cc: 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 , Oliver Upton , Jeremiah McReynolds , kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, x86@kernel.org Subject: Re: [PATCH v13 03/22] KVM: selftests: Initialize the TDX VM Message-ID: References: <20260521-tdx-selftests-v13-v13-0-6983ae4c3a4d@google.com> <20260521-tdx-selftests-v13-v13-3-6983ae4c3a4d@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Wed, Jun 17, 2026 at 11:21:49AM +0800, Xiaoyao Li wrote: > > +++ b/tools/testing/selftests/kvm/include/x86/tdx/tdx_util.h > > @@ -11,4 +11,34 @@ static inline bool is_tdx_vm(struct kvm_vm *vm) > > return vm->type == KVM_X86_TDX_VM; > > } Thanks for the review. I will change all comments for this patch I did not reply here in the next version. > > +/* > > + * TDX ioctls > > + * Use underscores to avoid collisions with struct member names. > > + */ > > +#define __tdx_vm_ioctl(vm, cmd, _flags, arg) \ > > +({ \ > > + int r; \ > > + \ > > + union { \ > > + struct kvm_tdx_cmd c; \ > > + unsigned long raw; \ > > + } tdx_cmd = { .c = { \ > > + .id = (cmd), \ > > + .flags = (u32)(_flags), \ > > + .data = (u64)(arg), \ > > + } }; \ > > + \ > > + r = __vm_ioctl(vm, KVM_MEMORY_ENCRYPT_OP, &tdx_cmd.raw); \ > > + r ?: tdx_cmd.c.hw_error; \ > > +}) > > It looks __tdx_vm_ioctl() can be implemented as the static inline function. > > Given all the existing xxx_ioctl() are implmeneted as MACRO, I'm OK with it. Most vm_ioctl() and vcpu_ioctl() used MACRO. I prefer to use MACRO for `tdx_vm_ioctl()` for the `#cmd`, but I am ok to change `__tdx_vm_ioctl()` to static inline function. If we can only change part of it, do you think it is better to change it as the static inline fucntion ? > > +} > > + > > +static struct kvm_cpuid_entry2 *tdx_find_cpuid_config(struct kvm_tdx_capabilities *cap, > > + u32 leaf, u32 sub_leaf) > > +{ > > + struct kvm_cpuid_entry2 *config; > > + u32 i; > > + > > + for (i = 0; i < cap->cpuid.nent; i++) { > > + config = &cap->cpuid.entries[i]; > > + > > + if (config->function == leaf && config->index == sub_leaf) > > + return config; > > + } > > + > > + return NULL; > > +} > > No need to introduce a new fucntin. We can use get_cpuid_entry(). I think we cannot use `get_cpuid_entry()` directly here. This function is called by `tdx_filter_cpuid()` to check if KVM's supported CPUID entries are present in the TDX capabilities list. Since the TDX list only contains a subset of CPUID leaves, some queries will naturally return NULL (which we want to gracefully filter out) However, `get_cpuid_entry()` has an embedded TEST_FAIL(), which would abort for any missing leaf. How about I add a `__get_cpuid_entry()` to share the same part of them? Lisa