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 737271ABCBA; Tue, 16 Jul 2024 14:29:28 +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=1721140168; cv=none; b=qp8xabnAJz+5xMhBjErTYUR3VdAJBu75RpIlu9z3KKBHPvwB9bof6Tz/jt1iPcmGwYL0CSUU5IEGKZM3bCeMfHYNAJT0mEbnB8UQLsbdboYtKtZyirCJ9IjVAd5eUJdwIMUkLhcAKdAiScEiO2977JEH8sy6BZXtUnVL3cmlv1c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721140168; c=relaxed/simple; bh=bpfITA42XWvZVHxWy7B4/5zK5MXRBy8D9dEJb9S7Ioc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JU2lPleeMTz7yLH8cLAP1z2Nm04I9eUV/YW8bkQTI75C5DFGypP4djvub5xS2XNrHmwlbnssUHFtmMB3zugeGwcoZE7ULaysf+3uQ+n6LEUBXPpCxKChIanJ/S9mQe5fS6wDEK8eXXlZFv6+Pl9kFluKj5rlmP5YIr7M/6uvA9o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aaC+pFsx; 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="aaC+pFsx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 642D7C4AF0E; Tue, 16 Jul 2024 14:29:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721140168; bh=bpfITA42XWvZVHxWy7B4/5zK5MXRBy8D9dEJb9S7Ioc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aaC+pFsx5ta5cxvOVVQgv/EYXxhDti8ZYekyy4MtThha2AN8hsNQc26ef0bRJ9zR3 BiGf9SS9Ewu4lzXb8p3SySA4pgQvxz4WGjq4fdiyV8ed2icjD5xA/Eu04G5LV2Q+S7 AiViiUT2nSibfXbbEMUmeLVXdjt/Z7VvQvHUC0+YofOgAOMISYczepLHQEpzPDIVb4 0uXt6Bow7Ia/67uN/aHv7qKyVPk0Mk12ievfWTBGgnIciULRwFMGkkja1Hsz2ViFQy XK7+TKC7xNy08C7fAi5CflmzL0A6FNRYqZhl5a2SG56GCfm565IBritGFnaRfSHi2K A/DnWqgPQiSCg== 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 5.15 3/9] powerpc/eeh: avoid possible crash when edev->pdev changes Date: Tue, 16 Jul 2024 10:29:05 -0400 Message-ID: <20240716142920.2713829-3-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716142920.2713829-1-sashal@kernel.org> References: <20240716142920.2713829-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 5.15.162 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 845e024321d47..a856d9ba42d20 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