Skip to contentSkip to conversation

-EINTR return in domain_relinquish_resources

DISCUSSION Konrad Rzeszutek Wilk 3 participants 14 messages Jan 21, 2015 – Jan 26, 2015

lore
Share & tools
lore
#0 lore raw

As I was looking at some of the XSA I realized that the call-chain of:

domain_relinquish_resources
->vcpu_destroy_pagetables

     -> put_page_and_type_preemptible
        -> __put_page_type
		returns -EINTR

which means we end up at:

 618         rc = domain_relinquish_resources(d);                                    
 619         if ( rc != 0 )                                                          
 620         {                                                                       

621 if ( rc == -ERESTART )
622 rc = -EAGAIN;
623 break; <=== with rc=-EINTR
624 }

And return -EINTR to user-space - which loop in
'xc_domain_destroy' is only looking for:

112 int xc_domain_destroy(xc_interface *xch,
113 uint32_t domid)
114 {

 115     int ret;                                                                    
 116     DECLARE_DOMCTL;                                                             
 117     domctl.cmd = XEN_DOMCTL_destroydomain;                                      
 118     domctl.domain = (domid_t)domid;                                             
 119     do {                                                                        

120 ret = do_domctl(xch, &domctl);
121 } while ( ret && (errno == EAGAIN) );
122 return ret;
123 }

which to my reading looks like we would exit out and leave an DOMDYING_dying domain. Looking at the code it seems possible to continue on if the user does 'xl destroy <X>' guest again, but I was wondering if:

a). Should the toolstack (libxl or libxc) have the code to
handle -EINTR?

b). Or should the hypervisor convert the -EINTR to -ERESTART
(or -EAGAIN) - which most of the code (see users of get_page_type_preemptible) do right now?

Thanks!

#1 lore raw
Quoted 39 lines · Konrad Rzeszutek Wilk

As I was looking at some of the XSA I realized that the call-chain of:

domain_relinquish_resources
->vcpu_destroy_pagetables

     -> put_page_and_type_preemptible
        -> __put_page_type
		returns -EINTR

which means we end up at:

 618         rc = domain_relinquish_resources(d);                                    
 619         if ( rc != 0 )                                                          
 620         {                                                                       

621 if ( rc == -ERESTART )
622 rc = -EAGAIN;
623 break; <=== with rc=-EINTR
624 }

And return -EINTR to user-space - which loop in
'xc_domain_destroy' is only looking for:

112 int xc_domain_destroy(xc_interface *xch,
113 uint32_t domid)
114 {

 115     int ret;                                                                    
 116     DECLARE_DOMCTL;                                                             
 117     domctl.cmd = XEN_DOMCTL_destroydomain;                                      
 118     domctl.domain = (domid_t)domid;                                             
 119     do {                                                                        

120 ret = do_domctl(xch, &domctl);
121 } while ( ret && (errno == EAGAIN) );
122 return ret;
123 }

which to my reading looks like we would exit out and leave an DOMDYING_dying domain. Looking at the code it seems possible to continue on if the user does 'xl destroy <X>' guest again, but I was wondering if:

Quoted 6 lines

a). Should the toolstack (libxl or libxc) have the code to
handle -EINTR?

b). Or should the hypervisor convert the -EINTR to -ERESTART
(or -EAGAIN) - which most of the code (see users of get_page_type_preemptible) do right now?

Good spot.

Other areas of similar code condense EINTR into ERESTART. I think in this case it is Xen's job to turn -EINTR into -EAGAIN as this hypercall specifically has preemptibility built into its normal use.

I wonder if there are other similar hypercall paths which need to catch EINTR as well as ERESTART?

~Andrew

#2 lore raw
Quoted 48 lines · Andrew Cooper
Quoted 39 lines · Konrad Rzeszutek Wilk

As I was looking at some of the XSA I realized that the call-chain of:

domain_relinquish_resources
->vcpu_destroy_pagetables

     -> put_page_and_type_preemptible
        -> __put_page_type
		returns -EINTR

which means we end up at:

 618         rc = domain_relinquish_resources(d);                                    
 619         if ( rc != 0 )                                                          
 620         {                                                                       

621 if ( rc == -ERESTART )
622 rc = -EAGAIN;
623 break; <=== with rc=-EINTR
624 }

And return -EINTR to user-space - which loop in
'xc_domain_destroy' is only looking for:

112 int xc_domain_destroy(xc_interface *xch,
113 uint32_t domid)
114 {

 115     int ret;                                                                    
 116     DECLARE_DOMCTL;                                                             
 117     domctl.cmd = XEN_DOMCTL_destroydomain;                                      
 118     domctl.domain = (domid_t)domid;                                             
 119     do {                                                                        

120 ret = do_domctl(xch, &domctl);
121 } while ( ret && (errno == EAGAIN) );
122 return ret;
123 }

which to my reading looks like we would exit out and leave an DOMDYING_dying domain. Looking at the code it seems possible to continue on if the user does 'xl destroy <X>' guest again, but I was wondering if:

Quoted 6 lines

a). Should the toolstack (libxl or libxc) have the code to
handle -EINTR?

b). Or should the hypervisor convert the -EINTR to -ERESTART
(or -EAGAIN) - which most of the code (see users of get_page_type_preemptible) do right now?

Good spot.

Quoted 8 lines

Other areas of similar code condense EINTR into ERESTART. I think in this case it is Xen's job to turn -EINTR into -EAGAIN as this hypercall specifically has preemptibility built into its normal use.

I wonder if there are other similar hypercall paths which need to catch EINTR as well as ERESTART?

~Andrew

Thinking about this, it occurs to me that, along with parameter clobbering in debug builds, we should assert that internal error codes never escape to guests.

It also occurs to me that the PV hypercall paths would both be far more simple (particularly the register clobbering bits) if they were written in C like their HVM counterparts, rather than ASM. I will see whether I can find some copious free time to see about making this happen.

~Andrew

#3 lore raw
Quoted 47 lines · Andrew Cooper
Quoted 46 lines · Andrew Cooper
Quoted 45 lines · Konrad Rzeszutek Wilk

As I was looking at some of the XSA I realized that the call-chain of:

domain_relinquish_resources
->vcpu_destroy_pagetables

     -> put_page_and_type_preemptible
        -> __put_page_type
		returns -EINTR

which means we end up at:

 618         rc = domain_relinquish_resources(d);                                    
 619         if ( rc != 0 )                                                          
 620         {                                                                       

621 if ( rc == -ERESTART )
622 rc = -EAGAIN;
623 break; <=== with rc=-EINTR
624 }

And return -EINTR to user-space - which loop in
'xc_domain_destroy' is only looking for:

112 int xc_domain_destroy(xc_interface *xch,
113 uint32_t domid)
114 {

 115     int ret;                                                                    
 116     DECLARE_DOMCTL;                                                             
 117     domctl.cmd = XEN_DOMCTL_destroydomain;                                      
 118     domctl.domain = (domid_t)domid;                                             
 119     do {                                                                        

120 ret = do_domctl(xch, &domctl);
121 } while ( ret && (errno == EAGAIN) );
122 return ret;
123 }

which to my reading looks like we would exit out and leave an DOMDYING_dying domain. Looking at the code it seems possible to continue on if the user does 'xl destroy <X>' guest again, but I was wondering if:

a). Should the toolstack (libxl or libxc) have the code to
handle -EINTR?

b). Or should the hypervisor convert the -EINTR to -ERESTART
(or -EAGAIN) - which most of the code (see users of get_page_type_preemptible) do right now?

Quoted 8 lines
Quoted 8 lines

Good spot.

Other areas of similar code condense EINTR into ERESTART. I think in this case it is Xen's job to turn -EINTR into -EAGAIN as this hypercall specifically has preemptibility built into its normal use.

I wonder if there are other similar hypercall paths which need to catch EINTR as well as ERESTART?

I did not see them.

Quoted 6 lines
Quoted 2 lines

~Andrew

Thinking about this, it occurs to me that, along with parameter clobbering in debug builds, we should assert that internal error codes never escape to guests.

Are there any other ones besides ERESTART/EINTR ?

Quoted 7 lines

It also occurs to me that the PV hypercall paths would both be far more simple (particularly the register clobbering bits) if they were written in C like their HVM counterparts, rather than ASM. I will see whether I can find some copious free time to see about making this happen.

~Andrew

#4 lore raw
In reply to Konrad Rzeszutek Wilk
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 21.01.15 at 22:27, <[email protected]> wrote:

As I was looking at some of the XSA I realized that the call-chain of:

domain_relinquish_resources
->vcpu_destroy_pagetables

Quoted 7 lines
     -> put_page_and_type_preemptible
        -> __put_page_type
		returns -EINTR

[...]
b). Or should the hypervisor convert the -EINTR to -ERESTART
(or -EAGAIN) - which most of the code (see users of get_page_type_preemptible) do right now?

This one, in vcpu_destroy_pagetables(). I'm afraid I overlooked this when adding the preemption capability here.

Jan

#5 lore raw
Quoted 14 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 21.01.15 at 22:27, <[email protected]> wrote:

As I was looking at some of the XSA I realized that the call-chain of:

domain_relinquish_resources
->vcpu_destroy_pagetables

Quoted 7 lines
     -> put_page_and_type_preemptible
        -> __put_page_type
		returns -EINTR

[...]
b). Or should the hypervisor convert the -EINTR to -ERESTART
(or -EAGAIN) - which most of the code (see users of get_page_type_preemptible) do right now?

Quoted 2 lines

This one, in vcpu_destroy_pagetables(). I'm afraid I overlooked this when adding the preemption capability here.

OK. Would this RFC patch be OK? (I can send it off as normal - just want to make sure you are OK with this being put there)

Quoted 1 line

From 1558a9870f438df949a8ad09a27825bd35a9f4ea Mon Sep 17 00:00:00 2001

From: Konrad Rzeszutek Wilk <[email protected]>
Date: Thu, 22 Jan 2015 11:34:21 -0500
Subject: [PATCH] domain: In vcpu_destroy_pagetables we can return -EINTR
instead of -EAGAIN

which has the side effect that domain_relinquish_resources will stop and return to user-space -EINTR - which it is not equipped to deal with. The preemption mechanism we have to domain destruction is to return -EAGAIN and as such we need to catch the case of:

domain_relinquish_resources
->vcpu_destroy_pagetables

    -> put_page_and_type_preemptible
       -> __put_page_type
           returns -EINTR

and convert it to the proper type.

---
 xen/arch/x86/mm.c | 3 +++
 1 file changed, 3 insertions(+)
xen/arch/x86/mm.c +3 -0
index 6e9c2c0..3ac2ae5 100644
@@ -2677,6 +2677,9 @@ int vcpu_destroy_pagetables(struct vcpu *v)
 
     v->arch.cr3 = 0;
 
+    if ( rc == -EINTR )
+        rc = -EAGAIN;
+
     return rc;
 }
 
Signature · 1 line
2.1.0
#6 lore raw
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 22.01.15 at 17:38, <[email protected]> wrote:
Quoted 14 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 21.01.15 at 22:27, <[email protected]> wrote:

As I was looking at some of the XSA I realized that the call-chain of:

domain_relinquish_resources
->vcpu_destroy_pagetables

     -> put_page_and_type_preemptible
        -> __put_page_type
		returns -EINTR

[...]
b). Or should the hypervisor convert the -EINTR to -ERESTART
(or -EAGAIN) - which most of the code (see users of get_page_type_preemptible) do right now?

Quoted 5 lines
Quoted 2 lines

This one, in vcpu_destroy_pagetables(). I'm afraid I overlooked this when adding the preemption capability here.

OK. Would this RFC patch be OK? (I can send it off as normal - just want to make sure you are OK with this being put there)

Conceptually yes, but there are issues:

Quoted 5 lines

From 1558a9870f438df949a8ad09a27825bd35a9f4ea Mon Sep 17 00:00:00 2001
From: Konrad Rzeszutek Wilk <[email protected]>
Date: Thu, 22 Jan 2015 11:34:21 -0500
Subject: [PATCH] domain: In vcpu_destroy_pagetables we can return -EINTR
instead of -EAGAIN

You should stop sending such conversions to EAGAIN. We switched to ERESTART, and you (just guessing) taking the patch from an older Xen version shouldn't result in this recurring mistake.

xen/arch/x86/mm.c int vcpu_destroy_pagetables(struct vcpu *v) · line 2682

Quoted 9 lines
xen/arch/x86/mm.c +3 -0
@@ -2677,6 +2677,9 @@ int vcpu_destroy_pagetables(struct vcpu *v)
 
     v->arch.cr3 = 0;
 
+    if ( rc == -EINTR )
+        rc = -EAGAIN;
+

Either (my preference) you attach this directly to the two put_page_and_type_preemptible() invocations, or you add a comment here explaining that this catches those two specific cases in one central place. This is because while right now only those two invocations can lead to rc being non-zero, there's nothing preventing other error generating code to be added to this function later on, and we shouldn't blindly convert -EINTR to some other error code, as that may lead to overlooking necessary conversions elsewhere (as happened while I made this function preemptible).

Jan

#7 lore raw
Quoted 30 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 22.01.15 at 17:38, <[email protected]> wrote:
Quoted 14 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 21.01.15 at 22:27, <[email protected]> wrote:

As I was looking at some of the XSA I realized that the call-chain of:

domain_relinquish_resources
->vcpu_destroy_pagetables

     -> put_page_and_type_preemptible
        -> __put_page_type
		returns -EINTR

[...]
b). Or should the hypervisor convert the -EINTR to -ERESTART
(or -EAGAIN) - which most of the code (see users of get_page_type_preemptible) do right now?

Quoted 5 lines
Quoted 2 lines

This one, in vcpu_destroy_pagetables(). I'm afraid I overlooked this when adding the preemption capability here.

OK. Would this RFC patch be OK? (I can send it off as normal - just want to make sure you are OK with this being put there)

Conceptually yes, but there are issues:

Quoted 5 lines

From 1558a9870f438df949a8ad09a27825bd35a9f4ea Mon Sep 17 00:00:00 2001
From: Konrad Rzeszutek Wilk <[email protected]>
Date: Thu, 22 Jan 2015 11:34:21 -0500
Subject: [PATCH] domain: In vcpu_destroy_pagetables we can return -EINTR
instead of -EAGAIN

Quoted 3 lines

You should stop sending such conversions to EAGAIN. We switched to ERESTART, and you (just guessing) taking the patch from an older Xen version shouldn't result in this recurring mistake.

Nah, Andrew said in his email EAGAIN so that is what I picked.

Quoted 7 lines
Quoted 7 lines
xen/arch/x86/mm.c +0 -0
@@ -2677,6 +2677,9 @@ int vcpu_destroy_pagetables(struct vcpu *v)
 
     v->arch.cr3 = 0;
 
Quoted 8 lines

xen/arch/x86/mm.c int vcpu_destroy_pagetables(struct vcpu *v) · line 2682

Quoted 3 lines
xen/arch/x86/mm.c +3 -0
+    if ( rc == -EINTR )
+        rc = -EAGAIN;
+

Either (my preference) you attach this directly to the two put_page_and_type_preemptible() invocations, or you add a comment here explaining that this catches those two specific cases in one central place. This is because while right now only

I will add explanation. The other users of put_page_.. all have catch the -EINTR and do the conversion.

Quoted 9 lines

those two invocations can lead to rc being non-zero, there's nothing preventing other error generating code to be added to this function later on, and we shouldn't blindly convert -EINTR to some other error code, as that may lead to overlooking necessary conversions elsewhere (as happened while I made this function preemptible).

Jan

#8 lore raw
Quoted 27 lines · Konrad Rzeszutek Wilk
Quoted 26 lines · Jan Beulich
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 22.01.15 at 17:38, <[email protected]> wrote:
Quoted 13 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 21.01.15 at 22:27, <[email protected]> wrote:

As I was looking at some of the XSA I realized that the call-chain of:

domain_relinquish_resources
->vcpu_destroy_pagetables

     -> put_page_and_type_preemptible
        -> __put_page_type
		returns -EINTR

[...]
b). Or should the hypervisor convert the -EINTR to -ERESTART
(or -EAGAIN) - which most of the code (see users of get_page_type_preemptible) do right now?

Quoted 4 lines
Quoted 2 lines

This one, in vcpu_destroy_pagetables(). I'm afraid I overlooked this when adding the preemption capability here.

OK. Would this RFC patch be OK? (I can send it off as normal - just want to make sure you are OK with this being put there)

Conceptually yes, but there are issues:

Quoted 5 lines

From 1558a9870f438df949a8ad09a27825bd35a9f4ea Mon Sep 17 00:00:00 2001
From: Konrad Rzeszutek Wilk <[email protected]>
Date: Thu, 22 Jan 2015 11:34:21 -0500
Subject: [PATCH] domain: In vcpu_destroy_pagetables we can return -EINTR
instead of -EAGAIN

Quoted 4 lines
Quoted 3 lines

You should stop sending such conversions to EAGAIN. We switched to ERESTART, and you (just guessing) taking the patch from an older Xen version shouldn't result in this recurring mistake.

Nah, Andrew said in his email EAGAIN so that is what I picked.

EAGAIN was correct for the domain_destroy hypercall, at this hypercall explicitly has continuation built into its API via EAGAIN.

However, you patched a more generic path which affects callers, and is therefore incomplete. I am sorry if I did not explain this very well.

~Andrew

#9 lore raw
Quoted 29 lines
Quoted 1 line
Quoted 1 line · On 23.01.15 at 15:46, <[email protected]> wrote:
Quoted 27 lines · Konrad Rzeszutek Wilk
Quoted 26 lines · Jan Beulich
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 22.01.15 at 17:38, <[email protected]> wrote:
Quoted 13 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 21.01.15 at 22:27, <[email protected]> wrote:

As I was looking at some of the XSA I realized that the call-chain of:

domain_relinquish_resources
->vcpu_destroy_pagetables

     -> put_page_and_type_preemptible
        -> __put_page_type
		returns -EINTR

[...]
b). Or should the hypervisor convert the -EINTR to -ERESTART
(or -EAGAIN) - which most of the code (see users of get_page_type_preemptible) do right now?

Quoted 4 lines
Quoted 2 lines

This one, in vcpu_destroy_pagetables(). I'm afraid I overlooked this when adding the preemption capability here.

OK. Would this RFC patch be OK? (I can send it off as normal - just want to make sure you are OK with this being put there)

Conceptually yes, but there are issues:

Quoted 5 lines

From 1558a9870f438df949a8ad09a27825bd35a9f4ea Mon Sep 17 00:00:00 2001
From: Konrad Rzeszutek Wilk <[email protected]>
Date: Thu, 22 Jan 2015 11:34:21 -0500
Subject: [PATCH] domain: In vcpu_destroy_pagetables we can return -EINTR
instead of -EAGAIN

Quoted 7 lines
Quoted 4 lines
Quoted 3 lines

You should stop sending such conversions to EAGAIN. We switched to ERESTART, and you (just guessing) taking the patch from an older Xen version shouldn't result in this recurring mistake.

Nah, Andrew said in his email EAGAIN so that is what I picked.

EAGAIN was correct for the domain_destroy hypercall, at this hypercall explicitly has continuation built into its API via EAGAIN.

Ouch - I based the comment on code resulting from a patch I didn't send out yet (largely because Konrad indicated issues with XEN_DOMCTL_destroydomain that I'd need to look into in more detail before doing so), doing away with the tool stack based continuations. Yet based on what domain_kill() does with domain_relinquish_resources()'s return value, it should nevertheless be -ERESTART here to ease future changes.

Jan

#10 lore raw
Quoted 37 lines · Jan Beulich
Quoted 29 lines
Quoted 1 line
Quoted 1 line · On 23.01.15 at 15:46, <[email protected]> wrote:
Quoted 27 lines · Konrad Rzeszutek Wilk
Quoted 26 lines · Jan Beulich
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 22.01.15 at 17:38, <[email protected]> wrote:
Quoted 13 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 21.01.15 at 22:27, <[email protected]> wrote:

As I was looking at some of the XSA I realized that the call-chain of:

domain_relinquish_resources
->vcpu_destroy_pagetables

     -> put_page_and_type_preemptible
        -> __put_page_type
		returns -EINTR

[...]
b). Or should the hypervisor convert the -EINTR to -ERESTART
(or -EAGAIN) - which most of the code (see users of get_page_type_preemptible) do right now?

Quoted 4 lines
Quoted 2 lines

This one, in vcpu_destroy_pagetables(). I'm afraid I overlooked this when adding the preemption capability here.

OK. Would this RFC patch be OK? (I can send it off as normal - just want to make sure you are OK with this being put there)

Conceptually yes, but there are issues:

Quoted 5 lines

From 1558a9870f438df949a8ad09a27825bd35a9f4ea Mon Sep 17 00:00:00 2001
From: Konrad Rzeszutek Wilk <[email protected]>
Date: Thu, 22 Jan 2015 11:34:21 -0500
Subject: [PATCH] domain: In vcpu_destroy_pagetables we can return -EINTR
instead of -EAGAIN

Quoted 7 lines
Quoted 4 lines
Quoted 3 lines

You should stop sending such conversions to EAGAIN. We switched to ERESTART, and you (just guessing) taking the patch from an older Xen version shouldn't result in this recurring mistake.

Nah, Andrew said in his email EAGAIN so that is what I picked.

EAGAIN was correct for the domain_destroy hypercall, at this hypercall explicitly has continuation built into its API via EAGAIN.

Quoted 7 lines

Ouch - I based the comment on code resulting from a patch I didn't send out yet (largely because Konrad indicated issues with XEN_DOMCTL_destroydomain that I'd need to look into in more detail before doing so), doing away with the tool stack based continuations. Yet based on what domain_kill() does with domain_relinquish_resources()'s return value, it should nevertheless be -ERESTART here to ease future changes.

OK :-)

Quoted 1 line

From ac642805a96261f518fbba7d47f3ca38c950b3c8 Mon Sep 17 00:00:00 2001

From: Konrad Rzeszutek Wilk <[email protected]>
Date: Thu, 22 Jan 2015 11:34:21 -0500
Subject: [PATCH] domain: In vcpu_destroy_pagetables we can return -ERESTART
instead of -EINTR

which has the side effect that domain_relinquish_resources will stop and return to user-space -EINTR - which it is not equipped to deal with. The preemption mechanism we have to domain destruction is to return -EAGAIN and as such we need to catch the case of:

domain_relinquish_resources
->vcpu_destroy_pagetables

    -> put_page_and_type_preemptible
       -> __put_page_type
           returns -EINTR

and convert it to the proper type.

---
v2: Add comment and s/ERESTART/EAGAIN/

---
 xen/arch/x86/mm.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
xen/arch/x86/mm.c +10 -0
index 6e9c2c0..5452c01 100644
@@ -2677,6 +2677,16 @@ int vcpu_destroy_pagetables(struct vcpu *v)
 
     v->arch.cr3 = 0;
 
+    /*
+     * The put_page_and_type_preemptible is liable to return -EINTR. Other
+     * callers of it filter the -EINTR to whatever they deem applicable - in
+     * this case we MUST do it as the caller of this function will return the
+     * error code to userspace. And userspace for domain destruction expects
+     * -EAGAIN (domain_relinquish_resources converts ERESTART to -EAGAIN).
+     */
+    if ( rc == -EINTR )
+        rc = -ERESTART;
+
     return rc;
 }
 
Signature · 1 line
2.1.0
#11 lore raw
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 23.01.15 at 16:46, <[email protected]> wrote:

Subject: [PATCH] domain: In vcpu_destroy_pagetables we can return -ERESTART
instead of -EINTR

which has the side effect that domain_relinquish_resources will stop and return to user-space -EINTR - which it is not equipped to deal with.

The title read wrong, especially on its own, as it appears to state the inverse thing of what you do in the patch. Perhaps

x86: vcpu_destroy_pagetables() must not return -EINTR

with the initial part of the description adjusted accordingly?

xen/arch/x86/mm.c int vcpu_destroy_pagetables(struct vcpu *v) · line 2686

Quoted 7 lines
xen/arch/x86/mm.c +7 -0
+    /*
+     * The put_page_and_type_preemptible is liable to return -EINTR. Other
+     * callers of it filter the -EINTR to whatever they deem applicable - in
+     * this case we MUST do it as the caller of this function will return the
+     * error code to userspace. And userspace for domain destruction expects
+     * -EAGAIN (domain_relinquish_resources converts ERESTART to -EAGAIN).
+     */

This is still misleading, as it kind of implies that the function has only that one caller. Don't talk about domain_relinquish_resources() and EAGAIN at all.

Jan

#12 lore raw
Quoted 22 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 23.01.15 at 16:46, <[email protected]> wrote:

Subject: [PATCH] domain: In vcpu_destroy_pagetables we can return -ERESTART
instead of -EINTR

which has the side effect that domain_relinquish_resources will stop and return to user-space -EINTR - which it is not equipped to deal with.

The title read wrong, especially on its own, as it appears to state the inverse thing of what you do in the patch. Perhaps

x86: vcpu_destroy_pagetables() must not return -EINTR

with the initial part of the description adjusted accordingly?

Review

Quoted 7 lines
(quoted diff) +7 -0
+    /*
+     * The put_page_and_type_preemptible is liable to return -EINTR. Other
+     * callers of it filter the -EINTR to whatever they deem applicable - in
+     * this case we MUST do it as the caller of this function will return the
+     * error code to userspace. And userspace for domain destruction expects
+     * -EAGAIN (domain_relinquish_resources converts ERESTART to -EAGAIN).
+     */
Quoted 3 lines

This is still misleading, as it kind of implies that the function has only that one caller. Don't talk about domain_relinquish_resources() and EAGAIN at all.

Right. I somehow managed to miss the other caller of vcpu_destroy_pagetables.

Please see following patch:

Quoted 1 line

From 3ace309c61805bae546378e37553913231e43cec Mon Sep 17 00:00:00 2001

From: Konrad Rzeszutek Wilk <[email protected]>
Date: Thu, 22 Jan 2015 11:34:21 -0500
Subject: [PATCH] domain: vcpu_destroy_pagetables() must not return -EINTR

.. otherwise it has the side effect that: domain_relinquish_resources will stop and will return to user-space with -EINTR which it is not equipped to deal with that error code; or vcpu_reset - which will ignore it and convert the error to -ENOMEM..

The preemption mechanism we have for domain destruction is to return -EAGAIN (and then user-space calls the hypercall again) and as such we need to catch the case of:

domain_relinquish_resources
->vcpu_destroy_pagetables

    -> put_page_and_type_preemptible
       -> __put_page_type
           returns -EINTR

and convert it to the proper type. For:

XEN_DOMCTL_setvcpucontext
-> vcpu_reset
-> vcpu_destroy_pagetables

we need to return -ERESTART otherwise we end up returning -ENOMEM.

There are also other callers of vcpu_destroy_pagetables: arch_vcpu_reset (vcpu_reset) are:
- hvm_s3_suspend (asserts on any return code),
- vlapic_init_sipi_one (asserts on any return code),

---
v2: Add comment and s/ERESTART/EAGAIN/
v3: Also include the hypercall.

---
 xen/arch/x86/mm.c | 7 +++++++
 1 file changed, 7 insertions(+)
xen/arch/x86/mm.c +7 -0
index 6e9c2c0..badbeab 100644
@@ -2677,6 +2677,13 @@ int vcpu_destroy_pagetables(struct vcpu *v)
 
     v->arch.cr3 = 0;
 
+    /*
+     * The put_page_and_type_preemptible is liable to return -EINTR. The
+     * callers of us expect -ERESTART so convert it over.
+     */
+    if ( rc == -EINTR )
+        rc = -ERESTART;
+
     return rc;
 }
 
Signature · 1 line
2.1.0
Quoted 3 lines

Jan

#13 lore raw
Quoted 24 lines
Quoted 1 line
Quoted 1 line · On 23.01.15 at 18:21, <[email protected]> wrote:
Quoted 22 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 23.01.15 at 16:46, <[email protected]> wrote:

Subject: [PATCH] domain: In vcpu_destroy_pagetables we can return -ERESTART
instead of -EINTR

which has the side effect that domain_relinquish_resources will stop and return to user-space -EINTR - which it is not equipped to deal with.

The title read wrong, especially on its own, as it appears to state the inverse thing of what you do in the patch. Perhaps

x86: vcpu_destroy_pagetables() must not return -EINTR

with the initial part of the description adjusted accordingly?

Quoted 7 lines
(quoted diff) +7 -0
+    /*
+     * The put_page_and_type_preemptible is liable to return -EINTR. Other
+     * callers of it filter the -EINTR to whatever they deem applicable - in
+     * this case we MUST do it as the caller of this function will return the
+     * error code to userspace. And userspace for domain destruction expects
+     * -EAGAIN (domain_relinquish_resources converts ERESTART to -EAGAIN).
+     */
Quoted 8 lines
Quoted 3 lines

This is still misleading, as it kind of implies that the function has only that one caller. Don't talk about domain_relinquish_resources() and EAGAIN at all.

Right. I somehow managed to miss the other caller of vcpu_destroy_pagetables.

Please see following patch:

Looks good. I don't see a reason not to apply it without you doing a formal submission.

Jan