From: Gianni Tedesco Subject: Re: [PATCH, RFC]: qemu: hang-free/error-tolerant PCI hot-plug protocol Date: Thu, 29 Jul 2010 18:58:42 +0100 Message-ID: <1280426322.1723.2269.camel@qabil.uk.xensource.com> References: <1280426058.1723.2266.camel@qabil.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1280426058.1723.2266.camel@qabil.uk.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Xen Devel List-Id: xen-devel@lists.xenproject.org On Thu, 2010-07-29 at 18:54 +0100, Gianni Tedesco wrote: > Hi, > > The interface for PCI hotplug is flexible enough to shoot ones-self in > the foot. It is possible to try to insert a PCI device in to a slot > already occupied by a qemu emulated device (NIC, PIIX, ISA-bridge, etc.) > In this case qemu (wisely) refuses to do the hotplug. Since there is no > way for a toolstack to query qemu's pci device layout there is no way to > check for this ahead of time. In this case the toolstack must wait for > device-model state to change to pci-inserted which never happens. > > I propose that when qemu decides not to hot-plug a device that it raise > the "pci-inserted" status anyway. The tools must then check the > "parameter" key in xenbus for a non-error string. In other words: > > send_command("pci-ins") > wait_for_device_model("pci-inserted") > if parameter[0-2] == "0x" { > /* success */ > }else{ > /* fail */ > } FYI: The corresponding patch I am proposing is actually this (should apply cleanly albeit with offsets): diff -r 414e906dd623 tools/libxl/libxl_pci.c --- a/tools/libxl/libxl_pci.c Thu Jul 29 17:58:38 2010 +0100 +++ b/tools/libxl/libxl_pci.c Thu Jul 29 18:59:32 2010 +0100 @@ -404,6 +479,12 @@ static int do_pci_add(libxl_ctx *ctx, ui XL_LOG(ctx, XL_LOG_ERROR, "Device Model didn't respond in time"); path = libxl_sprintf(ctx, "/local/domain/0/device-model/%d/parameter", domid); vdevfn = libxl_xs_read(ctx, XBT_NULL, path); + if ( strncmp(vdevfn, "0x", 2) ) { + XL_LOG(ctx, XL_LOG_ERROR, "qemu refused to add device: %s", vdevfn); + path = libxl_sprintf(ctx, "/local/domain/0/device-model/%d/state", domid); + xs_write(ctx->xsh, XBT_NULL, path, "running", strlen("running")); + return ERROR_FAIL; + } sscanf(vdevfn + 2, "%x", &pcidev->vdevfn); path = libxl_sprintf(ctx, "/local/domain/0/device-model/%d/state", domid); xs_write(ctx->xsh, XBT_NULL, path, state, strlen(state));