Skip to contentSkip to conversation

x86/PV: guest_get_eff_kern_l1e() may still need to switch page tables

PATCH In review Jan Beulich 3 participants 3 messages Dec 14, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/PV: guest_get_eff_kern_l1e() may still need to switch page tables

While indeed unnecessary for pv_ro_page_fault(), pv_map_ldt_shadow_page() may run when guest user mode is active, and hence may need to switch to the kernel page tables in order to retrieve an LDT page mapping.

Fixes 9ff970564764 ("x86/mm: drop guest_get_eff_l1e()")

---
Manuel, could you test this again, just to be on the safe side before we throw it in (at which point we could then also again add a Tested-by)? Thanks.

xen/arch/x86/pv/mm.h +10 -2
@@ -11,10 +11,15 @@ int new_guest_cr3(mfn_t mfn);
  */
 static inline l1_pgentry_t guest_get_eff_kern_l1e(unsigned long linear)
 {
+    struct vcpu *curr = current;
+    bool user_mode = !(curr->arch.flags & TF_kernel_mode);
     l1_pgentry_t l1e;
 
-    ASSERT(!paging_mode_translate(current->domain));
-    ASSERT(!paging_mode_external(current->domain));
+    ASSERT(!paging_mode_translate(curr->domain));
+    ASSERT(!paging_mode_external(curr->domain));
+
+    if ( user_mode )
+        toggle_guest_pt(curr);
 
     if ( unlikely(!__addr_ok(linear)) ||
          __copy_from_user(&l1e,
@@ -22,6 +27,9 @@ static inline l1_pgentry_t guest_get_eff
                           sizeof(l1_pgentry_t)) )
         l1e = l1e_empty();
 
+    if ( user_mode )
+        toggle_guest_pt(curr);
+
     return l1e;
 }
 
#1 lore raw
Quoted 4 lines · Jan Beulich

While indeed unnecessary for pv_ro_page_fault(), pv_map_ldt_shadow_page() may run when guest user mode is active, and hence may need to switch to the kernel page tables in order to retrieve an LDT page mapping.

Quoted 8 lines
Fixes 9ff970564764 ("x86/mm: drop guest_get_eff_l1e()")

---
Manuel, could you test this again, just to be on the safe side before we throw it in (at which point we could then also again add a Tested-by)? Thanks.

I've got a repro of the issue (literally - just booting the netinstaller), and this does fix it.

~Andrew

#2 lore raw
In reply to Jan Beulich
Quoted 4 lines · Jan Beulich

While indeed unnecessary for pv_ro_page_fault(), pv_map_ldt_shadow_page() may run when guest user mode is active, and hence may need to switch to the kernel page tables in order to retrieve an LDT page mapping.

Quoted 8 lines
Fixes 9ff970564764 ("x86/mm: drop guest_get_eff_l1e()")

---
Manuel, could you test this again, just to be on the safe side before we throw it in (at which point we could then also again add a Tested-by)? Thanks.

Yes, this works for me. thanks !

Signature · 3 lines
Manuel Bouyer <[email protected]>
     NetBSD: 26 ans d'experience feront toujours la difference
--