Skip to contentSkip to conversation

x86/pagewalk: Further bugfixes to pagetable walking

RFC PATCH In review Andrew Cooper 5 participants 21 messages May 26, 2017 – Jun 1, 2017

lore
Share & tools
lore
#0 lore raw

cover x86/pagewalk: Further bugfixes to pagetable walking

These bugfixes finally allow my comprehensive XTF test (following several bugfixes, and the added feature of the 0-level pagetable tests) to complete successfully on a Skylake Server system, with PKU.

I know this is getting very tight to the line on 4.9, but it would be nice to get these fixes in.

Andrew Cooper (2):
Revert "x86/hvm: disable pkeys for guests in non-paging mode" x86/pagewalk: Fix pagewalk's handling of instruction fetches

 xen/arch/x86/hvm/vmx/vmx.c   | 11 +++++------
 xen/arch/x86/mm/guest_walk.c | 22 +++++++++-------------
 2 files changed, 14 insertions(+), 19 deletions(-)
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw

PATCH 1/2 Revert "x86/hvm: disable pkeys for guests in non-paging mode"

This reverts commit c41e0266dd59ab50b7a153157e9bd2a3ad114b53.

When determining Access Rights, Protection Keys only take effect when CR4.PKE it set, and 4-level paging is active. All other circumstances (notibly, 32bit PAE paging) skip the Protection Key control mechanism.

Therefore, we do not need to clear CR4.PKE behind the back of a guest which is not using paging, as such a guest is necesserily running with EFER.LME disabled.

The {RD,WR}PKRU instructions are specified as being legal for use in any operating mode, but only if CR4.PKE is set. By clearing CR4.PKE behind the back of an unpaged guest, these instructions yield #UD despite the guest seeing PKE set if it reads CR4, and OSPKE being visible in CPUID.

---
CC: Jan Beulich <[email protected]>
CC: Jun Nakajima <[email protected]>
CC: Kevin Tian <[email protected]>
CC: Huaitong Han <[email protected]>

---
 xen/arch/x86/hvm/vmx/vmx.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
xen/arch/x86/hvm/vmx/vmx.c +5 -6
index c8ef18a..58552c3 100644
@@ -1673,13 +1673,12 @@ static void vmx_update_guest_cr(struct vcpu *v, unsigned int cr)
         if ( !hvm_paging_enabled(v) )
         {
             /*
-             * SMEP/SMAP/PKU is disabled if CPU is in non-paging mode in
-             * hardware. However Xen always uses paging mode to emulate guest
-             * non-paging mode. To emulate this behavior, SMEP/SMAP/PKU needs
-             * to be manually disabled when guest VCPU is in non-paging mode.
+             * SMEP/SMAP is disabled if CPU is in non-paging mode in hardware.
+             * However Xen always uses paging mode to emulate guest non-paging
+             * mode. To emulate this behavior, SMEP/SMAP needs to be manually
+             * disabled when guest VCPU is in non-paging mode.
              */
-            v->arch.hvm_vcpu.hw_cr[4] &=
-                ~(X86_CR4_SMEP | X86_CR4_SMAP | X86_CR4_PKE);
+            v->arch.hvm_vcpu.hw_cr[4] &= ~(X86_CR4_SMEP | X86_CR4_SMAP);
         }
         __vmwrite(GUEST_CR4, v->arch.hvm_vcpu.hw_cr[4]);
         break;
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] Revert "x86/hvm: disable pkeys for guests in non-paging mode"

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 26.05.17 at 19:03, <[email protected]> wrote:

This reverts commit c41e0266dd59ab50b7a153157e9bd2a3ad114b53.

When determining Access Rights, Protection Keys only take effect when CR4.PKE it set, and 4-level paging is active. All other circumstances (notibly, 32bit PAE paging) skip the Protection Key control mechanism.

Therefore, we do not need to clear CR4.PKE behind the back of a guest which is not using paging, as such a guest is necesserily running with EFER.LME disabled.

DYM EFER.LMA here?

Quoted 6 lines

The {RD,WR}PKRU instructions are specified as being legal for use in any operating mode, but only if CR4.PKE is set. By clearing CR4.PKE behind the back of an unpaged guest, these instructions yield #UD despite the guest seeing PKE set if it reads CR4, and OSPKE being visible in CPUID.

I would like to get clarification from Huaitong, however, on the reason for the original change: According to the reasoning here, it shouldn't have been an observed failure of some kind, but merely the thinking that something may be wrong (but really wasn't).

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Reviewed-by on v1 1/2
#3 lore raw

Re: [PATCH 1/2] Revert "x86/hvm: disable pkeys for guests in non-paging mode"

In reply to Andrew Cooper
Quoted 9 lines · Andrew Cooper

This reverts commit c41e0266dd59ab50b7a153157e9bd2a3ad114b53.

When determining Access Rights, Protection Keys only take effect when CR4.PKE it set, and 4-level paging is active. All other circumstances (notibly, 32bit PAE paging) skip the Protection Key control mechanism.

Therefore, we do not need to clear CR4.PKE behind the back of a guest which is not using paging, as such a guest is necesserily running with EFER.LME disabled.

Yes, if EFER.LME = 0, Protection Keys would take no effect too, so it isn't necessary to clear CR4.PKE in non-paging mode.

Quoted 5 lines

The {RD,WR}PKRU instructions are specified as being legal for use in any operating mode, but only if CR4.PKE is set. By clearing CR4.PKE behind the back of an unpaged guest, these instructions yield #UD despite the guest seeing PKE set if it reads CR4, and OSPKE being visible in CPUID.

If CR4.PKE is cleared, OSPKE would be invisible at the same time. When guest does set CR4_PKE in non-paging mode, then CR4_PKE would be cleared in vmcs loading, so, OSPKE should be always invisible, and #UD should not be yielded too.

Quoted 24 lines

---
CC: Jan Beulich <[email protected]>
CC: Jun Nakajima <[email protected]>
CC: Kevin Tian <[email protected]>
CC: Huaitong Han <[email protected]>

---
 xen/arch/x86/hvm/vmx/vmx.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
xen/arch/x86/hvm/vmx/vmx.c +1 -4
index c8ef18a..58552c3 100644
@@ -1673,13 +1673,12 @@ static void vmx_update_guest_cr(struct vcpu *v, unsigned int cr)
         if ( !hvm_paging_enabled(v) )
         {
             /*
-             * SMEP/SMAP/PKU is disabled if CPU is in non-paging mode in
-             * hardware. However Xen always uses paging mode to emulate guest
-             * non-paging mode. To emulate this behavior, SMEP/SMAP/PKU needs
-             * to be manually disabled when guest VCPU is in non-paging mode.
+             * SMEP/SMAP is disabled if CPU is in non-paging mode in hardware.

xen/arch/x86/hvm/vmx/vmx.c static void vmx_update_guest_cr(struct vcpu *v, unsigned int cr) · line 1684

Quoted 10 lines
xen/arch/x86/hvm/vmx/vmx.c +4 -2
+             * However Xen always uses paging mode to emulate guest non-paging
+             * mode. To emulate this behavior, SMEP/SMAP needs to be manually
+             * disabled when guest VCPU is in non-paging mode.
              */
-            v->arch.hvm_vcpu.hw_cr[4] &=
-                ~(X86_CR4_SMEP | X86_CR4_SMAP | X86_CR4_PKE);
+            v->arch.hvm_vcpu.hw_cr[4] &= ~(X86_CR4_SMEP | X86_CR4_SMAP);
         }
         __vmwrite(GUEST_CR4, v->arch.hvm_vcpu.hw_cr[4]);
         break;

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#4 lore raw

Re: [PATCH 1/2] Revert "x86/hvm: disable pkeys for guests in non-paging mode"

Quoted 13 lines · Huaitong
Quoted 9 lines · Andrew Cooper

This reverts commit c41e0266dd59ab50b7a153157e9bd2a3ad114b53.

When determining Access Rights, Protection Keys only take effect when CR4.PKE it set, and 4-level paging is active. All other circumstances (notibly, 32bit PAE paging) skip the Protection Key control mechanism.

Therefore, we do not need to clear CR4.PKE behind the back of a guest which is not using paging, as such a guest is necesserily running with EFER.LME disabled.

Yes, if EFER.LME = 0, Protection Keys would take no effect too, so it isn't necessary to clear CR4.PKE in non-paging mode.

Quoted 8 lines
Quoted 4 lines

The {RD,WR}PKRU instructions are specified as being legal for use in any operating mode, but only if CR4.PKE is set. By clearing CR4.PKE behind the back of an unpaged guest, these instructions yield #UD despite the guest seeing PKE set if it reads CR4, and OSPKE being visible in CPUID.

If CR4.PKE is cleared, OSPKE would be invisible at the same time. When guest does set CR4_PKE in non-paging mode, then CR4_PKE would be cleared in vmcs loading, so, OSPKE should be always invisible, and #UD should not be yielded too.

Remember that for HVM guests, Xen calculates OSPKE in software; it never comes from hardware, as CPUID is an automatic VMEXIT.

The CPUID code uses the same source of information as a read from cr4, so comes to the conclusion that OSPKE should be visible.

Therefore, when the guest looks at CPUID, it sees OSPKE set even though hardware would come to the opposite conclusion.

Quoted 1 line

Does this stand despite the OSPKE issue?

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#5 lore raw

Re: [PATCH 1/2] Revert "x86/hvm: disable pkeys for guests in non-paging mode"

Quoted 27 lines
Quoted 1 line
Quoted 1 line · On 31.05.17 at 09:44, <[email protected]> wrote:
Quoted 4 lines · Huaitong
Quoted 3 lines · Andrew Cooper

This reverts commit c41e0266dd59ab50b7a153157e9bd2a3ad114b53.

When determining Access Rights, Protection Keys only take effect when

CR4.PKE

Quoted 1 line
Quoted 1 line

it set, and 4-level paging is active. All other circumstances (notibly,

32bit

Quoted 3 lines
Quoted 3 lines

PAE paging) skip the Protection Key control mechanism.

Therefore, we do not need to clear CR4.PKE behind the back of a guest which

is

Quoted 5 lines
Quoted 2 lines

not using paging, as such a guest is necesserily running with EFER.LME disabled.

Yes, if EFER.LME = 0, Protection Keys would take no effect too, so it isn't necessary to clear CR4.PKE in non-paging mode.

Quoted 8 lines
Quoted 4 lines

The {RD,WR}PKRU instructions are specified as being legal for use in any operating mode, but only if CR4.PKE is set. By clearing CR4.PKE behind the back of an unpaged guest, these instructions yield #UD despite the guest seeing PKE set if it reads CR4, and OSPKE being visible in CPUID.

If CR4.PKE is cleared, OSPKE would be invisible at the same time. When guest does set CR4_PKE in non-paging mode, then CR4_PKE would be cleared in vmcs loading, so, OSPKE should be always invisible, and #UD should not be yielded too.

Quoted 8 lines

Remember that for HVM guests, Xen calculates OSPKE in software; it never comes from hardware, as CPUID is an automatic VMEXIT.

The CPUID code uses the same source of information as a read from cr4, so comes to the conclusion that OSPKE should be visible.

Therefore, when the guest looks at CPUID, it sees OSPKE set even though hardware would come to the opposite conclusion.

Shouldn't we correct this (independent of the patch here)?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#6 lore raw

Re: [PATCH 1/2] Revert "x86/hvm: disable pkeys for guests in non-paging mode"

Quoted 29 lines · Jan Beulich
Quoted 29 lines
Quoted 1 line
Quoted 1 line · On 31.05.17 at 09:44, <[email protected]> wrote:
Quoted 4 lines · Huaitong
Quoted 3 lines · Andrew Cooper

This reverts commit c41e0266dd59ab50b7a153157e9bd2a3ad114b53.

When determining Access Rights, Protection Keys only take effect when

CR4.PKE

Quoted 1 line
Quoted 1 line

it set, and 4-level paging is active. All other circumstances (notibly,

32bit

Quoted 3 lines
Quoted 3 lines

PAE paging) skip the Protection Key control mechanism.

Therefore, we do not need to clear CR4.PKE behind the back of a guest which

is

Quoted 5 lines
Quoted 2 lines

not using paging, as such a guest is necesserily running with EFER.LME disabled.

Yes, if EFER.LME = 0, Protection Keys would take no effect too, so it isn't necessary to clear CR4.PKE in non-paging mode.

Quoted 8 lines
Quoted 4 lines

The {RD,WR}PKRU instructions are specified as being legal for use in any operating mode, but only if CR4.PKE is set. By clearing CR4.PKE behind the back of an unpaged guest, these instructions yield #UD despite the guest seeing PKE set if it reads CR4, and OSPKE being visible in CPUID.

If CR4.PKE is cleared, OSPKE would be invisible at the same time. When guest does set CR4_PKE in non-paging mode, then CR4_PKE would be cleared in vmcs loading, so, OSPKE should be always invisible, and #UD should not be yielded too.

Remember that for HVM guests, Xen calculates OSPKE in software; it never comes from hardware, as CPUID is an automatic VMEXIT.

Quoted 6 lines
Quoted 5 lines

The CPUID code uses the same source of information as a read from cr4, so comes to the conclusion that OSPKE should be visible.

Therefore, when the guest looks at CPUID, it sees OSPKE set even though hardware would come to the opposite conclusion.

Shouldn't we correct this (independent of the patch here)?

No, I don't think so. That would involve the generic cpuid code looking at GUEST_CR4 and making decisions contrary to what is described in the manuals.

Besides, it very definitely should be visible in a read of CR4 (because the guest did really set it), which means OSPKE should be visible in CPUID.

This corner case (along with others) will soon be regression tested in the (newly-introduced) 0-level paging pagetable-emulation XTF test, which I put together after stumbling blindly into this particular #UD while investigating a different issue.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#7 lore raw

Re: [PATCH 1/2] Revert "x86/hvm: disable pkeys for guests in non-paging mode"

Quoted 36 lines
Quoted 1 line
Quoted 1 line · On 31.05.17 at 10:06, <[email protected]> wrote:
Quoted 34 lines · Jan Beulich
Quoted 34 lines
Quoted 1 line
Quoted 1 line · On 31.05.17 at 09:44, <[email protected]> wrote:
Quoted 4 lines · Huaitong
Quoted 3 lines · Andrew Cooper

This reverts commit c41e0266dd59ab50b7a153157e9bd2a3ad114b53.

When determining Access Rights, Protection Keys only take effect when

CR4.PKE

Quoted 1 line
Quoted 1 line

it set, and 4-level paging is active. All other circumstances (notibly,

32bit

Quoted 3 lines
Quoted 3 lines

PAE paging) skip the Protection Key control mechanism.

Therefore, we do not need to clear CR4.PKE behind the back of a guest which

is

Quoted 5 lines
Quoted 2 lines

not using paging, as such a guest is necesserily running with EFER.LME disabled.

Yes, if EFER.LME = 0, Protection Keys would take no effect too, so it isn't necessary to clear CR4.PKE in non-paging mode.

Quoted 8 lines
Quoted 4 lines

The {RD,WR}PKRU instructions are specified as being legal for use in any operating mode, but only if CR4.PKE is set. By clearing CR4.PKE behind the back of an unpaged guest, these instructions yield #UD despite the guest seeing PKE set if it reads CR4, and OSPKE being visible in CPUID.

If CR4.PKE is cleared, OSPKE would be invisible at the same time. When guest does set CR4_PKE in non-paging mode, then CR4_PKE would be cleared in vmcs loading, so, OSPKE should be always invisible, and #UD should not be yielded too.

Remember that for HVM guests, Xen calculates OSPKE in software; it never comes from hardware, as CPUID is an automatic VMEXIT.

The CPUID code uses the same source of information as a read from cr4, so comes to the conclusion that OSPKE should be visible.

Therefore, when the guest looks at CPUID, it sees OSPKE set even though hardware would come to the opposite conclusion.

Quoted 8 lines
Quoted 1 line

Shouldn't we correct this (independent of the patch here)?

No, I don't think so. That would involve the generic cpuid code looking at GUEST_CR4 and making decisions contrary to what is described in the manuals.

Besides, it very definitely should be visible in a read of CR4 (because the guest did really set it), which means OSPKE should be visible in CPUID.

Oh, then I misunderstood your earlier reply, taking it that we wrongly show the flag as set to the guest.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#8 lore raw

Re: [PATCH 1/2] Revert "x86/hvm: disable pkeys for guests in non-paging mode"

In reply to Andrew Cooper
Quoted 23 lines · Andrew Cooper
Quoted 13 lines · Huaitong
Quoted 9 lines · Andrew Cooper

This reverts commit c41e0266dd59ab50b7a153157e9bd2a3ad114b53.

When determining Access Rights, Protection Keys only take effect when CR4.PKE it set, and 4-level paging is active. All other circumstances (notibly, 32bit PAE paging) skip the Protection Key control mechanism.

Therefore, we do not need to clear CR4.PKE behind the back of a guest which is not using paging, as such a guest is necesserily running with EFER.LME disabled.

Yes, if EFER.LME = 0, Protection Keys would take no effect too, so it isn't necessary to clear CR4.PKE in non-paging mode.

Quoted 8 lines
Quoted 4 lines

The {RD,WR}PKRU instructions are specified as being legal for use in any operating mode, but only if CR4.PKE is set. By clearing CR4.PKE behind the back of an unpaged guest, these instructions yield #UD despite the guest seeing PKE set if it reads CR4, and OSPKE being visible in CPUID.

If CR4.PKE is cleared, OSPKE would be invisible at the same time. When guest does set CR4_PKE in non-paging mode, then CR4_PKE would be cleared in vmcs loading, so, OSPKE should be always invisible, and #UD should not be yielded too.

Quoted 8 lines

Remember that for HVM guests, Xen calculates OSPKE in software; it never comes from hardware, as CPUID is an automatic VMEXIT.

The CPUID code uses the same source of information as a read from cr4, so comes to the conclusion that OSPKE should be visible.

Therefore, when the guest looks at CPUID, it sees OSPKE set even though hardware would come to the opposite conclusion.

Yes, I get the reason: the hw_cr4 is updated, but the guest_cr4 is not updated, so the OSPKE is visible.

Quoted 4 lines
Quoted 2 lines

Does this stand despite the OSPKE issue?

Yes, I have no comments now.

Quoted 2 lines

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Acked-by
#9 lore raw

Re: [PATCH 1/2] Revert "x86/hvm: disable pkeys for guests in non-paging mode"

Quoted 40 lines

From: Han, Huaitong
Sent: Wednesday, May 31, 2017 4:15 PM

Quoted 5 lines · Andrew Cooper
Quoted 4 lines · Huaitong
Quoted 3 lines · Andrew Cooper

This reverts commit c41e0266dd59ab50b7a153157e9bd2a3ad114b53.

When determining Access Rights, Protection Keys only take effect when

CR4.PKE

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

it set, and 4-level paging is active. All other circumstances (notibly, 32bit PAE paging) skip the Protection Key control mechanism.

Therefore, we do not need to clear CR4.PKE behind the back of a guest

which is

Quoted 7 lines
Quoted 7 lines
Quoted 2 lines

not using paging, as such a guest is necesserily running with EFER.LME disabled.

Yes, if EFER.LME = 0, Protection Keys would take no effect too, so it isn't necessary to clear CR4.PKE in non-paging mode.

Quoted 2 lines

The {RD,WR}PKRU instructions are specified as being legal for use in any operating mode, but only if CR4.PKE is set. By clearing CR4.PKE behind

the

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

back of an unpaged guest, these instructions yield #UD despite the guest seeing PKE set if it reads CR4, and OSPKE being visible in CPUID.

If CR4.PKE is cleared, OSPKE would be invisible at the same time. When guest does set CR4_PKE in non-paging mode, then CR4_PKE would be

cleared

Quoted 11 lines
Quoted 2 lines

in vmcs loading, so, OSPKE should be always invisible, and #UD should not be yielded too.

Remember that for HVM guests, Xen calculates OSPKE in software; it never comes from hardware, as CPUID is an automatic VMEXIT.

The CPUID code uses the same source of information as a read from cr4, so comes to the conclusion that OSPKE should be visible.

Therefore, when the guest looks at CPUID, it sees OSPKE set even though hardware would come to the opposite conclusion.

Quoted 9 lines

Yes, I get the reason: the hw_cr4 is updated, but the guest_cr4 is not updated, so the OSPKE is visible.

Quoted 4 lines
Quoted 2 lines

Does this stand despite the OSPKE issue?

Yes, I have no comments now.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#10 lore raw

PATCH 2/2 x86/pagewalk: Fix pagewalk's handling of instruction fetches

In reply to Andrew Cooper

Despite the claim in the comment (which was based partly on the code already being like that, and mistaken reasoning because of Xen leaking NX into guest context), reality differs.

Use of the SMAP feature without NX, or in a 2-level guest, demonstrate an observable difference between reads and instruction fetches, despite PFEC_insn_fetch not being reported in the #PF error code. This demonstrates that instruction fetches are distinguished from data reads even without PFEC_insn_fetch being reported.

Alter the pagewalk logic to keep the pagewalk insn_fetch input intact, but only conditionally report insn_fetch in the error code. This logic is more in line with the Intel SDM text:

* I/D flag (bit 4).
This flag is 1 if (1) the access causing the page-fault exception was an instruction fetch; and (2) either (a) CR4.SMEP = 1; or (b) both (i) CR4.PAE = 1 (either PAE paging or 4-level paging is in use); and (ii) IA32_EFER.NXE = 1. Otherwise, the flag is 0. This flag describes the access causing the page-fault exception, not the access rights specified by paging.

and the AMD SDM text:

* I/D - Bit 4. If this bit is set to 1, it indicates that the access that caused the page fault was an instruction fetch. Otherwise, this bit is cleared to 0. This bit is only defined if no-execute feature is enabled (EFER.NXE=1 && CR4.PAE=1).

Curiously, the AMD manual doesn't mention SMEP despite some Fam16h processors and all Fam17h processors supporting it. Experimentally, it behaves as described by Intel.

---
CC: Jan Beulich <[email protected]>
CC: Tim Deegan <[email protected]>
CC: George Dunlap <[email protected]>

---
 xen/arch/x86/mm/guest_walk.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)
xen/arch/x86/mm/guest_walk.c +9 -13
index 5c6a85b..972364f 100644
@@ -114,22 +114,18 @@ guest_walk_tables(struct vcpu *v, struct p2m_domain *p2m,
     ASSERT(!(walk & PFEC_implicit) ||
            !(walk & (PFEC_insn_fetch | PFEC_user_mode)));
 
-    /*
-     * PFEC_insn_fetch is only used as an input to pagetable walking if NX or
-     * SMEP are enabled.  Otherwise, instruction fetches are indistinguishable
-     * from data reads.
-     *
-     * This property can be demonstrated on real hardware by having NX and
-     * SMEP inactive, but SMAP active, and observing that EFLAGS.AC determines
-     * whether a pagefault occures for supervisor execution on user mappings.
-     */
-    if ( !(guest_nx_enabled(v) || guest_smep_enabled(v)) )
-        walk &= ~PFEC_insn_fetch;
-
     perfc_incr(guest_walk);
     memset(gw, 0, sizeof(*gw));
     gw->va = va;
-    gw->pfec = walk & (PFEC_insn_fetch | PFEC_user_mode | PFEC_write_access);
+    gw->pfec = walk & (PFEC_user_mode | PFEC_write_access);
+
+    /*
+     * PFEC_insn_fetch is only reported if NX or SMEP are enabled.  Hardware
+     * still distingueses instruction fetches during determination of access
+     * rights.
+     */
+    if ( guest_nx_enabled(v) || guest_smep_enabled(v) )
+        gw->pfec |= (walk & PFEC_insn_fetch);
 
 #if GUEST_PAGING_LEVELS >= 3 /* PAE or 64... */
 #if GUEST_PAGING_LEVELS >= 4 /* 64-bit only... */
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#11 lore raw

Re: [PATCH 2/2] x86/pagewalk: Fix pagewalk's handling of instruction fetches

Quoted 25 lines
Quoted 1 line
Quoted 1 line · On 26.05.17 at 19:03, <[email protected]> wrote:
xen/arch/x86/mm/guest_walk.c +2 -13
@@ -114,22 +114,18 @@ guest_walk_tables(struct vcpu *v, struct p2m_domain *p2m,
     ASSERT(!(walk & PFEC_implicit) ||
            !(walk & (PFEC_insn_fetch | PFEC_user_mode)));
 
-    /*
-     * PFEC_insn_fetch is only used as an input to pagetable walking if NX or
-     * SMEP are enabled.  Otherwise, instruction fetches are indistinguishable
-     * from data reads.
-     *
-     * This property can be demonstrated on real hardware by having NX and
-     * SMEP inactive, but SMAP active, and observing that EFLAGS.AC determines
-     * whether a pagefault occures for supervisor execution on user mappings.
-     */
-    if ( !(guest_nx_enabled(v) || guest_smep_enabled(v)) )
-        walk &= ~PFEC_insn_fetch;
-
     perfc_incr(guest_walk);
     memset(gw, 0, sizeof(*gw));
     gw->va = va;
-    gw->pfec = walk & (PFEC_insn_fetch | PFEC_user_mode | PFEC_write_access);
+    gw->pfec = walk & (PFEC_user_mode | PFEC_write_access);
+

xen/arch/x86/mm/guest_walk.c guest_walk_tables(struct vcpu *v, struct p2m_domain *p2m, · line 131

Quoted 10 lines
xen/arch/x86/mm/guest_walk.c +7 -0
+    /*
+     * PFEC_insn_fetch is only reported if NX or SMEP are enabled.  Hardware
+     * still distingueses instruction fetches during determination of access
+     * rights.
+     */
+    if ( guest_nx_enabled(v) || guest_smep_enabled(v) )
+        gw->pfec |= (walk & PFEC_insn_fetch);
 
 #if GUEST_PAGING_LEVELS >= 3 /* PAE or 64... */
 #if GUEST_PAGING_LEVELS >= 4 /* 64-bit only... */

Don't you another adjustment to

    if ( (walk & PFEC_insn_fetch) && (ar & _PAGE_NX_BIT) )
        /* Requested an instruction fetch and found NX? Fail. */
        goto out;

I can't see anything that would keep _PAGE_NX_BIT out of ar if NX is not enabled.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#12 lore raw

Re: [PATCH 2/2] x86/pagewalk: Fix pagewalk's handling of instruction fetches

Quoted 37 lines · Jan Beulich
Quoted 25 lines
Quoted 1 line
Quoted 1 line · On 26.05.17 at 19:03, <[email protected]> wrote:
xen/arch/x86/mm/guest_walk.c +2 -13
@@ -114,22 +114,18 @@ guest_walk_tables(struct vcpu *v, struct p2m_domain *p2m,
     ASSERT(!(walk & PFEC_implicit) ||
            !(walk & (PFEC_insn_fetch | PFEC_user_mode)));
 
-    /*
-     * PFEC_insn_fetch is only used as an input to pagetable walking if NX or
-     * SMEP are enabled.  Otherwise, instruction fetches are indistinguishable
-     * from data reads.
-     *
-     * This property can be demonstrated on real hardware by having NX and
-     * SMEP inactive, but SMAP active, and observing that EFLAGS.AC determines
-     * whether a pagefault occures for supervisor execution on user mappings.
-     */
-    if ( !(guest_nx_enabled(v) || guest_smep_enabled(v)) )
-        walk &= ~PFEC_insn_fetch;
-
     perfc_incr(guest_walk);
     memset(gw, 0, sizeof(*gw));
     gw->va = va;
-    gw->pfec = walk & (PFEC_insn_fetch | PFEC_user_mode | PFEC_write_access);
+    gw->pfec = walk & (PFEC_user_mode | PFEC_write_access);
+

xen/arch/x86/mm/guest_walk.c guest_walk_tables(struct vcpu *v, struct p2m_domain *p2m, · line 131

Quoted 10 lines
xen/arch/x86/mm/guest_walk.c +7 -0
+    /*
+     * PFEC_insn_fetch is only reported if NX or SMEP are enabled.  Hardware
+     * still distingueses instruction fetches during determination of access
+     * rights.
+     */
+    if ( guest_nx_enabled(v) || guest_smep_enabled(v) )
+        gw->pfec |= (walk & PFEC_insn_fetch);
 
 #if GUEST_PAGING_LEVELS >= 3 /* PAE or 64... */
 #if GUEST_PAGING_LEVELS >= 4 /* 64-bit only... */

Don't you another adjustment to

Quoted 6 lines
    if ( (walk & PFEC_insn_fetch) && (ar & _PAGE_NX_BIT) )
        /* Requested an instruction fetch and found NX? Fail. */
        goto out;

I can't see anything that would keep _PAGE_NX_BIT out of ar if NX is not enabled.

_PAGE_NX_BIT is reserved if NX is not enabled, and is accounted for in guest_rsvd_bits() in guest_pt.h, and we never hit the access rights logic.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Reviewed-by
#13 lore raw

Re: [PATCH 2/2] x86/pagewalk: Fix pagewalk's handling of instruction fetches

Quoted 43 lines
Quoted 1 line
Quoted 1 line · On 29.05.17 at 11:03, <[email protected]> wrote:
Quoted 41 lines · Jan Beulich
Quoted 25 lines
Quoted 1 line
Quoted 1 line · On 26.05.17 at 19:03, <[email protected]> wrote:
xen/arch/x86/mm/guest_walk.c +2 -13
@@ -114,22 +114,18 @@ guest_walk_tables(struct vcpu *v, struct p2m_domain *p2m,
     ASSERT(!(walk & PFEC_implicit) ||
            !(walk & (PFEC_insn_fetch | PFEC_user_mode)));
 
-    /*
-     * PFEC_insn_fetch is only used as an input to pagetable walking if NX or
-     * SMEP are enabled.  Otherwise, instruction fetches are indistinguishable
-     * from data reads.
-     *
-     * This property can be demonstrated on real hardware by having NX and
-     * SMEP inactive, but SMAP active, and observing that EFLAGS.AC determines
-     * whether a pagefault occures for supervisor execution on user mappings.
-     */
-    if ( !(guest_nx_enabled(v) || guest_smep_enabled(v)) )
-        walk &= ~PFEC_insn_fetch;
-
     perfc_incr(guest_walk);
     memset(gw, 0, sizeof(*gw));
     gw->va = va;
-    gw->pfec = walk & (PFEC_insn_fetch | PFEC_user_mode | PFEC_write_access);
+    gw->pfec = walk & (PFEC_user_mode | PFEC_write_access);
+

xen/arch/x86/mm/guest_walk.c guest_walk_tables(struct vcpu *v, struct p2m_domain *p2m, · line 131

Quoted 10 lines
xen/arch/x86/mm/guest_walk.c +7 -0
+    /*
+     * PFEC_insn_fetch is only reported if NX or SMEP are enabled.  Hardware
+     * still distingueses instruction fetches during determination of access
+     * rights.
+     */
+    if ( guest_nx_enabled(v) || guest_smep_enabled(v) )
+        gw->pfec |= (walk & PFEC_insn_fetch);
 
 #if GUEST_PAGING_LEVELS >= 3 /* PAE or 64... */
 #if GUEST_PAGING_LEVELS >= 4 /* 64-bit only... */

Don't you another adjustment to

    if ( (walk & PFEC_insn_fetch) && (ar & _PAGE_NX_BIT) )
        /* Requested an instruction fetch and found NX? Fail. */
        goto out;
Quoted 5 lines
Quoted 2 lines

I can't see anything that would keep _PAGE_NX_BIT out of ar if NX is not enabled.

_PAGE_NX_BIT is reserved if NX is not enabled, and is accounted for in guest_rsvd_bits() in guest_pt.h, and we never hit the access rights logic.

Ah, right. But perhaps worth having a respective ASSERT() here, at once serving as documentation? In any event

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#14 lore raw

Re: [PATCH 2/2] x86/pagewalk: Fix pagewalk's handling of instruction fetches

Quoted 43 lines · Jan Beulich
Quoted 43 lines
Quoted 1 line
Quoted 1 line · On 29.05.17 at 11:03, <[email protected]> wrote:
Quoted 41 lines · Jan Beulich
Quoted 25 lines
Quoted 1 line
Quoted 1 line · On 26.05.17 at 19:03, <[email protected]> wrote:
xen/arch/x86/mm/guest_walk.c +2 -13
@@ -114,22 +114,18 @@ guest_walk_tables(struct vcpu *v, struct p2m_domain *p2m,
     ASSERT(!(walk & PFEC_implicit) ||
            !(walk & (PFEC_insn_fetch | PFEC_user_mode)));
 
-    /*
-     * PFEC_insn_fetch is only used as an input to pagetable walking if NX or
-     * SMEP are enabled.  Otherwise, instruction fetches are indistinguishable
-     * from data reads.
-     *
-     * This property can be demonstrated on real hardware by having NX and
-     * SMEP inactive, but SMAP active, and observing that EFLAGS.AC determines
-     * whether a pagefault occures for supervisor execution on user mappings.
-     */
-    if ( !(guest_nx_enabled(v) || guest_smep_enabled(v)) )
-        walk &= ~PFEC_insn_fetch;
-
     perfc_incr(guest_walk);
     memset(gw, 0, sizeof(*gw));
     gw->va = va;
-    gw->pfec = walk & (PFEC_insn_fetch | PFEC_user_mode | PFEC_write_access);
+    gw->pfec = walk & (PFEC_user_mode | PFEC_write_access);
+

xen/arch/x86/mm/guest_walk.c guest_walk_tables(struct vcpu *v, struct p2m_domain *p2m, · line 131

Quoted 10 lines
xen/arch/x86/mm/guest_walk.c +7 -0
+    /*
+     * PFEC_insn_fetch is only reported if NX or SMEP are enabled.  Hardware
+     * still distingueses instruction fetches during determination of access
+     * rights.
+     */
+    if ( guest_nx_enabled(v) || guest_smep_enabled(v) )
+        gw->pfec |= (walk & PFEC_insn_fetch);
 
 #if GUEST_PAGING_LEVELS >= 3 /* PAE or 64... */
 #if GUEST_PAGING_LEVELS >= 4 /* 64-bit only... */

Don't you another adjustment to

    if ( (walk & PFEC_insn_fetch) && (ar & _PAGE_NX_BIT) )
        /* Requested an instruction fetch and found NX? Fail. */
        goto out;
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

I can't see anything that would keep _PAGE_NX_BIT out of ar if NX is not enabled.

_PAGE_NX_BIT is reserved if NX is not enabled, and is accounted for in guest_rsvd_bits() in guest_pt.h, and we never hit the access rights logic.

Ah, right. But perhaps worth having a respective ASSERT() here, at once serving as documentation?

I could, but it would feel be out of place. NX being incorrectly set is a translation failure, and by definition, the translation needs to have succeeded before permissions get considered.

Would this clarification be acceptable?

index 5c6a85b..6d6b454 100644

xen/arch/x86/mm/guest_walk.c +0 -0
@@ -360,8 +360,9 @@ guest_walk_tables(struct vcpu *v, struct p2m_domain

*p2m,

     gw->pfec |= PFEC_page_present;
 
     /*
-     * The pagetable walk has returned a successful translation.  Now check
-     * access rights to see whether the access should succeed.
+     * The pagetable walk has returned a successful translation (i.e. All
+     * PTEs are present and have no reserved bits set).  Now check access
+     * rights to see whether the access should succeed.
      */
     ar = (ar_and & AR_ACCUM_AND) | (ar_or & AR_ACCUM_OR);

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#15 lore raw

Re: [PATCH 2/2] x86/pagewalk: Fix pagewalk's handling of instruction fetches

Quoted 69 lines
Quoted 1 line
Quoted 1 line · On 01.06.17 at 12:19, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 29.05.17 at 11:03, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich

xen/arch/x86/mm/guest_walk.c guest_walk_tables(struct vcpu *v, struct p2m_domain

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 26.05.17 at 19:03, <[email protected]> wrote:
xen/arch/x86/mm/guest_walk.c +0 -0
@@ -114,22 +114,18 @@ guest_walk_tables(struct vcpu *v, struct p2m_domain 

*p2m,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

xen/arch/x86/mm/guest_walk.c guest_walk_tables(struct vcpu *v, struct p2m_domain · line 118

Quoted 5 lines
xen/arch/x86/mm/guest_walk.c +0 -2
     ASSERT(!(walk & PFEC_implicit) ||
            !(walk & (PFEC_insn_fetch | PFEC_user_mode)));
 
-    /*
-     * PFEC_insn_fetch is only used as an input to pagetable walking if NX 

or

Quoted 1 line
Quoted 1 line
Quoted 1 line

xen/arch/x86/mm/guest_walk.c guest_walk_tables(struct vcpu *v, struct p2m_domain · line 119

Quoted 1 line
xen/arch/x86/mm/guest_walk.c +0 -1
-     * SMEP are enabled.  Otherwise, instruction fetches are 

indistinguishable

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

xen/arch/x86/mm/guest_walk.c guest_walk_tables(struct vcpu *v, struct p2m_domain · line 123

Quoted 4 lines
xen/arch/x86/mm/guest_walk.c +0 -4
-     * from data reads.
-     *
-     * This property can be demonstrated on real hardware by having NX and
-     * SMEP inactive, but SMAP active, and observing that EFLAGS.AC 

determines

Quoted 1 line
Quoted 1 line
Quoted 1 line

xen/arch/x86/mm/guest_walk.c guest_walk_tables(struct vcpu *v, struct p2m_domain · line 124

Quoted 1 line
xen/arch/x86/mm/guest_walk.c +0 -1
-     * whether a pagefault occures for supervisor execution on user 

mappings.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
xen/arch/x86/mm/guest_walk.c +0 -4
-     */
-    if ( !(guest_nx_enabled(v) || guest_smep_enabled(v)) )
-        walk &= ~PFEC_insn_fetch;
-
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

xen/arch/x86/mm/guest_walk.c guest_walk_tables(struct vcpu *v, struct p2m_domain · line 123

Quoted 8 lines
xen/arch/x86/mm/guest_walk.c +4 -1
     perfc_incr(guest_walk);
     memset(gw, 0, sizeof(*gw));
     gw->va = va;
-    gw->pfec = walk & (PFEC_insn_fetch | PFEC_user_mode | PFEC_write_access);
+    gw->pfec = walk & (PFEC_user_mode | PFEC_write_access);
+
+    /*
+     * PFEC_insn_fetch is only reported if NX or SMEP are enabled.  

Hardware

Quoted 1 line
Quoted 1 line
Quoted 1 line

xen/arch/x86/mm/guest_walk.c guest_walk_tables(struct vcpu *v, struct p2m_domain · line 124

Quoted 1 line
xen/arch/x86/mm/guest_walk.c +1 -0
+     * still distingueses instruction fetches during determination of 

access

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines

xen/arch/x86/mm/guest_walk.c guest_walk_tables(struct vcpu *v, struct p2m_domain · line 131

Quoted 7 lines
xen/arch/x86/mm/guest_walk.c +4 -0
+     * rights.
+     */
+    if ( guest_nx_enabled(v) || guest_smep_enabled(v) )
+        gw->pfec |= (walk & PFEC_insn_fetch);
 
 #if GUEST_PAGING_LEVELS >= 3 /* PAE or 64... */
 #if GUEST_PAGING_LEVELS >= 4 /* 64-bit only... */

Don't you another adjustment to

    if ( (walk & PFEC_insn_fetch) && (ar & _PAGE_NX_BIT) )
        /* Requested an instruction fetch and found NX? Fail. */
        goto out;
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

I can't see anything that would keep _PAGE_NX_BIT out of ar if NX is not enabled.

_PAGE_NX_BIT is reserved if NX is not enabled, and is accounted for in guest_rsvd_bits() in guest_pt.h, and we never hit the access rights logic.

Ah, right. But perhaps worth having a respective ASSERT() here, at once serving as documentation?

I could, but it would feel be out of place. NX being incorrectly set is a translation failure, and by definition, the translation needs to have succeeded before permissions get considered.

Would this clarification be acceptable?

index 5c6a85b..6d6b454 100644

xen/arch/x86/mm/guest_walk.c guest_walk_tables(struct vcpu *v, struct p2m_domain *p2m, · line 366

Quoted 9 lines
xen/arch/x86/mm/guest_walk.c +3 -2
@@ -360,8 +360,9 @@ guest_walk_tables(struct vcpu *v, struct p2m_domain *p2m,
     gw->pfec |= PFEC_page_present;
 
     /*
-     * The pagetable walk has returned a successful translation.  Now check
-     * access rights to see whether the access should succeed.
+     * The pagetable walk has returned a successful translation (i.e. All
+     * PTEs are present and have no reserved bits set).  Now check access
+     * rights to see whether the access should succeed.
      */

While this perhaps is a worthwhile addition, my original request really was to make more visible around the place where it matters that the NX bit is part of the reserved ones when NX is off. Hence I'm not sure the comment change is worthwhile, and if you dislike adding the suggested ASSERT() I won't the patch be left as is.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#16 lore raw

Re: [PATCH 2/2] x86/pagewalk: Fix pagewalk's handling of instruction fetches

Quoted 70 lines · Jan Beulich
Quoted 70 lines
Quoted 1 line
Quoted 1 line · On 01.06.17 at 12:19, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 29.05.17 at 11:03, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich

xen/arch/x86/mm/guest_walk.c guest_walk_tables(struct vcpu *v, struct p2m_domain

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 26.05.17 at 19:03, <[email protected]> wrote:
xen/arch/x86/mm/guest_walk.c +0 -0
@@ -114,22 +114,18 @@ guest_walk_tables(struct vcpu *v, struct p2m_domain 

*p2m,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

xen/arch/x86/mm/guest_walk.c guest_walk_tables(struct vcpu *v, struct p2m_domain · line 118

Quoted 5 lines
xen/arch/x86/mm/guest_walk.c +0 -2
     ASSERT(!(walk & PFEC_implicit) ||
            !(walk & (PFEC_insn_fetch | PFEC_user_mode)));
 
-    /*
-     * PFEC_insn_fetch is only used as an input to pagetable walking if NX 

or

Quoted 1 line
Quoted 1 line
Quoted 1 line

xen/arch/x86/mm/guest_walk.c guest_walk_tables(struct vcpu *v, struct p2m_domain · line 119

Quoted 1 line
xen/arch/x86/mm/guest_walk.c +0 -1
-     * SMEP are enabled.  Otherwise, instruction fetches are 

indistinguishable

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

xen/arch/x86/mm/guest_walk.c guest_walk_tables(struct vcpu *v, struct p2m_domain · line 123

Quoted 4 lines
xen/arch/x86/mm/guest_walk.c +0 -4
-     * from data reads.
-     *
-     * This property can be demonstrated on real hardware by having NX and
-     * SMEP inactive, but SMAP active, and observing that EFLAGS.AC 

determines

Quoted 1 line
Quoted 1 line
Quoted 1 line

xen/arch/x86/mm/guest_walk.c guest_walk_tables(struct vcpu *v, struct p2m_domain · line 124

Quoted 1 line
xen/arch/x86/mm/guest_walk.c +0 -1
-     * whether a pagefault occures for supervisor execution on user 

mappings.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
xen/arch/x86/mm/guest_walk.c +0 -4
-     */
-    if ( !(guest_nx_enabled(v) || guest_smep_enabled(v)) )
-        walk &= ~PFEC_insn_fetch;
-
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

xen/arch/x86/mm/guest_walk.c guest_walk_tables(struct vcpu *v, struct p2m_domain · line 123

Quoted 8 lines
xen/arch/x86/mm/guest_walk.c +4 -1
     perfc_incr(guest_walk);
     memset(gw, 0, sizeof(*gw));
     gw->va = va;
-    gw->pfec = walk & (PFEC_insn_fetch | PFEC_user_mode | PFEC_write_access);
+    gw->pfec = walk & (PFEC_user_mode | PFEC_write_access);
+
+    /*
+     * PFEC_insn_fetch is only reported if NX or SMEP are enabled.  

Hardware

Quoted 1 line
Quoted 1 line
Quoted 1 line

xen/arch/x86/mm/guest_walk.c guest_walk_tables(struct vcpu *v, struct p2m_domain · line 124

Quoted 1 line
xen/arch/x86/mm/guest_walk.c +1 -0
+     * still distingueses instruction fetches during determination of 

access

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines

xen/arch/x86/mm/guest_walk.c guest_walk_tables(struct vcpu *v, struct p2m_domain · line 131

Quoted 7 lines
xen/arch/x86/mm/guest_walk.c +4 -0
+     * rights.
+     */
+    if ( guest_nx_enabled(v) || guest_smep_enabled(v) )
+        gw->pfec |= (walk & PFEC_insn_fetch);
 
 #if GUEST_PAGING_LEVELS >= 3 /* PAE or 64... */
 #if GUEST_PAGING_LEVELS >= 4 /* 64-bit only... */

Don't you another adjustment to

    if ( (walk & PFEC_insn_fetch) && (ar & _PAGE_NX_BIT) )
        /* Requested an instruction fetch and found NX? Fail. */
        goto out;
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

I can't see anything that would keep _PAGE_NX_BIT out of ar if NX is not enabled.

_PAGE_NX_BIT is reserved if NX is not enabled, and is accounted for in guest_rsvd_bits() in guest_pt.h, and we never hit the access rights logic.

Ah, right. But perhaps worth having a respective ASSERT() here, at once serving as documentation?

I could, but it would feel be out of place. NX being incorrectly set is a translation failure, and by definition, the translation needs to have succeeded before permissions get considered.

Would this clarification be acceptable?

index 5c6a85b..6d6b454 100644

xen/arch/x86/mm/guest_walk.c +0 -0
@@ -360,8 +360,9 @@ guest_walk_tables(struct vcpu *v, struct p2m_domain *p2m,
     gw->pfec |= PFEC_page_present;
 
Quoted 12 lines

xen/arch/x86/mm/guest_walk.c guest_walk_tables(struct vcpu *v, struct p2m_domain *p2m, · line 366

Quoted 7 lines
xen/arch/x86/mm/guest_walk.c +3 -2
     /*
-     * The pagetable walk has returned a successful translation.  Now check
-     * access rights to see whether the access should succeed.
+     * The pagetable walk has returned a successful translation (i.e. All
+     * PTEs are present and have no reserved bits set).  Now check access
+     * rights to see whether the access should succeed.
      */

While this perhaps is a worthwhile addition, my original request really was to make more visible around the place where it matters that the NX bit is part of the reserved ones when NX is off. Hence I'm not sure the comment change is worthwhile, and if you dislike adding the suggested ASSERT() I won't the patch be left as is.

I presume you means something like you won't mind if the patch is left as-is?

How about this?

xen/arch/x86/mm/guest_walk.c +0 -0
index 972364f..6055fec 100644
@@ -356,11 +356,19 @@ guest_walk_tables(struct vcpu *v, struct

p2m_domain *p2m,

     gw->pfec |= PFEC_page_present;
 
     /*
-     * The pagetable walk has returned a successful translation.  Now check
-     * access rights to see whether the access should succeed.
+     * The pagetable walk has returned a successful translation (i.e.

All PTEs
+ * are present and have no reserved bits set). Now check access
rights to
+ * see whether the access should succeed.

      */
     ar = (ar_and & AR_ACCUM_AND) | (ar_or & AR_ACCUM_OR);

+ /*

+     * Sanity check.  If EFER.NX is disabled, _PAGE_NX_BIT is reserved and
+     * should have caused a translation failure before we get here.
+     */

+ if ( ar & _PAGE_NX_BIT )
+ ASSERT(guest_nx_enabled(v));
+
#if GUEST_PAGING_LEVELS >= 4 /* 64-bit only... */
/*
* If all access checks are thus far ok, check Protection Key for 64bit

One problem I have with an ASSERT beside the "if ( (walk & PFEC_insn_fetch) && (ar & _PAGE_NX_BIT) )" is that it is mid-way through the permissions checks, rather than at the start, which is likely to get missed if future access checks get introduced ahead of the protection key checks.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#17 lore raw

Re: [PATCH 2/2] x86/pagewalk: Fix pagewalk's handling of instruction fetches

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 01.06.17 at 13:22, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich

While this perhaps is a worthwhile addition, my original request really was to make more visible around the place where it matters that the NX bit is part of the reserved ones when NX is off. Hence I'm not sure the comment change is worthwhile, and if you dislike adding the suggested ASSERT() I won't the patch be left as is.

I presume you means something like you won't mind if the patch is left as-is?

Oop, yes.

Quoted 21 lines

How about this?

xen/arch/x86/mm/guest_walk.c +1 -2
index 972364f..6055fec 100644
@@ -356,11 +356,19 @@ guest_walk_tables(struct vcpu *v, struct
 p2m_domain *p2m,
     gw->pfec |= PFEC_page_present;
 
     /*
-     * The pagetable walk has returned a successful translation.  Now check
-     * access rights to see whether the access should succeed.
+     * The pagetable walk has returned a successful translation (i.e.

All PTEs
+ * are present and have no reserved bits set). Now check access
rights to

xen/arch/x86/mm/guest_walk.c +1 -0
+     * see whether the access should succeed.
      */
     ar = (ar_and & AR_ACCUM_AND) | (ar_or & AR_ACCUM_OR);
 

xen/arch/x86/mm/guest_walk.c

Quoted 10 lines
xen/arch/x86/mm/guest_walk.c +7 -0
+    /*
+     * Sanity check.  If EFER.NX is disabled, _PAGE_NX_BIT is reserved and
+     * should have caused a translation failure before we get here.
+     */
+    if ( ar & _PAGE_NX_BIT )
+        ASSERT(guest_nx_enabled(v));
+
 #if GUEST_PAGING_LEVELS >= 4 /* 64-bit only... */
     /*
      * If all access checks are thus far ok, check Protection Key for 64bit

That's fine, thanks.

Quoted 5 lines

One problem I have with an ASSERT beside the "if ( (walk & PFEC_insn_fetch) && (ar & _PAGE_NX_BIT) )" is that it is mid-way through the permissions checks, rather than at the start, which is likely to get missed if future access checks get introduced ahead of the protection key checks.

I can understand this.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#18 lore raw
In reply to Andrew Cooper

Hi Andrew,

Quoted 6 lines · Andrew Cooper

These bugfixes finally allow my comprehensive XTF test (following several bugfixes, and the added feature of the 0-level pagetable tests) to complete successfully on a Skylake Server system, with PKU.

I know this is getting very tight to the line on 4.9, but it would be nice to get these fixes in.

Is there any risk to take this patch in Xen 4.9?

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#19 lore raw
Quoted 9 lines · Julien Grall

Hi Andrew,

Quoted 6 lines · Andrew Cooper

These bugfixes finally allow my comprehensive XTF test (following several
bugfixes, and the added feature of the 0-level pagetable tests) to complete
successfully on a Skylake Server system, with PKU.

Quoted 5 lines
Quoted 3 lines

I know this is getting very tight to the line on 4.9, but it would be nice to
get these fixes in.

Is there any risk to take this patch in Xen 4.9?

Very little risk (if I do say so myself).

I have an XTF test which can prove the correctness of both patches.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#20 lore raw
Quoted 14 lines · Andrew Cooper
Quoted 13 lines · Julien Grall

Hi Andrew,

Quoted 9 lines · Andrew Cooper

These bugfixes finally allow my comprehensive XTF test (following several
bugfixes, and the added feature of the 0-level pagetable tests) to complete
successfully on a Skylake Server system, with PKU.

I know this is getting very tight to the line on 4.9, but it would be nice to
get these fixes in.

Quoted 5 lines
Quoted 1 line

Is there any risk to take this patch in Xen 4.9?

Very little risk (if I do say so myself).

I have an XTF test which can prove the correctness of both patches.

It is nice to have XTF around for that :).

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel