From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.15 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796009941; b=HejLRZCR3EeNHxKjiju1WbGyimTHUjfFrOHaO8hxPg0C6/nmxJifDi6Vz2RiUPoS9RoG WqX7V+YFW5Mq33tSCPGoRo8bANzUSCSMcJAPHdf8y6Bri41w3l1YcRTf/0Yd20iZ9LNAr gBtqRX4Tv3gf4WvJjmXn34wwIefzoLJHadh09W6uP4Ges1VS7vmMwWjiuzE8NvYS+/gwa hWSbNUCEbnF7QqCxhRoIu0xguyoy187amvz0FUXNSsigldM+apFOuVLz3YudgNrvW1O7j TncKchu0TeHfK9ei7Oh6dMRNjd0MgWU/Y9idcztGpxbG8hG1QSnJiKOHcNxn7FW69Jw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796009941; 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=M2T7xVcn2Ej0ILSZWeLe9g+OP++Fc3AfZJWp5AP+1uc=; b=PTSaA3OlErEmiNK6JTuEqWsSF/HFT7P6hjHdrqHsvDEruFXu3f9GQvQ6ac3Z1DUOoRao vgUOAbvOpGEpcLh46IqVg3iygK0eU+Ty3MeUV9sol/KHgcPMsheVuarutGuGGWu/jnATG bWx8pM5tEfygXgEKf+0E/FJAfYIR7rDqQXUMG4aTNy5bEm+mkk+bu/b0abZQ4rrGyIhE7 BCWZokz2/FX4PKe4zpWnpUQO2UsAIYRKa65ngw0MPED/tvjguHV9IkMu2N4Nuduk4MxVq Oi26XNGk01T8lsvh903SeCml6kejDycCWY1324pPB+afbvc2sw5j/j4/IZq702QoyQg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=lfFSEhxq; arc=none smtp.remote-ip=198.175.65.15 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) (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 DCEA6606A329; Mon, 30 Nov 2026 03:38:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DCEA6606A329 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.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=lfFSEhxq DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796009940; x=1827545940; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=PR1zwOi+wzopzrFSgj1FcKJLMDt3CWV32oiuzKbhDCY=; b=lfFSEhxq5hxPlpr6GvNLABGU6sz78tun9ZwETTTUgtah1wCPPcBYAshB S31PNBw+xKVg0hysGlJRggjFuSy8WvDvDE0cH6Bj/M90rIT+uNK0pM7bm /dmSk0FqdoHAPTrf4rTI9kXXDha0QpEhUmQz/KhXYcSKbnYp/bmTpEJYE hNGEA81/F8gNNglXFKJNgVJr70favFkLdtz9TxYzUccfUqfekgygxlD7F y0rwbcb9bsmOZUXi/rlpbWEC95fQCLmlR0ui0vXi5Scmw5Qgv6Egyw9yn 7o5tJ4q8sg2h3WezCeOP/46iihxphrU/cRP9BVzy/YiPpy/CMoCo6MQGT A==; X-CSE-ConnectionGUID: mCMiraLhSDq/gbei/EzNgg== X-CSE-MsgGUID: MDc4WFpERQuSX5ar+Oe6tg== X-IronPort-AV: E=McAfee;i="6800,10657,11981"; a="4815615" X-IronPort-AV: E=Sophos;i="6.27,242,1787036400"; d="scan'208";a="4815615" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Nov 2026 19:38:58 -0800 X-CSE-ConnectionGUID: Vx3kQIvITCeBqyEohd4uqA== X-CSE-MsgGUID: sY6S2EFjR2qiyTBaARFr9Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,242,1787036400"; d="scan'208";a="12994729" Received: from yilunxu-optiplex-7050.sh.intel.com (HELO localhost) ([10.239.47.46]) by orviesa001.jf.intel.com with ESMTP; 29 Nov 2026 19:38:52 -0800 Date: Mon, 30 Nov 2026 11:28:16 +0800 From: Xu Yilun To: "Aneesh Kumar K.V (Arm)" 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 , 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 03/18] virt: coco: tsm: Remove the device from lookup before PCI teardown Message-ID: References: <20261125081121.379481-1-aneesh.kumar@kernel.org> <20261125081121.379481-4-aneesh.kumar@kernel.org> 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; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261125081121.379481-4-aneesh.kumar@kernel.org> On Wed, Nov 25, 2026 at 01:41:06PM +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 before pci_tsm_unregister() that > 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 3e45b58183e2..863e2f5bb166 100644 > --- a/drivers/virt/coco/tsm-core.c > +++ b/drivers/virt/coco/tsm-core.c > @@ -56,8 +56,8 @@ 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_pci_or_reset(struct tsm_dev *tsm_dev, > + struct pci_tsm_ops *pci_ops) > { > int rc; > > @@ -66,13 +66,12 @@ static struct tsm_dev *tsm_register_pci_or_reset(struct tsm_dev *tsm_dev, > if (rc) { > 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; > } > > struct tsm_dev *tsm_register(struct device *parent, struct pci_tsm_ops *pci_ops) > @@ -96,14 +95,21 @@ 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_pci_or_reset(tsm_dev, pci_ops); > + if (rc) { > + device_del(dev); > + return ERR_PTR(rc); > + } > + return no_free_ptr(tsm_dev); These changes don't make functional difference, it is just trying to use the same function calls as the tsm_unregister(). I still don't think they are needed: - The postfix "_reset" of tsm_register_pci_or_reset() means the tsm_dev registration would be rolled back on failure. If you split the rollback out, you need to change the function name. - All these new changes would be deleted in next patch, replaced by a new flow. So why bother to make a temporary "neat" version, which wastes reviewer's effort. Maybe a note in changelog is better, like "Don't make the same change on register failure path yet as the tsm_register() flow still needs refactor in the subsequent patch". Though I don't even think a note is needed. > } > EXPORT_SYMBOL_GPL(tsm_register); > > void tsm_unregister(struct tsm_dev *tsm_dev) > { > + /* Remove the class lookup first. */ > + device_del(&tsm_dev->dev); > pci_tsm_unregister(tsm_dev); > - device_unregister(&tsm_dev->dev); > + put_device(&tsm_dev->dev); > } > EXPORT_SYMBOL_GPL(tsm_unregister); > > -- > 2.43.0 >