Re: [RFC PATCH 12/15] KVM: TDX: Add in-kernel Quote generation

From: Edgecombe, Rick P

Date: Wed Jul 22 2026 - 19:48:54 EST


On Fri, 2026-05-22 at 11:41 +0800, Xu Yilun wrote:
> +static u64 __get_quote_kernel(struct kvm_vcpu *vcpu, struct tdx_quote_req *req,
> +       size_t req_len, gpa_t req_gpa, size_t total_len)
> +{
> + struct tdx_td *td = &to_kvm_tdx(vcpu->kvm)->td;
> +
> + /* Only support version 1 as defined in the GHCI spec */
> + if (req->version != 1)
> + return TDX_QUOTE_STATUS_ERROR;
> +
> + if ((size_t)req->in_len + TDX_QUOTE_REQ_HDR_SIZE > req_len)
> + return TDX_QUOTE_STATUS_ERROR;
> +
> + /* The caller frees the quote data */
> + void *quote_data __free(kvfree) =
> + tdx_quote_generate(td, req->data, req->in_len, &req->out_len);
> +
> + if (!quote_data)
> + return TDX_QUOTE_STATUS_UNAVAILABLE;
> +
> + if ((size_t)req->out_len + TDX_QUOTE_REQ_HDR_SIZE > total_len)
> + return TDX_QUOTE_STATUS_ERROR;
> +
> + if (!write_quote_to_guest(vcpu, quote_data, req->out_len, req_gpa))
> + return TDX_QUOTE_STATUS_ERROR;
> +
> + return TDX_QUOTE_STATUS_SUCCESS;
> +}
> +

Kai, Peter and I just had an offlist chat about what internal TDX locks
TDH.QUOTE.GET takes.

The next version of this series needs to come with an analysis of which ones it
contends with and how unhandleable BUSY error codes are avoided with kernel side
locking.

On initial investigation the callers may need to hold
tdx_acquire_vm_state_locks() to avoid contention around TDR lock. TDH.QUOTE.GET
also takes "TDCS.OP_STATE" as exclusive, where TDH.MEM.PAGE.REMOVE takes it for
shared.