Skip to contentSkip to conversation

Arm: tighten translate_get_page()

PATCH In review Jan Beulich 3 participants 6 messages Feb 16 – Feb 23

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Arm: tighten translate_get_page()

Permitting writes when the P2M type says "read-only" can't be correct.

Fixes 1661158723a ("xen/arm: Extend copy_to_guest to support copying from/to guest physical address")

---
What exactly p2m_ram_ro means on Arm is unclear: The comment next to its definition says one thing, its use in get_page_from_gfn() says another. (I remember raising this point before, i.e. it feels a little odd that the ambiguity still exists.) The patch here assumes the comment is what is wrong.

xen/arch/arm/guestcopy.c +1 -1
@@ -44,7 +44,7 @@ static struct page_info *translate_get_p
     if ( !page )
         return NULL;
 
-    if ( !p2m_is_ram(p2mt) )
+    if ( write ? p2mt != p2m_ram_rw : !p2m_is_ram(p2mt) )
     {
         put_page(page);
         return NULL;
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Jan Beulich

Permitting writes when the P2M type says "read-only" can't be correct.

Fixes 1661158723a ("xen/arm: Extend copy_to_guest to support copying from/to guest physical address")
Quoted 10 lines

---
What exactly p2m_ram_ro means on Arm is unclear: The comment next to its definition says one thing, its use in get_page_from_gfn() says another. (I remember raising this point before, i.e. it feels a little odd that the ambiguity still exists.) The patch here assumes the comment is what is wrong.

xen/arch/arm/guestcopy.c static struct page_info *translate_get_p · line 50

Quoted 8 lines
xen/arch/arm/guestcopy.c +1 -1
@@ -44,7 +44,7 @@ static struct page_info *translate_get_p
     if ( !page )
         return NULL;
 
-    if ( !p2m_is_ram(p2mt) )
+    if ( write ? p2mt != p2m_ram_rw : !p2m_is_ram(p2mt) )
     {
         put_page(page);
         return NULL;

The ambiguity you mention is indeed problematic. This mixes page type with p2m type. The comment "The p2m_type is based on the type of the page" admits this conflation for DOMID_XEN.

AFAICT, p2m_ram_ro is not used on Arm for normal domains. The only use is in get_page_from_gfn() for DOMID_XEN. Maybe we could change get_page_from_gfn() to always return p2m_ram_rw since DOMID_XEN has direct 1:1 access anyway?

~Michal

#2 lore raw
Quoted 8 lines · Michal
Quoted 4 lines · Jan Beulich

Permitting writes when the P2M type says "read-only" can't be correct.

Fixes 1661158723a ("xen/arm: Extend copy_to_guest to support copying from/to guest physical address")

Thanks.

Quoted 23 lines
Quoted 10 lines

---
What exactly p2m_ram_ro means on Arm is unclear: The comment next to its definition says one thing, its use in get_page_from_gfn() says another. (I remember raising this point before, i.e. it feels a little odd that the ambiguity still exists.) The patch here assumes the comment is what is wrong.

xen/arch/arm/guestcopy.c static struct page_info *translate_get_p · line 50

Quoted 8 lines
xen/arch/arm/guestcopy.c +1 -1
@@ -44,7 +44,7 @@ static struct page_info *translate_get_p
     if ( !page )
         return NULL;
 
-    if ( !p2m_is_ram(p2mt) )
+    if ( write ? p2mt != p2m_ram_rw : !p2m_is_ram(p2mt) )
     {
         put_page(page);
         return NULL;

The ambiguity you mention is indeed problematic. This mixes page type with p2m type. The comment "The p2m_type is based on the type of the page" admits this conflation for DOMID_XEN.

Quoted 3 lines

AFAICT, p2m_ram_ro is not used on Arm for normal domains. The only use is in get_page_from_gfn() for DOMID_XEN. Maybe we could change get_page_from_gfn() to always return p2m_ram_rw since DOMID_XEN has direct 1:1 access anyway?

But that's not correct for cases where share_xen_page_with_privileged_guest() is passed SHARE_ro. XENMAPSPACE_gmfn_foreign requests have to result in r/o mappings in that case.

Jan

#3 lore raw
Quoted 35 lines · Jan Beulich
Quoted 8 lines · Michal
Quoted 4 lines · Jan Beulich

Permitting writes when the P2M type says "read-only" can't be correct.

Fixes 1661158723a ("xen/arm: Extend copy_to_guest to support copying from/to guest physical address")

Thanks.

Quoted 23 lines
Quoted 10 lines

---
What exactly p2m_ram_ro means on Arm is unclear: The comment next to its definition says one thing, its use in get_page_from_gfn() says another. (I remember raising this point before, i.e. it feels a little odd that the ambiguity still exists.) The patch here assumes the comment is what is wrong.

xen/arch/arm/guestcopy.c static struct page_info *translate_get_p · line 50

Quoted 8 lines
xen/arch/arm/guestcopy.c +1 -1
@@ -44,7 +44,7 @@ static struct page_info *translate_get_p
     if ( !page )
         return NULL;
 
-    if ( !p2m_is_ram(p2mt) )
+    if ( write ? p2mt != p2m_ram_rw : !p2m_is_ram(p2mt) )
     {
         put_page(page);
         return NULL;

The ambiguity you mention is indeed problematic. This mixes page type with p2m type. The comment "The p2m_type is based on the type of the page" admits this conflation for DOMID_XEN.

Quoted 7 lines
Quoted 3 lines

AFAICT, p2m_ram_ro is not used on Arm for normal domains. The only use is in get_page_from_gfn() for DOMID_XEN. Maybe we could change get_page_from_gfn() to always return p2m_ram_rw since DOMID_XEN has direct 1:1 access anyway?

But that's not correct for cases where share_xen_page_with_privileged_guest() is passed SHARE_ro. XENMAPSPACE_gmfn_foreign requests have to result in r/o mappings in that case.

Yes. Therefore, on Arm:
- p2m_ram_ro is never stored in P2M tables for normal domains
- it's only used by get_page_from_gfn() for DOMID_XEN pages
- it's used as a signal to install p2m_map_foreign_ro mappings

The code should stay as is then and we could modify the comment to say:
/* Read-only RAM; only used for DOMID_XEN */

~Michal

#4 lore raw

Hi Michal,

Quoted 5 lines · Michal
Quoted 3 lines

But that's not correct for cases where share_xen_page_with_privileged_guest() is passed SHARE_ro. XENMAPSPACE_gmfn_foreign requests have to result in r/o mappings in that case.

Yes. Therefore, on Arm:
- p2m_ram_ro is never stored in P2M tables for normal domains

p2m_set_permission() is able to deal with p2m_ram_ro. So this could in theory happen.

Quoted 5 lines

- it's only used by get_page_from_gfn() for DOMID_XEN pages
- it's used as a signal to install p2m_map_foreign_ro mappings

The code should stay as is then and we could modify the comment to say:
/* Read-only RAM; only used for DOMID_XEN */

With what I wrote above, I don't think we should add such comment.

Cheers,

Signature · 1 line
Julien Grall
#5 lore raw

Hi Julien,

Quoted 11 lines · Julien Grall

Hi Michal,

Quoted 5 lines · Michal
Quoted 3 lines

But that's not correct for cases where share_xen_page_with_privileged_guest() is passed SHARE_ro. XENMAPSPACE_gmfn_foreign requests have to result in r/o mappings in that case.

Yes. Therefore, on Arm:
- p2m_ram_ro is never stored in P2M tables for normal domains

p2m_set_permission() is able to deal with p2m_ram_ro. So this could in theory happen.

Only in theory. As of today, this is the unreachable code. In fact I checked our coverage reports for safety and indeed it shows up as an unreachable code. There is no path in Xen that can lead to that point.

Quoted 8 lines
Quoted 6 lines

- it's only used by get_page_from_gfn() for DOMID_XEN pages
- it's used as a signal to install p2m_map_foreign_ro mappings

The code should stay as is then and we could modify the comment to say:
/* Read-only RAM; only used for DOMID_XEN */

With what I wrote above, I don't think we should add such comment.

I think the goal here is to make the comment reflect the current situation (and as of now it's only used for DOMID_XEN). Taking what I wrote above, do you still think we should not update it? Once we have a use for RO for normal domains, we could then update the comment to reflect a new reality.

~Michal