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=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 A4745C433DB for ; Tue, 22 Dec 2020 11:19:09 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 37DC32312D for ; Tue, 22 Dec 2020 11:19:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 37DC32312D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 44E8D6B0080; Tue, 22 Dec 2020 06:19:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3FEB06B0082; Tue, 22 Dec 2020 06:19:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3153E6B0083; Tue, 22 Dec 2020 06:19:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0034.hostedemail.com [216.40.44.34]) by kanga.kvack.org (Postfix) with ESMTP id 1779A6B0080 for ; Tue, 22 Dec 2020 06:19:08 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id D3AB68249980 for ; Tue, 22 Dec 2020 11:19:07 +0000 (UTC) X-FDA: 77620671534.24.rod39_46176572745f Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin24.hostedemail.com (Postfix) with ESMTP id A58E81A4A0 for ; Tue, 22 Dec 2020 11:19:07 +0000 (UTC) X-HE-Tag: rod39_46176572745f X-Filterd-Recvd-Size: 3449 Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) by imf39.hostedemail.com (Postfix) with ESMTP for ; Tue, 22 Dec 2020 11:19:06 +0000 (UTC) Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4D0Yjq0MC7zhvVg; Tue, 22 Dec 2020 19:18:23 +0800 (CST) Received: from huawei.com (10.175.127.16) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.498.0; Tue, 22 Dec 2020 19:18:47 +0800 From: Pan Zhang To: , , , , , , , CC: , , , Subject: [PATCH] x86/kaslr: support separate multiple memmaps parameter parsing Date: Tue, 22 Dec 2020 19:31:24 +0800 Message-ID: <20201222113124.35367-1-zhangpan26@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" X-Originating-IP: [10.175.127.16] X-CFilter-Loop: Reflected 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: When the kernel is loading, the load address of the kernel needs to be calculated firstly. If the kernel address space layout randomization(`kaslr`) is enabled, the memory range reserved by the memmap parameter will be excluded to avoid loading the kernel address into the memmap reserved area. Currently, this is what the manual says: `memmap =3D nn [KMG] @ss [KMG] [KNL] Force usage of a specific region of memory. =C2=A0=C2=A0=C2=A0=C2=A0 Region of memory to be used is from ss to ss + n= n. =C2=A0=C2=A0=C2=A0 If @ss [KMG] is omitted, it is equivalent to mem =3D = nn [KMG], =C2=A0=C2=A0=C2=A0=C2=A0 which limits max address to nn [KMG]. Multiple different regions can be specified, comma delimited. Example: memmap=3D100M@2G, 100M#3G, 1G!1024G ` Can we relax the use of memmap? In our production environment we see many people who use it like this: Separate multiple memmaps parameters to reserve memory, memmap=3Dxx\$xxx memmap=3Dxx\$xxx memmap=3Dxx\$xxx memmap=3Dxx\$xxx memma= p=3Dxx\$xxx If this format is used, and the reserved memory segment is greater than 4= , there is no way to parse the 5th and subsequent memmaps and the kaslr can= not be disabled by `memmap_too_large` so the kernel loading address may fall within the memmap range (reserved memory area from memmap after fourth segment), which will have bad consequences for use of reserved memory. Signed-off-by: Pan Zhang --- arch/x86/boot/compressed/kaslr.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/= kaslr.c index d7408af..24a2778 100644 --- a/arch/x86/boot/compressed/kaslr.c +++ b/arch/x86/boot/compressed/kaslr.c @@ -203,9 +203,6 @@ static void mem_avoid_memmap(enum parse_mode mode, ch= ar *str) { static int i; =20 - if (i >=3D MAX_MEMMAP_REGIONS) - return; - while (str && (i < MAX_MEMMAP_REGIONS)) { int rc; unsigned long long start, size; @@ -233,7 +230,7 @@ static void mem_avoid_memmap(enum parse_mode mode, ch= ar *str) } =20 /* More than 4 memmaps, fail kaslr */ - if ((i >=3D MAX_MEMMAP_REGIONS) && str) + if ((i >=3D MAX_MEMMAP_REGIONS) && !memmap_too_large) memmap_too_large =3D true; } =20 --=20 2.7.4