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 65033606A333 for ; Tue, 24 Nov 2026 04:28:16 +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=GxOToWjG; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=jeLjHV1j 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:Content-Type:MIME-Version: Message-ID:Date:References:In-Reply-To:Subject:Cc:To:From: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=I0mp7A61esK3VrRBd+nFXF5BVs7NKqG01QIp73dC2D0=; b=GxOToWjGsHMQ6AGXfCbKwB7ElL NNF05I8pv+0pWGMVrjnWpZKHiDLPA6Gmk5qDO84iv+phH1GrmPfUFkHcPoWG19z3G6tsf8eVnKR/1 28DfbVek6ERhcI9XuVwVTSvIz9KC99e9E1JS+70/TS9egGrvoGRUl64SsJYuqz0FcXFhUQb2ZJ65D w5XKgnGvROkKt+bs2CgdTqVHkN14tW7NfecpgGV+EJul4U3Aga0xjg8MDr+pG108k3FJZXkBOU3N2 GM78ilnLWWOB9UBLk45YGK3xMzjZjyp8Yer2SgLnTnxaJgOtrH5SKROI2nsb3Zkte0fcIBLftgi0B SiOT748Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xVhey-00000005Ttn-0XxX; Tue, 24 Nov 2026 03:57:36 +0000 Received: from tor.source.kernel.org ([2600:3c04:e001:324:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xVhej-00000005TnL-24T7 for linux-arm-kernel@lists.infradead.org; Tue, 24 Nov 2026 03:57:22 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id AEAFA6193D; Tue, 24 Nov 2026 03:57:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4A54F1F000D4; Tue, 24 Nov 2026 03:57:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795492639; bh=I0mp7A61esK3VrRBd+nFXF5BVs7NKqG01QIp73dC2D0=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=jeLjHV1j+0TpVU9Hk9tvCDsB72vEt9R80xfmbQ28wipdFEcuw6wQbvCmRZBIyNRw5 VjXgLsKhqp9HdWjZkm2fnw266bar7hbn3O6AmxR5GAchqwTS8coNXKDdhmQCK7fmsX RMAOb6oPASFHBdDKsAM+LPOzPVnQv4fq/vyIAndrCq6ElK7KYlTeOPUtDjwdv0cuMA ddT0isU7gLNybgIWxe2KLs67EAeXaGl991V9GBvvPIBQR4LuP2prMbjv6oXhcOcdPI HSd78mtysn1gzSGQ++YEoyBQkrvxx7YmijwiB5IEtAdHiK4gLdy5EKA/+qrpu/pE4n xIpvvc1TnmASA== X-Mailer: emacs 31.1 (via feedmail 11-beta-1 I) From: Aneesh Kumar K.V To: Xu Yilun 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 , iommu@lists.linux.dev, Jonathan Cameron , Tom Lendacky , kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org, linux-tegra@vger.kernel.org, patches@lists.linux.dev Subject: Re: [PATCH v9 02/13] virt: coco: tsm: Remove the device from lookup before PCI teardown In-Reply-To: References: <20261116081935.85372-1-aneesh.kumar@kernel.org> <20261116081935.85372-3-aneesh.kumar@kernel.org> Date: Tue, 24 Nov 2026 09:27:04 +0530 Message-ID: X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain 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=-15.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 Xu Yilun writes: > On Mon, Nov 16, 2026 at 01:49:24PM +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 first, then take the PCI write >> lock to drain in-flight operations and 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 03894c5663f1..57db3f14cf46 100644 >> --- a/drivers/virt/coco/tsm-core.c >> +++ b/drivers/virt/coco/tsm-core.c >> @@ -56,23 +56,22 @@ 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(struct tsm_dev *tsm_dev, struct pci_tsm_ops *pci_ops) >> { >> int rc; >> >> tsm_dev->pci_ops = pci_ops; >> rc = pci_tsm_register(tsm_dev); >> if (rc) { >> + tsm_dev->pci_ops = NULL; > > Previous comment shows this can't solve any racing connect problem. > And with your next patch, the racing connect is solved. So I think > remove it. > I don't follow. This only undoes the changes made before pci_tsm_register() on the error path. > >> 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; > > I really don't think we need this wrapper. In next patch we move uevent > out, so this wrapper is just: > > tsm_dev->pci_ops = pci_ops; > pci_tsm_register(); > > Open code it, as Alexey and I suggest before. All kinds of xxx_tsm_register() > are really confusing. > I do that in the next patch, after moving the kobject_uevent() call out of the helper. > >> } >> >> struct tsm_dev *tsm_register(struct device *parent, struct pci_tsm_ops *pci_ops) >> @@ -96,15 +95,22 @@ 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(tsm_dev, pci_ops); >> + if (rc) { >> + device_del(dev); >> + return ERR_PTR(rc); >> + } >> + return no_free_ptr(tsm_dev); > > I think none of the above changes belongs to this patch. They don't > solve any problem mentioned in the changelog. > > They belong to the next patch. > We are replacing device_unregister() with device_del() followed by put_device(), so the error path should follow the same pattern. > >> } >> EXPORT_SYMBOL_GPL(tsm_register); >> >> void tsm_unregister(struct tsm_dev *tsm_dev) >> { >> + /* Remove the class lookup first. */ >> + device_del(&tsm_dev->dev); >> if (tsm_dev->pci_ops) > > The patch 1 rejects NULL pci_ops, so is this check still needed? Can we > remove this check in your Patch 1? > Sure, I will remove the check in the next revision. > >> pci_tsm_unregister(tsm_dev); >> - device_unregister(&tsm_dev->dev); >> + put_device(&tsm_dev->dev); >> } >> EXPORT_SYMBOL_GPL(tsm_unregister); >> -aneesh