Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1766103imm; Sun, 15 Jul 2018 16:39:32 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeaN+FYqXlwIV9UFJZh8uRGilF9WagIMB9mvdLAdkzitAltC79O+R2Ih59TM+FkmKeWl4JW X-Received: by 2002:a63:b40e:: with SMTP id s14-v6mr13812554pgf.9.1531697972614; Sun, 15 Jul 2018 16:39:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531697972; cv=none; d=google.com; s=arc-20160816; b=mYQGuqRpn/K/3MKbaxUK4ay5O0QtBEuRTinvpE2eyzJwrcWhnlqvX/LLobC9Eq069J hcVT/xdojB0l/LT+K6KRuZ5W6bD3Wp+dxAPNIPMRUPhMwk2CwzlhMmfmvfkyw9j8soWm PKwaJVpb4WOrmDj4fXfbTfcOV3TZJLbhppDTkGfQOtd6xkG/UmoK8Ryon/3VOYtABkiH Y3QrWvkEHk/TLiFSx4zqAW4v8pcx+HNf9m1rj5YCAPbbW5Sl8myVANHX/Sgjyc2YSyt9 OGP7oQTtTQKwKt2tn9W6JmYrGzhU6SlxQGmVWBQmIL2v1bK4V3H/b3yC+jzXUTCEg8SB 1m7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=UuyMBV4S+UaxSFH1B/cho/g214gGKv1ACXdBt0FH5Cw=; b=lTCfyy7o5S2ZkXDG/EhT5cXKQMDHq1CL/kwUVDgb80GM2kkau4cP7YGm6w05plx4v/ 3b8RFj2C1qgpVa+4ZOrPWhYLqDvci4xqilxyiYQcdcGTh9TK3P8r+y4zEoSeELKe0WQ/ 5pSvrOAGRndKZJt0OstGgKtDGLHrwPc/VQ9K7KuF5/KkuDsMgT7n2CtJ81gfnIXW6a5R 2KHoRZmejLaeo2Wb0ywwWM7W7P5MTmK3a4Gpns3QuFkQHRxGkyJVfzAEkwcxrXxR7snv mnjqDzl5iDDgVPOgjK2iplYtF57O6fF60V+/1e8Xk+YNcDOBBksuP5hds0WkLWKHaGBN jxEg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c20-v6si10561016pgg.367.2018.07.15.16.39.18; Sun, 15 Jul 2018 16:39:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727414AbeGPADV (ORCPT + 99 others); Sun, 15 Jul 2018 20:03:21 -0400 Received: from terminus.zytor.com ([198.137.202.136]:43371 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727001AbeGPADV (ORCPT ); Sun, 15 Jul 2018 20:03:21 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id w6FNcKQw922737 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sun, 15 Jul 2018 16:38:20 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w6FNcKi1922734; Sun, 15 Jul 2018 16:38:20 -0700 Date: Sun, 15 Jul 2018 16:38:20 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Arnd Bergmann Message-ID: Cc: hpa@zytor.com, linux-kernel@vger.kernel.org, tglx@linutronix.de, mingo@kernel.org, torvalds@linux-foundation.org, peterz@infradead.org, ard.biesheuvel@linaro.org, arnd@arndb.de Reply-To: hpa@zytor.com, linux-kernel@vger.kernel.org, tglx@linutronix.de, torvalds@linux-foundation.org, mingo@kernel.org, ard.biesheuvel@linaro.org, arnd@arndb.de, peterz@infradead.org In-Reply-To: <20180711094040.12506-5-ard.biesheuvel@linaro.org> References: <20180711094040.12506-5-ard.biesheuvel@linaro.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:efi/core] efi/cper: Avoid using get_seconds() Git-Commit-ID: 7bb497092a34a2bbb16bad5385a0487dee18a769 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, T_DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 7bb497092a34a2bbb16bad5385a0487dee18a769 Gitweb: https://git.kernel.org/tip/7bb497092a34a2bbb16bad5385a0487dee18a769 Author: Arnd Bergmann AuthorDate: Wed, 11 Jul 2018 11:40:36 +0200 Committer: Ingo Molnar CommitDate: Mon, 16 Jul 2018 00:43:12 +0200 efi/cper: Avoid using get_seconds() get_seconds() is deprecated because of the 32-bit time overflow in y2038/y2106 on 32-bit architectures. The way it is used in cper_next_record_id() causes an overflow in 2106 when unsigned UTC seconds overflow, even on 64-bit architectures. This starts using ktime_get_real_seconds() to give us more than 32 bits of timestamp on all architectures, and then changes the algorithm to use 39 bits for the timestamp after the y2038 wrap date, plus an always-1 bit at the top. This gives us another 127 epochs of 136 years, with strictly monotonically increasing sequence numbers across boots. This is almost certainly overkill, but seems better than just extending the deadline from 2038 to 2106. Signed-off-by: Arnd Bergmann Signed-off-by: Ard Biesheuvel Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: linux-efi@vger.kernel.org Link: http://lkml.kernel.org/r/20180711094040.12506-5-ard.biesheuvel@linaro.org Signed-off-by: Ingo Molnar --- drivers/firmware/efi/cper.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c index 3bf0dca378a6..b73fc4cab083 100644 --- a/drivers/firmware/efi/cper.c +++ b/drivers/firmware/efi/cper.c @@ -48,8 +48,21 @@ u64 cper_next_record_id(void) { static atomic64_t seq; - if (!atomic64_read(&seq)) - atomic64_set(&seq, ((u64)get_seconds()) << 32); + if (!atomic64_read(&seq)) { + time64_t time = ktime_get_real_seconds(); + + /* + * This code is unlikely to still be needed in year 2106, + * but just in case, let's use a few more bits for timestamps + * after y2038 to be sure they keep increasing monotonically + * for the next few hundred years... + */ + if (time < 0x80000000) + atomic64_set(&seq, (ktime_get_real_seconds()) << 32); + else + atomic64_set(&seq, 0x8000000000000000ull | + ktime_get_real_seconds() << 24); + } return atomic64_inc_return(&seq); }