Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1275391 > unrolled thread

[PATCH 1/6] x86/efi: PFN_ALIGN() _text and _end when calculating number of pages

Started byMatt Fleming <matt@codeblueprint.co.uk>
First post2015-11-23 14:40 +0100
Last post2015-11-27 22:10 +0100
Articles 5 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 1/6] x86/efi: PFN_ALIGN() _text and _end when calculating number of pages Matt Fleming <matt@codeblueprint.co.uk> - 2015-11-23 14:40 +0100
    Re: [PATCH 1/6] x86/efi: PFN_ALIGN() _text and _end when calculating  number of pages Ingo Molnar <mingo@kernel.org> - 2015-11-24 09:30 +0100
      Re: [PATCH 1/6] x86/efi: PFN_ALIGN() _text and _end when calculating  number of pages Matt Fleming <matt@codeblueprint.co.uk> - 2015-11-24 12:00 +0100
        Re: [PATCH 1/6] x86/efi: PFN_ALIGN() _text and _end when calculating  number of pages Ingo Molnar <mingo@kernel.org> - 2015-11-26 12:20 +0100
          Re: [PATCH 1/6] x86/efi: PFN_ALIGN() _text and _end when calculating  number of pages Matt Fleming <matt@codeblueprint.co.uk> - 2015-11-27 22:10 +0100

#1275391 — [PATCH 1/6] x86/efi: PFN_ALIGN() _text and _end when calculating number of pages

FromMatt Fleming <matt@codeblueprint.co.uk>
Date2015-11-23 14:40 +0100
Subject[PATCH 1/6] x86/efi: PFN_ALIGN() _text and _end when calculating number of pages
Message-ID<qxZvA-2lA-5@gated-at.bofh.it>
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 <dave.hansen@intel.com>
Reported-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Matt Fleming <matt@codeblueprint.co.uk>
---
 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);
 
 	if (kernel_map_pages_in_pgd(pgd, text >> PAGE_SHIFT, text, npages, 0)) {
-- 
2.6.2

--
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/

[toc] | [next] | [standalone]


#1276153 — Re: [PATCH 1/6] x86/efi: PFN_ALIGN() _text and _end when calculating number of pages

FromIngo Molnar <mingo@kernel.org>
Date2015-11-24 09:30 +0100
SubjectRe: [PATCH 1/6] x86/efi: PFN_ALIGN() _text and _end when calculating number of pages
Message-ID<qyh97-5D3-7@gated-at.bofh.it>
In reply to#1275391
* Matt Fleming <matt@codeblueprint.co.uk> 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 <dave.hansen@intel.com>
> Reported-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: Borislav Petkov <bp@alien8.de>
> Cc: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Matt Fleming <matt@codeblueprint.co.uk>
> ---
>  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/

[toc] | [prev] | [next] | [standalone]


#1276318 — Re: [PATCH 1/6] x86/efi: PFN_ALIGN() _text and _end when calculating number of pages

FromMatt Fleming <matt@codeblueprint.co.uk>
Date2015-11-24 12:00 +0100
SubjectRe: [PATCH 1/6] x86/efi: PFN_ALIGN() _text and _end when calculating number of pages
Message-ID<qyjui-72V-17@gated-at.bofh.it>
In reply to#1276153
On Tue, 24 Nov, at 09:23:23AM, Ingo Molnar wrote:
> 
> Didn't we want to do the _end alignment linker script fix instead?
 
I think we should do both. This patch is tagged for stable because it
fixes a bug in the existing code. It's obvious and it's explicit and
it's much easier to know when someone might want to backport it.

Changing the linker script which indirectly fixes the above bug is a
much more subtle solution, with much larger potential for fallout
because it affects multiple chunks of kernel code.

> 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.

I don't agree that sprinkling PFN_ALIGN() complicates the code, it's a
minimal change with a well known kernel idiom. But yes, aligning these
symbols in the linker script is generally a good idea.

The two patches are worthwhile, for different reasons; let's do both.
--
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/

[toc] | [prev] | [next] | [standalone]


#1278153 — Re: [PATCH 1/6] x86/efi: PFN_ALIGN() _text and _end when calculating number of pages

FromIngo Molnar <mingo@kernel.org>
Date2015-11-26 12:20 +0100
SubjectRe: [PATCH 1/6] x86/efi: PFN_ALIGN() _text and _end when calculating number of pages
Message-ID<qz2KK-4oQ-1@gated-at.bofh.it>
In reply to#1276318
* Matt Fleming <matt@codeblueprint.co.uk> wrote:

> On Tue, 24 Nov, at 09:23:23AM, Ingo Molnar wrote:
> > 
> > Didn't we want to do the _end alignment linker script fix instead?
>  
> I think we should do both. This patch is tagged for stable because it
> fixes a bug in the existing code. It's obvious and it's explicit and
> it's much easier to know when someone might want to backport it.
> 
> Changing the linker script which indirectly fixes the above bug is a
> much more subtle solution, with much larger potential for fallout
> because it affects multiple chunks of kernel code.
> 
> > 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.
> 
> I don't agree that sprinkling PFN_ALIGN() complicates the code, it's a
> minimal change with a well known kernel idiom. But yes, aligning these
> symbols in the linker script is generally a good idea.
> 
> The two patches are worthwhile, for different reasons; let's do both.

I disagree, this form:

        npages = (_end - _text) >> PAGE_SHIFT;

is a lot clearer to read than:

        npages = (PFN_ALIGN(_end) - PFN_ALIGN(_text)) >> PAGE_SHIFT;

especially once we ensure that _end and _text are page aligned. The latter form 
will only result in cargo-cult carrying over of unnecessary PFN_ALIGN() 
operations.

Section boundaries of the kernel should generally be page aligned, this is useful 
for a number of other reasons as well.

As far as backporting goes, it would generally be _safer_ to backport the linker 
script fix, in case there are other unrealized alignment bugs in the kernel. 
Especially if upstream does the same.

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/

[toc] | [prev] | [next] | [standalone]


#1278968 — Re: [PATCH 1/6] x86/efi: PFN_ALIGN() _text and _end when calculating number of pages

FromMatt Fleming <matt@codeblueprint.co.uk>
Date2015-11-27 22:10 +0100
SubjectRe: [PATCH 1/6] x86/efi: PFN_ALIGN() _text and _end when calculating number of pages
Message-ID<qzyrf-82O-1@gated-at.bofh.it>
In reply to#1278153
On Thu, 26 Nov, at 12:13:23PM, Ingo Molnar wrote:
> 
> As far as backporting goes, it would generally be _safer_ to backport the linker 
> script fix, in case there are other unrealized alignment bugs in the kernel. 
> Especially if upstream does the same.

OK, I'll respin this series and replace this patch with the linker
script fix.
--
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/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web