From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5700B606A31C for ; Mon, 30 Nov 2026 03:39:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=XkNS3elx; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=lfFSEhxq DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=M2T7xVcn2Ej0ILSZWeLe9g+OP++Fc3AfZJWp5AP+1uc=; b=XkNS3elxv3q6lt/YytTjo8DM28 DWzzajkMlS2VKC10KkI6G4DZUhPA3wqkSGVJI8pWCR0NHlnBHYgjN5wtGqM2ZayHpk7zQu/9Xy33s 8Njd1TGKyKTkQmeWVIWrLrEh6hX0a0cTRMWuPu/kpxWBKaJkb1o8ICUg3SX9qj2h+ZhDd2WXTQaFS I9bC0Kfk8tf6qVsLnzeEcqGkgQ73Pv2WTOOSn0SFSU4GXZTWfj34Ub9/5toqkiPQbK4PdaUfnMwLD jeI3rwC8ssUIfHvl0r+1Srz3+p1Bk2YZbj4L56djbwm/vQ/fI6fd3THJEWlC/Q+it5QJlPV2CbZPR A6pIk2Ng==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xXsEI-000000038ge-1aC4; Mon, 30 Nov 2026 03:39:02 +0000 Received: from mgamail.intel.com ([198.175.65.15]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xXsEF-000000038fN-3Hjw for linux-arm-kernel@lists.infradead.org; Mon, 30 Nov 2026 03:39:01 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796009940; x=1827545940; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=PR1zwOi+wzopzrFSgj1FcKJLMDt3CWV32oiuzKbhDCY=; b=lfFSEhxq5hxPlpr6GvNLABGU6sz78tun9ZwETTTUgtah1wCPPcBYAshB S31PNBw+xKVg0hysGlJRggjFuSy8WvDvDE0cH6Bj/M90rIT+uNK0pM7bm /dmSk0FqdoHAPTrf4rTI9kXXDha0QpEhUmQz/KhXYcSKbnYp/bmTpEJYE hNGEA81/F8gNNglXFKJNgVJr70favFkLdtz9TxYzUccfUqfekgygxlD7F y0rwbcb9bsmOZUXi/rlpbWEC95fQCLmlR0ui0vXi5Scmw5Qgv6Egyw9yn 7o5tJ4q8sg2h3WezCeOP/46iihxphrU/cRP9BVzy/YiPpy/CMoCo6MQGT A==; X-CSE-ConnectionGUID: 4DSTegKcSbOZ5/dYZg3bhw== X-CSE-MsgGUID: CyEj9SVmTB2GJgkcAsS6sQ== X-IronPort-AV: E=McAfee;i="6800,10657,11981"; a="4815618" X-IronPort-AV: E=Sophos;i="6.27,242,1787036400"; d="scan'208";a="4815618" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Nov 2026 19:38:58 -0800 X-CSE-ConnectionGUID: Vx3kQIvITCeBqyEohd4uqA== X-CSE-MsgGUID: sY6S2EFjR2qiyTBaARFr9Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,242,1787036400"; d="scan'208";a="12994729" Received: from yilunxu-optiplex-7050.sh.intel.com (HELO localhost) ([10.239.47.46]) by orviesa001.jf.intel.com with ESMTP; 29 Nov 2026 19:38:52 -0800 Date: Mon, 30 Nov 2026 11:28:16 +0800 From: Xu Yilun To: "Aneesh Kumar K.V (Arm)" Cc: linux-coco@lists.linux.dev, Alex Williamson , Alexey Kardashevskiy , Bjorn Helgaas , Catalin Marinas , Jacob Pan , Jason Gunthorpe , Joerg Roedel , Jonathan Cameron , Jonathan Hunter , Kevin Tian , Krishna Reddy , Lukas Wunner , Nicolin Chen , Robin Murphy , Samuel Ortiz , Shameer Kolothum , Steven Price , Suravee Suthikulpanit , Suzuki K Poulose , Thierry Reding , Vasant Hegde , Will Deacon , Ashish Kalra , Herbert Xu , Jonathan Cameron , Tom Lendacky , kvm@vger.kernel.org, iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org, linux-tegra@vger.kernel.org, patches@lists.linux.dev Subject: Re: [PATCH v10 03/18] virt: coco: tsm: Remove the device from lookup before PCI teardown Message-ID: References: <20261125081121.379481-1-aneesh.kumar@kernel.org> <20261125081121.379481-4-aneesh.kumar@kernel.org> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261125081121.379481-4-aneesh.kumar@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261129_193859_883418_496E1D8C X-CRM114-Status: GOOD ( 25.17 ) X-Spam-Score: -4.2 (----) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-13.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Wed, Nov 25, 2026 at 01:41:06PM +0530, Aneesh Kumar K.V (Arm) wrote: > PCI connect looks up a TSM by ID under pci_tsm_rwsem. Previously, > pci_tsm_unregister() released that lock after tearing down PCI state > while the TSM was still in the class lookup. A racing connect could then > attach a new PCI context that the teardown would never see. > > Remove the device from the class lookup before pci_tsm_unregister() that > destroy their contexts. Drop the device reference only after PCI > teardown completes. > > Reviewed-by: Kevin Tian > Cc: Alexey Kardashevskiy > Cc: Jason Gunthorpe > Cc: Lukas Wunner > Cc: linux-coco@lists.linux.dev > Fixes: 3225f52cde56 ("PCI/TSM: Establish Secure Sessions and Link Encryption") > Signed-off-by: Aneesh Kumar K.V (Arm) > --- > drivers/virt/coco/tsm-core.c | 20 +++++++++++++------- > 1 file changed, 13 insertions(+), 7 deletions(-) > > diff --git a/drivers/virt/coco/tsm-core.c b/drivers/virt/coco/tsm-core.c > index 3e45b58183e2..863e2f5bb166 100644 > --- a/drivers/virt/coco/tsm-core.c > +++ b/drivers/virt/coco/tsm-core.c > @@ -56,8 +56,8 @@ static struct tsm_dev *alloc_tsm_dev(struct device *parent) > return no_free_ptr(tsm_dev); > } > > -static struct tsm_dev *tsm_register_pci_or_reset(struct tsm_dev *tsm_dev, > - struct pci_tsm_ops *pci_ops) > +static int tsm_register_pci_or_reset(struct tsm_dev *tsm_dev, > + struct pci_tsm_ops *pci_ops) > { > int rc; > > @@ -66,13 +66,12 @@ static struct tsm_dev *tsm_register_pci_or_reset(struct tsm_dev *tsm_dev, > if (rc) { > dev_err(tsm_dev->dev.parent, > "PCI/TSM registration failure: %d\n", rc); > - device_unregister(&tsm_dev->dev); > - return ERR_PTR(rc); > + return rc; > } > > /* Notify TSM userspace that PCI/TSM operations are now possible */ > kobject_uevent(&tsm_dev->dev.kobj, KOBJ_CHANGE); > - return tsm_dev; > + return 0; > } > > struct tsm_dev *tsm_register(struct device *parent, struct pci_tsm_ops *pci_ops) > @@ -96,14 +95,21 @@ struct tsm_dev *tsm_register(struct device *parent, struct pci_tsm_ops *pci_ops) > if (rc) > return ERR_PTR(rc); > > - return tsm_register_pci_or_reset(no_free_ptr(tsm_dev), pci_ops); > + rc = tsm_register_pci_or_reset(tsm_dev, pci_ops); > + if (rc) { > + device_del(dev); > + return ERR_PTR(rc); > + } > + return no_free_ptr(tsm_dev); These changes don't make functional difference, it is just trying to use the same function calls as the tsm_unregister(). I still don't think they are needed: - The postfix "_reset" of tsm_register_pci_or_reset() means the tsm_dev registration would be rolled back on failure. If you split the rollback out, you need to change the function name. - All these new changes would be deleted in next patch, replaced by a new flow. So why bother to make a temporary "neat" version, which wastes reviewer's effort. Maybe a note in changelog is better, like "Don't make the same change on register failure path yet as the tsm_register() flow still needs refactor in the subsequent patch". Though I don't even think a note is needed. > } > EXPORT_SYMBOL_GPL(tsm_register); > > void tsm_unregister(struct tsm_dev *tsm_dev) > { > + /* Remove the class lookup first. */ > + device_del(&tsm_dev->dev); > pci_tsm_unregister(tsm_dev); > - device_unregister(&tsm_dev->dev); > + put_device(&tsm_dev->dev); > } > EXPORT_SYMBOL_GPL(tsm_unregister); > > -- > 2.43.0 >