Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp4639005ybf; Wed, 4 Mar 2020 07:49:32 -0800 (PST) X-Google-Smtp-Source: ADFU+vu2E62lLsv6ykptkZ606Y2nth2bQpQIdO0twjoL5ciHBJS0PgjZfYyo8UazcUR6BZ6p4to6 X-Received: by 2002:a05:6830:22d8:: with SMTP id q24mr3010312otc.0.1583336972553; Wed, 04 Mar 2020 07:49:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583336972; cv=none; d=google.com; s=arc-20160816; b=OwP+ScCbKRiIcK9SzRgfb2CjFJUkIRVItqhlM9RQ3SFFXoym+W3cH8cpabMx/hS5dx nb5MNljiIdGY0wHBtv6zvXPHgxrXcw2ihYbygP1msC6ZNuuWypzBOLx9p5xoCV5rkb// 2M0cvXdH5ajlABHBKj1AJEQV3Uxri2Ws+hzWwuLS+pQSzYqVLVtNtCDuhsI18AL8jIvt MB4y6SdMRnuiPC59GZ3m04goaibg5UZeGVN4/cFJ2+SNOSDkmfCCE/S9DUoMFVUh15Pf VTcT99JjxX0/2/LLPnaGNwzTB4BxqLkvHsmK8D1gKDJX5Y1KD4GFig6DB0dqS3Z7UF7E 5ubA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:date:from:dkim-signature; bh=TsTKXhrbnw/QAlugyUyOjWQ0P4Lr6lXfLnd3ahgcNlQ=; b=rZPhv/BXbJX+VolwdlLrus/uWCT431E4ZPnN/cHcgNp+c8eT6hmmXfLtrx1NujMUNP xpyW76/flpiZF6hEBFwWqzHrg8d561Woxezn17gcgryV5z/+AE/rdpLtFkftkf1vnqZj J77op4NVlIMIMGgSy/6EwezCgnx4tGdglwvmQfKOLf/OVPjedblUhk+xz5kgom9aNuqw 50SPmvSuQ8yTM1xlVjTkX03goq+KBH4NjnjKP/bwUQQl9aW8cOfxaWvDqRD/13eEowOa UVDz5YwzvZFiYOU5cQKoQz9MRG7unGMZbFTp6FqorlmRAXZgInjyM9GUk3QnTj8hShJF b4wQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b="LmHHN+/y"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d7si1475821ote.131.2020.03.04.07.49.21; Wed, 04 Mar 2020 07:49:32 -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=fail header.i=@gmail.com header.s=20161025 header.b="LmHHN+/y"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388040AbgCDPtN (ORCPT + 99 others); Wed, 4 Mar 2020 10:49:13 -0500 Received: from mail-qk1-f195.google.com ([209.85.222.195]:43845 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729573AbgCDPtN (ORCPT ); Wed, 4 Mar 2020 10:49:13 -0500 Received: by mail-qk1-f195.google.com with SMTP id q18so2037757qki.10; Wed, 04 Mar 2020 07:49:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=TsTKXhrbnw/QAlugyUyOjWQ0P4Lr6lXfLnd3ahgcNlQ=; b=LmHHN+/yzZIXHZsAT4mPjlLhLhDwRzyHrf4mOtnXBsZHhyIBerM7ivcQPYfmN0zu6M MCpqRZ0853FsImWkM8jJqsAAWmYEoyzkUielgjLay4Whb47ZdwgVV/VzoHfmSlnXlNo3 vt8KFlhUaOdOYWZq9BPIH3Ak+dzsUQs5cqzn/6cHlOj5RkPT6A0EvUvIKG8+IupQa8wa nHuSVnBnQyFqzFVhr3EUmcXmVdW5VdLx7na6S8dSRUpiMSgUI8B6So0y5dusrau4YXIf gRfJVVqcF0GcwaB+H3QjzSY6fzYJBksg2CAJjjpSFPH+WXaLKAWGoZEqYV4AbysBmG7S KxZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:date:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=TsTKXhrbnw/QAlugyUyOjWQ0P4Lr6lXfLnd3ahgcNlQ=; b=YWOxTE5rd/xZDD6NTHh03SqWsgHNrw6YPwj2IQ31lmwkfeu5C5DgvByztKZV3dsGMe 2Lt9X1kdEHvRxeKUDAGdibwlWx7c354R3b4XA9PQ3PC79MQIZ/xhdtu6evpbyxrLgyAi G/xKn7u6geSiD7TMrmPRUJQX4kBi5aCcmZWChl684XsdZiP9M+pnS8OH6qK35xNd7uGI C5N/99aft2O9dMZ+Vr0zg+sp7gPdclJdpSqvrdJ90zWosITnLyOj+pWP6zVd1fya1810 y0i8JNn3m0IoEOd11F3P3IJ3o+NMXDpEw5WQCiAsdhBhTOOKZvHu1DXyOoxk5Wl94eyH flUA== X-Gm-Message-State: ANhLgQ0b28NxaGJ5aZUWcXgR8qjTg9oSWMwmnboJT4Whh25BG4PNYbfH tf5HB/0eae34vv4CtW2kWRXGMOvly7g= X-Received: by 2002:a05:620a:21c9:: with SMTP id h9mr3527412qka.29.1583336951756; Wed, 04 Mar 2020 07:49:11 -0800 (PST) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id 89sm14195261qth.3.2020.03.04.07.49.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Mar 2020 07:49:11 -0800 (PST) From: Arvind Sankar X-Google-Original-From: Arvind Sankar Date: Wed, 4 Mar 2020 10:49:09 -0500 To: Ard Biesheuvel Cc: Arvind Sankar , 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 Subject: Re: [PATCH 1/4] x86/mm/pat: Handle no-GBPAGES case correctly in populate_pud Message-ID: <20200304154908.GB998825@rani.riverdale.lan> References: <20200303205445.3965393-1-nivedita@alum.mit.edu> <20200303205445.3965393-2-nivedita@alum.mit.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 04, 2020 at 09:17:44AM +0100, Ard Biesheuvel wrote: > 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? > The steps I'm following are - build x86_64 defconfig + enable EFI_PGT_DUMP (to show the incorrect pagetable) - run (QEMU is 4.2.0) $ qemu-system-x86_64 -cpu Haswell -pflash qemu/OVMF_32.fd -m 3072 -nographic \ -kernel kernel64/arch/x86/boot/bzImage -append "earlyprintk=ttyS0,keep efi=debug nokaslr" The EFI memory map I get is (abbreviated to regions of interest): ... [ 0.253991] efi: mem10: [Conventional Memory| | | | | | | | | |WB|WT|WC|UC] range=[0x00000000053e7000-0x000000003fffbfff] (940MB) [ 0.254424] efi: mem11: [Loader Data | | | | | | | | | |WB|WT|WC|UC] range=[0x000000003fffc000-0x000000003fffffff] (0MB) [ 0.254991] efi: mem12: [Conventional Memory| | | | | | | | | |WB|WT|WC|UC] range=[0x0000000040000000-0x00000000bbf77fff] (1983MB) ... The pagetable this produces is (abbreviated again): ... [ 0.272980] 0x0000000003400000-0x0000000004800000 20M ro PSE x pmd [ 0.273327] 0x0000000004800000-0x0000000005200000 10M RW PSE NX pmd [ 0.273987] 0x0000000005200000-0x0000000005400000 2M RW NX pte [ 0.274343] 0x0000000005400000-0x000000003fe00000 938M RW PSE NX pmd [ 0.274725] 0x000000003fe00000-0x0000000040000000 2M RW NX pte [ 0.275066] 0x0000000040000000-0x0000000080000000 1G RW PSE NX pmd [ 0.275437] 0x0000000080000000-0x00000000bbe00000 958M pmd ... Note how 0x80000000-0xbbe00000 range is unmapped in the resulting pagetable. The dump doesn't show physical addresses, but the 0x40000000-0x80000000 range is incorrectly mapped as well, as the loop in populate_pmd would just go over that virtual address range twice. while (end - start >= PMD_SIZE) { ... pmd = pmd_offset(pud, start); set_pmd(pmd, pmd_mkhuge(pfn_pmd(cpa->pfn, canon_pgprot(pmd_pgprot)))); start += PMD_SIZE; cpa->pfn += PMD_SIZE >> PAGE_SHIFT; cur_pages += PMD_SIZE >> PAGE_SHIFT; }