From: Paul Durrant <paul@xen.org>
To: xen-devel@lists.xenproject.org
Cc: Paul Durrant <pdurrant@amazon.com>,
Ian Jackson <iwj@xenproject.org>, Wei Liu <wl@xen.org>,
Anthony PERARD <anthony.perard@citrix.com>
Subject: [PATCH v4 23/23] xl / libxl: support 'xl pci-attach/detach' by name
Date: Tue, 24 Nov 2020 08:01:59 +0000 [thread overview]
Message-ID: <20201124080159.11912-24-paul@xen.org> (raw)
In-Reply-To: <20201124080159.11912-1-paul@xen.org>
From: Paul Durrant <pdurrant@amazon.com>
This patch adds a 'name' field into the idl for 'libxl_device_pci' and
libxlu_pci_parse_spec_string() is modified to parse the new 'name'
parameter of PCI_SPEC_STRING detailed in the updated documention in
xl-pci-configuration(5).
If the 'name' field is non-NULL then both libxl_device_pci_add() and
libxl_device_pci_remove() will use it to look up the device BDF in
the list of assignable devices.
Signed-off-by: Paul Durrant <pdurrant@amazon.com>
---
Cc: Ian Jackson <iwj@xenproject.org>
Cc: Wei Liu <wl@xen.org>
Cc: Anthony PERARD <anthony.perard@citrix.com>
---
tools/include/libxl.h | 6 ++++
tools/libs/light/libxl_pci.c | 67 +++++++++++++++++++++++++++++++++++++---
tools/libs/light/libxl_types.idl | 1 +
tools/libs/util/libxlu_pci.c | 7 ++++-
4 files changed, 75 insertions(+), 6 deletions(-)
diff --git a/tools/include/libxl.h b/tools/include/libxl.h
index 4025d3a3d4..5b55a20155 100644
--- a/tools/include/libxl.h
+++ b/tools/include/libxl.h
@@ -485,6 +485,12 @@
#define LIBXL_HAVE_PCI_ASSIGNABLE_NAME 1
/*
+ * LIBXL_HAVE_DEVICE_PCI_NAME indicates that the 'name' field of
+ * libxl_device_pci is defined.
+ */
+#define LIBXL_HAVE_DEVICE_PCI_NAME 1
+
+/*
* libxl ABI compatibility
*
* The only guarantee which libxl makes regarding ABI compatibility
diff --git a/tools/libs/light/libxl_pci.c b/tools/libs/light/libxl_pci.c
index 1da7fd5508..c45f4c6a40 100644
--- a/tools/libs/light/libxl_pci.c
+++ b/tools/libs/light/libxl_pci.c
@@ -60,6 +60,10 @@ static void libxl_create_pci_backend_device(libxl__gc *gc,
int num,
const libxl_device_pci *pci)
{
+ if (pci->name) {
+ flexarray_append(back, GCSPRINTF("name-%d", num));
+ flexarray_append(back, GCSPRINTF("%s", pci->name));
+ }
flexarray_append(back, GCSPRINTF("key-%d", num));
flexarray_append(back, GCSPRINTF(PCI_BDF, pci->bdf.domain, pci->bdf.bus, pci->bdf.dev, pci->bdf.func));
flexarray_append(back, GCSPRINTF("dev-%d", num));
@@ -284,6 +288,7 @@ retry_transaction:
retry_transaction2:
t = xs_transaction_start(ctx->xsh);
+ xs_rm(ctx->xsh, t, GCSPRINTF("%s/name-%d", be_path, i));
xs_rm(ctx->xsh, t, GCSPRINTF("%s/state-%d", be_path, i));
xs_rm(ctx->xsh, t, GCSPRINTF("%s/key-%d", be_path, i));
xs_rm(ctx->xsh, t, GCSPRINTF("%s/dev-%d", be_path, i));
@@ -322,6 +327,12 @@ retry_transaction2:
xs_write(ctx->xsh, t, GCSPRINTF("%s/vdevfn-%d", be_path, j - 1), tmp, strlen(tmp));
xs_rm(ctx->xsh, t, tmppath);
}
+ tmppath = GCSPRINTF("%s/name-%d", be_path, j);
+ tmp = libxl__xs_read(gc, t, tmppath);
+ if (tmp) {
+ xs_write(ctx->xsh, t, GCSPRINTF("%s/name-%d", be_path, j - 1), tmp, strlen(tmp));
+ xs_rm(ctx->xsh, t, tmppath);
+ }
}
if (!xs_transaction_end(ctx->xsh, t, 0))
if (errno == EAGAIN)
@@ -1619,6 +1630,23 @@ void libxl__device_pci_add(libxl__egc *egc, uint32_t domid,
pas->starting = starting;
pas->callback = device_pci_add_stubdom_done;
+ if (pci->name) {
+ libxl_pci_bdf *pcibdf =
+ libxl_device_pci_assignable_name2bdf(CTX, pci->name);
+
+ if (!pcibdf) {
+ rc = ERROR_FAIL;
+ goto out;
+ }
+
+ LOGD(DETAIL, domid, "'%s' -> %04x:%02x:%02x.%u", pci->name,
+ pcibdf->domain, pcibdf->bus, pcibdf->dev, pcibdf->func);
+
+ libxl_pci_bdf_copy(CTX, &pci->bdf, pcibdf);
+ libxl_pci_bdf_dispose(pcibdf);
+ free(pcibdf);
+ }
+
if (libxl__domain_type(gc, domid) == LIBXL_DOMAIN_TYPE_HVM) {
rc = xc_test_assign_device(ctx->xch, domid,
pci_encode_bdf(&pci->bdf));
@@ -1767,11 +1795,19 @@ static void device_pci_add_done(libxl__egc *egc,
libxl_device_pci *pci = &pas->pci;
if (rc) {
- LOGD(ERROR, domid,
- "libxl__device_pci_add failed for "
- "PCI device %x:%x:%x.%x (rc %d)",
- pci->bdf.domain, pci->bdf.bus, pci->bdf.dev, pci->bdf.func,
- rc);
+ if (pci->name) {
+ LOGD(ERROR, domid,
+ "libxl__device_pci_add failed for "
+ "PCI device '%s' (rc %d)",
+ pci->name,
+ rc);
+ } else {
+ LOGD(ERROR, domid,
+ "libxl__device_pci_add failed for "
+ "PCI device %x:%x:%x.%x (rc %d)",
+ pci->bdf.domain, pci->bdf.bus, pci->bdf.dev, pci->bdf.func,
+ rc);
+ }
pci_info_xs_remove(gc, &pci->bdf, "domid");
}
libxl_device_pci_dispose(pci);
@@ -2288,6 +2324,23 @@ static void libxl__device_pci_remove_common(libxl__egc *egc,
libxl__ev_time_init(&prs->timeout);
libxl__ev_time_init(&prs->retry_timer);
+ if (pci->name) {
+ libxl_pci_bdf *pcibdf =
+ libxl_device_pci_assignable_name2bdf(CTX, pci->name);
+
+ if (!pcibdf) {
+ rc = ERROR_FAIL;
+ goto out;
+ }
+
+ LOGD(DETAIL, domid, "'%s' -> %04x:%02x:%02x.%u", pci->name,
+ pcibdf->domain, pcibdf->bus, pcibdf->dev, pcibdf->func);
+
+ libxl_pci_bdf_copy(CTX, &prs->pci.bdf, pcibdf);
+ libxl_pci_bdf_dispose(pcibdf);
+ free(pcibdf);
+ }
+
prs->orig_vdev = pci->vdevfn & ~7U;
if ( pci->vfunc_mask == LIBXL_PCI_FUNC_ALL ) {
@@ -2422,6 +2475,10 @@ static int libxl__device_pci_from_xs_be(libxl__gc *gc,
} while ((p = strtok_r(NULL, ",=", &saveptr)) != NULL);
}
+ s = libxl__xs_read(gc, XBT_NULL, GCSPRINTF("%s/name-%d", be_path, nr));
+ if (s)
+ pci->name = strdup(s);
+
return 0;
}
diff --git a/tools/libs/light/libxl_types.idl b/tools/libs/light/libxl_types.idl
index 2c441142fb..44bad36f1c 100644
--- a/tools/libs/light/libxl_types.idl
+++ b/tools/libs/light/libxl_types.idl
@@ -778,6 +778,7 @@ libxl_pci_bdf = Struct("pci_bdf", [
libxl_device_pci = Struct("device_pci", [
("bdf", libxl_pci_bdf),
+ ("name", string),
("vdevfn", uint32),
("vfunc_mask", uint32),
("msitranslate", bool),
diff --git a/tools/libs/util/libxlu_pci.c b/tools/libs/util/libxlu_pci.c
index a8b6ce5427..543a1f80e9 100644
--- a/tools/libs/util/libxlu_pci.c
+++ b/tools/libs/util/libxlu_pci.c
@@ -151,6 +151,7 @@ int xlu_pci_parse_spec_string(XLU_Config *cfg, libxl_device_pci *pcidev,
{
const char *ptr = str;
bool bdf_present = false;
+ bool name_present = false;
int ret;
/* Attempt to parse 'bdf' as positional parameter */
@@ -193,6 +194,10 @@ int xlu_pci_parse_spec_string(XLU_Config *cfg, libxl_device_pci *pcidev,
pcidev->power_mgmt = atoi(val);
} else if (!strcmp(key, "rdm_policy")) {
ret = parse_rdm_policy(cfg, &pcidev->rdm_policy, val);
+ } else if (!strcmp(key, "name")) {
+ name_present = true;
+ pcidev->name = strdup(val);
+ if (!pcidev->name) ret = ERROR_NOMEM;
} else {
XLU__PCI_ERR(cfg, "Unknown PCI_SPEC_STRING option: %s", key);
ret = ERROR_INVAL;
@@ -205,7 +210,7 @@ int xlu_pci_parse_spec_string(XLU_Config *cfg, libxl_device_pci *pcidev,
return ret;
}
- if (!bdf_present)
+ if (!(bdf_present ^ name_present))
return ERROR_INVAL;
return 0;
--
2.11.0
prev parent reply other threads:[~2020-11-24 8:31 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-24 8:01 [PATCH v4 00/23] xl / libxl: named PCI pass-through devices Paul Durrant
2020-11-24 8:01 ` [PATCH v4 01/23] xl / libxl: s/pcidev/pci and remove DEFINE_DEVICE_TYPE_STRUCT_X Paul Durrant
2020-12-01 12:32 ` Oleksandr Andrushchenko
2020-12-03 13:00 ` Paul Durrant
2020-11-24 8:01 ` [PATCH v4 02/23] libxl: make libxl__device_list() work correctly for LIBXL__DEVICE_KIND_PCI Paul Durrant
2020-12-01 12:50 ` Oleksandr Andrushchenko
2020-11-24 8:01 ` [PATCH v4 03/23] libxl: Make sure devices added by pci-attach are reflected in the config Paul Durrant
2020-12-01 13:12 ` Oleksandr Andrushchenko
2020-12-03 13:17 ` Paul Durrant
2020-12-03 13:20 ` Oleksandr Andrushchenko
2020-11-24 8:01 ` [PATCH v4 04/23] libxl: add/recover 'rdm_policy' to/from PCI backend in xenstore Paul Durrant
2020-12-01 13:13 ` Oleksandr Andrushchenko
2020-11-24 8:01 ` [PATCH v4 05/23] libxl: s/detatched/detached in libxl_pci.c Paul Durrant
2020-12-01 13:15 ` Oleksandr Andrushchenko
2020-11-24 8:01 ` [PATCH v4 06/23] libxl: remove extraneous arguments to do_pci_remove() " Paul Durrant
2020-12-01 13:41 ` Oleksandr Andrushchenko
2020-11-24 8:01 ` [PATCH v4 07/23] libxl: stop using aodev->device_config in libxl__device_pci_add() Paul Durrant
2020-12-01 13:42 ` Oleksandr Andrushchenko
2020-11-24 8:01 ` [PATCH v4 08/23] libxl: generalise 'driver_path' xenstore access functions in libxl_pci.c Paul Durrant
2020-12-01 13:48 ` Oleksandr Andrushchenko
2020-11-24 8:01 ` [PATCH v4 09/23] libxl: remove unnecessary check from libxl__device_pci_add() Paul Durrant
2020-12-01 13:51 ` Oleksandr Andrushchenko
2020-11-24 8:01 ` [PATCH v4 10/23] libxl: remove get_all_assigned_devices() from libxl_pci.c Paul Durrant
2020-12-01 14:18 ` Oleksandr Andrushchenko
2020-11-24 8:01 ` [PATCH v4 11/23] libxl: make sure callers of libxl_device_pci_list() free the list after use Paul Durrant
2020-12-01 15:10 ` Oleksandr Andrushchenko
2020-11-24 8:01 ` [PATCH v4 12/23] libxl: add libxl_device_pci_assignable_list_free() Paul Durrant
2020-12-01 15:17 ` Oleksandr Andrushchenko
2020-11-24 8:01 ` [PATCH v4 13/23] libxl: use COMPARE_PCI() macro is_pci_in_array() Paul Durrant
2020-12-01 15:20 ` Oleksandr Andrushchenko
2020-11-24 8:01 ` [PATCH v4 14/23] docs/man: extract documentation of PCI_SPEC_STRING from the xl.cfg manpage Paul Durrant
2020-12-01 15:25 ` Oleksandr Andrushchenko
2020-11-24 8:01 ` [PATCH v4 15/23] docs/man: improve documentation of PCI_SPEC_STRING Paul Durrant
2020-11-24 8:01 ` [PATCH v4 16/23] docs/man: fix xl(1) documentation for 'pci' operations Paul Durrant
2020-11-24 8:01 ` [PATCH v4 17/23] libxl: introduce 'libxl_pci_bdf' in the idl Paul Durrant
2020-11-24 8:01 ` [PATCH v4 18/23] libxlu: introduce xlu_pci_parse_spec_string() Paul Durrant
2020-11-24 8:01 ` [PATCH v4 19/23] libxl: modify libxl_device_pci_assignable_add/remove/list/list_free() Paul Durrant
2020-11-24 8:01 ` [PATCH v4 20/23] docs/man: modify xl(1) in preparation for naming of assignable devices Paul Durrant
2020-11-24 8:01 ` [PATCH v4 21/23] xl / libxl: support " Paul Durrant
2020-11-24 8:01 ` [PATCH v4 22/23] docs/man: modify xl-pci-configuration(5) to add 'name' field to PCI_SPEC_STRING Paul Durrant
2020-11-24 8:01 ` Paul Durrant [this message]
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=20201124080159.11912-24-paul@xen.org \
--to=paul@xen.org \
--cc=anthony.perard@citrix.com \
--cc=iwj@xenproject.org \
--cc=pdurrant@amazon.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).