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=1796205854; b=SkC1bCozNSPPEIBCRGnEBBo5JmSiSAjYTLPsh3CGA1oviGYWYNVt/KkD5BuBnzUDA14w jfbDPAOvECEebVqnRyVa7vYiWdXuHLO3JPHXoIE6EEfeZduAMACEB0bZLeaqLG5JiRuLw dP/v939vhWBK1UNDOsN9dpBv9uteVLJcD3I6tU8BPqwtphug+REHQGHHmLjc4wD9qjCaH 0jU5a13ogGt/iywC3cGUq7e5hu7HKMXcrpjO7ywR8gVw5rZW9i98041CcmQAok49OGcFo LG8jw2DsKgiJJnbEK6bMTGMzI5yQ1M3DXfSk0OLCBj0aM6BqnV1H8C+1rICtickuCdQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796205854; h=Received:DKIM-Signature:X-Mailer:From:To:Cc:Subject:In-Reply-To: References:Date:Message-ID:MIME-Version:Content-Type; bh=JW8JT6sg4bkIrxj1bGbZGsXckZcN5+mNA9SuZwpatMs=; b=kbiGzOHbLAWarjGkQghyLKr9HSG4TVv87JUgQvjAQ5o1nj1djQMJEIUd6RaC3Un8NlYS 0qVkJHn4+SBwJGBWtVbBiBIytOtVb1D5YovbZB7h2IwBpIdtsK5M7+SGoDZ5fZfgNTh3I y8qruzeJPT77BTgBV5dRcT4JrNivAvwIgJBP0OSPOKNjK6z/pt149GayGpjgYwBsIYnyi AezcitAUt3zPxq0GMZQA2JXHwFN13Gp0OsH+txw6otLVE5mUxOYA/4pdbTHj+ZMdWAMcj RHUAiD8Q6BGVQ/jbWFeDfCENXo9kl+LaVkDy0gbJ29Mkur2NEU8l1Y2YP5vppngCplQ== 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=IBgymjM9; 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 B29B1606A31A; Wed, 2 Dec 2026 10:04:14 +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=IBgymjM9 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42E6B1F00893; Wed, 2 Dec 2026 10:04:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796205854; bh=JW8JT6sg4bkIrxj1bGbZGsXckZcN5+mNA9SuZwpatMs=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=IBgymjM9CFe3OcPSBKTfpgpNCMndW3GkTkljCjii5UwKTpaKqpmWjrbpJ0AMe1wCK yKhiiYzbMNK+ACov6OLRPTH9zcNTI9vFKj0OekIurBMxPmRMY/z6j6Tqmor+8c+GsO +dXfKZyxoykgsj0WBDHEwzuUc9Q0VNxxVDNOT1h3oxf3+ecbVCszdxgl43hbhE2HRZ 9eJLFRNXbqifGRmEqWhlc9rGwuLxsgFUhHB60d35WnOnZ5fzE5c0dkooPiuCApV/pP yHN6Xsif6nYFpzLcmemvP9oiZh+sfALA15+5Pev74mlJv+sMXBduBCuxmnLXvgj9Kk lhASadIKW6mqA== X-Mailer: emacs 31.1 (via feedmail 11-beta-1 I) From: Aneesh Kumar K.V To: Zhenzhong Duan Cc: linux-coco@lists.linux.dev, Dan Williams , Leon Romanovsky , Bjorn Helgaas , Jason Gunthorpe , Jonathan Cameron , Xu Yilun , Alexey Kardashevskiy , Greg Kroah-Hartman , "Rafael J . Wysocki" , Steven Price , Suzuki K Poulose , Lukas Wunner , Ashish Kalra , Tom Lendacky , Herbert Xu , driver-core@lists.linux.dev, linux-pci@vger.kernel.org, kvm@vger.kernel.org, patches@lists.linux.dev Subject: Re: [PATCH v1 08/10] PCI/TSM: Add sysfs lock and unlock for guest-assigned devices In-Reply-To: References: <20261123083337.2731019-1-aneesh.kumar@kernel.org> <20261123083337.2731019-9-aneesh.kumar@kernel.org> Date: Wed, 02 Dec 2026 15:34:03 +0530 Message-ID: X-Mailing-List: driver-core@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 Zhenzhong Duan writes: > On Mon, Nov 23, 2026 at 02:03:35PM +0530, Aneesh Kumar K.V (Arm) wrote: >> A confidential guest needs to lock a PCI device before collecting and >> verifying evidence about it. Userspace also needs a way to unlock the >> device after use or when verification fails. >> >> Add tsm/lock and tsm/unlock sysfs attributes for TSM drivers >> implementing devsec_ops. Writing a TSM device name to tsm/lock calls its >> lock callback. Unlock calls the matching driver's unlock callback >> >> Take device::mutex to prevent driver attachment, then pci_tsm_rwsem >> for write to protect pci_dev::tsm during either operation. This order >> matches PCI DMA preparation, which runs with the device mutex held. >> Return -EBUSY if a PCI driver is already attached. Also call unlock >> during PCI device removal or TSM unregister, using the same lock order. >> Guest TSM unregister processes one PCI device at a time and releases >> both locks before moving to the next device. >> >> Require ARCH_HAS_CC_PLATFORM and select CONFIDENTIAL_DEVICES so >> pci_tsm_unlock() clears the device's accepted state. >> >> Expose the TSM class device's pci_mode attribute so userspace can >> distinguish host link TSM from guest device-security TSM. Evidence >> retrieval and acceptance are handled separately through the attestation >> subsystem. >> >> Based on the original Device Security LOCK patch from >> Dan Williams , adapted to the current PCI/TSM structures >> and locking rules. >> >> Signed-off-by: Aneesh Kumar K.V (Arm) >> --- >> Documentation/ABI/testing/sysfs-bus-pci | 35 ++- >> Documentation/ABI/testing/sysfs-class-tsm | 19 ++ >> Documentation/driver-api/pci/tsm.rst | 47 ++++ >> drivers/pci/Kconfig | 2 + >> drivers/pci/tsm.c | 247 ++++++++++++++++++++-- >> drivers/virt/coco/tsm-core.c | 48 ++++- >> include/linux/pci-tsm.h | 21 +- >> 7 files changed, 401 insertions(+), 18 deletions(-) > > <...> > >> +/** >> + * pci_tsm_unlock() - Transition TDI from LOCKED/RUN to UNLOCKED >> + * @pdev: TDI device to unlock >> + * >> + * Returns void, requires all callers to have satisfied dependencies like making >> + * sure the device is locked and detached from its driver. >> + */ >> +static void pci_tsm_unlock(struct pci_dev *pdev) >> +{ >> + lockdep_assert_held_write(&pci_tsm_rwsem); >> + device_lock_assert(&pdev->dev); >> + >> + if (dev_WARN_ONCE(&pdev->dev, pdev->dev.driver, >> + "unlock attempted on driver attached device\n")) >> + return; >> + >> + device_cc_reject(&pdev->dev); >> + to_pci_tsm_ops(pdev->tsm)->unlock(pdev->tsm); >> + pdev->tsm = NULL; >> +} > > Vendor specific unlock() implemenation can fail for whatever reason, don't > we need to return the failure to caller and finally to userspace? > > I looked into old thread but didn't find why, sorry if I missed. > Yes. This was in part based on how pci_tsm_destroy() was handled, and that path did not handle errors. We have since changed it so that PCI device destruction waits for device disconnect, which returns -EBUSY if the device is still locked. Unlock is a CTLV spdm-end operation and can return an error status, so we should propagate that error to the caller and userspace. -aneesh