From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=44.202.169.39 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793460942; b=mogQzjKUDZX7bPOBgAxNJpJwI0AXSA7CXVdq0wBH6kfwRf8ue5atT7vrD8ncrIoiFnpL sQIajpVKuC4h4CPISjE0cwnTaBy2gBMLA7sd4V8JcWFpX3YeVeNjm5RamM8VcRO0nEvfQ aZkxYRMYh1ikeaBW8kymmgmtqgc/UoR25VBoRMEFrHDBurxoKkkdlACX9EU/RzeEzbL50 2kiEdlwJPECWOkqGDwDnj2kOds67yXFAJJC4UDVVmEIng33RhOUGKxQvGzEgckPL166bD oMFH7c31yFDYgr35lGvPH+YbWik+0hZQORkFtwW+ocmKx8hDoESoVJNWRiAJaPB4dBQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793460942; h=DMARC-Filter:Received:Received:X-Authority-Analysis:DKIM-Signature: Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:X-AntiAbuse: X-AntiAbuse:X-AntiAbuse:X-AntiAbuse:X-AntiAbuse:X-BWhitelist: X-Source-IP:X-Source-L:X-Exim-ID:X-Source:X-Source-Args:X-Source-Dir: X-Source-Sender:X-Source-Auth:X-Email-Count:X-Org:X-Source-Cap: X-Local-Domain:X-CMAE-Envelope; bh=I5WFgWNQkph9IT5r1JCURWK3D7hQlFW3aeqHZAWEzzc=; b=dDLr7RKHBsE61JKkH1q4dEcQ9km5HLuum0L41yOcGWcT+/utrfYhsZPKeHCRhoOtlQM1 R0F87pDMlmGmPhTDPRawv2ezJWpU4kD3U69Y64Kl/LaaKnlh52E+zBpWqHkq4eKLrPXAB hNuJxHKoUruAGsrP7iXpRUOoX4QCNZmda6yx4zesUve5udMBRZ+ILzBGjUgD7dFYJ01J3 ES/SmibN4tAd6Bm66gHl93OnheiWPNUVg17fMWsAjsYEOuJAwBHSB2Q++6f7ye86uY/h0 KW4VG+lnPAZRoVx4/oyWzSdJLdbC2WAUnD9Ltjz8g8nz/JHf6whmeCaqNVR2ziFCYfw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=roeck-us.net; spf=fail smtp.mailfrom=roeck-us.net; dkim=pass header.d=roeck-us.net header.i=@roeck-us.net header.a=rsa-sha256 header.s=default header.b=5SLQCJUa; arc=none smtp.remote-ip=44.202.169.39 Received: from omta040.useast.a.cloudfilter.net (omta040.useast.a.cloudfilter.net [44.202.169.39]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D2E5D606A31A for ; Sat, 31 Oct 2026 15:35:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D2E5D606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=roeck-us.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=roeck-us.net header.i=@roeck-us.net header.a=rsa-sha256 header.s=default header.b=5SLQCJUa Received: from eig-obgw-5006b.ext.cloudfilter.net ([10.0.29.217]) by cmsmtp with ESMTPS id N9cpxJnSZMylkNB7Gxn500; Sat, 31 Oct 2026 15:35:34 +0000 Received: from 162-215-252-36.unifiedlayer.com ([208.91.199.152]) by cmsmtp with ESMTPS id NB7GxPYluNSXiNB7GxtSJZ; Sat, 31 Oct 2026 15:35:34 +0000 X-Authority-Analysis: v=2.4 cv=JvXxrN4C c=1 sm=1 tr=0 ts=6ae60ac6 a=QNED+QcLUkoL9qulTODnwA==:117 a=2cfIYNtKkjgZNaOwnGXpGw==:17 a=660iZSQnnn4A:10 a=M0FbrtG7MMAA:10 a=VwQbUJbxAAAA:8 a=_jlGtV7tAAAA:8 a=FL1jxN2wxtSqEv0DJ00A:9 a=nlm17XC03S6CtCLSeiRr:22 a=KPbNTLLc3YvdawN95zVk:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=roeck-us.net; s=default; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Unsubscribe-Post:List-Subscribe:List-Post:List-Owner: List-Archive; bh=I5WFgWNQkph9IT5r1JCURWK3D7hQlFW3aeqHZAWEzzc=; b=5SLQCJUaeKjE O5TVNCiOPAjFOblVj6WpnUMtA10/ImSaoKBBijTr5KDwOBrTT9jESljRn1uY21eA3ItTTJwpcw47n 3qW/hZkdTQn2TBJ0WD7Ur6ORA5lI21l7Kk/8TxmR04BWx/yG+Xe6pqx04c1tDQ1FF656pzHICai0g Kd0C/hEVLdfBwlknL+cY3h0DPdaNFbPHpoQ4nJjqPw7Tis4AImGaqYeMssxDvfVyps9fF4xzcvIsg 35WBVmytFrVg5V3uFsSD+XK329fvm1MxPFmYf1DmLcha+xa7PekTA0MYkvqayjdmKvt7jFRJSB3xi SPLXoeiDmtBynDPTp5Zkhg==; Received: from 108-223-40-66.lightspeed.sntcca.sbcglobal.net ([108.223.40.66]:35832 helo=server.roeck-us.net) by bh-25.webhostbox.net with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.100.1) (envelope-from ) id 1xNB7G-00000001q9K-0Xf3; Sat, 31 Oct 2026 21:05:34 +0530 From: Guenter Roeck To: linux-hwmon@vger.kernel.org Cc: Guenter Roeck , Sashiko Subject: [PATCH 3/3] hwmon: (coretemp) Fix 32-bit jiffies wraparound in show_temp() Date: Sat, 31 Oct 2026 08:35:28 -0700 Message-ID: <20261031153528.3195123-4-linux@roeck-us.net> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20261031153528.3195123-1-linux@roeck-us.net> References: <20261031153528.3195123-1-linux@roeck-us.net> X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - bh-25.webhostbox.net X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - roeck-us.net X-BWhitelist: no X-Source-IP: 108.223.40.66 X-Source-L: No X-Exim-ID: 1xNB7G-00000001q9K-0Xf3 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 108-223-40-66.lightspeed.sntcca.sbcglobal.net (server.roeck-us.net) [108.223.40.66]:35832 X-Source-Auth: guenter@roeck-us.net X-Email-Count: 12 X-Org: HG=direseller_whb_net_legacy;ORG=directi; X-Source-Cap: cm9lY2s7YWN0aXZzdG07YmgtMjUud2ViaG9zdGJveC5uZXQ= X-Local-Domain: yes X-CMAE-Envelope: MS4xfIrjYHQJccde9aNWCc0A+aUPcNqn6pDEHzk7ru7Rs3mUNvbaxlSlIJK0HCoEsEep7aSYpJi03JUBQO6NPLZnl+/4X1AUvdIZE4ZcjEGaa7YeHsHXHv50 EtTJr62a46Mta9Eo1pUvcf+kRbK2cZz1lsxksf0CpINFo1M7/ssfkZbqWrm/w66smRugeAEwVI0eooJCF+au90dDrmsA3nCcmJfLo5iMzSicOXtucbygRV2G show_temp() rate-limits MSR reads by storing tdata->last_updated as an unsigned long and comparing it against jiffies using time_after(jiffies, tdata->last_updated + HZ). time_after() relies on signed long subtraction, which only produces the expected result while the two timestamps are within LONG_MAX jiffies of each other. On 32-bit kernels, if tempX_input is not read for more than LONG_MAX jiffies (~24.85 days at HZ=1000), the signed difference flips sign and time_after() evaluates to false. Because tdata->last_updated is only refreshed when time_after() succeeds, subsequent reads remain blocked from refreshing for another ~24.85 days until jiffies wraps past tdata->last_updated + HZ again, returning either a stale cached temperature or -ENODATA if the sensor had never been read since initialization. Store tdata->last_updated as a u64 and use get_jiffies_64() with time_after64(), which does not wrap in any practical uptime. Reported-by: Sashiko Fixes: bebe467823c0 ("hwmon: New coretemp driver") Signed-off-by: Guenter Roeck --- drivers/hwmon/coretemp.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c index 7fced0e2abeb..96d57fe12de6 100644 --- a/drivers/hwmon/coretemp.c +++ b/drivers/hwmon/coretemp.c @@ -76,7 +76,7 @@ struct temp_data { int temp; bool temp_valid; int tjmax; - unsigned long last_updated; + u64 last_updated; unsigned int cpu; int index; u32 cpu_core_id; @@ -407,7 +407,7 @@ static ssize_t show_temp(struct device *dev, mutex_lock(&tdata->update_lock); /* Check whether the time interval has elapsed */ - if (time_after(jiffies, tdata->last_updated + HZ)) { + if (time_after64(get_jiffies_64(), tdata->last_updated + HZ)) { tjmax = get_tjmax(tdata, dev); rdmsrq_on_cpu(tdata->cpu, tdata->status_reg, &val.q); /* @@ -417,7 +417,7 @@ static ssize_t show_temp(struct device *dev, */ tdata->temp_valid = (val.l >> 31) & 1; tdata->temp = tjmax - ((val.l >> 16) & 0xff) * 1000; - tdata->last_updated = jiffies; + tdata->last_updated = get_jiffies_64(); } valid = tdata->temp_valid; @@ -521,11 +521,8 @@ init_temp_data(struct platform_data *pdata, unsigned int cpu, int pkg_flag) tdata->cpu = cpu; tdata->cpu_core_id = topology_core_id(cpu); tdata->attr_size = MAX_CORE_ATTRS; - /* - * A zero timestamp does not look stale on 32-bit, where jiffies - * starts just short of wrapping. Backdate it instead. - */ - tdata->last_updated = jiffies - HZ - 1; + /* Backdate to force a refresh on the first read */ + tdata->last_updated = get_jiffies_64() - HZ - 1; mutex_init(&tdata->update_lock); return tdata; } -- 2.45.2