From: "Marek Marczykowski-Górecki" <marmarek@invisiblethingslab.com>
To: xen-devel@lists.xenproject.org
Cc: Anthony PERARD <anthony.perard@citrix.com>,
Ian Jackson <ian.jackson@eu.citrix.com>, Wei Liu <wl@xen.org>
Subject: [Xen-devel] [PATCH v8.1 3/4] libxl: attach PCI device to qemu only after setting pciback/pcifront
Date: Mon, 30 Sep 2019 23:24:19 -0500 [thread overview]
Message-ID: <20191001042419.GA5213@mail-itl> (raw)
In-Reply-To: <20190930151149.GE1163@perard.uk.xensource.com>
When qemu is running in stubdomain, handling "pci-ins" command will fail
if pcifront is not initialized already. Fix this by sending such command
only after confirming that pciback/front is running.
Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Reviewed-by: Anthony PERARD <anthony.perard@citrix.com>
---
Changes in v2:
- Fixed code style since previous version.
Changes in v8:
- rebase on staging
- rework for async api
Changes in v8.1:
- code style fixes
---
tools/libxl/libxl_pci.c | 45 ++++++++++++++++++++++++++++++++++++++++-
1 file changed, 44 insertions(+), 1 deletion(-)
diff --git a/tools/libxl/libxl_pci.c b/tools/libxl/libxl_pci.c
index ac597a58fe..8dc352c961 100644
--- a/tools/libxl/libxl_pci.c
+++ b/tools/libxl/libxl_pci.c
@@ -1012,6 +1012,9 @@ typedef struct pci_add_state {
bool starting;
void (*callback)(libxl__egc *, struct pci_add_state *, int rc);
+ /* private to device_pci_add_stubdom_wait */
+ libxl__ev_devstate pciback_ds;
+
/* private to do_pci_add */
libxl__xswait_state xswait;
libxl__ev_qmp qmp;
@@ -1487,6 +1490,10 @@ static int libxl_pcidev_assignable(libxl_ctx *ctx, libxl_device_pci *pcidev)
return i != num;
}
+static void device_pci_add_stubdom_wait(libxl__egc *egc,
+ pci_add_state *pas, int rc);
+static void device_pci_add_stubdom_ready(libxl__egc *egc,
+ libxl__ev_devstate *ds, int rc);
static void device_pci_add_stubdom_done(libxl__egc *egc,
pci_add_state *, int rc);
static void device_pci_add_done(libxl__egc *egc,
@@ -1563,7 +1570,8 @@ void libxl__device_pci_add(libxl__egc *egc, uint32_t domid,
GCNEW(pcidev_s);
libxl_device_pci_init(pcidev_s);
libxl_device_pci_copy(CTX, pcidev_s, pcidev);
- pas->callback = device_pci_add_stubdom_done;
+ pas->callback = device_pci_add_stubdom_wait;
+
do_pci_add(egc, stubdomid, pcidev_s, pas); /* must be last */
return;
}
@@ -1575,6 +1583,41 @@ out:
device_pci_add_done(egc, pas, rc); /* must be last */
}
+static void device_pci_add_stubdom_wait(libxl__egc *egc,
+ pci_add_state *pas,
+ int rc)
+{
+ libxl__ao_device *aodev = pas->aodev;
+ STATE_AO_GC(aodev->ao);
+ int stubdomid = libxl_get_stubdom_id(CTX, pas->domid);
+ char *state_path;
+
+ if (rc) goto out;
+
+ /* Wait for the device actually being connected, otherwise device model
+ * running there will fail to find the device. */
+ state_path = GCSPRINTF("%s/state",
+ libxl__domain_device_backend_path(gc, 0, stubdomid, 0,
+ LIBXL__DEVICE_KIND_PCI));
+ rc = libxl__ev_devstate_wait(ao, &pas->pciback_ds,
+ device_pci_add_stubdom_ready,
+ state_path, XenbusStateConnected,
+ LIBXL_DEVICE_MODEL_START_TIMEOUT * 1000);
+ if (rc) goto out;
+ return;
+out:
+ device_pci_add_done(egc, pas, rc); /* must be last */
+}
+
+static void device_pci_add_stubdom_ready(libxl__egc *egc,
+ libxl__ev_devstate *ds,
+ int rc)
+{
+ pci_add_state *pas = CONTAINER_OF(ds, *pas, pciback_ds);
+
+ device_pci_add_stubdom_done(egc, pas, rc); /* must be last */
+}
+
static void device_pci_add_stubdom_done(libxl__egc *egc,
pci_add_state *pas,
int rc)
--
2.21.0
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2019-10-01 4:24 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-28 14:20 [Xen-devel] [PATCH v8 0/4] Fix PCI passthrough for HVM with stubdomain Marek Marczykowski-Górecki
2019-09-28 14:20 ` [Xen-devel] [PATCH v8 1/4] libxl: fix cold plugged PCI device " Marek Marczykowski-Górecki
2019-09-30 14:33 ` Anthony PERARD
2019-10-02 15:43 ` Ian Jackson
2019-10-02 15:54 ` Jürgen Groß
2019-10-04 16:03 ` Ian Jackson
2019-09-28 14:20 ` [Xen-devel] [PATCH v8 2/4] libxl: do not attach xen-pciback to HVM domain, if stubdomain is in use Marek Marczykowski-Górecki
2019-10-04 16:00 ` Ian Jackson
2019-09-28 14:20 ` [Xen-devel] [PATCH v8 3/4] libxl: attach PCI device to qemu only after setting pciback/pcifront Marek Marczykowski-Górecki
2019-09-30 15:11 ` Anthony PERARD
2019-10-01 4:24 ` Marek Marczykowski-Górecki [this message]
2019-09-28 14:20 ` [Xen-devel] [PATCH v8 4/4] libxl: don't try to manipulate json config for stubdomain Marek Marczykowski-Górecki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191001042419.GA5213@mail-itl \
--to=marmarek@invisiblethingslab.com \
--cc=anthony.perard@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=wl@xen.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.