2013-10-27 04:00:46

by Dave Young

[permalink] [raw]
Subject: [patch 1/6] Add function efi_remap_region for remapping to saved virt address

Kexec kernel will use saved runtime virtual mapping, so add a
new function efi_remap_region to remapping it directly without
calculate the virt addr from efi_va.

The md is passed in from 1st kernel, the virtual addr is
saved in md->virt_addr.

Signed-off-by: Dave Young <[email protected]>
---
arch/x86/include/asm/efi.h | 1 +
arch/x86/platform/efi/efi_32.c | 4 ++++
arch/x86/platform/efi/efi_64.c | 13 +++++++++++++
3 files changed, 18 insertions(+)

--- linux-2.6.orig/arch/x86/include/asm/efi.h
+++ linux-2.6/arch/x86/include/asm/efi.h
@@ -112,6 +112,7 @@ extern void efi_call_phys_epilog(void);
extern void efi_unmap_memmap(void);
extern void efi_memory_uc(u64 addr, unsigned long size);
extern void __init efi_map_region(efi_memory_desc_t *md);
+extern void __init efi_remap_region(efi_memory_desc_t *md);
extern void efi_sync_low_kernel_mappings(void);
extern void __init old_map_region(efi_memory_desc_t *md);

--- linux-2.6.orig/arch/x86/platform/efi/efi_64.c
+++ linux-2.6/arch/x86/platform/efi/efi_64.c
@@ -177,6 +177,19 @@ void __init efi_map_region(efi_memory_de
md->virt_addr = efi_va;
}

+void __init efi_remap_region(efi_memory_desc_t *md)
+{
+ pgd_t *pgd = (pgd_t *)__va(real_mode_header->trampoline_pgd);
+ unsigned long pf = 0;
+
+ if (!(md->attribute & EFI_MEMORY_WB))
+ pf |= _PAGE_PCD;
+
+ if(kernel_map_pages_in_pgd(pgd, md->phys_addr, md->virt_addr, md->num_pages, pf))
+ pr_warning("Error mapping PA 0x%llx -> VA 0x%llx!\n",
+ md->phys_addr, md->virt_addr);
+}
+
void __iomem *__init efi_ioremap(unsigned long phys_addr, unsigned long size,
u32 type, u64 attribute)
{
--- linux-2.6.orig/arch/x86/platform/efi/efi_32.c
+++ linux-2.6/arch/x86/platform/efi/efi_32.c
@@ -46,6 +46,10 @@ void __init efi_map_region(efi_memory_de
old_map_region(md);
}

+void __init efi_remap_region(efi_memory_desc_t *md)
+{
+}
+
void efi_call_phys_prelog(void)
{
struct desc_ptr gdt_descr;


2013-10-27 11:50:47

by Borislav Petkov

[permalink] [raw]
Subject: Re: [patch 1/6] Add function efi_remap_region for remapping to saved virt address

On Sun, Oct 27, 2013 at 11:47:14AM +0800, [email protected] wrote:
> Kexec kernel will use saved runtime virtual mapping, so add a
> new function efi_remap_region to remapping it directly without
> calculate the virt addr from efi_va.
>
> The md is passed in from 1st kernel, the virtual addr is
> saved in md->virt_addr.
>
> Signed-off-by: Dave Young <[email protected]>
> ---
> arch/x86/include/asm/efi.h | 1 +
> arch/x86/platform/efi/efi_32.c | 4 ++++
> arch/x86/platform/efi/efi_64.c | 13 +++++++++++++
> 3 files changed, 18 insertions(+)
>
> --- linux-2.6.orig/arch/x86/include/asm/efi.h
> +++ linux-2.6/arch/x86/include/asm/efi.h
> @@ -112,6 +112,7 @@ extern void efi_call_phys_epilog(void);
> extern void efi_unmap_memmap(void);
> extern void efi_memory_uc(u64 addr, unsigned long size);
> extern void __init efi_map_region(efi_memory_desc_t *md);
> +extern void __init efi_remap_region(efi_memory_desc_t *md);
> extern void efi_sync_low_kernel_mappings(void);
> extern void __init old_map_region(efi_memory_desc_t *md);
>
> --- linux-2.6.orig/arch/x86/platform/efi/efi_64.c
> +++ linux-2.6/arch/x86/platform/efi/efi_64.c
> @@ -177,6 +177,19 @@ void __init efi_map_region(efi_memory_de
> md->virt_addr = efi_va;
> }
>
> +void __init efi_remap_region(efi_memory_desc_t *md)

remap? Why?

You did have efi_map_region_fixed() which made more sense.

> +{
> + pgd_t *pgd = (pgd_t *)__va(real_mode_header->trampoline_pgd);
> + unsigned long pf = 0;
> +
> + if (!(md->attribute & EFI_MEMORY_WB))
> + pf |= _PAGE_PCD;
> +
> + if(kernel_map_pages_in_pgd(pgd, md->phys_addr, md->virt_addr, md->num_pages, pf))

ERROR: space required before the open parenthesis '('
#59: FILE: arch/x86/platform/efi/efi_64.c:188:
+ if(kernel_map_pages_in_pgd(pgd, md->phys_addr, md->virt_addr, md->num_pages, pf))


Please run them all through checkpatch.pl - better yet, integrate
checkpatch into your workflow like using git hooks, for example.

> + pr_warning("Error mapping PA 0x%llx -> VA 0x%llx!\n",

WARNING: Prefer pr_warn(... to pr_warning(...
#60: FILE: arch/x86/platform/efi/efi_64.c:189:
+ pr_warning("Error mapping PA 0x%llx -> VA 0x%llx!\n",

> + md->phys_addr, md->virt_addr);
> +}
> +
> void __iomem *__init efi_ioremap(unsigned long phys_addr, unsigned long size,
> u32 type, u64 attribute)
> {
> --- linux-2.6.orig/arch/x86/platform/efi/efi_32.c
> +++ linux-2.6/arch/x86/platform/efi/efi_32.c
> @@ -46,6 +46,10 @@ void __init efi_map_region(efi_memory_de
> old_map_region(md);
> }
>
> +void __init efi_remap_region(efi_memory_desc_t *md)
> +{
> +}

Let's keep braces on the same line as the function to save space:

void __init efi_remap_region(efi_memory_desc_t *md) {}

--
Regards/Gruss,
Boris.

Sent from a fat crate under my desk. Formatting is fine.
--

2013-10-28 01:26:11

by Dave Young

[permalink] [raw]
Subject: Re: [patch 1/6] Add function efi_remap_region for remapping to saved virt address

Hi, Thanks for review

On 10/27/13 at 12:50pm, Borislav Petkov wrote:
> On Sun, Oct 27, 2013 at 11:47:14AM +0800, [email protected] wrote:
> > Kexec kernel will use saved runtime virtual mapping, so add a
> > new function efi_remap_region to remapping it directly without
> > calculate the virt addr from efi_va.
> >
> > The md is passed in from 1st kernel, the virtual addr is
> > saved in md->virt_addr.
> >
> > Signed-off-by: Dave Young <[email protected]>
> > ---
> > arch/x86/include/asm/efi.h | 1 +
> > arch/x86/platform/efi/efi_32.c | 4 ++++
> > arch/x86/platform/efi/efi_64.c | 13 +++++++++++++
> > 3 files changed, 18 insertions(+)
> >
> > --- linux-2.6.orig/arch/x86/include/asm/efi.h
> > +++ linux-2.6/arch/x86/include/asm/efi.h
> > @@ -112,6 +112,7 @@ extern void efi_call_phys_epilog(void);
> > extern void efi_unmap_memmap(void);
> > extern void efi_memory_uc(u64 addr, unsigned long size);
> > extern void __init efi_map_region(efi_memory_desc_t *md);
> > +extern void __init efi_remap_region(efi_memory_desc_t *md);
> > extern void efi_sync_low_kernel_mappings(void);
> > extern void __init old_map_region(efi_memory_desc_t *md);
> >
> > --- linux-2.6.orig/arch/x86/platform/efi/efi_64.c
> > +++ linux-2.6/arch/x86/platform/efi/efi_64.c
> > @@ -177,6 +177,19 @@ void __init efi_map_region(efi_memory_de
> > md->virt_addr = efi_va;
> > }
> >
> > +void __init efi_remap_region(efi_memory_desc_t *md)
>
> remap? Why?
>
> You did have efi_map_region_fixed() which made more sense.

remap here means mapping to same virt addr in 2nd kernel, I feel
it's a little better, but I have no strong opinion.

Will change to _fixed

>
> > +{
> > + pgd_t *pgd = (pgd_t *)__va(real_mode_header->trampoline_pgd);
> > + unsigned long pf = 0;
> > +
> > + if (!(md->attribute & EFI_MEMORY_WB))
> > + pf |= _PAGE_PCD;
> > +
> > + if(kernel_map_pages_in_pgd(pgd, md->phys_addr, md->virt_addr, md->num_pages, pf))
>
> ERROR: space required before the open parenthesis '('
> #59: FILE: arch/x86/platform/efi/efi_64.c:188:
> + if(kernel_map_pages_in_pgd(pgd, md->phys_addr, md->virt_addr, md->num_pages, pf))

Will fix

>
>
> Please run them all through checkpatch.pl - better yet, integrate
> checkpatch into your workflow like using git hooks, for example.

Hmm, will do. Have been long time being away from sending patches.

>
> > + pr_warning("Error mapping PA 0x%llx -> VA 0x%llx!\n",
>
> WARNING: Prefer pr_warn(... to pr_warning(...
> #60: FILE: arch/x86/platform/efi/efi_64.c:189:
> + pr_warning("Error mapping PA 0x%llx -> VA 0x%llx!\n",

Will fix

>
> > + md->phys_addr, md->virt_addr);
> > +}
> > +
> > void __iomem *__init efi_ioremap(unsigned long phys_addr, unsigned long size,
> > u32 type, u64 attribute)
> > {
> > --- linux-2.6.orig/arch/x86/platform/efi/efi_32.c
> > +++ linux-2.6/arch/x86/platform/efi/efi_32.c
> > @@ -46,6 +46,10 @@ void __init efi_map_region(efi_memory_de
> > old_map_region(md);
> > }
> >
> > +void __init efi_remap_region(efi_memory_desc_t *md)
> > +{
> > +}
>
> Let's keep braces on the same line as the function to save space:

Ok, will update

>
> void __init efi_remap_region(efi_memory_desc_t *md) {}
>
> --
> Regards/Gruss,
> Boris.
>
> Sent from a fat crate under my desk. Formatting is fine.
> --