diff mbox series

[RFC,59/84] x86/pmap: break the loop in pmap APIs.

Message ID 3dba7fe6e3a9be5f41d02d41bc4ec6dbb1ba734c.1569489002.git.hongyax@amazon.com (mailing list archive)
State New, archived
Headers show
Series Remove direct map from Xen | expand

Commit Message

Xia, Hongyan Sept. 26, 2019, 9:46 a.m. UTC
From: Hongyan Xia <hongyax@amazon.com>

Modify the pmap PTEs directly. Using set/clear_fixmap() may result in
invocation loops.

Signed-off-by: Hongyan Xia <hongyax@amazon.com>
---
 xen/arch/x86/pmap.c        | 11 ++++++++---
 xen/include/asm-x86/pmap.h |  2 +-
 2 files changed, 9 insertions(+), 4 deletions(-)

Comments

Wei Liu Sept. 26, 2019, 1:21 p.m. UTC | #1
On Thu, Sep 26, 2019 at 10:46:22AM +0100, hongyax@amazon.com wrote:
> From: Hongyan Xia <hongyax@amazon.com>
> 
> Modify the pmap PTEs directly. Using set/clear_fixmap() may result in
> invocation loops.
> 

Thanks. This is a good catch. I never got to test PMAP seriously.

This patch should be squashed into the patch that introduced PMAP. You
will need too keep your SoB there.

Wei.
diff mbox series

Patch

diff --git a/xen/arch/x86/pmap.c b/xen/arch/x86/pmap.c
index 4ae16b0212..93104d0b86 100644
--- a/xen/arch/x86/pmap.c
+++ b/xen/arch/x86/pmap.c
@@ -29,11 +29,12 @@  void pmap_unlock(void)
     spin_unlock(&lock);
 }
 
-void *pmap_map(struct page_info *page)
+void *pmap_map(mfn_t mfn)
 {
     unsigned int idx;
     void *linear = NULL;
     enum fixed_addresses slot;
+    l1_pgentry_t *pl1e;
 
     ASSERT(!in_irq());
     ASSERT(spin_is_locked(&lock));
@@ -47,7 +48,8 @@  void *pmap_map(struct page_info *page)
     slot = idx + FIX_PMAP_BEGIN;
     ASSERT(slot >= FIX_PMAP_BEGIN && slot <= FIX_PMAP_END);
 
-    set_fixmap(slot, mfn_x(page_to_mfn(page)));
+    pl1e = &l1_fixmap[L1_PAGETABLE_ENTRIES - 1 - slot];
+    l1e_write_atomic(pl1e, l1e_from_mfn(mfn, PAGE_HYPERVISOR));
     linear = (void *)__fix_to_virt(slot);
 
     return linear;
@@ -56,6 +58,7 @@  void *pmap_map(struct page_info *page)
 void pmap_unmap(void *p)
 {
     unsigned int idx;
+    l1_pgentry_t *pl1e;
     enum fixed_addresses slot = __virt_to_fix((unsigned long)p);
 
     ASSERT(!in_irq());
@@ -64,7 +67,9 @@  void pmap_unmap(void *p)
 
     idx = slot - FIX_PMAP_BEGIN;
     __clear_bit(idx, &inuse);
-    clear_fixmap(slot);
+
+    pl1e = &l1_fixmap[L1_PAGETABLE_ENTRIES - 1 - slot];
+    l1e_write_atomic(pl1e, l1e_from_mfn(_mfn(0), 0));
 }
 
 static void __maybe_unused build_assertions(void)
diff --git a/xen/include/asm-x86/pmap.h b/xen/include/asm-x86/pmap.h
index 42cd4c7793..feab1e9170 100644
--- a/xen/include/asm-x86/pmap.h
+++ b/xen/include/asm-x86/pmap.h
@@ -6,7 +6,7 @@ 
 
 void pmap_lock(void);
 void pmap_unlock(void);
-void *pmap_map(struct page_info *page);
+void *pmap_map(mfn_t mfn);
 void pmap_unmap(void *p);
 
 #endif	/* __X86_PMAP_H__ */