Skip to contentSkip to conversation

libxl: do not rely on guest to respond when forcing pci device removal

PATCH Applied Ian Campbell 5 participants 12 messages Mar 8, 2011 – Mar 10, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libxl: do not rely on guest to respond when forcing pci device removal

# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1299584929 0
# Node ID 5084214b8983045d789a86c01e7a0fede46b5e58
# Parent 0e3211b5c4da98d170ed665c221bcb00e771fc56
libxl: do not rely on guest to respond when forcing pci device removal

This is consistent with the expected semantics of a forced device removal and also avoids a delay when destroying an HVM domain which either does not support hot unplug (does not respond to SCI) or has crashed.

tools/libxl/libxl_pci.c +2 -3
diff -r 0e3211b5c4da -r 5084214b8983 tools/libxl/libxl_pci.c
@@ -866,7 +866,7 @@ static int do_pci_remove(libxl__gc *gc, 
 
         /* Remove all functions at once atomically by only signalling
          * device-model for function 0 */
-        if ( (pcidev->vdevfn & 0x7) == 0 ) {
+        if ( !force && (pcidev->vdevfn & 0x7) == 0 ) {
             xs_write(ctx->xsh, XBT_NULL, path, "pci-rem", strlen("pci-rem"));
             if (libxl__wait_for_device_model(ctx, domid, "pci-removed", NULL, NULL) < 0) {
                 LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Device Model didn't respond in time");
@@ -874,8 +874,7 @@ static int do_pci_remove(libxl__gc *gc, 
                  * SCI, if it doesn't respond in time then we may wish to 
                  * force the removal.
                  */
-                if ( !force )
-                    return ERROR_FAIL;
+                return ERROR_FAIL;
             }
         }
         path = libxl__sprintf(gc, "/local/domain/0/device-model/%d/state", domid);
Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1299584929 0
# Node ID 5084214b8983045d789a86c01e7a0fede46b5e58
# Parent 0e3211b5c4da98d170ed665c221bcb00e771fc56
libxl: do not rely on guest to respond when forcing pci device removal

Quoted 7 lines

This is consistent with the expected semantics of a forced device removal and also avoids a delay when destroying an HVM domain which either does not support hot unplug (does not respond to SCI) or has crashed.

#2 lore raw
In reply to Ian Campbell
Quoted 18 lines · Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1299584929 0
# Node ID 5084214b8983045d789a86c01e7a0fede46b5e58
# Parent 0e3211b5c4da98d170ed665c221bcb00e771fc56
libxl: do not rely on guest to respond when forcing pci device removal

This is consistent with the expected semantics of a forced device removal and also avoids a delay when destroying an HVM domain which either does not support hot unplug (does not respond to SCI) or has crashed.

diff -r 0e3211b5c4da -r 5084214b8983 tools/libxl/libxl_pci.c

tools/libxl/libxl_pci.c static int do_pci_remove(libxl__gc *gc, · line 870

Quoted 6 lines
tools/libxl/libxl_pci.c +1 -1
@@ -866,7 +866,7 @@ static int do_pci_remove(libxl__gc *gc, 
 
         /* Remove all functions at once atomically by only signalling
          * device-model for function 0 */
-        if ( (pcidev->vdevfn & 0x7) == 0 ) {
+        if ( !force && (pcidev->vdevfn & 0x7) == 0 ) {
             xs_write(ctx->xsh, XBT_NULL, path, "pci-rem", strlen("pci-rem"));

Shouldn't we maybe send the pci-rem when force removing to give the guest a chance to do something if it can.

tools/libxl/libxl_pci.c static int do_pci_remove(libxl__gc *gc, · line 871

Quoted 1 line
tools/libxl/libxl_pci.c +0 -0
             if (libxl__wait_for_device_model(ctx, domid, "pci-removed", NULL, NULL) < 0) {
			&& !force ) {

perhaps?

tools/libxl/libxl_pci.c static int do_pci_remove(libxl__gc *gc, · line 880

Quoted 11 lines
tools/libxl/libxl_pci.c +1 -2
                 LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Device Model didn't respond in time");
@@ -874,8 +874,7 @@ static int do_pci_remove(libxl__gc *gc, 
                  * SCI, if it doesn't respond in time then we may wish to 
                  * force the removal.
                  */
-                if ( !force )
-                    return ERROR_FAIL;
+                return ERROR_FAIL;
             }
         }
         path = libxl__sprintf(gc, "/local/domain/0/device-model/%d/state", domid);

The more I think about any of this code the worse the idea of the "xenstore + wait a bit" API seems, frankly, erroneous.

Gianni

#3 lore raw
Quoted 20 lines · Gianni Tedesco
Quoted 19 lines · Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1299584929 0
# Node ID 5084214b8983045d789a86c01e7a0fede46b5e58
# Parent 0e3211b5c4da98d170ed665c221bcb00e771fc56
libxl: do not rely on guest to respond when forcing pci device removal

This is consistent with the expected semantics of a forced device removal and also avoids a delay when destroying an HVM domain which either does not support hot unplug (does not respond to SCI) or has crashed.

diff -r 0e3211b5c4da -r 5084214b8983 tools/libxl/libxl_pci.c

tools/libxl/libxl_pci.c +0 -0
@@ -866,7 +866,7 @@ static int do_pci_remove(libxl__gc *gc, 
 
Quoted 8 lines

tools/libxl/libxl_pci.c static int do_pci_remove(libxl__gc *gc, · line 870

Quoted 5 lines
tools/libxl/libxl_pci.c +1 -1
         /* Remove all functions at once atomically by only signalling
          * device-model for function 0 */
-        if ( (pcidev->vdevfn & 0x7) == 0 ) {
+        if ( !force && (pcidev->vdevfn & 0x7) == 0 ) {
             xs_write(ctx->xsh, XBT_NULL, path, "pci-rem", strlen("pci-rem"));

Shouldn't we maybe send the pci-rem when force removing to give the guest a chance to do something if it can.

My concern was just that if this wasn't reacted to by qemu it might interfere with us sending other requests in the future (I don't know and haven't checked if that is the case).

Quoted 5 lines

tools/libxl/libxl_pci.c static int do_pci_remove(libxl__gc *gc, · line 871

Quoted 2 lines
tools/libxl/libxl_pci.c +0 -0
             if (libxl__wait_for_device_model(ctx, domid, "pci-removed", NULL, NULL) < 0) {
			&& !force ) {

perhaps?

Did you mean "!force && libxl__wait..." iow you need the !force to short-circuit the waiting which was the point of the patch.

Ian.

Quoted 18 lines

tools/libxl/libxl_pci.c static int do_pci_remove(libxl__gc *gc, · line 880

Quoted 12 lines
tools/libxl/libxl_pci.c +1 -2
                 LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Device Model didn't respond in time");
@@ -874,8 +874,7 @@ static int do_pci_remove(libxl__gc *gc, 
                  * SCI, if it doesn't respond in time then we may wish to 
                  * force the removal.
                  */
-                if ( !force )
-                    return ERROR_FAIL;
+                return ERROR_FAIL;
             }
         }
         path = libxl__sprintf(gc, "/local/domain/0/device-model/%d/state", domid);

The more I think about any of this code the worse the idea of the "xenstore + wait a bit" API seems, frankly, erroneous.

Gianni

#4 lore raw
Quoted 30 lines · Ian Campbell
Quoted 20 lines · Gianni Tedesco
Quoted 19 lines · Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1299584929 0
# Node ID 5084214b8983045d789a86c01e7a0fede46b5e58
# Parent 0e3211b5c4da98d170ed665c221bcb00e771fc56
libxl: do not rely on guest to respond when forcing pci device removal

This is consistent with the expected semantics of a forced device removal and also avoids a delay when destroying an HVM domain which either does not support hot unplug (does not respond to SCI) or has crashed.

diff -r 0e3211b5c4da -r 5084214b8983 tools/libxl/libxl_pci.c

tools/libxl/libxl_pci.c +0 -0
@@ -866,7 +866,7 @@ static int do_pci_remove(libxl__gc *gc, 
 
Quoted 8 lines

tools/libxl/libxl_pci.c static int do_pci_remove(libxl__gc *gc, · line 870

Quoted 5 lines
tools/libxl/libxl_pci.c +1 -1
         /* Remove all functions at once atomically by only signalling
          * device-model for function 0 */
-        if ( (pcidev->vdevfn & 0x7) == 0 ) {
+        if ( !force && (pcidev->vdevfn & 0x7) == 0 ) {
             xs_write(ctx->xsh, XBT_NULL, path, "pci-rem", strlen("pci-rem"));

Shouldn't we maybe send the pci-rem when force removing to give the guest a chance to do something if it can.

Quoted 3 lines

My concern was just that if this wasn't reacted to by qemu it might interfere with us sending other requests in the future (I don't know and haven't checked if that is the case).

The guest OS should be able to shutdown properly no matter if it receives the hot-unplug event or not.
And Xen should be able to clean up the resources in use no matter if the guest OS handles the hot-unplug event or not.
Therefore avoiding the hot-unplug code path on shutdown is perfectly reasonable.

#5 lore raw
Quoted 31 lines · Stefano Stabellini
Quoted 30 lines · Ian Campbell
Quoted 28 lines · Gianni Tedesco
Quoted 18 lines · Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1299584929 0
# Node ID 5084214b8983045d789a86c01e7a0fede46b5e58
# Parent 0e3211b5c4da98d170ed665c221bcb00e771fc56
libxl: do not rely on guest to respond when forcing pci device removal

This is consistent with the expected semantics of a forced device removal and also avoids a delay when destroying an HVM domain which either does not support hot unplug (does not respond to SCI) or has crashed.

diff -r 0e3211b5c4da -r 5084214b8983 tools/libxl/libxl_pci.c

tools/libxl/libxl_pci.c static int do_pci_remove(libxl__gc *gc, · line 870

Quoted 6 lines
tools/libxl/libxl_pci.c +1 -1
@@ -866,7 +866,7 @@ static int do_pci_remove(libxl__gc *gc, 
 
         /* Remove all functions at once atomically by only signalling
          * device-model for function 0 */
-        if ( (pcidev->vdevfn & 0x7) == 0 ) {
+        if ( !force && (pcidev->vdevfn & 0x7) == 0 ) {
             xs_write(ctx->xsh, XBT_NULL, path, "pci-rem", strlen("pci-rem"));

Shouldn't we maybe send the pci-rem when force removing to give the guest a chance to do something if it can.

Quoted 6 lines
Quoted 3 lines

My concern was just that if this wasn't reacted to by qemu it might interfere with us sending other requests in the future (I don't know and haven't checked if that is the case).

The guest OS should be able to shutdown properly no matter if it receives the hot-unplug event or not.

Or it may have crashed.

Quoted 4 lines

And Xen should be able to clean up the resources in use no matter if the guest OS handles the hot-unplug event or not.
Therefore avoiding the hot-unplug code path on shutdown is perfectly reasonable.

Note that this change impacts the destroy path but not the shutdown path.

Avoiding any need to do a graceful teardown is part of the point of the difference between destroy and shutdown.

Ian.

#6 lore raw
In reply to Ian Campbell
Quoted 30 lines · Ian Campbell
Quoted 20 lines · Gianni Tedesco
Quoted 19 lines · Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1299584929 0
# Node ID 5084214b8983045d789a86c01e7a0fede46b5e58
# Parent 0e3211b5c4da98d170ed665c221bcb00e771fc56
libxl: do not rely on guest to respond when forcing pci device removal

This is consistent with the expected semantics of a forced device removal and also avoids a delay when destroying an HVM domain which either does not support hot unplug (does not respond to SCI) or has crashed.

diff -r 0e3211b5c4da -r 5084214b8983 tools/libxl/libxl_pci.c

tools/libxl/libxl_pci.c +0 -0
@@ -866,7 +866,7 @@ static int do_pci_remove(libxl__gc *gc, 
 
Quoted 8 lines

tools/libxl/libxl_pci.c static int do_pci_remove(libxl__gc *gc, · line 870

Quoted 5 lines
tools/libxl/libxl_pci.c +1 -1
         /* Remove all functions at once atomically by only signalling
          * device-model for function 0 */
-        if ( (pcidev->vdevfn & 0x7) == 0 ) {
+        if ( !force && (pcidev->vdevfn & 0x7) == 0 ) {
             xs_write(ctx->xsh, XBT_NULL, path, "pci-rem", strlen("pci-rem"));

Shouldn't we maybe send the pci-rem when force removing to give the guest a chance to do something if it can.

Quoted 3 lines

My concern was just that if this wasn't reacted to by qemu it might interfere with us sending other requests in the future (I don't know and haven't checked if that is the case).

It's possible but I think it's unlikely. Generally the qemu hardware emulation works in discrete steps advancing the state machine. The xenstore watching bits work in pretty much the same way.

Quoted 8 lines
Quoted 5 lines

tools/libxl/libxl_pci.c static int do_pci_remove(libxl__gc *gc, · line 871

Quoted 2 lines
tools/libxl/libxl_pci.c +0 -0
             if (libxl__wait_for_device_model(ctx, domid, "pci-removed", NULL, NULL) < 0) {
			&& !force ) {

perhaps?

Did you mean "!force && libxl__wait..." iow you need the !force to short-circuit the waiting which was the point of the patch.

No, I meant to do the wait first but just not whinge about it if it times out. But the other way could make sense too, I'll get to that.

I'm just saying, I think force should try and do things in the normal way and the only difference should be that when it completes, the device is always removed regardless of any guest non-cooperativeness.

OTOH Stefano makes a good point that this code is also called on shutdown as well as if user requests forceful unplug so in the former case doing the hotplug sequence is pointless and in the latter case the user probably already tried a clean hotplug and it failed.

Gianni

#7 lore raw
Quoted 43 lines · Gianni Tedesco
Quoted 30 lines · Ian Campbell
Quoted 20 lines · Gianni Tedesco
Quoted 19 lines · Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1299584929 0
# Node ID 5084214b8983045d789a86c01e7a0fede46b5e58
# Parent 0e3211b5c4da98d170ed665c221bcb00e771fc56
libxl: do not rely on guest to respond when forcing pci device removal

This is consistent with the expected semantics of a forced device removal and also avoids a delay when destroying an HVM domain which either does not support hot unplug (does not respond to SCI) or has crashed.

diff -r 0e3211b5c4da -r 5084214b8983 tools/libxl/libxl_pci.c

tools/libxl/libxl_pci.c +0 -0
@@ -866,7 +866,7 @@ static int do_pci_remove(libxl__gc *gc, 
 
Quoted 8 lines

tools/libxl/libxl_pci.c static int do_pci_remove(libxl__gc *gc, · line 870

Quoted 5 lines
tools/libxl/libxl_pci.c +1 -1
         /* Remove all functions at once atomically by only signalling
          * device-model for function 0 */
-        if ( (pcidev->vdevfn & 0x7) == 0 ) {
+        if ( !force && (pcidev->vdevfn & 0x7) == 0 ) {
             xs_write(ctx->xsh, XBT_NULL, path, "pci-rem", strlen("pci-rem"));

Shouldn't we maybe send the pci-rem when force removing to give the guest a chance to do something if it can.

Quoted 3 lines

My concern was just that if this wasn't reacted to by qemu it might interfere with us sending other requests in the future (I don't know and haven't checked if that is the case).

It's possible but I think it's unlikely. Generally the qemu hardware emulation works in discrete steps advancing the state machine. The xenstore watching bits work in pretty much the same way.

Quoted 4 lines
Quoted 4 lines

tools/libxl/libxl_pci.c static int do_pci_remove(libxl__gc *gc, · line 871

Quoted 2 lines
tools/libxl/libxl_pci.c +0 -0
             if (libxl__wait_for_device_model(ctx, domid, "pci-removed", NULL, NULL) < 0) {
			&& !force ) {
Quoted 7 lines
Quoted 4 lines
Quoted 1 line

perhaps?

Did you mean "!force && libxl__wait..." iow you need the !force to short-circuit the waiting which was the point of the patch.

No, I meant to do the wait first but just not whinge about it if it times out. But the other way could make sense too, I'll get to that.

The wait and the timeout are the specific issue I am trying to address. When I type "xl destroy foo" I expect domain foo to get shot in the head right now, no questions and no hanging around. Similarly if I do "xl pci-detach --force...".

Quoted 8 lines

I'm just saying, I think force should try and do things in the normal way and the only difference should be that when it completes, the device is always removed regardless of any guest non-cooperativeness.

OTOH Stefano makes a good point that this code is also called on shutdown as well as if user requests forceful unplug so in the former case doing the hotplug sequence is pointless and in the latter case the user probably already tried a clean hotplug and it failed.

In the shutdown case libxl_domain_destroy is called in response to the LIBXL_EVENT_DOMAIN_DEATH event. Nothing is alive to respond to any unplug request.

Ian.

Quoted 3 lines

Gianni

#8 lore raw
Quoted 49 lines · Ian Campbell
Quoted 48 lines · Gianni Tedesco
Quoted 30 lines · Ian Campbell
Quoted 20 lines · Gianni Tedesco
Quoted 19 lines · Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1299584929 0
# Node ID 5084214b8983045d789a86c01e7a0fede46b5e58
# Parent 0e3211b5c4da98d170ed665c221bcb00e771fc56
libxl: do not rely on guest to respond when forcing pci device removal

This is consistent with the expected semantics of a forced device removal and also avoids a delay when destroying an HVM domain which either does not support hot unplug (does not respond to SCI) or has crashed.

diff -r 0e3211b5c4da -r 5084214b8983 tools/libxl/libxl_pci.c

tools/libxl/libxl_pci.c +0 -0
@@ -866,7 +866,7 @@ static int do_pci_remove(libxl__gc *gc, 
 
Quoted 8 lines

tools/libxl/libxl_pci.c static int do_pci_remove(libxl__gc *gc, · line 870

Quoted 5 lines
tools/libxl/libxl_pci.c +1 -1
         /* Remove all functions at once atomically by only signalling
          * device-model for function 0 */
-        if ( (pcidev->vdevfn & 0x7) == 0 ) {
+        if ( !force && (pcidev->vdevfn & 0x7) == 0 ) {
             xs_write(ctx->xsh, XBT_NULL, path, "pci-rem", strlen("pci-rem"));

Shouldn't we maybe send the pci-rem when force removing to give the guest a chance to do something if it can.

Quoted 3 lines

My concern was just that if this wasn't reacted to by qemu it might interfere with us sending other requests in the future (I don't know and haven't checked if that is the case).

It's possible but I think it's unlikely. Generally the qemu hardware emulation works in discrete steps advancing the state machine. The xenstore watching bits work in pretty much the same way.

Quoted 8 lines
Quoted 5 lines

tools/libxl/libxl_pci.c static int do_pci_remove(libxl__gc *gc, · line 871

Quoted 2 lines
tools/libxl/libxl_pci.c +0 -0
             if (libxl__wait_for_device_model(ctx, domid, "pci-removed", NULL, NULL) < 0) {
			&& !force ) {

perhaps?

Did you mean "!force && libxl__wait..." iow you need the !force to short-circuit the waiting which was the point of the patch.

Quoted 7 lines
Quoted 2 lines

No, I meant to do the wait first but just not whinge about it if it times out. But the other way could make sense too, I'll get to that.

The wait and the timeout are the specific issue I am trying to address. When I type "xl destroy foo" I expect domain foo to get shot in the head right now, no questions and no hanging around. Similarly if I do "xl pci-detach --force...".

OK, fair enough. Honestly, I think my expectation for the detach case to be more as I stated, but I don't feel strongly about it and it would just add complexity to have it that way.

Gianni

#9 lore raw
Quoted 53 lines · Gianni Tedesco
Quoted 52 lines · Ian Campbell
Quoted 50 lines · Gianni Tedesco
Quoted 30 lines · Ian Campbell
Quoted 20 lines · Gianni Tedesco
Quoted 19 lines · Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1299584929 0
# Node ID 5084214b8983045d789a86c01e7a0fede46b5e58
# Parent 0e3211b5c4da98d170ed665c221bcb00e771fc56
libxl: do not rely on guest to respond when forcing pci device removal

This is consistent with the expected semantics of a forced device removal and also avoids a delay when destroying an HVM domain which either does not support hot unplug (does not respond to SCI) or has crashed.

diff -r 0e3211b5c4da -r 5084214b8983 tools/libxl/libxl_pci.c

tools/libxl/libxl_pci.c +0 -0
@@ -866,7 +866,7 @@ static int do_pci_remove(libxl__gc *gc, 
 
Quoted 8 lines

tools/libxl/libxl_pci.c static int do_pci_remove(libxl__gc *gc, · line 870

Quoted 5 lines
tools/libxl/libxl_pci.c +1 -1
         /* Remove all functions at once atomically by only signalling
          * device-model for function 0 */
-        if ( (pcidev->vdevfn & 0x7) == 0 ) {
+        if ( !force && (pcidev->vdevfn & 0x7) == 0 ) {
             xs_write(ctx->xsh, XBT_NULL, path, "pci-rem", strlen("pci-rem"));

Shouldn't we maybe send the pci-rem when force removing to give the guest a chance to do something if it can.

Quoted 3 lines

My concern was just that if this wasn't reacted to by qemu it might interfere with us sending other requests in the future (I don't know and haven't checked if that is the case).

It's possible but I think it's unlikely. Generally the qemu hardware emulation works in discrete steps advancing the state machine. The xenstore watching bits work in pretty much the same way.

Quoted 8 lines
Quoted 5 lines

tools/libxl/libxl_pci.c static int do_pci_remove(libxl__gc *gc, · line 871

Quoted 2 lines
tools/libxl/libxl_pci.c +0 -0
             if (libxl__wait_for_device_model(ctx, domid, "pci-removed", NULL, NULL) < 0) {
			&& !force ) {

perhaps?

Did you mean "!force && libxl__wait..." iow you need the !force to short-circuit the waiting which was the point of the patch.

No, I meant to do the wait first but just not whinge about it if it times out. But the other way could make sense too, I'll get to that.

Quoted 8 lines
Quoted 4 lines

The wait and the timeout are the specific issue I am trying to address. When I type "xl destroy foo" I expect domain foo to get shot in the head right now, no questions and no hanging around. Similarly if I do "xl pci-detach --force...".

OK, fair enough. Honestly, I think my expectation for the detach case to be more as I stated, but I don't feel strongly about it and it would just add complexity to have it that way.

That's the non--force'd way of doing it and AFAICT it behaves pretty much as you describe.

Ian.

#10 lore raw
Quoted 6 lines · Ian Campbell
Quoted 3 lines

OK, fair enough. Honestly, I think my expectation for the detach case to be more as I stated, but I don't feel strongly about it and it would just add complexity to have it that way.

That's the non--force'd way of doing it and AFAICT it behaves pretty much as you describe.

Except that the non-force way will bail if the guest doesn't respond and leave everything as it is so that the device can still function.

How I described is try to play nice but before returning to caller - make sure everything is removed.

Anyway, it's a minor point.

Gianni

Applied
#11 lore raw
In reply to Ian Campbell

Ian Campbell writes ("[Xen-devel] [PATCH] libxl: do not rely on guest to respond when forcing pci device removal"):

Quoted 1 line

libxl: do not rely on guest to respond when forcing pci device removal

Applied, thanks.

Ian.