Received: by 2002:ab2:6c55:0:b0:1fd:c486:4f03 with SMTP id v21csp696206lqp; Wed, 12 Jun 2024 13:25:56 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX83RehC2D0fZXGHoQ5mrmxGRpv69p9tYoFx3suY0dQUVlIgBzwCZciDscOifpWFgMSzHhJeV/AGZFMFCeWoDeQDiKMPB1s04M8ueKaBA== X-Google-Smtp-Source: AGHT+IGpDA7N+fholJek8tGs7MpUk+c+iRML1Kg138A4pqcI7KcxUoTdrXR/JNljpAC+fZKC7pR4 X-Received: by 2002:a17:906:c149:b0:a6f:1fc0:3fc0 with SMTP id a640c23a62f3a-a6f47c9b35emr240143466b.6.1718223956045; Wed, 12 Jun 2024 13:25:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718223956; cv=pass; d=google.com; s=arc-20160816; b=ZAK2+A97XGj55oVGNbinbuWl1q3r3akzRW7CrnCcO/vaQztMLltuX32kg6SD5i0kgC fKWkBIhwgEx2qXPpssMMOoRxYb/ezK03gYAYxmu/JYtW66XmpQSrShniig8KxkfG5lHM Dp0ty/cv+/7/2gxxZnwx4f1vVaWIM1Gk1M5s+4ZZ0bFdSGt93HroKAZmJnGpoCIW98LM WwRf0Oszs9yDNcnPSc0Nv1cMjFr7KXGqmF0oSmo3E3RQhhd9ToPXRlsIHjLF7L0es5Za cf/PnKvVA7feBAhjAu/EH4J3exk4NNm5c+dB8Ep2cnqJxEgKhKA/KaDrvNDqz0oVU7KT sdpw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:precedence:robot-unsubscribe:robot-id :message-id:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:in-reply-to:cc:subject:to:reply-to:sender :from:dkim-signature:dkim-signature:date; bh=JhnUWrKH8oCfrVNns6zPYwh5A7hm6cjQDq/+0BZwGaE=; fh=AkDx5SWRzZQqa1GChgFXO0hx/mbZkk+LlUnQOW8XMbI=; b=Z43eIskJd9Ql0dlfxRzyfbWrVVot5UpOfDQ9WMuBujpdno2HmhUwFX490q4ZXP26Ge k1iwewO7HPLGMZSOtG4NBKH8ne8ETo3Lswy5TfrFwPIkXbHmLMDx+kJLuwFV2d/IlLvP QE/TLu78ZQ+Ga/HVM5BTacaWUtARRCtmoG6uZCZhOqrZQ0I6jez4QzTypaqOd4wBnTEJ i5EU0YCOmEVq/DwxOyjSlbeKdw8h2exGDvQvbQhW0IpkBb51AFE+VZKbJXDkx7u9aFCa a4cDnzq5Pb6zKMVLd3z+Xhq2PkKbFxoyO1TpGh80LvfO6DJk/h8+tIxRNMgCd95YmFki F52A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=JVV2Epxe; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-212216-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212216-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a6f0de9f27asi454346466b.940.2024.06.12.13.25.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 13:25:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-212216-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=JVV2Epxe; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-212216-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212216-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 99EBC1F24D8B for ; Wed, 12 Jun 2024 20:25:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1767D12B170; Wed, 12 Jun 2024 20:24:31 +0000 (UTC) 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" 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 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: 7bit The following commit has been merged into the x86/misc branch of tip: Commit-ID: c2d79cc5455c891de6c93e1e0c73d806e299c54f Gitweb: https://git.kernel.org/tip/c2d79cc5455c891de6c93e1e0c73d806e299c54f 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, u32 *regval) 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 = 0; } static long get_raw_temp(struct k10temp_data *data) @@ -205,6 +206,7 @@ static int k10temp_read_temp(struct device *dev, u32 attr, int channel, long *val) { struct k10temp_data *data = dev_get_drvdata(dev); + int ret = -EOPNOTSUPP; u32 regval; switch (attr) { @@ -221,13 +223,17 @@ static int k10temp_read_temp(struct device *dev, u32 attr, int channel, *val = 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 = 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 = (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 attr, 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 *pdev, int i; for (i = 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 |= BIT(TCCD_BIT(i)); }