Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1268526ybp; Fri, 11 Oct 2019 11:30:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqzc7tsS31CUm1jHCHSoRPh+/egu/1XP5oxvA0KeAU3JrmWXRkDK7dg6C8PrxCTBLd6x0C0M X-Received: by 2002:a50:a781:: with SMTP id i1mr14971227edc.17.1570818647366; Fri, 11 Oct 2019 11:30:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570818647; cv=none; d=google.com; s=arc-20160816; b=Frz0VeiKRwzc0ZwKuZXbkGc2uxZenZxW6Lq/0DKc8TLD7V55Nrkv6unvjXDc4cr5ni LLLT92Le0peuW4mNEa4yT4Kweh1PEEsDZs1flo8156E0vkYrc76PeGQJYWrvM88cNXqX IPjjHaJ3/ZGXtF5mXoV6dly1hNstKCPgHW5eT2PDs7/KriV42oF3Kcd/fLdCxWeQHx83 vsu3Hu8quHjBmB+OHNsgVp6JHjp6Q4IjTAqJyU4SqBdYUWNHiX7kQ88im+EDrZ+reSqq Fksdq8Selu98TZBWtLN9r4XINiVA10lWuqyZ1RD4P8eTmaqwYNw4jImEnas7eS044Msj jOjw== 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 :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:date; bh=ALpcfwx0tpC+V2THs665qup8V2P7qEntneIGRwhladc=; b=AVmbcDI/fA4cCfpSOs3fzop6QGZcdmP5X1BAv/mxrHkX8c+Gqbd9LkKB6QMku45M50 JjKmsvyTlYcFcsVTYY7JEZGs2x1fzdxHp0AjtT6QpYwhN90JV1t4lIjlj4wc/W5xi/l+ HLmREvfgBCZP8up7hCuHD2jfAO08AiU8mmkPBBmln1t36wCsxULjJp0DVacA4pRNSk/H riF7e7cg1XLH7vnCNr5A7DghjB49LsPFMI/nhpcc56XyIYppICV4xuMDOadyp6/+LgOc ry41UsBFBYxw6esobhLlm72rxDMwq7eQTcufARYXa0BzWM7HLrOLWqrM13bDXXf7OTdf 9xyQ== 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 b1si6252896edm.271.2019.10.11.11.30.23; Fri, 11 Oct 2019 11:30:47 -0700 (PDT) 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 S1728762AbfJKSaM (ORCPT + 99 others); Fri, 11 Oct 2019 14:30:12 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:33610 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728470AbfJKSaM (ORCPT ); Fri, 11 Oct 2019 14:30:12 -0400 Received: from [5.158.153.53] (helo=tip-bot2.lab.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1iIzdj-0008R5-1u; Fri, 11 Oct 2019 20:27:47 +0200 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id 682E31C0178; Fri, 11 Oct 2019 20:27:46 +0200 (CEST) Date: Fri, 11 Oct 2019 18:27:46 -0000 From: "tip-bot2 for Steve Wahl" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/urgent] x86/boot/64: Round memory hole size up to next PMD page Cc: Steve Wahl , Borislav Petkov , Dave Hansen , "Kirill A. Shutemov" , Baoquan He , Brijesh Singh , dimitri.sivanich@hpe.com, Feng Tang , "H. Peter Anvin" , Ingo Molnar , Jordan Borgner , Juergen Gross , mike.travis@hpe.com, russ.anderson@hpe.com, Thomas Gleixner , "x86-ml" , Zhenzhong Duan , Ingo Molnar , Borislav Petkov , linux-kernel@vger.kernel.org In-Reply-To: References: MIME-Version: 1.0 Message-ID: <157081846631.9978.9049202899557176748.tip-bot2@tip-bot2> X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/urgent branch of tip: Commit-ID: 1869dbe87cb94dc9a218ae1d9301dea3678bd4ff Gitweb: https://git.kernel.org/tip/1869dbe87cb94dc9a218ae1d9301dea3678bd4ff Author: Steve Wahl AuthorDate: Tue, 24 Sep 2019 16:04:31 -05:00 Committer: Borislav Petkov CommitterDate: Fri, 11 Oct 2019 18:47:23 +02:00 x86/boot/64: Round memory hole size up to next PMD page The kernel image map is created using PMD pages, which can include some extra space beyond what's actually needed. Round the size of the memory hole we search for up to the next PMD boundary, to be certain all of the space to be mapped is usable RAM and includes no reserved areas. Signed-off-by: Steve Wahl Signed-off-by: Borislav Petkov Acked-by: Dave Hansen Acked-by: Kirill A. Shutemov Cc: Baoquan He Cc: Brijesh Singh Cc: dimitri.sivanich@hpe.com Cc: Feng Tang Cc: "H. Peter Anvin" Cc: Ingo Molnar Cc: Jordan Borgner Cc: Juergen Gross Cc: mike.travis@hpe.com Cc: russ.anderson@hpe.com Cc: Thomas Gleixner Cc: x86-ml Cc: Zhenzhong Duan Link: https://lkml.kernel.org/r/df4f49f05c0c27f108234eb93db5c613d09ea62e.1569358539.git.steve.wahl@hpe.com --- arch/x86/boot/compressed/misc.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c index 53ac0cb..9652d5c 100644 --- a/arch/x86/boot/compressed/misc.c +++ b/arch/x86/boot/compressed/misc.c @@ -345,6 +345,7 @@ asmlinkage __visible void *extract_kernel(void *rmode, memptr heap, { const unsigned long kernel_total_size = VO__end - VO__text; unsigned long virt_addr = LOAD_PHYSICAL_ADDR; + unsigned long needed_size; /* Retain x86 boot parameters pointer passed from startup_32/64. */ boot_params = rmode; @@ -379,26 +380,38 @@ asmlinkage __visible void *extract_kernel(void *rmode, memptr heap, free_mem_ptr = heap; /* Heap */ free_mem_end_ptr = heap + BOOT_HEAP_SIZE; + /* + * The memory hole needed for the kernel is the larger of either + * the entire decompressed kernel plus relocation table, or the + * entire decompressed kernel plus .bss and .brk sections. + * + * On X86_64, the memory is mapped with PMD pages. Round the + * size up so that the full extent of PMD pages mapped is + * included in the check against the valid memory table + * entries. This ensures the full mapped area is usable RAM + * and doesn't include any reserved areas. + */ + needed_size = max(output_len, kernel_total_size); +#ifdef CONFIG_X86_64 + needed_size = ALIGN(needed_size, MIN_KERNEL_ALIGN); +#endif + /* Report initial kernel position details. */ debug_putaddr(input_data); debug_putaddr(input_len); debug_putaddr(output); debug_putaddr(output_len); debug_putaddr(kernel_total_size); + debug_putaddr(needed_size); #ifdef CONFIG_X86_64 /* Report address of 32-bit trampoline */ debug_putaddr(trampoline_32bit); #endif - /* - * The memory hole needed for the kernel is the larger of either - * the entire decompressed kernel plus relocation table, or the - * entire decompressed kernel plus .bss and .brk sections. - */ choose_random_location((unsigned long)input_data, input_len, (unsigned long *)&output, - max(output_len, kernel_total_size), + needed_size, &virt_addr); /* Validate memory location choices. */