Skip to contentSkip to conversation

xen/arm: Correctly implement domain_page_map_to_mfn

PATCH Applied Julien Grall 4 participants 7 messages Feb 5, 2014 – Feb 6, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/arm: Correctly implement domain_page_map_to_mfn

The function domain_page_map_to_mfn can be used to translate a virtual address mapped by both map_domain_page and map_domain_page_global. The former is using vmap to map the mfn, therefore domain_page_map_to_mfn will always fail because the address is not in DOMHEAP range.

Check if the address is in vmap range and use __pa to translate it.

This patch fix guest shutdown when the event fifo is used.

---
This is a bug fix for Xen 4.4. Without this patch, it's impossible to
use Linux 3.14 (and higher) as guest with the event fifo driver.

---
 xen/arch/arm/mm.c |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
xen/arch/arm/mm.c +7 -3
index 127cce0..bdca68a 100644
@@ -325,11 +325,15 @@ void unmap_domain_page(const void *va)
     local_irq_restore(flags);
 }
 
-unsigned long domain_page_map_to_mfn(const void *va)
+unsigned long domain_page_map_to_mfn(const void *ptr)
 {
+    unsigned long va = (unsigned long)ptr;
     lpae_t *map = this_cpu(xen_dommap);
-    int slot = ((unsigned long) va - DOMHEAP_VIRT_START) >> SECOND_SHIFT;
-    unsigned long offset = ((unsigned long)va>>THIRD_SHIFT) & LPAE_ENTRY_MASK;
+    int slot = (va - DOMHEAP_VIRT_START) >> SECOND_SHIFT;
+    unsigned long offset = (va>>THIRD_SHIFT) & LPAE_ENTRY_MASK;
+
+    if ( va >= VMAP_VIRT_START && va < VMAP_VIRT_END )
+        return virt_to_mfn(va);
 
     ASSERT(slot >= 0 && slot < DOMHEAP_ENTRIES);
     ASSERT(map[slot].pt.avail != 0);
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 10 lines · Julien Grall

The function domain_page_map_to_mfn can be used to translate a virtual address mapped by both map_domain_page and map_domain_page_global. The former is using vmap to map the mfn, therefore domain_page_map_to_mfn will always fail because the address is not in DOMHEAP range.

Check if the address is in vmap range and use __pa to translate it.

This patch fix guest shutdown when the event fifo is used.

I assume this brings the arm paths into line with the x86 functionality?

-George

Quoted 31 lines

---
This is a bug fix for Xen 4.4. Without this patch, it's impossible to
use Linux 3.14 (and higher) as guest with the event fifo driver.

---
  xen/arch/arm/mm.c |   10 +++++++---
  1 file changed, 7 insertions(+), 3 deletions(-)
xen/arch/arm/mm.c +7 -3
index 127cce0..bdca68a 100644
@@ -325,11 +325,15 @@ void unmap_domain_page(const void *va)
      local_irq_restore(flags);
  }
 
-unsigned long domain_page_map_to_mfn(const void *va)
+unsigned long domain_page_map_to_mfn(const void *ptr)
  {
+    unsigned long va = (unsigned long)ptr;
      lpae_t *map = this_cpu(xen_dommap);
-    int slot = ((unsigned long) va - DOMHEAP_VIRT_START) >> SECOND_SHIFT;
-    unsigned long offset = ((unsigned long)va>>THIRD_SHIFT) & LPAE_ENTRY_MASK;
+    int slot = (va - DOMHEAP_VIRT_START) >> SECOND_SHIFT;
+    unsigned long offset = (va>>THIRD_SHIFT) & LPAE_ENTRY_MASK;
+
+    if ( va >= VMAP_VIRT_START && va < VMAP_VIRT_END )
+        return virt_to_mfn(va);
 
      ASSERT(slot >= 0 && slot < DOMHEAP_ENTRIES);
      ASSERT(map[slot].pt.avail != 0);
#2 lore raw
Quoted 6 lines · George Dunlap
Quoted 5 lines · Julien Grall

The function domain_page_map_to_mfn can be used to translate a virtual address mapped by both map_domain_page and map_domain_page_global. The former is using vmap to map the mfn, therefore domain_page_map_to_mfn will always fail because the address is not in DOMHEAP range.

Quoted 7 lines
Quoted 5 lines

Check if the address is in vmap range and use __pa to translate it.

This patch fix guest shutdown when the event fifo is used.

I assume this brings the arm paths into line with the x86 functionality?

Yes, functionality which is now expected by common code as well (FIFO evthcn stuff).

Quoted 36 lines

-George

Quoted 31 lines

---
This is a bug fix for Xen 4.4. Without this patch, it's impossible to
use Linux 3.14 (and higher) as guest with the event fifo driver.

---
  xen/arch/arm/mm.c |   10 +++++++---
  1 file changed, 7 insertions(+), 3 deletions(-)
xen/arch/arm/mm.c +7 -3
index 127cce0..bdca68a 100644
@@ -325,11 +325,15 @@ void unmap_domain_page(const void *va)
      local_irq_restore(flags);
  }
 
-unsigned long domain_page_map_to_mfn(const void *va)
+unsigned long domain_page_map_to_mfn(const void *ptr)
  {
+    unsigned long va = (unsigned long)ptr;
      lpae_t *map = this_cpu(xen_dommap);
-    int slot = ((unsigned long) va - DOMHEAP_VIRT_START) >> SECOND_SHIFT;
-    unsigned long offset = ((unsigned long)va>>THIRD_SHIFT) & LPAE_ENTRY_MASK;
+    int slot = (va - DOMHEAP_VIRT_START) >> SECOND_SHIFT;
+    unsigned long offset = (va>>THIRD_SHIFT) & LPAE_ENTRY_MASK;
+
+    if ( va >= VMAP_VIRT_START && va < VMAP_VIRT_END )
+        return virt_to_mfn(va);
 
      ASSERT(slot >= 0 && slot < DOMHEAP_ENTRIES);
      ASSERT(map[slot].pt.avail != 0);
#3 lore raw
Quoted 7 lines · Ian Campbell
Quoted 6 lines · George Dunlap
Quoted 5 lines · Julien Grall

The function domain_page_map_to_mfn can be used to translate a virtual address mapped by both map_domain_page and map_domain_page_global. The former is using vmap to map the mfn, therefore domain_page_map_to_mfn will always fail because the address is not in DOMHEAP range.

Quoted 8 lines
Quoted 6 lines
Quoted 5 lines

Check if the address is in vmap range and use __pa to translate it.

This patch fix guest shutdown when the event fifo is used.

I assume this brings the arm paths into line with the x86 functionality?

Yes, functionality which is now expected by common code as well (FIFO evthcn stuff).

In that case:

Applied
#4 lore raw
Quoted 12 lines · George Dunlap
Quoted 11 lines · Ian Campbell
Quoted 10 lines · George Dunlap
Quoted 9 lines · Julien Grall

The function domain_page_map_to_mfn can be used to translate a virtual address mapped by both map_domain_page and map_domain_page_global. The former is using vmap to map the mfn, therefore domain_page_map_to_mfn will always fail because the address is not in DOMHEAP range.

Check if the address is in vmap range and use __pa to translate it.

This patch fix guest shutdown when the event fifo is used.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Quoted 1 line

I assume this brings the arm paths into line with the x86 functionality?

Yes, functionality which is now expected by common code as well (FIFO evthcn stuff).

In that case:

Thanks, applied.

Acked-by on v1 1/1
#5 lore raw
In reply to Julien Grall
Quoted 11 lines · Julien Grall

The function domain_page_map_to_mfn can be used to translate a virtual address mapped by both map_domain_page and map_domain_page_global. The former is using vmap to map the mfn, therefore domain_page_map_to_mfn will always fail because the address is not in DOMHEAP range.

Check if the address is in vmap range and use __pa to translate it.

This patch fix guest shutdown when the event fifo is used.

It looks good to me.

Quoted 33 lines

---
This is a bug fix for Xen 4.4. Without this patch, it's impossible to
use Linux 3.14 (and higher) as guest with the event fifo driver.

---
 xen/arch/arm/mm.c |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
xen/arch/arm/mm.c +7 -3
index 127cce0..bdca68a 100644
@@ -325,11 +325,15 @@ void unmap_domain_page(const void *va)
     local_irq_restore(flags);
 }
 
-unsigned long domain_page_map_to_mfn(const void *va)
+unsigned long domain_page_map_to_mfn(const void *ptr)
 {
+    unsigned long va = (unsigned long)ptr;
     lpae_t *map = this_cpu(xen_dommap);
-    int slot = ((unsigned long) va - DOMHEAP_VIRT_START) >> SECOND_SHIFT;
-    unsigned long offset = ((unsigned long)va>>THIRD_SHIFT) & LPAE_ENTRY_MASK;
+    int slot = (va - DOMHEAP_VIRT_START) >> SECOND_SHIFT;
+    unsigned long offset = (va>>THIRD_SHIFT) & LPAE_ENTRY_MASK;
+
+    if ( va >= VMAP_VIRT_START && va < VMAP_VIRT_END )
+        return virt_to_mfn(va);
 
     ASSERT(slot >= 0 && slot < DOMHEAP_ENTRIES);
     ASSERT(map[slot].pt.avail != 0);
Signature · 1 line
1.7.10.4
Acked-by on v1 1/1
#6 lore raw
In reply to Julien Grall
Quoted 11 lines · Julien Grall

The function domain_page_map_to_mfn can be used to translate a virtual address mapped by both map_domain_page and map_domain_page_global. The former is using vmap to map the mfn, therefore domain_page_map_to_mfn will always fail because the address is not in DOMHEAP range.

Check if the address is in vmap range and use __pa to translate it.

This patch fix guest shutdown when the event fifo is used.

Quoted 31 lines

---
This is a bug fix for Xen 4.4. Without this patch, it's impossible to
use Linux 3.14 (and higher) as guest with the event fifo driver.

---
 xen/arch/arm/mm.c |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
xen/arch/arm/mm.c +7 -3
index 127cce0..bdca68a 100644
@@ -325,11 +325,15 @@ void unmap_domain_page(const void *va)
     local_irq_restore(flags);
 }
 
-unsigned long domain_page_map_to_mfn(const void *va)
+unsigned long domain_page_map_to_mfn(const void *ptr)
 {
+    unsigned long va = (unsigned long)ptr;
     lpae_t *map = this_cpu(xen_dommap);
-    int slot = ((unsigned long) va - DOMHEAP_VIRT_START) >> SECOND_SHIFT;
-    unsigned long offset = ((unsigned long)va>>THIRD_SHIFT) & LPAE_ENTRY_MASK;
+    int slot = (va - DOMHEAP_VIRT_START) >> SECOND_SHIFT;
+    unsigned long offset = (va>>THIRD_SHIFT) & LPAE_ENTRY_MASK;
+
+    if ( va >= VMAP_VIRT_START && va < VMAP_VIRT_END )
+        return virt_to_mfn(va);
 
     ASSERT(slot >= 0 && slot < DOMHEAP_ENTRIES);
     ASSERT(map[slot].pt.avail != 0);