From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796384869; b=2t0FsnP8fhBKnaRpiBuviIM6UQsrtVfrJNaIUomgoaLxbVmasP8/jVafJdgkmcYylGe1 Z0UKdTMhh3hmJyn2VVnADMaFTGbEp2Dro9fvZ+Bnr7XvMHJxqsvvwsz1BGp0ra50cIWbY 2y+jQuXqfQ7PUsOJmmrxYFKPRX3LpVcJwYCWNvXRYRZdCTDPqh9BtnhUzboLWRQv7gLkZ y+mcFj75gWEJhZ6k1BZWcrktr+KyW6426r2E31tPnsUG+Xq/HMnAG8R14FB0G3IpApWe3 M/4+EaMVmcvk3MGiKT0mHp/xCX28+4PE6bRXEwMeDNtsd5YA4rR3Z3ANgKozpzveKzg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384869; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=poxlfBoJhhxVQ1D+UCx0/OskpMl/9zmzsR8iGgBWzPE=; b=NaZtMZujGYoyGGaLa0DptJjI8Z67nR1YUESiyCH6u31aVf7YPX06dPEWU10gImhpUFNu qPib54p8Y2CoDffAvSgKQcvguFvvdyLHBOF/oH1u8+ioH83hI6CY98k2+w9wLHzf7Rwli EngBQHFs1z6qzdYGvYdd41Jayj//qMs0oRnetfsdQEWKP0uxX3bqKUBb5sRytP60MLwiW sW8DiuxZd18YrN5qINQqpBlyyItvrYVquEUk+ilF8V6NrcuiQbtnA44ZXUbMqXqvRPeQW FizWi/nWzvx0uKWU3YKOCJr/aUnla2wmv89Nk+FI8bggb92AV4LfV9Z/Wn4x9k2XAfQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=Y7W9LhFh; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1CBA3606A322; Fri, 4 Dec 2026 11:47:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=Y7W9LhFh Received: by smtp.kernel.org (Postfix) with ESMTPSA id 640EC1F00931; Fri, 4 Dec 2026 11:47:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384868; bh=poxlfBoJhhxVQ1D+UCx0/OskpMl/9zmzsR8iGgBWzPE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Y7W9LhFhImdHmH40CXaqpjHMwh0zAAn9i08c88/lD9RcTebvqWH8cIX1ukzFrR7cE pFiLBMrze7rAPxjU8Rk5l+nojVcEb1NrucnJdTWucBlsY0J49LI6+k+6Pl/wXpFhw0 y04Tw0kJum/8CQILnWcR4KhrMMGs0lMWk0loT+Ho= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Guenter Roeck , Ricardo Neri , Sasha Levin Subject: [PATCH 6.6 0287/1167] hwmon: (coretemp) Return -ENODATA for invalid temperature readings Date: Fri, 4 Dec 2026 18:55:14 +0900 Message-ID: <20261204100709.518512509@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ricardo Neri [ Upstream commit f63aaa529cbc73146ff0d52235e5479042285cae ] IA32_THERM_STATUS and IA32_PACKAGE_THERM_STATUS have a valid bit, bit 31. The Intel SDM documents it only for the former, but the package register implements it too: x86_pkg_temp_thermal has required it since commit f1a18a105660 ("Thermal: CPU Package temperature thermal"). This driver checked the bit for both registers as well, until commit bf6ea084ebb5 ("hwmon: (coretemp) Do not return -EAGAIN for low temperatures") made it ignore the bit because some CPUs clear it while the temperature is too low to be measured. Since then, temp%d_input reports such a reading as a real temperature. Userspace cannot tell it apart from a genuinely low one. Fail the read with -ENODATA while the CPU reports the reading as invalid. On a CPU that clears the bit, reading temp%d_input now fails where it used to return a low value. sensors(1) shows N/A in its place. Cc: stable@vger.kernel.org Suggested-by: Guenter Roeck Link: https://lore.kernel.org/all/46f9f319-de71-412f-a424-6cb801478456@roeck-us.net/ Signed-off-by: Ricardo Neri Link: https://patch.msgid.link/20261006-coretemp-enodata-v2-1-64e788acc7dc@linux.intel.com Signed-off-by: Guenter Roeck [ sashal: Kept this tree's existing msr/jiffies code (rdmsr_on_cpu with eax, get_jiffies_64, 0x7f mask, core_data lookup) and applied the valid-bit and -ENODATA changes on top, plus a doc context adjustment. ] Signed-off-by: Sasha Levin --- Documentation/hwmon/coretemp.rst | 3 +++ drivers/hwmon/coretemp.c | 21 +++++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Documentation/hwmon/coretemp.rst b/Documentation/hwmon/coretemp.rst index c609329e3bc45..6089bee1159f1 100644 --- a/Documentation/hwmon/coretemp.rst +++ b/Documentation/hwmon/coretemp.rst @@ -47,6 +47,9 @@ All Sysfs entries are named with their core_id (represented here by 'X'). ================= ======================================================== tempX_input Core temperature (in millidegrees Celsius). + Reading fails with -ENODATA while the CPU reports the + temperature as invalid. Some CPUs do this when the + temperature is too low to be measured. tempX_max All cooling devices should be turned on (on Core2). tempX_crit Maximum junction temperature (in millidegrees Celsius). tempX_crit_alarm Set when Out-of-spec bit is set, never clears. diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c index a8b16b6eeca73..4c14c1433daa8 100644 --- a/drivers/hwmon/coretemp.c +++ b/drivers/hwmon/coretemp.c @@ -56,6 +56,8 @@ MODULE_PARM_DESC(tjmax, "TjMax value in degrees Celsius"); /* * Per-Core Temperature Data + * @temp_valid: Whether the CPU reported @temp as valid. @temp is not + * reported when this is false. * @tjmax: The static tjmax value when tjmax cannot be retrieved from * IA32_TEMPERATURE_TARGET MSR. * @last_updated: The time when the current temperature value was updated @@ -70,6 +72,7 @@ MODULE_PARM_DESC(tjmax, "TjMax value in degrees Celsius"); */ struct temp_data { int temp; + bool temp_valid; int tjmax; u64 last_updated; unsigned int cpu; @@ -396,7 +399,8 @@ static ssize_t show_temp(struct device *dev, struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct platform_data *pdata = dev_get_drvdata(dev); struct temp_data *tdata = pdata->core_data[attr->index]; - int tjmax; + int tjmax, temp; + bool valid; mutex_lock(&tdata->update_lock); @@ -405,17 +409,22 @@ static ssize_t show_temp(struct device *dev, if (time_after64(get_jiffies_64(), tdata->last_updated + HZ)) { rdmsr_on_cpu(tdata->cpu, tdata->status_reg, &eax, &edx); /* - * Ignore the valid bit. In all observed cases the register - * value is either low or zero if the valid bit is 0. - * Return it instead of reporting an error which doesn't - * really help at all. + * Bit 31 indicates whether the reading is valid. Some CPUs + * clear it while the temperature is too low to be measured. + * Such a reading is not a temperature. Do not report it. */ + tdata->temp_valid = (eax >> 31) & 1; tdata->temp = tjmax - ((eax >> 16) & 0x7f) * 1000; tdata->last_updated = get_jiffies_64(); } + valid = tdata->temp_valid; + temp = tdata->temp; mutex_unlock(&tdata->update_lock); - return sprintf(buf, "%d\n", tdata->temp); + + if (!valid) + return -ENODATA; + return sprintf(buf, "%d\n", temp); } static int create_core_attrs(struct temp_data *tdata, struct device *dev, -- 2.53.0