Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp1770995ybn; Thu, 26 Sep 2019 01:52:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqw2+j7yMmFSbp2ftLzvwi6+yiH2u/JQAvb9joEf68MgoKCEueIPgxfu84YNGHPOY9Jh4Jhp X-Received: by 2002:a17:906:4544:: with SMTP id s4mr2095240ejq.116.1569487946946; Thu, 26 Sep 2019 01:52:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569487946; cv=none; d=google.com; s=arc-20160816; b=h3zDnr0EmkLE35K63FPWL2RIVRX1CeaAaspi4VB1teEgxUOjGs8CLnoTwkyfMobVOr t4KQLRUdqaXJFsyMMogXuM5VUzR6vBLoajJMv+LELyUCglNh7j5DaICqrFxnaWXnQ/bi sVglZIN9BMroEzcMApxOq0Lzmx+Htbnd1ghLCrqqhZFdip2YrRY840mSUgDqIwIlaJs4 RKXk1rYMjcr2yjXDT0vuwRS9tqSO/txbez4Q6Zkowmi42kN8/RbTdpPGmDMrQeozpnSa mu/5bmfi+QcRvZoheJbXsPsJV7Enf2FJerjIVRWeNr4CcAbzVDOd8yIm9ndlpVeafwlY oT4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=a8LSWLAO6eQgqUMMkyKTTFs9AnKiykuomT5YWiAPT68=; b=MfaVPQfNqoMrpghXt9kNd2R8aN61YYOU6VyBvZsiV3qlvW8PQjnKN24OdV7NpTGf/d 6XbDQDR4Z59qOPo67QY8EJwOQmY2E1qkQwh8TB2zdKmn3Za3tbmZZ/KK9aOb24ajBGQh m0YETxd8AwnhXQ4gLrmj3eXFbvHI5zY5KxXbKJ9AcULjbhOgB7tLsbj6RuG5Et9duPla xV46xEHZkQ6j3/K0RMsNElYSalUT/kC83t8buni3b3GHvBNiCiQSZdZqlcZ7eiwl4nRR Xf1R0CyhMbgcmrXoegn+S0tXMm22uu8/V1RG3O9JXaAmCwWn+gek04ctapBPUF4/2A79 1JYg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=hpe.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v57si891033edc.171.2019.09.26.01.52.03; Thu, 26 Sep 2019 01:52:26 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=hpe.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2633523AbfIXVEq (ORCPT + 99 others); Tue, 24 Sep 2019 17:04:46 -0400 Received: from mx0a-002e3701.pphosted.com ([148.163.147.86]:15950 "EHLO mx0a-002e3701.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2633500AbfIXVEq (ORCPT ); Tue, 24 Sep 2019 17:04:46 -0400 Received: from pps.filterd (m0134420.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id x8OKvFQr001080; Tue, 24 Sep 2019 21:04:33 GMT Received: from g2t2354.austin.hpe.com (g2t2354.austin.hpe.com [15.233.44.27]) by mx0b-002e3701.pphosted.com with ESMTP id 2v7t53rjem-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 24 Sep 2019 21:04:33 +0000 Received: from g2t2360.austin.hpecorp.net (g2t2360.austin.hpecorp.net [16.196.225.135]) by g2t2354.austin.hpe.com (Postfix) with ESMTP id 681D783; Tue, 24 Sep 2019 21:04:32 +0000 (UTC) Received: from swahl-linux (swahl-linux.americas.hpqcorp.net [10.33.153.21]) by g2t2360.austin.hpecorp.net (Postfix) with ESMTP id A4A8139; Tue, 24 Sep 2019 21:04:31 +0000 (UTC) Date: Tue, 24 Sep 2019 16:04:31 -0500 From: Steve Wahl To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , x86@kernel.org, Juergen Gross , "Kirill A. Shutemov" , Brijesh Singh , Steve Wahl , Jordan Borgner , Feng Tang , linux-kernel@vger.kernel.org, Zhenzhong Duan , Dave Hansen Cc: Baoquan He , russ.anderson@hpe.com, dimitri.sivanich@hpe.com, mike.travis@hpe.com Subject: [PATCH v3 2/2] x86/boot/64: round memory hole size up to next PMD page. Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.12.1 (2019-06-15) X-HPE-SCL: -1 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.95,1.0.8 definitions=2019-09-24_10:2019-09-23,2019-09-24 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 priorityscore=1501 mlxlogscore=999 suspectscore=2 impostorscore=0 clxscore=1015 lowpriorityscore=0 phishscore=0 bulkscore=0 adultscore=0 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-1908290000 definitions=main-1909240169 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Cc: stable@vger.kernel.org --- Changes since v1: * This patch is completely new to this verison. Changes since v2: None. 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 53ac0cb2396d..9652d5c2afda 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. */ -- 2.21.0 -- Steve Wahl, Hewlett Packard Enterprise