Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp4267355ybf; Wed, 4 Mar 2020 00:18:30 -0800 (PST) X-Google-Smtp-Source: ADFU+vtwVEDbaFRXbSS8RWn2w76TnnO5aFaFbuzQZctpCBOsry20dPTcUs2idbUurCDT61tz6ntU X-Received: by 2002:aca:530c:: with SMTP id h12mr1024648oib.86.1583309909631; Wed, 04 Mar 2020 00:18:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583309909; cv=none; d=google.com; s=arc-20160816; b=Bg0FIQsp6JsGe0iG159aKrvUJTsuXF4IKChimm3tkxdg4+5WGfrY0DLWXFcZqSp+0c oFhIxP80SM/p2UmNmI+Y3KV5XY4APTNp9FcuPg/DkUb9OMC/d34MRaApHjpz0rQxHjQ2 T+wbB7Y28ATbMQ3WfOvqwacXwWuV/5N8g3Y+iwwsPYTYGaGyCWc3G5nfzpwhxlW8kfEg ua/FPdEdl1F7mzqM04tAvvo2HjRN4LCE6mI+45ZFy07MBjSBGuejq13rEPN+dFoHbH1g VfzR3pXKO04STqfDanf3rE35vmzJCZpI8EjnisBgPnkNQ1nO/Ksy/K8BVo58zhVtVF9b /upw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=Z1dkKXIqmwJxeCU6Ywfo8TLyld6LEBjLZLYx2E/mT80=; b=wpUj5XcG+ipiO4Byv9TsOcT+DQKd4JXU/WfVuAcps/38KetAq1jy7mS1DYqPl7UiFr lgOoOtLP8xDIOIUNAVtP4Dkx7MZIguJkbaZX9BQt0Dgzg+SS9/6ecSJWxqZcc7yvftug rl4dnmVumwzFhxM+8LzJ30BZ0SCvI1FrzdzaZgEiXJD9+G6Ot0Cgq0xOJEDy2RkcyuX3 zn9yjyuKQ8heYOvpEh/j93JfhieiUSkRW9yxeQ5sFRtCloAODC7DiJBbQC1UgwlVve/K cMCLx5hyfGd7xcaxkDlhXZBTJX5WIeLm/3/BPKcVr7TsPMFzTdYLfAQW7QIcOfQ6C4Lu ta/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=eW4zwJEd; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 88si871912otv.12.2020.03.04.00.18.17; Wed, 04 Mar 2020 00:18:29 -0800 (PST) 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=@kernel.org header.s=default header.b=eW4zwJEd; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728845AbgCDIR6 (ORCPT + 99 others); Wed, 4 Mar 2020 03:17:58 -0500 Received: from mail.kernel.org ([198.145.29.99]:52096 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725271AbgCDIR6 (ORCPT ); Wed, 4 Mar 2020 03:17:58 -0500 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5A36721D56 for ; Wed, 4 Mar 2020 08:17:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583309877; bh=VvP9M7K7X5tlAWb9QFz2KtHF0kHJfukxQs5jv7ivTU8=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=eW4zwJEdSJY5I0QoJh7Odniwh1Sg0fHbL4TFjN6HFW9JJjGksk7sGD5guX6KFkFnf LTQDCRccwxj2cXUqN3Ti00co9S1ukRyEB5Vhbp3HNYd8fRq0sFi6t9LR4wUePIjQCl X51cq/z0Xud+9r5EBzGIA/P9Oi4d2GtFSCuxqR7s= Received: by mail-wm1-f41.google.com with SMTP id a5so874678wmb.0 for ; Wed, 04 Mar 2020 00:17:57 -0800 (PST) X-Gm-Message-State: ANhLgQ3EWa03/hfCV74B+kmal0CpSKacyymAoWxaU0mNds3zZIxAN1yr uZTKvhycIR2x0WipfD0VYMZyEOLBCLFeLO2Zs8GwUw== X-Received: by 2002:a7b:cb93:: with SMTP id m19mr2449069wmi.133.1583309875696; Wed, 04 Mar 2020 00:17:55 -0800 (PST) MIME-Version: 1.0 References: <20200303205445.3965393-1-nivedita@alum.mit.edu> <20200303205445.3965393-2-nivedita@alum.mit.edu> In-Reply-To: <20200303205445.3965393-2-nivedita@alum.mit.edu> From: Ard Biesheuvel Date: Wed, 4 Mar 2020 09:17:44 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/4] x86/mm/pat: Handle no-GBPAGES case correctly in populate_pud To: Arvind Sankar Cc: Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , "the arch/x86 maintainers" , linux-efi , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 3 Mar 2020 at 21:54, Arvind Sankar wrote: > > Commit d367cef0a7f0 ("x86/mm/pat: Fix boot crash when 1GB pages are not > supported by the CPU") added checking for CPU support for 1G pages > before using them. > > However, when support is not present, nothing is done to map the > intermediate 1G regions and we go directly to the code that normally > maps the remainder after 1G mappings have been done. This code can only > handle mappings that fit inside a single PUD entry, but there is no > check, and it instead silently produces a corrupted mapping to the end > of the PUD entry, and no mapping beyond it, but still returns success. > > This bug is encountered on EFI machines in mixed mode (32-bit firmware > with 64-bit kernel), with RAM beyond 2G. The EFI support code > direct-maps all the RAM, so a memory range from below 1G to above 2G > triggers the bug and results in no mapping above 2G, and an incorrect > mapping in the 1G-2G range. If the kernel resides in the 1G-2G range, a > firmware call does not return correctly, and if it resides above 2G, we > end up passing addresses that are not mapped in the EFI pagetable. > > Fix this by mapping the 1G regions using 2M pages when 1G page support > is not available. > > Signed-off-by: Arvind Sankar I was trying to test these patches, and while they seem fine from a regression point of view, I can't seem to reproduce this issue and make it go away again by applying this patch. Do you have any detailed instructions how to reproduce this? > --- > arch/x86/mm/pat/set_memory.c | 18 ++++++++++++++---- > 1 file changed, 14 insertions(+), 4 deletions(-) > > diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c > index c4aedd00c1ba..d0b7b06253a5 100644 > --- a/arch/x86/mm/pat/set_memory.c > +++ b/arch/x86/mm/pat/set_memory.c > @@ -1370,12 +1370,22 @@ static int populate_pud(struct cpa_data *cpa, unsigned long start, p4d_t *p4d, > /* > * Map everything starting from the Gb boundary, possibly with 1G pages > */ > - while (boot_cpu_has(X86_FEATURE_GBPAGES) && end - start >= PUD_SIZE) { > - set_pud(pud, pud_mkhuge(pfn_pud(cpa->pfn, > - canon_pgprot(pud_pgprot)))); > + while (end - start >= PUD_SIZE) { > + if (boot_cpu_has(X86_FEATURE_GBPAGES)) { > + set_pud(pud, pud_mkhuge(pfn_pud(cpa->pfn, > + canon_pgprot(pud_pgprot)))); > + cpa->pfn += PUD_SIZE >> PAGE_SHIFT; > + } else { > + if (pud_none(*pud)) > + if (alloc_pmd_page(pud)) > + return -1; > + if (populate_pmd(cpa, start, start + PUD_SIZE, > + PUD_SIZE >> PAGE_SHIFT, > + pud, pgprot) < 0) > + return cur_pages; > + } > > start += PUD_SIZE; > - cpa->pfn += PUD_SIZE >> PAGE_SHIFT; > cur_pages += PUD_SIZE >> PAGE_SHIFT; > pud++; > } > -- > 2.24.1 >