From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 1838B19D896; Tue, 16 Jul 2024 14:25:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721139931; cv=none; b=gFFxMBufcE97Yd5893r1TLcZzUQkTeODb6mfjybOxlCyO0FSYTRJmhNRDAEoF/xt8Eujer6dvwuRjF6MDtoX+NJGnMlFpc9cW2nhNYjp2jqNWl7thTqec9vop0Zd6Ile2qsB0FfssJz6lh760OHoX4tHF75fCRjpNDc4IsQY1/A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721139931; c=relaxed/simple; bh=Q5oPOfaPPMtVbJo9sOz517kdeGlVdwhnoDlCg22S/Pg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FQjcsDFrmmkJiMlhe5bwxZPi5LyXbmO/JtpCHgZlZ6ypyhwOr0aRa82PfVqa8Thslq+QmTIwiuZxONu/zqML24YF49h74e7Q1wmCW79QeIz7Fd2JbUK+u39JfNjpv0z0uAL4CSa01AnKM13Tk51+ClzVgVyF7/CCNdS5a//tGV4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dg0rfLEh; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="dg0rfLEh" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 59D1BC4AF0D; Tue, 16 Jul 2024 14:25:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721139930; bh=Q5oPOfaPPMtVbJo9sOz517kdeGlVdwhnoDlCg22S/Pg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dg0rfLEhvWLxm1RCOVV1Qy28tuRXLrndXV3VQJq3ACF32d1MAa6F0dCqiAvY9ZmNi TeAuyWJtFqLdkfkBDyl8O1Fw3eMZL1t9/7pIJ87JcyFMRhvFCggelP6JC+S1u1ahse K3yXvUowRwUkfhVS2hEhfhVADngjnCTJ3p+FNaBaZrdVZZB1gyjPcfr0YSLHGp+aaX Cjz9nYBEy1GLIII8Ip9Sr+PNqd/k/xzSP4EfZQN+BeYUdFOI7qTGOFLV/V+UpiXgkv 3qKf+RO+SCi5s8ON0p3/Co8lHqyhqbeSm9YXuBpgu6uOb/RnQrTF9tqQgYwRAdVtj/ jXed5+4C/XJAg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Ganesh Goudar , Michael Ellerman , Sasha Levin , mahesh@linux.ibm.com, linuxppc-dev@lists.ozlabs.org Subject: [PATCH AUTOSEL 6.9 04/22] powerpc/eeh: avoid possible crash when edev->pdev changes Date: Tue, 16 Jul 2024 10:24:11 -0400 Message-ID: <20240716142519.2712487-4-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716142519.2712487-1-sashal@kernel.org> References: <20240716142519.2712487-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.9.9 Content-Transfer-Encoding: 8bit From: Ganesh Goudar [ Upstream commit a1216e62d039bf63a539bbe718536ec789a853dd ] If a PCI device is removed during eeh_pe_report_edev(), edev->pdev will change and can cause a crash, hold the PCI rescan/remove lock while taking a copy of edev->pdev->bus. Signed-off-by: Ganesh Goudar Signed-off-by: Michael Ellerman Link: https://msgid.link/20240617140240.580453-1-ganeshgr@linux.ibm.com Signed-off-by: Sasha Levin --- arch/powerpc/kernel/eeh_pe.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/kernel/eeh_pe.c b/arch/powerpc/kernel/eeh_pe.c index e0ce812796241..7d1b50599dd6c 100644 --- a/arch/powerpc/kernel/eeh_pe.c +++ b/arch/powerpc/kernel/eeh_pe.c @@ -849,6 +849,7 @@ struct pci_bus *eeh_pe_bus_get(struct eeh_pe *pe) { struct eeh_dev *edev; struct pci_dev *pdev; + struct pci_bus *bus = NULL; if (pe->type & EEH_PE_PHB) return pe->phb->bus; @@ -859,9 +860,11 @@ struct pci_bus *eeh_pe_bus_get(struct eeh_pe *pe) /* Retrieve the parent PCI bus of first (top) PCI device */ edev = list_first_entry_or_null(&pe->edevs, struct eeh_dev, entry); + pci_lock_rescan_remove(); pdev = eeh_dev_to_pci_dev(edev); if (pdev) - return pdev->bus; + bus = pdev->bus; + pci_unlock_rescan_remove(); - return NULL; + return bus; } -- 2.43.0