Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp302033imm; Wed, 11 Jul 2018 02:43:47 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcbtnDNmLV0el8lOS/ZWwt+LBx6E4uuKoRIDWZrmRck41sPw4FN1QcbH3yDW6D6z8pON1sh X-Received: by 2002:a62:6a01:: with SMTP id f1-v6mr29376675pfc.156.1531302226977; Wed, 11 Jul 2018 02:43:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531302226; cv=none; d=google.com; s=arc-20160816; b=FXrj30W2+zCLw1Gtk/m5Z7E1lpXlzK2wFAhDNrsi3VhAk7ue1NhDooERKVPxg2koNn XiRGEYtF8QG6ihEHUC0za8BKKyQOTndMnp4+buufuP2Y+tvteSjXUiSsG3aV5D9bcPhN iN2olereQrkV1GlbHGQrzjyZCLU4eBMA6IsEJpXvFixjZNvsOG4ngA05XCP54iXP3FkV WuO5jKpf3mPRwcBzEoNAaeMP7xiY8//01v8C/MzBX42AGelMyHi2fhXRzfsHSTqp7AKh wBkpIlJ2BSsNznMB5SrjXismaaDwPyEiQ0C31Zs/a5HwRqLwOSowDc4VKDnUl2uYiEKv X1qA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=sA0x4vnqsHOfjf2tc9OZ1sVTXlxbVufq2Bf9Pecho2U=; b=fcxxUpmE97gOaF5b47qNGrolsKlP9epyYhhJJkNYs4HA/EtOB0lcRCwAtIyKH/42AJ oqz0i6l/hsP6/9GxZzUVlKyAT3jZNEW/BfWDyABrV1uUPEA+P0/tCk6E6l1NsQtaX5FK C0kgalmm1tu1pNFVy2GRTX5dSCzI1hS/nsIbbinkuyFEziBKHXfHXK/zwdfccwwPW0+Q 3ygp9NtBLJOHRD9oMga4AgD624hR8vhRS7WBKB/netryD43IQ4qLRkDDq6NzghqLWK9i 3AiVXeeoYkzLl7Ld3Elg7vTbY1D2/rJhcKEP7TdF980GfjJJc1lNp+h4cP4BF9RTEFaL ym1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GnRSApHQ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t85-v6si20155312pfj.231.2018.07.11.02.43.31; Wed, 11 Jul 2018 02:43:46 -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; dkim=pass header.i=@linaro.org header.s=google header.b=GnRSApHQ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732662AbeGKJoX (ORCPT + 99 others); Wed, 11 Jul 2018 05:44:23 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:40032 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726490AbeGKJoW (ORCPT ); Wed, 11 Jul 2018 05:44:22 -0400 Received: by mail-wr1-f68.google.com with SMTP id t6-v6so17452709wrn.7 for ; Wed, 11 Jul 2018 02:40:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sA0x4vnqsHOfjf2tc9OZ1sVTXlxbVufq2Bf9Pecho2U=; b=GnRSApHQiDH25jpATv9Hy+YfcdUmFoLZmSkR5RQxzvJvMbWjA3RmDby27bcyBy1RUz Oof0Qm/nHboGrcB+Ntm1+mzwKeIshCj+rPnL9jEvINjnPA+sH0QEo1S6uiAkA9XFMFBZ 6nsv0PbzDLsyqQlxlXhS4hl4MgNW/7ekODA5o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=sA0x4vnqsHOfjf2tc9OZ1sVTXlxbVufq2Bf9Pecho2U=; b=ftiLps/lxaR6ImrAPPFCsJGGTTWW5CLd+99sXPOHqLJItRZDDxF3IVPFWoP4tybcT+ MQ8DzEJOSFVKMUs9WHzKZsJNF413gEwO9vEHUjO0sRkUcIbE5SABgJipqiHfmdLXvr81 ky+K1tLbkSbGBPFPPxO/wKKrkpFscvV5vMduE/1dOuGmuXz3Fga9MmZQRpdtS5LSTsp1 aldlb01EfzYzpSoZB1OHq3IZT2AWHMKF3pa04ywGMYas6Wr1RR5/ZAvu5qRbjlMx4Sqh Dw9cJECJnFBJ2F5A1uc/m01XrVe06XZnYbGxTb4zfCoTc4LjL2PkKJmkN9E2QMDVVnF6 zS6Q== X-Gm-Message-State: APt69E2ZKPo/1oBGeLdkqcwiVmKv9NBhbdn9n2Mq1aaXBqiSua1vy7w/ pCX9oE+xgKKK0lHoJtJQUvIbWw== X-Received: by 2002:adf:b3d4:: with SMTP id x20-v6mr21143810wrd.272.1531302054562; Wed, 11 Jul 2018 02:40:54 -0700 (PDT) Received: from localhost.localdomain (33.153.69.91.rev.sfr.net. [91.69.153.33]) by smtp.gmail.com with ESMTPSA id t124-v6sm1641311wmt.29.2018.07.11.02.40.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jul 2018 02:40:53 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Arnd Bergmann , Ard Biesheuvel , linux-kernel@vger.kernel.org Subject: [PATCH 4/8] efi: cper: avoid using get_seconds() Date: Wed, 11 Jul 2018 11:40:36 +0200 Message-Id: <20180711094040.12506-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180711094040.12506-1-ard.biesheuvel@linaro.org> References: <20180711094040.12506-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Arnd Bergmann 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 --- 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); } -- 2.17.1