Skip to contentSkip to conversation

x86/shadow: adjust cachability flags handling

RFC PATCH In review Jan Beulich 2 participants 4 messages Mar 5, 2014 – Mar 6, 2014

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 x86/shadow: adjust cachability flags handling

For one, including _PAGE_PAT in the pass-through flags is valid only for L1 entries (otherwise _PAGE_PSE_PAT would need looking at). Looking around I _think_ that for page directories we'd always get a valid MFN passed in here, and hence I _think_ the assertion is correct.

And second we need to avoid or-ing guest PAT/PCD/PWT with ones coming from pat_type_2_pte_flags()/get_pat_flags(). An alternative to the pass_thru_flags check might be to use mfn_valid(target_mfn).

xen/arch/x86/mm/shadow/multi.c +4 -0
@@ -580,7 +580,10 @@ _sh_propagate(struct vcpu *v, 
     if ( guest_supports_nx(v) )
         pass_thru_flags |= _PAGE_NX_BIT;
     if ( !shadow_mode_refcounts(d) && !mfn_valid(target_mfn) )
+    {
+        ASSERT(level == 1);
         pass_thru_flags |= _PAGE_PAT | _PAGE_PCD | _PAGE_PWT;
+    }
     sflags = gflags & pass_thru_flags;
 
     /*
@@ -588,6 +591,7 @@ _sh_propagate(struct vcpu *v, 
      * caching attributes in the shadows to match what was asked for.
      */
     if ( (level == 1) && is_hvm_domain(d) &&
+         !(pass_thru_flags & (_PAGE_PAT | _PAGE_PCD | _PAGE_PWT)) &&
          !is_xen_heap_mfn(mfn_x(target_mfn)) )
     {
         unsigned int type;
#1 lore raw
Quoted 12 lines · Jan Beulich

For one, including _PAGE_PAT in the pass-through flags is valid only for L1 entries (otherwise _PAGE_PSE_PAT would need looking at). Looking around I _think_ that for page directories we'd always get a valid MFN passed in here, and hence I _think_ the assertion is correct.

And second we need to avoid or-ing guest PAT/PCD/PWT with ones coming from pat_type_2_pte_flags()/get_pat_flags(). An alternative to the pass_thru_flags check might be to use mfn_valid(target_mfn).

xen/arch/x86/mm/shadow/multi.c _sh_propagate(struct vcpu *v, · line 584

Quoted 5 lines
xen/arch/x86/mm/shadow/multi.c +2 -0
@@ -580,7 +580,10 @@ _sh_propagate(struct vcpu *v, 
     if ( guest_supports_nx(v) )
         pass_thru_flags |= _PAGE_NX_BIT;
     if ( !shadow_mode_refcounts(d) && !mfn_valid(target_mfn) )
+    {
+        ASSERT(level == 1);

Yes, this assertion is correct -- enforced by this block just above:

    if ( !mfn_valid(target_mfn)
         && !(level == 1 && (!shadow_mode_refcounts(d) 
                             || p2mt == p2m_mmio_direct)) )
    {
        ASSERT((ft == ft_prefetch));
        *sp = shadow_l1e_empty();
        goto done;
    }

xen/arch/x86/mm/shadow/multi.c _sh_propagate(struct vcpu *v, · line 594

Quoted 10 lines
xen/arch/x86/mm/shadow/multi.c +2 -0
         pass_thru_flags |= _PAGE_PAT | _PAGE_PCD | _PAGE_PWT;
+    }
     sflags = gflags & pass_thru_flags;
 
     /*
@@ -588,6 +591,7 @@ _sh_propagate(struct vcpu *v, 
      * caching attributes in the shadows to match what was asked for.
      */
     if ( (level == 1) && is_hvm_domain(d) &&
+         !(pass_thru_flags & (_PAGE_PAT | _PAGE_PCD | _PAGE_PWT)) &&

I don't think this is necessary -- is_hvm_domain() implies shadow_mode_refcounts(), so we won't have set these flags in pass_thru_flags above.

If you want to make a change for clarity, I'd be happier with ASSERT(!(gflags & (_PAGE_PAT | _PAGE_PCD | _PAGE_PWT))) here.

Cheers,

Tim.

Quoted 10 lines
xen/arch/x86/mm/shadow/multi.c +0 -0
          !is_xen_heap_mfn(mfn_x(target_mfn)) )
     {
         unsigned int type;

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

#2 lore raw
Quoted 22 lines
Quoted 1 line
Quoted 1 line · Tim Deegan
Quoted 12 lines · Jan Beulich

For one, including _PAGE_PAT in the pass-through flags is valid only for L1 entries (otherwise _PAGE_PSE_PAT would need looking at). Looking around I _think_ that for page directories we'd always get a valid MFN passed in here, and hence I _think_ the assertion is correct.

And second we need to avoid or-ing guest PAT/PCD/PWT with ones coming from pat_type_2_pte_flags()/get_pat_flags(). An alternative to the pass_thru_flags check might be to use mfn_valid(target_mfn).

xen/arch/x86/mm/shadow/multi.c _sh_propagate(struct vcpu *v, · line 584

Quoted 5 lines
xen/arch/x86/mm/shadow/multi.c +2 -0
@@ -580,7 +580,10 @@ _sh_propagate(struct vcpu *v, 
     if ( guest_supports_nx(v) )
         pass_thru_flags |= _PAGE_NX_BIT;
     if ( !shadow_mode_refcounts(d) && !mfn_valid(target_mfn) )
+    {
+        ASSERT(level == 1);

Yes, this assertion is correct -- enforced by this block just above:

Quoted 8 lines
    if ( !mfn_valid(target_mfn)
         && !(level == 1 && (!shadow_mode_refcounts(d) 
                             || p2mt == p2m_mmio_direct)) )
    {
        ASSERT((ft == ft_prefetch));
        *sp = shadow_l1e_empty();
        goto done;
    }

I see. Question then is whether, together with the below, another assertion here is really worthwhile.

Quoted 15 lines

xen/arch/x86/mm/shadow/multi.c _sh_propagate(struct vcpu *v, · line 594

Quoted 10 lines
xen/arch/x86/mm/shadow/multi.c +2 -0
         pass_thru_flags |= _PAGE_PAT | _PAGE_PCD | _PAGE_PWT;
+    }
     sflags = gflags & pass_thru_flags;
 
     /*
@@ -588,6 +591,7 @@ _sh_propagate(struct vcpu *v, 
      * caching attributes in the shadows to match what was asked for.
      */
     if ( (level == 1) && is_hvm_domain(d) &&
+         !(pass_thru_flags & (_PAGE_PAT | _PAGE_PCD | _PAGE_PWT)) &&

I don't think this is necessary -- is_hvm_domain() implies shadow_mode_refcounts(), so we won't have set these flags in pass_thru_flags above.

Quoted 2 lines

If you want to make a change for clarity, I'd be happier with ASSERT(!(gflags & (_PAGE_PAT | _PAGE_PCD | _PAGE_PWT))) here.

But I suppose you really meant to use sflags here; I think there's nothing wrong with gflags having any of these set.

Jan

#3 lore raw
Quoted 31 lines · Jan Beulich
Quoted 22 lines
Quoted 1 line
Quoted 1 line · Tim Deegan
Quoted 12 lines · Jan Beulich

For one, including _PAGE_PAT in the pass-through flags is valid only for L1 entries (otherwise _PAGE_PSE_PAT would need looking at). Looking around I _think_ that for page directories we'd always get a valid MFN passed in here, and hence I _think_ the assertion is correct.

And second we need to avoid or-ing guest PAT/PCD/PWT with ones coming from pat_type_2_pte_flags()/get_pat_flags(). An alternative to the pass_thru_flags check might be to use mfn_valid(target_mfn).

xen/arch/x86/mm/shadow/multi.c _sh_propagate(struct vcpu *v, · line 584

Quoted 5 lines
xen/arch/x86/mm/shadow/multi.c +2 -0
@@ -580,7 +580,10 @@ _sh_propagate(struct vcpu *v, 
     if ( guest_supports_nx(v) )
         pass_thru_flags |= _PAGE_NX_BIT;
     if ( !shadow_mode_refcounts(d) && !mfn_valid(target_mfn) )
+    {
+        ASSERT(level == 1);

Yes, this assertion is correct -- enforced by this block just above:

Quoted 8 lines
    if ( !mfn_valid(target_mfn)
         && !(level == 1 && (!shadow_mode_refcounts(d) 
                             || p2mt == p2m_mmio_direct)) )
    {
        ASSERT((ft == ft_prefetch));
        *sp = shadow_l1e_empty();
        goto done;
    }
Quoted 2 lines

I see. Question then is whether, together with the below, another assertion here is really worthwhile.

I think the one below would be enough.

Quoted 15 lines
Quoted 15 lines

xen/arch/x86/mm/shadow/multi.c _sh_propagate(struct vcpu *v, · line 594

Quoted 10 lines
xen/arch/x86/mm/shadow/multi.c +2 -0
         pass_thru_flags |= _PAGE_PAT | _PAGE_PCD | _PAGE_PWT;
+    }
     sflags = gflags & pass_thru_flags;
 
     /*
@@ -588,6 +591,7 @@ _sh_propagate(struct vcpu *v, 
      * caching attributes in the shadows to match what was asked for.
      */
     if ( (level == 1) && is_hvm_domain(d) &&
+         !(pass_thru_flags & (_PAGE_PAT | _PAGE_PCD | _PAGE_PWT)) &&

I don't think this is necessary -- is_hvm_domain() implies shadow_mode_refcounts(), so we won't have set these flags in pass_thru_flags above.

Quoted 4 lines
Quoted 2 lines

If you want to make a change for clarity, I'd be happier with ASSERT(!(gflags & (_PAGE_PAT | _PAGE_PCD | _PAGE_PWT))) here.

But I suppose you really meant to use sflags here

Oops, yes I did.

Cheers,

Tim.