Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp3834279ybf; Tue, 3 Mar 2020 13:49:51 -0800 (PST) X-Google-Smtp-Source: ADFU+vvFEuyrND/N4puPGlNJ2ewF6lmS6KaEQdtFiuB6iqgO+OtE9Jk8rrpcMl3kTYAus3azL7U6 X-Received: by 2002:a9d:5c0c:: with SMTP id o12mr4928411otk.145.1583272190893; Tue, 03 Mar 2020 13:49:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583272190; cv=none; d=google.com; s=arc-20160816; b=JHEJZmcusqqZYmdzTuehIdKdQ/Bhjd0F0x3icamJW8s6i+VkfVDJs4wkrPy6T/Zdzu ZISSYZ9N9Hyl3WO5XPM95vDAQ3eHJ2RfSXKl5Rls3zvKSIE88itvY6/wda9HR82rP+9v uCMpfXvrKQKX1L+KEdmAlLf8uoGO111yeNKfFJJkxqUpSpf/apzGwHWqrvQOzQIrHiVk DrxgN0U3rvrqmWP1Lbcm0p1krj0Ianwp3xPQcyQM8XBrF9aYHTjCCbq/LPAwVb6uxCwM vvIqtj5o4OrPYaezTw8MmU+iOhJa9CKxdxF/I4+WybfByxNQVuNMCBCL7Suk1mWm5jD6 q8jA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=yxnoNODxTRgUma85r+YaM42HDwfM3r/uZczD0dRTEq0=; b=ecc/9Mk51C6QS5Bj2jCWbeYE1DfbyC6SjAxaRKNKyjpUycjgLtu0KwWNjL7kgtKkKR mGyvrqQu7A7WE7movvx/zdu9IRDf3QLcw5wAPNaaEjRauZahtRB1LevUoVTtAiRQJQzS nPJk/aXSswog3wp2H00mY1rKAkRumIm7ucbYUMuV8OUBtcXVUiQsf89mrXZPdv9kTnYr 6pYuNdYTJ3tbF3rMaK9F7cALQQzc5C+bjIxO8PYZvUygc4djKg2fIrgKg+f1dHmyiGLK bSdUb+0F5L/T942LGslp9CgFFVX+E//Tn6CEltmS2BbgB86a3NB2w6X7HEhdN9U17vHf p7SA== ARC-Authentication-Results: i=1; mx.google.com; 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 v5si6203498ota.39.2020.03.03.13.49.39; Tue, 03 Mar 2020 13:49:50 -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; 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 S1732067AbgCCUys (ORCPT + 99 others); Tue, 3 Mar 2020 15:54:48 -0500 Received: from mail-qt1-f195.google.com ([209.85.160.195]:35049 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730949AbgCCUys (ORCPT ); Tue, 3 Mar 2020 15:54:48 -0500 Received: by mail-qt1-f195.google.com with SMTP id v15so1171258qto.2; Tue, 03 Mar 2020 12:54:47 -0800 (PST) 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:mime-version:content-transfer-encoding; bh=yxnoNODxTRgUma85r+YaM42HDwfM3r/uZczD0dRTEq0=; b=SXTmef6bob839lACsbHpa2qoAszBbau66MLxqShVRNIgb5KxAiJSAsxfyFQBH3Bb5L g+4YeL0WIXBbiUjOtFq32DWk/QYHBw/ZbLxjec+T1FweVQiw4T5pDBaozy7NAoK0xQxt 5uOPHr2lWIPh6EiiqB9NxtSq57jvnB5H/nVBU94S7ZxeCT9AIDYblZRRDHKtzV9dOROQ 8YQjCwnBWtf/MfkZNKWQt2ve6Ff8VrbMpANbb2jldnhyaFA8/q1v7tuF+hV+bYqgf6/E 2zs05Iw8WMIAKTRT163xVW497ZfnwAV3NXFypbLf06F3bbv/sKqtBEgqsSeGZJCbpjCx nCdw== X-Gm-Message-State: ANhLgQ3OQOkGKA0lKGbLaEP2XKHZDRJBJVEEWHvlr4F/u9qci70Ag3Zl Wl4MGt4dr2y7VBZ5LOTPA1Y= X-Received: by 2002:ac8:73c8:: with SMTP id v8mr5986511qtp.270.1583268887098; Tue, 03 Mar 2020 12:54:47 -0800 (PST) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id v12sm11473041qti.84.2020.03.03.12.54.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2020 12:54:46 -0800 (PST) From: Arvind Sankar To: Dave Hansen , Andy Lutomirski , Peter Zijlstra Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , x86@kernel.org, Ard Biesheuvel , linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/4] x86/mm/pat: Handle no-GBPAGES case correctly in populate_pud Date: Tue, 3 Mar 2020 15:54:42 -0500 Message-Id: <20200303205445.3965393-2-nivedita@alum.mit.edu> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200303205445.3965393-1-nivedita@alum.mit.edu> References: <20200303205445.3965393-1-nivedita@alum.mit.edu> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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