Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753250AbbKXIX3 (ORCPT ); Tue, 24 Nov 2015 03:23:29 -0500 Received: from mail-wm0-f48.google.com ([74.125.82.48]:34653 "EHLO mail-wm0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752146AbbKXIX1 (ORCPT ); Tue, 24 Nov 2015 03:23:27 -0500 Date: Tue, 24 Nov 2015 09:23:23 +0100 From: Ingo Molnar To: Matt Fleming Cc: Thomas Gleixner , "H . Peter Anvin" , Toshi Kani , linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org, Borislav Petkov , Sai Praneeth Prakhya , stable@vger.kernel.org, Dave Hansen Subject: Re: [PATCH 1/6] x86/efi: PFN_ALIGN() _text and _end when calculating number of pages Message-ID: <20151124082323.GA23451@gmail.com> References: <1448285594-17617-1-git-send-email-matt@codeblueprint.co.uk> <1448285594-17617-2-git-send-email-matt@codeblueprint.co.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1448285594-17617-2-git-send-email-matt@codeblueprint.co.uk> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2061 Lines: 53 * Matt Fleming wrote: > While _text is currently aligned to PAGE_SIZE in the vmlinux linker > script because it's based on CONFIG_PHYSICAL_ALIGN, it's always better > to be explicit about these things to be sure no alignment bugs are > lurking. There's no analogous enforcement for _end. > > Dave provided an example of why the 'npages' calculation is wrong, > > "Just for fun, imagine that _end=0xfff and _text=0x1001. npages > would be 0." > > Use PFN_ALIGN() to be sure the calculation is correctly aligned to > PAGE_SIZE. > > Reported-by: Dave Hansen > Reported-by: Thomas Gleixner > Cc: Borislav Petkov > Cc: Sai Praneeth Prakhya > Cc: Ingo Molnar > Cc: > Signed-off-by: Matt Fleming > --- > arch/x86/platform/efi/efi_64.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c > index a0ac0f9c307f..3a90eb72d153 100644 > --- a/arch/x86/platform/efi/efi_64.c > +++ b/arch/x86/platform/efi/efi_64.c > @@ -183,7 +183,7 @@ int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages) > efi_scratch.phys_stack = virt_to_phys(page_address(page)); > efi_scratch.phys_stack += PAGE_SIZE; /* stack grows down */ > > - npages = (_end - _text) >> PAGE_SHIFT; > + npages = (PFN_ALIGN(_end) - PFN_ALIGN(_text)) >> PAGE_SHIFT; > text = __pa(_text); Didn't we want to do the _end alignment linker script fix instead? Alignment assumptions are easy to make when symbols are well aligned typically (as in this case), so we should guarantee the alignment property instead of complicating the code. Thanks, Ingo -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/