From nobody Thu Feb 12 10:56:04 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 2DD6785654; Wed, 12 Jun 2024 20:24:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718223870; cv=none; b=TlB/QRigDWKr2OPhvC5mRl8puON+raRwH3WVxwsuMNvBc5rYDOO5NYzuRwAgg7j5fq+DloGV+nV682iFrki8zIyBnqA9rLfnmt6gRO4KT8wCpQXZOFsaelf0o0S0KaLhW2N8cI+NjIZjconyMLlBAqZl+GZCyIYyDPZ66/eJvis= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718223870; c=relaxed/simple; bh=5ptvDrTnJH6LMCFYjRa23MCvX6WJR/txMfkuYtdTgmo=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=Upe6gGratLNdgPAz/QcU8z68la0Cxz8nbKdruzEB2bLAMzoLkklRvZlT6UyqHlBEMbJGvgs0vw7QjNNQqjHRys5YreSqE2nYLisHTntT231FRgAvcXtIg+rZtMJ/D5S6Whi60QRKueCnNnJHBCEXq/1yem3iqw2FIX8/Y7u+fw8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=JVV2Epxe; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=bNvtegmx; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="JVV2Epxe"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="bNvtegmx" Date: Wed, 12 Jun 2024 20:24:24 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1718223864; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JhnUWrKH8oCfrVNns6zPYwh5A7hm6cjQDq/+0BZwGaE=; b=JVV2EpxeuH5hPwEEHsiqv/jXk04eDdskTEcmt+mw3TG4/q83bmyuiuH5YVJUoOeIn3xln7 nRcD6Sv7tY50vWdyCZeaNdFmj5H/3SW1sM1waxe7JnhtLlrb5ahANMf+RxfpOgcaHLklFI X/Glb4i5ri74rkFfMzxnSMOYMzSnFZxyJdKb5fjDKWyN6evFL0icO+K43BB10xWLNW1bSr BzZC4i15Kp49snKry57zZDs16T7hFdj2xt6nQapPG425X3589OwhevYsqIF5o1ascUu7Bd mxM3eMlI0tZu1cVH1K3dZAJaB7uVpbMgJG7DNtdWIxXls9DUIZCdPpnIfFmsfQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1718223864; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JhnUWrKH8oCfrVNns6zPYwh5A7hm6cjQDq/+0BZwGaE=; b=bNvtegmxwBHdqr1OQWpX+sbveY0OpYC0Wqp8/l3mYBVeypMOXsBh0N4ridJt/pG7qsl0Ke MnMeY00+7SP3ZiCQ== From: "tip-bot2 for Yazen Ghannam" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/misc] hwmon: (k10temp) Check return value of amd_smn_read() Cc: Yazen Ghannam , "Borislav Petkov (AMD)" , Mario Limonciello , Guenter Roeck , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20240606-fix-smn-bad-read-v4-3-ffde21931c3f@amd.com> References: <20240606-fix-smn-bad-read-v4-3-ffde21931c3f@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <171822386432.10875.15028242474878869250.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the x86/misc branch of tip: Commit-ID: c2d79cc5455c891de6c93e1e0c73d806e299c54f Gitweb: https://git.kernel.org/tip/c2d79cc5455c891de6c93e1e0c73d806e= 299c54f Author: Yazen Ghannam AuthorDate: Thu, 06 Jun 2024 11:12:56 -05:00 Committer: Borislav Petkov (AMD) CommitterDate: Wed, 12 Jun 2024 11:33:46 +02:00 hwmon: (k10temp) Check return value of amd_smn_read() Check the return value of amd_smn_read() before saving a value. This ensures invalid values aren't saved or used. There are three cases here with slightly different behavior: 1) read_tempreg_nb_zen(): This is a function pointer which does not include a return code. In this case, set the register value to 0 on failure. This enforces Read-as-Zero behavior. 2) k10temp_read_temp(): This function does have return codes, so return the error code from the failed register read. Continued operation is not necessary, since there is no valid data from the register. Furthermore, if the register value was set to 0, then the following operation would underflow. 3) k10temp_get_ccd_support(): This function reads the same register from multiple CCD instances in a loop. And a bitmask is formed if a specific bit is set in each register instance. The loop should continue on a failed register read, skipping the bit check. Signed-off-by: Yazen Ghannam Signed-off-by: Borislav Petkov (AMD) Reviewed-by: Mario Limonciello Acked-by: Guenter Roeck Link: https://lore.kernel.org/r/20240606-fix-smn-bad-read-v4-3-ffde21931c3f= @amd.com --- drivers/hwmon/k10temp.c | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/drivers/hwmon/k10temp.c b/drivers/hwmon/k10temp.c index 8092312..6cad35e 100644 --- a/drivers/hwmon/k10temp.c +++ b/drivers/hwmon/k10temp.c @@ -153,8 +153,9 @@ static void read_tempreg_nb_f15(struct pci_dev *pdev, u= 32 *regval) =20 static void read_tempreg_nb_zen(struct pci_dev *pdev, u32 *regval) { - amd_smn_read(amd_pci_dev_to_node_id(pdev), - ZEN_REPORTED_TEMP_CTRL_BASE, regval); + if (amd_smn_read(amd_pci_dev_to_node_id(pdev), + ZEN_REPORTED_TEMP_CTRL_BASE, regval)) + *regval =3D 0; } =20 static long get_raw_temp(struct k10temp_data *data) @@ -205,6 +206,7 @@ static int k10temp_read_temp(struct device *dev, u32 at= tr, int channel, long *val) { struct k10temp_data *data =3D dev_get_drvdata(dev); + int ret =3D -EOPNOTSUPP; u32 regval; =20 switch (attr) { @@ -221,13 +223,17 @@ static int k10temp_read_temp(struct device *dev, u32 = attr, int channel, *val =3D 0; break; case 2 ... 13: /* Tccd{1-12} */ - amd_smn_read(amd_pci_dev_to_node_id(data->pdev), - ZEN_CCD_TEMP(data->ccd_offset, channel - 2), - ®val); + ret =3D amd_smn_read(amd_pci_dev_to_node_id(data->pdev), + ZEN_CCD_TEMP(data->ccd_offset, channel - 2), + ®val); + + if (ret) + return ret; + *val =3D (regval & ZEN_CCD_TEMP_MASK) * 125 - 49000; break; default: - return -EOPNOTSUPP; + return ret; } break; case hwmon_temp_max: @@ -243,7 +249,7 @@ static int k10temp_read_temp(struct device *dev, u32 at= tr, int channel, - ((regval >> 24) & 0xf)) * 500 + 52000; break; default: - return -EOPNOTSUPP; + return ret; } return 0; } @@ -381,8 +387,20 @@ static void k10temp_get_ccd_support(struct pci_dev *pd= ev, int i; =20 for (i =3D 0; i < limit; i++) { - amd_smn_read(amd_pci_dev_to_node_id(pdev), - ZEN_CCD_TEMP(data->ccd_offset, i), ®val); + /* + * Ignore inaccessible CCDs. + * + * Some systems will return a register value of 0, and the TEMP_VALID + * bit check below will naturally fail. + * + * Other systems will return a PCI_ERROR_RESPONSE (0xFFFFFFFF) for + * the register value. And this will incorrectly pass the TEMP_VALID + * bit check. + */ + if (amd_smn_read(amd_pci_dev_to_node_id(pdev), + ZEN_CCD_TEMP(data->ccd_offset, i), ®val)) + continue; + if (regval & ZEN_CCD_TEMP_VALID) data->show_temp |=3D BIT(TCCD_BIT(i)); }