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 415B8606A322 for ; Thu, 3 Dec 2026 08:23:43 +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=tM4C0528; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Gi+mPEzI 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=9UDDopUcjrIQP/BRDKeLFMYpEXO7XKZ5vBgNx0zWF0E=; b=tM4C0528MYGni2XIDx+KxilZaP jDi/dKHzd8qZn8G696cOXsrmTgDgQDApK60u+6eSAu6vNrWTuhSvYnK9kIzfSZ7IMIXo/1duHdQLN i/z/pvxMhq3mpvyOwKuJ0jpOrMsCMEfbxJDvJYoVGm1J/C3LXv2vOlA27Iwyw8Okjjy7Xsem8oo3o bLDZNHMkEdfVXxMZ/KSw0UWj+OPAgJsyhwsQRDETQPcWCtCymYCWtEJ/5APR/VlcOt9sxT+Sd3kna Qna2QRpQFu5dMSCl5daJPnr0iJKX/hHp/d2QjuaWV2pjC1oc9eO0cMPGvG+0vurOAxnxAFCNkt7kh BZ6mZ17A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZ26L-0000000DpbP-0jDT; Thu, 03 Dec 2026 08:23:37 +0000 Received: from sea.source.kernel.org ([172.234.252.31]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZ26J-0000000Dpb6-2snU for linux-arm-kernel@lists.infradead.org; Thu, 03 Dec 2026 08:23:35 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 3C84444879; Thu, 3 Dec 2026 08:23:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 76C541F000C1; Thu, 3 Dec 2026 08:23:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796286215; bh=9UDDopUcjrIQP/BRDKeLFMYpEXO7XKZ5vBgNx0zWF0E=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=Gi+mPEzIz68GekDiXij96c+mVNK1TEIS+3ATkqnxkhLoa6GiRtfYTLFcFTiGZsKyb EPTvCDGWbUBOt5Yy3b3OReYbChZiMzdlpsTplH+9IJ6tZK060O9wvU7Mh9QeDOERVr NDSckjdAL2KLiH5xCVkePBpKT46QFAPB8Kh3mzkgTOJe4lDNodJTXoL+/PyjrakZDY BlsCruTTWFG4xlZhwHhfRKvvZU9NZASANtsEVo1SD9Tzvub9VS0gwjMFlocHUN2WQw 2aYjUGY3u2CfMDcqp5L46vdewcxwNZ8aySQV045PF+PdOFQvi8l99SxVFEWlbGf5F2 H0sKZmtXLEo5g== X-Mailer: emacs 31.1 (via feedmail 11-beta-1 I) From: Aneesh Kumar K.V To: Baolu Lu , linux-coco@lists.linux.dev Cc: baolu.lu@linux.intel.com, 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 , Xu Yilun , 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 10/18] PCI/TSM: Add helpers to prevent disconnect while in use In-Reply-To: References: <20261125081121.379481-1-aneesh.kumar@kernel.org> <20261125081121.379481-11-aneesh.kumar@kernel.org> Date: Thu, 03 Dec 2026 13:53:22 +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 Baolu Lu writes: > On 11/25/2026 4:11 PM, Aneesh Kumar K.V (Arm) wrote: >> Add PCI TEE Security Manager (TSM) helpers that prevent PF0 disconnect >> while a function is in use. Validate the function's TSM association and >> increment PF0's dsm_context_users count on get. Find PF0 through the >> same function and decrement the count on put. Reject disconnect with >> -EBUSY until all users have released it. >> >> The caller must prevent removal of the function between get and put, for >> example by keeping its VFIO device open. No per-call allocation is >> needed. >> >> Cc: Bjorn Helgaas >> Cc: linux-pci@vger.kernel.org >> Cc: Alexey Kardashevskiy >> Cc: Jason Gunthorpe >> Cc: Lukas Wunner >> Signed-off-by: Aneesh Kumar K.V (Arm) >> --- >> Documentation/ABI/testing/sysfs-bus-pci | 1 + >> drivers/pci/tsm.c | 79 ++++++++++++++++++++++--- >> include/linux/pci-tsm.h | 14 +++++ >> 3 files changed, 85 insertions(+), 9 deletions(-) >> >> diff --git a/Documentation/ABI/testing/sysfs-bus-pci b/Documentation/ABI/testing/sysfs-bus-pci >> index be9126e56894..2906257eb610 100644 >> --- a/Documentation/ABI/testing/sysfs-bus-pci >> +++ b/Documentation/ABI/testing/sysfs-bus-pci >> @@ -660,6 +660,7 @@ Contact: linux-coco@lists.linux.dev >> Description: >> (WO) Write the name of the TSM device that was specified >> to 'connect' to teardown the connection. >> + The write fails with EBUSY if the TSM is in use. > > "In use" is vague for an ABI document. Something like "while any > function managed by this DSM is assigned to a TVM" would tell userspace > what to undo before retrying. > Sure, I'll update the ABI documentation. > >> >> What: /sys/bus/pci/devices/.../tsm/dsm >> Contact: linux-coco@lists.linux.dev >> diff --git a/drivers/pci/tsm.c b/drivers/pci/tsm.c >> index 1423c64dc9c8..73f16a9a78ef 100644 >> --- a/drivers/pci/tsm.c >> +++ b/drivers/pci/tsm.c >> @@ -292,6 +292,51 @@ static int remove_fn(struct pci_dev *pdev, void *data) [ ... 109 lines skipped ... ] >> >> - if (is_link_tsm(tsm_dev) && is_pci_tsm_pf0(pdev)) >> - pci_tsm_disconnect(pdev); >> - else >> + if (is_link_tsm(tsm_dev) && is_pci_tsm_pf0(pdev)) { >> + if (pci_tsm_disconnect(pdev)) >> + pci_warn(pdev, "TSM connection is still in use\n"); > > This will cause leaks and use-after-free. A warning is not a good > solution for such BUSY case in a cannot-fail path. > The full series makes both the destroy and disconnect paths wait, similar to how VFIO makes PCI device destruction wait. The final two patches implement this. > >> + } else { >> pci_tsm_fn_exit(pdev); >> + } >> } >> -aneesh