From nobody Sat Jun 13 01:42:39 2026 Received: from mx0b-0064b401.pphosted.com (mx0b-0064b401.pphosted.com [205.220.178.238]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3BF4A3246F0; Wed, 22 Apr 2026 06:34:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.178.238 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776839656; cv=fail; b=HrukbtISOGceg7iaOBbe2l3wbozkm9JpMKKcdlHTE40d7cDam00IaXcfgt8v6WhtLvp4RH8VlvMQqrKjxfwaRjqdL5krJHz3hgSOxcF/MrOCSMzQiAk+JYbjnSvnHzE3LBaaRDaV9D1x3yb3BHZcXTgRT9I9qVvW+uUAfq3kCuw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776839656; c=relaxed/simple; bh=Oj9aUMqqclCYjPLPIDz+E2EVJDxwobLb+GErdT26r7I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=CZHGxoIcgjkOm03VlyV+086Cj23dbadHAyCM7E7nJJFlhlTGkMuAwYX3pqo/iIgRrndMvALF1aZLhmdYP3mNVs2P7vrBRvL/blDjFGE3ecxLIjWIah9p3aq/j9nKxv+B3tL4t0moAr8JHEGxEaUj/waHmo5jTsgLE3YllbDNj2A= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=windriver.com; spf=pass smtp.mailfrom=windriver.com; dkim=pass (2048-bit key) header.d=windriver.com header.i=@windriver.com header.b=Fajmsw2r; arc=fail smtp.client-ip=205.220.178.238 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=windriver.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=windriver.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=windriver.com header.i=@windriver.com header.b="Fajmsw2r" Received: from pps.filterd (m0250812.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 63M5gD6p943792; Wed, 22 Apr 2026 06:33:45 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=windriver.com; h=cc:content-transfer-encoding:content-type:date:from :in-reply-to:message-id:mime-version:references:subject:to; s= PPS06212021; bh=wjPon4yJp0Gp49rOEHpr5bIo4Hxao5DJ37lNHhuRtks=; b= Fajmsw2rsGc0nnnq5IOcK/NxY74ZejKFSADYGNlMDX7rIX8SOBMP2XLdI26YOlHe tY/8SqMee9MN0dTJcR5qwXWySOUa9740NIvUcpdwwsCx9b20x75CSxSeK2z8bFGU JWgeAwna6/dAXgRkXE50R5/poiUKBWYjS2l50jvqlDKsmO8lSEJQMcXQD5tg01/H +J1MBkQVWDSx9dEgTegaRFFYFRW3+XhQhg6LN7m3JhNG5L1QhKp1qhwh2d1PgB1E 2aN8w+OyHTcD270e2clvIdNEwLcEOMejF62O3fLMLfcDYAitFQUPf+PRRDoCfTTd bABnjb4O2DK4h0E8RHE9Aw== Received: from cy3pr05cu001.outbound.protection.outlook.com (mail-westcentralusazon11013028.outbound.protection.outlook.com [40.93.201.28]) by mx0a-0064b401.pphosted.com (PPS) with ESMTPS id 4dpenv8heg-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 22 Apr 2026 06:33:43 +0000 (GMT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Ia8rkYlLGlfuuxGXmInYpdLwud7wQUkwMtKs/2JmOqdf7dRCs+6xGGUoVVsRgBONh718AZwsvoZPPNyl5+2WvOSK2bGQrWN9ONOGOVyS4l70i+wOuMxhyiYxaxSuTsEyLZNoXrHahu0Ed6KUfq3SeOXkyU3cZ6CV8CWHMtF00Tbjl3s9166XISEbG0SF8Ih0/FylDzwNbRjkrGbdoJpX3bqSu1YkHQ0J1ZbdiaL8JLfCwT0xg52Jqb8ihxVqbcUOQCok0p4MALyVI6SbH0MQa3+K9gahNKFw14wv7Rw//uBKmYFBR5fkgeXA2Z+U7vhQEdlXCx5aONqGHUcG4yo9+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=wjPon4yJp0Gp49rOEHpr5bIo4Hxao5DJ37lNHhuRtks=; b=YuZiiSlip57Wxg7aQbxsY3KPG3pAgjyNHZSDQevD0vh3wy5eV2lNUxoCZ6M4Wy6PKEBUGlzTgzdnUKgeGXkGHis8LzmUv0W6AeelzHOghyL68ESTfx0Ja8lqV9hjvOIg9geVwuicZTMQzYLyDbal97EG7tSbVk7YTHfRRAUyE6KN/4OjoiZ9fY5Qwma1st4wSwnnSZJXt4vNt8RM9GaJSebbGzIaDlGuxPzxxSVoqCAt6JQGGnQaMDLCsOUrnB0rOnmbF2OTyBmciXlZFpjn9vpLmqc+gdOHfHZEdrcdUIvb8T3Ca2cS+LguUFsy730ESKykG52F67XCjoBds4s9LQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=windriver.com; dmarc=pass action=none header.from=windriver.com; dkim=pass header.d=windriver.com; arc=none Received: from SN7PR11MB7540.namprd11.prod.outlook.com (2603:10b6:806:340::7) by SA2PR11MB5116.namprd11.prod.outlook.com (2603:10b6:806:fa::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9846.20; Wed, 22 Apr 2026 06:33:41 +0000 Received: from SN7PR11MB7540.namprd11.prod.outlook.com ([fe80::2edd:5c6d:169c:389b]) by SN7PR11MB7540.namprd11.prod.outlook.com ([fe80::2edd:5c6d:169c:389b%6]) with mapi id 15.20.9846.016; Wed, 22 Apr 2026 06:33:41 +0000 From: "Ionut Nechita (Wind River)" To: linux-pci@vger.kernel.org, bhelgaas@google.com Cc: helgaas@kernel.org, sebott@linux.ibm.com, schnelle@linux.ibm.com, bblock@linux.ibm.com, linux@roeck-us.net, lukas@wunner.de, stable@vger.kernel.org, linux-kernel@vger.kernel.org, intel-xe@lists.freedesktop.org, matthew.brost@intel.com, michal.wajdeczko@intel.com, piotr.piorkowski@intel.com, dtatulea@nvidia.com, mani@kernel.org, kbusch@kernel.org, lkml@mageta.org, alifm@linux.ibm.com, julianr@linux.ibm.com, ionut_n2001@yahoo.com, sunlightlinux@gmail.com Subject: [PATCH v14 1/2] PCI/IOV: Make pci_lock_rescan_remove() reentrant and protect sriov_add_vfs/sriov_del_vfs Date: Wed, 22 Apr 2026 09:32:41 +0300 Message-ID: <2ff52853da5f36c2d695d090c839bac87a35edcb.1776839248.git.ionut.nechita@windriver.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: VIYP296CA0004.AUTP296.PROD.OUTLOOK.COM (2603:10a6:800:29d::15) To PH0PR11MB7541.namprd11.prod.outlook.com (2603:10b6:510:26d::16) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN7PR11MB7540:EE_|SA2PR11MB5116:EE_ X-MS-Office365-Filtering-Correlation-Id: b26e39f9-ddec-4ee6-a50b-08dea03917fc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|10070799003|1800799024|366016|376014|7416014|52116014|22082099003|18002099003|56012099003; X-Microsoft-Antispam-Message-Info: /vBzrWuOSIhvcjvTGDr7DjR03vd/VkZOZlkad/srDCAJCEkOjQkqj9im9FGBX+PyObqnzVWa7rZN0blNfIbQ0wnceZt3HZ8SIubfDtBFHO05RpJJAB8cbsfz3leFcEiPpjStSZa6ERiKMfLDXquocsBdEv4JxEm/QWAtghLvdqhe5Kb7Xp7uaL/PbzngxAv8SRj+mF17N6ZpyUW+MMv/ruxvOhwhkACpB4n+hbgzfsIqEL1k7Atqv7d3SAczEzgM1rz/afAaL5BUK7CRS1D6sQm6vYGnKd6ultxebMtI3SlEJ3k53SWIPsraJ5EE57N6x0znjeQYRXPUHrkUs0PdvaLdIzBaBNhmMYyF97/8V+Rx1I2a5EwtoBRlrSUGOZdfGSlGOVJUWkJMmswdjawNP8rMKbZX4LH2W8B2qCTk3WaHUAv0gK5WsPbR6X9P2e3nJaWa9hfXopZbc4Jd4w/us+ZScqV9Yf6FBn8fPgvrenOZmt6R6QmQCgm4rL/YukR2ogI+zNyTIx0ynLOEDiKeYKkpUROzlGigEuDApb0t5GKqC44dcbORnG1Z6aV511A/c1pdBTp5yo7seP8XXfTJW4CjxmTUNRJw1Jm0+gIrmBVMCokSjFKsGTRtUzYctTRsK4TybAl7qhDBPQnnLSrAs6p3JJMq9RuMGsM3XcwnSIWvwxqTDJLbzOEZ5u1QDRVd+Pbf6/Q6dh6cF4tGVt7f8Dhoxw1XRN2o9mnBbFrk0+A= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN7PR11MB7540.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(10070799003)(1800799024)(366016)(376014)(7416014)(52116014)(22082099003)(18002099003)(56012099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 2 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?yjD+N7g5G5kB6GIK85LwG3eA7I0a5bprNIKlimne5zaJbTEXbnpjiZVnD+t0?= =?us-ascii?Q?VvTKuEyN49+sS83sO6sUDeNwWPMBC69LrxIwCxZGNU6fF+jRqHGoNk8tOrxX?= =?us-ascii?Q?sQayF3K+OZwdQgidmKTSaGImUvGt/R4JmQ4gctvzAY8See5YalpcUPdv265u?= =?us-ascii?Q?hCPFQV5cZINFgbVfYcVIn5AUX3HiiELjhtoCiwt+TmlMewnTjWS+iOf+IiDV?= =?us-ascii?Q?ezSYvSd5ESXqsiFoP8s+CXRTvwBdygJDdzoHes4nFeIhf9A0JDzRQ5FNk896?= =?us-ascii?Q?Rt7GgYqs0BGjTjT9hPoTQ8GKjvhJT1H/SwI6pqC2PbaZRlexzn6os+F4RBTU?= =?us-ascii?Q?2nRrBwaI41qY3HyLAfQ+akQpLvlxSaSjBqkl722ng3uzoICDK2gsnvEB7Mhl?= =?us-ascii?Q?9SpNOvY6f9SmcgA3jB+6PW4SBTWHeNZjXN1eXPvvZVLJY/fZMhXdFsPEeSF+?= =?us-ascii?Q?2JYd0lGoSrRgmCVPQzOYYRiihzn5ytmWuC1IBUOmPnkILOQl3Y64PbNFOHFn?= =?us-ascii?Q?f1lGs+TdVz/k00arTH0IwVw818CurGfQD7bEVG9g8VbuuFMc7E5SVia2hnDU?= =?us-ascii?Q?TZp5TTzEPOpR6o6yax1yj+aTEQ5NrFgYxGrfKzktguTZSH0AmXrcifgsoXyr?= =?us-ascii?Q?FRO5x/4fN7WfiNTdltEgOB84LOhK+xN/fP40y8P6/ITP5uDahAAxPat85P5N?= =?us-ascii?Q?3Ue124pCiRkLHv+VubuDghsouOz19M9tZOosxrm1481/IUgRqHHo+rGDRBu2?= =?us-ascii?Q?AVow6H5rJobpXFZl2m778dtX9pD54bSErO7V1wIqDjJjLO3bK/MZsEyUUKjV?= =?us-ascii?Q?0uFPMKeorwHoKQSkP9TEWGgWlqg7KvioIQhj0oeu6AcoCw4rc/H4lohPF77C?= =?us-ascii?Q?7lFr7LMgcsV6RIdybTnU4e77ZR+2wkgGUqQifdg1Q/BAVnwBcohFf0shoISZ?= =?us-ascii?Q?W6TKgx5GqWeAaew9igng7MXEq10oA55TGhekXEnAO+feSn/IkKlm+tFWUJnL?= =?us-ascii?Q?GElNuqeCP2Cl+oiVGZVsNIRyILvFiBKsO22vqm8SU/V0FhnGEattqdzxWFcv?= =?us-ascii?Q?WmggZmzeTC3ay9m1VNeLnk7QLimmO5jBrO0M16Z2ENJo7U06iZHDKXUDUMTb?= =?us-ascii?Q?dlagBEHtvj2e47JoeE1drSTxP/b7u6us1nGW1/wt/APufaQphEZmUbSOYw93?= =?us-ascii?Q?B8ldUNx1dHXDFqbxkxWR/cc6K14Mb+sgXxb9g9vsraXqxaLH+Cl7HuJMr/NC?= =?us-ascii?Q?VRs5H2nh723nZIzDQhG2HINeG5uDgEaLFhgkVPTc2I2macCSWadkV1jMUCkw?= =?us-ascii?Q?o6Syuk9WX5QxeVsakuiTGJxQBojs6cMtlW0iueyUkIR9Yjp5zA9vhce6v5Q/?= =?us-ascii?Q?aI0lVWmJCWvTV5smElhQmvkQGigMJCbzu44Yxa9DsTEq4oFhi5tqsT8d5+mF?= =?us-ascii?Q?n/EwGGDQcG6PjHzdDq6Muh+ro/easDiCNaBDvwwQzSl//qbtY2hQXOzEeLW0?= =?us-ascii?Q?3zgJtYtGm1bM0ZjmlWWmiWnG6K+tzMUW0VyoBHH+gHzmgRceMgsk5ov/DHDG?= =?us-ascii?Q?PCQSgj79PnIupj1xZjNJm3zBtwuheTNe6tXUL+c5Zv6E4FflQXspN1BXn3WH?= =?us-ascii?Q?D261UB1VR+0VKE32YAAlJoRs7ujT3qsZPDXfUWzOtlqzeRmeWi5uGbe40un1?= =?us-ascii?Q?i4QSQHWKfEeVrAlALl6+RnQEwj67mN5pZGJ/kisabx1V8l1LNf5Lxi/StDDy?= =?us-ascii?Q?2YNseudMlnKPYKRlQFn6AML8ctNPUK6kaaHCbMpSb7aFVNdrJfWwzea/Bped?= X-MS-Exchange-AntiSpam-MessageData-1: w/tVjliMT46JGddry4z2r/0yuottBkLPw6s= X-Exchange-RoutingPolicyChecked: C4etp8mUMAweH60/3atmM1R7QYOxhyRupbp9Fg3KHIUsKHNns9VjEpxlOC4a4aWsEfZvu/DCMFfIilWtw1kS9+ldjd53/yqPXg6BuVlTcUyNNtwe386OTNJNWA1X4H5htZ2po4U09a5w2hB72RKzImuPKeooY95Q/6PXIY2NnWvhNpRYS74U8aPiQOykWKxQtyvf1oGtWW6TAQec67wuymkMK3G+9OmJbhRI4hD/wNziCgZ5THY8avdpcpgg0kkU/hJHB/KP9C/Ke/Y0ZSM/L+zUfI1XV2MgPRULHapJ97jAQCOUtfCcYIh1hC42L6YJuyg/vWJ8M/vqrdpWPRD7iw== X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: b26e39f9-ddec-4ee6-a50b-08dea03917fc X-MS-Exchange-CrossTenant-AuthSource: PH0PR11MB7541.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2026 06:33:41.5729 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ddb2873-a1ad-4a18-ae4e-4644631433be X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: nFEhsp8Ka6NYcHTCpET4gJkQdIouPvaToaiCXEvh/P5nTOLisSz2Axc+FwccO6e13/04ImaKuP8AffjCC6cp1ZXcmRaYkAw762bPCZPVA1c= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR11MB5116 X-Proofpoint-ORIG-GUID: ZgAi5WJ7DrWwBkZxGrR2_ptg9CUTu_fJ X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIyMDA1OSBTYWx0ZWRfX/4hPaENNKqOv iHiA/rhhj2Jlzk4r0vQpiLMA8tOZ/W9CwkgAirC0lXvCd4ijJRTtMblzJqwYjYhj8VgnwUB0TRU KD3o2QB1jV8C1BThRS8fSpA4X0pDV9lj91X3uJhoMGNbYu/rDO5OIQhZADsZvMKV7A+NLWOx7aQ WXNCYvXM2hi22MEfZkT/Ps0u4Zom3iJ66vDlME9nF7UdTBhE+vNwnQYLkMW+d9/uJbz/wyvs4zN +4eeH/ZGLSgDXB1G/qru/3KF2aulfW28SElMJQbD5lGLBQ5FQIFmB6kGxpDfvIUcuxrOXujMl4+ 5wGPOI4nFVDdaCTHS2QYwEJI/bTWF/doI5+s0nUNl/63nJoQaIWcXBmPiGdmyRbXmaq87L5HyYw x6yFoL4cVbucyWwvkZErdCWSGDEZN0IyY2Y7jOjEoAh7Q7Tn8g1jfhVWhwFZK/unoJ39MQQDIgN MZBdxNUXagb59uPXvCg== X-Authority-Analysis: v=2.4 cv=B9yJFutM c=1 sm=1 tr=0 ts=69e86bc7 cx=c_pps a=6NHOJSrb2DrgGhcKreW8mw==:117 a=6eWqkTHjU83fiwn7nKZWdM+Sl24=:19 a=z/mQ4Ysz8XfWz/Q5cLBRGdckG28=:19 a=lCpzRmAYbLLaTzLvsPZ7Mbvzbb8=:19 a=xqWC_Br6kY4A:10 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=bi6dqmuHe4P4UrxVR6um:22 a=fTW__CHxibyLmBMfj2wP:22 a=t7CeM3EgAAAA:8 a=VwQbUJbxAAAA:8 a=VnNF1IyMAAAA:8 a=hh5_vNSPTWDFZ6TSUYYA:9 a=FdTzh2GWekK77mhwV6Dw:22 X-Proofpoint-GUID: ZgAi5WJ7DrWwBkZxGrR2_ptg9CUTu_fJ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-21_03,2026-04-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 malwarescore=0 lowpriorityscore=0 impostorscore=0 suspectscore=0 phishscore=0 bulkscore=0 priorityscore=1501 adultscore=0 spamscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604200000 definitions=main-2604220059 Content-Type: text/plain; charset="utf-8" From: Ionut Nechita After reverting commit 05703271c3cd ("PCI/IOV: Add PCI rescan-remove locking when enabling/disabling SR-IOV") and moving the lock to sriov_numvfs_store(), the path through driver .remove() (e.g. rmmod, or manual unbind) that calls pci_disable_sriov() directly remains unprotected against concurrent hotplug events. This affects any SR-IOV capable driver that calls pci_disable_sriov() from its .remove() callback (i40e, ice, mlx5, bnxt, etc.). On s390, platform-generated hot-unplug events for VFs can race with sriov_del_vfs() when a PF driver is being unloaded. The platform event handler takes pci_rescan_remove_lock, but sriov_del_vfs() does not, leading to double removal and list corruption. We cannot use a plain mutex_lock() here because sriov_del_vfs() may also be called from paths that already hold pci_rescan_remove_lock (e.g. remove_store -> pci_stop_and_remove_bus_device_locked, or sriov_numvfs_store with the lock taken by the previous patch). Using mutex_lock() in those cases would deadlock. Make pci_lock_rescan_remove() itself reentrant by tracking the current owner task and a recursion depth counter, as suggested by Lukas Wunner and Benjamin Block, since these recursive locking scenarios exist elsewhere in the PCI subsystem: - If the lock is already held by the current task (owner =3D=3D current): increments the depth counter and returns without re-acquiring, avoiding deadlock. - If the lock is held by another task: blocks until the lock is released, then records the owner and sets depth to 1. - If the lock is not held: acquires the mutex normally. pci_unlock_rescan_remove() decrements the depth counter and releases the mutex (clearing the owner) only when the depth reaches zero. A WARN_ON catches mismatched unlock calls from tasks that do not own the lock. This avoids relying on mutex_get_owner(), which is not exported to modules and caused link failures for builds that inline this code outside of the core kernel image. This approach keeps the API unchanged: callers simply pair lock/unlock calls without needing to track any return value or use separate reentrant variants. Add pci_lock_rescan_remove()/pci_unlock_rescan_remove() calls to sriov_add_vfs() and sriov_del_vfs() to protect VF addition and removal against concurrent hotplug events. Remove the rescan/remove locking from sriov_numvfs_store() that was introduced by commit a5338e365c45 ("PCI/IOV: Fix race between SR-IOV enable/disable and hotplug"), since the locking is now handled directly in sriov_add_vfs() and sriov_del_vfs() where it is actually needed, reducing the lock scope. Fixes: 18f9e9d150fc ("PCI/IOV: Factor out sriov_add_vfs()") Fixes: 05703271c3cd ("PCI/IOV: Add PCI rescan-remove locking when enabling/= disabling SR-IOV") Fixes: a5338e365c45 ("PCI/IOV: Fix race between SR-IOV enable/disable and h= otplug") Cc: stable@vger.kernel.org Suggested-by: Lukas Wunner Suggested-by: Benjamin Block Reviewed-by: Benjamin Block Tested-by: Benjamin Block Signed-off-by: Ionut Nechita --- drivers/pci/iov.c | 9 +++++---- drivers/pci/probe.c | 18 ++++++++++++++++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index 91ac4e37ecb9..7ed902539051 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -495,9 +495,7 @@ static ssize_t sriov_numvfs_store(struct device *dev, =20 if (num_vfs =3D=3D 0) { /* disable VFs */ - pci_lock_rescan_remove(); ret =3D pdev->driver->sriov_configure(pdev, 0); - pci_unlock_rescan_remove(); goto exit; } =20 @@ -509,9 +507,7 @@ static ssize_t sriov_numvfs_store(struct device *dev, goto exit; } =20 - pci_lock_rescan_remove(); ret =3D pdev->driver->sriov_configure(pdev, num_vfs); - pci_unlock_rescan_remove(); if (ret < 0) goto exit; =20 @@ -633,15 +629,18 @@ static int sriov_add_vfs(struct pci_dev *dev, u16 num= _vfs) if (dev->no_vf_scan) return 0; =20 + pci_lock_rescan_remove(); for (i =3D 0; i < num_vfs; i++) { rc =3D pci_iov_add_virtfn(dev, i); if (rc) goto failed; } + pci_unlock_rescan_remove(); return 0; failed: while (i--) pci_iov_remove_virtfn(dev, i); + pci_unlock_rescan_remove(); =20 return rc; } @@ -766,8 +765,10 @@ static void sriov_del_vfs(struct pci_dev *dev) struct pci_sriov *iov =3D dev->sriov; int i; =20 + pci_lock_rescan_remove(); for (i =3D 0; i < iov->num_VFs; i++) pci_iov_remove_virtfn(dev, i); + pci_unlock_rescan_remove(); } =20 static void sriov_disable(struct pci_dev *dev) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index b63cd0c310bc..91f1dae6943b 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -3513,16 +3513,30 @@ EXPORT_SYMBOL_GPL(pci_rescan_bus); * routines should always be executed under this mutex. */ DEFINE_MUTEX(pci_rescan_remove_lock); +static const struct task_struct *pci_rescan_remove_owner; +static unsigned int pci_rescan_remove_depth; =20 void pci_lock_rescan_remove(void) { - mutex_lock(&pci_rescan_remove_lock); + if (pci_rescan_remove_owner =3D=3D current) { + pci_rescan_remove_depth++; + } else { + mutex_lock(&pci_rescan_remove_lock); + pci_rescan_remove_owner =3D current; + pci_rescan_remove_depth =3D 1; + } } EXPORT_SYMBOL_GPL(pci_lock_rescan_remove); =20 void pci_unlock_rescan_remove(void) { - mutex_unlock(&pci_rescan_remove_lock); + if (WARN_ON(pci_rescan_remove_owner !=3D current)) + return; + + if (--pci_rescan_remove_depth =3D=3D 0) { + pci_rescan_remove_owner =3D NULL; + mutex_unlock(&pci_rescan_remove_lock); + } } EXPORT_SYMBOL_GPL(pci_unlock_rescan_remove); =20 --=20 2.53.0 From nobody Sat Jun 13 01:42:39 2026 Received: from mx0b-0064b401.pphosted.com (mx0b-0064b401.pphosted.com [205.220.178.238]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E60F73101B8; Wed, 22 Apr 2026 06:34:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.178.238 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776839686; cv=fail; b=blDTOsLhPCLXEVNVj3ePAHpNrCau9NfzwB99TOKkZWmpD1LgtL+i+MyiQa0kTUbyx2tqJS5X9s5QpiuTBVyuGc2+ZcwKzdWlIjxygpzU+LYpmIRzmk9Qc/FgQKciMDbiq3NeYfoE5GEgCZHtDWj6oZe8Fz+BJffrBDdz8Yu0W3U= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776839686; c=relaxed/simple; bh=vrJgq2ubLedxXwnejb8xqvFNi+iBVzJof5NUXTpqQ60=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=uMq0NsgGJ3+YAGOkTDFlJ6ax64vOpyLfEA00g9gpI/xmH60CaMfG7phY9AeslWiV07xtXfcPdP5Z4QVndO0TbBtDnrWjoxs2DTiVe1o006bhjnCvsPQd7QTSXnmAKei6w258SCPEeuzPm3XjVbM7x1RcxH+0cesKbWS1YxjdzXM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=windriver.com; spf=fail smtp.mailfrom=windriver.com; dkim=pass (2048-bit key) header.d=windriver.com header.i=@windriver.com header.b=ncJKUFO6; arc=fail smtp.client-ip=205.220.178.238 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=windriver.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=windriver.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=windriver.com header.i=@windriver.com header.b="ncJKUFO6" Received: from pps.filterd (m0250812.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 63M5gD6q943792; Wed, 22 Apr 2026 06:34:05 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=windriver.com; h=cc:content-transfer-encoding:content-type:date:from :in-reply-to:message-id:mime-version:references:subject:to; s= PPS06212021; bh=edruRNhOFxoTqLpoRttq5X20SXLnytn48rYp1IqcNcs=; b= ncJKUFO6DchRS46poZs7L2jRYyXoTgo42V9slULzqi5b/ebO6BocjuhiYxjju5nl 3ZMcUrADFGfbpYyzEMponkOxp4JDT1g671Q/2kXIOOkaiAnyIDOixq1iEWfMxmJ2 CTnXZqpX75VEeagnWpoy0CNE/SFza9fW5Ztkl3YwbNkoY5R5XLf13evLjk8D+ybP aBxssiczL4uwdNkgua+Bz57e02hOPPhf4gh5dUvf/PgAz4KDpJ/bxzN0OQiWncfi GzXBEQUmDB6d8B7JRl2t31IBNXim2AmdyJdpPWt8MHhG0A1Vn8k8EN24971Cmq1a 5nOVuXlnu6NsxeQqQNUEEQ== Received: from ph7pr06cu001.outbound.protection.outlook.com (mail-westus3azon11010051.outbound.protection.outlook.com [52.101.201.51]) by mx0a-0064b401.pphosted.com (PPS) with ESMTPS id 4dpenv8hep-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 22 Apr 2026 06:34:04 +0000 (GMT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=MW++Ox3gcMUZNvBPGfMhFujwz/XXty5jeCf3zEbUBNXfwAgSynZiOIAZ+oBxUtRRLmOJ1+WD8UPcR22lTwCqMI8Ojzl1gddQ1UK62JwqnjE/ATYU3TTyP9FMCttroKQPphO/Gqk2/FO1DstNckkDOTE7zcKL2MoA6uiP1h3vtxfTu0CsU3B10V1UzDs/EJ1nMEJDGnS2rey3Tg7N+UmNwQ4GMa8VkWN0tPGkIrSbHvqtGaZ/lzkEF64NErzXWc/31Yj5DzFY9RslgR5bJElfRY5zIorCOO1tVZUvHdaITBJsmekXIQMqv8l4aDsMB2ZRHJWYl15kk6GfkcaHiKUisw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=edruRNhOFxoTqLpoRttq5X20SXLnytn48rYp1IqcNcs=; b=h+wHBdlN+D30Gxg0a8c3OohMykJ3cjti4y5O8XVx3A0wNvFTa9294adbqoLrCvfw4XikwbhKRdAI2dgohhkkIXQiP7N8z8j6mMkiDWXNQJVi+y80SJRTL1B0shHmd6TTsNS3ShJPDKjiT6ppHsll6d8x08daQKGogGgaCdazcc6AQ58pK5xg5j5mlHRPMieChk90uIyNGEa8T8VsUEGtSmHu9kWWee1x2Jm+kfJJBCd8X6pD8fKuhk6iEFNz4S48szPzT3X/6p9/RldaBinDth4fQbXTpI4IjIYmCrDqiIezn3R76RCj3op1mDUz6fwgzgjYDssjp7FbKLDXSK3dRg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=windriver.com; dmarc=pass action=none header.from=windriver.com; dkim=pass header.d=windriver.com; arc=none Received: from SN7PR11MB7540.namprd11.prod.outlook.com (2603:10b6:806:340::7) by SJ0PR11MB5197.namprd11.prod.outlook.com (2603:10b6:a03:2d1::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9846.16; Wed, 22 Apr 2026 06:34:02 +0000 Received: from SN7PR11MB7540.namprd11.prod.outlook.com ([fe80::2edd:5c6d:169c:389b]) by SN7PR11MB7540.namprd11.prod.outlook.com ([fe80::2edd:5c6d:169c:389b%6]) with mapi id 15.20.9846.016; Wed, 22 Apr 2026 06:34:02 +0000 From: "Ionut Nechita (Wind River)" To: linux-pci@vger.kernel.org, bhelgaas@google.com Cc: helgaas@kernel.org, sebott@linux.ibm.com, schnelle@linux.ibm.com, bblock@linux.ibm.com, linux@roeck-us.net, lukas@wunner.de, stable@vger.kernel.org, linux-kernel@vger.kernel.org, intel-xe@lists.freedesktop.org, matthew.brost@intel.com, michal.wajdeczko@intel.com, piotr.piorkowski@intel.com, dtatulea@nvidia.com, mani@kernel.org, kbusch@kernel.org, lkml@mageta.org, alifm@linux.ibm.com, julianr@linux.ibm.com, ionut_n2001@yahoo.com, sunlightlinux@gmail.com Subject: [PATCH v14 2/2] PCI: Fix AB-BA deadlock between device_lock and pci_rescan_remove_lock in remove_store Date: Wed, 22 Apr 2026 09:32:42 +0300 Message-ID: <87f609ef2eb1308daff16fa943ee204f5bdc40ea.1776839248.git.ionut.nechita@windriver.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: VIYP296CA0004.AUTP296.PROD.OUTLOOK.COM (2603:10a6:800:29d::15) To PH0PR11MB7541.namprd11.prod.outlook.com (2603:10b6:510:26d::16) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN7PR11MB7540:EE_|SJ0PR11MB5197:EE_ X-MS-Office365-Filtering-Correlation-Id: 0fb5f609-14a1-484c-c507-08dea03923f4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|10070799003|7416014|376014|52116014|22082099003|56012099003|18002099003; X-Microsoft-Antispam-Message-Info: DLS1E3T0dqlGW1YNkU3ezEZmo3oLx1pp2dKZkNyVm8owdCwciB93HS1nUdC8kP3dt5zsiNWZl3QnfUkMYUaXSKIeWDsHX6wMTZasWeHp+DrrjtkNp2xWiJrb+hD6Prc4TE3IjTmsSUtvm5BniNbw/xlyiZP2lUNlex4Dx0853SbUSoJm71MZc/KOeNKYdPxFYfwGALuww9altyjQ67m5cnxJNFRw7oRvNHvj97qGQ3T8KWecYKwky0CI39D8cEJrcXNAdyYQwD5T1CphIxnr0Ohn9FBPplj/g1VicN/tgpt9XV6leG0wvbvp/DAsSyk9nm1F2v7eUm5apCSYgY+TLMchbcm+k0Ov9tFVaure/qS6TGhskb+YZ5EmhKCZDEDsA7EFF8m/xYo/CBO43OyCwhtg5PzCZW93W0yTXPzFVLZR4X8hIFseQfwfyWjrcSo5uGOqTtzhfAaDHl4cyQIyTLrpgNU53oCKVtx852ry1LT1KoVfF0IqDChvHTUmAWbGFe2cIsJoBnMFde8QaIMqeqZhvB5yI84hHaPtWrIeoI1zmNkbbA0Xqs43+Nkudpx/ZbtUQp1M/JKptkdHuXqEpmUJilU1rO/i1TcwQ6UDnDfnEDGtx+jklOtFwOf9fyFnSmHxnqTR1LXkADDXhuH/m7ECSGhWW4wFhFP90aMQ/sXnKJXrqw32swIMWF6ZVHID X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN7PR11MB7540.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(10070799003)(7416014)(376014)(52116014)(22082099003)(56012099003)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 2 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?D9pmhzNb+EX/FMQcU1vzc8p4Qj90dd39awkj64zaxUDMWwuJLOlLHuejk5cK?= =?us-ascii?Q?GrvD76ZHpi/qxPkV8kmFJHgBLDzBqjpjt+P/mYjPCEq+TpS7KZaJT988LCqz?= =?us-ascii?Q?ASWxrFrvV+q85clO8tLdga/31GyftWjYOG2GECXaFEz523xcCMvMYmF99+rb?= =?us-ascii?Q?pOGTe+6QJ14IP/ILGw8iqrms8fPZub2nXh8nEmLh+1RD0G+ohNJCFsE5oCIh?= =?us-ascii?Q?DL+iRBaC0UKhl+WWKYTx2b+AXZk7HkYdaMZ8m1mv1N9ih1QWQGR2JOXTGrir?= =?us-ascii?Q?+CFzlPWj39RZ5GrHZVzqWA599bq1ukHqqQrq5H3FXNW0N2rpAhPleiZ0EFft?= =?us-ascii?Q?1jcwQXbaaU39k3OeOLy7DLWVtQv5M6sJiCDpsNR0ZsMI31c4Mkixh2tiXexb?= =?us-ascii?Q?74HsQorviN0Jl0bXH1PwJqLnSrThL8+Dnsqm5QEw3LvqPGmF+IAM6HxCJZpW?= =?us-ascii?Q?n4gPSvQC/yRw1bCPLGq77Phb2CHyDlFlq/Rw3k1gkmoQewF1hh6pBqj83lTl?= =?us-ascii?Q?oS2dgFHq9UlddVLuxfEJ6X/kU8PrcBu1NODuY/jjay3ff1jp2NKTKrOZpfwS?= =?us-ascii?Q?3Gl/a2i2o2eI8g7Vi+PatjBEClK2XCm/+RW2XhxW/kRcmQB9FMfXA7mm3wds?= =?us-ascii?Q?qssUfIlk7bG41vvnp3aAF5k5iDYRDm5RA8RQHRYQS96/q+Ut9YH/b6Yqr6lK?= =?us-ascii?Q?ZfWaRSmh6R0nVhNfsMwfbQ/Sj3yBkL0YscT7KEFMXsHYI+ar0ddwDOWgpsSk?= =?us-ascii?Q?BMY2cYiv/qiqAYOwhAGBFK5T4yZFywhBkvOZ9Z702Qb43s07X8Kou5+NKsYz?= =?us-ascii?Q?IA/q5kuinwSyFnJVGHugrUb7oo92bZmCju0Qn91/5hDpZQjMSmPbxotGbNh0?= =?us-ascii?Q?mDILQApvwMtNjtujdQlLNqiLsVxAkH07/JQM2NWH0hHDv55QefxTx4IT/6+d?= =?us-ascii?Q?C/poH65ZCl8ZbZTaafotapRXC8tG4bjWy7c3jtHg9xSIiB8yrqzkmNcvsLtd?= =?us-ascii?Q?U+xmJU1SH/828BL6c/Pzcv3erK+aHwUicKDknMauLD2lyHxGsXwsf4uTg+DG?= =?us-ascii?Q?IeFLyoGTlSHkhQ1nwuoHrXL5U1m6eGkQsULLqQufVoWyYosAbecArmus509d?= =?us-ascii?Q?eUBT1mms72BNU4vYRkRI6tKQ93/DOUNLd/QVUx4GShKY62Zsb9YfH59CmO89?= =?us-ascii?Q?5nFAh4MMz6mT+YDVeA4VxCbXQ7VICaJ2Fpj4W9MIdmkpzUUfwlzlKml9IcR5?= =?us-ascii?Q?5F4STDbzX9uFjrjzPL1rTmpq9m3XG4OLb1Ci+4+k8jfT4pTjf1rzaP93fzd6?= =?us-ascii?Q?brtF11OOat7OYSJ6JMK0BJfPnWZwp6EUAYGSZ88cweogTpMPQww0F7Rvfao8?= =?us-ascii?Q?mEZNbfR8J5Ffsdl19mC0cxfl4jNLILyy6g2gReQeI6HhGTIb9Sn/IHuhRmYV?= =?us-ascii?Q?kob/PJdc2YhzBFIIzs2Tx13clJgW4AWMB6Y64XPk92G/B6AvHdYh4DNndLmD?= =?us-ascii?Q?8KauDWb5VpvBVyPp1qZAV2HknphUzj3wchbi/uVN+pM3KwW2PF82Nw4yvuMD?= =?us-ascii?Q?XXEnJsmZEd6WEgcBRfuJSiJUF0LLbiL6rkmDfJCA0eEB22spgzjayHTkvZIO?= =?us-ascii?Q?mJted/5j6NES5yF3YGsC+Fd4HPjNR4l0aTKL+UIjht7XQarNaQs0HDdSMgUS?= =?us-ascii?Q?gUxXuoy86AqJg82RVK3CjOgyo28mOWlJNDN5bwhh7PI61Eqx6QwAQ0iICes/?= =?us-ascii?Q?7QYjP8u/dN/CGfYmqebQFAcDVyFiSV4eVeQIlrRPP3p2I0EMMfAnIXu7LNNv?= X-MS-Exchange-AntiSpam-MessageData-1: fPHmlt3z1dmgm50nuShZqrNoYuPB7p8Btr4= X-Exchange-RoutingPolicyChecked: kn6wYRH0jAYTXCtHhAuNnPoa8Eee+qLqvClCXupoYe8YkcLEVwYomar5RBTE1NLDwEaLms4NJHawLQ5zVPTjLGQz/wgJkz17mMt6rJP6MpNOUtLfvyHF/RYxAPVqjPb6F9ziXJ2cM97ECpVT5aVQ26f0s1tj/n1zn6rSpzOM9VENh/leIZXYisvLbAL8Y3YKIRx4PpoVl85LnDyg2l6hOq1fYt2KMiv6xoHFBoLryD+mE/jKpnObNnu3FCkn1jy6zfTeP5e47Jwwmv+wT/SCTFPL1uzxHqD2Wh1ycYzyJPOFR+EegLFdlh8+NKihnkLi0InpFJD6IzCavlXwCA+sWw== X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0fb5f609-14a1-484c-c507-08dea03923f4 X-MS-Exchange-CrossTenant-AuthSource: PH0PR11MB7541.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2026 06:34:01.8982 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ddb2873-a1ad-4a18-ae4e-4644631433be X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: uCbofIRii7vYnwfI+m2xP0phhJCoSijVdLLViTi1YxDZW+XXvcLTOUD8ZqHA+PcHRJS6fypV4WUVPUUj3ITs3D8sUnElzUohJ0czTMefKGg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR11MB5197 X-Proofpoint-ORIG-GUID: izl7XkIqjWzYp0mKzIarLw-qOGboySbs X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIyMDA1OSBTYWx0ZWRfX+IFAwoYD046C Uw/B+NlEFflkJuPjPvXsp+95WLtKic8pzdxH2zCetkcyrAkT8mHi69zZFEbIcBaoP/Z3R+XrMjh gVbEq4OiH/HoLpu2Z/+fByx9vPEkyxuozaWhScPhcFVtzHb71EGs3mt3NCVswS8stQfXEDTVbVX k9Ys6RKETgFnAWOWkCEYxw5z+Git7YNjLJHTBW2wxT1bR4+aGEwldNzU2w2G2JRSUgpJQmee9u2 TU8mUvv73vp1MTgKjOgixv9jJstYnvUsAYkRDKVltqTQg2mXx5JyT4i4Vb3Y5LwGRqb75vix+et 1HH9KBG8fhEw8YLkMOssU+5vF9eqoSEgdeXi+Nk8+VfzpKJ8gBl4BCkov4RcKmiyYt4hfHPhhJi noSrTT9EKtx62RZjRW5UyHh7j5sbNqtYq1M9a6iwnqLfQzDRPXDUhy7qO21cVzBu85znv2i4Dh4 ngMCQiv+NnQxefmxcoA== X-Authority-Analysis: v=2.4 cv=B9yJFutM c=1 sm=1 tr=0 ts=69e86bdc cx=c_pps a=f0OpuPnQRmDrWRgsA3vZMw==:117 a=6eWqkTHjU83fiwn7nKZWdM+Sl24=:19 a=z/mQ4Ysz8XfWz/Q5cLBRGdckG28=:19 a=lCpzRmAYbLLaTzLvsPZ7Mbvzbb8=:19 a=xqWC_Br6kY4A:10 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=bi6dqmuHe4P4UrxVR6um:22 a=fTW__CHxibyLmBMfj2wP:22 a=VwQbUJbxAAAA:8 a=_jlGtV7tAAAA:8 a=p2eoyRXnAAAA:8 a=t7CeM3EgAAAA:8 a=VnNF1IyMAAAA:8 a=mm2UkWPFonPHBTd3Hn4A:9 a=nlm17XC03S6CtCLSeiRr:22 a=KSHYvF9M28j0gckGFaEs:22 a=FdTzh2GWekK77mhwV6Dw:22 X-Proofpoint-GUID: izl7XkIqjWzYp0mKzIarLw-qOGboySbs X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-21_03,2026-04-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 malwarescore=0 lowpriorityscore=0 impostorscore=0 suspectscore=0 phishscore=0 bulkscore=0 priorityscore=1501 adultscore=0 spamscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604200000 definitions=main-2604220059 Content-Type: text/plain; charset="utf-8" From: Ionut Nechita remove_store() calls pci_stop_and_remove_bus_device_locked() which takes pci_rescan_remove_lock first, then device_lock during driver release. Meanwhile, unbind_store() takes device_lock first (via device_driver_detach), and the driver's .remove() callback may call pci_disable_sriov() -> sriov_del_vfs() -> pci_lock_rescan_remove(). This creates an AB-BA deadlock: CPU0 (remove_store) CPU1 (unbind_store) -------------------- -------------------- pci_lock_rescan_remove() device_lock() driver .remove() sriov_del_vfs() pci_lock_rescan_remove() <-- WAITS pci_stop_bus_device() device_release_driver() device_lock() <-- WAITS Fix this by first marking the device as dead using kill_device() to prevent any new driver from binding, then calling device_release_driver() before pci_stop_and_remove_bus_device_locked(). Marking the device dead closes the race window between unbinding and removal where a new driver could theoretically bind: once the dead flag is set, the device core will refuse any new driver probe. After device_release_driver() returns, the driver is already unbound, so the subsequent device_release_driver() call inside pci_stop_and_remove_bus_device_locked() becomes a no-op. Fixes: a5338e365c45 ("PCI/IOV: Fix race between SR-IOV enable/disable and h= otplug") Reported-by: Guenter Roeck Closes: https://lore.kernel.org/linux-pci/0ca9e675-478c-411d-be32-e2d814392= 88f@roeck-us.net/ Reported-by: Benjamin Block Closes: https://lore.kernel.org/linux-pci/20260317090149.GA3835708@chlorum.= ategam.org/ Suggested-by: Benjamin Block Cc: stable@vger.kernel.org Reviewed-by: Niklas Schnelle Reviewed-by: Benjamin Block Tested-by: Benjamin Block Signed-off-by: Ionut Nechita --- drivers/pci/pci-sysfs.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index d37860841260..1426328e9f05 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -521,8 +521,36 @@ static ssize_t remove_store(struct device *dev, struct= device_attribute *attr, if (kstrtoul(buf, 0, &val) < 0) return -EINVAL; =20 - if (val && device_remove_file_self(dev, attr)) + if (val && device_remove_file_self(dev, attr)) { + /* + * Mark the device as dead so that no new driver can bind + * between the unbind and the removal below. Once the + * dead flag is set, the device core will refuse any new + * driver probe. + */ + device_lock(dev); + kill_device(dev); + device_unlock(dev); + + /* + * Unbind the driver before removing the device to avoid + * an AB-BA deadlock between device_lock and + * pci_rescan_remove_lock. Without this, remove_store + * takes pci_rescan_remove_lock first (via + * pci_stop_and_remove_bus_device_locked) and then + * device_lock during driver release, while a concurrent + * unbind_store (or sriov_numvfs_store) takes device_lock + * first and then pci_rescan_remove_lock (via + * sriov_del_vfs), creating a circular dependency. + * + * By unbinding first, the driver's .remove() callback + * (including any SR-IOV VF cleanup) completes before + * pci_rescan_remove_lock is acquired, ensuring both + * paths take locks in the same order. + */ + device_release_driver(dev); pci_stop_and_remove_bus_device_locked(to_pci_dev(dev)); + } return count; } static DEVICE_ATTR_IGNORE_LOCKDEP(remove, 0220, NULL, --=20 2.53.0