From patchwork Tue May 8 16:28:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 10386489 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 C14D160353 for ; Tue, 8 May 2018 16:28:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B09F728E3F for ; Tue, 8 May 2018 16:28:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A547C28E6E; Tue, 8 May 2018 16:28:37 +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 4055228E3F for ; Tue, 8 May 2018 16:28:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2EBDB6B02AF; Tue, 8 May 2018 12:28:36 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2C2CA6B02B0; Tue, 8 May 2018 12:28:36 -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 1B44B6B02B1; Tue, 8 May 2018 12:28:36 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr0-f199.google.com (mail-wr0-f199.google.com [209.85.128.199]) by kanga.kvack.org (Postfix) with ESMTP id B51786B02AF for ; Tue, 8 May 2018 12:28:35 -0400 (EDT) Received: by mail-wr0-f199.google.com with SMTP id p1-v6so21733436wrm.7 for ; Tue, 08 May 2018 09:28:35 -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=XnklfenQzdkQsT7Izc5J7n6R7CxYJMUUGlir+jYOgos=; b=dOh4Ti62HKMJ8+RAIHuGrSh3Jy4yQsTzxEcezrxXD9MWx5kQbtRttR31r4v4mT9xrY vI8D/87deiea2Hr3tZypZsAlff7u570Zjda1cYcJI83ssAGKiGqkwgBpq7o1wzw1lkAo jivTQIENk9/DJD8Fr3VXW1RqQnxO+Zu4SH2CGi/59XncQCTdr+m02AzL1DF0FaGJmTUE Weg3uIVdxTpHXwZC85k6pjk+BRPciTAQFtb25BeWO3Z+laVe9Tt3DtcWt33Ktu46MJUM ng9ZkLT9/XhsDfpUXowgLoTayduOyGmqWKDf428ogWyTxEcpPFKYtuQzlZjhOzG8QZBE KPlg== X-Gm-Message-State: ALKqPwdGR1OHVmbItZZbXKQkvMABfFzF3+2dzgkxtfb5F0TuqtrXjrVz KTZ+5VbXzOwQWCkzFi0oNopc5OJrrPiaHu5trefATJMySQfaXNk1k2H7Zyppkox3PRGeDjttTpd 9hEccbFGEjk2ual8LQLyrpE+SJD2+k968pefFeg4JgCrBQ1hthqyJQb3jd5HkdST/rOv6KPPC+O HzYre/JzQrKqGE0zt6dOK7IGXVJ7UyV9EL4GTyWkQyJaPIs7PY8kjIf9tPHWJOttDTGZnVXIJzH mzSEMtBsY0mvnU/3dXdkTjyZBrxWvsbSA1Zn7y2UsIP7LLRvu1mK/4ClyeDaChDCg8O6gtbEOfW tO2utZcPPkE1CN4ucHHQWvkyh3WC0eoJX0sNjbZ0GIDENyIeEZI7i5RecXY2QmEkl/Hf4+dPPYJ b X-Received: by 2002:a1c:e58a:: with SMTP id c132-v6mr3756768wmh.23.1525796915266; Tue, 08 May 2018 09:28:35 -0700 (PDT) X-Received: by 2002:a1c:e58a:: with SMTP id c132-v6mr3756727wmh.23.1525796914119; Tue, 08 May 2018 09:28:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525796914; cv=none; d=google.com; s=arc-20160816; b=NftBodojp5ezASUgPhc8zCR4pgOkHFKKrY1uboBxmBzYhIBLIZ0IAOUjaXJAzMAbl+ CKIMJ6ZbDYVRYNLIymEnO5jJGpiZuA4LC0LH5hQbCvkOYpHTdtGD7lCD8o9pET2rQU83 2x9U153lEGkS5z1lnVcf9ADlLTFWtRVPmzDfv49SdIIwyzY2J81V7ZLVhrUSz3NsxRaC UuIhMD9LdgyHX+qQeMCBg9mEzEn1sJbvTkiCdpJtl70dqwcduYzplSSNcUnOegWG+MAT XXPBjgcWbzpdlvoqkvjagqD5Qy0f6qGadTOXtsKNPY4lkiuKMh26O6Hbj488bes1KZtu ZAEA== 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=XnklfenQzdkQsT7Izc5J7n6R7CxYJMUUGlir+jYOgos=; b=z2xt208cTTGxbFGylu++9Hm6TiYjYJ7PPko1w6oLYLPbfRj9aLLnOA89ANiq/FV1QK nMmBrAidS8YQ+SDR8A38BkDkkXfKk+yNvnTaKLMjkYlgkGyImzr85yCWGqPhXKGT2Ybz WRG1loPnhQKtrjxTLF6KjY6kgfH1V83igZfrPoiiF8uwOK3yElDsxglwwZgm9Pt5j9my 9YG148y2KQ8PXnEv55ND3h9cvYJlyOefCtplvSRvuFIrJEw9EZ6KroU3VQN6rHyTfe9R g19bh4NiUibqTtuS3hqwb/x9NMK/Km9Gpyfx0z51jZ7Be/pIQStNrhQMM7E+dm0Ci1Qi ClBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=VTP1aF8P; 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 x6-v6sor11641910wrl.36.2018.05.08.09.28.33 for (Google Transport Security); Tue, 08 May 2018 09:28:34 -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=VTP1aF8P; 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=XnklfenQzdkQsT7Izc5J7n6R7CxYJMUUGlir+jYOgos=; b=VTP1aF8PyZqHuOQYPO2NwjBdMrKdFXEGQWEwQAEITvNV7uhtdpkILZ8Qs7YgL6jM7F afqWTkolYjHkelofhliFmxf8ZEUdtu+eg+9bt/SjSTtgDD/Bo3lnXm8nEapyG/JaZL9T 0UB3kw69XJWDi5oWrCS6jM67/Cxct36Ri/N5f5PdGzq9Kc2oJ9bFrfSzWqm8n4c6b2G7 XKEzLleUtlwQZe1duGYMnLKE8lHc4yJPTgxu8XS1NDY+RqgiIT2lJ9283tHO9iqmqAhB Ai47h0OXISF3vhWIctNFL3vMtJsDq6lZ7Ce4K8L12dMLCEpqu3ukzc5VcU7KlwNr+Nzi mX0g== X-Google-Smtp-Source: AB8JxZone6v8n+C+AXE3D4QMJ1XwPzqSpSQ+4v81iieu0KQ8Ezxy5CVR/wI2bcNAnv2jjCTchAYR1A== X-Received: by 2002:adf:b3d7:: with SMTP id x23-v6mr26199271wrd.142.1525796913440; Tue, 08 May 2018 09:28:33 -0700 (PDT) Received: from glider0.muc.corp.google.com ([2a00:79e0:15:10:e0c7:92b9:c022:f69b]) by smtp.gmail.com with ESMTPSA id n71-v6sm10642780wmi.14.2018.05.08.09.28.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 May 2018 09:28:32 -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 v2] x86/boot/64/clang: Use fixup_pointer() to access '__supported_pte_mask' Date: Tue, 8 May 2018 18:28:29 +0200 Message-Id: <20180508162829.7729-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") Reviewed-by: Dave Hansen --- 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..9223792f6d0e 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 = (pteval_t *)fixup_pointer(&__supported_pte_mask, physaddr); + pmd_entry &= *mask_ptr; pmd_entry += sme_get_me_mask(); pmd_entry += physaddr;