From nobody Tue Apr 7 22:01:06 2026 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 4B9A631AF1B; Wed, 11 Mar 2026 13:27:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773235679; cv=none; b=l1YbUfU009Auw3AwOjxNrojG2st4aF+3ACGQHhiMRsRFoKTs/5igl61qKyGNda3Rs8debS5kNIhXY+wOBO6P60QRINKU/MDcCTGXt50Go4cDfUIfi+Owa52eVDDWVX6BPX5zqG/qKQjGJECAdgvG2A82QPF5QHQ2zAR8BhlLdpA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773235679; c=relaxed/simple; bh=ojkmc1O/iVrw5QvN5vOI5XGosJie2J9egrshtD19wRU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KMqH+e9ySduSoxbxnBK1zbLtbtmvuRVAQfay07l5v/HIBjPY9D6hZ4Rpfi6oANfOdDPpXSZ0fNo3FJ7bSrFOSjckIyaY6DsIem3qIQcnRzQJzRrXJk60La4CXi/B05ObJ/5P3/BMoZLHGSf7XLjwRrTUPPqzN/FXJpvkh2/nv7Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=LWi9Gm63; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="LWi9Gm63" Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 62ALJhm51237000; Wed, 11 Mar 2026 13:27:56 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:sender:subject:to; s=pp1; bh=v12UnWacSu kRAwpPiLST1JBJ6l9mHvVtQYE5aNqJOKo=; b=LWi9Gm63XS10kscWJgQGn6ny7O +mj/Lel44sLQeBUwIqwP6AOv9JBMTqvqn1TY/UJEdl93/2w+IrIvspNcgFFRKdfK L65pYtBFKQFo1ibpHf7PCVxEGk+Lgj1X1edT4mIDQDYK51W9iswom0gFLR0GKUbO SrL5ZU9NGmu62UuG7xQJOo+ozAo0Afuf0Pc+a+d71q5r4k8f3KKYEXXTcgIEGkj4 uHcFwLuIpPV4EINVj4hkP0U9nbbFVjugTtnHXvEYIiOXdcNzD0Vy27tO7YtYWYUM QGah12QgNFiDWeG11wQrH6jHX0OesXGAueMo91CbgXY6mHKyDDeRm4sVc0Sg== Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4crd1mqgpe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Mar 2026 13:27:55 +0000 (GMT) Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 62BDCOQW025052; Wed, 11 Mar 2026 13:27:55 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 4cs0jk5duc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Mar 2026 13:27:54 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 62BDRpFu17039764 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Mar 2026 13:27:51 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 014552004E; Wed, 11 Mar 2026 13:27:51 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E10CB2004B; Wed, 11 Mar 2026 13:27:50 +0000 (GMT) Received: from p1gen4-pw042f0m (unknown [9.52.223.163]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTPS; Wed, 11 Mar 2026 13:27:50 +0000 (GMT) Received: from bblock by p1gen4-pw042f0m with local (Exim 4.99.1) (envelope-from ) id 1w0JbK-00000008V4R-2mAv; Wed, 11 Mar 2026 14:27:50 +0100 From: Benjamin Block To: Alexander Gordeev , Gerd Bayer , Bjorn Helgaas , Niklas Schnelle , Vasily Gorbik , Heiko Carstens Cc: Gerald Schaefer , Christian Borntraeger , Andreas Krebbel , linux-pci , linux-kernel , Ionut Nechita , Tobias Schumacher , Sven Schnelle , Matthew Rosato , linux-s390 , Julian Ruess , Ionut Nechita , Farhan Ali , Benjamin Block Subject: [PATCH v2 1/3] PCI: Move declaration of pci_rescan_remove_lock into public pci.h Date: Wed, 11 Mar 2026 14:27:48 +0100 Message-ID: X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: =?unknown-8bit?q?IBM_Deutschland_Research_=26_Development_GmbH=2C_https=3A//www=2Eibm=2Ecom/privacy=2C_Vors=2E_Aufs=2E-R=2E=3A_Wolfgang_Wendt=2C_Gesch=C3=A4ftsf=C3=BChrung=3A_David_Faller=2E_Sitz_der_Ges=2E=3A_Ehningen=2C_Registergericht=3A_AmtsG_Stuttgart=2C_HRB_243294?= Content-Transfer-Encoding: quoted-printable Sender: Benjamin Block X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Authority-Analysis: v=2.4 cv=ds3Wylg4 c=1 sm=1 tr=0 ts=69b16ddc cx=c_pps a=AfN7/Ok6k8XGzOShvHwTGQ==:117 a=AfN7/Ok6k8XGzOShvHwTGQ==:17 a=Yq5XynenixoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=V8glGbnc2Ofi9Qvn3v5h:22 a=VnNF1IyMAAAA:8 a=vf2HUNMP9xvVswJDcwYA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMzExMDExMCBTYWx0ZWRfXyy9F7LfA7Pnj aj6AeYxkyNugVf+FoSjkZnxSwk3EfEuXZg6IksNlwiP2huW87W37C2+N/gTK+3pqlaaK9goChBP MnStgtfPZLEbdCln9t29FIbsxxm+cP/Kg8gTkxiukin2PQIZ7ITH39/1S7QNoYmQni4C1VAos01 Z2W8ucs9Za3EQbHjESCb5a8RD2ARqwGO9UuosT4q3tXNx4qsC3QnZegP9qxVA0bVz7pHi7MLITH XttxFeO4hM09V7vt/PPuAskw8RdjvEvwSc4uI5gX+awj6AJgoqytltQki3wjgkyACHPTtMgOZju QDs55JpG9+mCKC/2P2QCCW06gxD1CNX9nRE1VBEHmunVP7F5C1KESBFXpR5QEMAXnwFipPgsOm0 Gcqb3rna4uv0vtQM0xAeGfzkqB5dnqiCi0w08eW5nxYoz9Cui9JXG7DyD/sSPZsyc4GoBEj2oSf LcYu8vsLL1rft+soLyw== X-Proofpoint-GUID: Or0kII9nvfl59S-E7NSU-dbSBoug22TV X-Proofpoint-ORIG-GUID: GkzOiCd3X2MmloVmJ8jdpA6GODkboARw 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-03-11_01,2026-03-09_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 phishscore=0 clxscore=1015 impostorscore=0 suspectscore=0 priorityscore=1501 lowpriorityscore=0 malwarescore=0 adultscore=0 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2602130000 definitions=main-2603110110 Content-Type: text/plain; charset="utf-8" So far it is possible to use and call the functions pci_lock_rescan_remove() and pci_unlock_rescan_remove() from any PCI code, including modules and architecture code; but the lock variable `pci_rescan_remove_lock` itself is private to objects residing in `drivers/pci/` via the header `drivers/pci/pci.h`. This makes it possible to use the lock - lock it, unlock it - from anywhere, but it is not possible to use lockdep annotations such as lockdep_assert_held(), or sparse annotations such as __must_hold() in modules or architecture code for PCI to make the usage more safe. Since it is useful for `pci_rescan_remove_lock` to have such annotations, move the variable declaration into `include/linux/pci.h`. Signed-off-by: Benjamin Block Reviewed-by: Niklas Schnelle --- drivers/pci/pci.h | 2 -- drivers/pci/probe.c | 1 + include/linux/pci.h | 2 ++ 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 13d998fbacce..6d611523420f 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -110,8 +110,6 @@ struct pcie_tlp_log; extern const unsigned char pcie_link_speed[]; extern bool pci_early_dump; =20 -extern struct mutex pci_rescan_remove_lock; - bool pcie_cap_has_lnkctl(const struct pci_dev *dev); bool pcie_cap_has_lnkctl2(const struct pci_dev *dev); bool pcie_cap_has_rtctl(const struct pci_dev *dev); diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index bccc7a4bdd79..e5b12878e972 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -3509,6 +3509,7 @@ EXPORT_SYMBOL_GPL(pci_rescan_bus); * routines should always be executed under this mutex. */ DEFINE_MUTEX(pci_rescan_remove_lock); +EXPORT_SYMBOL_GPL(pci_rescan_remove_lock); =20 void pci_lock_rescan_remove(void) { diff --git a/include/linux/pci.h b/include/linux/pci.h index 1c270f1d5123..fd7a962a64ef 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -39,6 +39,7 @@ #include #include #include +#include #include =20 #include @@ -1533,6 +1534,7 @@ void set_pcie_hotplug_bridge(struct pci_dev *pdev); =20 /* Functions for PCI Hotplug drivers to use */ unsigned int pci_rescan_bus(struct pci_bus *bus); +extern struct mutex pci_rescan_remove_lock; void pci_lock_rescan_remove(void); void pci_unlock_rescan_remove(void); =20 --=20 2.53.0 From nobody Tue Apr 7 22:01:06 2026 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 4B89923D7F0; Wed, 11 Mar 2026 13:27:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773235678; cv=none; b=oEiuHm+HdR19lXg4RXngLJ+Mv9BWt6cJZnLsJlbSMlaELgnazzfGr9ozkgDqDKAMqF59p1nI9Sq8sicLHNaB0VIkLjpv7TyoMogcdJKU0Z5Y3c6RjRzrshjS455G6lAWGFc9xYIi0Cj/Er7u5mFc8fhRkuAt3wR1y34HV6iSCdU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773235678; c=relaxed/simple; bh=pgVfp++xnaWG3o5SBaf3zcDumRCcFiH3KiRg4ok919g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LsXkDw9ii0iTpOSnPXGPlR4aWcWR83CDwfcCYSc3nNCOTICFdncfpTHGP/6+wQuwSFTJFBZHZ8PwO75alILZCRCyAWB7UjUBClCvs9DfdPOaDbAj0RGm78+wFLRTIw5RC3yNBJP0Y+ZmHARKuQlDgnKSTLmJGjjHHEo8fmLSW1g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=ODLQod8E; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="ODLQod8E" Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 62B8u4bn056775; Wed, 11 Mar 2026 13:27:56 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:sender:subject:to; s=pp1; bh=dMPhgHcSt3 QLfSzVOvCxD77HfbBQXLqvXvAivL6lOh8=; b=ODLQod8Eya7x0x06kVHMM4aHBt MkEozzSv+Onpuw3X40a6OUUqL0gqAp6jif/ejsx2h052jKv/y+6wDr9Au3Y179F0 ybPObnzDdeyXalzsN2Vu4Zb4FZTQptr+bVnTA3dSs6AFLdy9ytL3Q4abAareitQ5 7fkVvKWPDmTP8d39H0v8nmVo8RI3GSsbRUtKqoXKIdugSXs+tTheoldYOYKq2CB6 dA8Vmfs8oJDaEVdSdkgT7pMOwI4vAX9MPG5sB14GZKqBLtglfNC/aQPUtlg634qa 9TVOw9cVwuX4eWZtHDsF2vML+KXkryKYMOUbXgyYKxLVnu0JZNkqZYxpN30A== Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4crcvrfjvb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Mar 2026 13:27:55 +0000 (GMT) Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 62BC1RQK023007; Wed, 11 Mar 2026 13:27:55 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4ct8ng6hry-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Mar 2026 13:27:55 +0000 Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 62BDRpBi39322056 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Mar 2026 13:27:51 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 087D82004D; Wed, 11 Mar 2026 13:27:51 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E9B132004B; Wed, 11 Mar 2026 13:27:50 +0000 (GMT) Received: from p1gen4-pw042f0m (unknown [9.52.223.163]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTPS; Wed, 11 Mar 2026 13:27:50 +0000 (GMT) Received: from bblock by p1gen4-pw042f0m with local (Exim 4.99.1) (envelope-from ) id 1w0JbK-00000008V4T-2sp7; Wed, 11 Mar 2026 14:27:50 +0100 From: Benjamin Block To: Alexander Gordeev , Gerd Bayer , Bjorn Helgaas , Niklas Schnelle , Vasily Gorbik , Heiko Carstens Cc: Gerald Schaefer , Christian Borntraeger , Andreas Krebbel , linux-pci , linux-kernel , Ionut Nechita , Tobias Schumacher , Sven Schnelle , Matthew Rosato , linux-s390 , Julian Ruess , Ionut Nechita , Farhan Ali , Benjamin Block Subject: [PATCH v2 2/3] PCI: Provide lock guard for pci_rescan_remove_lock Date: Wed, 11 Mar 2026 14:27:49 +0100 Message-ID: X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: =?unknown-8bit?q?IBM_Deutschland_Research_=26_Development_GmbH=2C_https=3A//www=2Eibm=2Ecom/privacy=2C_Vors=2E_Aufs=2E-R=2E=3A_Wolfgang_Wendt=2C_Gesch=C3=A4ftsf=C3=BChrung=3A_David_Faller=2E_Sitz_der_Ges=2E=3A_Ehningen=2C_Registergericht=3A_AmtsG_Stuttgart=2C_HRB_243294?= Content-Transfer-Encoding: quoted-printable Sender: Benjamin Block X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMzExMDExMCBTYWx0ZWRfXwq/yzkw8sw02 pODyLK6G2C8joPdj1Yoq+HwTay59zBdV2EZpG9P1ujeX47v666tCCtSWvz+s23PDkpaccS42wcu rFzPuIfO+cgxhdG+7mH/jwxgDdx2eruZJ4TYJGqOntNozAJumETfeK/bwmpyjTf1KlO/SWM+vvC dwxxdHyo7xV1ZICwh/0bejXIi1xLhtwksIX+9F8xLh0Gc6hBHF7XVebtltU+VY40OqvvGm0IzQx QZn9Wau532Au607Y8gyte9z/GBaH1D1HAWG/45qqo+Sgu5C/l4vsb0SYNYTjYjNboluOJ/rpokd OdNuw9MliDqMWi4YkOX/kvqMGUP3/sVIS6x+7JDRmVBeEuq5y61Bsla2TZYV340RyHtf6yyVMSL AJBiuBMghEC9rDJl3jb6ZmFA46HN8pe4F4kUCfATH4CMfdlaELHmgRRd2rE43xekK9NEPgT03XI oQsG5Z58oxKH1CnoQtg== X-Proofpoint-GUID: mFzvpGUggbl7ooKcmekISc9utmEaT-Lq X-Proofpoint-ORIG-GUID: gyGfgt7S7_DLNGek_P5w5M9Y4gfSA0yc X-Authority-Analysis: v=2.4 cv=QoFTHFyd c=1 sm=1 tr=0 ts=69b16ddc cx=c_pps a=5BHTudwdYE3Te8bg5FgnPg==:117 a=5BHTudwdYE3Te8bg5FgnPg==:17 a=Yq5XynenixoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=RzCfie-kr_QcCd8fBx8p:22 a=VnNF1IyMAAAA:8 a=qAR2Z3AMSIpdRBh0OscA:9 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-03-11_01,2026-03-09_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 spamscore=0 priorityscore=1501 phishscore=0 lowpriorityscore=0 adultscore=0 clxscore=1015 malwarescore=0 suspectscore=0 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2602130000 definitions=main-2603110110 Content-Type: text/plain; charset="utf-8" Make it possible to use guard() or scoped_guard() to lock, and automatically unlock `pci_rescan_remove_lock`. Since the actual mutex `pci_rescan_remove_lock` is always supposed to be taken and released using the functions pci_lock_rescan_remove() and pci_unlock_rescan_remove() it is not possible to simply use the already existing guards for `struct mutex`. Instead define a new guard `pci_rescan_remove` that will also call the functions in question, but is usable via guard() or scoped_guard(). Signed-off-by: Benjamin Block Reviewed-by: Niklas Schnelle --- include/linux/pci.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/linux/pci.h b/include/linux/pci.h index fd7a962a64ef..4c41b5a2c90a 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -41,6 +41,7 @@ #include #include #include +#include =20 #include =20 @@ -1537,6 +1538,8 @@ unsigned int pci_rescan_bus(struct pci_bus *bus); extern struct mutex pci_rescan_remove_lock; void pci_lock_rescan_remove(void); void pci_unlock_rescan_remove(void); +DEFINE_LOCK_GUARD_0(pci_rescan_remove, pci_lock_rescan_remove(), + pci_unlock_rescan_remove()); =20 /* Vital Product Data routines */ ssize_t pci_read_vpd(struct pci_dev *dev, loff_t pos, size_t count, void *= buf); --=20 2.53.0 From nobody Tue Apr 7 22:01:06 2026 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (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 1A0EE1A6829; Wed, 11 Mar 2026 13:27:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773235678; cv=none; b=C5oHrpAyGi+J0P8qQDS4xBE36g5E8kdQIu1i2+0kapWR8b3G2lO2PJIBMW3fFcOuUsq1EAvgSTzf9Kg8z6GjOj2ZaZsT91V64u2ryEVQq3D3hwpNSdQOJUHhEdPSHyaYDiky2XuONWBZfiTklknEzc2r8DJeURa1cXpaiddaNK8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773235678; c=relaxed/simple; bh=Cn9LF1t0cttQqvmIDVD4dlYiJbsuWRlI1wC1Cjn1LnY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Iyhnl/ywuVFEyCNBX8yPCHTUZ0FKEOyX7axNFJpFTG2pXg5GTu88+aOFD+MOdS2+R2LMS5Y/MdXnJlq/noAqYabUL0T2HnYuiHtVIpKkBx66mF1o7TbO1C4rv9+yM7WW1Aok8grTMIYBj5MgAdLiUmgjr9dZFn4MmeIpjBh+5Cc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=kkdQTPRi; arc=none smtp.client-ip=148.163.156.1 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="kkdQTPRi" Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 62B8b55H576632; Wed, 11 Mar 2026 13:27:56 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:sender:subject:to; s=pp1; bh=3gbzl7jb1qOKG04PVKkoawfwEKnH5zepUUCqawqu7Hs=; b=kkdQTPRiziH3 qJDkJTZrQytWD+unM0Lt1NeO8whR/daSVEYBg3NWPS0VN0P++KQvE4Bh0DWP9tBY 9XxCMVf6sFaHUhgMFWUbD1kAZzplRDPfkVKS3v3kzmHwd/9ivLV1CIJIz23p8idU ZNA+YYAaRGnK7JSFYe/ja/xXPlIwEs/F2pNBm7U8TdG5IIz6JD6WayKEmRtEDJni +kYnshe0s+aTLey68u+nPZQahmVIuTLVv5MlXEM4ENEOJbe+xQWWM8OfScB1i3wk 41xiuBVt9rycemsuH7VlI8Cok1hhGoqkeY+DuuCKOan32i4gYXhCGbU0YqhS+NT8 SLQ98NKbOw== Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4crcuyg24t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Mar 2026 13:27:55 +0000 (GMT) Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 62BCMf6C021521; Wed, 11 Mar 2026 13:27:54 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 4crxbswq3a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Mar 2026 13:27:54 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 62BDRpI031392510 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Mar 2026 13:27:51 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 162252004B; Wed, 11 Mar 2026 13:27:51 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EAF872004D; Wed, 11 Mar 2026 13:27:50 +0000 (GMT) Received: from p1gen4-pw042f0m (unknown [9.52.223.163]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTPS; Wed, 11 Mar 2026 13:27:50 +0000 (GMT) Received: from bblock by p1gen4-pw042f0m with local (Exim 4.99.1) (envelope-from ) id 1w0JbK-00000008V4X-3021; Wed, 11 Mar 2026 14:27:50 +0100 From: Benjamin Block To: Alexander Gordeev , Gerd Bayer , Bjorn Helgaas , Niklas Schnelle , Vasily Gorbik , Heiko Carstens Cc: Gerald Schaefer , Christian Borntraeger , Andreas Krebbel , linux-pci , linux-kernel , Ionut Nechita , Tobias Schumacher , Sven Schnelle , Matthew Rosato , linux-s390 , Julian Ruess , Ionut Nechita , Farhan Ali , Benjamin Block Subject: [PATCH v2 3/3] s390/pci: Fix circular/recursive deadlocks in PCI-bus and -device release Date: Wed, 11 Mar 2026 14:27:50 +0100 Message-ID: <354b9e4a54ced67f3c89df198041df19434fe4c8.1773235561.git.bblock@linux.ibm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Organization: =?unknown-8bit?q?IBM_Deutschland_Research_=26_Development_GmbH=2C_https=3A//www=2Eibm=2Ecom/privacy=2C_Vors=2E_Aufs=2E-R=2E=3A_Wolfgang_Wendt=2C_Gesch=C3=A4ftsf=C3=BChrung=3A_David_Faller=2E_Sitz_der_Ges=2E=3A_Ehningen=2C_Registergericht=3A_AmtsG_Stuttgart=2C_HRB_243294?= Content-Transfer-Encoding: quoted-printable Sender: Benjamin Block X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Authority-Analysis: v=2.4 cv=EK4LElZC c=1 sm=1 tr=0 ts=69b16ddc cx=c_pps a=bLidbwmWQ0KltjZqbj+ezA==:117 a=bLidbwmWQ0KltjZqbj+ezA==:17 a=IkcTkHD0fZMA:10 a=Yq5XynenixoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=uAbxVGIbfxUO_5tXvNgY:22 a=VnNF1IyMAAAA:8 a=4Ogr7rOChN4w0RTaVvUA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMzExMDExMCBTYWx0ZWRfX+rW/MwJxXu2W hgDOTGHJBmHWXVfMAI1ZLiQh5YbCkXavq+IQQ/N5SbyBcILvVB9BETSu1ZzU5owcPzbdoBrxIqb 5+sanVsB/90hqDS2ADgLmn/5QNedOtUzqDOE7XZ1JqReqVfTq2tYAnPDOH2qUEcc98ngrfMZLq7 jlsw7/T0iw52X44lJ0UBaKLDDYC0vUmWj/fzG73wc8B84V+aG7RGxV/0gHCizcM3z/iSwpTOQyS cc4fK+AEr+wTppdPxD5VqK2ESN+SHSg0cNLHw85brzcnRK+Tvf5gkAgVIaVaVQ3jPupAi6gTnVo dQ+aarM/0OFO46WByaeExfebKAscKhYtoLza4wlooGSDkMOqU5I5qctXukdxEPtcRA11h0emGvX knc/hMXIgIKwclc/gorg4voSKK28gnO4D7uAx9AIAwITSEdGgcZpKHGn+zNCGvo6eBuS614wGe0 43kgofLHjWCWPlrDSwg== X-Proofpoint-GUID: 1m2yKTsirBGTeEPkegVgLjKt_T358LCh X-Proofpoint-ORIG-GUID: x6k1tDpIHA423-9-I9IppV1XB8pf_pAg 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-03-11_01,2026-03-09_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 lowpriorityscore=0 spamscore=0 suspectscore=0 clxscore=1015 bulkscore=0 impostorscore=0 priorityscore=1501 malwarescore=0 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2602130000 definitions=main-2603110110 When removing PCI device or PCI bus objects there are a couple of call-chains where it is possible that the kernel runs into a circular or recursive deadlock involving taking the central `pci_rescan_remove_lock`. For example: (A) Thread =CE=B1 receives a CRW event notifying the kernel that a PCI virtual function has been moved into Reserved state, and so the PCI subsystem will try to remove that PCI function. The call-chain for that looks like this: __zpci_event_availability() -> zpci_zdev_put() # will lock(zpci_add_remove_lock), # and lock(zpci_list_lock) -> zpci_release_device() # will unlock(zpci_list_lock) -> zpci_cleanup_bus_resources() # will lock(pci_rescan_remove_lock) Thread =CE=B2 is triggered by userspace writing 0 into the SysFS attribute `sriov_numvfs` of the parent PCI physical function of the same function we just try to remove. This will also try to release the PCI virtual function; but this time the call-chain looks like this: sriov_numvfs_store() # will lock(pci_rescan_remove_lock) -> ... (deep chain) -> pci_release_dev() -> pcibios_release_device() -> zpci_zdev_put() # will lock(zpci_add_remove_lock) If thread =CE=B1 and =CE=B2 coincide, this will result in a cyclic deadlock. (B) Consider thread =CE=B2 from above; if the thread was to follow the same outlined call-chain for thread =CE=B1, and not fall into the cyclic deadloc= k, it would recursive deadlock: sriov_numvfs_store() # will lock(pci_rescan_remove_lock) -> ... (deep chain) -> pci_release_dev() -> pcibios_release_device() -> zpci_zdev_put() # will lock(zpci_add_remove_lock), # and lock(zpci_list_lock) -> zpci_release_device() # will unlock(zpci_list_lock) -> zpci_cleanup_bus_resources() # will lock(pci_rescan_remove_lock) (C) And even in case `pci_rescan_remove_lock` was removed from zpci_cleanup_bus_resources(), the resulting call-chain would recursive deadlock when it tries to release the associated PCI bus: sriov_numvfs_store() # will lock(pci_rescan_remove_lock) -> ... (deep chain) -> pci_release_dev() -> pcibios_release_device() -> zpci_zdev_put() # will lock(zpci_add_remove_lock), # and lock(zpci_list_lock) -> zpci_release_device() # will unlock(zpci_list_lock) -> zpci_bus_device_unregister() -> zpci_bus_put() # will lock(zbus_list_lock) -> zpci_bus_release() # will unlock(zbus_list_lock), # will lock(pci_rescan_remove_lock) It can also easily be seen that scenario (C) offers the same risk as (A) for a cyclic deadlock in cases where `pci_rescan_remove_lock` is first locked, and the PCI bus released under its protection. `pci_rescan_remove_lock` has to be and is taken at a "high level" in most call-chains since it is intended to protect/mutual exclude all rescan and/or removal actions taken in the PCI subsystem. So to prevent the outlined deadlock scenarios above remove it instead from the "low level" release function for both the PCI device and PCI bus objects. Instead, lock `pci_rescan_remove_lock` in all call-chains leading to those release functions: * initialization of the PCI subsystem; * processing of availability events (CRWs) for PCI functions; * processing of error events (CRWs) for PCI functions; * architecture specific release PCI device implementation. Additionally, remove `pci_rescan_remove_lock` from zpci_bus_scan_bus() since it is now always already taken when called. Lastly, document the new locking expectations after these changes. Add sparse and lockdep annotations to functions that previously locked `pci_rescan_remove_lock` explicitly, making sure the lock is now already held when called. Additionally also add the annotations to zpci_zdev_put() and zpci_bus_put() to make sure that every function that potentially drops the last reference already holds the lock to prevent surprises. Fixes: 05bc1be6db4b2 ("s390/pci: create zPCI bus") Fixes: ab909509850b2 ("PCI: s390: Fix use-after-free of PCI resources with = per-function hotplug") Signed-off-by: Benjamin Block Reviewed-by: Niklas Schnelle Tested-by: Niklas Schnelle --- arch/s390/pci/pci.c | 11 ++++++++--- arch/s390/pci/pci_bus.c | 15 ++++++++------- arch/s390/pci/pci_event.c | 28 +++++++++++++++++++--------- arch/s390/pci/pci_iov.c | 3 +-- arch/s390/pci/pci_sysfs.c | 9 +++------ 5 files changed, 39 insertions(+), 27 deletions(-) diff --git a/arch/s390/pci/pci.c b/arch/s390/pci/pci.c index 2a430722cbe4..86ef1e516857 100644 --- a/arch/s390/pci/pci.c +++ b/arch/s390/pci/pci.c @@ -71,9 +71,11 @@ struct airq_iv *zpci_aif_sbv; EXPORT_SYMBOL_GPL(zpci_aif_sbv); =20 void zpci_zdev_put(struct zpci_dev *zdev) + __must_hold(&pci_rescan_remove_lock) { if (!zdev) return; + lockdep_assert_held(&pci_rescan_remove_lock); mutex_lock(&zpci_add_remove_lock); kref_put_lock(&zdev->kref, zpci_release_device, &zpci_list_lock); mutex_unlock(&zpci_add_remove_lock); @@ -582,11 +584,13 @@ int zpci_setup_bus_resources(struct zpci_dev *zdev) } =20 static void zpci_cleanup_bus_resources(struct zpci_dev *zdev) + __must_hold(&pci_rescan_remove_lock) { struct resource *res; int i; =20 - pci_lock_rescan_remove(); + lockdep_assert_held(&pci_rescan_remove_lock); + for (i =3D 0; i < PCI_STD_NUM_BARS; i++) { res =3D zdev->bars[i].res; if (!res) @@ -599,7 +603,6 @@ static void zpci_cleanup_bus_resources(struct zpci_dev = *zdev) kfree(res); } zdev->has_resources =3D 0; - pci_unlock_rescan_remove(); } =20 int pcibios_device_add(struct pci_dev *pdev) @@ -629,6 +632,7 @@ void pcibios_release_device(struct pci_dev *pdev) { struct zpci_dev *zdev =3D to_zpci(pdev); =20 + guard(pci_rescan_remove)(); zpci_unmap_resources(pdev); zpci_zdev_put(zdev); } @@ -1208,7 +1212,8 @@ static int __init pci_base_init(void) if (rc) goto out_irq; =20 - rc =3D zpci_scan_devices(); + scoped_guard(pci_rescan_remove) + rc =3D zpci_scan_devices(); if (rc) goto out_find; =20 diff --git a/arch/s390/pci/pci_bus.c b/arch/s390/pci/pci_bus.c index 36a4807285fa..c1b48b572e86 100644 --- a/arch/s390/pci/pci_bus.c +++ b/arch/s390/pci/pci_bus.c @@ -82,9 +82,8 @@ int zpci_bus_scan_device(struct zpci_dev *zdev) if (!pdev) return -ENODEV; =20 - pci_lock_rescan_remove(); + guard(pci_rescan_remove)(); pci_bus_add_device(pdev); - pci_unlock_rescan_remove(); =20 return 0; } @@ -132,10 +131,13 @@ void zpci_bus_remove_device(struct zpci_dev *zdev, bo= ol set_error) * Return: 0 on success, an error value otherwise */ int zpci_bus_scan_bus(struct zpci_bus *zbus) + __must_hold(&pci_rescan_remove_lock) { struct zpci_dev *zdev; int devfn, rc, ret =3D 0; =20 + lockdep_assert_held(&pci_rescan_remove_lock); + for (devfn =3D 0; devfn < ZPCI_FUNCTIONS_PER_BUS; devfn++) { zdev =3D zbus->function[devfn]; if (zdev && zdev->state =3D=3D ZPCI_FN_STATE_CONFIGURED) { @@ -145,10 +147,8 @@ int zpci_bus_scan_bus(struct zpci_bus *zbus) } } =20 - pci_lock_rescan_remove(); pci_scan_child_bus(zbus->bus); pci_bus_add_devices(zbus->bus); - pci_unlock_rescan_remove(); =20 return ret; } @@ -214,11 +214,12 @@ static int zpci_bus_create_pci_bus(struct zpci_bus *z= bus, struct zpci_dev *fr, s * run of the function. */ static inline void zpci_bus_release(struct kref *kref) - __releases(&zbus_list_lock) + __releases(&zbus_list_lock) __must_hold(&pci_rescan_remove_lock) { struct zpci_bus *zbus =3D container_of(kref, struct zpci_bus, kref); =20 lockdep_assert_held(&zbus_list_lock); + lockdep_assert_held(&pci_rescan_remove_lock); =20 list_del(&zbus->bus_next); mutex_unlock(&zbus_list_lock); @@ -229,14 +230,12 @@ static inline void zpci_bus_release(struct kref *kref) */ =20 if (zbus->bus) { - pci_lock_rescan_remove(); pci_stop_root_bus(zbus->bus); =20 zpci_free_domain(zbus->domain_nr); pci_free_resource_list(&zbus->resources); =20 pci_remove_root_bus(zbus->bus); - pci_unlock_rescan_remove(); } =20 zpci_remove_parent_msi_domain(zbus); @@ -250,7 +249,9 @@ static inline void __zpci_bus_get(struct zpci_bus *zbus) } =20 static inline void zpci_bus_put(struct zpci_bus *zbus) + __must_hold(&pci_rescan_remove_lock) { + lockdep_assert_held(&pci_rescan_remove_lock); kref_put_mutex(&zbus->kref, zpci_bus_release, &zbus_list_lock); } =20 diff --git a/arch/s390/pci/pci_event.c b/arch/s390/pci/pci_event.c index 839bd91c056e..98253706b591 100644 --- a/arch/s390/pci/pci_event.c +++ b/arch/s390/pci/pci_event.c @@ -342,6 +342,7 @@ static void __zpci_event_error(struct zpci_ccdf_err *cc= df) no_pdev: if (zdev) mutex_unlock(&zdev->state_lock); + guard(pci_rescan_remove)(); zpci_zdev_put(zdev); } =20 @@ -400,9 +401,11 @@ static void __zpci_event_availability(struct zpci_ccdf= _avail *ccdf) zdev =3D zpci_create_device(ccdf->fid, ccdf->fh, ZPCI_FN_STATE_CONFIGUR= ED); if (IS_ERR(zdev)) break; - if (zpci_add_device(zdev)) { - kfree(zdev); - break; + scoped_guard(pci_rescan_remove) { + if (zpci_add_device(zdev)) { + kfree(zdev); + break; + } } } else { if (zdev->state =3D=3D ZPCI_FN_STATE_RESERVED) @@ -419,9 +422,11 @@ static void __zpci_event_availability(struct zpci_ccdf= _avail *ccdf) zdev =3D zpci_create_device(ccdf->fid, ccdf->fh, ZPCI_FN_STATE_STANDBY); if (IS_ERR(zdev)) break; - if (zpci_add_device(zdev)) { - kfree(zdev); - break; + scoped_guard(pci_rescan_remove) { + if (zpci_add_device(zdev)) { + kfree(zdev); + break; + } } } else { if (zdev->state =3D=3D ZPCI_FN_STATE_RESERVED) @@ -450,24 +455,29 @@ static void __zpci_event_availability(struct zpci_ccd= f_avail *ccdf) /* The 0x0304 event may immediately reserve the device */ if (!clp_get_state(zdev->fid, &state) && state =3D=3D ZPCI_FN_STATE_RESERVED) { + guard(pci_rescan_remove)(); zpci_device_reserved(zdev); } } break; case 0x0306: /* 0x308 or 0x302 for multiple devices */ - zpci_remove_reserved_devices(); - zpci_scan_devices(); + scoped_guard(pci_rescan_remove) { + zpci_remove_reserved_devices(); + zpci_scan_devices(); + } break; case 0x0308: /* Standby -> Reserved */ if (!zdev) break; - zpci_device_reserved(zdev); + scoped_guard(pci_rescan_remove) + zpci_device_reserved(zdev); break; default: break; } if (existing_zdev) { mutex_unlock(&zdev->state_lock); + guard(pci_rescan_remove)(); zpci_zdev_put(zdev); } } diff --git a/arch/s390/pci/pci_iov.c b/arch/s390/pci/pci_iov.c index 13050ce5c3e9..1f7e4dd018e7 100644 --- a/arch/s390/pci/pci_iov.c +++ b/arch/s390/pci/pci_iov.c @@ -38,10 +38,9 @@ void zpci_iov_map_resources(struct pci_dev *pdev) =20 void zpci_iov_remove_virtfn(struct pci_dev *pdev, int vfn) { - pci_lock_rescan_remove(); + guard(pci_rescan_remove)(); /* Linux' vfid's start at 0 vfn at 1 */ pci_iov_remove_virtfn(pdev->physfn, vfn - 1); - pci_unlock_rescan_remove(); } =20 static int zpci_iov_link_virtfn(struct pci_dev *pdev, struct pci_dev *virt= fn, int vfid) diff --git a/arch/s390/pci/pci_sysfs.c b/arch/s390/pci/pci_sysfs.c index c2444a23e26c..f5027aa95928 100644 --- a/arch/s390/pci/pci_sysfs.c +++ b/arch/s390/pci/pci_sysfs.c @@ -98,9 +98,9 @@ static ssize_t recover_store(struct device *dev, struct d= evice_attribute *attr, WARN_ON_ONCE(!kn); =20 /* Device needs to be configured and state must not change */ - mutex_lock(&zdev->state_lock); + guard(mutex)(&zdev->state_lock); if (zdev->state !=3D ZPCI_FN_STATE_CONFIGURED) - goto out; + return count; =20 /* device_remove_file() serializes concurrent calls ignoring all but * the first @@ -112,15 +112,12 @@ static ssize_t recover_store(struct device *dev, stru= ct device_attribute *attr, * Once it unblocks from pci_lock_rescan_remove() the original pdev * will already be removed. */ - pci_lock_rescan_remove(); + guard(pci_rescan_remove)(); if (pci_dev_is_added(pdev)) { ret =3D _do_recover(pdev, zdev); } pci_rescan_bus(zdev->zbus->bus); - pci_unlock_rescan_remove(); =20 -out: - mutex_unlock(&zdev->state_lock); if (kn) sysfs_unbreak_active_protection(kn); return ret ? ret : count; --=20 2.53.0