Skip to contentSkip to conversation

xen: grant-table: Simplify get_paged_frame

PATCH Superseded Julien Grall 5 participants 16 messages Sep 18, 2017 – Sep 20, 2017

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 xen: grant-table: Simplify get_paged_frame

The implementation of get_paged_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 main difference is the x86 version will allow grant on foreign page when using HVM/PVH whilst Arm does not. At the moment, on x86 foreign pages are only allowed for PVH Dom0. It seems that foreign pages should never be granted so deny them

The check for shared/paged memory are now 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]>

Changes in v2:
- Deny grant on foreign page (aligned with the ARM code)
- Use #ifdef rather than #if defined
- Update commit message
- Fix typo in the title

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.

This patch will deny granting foreign pages. Jan Beulich is happy with it. Any other opinions?

---
 xen/common/grant_table.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)
xen/common/grant_table.c +8 -11
index c3895e6201..a6a168df6e 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,24 @@ static int get_paged_frame(unsigned long gfn, unsigned long *frame,
     if ( !(*page) )
     {
         *frame = mfn_x(INVALID_MFN);
+#ifdef P2M_SHARED_TYPES
         if ( p2m_is_shared(p2mt) )
             return GNTST_eagain;
+#endif
+#ifdef P2M_PAGES_TYPES
         if ( p2m_is_paging(p2mt) )
         {
             p2m_mem_paging_populate(rd, gfn);
             return GNTST_eagain;
         }
+#endif
         return GNTST_bad_page;
     }
+
+    if ( p2m_is_foreign(p2mt) )
+        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 40 lines · Julien Grall

The implementation of get_paged_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 main difference is the x86 version will allow grant on foreign page when using HVM/PVH whilst Arm does not. At the moment, on x86 foreign pages are only allowed for PVH Dom0. It seems that foreign pages should never be granted so deny them

The check for shared/paged memory are now 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]>

Changes in v2:
- Deny grant on foreign page (aligned with the ARM code)
- Use #ifdef rather than #if defined
- Update commit message
- Fix typo in the title

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.

This patch will deny granting foreign pages. Jan Beulich is happy with it. Any other opinions?

Won't this break QEMU running in stub domains?

I haven't tested it, but I'm afraid QEMU running in a stub domain might try to grant a foreign frame. Ie: the emulated network code in QEMU might try to grant a foreign frame in order to forward operations from emulated devices to PV frontends.

Roger.

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

#2 lore raw

Hi Roger,

Quoted 50 lines · Roger Pau Monné
Quoted 40 lines · Julien Grall

The implementation of get_paged_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 main difference is the x86 version will allow grant on foreign page when using HVM/PVH whilst Arm does not. At the moment, on x86 foreign pages are only allowed for PVH Dom0. It seems that foreign pages should never be granted so deny them

The check for shared/paged memory are now 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]>

Changes in v2:
- Deny grant on foreign page (aligned with the ARM code)
- Use #ifdef rather than #if defined
- Update commit message
- Fix typo in the title

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.

This patch will deny granting foreign pages. Jan Beulich is happy with it. Any other opinions?

Quoted 6 lines

Won't this break QEMU running in stub domains?

I haven't tested it, but I'm afraid QEMU running in a stub domain might try to grant a foreign frame. Ie: the emulated network code in QEMU might try to grant a foreign frame in order to forward operations from emulated devices to PV frontends.

I don't think it will break any existing setup because foreign mapping are only allowed for the hardware domain (see p2m_add_foreign).

Now, what should be expected in the future? I am not sure why we would allow grant on foreign mapping. It is very similar to QEMU granting a page that was granted by another domain, this is not allowed today.

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#3 lore raw
Quoted 55 lines · Julien Grall

Hi Roger,

Quoted 52 lines · Roger Pau Monné
Quoted 40 lines · Julien Grall

The implementation of get_paged_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 main difference is the x86 version will allow grant on foreign page when using HVM/PVH whilst Arm does not. At the moment, on x86 foreign pages are only allowed for PVH Dom0. It seems that foreign pages should never be granted so deny them

The check for shared/paged memory are now 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]>

Changes in v2:
- Deny grant on foreign page (aligned with the ARM code)
- Use #ifdef rather than #if defined
- Update commit message
- Fix typo in the title

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.

This patch will deny granting foreign pages. Jan Beulich is happy with it. Any other opinions?

Won't this break QEMU running in stub domains?

Quoted 7 lines
Quoted 4 lines

I haven't tested it, but I'm afraid QEMU running in a stub domain might try to grant a foreign frame. Ie: the emulated network code in QEMU might try to grant a foreign frame in order to forward operations from emulated devices to PV frontends.

I don't think it will break any existing setup because foreign mapping are only allowed for the hardware domain (see p2m_add_foreign).

IIRC this only applies to auto-translated (HVM) domains, not to PV domains. QEMU stubdomains are PV guests.

Roger.

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

#4 lore raw

Hi,

Quoted 61 lines · Roger Pau Monné
Quoted 60 lines · Julien Grall

Hi Roger,

Quoted 56 lines · Roger Pau Monné
Quoted 40 lines · Julien Grall

The implementation of get_paged_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 main difference is the x86 version will allow grant on foreign page when using HVM/PVH whilst Arm does not. At the moment, on x86 foreign pages are only allowed for PVH Dom0. It seems that foreign pages should never be granted so deny them

The check for shared/paged memory are now 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]>

Changes in v2:
- Deny grant on foreign page (aligned with the ARM code)
- Use #ifdef rather than #if defined
- Update commit message
- Fix typo in the title

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.

This patch will deny granting foreign pages. Jan Beulich is happy with it. Any other opinions?

Won't this break QEMU running in stub domains?

I haven't tested it, but I'm afraid QEMU running in a stub domain might try to grant a foreign frame. Ie: the emulated network code in QEMU might try to grant a foreign frame in order to forward operations from emulated devices to PV frontends.

Quoted 5 lines
Quoted 2 lines

I don't think it will break any existing setup because foreign mapping are only allowed for the hardware domain (see p2m_add_foreign).

IIRC this only applies to auto-translated (HVM) domains, not to PV domains. QEMU stubdomains are PV guests.

Still, p2m_map_foreign can only be used for auto-translated domains.

Furthermore, if you look at the implementation of get_page_from_gfn, for PV domain is basically a get_page(page, d) that can't not work on foreign pages.

So I really don't see any problem here.

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#5 lore raw
Quoted 64 lines · Julien Grall

Hi,

Quoted 61 lines · Roger Pau Monné
Quoted 60 lines · Julien Grall

Hi Roger,

Quoted 56 lines · Roger Pau Monné
Quoted 40 lines · Julien Grall

The implementation of get_paged_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 main difference is the x86 version will allow grant on foreign page when using HVM/PVH whilst Arm does not. At the moment, on x86 foreign pages are only allowed for PVH Dom0. It seems that foreign pages should never be granted so deny them

The check for shared/paged memory are now 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]>

Changes in v2:
- Deny grant on foreign page (aligned with the ARM code)
- Use #ifdef rather than #if defined
- Update commit message
- Fix typo in the title

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.

This patch will deny granting foreign pages. Jan Beulich is happy with it. Any other opinions?

Won't this break QEMU running in stub domains?

I haven't tested it, but I'm afraid QEMU running in a stub domain might try to grant a foreign frame. Ie: the emulated network code in QEMU might try to grant a foreign frame in order to forward operations from emulated devices to PV frontends.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

I don't think it will break any existing setup because foreign mapping are only allowed for the hardware domain (see p2m_add_foreign).

IIRC this only applies to auto-translated (HVM) domains, not to PV domains. QEMU stubdomains are PV guests.

Still, p2m_map_foreign can only be used for auto-translated domains.

Oh, so you are limiting this only for auto-translated guests? Should have looked more closely at the commit message.

Roger.

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

#6 lore raw

Hi Roger,

Quoted 68 lines · Roger Pau Monné
Quoted 67 lines · Julien Grall

Hi,

Quoted 64 lines · Roger Pau Monné
Quoted 62 lines · Julien Grall

Hi Roger,

Quoted 50 lines · Roger Pau Monné
Quoted 40 lines · Julien Grall

The implementation of get_paged_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 main difference is the x86 version will allow grant on foreign page when using HVM/PVH whilst Arm does not. At the moment, on x86 foreign pages are only allowed for PVH Dom0. It seems that foreign pages should never be granted so deny them

The check for shared/paged memory are now 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]>

Changes in v2:
- Deny grant on foreign page (aligned with the ARM code)
- Use #ifdef rather than #if defined
- Update commit message
- Fix typo in the title

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.

This patch will deny granting foreign pages. Jan Beulich is happy with it. Any other opinions?

Quoted 6 lines

Won't this break QEMU running in stub domains?

I haven't tested it, but I'm afraid QEMU running in a stub domain might try to grant a foreign frame. Ie: the emulated network code in QEMU might try to grant a foreign frame in order to forward operations from emulated devices to PV frontends.

I don't think it will break any existing setup because foreign mapping are only allowed for the hardware domain (see p2m_add_foreign).

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

IIRC this only applies to auto-translated (HVM) domains, not to PV domains. QEMU stubdomains are PV guests.

Still, p2m_map_foreign can only be used for auto-translated domains.

Oh, so you are limiting this only for auto-translated guests? Should have looked more closely at the commit message.

That's right. I am happy to update the commit message if it is not clear enough.

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#7 lore raw
In reply to Julien Grall
Quoted 55 lines

-----Original Message-----
From: Xen-devel [mailto:[email protected]] On Behalf Of Julien Grall
Sent: 18 September 2017 17:28
To: [email protected]
Cc: [email protected]; Wei Liu <[email protected]>; George Dunlap <[email protected]>; Andrew Cooper <[email protected]>; Ian Jackson <[email protected]>; Tim (Xen.org) <[email protected]>; Julien Grall <[email protected]>; [email protected]
Subject: [Xen-devel] [PATCH v2] xen: grant-table: Simplify get_paged_frame

The implementation of get_paged_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 main difference is the x86 version will allow grant on foreign page when using HVM/PVH whilst Arm does not. At the moment, on x86 foreign pages
are only allowed for PVH Dom0. It seems that foreign pages should never be granted so deny them

The check for shared/paged memory are now 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]>

Changes in v2:
- Deny grant on foreign page (aligned with the ARM code)
- Use #ifdef rather than #if defined
- Update commit message
- Fix typo in the title

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.

This patch will deny granting foreign pages. Jan Beulich is happy with it. Any other opinions?

That seems reasonable to me. You can't grant frames that have been grant mapped from another domain (except by using v2 transitive grants) so disallowing granting of priv mapped frames is at least consistent.

I do wonder whether this function belongs in the grant table code though. Getting the page from a (d, gfn) tuple is probably something that's needed in a few places and hence putting the code in common/memory.c (with suitable adjustment to the error values) would seem more appropriate.

Paul

Quoted 57 lines
---
 xen/common/grant_table.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)
xen/common/grant_table.c +0 -1
index c3895e6201..a6a168df6e 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,
xen/common/grant_table.c +8 -10
@@ -267,26 +266,24 @@ static int get_paged_frame(unsigned long gfn,
 unsigned long *frame,
     if ( !(*page) )
     {
         *frame = mfn_x(INVALID_MFN);
+#ifdef P2M_SHARED_TYPES
         if ( p2m_is_shared(p2mt) )
             return GNTST_eagain;
+#endif
+#ifdef P2M_PAGES_TYPES
         if ( p2m_is_paging(p2mt) )
         {
             p2m_mem_paging_populate(rd, gfn);
             return GNTST_eagain;
         }
+#endif
         return GNTST_bad_page;
     }
+
+    if ( p2m_is_foreign(p2mt) )
+        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;

}
--
2.11.0

Quoted 4 lines

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

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

#8 lore raw
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 19.09.17 at 10:34, <[email protected]> wrote:

I do wonder whether this function belongs in the grant table code though. Getting the page from a (d, gfn) tuple is probably something that's needed in a few places and hence putting the code in common/memory.c (with suitable adjustment to the error values) would seem more appropriate.

That's been true from the very beginning of the existence of the function, I think.

Jan

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

#9 lore raw

Hi,

Quoted 8 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 19.09.17 at 10:34, <[email protected]> wrote:

I do wonder whether this function belongs in the grant table code though. Getting the page from a (d, gfn) tuple is probably something that's needed in a few places and hence putting the code in common/memory.c (with suitable adjustment to the error values) would seem more appropriate.

That's been true from the very beginning of the existence of the function, I think.

I am not sure how this function would fit in common/memory.c code. We already have get_page_from_gfn to get a page from the tuple (d, gfn).

This function adds more check that may not fit everyone. The only place I could see potential usage is prepare_ring_for_helper. But what would be a suitable name given?

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#10 lore raw
Quoted 20 lines

-----Original Message-----
From: Julien Grall [mailto:[email protected]]
Sent: 19 September 2017 10:40
To: Jan Beulich <[email protected]>; Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; Wei Liu <[email protected]>; [email protected]; [email protected]; Tim (Xen.org) <[email protected]>
Subject: Re: [Xen-devel] [PATCH v2] xen: grant-table: Simplify get_paged_frame

Hi,

Quoted 3 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 19.09.17 at 10:34, <[email protected]> wrote:

I do wonder whether this function belongs in the grant table code though. Getting the page from a (d, gfn) tuple is probably something that's

needed in

Quoted 1 line
Quoted 1 line

a few places and hence putting the code in common/memory.c (with

Quoted 9 lines

suitable

Quoted 4 lines
Quoted 1 line

adjustment to the error values) would seem more appropriate.

That's been true from the very beginning of the existence of the function, I think.

I am not sure how this function would fit in common/memory.c code. We already have get_page_from_gfn to get a page from the tuple (d, gfn).

But that doesn't have the extra logic for populating and unsharing right? Otherwise why would get_paged_frame() need to exist at all?

Quoted 4 lines

This function adds more check that may not fit everyone. The only place I could see potential usage is prepare_ring_for_helper. But what would be a suitable name given?

I would leave the name alone and just move the code.

Paul

Quoted 4 lines

Cheers,

--
Julien Grall

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

#11 lore raw
Quoted 23 lines · Paul Durrant
Quoted 23 lines

-----Original Message-----
From: Julien Grall [mailto:[email protected]]
Sent: 19 September 2017 10:40
To: Jan Beulich <[email protected]>; Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; Wei Liu <[email protected]>; [email protected]; [email protected]; Tim (Xen.org) <[email protected]>
Subject: Re: [Xen-devel] [PATCH v2] xen: grant-table: Simplify get_paged_frame

Hi,

Quoted 3 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 19.09.17 at 10:34, <[email protected]> wrote:

I do wonder whether this function belongs in the grant table code though. Getting the page from a (d, gfn) tuple is probably something that's

needed in

Quoted 1 line
Quoted 1 line

a few places and hence putting the code in common/memory.c (with

suitable

Quoted 2 lines
Quoted 1 line

adjustment to the error values) would seem more appropriate.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

That's been true from the very beginning of the existence of the function, I think.

I am not sure how this function would fit in common/memory.c code. We already have get_page_from_gfn to get a page from the tuple (d, gfn).

But that doesn't have the extra logic for populating and unsharing right? Otherwise why would get_paged_frame() need to exist at all?

This code does not have the logic to unshare. It just denies it.

There are multiple places in grant-table which require similar check. Hence why the helper is here to avoid duplicating the code in grant_table.c.

With this patch, this will contain specific check for grant mapping, such as denying foreign mapping. Are we going to impose that for get_paged_frame in common/memory.c?

Quoted 7 lines
Quoted 5 lines

This function adds more check that may not fit everyone. The only place I could see potential usage is prepare_ring_for_helper. But what would be a suitable name given?

I would leave the name alone and just move the code.

The name does not make sense in common/memory.c. Why would you allow populating but not unsharing? This looks to me a decision that fits grant-table and not necessarily the rest of the Xen.

So I still don't think this would be a suitable function in common/memory.c

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#12 lore raw
In reply to Julien Grall
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 19.09.17 at 11:39, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 19.09.17 at 10:34, <[email protected]> wrote:

I do wonder whether this function belongs in the grant table code though. Getting the page from a (d, gfn) tuple is probably something that's needed in a few places and hence putting the code in common/memory.c (with suitable adjustment to the error values) would seem more appropriate.

That's been true from the very beginning of the existence of the function, I think.

Quoted 6 lines

I am not sure how this function would fit in common/memory.c code. We already have get_page_from_gfn to get a page from the tuple (d, gfn).

This function adds more check that may not fit everyone. The only place I could see potential usage is prepare_ring_for_helper. But what would be a suitable name given?

Actually I didn't mean to suggest you do anything beyond what the patch already does. If you, Paul, or anyone else feel like moving the function, it would probably better be a separate patch (and we may then want to think of not only a better name, but also where else such that function may be usable).

Jan

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

#13 lore raw
Quoted 33 lines

-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 19 September 2017 10:58
To: Julien Grall <[email protected]>
Cc: Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; Paul Durrant <[email protected]>; Wei Liu <[email protected]>; [email protected]; [email protected]; Tim (Xen.org) <[email protected]>
Subject: Re: [Xen-devel] [PATCH v2] xen: grant-table: Simplify get_paged_frame

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 19.09.17 at 11:39, <[email protected]> wrote:
Quoted 2 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 19.09.17 at 10:34, <[email protected]> wrote:

I do wonder whether this function belongs in the grant table code

though.

Quoted 1 line
Quoted 1 line
Quoted 1 line

Getting the page from a (d, gfn) tuple is probably something that's

needed in

Quoted 1 line
Quoted 1 line
Quoted 1 line

a few places and hence putting the code in common/memory.c (with

suitable

Quoted 11 lines
Quoted 4 lines
Quoted 1 line

adjustment to the error values) would seem more appropriate.

That's been true from the very beginning of the existence of the function, I think.

I am not sure how this function would fit in common/memory.c code. We already have get_page_from_gfn to get a page from the tuple (d, gfn).

This function adds more check that may not fit everyone. The only place I could see potential usage is prepare_ring_for_helper. But what would be a suitable name given?

Quoted 6 lines

Actually I didn't mean to suggest you do anything beyond what the patch already does. If you, Paul, or anyone else feel like moving the function, it would probably better be a separate patch (and we may then want to think of not only a better name, but also where else such that function may be usable).

Ok, I'll do it then. I need the same functionality for PV-IOMMU.

Paul

Quoted 1 line

Jan

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

#14 lore raw
In reply to Julien Grall
Quoted 57 lines · Julien Grall

The implementation of get_paged_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 main difference is the x86 version will allow grant on foreign page when using HVM/PVH whilst Arm does not. At the moment, on x86 foreign pages are only allowed for PVH Dom0. It seems that foreign pages should never be granted so deny them

The check for shared/paged memory are now 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]>

Changes in v2:
- Deny grant on foreign page (aligned with the ARM code)
- Use #ifdef rather than #if defined
- Update commit message
- Fix typo in the title

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.

This patch will deny granting foreign pages. Jan Beulich is happy with it. Any other opinions?

---
 xen/common/grant_table.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)
xen/common/grant_table.c +0 -0
index c3895e6201..a6a168df6e 100644

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

Quoted 7 lines
xen/common/grant_table.c +0 -1
@@ -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,

While you're at it, mind dropping the pointless brackets around readonly?

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

Quoted 2 lines
xen/common/grant_table.c +0 -0
@@ -267,26 +266,24 @@ static int get_paged_frame(unsigned long gfn, unsigned long *frame,
     if ( !(*page) )

And here as well.

Quoted 8 lines
xen/common/grant_table.c +3 -0
     {
         *frame = mfn_x(INVALID_MFN);
+#ifdef P2M_SHARED_TYPES
         if ( p2m_is_shared(p2mt) )
             return GNTST_eagain;
+#endif
+#ifdef P2M_PAGES_TYPES
         if ( p2m_is_paging(p2mt) )

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

Quoted 10 lines
xen/common/grant_table.c +4 -0
         {
             p2m_mem_paging_populate(rd, gfn);
             return GNTST_eagain;
         }
+#endif
         return GNTST_bad_page;
     }
+
+    if ( p2m_is_foreign(p2mt) )
+        return GNTST_bad_page;

You only get here when you have taken a ref on the page. You should drop the ref before returning.

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

#15 lore raw

Hi Wei,

Quoted 64 lines · Wei Liu
Quoted 63 lines · Julien Grall

The implementation of get_paged_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 main difference is the x86 version will allow grant on foreign page when using HVM/PVH whilst Arm does not. At the moment, on x86 foreign pages are only allowed for PVH Dom0. It seems that foreign pages should never be granted so deny them

The check for shared/paged memory are now 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]>

Changes in v2:
- Deny grant on foreign page (aligned with the ARM code)
- Use #ifdef rather than #if defined
- Update commit message
- Fix typo in the title

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.

This patch will deny granting foreign pages. Jan Beulich is happy with it. Any other opinions?

---
  xen/common/grant_table.c | 19 ++++++++-----------
  1 file changed, 8 insertions(+), 11 deletions(-)
xen/common/grant_table.c +0 -1
index c3895e6201..a6a168df6e 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;
 
Quoted 4 lines

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

Quoted 1 line
xen/common/grant_table.c +0 -0
      *page = get_page_from_gfn(rd, gfn, &p2mt,

While you're at it, mind dropping the pointless brackets around readonly?

Will do.

Quoted 18 lines

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

Quoted 2 lines
xen/common/grant_table.c +0 -0
@@ -267,26 +266,24 @@ static int get_paged_frame(unsigned long gfn, unsigned long *frame,
      if ( !(*page) )

And here as well.

Quoted 13 lines
xen/common/grant_table.c +4 -0
      {
          *frame = mfn_x(INVALID_MFN);
+#ifdef P2M_SHARED_TYPES
          if ( p2m_is_shared(p2mt) )
              return GNTST_eagain;
+#endif
+#ifdef P2M_PAGES_TYPES
          if ( p2m_is_paging(p2mt) )
          {
              p2m_mem_paging_populate(rd, gfn);
              return GNTST_eagain;
          }
+#endif
Quoted 8 lines

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

Quoted 5 lines
xen/common/grant_table.c +3 -0
          return GNTST_bad_page;
      }
+
+    if ( p2m_is_foreign(p2mt) )
+        return GNTST_bad_page;

You only get here when you have taken a ref on the page. You should drop the ref before returning.

Hmmm yes. I will send a new version with that fixed.

Cheers,

Signature · 6 lines
Julien Grall

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