All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] [RFC] xen: Fix memory hotplug end limit test for updating compat M2P table
@ 2012-04-23 18:07 Malcolm Crossley
  2012-04-24  7:21 ` Jan Beulich
  0 siblings, 1 reply; 4+ messages in thread
From: Malcolm Crossley @ 2012-04-23 18:07 UTC (permalink / raw)
  To: xen-devel; +Cc: tim

The memory hotplug code was masking the hotplugged memory start address and comparing to a shifted version of COMPAT MPT size but not doing the same for the end address.
This patch applies the same shifting and masking to the end address and reapplies the mask if the end address has been clamped.

diff -r 274e5accd62d -r 8470671d407f xen/arch/x86/x86_64/mm.c
--- a/xen/arch/x86/x86_64/mm.c
+++ b/xen/arch/x86/x86_64/mm.c
@@ -446,6 +446,8 @@ static int setup_compat_m2p_table(struct
     int err = 0;
 
     smap = info->spfn & (~((1UL << (L2_PAGETABLE_SHIFT - 2)) -1));
+    emap = ( (epfn + ((1UL << (L2_PAGETABLE_SHIFT - 2)) - 1 )) &
+                ~((1UL << (L2_PAGETABLE_SHIFT - 2)) - 1) );
 
     /*
      * Notice: For hot-added memory, only range below m2p_compat_vstart
@@ -454,11 +456,11 @@ static int setup_compat_m2p_table(struct
     if   ((smap > ((RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START) >> 2)) )
         return 0;
 
-    if (epfn > (RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START))
-        epfn = (RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START) >> 2;
-
-    emap = ( (epfn + ((1UL << (L2_PAGETABLE_SHIFT - 2)) - 1 )) &
-                ~((1UL << (L2_PAGETABLE_SHIFT - 2)) - 1) );
+    if (emap > ((RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START) >> 2))
+    {
+        emap = (RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START) >> 2;
+    	emap = emap & ~((1UL << (L2_PAGETABLE_SHIFT - 2)) - 1);
+    }
 
     va = HIRO_COMPAT_MPT_VIRT_START +
          smap * sizeof(*compat_machine_to_phys_mapping);

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] [RFC] xen: Fix memory hotplug end limit test for updating compat M2P table
  2012-04-23 18:07 [PATCH] [RFC] xen: Fix memory hotplug end limit test for updating compat M2P table Malcolm Crossley
@ 2012-04-24  7:21 ` Jan Beulich
  2012-04-24 16:02   ` Malcolm Crossley
  0 siblings, 1 reply; 4+ messages in thread
From: Jan Beulich @ 2012-04-24  7:21 UTC (permalink / raw)
  To: Malcolm Crossley; +Cc: tim, xen-devel

>>> On 23.04.12 at 20:07, Malcolm Crossley <malcolm.crossley@citrix.com> wrote:
> The memory hotplug code was masking the hotplugged memory start address and 
> comparing to a shifted version of COMPAT MPT size but not doing the same for 
> the end address.
> This patch applies the same shifting and masking to the end address and 
> reapplies the mask if the end address has been clamped.

This lacks a Signed-off-by tag in any case.

I'm not, however, seeing what is being fixed here:
RDWR_COMPAT_MPT_VIRT_{START,END} are both aligned to a
1Gb boundary, so I'm not immediately seeing how the adjustment
would result in any changed behavior.

Also, assuming I'm overlooking something and the patch is indeed
needed (and hence you'll resubmit), please fix the indentation to
not use hard tabs, and adjust the lines you change anyway to
match Xen's coding style.

Jan

> diff -r 274e5accd62d -r 8470671d407f xen/arch/x86/x86_64/mm.c
> --- a/xen/arch/x86/x86_64/mm.c
> +++ b/xen/arch/x86/x86_64/mm.c
> @@ -446,6 +446,8 @@ static int setup_compat_m2p_table(struct
>      int err = 0;
>  
>      smap = info->spfn & (~((1UL << (L2_PAGETABLE_SHIFT - 2)) -1));
> +    emap = ( (epfn + ((1UL << (L2_PAGETABLE_SHIFT - 2)) - 1 )) &
> +                ~((1UL << (L2_PAGETABLE_SHIFT - 2)) - 1) );
>  
>      /*
>       * Notice: For hot-added memory, only range below m2p_compat_vstart
> @@ -454,11 +456,11 @@ static int setup_compat_m2p_table(struct
>      if   ((smap > ((RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START) >> 
> 2)) )
>          return 0;
>  
> -    if (epfn > (RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START))
> -        epfn = (RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START) >> 2;
> -
> -    emap = ( (epfn + ((1UL << (L2_PAGETABLE_SHIFT - 2)) - 1 )) &
> -                ~((1UL << (L2_PAGETABLE_SHIFT - 2)) - 1) );
> +    if (emap > ((RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START) >> 2))
> +    {
> +        emap = (RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START) >> 2;
> +    	emap = emap & ~((1UL << (L2_PAGETABLE_SHIFT - 2)) - 1);
> +    }
>  
>      va = HIRO_COMPAT_MPT_VIRT_START +
>           smap * sizeof(*compat_machine_to_phys_mapping);
> 
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xen.org 
> http://lists.xen.org/xen-devel 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] [RFC] xen: Fix memory hotplug end limit test for updating compat M2P table
  2012-04-24  7:21 ` Jan Beulich
@ 2012-04-24 16:02   ` Malcolm Crossley
  2012-04-24 16:11     ` Jan Beulich
  0 siblings, 1 reply; 4+ messages in thread
From: Malcolm Crossley @ 2012-04-24 16:02 UTC (permalink / raw)
  To: Jan Beulich; +Cc: Tim (Xen.org), xen-devel

On 24/04/12 08:21, Jan Beulich wrote:
>>>> On 23.04.12 at 20:07, Malcolm Crossley<malcolm.crossley@citrix.com>  wrote:
>> The memory hotplug code was masking the hotplugged memory start address and
>> comparing to a shifted version of COMPAT MPT size but not doing the same for
>> the end address.
>> This patch applies the same shifting and masking to the end address and
>> reapplies the mask if the end address has been clamped.
> This lacks a Signed-off-by tag in any case.
>
> I'm not, however, seeing what is being fixed here:
> RDWR_COMPAT_MPT_VIRT_{START,END} are both aligned to a
> 1Gb boundary, so I'm not immediately seeing how the adjustment
> would result in any changed behavior.
>
> Also, assuming I'm overlooking something and the patch is indeed
> needed (and hence you'll resubmit), please fix the indentation to
> not use hard tabs, and adjust the lines you change anyway to
> match Xen's coding style.
>
> Jan
I didn't include a signed off by because it's an RFC patch and I wasn't completely sure the change was required.
I kept the code style of the existing code around the patch but I will update it to Xen coding style in the future
and it was my mistake for using hard tabs and my editor has been reconfigured so it won't happen in the future.

The key fix is the patch is that epfn is being compared to (RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START)
without a 2 bit shift.

This means that epfn is being compared to the size of the RDWR_COMPAT_MPT table instead of the maximum number of
entries the RDWR_COMPAT_MPT table can contain. This could result in the end regions of hotplugged memory being
inaccessible when using the RDWR_COMPAT_MPT table.

I also moved the epfn masking to occur before the comparison to RDWR_COMPAT_MPT to be consistent with the
spfn comparison code.

I can split the patch for to make the changes clearer if you want?

Malcolm

>> diff -r 274e5accd62d -r 8470671d407f xen/arch/x86/x86_64/mm.c
>> --- a/xen/arch/x86/x86_64/mm.c
>> +++ b/xen/arch/x86/x86_64/mm.c
>> @@ -446,6 +446,8 @@ static int setup_compat_m2p_table(struct
>>       int err = 0;
>>
>>       smap = info->spfn&  (~((1UL<<  (L2_PAGETABLE_SHIFT - 2)) -1));
>> +    emap = ( (epfn + ((1UL<<  (L2_PAGETABLE_SHIFT - 2)) - 1 ))&
>> +                ~((1UL<<  (L2_PAGETABLE_SHIFT - 2)) - 1) );
>>
>>       /*
>>        * Notice: For hot-added memory, only range below m2p_compat_vstart
>> @@ -454,11 +456,11 @@ static int setup_compat_m2p_table(struct
>>       if   ((smap>  ((RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START)>>
>> 2)) )
>>           return 0;
>>
>> -    if (epfn>  (RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START))
>> -        epfn = (RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START)>>  2;
>> -
>> -    emap = ( (epfn + ((1UL<<  (L2_PAGETABLE_SHIFT - 2)) - 1 ))&
>> -                ~((1UL<<  (L2_PAGETABLE_SHIFT - 2)) - 1) );
>> +    if (emap>  ((RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START)>>  2))
>> +    {
>> +        emap = (RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START)>>  2;
>> +    	emap = emap&  ~((1UL<<  (L2_PAGETABLE_SHIFT - 2)) - 1);
>> +    }
>>
>>       va = HIRO_COMPAT_MPT_VIRT_START +
>>            smap * sizeof(*compat_machine_to_phys_mapping);
>>
>> _______________________________________________
>> Xen-devel mailing list
>> Xen-devel@lists.xen.org
>> http://lists.xen.org/xen-devel
>
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] [RFC] xen: Fix memory hotplug end limit test for updating compat M2P table
  2012-04-24 16:02   ` Malcolm Crossley
@ 2012-04-24 16:11     ` Jan Beulich
  0 siblings, 0 replies; 4+ messages in thread
From: Jan Beulich @ 2012-04-24 16:11 UTC (permalink / raw)
  To: Malcolm Crossley; +Cc: Tim (Xen.org), xen-devel

>>> On 24.04.12 at 18:02, Malcolm Crossley <malcolm.crossley@citrix.com> wrote:
> The key fix is the patch is that epfn is being compared to 
> (RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START)
> without a 2 bit shift.

Ah, okay, that was well hidden among all the other changes you did,
and at least I wasn't able to decode this from the patch description.

> This means that epfn is being compared to the size of the RDWR_COMPAT_MPT 
> table instead of the maximum number of
> entries the RDWR_COMPAT_MPT table can contain. This could result in the end 
> regions of hotplugged memory being
> inaccessible when using the RDWR_COMPAT_MPT table.
> 
> I also moved the epfn masking to occur before the comparison to 
> RDWR_COMPAT_MPT to be consistent with the
> spfn comparison code.
> 
> I can split the patch for to make the changes clearer if you want?

I'm really not certain all the other changes really matter in any way,
so I'd really like to ask for a patch just adding the missing shift.

Jan

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-04-24 16:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-23 18:07 [PATCH] [RFC] xen: Fix memory hotplug end limit test for updating compat M2P table Malcolm Crossley
2012-04-24  7:21 ` Jan Beulich
2012-04-24 16:02   ` Malcolm Crossley
2012-04-24 16:11     ` Jan Beulich

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.