Skip to contentSkip to conversation

Migration bug added by commit 2df1aa01bef7366798248ac6d03cfb42048b003d

DISCUSSION Don Slutz 3 participants 10 messages Jun 27, 2015 – Jul 6, 2015

lore
Share & tools
lore

Don Slutz

author
#0 lore raw

commit 2df1aa01bef7366798248ac6d03cfb42048b003d

Author: Paul Durrant <[email protected]>
Date:   Tue Jun 23 18:07:49 2015 +0200

x86/hvm: remove hvm_io_pending() check in hvmemul_do_io()

...

-            rc = X86EMUL_RETRY;
-            if ( !hvm_send_assist_req(s, &p) )
+            rc = hvm_send_assist_req(s, &p);
+            if ( rc != X86EMUL_RETRY )

...
if ( unlikely(!vcpu_start_shutdown_deferral(curr)) )
- return 0; /* implicitly bins the i/o operation */
+ return X86EMUL_OKAY;

So now X86EMUL_OKAY is returned from hvmemul_do_io() during shutdown.

From Jan Beulich about this:

Re: [Xen-devel] [PATCH 3/5] hvmemul_do_io: If the send to the ioreq server failed do not retry.
<https://www.mail-archive.com/[email protected]&q=subject:%22Re%5C%3A+%5C%5BXen%5C-devel%5C%5D+%5C%5BPATCH+3%5C%2F5%5C%5D+hvmemul_do_io%5C%3A+If+the+send+to+the+ioreq+server+failed+do+not+retry.%22&o=newest>

Jan Beulich <https://www.mail-archive.com/[email protected]&q=from:%22Jan+Beulich%22> Fri, 30 Jan 2015 02:24:55 -0800 <https://www.mail-archive.com/[email protected]&q=date:20150130>

Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 30.01.15 at 01:52, <[email protected]> wrote:

I.E. do just what no backing DM does.

_If_ this is correct, the if() modified here should be folded with the one a few lines up. But looking at the description of the commit that introduced this (bac0999325 "x86 hvm: Do not incorrectly retire an instruction emulation...", almost immediately modified by f20f3c8ece "x86 hvm: On failed hvm_send_assist_req(), io emulation...") I doubt this is really what we want, or at the very least your change description should explain what was wrong with the original commit.

Jan

going up the call stack:

in handle_pio when hvmemul_do_pio_buffer() returns X86EMUL_OKAY, it returns 1.

svm_vmexit_handler 2578 if ( handle_pio(port, bytes, dir) )
or
vmx_vmexit_handler 3178 if ( handle_pio(port, bytes, dir) )

both update the IP in this case which is wrong during shutdown.

So I think:

            rc = hvm_send_assist_req(s, &p);
            if ( rc != X86EMUL_RETRY )
                 vio->io_state = HVMIO_none;

needs to change to:

                rc = hvm_send_assist_req(s, &p);
                if ( rc != X86EMUL_RETRY )
                {
                    vio->io_state = HVMIO_none;
                    if ( rc == X86EMUL_OKAY )
                        rc = X86EMUL_RETRY;
                }

-Don Slutz

#1 lore raw
Quoted 64 lines

-----Original Message-----
From: Don Slutz [mailto:[email protected]]
Sent: 27 June 2015 22:02
To: [email protected]; Paul Durrant; Jan Beulich
Subject: Migration bug added by commit 2df1aa01bef7366798248ac6d03cfb42048b003d

commit 2df1aa01bef7366798248ac6d03cfb42048b003d

Author: Paul Durrant <[email protected]>
Date:   Tue Jun 23 18:07:49 2015 +0200

x86/hvm: remove hvm_io_pending() check in hvmemul_do_io()

...

(quoted diff) +3 -3
-            rc = X86EMUL_RETRY;
-            if ( !hvm_send_assist_req(s, &p) )
+            rc = hvm_send_assist_req(s, &p);
+            if ( rc != X86EMUL_RETRY )
...
      if ( unlikely(!vcpu_start_shutdown_deferral(curr)) )
-        return 0; /* implicitly bins the i/o operation */
+        return X86EMUL_OKAY;

So now X86EMUL_OKAY is returned from hvmemul_do_io() during shutdown.

From Jan Beulich about this:

Re: [Xen-devel] [PATCH 3/5] hvmemul_do_io: If the send to the ioreq server failed do not retry.
<https://www.mail-archive.com/search?l=xen-
[email protected]&q=subject:%22Re%5C%3A+%5C%5BXen%5C- devel%5C%5D+%5C%5BPATCH+3%5C%2F5%5C%5D+hvmemul_do_io%5C%3 A+If+the+send+to+the+ioreq+server+failed+do+not+retry.%22&o=newest

Quoted 1 line

Jan Beulich
<https://www.mail-archive.com/search?l=xen-
[email protected]&q=from:%22Jan+Beulich%22>
Fri, 30 Jan 2015 02:24:55 -0800
<https://www.mail-archive.com/search?l=xen-
[email protected]&q=date:20150130>

Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 30.01.15 at 01:52, <[email protected]> wrote:

I.E. do just what no backing DM does.

_If_ this is correct, the if() modified here should be folded with the one a few lines up. But looking at the description of the commit that introduced this (bac0999325 "x86 hvm: Do not incorrectly retire an instruction emulation...", almost immediately modified by f20f3c8ece "x86 hvm: On failed hvm_send_assist_req(), io emulation...") I doubt this is really what we want, or at the very least your change description should explain what was wrong with the original commit.

Jan

going up the call stack:

Quoted 9 lines

in handle_pio when hvmemul_do_pio_buffer() returns X86EMUL_OKAY, it returns 1.

svm_vmexit_handler 2578 if ( handle_pio(port, bytes, dir) )
or
vmx_vmexit_handler 3178 if ( handle_pio(port, bytes, dir) )

both update the IP in this case which is wrong during shutdown.

If this is indeed the problem then it seems to me that the correct fix is to add a check in handle_pio() and return 0 if the cpu is shutting down.

Paul

Quoted 18 lines

So I think:

             rc = hvm_send_assist_req(s, &p);
             if ( rc != X86EMUL_RETRY )
                  vio->io_state = HVMIO_none;

needs to change to:

                 rc = hvm_send_assist_req(s, &p);
                 if ( rc != X86EMUL_RETRY )
                 {
                     vio->io_state = HVMIO_none;
                     if ( rc == X86EMUL_OKAY )
                         rc = X86EMUL_RETRY;
                 }


    -Don Slutz
#2 lore raw
Quoted 81 lines

-----Original Message-----
From: [email protected] [mailto:xen-devel- [email protected]] On Behalf Of Paul Durrant
Sent: 29 June 2015 10:42
To: Don Slutz; [email protected]; Jan Beulich
Subject: Re: [Xen-devel] Migration bug added by commit 2df1aa01bef7366798248ac6d03cfb42048b003d

Quoted 26 lines

-----Original Message-----
From: Don Slutz [mailto:[email protected]]
Sent: 27 June 2015 22:02
To: [email protected]; Paul Durrant; Jan Beulich
Subject: Migration bug added by commit 2df1aa01bef7366798248ac6d03cfb42048b003d

commit 2df1aa01bef7366798248ac6d03cfb42048b003d

Author: Paul Durrant <[email protected]>
Date:   Tue Jun 23 18:07:49 2015 +0200

x86/hvm: remove hvm_io_pending() check in hvmemul_do_io()

...

(quoted diff) +3 -3
-            rc = X86EMUL_RETRY;
-            if ( !hvm_send_assist_req(s, &p) )
+            rc = hvm_send_assist_req(s, &p);
+            if ( rc != X86EMUL_RETRY )
...
      if ( unlikely(!vcpu_start_shutdown_deferral(curr)) )
-        return 0; /* implicitly bins the i/o operation */
+        return X86EMUL_OKAY;

So now X86EMUL_OKAY is returned from hvmemul_do_io() during shutdown.

Quoted 8 lines

From Jan Beulich about this:

Re: [Xen-devel] [PATCH 3/5] hvmemul_do_io: If the send to the ioreq server failed do not retry.
<https://www.mail-archive.com/search?l=xen-
[email protected]&q=subject:%22Re%5C%3A+%5C%5BXen%5C-

devel%5C%5D+%5C%5BPATCH+3%5C%2F5%5C%5D+hvmemul_do_io%5C%3

Quoted 1 line

A+If+the+send+to+the+ioreq+server+failed+do+not+retry.%22&o=newest

Quoted 36 lines
Quoted 1 line

Jan Beulich
<https://www.mail-archive.com/search?l=xen-
[email protected]&q=from:%22Jan+Beulich%22>
Fri, 30 Jan 2015 02:24:55 -0800
<https://www.mail-archive.com/search?l=xen-
[email protected]&q=date:20150130>

Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 30.01.15 at 01:52, <[email protected]> wrote:

I.E. do just what no backing DM does.

_If_ this is correct, the if() modified here should be folded with the one a few lines up. But looking at the description of the commit that introduced this (bac0999325 "x86 hvm: Do not incorrectly retire an instruction emulation...", almost immediately modified by f20f3c8ece "x86 hvm: On failed hvm_send_assist_req(), io emulation...") I doubt this is really what we want, or at the very least your change description should explain what was wrong with the original commit.

Jan

going up the call stack:

in handle_pio when hvmemul_do_pio_buffer() returns X86EMUL_OKAY, it returns 1.

svm_vmexit_handler 2578 if ( handle_pio(port, bytes, dir) )
or
vmx_vmexit_handler 3178 if ( handle_pio(port, bytes, dir) )

Quoted 6 lines
Quoted 2 lines

both update the IP in this case which is wrong during shutdown.

If this is indeed the problem then it seems to me that the correct fix is to add a check in handle_pio() and return 0 if the cpu is shutting down.

Actually, with some more thought, it sounds like we essentially want to unwind the I/O emulation if we're shutting down and I think this could be achieved by having hvm_send_assist_req() return X86EMUL_RETRY if it hits the shutdown deferral case, having hvm_emul_do_io() reset the emulation state back to 'none' if the domain is shutting down, and then having handle_pio() return 0 if sees X86EMUL_RETRY without any form of completion being requested.

Paul

Quoted 24 lines

Paul

Quoted 8 lines

So I think:

             rc = hvm_send_assist_req(s, &p);
             if ( rc != X86EMUL_RETRY )
                  vio->io_state = HVMIO_none;

needs to change to:

Quoted 10 lines
                 rc = hvm_send_assist_req(s, &p);
                 if ( rc != X86EMUL_RETRY )
                 {
                     vio->io_state = HVMIO_none;
                     if ( rc == X86EMUL_OKAY )
                         rc = X86EMUL_RETRY;
                 }


    -Don Slutz

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

#3 lore raw
Quoted 99 lines

-----Original Message-----
From: Paul Durrant
Sent: 29 June 2015 13:54
To: Paul Durrant; Don Slutz; [email protected]; Jan Beulich
Subject: RE: [Xen-devel] Migration bug added by commit 2df1aa01bef7366798248ac6d03cfb42048b003d

Quoted 43 lines

-----Original Message-----
From: [email protected] [mailto:xen-devel- [email protected]] On Behalf Of Paul Durrant
Sent: 29 June 2015 10:42
To: Don Slutz; [email protected]; Jan Beulich
Subject: Re: [Xen-devel] Migration bug added by commit 2df1aa01bef7366798248ac6d03cfb42048b003d

Quoted 34 lines

-----Original Message-----
From: Don Slutz [mailto:[email protected]]
Sent: 27 June 2015 22:02
To: [email protected]; Paul Durrant; Jan Beulich
Subject: Migration bug added by commit 2df1aa01bef7366798248ac6d03cfb42048b003d

commit 2df1aa01bef7366798248ac6d03cfb42048b003d

Author: Paul Durrant <[email protected]>
Date:   Tue Jun 23 18:07:49 2015 +0200

x86/hvm: remove hvm_io_pending() check in hvmemul_do_io()

...

(quoted diff) +3 -3
-            rc = X86EMUL_RETRY;
-            if ( !hvm_send_assist_req(s, &p) )
+            rc = hvm_send_assist_req(s, &p);
+            if ( rc != X86EMUL_RETRY )
...
      if ( unlikely(!vcpu_start_shutdown_deferral(curr)) )
-        return 0; /* implicitly bins the i/o operation */
+        return X86EMUL_OKAY;

So now X86EMUL_OKAY is returned from hvmemul_do_io() during shutdown.

From Jan Beulich about this:

Re: [Xen-devel] [PATCH 3/5] hvmemul_do_io: If the send to the ioreq server failed do not retry.
<https://www.mail-archive.com/search?l=xen-
[email protected]&q=subject:%22Re%5C%3A+%5C%5BXen%5C-

devel%5C%5D+%5C%5BPATCH+3%5C%2F5%5C%5D+hvmemul_do_io%5C%3

Quoted 2 lines
Quoted 1 line

A+If+the+send+to+the+ioreq+server+failed+do+not+retry.%22&o=newest

Quoted 23 lines
Quoted 23 lines
Quoted 1 line

Jan Beulich
<https://www.mail-archive.com/search?l=xen-
[email protected]&q=from:%22Jan+Beulich%22>
Fri, 30 Jan 2015 02:24:55 -0800
<https://www.mail-archive.com/search?l=xen-
[email protected]&q=date:20150130>

Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 30.01.15 at 01:52, <[email protected]> wrote:

I.E. do just what no backing DM does.

_If_ this is correct, the if() modified here should be folded with the one a few lines up. But looking at the description of the commit that introduced this (bac0999325 "x86 hvm: Do not incorrectly retire an instruction emulation...", almost immediately modified by f20f3c8ece "x86 hvm: On failed hvm_send_assist_req(), io emulation...") I doubt this is really what we want, or at the very least your change description should explain what was wrong with the original commit.

Quoted 7 lines
Quoted 7 lines

Jan

going up the call stack:

in handle_pio when hvmemul_do_pio_buffer() returns X86EMUL_OKAY,

it

Quoted 10 lines
Quoted 8 lines

returns 1.

svm_vmexit_handler 2578 if ( handle_pio(port, bytes, dir) )
or
vmx_vmexit_handler 3178 if ( handle_pio(port, bytes, dir) )

both update the IP in this case which is wrong during shutdown.

If this is indeed the problem then it seems to me that the correct fix is to

add

Quoted 2 lines

a check in handle_pio() and return 0 if the cpu is shutting down.

Quoted 8 lines

Actually, with some more thought, it sounds like we essentially want to unwind the I/O emulation if we're shutting down and I think this could be achieved by having hvm_send_assist_req() return X86EMUL_RETRY if it hits the shutdown deferral case, having hvm_emul_do_io() reset the emulation state back to 'none' if the domain is shutting down, and then having handle_pio() return 0 if sees X86EMUL_RETRY without any form of completion being requested.

I think this patch should do it for now:

xen/arch/x86/hvm/emulate.c +1 -1
index a4d7225..cc6130c 100644
@@ -183,7 +183,7 @@ static int hvmemul_do_io(
         else
         {
             rc = hvm_send_assist_req(s, &p);
-            if ( rc != X86EMUL_RETRY )
+            if ( rc != X86EMUL_RETRY || curr->domain->is_shutting_down )
                 vio->io_state = HVMIO_none;
             else if ( data_is_addr || dir == IOREQ_WRITE )
                 rc = X86EMUL_OKAY;
xen/arch/x86/hvm/hvm.c +1 -1
index 8226d8c..aba4ef6 100644
@@ -2547,7 +2547,7 @@ int hvm_send_assist_req(struct hvm_ioreq_server *s, ioreq_t *proto_p)
 
     ASSERT(s);
     if ( unlikely(!vcpu_start_shutdown_deferral(curr)) )
-        return X86EMUL_OKAY;
+        return X86EMUL_RETRY;
 
     list_for_each_entry ( sv,
                           &s->ioreq_vcpu_list,
Quoted 26 lines

Paul

Quoted 24 lines

Paul

Quoted 8 lines

So I think:

             rc = hvm_send_assist_req(s, &p);
             if ( rc != X86EMUL_RETRY )
                  vio->io_state = HVMIO_none;

needs to change to:

Quoted 10 lines
                 rc = hvm_send_assist_req(s, &p);
                 if ( rc != X86EMUL_RETRY )
                 {
                     vio->io_state = HVMIO_none;
                     if ( rc == X86EMUL_OKAY )
                         rc = X86EMUL_RETRY;
                 }


    -Don Slutz

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

author
#4 lore raw
Quoted 106 lines · Paul Durrant
Quoted 91 lines

-----Original Message-----
From: Paul Durrant
Sent: 29 June 2015 13:54
To: Paul Durrant; Don Slutz; [email protected]; Jan Beulich
Subject: RE: [Xen-devel] Migration bug added by commit 2df1aa01bef7366798248ac6d03cfb42048b003d

Quoted 42 lines

-----Original Message-----
From: [email protected] [mailto:xen-devel- [email protected]] On Behalf Of Paul Durrant
Sent: 29 June 2015 10:42
To: Don Slutz; [email protected]; Jan Beulich
Subject: Re: [Xen-devel] Migration bug added by commit 2df1aa01bef7366798248ac6d03cfb42048b003d

Quoted 34 lines

-----Original Message-----
From: Don Slutz [mailto:[email protected]]
Sent: 27 June 2015 22:02
To: [email protected]; Paul Durrant; Jan Beulich
Subject: Migration bug added by commit 2df1aa01bef7366798248ac6d03cfb42048b003d

commit 2df1aa01bef7366798248ac6d03cfb42048b003d

Author: Paul Durrant <[email protected]>
Date:   Tue Jun 23 18:07:49 2015 +0200

x86/hvm: remove hvm_io_pending() check in hvmemul_do_io()

...

(quoted diff) +3 -3
-            rc = X86EMUL_RETRY;
-            if ( !hvm_send_assist_req(s, &p) )
+            rc = hvm_send_assist_req(s, &p);
+            if ( rc != X86EMUL_RETRY )
...
       if ( unlikely(!vcpu_start_shutdown_deferral(curr)) )
-        return 0; /* implicitly bins the i/o operation */
+        return X86EMUL_OKAY;

So now X86EMUL_OKAY is returned from hvmemul_do_io() during shutdown.

From Jan Beulich about this:

Re: [Xen-devel] [PATCH 3/5] hvmemul_do_io: If the send to the ioreq server failed do not retry.
<https://www.mail-archive.com/search?l=xen-
[email protected]&q=subject:%22Re%5C%3A+%5C%5BXen%5C-

devel%5C%5D+%5C%5BPATCH+3%5C%2F5%5C%5D+hvmemul_do_io%5C%3 A+If+the+send+to+the+ioreq+server+failed+do+not+retry.%22&o=newest

Quoted 20 lines
Quoted 20 lines

Jan Beulich
<https://www.mail-archive.com/search?l=xen-
[email protected]&q=from:%22Jan+Beulich%22>
Fri, 30 Jan 2015 02:24:55 -0800
<https://www.mail-archive.com/search?l=xen-
[email protected]&q=date:20150130>

Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 30.01.15 at 01:52, <[email protected]> wrote:

I.E. do just what no backing DM does.

_If_ this is correct, the if() modified here should be folded with the one a few lines up. But looking at the description of the commit that introduced this (bac0999325 "x86 hvm: Do not incorrectly retire an instruction emulation...", almost immediately modified by f20f3c8ece "x86 hvm: On failed hvm_send_assist_req(), io emulation...") I doubt this is really what we want, or at the very least your change description should explain what was wrong with the original commit.

Quoted 7 lines
Quoted 7 lines

Jan

going up the call stack:

in handle_pio when hvmemul_do_pio_buffer() returns X86EMUL_OKAY,

it

Quoted 9 lines
Quoted 8 lines

returns 1.

svm_vmexit_handler 2578 if ( handle_pio(port, bytes, dir) )
or
vmx_vmexit_handler 3178 if ( handle_pio(port, bytes, dir) )

both update the IP in this case which is wrong during shutdown.

If this is indeed the problem then it seems to me that the correct fix is to

add

Quoted 2 lines

a check in handle_pio() and return 0 if the cpu is shutting down.

Quoted 8 lines

Actually, with some more thought, it sounds like we essentially want to unwind the I/O emulation if we're shutting down and I think this could be achieved by having hvm_send_assist_req() return X86EMUL_RETRY if it hits the shutdown deferral case, having hvm_emul_do_io() reset the emulation state back to 'none' if the domain is shutting down, and then having handle_pio() return 0 if sees X86EMUL_RETRY without any form of completion being requested.

I think this patch should do it for now:

xen/arch/x86/hvm/emulate.c +0 -0
index a4d7225..cc6130c 100644

xen/arch/x86/hvm/emulate.c static int hvmemul_do_io( · line 186

Quoted 5 lines
xen/arch/x86/hvm/emulate.c +1 -1
@@ -183,7 +183,7 @@ static int hvmemul_do_io(
          else
          {
              rc = hvm_send_assist_req(s, &p);
-            if ( rc != X86EMUL_RETRY )
+            if ( rc != X86EMUL_RETRY || curr->domain->is_shutting_down )

I do not know enough about "is_shutting_down" to agree. What is clear is that this test is not the same as "!vcpu_start_shutdown_deferral(curr)".

-Don Slutz

Quoted 43 lines
xen/arch/x86/hvm/emulate.c +0 -0
                  vio->io_state = HVMIO_none;
              else if ( data_is_addr || dir == IOREQ_WRITE )
                  rc = X86EMUL_OKAY;
xen/arch/x86/hvm/hvm.c +1 -1
index 8226d8c..aba4ef6 100644
@@ -2547,7 +2547,7 @@ int hvm_send_assist_req(struct hvm_ioreq_server *s, ioreq_t *proto_p)
 
      ASSERT(s);
      if ( unlikely(!vcpu_start_shutdown_deferral(curr)) )
-        return X86EMUL_OKAY;
+        return X86EMUL_RETRY;
 
      list_for_each_entry ( sv,
                            &s->ioreq_vcpu_list,
Quoted 27 lines

Paul

Quoted 24 lines

Paul

Quoted 8 lines

So I think:

              rc = hvm_send_assist_req(s, &p);
              if ( rc != X86EMUL_RETRY )
                   vio->io_state = HVMIO_none;

needs to change to:

Quoted 10 lines
                  rc = hvm_send_assist_req(s, &p);
                  if ( rc != X86EMUL_RETRY )
                  {
                      vio->io_state = HVMIO_none;
                      if ( rc == X86EMUL_OKAY )
                          rc = X86EMUL_RETRY;
                  }


     -Don Slutz

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

#5 lore raw
Quoted 114 lines

-----Original Message-----
From: Don Slutz [mailto:[email protected]]
Sent: 29 June 2015 16:14
To: Paul Durrant; [email protected]; Jan Beulich
Subject: Re: [Xen-devel] Migration bug added by commit 2df1aa01bef7366798248ac6d03cfb42048b003d

Quoted 44 lines · Paul Durrant
Quoted 44 lines

-----Original Message-----
From: Paul Durrant
Sent: 29 June 2015 13:54
To: Paul Durrant; Don Slutz; [email protected]; Jan Beulich
Subject: RE: [Xen-devel] Migration bug added by commit 2df1aa01bef7366798248ac6d03cfb42048b003d

Quoted 37 lines

-----Original Message-----
From: [email protected] [mailto:xen-devel- [email protected]] On Behalf Of Paul Durrant
Sent: 29 June 2015 10:42
To: Don Slutz; [email protected]; Jan Beulich
Subject: Re: [Xen-devel] Migration bug added by commit 2df1aa01bef7366798248ac6d03cfb42048b003d

Quoted 29 lines

-----Original Message-----
From: Don Slutz [mailto:[email protected]]
Sent: 27 June 2015 22:02
To: [email protected]; Paul Durrant; Jan Beulich
Subject: Migration bug added by commit 2df1aa01bef7366798248ac6d03cfb42048b003d

commit 2df1aa01bef7366798248ac6d03cfb42048b003d

Author: Paul Durrant <[email protected]>
Date:   Tue Jun 23 18:07:49 2015 +0200

x86/hvm: remove hvm_io_pending() check in hvmemul_do_io()

...

(quoted diff) +3 -3
-            rc = X86EMUL_RETRY;
-            if ( !hvm_send_assist_req(s, &p) )
+            rc = hvm_send_assist_req(s, &p);
+            if ( rc != X86EMUL_RETRY )
...
       if ( unlikely(!vcpu_start_shutdown_deferral(curr)) )
-        return 0; /* implicitly bins the i/o operation */
+        return X86EMUL_OKAY;

So now X86EMUL_OKAY is returned from hvmemul_do_io() during shutdown.

From Jan Beulich about this:

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 5 lines

Re: [Xen-devel] [PATCH 3/5] hvmemul_do_io: If the send to the ioreq server failed do not retry.
<https://www.mail-archive.com/search?l=xen-
[email protected]&q=subject:%22Re%5C%3A+%5C%5BXen%5C-

devel%5C%5D+%5C%5BPATCH+3%5C%2F5%5C%5D+hvmemul_do_io%5C%3

Quoted 1 line
Quoted 1 line

A+If+the+send+to+the+ioreq+server+failed+do+not+retry.%22&o=newest

Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines

Jan Beulich
<https://www.mail-archive.com/search?l=xen-
[email protected]&q=from:%22Jan+Beulich%22>
Fri, 30 Jan 2015 02:24:55 -0800
<https://www.mail-archive.com/search?l=xen-
[email protected]&q=date:20150130>

Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 30.01.15 at 01:52, <[email protected]> wrote:

I.E. do just what no backing DM does.

_If_ this is correct, the if() modified here should be folded with the one a few lines up. But looking at the description of the commit that introduced this (bac0999325 "x86 hvm: Do not incorrectly retire an instruction emulation...", almost immediately modified by f20f3c8ece "x86 hvm: On failed hvm_send_assist_req(), io emulation...") I doubt this is really what we want, or at the very least your change description should explain what was wrong with the original commit.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Jan

going up the call stack:

in handle_pio when hvmemul_do_pio_buffer() returns

X86EMUL_OKAY,

Quoted 9 lines
Quoted 9 lines

it

Quoted 8 lines
Quoted 8 lines

returns 1.

svm_vmexit_handler 2578 if ( handle_pio(port, bytes, dir) )
or
vmx_vmexit_handler 3178 if ( handle_pio(port, bytes, dir) )

both update the IP in this case which is wrong during shutdown.

Quoted 7 lines
Quoted 7 lines
Quoted 1 line

If this is indeed the problem then it seems to me that the correct fix is to

add

Quoted 2 lines

a check in handle_pio() and return 0 if the cpu is shutting down.

Actually, with some more thought, it sounds like we essentially want to unwind the I/O emulation if we're shutting down and I think this could be achieved by having hvm_send_assist_req() return X86EMUL_RETRY if it

hits

Quoted 1 line
Quoted 1 line

the shutdown deferral case, having hvm_emul_do_io() reset the

emulation

Quoted 6 lines
Quoted 4 lines

state back to 'none' if the domain is shutting down, and then having handle_pio() return 0 if sees X86EMUL_RETRY without any form of completion being requested.

I think this patch should do it for now:

Quoted 15 lines

xen/arch/x86/hvm/emulate.c static int hvmemul_do_io( · line 186

Quoted 10 lines
xen/arch/x86/hvm/emulate.c +1 -1
index a4d7225..cc6130c 100644
@@ -183,7 +183,7 @@ static int hvmemul_do_io(
          else
          {
              rc = hvm_send_assist_req(s, &p);
-            if ( rc != X86EMUL_RETRY )
+            if ( rc != X86EMUL_RETRY || curr->domain->is_shutting_down )

I do not know enough about "is_shutting_down" to agree. What is clear is that
this test is not the same as "!vcpu_start_shutdown_deferral(curr)".

It pretty much is. If you look at the code for vcpu_start_shutdown_deferral() then you can see that it will only return 0 in the case that the domain's is_shutting_down flag is true.

Paul

Quoted 46 lines

-Don Slutz

xen/arch/x86/hvm/hvm.c int hvm_send_assist_req(struct

Quoted 8 lines
xen/arch/x86/hvm/emulate.c +0 -0
                  vio->io_state = HVMIO_none;
              else if ( data_is_addr || dir == IOREQ_WRITE )
                  rc = X86EMUL_OKAY;
xen/arch/x86/hvm/hvm.c +0 -0
index 8226d8c..aba4ef6 100644
@@ -2547,7 +2547,7 @@ int hvm_send_assist_req(struct

hvm_ioreq_server *s, ioreq_t *proto_p)

Quoted 35 lines
xen/arch/x86/hvm/hvm.c +1 -1
      ASSERT(s);
      if ( unlikely(!vcpu_start_shutdown_deferral(curr)) )
-        return X86EMUL_OKAY;
+        return X86EMUL_RETRY;
 
      list_for_each_entry ( sv,
                            &s->ioreq_vcpu_list,
 
Quoted 26 lines

Paul

Quoted 24 lines

Paul

Quoted 8 lines

So I think:

              rc = hvm_send_assist_req(s, &p);
              if ( rc != X86EMUL_RETRY )
                   vio->io_state = HVMIO_none;

needs to change to:

Quoted 10 lines
                  rc = hvm_send_assist_req(s, &p);
                  if ( rc != X86EMUL_RETRY )
                  {
                      vio->io_state = HVMIO_none;
                      if ( rc == X86EMUL_OKAY )
                          rc = X86EMUL_RETRY;
                  }


     -Don Slutz

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

#6 lore raw
In reply to Don Slutz
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 29.06.15 at 17:14, <[email protected]> wrote:
Quoted 2 lines · Paul Durrant

I think this patch should do it for now:

Quoted 14 lines

xen/arch/x86/hvm/emulate.c static int hvmemul_do_io( · line 186

Quoted 10 lines
xen/arch/x86/hvm/emulate.c +1 -1
index a4d7225..cc6130c 100644
@@ -183,7 +183,7 @@ static int hvmemul_do_io(
          else
          {
              rc = hvm_send_assist_req(s, &p);
-            if ( rc != X86EMUL_RETRY )
+            if ( rc != X86EMUL_RETRY || curr->domain->is_shutting_down )

I do not know enough about "is_shutting_down" to agree. What is clear is that
this test is not the same as "!vcpu_start_shutdown_deferral(curr)".

Together with Paul's reply the main question appears to have remained un-answered: Does the patch suggested by Paul address the problem you observed?

Jan

#7 lore raw
Quoted 27 lines

-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 06 July 2015 11:03
To: Don Slutz
Cc: Paul Durrant; [email protected]
Subject: Re: [Xen-devel] Migration bug added by commit 2df1aa01bef7366798248ac6d03cfb42048b003d

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 29.06.15 at 17:14, <[email protected]> wrote:
Quoted 2 lines · Paul Durrant

I think this patch should do it for now:

Quoted 14 lines

xen/arch/x86/hvm/emulate.c static int hvmemul_do_io( · line 186

Quoted 10 lines
xen/arch/x86/hvm/emulate.c +1 -1
index a4d7225..cc6130c 100644
@@ -183,7 +183,7 @@ static int hvmemul_do_io(
          else
          {
              rc = hvm_send_assist_req(s, &p);
-            if ( rc != X86EMUL_RETRY )
+            if ( rc != X86EMUL_RETRY || curr->domain->is_shutting_down )

I do not know enough about "is_shutting_down" to agree. What is clear is that
this test is not the same as "!vcpu_start_shutdown_deferral(curr)".

Quoted 4 lines

Together with Paul's reply the main question appears to have remained un-answered: Does the patch suggested by Paul address the problem you observed?

I can at least say that the patch definitely resolved a regression seen in automated testing of migration of Windows Server 2003 VMs on XenServer.

Paul

Quoted 1 line

Jan

#8 lore raw
Quoted 28 lines
Quoted 28 lines
Quoted 1 line · On 06.07.15 at 12:08, <[email protected]> wrote:

-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 06 July 2015 11:03
To: Don Slutz
Cc: Paul Durrant; [email protected]
Subject: Re: [Xen-devel] Migration bug added by commit 2df1aa01bef7366798248ac6d03cfb42048b003d

Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 29.06.15 at 17:14, <[email protected]> wrote:

xen/arch/x86/hvm/emulate.c static int hvmemul_do_io( · line 186

Quoted 12 lines · Paul Durrant

I think this patch should do it for now:

xen/arch/x86/hvm/emulate.c +1 -1
index a4d7225..cc6130c 100644
@@ -183,7 +183,7 @@ static int hvmemul_do_io(
          else
          {
              rc = hvm_send_assist_req(s, &p);
-            if ( rc != X86EMUL_RETRY )
+            if ( rc != X86EMUL_RETRY || curr->domain->is_shutting_down )

I do not know enough about "is_shutting_down" to agree. What is clear is that
this test is not the same as "!vcpu_start_shutdown_deferral(curr)".

Quoted 7 lines
Quoted 4 lines

Together with Paul's reply the main question appears to have remained un-answered: Does the patch suggested by Paul address the problem you observed?

I can at least say that the patch definitely resolved a regression seen in automated testing of migration of Windows Server 2003 VMs on XenServer.

Good. Not even having got close to the end of unread mails, I suppose I'll find it somewhere as a formal submission...

Jan

#9 lore raw
Quoted 42 lines

-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 06 July 2015 11:14
To: Paul Durrant
Cc: Don Slutz; [email protected]
Subject: RE: [Xen-devel] Migration bug added by commit 2df1aa01bef7366798248ac6d03cfb42048b003d

Quoted 9 lines
Quoted 9 lines
Quoted 1 line · On 06.07.15 at 12:08, <[email protected]> wrote:

-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 06 July 2015 11:03
To: Don Slutz
Cc: Paul Durrant; [email protected]
Subject: Re: [Xen-devel] Migration bug added by commit 2df1aa01bef7366798248ac6d03cfb42048b003d

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 29.06.15 at 17:14, <[email protected]> wrote:

Review

Quoted 3 lines · Paul Durrant

I think this patch should do it for now:

(quoted diff) +0 -0

b/xen/arch/x86/hvm/emulate.c

Quoted 19 lines
Quoted 18 lines
Quoted 5 lines
Quoted 5 lines

index a4d7225..cc6130c 100644

xen/arch/x86/hvm/emulate.c +0 -0
@@ -183,7 +183,7 @@ static int hvmemul_do_io(
          else
Quoted 8 lines

xen/arch/x86/hvm/emulate.c static int hvmemul_do_io( · line 186

Quoted 4 lines
xen/arch/x86/hvm/emulate.c +1 -1
          {
              rc = hvm_send_assist_req(s, &p);
-            if ( rc != X86EMUL_RETRY )
+            if ( rc != X86EMUL_RETRY || curr->domain->is_shutting_down )

I do not know enough about "is_shutting_down" to agree. What is clear is that
this test is not the same as "!vcpu_start_shutdown_deferral(curr)".

Together with Paul's reply the main question appears to have remained un-answered: Does the patch suggested by Paul address the problem you observed?

Quoted 7 lines
Quoted 2 lines

I can at least say that the patch definitely resolved a regression seen in automated testing of migration of Windows Server 2003 VMs on

XenServer.

Good. Not even having got close to the end of unread mails, I suppose I'll find it somewhere as a formal submission...

Yes, it's 01/16 of v6 of the series. Andrew has already reviewed it.

Paul

Quoted 1 line

Jan