Skip to contentSkip to conversation

Xen-unstable: problems with qmp socket error in libxl_pci teardown path for HVM guest with PCI passthrough

PATCH In review Sander Eikelenboom 4 participants 16 messages Nov 26, 2014 – Jan 23, 2015

lore
Share & tools
lore
#0 lore raw

Hi,

While testing a patch for Konrad i was wondering why "libxl_pci.c: libxl__device_pci_reset()" doesn't get called on guest shutdown of a HVM guest (qemu-xen) with pci passthrough. xl didn't show any problems on the commandline so i never drawed much attention to it, but /var/log/xen/xl-guest.log shows:

Waiting for domain xbmc13sid (domid 19) to die [pid 20450]
Domain 19 has shut down, reason code 0 0x0
Action for shutdown reason code 0 is destroy
Domain 19 needs to be cleaned up: destroying the domain
libxl: error: libxl_qmp.c:443:qmp_next: Socket read error: Connection reset by peer
libxl: error: libxl_qmp.c:701:libxl__qmp_initialize: Failed to connect to QMP
libxl: error: libxl_pci.c:1242:do_pci_remove: libxl__qmp_pci_del: Connection reset by peer
libxl: error: libxl_dm.c:1575:kill_device_model: Device Model already exited Done. Exiting now

So it doesn't even get to calling "libxl_pci.c: libxl__device_pci_reset()".

--
Sander

#1 lore raw

create ^
title it QMP connection problems prevent libxl from calling libxl__device_pci_reset on domain shutdown thanks

Quoted 22 lines · Sander Eikelenboom

Hi,

While testing a patch for Konrad i was wondering why "libxl_pci.c: libxl__device_pci_reset()" doesn't get called on guest shutdown of a HVM guest (qemu-xen) with pci passthrough. xl didn't show any problems on the commandline so i never drawed much attention to it, but /var/log/xen/xl-guest.log shows:

Waiting for domain xbmc13sid (domid 19) to die [pid 20450]
Domain 19 has shut down, reason code 0 0x0
Action for shutdown reason code 0 is destroy
Domain 19 needs to be cleaned up: destroying the domain
libxl: error: libxl_qmp.c:443:qmp_next: Socket read error: Connection reset by peer
libxl: error: libxl_qmp.c:701:libxl__qmp_initialize: Failed to connect to QMP
libxl: error: libxl_pci.c:1242:do_pci_remove: libxl__qmp_pci_del: Connection reset by peer
libxl: error: libxl_dm.c:1575:kill_device_model: Device Model already exited Done. Exiting now

So it doesn't even get to calling "libxl_pci.c: libxl__device_pci_reset()".

--
Sander

#2 lore raw
Quoted 4 lines · Stefano Stabellini

create ^
title it QMP connection problems prevent libxl from calling libxl__device_pci_reset on domain shutdown thanks

Quoted 21 lines
Quoted 20 lines · Sander Eikelenboom

Hi,

While testing a patch for Konrad i was wondering why "libxl_pci.c: libxl__device_pci_reset()" doesn't get called on guest shutdown of a HVM guest (qemu-xen) with pci passthrough. xl didn't show any problems on the commandline so i never drawed much attention to it, but /var/log/xen/xl-guest.log shows:

Waiting for domain xbmc13sid (domid 19) to die [pid 20450]
Domain 19 has shut down, reason code 0 0x0
Action for shutdown reason code 0 is destroy
Domain 19 needs to be cleaned up: destroying the domain
libxl: error: libxl_qmp.c:443:qmp_next: Socket read error: Connection reset by peer
libxl: error: libxl_qmp.c:701:libxl__qmp_initialize: Failed to connect to QMP
libxl: error: libxl_pci.c:1242:do_pci_remove: libxl__qmp_pci_del: Connection reset by peer
libxl: error: libxl_dm.c:1575:kill_device_model: Device Model already exited Done. Exiting now

So it doesn't even get to calling "libxl_pci.c: libxl__device_pci_reset()".

--

It's worth checking whether the device model exits too early, i.e., did it crash? What's in the DM log?

Wei.

Quoted 2 lines
Quoted 2 lines

Sander

#3 lore raw
Quoted 23 lines · Wei Liu
Quoted 22 lines · Stefano Stabellini

create ^
title it QMP connection problems prevent libxl from calling libxl__device_pci_reset on domain shutdown thanks

Quoted 17 lines · Sander Eikelenboom

Hi,

While testing a patch for Konrad i was wondering why "libxl_pci.c: libxl__device_pci_reset()" doesn't get called on guest shutdown of a HVM guest (qemu-xen) with pci passthrough. xl didn't show any problems on the commandline so i never drawed much attention to it, but /var/log/xen/xl-guest.log shows:

Waiting for domain xbmc13sid (domid 19) to die [pid 20450]
Domain 19 has shut down, reason code 0 0x0
Action for shutdown reason code 0 is destroy
Domain 19 needs to be cleaned up: destroying the domain
libxl: error: libxl_qmp.c:443:qmp_next: Socket read error: Connection reset by peer
libxl: error: libxl_qmp.c:701:libxl__qmp_initialize: Failed to connect to QMP
libxl: error: libxl_pci.c:1242:do_pci_remove: libxl__qmp_pci_del: Connection reset by peer
libxl: error: libxl_dm.c:1575:kill_device_model: Device Model already exited Done. Exiting now

Quoted 6 lines
Quoted 3 lines
Quoted 3 lines

So it doesn't even get to calling "libxl_pci.c: libxl__device_pci_reset()".

--

It's worth checking whether the device model exits too early, i.e., did it crash? What's in the DM log?

Firstly I was thinking that if force=1 it makes sense to continue even when QEMU returns error, see:

http://marc.info/?i=alpine.DEB.2.02.1411281648500.14135%40kaball.uk.xensource.com

#4 lore raw
Quoted 28 lines · Stefano Stabellini
Quoted 27 lines · Wei Liu
Quoted 25 lines · Stefano Stabellini

create ^
title it QMP connection problems prevent libxl from calling libxl__device_pci_reset on domain shutdown thanks

Quoted 20 lines · Sander Eikelenboom

Hi,

While testing a patch for Konrad i was wondering why "libxl_pci.c: libxl__device_pci_reset()" doesn't get called on guest shutdown of a HVM guest (qemu-xen) with pci passthrough. xl didn't show any problems on the commandline so i never drawed much attention to it, but /var/log/xen/xl-guest.log shows:

Waiting for domain xbmc13sid (domid 19) to die [pid 20450]
Domain 19 has shut down, reason code 0 0x0
Action for shutdown reason code 0 is destroy
Domain 19 needs to be cleaned up: destroying the domain
libxl: error: libxl_qmp.c:443:qmp_next: Socket read error: Connection reset by peer
libxl: error: libxl_qmp.c:701:libxl__qmp_initialize: Failed to connect to QMP
libxl: error: libxl_pci.c:1242:do_pci_remove: libxl__qmp_pci_del: Connection reset by peer
libxl: error: libxl_dm.c:1575:kill_device_model: Device Model already exited Done. Exiting now

So it doesn't even get to calling "libxl_pci.c: libxl__device_pci_reset()".

--

Quoted 7 lines
Quoted 2 lines

It's worth checking whether the device model exits too early, i.e., did it crash? What's in the DM log?

Firstly I was thinking that if force=1 it makes sense to continue even when QEMU returns error, see:

http://marc.info/?i=alpine.DEB.2.02.1411281648500.14135%40kaball.uk.xensource.com

In normal case DM is not destroyed until PCI device is removed. So I think the real issue is DM crashed.

libxl.c:
1571 if (libxl__device_pci_destroy_all(gc, domid) < 0)
1572 LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "pci shutdown failed for domid %d", domid);
1573 rc = xc_domain_pause(ctx->xch, domid);
1574 if (rc < 0) {
1575 LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc, "xc_domain_pause failed for %d", domid);
1576 }
1577 if (dm_present) {
1578 if (libxl__destroy_device_model(gc, domid) < 0)
1579 LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "libxl__destroy_device_model failed for %d", domid);
1580
1581 libxl__qmp_cleanup(gc, domid);
1582 }

The patch you posted covers up the real issue.

Wei.

#5 lore raw
Quoted 32 lines · Wei Liu
Quoted 31 lines · Stefano Stabellini
Quoted 29 lines · Wei Liu
Quoted 4 lines · Stefano Stabellini

create ^
title it QMP connection problems prevent libxl from calling libxl__device_pci_reset on domain shutdown thanks

Quoted 21 lines
Quoted 20 lines · Sander Eikelenboom

Hi,

While testing a patch for Konrad i was wondering why "libxl_pci.c: libxl__device_pci_reset()" doesn't get called on guest shutdown of a HVM guest (qemu-xen) with pci passthrough. xl didn't show any problems on the commandline so i never drawed much attention to it, but /var/log/xen/xl-guest.log shows:

Waiting for domain xbmc13sid (domid 19) to die [pid 20450]
Domain 19 has shut down, reason code 0 0x0
Action for shutdown reason code 0 is destroy
Domain 19 needs to be cleaned up: destroying the domain
libxl: error: libxl_qmp.c:443:qmp_next: Socket read error: Connection reset by peer
libxl: error: libxl_qmp.c:701:libxl__qmp_initialize: Failed to connect to QMP
libxl: error: libxl_pci.c:1242:do_pci_remove: libxl__qmp_pci_del: Connection reset by peer
libxl: error: libxl_dm.c:1575:kill_device_model: Device Model already exited Done. Exiting now

So it doesn't even get to calling "libxl_pci.c: libxl__device_pci_reset()".

--

It's worth checking whether the device model exits too early, i.e., did it crash? What's in the DM log?

Quoted 7 lines
Quoted 4 lines

Firstly I was thinking that if force=1 it makes sense to continue even when QEMU returns error, see:

http://marc.info/?i=alpine.DEB.2.02.1411281648500.14135%40kaball.uk.xensource.com

In normal case DM is not destroyed until PCI device is removed. So I think the real issue is DM crashed.

I don't think it crashed: QEMU detects that domain shutdown has been called and exits.
See:

static void main_loop(void)

{
    bool nonblocking;
    int last_io = 0;
#ifdef CONFIG_PROFILER
    int64_t ti;
#endif
    do {

[...]

    } while (!main_loop_should_exit());
}

main_loop_should_exit returns true when qemu_shutdown_requested().

Quoted 14 lines

libxl.c:
1571 if (libxl__device_pci_destroy_all(gc, domid) < 0)
1572 LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "pci shutdown failed for domid %d", domid);
1573 rc = xc_domain_pause(ctx->xch, domid);
1574 if (rc < 0) {
1575 LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc, "xc_domain_pause failed for %d", domid);
1576 }
1577 if (dm_present) {
1578 if (libxl__destroy_device_model(gc, domid) < 0)
1579 LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "libxl__destroy_device_model failed for %d", domid);
1580
1581 libxl__qmp_cleanup(gc, domid);
1582 }

Quoted 1 line

The patch you posted covers up the real issue.

That is true, but I think the patch is correct regardless of the issue.

#6 lore raw
Quoted 77 lines · you
Quoted 32 lines · Wei Liu
Quoted 31 lines · Stefano Stabellini
Quoted 29 lines · Wei Liu
Quoted 4 lines · Stefano Stabellini

create ^
title it QMP connection problems prevent libxl from calling libxl__device_pci_reset on domain shutdown thanks

Quoted 21 lines
Quoted 20 lines · Sander Eikelenboom

Hi,

While testing a patch for Konrad i was wondering why "libxl_pci.c: libxl__device_pci_reset()" doesn't get called on guest shutdown of a HVM guest (qemu-xen) with pci passthrough. xl didn't show any problems on the commandline so i never drawed much attention to it, but /var/log/xen/xl-guest.log shows:

Waiting for domain xbmc13sid (domid 19) to die [pid 20450]
Domain 19 has shut down, reason code 0 0x0
Action for shutdown reason code 0 is destroy
Domain 19 needs to be cleaned up: destroying the domain
libxl: error: libxl_qmp.c:443:qmp_next: Socket read error: Connection reset by peer
libxl: error: libxl_qmp.c:701:libxl__qmp_initialize: Failed to connect to QMP
libxl: error: libxl_pci.c:1242:do_pci_remove: libxl__qmp_pci_del: Connection reset by peer
libxl: error: libxl_dm.c:1575:kill_device_model: Device Model already exited Done. Exiting now

So it doesn't even get to calling "libxl_pci.c: libxl__device_pci_reset()".

--

It's worth checking whether the device model exits too early, i.e., did it crash? What's in the DM log?

Quoted 7 lines
Quoted 4 lines

Firstly I was thinking that if force=1 it makes sense to continue even when QEMU returns error, see:

http://marc.info/?i=alpine.DEB.2.02.1411281648500.14135%40kaball.uk.xensource.com

In normal case DM is not destroyed until PCI device is removed. So I think the real issue is DM crashed.

I don't think it crashed: QEMU detects that domain shutdown has been called and exits.
See:

static void main_loop(void)

{
    bool nonblocking;
    int last_io = 0;
#ifdef CONFIG_PROFILER
    int64_t ti;
#endif
    do {

[...]

    } while (!main_loop_should_exit());
}

main_loop_should_exit returns true when qemu_shutdown_requested().

Quoted 14 lines

libxl.c:
1571 if (libxl__device_pci_destroy_all(gc, domid) < 0)
1572 LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "pci shutdown failed for domid %d", domid);
1573 rc = xc_domain_pause(ctx->xch, domid);
1574 if (rc < 0) {
1575 LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc, "xc_domain_pause failed for %d", domid);
1576 }
1577 if (dm_present) {
1578 if (libxl__destroy_device_model(gc, domid) < 0)
1579 LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "libxl__destroy_device_model failed for %d", domid);
1580
1581 libxl__qmp_cleanup(gc, domid);
1582 }

Quoted 3 lines
Quoted 1 line

The patch you posted covers up the real issue.

That is true, but I think the patch is correct regardless of the issue.

Hmm how about qemu's "-no-shutdown" option ?

Quoted 1 line

From the manpage:

-no-shutdown
Don't exit QEMU on guest shutdown, but instead only stop the emulation. This allows for instance switching to monitor to commit changes to the disk image.

with:
device_model_args_hvm = [ '-no-shutdown' ]

I get:

/var/log/xen/xl-tv.log:

Waiting for domain tv (domid 18) to die [pid 18587]
Domain 18 has shut down, reason code 0 0x0
Action for shutdown reason code 0 is destroy
Domain 18 needs to be cleaned up: destroying the domain
libxl: error: libxl_pci.c:1299:do_pci_remove: xc_domain_irq_permission irq=40: Invalid argument
libxl: error: libxl_pci.c:1012:libxl__device_pci_reset: ?!?!? Me here
Done. Exiting now

/var/log/xen/qemu-dm-tv.log:

char device redirected to /dev/pts/21 (label serial0) VNC server running on `127.0.0.1:5901'
xen be: vkbd-0: initialise() failed
xen be: vkbd-0: initialise() failed
xen be: vkbd-0: initialise() failed
Issued domain 18 poweroff
qemu: terminating on signal 1 from pid 18587

#7 lore raw
Quoted 93 lines · Sander Eikelenboom
Quoted 77 lines · you
Quoted 32 lines · Wei Liu
Quoted 31 lines · Stefano Stabellini
Quoted 29 lines · Wei Liu
Quoted 4 lines · Stefano Stabellini

create ^
title it QMP connection problems prevent libxl from calling libxl__device_pci_reset on domain shutdown thanks

Quoted 21 lines
Quoted 20 lines · Sander Eikelenboom

Hi,

While testing a patch for Konrad i was wondering why "libxl_pci.c: libxl__device_pci_reset()" doesn't get called on guest shutdown of a HVM guest (qemu-xen) with pci passthrough. xl didn't show any problems on the commandline so i never drawed much attention to it, but /var/log/xen/xl-guest.log shows:

Waiting for domain xbmc13sid (domid 19) to die [pid 20450]
Domain 19 has shut down, reason code 0 0x0
Action for shutdown reason code 0 is destroy
Domain 19 needs to be cleaned up: destroying the domain
libxl: error: libxl_qmp.c:443:qmp_next: Socket read error: Connection reset by peer
libxl: error: libxl_qmp.c:701:libxl__qmp_initialize: Failed to connect to QMP
libxl: error: libxl_pci.c:1242:do_pci_remove: libxl__qmp_pci_del: Connection reset by peer
libxl: error: libxl_dm.c:1575:kill_device_model: Device Model already exited Done. Exiting now

So it doesn't even get to calling "libxl_pci.c: libxl__device_pci_reset()".

--

It's worth checking whether the device model exits too early, i.e., did it crash? What's in the DM log?

Quoted 7 lines
Quoted 4 lines

Firstly I was thinking that if force=1 it makes sense to continue even when QEMU returns error, see:

http://marc.info/?i=alpine.DEB.2.02.1411281648500.14135%40kaball.uk.xensource.com

In normal case DM is not destroyed until PCI device is removed. So I think the real issue is DM crashed.

I don't think it crashed: QEMU detects that domain shutdown has been called and exits.
See:

static void main_loop(void)

{
    bool nonblocking;
    int last_io = 0;
#ifdef CONFIG_PROFILER
    int64_t ti;
#endif
    do {

[...]

    } while (!main_loop_should_exit());
}

main_loop_should_exit returns true when qemu_shutdown_requested().

Quoted 14 lines

libxl.c:
1571 if (libxl__device_pci_destroy_all(gc, domid) < 0)
1572 LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "pci shutdown failed for domid %d", domid);
1573 rc = xc_domain_pause(ctx->xch, domid);
1574 if (rc < 0) {
1575 LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc, "xc_domain_pause failed for %d", domid);
1576 }
1577 if (dm_present) {
1578 if (libxl__destroy_device_model(gc, domid) < 0)
1579 LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "libxl__destroy_device_model failed for %d", domid);
1580
1581 libxl__qmp_cleanup(gc, domid);
1582 }

Quoted 3 lines
Quoted 1 line

The patch you posted covers up the real issue.

That is true, but I think the patch is correct regardless of the issue.

Hmm how about qemu's "-no-shutdown" option ?

Quoted 1 line

From the manpage:

-no-shutdown
Don't exit QEMU on guest shutdown, but instead only stop the emulation. This allows for instance switching to monitor to commit changes to the disk image.

with:
device_model_args_hvm = [ '-no-shutdown' ]

I get:

Quoted 7 lines

/var/log/xen/xl-tv.log:

Waiting for domain tv (domid 18) to die [pid 18587]
Domain 18 has shut down, reason code 0 0x0
Action for shutdown reason code 0 is destroy
Domain 18 needs to be cleaned up: destroying the domain
libxl: error: libxl_pci.c:1299:do_pci_remove: xc_domain_irq_permission irq=40: Invalid argument

Thanks for testing! The suggestion might be a good idea, but I am not sure whether it is suitable given the stage of the release cycle. I would wait until 4.6 before making that change.

Regarding the xc_domain_irq_permission error, it is just a matter of calling xc_physdev_unmap_pirq after xc_domain_irq_permission:

tools/libxl/libxl_pci.c +4 -4
index 316643c..904d255 100644
@@ -1288,14 +1290,14 @@ skip1:
             goto out;
         }
         if ((fscanf(f, "%u", &irq) == 1) && irq) {
-            rc = xc_physdev_unmap_pirq(ctx->xch, domid, irq);
-            if (rc < 0) {
-                LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "xc_physdev_unmap_pirq irq=%d", irq);
-            }
             rc = xc_domain_irq_permission(ctx->xch, domid, irq, 0);
             if (rc < 0) {
                 LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "xc_domain_irq_permission irq=%d", irq);
             }
+            rc = xc_physdev_unmap_pirq(ctx->xch, domid, irq);
+            if (rc < 0) {
+                LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "xc_physdev_unmap_pirq irq=%d", irq);
+            }
         }
         fclose(f);
     }
#8 lore raw

PATCH 1/1 call xc_domain_irq_permission before xc_domain_irq_permission

In reply to Sander Eikelenboom

xc_physdev_unmap_pirq might revoke the permission to map the irq from the domain causing the following xc_domain_irq_permission call to fail and return error (domain_pirq_to_irq returns 0).

Call xc_domain_irq_permission first to prevent this from happening (xc_physdev_unmap_pirq calls irq_deny_access, that doesn't fail if the permission is already removed).

This is a simple bug fix and I think should go in 4.5.

tools/libxl/libxl_pci.c +4 -4
index 316643c..904d255 100644
@@ -1288,14 +1290,14 @@ skip1:
             goto out;
         }
         if ((fscanf(f, "%u", &irq) == 1) && irq) {
-            rc = xc_physdev_unmap_pirq(ctx->xch, domid, irq);
-            if (rc < 0) {
-                LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "xc_physdev_unmap_pirq irq=%d", irq);
-            }
             rc = xc_domain_irq_permission(ctx->xch, domid, irq, 0);
             if (rc < 0) {
                 LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "xc_domain_irq_permission irq=%d", irq);
             }
+            rc = xc_physdev_unmap_pirq(ctx->xch, domid, irq);
+            if (rc < 0) {
+                LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "xc_physdev_unmap_pirq irq=%d", irq);
+            }
         }
         fclose(f);
     }
#9 lore raw

Re: [PATCH for-4.5] call xc_domain_irq_permission before xc_domain_irq_permission

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 01.12.14 at 20:22, <[email protected]> wrote:

xc_physdev_unmap_pirq might revoke the permission to map the irq from the domain causing the following xc_domain_irq_permission call to fail and return error (domain_pirq_to_irq returns 0).

Apart from the patch title being rather confusing, isn't the root problem then xc_physdev_unmap_pirq() removes permissions? At least after the strict splitting of permission granting and mapping for MMIO (commit 0561e1f0) it would seem that if the underlying hypercall here behaves similarly to the original behavior there, it ought to be fixed in an analogous way.

Jan

Quoted 39 lines

Call xc_domain_irq_permission first to prevent this from happening (xc_physdev_unmap_pirq calls irq_deny_access, that doesn't fail if the permission is already removed).

This is a simple bug fix and I think should go in 4.5.

tools/libxl/libxl_pci.c +4 -4
index 316643c..904d255 100644
@@ -1288,14 +1290,14 @@ skip1:
             goto out;
         }
         if ((fscanf(f, "%u", &irq) == 1) && irq) {
-            rc = xc_physdev_unmap_pirq(ctx->xch, domid, irq);
-            if (rc < 0) {
-                LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, 
 "xc_physdev_unmap_pirq irq=%d", irq);
-            }
             rc = xc_domain_irq_permission(ctx->xch, domid, irq, 0);
             if (rc < 0) {
                 LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, 
 "xc_domain_irq_permission irq=%d", irq);
             }
+            rc = xc_physdev_unmap_pirq(ctx->xch, domid, irq);
+            if (rc < 0) {
+                LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, 
 "xc_physdev_unmap_pirq irq=%d", irq);
+            }
         }
         fclose(f);
     }

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

#10 lore raw

Re: [PATCH for-4.5] call xc_domain_irq_permission before xc_domain_irq_permission

Quoted 11 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 01.12.14 at 20:22, <[email protected]> wrote:

xc_physdev_unmap_pirq might revoke the permission to map the irq from the domain causing the following xc_domain_irq_permission call to fail and return error (domain_pirq_to_irq returns 0).

Apart from the patch title being rather confusing, isn't the root problem then xc_physdev_unmap_pirq() removes permissions? At least after the strict splitting of permission granting and mapping for MMIO (commit 0561e1f0) it would seem that if the underlying hypercall here behaves similarly to the original behavior there, it ought to be fixed in an analogous way.

The big difference is that 0561e1f0 makes XEN_DOMCTL_memory_mapping stricker, while you are suggesting to make xc_physdev_unmap_pirq laxer.

Are you sure that is a good idea? What if a third party caller of xc_physdev_unmap_pirq relies on that behaviour?

Quoted 42 lines
Quoted 39 lines

Call xc_domain_irq_permission first to prevent this from happening (xc_physdev_unmap_pirq calls irq_deny_access, that doesn't fail if the permission is already removed).

This is a simple bug fix and I think should go in 4.5.

tools/libxl/libxl_pci.c +4 -4
index 316643c..904d255 100644
@@ -1288,14 +1290,14 @@ skip1:
             goto out;
         }
         if ((fscanf(f, "%u", &irq) == 1) && irq) {
-            rc = xc_physdev_unmap_pirq(ctx->xch, domid, irq);
-            if (rc < 0) {
-                LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, 
 "xc_physdev_unmap_pirq irq=%d", irq);
-            }
             rc = xc_domain_irq_permission(ctx->xch, domid, irq, 0);
             if (rc < 0) {
                 LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, 
 "xc_domain_irq_permission irq=%d", irq);
             }
+            rc = xc_physdev_unmap_pirq(ctx->xch, domid, irq);
+            if (rc < 0) {
+                LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, 
 "xc_physdev_unmap_pirq irq=%d", irq);
+            }
         }
         fclose(f);
     }

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

#11 lore raw

Re: [PATCH for-4.5] call xc_domain_irq_permission before xc_domain_irq_permission

Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 02.12.14 at 11:55, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 01.12.14 at 20:22, <[email protected]> wrote:

xc_physdev_unmap_pirq might revoke the permission to map the irq from the domain causing the following xc_domain_irq_permission call to fail and return error (domain_pirq_to_irq returns 0).

Apart from the patch title being rather confusing, isn't the root problem then xc_physdev_unmap_pirq() removes permissions? At least after the strict splitting of permission granting and mapping for MMIO (commit 0561e1f0) it would seem that if the underlying hypercall here behaves similarly to the original behavior there, it ought to be fixed in an analogous way.

Quoted 5 lines

The big difference is that 0561e1f0 makes XEN_DOMCTL_memory_mapping stricker, while you are suggesting to make xc_physdev_unmap_pirq laxer.

Are you sure that is a good idea? What if a third party caller of xc_physdev_unmap_pirq relies on that behaviour?

Yes, I think this would be correct. We expect tool stacks to be in sync with the hypervisor. That said, I'm not sure it would actually work, since if we did that change, the implicit access granting in the map operation would also need to be dropped. Yet the map operation is a prerequisite for XEN_DOMCTL_irq_permission to work at all right now, as it needs to look up the pIRQ->IRQ translation (which looks wrong to me now anyway, as it makes little sense for the same pIRQ to be associated with the same IRQ in two different domains, i.e. I think the pirq_{permit,deny}_access() calls there really need to be irq_{permit,deny}_access(), handed the IRQ translated from the passed in pIRQ).

Jan

#12 lore raw

Re: [PATCH for-4.5] call xc_domain_irq_permission before xc_domain_irq_permission

In reply to Stefano Stabellini
Quoted 11 lines · Stefano Stabellini

xc_physdev_unmap_pirq might revoke the permission to map the irq from the domain causing the following xc_domain_irq_permission call to fail and return error (domain_pirq_to_irq returns 0).

Call xc_domain_irq_permission first to prevent this from happening (xc_physdev_unmap_pirq calls irq_deny_access, that doesn't fail if the permission is already removed).

This is a simple bug fix and I think should go in 4.5.

This patch didn't actually make it into 4.5, but I think it should have. We could at least apply to master now.

Quoted 24 lines
tools/libxl/libxl_pci.c +4 -4
index 316643c..904d255 100644
@@ -1288,14 +1290,14 @@ skip1:
             goto out;
         }
         if ((fscanf(f, "%u", &irq) == 1) && irq) {
-            rc = xc_physdev_unmap_pirq(ctx->xch, domid, irq);
-            if (rc < 0) {
-                LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "xc_physdev_unmap_pirq irq=%d", irq);
-            }
             rc = xc_domain_irq_permission(ctx->xch, domid, irq, 0);
             if (rc < 0) {
                 LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "xc_domain_irq_permission irq=%d", irq);
             }
+            rc = xc_physdev_unmap_pirq(ctx->xch, domid, irq);
+            if (rc < 0) {
+                LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "xc_physdev_unmap_pirq irq=%d", irq);
+            }
         }
         fclose(f);
     }
#13 lore raw

Re: [PATCH for-4.5] call xc_domain_irq_permission before xc_domain_irq_permission

Quoted 9 lines · you
Quoted 8 lines · Stefano Stabellini

xc_physdev_unmap_pirq might revoke the permission to map the irq from the domain causing the following xc_domain_irq_permission call to fail and return error (domain_pirq_to_irq returns 0).

Call xc_domain_irq_permission first to prevent this from happening (xc_physdev_unmap_pirq calls irq_deny_access, that doesn't fail if the permission is already removed).

Quoted 6 lines
Quoted 3 lines

This is a simple bug fix and I think should go in 4.5.

This patch didn't actually make it into 4.5, but I think it should have. We could at least apply to master now.

Didn't Jan issue a patch for that in:
http://xenbits.xen.org/gitweb/?p=xen.git;a=commit;h=6fb3a07bc0ad656b5f76eb9fc961bcd1d3cace58

--
Sander

Quoted 24 lines
Quoted 24 lines
tools/libxl/libxl_pci.c +4 -4
index 316643c..904d255 100644
@@ -1288,14 +1290,14 @@ skip1:
             goto out;
         }
         if ((fscanf(f, "%u", &irq) == 1) && irq) {
-            rc = xc_physdev_unmap_pirq(ctx->xch, domid, irq);
-            if (rc < 0) {
-                LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "xc_physdev_unmap_pirq irq=%d", irq);
-            }
             rc = xc_domain_irq_permission(ctx->xch, domid, irq, 0);
             if (rc < 0) {
                 LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "xc_domain_irq_permission irq=%d", irq);
             }
+            rc = xc_physdev_unmap_pirq(ctx->xch, domid, irq);
+            if (rc < 0) {
+                LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "xc_physdev_unmap_pirq irq=%d", irq);
+            }
         }
         fclose(f);
     }
#14 lore raw

Re: [PATCH for-4.5] call xc_domain_irq_permission before xc_domain_irq_permission

Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 23.01.15 at 13:59, <[email protected]> wrote:
Quoted 11 lines · you
Quoted 10 lines · Stefano Stabellini

xc_physdev_unmap_pirq might revoke the permission to map the irq from the domain causing the following xc_domain_irq_permission call to fail and return error (domain_pirq_to_irq returns 0).

Call xc_domain_irq_permission first to prevent this from happening (xc_physdev_unmap_pirq calls irq_deny_access, that doesn't fail if the permission is already removed).

This is a simple bug fix and I think should go in 4.5.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

This patch didn't actually make it into 4.5, but I think it should have. We could at least apply to master now.

Didn't Jan issue a patch for that in:
http://xenbits.xen.org/gitweb/?p=xen.git;a=commit;h=6fb3a07bc0ad656b5f76eb9f
c961bcd1d3cace58

Indeed, that one was meant to make this one unnecessary.

Jan

#15 lore raw

Re: [PATCH for-4.5] call xc_domain_irq_permission before xc_domain_irq_permission

Quoted 17 lines · Jan Beulich
Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 23.01.15 at 13:59, <[email protected]> wrote:
Quoted 12 lines · you
Quoted 11 lines · Stefano Stabellini

xc_physdev_unmap_pirq might revoke the permission to map the irq from the domain causing the following xc_domain_irq_permission call to fail and return error (domain_pirq_to_irq returns 0).

Call xc_domain_irq_permission first to prevent this from happening (xc_physdev_unmap_pirq calls irq_deny_access, that doesn't fail if the permission is already removed).

This is a simple bug fix and I think should go in 4.5.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

This patch didn't actually make it into 4.5, but I think it should have. We could at least apply to master now.

Didn't Jan issue a patch for that in:
http://xenbits.xen.org/gitweb/?p=xen.git;a=commit;h=6fb3a07bc0ad656b5f76eb9f
c961bcd1d3cace58

Indeed, that one was meant to make this one unnecessary.

Great, thanks Jan and Sander, I missed it.