From patchwork Wed May 9 09:18:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 10388845 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9B6F460153 for ; Wed, 9 May 2018 09:18:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C82D28E16 for ; Wed, 9 May 2018 09:18:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 80D7228E54; Wed, 9 May 2018 09:18:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1AAEB28E16 for ; Wed, 9 May 2018 09:18:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B90096B04C9; Wed, 9 May 2018 05:18:30 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B41D96B04CB; Wed, 9 May 2018 05:18:30 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A30E86B04CC; Wed, 9 May 2018 05:18:30 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wm0-f70.google.com (mail-wm0-f70.google.com [74.125.82.70]) by kanga.kvack.org (Postfix) with ESMTP id 47FFD6B04C9 for ; Wed, 9 May 2018 05:18:30 -0400 (EDT) Received: by mail-wm0-f70.google.com with SMTP id e1-v6so3998584wma.3 for ; Wed, 09 May 2018 02:18:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id; bh=RDGLv/6a+qd4+/YoGyxtqQMbIPF4+JXYyARaHA1sXvc=; b=nWYNS59kX5eo2q7GiGrZcSRTHZHydqEz2laEsK+VeEJUTHX/Kuw/JgwJWin/OCMny/ nI/igYAFehQFt547OQ05zQ2LzxZZvNZYEcOFijsgsEXqI+Ytkdyc6Jzd4nw2UgdBmiRL DOkTKqKHVYr5XDTkDmED83KNtnUg9isdgZBEkCduLeZpVJmzKnbuVEKvjcMpUymt5wbI EL4mjbPbwV7Hdqe72rxcAj/LQtqMTgb8I8J+5md0uXLq8SCFFLg482MGdEBynjDK4tAt TRd2/Valf5stOg3NpYuNaPx30tFGaHqxU9DbH1khJKqiClRBzIETj32LsD84Cgqt2t2l /+TA== X-Gm-Message-State: ALQs6tDnKJNNDhXAETxwMbRgEv0ek8zZhf8t9BbO7eeP7bECORJ5UTu1 yQWQqiE7G4xJoA9YTf0LIPPNe7AmiytZKHW+RoLuMQkIszl2bZrrF69nTfS24X6+bk/v8UuEdTa hO/MCgOEi4j0eshUH5Tdrj5xG9QBdYNVbs6l+SHzW6Ox/7UXZkWemW4C2zvns2MLjaC4uhEVvmS OIkW12/Ln3CUV2KTx8suWHeMrjckd2jYltcrttSsJDs2W9xoNHuPhQZVemc0MTCiqkNILxEI+wE +vKygTZA1kfHXw6CsU8wvq2OnZ075OeQ8YRQrRbgQyuOmxP6vvC0zf2SUibnz/4PjMNVwfMGdgQ CHkEfh3fQ/WwSEJCszqdwdbf+GUDh5r+yijBOZgI3wQIe9ISSDW42dTfc9Fj8rr6IS/2xoI5+pG D X-Received: by 2002:adf:86fa:: with SMTP id 55-v6mr39787542wry.232.1525857509836; Wed, 09 May 2018 02:18:29 -0700 (PDT) X-Received: by 2002:adf:86fa:: with SMTP id 55-v6mr39787500wry.232.1525857509094; Wed, 09 May 2018 02:18:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525857509; cv=none; d=google.com; s=arc-20160816; b=jbL6SfXTjfl5QBZbM7Md5qrpGfbTEndee5bBbjYGsQYMcmAkCIY79BIkUO+D7+1pY2 OVB5WLSRPMM18HBeICSEaxMTtfY0FixLjfygEJ6YSxuXU429pixM+DjXkDMh5tFo1sdy hULLyyU9Vv6VbJ7t4ENtJ/xTKQoaAAsfBV47RfegrdTEq+q9bwaHpKYjnU+MS70OQBfF SDpmxNlkq/2u5aGkKAFj4sjlBXRRpAEKuh0uDWoATw4Uodfkwx/a9ryCjU0X+Qm3lMya w1k9R/BHqDiJyzmHHfOEvzDJENa74h7XPzzCuAd9ydwAhu9L8iLyCsH2isb+iEFYonpt vdcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=RDGLv/6a+qd4+/YoGyxtqQMbIPF4+JXYyARaHA1sXvc=; b=KD6g+VxJ/HRUZHc5kFrpJhcxSkdYO3oR74OBd8jvrxXnc0Z8iKjxd2Ea/Qdp2gncCs Zuki2eUo6XIqvpgpaccKPFY4IuNJt1YRMyRZ/CxuEM1AqK+WJwnmWH6QuV1x/cFcXyCd e1P47GPZ0M5ogSqEfHUUj+Zo9Cdjevl/ZmnuPvHnqbRuGE1dGRyj6T9ShVhjWMA1HmJB L0WHuALg4EZ+U48gzZ/so5qiDI3XnKAFoVxkpIm1VebwQIxkgK7r/Zj3MJXK92UGLeX3 O5ynR/UniVIeUEbp1LAek2D4NPEndUVLjcJCs/Hp4hcuGbwSNb2uoyOWMwCxHMjudqL/ gN7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=s0apAPXs; spf=pass (google.com: domain of glider@google.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=glider@google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id 70sor2787358wmf.63.2018.05.09.02.18.28 for (Google Transport Security); Wed, 09 May 2018 02:18:29 -0700 (PDT) Received-SPF: pass (google.com: domain of glider@google.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=s0apAPXs; spf=pass (google.com: domain of glider@google.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=glider@google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=RDGLv/6a+qd4+/YoGyxtqQMbIPF4+JXYyARaHA1sXvc=; b=s0apAPXsAZQDK1GDFTBh/aYLw3DqI6BTxU84Jlmw4PT3cqnvUC0cEAHOevcpMf525t m6FEFv+Ozwfd/TWUJXugB7kWXDD4Ux1r1EgbKby4yAU7q4qwIs3coM5sy/59wePQzZn+ btqYBdA/wLD4ir7MEv/IZYRt6fpBktr4QtvV+lJzvV+//zsqb/pOWefK/ZOnvhTEn/qv Q4lT3v2Oh5Rf67nt1H87QNxg3vxFw650S4v6YUerSdBjXlmEwgRZxSoDj8eqyyzpCAvQ vP1u2h8MfNuO5vRhvbgBTZY+UK/0sJvFY9HeQ+J5uib5mhehB5HA8nzYmMN38VTq808j 182w== X-Google-Smtp-Source: AB8JxZpBI2FXa1DnYYxvFUPLBY3AIOXR50czh4u2hyNxdXmUn1jcJ9XbeACHkiB3xL2901nwqUMlOQ== X-Received: by 10.28.74.13 with SMTP id x13mr5001977wma.150.1525857508252; Wed, 09 May 2018 02:18:28 -0700 (PDT) Received: from glider0.muc.corp.google.com ([2a00:79e0:15:10:e0c7:92b9:c022:f69b]) by smtp.gmail.com with ESMTPSA id t46-v6sm35350140wrc.95.2018.05.09.02.18.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 May 2018 02:18:27 -0700 (PDT) From: Alexander Potapenko To: dave.hansen@linux.intel.com, mingo@kernel.org, kirill.shutemov@linux.intel.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, mka@chromium.org, dvyukov@google.com, md@google.com Subject: [PATCH v3] x86/boot/64/clang: Use fixup_pointer() to access '__supported_pte_mask' Date: Wed, 9 May 2018 11:18:22 +0200 Message-Id: <20180509091822.191810-1-glider@google.com> X-Mailer: git-send-email 2.17.0.441.gb46fe60e1d-goog X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Clang builds with defconfig started crashing after commit fb43d6cb91ef ("x86/mm: Do not auto-massage page protections") This was caused by introducing a new global access in __startup_64(). Code in __startup_64() can be relocated during execution, but the compiler doesn't have to generate PC-relative relocations when accessing globals from that function. Clang actually does not generate them, which leads to boot-time crashes. To work around this problem, every global pointer must be adjusted using fixup_pointer(). Signed-off-by: Alexander Potapenko Fixes: fb43d6cb91ef ("x86/mm: Do not auto-massage page protections") Acked-by: Kirill A. Shutemov --- v3: removed unnecessary cast v2: better patch description, added a comment to __startup_64() --- arch/x86/kernel/head64.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c index 0c408f8c4ed4..5ea28e9a0250 100644 --- a/arch/x86/kernel/head64.c +++ b/arch/x86/kernel/head64.c @@ -104,6 +104,13 @@ static bool __head check_la57_support(unsigned long physaddr) } #endif + +/* Code in __startup_64() can be relocated during execution, but the compiler + * doesn't have to generate PC-relative relocations when accessing globals from + * that function. Clang actually does not generate them, which leads to + * boot-time crashes. To work around this problem, every global pointer must + * be adjusted using fixup_pointer(). + */ unsigned long __head __startup_64(unsigned long physaddr, struct boot_params *bp) { @@ -113,6 +120,7 @@ unsigned long __head __startup_64(unsigned long physaddr, p4dval_t *p4d; pudval_t *pud; pmdval_t *pmd, pmd_entry; + pteval_t *mask_ptr; bool la57; int i; unsigned int *next_pgt_ptr; @@ -196,7 +204,8 @@ unsigned long __head __startup_64(unsigned long physaddr, pmd_entry = __PAGE_KERNEL_LARGE_EXEC & ~_PAGE_GLOBAL; /* Filter out unsupported __PAGE_KERNEL_* bits: */ - pmd_entry &= __supported_pte_mask; + mask_ptr = fixup_pointer(&__supported_pte_mask, physaddr); + pmd_entry &= *mask_ptr; pmd_entry += sme_get_me_mask(); pmd_entry += physaddr;