Skip to contentSkip to conversation

xen: grant-table: Simplify get_page_frame

PATCH Superseded Julien Grall 2 participants 3 messages Sep 14, 2017 – Sep 15, 2017

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen: grant-table: Simplify get_page_frame

The implementation of get_page_frame is currently different whether the architecture support sharing memory or paging memory. Both version are extremely similar so it is possible to consolidate in a single implementation.

The check for shared/paged memory are gated with the respective ifdef. Potentially, dummy p2m_is_shared/p2m_is_paging could be implemented for Arm.

---

Cc Andrew Cooper <[email protected]>
Cc George Dunlap <[email protected]>
Cc Ian Jackson <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Konrad Rzeszutek Wilk <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Tim Deegan <[email protected]>
Cc Wei Liu <[email protected]>

get_page_from_gfn will be able to get reference on foreign page and as per my understanding will allow to grant page on foreign memory.

This was not allowed with a simple get_page(...) on the ARM implementation (no sharing nor paging supprot) but is allowed on the x86 implementation due to get_page_from_gfn.

On x86, foreign pages are currently only allowed for PVH dom0, so I think it is not a big deal for now.

On Arm, foreign pages can be present on any domain. So this patch would permit grant on foreing pages.

So I would like to check whether it would be valid to grant a mapping on foreign pages?

If not, I could add a check if ( p2m_is_foreign(...) ) return GTNST_bad_page.

---
 xen/common/grant_table.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)
xen/common/grant_table.c +4 -11
index c3895e6201..97d3200313 100644
@@ -259,7 +259,6 @@ static int get_paged_frame(unsigned long gfn, unsigned long *frame,
                            struct domain *rd)
 {
     int rc = GNTST_okay;
-#if defined(P2M_PAGED_TYPES) || defined(P2M_SHARED_TYPES)
     p2m_type_t p2mt;
 
     *page = get_page_from_gfn(rd, gfn, &p2mt,
@@ -267,26 +266,20 @@ static int get_paged_frame(unsigned long gfn, unsigned long *frame,
     if ( !(*page) )
     {
         *frame = mfn_x(INVALID_MFN);
+#if defined(P2M_SHARED_TYPES)
         if ( p2m_is_shared(p2mt) )
             return GNTST_eagain;
+#endif
+#if defined(P2M_PAGES_TYPES)
         if ( p2m_is_paging(p2mt) )
         {
             p2m_mem_paging_populate(rd, gfn);
             return GNTST_eagain;
         }
+#endif
         return GNTST_bad_page;
     }
     *frame = page_to_mfn(*page);
-#else
-    *frame = mfn_x(gfn_to_mfn(rd, _gfn(gfn)));
-    *page = mfn_valid(_mfn(*frame)) ? mfn_to_page(*frame) : NULL;
-    if ( (!(*page)) || (!get_page(*page, rd)) )
-    {
-        *frame = mfn_x(INVALID_MFN);
-        *page = NULL;
-        rc = GNTST_bad_page;
-    }
-#endif
 
     return rc;
 }
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 14.09.17 at 18:49, <[email protected]> wrote:

get_page_from_gfn will be able to get reference on foreign page and as per my understanding will allow to grant page on foreign memory.

This was not allowed with a simple get_page(...) on the ARM implementation (no sharing nor paging supprot) but is allowed on the x86 implementation due to get_page_from_gfn.

Quoted 8 lines

On x86, foreign pages are currently only allowed for PVH dom0, so I think it is not a big deal for now.

On Arm, foreign pages can be present on any domain. So this patch would permit grant on foreing pages.

So I would like to check whether it would be valid to grant a mapping on foreign pages?

No, I don't think grants should be permitted for other domains' pages.

Quoted 2 lines

If not, I could add a check if ( p2m_is_foreign(...) ) return GTNST_bad_page.

Please do.

xen/common/grant_table.c static int get_paged_frame(unsigned long gfn, unsigned long *frame, · line 269

Quoted 5 lines
xen/common/grant_table.c +1 -0
@@ -267,26 +266,20 @@ static int get_paged_frame(unsigned long gfn, unsigned long *frame,
     if ( !(*page) )
     {
         *frame = mfn_x(INVALID_MFN);
+#if defined(P2M_SHARED_TYPES)

#ifdef please.

xen/common/grant_table.c static int get_paged_frame(unsigned long gfn, unsigned long *frame, · line 273

Quoted 4 lines
xen/common/grant_table.c +2 -0
         if ( p2m_is_shared(p2mt) )
             return GNTST_eagain;
+#endif
+#if defined(P2M_PAGES_TYPES)

Same here.

Jan

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

#2 lore raw

Hi Jan,

Quoted 11 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 14.09.17 at 18:49, <[email protected]> wrote:

get_page_from_gfn will be able to get reference on foreign page and as per my understanding will allow to grant page on foreign memory.

This was not allowed with a simple get_page(...) on the ARM implementation (no sharing nor paging supprot) but is allowed on the x86 implementation due to get_page_from_gfn.

On x86, foreign pages are currently only allowed for PVH dom0, so I think it is not a big deal for now.

Quoted 8 lines
Quoted 5 lines

On Arm, foreign pages can be present on any domain. So this patch would permit grant on foreing pages.

So I would like to check whether it would be valid to grant a mapping on foreign pages?

No, I don't think grants should be permitted for other domains' pages.

Which seems to match the PV behavior. I will update the patch to forbid foreign pages and use #ifdef.

Cheers,

Signature · 6 lines
Julien Grall

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