From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796286215; b=06+Eg1d08PAB0E5FyoTS82FoYKX5gedtBlQ2AeOvOgUdgNfSBdt/XwCi3YZPqtVFKoys Au01rTwd996zaCk94kN0MlBvXcAXenFE6UaJ7mksHQ8bUqVOd7ozhZvLNxvMjOsZAcHRq qRnl0/izmT/LsPnvNskS2h+3O54CvZBRkew8jugsqCE7IY5k/waebZuBbPnsrDsgqCCf7 Pz/QMZQHNam/rkNvxcpuT7q2mlw0QqB1+TQF3LhJubQsMaT/BnaS7mrq2cXX9RMhkW//v 3wbrR6Iy6E2QAbI4Joz9Pozb8k/6hsgiBvQ4yHRiMXdXgbWWs4M8bMGaXzlK6elXM9w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796286215; h=Received:DKIM-Signature:X-Mailer:From:To:Cc:Subject:In-Reply-To: References:Date:Message-ID:MIME-Version:Content-Type; bh=9UDDopUcjrIQP/BRDKeLFMYpEXO7XKZ5vBgNx0zWF0E=; b=nIiv3j0w01pHM0D3IgIQa07CCLO+FzfkTEtK9N7B1QJovu8dA5l88GJJI8iSwMyu9n8P mAFFtaCI3uAQe+WLMkCuEVea7PDL4mmKTvUP5hrE3CgWQNoeZD2pxU78pTKo5A718VVcv pzgdWFlCiQepRJL0yP5LlpjlyLTJ2VUowvb3ANNcx7jhzs+qkbcAo6W/AhtalEQStFsSE SnoVWkUpuzmlrXPjB4P25kj4wZ6GV/OnpslLGaK20Me0KAeILNTdLSNTZa/XD9pUA32M5 FF9KNRk9b7u9PJNSNp13EbfMBKexRFpJ2EnQP49+Yx+ZTUOHhUQ9Nsu6aTBbWvhzSEg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Gi+mPEzI; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7EFFC606A32C; Thu, 3 Dec 2026 08:23:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Gi+mPEzI 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-Mailing-List: linux-coco@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain 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