RE: [PATCH 2/2] x86, efi: Add "efi_fake_mem_mirror" boot option

2015-08-26 Thread Izumi, Taku
Dear Matt,

Thank you for reviewing.

I updated my patchset.
I'm happy if you review new one.

Sincerely,
Taku Izumi

> -Original Message-
> From: Matt Fleming [mailto:m...@codeblueprint.co.uk]
> Sent: Wednesday, August 26, 2015 8:46 AM
> To: Izumi, Taku/泉 拓
> Cc: linux-kernel@vger.kernel.org; linux-...@vger.kernel.org; x...@kernel.org; 
> matt.flem...@intel.com;
> t...@linutronix.de; mi...@redhat.com; h...@zytor.com; tony.l...@intel.com; 
> qiuxi...@huawei.com; Kamezawa, Hiroyuki/亀
> 澤 寛之
> Subject: Re: [PATCH 2/2] x86, efi: Add "efi_fake_mem_mirror" boot option
> 
> On Fri, 21 Aug, at 02:16:00AM, Taku Izumi wrote:
> > This patch introduces new boot option named "efi_fake_mem_mirror".
> > By specifying this parameter, you can mark specific memory as
> > mirrored memory. This is useful for debugging of Address Range
> > Mirroring feature.
> >
> > For example, if you specify "efi_fake_mem_mirror=2G@4G,2G@0x10a000",
> > the original (firmware provided) EFI memmap will be updated so that
> > the specified memory regions have EFI_MEMORY_MORE_RELIABLE attribute:
> >
> >  
> >efi: mem00: [Boot Data  |   ||  |  |  |   |WB|WT|WC|UC] 
> > range=[0x-0x1000)
> (0MB)
> >efi: mem01: [Loader Data|   ||  |  |  |   |WB|WT|WC|UC] 
> > range=[0x1000-0x2000)
> (0MB)
> >...
> >efi: mem35: [Boot Data  |   ||  |  |  |   |WB|WT|WC|UC] 
> > range=[0x47ee6000-0x48014000)
> (1MB)
> >efi: mem36: [Conventional Memory|   ||  |  |  |   |WB|WT|WC|UC] 
> > range=[0x0001-0x0020a000)
> (129536MB)
> >efi: mem37: [Reserved   |RUN||  |  |  |   |  |  |  |UC] 
> > range=[0x6000-0x9000)
> (768MB)
> >
> >  
> >efi: mem00: [Boot Data  |   ||  |  |  |   |WB|WT|WC|UC] 
> > range=[0x-0x1000)
> (0MB)
> >efi: mem01: [Loader Data|   ||  |  |  |   |WB|WT|WC|UC] 
> > range=[0x1000-0x2000)
> (0MB)
> >...
> >efi: mem35: [Boot Data  |   ||  |  |  |   |WB|WT|WC|UC] 
> > range=[0x47ee6000-0x48014000)
> (1MB)
> >efi: mem36: [Conventional Memory|   |RELY|  |  |  |   |WB|WT|WC|UC] 
> > range=[0x0001-0x00018000)
> (2048MB)
> >efi: mem37: [Conventional Memory|   ||  |  |  |   |WB|WT|WC|UC] 
> > range=[0x00018000-0x0010a000)
> (61952MB)
> >efi: mem38: [Conventional Memory|   |RELY|  |  |  |   |WB|WT|WC|UC] 
> > range=[0x0010a000-0x00112000)
> (2048MB)
> >efi: mem39: [Conventional Memory|   ||  |  |  |   |WB|WT|WC|UC] 
> > range=[0x00112000-0x0020a000)
> (63488MB)
> >efi: mem40: [Reserved   |RUN||  |  |  |   |  |  |  |UC] 
> > range=[0x6000-0x9000)
> (768MB)
> >
> > And you will find that the following message is output:
> >
> >efi: Memory: 4096M/131455M mirrored memory
> >
> > Signed-off-by: Taku Izumi 
> > ---
> >  Documentation/kernel-parameters.txt |   8 ++
> >  arch/x86/include/asm/efi.h  |   2 +
> >  arch/x86/kernel/setup.c |   4 +-
> >  arch/x86/platform/efi/efi.c |   2 +-
> >  arch/x86/platform/efi/quirks.c  | 169 
> > 
> >  5 files changed, 183 insertions(+), 2 deletions(-)
> 
> [...]
> 
> > diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c
> > index 1c7380d..5c785e1 100644
> > --- a/arch/x86/platform/efi/quirks.c
> > +++ b/arch/x86/platform/efi/quirks.c
> > @@ -18,6 +18,10 @@
> >
> 
> The quirks file isn't intended to be used for this kind of feature.
> It's very much a repository for workarounds for quirky firmware, i.e.
> known bugs.
> 
> Instead, how about putting all this into a new fake_mem.c file? Going
> further than that, there's nothing that I can see that looks
> particularly x86-specific, so how about sticking all this in
> drivers/firmware/efi/fake_mem.c so that the arm64 folks can make use
> of it if/when they want to start playing around with
> EFI_MEMORY_MORE_RELIABLE?
> 
> >  static efi_char16_t efi_dummy_name[6] = { 'D', 'U', 'M', 'M', 'Y', 0 };
> >
> > +#define EFI_MAX_FAKE_MIRROR 8
> > +static struct range fake_mirrors[EFI_MAX_FAKE_MIRROR];
> > +static int num_fake_mirror;
> > +
> >  static bool efi_no_storage_paranoia;
> >
> >  

RE: [PATCH 2/2] x86, efi: Add efi_fake_mem_mirror boot option

2015-08-26 Thread Izumi, Taku
Dear Matt,

Thank you for reviewing.

I updated my patchset.
I'm happy if you review new one.

Sincerely,
Taku Izumi

 -Original Message-
 From: Matt Fleming [mailto:m...@codeblueprint.co.uk]
 Sent: Wednesday, August 26, 2015 8:46 AM
 To: Izumi, Taku/泉 拓
 Cc: linux-kernel@vger.kernel.org; linux-...@vger.kernel.org; x...@kernel.org; 
 matt.flem...@intel.com;
 t...@linutronix.de; mi...@redhat.com; h...@zytor.com; tony.l...@intel.com; 
 qiuxi...@huawei.com; Kamezawa, Hiroyuki/亀
 澤 寛之
 Subject: Re: [PATCH 2/2] x86, efi: Add efi_fake_mem_mirror boot option
 
 On Fri, 21 Aug, at 02:16:00AM, Taku Izumi wrote:
  This patch introduces new boot option named efi_fake_mem_mirror.
  By specifying this parameter, you can mark specific memory as
  mirrored memory. This is useful for debugging of Address Range
  Mirroring feature.
 
  For example, if you specify efi_fake_mem_mirror=2G@4G,2G@0x10a000,
  the original (firmware provided) EFI memmap will be updated so that
  the specified memory regions have EFI_MEMORY_MORE_RELIABLE attribute:
 
   original EFI memmap
 efi: mem00: [Boot Data  |   ||  |  |  |   |WB|WT|WC|UC] 
  range=[0x-0x1000)
 (0MB)
 efi: mem01: [Loader Data|   ||  |  |  |   |WB|WT|WC|UC] 
  range=[0x1000-0x2000)
 (0MB)
 ...
 efi: mem35: [Boot Data  |   ||  |  |  |   |WB|WT|WC|UC] 
  range=[0x47ee6000-0x48014000)
 (1MB)
 efi: mem36: [Conventional Memory|   ||  |  |  |   |WB|WT|WC|UC] 
  range=[0x0001-0x0020a000)
 (129536MB)
 efi: mem37: [Reserved   |RUN||  |  |  |   |  |  |  |UC] 
  range=[0x6000-0x9000)
 (768MB)
 
   updated EFI memmap
 efi: mem00: [Boot Data  |   ||  |  |  |   |WB|WT|WC|UC] 
  range=[0x-0x1000)
 (0MB)
 efi: mem01: [Loader Data|   ||  |  |  |   |WB|WT|WC|UC] 
  range=[0x1000-0x2000)
 (0MB)
 ...
 efi: mem35: [Boot Data  |   ||  |  |  |   |WB|WT|WC|UC] 
  range=[0x47ee6000-0x48014000)
 (1MB)
 efi: mem36: [Conventional Memory|   |RELY|  |  |  |   |WB|WT|WC|UC] 
  range=[0x0001-0x00018000)
 (2048MB)
 efi: mem37: [Conventional Memory|   ||  |  |  |   |WB|WT|WC|UC] 
  range=[0x00018000-0x0010a000)
 (61952MB)
 efi: mem38: [Conventional Memory|   |RELY|  |  |  |   |WB|WT|WC|UC] 
  range=[0x0010a000-0x00112000)
 (2048MB)
 efi: mem39: [Conventional Memory|   ||  |  |  |   |WB|WT|WC|UC] 
  range=[0x00112000-0x0020a000)
 (63488MB)
 efi: mem40: [Reserved   |RUN||  |  |  |   |  |  |  |UC] 
  range=[0x6000-0x9000)
 (768MB)
 
  And you will find that the following message is output:
 
 efi: Memory: 4096M/131455M mirrored memory
 
  Signed-off-by: Taku Izumi izumi.t...@jp.fujitsu.com
  ---
   Documentation/kernel-parameters.txt |   8 ++
   arch/x86/include/asm/efi.h  |   2 +
   arch/x86/kernel/setup.c |   4 +-
   arch/x86/platform/efi/efi.c |   2 +-
   arch/x86/platform/efi/quirks.c  | 169 
  
   5 files changed, 183 insertions(+), 2 deletions(-)
 
 [...]
 
  diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c
  index 1c7380d..5c785e1 100644
  --- a/arch/x86/platform/efi/quirks.c
  +++ b/arch/x86/platform/efi/quirks.c
  @@ -18,6 +18,10 @@
 
 
 The quirks file isn't intended to be used for this kind of feature.
 It's very much a repository for workarounds for quirky firmware, i.e.
 known bugs.
 
 Instead, how about putting all this into a new fake_mem.c file? Going
 further than that, there's nothing that I can see that looks
 particularly x86-specific, so how about sticking all this in
 drivers/firmware/efi/fake_mem.c so that the arm64 folks can make use
 of it if/when they want to start playing around with
 EFI_MEMORY_MORE_RELIABLE?
 
   static efi_char16_t efi_dummy_name[6] = { 'D', 'U', 'M', 'M', 'Y', 0 };
 
  +#define EFI_MAX_FAKE_MIRROR 8
  +static struct range fake_mirrors[EFI_MAX_FAKE_MIRROR];
  +static int num_fake_mirror;
  +
   static bool efi_no_storage_paranoia;
 
   /*
  @@ -288,3 +292,168 @@ bool efi_poweroff_required(void)
   {
  return !!acpi_gbl_reduced_hardware;
   }
  +
  +void __init efi_fake_memmap(void)
  +{
  +   efi_memory_desc_t *md;
  +   void *p, *q;
  +   int i;
  +   int nr_map = memmap.nr_map;
  +   u64 start, end, m_start, m_end;
  +   u64 new_memmap_phy;
  +   void *new_memmap;
  +
  +   if (!num_fake_mirror)
  +   return;
  +
  +   /* count up the number of EFI memory descriptor */
  +   for (p = memmap.map; p  memmap.map_end; p += memmap.desc_size) {
  +   md = p;
  +   start = md-phys_addr;
  +   end = start + (md-num_pages  EFI_PAGE_SHIFT) - 1;
  +
  +   for (i = 0; i  num_fake_mirror; i

Re: [PATCH 2/2] x86, efi: Add "efi_fake_mem_mirror" boot option

2015-08-25 Thread Matt Fleming
On Fri, 21 Aug, at 02:16:00AM, Taku Izumi wrote:
> This patch introduces new boot option named "efi_fake_mem_mirror".
> By specifying this parameter, you can mark specific memory as
> mirrored memory. This is useful for debugging of Address Range
> Mirroring feature.
> 
> For example, if you specify "efi_fake_mem_mirror=2G@4G,2G@0x10a000",
> the original (firmware provided) EFI memmap will be updated so that
> the specified memory regions have EFI_MEMORY_MORE_RELIABLE attribute:
> 
>  
>efi: mem00: [Boot Data  |   ||  |  |  |   |WB|WT|WC|UC] 
> range=[0x-0x1000) (0MB)
>efi: mem01: [Loader Data|   ||  |  |  |   |WB|WT|WC|UC] 
> range=[0x1000-0x2000) (0MB)
>...
>efi: mem35: [Boot Data  |   ||  |  |  |   |WB|WT|WC|UC] 
> range=[0x47ee6000-0x48014000) (1MB)
>efi: mem36: [Conventional Memory|   ||  |  |  |   |WB|WT|WC|UC] 
> range=[0x0001-0x0020a000) (129536MB)
>efi: mem37: [Reserved   |RUN||  |  |  |   |  |  |  |UC] 
> range=[0x6000-0x9000) (768MB)
> 
>  
>efi: mem00: [Boot Data  |   ||  |  |  |   |WB|WT|WC|UC] 
> range=[0x-0x1000) (0MB)
>efi: mem01: [Loader Data|   ||  |  |  |   |WB|WT|WC|UC] 
> range=[0x1000-0x2000) (0MB)
>...
>efi: mem35: [Boot Data  |   ||  |  |  |   |WB|WT|WC|UC] 
> range=[0x47ee6000-0x48014000) (1MB)
>efi: mem36: [Conventional Memory|   |RELY|  |  |  |   |WB|WT|WC|UC] 
> range=[0x0001-0x00018000) (2048MB)
>efi: mem37: [Conventional Memory|   ||  |  |  |   |WB|WT|WC|UC] 
> range=[0x00018000-0x0010a000) (61952MB)
>efi: mem38: [Conventional Memory|   |RELY|  |  |  |   |WB|WT|WC|UC] 
> range=[0x0010a000-0x00112000) (2048MB)
>efi: mem39: [Conventional Memory|   ||  |  |  |   |WB|WT|WC|UC] 
> range=[0x00112000-0x0020a000) (63488MB)
>efi: mem40: [Reserved   |RUN||  |  |  |   |  |  |  |UC] 
> range=[0x6000-0x9000) (768MB)
> 
> And you will find that the following message is output:
> 
>efi: Memory: 4096M/131455M mirrored memory
> 
> Signed-off-by: Taku Izumi 
> ---
>  Documentation/kernel-parameters.txt |   8 ++
>  arch/x86/include/asm/efi.h  |   2 +
>  arch/x86/kernel/setup.c |   4 +-
>  arch/x86/platform/efi/efi.c |   2 +-
>  arch/x86/platform/efi/quirks.c  | 169 
> 
>  5 files changed, 183 insertions(+), 2 deletions(-)

[...]

> diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c
> index 1c7380d..5c785e1 100644
> --- a/arch/x86/platform/efi/quirks.c
> +++ b/arch/x86/platform/efi/quirks.c
> @@ -18,6 +18,10 @@
>  

The quirks file isn't intended to be used for this kind of feature.
It's very much a repository for workarounds for quirky firmware, i.e.
known bugs.

Instead, how about putting all this into a new fake_mem.c file? Going
further than that, there's nothing that I can see that looks
particularly x86-specific, so how about sticking all this in
drivers/firmware/efi/fake_mem.c so that the arm64 folks can make use
of it if/when they want to start playing around with
EFI_MEMORY_MORE_RELIABLE?

>  static efi_char16_t efi_dummy_name[6] = { 'D', 'U', 'M', 'M', 'Y', 0 };
>  
> +#define EFI_MAX_FAKE_MIRROR 8
> +static struct range fake_mirrors[EFI_MAX_FAKE_MIRROR];
> +static int num_fake_mirror;
> +
>  static bool efi_no_storage_paranoia;
>  
>  /*
> @@ -288,3 +292,168 @@ bool efi_poweroff_required(void)
>  {
>   return !!acpi_gbl_reduced_hardware;
>  }
> +
> +void __init efi_fake_memmap(void)
> +{
> + efi_memory_desc_t *md;
> + void *p, *q;
> + int i;
> + int nr_map = memmap.nr_map;
> + u64 start, end, m_start, m_end;
> + u64 new_memmap_phy;
> + void *new_memmap;
> +
> + if (!num_fake_mirror)
> + return;
> +
> + /* count up the number of EFI memory descriptor */
> + for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
> + md = p;
> + start = md->phys_addr;
> + end = start + (md->num_pages << EFI_PAGE_SHIFT) - 1;
> +
> + for (i = 0; i < num_fake_mirror; i++) {
> + /* mirroring range */
> + m_start = fake_mirrors[i].start;
> + m_end = fake_mirrors[i].end;
> +
> + if (m_start <= start) {
> + /* split into 2 parts */
> + if (start < m_end && m_end < end)
> + nr_map++;
> + }
> + if (start < m_start && m_start < end) {
> + /* split into 3 parts */
> + if (m_end < end)
> + 

Re: [PATCH 2/2] x86, efi: Add efi_fake_mem_mirror boot option

2015-08-25 Thread Matt Fleming
On Fri, 21 Aug, at 02:16:00AM, Taku Izumi wrote:
 This patch introduces new boot option named efi_fake_mem_mirror.
 By specifying this parameter, you can mark specific memory as
 mirrored memory. This is useful for debugging of Address Range
 Mirroring feature.
 
 For example, if you specify efi_fake_mem_mirror=2G@4G,2G@0x10a000,
 the original (firmware provided) EFI memmap will be updated so that
 the specified memory regions have EFI_MEMORY_MORE_RELIABLE attribute:
 
  original EFI memmap
efi: mem00: [Boot Data  |   ||  |  |  |   |WB|WT|WC|UC] 
 range=[0x-0x1000) (0MB)
efi: mem01: [Loader Data|   ||  |  |  |   |WB|WT|WC|UC] 
 range=[0x1000-0x2000) (0MB)
...
efi: mem35: [Boot Data  |   ||  |  |  |   |WB|WT|WC|UC] 
 range=[0x47ee6000-0x48014000) (1MB)
efi: mem36: [Conventional Memory|   ||  |  |  |   |WB|WT|WC|UC] 
 range=[0x0001-0x0020a000) (129536MB)
efi: mem37: [Reserved   |RUN||  |  |  |   |  |  |  |UC] 
 range=[0x6000-0x9000) (768MB)
 
  updated EFI memmap
efi: mem00: [Boot Data  |   ||  |  |  |   |WB|WT|WC|UC] 
 range=[0x-0x1000) (0MB)
efi: mem01: [Loader Data|   ||  |  |  |   |WB|WT|WC|UC] 
 range=[0x1000-0x2000) (0MB)
...
efi: mem35: [Boot Data  |   ||  |  |  |   |WB|WT|WC|UC] 
 range=[0x47ee6000-0x48014000) (1MB)
efi: mem36: [Conventional Memory|   |RELY|  |  |  |   |WB|WT|WC|UC] 
 range=[0x0001-0x00018000) (2048MB)
efi: mem37: [Conventional Memory|   ||  |  |  |   |WB|WT|WC|UC] 
 range=[0x00018000-0x0010a000) (61952MB)
efi: mem38: [Conventional Memory|   |RELY|  |  |  |   |WB|WT|WC|UC] 
 range=[0x0010a000-0x00112000) (2048MB)
efi: mem39: [Conventional Memory|   ||  |  |  |   |WB|WT|WC|UC] 
 range=[0x00112000-0x0020a000) (63488MB)
efi: mem40: [Reserved   |RUN||  |  |  |   |  |  |  |UC] 
 range=[0x6000-0x9000) (768MB)
 
 And you will find that the following message is output:
 
efi: Memory: 4096M/131455M mirrored memory
 
 Signed-off-by: Taku Izumi izumi.t...@jp.fujitsu.com
 ---
  Documentation/kernel-parameters.txt |   8 ++
  arch/x86/include/asm/efi.h  |   2 +
  arch/x86/kernel/setup.c |   4 +-
  arch/x86/platform/efi/efi.c |   2 +-
  arch/x86/platform/efi/quirks.c  | 169 
 
  5 files changed, 183 insertions(+), 2 deletions(-)

[...]

 diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c
 index 1c7380d..5c785e1 100644
 --- a/arch/x86/platform/efi/quirks.c
 +++ b/arch/x86/platform/efi/quirks.c
 @@ -18,6 +18,10 @@
  

The quirks file isn't intended to be used for this kind of feature.
It's very much a repository for workarounds for quirky firmware, i.e.
known bugs.

Instead, how about putting all this into a new fake_mem.c file? Going
further than that, there's nothing that I can see that looks
particularly x86-specific, so how about sticking all this in
drivers/firmware/efi/fake_mem.c so that the arm64 folks can make use
of it if/when they want to start playing around with
EFI_MEMORY_MORE_RELIABLE?

  static efi_char16_t efi_dummy_name[6] = { 'D', 'U', 'M', 'M', 'Y', 0 };
  
 +#define EFI_MAX_FAKE_MIRROR 8
 +static struct range fake_mirrors[EFI_MAX_FAKE_MIRROR];
 +static int num_fake_mirror;
 +
  static bool efi_no_storage_paranoia;
  
  /*
 @@ -288,3 +292,168 @@ bool efi_poweroff_required(void)
  {
   return !!acpi_gbl_reduced_hardware;
  }
 +
 +void __init efi_fake_memmap(void)
 +{
 + efi_memory_desc_t *md;
 + void *p, *q;
 + int i;
 + int nr_map = memmap.nr_map;
 + u64 start, end, m_start, m_end;
 + u64 new_memmap_phy;
 + void *new_memmap;
 +
 + if (!num_fake_mirror)
 + return;
 +
 + /* count up the number of EFI memory descriptor */
 + for (p = memmap.map; p  memmap.map_end; p += memmap.desc_size) {
 + md = p;
 + start = md-phys_addr;
 + end = start + (md-num_pages  EFI_PAGE_SHIFT) - 1;
 +
 + for (i = 0; i  num_fake_mirror; i++) {
 + /* mirroring range */
 + m_start = fake_mirrors[i].start;
 + m_end = fake_mirrors[i].end;
 +
 + if (m_start = start) {
 + /* split into 2 parts */
 + if (start  m_end  m_end  end)
 + nr_map++;
 + }
 + if (start  m_start  m_start  end) {
 + /* split into 3 parts */
 + if (m_end  end)
 + nr_map += 2;
 + /*