From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C00C31BC41 for ; Mon, 10 Nov 2025 11:45:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.176.79.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762775130; cv=none; b=FN6RlCzQe3WPToOK43+qxeP7iXTWFHKcGMHX088or00SpYyjHHkkhMDCpQQYzbNL4m4rOsvXIflaM06uOVlWTcm1djtKhU14j3K896DyaNmZbwESCf492/byKBpXU4m7hEzz2DSiMrLIj4FweqCkcnC1/FSiJrG24t9DN5FvAYQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762775130; c=relaxed/simple; bh=mO+M3OsZ99LF3rLkInL/l5A71FoJ9EbfBycGqzjIcy8=; h=Date:From:To:CC:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=PoCttXPFDxwxSvBX0Tv+HP4U83o3KjR5Bj6asxy+YQLrYC606KYTAwXS10p5NddOmupSsbyju08hyiAZlo8vHEzdU7irwLsk8NKPz7V7fs617Bm2lYaFOZtfUsWTsupmYxIpln67tBB4lcUW+AKlnumdmrMwIGex3g64HUtqtj8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=185.176.79.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.18.186.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTPS id 4d4nsC5DyxzHnGf6; Mon, 10 Nov 2025 19:45:03 +0800 (CST) Received: from dubpeml100005.china.huawei.com (unknown [7.214.146.113]) by mail.maildlp.com (Postfix) with ESMTPS id C4D2C14038F; Mon, 10 Nov 2025 19:45:18 +0800 (CST) Received: from localhost (10.203.177.15) by dubpeml100005.china.huawei.com (7.214.146.113) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.36; Mon, 10 Nov 2025 11:45:18 +0000 Date: Mon, 10 Nov 2025 11:45:17 +0000 From: Jonathan Cameron To: Xu Yilun CC: , , , , Subject: Re: [RFC PATCH 20/27] coco/tdx-host: Add connect()/disconnect() handlers prototype Message-ID: <20251110114517.00000280@huawei.com> In-Reply-To: References: <20250919142237.418648-1-dan.j.williams@intel.com> <20250919142237.418648-21-dan.j.williams@intel.com> <20251030112055.00001fcb@huawei.com> <69093bf7d6ee_74f59100fe@dwillia2-mobl4.notmuch> X-Mailer: Claws Mail 4.3.0 (GTK 3.24.42; x86_64-w64-mingw32) Precedence: bulk X-Mailing-List: linux-coco@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-ClientProxiedBy: lhrpeml500009.china.huawei.com (7.191.174.84) To dubpeml100005.china.huawei.com (7.214.146.113) On Thu, 6 Nov 2025 13:18:41 +0800 Xu Yilun wrote: > On Mon, Nov 03, 2025 at 03:34:15PM -0800, dan.j.williams@intel.com wrote: > > Jonathan Cameron wrote: > > > On Fri, 19 Sep 2025 07:22:29 -0700 > > > Dan Williams wrote: > > > > > > > From: Xu Yilun > > > > > > > > Add basic skeleton for connect()/disconnect() handlers. The major steps > > > > are SPDM setup first and then IDE selective stream setup. > > > > > > > > No detailed TDX Connect implementation. > > > > > > > > Signed-off-by: Xu Yilun > > > > Signed-off-by: Dan Williams > > > Feels like use of __free() in here is inappropriate to me. > > > > > > > --- > > > > drivers/virt/coco/tdx-host/tdx-host.c | 49 ++++++++++++++++++++++++++- > > > > 1 file changed, 48 insertions(+), 1 deletion(-) > > > > > > > > diff --git a/drivers/virt/coco/tdx-host/tdx-host.c b/drivers/virt/coco/tdx-host/tdx-host.c > > > > index f5a869443b15..0d052a1acf62 100644 > > > > --- a/drivers/virt/coco/tdx-host/tdx-host.c > > > > +++ b/drivers/virt/coco/tdx-host/tdx-host.c > > > > @@ -104,13 +104,60 @@ static int __maybe_unused tdx_spdm_msg_exchange(struct tdx_link *tlink, > > > > return ret; > > > > > > > + > > > > +static void __tdx_link_disconnect(struct tdx_link *tlink) > > > > +{ > > > > + tdx_ide_stream_teardown(tlink); > > > > + tdx_spdm_session_teardown(tlink); > > > > +} > > > > + > > > > +DEFINE_FREE(__tdx_link_disconnect, struct tdx_link *, if (_T) __tdx_link_disconnect(_T)) > > > > + > > > > static int tdx_link_connect(struct pci_dev *pdev) > > > > { > > > > - return -ENXIO; > > > > + struct tdx_link *tlink = to_tdx_link(pdev->tsm); > > > > + int ret; > > > > + > > > > + struct tdx_link *__tlink __free(__tdx_link_disconnect) = tlink; > > > I'm not a fan on an ownership pass like this just for purposes of cleaning up. > > > > Yeah this needs a rethink. The session and the stream are independent > > resources. It can be a composite object that encapsulates both > > resources, but not tlink directly. > > > > ...chalk this up to RFC expediency. > > > > > I'd be a bit happier if you could make it > > > struct tdx_link *tlink __free(__tdx_link_disconnect) = to_tdx_link(pdev->dsm); > > > > > > but I still don't really like it. I think I'd just not use __free and stick > > > to traditional cleanup in via a goto. > > > > I would not go that far, but certainly I can see that being preferable > > than reusing the existing base 'struct tdx_link *' as the cleanup > > variable. > > The latest implementation internally is as follows. tlink_spdm & > tlink_ide represent independent resources though they point to the same > instance. I'm already comfortable about this code: > > static int tdx_link_connect(struct pci_dev *pdev) > { > struct tdx_link *tlink = to_tdx_link(pdev->tsm); > > struct tdx_link *tlink_spdm __free(tdx_spdm_session_teardown) = > tdx_spdm_session_setup(tlink); > if (IS_ERR(tlink_spdm)) { > pci_err(pdev, "fail to setup spdm session\n"); > return PTR_ERR(tlink_spdm); > } > > struct tdx_link *tlink_ide __free(tdx_ide_stream_teardown) = > tdx_ide_stream_setup(tlink); > if (IS_ERR(tlink_ide)) { > pci_err(pdev, "fail to setup ide stream\n"); > return PTR_ERR(tlink_ide); > } > > retain_and_null_ptr(tlink_spdm); > retain_and_null_ptr(tlink_ide); > > return 0; > } Nice. That looks good to me. J