Re: [Xen-devel] [PATCH v4 3/9] x86/mm: introduce l{1, 2}t local variables to map_pages_to_xen

2019-12-05 Thread Jan Beulich
On 04.12.2019 19:01, Xia, Hongyan wrote:
>>> @@ -5272,6 +5279,7 @@ int map_pages_to_xen(
>>>  ((1u << PAGETABLE_ORDER) - 1)) == 0)) )
>>>  {
>>>  unsigned long base_mfn;
>>> +l1_pgentry_t *l1t;
>>
>> const, as this looks to be used for lookup only?
> 
> I cannot do this for now since variables like l1t are still using the
> old API which is non-const. I can change it once they are switched to
> the new const API in later patches.

Maybe I've indeed picked an example where this won't work yet,
but there look to be cases where the old interface wouldn't
get in the way. I'd appreciate if at least those cases could
have const added right away.

Jan

___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH v4 3/9] x86/mm: introduce l{1, 2}t local variables to map_pages_to_xen

2019-12-04 Thread Xia, Hongyan
>> @@ -5272,6 +5279,7 @@ int map_pages_to_xen(
>>  ((1u << PAGETABLE_ORDER) - 1)) == 0)) )
>>  {
>>  unsigned long base_mfn;
>> +l1_pgentry_t *l1t;
>
> const, as this looks to be used for lookup only?

I cannot do this for now since variables like l1t are still using the
old API which is non-const. I can change it once they are switched to
the new const API in later patches.

Hongyan
___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

[Xen-devel] [PATCH v4 3/9] x86/mm: introduce l{1, 2}t local variables to map_pages_to_xen

2019-12-04 Thread Hongyan Xia
From: Wei Liu 

The pl2e and pl1e variables are heavily (ab)used in that function. It
is fine at the moment because all page tables are always mapped so
there is no need to track the life time of each variable.

We will soon have the requirement to map and unmap page tables. We
need to track the life time of each variable to avoid leakage.

Introduce some l{1,2}t variables with limited scope so that we can
track life time of pointers to xen page tables more easily.

No functional change.

Signed-off-by: Wei Liu 
Reviewed-by: Jan Beulich 
---
 xen/arch/x86/mm.c | 75 ++-
 1 file changed, 42 insertions(+), 33 deletions(-)

diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
index ca362ad638..790578d2b3 100644
--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -5234,10 +5234,12 @@ int map_pages_to_xen(
 }
 else
 {
-pl2e = l3e_to_l2e(ol3e);
+l2_pgentry_t *l2t;
+
+l2t = l3e_to_l2e(ol3e);
 for ( i = 0; i < L2_PAGETABLE_ENTRIES; i++ )
 {
-ol2e = pl2e[i];
+ol2e = l2t[i];
 if ( !(l2e_get_flags(ol2e) & _PAGE_PRESENT) )
 continue;
 if ( l2e_get_flags(ol2e) & _PAGE_PSE )
@@ -5245,21 +5247,22 @@ int map_pages_to_xen(
 else
 {
 unsigned int j;
+l1_pgentry_t *l1t;
 
-pl1e = l2e_to_l1e(ol2e);
+l1t = l2e_to_l1e(ol2e);
 for ( j = 0; j < L1_PAGETABLE_ENTRIES; j++ )
-flush_flags(l1e_get_flags(pl1e[j]));
+flush_flags(l1e_get_flags(l1t[j]));
 }
 }
 flush_area(virt, flush_flags);
 for ( i = 0; i < L2_PAGETABLE_ENTRIES; i++ )
 {
-ol2e = pl2e[i];
+ol2e = l2t[i];
 if ( (l2e_get_flags(ol2e) & _PAGE_PRESENT) &&
  !(l2e_get_flags(ol2e) & _PAGE_PSE) )
 free_xen_pagetable(l2e_to_l1e(ol2e));
 }
-free_xen_pagetable(pl2e);
+free_xen_pagetable(l2t);
 }
 }
 
@@ -5275,6 +5278,7 @@ int map_pages_to_xen(
 {
 unsigned int flush_flags =
 FLUSH_TLB | FLUSH_ORDER(2 * PAGETABLE_ORDER);
+l2_pgentry_t *l2t;
 
 /* Skip this PTE if there is no change. */
 if ( ((l3e_get_pfn(ol3e) & ~(L2_PAGETABLE_ENTRIES *
@@ -5296,12 +5300,12 @@ int map_pages_to_xen(
 continue;
 }
 
-pl2e = alloc_xen_pagetable();
-if ( pl2e == NULL )
+l2t = alloc_xen_pagetable();
+if ( l2t == NULL )
 return -ENOMEM;
 
 for ( i = 0; i < L2_PAGETABLE_ENTRIES; i++ )
-l2e_write(pl2e + i,
+l2e_write(l2t + i,
   l2e_from_pfn(l3e_get_pfn(ol3e) +
(i << PAGETABLE_ORDER),
l3e_get_flags(ol3e)));
@@ -5314,15 +5318,15 @@ int map_pages_to_xen(
 if ( (l3e_get_flags(*pl3e) & _PAGE_PRESENT) &&
  (l3e_get_flags(*pl3e) & _PAGE_PSE) )
 {
-l3e_write_atomic(pl3e, l3e_from_mfn(virt_to_mfn(pl2e),
+l3e_write_atomic(pl3e, l3e_from_mfn(virt_to_mfn(l2t),
 __PAGE_HYPERVISOR));
-pl2e = NULL;
+l2t = NULL;
 }
 if ( locking )
 spin_unlock(_pgdir_lock);
 flush_area(virt, flush_flags);
-if ( pl2e )
-free_xen_pagetable(pl2e);
+if ( l2t )
+free_xen_pagetable(l2t);
 }
 
 pl2e = virt_to_xen_l2e(virt);
@@ -5350,11 +5354,13 @@ int map_pages_to_xen(
 }
 else
 {
-pl1e = l2e_to_l1e(ol2e);
+l1_pgentry_t *l1t;
+
+l1t = l2e_to_l1e(ol2e);
 for ( i = 0; i < L1_PAGETABLE_ENTRIES; i++ )
-flush_flags(l1e_get_flags(pl1e[i]));
+flush_flags(l1e_get_flags(l1t[i]));
 flush_area(virt, flush_flags);
-free_xen_pagetable(pl1e);
+free_xen_pagetable(l1t);
 }
 }
 
@@ -5376,6 +5382,7 @@ int map_pages_to_xen(
 {
 unsigned int flush_flags =
 FLUSH_TLB | FLUSH_ORDER(PAGETABLE_ORDER);
+