From patchwork Mon Jun 18 14:17:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 138959 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp4010679lji; Mon, 18 Jun 2018 07:18:42 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKSOzww5yh2cnhNPqf5XA2x9dve++EjXEQHC493wC0TGl/bMAB9rRmNWIXbMa1KYNi+ZvuA X-Received: by 2002:a17:902:6f0f:: with SMTP id w15-v6mr13998876plk.216.1529331522128; Mon, 18 Jun 2018 07:18:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529331522; cv=none; d=google.com; s=arc-20160816; b=ejiFu5ECXdoFlSmxoksfY3MBD31ppLH6V0DbIWzlooe9ytZ2ULfasF1IoXWjWHcO+Q ykoTqBlWdHuMQa2CLierNTry0gSVNrQEswuUo265GB7V/IhzMTQZ4xTTKbVChlew9p/l oM1rCE+eAjEtnEvWeIlmIzvvd6WXo9VwT4d1NGCcs6Sl46bC3eN3AYlZQshOgrkeLmcy sD05MRkEzvtXNpFX2q5wGlMUmciIX7GGwkm6OetHvoKE9r7RPV6TXl7RiStgxrdOGyss S0X598RYcvx5VxaiInbUyuodZVoBaMG1Lbzlzf6LoLvBwDvKa24atz7s9N+zOVcuAqLn zKNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=J8u9mXmbTVMS5/MEJl6DoM9yum5yNC9jtxvcCz4dbL8=; b=UBUhEeM/bZHkAiJA6x25uMVHO7ABgDkElx2QN2tgESkwxKZMjmeHXjwpfrTdCPLqi0 W76ARl5kfRl/3c1J+gi0ABQJbbdEGS2TcbG5zuiVxmUvO1EHhZVq3TtD1rzyBFYNO6sh DbpbC4J8JwSRbtzkROkASrUDuxRCtSJhpzLjCyhCu2spCmXfx7xCEK2KawMUHzZuI9yA KkqorN9dItU41YSUumY9k9TrZg/Pc8rJTdwAH0OIrlGu1lgvDARnQ5E8hSx4cuLIalXz X2pMUnSUUbuppbQbtJHqo8CdsorXBnDTppaVUv0Qf6AQVPYxmF3ZyXUbjlDAh8bDhnVa MQxw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-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 q1-v6si12393044pgs.441.2018.06.18.07.18.41; Mon, 18 Jun 2018 07:18:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-efi-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-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934685AbeFROSl (ORCPT + 2 others); Mon, 18 Jun 2018 10:18:41 -0400 Received: from mout.kundenserver.de ([212.227.126.134]:33971 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934470AbeFROSk (ORCPT ); Mon, 18 Jun 2018 10:18:40 -0400 Received: from wuerfel.lan ([95.208.111.237]) by mrelayeu.kundenserver.de (mreue006 [212.227.15.129]) with ESMTPA (Nemesis) id 0Ma987-1fmqRT04Pn-00Ln1s; Mon, 18 Jun 2018 16:18:16 +0200 From: Arnd Bergmann To: Ard Biesheuvel Cc: y2038@lists.linaro.org, Arnd Bergmann , Tyler Baicar , Will Deacon , Ingo Molnar , Borislav Petkov , Yazen Ghannam , Andy Shevchenko , gengdongjiu , linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] efi: cper: avoid using get_seconds() Date: Mon, 18 Jun 2018 16:17:59 +0200 Message-Id: <20180618141811.3353245-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K1:x/kopYaU6xZQ1BGqruRHbgEPeilTEVHQKqoSVv1+vPMkwxMVmyq PXDKqgAEgydWN0DgXlb6vroY3+DZbS5pNs+Q8GTObGeGNJloIV7tkd5Zrktm6LfsBa3PPrk tYhXISgXROZh0Okl5UDhLAfD5Dt+4BfBBL/rphWmIoA02RwojQDDIozeBLUpqj3TKCaBjBA 5PqtYwg5NDwD3EAfpwfwg== X-UI-Out-Filterresults: notjunk:1; V01:K0:GmecSOGqaZs=:+AgQaKmuclsQIYcTsnUi1i FR+jxMZoTZAP23cfq6XhFEunhJveLxmKc2Nvf2wKVTiyCKk2HWmxDoFl0+QyQ4vAcxp0FuLnl j27yb/I0fsg+sd/DoLvqqtyiU2r1hB+I5+UZgOCb7stOvneRjyxHTognXm27KF+vrz34Lc4QC NpTJymM8VfPLGu6VWKP5DeJsfU7s6o0ky8KltcIx/vVBi922meWlLBeihYcjjqrv/mljYmM3L Pvc53J/DfqlB3foLBQ/S8u+QPPW/z33bEHdSClhb1yZ7YiPH3rM5EYqMb18EX0T74Eroqjxif Ofs5yYc7w1LG3nlmgVHsJMD3N0pF2D1ZEnac9Hu9NRibvnWRRfssuzV3+wYHY/6EDR4WdKjBG 8wOtv07aeqa4WNVBjcY95Eu5hlBhNsjQJqGLpllTy7tEcOTANI1L7sVyz3VKa/R874HeRYljG 7DKlFYiGqKwcEFy/2iJB1D70uueEyXCselFWJ1AkHyj93eqOs+Zq4weAj7EB0hoddGZQw1fIj rI4fciQYekMywF3/6E4FL7TiWErTytAqQgSw72EA9Nqat57qtVaAvjJ5sAbLYWGNmBceOhSBp CgJ/qtKTGmKuQgcx5wivTFEx8RDQQn0lSlzuCBjo+Le5FqvJkkTfh/2G1uYZXtu1Xmxpk5ICF kphRIWfPWDrdEkmljtDNpdQJngAxqG67nATE1GM27uL8aK0KB95FAHPqUHho/HqmeF6k= Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org 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 --- drivers/firmware/efi/cper.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) -- 2.9.0 -- To unsubscribe from this list: send the line "unsubscribe linux-efi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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); }