Skip to contentSkip to conversation

x86/ept: pass correct level to p2m_entry_modify

PATCH In review Roger Pau Monne 3 participants 3 messages Jul 3, 2019 – Jul 10, 2019

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 x86/ept: pass correct level to p2m_entry_modify

EPT differs from NPT and shadow when translating page orders to levels in the physmap page tables. EPT page tables level for order 0 pages is 0, while NPT and shadow instead use 1, ie: EPT page tables levels starts at 0 while NPT and shadow starts at 1.

Fix the p2m_entry_modify call in atomic_write_ept_entry to always add one to the level, in order to match NPT and shadow usage.

While there also add a check to ensure p2m_entry_modify is never called with level == 0. That should allow to catch future errors related to the level parameter.

Fixes c7a4c088ad1c ('x86/mm: split p2m ioreq server pages special handling into helper')

---
Cc: Jun Nakajima <[email protected]>
Cc: Kevin Tian <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
---
Changes since v1:
- Check level is != 0 in p2m_entry_modify.
- Expand digits of hash id.

---
 xen/arch/x86/mm/p2m-ept.c | 2 +-
 xen/include/asm-x86/p2m.h | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
xen/arch/x86/mm/p2m-ept.c +1 -1
index e3044bee2e..6b8468c793 100644
@@ -51,7 +51,7 @@ static int atomic_write_ept_entry(struct p2m_domain *p2m,
                                   int level)
 {
     int rc = p2m_entry_modify(p2m, new.sa_p2mt, entryptr->sa_p2mt,
-                              _mfn(new.mfn), _mfn(entryptr->mfn), level);
+                              _mfn(new.mfn), _mfn(entryptr->mfn), level + 1);
 
     if ( rc )
         return rc;
xen/include/asm-x86/p2m.h +1 -0
index 09ef7e02fd..aff34e3adf 100644
@@ -946,6 +946,7 @@ static inline int p2m_entry_modify(struct p2m_domain *p2m, p2m_type_t nt,
                                    p2m_type_t ot, mfn_t nfn, mfn_t ofn,
                                    unsigned int level)
 {
+    BUG_ON(!level);
     BUG_ON(level > 1 && (nt == p2m_ioreq_server || nt == p2m_map_foreign));
 
     if ( level != 1 || (nt == ot && mfn_eq(nfn, ofn)) )
Signature · 7 lines
2.20.1 (Apple Git-117)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v2 1/1
#1 lore raw
Quoted 8 lines · Roger Pau Monne

EPT differs from NPT and shadow when translating page orders to levels in the physmap page tables. EPT page tables level for order 0 pages is 0, while NPT and shadow instead use 1, ie: EPT page tables levels starts at 0 while NPT and shadow starts at 1.

Fix the p2m_entry_modify call in atomic_write_ept_entry to always add one to the level, in order to match NPT and shadow usage.

Quoted 6 lines

While there also add a check to ensure p2m_entry_modify is never called with level == 0. That should allow to catch future errors related to the level parameter.

Fixes c7a4c088ad1c ('x86/mm: split p2m ioreq server pages special handling into helper')

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

Reviewed-by on v2 1/1
#2 lore raw
In reply to Roger Pau Monne
Quoted 11 lines

From: Roger Pau Monne [mailto:[email protected]]
Sent: Wednesday, July 3, 2019 7:33 PM

EPT differs from NPT and shadow when translating page orders to levels in the physmap page tables. EPT page tables level for order 0 pages is 0, while NPT and shadow instead use 1, ie: EPT page tables levels starts at 0 while NPT and shadow starts at 1.

Fix the p2m_entry_modify call in atomic_write_ept_entry to always add one to the level, in order to match NPT and shadow usage.

Quoted 7 lines

While there also add a check to ensure p2m_entry_modify is never called with level == 0. That should allow to catch future errors related to the level parameter.

Fixes c7a4c088ad1c ('x86/mm: split p2m ioreq server pages special handling

into helper')

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