Skip to contentSkip to conversation

x86/mm: account for PGT_pae_xen_l2 in recently added assertion

PATCH In review Jan Beulich 2 participants 4 messages Jun 10, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/mm: account for PGT_pae_xen_l2 in recently added assertion

While PGT_pae_xen_l2 will be zapped once the type refcount of an L2 page reaches zero, it'll be retained as long as the type refcount is non- zero. Hence any checking against the requested type needs to either zap the bit from the type or include it in the used mask.

Fixes 9186e96b199e ("x86/pv: Clean up _get_page_type()")

---
The check around the TLB flush which was moved for XSA-401 also looks to needlessly trigger a flush when "type" has the bit set (while "x" wouldn't). That's no different from original behavior, but still looks inefficient.

xen/arch/x86/mm.c +2 -1
@@ -2956,7 +2956,8 @@ static int _get_page_type(struct page_in
              * The page is in one of two states (depending on PGT_partial),
              * and should have exactly one reference.
              */
-            ASSERT((x & (PGT_type_mask | PGT_count_mask)) == (type | 1));
+            ASSERT((x & (PGT_type_mask | PGT_pae_xen_l2 | PGT_count_mask)) ==
+                   (type | 1));
 
             if ( !(x & PGT_partial) )
             {
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Jan Beulich

While PGT_pae_xen_l2 will be zapped once the type refcount of an L2 page reaches zero, it'll be retained as long as the type refcount is non- zero. Hence any checking against the requested type needs to either zap the bit from the type or include it in the used mask.

Fixes 9186e96b199e ("x86/pv: Clean up _get_page_type()")

pae_xen_l2 being outside of the typemask is deeply confusing to work with.  It also renders all of the comments trying to explain the structure of this logic wrong.

I'm a little concerned with type usage in the non-coherent path too. It's safe, but is (along side the IOMMU path) a misleading example to surrounding code.

I can't think of anything better to do in the short term.

Quoted 5 lines

---
The check around the TLB flush which was moved for XSA-401 also looks to needlessly trigger a flush when "type" has the bit set (while "x" wouldn't). That's no different from original behavior, but still looks inefficient.

It's not the only inefficiency here.  Still plenty of improvements to be had in _get_page_type().

~Andrew

#2 lore raw
Quoted 13 lines · Andrew Cooper
Quoted 7 lines · Jan Beulich

While PGT_pae_xen_l2 will be zapped once the type refcount of an L2 page reaches zero, it'll be retained as long as the type refcount is non- zero. Hence any checking against the requested type needs to either zap the bit from the type or include it in the used mask.

Fixes 9186e96b199e ("x86/pv: Clean up _get_page_type()")

pae_xen_l2 being outside of the typemask is deeply confusing to work with.  It also renders all of the comments trying to explain the structure of this logic wrong.

Quoted 5 lines

I'm a little concerned with type usage in the non-coherent path too. It's safe, but is (along side the IOMMU path) a misleading example to surrounding code.

Thanks.

Quoted 10 lines

I can't think of anything better to do in the short term.

Quoted 5 lines

---
The check around the TLB flush which was moved for XSA-401 also looks to needlessly trigger a flush when "type" has the bit set (while "x" wouldn't). That's no different from original behavior, but still looks inefficient.

It's not the only inefficiency here.  Still plenty of improvements to be had in _get_page_type().

You did say you have some follow-up changes pending. It wasn't clear to me whether this particular aspect was among them. If not, I can make a(nother) patch ...

Jan

#3 lore raw
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Andrew Cooper
Quoted 5 lines · Jan Beulich

---
The check around the TLB flush which was moved for XSA-401 also looks to needlessly trigger a flush when "type" has the bit set (while "x" wouldn't). That's no different from original behavior, but still looks inefficient.

Quoted 5 lines
Quoted 2 lines

It's not the only inefficiency here.  Still plenty of improvements to be had in _get_page_type().

You did say you have some follow-up changes pending. It wasn't clear to me whether this particular aspect was among them. If not, I can make a(nother) patch ...

At this point, it's probably more accurate to say that I've got a pile of plans about making improvements, rather than a pile of patches.

The major improvement is the early exit for PGT_validated, making the second half of the function exclusively for the validate-locked state.

Other improvements (off the top of my head) are shuffling the TLB flush setup logic to not even do the tlb filter calculations if we're going to skip the flush call anyway, deduping the page_get_owner() calls/variables, sorting out PGC_page_table naming/semantics, reducing the number of redundant ways we've got of expressing the same logic (there are a lot of invariants between x, nx and type), better explanation of the iommu behaviour, and better explanation of the tlb flushing safety requirements.

If you think some of that's easy enough to do, then feel free.

~Andrew