RE: [RFC PATCH 06/15] virt: tdx-guest: Support TDI bind and unbind operations
From: Duan, Zhenzhong
Date: Tue Oct 27 2026 - 06:22:23 EST
>-----Original Message-----
>From: Li, Xiaoyao <xiaoyao.li@xxxxxxxxx>
>Subject: Re: [RFC PATCH 06/15] virt: tdx-guest: Support TDI bind and unbind
>operations
>
>On 9/24/2026 12:10 PM, Zhenzhong Duan wrote:
>> Introduce support for binding and unbinding the Trust Device Interface
>> (TDI) using the TDCM_OP_BIND and TDCM_OP_UNBIND commands.
>>
>> Executing TDCM_OP_BIND transitions the TDI state to a locked state
>> (TDI_STATE_CONFIG_LOCKED). Add a sanity check following the bind
>operation
>> to verify this state transition succeeded before finalizing device
>locking.
>
>Can we expand it to talk more about the BIND and UNBIND?
OK.
>
>> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@xxxxxxxxx>
>> ---
>> drivers/virt/coco/tdx-guest/connect.c | 75 +++++++++++++++++++++++++++
>> 1 file changed, 75 insertions(+)
>>
>> diff --git a/drivers/virt/coco/tdx-guest/connect.c
>b/drivers/virt/coco/tdx-guest/connect.c
>> index 1f52a187b30f..e36515fc43ef 100644
>> --- a/drivers/virt/coco/tdx-guest/connect.c
>> +++ b/drivers/virt/coco/tdx-guest/connect.c
>> @@ -159,8 +159,67 @@ static bool tdx_is_dev_teeio_support(struct
>tdx_devsec *tdevsec)
>> return !!rsp->is_supported;
>> }
>>
>> +static struct tdx_devsec *tdx_tdi_bind_dev(struct tdx_devsec *tdevsec)
>> +{
>> + struct pci_dev *pdev = tdevsec->pci.base_tsm.pdev;
>> + int ret;
>> +
>> + struct tdcm_ctx *tdcm __free(tdx_tdcm_free) = tdx_tdcm_alloc(pdev,
>TDCM_OP_BIND, 0, 0);
>> + if (IS_ERR(tdcm))
>> + return ERR_CAST(tdcm);
>> +
>> + ret = tdx_tdcm_run(tdcm);
>> + if (ret)
>> + return ERR_PTR(ret);
>> +
>> + return tdevsec;
>> +}
>
>This return tdevsec and ...
>
>> +
>> static struct pci_tsm *tdx_devsec_lock(struct tsm_dev *tsm_dev, struct
>pci_dev *pdev)
>> {
>> + u8 state;
>> int ret;
>>
>> struct tdx_devsec *tdevsec __free(kfree) = kzalloc(sizeof(*tdevsec),
>GFP_KERNEL);
>> @@ -174,6 +233,19 @@ static struct pci_tsm *tdx_devsec_lock(struct
>tsm_dev *tsm_dev, struct pci_dev *
>> if (!tdx_is_dev_teeio_support(tdevsec))
>> return ERR_PTR(-EOPNOTSUPP);
>>
>> + struct tdx_devsec *tdevsec_bind __free(tdx_tdi_unbind_dev) =
>tdx_tdi_bind_dev(tdevsec);
>
>... the __free(tdx_tdi_unbind_dev) are not easy to follow.
>
>I'm worried if it is OK to Dave given the previous discussion[1]
>
>[1] https://lore.kernel.org/all/70056924-1702-4020-b805-
>014efb87afdd@xxxxxxxxx/
I see in another comments Dave said "It depends", though I'm not clear
his choice on this error path. I think we can keep it as is and do the
change once he commented his preference here. Switching to goto is a
trivial work here.
https://lore.kernel.org/all/e3830b06-dac8-4f22-bd07-98073886678a@xxxxxxxxx/