From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (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 53F90425CEB for ; Wed, 1 Jul 2026 11:46:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782906382; cv=none; b=D4lFO3A65CXt+PZ6BOf/DndqHDXgEtF4yc4QsSIe4z6djBevrgg45gLuvaLhpo5cX7El7+s835jg+aCpeQiFmpqtZEibb1/BfzRtFyv/NF2yVIPqEgr9KEAUr3lJYV2zFyqD7z/a7RQyDmQ4MOCWCdXp9UPJcHcEzc9g4+/6mbo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782906382; c=relaxed/simple; bh=xTEfbWT5LJSM6gKyc3oFGUQ41/RoQ8ITPezgvgLQC0k=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=iNXbMwPfVgvJfC7i+XXwN1OabmZJoAG7bkz1+ugbhacOQzdoLRqd7a3kpvZLGWYLEguz9Rqr8cRFpm0vGx1QSX4fS/sCwIc0Xx6kytTFN6sNa9nssKszw34CJcgldXiOxMVd27J4DoXoiKbGGkEMATbvUxorwa6o7aIH+cCnIjg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=Dys334I+; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="Dys334I+" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-493c2c0b9a8so2825215e9.1 for ; Wed, 01 Jul 2026 04:46:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1782906379; x=1783511179; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :from:references:cc:to:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=84l0kSo6RKfg4k5hRcx6ro1EZzuiFwmA3iygG4exLEE=; b=Dys334I+cANwPPPtLBupIKIimF1gBcHwKSt1z17utzyV1WIsBFKiTClpAfU9devm/I TgfimPBACia2XXSnWKPSEX1zEpjP3t2U8pPM532mtqTyRisD/B+iIl6HOcP/lLBlt7PE S3t/VlloqgcLwe+XbC7qR30y+533KBfdYdpXGBZtD8sm4OieAYBFgx+OYrnqSxg8d9KJ xYPdeznvWf+ks+VB4x91BOwoANjVG0y0KkhbNN0o4ahcJ6/Gd9QbILBjibLyJyisKAfa T4FraaN+/9K/dsYERmTqW474R9y6l5YaMcqtvOgJQuTUcprWwQ5VtM6rlcBuX6tA32Dh T6IQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782906379; x=1783511179; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :from:references:cc:to:subject:user-agent:mime-version:date :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=84l0kSo6RKfg4k5hRcx6ro1EZzuiFwmA3iygG4exLEE=; b=hnZJOsavGstdP6jT1Q+Oka3jBdWAOlNPAQd+L8G4Vj1G+UWnxhqFkbqre7cce7z2jR s3i//4ZJBycHuNPKW5fgcHD+U1MbJUYe1GCg2stbmGcBGQeMAF1nVDYKrr2VPoud43jS rTwMmRB3HP932mOtPf2j1wTHMOr+i57+eYmsL2W5GGkMG39Sadwqt1DmcDbzNmjYekr7 q8ikK6sFpvH/yXU3ceDmkp4Z9VxLyVt2RnAoLSBI0nCDucyEPCudvdmteJvFxaSPqFcm 531FI4RYV2ap6VB3cgsntWwf7iJ+i8ekXAS1vrmK9LefsOLf1V9q+UgNmaTeIzAaAAsX +3Qw== X-Forwarded-Encrypted: i=1; AFNElJ9II7OLiJjpqy4RTxcvQDl0p7ILUIaxmFJkYGiSSemOeAVpkMb4XgmzJcet3vRC/WNRV4yw5Hg6RdUU0Sk=@vger.kernel.org X-Gm-Message-State: AOJu0YyHcW6+PolP2lWffJpWFWMFAbrhaoSy9PH3Ud/rr1tu/D8n3ukV 7QG3ymMlFL2PMEI8M7CLXIFovEi4HMd4BcwSog76MPzbDvaUEtpyt5dG46PuHh0ijMY= X-Gm-Gg: AfdE7cn61EHmJasikNNa/F8cGSeNGJOnNLM2Rz4LS4iuTPVMXtkrIBzgJX38FHmSnHq Bw7R98TPJ3+SNtBpV3nW9TV0jS5A6hcL/pjmP5gZ6EttHH9qKYdDEOhMzvYkhxPXAjWOeTc/92V my5w1ywzpxOHzBj7N6arjPWPCBsQ2+GVeTr8Eo14iR9u9/60fQUOQYPT49iOHaaCc1RpWal4nfu 3ps//To90smPw6yy03Oe6GQa9MQ5c9dpBNFe6QybJBcsdlfsWyfEJFAtJ27D4T/QUpCON6IiUjI eZ7nLvoMPgiCblXEuD3yhOTu/de2U2TYVF4ZLsRk+saP0PrPWLuzhT3ZNqXzHwQg9iCpyfcYmlO S9eNi4wKzzHdlp8L8HD5+EXAQKKFdrF3UKFG94Ew+QLhf8ZlBV4jyVj9EMaDV68U+lPbD8NsMYQ YRFM7BJ1lpyPV4aA42cTeJ1xWR5g== X-Received: by 2002:a05:600c:e494:20b0:493:9661:f55d with SMTP id 5b1f17b1804b1-493c3cfd391mr2852225e9.30.1782906378668; Wed, 01 Jul 2026 04:46:18 -0700 (PDT) Received: from [10.20.4.146] ([149.62.207.101]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-493bfc32992sm61543595e9.11.2026.07.01.04.46.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 01 Jul 2026 04:46:18 -0700 (PDT) Message-ID: Date: Wed, 1 Jul 2026 14:46:16 +0300 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH 09/15] x86/virt/tdx: Add interface to generate a Quote To: Xu Yilun , kas@kernel.org, djbw@kernel.org, rick.p.edgecombe@intel.com, x86@kernel.org, peter.fang@intel.com Cc: linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, sohil.mehta@intel.com, yilun.xu@intel.com, baolu.lu@linux.intel.com, zhenzhong.duan@intel.com, xiaoyao.li@intel.com References: <20260522034128.3144354-1-yilun.xu@linux.intel.com> <20260522034128.3144354-10-yilun.xu@linux.intel.com> From: Nikolay Borisov Content-Language: en-US Autocrypt: addr=nik.borisov@suse.com; keydata= xsFNBGcrpvIBEAD5cAR5+qu30GnmPrK9veWX5RVzzbgtkk9C/EESHy9Yz0+HWgCVRoNyRQsZ 7DW7vE1KhioDLXjDmeu8/0A8u5nFMqv6d1Gt1lb7XzSAYw7uSWXLPEjFBtz9+fBJJLgbYU7G OpTKy6gRr6GaItZze+r04PGWjeyVUuHZuncTO7B2huxcwIk9tFtRX21gVSOOC96HcxSVVA7X N/LLM2EOL7kg4/yDWEhAdLQDChswhmdpHkp5g6ytj9TM8bNlq9I41hl/3cBEeAkxtb/eS5YR 88LBb/2FkcGnhxkGJPNB+4Siku7K8Mk2Y6elnkOctJcDvk29DajYbQnnW4nhfelZuLNupb1O M0912EvzOVI0dIVgR+xtosp66bYTOpX4Xb0fylED9kYGiuEAeoQZaDQ2eICDcHPiaLzh+6cc pkVTB0sXkWHUsPamtPum6/PgWLE9vGI5s+FaqBaqBYDKyvtJfLK4BdZng0Uc3ijyc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G2ZnExv XXhOGKs/y3VGhjZeCDWZ+0ZQHPCL3HUebLxW49wwLxvXU6sLNfYnTJxdqn58Aq4sBXW5Un0Q vfbd9VFV/bKFfvUscYk2UKPi9vgn1hY38IfmsnoS8b0uwDq75IBvup9pYFyNyPf5SutxhFfP JDjakbdjBoYDWVoaPbp5KAQ2VQRiR54lir/inyqGX+dwzPX/F4OHfB5RTiAFLJliCxniKFsM d8eHe88jWjm6/ilx4IlLl9/MdVUGjLpBi18X7ejLz3U2quYD8DBAGzCjy49wJ4Di4qQjblb2 pTXoEyM2L6E604NbDu0VDvHg7EXh1WwmijEu28c/hEB6DwtzslLpBSsJV0s1/jE= In-Reply-To: <20260522034128.3144354-10-yilun.xu@linux.intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 5/22/26 06:41, Xu Yilun wrote: > From: Peter Fang > > Use the TDX Quoting extension's TDH.QUOTE.GET SEAMCALL to generate a > Quote. Since the interface is shared across all KVM instances, > serialize access to the SEAMCALL buffer with a mutex. > > Allocate and return a per-call buffer containing the generated Quote so > callers don't need to size the Quote buffer themselves. The caller is > responsible for freeing the returned buffer. > > Signed-off-by: Peter Fang > Signed-off-by: Xu Yilun > --- > arch/x86/include/asm/tdx.h | 2 + > arch/x86/virt/vmx/tdx/tdx.h | 1 + > arch/x86/virt/vmx/tdx/tdx.c | 82 +++++++++++++++++++++++++++++++++++++ > 3 files changed, 85 insertions(+) > > diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h > index 7b257088aa1e..bc512a00a0d0 100644 > --- a/arch/x86/include/asm/tdx.h > +++ b/arch/x86/include/asm/tdx.h > @@ -177,6 +177,8 @@ struct tdx_vp { > }; > > bool tdx_quote_enabled(void); > +void *tdx_quote_generate(struct tdx_td *td, void *in_data, u32 in_data_len, > + u32 *quote_len); > > static inline u64 mk_keyed_paddr(u16 hkid, struct page *page) > { > diff --git a/arch/x86/virt/vmx/tdx/tdx.h b/arch/x86/virt/vmx/tdx/tdx.h > index 3849f4f9cc78..01a7d7d8ada9 100644 > --- a/arch/x86/virt/vmx/tdx/tdx.h > +++ b/arch/x86/virt/vmx/tdx/tdx.h > @@ -49,6 +49,7 @@ > #define TDH_EXT_INIT 60 > #define TDH_EXT_MEM_ADD 61 > #define TDH_SYS_DISABLE 69 > +#define TDH_QUOTE_GET 98 > #define TDH_QUOTE_INIT 100 > > /* > diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c > index b305fa5aab5c..821f677e9a86 100644 > --- a/arch/x86/virt/vmx/tdx/tdx.c > +++ b/arch/x86/virt/vmx/tdx/tdx.c > @@ -62,6 +62,8 @@ static LIST_HEAD(tdx_memlist); > static struct tdx_sys_info tdx_sysinfo __ro_after_init; > static bool tdx_module_initialized __ro_after_init; > > +static DEFINE_MUTEX(tdx_quote_lock); > + > static struct quote_data { > void *buf; > u64 buf_len; > @@ -1228,6 +1230,86 @@ bool tdx_quote_enabled(void) > } > EXPORT_SYMBOL_FOR_KVM(tdx_quote_enabled); > > +#define QUOTE_ID_MASK GENMASK_U64(47, 32) > + > +static u64 tdx_quote_get(struct tdx_td *td, u64 in_data_pa, u64 in_data_len, > + u64 hpa_list_pa, u64 total_len, u64 *quote_len) > +{ > + struct tdx_module_args args = { > + .rcx = tdx_tdr_pa(td), > + /* Don't bother specifying the quote id */ > + .rdx = QUOTE_ID_MASK & (u64)-1, This is simply equal to QUOTE_ID_MASK, so why not create a special value meaning "ANY QUOTE" i.e #define QUOTE_ID_MASK .... #define ANY_QUOTE QUOTE_ID_MASK or some such . > + .r8 = in_data_pa, > + .r9 = in_data_len, > + .r10 = hpa_list_pa, > + .r11 = total_len, > + }; > + u64 r; > + > + do { > + r = seamcall_ret(TDH_QUOTE_GET, &args); > + } while (r == TDX_INTERRUPTED_RESUMABLE); nit: This pattern seems to repeat a lot, might be worth it to consider introducing a wrapper similar to existing sc_retry? > + > + *quote_len = args.rcx; > + > + return r; > +} > + > +/** > + * tdx_quote_generate() - Generate a quote for a TD > + * @td: The TD to generate the quote for. > + * @in_data: Input data for the quote request. > + * @in_data_len: Size of the input data in bytes. > + * @quote_len: Returned size of the generated quote in bytes. > + * > + * Use the TDX Quoting extension to generate a TD quote. Pass the input data > + * through the shared quote buffer and return the quote. > + * > + * Return: Newly allocated quote buffer or %NULL on failure. > + * The caller must free the returned buffer with kvfree(). > + */ > +void *tdx_quote_generate(struct tdx_td *td, void *in_data, u32 in_data_len, > + u32 *quote_len) > +{ > + void *quote_dup = NULL; > + u64 r, out_len; > + > + if (!tdx_quote_enabled()) > + return NULL; > + > + /* TDH.QUOTE.GET expects the input data to fit in a page */ > + if (in_data_len > PAGE_SIZE) > + return NULL; > + > + mutex_lock(&tdx_quote_lock); > + > + /* > + * Use the first page of the quote buffer for input data. The buffer > + * must be at least one page in size. @in_data may not be page-aligned, > + * but TDH.QUOTE.GET expects page-aligned addresses. > + */ > + memcpy(quote_data.buf, in_data, (size_t)in_data_len); Perhaps you can use min(PAGE_SIZE, in_data_len) and that way you can eliminate the in_data_len check above and copy up-to PAGE_SIZE data, if the data is longer - you will copy PAGE_SIZE which will likely result in error on generating the quote? > + > + r = tdx_quote_get(td, quote_data.hpa_list[0], (u64)in_data_len, > + quote_data.hpa_list_pa, quote_data.buf_len, &out_len); > + if (r || !out_len || out_len > quote_data.buf_len) > + goto out; > + > + /* > + * The quote buffer is a shared resource, so use it only for the > + * SEAMCALL and copy the data out as soon as possible. > + */ > + quote_dup = kvmemdup(quote_data.buf, out_len, GFP_KERNEL); > + > +out: > + mutex_unlock(&tdx_quote_lock); > + > + *quote_len = (u32)out_len; > + > + return quote_dup; > +} > +EXPORT_SYMBOL_FOR_KVM(tdx_quote_generate); > + > #define HPAS_PER_PAGE (PAGE_SIZE / sizeof(u64)) > > static int tdx_quote_create_buf(unsigned int nr_pages, struct quote_data *qdata)