From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.16 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796115401; b=xpQfwgpMGZTDejp1p+QvDyXSse1VM2ifVFVjwsITk4R+G11ngyfj0zUcu2wdqfaZ+2Qn kznESSCveGhInNUlBFSydcclaZ32SRwVMr2LEfMB8vTEdObQXVni5fYFSHbaLzPt6VG12 wAsmx62TdktKdWy0tVTQHlFjz8wpgxvS+KX305eaC3T0YnXQn8Pyop08sARge2xIKE6Ry Vl5QsFdBBSTqYgD1h+DbXdlH1ekoSKAKjsYPSSK2k5nb9gudtQwPKDFdSc80Qykn07UUc n5daDRb861Y6nbYfSMJRiYkAX5ufBk1Ll7NFQCuxnpPMM3wfAz4LEMVJ367TMSBXAAw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796115401; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:Date:From:To:Cc: Subject:Message-ID:References:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; bh=e6LxdO7OiNovFbJslmHGg/Vm8tlmlD/mHTMxoQupAl0=; b=RgNIXkmaVCIsJ6JC+5Gw9n72GCbgyAF4FlqZtJKX5SAWnwExgSw56WD89auZtiMVvGQ/ zi5YJdxlE4wJE8EKDzM1sxiH4NK2MABPNhFZZjo68ebzQy8vAVcusAR5YdH+MkyxB38FF YkEDlSBdS8rfLbWAwM8ZWiK3YSI1kOMYNJ7yPzWMDvYzxfVU1oPfnd05iobRfdZ01SCO4 QQXojctA2SHvFBNLFoLziV1gzFtyVUmVEWDTxMjK1T6SiPo2ZbkFmXq7etsAIq+MQNFZg XZsnCCvgjRSq2bHiV6LKcu2CVZyruwuFbwkBula2fe6j2JrQ/13Wwxu1Xy5CWZ4szlw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=SuCg7+bO; arc=none smtp.remote-ip=192.198.163.16 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.16]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DB674606A320; Tue, 1 Dec 2026 08:56:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DB674606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=SuCg7+bO DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796115401; x=1827651401; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=e6LxdO7OiNovFbJslmHGg/Vm8tlmlD/mHTMxoQupAl0=; b=SuCg7+bO6h8Z0fw+1cj74T08/LDffim93nXlqaM70h7GFD8cUTHudYL9 QX4/+tJAP+Q0hjiHQCHN1u1SbKcgvs78Efes+UQBJUamqVCK7oilabrpA ZTe7uwvJ8nehFJ6bt7b3a19hPs0VoKBpMpe/WgzPs5coJBx4iAyOoFnfF exMACffqS7r/3eo4Ahd694YpYGT1gcmoGryphw7OEDKXlZiBCJGkCWhze n0r37d0Njfb+gGxXfREx2dfRT+4QfJswRMQmQ2sEwpcawP7qhS0olPS3L NmJVdCiTy5jp0YTw0sVK1b5ZvIe7bCTANALFf/Mb3CQmSFIy8D+NWlfK+ A==; X-CSE-ConnectionGUID: Hqk343WQRNWsUGeP7Yhcag== X-CSE-MsgGUID: BFakA0esR3O5mh4QxAoDIA== X-IronPort-AV: E=McAfee;i="6800,10657,11982"; a="4984153" X-IronPort-AV: E=Sophos;i="6.27,244,1787036400"; d="scan'208";a="4984153" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa110.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2026 00:56:40 -0800 X-CSE-ConnectionGUID: Y75WSdExQTS4D3C276mgnA== X-CSE-MsgGUID: rd5FxMmvQ6WskhvmPx0eWw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,244,1787036400"; d="scan'208";a="13314739" Received: from unknown (HELO gnr-sp-2s-612) ([10.112.229.148]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2026 00:56:36 -0800 Date: Tue, 1 Dec 2026 16:56:28 +0800 From: Zhenzhong Duan To: "Aneesh Kumar K.V (Arm)" 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 Message-ID: References: <20261123083337.2731019-1-aneesh.kumar@kernel.org> <20261123083337.2731019-9-aneesh.kumar@kernel.org> 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; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261123083337.2731019-9-aneesh.kumar@kernel.org> 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. Thanks Zhenzhong