diff mbox series

[Xen-devel,for-4.12,v3,4/8] xen/arm: Make get_page_from_gfn working with DOMID_XEN

Message ID 20181221162650.11515-5-julien.grall@arm.com
State New
Headers show
Series xen/arm: Add xentrace support | expand

Commit Message

Julien Grall Dec. 21, 2018, 4:26 p.m. UTC
DOMID_XEN is used to share pages beloging to the hypervisor
(e.g trace buffers). Unlike other domains, DOMID_XEN is a non-auto
translated domain and therefore does not have a P2M.

This patch adds a special case for DOMID_XEN in get_page_from_gfn. We
may want to provide "non-auto translated helpers" in the future if we
see more case.

Signed-off-by: Julien Grall <julien.grall@arm.com>

---
    Changes in v3:
        - Split from "xen/arm: Add support for read-only foreign
        mappings"
        - Use likely rather than unlikely
        - Fix typoes
---
 xen/include/asm-arm/p2m.h | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

Comments

Andrii Anisov Dec. 21, 2018, 5:26 p.m. UTC | #1
On 21.12.18 18:26, Julien Grall wrote:
> DOMID_XEN is used to share pages beloging to the hypervisor
> (e.g trace buffers). Unlike other domains, DOMID_XEN is a non-auto
> translated domain and therefore does not have a P2M.
> 
> This patch adds a special case for DOMID_XEN in get_page_from_gfn. We
> may want to provide "non-auto translated helpers" in the future if we
> see more case.
> 
> Signed-off-by: Julien Grall <julien.grall@arm.com>

Andrii Anisov <andrii_anisov@epam.com>
Julien Grall Dec. 21, 2018, 5:27 p.m. UTC | #2
Hi Andrii,

On 21/12/2018 17:26, Andrii Anisov wrote:
> 
> 
> On 21.12.18 18:26, Julien Grall wrote:
>> DOMID_XEN is used to share pages beloging to the hypervisor
>> (e.g trace buffers). Unlike other domains, DOMID_XEN is a non-auto
>> translated domain and therefore does not have a P2M.
>>
>> This patch adds a special case for DOMID_XEN in get_page_from_gfn. We
>> may want to provide "non-auto translated helpers" in the future if we
>> see more case.
>>
>> Signed-off-by: Julien Grall <julien.grall@arm.com>
> 
> Andrii Anisov <andrii_anisov@epam.com>

Is it a wildcard tag? :)

Cheers,
Andrii Anisov Dec. 21, 2018, 5:28 p.m. UTC | #3
On 21.12.18 19:27, Julien Grall wrote:

> Is it a wildcard tag? :)

No, just a wrong copy-paste.
Must be:

Reviewed-by: Andrii Anisov <andrii_anisov@epam.com>

;)
diff mbox series

Patch

diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h
index a03a033a05..041dea827c 100644
--- a/xen/include/asm-arm/p2m.h
+++ b/xen/include/asm-arm/p2m.h
@@ -300,7 +300,38 @@  struct page_info *p2m_get_page_from_gfn(struct domain *d, gfn_t gfn,
 static inline struct page_info *get_page_from_gfn(
     struct domain *d, unsigned long gfn, p2m_type_t *t, p2m_query_t q)
 {
-    return p2m_get_page_from_gfn(d, _gfn(gfn), t);
+    mfn_t mfn;
+    p2m_type_t _t;
+    struct page_info *page;
+
+    /*
+     * Special case for DOMID_XEN as it is the only domain so far that is
+     * not auto-translated.
+     */
+    if ( likely(d != dom_xen) )
+        return p2m_get_page_from_gfn(d, _gfn(gfn), t);
+
+    if ( !t )
+        t = &_t;
+
+    *t = p2m_invalid;
+
+    /*
+     * DOMID_XEN sees 1-1 RAM. The p2m_type is based on the type of the
+     * page.
+     */
+    mfn = _mfn(gfn);
+    page = mfn_to_page(mfn);
+
+    if ( !mfn_valid(mfn) || !get_page(page, d) )
+        return NULL;
+
+    if ( page->u.inuse.type_info & PGT_writable_page )
+        *t = p2m_ram_rw;
+    else
+        *t = p2m_ram_ro;
+
+    return page;
 }
 
 int get_page_type(struct page_info *page, unsigned long type);