Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1266502ybp; Fri, 11 Oct 2019 11:28:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqz3HD9oqq08863NwXUJf1OD5XsuVwxgYoVzwhe+UakVTRIlCDuxCqXvo8H1d+Y6GTi3ABg4 X-Received: by 2002:a50:aca5:: with SMTP id x34mr14923311edc.130.1570818525845; Fri, 11 Oct 2019 11:28:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570818525; cv=none; d=google.com; s=arc-20160816; b=Gp85qxuGrKMEJ9emSMXtutE120Lyv5sg8meaIGWB/foO9MBWqbrnY64FFRAyCR0MKF s4/by6MO7JnfK0viHL4ABEc4biMKAZCnf5kJTdXFC2NmzSv0Pqs6BlPZ8MSG1hyLUN5n W3up4vOKJnNmSsFgSNKvfnCmJYiRTq+Yz9p6TzxF4IKmbrsdC+tFdGEnPvY7ZPalsnjU Nn/bc0EvkmgvZb5nCSuOX5jUnQAifsQmdmSsWiwdEpmAi+JAgzq0bJMsqWWKcP8VDrj2 IXUFNyby4pmsG+cYQlRqm+pSU+N1Kun0lERPWSuDkzqI2yCOVnEbU0rutBgii3GJhEAo hVIg== 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=hzDoRQw2mqR5KgiLvK80RQsNnSbB8G+8dovDrCecQoPqvxLQvIionvVQe9YnvJG7tB NqRhQQsgy3O9bxx0lLHsMU81sDo1tnA07N17wijNdlrQDI7feJ9u5KncYWg11Tdg3t0y GT2VdOfGdv5ipstSMMIhN0FqNMldP2GJPi3cyycKw8zz5hAyWFpj89qo3DOuXO+IJauo w7I939/BUR8WQzxEB8dRQARkh6uRKIQAfvHqERTMaMeu0vcbLi3L6++9AZSX/rqXvF/T VbIo5tq6tC31j1met4WDZpbQrwKPcOWePY8fH/ob9vsabMsasFRcGTTEBFHMMDGiubKC JWKA== 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 g21si5914811edg.339.2019.10.11.11.28.21; Fri, 11 Oct 2019 11:28:45 -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 S1728794AbfJKS2K (ORCPT + 99 others); Fri, 11 Oct 2019 14:28:10 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:33590 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728501AbfJKS2K (ORCPT ); Fri, 11 Oct 2019 14:28:10 -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 1iIzdp-0008Sl-Rk; Fri, 11 Oct 2019 20:27:53 +0200 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id 7B1DD1C0178; Fri, 11 Oct 2019 20:27:53 +0200 (CEST) Date: Fri, 11 Oct 2019 18:27:53 -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: <157081847335.9978.12589261969290312814.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. */