From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D1F7C47255 for ; Mon, 11 May 2020 19:17:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0E747206E6 for ; Mon, 11 May 2020 19:17:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0E747206E6 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 6929990007C; Mon, 11 May 2020 15:17:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 61C48900036; Mon, 11 May 2020 15:17:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4E3E790007C; Mon, 11 May 2020 15:17:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 31B26900036 for ; Mon, 11 May 2020 15:17:41 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id DE15A40D0 for ; Mon, 11 May 2020 19:17:40 +0000 (UTC) X-FDA: 76805397480.24.bear76_6016614ea3110 X-HE-Tag: bear76_6016614ea3110 X-Filterd-Recvd-Size: 3798 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by imf30.hostedemail.com (Postfix) with ESMTP for ; Mon, 11 May 2020 19:17:40 +0000 (UTC) IronPort-SDR: 3ZlzTMDyrzJZut9vPusdIPQvUdGy4Vj70gCqBz/iEurfVhJvz6PlOiSlzNIqAW6uUQVBh+cOqe /eLz4IB64iqQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2020 12:17:38 -0700 IronPort-SDR: 7rI5Y2URj4Z3ZVTn5xNuUPdfFIBRovGG6XDdw2LDRlLTSmih0uTEq4GyrUiFsSnLjPbUTZVGdP mJBavOIgkTEg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,381,1583222400"; d="scan'208";a="261865903" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga003.jf.intel.com with ESMTP; 11 May 2020 12:17:34 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id CE171170; Mon, 11 May 2020 22:17:33 +0300 (EEST) From: "Kirill A. Shutemov" To: Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" Cc: Dan Williams , Tony Luck , x86@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" , Dave Hansen , stable@vger.kernel.org Subject: [PATCH] x86/mm: Fix boot with some memory above MAXMEM Date: Mon, 11 May 2020 22:17:21 +0300 Message-Id: <20200511191721.1416-1-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: A 5-level paging capable machine can have memory above 46-bit in the physical address space. This memory is only addressable in the 5-level paging mode: we don't have enough virtual address space to create direct mapping for such memory in the 4-level paging mode. Currently, we fail boot completely: NULL pointer dereference in subsection_map_init(). Skip creating a memblock for such memory instead and notify user that some memory is not addressable. Signed-off-by: Kirill A. Shutemov Reviewed-by: Dave Hansen Cc: stable@vger.kernel.org # v4.14 --- Tested with a hacked QEMU: https://gist.github.com/kiryl/d45eb54110944ff9= 5e544972d8bdac1d --- arch/x86/kernel/e820.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c index c5399e80c59c..d320d37d0f95 100644 --- a/arch/x86/kernel/e820.c +++ b/arch/x86/kernel/e820.c @@ -1280,8 +1280,8 @@ void __init e820__memory_setup(void) =20 void __init e820__memblock_setup(void) { + u64 size, end, not_addressable =3D 0; int i; - u64 end; =20 /* * The bootstrap memblock region count maximum is 128 entries @@ -1307,7 +1307,22 @@ void __init e820__memblock_setup(void) if (entry->type !=3D E820_TYPE_RAM && entry->type !=3D E820_TYPE_RESER= VED_KERN) continue; =20 - memblock_add(entry->addr, entry->size); + if (entry->addr >=3D MAXMEM) { + not_addressable +=3D entry->size; + continue; + } + + end =3D min_t(u64, end, MAXMEM - 1); + size =3D end - entry->addr; + not_addressable +=3D entry->size - size; + memblock_add(entry->addr, size); + } + + if (not_addressable) { + pr_err("%lldGB of physical memory is not addressable in the paging mod= e\n", + not_addressable >> 30); + if (!pgtable_l5_enabled()) + pr_err("Consider enabling 5-level paging\n"); } =20 /* Throw away partial pages: */ --=20 2.26.2