From nobody Mon Feb 9 19:30:41 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1607455873; cv=none; d=zohomail.com; s=zohoarc; b=GyMJuv1xHWARg3sWnGAcG6/Skc2lZ8H8ngOUa11Ik7wFrt22wnTwWbKzshN1dEvzEAEAkCbVblxQ8jkKLwUaxuaK1mEV71xAQsNqwWVcfivfUGHv0MPCjRZ/IaF3CVGrqgtxkcMmoZt2ke8RdgrZB9es3+Wem4bZmOQ3O8V7+ZM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1607455873; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ksPadBrGqHahICVt3GhGrqsoWKZBYE1bmDQJ3Zcn3LQ=; b=UbKh/N46EhlUmAeXHTfI8xluOXrz/QbOp290YGY3mO1onZGpqatD/LvDjU9br9Dvy9L3qlMv/XW1LuJW5MkqoDKawYDUSDXPKwfM2so8BI1I4QrSEnnw0Q+n+NG1L+Ojm4nuJHTMIhX6I4EC36A7lfxf4FB/2cxwqiLliq1u+1Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1607455873050182.52058106748564; Tue, 8 Dec 2020 11:31:13 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.47686.84415 (Exim 4.92) (envelope-from ) id 1kmihC-0000iu-6Q; Tue, 08 Dec 2020 19:30:46 +0000 Received: by outflank-mailman (output) from mailman id 47686.84415; Tue, 08 Dec 2020 19:30:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kmihC-0000ii-2H; Tue, 08 Dec 2020 19:30:46 +0000 Received: by outflank-mailman (input) for mailman id 47686; Tue, 08 Dec 2020 19:30:44 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kmihA-0000fk-F1 for xen-devel@lists.xenproject.org; Tue, 08 Dec 2020 19:30:44 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kmih9-0007LM-AX; Tue, 08 Dec 2020 19:30:43 +0000 Received: from host86-183-162-145.range86-183.btcentralplus.com ([86.183.162.145] helo=desktop.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kmih9-0001p0-2U; Tue, 08 Dec 2020 19:30:43 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=ksPadBrGqHahICVt3GhGrqsoWKZBYE1bmDQJ3Zcn3LQ=; b=5Z/dwt9+QRVw8sUtsbwUS3/Y/7 VL75Y2FmpZXqSRzR2TYjR+IufvJqWkCxE8uVgGcDBlzsPtZfbQ2FTYVOxVIToPsAbuBxAc6pYbQtF i4FX0TzBbZvEtwyFgWMHh9DXhKjaiM6s+px+WOmY8azThfL8/rM4YuMfVsdBckM2vqUQ=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Oleksandr Andrushchenko , Wei Liu , Ian Jackson , Anthony PERARD Subject: [PATCH v6 03/25] libxl: make libxl__device_list() work correctly for LIBXL__DEVICE_KIND_PCI... Date: Tue, 8 Dec 2020 19:30:11 +0000 Message-Id: <20201208193033.11306-4-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201208193033.11306-1-paul@xen.org> References: <20201208193033.11306-1-paul@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) Content-Type: text/plain; charset="utf-8" From: Paul Durrant ... devices. Currently there is an assumption built into libxl__device_list() that device backends are fully enumarated under the '/libxl' path in xenstore. This is not the case for PCI backend devices, which are only properly enumerated under '/local/domain/0/backend'. This patch adds a new get_path() method to libxl__device_type to allow a backend implementation (such as PCI) to specify the xenstore path where devices are enumerated and modifies libxl__device_list() to use this method if it is available. Also, if the get_num() method is defined then the from_xenstore() method expects to be passed the backend path without the de= vice number concatenated, so this issue is also rectified. Having made libxl__device_list() work correctly, this patch removes the open-coded libxl_pci_device_pci_list() in favour of an evaluation of the LIBXL_DEFINE_DEVICE_LIST() macro. This has the side-effect of also defining libxl_pci_device_pci_list_free() which will be used in subsequent patches. Signed-off-by: Paul Durrant Reviewed-by: Oleksandr Andrushchenko Acked-by: Wei Liu --- Cc: Ian Jackson Cc: Anthony PERARD v3: - New in v3 (replacing "libxl: use LIBXL_DEFINE_DEVICE_LIST for pci device= s") --- tools/include/libxl.h | 7 ++++ tools/libs/light/libxl_device.c | 66 ++++++++++++++++--------------- tools/libs/light/libxl_internal.h | 2 + tools/libs/light/libxl_pci.c | 29 ++++---------- 4 files changed, 52 insertions(+), 52 deletions(-) diff --git a/tools/include/libxl.h b/tools/include/libxl.h index 733263522bd9..bb7fc893fc13 100644 --- a/tools/include/libxl.h +++ b/tools/include/libxl.h @@ -451,6 +451,12 @@ */ #define LIBXL_HAVE_VIRIDIAN_EX_PROCESSOR_MASKS 1 =20 +/* + * LIBXL_HAVE_DEVICE_PCI_LIST_FREE indicates that the + * libxl_device_pci_list_free() function is defined. + */ +#define LIBXL_HAVE_DEVICE_PCI_LIST_FREE 1 + /* * libxl ABI compatibility * @@ -2321,6 +2327,7 @@ int libxl_device_pci_destroy(libxl_ctx *ctx, uint32_t= domid, =20 libxl_device_pci *libxl_device_pci_list(libxl_ctx *ctx, uint32_t domid, int *num); +void libxl_device_pci_list_free(libxl_device_pci* list, int num); =20 /* * Turns the current process into a backend device service daemon diff --git a/tools/libs/light/libxl_device.c b/tools/libs/light/libxl_devic= e.c index e081faf9a94e..ac173a043d31 100644 --- a/tools/libs/light/libxl_device.c +++ b/tools/libs/light/libxl_device.c @@ -2011,7 +2011,7 @@ void *libxl__device_list(libxl__gc *gc, const libxl__= device_type *dt, void *r =3D NULL; void *list =3D NULL; void *item =3D NULL; - char *libxl_path; + char *path; char **dir =3D NULL; unsigned int ndirs =3D 0; unsigned int ndevs =3D 0; @@ -2019,42 +2019,46 @@ void *libxl__device_list(libxl__gc *gc, const libxl= __device_type *dt, =20 *num =3D 0; =20 - libxl_path =3D GCSPRINTF("%s/device/%s", - libxl__xs_libxl_path(gc, domid), - libxl__device_kind_to_string(dt->type)); - - dir =3D libxl__xs_directory(gc, XBT_NULL, libxl_path, &ndirs); + if (dt->get_path) { + rc =3D dt->get_path(gc, domid, &path); + if (rc) goto out; + } else { + path =3D GCSPRINTF("%s/device/%s", + libxl__xs_libxl_path(gc, domid), + libxl__device_kind_to_string(dt->type)); + } =20 - if (dir && ndirs) { - if (dt->get_num) { - if (ndirs !=3D 1) { - LOGD(ERROR, domid, "multiple entries in %s\n", libxl_path); - rc =3D ERROR_FAIL; - goto out; - } - rc =3D dt->get_num(gc, GCSPRINTF("%s/%s", libxl_path, *dir), &= ndevs); - if (rc) goto out; - } else { + if (dt->get_num) { + rc =3D dt->get_num(gc, path, &ndevs); + if (rc) goto out; + } else { + dir =3D libxl__xs_directory(gc, XBT_NULL, path, &ndirs); + if (dir && ndirs) ndevs =3D ndirs; - } - list =3D libxl__malloc(NOGC, dt->dev_elem_size * ndevs); - item =3D list; + } =20 - while (*num < ndevs) { - dt->init(item); + if (!ndevs) + return NULL; =20 - if (dt->from_xenstore) { - int nr =3D dt->get_num ? *num : atoi(*dir); - char *device_libxl_path =3D GCSPRINTF("%s/%s", libxl_path,= *dir); - rc =3D dt->from_xenstore(gc, device_libxl_path, nr, item); - if (rc) goto out; - } + list =3D libxl__malloc(NOGC, dt->dev_elem_size * ndevs); + item =3D list; =20 - item =3D (uint8_t *)item + dt->dev_elem_size; - ++(*num); - if (!dt->get_num) - ++dir; + while (*num < ndevs) { + dt->init(item); + + if (dt->from_xenstore) { + int nr =3D dt->get_num ? *num : atoi(*dir); + char *device_path =3D dt->get_num ? path : + GCSPRINTF("%s/%d", path, nr); + + rc =3D dt->from_xenstore(gc, device_path, nr, item); + if (rc) goto out; } + + item =3D (uint8_t *)item + dt->dev_elem_size; + ++(*num); + if (!dt->get_num) + ++dir; } =20 r =3D list; diff --git a/tools/libs/light/libxl_internal.h b/tools/libs/light/libxl_int= ernal.h index c2c5a9b92673..d0c23def3c3e 100644 --- a/tools/libs/light/libxl_internal.h +++ b/tools/libs/light/libxl_internal.h @@ -3917,6 +3917,7 @@ typedef int (*device_dm_needed_fn_t)(void *, unsigned= ); typedef void (*device_update_config_fn_t)(libxl__gc *, void *, void *); typedef int (*device_update_devid_fn_t)(libxl__gc *, uint32_t, void *); typedef int (*device_get_num_fn_t)(libxl__gc *, const char *, unsigned int= *); +typedef int (*device_get_path_fn_t)(libxl__gc *, uint32_t, char **); typedef int (*device_from_xenstore_fn_t)(libxl__gc *, const char *, libxl_devid, void *); typedef int (*device_set_xenstore_config_fn_t)(libxl__gc *, uint32_t, void= *, @@ -3941,6 +3942,7 @@ struct libxl__device_type { device_update_config_fn_t update_config; device_update_devid_fn_t update_devid; device_get_num_fn_t get_num; + device_get_path_fn_t get_path; device_from_xenstore_fn_t from_xenstore; device_set_xenstore_config_fn_t set_xenstore_config; }; diff --git a/tools/libs/light/libxl_pci.c b/tools/libs/light/libxl_pci.c index 3340076d2cb3..d536702ac420 100644 --- a/tools/libs/light/libxl_pci.c +++ b/tools/libs/light/libxl_pci.c @@ -2393,29 +2393,13 @@ static int libxl__device_pci_get_num(libxl__gc *gc,= const char *be_path, return rc; } =20 -libxl_device_pci *libxl_device_pci_list(libxl_ctx *ctx, uint32_t domid, in= t *num) +static int libxl__device_pci_get_path(libxl__gc *gc, uint32_t domid, + char **path) { - GC_INIT(ctx); - char *be_path; - unsigned int n, i; - libxl_device_pci *pcis =3D NULL; - - *num =3D 0; - - be_path =3D libxl__domain_device_backend_path(gc, 0, domid, 0, - LIBXL__DEVICE_KIND_PCI); - if (libxl__device_pci_get_num(gc, be_path, &n)) - goto out; + *path =3D libxl__domain_device_backend_path(gc, 0, domid, 0, + LIBXL__DEVICE_KIND_PCI); =20 - pcis =3D calloc(n, sizeof(libxl_device_pci)); - - for (i =3D 0; i < n; i++) - libxl__device_pci_from_xs_be(gc, be_path, i, pcis + i); - - *num =3D n; -out: - GC_FREE; - return pcis; + return 0; } =20 void libxl__device_pci_destroy_all(libxl__egc *egc, uint32_t domid, @@ -2492,10 +2476,13 @@ static int libxl_device_pci_compare(const libxl_dev= ice_pci *d1, return COMPARE_PCI(d1, d2); } =20 +LIBXL_DEFINE_DEVICE_LIST(pci) + #define libxl__device_pci_update_devid NULL =20 DEFINE_DEVICE_TYPE_STRUCT(pci, PCI, pcidevs, .get_num =3D libxl__device_pci_get_num, + .get_path =3D libxl__device_pci_get_path, .from_xenstore =3D libxl__device_pci_from_xs_be, ); =20 --=20 2.20.1