Skip to contentSkip to conversation

xen: arm: Ensure all PTE bits have a known value

PATCH Superseded Chris Brand 4 participants 8 messages Aug 20, 2015 – Sep 1, 2015

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover xen: arm: Ensure all PTE bits have a known value

This is more-or-less what Julien requested. He noted that pt.config was never set to zero. When I looked further, I found other bits that were also never given a value. Looking at the callsites, they almost all seem to assume a value of zero, so that's what I went with.

Patch 1 re-orders the assignments to match the declaration, making it clearer which ones are missing. Patch 2 then adds the missing bits.

Chris

Chris Brand (2):
xen: arm re-order assignments in mfn_to_xen_entry()
xen: arm: Set all bits in mfn_to_xen_entry()

 xen/include/asm-arm/page.h | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

PATCH v2 1/2 xen: arm re-order assignments in mfn_to_xen_entry()

Shuffle lines around so that the assignments in mfn_to_xen_entry() occur in the same order as the bits are declared in lpae_pt_t. This makes it easier to see which ones are never given a value. No change in behaviour.

Also fix a minor comment typo.

---
 xen/include/asm-arm/page.h | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
xen/include/asm-arm/page.h +7 -7
index 5ecfd0705e07..01628f3e96cb 100644
@@ -197,18 +197,18 @@ static inline lpae_t mfn_to_xen_entry(unsigned long mfn, unsigned attr)
     paddr_t pa = ((paddr_t) mfn) << PAGE_SHIFT;
     lpae_t e = (lpae_t) {
         .pt = {
-            .xn = 1,              /* No need to execute outside .text */
-            .ng = 1,              /* Makes TLB flushes easier */
-            .af = 1,              /* No need for access tracking */
+            .valid = 1,           /* Mappings are present */
+            .table = 0,           /* Set to 1 for links and 4k maps */
+            .ai = attr,
             .ns = 1,              /* Hyp mode is in the non-secure world */
             .user = 1,            /* See below */
-            .ai = attr,
-            .table = 0,           /* Set to 1 for links and 4k maps */
-            .valid = 1,           /* Mappings are present */
+            .af = 1,              /* No need for access tracking */
+            .ng = 1,              /* Makes TLB flushes easier */
+            .xn = 1,              /* No need to execute outside .text */
         }};;
     /* Setting the User bit is strange, but the ATS1H[RW] instructions
      * don't seem to work otherwise, and since we never run on Xen
-     * pagetables un User mode it's OK.  If this changes, remember
+     * pagetables in User mode it's OK.  If this changes, remember
      * to update the hard-coded values in head.S too */
 
     switch ( attr )
Signature · 1 line
1.9.1
Acked-by on v2 1/2
#2 lore raw

Re: [PATCH 1/2 v2] xen: arm re-order assignments in mfn_to_xen_entry()

Quoted 9 lines · Chris Brand

Shuffle lines around so that the assignments in mfn_to_xen_entry() occur in the same order as the bits are declared in lpae_pt_t. This makes it easier to see which ones are never given a value. No change in behaviour.

Also fix a minor comment typo.

#3 lore raw

PATCH v2 2/2 xen: arm: Set all bits in mfn_to_xen_entry()

In reply to Chris Brand

Ensure that every bit has a specific value.

---
v2 adds comments on pxn and avail.

 xen/include/asm-arm/page.h | 5 +++++
 1 file changed, 5 insertions(+)
xen/include/asm-arm/page.h +5 -0
index 01628f3e96cb..4f430a5ff4fa 100644
@@ -202,9 +202,14 @@ static inline lpae_t mfn_to_xen_entry(unsigned long mfn, unsigned attr)
             .ai = attr,
             .ns = 1,              /* Hyp mode is in the non-secure world */
             .user = 1,            /* See below */
+            .ro = 0,              /* Assume read-write */
             .af = 1,              /* No need for access tracking */
             .ng = 1,              /* Makes TLB flushes easier */
+            .sbz = 0,
+            .contig = 0,          /* Assume non-contiguous */
+            .pxn = 0,             /* Reserved for PL2 stage 1 page table */
             .xn = 1,              /* No need to execute outside .text */
+            .avail = 0,           /* Reference count for domheap mapping */
         }};;
     /* Setting the User bit is strange, but the ATS1H[RW] instructions
      * don't seem to work otherwise, and since we never run on Xen
Signature · 1 line
1.9.1
#4 lore raw

Re: [PATCH 2/2 v2] xen: arm: Set all bits in mfn_to_xen_entry()

Quoted 6 lines · Chris Brand

Ensure that every bit has a specific value.

---
v2 adds comments on pxn and avail.

This is no functional change, if the compiler is conforming to the C spec.

The spec guarantees that structure initialisation like this causes unspecified names to gain their default value. As these are integer bitfields, the default value is 0.

What compiler is in use? It would appear that it is buggy, or at least has buggy scalar replacement optimisations.

~Andrew

Quoted 23 lines
 xen/include/asm-arm/page.h | 5 +++++
 1 file changed, 5 insertions(+)
xen/include/asm-arm/page.h +5 -0
index 01628f3e96cb..4f430a5ff4fa 100644
@@ -202,9 +202,14 @@ static inline lpae_t mfn_to_xen_entry(unsigned long mfn, unsigned attr)
             .ai = attr,
             .ns = 1,              /* Hyp mode is in the non-secure world */
             .user = 1,            /* See below */
+            .ro = 0,              /* Assume read-write */
             .af = 1,              /* No need for access tracking */
             .ng = 1,              /* Makes TLB flushes easier */
+            .sbz = 0,
+            .contig = 0,          /* Assume non-contiguous */
+            .pxn = 0,             /* Reserved for PL2 stage 1 page table */
             .xn = 1,              /* No need to execute outside .text */
+            .avail = 0,           /* Reference count for domheap mapping */
         }};;
     /* Setting the User bit is strange, but the ATS1H[RW] instructions
      * don't seem to work otherwise, and since we never run on Xen
#5 lore raw

Re: [PATCH 2/2 v2] xen: arm: Set all bits in mfn_to_xen_entry()

Hi Andrew,

Quoted 8 lines · Chris Brand
Quoted 6 lines

Ensure that every bit has a specific value.

---
v2 adds comments on pxn and avail.

Quoted 8 lines

This is no functional change, if the compiler is conforming to the C spec.

The spec guarantees that structure initialisation like this causes unspecified names to gain their default value. As these are integer bitfields, the default value is 0.

What compiler is in use? It would appear that it is buggy, or at least has buggy scalar replacement optimisations.

That's right. I'd forgotten about that. This was actually suggested by Julien in a review of another patch I sent. I haven't seen any problems this fixes.

Chris

#6 lore raw

Re: [PATCH 2/2 v2] xen: arm: Set all bits in mfn_to_xen_entry()

Quoted 16 lines · Chris (Christopher) Brand

Hi Andrew,

Quoted 14 lines · Chris Brand
Quoted 6 lines

Ensure that every bit has a specific value.

---
v2 adds comments on pxn and avail.

This is no functional change, if the compiler is conforming to the C spec.

The spec guarantees that structure initialisation like this causes unspecified names to gain their default value. As these are integer bitfields, the default value is 0.

Quoted 5 lines
Quoted 2 lines

What compiler is in use? It would appear that it is buggy, or at least has buggy scalar replacement optimisations.

That's right. I'd forgotten about that. This was actually suggested by Julien in a review of another patch I sent. I haven't seen any problems this fixes.

I still think those patches are valid in order to know which value are set by default and what does it mean.

Regards,

Signature · 1 line
Julien Grall
#7 lore raw

Re: [PATCH 2/2 v2] xen: arm: Set all bits in mfn_to_xen_entry()

In reply to Chris Brand
Quoted 15 lines · Chris Brand

Ensure that every bit has a specific value.

---
v2 adds comments on pxn and avail.

 xen/include/asm-arm/page.h | 5 +++++
 1 file changed, 5 insertions(+)
xen/include/asm-arm/page.h +0 -0
index 01628f3e96cb..4f430a5ff4fa 100644

xen/include/asm-arm/page.h static inline lpae_t mfn_to_xen_entry(unsigned long · line 207

Quoted 6 lines
xen/include/asm-arm/page.h +1 -0
@@ -202,9 +202,14 @@ static inline lpae_t mfn_to_xen_entry(unsigned long 
 mfn, unsigned attr)
             .ai = attr,
             .ns = 1,              /* Hyp mode is in the non-secure world 
 */
             .user = 1,            /* See below */
+            .ro = 0,              /* Assume read-write */

OK

xen/include/asm-arm/page.h static inline lpae_t mfn_to_xen_entry(unsigned long mfn, unsigned attr) · line 208

Quoted 3 lines
xen/include/asm-arm/page.h +1 -0
             .af = 1,              /* No need for access tracking */
             .ng = 1,              /* Makes TLB flushes easier */
+            .sbz = 0,

I think this one can/should be omitted, it's basically a padding field and it will be zero by C specs.

xen/include/asm-arm/page.h static inline lpae_t mfn_to_xen_entry(unsigned long mfn, unsigned attr) · line 209

Quoted 1 line
xen/include/asm-arm/page.h +1 -0
+            .contig = 0,          /* Assume non-contiguous */

OK

xen/include/asm-arm/page.h static inline lpae_t mfn_to_xen_entry(unsigned long mfn, unsigned attr) · line 210

Quoted 1 line
xen/include/asm-arm/page.h +1 -0
+            .pxn = 0,             /* Reserved for PL2 stage 1 page table */

Do you mean "Reserved in ..." or maybe "Reserved at ..."?

"Reserved for ..." doesn't make much sense since this function is constructing a PL2 stage 1 PT and this bit is not reserved for (i.e. "set aside for") use there.

I think in this context pxn is essentially a padding bit and should be just omitted as with .sbz.

xen/include/asm-arm/page.h static inline lpae_t mfn_to_xen_entry(unsigned long · line 214

Quoted 2 lines
xen/include/asm-arm/page.h +1 -0
             .xn = 1,              /* No need to execute outside .text */
+            .avail = 0,           /* Reference count for domheap mapping 

OK

Quoted 4 lines
xen/include/asm-arm/page.h +0 -0
 */
         }};;
     /* Setting the User bit is strange, but the ATS1H[RW] instructions
      * don't seem to work otherwise, and since we never run on Xen