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 8B7E21741D8; Wed, 3 Jul 2024 10:46:23 +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=1720003583; cv=none; b=jTkPK93T+RJICN8x+AOsctozgDm1foBz/rGEAt3OA2M3Wec4Ob2RxL+E+pkfcyAi7u4cxscPLpqGMue6nlLPSAjC1jMlgzvGMbKKh/zUx1CSFU9BN1j+Pg8UB9qmNRurLVqkoziJHt82T0VaQ9gphtKfR0VE6ukv2FYpkdWyPK0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720003583; c=relaxed/simple; bh=hO132jt60qibtyvaRIfN67KOxoqsd3uzPxhAtwFLSPg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=URSbO2VDFl8E00rQ84atkTUAbQJ/aSjvoQxb2f+dOW5TDQ9XQcxl6hr57B5iM8foUO4cDLvcQakLt/mqRBTvG48NZkvFj19AjHAq7bpR1ArYQfwR8IDTP+zHcBbxS8kBMQvR+A6EZ/6ARvzcX/SqanC0952cX0+DFpE2kEoAN28= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=QIDdnOfV; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="QIDdnOfV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 075E5C2BD10; Wed, 3 Jul 2024 10:46:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1720003583; bh=hO132jt60qibtyvaRIfN67KOxoqsd3uzPxhAtwFLSPg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QIDdnOfVUYe4vtp18/DvvcrWvk2IY0PO0mD7G4oy5aG90iOH4T1DRO6oBj8fcThb7 qL3t8S1OUGejYRHfI5GaTBVX1tTl7UKh4krnFiAgMZNbBUmCpdO5EHUj5uaBF+93iE 19aKImRtX39II6GFaN8u4Ex63rF0Zc/DnbLU08WM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yazen Ghannam , "Borislav Petkov (AMD)" , Sasha Levin Subject: [PATCH 4.19 089/139] x86/amd_nb: Check for invalid SMN reads Date: Wed, 3 Jul 2024 12:39:46 +0200 Message-ID: <20240703102833.802719611@linuxfoundation.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240703102830.432293640@linuxfoundation.org> References: <20240703102830.432293640@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yazen Ghannam [ Upstream commit c625dabbf1c4a8e77e4734014f2fde7aa9071a1f ] AMD Zen-based systems use a System Management Network (SMN) that provides access to implementation-specific registers. SMN accesses are done indirectly through an index/data pair in PCI config space. The PCI config access may fail and return an error code. This would prevent the "read" value from being updated. However, the PCI config access may succeed, but the return value may be invalid. This is in similar fashion to PCI bad reads, i.e. return all bits set. Most systems will return 0 for SMN addresses that are not accessible. This is in line with AMD convention that unavailable registers are Read-as-Zero/Writes-Ignored. However, some systems will return a "PCI Error Response" instead. This value, along with an error code of 0 from the PCI config access, will confuse callers of the amd_smn_read() function. Check for this condition, clear the return value, and set a proper error code. Fixes: ddfe43cdc0da ("x86/amd_nb: Add SMN and Indirect Data Fabric access for AMD Fam17h") Signed-off-by: Yazen Ghannam Signed-off-by: Borislav Petkov (AMD) Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20230403164244.471141-1-yazen.ghannam@amd.com Signed-off-by: Sasha Levin --- arch/x86/kernel/amd_nb.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/amd_nb.c b/arch/x86/kernel/amd_nb.c index 923b4bac96138..ef1fa51ea98e9 100644 --- a/arch/x86/kernel/amd_nb.c +++ b/arch/x86/kernel/amd_nb.c @@ -145,7 +145,14 @@ static int __amd_smn_rw(u16 node, u32 address, u32 *value, bool write) int amd_smn_read(u16 node, u32 address, u32 *value) { - return __amd_smn_rw(node, address, value, false); + int err = __amd_smn_rw(node, address, value, false); + + if (PCI_POSSIBLE_ERROR(*value)) { + err = -ENODEV; + *value = 0; + } + + return err; } EXPORT_SYMBOL_GPL(amd_smn_read); -- 2.43.0