Skip to contentSkip to conversation

common: map_vcpu_info() wants to unshare the underlying page

PATCH In review Jan Beulich 4 participants 8 messages Oct 11, 2022 – Oct 28, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 common: map_vcpu_info() wants to unshare the underlying page

Not passing P2M_UNSHARE to get_page_from_gfn() means there won't even be an attempt to unshare the referenced page, without any indication to the caller (e.g. -EAGAIN). Note that guests have no direct control over which of their pages are shared (or paged out), and hence they have no way to make sure all on their own that the subsequent obtaining of a writable type reference can actually succeed.

---
Really I wonder whether the function wouldn't better use check_get_page_from_gfn() _and_ permit p2m_ram_rw only. Otoh the P2M type is stale by the time it is being looked at, so all depends on the subsequent obtaining of a writable type reference anyway ...

A similar issue then apparently exists in guest_wrmsr_xen() when writing the hypercall page. Interestingly there p2m_is_paging() is being checked for (but shared pages aren't).

xen/common/domain.c +1 -1
@@ -1484,7 +1484,7 @@ int map_vcpu_info(struct vcpu *v, unsign
     if ( (v != current) && !(v->pause_flags & VPF_down) )
         return -EINVAL;
 
-    page = get_page_from_gfn(d, gfn, NULL, P2M_ALLOC);
+    page = get_page_from_gfn(d, gfn, NULL, P2M_UNSHARE);
     if ( !page )
         return -EINVAL;
 
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Jan Beulich

Not passing P2M_UNSHARE to get_page_from_gfn() means there won't even be an attempt to unshare the referenced page, without any indication to the caller (e.g. -EAGAIN). Note that guests have no direct control over which of their pages are shared (or paged out), and hence they have no way to make sure all on their own that the subsequent obtaining of a writable type reference can actually succeed.

Quoted 9 lines

---
Really I wonder whether the function wouldn't better use check_get_page_from_gfn() _and_ permit p2m_ram_rw only. Otoh the P2M type is stale by the time it is being looked at, so all depends on the subsequent obtaining of a writable type reference anyway ...

A similar issue then apparently exists in guest_wrmsr_xen() when writing the hypercall page. Interestingly there p2m_is_paging() is being checked for (but shared pages aren't).

Doesn't guest_wrmsr_xen() also needs to use UNSHARE?

I wonder if it would be helpful to introduce some kind of helper so that all functions can use it, get_guest_writable_page() or similar.

xen/common/domain.c int map_vcpu_info(struct vcpu *v, unsign · line 1487

Quoted 9 lines
xen/common/domain.c +1 -1
@@ -1484,7 +1484,7 @@ int map_vcpu_info(struct vcpu *v, unsign
     if ( (v != current) && !(v->pause_flags & VPF_down) )
         return -EINVAL;
 
-    page = get_page_from_gfn(d, gfn, NULL, P2M_ALLOC);
+    page = get_page_from_gfn(d, gfn, NULL, P2M_UNSHARE);

I had to go look up that P2M_UNSHARE implies P2M_ALLOC for the users of the parameter, it would be helpful to add a comment in p2m.h that UNSHARE implies ALLOC.

Thanks, Roger.

#2 lore raw
Quoted 11 lines · Roger Pau Monné
Quoted 8 lines · Jan Beulich

Not passing P2M_UNSHARE to get_page_from_gfn() means there won't even be an attempt to unshare the referenced page, without any indication to the caller (e.g. -EAGAIN). Note that guests have no direct control over which of their pages are shared (or paged out), and hence they have no way to make sure all on their own that the subsequent obtaining of a writable type reference can actually succeed.

Thanks.

Quoted 11 lines
Quoted 9 lines

---
Really I wonder whether the function wouldn't better use check_get_page_from_gfn() _and_ permit p2m_ram_rw only. Otoh the P2M type is stale by the time it is being looked at, so all depends on the subsequent obtaining of a writable type reference anyway ...

A similar issue then apparently exists in guest_wrmsr_xen() when writing the hypercall page. Interestingly there p2m_is_paging() is being checked for (but shared pages aren't).

Doesn't guest_wrmsr_xen() also needs to use UNSHARE?

I think so (hence I did say "A similar issue then apparently exists ..."). With the one caveat that a page that was already initialized as a hypercall one (and was shared afterwards) wouldn't need to be unshared.

Quoted 2 lines

I wonder if it would be helpful to introduce some kind of helper so that all functions can use it, get_guest_writable_page() or similar.

Maybe. Using check_get_page_from_gfn() would already help, I guess.

Quoted 6 lines
Quoted 6 lines
xen/common/domain.c +0 -0
@@ -1484,7 +1484,7 @@ int map_vcpu_info(struct vcpu *v, unsign
     if ( (v != current) && !(v->pause_flags & VPF_down) )
         return -EINVAL;
 
Quoted 6 lines

xen/common/domain.c int map_vcpu_info(struct vcpu *v, unsign · line 1487

Quoted 2 lines
xen/common/domain.c +1 -1
-    page = get_page_from_gfn(d, gfn, NULL, P2M_ALLOC);
+    page = get_page_from_gfn(d, gfn, NULL, P2M_UNSHARE);

I had to go look up that P2M_UNSHARE implies P2M_ALLOC for the users of the parameter, it would be helpful to add a comment in p2m.h that UNSHARE implies ALLOC.

Same here, plus I needed to further figure out that the same implication missing on Arm is okay merely because they ignore the respective argument.

Jan

#3 lore raw
Quoted 15 lines · Jan Beulich
Quoted 7 lines · Roger Pau Monné
Quoted 6 lines · Jan Beulich
xen/common/domain.c +0 -0
@@ -1484,7 +1484,7 @@ int map_vcpu_info(struct vcpu *v, unsign
     if ( (v != current) && !(v->pause_flags & VPF_down) )
         return -EINVAL;
 
Quoted 6 lines

xen/common/domain.c int map_vcpu_info(struct vcpu *v, unsign · line 1487

Quoted 2 lines
xen/common/domain.c +1 -1
-    page = get_page_from_gfn(d, gfn, NULL, P2M_ALLOC);
+    page = get_page_from_gfn(d, gfn, NULL, P2M_UNSHARE);

I had to go look up that P2M_UNSHARE implies P2M_ALLOC for the users of the parameter, it would be helpful to add a comment in p2m.h that UNSHARE implies ALLOC.

Quoted 2 lines

Same here, plus I needed to further figure out that the same implication missing on Arm is okay merely because they ignore the respective argument.

... it's made worse by some callers using P2M_ALLOC | P2M_UNSHARE which adds to the confusion.

Thanks, Roger.

#4 lore raw

[4.17?] Re: [PATCH] common: map_vcpu_info() wants to unshare the underlying page

In reply to Roger Pau Monné
Quoted 11 lines · Roger Pau Monné
Quoted 8 lines · Jan Beulich

Not passing P2M_UNSHARE to get_page_from_gfn() means there won't even be an attempt to unshare the referenced page, without any indication to the caller (e.g. -EAGAIN). Note that guests have no direct control over which of their pages are shared (or paged out), and hence they have no way to make sure all on their own that the subsequent obtaining of a writable type reference can actually succeed.

I didn't Cc you on the initial submission because mem-sharing isn't a supported feature, but upon reconsideration I thought I'd at least ask whether you would want to give this a release-ack. I don't really see any risk associated with it.

Jan

#5 lore raw

RE: [4.17?] Re: [PATCH] common: map_vcpu_info() wants to unshare the underlying page

(+Arm maintainers)

Hi Jan,

Quoted 21 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Wednesday, October 26, 2022 12:07 AM
To: Henry Wang <[email protected]>
Cc: [email protected]; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monné <[email protected]>
Subject: [4.17?] Re: [PATCH] common: map_vcpu_info() wants to unshare the underlying page

Quoted 2 lines · Roger Pau Monné
Quoted 1 line · Jan Beulich

Not passing P2M_UNSHARE to get_page_from_gfn() means there won't

even be

Quoted 6 lines
Quoted 6 lines

an attempt to unshare the referenced page, without any indication to the caller (e.g. -EAGAIN). Note that guests have no direct control over which of their pages are shared (or paged out), and hence they have no way to make sure all on their own that the subsequent obtaining of a writable type reference can actually succeed.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

I didn't Cc you on the initial submission because mem-sharing isn't a supported feature, but upon reconsideration I thought I'd at least ask whether you would want to give this a release-ack. I don't really see any risk associated with it.

By looking at the patch itself, this change seems ok to me, so I think I will not block it, but I think Arm maintainers' approval might be needed because of the discussion in [1], so I added them for their information. If Arm maintainers do not object the change, you can have my release-ack.

[1] https://lore.kernel.org/xen-devel/[email protected]/

Kind regards,
Henry

Quoted 2 lines

Jan

Acked-by
#6 lore raw

Re: [4.17?] Re: [PATCH] common: map_vcpu_info() wants to unshare the underlying page

Hi Henry, Jan,

Sorry for the late reply.

Quoted 30 lines · Henry Wang
Quoted 21 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Wednesday, October 26, 2022 12:07 AM
To: Henry Wang <[email protected]>
Cc: [email protected]; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monné <[email protected]>
Subject: [4.17?] Re: [PATCH] common: map_vcpu_info() wants to unshare the underlying page

Quoted 2 lines · Roger Pau Monné
Quoted 1 line · Jan Beulich

Not passing P2M_UNSHARE to get_page_from_gfn() means there won't

even be

Quoted 6 lines
Quoted 6 lines

an attempt to unshare the referenced page, without any indication to the caller (e.g. -EAGAIN). Note that guests have no direct control over which of their pages are shared (or paged out), and hence they have no way to make sure all on their own that the subsequent obtaining of a writable type reference can actually succeed.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

I didn't Cc you on the initial submission because mem-sharing isn't a supported feature, but upon reconsideration I thought I'd at least ask whether you would want to give this a release-ack. I don't really see any risk associated with it.

Quoted 4 lines

By looking at the patch itself, this change seems ok to me, so I think I will not block it, but I think Arm maintainers' approval might be needed because of the discussion in [1], so I added them for their information. If Arm maintainers do not object the change, you can have my release-ack.

The P2M query type is so far ignored on Arm as we neither support populate-on-demand nor memsharing.

I am assuming that if we ever introduce any those of features, we would follow the same behavior as x86. So:

Cheers,

Signature · 1 line
Julien Grall
#7 lore raw

Re: [4.17?] Re: [PATCH] common: map_vcpu_info() wants to unshare the underlying page

Quoted 31 lines · Julien Grall
Quoted 30 lines · Henry Wang
Quoted 29 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Wednesday, October 26, 2022 12:07 AM
To: Henry Wang <[email protected]>
Cc: [email protected]; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monné <[email protected]>
Subject: [4.17?] Re: [PATCH] common: map_vcpu_info() wants to unshare the underlying page

Quoted 2 lines · Roger Pau Monné
Quoted 1 line · Jan Beulich

Not passing P2M_UNSHARE to get_page_from_gfn() means there won't

even be

Quoted 9 lines
Quoted 7 lines

an attempt to unshare the referenced page, without any indication to the caller (e.g. -EAGAIN). Note that guests have no direct control over which of their pages are shared (or paged out), and hence they have no way to make sure all on their own that the subsequent obtaining of a writable type reference can actually succeed.

I didn't Cc you on the initial submission because mem-sharing isn't a supported feature, but upon reconsideration I thought I'd at least ask whether you would want to give this a release-ack. I don't really see any risk associated with it.

Quoted 4 lines
Quoted 4 lines

By looking at the patch itself, this change seems ok to me, so I think I will not block it, but I think Arm maintainers' approval might be needed because of the discussion in [1], so I added them for their information. If Arm maintainers do not object the change, you can have my release-ack.

I'll take the liberty then to translate this into an actual tag, with ...

Quoted 7 lines

The P2M query type is so far ignored on Arm as we neither support populate-on-demand nor memsharing.

I am assuming that if we ever introduce any those of features, we would follow the same behavior as x86. So:

... this now in place (thanks Julien).

Jan