Re: [PATCH v2 2/4] kaslr: select the memory region in immovable node to process

2017-11-13 Thread Baoquan He
On 11/13/17 at 05:50pm, Chao Fan wrote:
> On Mon, Nov 13, 2017 at 05:26:24PM +0800, Baoquan He wrote:
  
> >> >> +static bool select_immovable_node(struct mem_vector region,
> >> >> + unsigned long long minimum,
> >> >> + unsigned long long image_size)
> >> >> +{
> >> >
> >> >About this patch, I just want to notice two things:
> >> >1) From the current code, 'movable_node' kernel parameter is exclusive.
> >> >In find_zone_movable_pfns_for_nodes(), you can see that 'kernelcore' and
> >> >'movablecore' will be ignored as long as 'movable_node' is specified.
> >> >Please also consider this in your code here. If 'movable_node' has to be
> >> >specified too, and need skip the kernel mirror handling.
> >> >
> >> 
> >> Thanks for the notice, I will add the similar operation.
> >
> >No, I meant if movable_node is specified, we have to ignore
> >'kernelcore=', then we may need skip the kernel mirror handling. Since
> >kernel mirror is enabled by 'kernelcore=mirror'.
> >
> 
> Yes, the two parameters are conflict.
> Then if "movable_node" specified, we shoul not consider mirror region.
> I think there can be one another patch to handle this, but not in this
> serials. I will add the change.

Well, no.

You didn't get what I said. In process_efi_entries() mirrorred
regions are picked. If movable_node specified, mirror feature will be
ignored. That has been handled in find_zone_movable_pfns_for_nodes()
very well. So you need make it be consistent. 

And if you add a new kernel para, like immovable_mem=xx@xx, movable_node
will be expected. Anyway, please read find_zone_movable_pfns_for_nodes()
carefully.

Thanks
Baoquan
> 
> >
> >> 
> >> >2)process_mem_region() is a key function to process the available memory
> >> >regions. Please don't make another process_mem_region() like below. You
> >> >can write a small helper function to find the immovable_mem[] which is
> >> >intersecting with the passed in memory region and use clamp() to get
> >> >the real available region. You 'REALLY' don't need to split the region
> >> >in your so called 'select_immovable_node()' function here.
> >> >
> >> 
> >> OK, I will try to make a new method, which is smaller and better to
> >> filter the regions.
> >> 
> >> Thanks,
> >> Chao Fan
> >> 
> >> >PLEASE elaborate more on these details before post.
> >> >
> >> >Thanks
> >> >Baoquan
> >> >
> >> >> +   int i;
> >> >> +
> >> >> +   /* If no immovable_mem stored, use region directly */
> >> >> +   if (num_immovable_region == 0) {
> >> >> +   process_mem_region(, minimum, image_size);
> >> >> +
> >> >> +   if (slot_area_index == MAX_SLOT_AREA) {
> >> >> +   debug_putstr("Aborted memmap scan (slot_areas 
> >> >> full)!\n");
> >> >> +   return 1;
> >> >> +   }
> >> >> +   } else {
> >> >> +   /*
> >> >> +* Walk all immovable regions, and filter the 
> >> >> intersection
> >> >> +* to process_mem_region.
> >> >> +*/
> >> >> +   for (i = 0; i < num_immovable_region; i++) {
> >> >> +   struct mem_vector entry;
> >> >> +   unsigned long long start, end, select_end, 
> >> >> region_end;
> >> >> +
> >> >> +   region_end = region.start + region.size - 1;
> >> >> +   start = immovable_mem[i].start;
> >> >> +   end = start + immovable_mem[i].size - 1;
> >> >> +
> >> >> +   if (region_end < start || region.start > end)
> >> >> +   continue;
> >> >> +
> >> >> +   /* May split one region to several entries. */
> >> >> +   entry.start = start > region.start ?
> >> >> + start : region.start;
> >> >> +   select_end = end > region_end ? region_end : 
> >> >> end;
> >> >> +
> >> >> +   entry.size = select_end - entry.start + 1;
> >> >> +
> >> >> +   process_mem_region(, minimum, image_size);
> >> >> +
> >> >> +   if (slot_area_index == MAX_SLOT_AREA) {
> >> >> +   debug_putstr("Aborted memmap scan 
> >> >> (slot_areas full)!\n");
> >> >> +   return 1;
> >> >> +   }
> >> >> +   }
> >> >> +   }
> >> >> +   return 0;
> >> >> +}
> >> >> +
> >> >>  #ifdef CONFIG_EFI
> >> >>  /*
> >> >>   * Returns true if mirror region found (and must have been processed
> >> >> @@ -699,11 +747,9 @@ process_efi_entries(unsigned long minimum, 
> >> >> unsigned long image_size)
> >> >>  
> >> >> region.start = md->phys_addr;
> >> >> region.size = md->num_pages << EFI_PAGE_SHIFT;
> >> >> -   process_mem_region(, minimum, image_size);
> >> >> -   if (slot_area_index 

Re: [PATCH v2 2/4] kaslr: select the memory region in immovable node to process

2017-11-13 Thread Baoquan He
On 11/13/17 at 05:50pm, Chao Fan wrote:
> On Mon, Nov 13, 2017 at 05:26:24PM +0800, Baoquan He wrote:
  
> >> >> +static bool select_immovable_node(struct mem_vector region,
> >> >> + unsigned long long minimum,
> >> >> + unsigned long long image_size)
> >> >> +{
> >> >
> >> >About this patch, I just want to notice two things:
> >> >1) From the current code, 'movable_node' kernel parameter is exclusive.
> >> >In find_zone_movable_pfns_for_nodes(), you can see that 'kernelcore' and
> >> >'movablecore' will be ignored as long as 'movable_node' is specified.
> >> >Please also consider this in your code here. If 'movable_node' has to be
> >> >specified too, and need skip the kernel mirror handling.
> >> >
> >> 
> >> Thanks for the notice, I will add the similar operation.
> >
> >No, I meant if movable_node is specified, we have to ignore
> >'kernelcore=', then we may need skip the kernel mirror handling. Since
> >kernel mirror is enabled by 'kernelcore=mirror'.
> >
> 
> Yes, the two parameters are conflict.
> Then if "movable_node" specified, we shoul not consider mirror region.
> I think there can be one another patch to handle this, but not in this
> serials. I will add the change.

Well, no.

You didn't get what I said. In process_efi_entries() mirrorred
regions are picked. If movable_node specified, mirror feature will be
ignored. That has been handled in find_zone_movable_pfns_for_nodes()
very well. So you need make it be consistent. 

And if you add a new kernel para, like immovable_mem=xx@xx, movable_node
will be expected. Anyway, please read find_zone_movable_pfns_for_nodes()
carefully.

Thanks
Baoquan
> 
> >
> >> 
> >> >2)process_mem_region() is a key function to process the available memory
> >> >regions. Please don't make another process_mem_region() like below. You
> >> >can write a small helper function to find the immovable_mem[] which is
> >> >intersecting with the passed in memory region and use clamp() to get
> >> >the real available region. You 'REALLY' don't need to split the region
> >> >in your so called 'select_immovable_node()' function here.
> >> >
> >> 
> >> OK, I will try to make a new method, which is smaller and better to
> >> filter the regions.
> >> 
> >> Thanks,
> >> Chao Fan
> >> 
> >> >PLEASE elaborate more on these details before post.
> >> >
> >> >Thanks
> >> >Baoquan
> >> >
> >> >> +   int i;
> >> >> +
> >> >> +   /* If no immovable_mem stored, use region directly */
> >> >> +   if (num_immovable_region == 0) {
> >> >> +   process_mem_region(, minimum, image_size);
> >> >> +
> >> >> +   if (slot_area_index == MAX_SLOT_AREA) {
> >> >> +   debug_putstr("Aborted memmap scan (slot_areas 
> >> >> full)!\n");
> >> >> +   return 1;
> >> >> +   }
> >> >> +   } else {
> >> >> +   /*
> >> >> +* Walk all immovable regions, and filter the 
> >> >> intersection
> >> >> +* to process_mem_region.
> >> >> +*/
> >> >> +   for (i = 0; i < num_immovable_region; i++) {
> >> >> +   struct mem_vector entry;
> >> >> +   unsigned long long start, end, select_end, 
> >> >> region_end;
> >> >> +
> >> >> +   region_end = region.start + region.size - 1;
> >> >> +   start = immovable_mem[i].start;
> >> >> +   end = start + immovable_mem[i].size - 1;
> >> >> +
> >> >> +   if (region_end < start || region.start > end)
> >> >> +   continue;
> >> >> +
> >> >> +   /* May split one region to several entries. */
> >> >> +   entry.start = start > region.start ?
> >> >> + start : region.start;
> >> >> +   select_end = end > region_end ? region_end : 
> >> >> end;
> >> >> +
> >> >> +   entry.size = select_end - entry.start + 1;
> >> >> +
> >> >> +   process_mem_region(, minimum, image_size);
> >> >> +
> >> >> +   if (slot_area_index == MAX_SLOT_AREA) {
> >> >> +   debug_putstr("Aborted memmap scan 
> >> >> (slot_areas full)!\n");
> >> >> +   return 1;
> >> >> +   }
> >> >> +   }
> >> >> +   }
> >> >> +   return 0;
> >> >> +}
> >> >> +
> >> >>  #ifdef CONFIG_EFI
> >> >>  /*
> >> >>   * Returns true if mirror region found (and must have been processed
> >> >> @@ -699,11 +747,9 @@ process_efi_entries(unsigned long minimum, 
> >> >> unsigned long image_size)
> >> >>  
> >> >> region.start = md->phys_addr;
> >> >> region.size = md->num_pages << EFI_PAGE_SHIFT;
> >> >> -   process_mem_region(, minimum, image_size);
> >> >> -   if (slot_area_index 

Re: [PATCH v2 2/4] kaslr: select the memory region in immovable node to process

2017-11-13 Thread Chao Fan
On Mon, Nov 13, 2017 at 05:26:24PM +0800, Baoquan He wrote:
>On 11/13/17 at 05:18pm, Chao Fan wrote:
>> On Mon, Nov 13, 2017 at 04:31:31PM +0800, Baoquan He wrote:
>> >On 11/01/17 at 07:32pm, Chao Fan wrote:
>> >> Compare the region of memmap entry and immovable_mem, then choose the
>> >> intersection to process_mem_region.
>> >> 
>> >> Since the interrelationship between e820 or efi entries and memory
>> >> region in immovable_mem is different:
>> >> One memory region in one node may contain several entries of e820 or
>> >> efi sometimes, and one entry of e820 or efi may contain the memory in
>> >> different nodes sometimes.
>> >> It may split one node or one entry to several regions.
>> >> 
>> >> Signed-off-by: Chao Fan 
>> >> ---
>> >>  arch/x86/boot/compressed/kaslr.c | 60 
>> >> ++--
>> >>  1 file changed, 52 insertions(+), 8 deletions(-)
>> >> 
>> >> diff --git a/arch/x86/boot/compressed/kaslr.c 
>> >> b/arch/x86/boot/compressed/kaslr.c
>> >> index 0a591c0023f1..fcd640fdeaed 100644
>> >> --- a/arch/x86/boot/compressed/kaslr.c
>> >> +++ b/arch/x86/boot/compressed/kaslr.c
>> >> @@ -634,6 +634,54 @@ static void process_mem_region(struct mem_vector 
>> >> *entry,
>> >>   }
>> >>  }
>> >>  
>> >> +static bool select_immovable_node(struct mem_vector region,
>> >> +   unsigned long long minimum,
>> >> +   unsigned long long image_size)
>> >> +{
>> >
>> >About this patch, I just want to notice two things:
>> >1) From the current code, 'movable_node' kernel parameter is exclusive.
>> >In find_zone_movable_pfns_for_nodes(), you can see that 'kernelcore' and
>> >'movablecore' will be ignored as long as 'movable_node' is specified.
>> >Please also consider this in your code here. If 'movable_node' has to be
>> >specified too, and need skip the kernel mirror handling.
>> >
>> 
>> Thanks for the notice, I will add the similar operation.
>
>No, I meant if movable_node is specified, we have to ignore
>'kernelcore=', then we may need skip the kernel mirror handling. Since
>kernel mirror is enabled by 'kernelcore=mirror'.
>

Yes, the two parameters are conflict.
Then if "movable_node" specified, we shoul not consider mirror region.
I think there can be one another patch to handle this, but not in this
serials. I will add the change.

Thanks,
Chao Fan

>
>> 
>> >2)process_mem_region() is a key function to process the available memory
>> >regions. Please don't make another process_mem_region() like below. You
>> >can write a small helper function to find the immovable_mem[] which is
>> >intersecting with the passed in memory region and use clamp() to get
>> >the real available region. You 'REALLY' don't need to split the region
>> >in your so called 'select_immovable_node()' function here.
>> >
>> 
>> OK, I will try to make a new method, which is smaller and better to
>> filter the regions.
>> 
>> Thanks,
>> Chao Fan
>> 
>> >PLEASE elaborate more on these details before post.
>> >
>> >Thanks
>> >Baoquan
>> >
>> >> + int i;
>> >> +
>> >> + /* If no immovable_mem stored, use region directly */
>> >> + if (num_immovable_region == 0) {
>> >> + process_mem_region(, minimum, image_size);
>> >> +
>> >> + if (slot_area_index == MAX_SLOT_AREA) {
>> >> + debug_putstr("Aborted memmap scan (slot_areas 
>> >> full)!\n");
>> >> + return 1;
>> >> + }
>> >> + } else {
>> >> + /*
>> >> +  * Walk all immovable regions, and filter the intersection
>> >> +  * to process_mem_region.
>> >> +  */
>> >> + for (i = 0; i < num_immovable_region; i++) {
>> >> + struct mem_vector entry;
>> >> + unsigned long long start, end, select_end, region_end;
>> >> +
>> >> + region_end = region.start + region.size - 1;
>> >> + start = immovable_mem[i].start;
>> >> + end = start + immovable_mem[i].size - 1;
>> >> +
>> >> + if (region_end < start || region.start > end)
>> >> + continue;
>> >> +
>> >> + /* May split one region to several entries. */
>> >> + entry.start = start > region.start ?
>> >> +   start : region.start;
>> >> + select_end = end > region_end ? region_end : end;
>> >> +
>> >> + entry.size = select_end - entry.start + 1;
>> >> +
>> >> + process_mem_region(, minimum, image_size);
>> >> +
>> >> + if (slot_area_index == MAX_SLOT_AREA) {
>> >> + debug_putstr("Aborted memmap scan (slot_areas 
>> >> full)!\n");
>> >> + return 1;
>> >> + }
>> >> + }
>> >> + }
>> >> + return 0;
>> >> +}
>> >> +
>> >>  #ifdef CONFIG_EFI
>> >>  /*
>> >>   * Returns true if mirror region found (and must have been processed
>> >> @@ -699,11 +747,9 @@ 

Re: [PATCH v2 2/4] kaslr: select the memory region in immovable node to process

2017-11-13 Thread Chao Fan
On Mon, Nov 13, 2017 at 05:26:24PM +0800, Baoquan He wrote:
>On 11/13/17 at 05:18pm, Chao Fan wrote:
>> On Mon, Nov 13, 2017 at 04:31:31PM +0800, Baoquan He wrote:
>> >On 11/01/17 at 07:32pm, Chao Fan wrote:
>> >> Compare the region of memmap entry and immovable_mem, then choose the
>> >> intersection to process_mem_region.
>> >> 
>> >> Since the interrelationship between e820 or efi entries and memory
>> >> region in immovable_mem is different:
>> >> One memory region in one node may contain several entries of e820 or
>> >> efi sometimes, and one entry of e820 or efi may contain the memory in
>> >> different nodes sometimes.
>> >> It may split one node or one entry to several regions.
>> >> 
>> >> Signed-off-by: Chao Fan 
>> >> ---
>> >>  arch/x86/boot/compressed/kaslr.c | 60 
>> >> ++--
>> >>  1 file changed, 52 insertions(+), 8 deletions(-)
>> >> 
>> >> diff --git a/arch/x86/boot/compressed/kaslr.c 
>> >> b/arch/x86/boot/compressed/kaslr.c
>> >> index 0a591c0023f1..fcd640fdeaed 100644
>> >> --- a/arch/x86/boot/compressed/kaslr.c
>> >> +++ b/arch/x86/boot/compressed/kaslr.c
>> >> @@ -634,6 +634,54 @@ static void process_mem_region(struct mem_vector 
>> >> *entry,
>> >>   }
>> >>  }
>> >>  
>> >> +static bool select_immovable_node(struct mem_vector region,
>> >> +   unsigned long long minimum,
>> >> +   unsigned long long image_size)
>> >> +{
>> >
>> >About this patch, I just want to notice two things:
>> >1) From the current code, 'movable_node' kernel parameter is exclusive.
>> >In find_zone_movable_pfns_for_nodes(), you can see that 'kernelcore' and
>> >'movablecore' will be ignored as long as 'movable_node' is specified.
>> >Please also consider this in your code here. If 'movable_node' has to be
>> >specified too, and need skip the kernel mirror handling.
>> >
>> 
>> Thanks for the notice, I will add the similar operation.
>
>No, I meant if movable_node is specified, we have to ignore
>'kernelcore=', then we may need skip the kernel mirror handling. Since
>kernel mirror is enabled by 'kernelcore=mirror'.
>

Yes, the two parameters are conflict.
Then if "movable_node" specified, we shoul not consider mirror region.
I think there can be one another patch to handle this, but not in this
serials. I will add the change.

Thanks,
Chao Fan

>
>> 
>> >2)process_mem_region() is a key function to process the available memory
>> >regions. Please don't make another process_mem_region() like below. You
>> >can write a small helper function to find the immovable_mem[] which is
>> >intersecting with the passed in memory region and use clamp() to get
>> >the real available region. You 'REALLY' don't need to split the region
>> >in your so called 'select_immovable_node()' function here.
>> >
>> 
>> OK, I will try to make a new method, which is smaller and better to
>> filter the regions.
>> 
>> Thanks,
>> Chao Fan
>> 
>> >PLEASE elaborate more on these details before post.
>> >
>> >Thanks
>> >Baoquan
>> >
>> >> + int i;
>> >> +
>> >> + /* If no immovable_mem stored, use region directly */
>> >> + if (num_immovable_region == 0) {
>> >> + process_mem_region(, minimum, image_size);
>> >> +
>> >> + if (slot_area_index == MAX_SLOT_AREA) {
>> >> + debug_putstr("Aborted memmap scan (slot_areas 
>> >> full)!\n");
>> >> + return 1;
>> >> + }
>> >> + } else {
>> >> + /*
>> >> +  * Walk all immovable regions, and filter the intersection
>> >> +  * to process_mem_region.
>> >> +  */
>> >> + for (i = 0; i < num_immovable_region; i++) {
>> >> + struct mem_vector entry;
>> >> + unsigned long long start, end, select_end, region_end;
>> >> +
>> >> + region_end = region.start + region.size - 1;
>> >> + start = immovable_mem[i].start;
>> >> + end = start + immovable_mem[i].size - 1;
>> >> +
>> >> + if (region_end < start || region.start > end)
>> >> + continue;
>> >> +
>> >> + /* May split one region to several entries. */
>> >> + entry.start = start > region.start ?
>> >> +   start : region.start;
>> >> + select_end = end > region_end ? region_end : end;
>> >> +
>> >> + entry.size = select_end - entry.start + 1;
>> >> +
>> >> + process_mem_region(, minimum, image_size);
>> >> +
>> >> + if (slot_area_index == MAX_SLOT_AREA) {
>> >> + debug_putstr("Aborted memmap scan (slot_areas 
>> >> full)!\n");
>> >> + return 1;
>> >> + }
>> >> + }
>> >> + }
>> >> + return 0;
>> >> +}
>> >> +
>> >>  #ifdef CONFIG_EFI
>> >>  /*
>> >>   * Returns true if mirror region found (and must have been processed
>> >> @@ -699,11 +747,9 @@ process_efi_entries(unsigned long 

Re: [PATCH v2 2/4] kaslr: select the memory region in immovable node to process

2017-11-13 Thread Baoquan He
On 11/13/17 at 05:18pm, Chao Fan wrote:
> On Mon, Nov 13, 2017 at 04:31:31PM +0800, Baoquan He wrote:
> >On 11/01/17 at 07:32pm, Chao Fan wrote:
> >> Compare the region of memmap entry and immovable_mem, then choose the
> >> intersection to process_mem_region.
> >> 
> >> Since the interrelationship between e820 or efi entries and memory
> >> region in immovable_mem is different:
> >> One memory region in one node may contain several entries of e820 or
> >> efi sometimes, and one entry of e820 or efi may contain the memory in
> >> different nodes sometimes.
> >> It may split one node or one entry to several regions.
> >> 
> >> Signed-off-by: Chao Fan 
> >> ---
> >>  arch/x86/boot/compressed/kaslr.c | 60 
> >> ++--
> >>  1 file changed, 52 insertions(+), 8 deletions(-)
> >> 
> >> diff --git a/arch/x86/boot/compressed/kaslr.c 
> >> b/arch/x86/boot/compressed/kaslr.c
> >> index 0a591c0023f1..fcd640fdeaed 100644
> >> --- a/arch/x86/boot/compressed/kaslr.c
> >> +++ b/arch/x86/boot/compressed/kaslr.c
> >> @@ -634,6 +634,54 @@ static void process_mem_region(struct mem_vector 
> >> *entry,
> >>}
> >>  }
> >>  
> >> +static bool select_immovable_node(struct mem_vector region,
> >> +unsigned long long minimum,
> >> +unsigned long long image_size)
> >> +{
> >
> >About this patch, I just want to notice two things:
> >1) From the current code, 'movable_node' kernel parameter is exclusive.
> >In find_zone_movable_pfns_for_nodes(), you can see that 'kernelcore' and
> >'movablecore' will be ignored as long as 'movable_node' is specified.
> >Please also consider this in your code here. If 'movable_node' has to be
> >specified too, and need skip the kernel mirror handling.
> >
> 
> Thanks for the notice, I will add the similar operation.

No, I meant if movable_node is specified, we have to ignore
'kernelcore=', then we may need skip the kernel mirror handling. Since
kernel mirror is enabled by 'kernelcore=mirror'.


> 
> >2)process_mem_region() is a key function to process the available memory
> >regions. Please don't make another process_mem_region() like below. You
> >can write a small helper function to find the immovable_mem[] which is
> >intersecting with the passed in memory region and use clamp() to get
> >the real available region. You 'REALLY' don't need to split the region
> >in your so called 'select_immovable_node()' function here.
> >
> 
> OK, I will try to make a new method, which is smaller and better to
> filter the regions.
> 
> Thanks,
> Chao Fan
> 
> >PLEASE elaborate more on these details before post.
> >
> >Thanks
> >Baoquan
> >
> >> +  int i;
> >> +
> >> +  /* If no immovable_mem stored, use region directly */
> >> +  if (num_immovable_region == 0) {
> >> +  process_mem_region(, minimum, image_size);
> >> +
> >> +  if (slot_area_index == MAX_SLOT_AREA) {
> >> +  debug_putstr("Aborted memmap scan (slot_areas 
> >> full)!\n");
> >> +  return 1;
> >> +  }
> >> +  } else {
> >> +  /*
> >> +   * Walk all immovable regions, and filter the intersection
> >> +   * to process_mem_region.
> >> +   */
> >> +  for (i = 0; i < num_immovable_region; i++) {
> >> +  struct mem_vector entry;
> >> +  unsigned long long start, end, select_end, region_end;
> >> +
> >> +  region_end = region.start + region.size - 1;
> >> +  start = immovable_mem[i].start;
> >> +  end = start + immovable_mem[i].size - 1;
> >> +
> >> +  if (region_end < start || region.start > end)
> >> +  continue;
> >> +
> >> +  /* May split one region to several entries. */
> >> +  entry.start = start > region.start ?
> >> +start : region.start;
> >> +  select_end = end > region_end ? region_end : end;
> >> +
> >> +  entry.size = select_end - entry.start + 1;
> >> +
> >> +  process_mem_region(, minimum, image_size);
> >> +
> >> +  if (slot_area_index == MAX_SLOT_AREA) {
> >> +  debug_putstr("Aborted memmap scan (slot_areas 
> >> full)!\n");
> >> +  return 1;
> >> +  }
> >> +  }
> >> +  }
> >> +  return 0;
> >> +}
> >> +
> >>  #ifdef CONFIG_EFI
> >>  /*
> >>   * Returns true if mirror region found (and must have been processed
> >> @@ -699,11 +747,9 @@ process_efi_entries(unsigned long minimum, unsigned 
> >> long image_size)
> >>  
> >>region.start = md->phys_addr;
> >>region.size = md->num_pages << EFI_PAGE_SHIFT;
> >> -  process_mem_region(, minimum, image_size);
> >> -  if (slot_area_index == MAX_SLOT_AREA) {
> >> -  debug_putstr("Aborted EFI scan (slot_areas 

Re: [PATCH v2 2/4] kaslr: select the memory region in immovable node to process

2017-11-13 Thread Baoquan He
On 11/13/17 at 05:18pm, Chao Fan wrote:
> On Mon, Nov 13, 2017 at 04:31:31PM +0800, Baoquan He wrote:
> >On 11/01/17 at 07:32pm, Chao Fan wrote:
> >> Compare the region of memmap entry and immovable_mem, then choose the
> >> intersection to process_mem_region.
> >> 
> >> Since the interrelationship between e820 or efi entries and memory
> >> region in immovable_mem is different:
> >> One memory region in one node may contain several entries of e820 or
> >> efi sometimes, and one entry of e820 or efi may contain the memory in
> >> different nodes sometimes.
> >> It may split one node or one entry to several regions.
> >> 
> >> Signed-off-by: Chao Fan 
> >> ---
> >>  arch/x86/boot/compressed/kaslr.c | 60 
> >> ++--
> >>  1 file changed, 52 insertions(+), 8 deletions(-)
> >> 
> >> diff --git a/arch/x86/boot/compressed/kaslr.c 
> >> b/arch/x86/boot/compressed/kaslr.c
> >> index 0a591c0023f1..fcd640fdeaed 100644
> >> --- a/arch/x86/boot/compressed/kaslr.c
> >> +++ b/arch/x86/boot/compressed/kaslr.c
> >> @@ -634,6 +634,54 @@ static void process_mem_region(struct mem_vector 
> >> *entry,
> >>}
> >>  }
> >>  
> >> +static bool select_immovable_node(struct mem_vector region,
> >> +unsigned long long minimum,
> >> +unsigned long long image_size)
> >> +{
> >
> >About this patch, I just want to notice two things:
> >1) From the current code, 'movable_node' kernel parameter is exclusive.
> >In find_zone_movable_pfns_for_nodes(), you can see that 'kernelcore' and
> >'movablecore' will be ignored as long as 'movable_node' is specified.
> >Please also consider this in your code here. If 'movable_node' has to be
> >specified too, and need skip the kernel mirror handling.
> >
> 
> Thanks for the notice, I will add the similar operation.

No, I meant if movable_node is specified, we have to ignore
'kernelcore=', then we may need skip the kernel mirror handling. Since
kernel mirror is enabled by 'kernelcore=mirror'.


> 
> >2)process_mem_region() is a key function to process the available memory
> >regions. Please don't make another process_mem_region() like below. You
> >can write a small helper function to find the immovable_mem[] which is
> >intersecting with the passed in memory region and use clamp() to get
> >the real available region. You 'REALLY' don't need to split the region
> >in your so called 'select_immovable_node()' function here.
> >
> 
> OK, I will try to make a new method, which is smaller and better to
> filter the regions.
> 
> Thanks,
> Chao Fan
> 
> >PLEASE elaborate more on these details before post.
> >
> >Thanks
> >Baoquan
> >
> >> +  int i;
> >> +
> >> +  /* If no immovable_mem stored, use region directly */
> >> +  if (num_immovable_region == 0) {
> >> +  process_mem_region(, minimum, image_size);
> >> +
> >> +  if (slot_area_index == MAX_SLOT_AREA) {
> >> +  debug_putstr("Aborted memmap scan (slot_areas 
> >> full)!\n");
> >> +  return 1;
> >> +  }
> >> +  } else {
> >> +  /*
> >> +   * Walk all immovable regions, and filter the intersection
> >> +   * to process_mem_region.
> >> +   */
> >> +  for (i = 0; i < num_immovable_region; i++) {
> >> +  struct mem_vector entry;
> >> +  unsigned long long start, end, select_end, region_end;
> >> +
> >> +  region_end = region.start + region.size - 1;
> >> +  start = immovable_mem[i].start;
> >> +  end = start + immovable_mem[i].size - 1;
> >> +
> >> +  if (region_end < start || region.start > end)
> >> +  continue;
> >> +
> >> +  /* May split one region to several entries. */
> >> +  entry.start = start > region.start ?
> >> +start : region.start;
> >> +  select_end = end > region_end ? region_end : end;
> >> +
> >> +  entry.size = select_end - entry.start + 1;
> >> +
> >> +  process_mem_region(, minimum, image_size);
> >> +
> >> +  if (slot_area_index == MAX_SLOT_AREA) {
> >> +  debug_putstr("Aborted memmap scan (slot_areas 
> >> full)!\n");
> >> +  return 1;
> >> +  }
> >> +  }
> >> +  }
> >> +  return 0;
> >> +}
> >> +
> >>  #ifdef CONFIG_EFI
> >>  /*
> >>   * Returns true if mirror region found (and must have been processed
> >> @@ -699,11 +747,9 @@ process_efi_entries(unsigned long minimum, unsigned 
> >> long image_size)
> >>  
> >>region.start = md->phys_addr;
> >>region.size = md->num_pages << EFI_PAGE_SHIFT;
> >> -  process_mem_region(, minimum, image_size);
> >> -  if (slot_area_index == MAX_SLOT_AREA) {
> >> -  debug_putstr("Aborted EFI scan (slot_areas full)!\n");
> >> +
> >> +  

Re: [PATCH v2 2/4] kaslr: select the memory region in immovable node to process

2017-11-13 Thread Chao Fan
On Mon, Nov 13, 2017 at 04:31:31PM +0800, Baoquan He wrote:
>On 11/01/17 at 07:32pm, Chao Fan wrote:
>> Compare the region of memmap entry and immovable_mem, then choose the
>> intersection to process_mem_region.
>> 
>> Since the interrelationship between e820 or efi entries and memory
>> region in immovable_mem is different:
>> One memory region in one node may contain several entries of e820 or
>> efi sometimes, and one entry of e820 or efi may contain the memory in
>> different nodes sometimes.
>> It may split one node or one entry to several regions.
>> 
>> Signed-off-by: Chao Fan 
>> ---
>>  arch/x86/boot/compressed/kaslr.c | 60 
>> ++--
>>  1 file changed, 52 insertions(+), 8 deletions(-)
>> 
>> diff --git a/arch/x86/boot/compressed/kaslr.c 
>> b/arch/x86/boot/compressed/kaslr.c
>> index 0a591c0023f1..fcd640fdeaed 100644
>> --- a/arch/x86/boot/compressed/kaslr.c
>> +++ b/arch/x86/boot/compressed/kaslr.c
>> @@ -634,6 +634,54 @@ static void process_mem_region(struct mem_vector *entry,
>>  }
>>  }
>>  
>> +static bool select_immovable_node(struct mem_vector region,
>> +  unsigned long long minimum,
>> +  unsigned long long image_size)
>> +{
>
>About this patch, I just want to notice two things:
>1) From the current code, 'movable_node' kernel parameter is exclusive.
>In find_zone_movable_pfns_for_nodes(), you can see that 'kernelcore' and
>'movablecore' will be ignored as long as 'movable_node' is specified.
>Please also consider this in your code here. If 'movable_node' has to be
>specified too, and need skip the kernel mirror handling.
>

Thanks for the notice, I will add the similar operation.

>2)process_mem_region() is a key function to process the available memory
>regions. Please don't make another process_mem_region() like below. You
>can write a small helper function to find the immovable_mem[] which is
>intersecting with the passed in memory region and use clamp() to get
>the real available region. You 'REALLY' don't need to split the region
>in your so called 'select_immovable_node()' function here.
>

OK, I will try to make a new method, which is smaller and better to
filter the regions.

Thanks,
Chao Fan

>PLEASE elaborate more on these details before post.
>
>Thanks
>Baoquan
>
>> +int i;
>> +
>> +/* If no immovable_mem stored, use region directly */
>> +if (num_immovable_region == 0) {
>> +process_mem_region(, minimum, image_size);
>> +
>> +if (slot_area_index == MAX_SLOT_AREA) {
>> +debug_putstr("Aborted memmap scan (slot_areas 
>> full)!\n");
>> +return 1;
>> +}
>> +} else {
>> +/*
>> + * Walk all immovable regions, and filter the intersection
>> + * to process_mem_region.
>> + */
>> +for (i = 0; i < num_immovable_region; i++) {
>> +struct mem_vector entry;
>> +unsigned long long start, end, select_end, region_end;
>> +
>> +region_end = region.start + region.size - 1;
>> +start = immovable_mem[i].start;
>> +end = start + immovable_mem[i].size - 1;
>> +
>> +if (region_end < start || region.start > end)
>> +continue;
>> +
>> +/* May split one region to several entries. */
>> +entry.start = start > region.start ?
>> +  start : region.start;
>> +select_end = end > region_end ? region_end : end;
>> +
>> +entry.size = select_end - entry.start + 1;
>> +
>> +process_mem_region(, minimum, image_size);
>> +
>> +if (slot_area_index == MAX_SLOT_AREA) {
>> +debug_putstr("Aborted memmap scan (slot_areas 
>> full)!\n");
>> +return 1;
>> +}
>> +}
>> +}
>> +return 0;
>> +}
>> +
>>  #ifdef CONFIG_EFI
>>  /*
>>   * Returns true if mirror region found (and must have been processed
>> @@ -699,11 +747,9 @@ process_efi_entries(unsigned long minimum, unsigned 
>> long image_size)
>>  
>>  region.start = md->phys_addr;
>>  region.size = md->num_pages << EFI_PAGE_SHIFT;
>> -process_mem_region(, minimum, image_size);
>> -if (slot_area_index == MAX_SLOT_AREA) {
>> -debug_putstr("Aborted EFI scan (slot_areas full)!\n");
>> +
>> +if (select_immovable_node(region, minimum, image_size))
>>  break;
>> -}
>>  }
>>  return true;
>>  }
>> @@ -730,11 +776,9 @@ static void process_e820_entries(unsigned long minimum,
>>  continue;
>>  region.start = entry->addr;
>>  region.size = entry->size;
>> -   

Re: [PATCH v2 2/4] kaslr: select the memory region in immovable node to process

2017-11-13 Thread Chao Fan
On Mon, Nov 13, 2017 at 04:31:31PM +0800, Baoquan He wrote:
>On 11/01/17 at 07:32pm, Chao Fan wrote:
>> Compare the region of memmap entry and immovable_mem, then choose the
>> intersection to process_mem_region.
>> 
>> Since the interrelationship between e820 or efi entries and memory
>> region in immovable_mem is different:
>> One memory region in one node may contain several entries of e820 or
>> efi sometimes, and one entry of e820 or efi may contain the memory in
>> different nodes sometimes.
>> It may split one node or one entry to several regions.
>> 
>> Signed-off-by: Chao Fan 
>> ---
>>  arch/x86/boot/compressed/kaslr.c | 60 
>> ++--
>>  1 file changed, 52 insertions(+), 8 deletions(-)
>> 
>> diff --git a/arch/x86/boot/compressed/kaslr.c 
>> b/arch/x86/boot/compressed/kaslr.c
>> index 0a591c0023f1..fcd640fdeaed 100644
>> --- a/arch/x86/boot/compressed/kaslr.c
>> +++ b/arch/x86/boot/compressed/kaslr.c
>> @@ -634,6 +634,54 @@ static void process_mem_region(struct mem_vector *entry,
>>  }
>>  }
>>  
>> +static bool select_immovable_node(struct mem_vector region,
>> +  unsigned long long minimum,
>> +  unsigned long long image_size)
>> +{
>
>About this patch, I just want to notice two things:
>1) From the current code, 'movable_node' kernel parameter is exclusive.
>In find_zone_movable_pfns_for_nodes(), you can see that 'kernelcore' and
>'movablecore' will be ignored as long as 'movable_node' is specified.
>Please also consider this in your code here. If 'movable_node' has to be
>specified too, and need skip the kernel mirror handling.
>

Thanks for the notice, I will add the similar operation.

>2)process_mem_region() is a key function to process the available memory
>regions. Please don't make another process_mem_region() like below. You
>can write a small helper function to find the immovable_mem[] which is
>intersecting with the passed in memory region and use clamp() to get
>the real available region. You 'REALLY' don't need to split the region
>in your so called 'select_immovable_node()' function here.
>

OK, I will try to make a new method, which is smaller and better to
filter the regions.

Thanks,
Chao Fan

>PLEASE elaborate more on these details before post.
>
>Thanks
>Baoquan
>
>> +int i;
>> +
>> +/* If no immovable_mem stored, use region directly */
>> +if (num_immovable_region == 0) {
>> +process_mem_region(, minimum, image_size);
>> +
>> +if (slot_area_index == MAX_SLOT_AREA) {
>> +debug_putstr("Aborted memmap scan (slot_areas 
>> full)!\n");
>> +return 1;
>> +}
>> +} else {
>> +/*
>> + * Walk all immovable regions, and filter the intersection
>> + * to process_mem_region.
>> + */
>> +for (i = 0; i < num_immovable_region; i++) {
>> +struct mem_vector entry;
>> +unsigned long long start, end, select_end, region_end;
>> +
>> +region_end = region.start + region.size - 1;
>> +start = immovable_mem[i].start;
>> +end = start + immovable_mem[i].size - 1;
>> +
>> +if (region_end < start || region.start > end)
>> +continue;
>> +
>> +/* May split one region to several entries. */
>> +entry.start = start > region.start ?
>> +  start : region.start;
>> +select_end = end > region_end ? region_end : end;
>> +
>> +entry.size = select_end - entry.start + 1;
>> +
>> +process_mem_region(, minimum, image_size);
>> +
>> +if (slot_area_index == MAX_SLOT_AREA) {
>> +debug_putstr("Aborted memmap scan (slot_areas 
>> full)!\n");
>> +return 1;
>> +}
>> +}
>> +}
>> +return 0;
>> +}
>> +
>>  #ifdef CONFIG_EFI
>>  /*
>>   * Returns true if mirror region found (and must have been processed
>> @@ -699,11 +747,9 @@ process_efi_entries(unsigned long minimum, unsigned 
>> long image_size)
>>  
>>  region.start = md->phys_addr;
>>  region.size = md->num_pages << EFI_PAGE_SHIFT;
>> -process_mem_region(, minimum, image_size);
>> -if (slot_area_index == MAX_SLOT_AREA) {
>> -debug_putstr("Aborted EFI scan (slot_areas full)!\n");
>> +
>> +if (select_immovable_node(region, minimum, image_size))
>>  break;
>> -}
>>  }
>>  return true;
>>  }
>> @@ -730,11 +776,9 @@ static void process_e820_entries(unsigned long minimum,
>>  continue;
>>  region.start = entry->addr;
>>  region.size = entry->size;
>> -process_mem_region(, 

Re: [PATCH v2 2/4] kaslr: select the memory region in immovable node to process

2017-11-13 Thread Baoquan He
On 11/01/17 at 07:32pm, Chao Fan wrote:
> Compare the region of memmap entry and immovable_mem, then choose the
> intersection to process_mem_region.
> 
> Since the interrelationship between e820 or efi entries and memory
> region in immovable_mem is different:
> One memory region in one node may contain several entries of e820 or
> efi sometimes, and one entry of e820 or efi may contain the memory in
> different nodes sometimes.
> It may split one node or one entry to several regions.
> 
> Signed-off-by: Chao Fan 
> ---
>  arch/x86/boot/compressed/kaslr.c | 60 
> ++--
>  1 file changed, 52 insertions(+), 8 deletions(-)
> 
> diff --git a/arch/x86/boot/compressed/kaslr.c 
> b/arch/x86/boot/compressed/kaslr.c
> index 0a591c0023f1..fcd640fdeaed 100644
> --- a/arch/x86/boot/compressed/kaslr.c
> +++ b/arch/x86/boot/compressed/kaslr.c
> @@ -634,6 +634,54 @@ static void process_mem_region(struct mem_vector *entry,
>   }
>  }
>  
> +static bool select_immovable_node(struct mem_vector region,
> +   unsigned long long minimum,
> +   unsigned long long image_size)
> +{

About this patch, I just want to notice two things:
1) From the current code, 'movable_node' kernel parameter is exclusive.
In find_zone_movable_pfns_for_nodes(), you can see that 'kernelcore' and
'movablecore' will be ignored as long as 'movable_node' is specified.
Please also consider this in your code here. If 'movable_node' has to be
specified too, and need skip the kernel mirror handling.

2)process_mem_region() is a key function to process the available memory
regions. Please don't make another process_mem_region() like below. You
can write a small helper function to find the immovable_mem[] which is
intersecting with the passed in memory region and use clamp() to get
the real available region. You 'REALLY' don't need to split the region
in your so called 'select_immovable_node()' function here.

PLEASE elaborate more on these details before post.

Thanks
Baoquan

> + int i;
> +
> + /* If no immovable_mem stored, use region directly */
> + if (num_immovable_region == 0) {
> + process_mem_region(, minimum, image_size);
> +
> + if (slot_area_index == MAX_SLOT_AREA) {
> + debug_putstr("Aborted memmap scan (slot_areas 
> full)!\n");
> + return 1;
> + }
> + } else {
> + /*
> +  * Walk all immovable regions, and filter the intersection
> +  * to process_mem_region.
> +  */
> + for (i = 0; i < num_immovable_region; i++) {
> + struct mem_vector entry;
> + unsigned long long start, end, select_end, region_end;
> +
> + region_end = region.start + region.size - 1;
> + start = immovable_mem[i].start;
> + end = start + immovable_mem[i].size - 1;
> +
> + if (region_end < start || region.start > end)
> + continue;
> +
> + /* May split one region to several entries. */
> + entry.start = start > region.start ?
> +   start : region.start;
> + select_end = end > region_end ? region_end : end;
> +
> + entry.size = select_end - entry.start + 1;
> +
> + process_mem_region(, minimum, image_size);
> +
> + if (slot_area_index == MAX_SLOT_AREA) {
> + debug_putstr("Aborted memmap scan (slot_areas 
> full)!\n");
> + return 1;
> + }
> + }
> + }
> + return 0;
> +}
> +
>  #ifdef CONFIG_EFI
>  /*
>   * Returns true if mirror region found (and must have been processed
> @@ -699,11 +747,9 @@ process_efi_entries(unsigned long minimum, unsigned long 
> image_size)
>  
>   region.start = md->phys_addr;
>   region.size = md->num_pages << EFI_PAGE_SHIFT;
> - process_mem_region(, minimum, image_size);
> - if (slot_area_index == MAX_SLOT_AREA) {
> - debug_putstr("Aborted EFI scan (slot_areas full)!\n");
> +
> + if (select_immovable_node(region, minimum, image_size))
>   break;
> - }
>   }
>   return true;
>  }
> @@ -730,11 +776,9 @@ static void process_e820_entries(unsigned long minimum,
>   continue;
>   region.start = entry->addr;
>   region.size = entry->size;
> - process_mem_region(, minimum, image_size);
> - if (slot_area_index == MAX_SLOT_AREA) {
> - debug_putstr("Aborted e820 scan (slot_areas full)!\n");
> +
> + if (select_immovable_node(region, minimum, image_size))
>   break;
> - 

Re: [PATCH v2 2/4] kaslr: select the memory region in immovable node to process

2017-11-13 Thread Baoquan He
On 11/01/17 at 07:32pm, Chao Fan wrote:
> Compare the region of memmap entry and immovable_mem, then choose the
> intersection to process_mem_region.
> 
> Since the interrelationship between e820 or efi entries and memory
> region in immovable_mem is different:
> One memory region in one node may contain several entries of e820 or
> efi sometimes, and one entry of e820 or efi may contain the memory in
> different nodes sometimes.
> It may split one node or one entry to several regions.
> 
> Signed-off-by: Chao Fan 
> ---
>  arch/x86/boot/compressed/kaslr.c | 60 
> ++--
>  1 file changed, 52 insertions(+), 8 deletions(-)
> 
> diff --git a/arch/x86/boot/compressed/kaslr.c 
> b/arch/x86/boot/compressed/kaslr.c
> index 0a591c0023f1..fcd640fdeaed 100644
> --- a/arch/x86/boot/compressed/kaslr.c
> +++ b/arch/x86/boot/compressed/kaslr.c
> @@ -634,6 +634,54 @@ static void process_mem_region(struct mem_vector *entry,
>   }
>  }
>  
> +static bool select_immovable_node(struct mem_vector region,
> +   unsigned long long minimum,
> +   unsigned long long image_size)
> +{

About this patch, I just want to notice two things:
1) From the current code, 'movable_node' kernel parameter is exclusive.
In find_zone_movable_pfns_for_nodes(), you can see that 'kernelcore' and
'movablecore' will be ignored as long as 'movable_node' is specified.
Please also consider this in your code here. If 'movable_node' has to be
specified too, and need skip the kernel mirror handling.

2)process_mem_region() is a key function to process the available memory
regions. Please don't make another process_mem_region() like below. You
can write a small helper function to find the immovable_mem[] which is
intersecting with the passed in memory region and use clamp() to get
the real available region. You 'REALLY' don't need to split the region
in your so called 'select_immovable_node()' function here.

PLEASE elaborate more on these details before post.

Thanks
Baoquan

> + int i;
> +
> + /* If no immovable_mem stored, use region directly */
> + if (num_immovable_region == 0) {
> + process_mem_region(, minimum, image_size);
> +
> + if (slot_area_index == MAX_SLOT_AREA) {
> + debug_putstr("Aborted memmap scan (slot_areas 
> full)!\n");
> + return 1;
> + }
> + } else {
> + /*
> +  * Walk all immovable regions, and filter the intersection
> +  * to process_mem_region.
> +  */
> + for (i = 0; i < num_immovable_region; i++) {
> + struct mem_vector entry;
> + unsigned long long start, end, select_end, region_end;
> +
> + region_end = region.start + region.size - 1;
> + start = immovable_mem[i].start;
> + end = start + immovable_mem[i].size - 1;
> +
> + if (region_end < start || region.start > end)
> + continue;
> +
> + /* May split one region to several entries. */
> + entry.start = start > region.start ?
> +   start : region.start;
> + select_end = end > region_end ? region_end : end;
> +
> + entry.size = select_end - entry.start + 1;
> +
> + process_mem_region(, minimum, image_size);
> +
> + if (slot_area_index == MAX_SLOT_AREA) {
> + debug_putstr("Aborted memmap scan (slot_areas 
> full)!\n");
> + return 1;
> + }
> + }
> + }
> + return 0;
> +}
> +
>  #ifdef CONFIG_EFI
>  /*
>   * Returns true if mirror region found (and must have been processed
> @@ -699,11 +747,9 @@ process_efi_entries(unsigned long minimum, unsigned long 
> image_size)
>  
>   region.start = md->phys_addr;
>   region.size = md->num_pages << EFI_PAGE_SHIFT;
> - process_mem_region(, minimum, image_size);
> - if (slot_area_index == MAX_SLOT_AREA) {
> - debug_putstr("Aborted EFI scan (slot_areas full)!\n");
> +
> + if (select_immovable_node(region, minimum, image_size))
>   break;
> - }
>   }
>   return true;
>  }
> @@ -730,11 +776,9 @@ static void process_e820_entries(unsigned long minimum,
>   continue;
>   region.start = entry->addr;
>   region.size = entry->size;
> - process_mem_region(, minimum, image_size);
> - if (slot_area_index == MAX_SLOT_AREA) {
> - debug_putstr("Aborted e820 scan (slot_areas full)!\n");
> +
> + if (select_immovable_node(region, minimum, image_size))
>   break;
> - }
>   }
>  }

Re: [PATCH v2 2/4] kaslr: select the memory region in immovable node to process

2017-11-09 Thread Chao Fan
On Fri, Nov 10, 2017 at 11:14:37AM +0800, Baoquan He wrote:
>On 11/10/17 at 11:03am, Chao Fan wrote:
>> On Thu, Nov 09, 2017 at 04:21:32PM +0800, Baoquan He wrote:
>> >Hi Chao,
>> >
>> >On 11/01/17 at 07:32pm, Chao Fan wrote:
>> >> Compare the region of memmap entry and immovable_mem, then choose the
>> >> intersection to process_mem_region.
>> >> 
>> >> Since the interrelationship between e820 or efi entries and memory
>> >> region in immovable_mem is different:
>> >
>> >Could you paste a bootlog with efi=debug specified in cmdline on the
>> >system you tested? I want to check what kind of intersection between
>> >them. The adding makes code pretty ugly, want to make sure if we have
>> >to do like this.
>> Hi Baoquan,
>> 
>> Here is a machine with efi.
>

Here is a log for e820, also 10 nodes in this machine.

Thanks,
Chao Fan

>Thanks, do you have the whole boot log? I want to have a look at e820.
>And this is a special system, or a customized system? I mean you just
>customize the firmware for better testing to cover kinds of cases.
>
>If it's too big, please attach it and send to me privately.
>
>Anyway, seems your considering about the intersection is right.
>
>Thanks
>Baoquan
>> 
>> The memory information in SRAT from dmesg:
>> [0.00] ACPI: SRAT: Node 0 PXM 0 [mem 0x-0x0009]
>> [0.00] ACPI: SRAT: Node 0 PXM 0 [mem 0x0010-0x1f3f]
>> [0.00] ACPI: SRAT: Node 1 PXM 1 [mem 0x1f40-0x3e7f]
>> [0.00] ACPI: SRAT: Node 2 PXM 2 [mem 0x3e80-0x5dbf]
>> [0.00] ACPI: SRAT: Node 3 PXM 3 [mem 0x5dc0-0x7cff]
>> [0.00] ACPI: SRAT: Node 4 PXM 4 [mem 0x7d00-0x9c3f]
>> [0.00] ACPI: SRAT: Node 5 PXM 5 [mem 0x9c40-0xbb7f]
>> [0.00] ACPI: SRAT: Node 6 PXM 6 [mem 0xbb80-0xbfff]
>> [0.00] ACPI: SRAT: Node 6 PXM 6 [mem 0x1-0x11abf]
>> [0.00] ACPI: SRAT: Node 7 PXM 7 [mem 0x11ac0-0x139ff]
>> [0.00] ACPI: SRAT: Node 8 PXM 8 [mem 0x13a00-0x1593f]
>> [0.00] ACPI: SRAT: Node 9 PXM 9 [mem 0x15940-0x1787f]
>> 
>> There are 10 nodes, and 500M memory in every node.
>> And node0 and node 6 has two parts.
>> 
>> 
>> Here is the efi mem:
>> [0.00] efi: mem00: [Boot Code  |   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x-0x0fff] (0MB)
>> [0.00] efi: mem01: [Loader Data|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x1000-0x1fff] (0MB)
>> [0.00] efi: mem02: [Conventional Memory|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x2000-0x0009] (0MB)
>> [0.00] efi: mem03: [Conventional Memory|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x0010-0x00805fff] (7MB)
>> [0.00] efi: mem04: [Boot Data  |   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x00806000-0x00806fff] (0MB)
>> [0.00] efi: mem05: [Conventional Memory|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x00807000-0x0081] (0MB)
>> [0.00] efi: mem06: [Boot Data  |   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x0082-0x012f] (10MB)
>> [0.00] efi: mem07: [Conventional Memory|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x0130-0x01ff] (13MB)
>> [0.00] efi: mem08: [Loader Data|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x0200-0x036e3fff] (22MB)
>> (From mem00 to mem08, belongs to node0)
>> [0.00] efi: mem09: [Conventional Memory|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x036e4000-0x3d626fff] (927MB)
>> (mem09 has part of node0 and part of node1, but not the whole of node0 and 
>> node1)
>> [0.00] efi: mem10: [Loader Data|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x3d627000-0x3fff] (41MB)
>> (part of node1 and part of node2)
>> [0.00] efi: mem11: [Conventional Memory|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x4000-0x8c92dfff] (1225MB)
>> [0.00] efi: mem12: [Loader Data|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x8c92e000-0xbbfbdfff] (758MB)
>> [0.00] efi: mem13: [Boot Data  |   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0xbbfbe000-0xbbfddfff] (0MB)
>> [0.00] efi: mem14: [Conventional Memory|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0xbbfde000-0xbe350fff] (35MB)
>> [0.00] efi: mem15: [Loader Data|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0xbe351000-0xbe579fff] (2MB)
>> [0.00] efi: mem16: [Loader Code|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0xbe57a000-0xbe6a0fff] (1MB)
>> [0.00] efi: mem17: [Boot Data  |   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] 

Re: [PATCH v2 2/4] kaslr: select the memory region in immovable node to process

2017-11-09 Thread Chao Fan
On Fri, Nov 10, 2017 at 11:14:37AM +0800, Baoquan He wrote:
>On 11/10/17 at 11:03am, Chao Fan wrote:
>> On Thu, Nov 09, 2017 at 04:21:32PM +0800, Baoquan He wrote:
>> >Hi Chao,
>> >
>> >On 11/01/17 at 07:32pm, Chao Fan wrote:
>> >> Compare the region of memmap entry and immovable_mem, then choose the
>> >> intersection to process_mem_region.
>> >> 
>> >> Since the interrelationship between e820 or efi entries and memory
>> >> region in immovable_mem is different:
>> >
>> >Could you paste a bootlog with efi=debug specified in cmdline on the
>> >system you tested? I want to check what kind of intersection between
>> >them. The adding makes code pretty ugly, want to make sure if we have
>> >to do like this.
>> Hi Baoquan,
>> 
>> Here is a machine with efi.
>

Here is a log for e820, also 10 nodes in this machine.

Thanks,
Chao Fan

>Thanks, do you have the whole boot log? I want to have a look at e820.
>And this is a special system, or a customized system? I mean you just
>customize the firmware for better testing to cover kinds of cases.
>
>If it's too big, please attach it and send to me privately.
>
>Anyway, seems your considering about the intersection is right.
>
>Thanks
>Baoquan
>> 
>> The memory information in SRAT from dmesg:
>> [0.00] ACPI: SRAT: Node 0 PXM 0 [mem 0x-0x0009]
>> [0.00] ACPI: SRAT: Node 0 PXM 0 [mem 0x0010-0x1f3f]
>> [0.00] ACPI: SRAT: Node 1 PXM 1 [mem 0x1f40-0x3e7f]
>> [0.00] ACPI: SRAT: Node 2 PXM 2 [mem 0x3e80-0x5dbf]
>> [0.00] ACPI: SRAT: Node 3 PXM 3 [mem 0x5dc0-0x7cff]
>> [0.00] ACPI: SRAT: Node 4 PXM 4 [mem 0x7d00-0x9c3f]
>> [0.00] ACPI: SRAT: Node 5 PXM 5 [mem 0x9c40-0xbb7f]
>> [0.00] ACPI: SRAT: Node 6 PXM 6 [mem 0xbb80-0xbfff]
>> [0.00] ACPI: SRAT: Node 6 PXM 6 [mem 0x1-0x11abf]
>> [0.00] ACPI: SRAT: Node 7 PXM 7 [mem 0x11ac0-0x139ff]
>> [0.00] ACPI: SRAT: Node 8 PXM 8 [mem 0x13a00-0x1593f]
>> [0.00] ACPI: SRAT: Node 9 PXM 9 [mem 0x15940-0x1787f]
>> 
>> There are 10 nodes, and 500M memory in every node.
>> And node0 and node 6 has two parts.
>> 
>> 
>> Here is the efi mem:
>> [0.00] efi: mem00: [Boot Code  |   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x-0x0fff] (0MB)
>> [0.00] efi: mem01: [Loader Data|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x1000-0x1fff] (0MB)
>> [0.00] efi: mem02: [Conventional Memory|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x2000-0x0009] (0MB)
>> [0.00] efi: mem03: [Conventional Memory|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x0010-0x00805fff] (7MB)
>> [0.00] efi: mem04: [Boot Data  |   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x00806000-0x00806fff] (0MB)
>> [0.00] efi: mem05: [Conventional Memory|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x00807000-0x0081] (0MB)
>> [0.00] efi: mem06: [Boot Data  |   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x0082-0x012f] (10MB)
>> [0.00] efi: mem07: [Conventional Memory|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x0130-0x01ff] (13MB)
>> [0.00] efi: mem08: [Loader Data|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x0200-0x036e3fff] (22MB)
>> (From mem00 to mem08, belongs to node0)
>> [0.00] efi: mem09: [Conventional Memory|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x036e4000-0x3d626fff] (927MB)
>> (mem09 has part of node0 and part of node1, but not the whole of node0 and 
>> node1)
>> [0.00] efi: mem10: [Loader Data|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x3d627000-0x3fff] (41MB)
>> (part of node1 and part of node2)
>> [0.00] efi: mem11: [Conventional Memory|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x4000-0x8c92dfff] (1225MB)
>> [0.00] efi: mem12: [Loader Data|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x8c92e000-0xbbfbdfff] (758MB)
>> [0.00] efi: mem13: [Boot Data  |   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0xbbfbe000-0xbbfddfff] (0MB)
>> [0.00] efi: mem14: [Conventional Memory|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0xbbfde000-0xbe350fff] (35MB)
>> [0.00] efi: mem15: [Loader Data|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0xbe351000-0xbe579fff] (2MB)
>> [0.00] efi: mem16: [Loader Code|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0xbe57a000-0xbe6a0fff] (1MB)
>> [0.00] efi: mem17: [Boot Data  |   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] 

Re: [PATCH v2 2/4] kaslr: select the memory region in immovable node to process

2017-11-09 Thread Chao Fan
On Fri, Nov 10, 2017 at 11:14:37AM +0800, Baoquan He wrote:
>On 11/10/17 at 11:03am, Chao Fan wrote:
>> On Thu, Nov 09, 2017 at 04:21:32PM +0800, Baoquan He wrote:
>> >Hi Chao,
>> >
>> >On 11/01/17 at 07:32pm, Chao Fan wrote:
>> >> Compare the region of memmap entry and immovable_mem, then choose the
>> >> intersection to process_mem_region.
>> >> 
>> >> Since the interrelationship between e820 or efi entries and memory
>> >> region in immovable_mem is different:
>> >
>> >Could you paste a bootlog with efi=debug specified in cmdline on the
>> >system you tested? I want to check what kind of intersection between
>> >them. The adding makes code pretty ugly, want to make sure if we have
>> >to do like this.
>> Hi Baoquan,
>> 
>> Here is a machine with efi.
>
>Thanks, do you have the whole boot log? I want to have a look at e820.

No problem, I will paste the whole in attach file.

>And this is a special system, or a customized system? I mean you just

It's a qemu machine, in which I can make more nodes to test.
I have no suitable host machine available in my hand.

>customize the firmware for better testing to cover kinds of cases.

Although the code may be a little ugly, after comparing the
different memory regions, this method and logic are better to
cover more cases.
If you have some ideas to improve the code. Thank you very much!

Thanks,
Chao Fan

>
>If it's too big, please attach it and send to me privately.
>
>Anyway, seems your considering about the intersection is right.
>
>Thanks
>Baoquan
>> 
>> The memory information in SRAT from dmesg:
>> [0.00] ACPI: SRAT: Node 0 PXM 0 [mem 0x-0x0009]
>> [0.00] ACPI: SRAT: Node 0 PXM 0 [mem 0x0010-0x1f3f]
>> [0.00] ACPI: SRAT: Node 1 PXM 1 [mem 0x1f40-0x3e7f]
>> [0.00] ACPI: SRAT: Node 2 PXM 2 [mem 0x3e80-0x5dbf]
>> [0.00] ACPI: SRAT: Node 3 PXM 3 [mem 0x5dc0-0x7cff]
>> [0.00] ACPI: SRAT: Node 4 PXM 4 [mem 0x7d00-0x9c3f]
>> [0.00] ACPI: SRAT: Node 5 PXM 5 [mem 0x9c40-0xbb7f]
>> [0.00] ACPI: SRAT: Node 6 PXM 6 [mem 0xbb80-0xbfff]
>> [0.00] ACPI: SRAT: Node 6 PXM 6 [mem 0x1-0x11abf]
>> [0.00] ACPI: SRAT: Node 7 PXM 7 [mem 0x11ac0-0x139ff]
>> [0.00] ACPI: SRAT: Node 8 PXM 8 [mem 0x13a00-0x1593f]
>> [0.00] ACPI: SRAT: Node 9 PXM 9 [mem 0x15940-0x1787f]
>> 
>> There are 10 nodes, and 500M memory in every node.
>> And node0 and node 6 has two parts.
>> 
>> 
>> Here is the efi mem:
>> [0.00] efi: mem00: [Boot Code  |   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x-0x0fff] (0MB)
>> [0.00] efi: mem01: [Loader Data|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x1000-0x1fff] (0MB)
>> [0.00] efi: mem02: [Conventional Memory|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x2000-0x0009] (0MB)
>> [0.00] efi: mem03: [Conventional Memory|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x0010-0x00805fff] (7MB)
>> [0.00] efi: mem04: [Boot Data  |   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x00806000-0x00806fff] (0MB)
>> [0.00] efi: mem05: [Conventional Memory|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x00807000-0x0081] (0MB)
>> [0.00] efi: mem06: [Boot Data  |   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x0082-0x012f] (10MB)
>> [0.00] efi: mem07: [Conventional Memory|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x0130-0x01ff] (13MB)
>> [0.00] efi: mem08: [Loader Data|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x0200-0x036e3fff] (22MB)
>> (From mem00 to mem08, belongs to node0)
>> [0.00] efi: mem09: [Conventional Memory|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x036e4000-0x3d626fff] (927MB)
>> (mem09 has part of node0 and part of node1, but not the whole of node0 and 
>> node1)
>> [0.00] efi: mem10: [Loader Data|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x3d627000-0x3fff] (41MB)
>> (part of node1 and part of node2)
>> [0.00] efi: mem11: [Conventional Memory|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x4000-0x8c92dfff] (1225MB)
>> [0.00] efi: mem12: [Loader Data|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x8c92e000-0xbbfbdfff] (758MB)
>> [0.00] efi: mem13: [Boot Data  |   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0xbbfbe000-0xbbfddfff] (0MB)
>> [0.00] efi: mem14: [Conventional Memory|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0xbbfde000-0xbe350fff] (35MB)
>> [0.00] efi: mem15: [Loader Data|   |  |  |  |  | 

Re: [PATCH v2 2/4] kaslr: select the memory region in immovable node to process

2017-11-09 Thread Chao Fan
On Fri, Nov 10, 2017 at 11:14:37AM +0800, Baoquan He wrote:
>On 11/10/17 at 11:03am, Chao Fan wrote:
>> On Thu, Nov 09, 2017 at 04:21:32PM +0800, Baoquan He wrote:
>> >Hi Chao,
>> >
>> >On 11/01/17 at 07:32pm, Chao Fan wrote:
>> >> Compare the region of memmap entry and immovable_mem, then choose the
>> >> intersection to process_mem_region.
>> >> 
>> >> Since the interrelationship between e820 or efi entries and memory
>> >> region in immovable_mem is different:
>> >
>> >Could you paste a bootlog with efi=debug specified in cmdline on the
>> >system you tested? I want to check what kind of intersection between
>> >them. The adding makes code pretty ugly, want to make sure if we have
>> >to do like this.
>> Hi Baoquan,
>> 
>> Here is a machine with efi.
>
>Thanks, do you have the whole boot log? I want to have a look at e820.

No problem, I will paste the whole in attach file.

>And this is a special system, or a customized system? I mean you just

It's a qemu machine, in which I can make more nodes to test.
I have no suitable host machine available in my hand.

>customize the firmware for better testing to cover kinds of cases.

Although the code may be a little ugly, after comparing the
different memory regions, this method and logic are better to
cover more cases.
If you have some ideas to improve the code. Thank you very much!

Thanks,
Chao Fan

>
>If it's too big, please attach it and send to me privately.
>
>Anyway, seems your considering about the intersection is right.
>
>Thanks
>Baoquan
>> 
>> The memory information in SRAT from dmesg:
>> [0.00] ACPI: SRAT: Node 0 PXM 0 [mem 0x-0x0009]
>> [0.00] ACPI: SRAT: Node 0 PXM 0 [mem 0x0010-0x1f3f]
>> [0.00] ACPI: SRAT: Node 1 PXM 1 [mem 0x1f40-0x3e7f]
>> [0.00] ACPI: SRAT: Node 2 PXM 2 [mem 0x3e80-0x5dbf]
>> [0.00] ACPI: SRAT: Node 3 PXM 3 [mem 0x5dc0-0x7cff]
>> [0.00] ACPI: SRAT: Node 4 PXM 4 [mem 0x7d00-0x9c3f]
>> [0.00] ACPI: SRAT: Node 5 PXM 5 [mem 0x9c40-0xbb7f]
>> [0.00] ACPI: SRAT: Node 6 PXM 6 [mem 0xbb80-0xbfff]
>> [0.00] ACPI: SRAT: Node 6 PXM 6 [mem 0x1-0x11abf]
>> [0.00] ACPI: SRAT: Node 7 PXM 7 [mem 0x11ac0-0x139ff]
>> [0.00] ACPI: SRAT: Node 8 PXM 8 [mem 0x13a00-0x1593f]
>> [0.00] ACPI: SRAT: Node 9 PXM 9 [mem 0x15940-0x1787f]
>> 
>> There are 10 nodes, and 500M memory in every node.
>> And node0 and node 6 has two parts.
>> 
>> 
>> Here is the efi mem:
>> [0.00] efi: mem00: [Boot Code  |   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x-0x0fff] (0MB)
>> [0.00] efi: mem01: [Loader Data|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x1000-0x1fff] (0MB)
>> [0.00] efi: mem02: [Conventional Memory|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x2000-0x0009] (0MB)
>> [0.00] efi: mem03: [Conventional Memory|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x0010-0x00805fff] (7MB)
>> [0.00] efi: mem04: [Boot Data  |   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x00806000-0x00806fff] (0MB)
>> [0.00] efi: mem05: [Conventional Memory|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x00807000-0x0081] (0MB)
>> [0.00] efi: mem06: [Boot Data  |   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x0082-0x012f] (10MB)
>> [0.00] efi: mem07: [Conventional Memory|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x0130-0x01ff] (13MB)
>> [0.00] efi: mem08: [Loader Data|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x0200-0x036e3fff] (22MB)
>> (From mem00 to mem08, belongs to node0)
>> [0.00] efi: mem09: [Conventional Memory|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x036e4000-0x3d626fff] (927MB)
>> (mem09 has part of node0 and part of node1, but not the whole of node0 and 
>> node1)
>> [0.00] efi: mem10: [Loader Data|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x3d627000-0x3fff] (41MB)
>> (part of node1 and part of node2)
>> [0.00] efi: mem11: [Conventional Memory|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x4000-0x8c92dfff] (1225MB)
>> [0.00] efi: mem12: [Loader Data|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0x8c92e000-0xbbfbdfff] (758MB)
>> [0.00] efi: mem13: [Boot Data  |   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0xbbfbe000-0xbbfddfff] (0MB)
>> [0.00] efi: mem14: [Conventional Memory|   |  |  |  |  |  |  |   
>> |WB|WT|WC|UC] range=[0xbbfde000-0xbe350fff] (35MB)
>> [0.00] efi: mem15: [Loader Data|   |  |  |  |  | 

Re: [PATCH v2 2/4] kaslr: select the memory region in immovable node to process

2017-11-09 Thread Baoquan He
On 11/10/17 at 11:03am, Chao Fan wrote:
> On Thu, Nov 09, 2017 at 04:21:32PM +0800, Baoquan He wrote:
> >Hi Chao,
> >
> >On 11/01/17 at 07:32pm, Chao Fan wrote:
> >> Compare the region of memmap entry and immovable_mem, then choose the
> >> intersection to process_mem_region.
> >> 
> >> Since the interrelationship between e820 or efi entries and memory
> >> region in immovable_mem is different:
> >
> >Could you paste a bootlog with efi=debug specified in cmdline on the
> >system you tested? I want to check what kind of intersection between
> >them. The adding makes code pretty ugly, want to make sure if we have
> >to do like this.
> Hi Baoquan,
> 
> Here is a machine with efi.

Thanks, do you have the whole boot log? I want to have a look at e820.
And this is a special system, or a customized system? I mean you just
customize the firmware for better testing to cover kinds of cases.

If it's too big, please attach it and send to me privately.

Anyway, seems your considering about the intersection is right.

Thanks
Baoquan
> 
> The memory information in SRAT from dmesg:
> [0.00] ACPI: SRAT: Node 0 PXM 0 [mem 0x-0x0009]
> [0.00] ACPI: SRAT: Node 0 PXM 0 [mem 0x0010-0x1f3f]
> [0.00] ACPI: SRAT: Node 1 PXM 1 [mem 0x1f40-0x3e7f]
> [0.00] ACPI: SRAT: Node 2 PXM 2 [mem 0x3e80-0x5dbf]
> [0.00] ACPI: SRAT: Node 3 PXM 3 [mem 0x5dc0-0x7cff]
> [0.00] ACPI: SRAT: Node 4 PXM 4 [mem 0x7d00-0x9c3f]
> [0.00] ACPI: SRAT: Node 5 PXM 5 [mem 0x9c40-0xbb7f]
> [0.00] ACPI: SRAT: Node 6 PXM 6 [mem 0xbb80-0xbfff]
> [0.00] ACPI: SRAT: Node 6 PXM 6 [mem 0x1-0x11abf]
> [0.00] ACPI: SRAT: Node 7 PXM 7 [mem 0x11ac0-0x139ff]
> [0.00] ACPI: SRAT: Node 8 PXM 8 [mem 0x13a00-0x1593f]
> [0.00] ACPI: SRAT: Node 9 PXM 9 [mem 0x15940-0x1787f]
> 
> There are 10 nodes, and 500M memory in every node.
> And node0 and node 6 has two parts.
> 
> 
> Here is the efi mem:
> [0.00] efi: mem00: [Boot Code  |   |  |  |  |  |  |  |   
> |WB|WT|WC|UC] range=[0x-0x0fff] (0MB)
> [0.00] efi: mem01: [Loader Data|   |  |  |  |  |  |  |   
> |WB|WT|WC|UC] range=[0x1000-0x1fff] (0MB)
> [0.00] efi: mem02: [Conventional Memory|   |  |  |  |  |  |  |   
> |WB|WT|WC|UC] range=[0x2000-0x0009] (0MB)
> [0.00] efi: mem03: [Conventional Memory|   |  |  |  |  |  |  |   
> |WB|WT|WC|UC] range=[0x0010-0x00805fff] (7MB)
> [0.00] efi: mem04: [Boot Data  |   |  |  |  |  |  |  |   
> |WB|WT|WC|UC] range=[0x00806000-0x00806fff] (0MB)
> [0.00] efi: mem05: [Conventional Memory|   |  |  |  |  |  |  |   
> |WB|WT|WC|UC] range=[0x00807000-0x0081] (0MB)
> [0.00] efi: mem06: [Boot Data  |   |  |  |  |  |  |  |   
> |WB|WT|WC|UC] range=[0x0082-0x012f] (10MB)
> [0.00] efi: mem07: [Conventional Memory|   |  |  |  |  |  |  |   
> |WB|WT|WC|UC] range=[0x0130-0x01ff] (13MB)
> [0.00] efi: mem08: [Loader Data|   |  |  |  |  |  |  |   
> |WB|WT|WC|UC] range=[0x0200-0x036e3fff] (22MB)
> (From mem00 to mem08, belongs to node0)
> [0.00] efi: mem09: [Conventional Memory|   |  |  |  |  |  |  |   
> |WB|WT|WC|UC] range=[0x036e4000-0x3d626fff] (927MB)
> (mem09 has part of node0 and part of node1, but not the whole of node0 and 
> node1)
> [0.00] efi: mem10: [Loader Data|   |  |  |  |  |  |  |   
> |WB|WT|WC|UC] range=[0x3d627000-0x3fff] (41MB)
> (part of node1 and part of node2)
> [0.00] efi: mem11: [Conventional Memory|   |  |  |  |  |  |  |   
> |WB|WT|WC|UC] range=[0x4000-0x8c92dfff] (1225MB)
> [0.00] efi: mem12: [Loader Data|   |  |  |  |  |  |  |   
> |WB|WT|WC|UC] range=[0x8c92e000-0xbbfbdfff] (758MB)
> [0.00] efi: mem13: [Boot Data  |   |  |  |  |  |  |  |   
> |WB|WT|WC|UC] range=[0xbbfbe000-0xbbfddfff] (0MB)
> [0.00] efi: mem14: [Conventional Memory|   |  |  |  |  |  |  |   
> |WB|WT|WC|UC] range=[0xbbfde000-0xbe350fff] (35MB)
> [0.00] efi: mem15: [Loader Data|   |  |  |  |  |  |  |   
> |WB|WT|WC|UC] range=[0xbe351000-0xbe579fff] (2MB)
> [0.00] efi: mem16: [Loader Code|   |  |  |  |  |  |  |   
> |WB|WT|WC|UC] range=[0xbe57a000-0xbe6a0fff] (1MB)
> [0.00] efi: mem17: [Boot Data  |   |  |  |  |  |  |  |   
> |WB|WT|WC|UC] range=[0xbe6a1000-0xbeb21fff] (4MB)
> [0.00] efi: mem18: [Boot Code  |   |  |  |  |  |  |  |   
> |WB|WT|WC|UC] range=[0xbeb22000-0xbed95fff] (2MB)
> [0.00] efi: mem19: 

Re: [PATCH v2 2/4] kaslr: select the memory region in immovable node to process

2017-11-09 Thread Baoquan He
On 11/10/17 at 11:03am, Chao Fan wrote:
> On Thu, Nov 09, 2017 at 04:21:32PM +0800, Baoquan He wrote:
> >Hi Chao,
> >
> >On 11/01/17 at 07:32pm, Chao Fan wrote:
> >> Compare the region of memmap entry and immovable_mem, then choose the
> >> intersection to process_mem_region.
> >> 
> >> Since the interrelationship between e820 or efi entries and memory
> >> region in immovable_mem is different:
> >
> >Could you paste a bootlog with efi=debug specified in cmdline on the
> >system you tested? I want to check what kind of intersection between
> >them. The adding makes code pretty ugly, want to make sure if we have
> >to do like this.
> Hi Baoquan,
> 
> Here is a machine with efi.

Thanks, do you have the whole boot log? I want to have a look at e820.
And this is a special system, or a customized system? I mean you just
customize the firmware for better testing to cover kinds of cases.

If it's too big, please attach it and send to me privately.

Anyway, seems your considering about the intersection is right.

Thanks
Baoquan
> 
> The memory information in SRAT from dmesg:
> [0.00] ACPI: SRAT: Node 0 PXM 0 [mem 0x-0x0009]
> [0.00] ACPI: SRAT: Node 0 PXM 0 [mem 0x0010-0x1f3f]
> [0.00] ACPI: SRAT: Node 1 PXM 1 [mem 0x1f40-0x3e7f]
> [0.00] ACPI: SRAT: Node 2 PXM 2 [mem 0x3e80-0x5dbf]
> [0.00] ACPI: SRAT: Node 3 PXM 3 [mem 0x5dc0-0x7cff]
> [0.00] ACPI: SRAT: Node 4 PXM 4 [mem 0x7d00-0x9c3f]
> [0.00] ACPI: SRAT: Node 5 PXM 5 [mem 0x9c40-0xbb7f]
> [0.00] ACPI: SRAT: Node 6 PXM 6 [mem 0xbb80-0xbfff]
> [0.00] ACPI: SRAT: Node 6 PXM 6 [mem 0x1-0x11abf]
> [0.00] ACPI: SRAT: Node 7 PXM 7 [mem 0x11ac0-0x139ff]
> [0.00] ACPI: SRAT: Node 8 PXM 8 [mem 0x13a00-0x1593f]
> [0.00] ACPI: SRAT: Node 9 PXM 9 [mem 0x15940-0x1787f]
> 
> There are 10 nodes, and 500M memory in every node.
> And node0 and node 6 has two parts.
> 
> 
> Here is the efi mem:
> [0.00] efi: mem00: [Boot Code  |   |  |  |  |  |  |  |   
> |WB|WT|WC|UC] range=[0x-0x0fff] (0MB)
> [0.00] efi: mem01: [Loader Data|   |  |  |  |  |  |  |   
> |WB|WT|WC|UC] range=[0x1000-0x1fff] (0MB)
> [0.00] efi: mem02: [Conventional Memory|   |  |  |  |  |  |  |   
> |WB|WT|WC|UC] range=[0x2000-0x0009] (0MB)
> [0.00] efi: mem03: [Conventional Memory|   |  |  |  |  |  |  |   
> |WB|WT|WC|UC] range=[0x0010-0x00805fff] (7MB)
> [0.00] efi: mem04: [Boot Data  |   |  |  |  |  |  |  |   
> |WB|WT|WC|UC] range=[0x00806000-0x00806fff] (0MB)
> [0.00] efi: mem05: [Conventional Memory|   |  |  |  |  |  |  |   
> |WB|WT|WC|UC] range=[0x00807000-0x0081] (0MB)
> [0.00] efi: mem06: [Boot Data  |   |  |  |  |  |  |  |   
> |WB|WT|WC|UC] range=[0x0082-0x012f] (10MB)
> [0.00] efi: mem07: [Conventional Memory|   |  |  |  |  |  |  |   
> |WB|WT|WC|UC] range=[0x0130-0x01ff] (13MB)
> [0.00] efi: mem08: [Loader Data|   |  |  |  |  |  |  |   
> |WB|WT|WC|UC] range=[0x0200-0x036e3fff] (22MB)
> (From mem00 to mem08, belongs to node0)
> [0.00] efi: mem09: [Conventional Memory|   |  |  |  |  |  |  |   
> |WB|WT|WC|UC] range=[0x036e4000-0x3d626fff] (927MB)
> (mem09 has part of node0 and part of node1, but not the whole of node0 and 
> node1)
> [0.00] efi: mem10: [Loader Data|   |  |  |  |  |  |  |   
> |WB|WT|WC|UC] range=[0x3d627000-0x3fff] (41MB)
> (part of node1 and part of node2)
> [0.00] efi: mem11: [Conventional Memory|   |  |  |  |  |  |  |   
> |WB|WT|WC|UC] range=[0x4000-0x8c92dfff] (1225MB)
> [0.00] efi: mem12: [Loader Data|   |  |  |  |  |  |  |   
> |WB|WT|WC|UC] range=[0x8c92e000-0xbbfbdfff] (758MB)
> [0.00] efi: mem13: [Boot Data  |   |  |  |  |  |  |  |   
> |WB|WT|WC|UC] range=[0xbbfbe000-0xbbfddfff] (0MB)
> [0.00] efi: mem14: [Conventional Memory|   |  |  |  |  |  |  |   
> |WB|WT|WC|UC] range=[0xbbfde000-0xbe350fff] (35MB)
> [0.00] efi: mem15: [Loader Data|   |  |  |  |  |  |  |   
> |WB|WT|WC|UC] range=[0xbe351000-0xbe579fff] (2MB)
> [0.00] efi: mem16: [Loader Code|   |  |  |  |  |  |  |   
> |WB|WT|WC|UC] range=[0xbe57a000-0xbe6a0fff] (1MB)
> [0.00] efi: mem17: [Boot Data  |   |  |  |  |  |  |  |   
> |WB|WT|WC|UC] range=[0xbe6a1000-0xbeb21fff] (4MB)
> [0.00] efi: mem18: [Boot Code  |   |  |  |  |  |  |  |   
> |WB|WT|WC|UC] range=[0xbeb22000-0xbed95fff] (2MB)
> [0.00] efi: mem19: 

Re: [PATCH v2 2/4] kaslr: select the memory region in immovable node to process

2017-11-09 Thread Chao Fan
On Thu, Nov 09, 2017 at 04:21:32PM +0800, Baoquan He wrote:
>Hi Chao,
>
>On 11/01/17 at 07:32pm, Chao Fan wrote:
>> Compare the region of memmap entry and immovable_mem, then choose the
>> intersection to process_mem_region.
>> 
>> Since the interrelationship between e820 or efi entries and memory
>> region in immovable_mem is different:
>
>Could you paste a bootlog with efi=debug specified in cmdline on the
>system you tested? I want to check what kind of intersection between
>them. The adding makes code pretty ugly, want to make sure if we have
>to do like this.
Hi Baoquan,

Here is a machine with efi.

The memory information in SRAT from dmesg:
[0.00] ACPI: SRAT: Node 0 PXM 0 [mem 0x-0x0009]
[0.00] ACPI: SRAT: Node 0 PXM 0 [mem 0x0010-0x1f3f]
[0.00] ACPI: SRAT: Node 1 PXM 1 [mem 0x1f40-0x3e7f]
[0.00] ACPI: SRAT: Node 2 PXM 2 [mem 0x3e80-0x5dbf]
[0.00] ACPI: SRAT: Node 3 PXM 3 [mem 0x5dc0-0x7cff]
[0.00] ACPI: SRAT: Node 4 PXM 4 [mem 0x7d00-0x9c3f]
[0.00] ACPI: SRAT: Node 5 PXM 5 [mem 0x9c40-0xbb7f]
[0.00] ACPI: SRAT: Node 6 PXM 6 [mem 0xbb80-0xbfff]
[0.00] ACPI: SRAT: Node 6 PXM 6 [mem 0x1-0x11abf]
[0.00] ACPI: SRAT: Node 7 PXM 7 [mem 0x11ac0-0x139ff]
[0.00] ACPI: SRAT: Node 8 PXM 8 [mem 0x13a00-0x1593f]
[0.00] ACPI: SRAT: Node 9 PXM 9 [mem 0x15940-0x1787f]

There are 10 nodes, and 500M memory in every node.
And node0 and node 6 has two parts.


Here is the efi mem:
[0.00] efi: mem00: [Boot Code  |   |  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0x-0x0fff] (0MB)
[0.00] efi: mem01: [Loader Data|   |  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0x1000-0x1fff] (0MB)
[0.00] efi: mem02: [Conventional Memory|   |  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0x2000-0x0009] (0MB)
[0.00] efi: mem03: [Conventional Memory|   |  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0x0010-0x00805fff] (7MB)
[0.00] efi: mem04: [Boot Data  |   |  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0x00806000-0x00806fff] (0MB)
[0.00] efi: mem05: [Conventional Memory|   |  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0x00807000-0x0081] (0MB)
[0.00] efi: mem06: [Boot Data  |   |  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0x0082-0x012f] (10MB)
[0.00] efi: mem07: [Conventional Memory|   |  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0x0130-0x01ff] (13MB)
[0.00] efi: mem08: [Loader Data|   |  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0x0200-0x036e3fff] (22MB)
(From mem00 to mem08, belongs to node0)
[0.00] efi: mem09: [Conventional Memory|   |  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0x036e4000-0x3d626fff] (927MB)
(mem09 has part of node0 and part of node1, but not the whole of node0 and 
node1)
[0.00] efi: mem10: [Loader Data|   |  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0x3d627000-0x3fff] (41MB)
(part of node1 and part of node2)
[0.00] efi: mem11: [Conventional Memory|   |  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0x4000-0x8c92dfff] (1225MB)
[0.00] efi: mem12: [Loader Data|   |  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0x8c92e000-0xbbfbdfff] (758MB)
[0.00] efi: mem13: [Boot Data  |   |  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0xbbfbe000-0xbbfddfff] (0MB)
[0.00] efi: mem14: [Conventional Memory|   |  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0xbbfde000-0xbe350fff] (35MB)
[0.00] efi: mem15: [Loader Data|   |  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0xbe351000-0xbe579fff] (2MB)
[0.00] efi: mem16: [Loader Code|   |  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0xbe57a000-0xbe6a0fff] (1MB)
[0.00] efi: mem17: [Boot Data  |   |  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0xbe6a1000-0xbeb21fff] (4MB)
[0.00] efi: mem18: [Boot Code  |   |  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0xbeb22000-0xbed95fff] (2MB)
[0.00] efi: mem19: [Runtime Data   |RUN|  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0xbed96000-0xbed9afff] (0MB)
[0.00] efi: mem20: [Runtime Code   |RUN|  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0xbed9b000-0xbeda1fff] (0MB)
[0.00] efi: mem21: [Runtime Data   |RUN|  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0xbeda2000-0xbeda6fff] (0MB)
[0.00] efi: mem22: [Runtime Code   |RUN|  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0xbeda7000-0xbedacfff] (0MB)
[0.00] 

Re: [PATCH v2 2/4] kaslr: select the memory region in immovable node to process

2017-11-09 Thread Chao Fan
On Thu, Nov 09, 2017 at 04:21:32PM +0800, Baoquan He wrote:
>Hi Chao,
>
>On 11/01/17 at 07:32pm, Chao Fan wrote:
>> Compare the region of memmap entry and immovable_mem, then choose the
>> intersection to process_mem_region.
>> 
>> Since the interrelationship between e820 or efi entries and memory
>> region in immovable_mem is different:
>
>Could you paste a bootlog with efi=debug specified in cmdline on the
>system you tested? I want to check what kind of intersection between
>them. The adding makes code pretty ugly, want to make sure if we have
>to do like this.
Hi Baoquan,

Here is a machine with efi.

The memory information in SRAT from dmesg:
[0.00] ACPI: SRAT: Node 0 PXM 0 [mem 0x-0x0009]
[0.00] ACPI: SRAT: Node 0 PXM 0 [mem 0x0010-0x1f3f]
[0.00] ACPI: SRAT: Node 1 PXM 1 [mem 0x1f40-0x3e7f]
[0.00] ACPI: SRAT: Node 2 PXM 2 [mem 0x3e80-0x5dbf]
[0.00] ACPI: SRAT: Node 3 PXM 3 [mem 0x5dc0-0x7cff]
[0.00] ACPI: SRAT: Node 4 PXM 4 [mem 0x7d00-0x9c3f]
[0.00] ACPI: SRAT: Node 5 PXM 5 [mem 0x9c40-0xbb7f]
[0.00] ACPI: SRAT: Node 6 PXM 6 [mem 0xbb80-0xbfff]
[0.00] ACPI: SRAT: Node 6 PXM 6 [mem 0x1-0x11abf]
[0.00] ACPI: SRAT: Node 7 PXM 7 [mem 0x11ac0-0x139ff]
[0.00] ACPI: SRAT: Node 8 PXM 8 [mem 0x13a00-0x1593f]
[0.00] ACPI: SRAT: Node 9 PXM 9 [mem 0x15940-0x1787f]

There are 10 nodes, and 500M memory in every node.
And node0 and node 6 has two parts.


Here is the efi mem:
[0.00] efi: mem00: [Boot Code  |   |  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0x-0x0fff] (0MB)
[0.00] efi: mem01: [Loader Data|   |  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0x1000-0x1fff] (0MB)
[0.00] efi: mem02: [Conventional Memory|   |  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0x2000-0x0009] (0MB)
[0.00] efi: mem03: [Conventional Memory|   |  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0x0010-0x00805fff] (7MB)
[0.00] efi: mem04: [Boot Data  |   |  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0x00806000-0x00806fff] (0MB)
[0.00] efi: mem05: [Conventional Memory|   |  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0x00807000-0x0081] (0MB)
[0.00] efi: mem06: [Boot Data  |   |  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0x0082-0x012f] (10MB)
[0.00] efi: mem07: [Conventional Memory|   |  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0x0130-0x01ff] (13MB)
[0.00] efi: mem08: [Loader Data|   |  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0x0200-0x036e3fff] (22MB)
(From mem00 to mem08, belongs to node0)
[0.00] efi: mem09: [Conventional Memory|   |  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0x036e4000-0x3d626fff] (927MB)
(mem09 has part of node0 and part of node1, but not the whole of node0 and 
node1)
[0.00] efi: mem10: [Loader Data|   |  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0x3d627000-0x3fff] (41MB)
(part of node1 and part of node2)
[0.00] efi: mem11: [Conventional Memory|   |  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0x4000-0x8c92dfff] (1225MB)
[0.00] efi: mem12: [Loader Data|   |  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0x8c92e000-0xbbfbdfff] (758MB)
[0.00] efi: mem13: [Boot Data  |   |  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0xbbfbe000-0xbbfddfff] (0MB)
[0.00] efi: mem14: [Conventional Memory|   |  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0xbbfde000-0xbe350fff] (35MB)
[0.00] efi: mem15: [Loader Data|   |  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0xbe351000-0xbe579fff] (2MB)
[0.00] efi: mem16: [Loader Code|   |  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0xbe57a000-0xbe6a0fff] (1MB)
[0.00] efi: mem17: [Boot Data  |   |  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0xbe6a1000-0xbeb21fff] (4MB)
[0.00] efi: mem18: [Boot Code  |   |  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0xbeb22000-0xbed95fff] (2MB)
[0.00] efi: mem19: [Runtime Data   |RUN|  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0xbed96000-0xbed9afff] (0MB)
[0.00] efi: mem20: [Runtime Code   |RUN|  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0xbed9b000-0xbeda1fff] (0MB)
[0.00] efi: mem21: [Runtime Data   |RUN|  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0xbeda2000-0xbeda6fff] (0MB)
[0.00] efi: mem22: [Runtime Code   |RUN|  |  |  |  |  |  |   
|WB|WT|WC|UC] range=[0xbeda7000-0xbedacfff] (0MB)
[0.00] 

Re: [PATCH v2 2/4] kaslr: select the memory region in immovable node to process

2017-11-09 Thread Chao Fan
On Thu, Nov 09, 2017 at 04:21:32PM +0800, Baoquan He wrote:
>Hi Chao,
>
>On 11/01/17 at 07:32pm, Chao Fan wrote:
>> Compare the region of memmap entry and immovable_mem, then choose the
>> intersection to process_mem_region.
>> 
>> Since the interrelationship between e820 or efi entries and memory
>> region in immovable_mem is different:
>
>Could you paste a bootlog with efi=debug specified in cmdline on the
>system you tested? I want to check what kind of intersection between

Sure, I will.

Thanks,
Chao Fan

>them. The adding makes code pretty ugly, want to make sure if we have
>to do like this.
>
>Thanks
>Baoquan
>
>> One memory region in one node may contain several entries of e820 or
>> efi sometimes, and one entry of e820 or efi may contain the memory in
>> different nodes sometimes.
>> It may split one node or one entry to several regions.
>> 
>> Signed-off-by: Chao Fan 
>> ---
>>  arch/x86/boot/compressed/kaslr.c | 60 
>> ++--
>>  1 file changed, 52 insertions(+), 8 deletions(-)
>> 
>> diff --git a/arch/x86/boot/compressed/kaslr.c 
>> b/arch/x86/boot/compressed/kaslr.c
>> index 0a591c0023f1..fcd640fdeaed 100644
>> --- a/arch/x86/boot/compressed/kaslr.c
>> +++ b/arch/x86/boot/compressed/kaslr.c
>> @@ -634,6 +634,54 @@ static void process_mem_region(struct mem_vector *entry,
>>  }
>>  }
>>  
>> +static bool select_immovable_node(struct mem_vector region,
>> +  unsigned long long minimum,
>> +  unsigned long long image_size)
>> +{
>> +int i;
>> +
>> +/* If no immovable_mem stored, use region directly */
>> +if (num_immovable_region == 0) {
>> +process_mem_region(, minimum, image_size);
>> +
>> +if (slot_area_index == MAX_SLOT_AREA) {
>> +debug_putstr("Aborted memmap scan (slot_areas 
>> full)!\n");
>> +return 1;
>> +}
>> +} else {
>> +/*
>> + * Walk all immovable regions, and filter the intersection
>> + * to process_mem_region.
>> + */
>> +for (i = 0; i < num_immovable_region; i++) {
>> +struct mem_vector entry;
>> +unsigned long long start, end, select_end, region_end;
>> +
>> +region_end = region.start + region.size - 1;
>> +start = immovable_mem[i].start;
>> +end = start + immovable_mem[i].size - 1;
>> +
>> +if (region_end < start || region.start > end)
>> +continue;
>> +
>> +/* May split one region to several entries. */
>> +entry.start = start > region.start ?
>> +  start : region.start;
>> +select_end = end > region_end ? region_end : end;
>> +
>> +entry.size = select_end - entry.start + 1;
>> +
>> +process_mem_region(, minimum, image_size);
>> +
>> +if (slot_area_index == MAX_SLOT_AREA) {
>> +debug_putstr("Aborted memmap scan (slot_areas 
>> full)!\n");
>> +return 1;
>> +}
>> +}
>> +}
>> +return 0;
>> +}
>> +
>>  #ifdef CONFIG_EFI
>>  /*
>>   * Returns true if mirror region found (and must have been processed
>> @@ -699,11 +747,9 @@ process_efi_entries(unsigned long minimum, unsigned 
>> long image_size)
>>  
>>  region.start = md->phys_addr;
>>  region.size = md->num_pages << EFI_PAGE_SHIFT;
>> -process_mem_region(, minimum, image_size);
>> -if (slot_area_index == MAX_SLOT_AREA) {
>> -debug_putstr("Aborted EFI scan (slot_areas full)!\n");
>> +
>> +if (select_immovable_node(region, minimum, image_size))
>>  break;
>> -}
>>  }
>>  return true;
>>  }
>> @@ -730,11 +776,9 @@ static void process_e820_entries(unsigned long minimum,
>>  continue;
>>  region.start = entry->addr;
>>  region.size = entry->size;
>> -process_mem_region(, minimum, image_size);
>> -if (slot_area_index == MAX_SLOT_AREA) {
>> -debug_putstr("Aborted e820 scan (slot_areas full)!\n");
>> +
>> +if (select_immovable_node(region, minimum, image_size))
>>  break;
>> -}
>>  }
>>  }
>>  
>> -- 
>> 2.13.6
>> 
>> 
>> 
>
>




Re: [PATCH v2 2/4] kaslr: select the memory region in immovable node to process

2017-11-09 Thread Chao Fan
On Thu, Nov 09, 2017 at 04:21:32PM +0800, Baoquan He wrote:
>Hi Chao,
>
>On 11/01/17 at 07:32pm, Chao Fan wrote:
>> Compare the region of memmap entry and immovable_mem, then choose the
>> intersection to process_mem_region.
>> 
>> Since the interrelationship between e820 or efi entries and memory
>> region in immovable_mem is different:
>
>Could you paste a bootlog with efi=debug specified in cmdline on the
>system you tested? I want to check what kind of intersection between

Sure, I will.

Thanks,
Chao Fan

>them. The adding makes code pretty ugly, want to make sure if we have
>to do like this.
>
>Thanks
>Baoquan
>
>> One memory region in one node may contain several entries of e820 or
>> efi sometimes, and one entry of e820 or efi may contain the memory in
>> different nodes sometimes.
>> It may split one node or one entry to several regions.
>> 
>> Signed-off-by: Chao Fan 
>> ---
>>  arch/x86/boot/compressed/kaslr.c | 60 
>> ++--
>>  1 file changed, 52 insertions(+), 8 deletions(-)
>> 
>> diff --git a/arch/x86/boot/compressed/kaslr.c 
>> b/arch/x86/boot/compressed/kaslr.c
>> index 0a591c0023f1..fcd640fdeaed 100644
>> --- a/arch/x86/boot/compressed/kaslr.c
>> +++ b/arch/x86/boot/compressed/kaslr.c
>> @@ -634,6 +634,54 @@ static void process_mem_region(struct mem_vector *entry,
>>  }
>>  }
>>  
>> +static bool select_immovable_node(struct mem_vector region,
>> +  unsigned long long minimum,
>> +  unsigned long long image_size)
>> +{
>> +int i;
>> +
>> +/* If no immovable_mem stored, use region directly */
>> +if (num_immovable_region == 0) {
>> +process_mem_region(, minimum, image_size);
>> +
>> +if (slot_area_index == MAX_SLOT_AREA) {
>> +debug_putstr("Aborted memmap scan (slot_areas 
>> full)!\n");
>> +return 1;
>> +}
>> +} else {
>> +/*
>> + * Walk all immovable regions, and filter the intersection
>> + * to process_mem_region.
>> + */
>> +for (i = 0; i < num_immovable_region; i++) {
>> +struct mem_vector entry;
>> +unsigned long long start, end, select_end, region_end;
>> +
>> +region_end = region.start + region.size - 1;
>> +start = immovable_mem[i].start;
>> +end = start + immovable_mem[i].size - 1;
>> +
>> +if (region_end < start || region.start > end)
>> +continue;
>> +
>> +/* May split one region to several entries. */
>> +entry.start = start > region.start ?
>> +  start : region.start;
>> +select_end = end > region_end ? region_end : end;
>> +
>> +entry.size = select_end - entry.start + 1;
>> +
>> +process_mem_region(, minimum, image_size);
>> +
>> +if (slot_area_index == MAX_SLOT_AREA) {
>> +debug_putstr("Aborted memmap scan (slot_areas 
>> full)!\n");
>> +return 1;
>> +}
>> +}
>> +}
>> +return 0;
>> +}
>> +
>>  #ifdef CONFIG_EFI
>>  /*
>>   * Returns true if mirror region found (and must have been processed
>> @@ -699,11 +747,9 @@ process_efi_entries(unsigned long minimum, unsigned 
>> long image_size)
>>  
>>  region.start = md->phys_addr;
>>  region.size = md->num_pages << EFI_PAGE_SHIFT;
>> -process_mem_region(, minimum, image_size);
>> -if (slot_area_index == MAX_SLOT_AREA) {
>> -debug_putstr("Aborted EFI scan (slot_areas full)!\n");
>> +
>> +if (select_immovable_node(region, minimum, image_size))
>>  break;
>> -}
>>  }
>>  return true;
>>  }
>> @@ -730,11 +776,9 @@ static void process_e820_entries(unsigned long minimum,
>>  continue;
>>  region.start = entry->addr;
>>  region.size = entry->size;
>> -process_mem_region(, minimum, image_size);
>> -if (slot_area_index == MAX_SLOT_AREA) {
>> -debug_putstr("Aborted e820 scan (slot_areas full)!\n");
>> +
>> +if (select_immovable_node(region, minimum, image_size))
>>  break;
>> -}
>>  }
>>  }
>>  
>> -- 
>> 2.13.6
>> 
>> 
>> 
>
>




Re: [PATCH v2 2/4] kaslr: select the memory region in immovable node to process

2017-11-09 Thread Baoquan He
Hi Chao,

On 11/01/17 at 07:32pm, Chao Fan wrote:
> Compare the region of memmap entry and immovable_mem, then choose the
> intersection to process_mem_region.
> 
> Since the interrelationship between e820 or efi entries and memory
> region in immovable_mem is different:

Could you paste a bootlog with efi=debug specified in cmdline on the
system you tested? I want to check what kind of intersection between
them. The adding makes code pretty ugly, want to make sure if we have
to do like this.

Thanks
Baoquan

> One memory region in one node may contain several entries of e820 or
> efi sometimes, and one entry of e820 or efi may contain the memory in
> different nodes sometimes.
> It may split one node or one entry to several regions.
> 
> Signed-off-by: Chao Fan 
> ---
>  arch/x86/boot/compressed/kaslr.c | 60 
> ++--
>  1 file changed, 52 insertions(+), 8 deletions(-)
> 
> diff --git a/arch/x86/boot/compressed/kaslr.c 
> b/arch/x86/boot/compressed/kaslr.c
> index 0a591c0023f1..fcd640fdeaed 100644
> --- a/arch/x86/boot/compressed/kaslr.c
> +++ b/arch/x86/boot/compressed/kaslr.c
> @@ -634,6 +634,54 @@ static void process_mem_region(struct mem_vector *entry,
>   }
>  }
>  
> +static bool select_immovable_node(struct mem_vector region,
> +   unsigned long long minimum,
> +   unsigned long long image_size)
> +{
> + int i;
> +
> + /* If no immovable_mem stored, use region directly */
> + if (num_immovable_region == 0) {
> + process_mem_region(, minimum, image_size);
> +
> + if (slot_area_index == MAX_SLOT_AREA) {
> + debug_putstr("Aborted memmap scan (slot_areas 
> full)!\n");
> + return 1;
> + }
> + } else {
> + /*
> +  * Walk all immovable regions, and filter the intersection
> +  * to process_mem_region.
> +  */
> + for (i = 0; i < num_immovable_region; i++) {
> + struct mem_vector entry;
> + unsigned long long start, end, select_end, region_end;
> +
> + region_end = region.start + region.size - 1;
> + start = immovable_mem[i].start;
> + end = start + immovable_mem[i].size - 1;
> +
> + if (region_end < start || region.start > end)
> + continue;
> +
> + /* May split one region to several entries. */
> + entry.start = start > region.start ?
> +   start : region.start;
> + select_end = end > region_end ? region_end : end;
> +
> + entry.size = select_end - entry.start + 1;
> +
> + process_mem_region(, minimum, image_size);
> +
> + if (slot_area_index == MAX_SLOT_AREA) {
> + debug_putstr("Aborted memmap scan (slot_areas 
> full)!\n");
> + return 1;
> + }
> + }
> + }
> + return 0;
> +}
> +
>  #ifdef CONFIG_EFI
>  /*
>   * Returns true if mirror region found (and must have been processed
> @@ -699,11 +747,9 @@ process_efi_entries(unsigned long minimum, unsigned long 
> image_size)
>  
>   region.start = md->phys_addr;
>   region.size = md->num_pages << EFI_PAGE_SHIFT;
> - process_mem_region(, minimum, image_size);
> - if (slot_area_index == MAX_SLOT_AREA) {
> - debug_putstr("Aborted EFI scan (slot_areas full)!\n");
> +
> + if (select_immovable_node(region, minimum, image_size))
>   break;
> - }
>   }
>   return true;
>  }
> @@ -730,11 +776,9 @@ static void process_e820_entries(unsigned long minimum,
>   continue;
>   region.start = entry->addr;
>   region.size = entry->size;
> - process_mem_region(, minimum, image_size);
> - if (slot_area_index == MAX_SLOT_AREA) {
> - debug_putstr("Aborted e820 scan (slot_areas full)!\n");
> +
> + if (select_immovable_node(region, minimum, image_size))
>   break;
> - }
>   }
>  }
>  
> -- 
> 2.13.6
> 
> 
> 


Re: [PATCH v2 2/4] kaslr: select the memory region in immovable node to process

2017-11-09 Thread Baoquan He
Hi Chao,

On 11/01/17 at 07:32pm, Chao Fan wrote:
> Compare the region of memmap entry and immovable_mem, then choose the
> intersection to process_mem_region.
> 
> Since the interrelationship between e820 or efi entries and memory
> region in immovable_mem is different:

Could you paste a bootlog with efi=debug specified in cmdline on the
system you tested? I want to check what kind of intersection between
them. The adding makes code pretty ugly, want to make sure if we have
to do like this.

Thanks
Baoquan

> One memory region in one node may contain several entries of e820 or
> efi sometimes, and one entry of e820 or efi may contain the memory in
> different nodes sometimes.
> It may split one node or one entry to several regions.
> 
> Signed-off-by: Chao Fan 
> ---
>  arch/x86/boot/compressed/kaslr.c | 60 
> ++--
>  1 file changed, 52 insertions(+), 8 deletions(-)
> 
> diff --git a/arch/x86/boot/compressed/kaslr.c 
> b/arch/x86/boot/compressed/kaslr.c
> index 0a591c0023f1..fcd640fdeaed 100644
> --- a/arch/x86/boot/compressed/kaslr.c
> +++ b/arch/x86/boot/compressed/kaslr.c
> @@ -634,6 +634,54 @@ static void process_mem_region(struct mem_vector *entry,
>   }
>  }
>  
> +static bool select_immovable_node(struct mem_vector region,
> +   unsigned long long minimum,
> +   unsigned long long image_size)
> +{
> + int i;
> +
> + /* If no immovable_mem stored, use region directly */
> + if (num_immovable_region == 0) {
> + process_mem_region(, minimum, image_size);
> +
> + if (slot_area_index == MAX_SLOT_AREA) {
> + debug_putstr("Aborted memmap scan (slot_areas 
> full)!\n");
> + return 1;
> + }
> + } else {
> + /*
> +  * Walk all immovable regions, and filter the intersection
> +  * to process_mem_region.
> +  */
> + for (i = 0; i < num_immovable_region; i++) {
> + struct mem_vector entry;
> + unsigned long long start, end, select_end, region_end;
> +
> + region_end = region.start + region.size - 1;
> + start = immovable_mem[i].start;
> + end = start + immovable_mem[i].size - 1;
> +
> + if (region_end < start || region.start > end)
> + continue;
> +
> + /* May split one region to several entries. */
> + entry.start = start > region.start ?
> +   start : region.start;
> + select_end = end > region_end ? region_end : end;
> +
> + entry.size = select_end - entry.start + 1;
> +
> + process_mem_region(, minimum, image_size);
> +
> + if (slot_area_index == MAX_SLOT_AREA) {
> + debug_putstr("Aborted memmap scan (slot_areas 
> full)!\n");
> + return 1;
> + }
> + }
> + }
> + return 0;
> +}
> +
>  #ifdef CONFIG_EFI
>  /*
>   * Returns true if mirror region found (and must have been processed
> @@ -699,11 +747,9 @@ process_efi_entries(unsigned long minimum, unsigned long 
> image_size)
>  
>   region.start = md->phys_addr;
>   region.size = md->num_pages << EFI_PAGE_SHIFT;
> - process_mem_region(, minimum, image_size);
> - if (slot_area_index == MAX_SLOT_AREA) {
> - debug_putstr("Aborted EFI scan (slot_areas full)!\n");
> +
> + if (select_immovable_node(region, minimum, image_size))
>   break;
> - }
>   }
>   return true;
>  }
> @@ -730,11 +776,9 @@ static void process_e820_entries(unsigned long minimum,
>   continue;
>   region.start = entry->addr;
>   region.size = entry->size;
> - process_mem_region(, minimum, image_size);
> - if (slot_area_index == MAX_SLOT_AREA) {
> - debug_putstr("Aborted e820 scan (slot_areas full)!\n");
> +
> + if (select_immovable_node(region, minimum, image_size))
>   break;
> - }
>   }
>  }
>  
> -- 
> 2.13.6
> 
> 
> 


[PATCH v2 2/4] kaslr: select the memory region in immovable node to process

2017-11-01 Thread Chao Fan
Compare the region of memmap entry and immovable_mem, then choose the
intersection to process_mem_region.

Since the interrelationship between e820 or efi entries and memory
region in immovable_mem is different:
One memory region in one node may contain several entries of e820 or
efi sometimes, and one entry of e820 or efi may contain the memory in
different nodes sometimes.
It may split one node or one entry to several regions.

Signed-off-by: Chao Fan 
---
 arch/x86/boot/compressed/kaslr.c | 60 ++--
 1 file changed, 52 insertions(+), 8 deletions(-)

diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
index 0a591c0023f1..fcd640fdeaed 100644
--- a/arch/x86/boot/compressed/kaslr.c
+++ b/arch/x86/boot/compressed/kaslr.c
@@ -634,6 +634,54 @@ static void process_mem_region(struct mem_vector *entry,
}
 }
 
+static bool select_immovable_node(struct mem_vector region,
+ unsigned long long minimum,
+ unsigned long long image_size)
+{
+   int i;
+
+   /* If no immovable_mem stored, use region directly */
+   if (num_immovable_region == 0) {
+   process_mem_region(, minimum, image_size);
+
+   if (slot_area_index == MAX_SLOT_AREA) {
+   debug_putstr("Aborted memmap scan (slot_areas 
full)!\n");
+   return 1;
+   }
+   } else {
+   /*
+* Walk all immovable regions, and filter the intersection
+* to process_mem_region.
+*/
+   for (i = 0; i < num_immovable_region; i++) {
+   struct mem_vector entry;
+   unsigned long long start, end, select_end, region_end;
+
+   region_end = region.start + region.size - 1;
+   start = immovable_mem[i].start;
+   end = start + immovable_mem[i].size - 1;
+
+   if (region_end < start || region.start > end)
+   continue;
+
+   /* May split one region to several entries. */
+   entry.start = start > region.start ?
+ start : region.start;
+   select_end = end > region_end ? region_end : end;
+
+   entry.size = select_end - entry.start + 1;
+
+   process_mem_region(, minimum, image_size);
+
+   if (slot_area_index == MAX_SLOT_AREA) {
+   debug_putstr("Aborted memmap scan (slot_areas 
full)!\n");
+   return 1;
+   }
+   }
+   }
+   return 0;
+}
+
 #ifdef CONFIG_EFI
 /*
  * Returns true if mirror region found (and must have been processed
@@ -699,11 +747,9 @@ process_efi_entries(unsigned long minimum, unsigned long 
image_size)
 
region.start = md->phys_addr;
region.size = md->num_pages << EFI_PAGE_SHIFT;
-   process_mem_region(, minimum, image_size);
-   if (slot_area_index == MAX_SLOT_AREA) {
-   debug_putstr("Aborted EFI scan (slot_areas full)!\n");
+
+   if (select_immovable_node(region, minimum, image_size))
break;
-   }
}
return true;
 }
@@ -730,11 +776,9 @@ static void process_e820_entries(unsigned long minimum,
continue;
region.start = entry->addr;
region.size = entry->size;
-   process_mem_region(, minimum, image_size);
-   if (slot_area_index == MAX_SLOT_AREA) {
-   debug_putstr("Aborted e820 scan (slot_areas full)!\n");
+
+   if (select_immovable_node(region, minimum, image_size))
break;
-   }
}
 }
 
-- 
2.13.6





[PATCH v2 2/4] kaslr: select the memory region in immovable node to process

2017-11-01 Thread Chao Fan
Compare the region of memmap entry and immovable_mem, then choose the
intersection to process_mem_region.

Since the interrelationship between e820 or efi entries and memory
region in immovable_mem is different:
One memory region in one node may contain several entries of e820 or
efi sometimes, and one entry of e820 or efi may contain the memory in
different nodes sometimes.
It may split one node or one entry to several regions.

Signed-off-by: Chao Fan 
---
 arch/x86/boot/compressed/kaslr.c | 60 ++--
 1 file changed, 52 insertions(+), 8 deletions(-)

diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
index 0a591c0023f1..fcd640fdeaed 100644
--- a/arch/x86/boot/compressed/kaslr.c
+++ b/arch/x86/boot/compressed/kaslr.c
@@ -634,6 +634,54 @@ static void process_mem_region(struct mem_vector *entry,
}
 }
 
+static bool select_immovable_node(struct mem_vector region,
+ unsigned long long minimum,
+ unsigned long long image_size)
+{
+   int i;
+
+   /* If no immovable_mem stored, use region directly */
+   if (num_immovable_region == 0) {
+   process_mem_region(, minimum, image_size);
+
+   if (slot_area_index == MAX_SLOT_AREA) {
+   debug_putstr("Aborted memmap scan (slot_areas 
full)!\n");
+   return 1;
+   }
+   } else {
+   /*
+* Walk all immovable regions, and filter the intersection
+* to process_mem_region.
+*/
+   for (i = 0; i < num_immovable_region; i++) {
+   struct mem_vector entry;
+   unsigned long long start, end, select_end, region_end;
+
+   region_end = region.start + region.size - 1;
+   start = immovable_mem[i].start;
+   end = start + immovable_mem[i].size - 1;
+
+   if (region_end < start || region.start > end)
+   continue;
+
+   /* May split one region to several entries. */
+   entry.start = start > region.start ?
+ start : region.start;
+   select_end = end > region_end ? region_end : end;
+
+   entry.size = select_end - entry.start + 1;
+
+   process_mem_region(, minimum, image_size);
+
+   if (slot_area_index == MAX_SLOT_AREA) {
+   debug_putstr("Aborted memmap scan (slot_areas 
full)!\n");
+   return 1;
+   }
+   }
+   }
+   return 0;
+}
+
 #ifdef CONFIG_EFI
 /*
  * Returns true if mirror region found (and must have been processed
@@ -699,11 +747,9 @@ process_efi_entries(unsigned long minimum, unsigned long 
image_size)
 
region.start = md->phys_addr;
region.size = md->num_pages << EFI_PAGE_SHIFT;
-   process_mem_region(, minimum, image_size);
-   if (slot_area_index == MAX_SLOT_AREA) {
-   debug_putstr("Aborted EFI scan (slot_areas full)!\n");
+
+   if (select_immovable_node(region, minimum, image_size))
break;
-   }
}
return true;
 }
@@ -730,11 +776,9 @@ static void process_e820_entries(unsigned long minimum,
continue;
region.start = entry->addr;
region.size = entry->size;
-   process_mem_region(, minimum, image_size);
-   if (slot_area_index == MAX_SLOT_AREA) {
-   debug_putstr("Aborted e820 scan (slot_areas full)!\n");
+
+   if (select_immovable_node(region, minimum, image_size))
break;
-   }
}
 }
 
-- 
2.13.6