From nobody Sun May 5 11:10:29 2024 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=1603470242; cv=none; d=zohomail.com; s=zohoarc; b=n5r+tOzJN9cWQie32Ma6wIKN49kSVOlKP06VFDCCtEXx+SiGfOtzWp2xaiW+UazifNw5HyiwVFF0kVxWht/WxkGibUqH052QC97Hb4f7ddQ7NoBFBAgy0WKBa124jv/IDT4syB6ygJV6au/2XcvrO9f6E+R8B0QIetsIjuCuLeA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603470242; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=2Epbe5jjBp/+RA6U7S2vptokK57Dpce2kJ38YAOJuqY=; b=JUB0OqMyLNxeWi4CF/w7e7zEc64ZrGGeWxU0wrjz7FONYdIBXDG82FFI9iV9zx30S75M/5Q3uDfpHZfUpzXqOK15M3M48KpnqqflbVU1ncoB0iuYoh4KZ9hLuj6DvShzPgK+b41vjLvrM1kkR/TDeI6RgkS56k5q7S7tMYnBSgc= 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 1603470242418623.731478578325; Fri, 23 Oct 2020 09:24:02 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.11164.29633 (Exim 4.92) (envelope-from ) id 1kVzqt-0008MW-D7; Fri, 23 Oct 2020 16:23:39 +0000 Received: by outflank-mailman (output) from mailman id 11164.29633; Fri, 23 Oct 2020 16:23:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzqt-0008M9-5T; Fri, 23 Oct 2020 16:23:39 +0000 Received: by outflank-mailman (input) for mailman id 11164; Fri, 23 Oct 2020 16:23:37 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzqr-00081e-CW for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:23:37 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 21eda335-bcb2-431d-8b54-8363e40956a4; Fri, 23 Oct 2020 16:23:22 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzqb-0008Iw-64; Fri, 23 Oct 2020 16:23:21 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqa-000376-MR; Fri, 23 Oct 2020 16:23:21 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzqr-00081e-CW for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:23:37 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 21eda335-bcb2-431d-8b54-8363e40956a4; Fri, 23 Oct 2020 16:23:22 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzqb-0008Iw-64; Fri, 23 Oct 2020 16:23:21 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqa-000376-MR; Fri, 23 Oct 2020 16:23:21 +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" X-Inumbo-ID: 21eda335-bcb2-431d-8b54-8363e40956a4 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=2Epbe5jjBp/+RA6U7S2vptokK57Dpce2kJ38YAOJuqY=; b=AdOIB0mG+bpDznfUEDEzTL6BL gaezcrVA48p/TZuC6W2jAHliQEDFbwJei9i6MeARq9vrLiYOYIw1joNQCeNpe61DghMTwW5gWAOgw 5mWLqGZAmBqT5oFw3SI80pQ3VauWzGSGI5WshuurDrJWRHxtA6ZlBpmbLvdr/uoDAD6jI=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH 01/25] xl / libxl: s/pcidev/pci and remove DEFINE_DEVICE_TYPE_STRUCT_X Date: Fri, 23 Oct 2020 16:22:50 +0000 Message-Id: <20201023162314.2235-2-paul@xen.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20201023162314.2235-1-paul@xen.org> References: <20201023162314.2235-1-paul@xen.org> X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paul Durrant The seemingly arbitrary use of 'pci' and 'pcidev' in the code in libxl_pci.c is confusing and also compromises use of some macros used for other device types. Indeed it seems that DEFINE_DEVICE_TYPE_STRUCT_X exists solely becau= se of this duality. This patch purges use of 'pcidev' from the libxl code, allowing evaluation = of DEFINE_DEVICE_TYPE_STRUCT_X to be replaced with DEFINE_DEVICE_TYPE_STRUCT, hence allowing removal of the former. For consistency the xl and libs/util code is also modified, but in this case it is purely cosmetic. NOTE: Some of the more gross formatting errors (such as lack of spaces after keywords) that came into context have been fixed in libxl_pci.c. Signed-off-by: Paul Durrant Acked-by: Christian Lindig --- Cc: Ian Jackson Cc: Wei Liu Cc: Anthony PERARD --- tools/include/libxl.h | 17 +- tools/libs/light/libxl_create.c | 6 +- tools/libs/light/libxl_dm.c | 18 +- tools/libs/light/libxl_internal.h | 45 ++- tools/libs/light/libxl_pci.c | 582 +++++++++++++++++++---------------= ---- tools/libs/light/libxl_types.idl | 2 +- tools/libs/util/libxlu_pci.c | 36 +-- tools/xl/xl_parse.c | 28 +- tools/xl/xl_pci.c | 68 ++--- tools/xl/xl_sxp.c | 12 +- 10 files changed, 409 insertions(+), 405 deletions(-) diff --git a/tools/include/libxl.h b/tools/include/libxl.h index 1ea5b4f446..fbe4c81ba5 100644 --- a/tools/include/libxl.h +++ b/tools/include/libxl.h @@ -445,6 +445,13 @@ #define LIBXL_HAVE_DISK_SAFE_REMOVE 1 =20 /* + * LIBXL_HAVE_CONFIG_PCIS indicates that the 'pcidevs' and 'num_pcidevs' + * fields in libxl_domain_config have been renamed to 'pcis' and 'num_pcis' + * respectively. + */ +#define LIBXL_HAVE_CONFIG_PCIS 1 + +/* * libxl ABI compatibility * * The only guarantee which libxl makes regarding ABI compatibility @@ -2300,15 +2307,15 @@ int libxl_device_pvcallsif_destroy(libxl_ctx *ctx, = uint32_t domid, =20 /* PCI Passthrough */ int libxl_device_pci_add(libxl_ctx *ctx, uint32_t domid, - libxl_device_pci *pcidev, + libxl_device_pci *pci, const libxl_asyncop_how *ao_how) LIBXL_EXTERNAL_CALLERS_ONLY; int libxl_device_pci_remove(libxl_ctx *ctx, uint32_t domid, - libxl_device_pci *pcidev, + libxl_device_pci *pci, const libxl_asyncop_how *ao_how) LIBXL_EXTERNAL_CALLERS_ONLY; int libxl_device_pci_destroy(libxl_ctx *ctx, uint32_t domid, - libxl_device_pci *pcidev, + libxl_device_pci *pci, const libxl_asyncop_how *ao_how) LIBXL_EXTERNAL_CALLERS_ONLY; =20 @@ -2352,8 +2359,8 @@ int libxl_device_events_handler(libxl_ctx *ctx, * added or is not bound, the functions will emit a warning but return * SUCCESS. */ -int libxl_device_pci_assignable_add(libxl_ctx *ctx, libxl_device_pci *pcid= ev, int rebind); -int libxl_device_pci_assignable_remove(libxl_ctx *ctx, libxl_device_pci *p= cidev, int rebind); +int libxl_device_pci_assignable_add(libxl_ctx *ctx, libxl_device_pci *pci,= int rebind); +int libxl_device_pci_assignable_remove(libxl_ctx *ctx, libxl_device_pci *p= ci, int rebind); libxl_device_pci *libxl_device_pci_assignable_list(libxl_ctx *ctx, int *nu= m); =20 /* CPUID handling */ diff --git a/tools/libs/light/libxl_create.c b/tools/libs/light/libxl_creat= e.c index 321a13e519..1f5052c520 100644 --- a/tools/libs/light/libxl_create.c +++ b/tools/libs/light/libxl_create.c @@ -1100,7 +1100,7 @@ int libxl__domain_config_setdefault(libxl__gc *gc, goto error_out; } =20 - bool need_pt =3D d_config->num_pcidevs || d_config->num_dtdevs; + bool need_pt =3D d_config->num_pcis || d_config->num_dtdevs; if (c_info->passthrough =3D=3D LIBXL_PASSTHROUGH_DEFAULT) { c_info->passthrough =3D need_pt ? LIBXL_PASSTHROUGH_ENABLED : LIBXL_PASSTHROUGH_DISABLED; @@ -1141,7 +1141,7 @@ int libxl__domain_config_setdefault(libxl__gc *gc, * assignment when PoD is enabled. */ if (d_config->c_info.type !=3D LIBXL_DOMAIN_TYPE_PV && - d_config->num_pcidevs && pod_enabled) { + d_config->num_pcis && pod_enabled) { ret =3D ERROR_INVAL; LOGD(ERROR, domid, "PCI device assignment for HVM guest failed due to PoD enable= d"); @@ -1817,7 +1817,7 @@ const libxl__device_type *device_type_tbl[] =3D { &libxl__vtpm_devtype, &libxl__usbctrl_devtype, &libxl__usbdev_devtype, - &libxl__pcidev_devtype, + &libxl__pci_devtype, &libxl__dtdev_devtype, &libxl__vdispl_devtype, &libxl__vsnd_devtype, diff --git a/tools/libs/light/libxl_dm.c b/tools/libs/light/libxl_dm.c index d1ff35dda3..f147a733c8 100644 --- a/tools/libs/light/libxl_dm.c +++ b/tools/libs/light/libxl_dm.c @@ -442,7 +442,7 @@ int libxl__domain_device_construct_rdm(libxl__gc *gc, =20 /* Might not expose rdm. */ if (strategy =3D=3D LIBXL_RDM_RESERVE_STRATEGY_IGNORE && - !d_config->num_pcidevs) + !d_config->num_pcis) return 0; =20 /* Query all RDM entries in this platform */ @@ -469,13 +469,13 @@ int libxl__domain_device_construct_rdm(libxl__gc *gc, } =20 /* Query RDM entries per-device */ - for (i =3D 0; i < d_config->num_pcidevs; i++) { + for (i =3D 0; i < d_config->num_pcis; i++) { unsigned int n, nr_entries; =20 - seg =3D d_config->pcidevs[i].domain; - bus =3D d_config->pcidevs[i].bus; - devfn =3D PCI_DEVFN(d_config->pcidevs[i].dev, - d_config->pcidevs[i].func); + seg =3D d_config->pcis[i].domain; + bus =3D d_config->pcis[i].bus; + devfn =3D PCI_DEVFN(d_config->pcis[i].dev, + d_config->pcis[i].func); nr_entries =3D 0; rc =3D libxl__xc_device_get_rdm(gc, 0, seg, bus, devfn, &nr_entries, &xrdm); @@ -488,7 +488,7 @@ int libxl__domain_device_construct_rdm(libxl__gc *gc, assert(xrdm); =20 rc =3D libxl__device_pci_setdefault(gc, DOMID_INVALID, - &d_config->pcidevs[i], false); + &d_config->pcis[i], false); if (rc) goto out; =20 @@ -516,7 +516,7 @@ int libxl__domain_device_construct_rdm(libxl__gc *gc, * global policy in this case. */ d_config->rdms[j].policy - =3D d_config->pcidevs[i].rdm_policy; + =3D d_config->pcis[i].rdm_policy; new =3D false; break; } @@ -526,7 +526,7 @@ int libxl__domain_device_construct_rdm(libxl__gc *gc, add_rdm_entry(gc, d_config, pfn_to_paddr(xrdm[n].start_pfn), pfn_to_paddr(xrdm[n].nr_pages), - d_config->pcidevs[i].rdm_policy); + d_config->pcis[i].rdm_policy); } } =20 diff --git a/tools/libs/light/libxl_internal.h b/tools/libs/light/libxl_int= ernal.h index e26cda9b50..3e70ff639b 100644 --- a/tools/libs/light/libxl_internal.h +++ b/tools/libs/light/libxl_internal.h @@ -1709,7 +1709,7 @@ _hidden int libxl__pci_topology_init(libxl__gc *gc, /* from libxl_pci */ =20 _hidden void libxl__device_pci_add(libxl__egc *egc, uint32_t domid, - libxl_device_pci *pcidev, bool starting, + libxl_device_pci *pci, bool starting, libxl__ao_device *aodev); _hidden void libxl__device_pci_destroy_all(libxl__egc *egc, uint32_t domid, libxl__multidev *); @@ -3945,30 +3945,27 @@ struct libxl__device_type { device_set_xenstore_config_fn_t set_xenstore_config; }; =20 -#define DEFINE_DEVICE_TYPE_STRUCT_X(name, sname, kind, ...) = \ - const libxl__device_type libxl__ ## name ## _devtype =3D { = \ - .type =3D LIBXL__DEVICE_KIND_ ## kind, = \ - .ptr_offset =3D offsetof(libxl_domain_config, name ## s), = \ - .num_offset =3D offsetof(libxl_domain_config, num_ ## name ## s= ), \ - .dev_elem_size =3D sizeof(libxl_device_ ## sname), = \ - .add =3D libxl__add_ ## name ## s, = \ - .set_default =3D (device_set_default_fn_t) = \ - libxl__device_ ## sname ## _setdefault, = \ - .to_device =3D (device_to_device_fn_t)libxl__device_from_ ## n= ame, \ - .init =3D (device_init_fn_t)libxl_device_ ## sname ## _in= it, \ - .copy =3D (device_copy_fn_t)libxl_device_ ## sname ## _co= py, \ - .dispose =3D (device_dispose_fn_t) = \ - libxl_device_ ## sname ## _dispose, = \ - .compare =3D (device_compare_fn_t) = \ - libxl_device_ ## sname ## _compare, = \ - .update_devid =3D (device_update_devid_fn_t) = \ - libxl__device_ ## sname ## _update_devid, = \ - __VA_ARGS__ = \ +#define DEFINE_DEVICE_TYPE_STRUCT(name, kind, ...) = \ + const libxl__device_type libxl__ ## name ## _devtype =3D { = \ + .type =3D LIBXL__DEVICE_KIND_ ## kind, = \ + .ptr_offset =3D offsetof(libxl_domain_config, name ## s), = \ + .num_offset =3D offsetof(libxl_domain_config, num_ ## name ## s= ), \ + .dev_elem_size =3D sizeof(libxl_device_ ## name), = \ + .add =3D libxl__add_ ## name ## s, = \ + .set_default =3D (device_set_default_fn_t) = \ + libxl__device_ ## name ## _setdefault, = \ + .to_device =3D (device_to_device_fn_t)libxl__device_from_ ## n= ame, \ + .init =3D (device_init_fn_t)libxl_device_ ## name ## _ini= t, \ + .copy =3D (device_copy_fn_t)libxl_device_ ## name ## _cop= y, \ + .dispose =3D (device_dispose_fn_t) = \ + libxl_device_ ## name ## _dispose, = \ + .compare =3D (device_compare_fn_t) = \ + libxl_device_ ## name ## _compare, = \ + .update_devid =3D (device_update_devid_fn_t) = \ + libxl__device_ ## name ## _update_devid, = \ + __VA_ARGS__ = \ } =20 -#define DEFINE_DEVICE_TYPE_STRUCT(name, kind, ...) = \ - DEFINE_DEVICE_TYPE_STRUCT_X(name, name, kind, __VA_ARGS__) - static inline void **libxl__device_type_get_ptr( const libxl__device_type *dt, const libxl_domain_config *d_config) { @@ -3995,7 +3992,7 @@ extern const libxl__device_type libxl__nic_devtype; extern const libxl__device_type libxl__vtpm_devtype; extern const libxl__device_type libxl__usbctrl_devtype; extern const libxl__device_type libxl__usbdev_devtype; -extern const libxl__device_type libxl__pcidev_devtype; +extern const libxl__device_type libxl__pci_devtype; extern const libxl__device_type libxl__vdispl_devtype; extern const libxl__device_type libxl__p9_devtype; extern const libxl__device_type libxl__pvcallsif_devtype; diff --git a/tools/libs/light/libxl_pci.c b/tools/libs/light/libxl_pci.c index bc5843b137..2ff1c64a31 100644 --- a/tools/libs/light/libxl_pci.c +++ b/tools/libs/light/libxl_pci.c @@ -25,51 +25,51 @@ #define PCI_BDF_XSPATH "%04x-%02x-%02x-%01x" #define PCI_PT_QDEV_ID "pci-pt-%02x_%02x.%01x" =20 -static unsigned int pcidev_encode_bdf(libxl_device_pci *pcidev) +static unsigned int pci_encode_bdf(libxl_device_pci *pci) { unsigned int value; =20 - value =3D pcidev->domain << 16; - value |=3D (pcidev->bus & 0xff) << 8; - value |=3D (pcidev->dev & 0x1f) << 3; - value |=3D (pcidev->func & 0x7); + value =3D pci->domain << 16; + value |=3D (pci->bus & 0xff) << 8; + value |=3D (pci->dev & 0x1f) << 3; + value |=3D (pci->func & 0x7); =20 return value; } =20 -static void pcidev_struct_fill(libxl_device_pci *pcidev, unsigned int doma= in, - unsigned int bus, unsigned int dev, - unsigned int func, unsigned int vdevfn) +static void pci_struct_fill(libxl_device_pci *pci, unsigned int domain, + unsigned int bus, unsigned int dev, + unsigned int func, unsigned int vdevfn) { - pcidev->domain =3D domain; - pcidev->bus =3D bus; - pcidev->dev =3D dev; - pcidev->func =3D func; - pcidev->vdevfn =3D vdevfn; + pci->domain =3D domain; + pci->bus =3D bus; + pci->dev =3D dev; + pci->func =3D func; + pci->vdevfn =3D vdevfn; } =20 static void libxl_create_pci_backend_device(libxl__gc *gc, flexarray_t *back, int num, - const libxl_device_pci *pcidev) + const libxl_device_pci *pci) { flexarray_append(back, GCSPRINTF("key-%d", num)); - flexarray_append(back, GCSPRINTF(PCI_BDF, pcidev->domain, pcidev->bus,= pcidev->dev, pcidev->func)); + flexarray_append(back, GCSPRINTF(PCI_BDF, pci->domain, pci->bus, pci->= dev, pci->func)); flexarray_append(back, GCSPRINTF("dev-%d", num)); - flexarray_append(back, GCSPRINTF(PCI_BDF, pcidev->domain, pcidev->bus,= pcidev->dev, pcidev->func)); - if (pcidev->vdevfn) - flexarray_append_pair(back, GCSPRINTF("vdevfn-%d", num), GCSPRINTF= ("%x", pcidev->vdevfn)); + flexarray_append(back, GCSPRINTF(PCI_BDF, pci->domain, pci->bus, pci->= dev, pci->func)); + if (pci->vdevfn) + flexarray_append_pair(back, GCSPRINTF("vdevfn-%d", num), GCSPRINTF= ("%x", pci->vdevfn)); flexarray_append(back, GCSPRINTF("opts-%d", num)); flexarray_append(back, GCSPRINTF("msitranslate=3D%d,power_mgmt=3D%d,permissive=3D%d= ", - pcidev->msitranslate, pcidev->power_mgmt, - pcidev->permissive)); + pci->msitranslate, pci->power_mgmt, + pci->permissive)); flexarray_append_pair(back, GCSPRINTF("state-%d", num), GCSPRINTF("%d"= , XenbusStateInitialising)); } =20 -static void libxl__device_from_pcidev(libxl__gc *gc, uint32_t domid, - const libxl_device_pci *pcidev, - libxl__device *device) +static void libxl__device_from_pci(libxl__gc *gc, uint32_t domid, + const libxl_device_pci *pci, + libxl__device *device) { device->backend_devid =3D 0; device->backend_domid =3D 0; @@ -80,7 +80,7 @@ static void libxl__device_from_pcidev(libxl__gc *gc, uint= 32_t domid, } =20 static int libxl__create_pci_backend(libxl__gc *gc, uint32_t domid, - const libxl_device_pci *pcidev, + const libxl_device_pci *pci, int num) { flexarray_t *front =3D NULL; @@ -94,15 +94,15 @@ static int libxl__create_pci_backend(libxl__gc *gc, uin= t32_t domid, LOGD(DEBUG, domid, "Creating pci backend"); =20 /* add pci device */ - libxl__device_from_pcidev(gc, domid, pcidev, &device); + libxl__device_from_pci(gc, domid, pci, &device); =20 flexarray_append_pair(back, "frontend-id", GCSPRINTF("%d", domid)); flexarray_append_pair(back, "online", "1"); flexarray_append_pair(back, "state", GCSPRINTF("%d", XenbusStateInitia= lising)); flexarray_append_pair(back, "domain", libxl__domid_to_name(gc, domid)); =20 - for (i =3D 0; i < num; i++, pcidev++) - libxl_create_pci_backend_device(gc, back, i, pcidev); + for (i =3D 0; i < num; i++, pci++) + libxl_create_pci_backend_device(gc, back, i, pci); =20 flexarray_append_pair(back, "num_devs", GCSPRINTF("%d", num)); flexarray_append_pair(front, "backend-id", GCSPRINTF("%d", 0)); @@ -116,7 +116,7 @@ static int libxl__create_pci_backend(libxl__gc *gc, uin= t32_t domid, =20 static int libxl__device_pci_add_xenstore(libxl__gc *gc, uint32_t domid, - const libxl_device_pci *pcidev, + const libxl_device_pci *pci, bool starting) { flexarray_t *back; @@ -136,7 +136,7 @@ static int libxl__device_pci_add_xenstore(libxl__gc *gc, LIBXL__DEVICE_KIND_PCI); num_devs =3D libxl__xs_read(gc, XBT_NULL, GCSPRINTF("%s/num_devs", be_= path)); if (!num_devs) - return libxl__create_pci_backend(gc, domid, pcidev, 1); + return libxl__create_pci_backend(gc, domid, pci, 1); =20 libxl_domain_type domtype =3D libxl__domain_type(gc, domid); if (domtype =3D=3D LIBXL_DOMAIN_TYPE_INVALID) @@ -151,7 +151,7 @@ static int libxl__device_pci_add_xenstore(libxl__gc *gc, =20 LOGD(DEBUG, domid, "Adding new pci device to xenstore"); num =3D atoi(num_devs); - libxl_create_pci_backend_device(gc, back, num, pcidev); + libxl_create_pci_backend_device(gc, back, num, pci); flexarray_append_pair(back, "num_devs", GCSPRINTF("%d", num + 1)); if (!starting) flexarray_append_pair(back, "state", GCSPRINTF("%d", XenbusStateRe= configuring)); @@ -170,8 +170,8 @@ static int libxl__device_pci_add_xenstore(libxl__gc *gc, rc =3D libxl__get_domain_configuration(gc, domid, &d_config); if (rc) goto out; =20 - device_add_domain_config(gc, &d_config, &libxl__pcidev_devtype, - pcidev); + device_add_domain_config(gc, &d_config, &libxl__pci_devtype, + pci); =20 rc =3D libxl__dm_check_start(gc, &d_config, domid); if (rc) goto out; @@ -201,7 +201,7 @@ out: return rc; } =20 -static int libxl__device_pci_remove_xenstore(libxl__gc *gc, uint32_t domid= , libxl_device_pci *pcidev) +static int libxl__device_pci_remove_xenstore(libxl__gc *gc, uint32_t domid= , libxl_device_pci *pci) { libxl_ctx *ctx =3D libxl__gc_owner(gc); char *be_path, *num_devs_path, *num_devs, *xsdev, *tmp, *tmppath; @@ -231,8 +231,8 @@ static int libxl__device_pci_remove_xenstore(libxl__gc = *gc, uint32_t domid, libx unsigned int domain =3D 0, bus =3D 0, dev =3D 0, func =3D 0; xsdev =3D libxl__xs_read(gc, XBT_NULL, GCSPRINTF("%s/dev-%d", be_p= ath, i)); sscanf(xsdev, PCI_BDF, &domain, &bus, &dev, &func); - if (domain =3D=3D pcidev->domain && bus =3D=3D pcidev->bus && - pcidev->dev =3D=3D dev && pcidev->func =3D=3D func) { + if (domain =3D=3D pci->domain && bus =3D=3D pci->bus && + pci->dev =3D=3D dev && pci->func =3D=3D func) { break; } } @@ -350,7 +350,7 @@ static int get_all_assigned_devices(libxl__gc *gc, libx= l_device_pci **list, int *list =3D realloc(*list, sizeof(libxl_device_pci) * ((= *num) + 1)); if (*list =3D=3D NULL) return ERROR_NOMEM; - pcidev_struct_fill(*list + *num, dom, bus, dev, func, = 0); + pci_struct_fill(*list + *num, dom, bus, dev, func, 0); (*num)++; } } @@ -361,8 +361,8 @@ static int get_all_assigned_devices(libxl__gc *gc, libx= l_device_pci **list, int return 0; } =20 -static int is_pcidev_in_array(libxl_device_pci *assigned, int num_assigned, - int dom, int bus, int dev, int func) +static int is_pci_in_array(libxl_device_pci *assigned, int num_assigned, + int dom, int bus, int dev, int func) { int i; =20 @@ -383,7 +383,7 @@ static int is_pcidev_in_array(libxl_device_pci *assigne= d, int num_assigned, =20 /* Write the standard BDF into the sysfs path given by sysfs_path. */ static int sysfs_write_bdf(libxl__gc *gc, const char * sysfs_path, - libxl_device_pci *pcidev) + libxl_device_pci *pci) { int rc, fd; char *buf; @@ -394,8 +394,8 @@ static int sysfs_write_bdf(libxl__gc *gc, const char * = sysfs_path, return ERROR_FAIL; } =20 - buf =3D GCSPRINTF(PCI_BDF, pcidev->domain, pcidev->bus, - pcidev->dev, pcidev->func); + buf =3D GCSPRINTF(PCI_BDF, pci->domain, pci->bus, + pci->dev, pci->func); rc =3D write(fd, buf, strlen(buf)); /* Annoying to have two if's, but we need the errno */ if (rc < 0) @@ -411,7 +411,7 @@ static int sysfs_write_bdf(libxl__gc *gc, const char * = sysfs_path, libxl_device_pci *libxl_device_pci_assignable_list(libxl_ctx *ctx, int *nu= m) { GC_INIT(ctx); - libxl_device_pci *pcidevs =3D NULL, *new, *assigned; + libxl_device_pci *pcis =3D NULL, *new, *assigned; struct dirent *de; DIR *dir; int r, num_assigned; @@ -436,40 +436,40 @@ libxl_device_pci *libxl_device_pci_assignable_list(li= bxl_ctx *ctx, int *num) if (sscanf(de->d_name, PCI_BDF, &dom, &bus, &dev, &func) !=3D 4) continue; =20 - if (is_pcidev_in_array(assigned, num_assigned, dom, bus, dev, func= )) + if (is_pci_in_array(assigned, num_assigned, dom, bus, dev, func)) continue; =20 - new =3D realloc(pcidevs, ((*num) + 1) * sizeof(*new)); + new =3D realloc(pcis, ((*num) + 1) * sizeof(*new)); if (NULL =3D=3D new) continue; =20 - pcidevs =3D new; - new =3D pcidevs + *num; + pcis =3D new; + new =3D pcis + *num; =20 memset(new, 0, sizeof(*new)); - pcidev_struct_fill(new, dom, bus, dev, func, 0); + pci_struct_fill(new, dom, bus, dev, func, 0); (*num)++; } =20 closedir(dir); out: GC_FREE; - return pcidevs; + return pcis; } =20 /* Unbind device from its current driver, if any. If driver_path is non-N= ULL, * store the path to the original driver in it. */ -static int sysfs_dev_unbind(libxl__gc *gc, libxl_device_pci *pcidev, +static int sysfs_dev_unbind(libxl__gc *gc, libxl_device_pci *pci, char **driver_path) { char * spath, *dp =3D NULL; struct stat st; =20 spath =3D GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/driver", - pcidev->domain, - pcidev->bus, - pcidev->dev, - pcidev->func); + pci->domain, + pci->bus, + pci->dev, + pci->func); if ( !lstat(spath, &st) ) { /* Find the canonical path to the driver. */ dp =3D libxl__zalloc(gc, PATH_MAX); @@ -483,7 +483,7 @@ static int sysfs_dev_unbind(libxl__gc *gc, libxl_device= _pci *pcidev, =20 /* Unbind from the old driver */ spath =3D GCSPRINTF("%s/unbind", dp); - if ( sysfs_write_bdf(gc, spath, pcidev) < 0 ) { + if ( sysfs_write_bdf(gc, spath, pci) < 0 ) { LOGE(ERROR, "Couldn't unbind device"); return -1; } @@ -495,11 +495,11 @@ static int sysfs_dev_unbind(libxl__gc *gc, libxl_devi= ce_pci *pcidev, return 0; } =20 -static uint16_t sysfs_dev_get_vendor(libxl__gc *gc, libxl_device_pci *pcid= ev) +static uint16_t sysfs_dev_get_vendor(libxl__gc *gc, libxl_device_pci *pci) { char *pci_device_vendor_path =3D GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/vendor", - pcidev->domain, pcidev->bus, pcidev->dev, pcidev->fu= nc); + pci->domain, pci->bus, pci->dev, pci->func); uint16_t read_items; uint16_t pci_device_vendor; =20 @@ -507,7 +507,7 @@ static uint16_t sysfs_dev_get_vendor(libxl__gc *gc, lib= xl_device_pci *pcidev) if (!f) { LOGE(ERROR, "pci device "PCI_BDF" does not have vendor attribute", - pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func); + pci->domain, pci->bus, pci->dev, pci->func); return 0xffff; } read_items =3D fscanf(f, "0x%hx\n", &pci_device_vendor); @@ -515,18 +515,18 @@ static uint16_t sysfs_dev_get_vendor(libxl__gc *gc, l= ibxl_device_pci *pcidev) if (read_items !=3D 1) { LOGE(ERROR, "cannot read vendor of pci device "PCI_BDF, - pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func); + pci->domain, pci->bus, pci->dev, pci->func); return 0xffff; } =20 return pci_device_vendor; } =20 -static uint16_t sysfs_dev_get_device(libxl__gc *gc, libxl_device_pci *pcid= ev) +static uint16_t sysfs_dev_get_device(libxl__gc *gc, libxl_device_pci *pci) { char *pci_device_device_path =3D GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/device", - pcidev->domain, pcidev->bus, pcidev->dev, pcidev->fu= nc); + pci->domain, pci->bus, pci->dev, pci->func); uint16_t read_items; uint16_t pci_device_device; =20 @@ -534,7 +534,7 @@ static uint16_t sysfs_dev_get_device(libxl__gc *gc, lib= xl_device_pci *pcidev) if (!f) { LOGE(ERROR, "pci device "PCI_BDF" does not have device attribute", - pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func); + pci->domain, pci->bus, pci->dev, pci->func); return 0xffff; } read_items =3D fscanf(f, "0x%hx\n", &pci_device_device); @@ -542,25 +542,25 @@ static uint16_t sysfs_dev_get_device(libxl__gc *gc, l= ibxl_device_pci *pcidev) if (read_items !=3D 1) { LOGE(ERROR, "cannot read device of pci device "PCI_BDF, - pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func); + pci->domain, pci->bus, pci->dev, pci->func); return 0xffff; } =20 return pci_device_device; } =20 -static int sysfs_dev_get_class(libxl__gc *gc, libxl_device_pci *pcidev, +static int sysfs_dev_get_class(libxl__gc *gc, libxl_device_pci *pci, unsigned long *class) { char *pci_device_class_path =3D GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/cla= ss", - pcidev->domain, pcidev->bus, pcidev->dev, pcidev->fun= c); + pci->domain, pci->bus, pci->dev, pci->func); int read_items, ret =3D 0; =20 FILE *f =3D fopen(pci_device_class_path, "r"); if (!f) { LOGE(ERROR, "pci device "PCI_BDF" does not have class attribute", - pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func); + pci->domain, pci->bus, pci->dev, pci->func); ret =3D ERROR_FAIL; goto out; } @@ -569,7 +569,7 @@ static int sysfs_dev_get_class(libxl__gc *gc, libxl_dev= ice_pci *pcidev, if (read_items !=3D 1) { LOGE(ERROR, "cannot read class of pci device "PCI_BDF, - pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func); + pci->domain, pci->bus, pci->dev, pci->func); ret =3D ERROR_FAIL; } =20 @@ -588,16 +588,16 @@ bool libxl__is_igd_vga_passthru(libxl__gc *gc, uint16_t pt_vendor, pt_device; unsigned long class; =20 - for (i =3D 0 ; i < d_config->num_pcidevs ; i++) { - libxl_device_pci *pcidev =3D &d_config->pcidevs[i]; - pt_vendor =3D sysfs_dev_get_vendor(gc, pcidev); - pt_device =3D sysfs_dev_get_device(gc, pcidev); + for (i =3D 0 ; i < d_config->num_pcis ; i++) { + libxl_device_pci *pci =3D &d_config->pcis[i]; + pt_vendor =3D sysfs_dev_get_vendor(gc, pci); + pt_device =3D sysfs_dev_get_device(gc, pci); =20 if (pt_vendor =3D=3D 0xffff || pt_device =3D=3D 0xffff || pt_vendor !=3D 0x8086) continue; =20 - if (sysfs_dev_get_class(gc, pcidev, &class)) + if (sysfs_dev_get_class(gc, pci, &class)) continue; if (class =3D=3D 0x030000) return true; @@ -621,8 +621,8 @@ bool libxl__is_igd_vga_passthru(libxl__gc *gc, * already exist. */ =20 -/* Scan through /sys/.../pciback/slots looking for pcidev's BDF */ -static int pciback_dev_has_slot(libxl__gc *gc, libxl_device_pci *pcidev) +/* Scan through /sys/.../pciback/slots looking for pci's BDF */ +static int pciback_dev_has_slot(libxl__gc *gc, libxl_device_pci *pci) { FILE *f; int rc =3D 0; @@ -635,11 +635,11 @@ static int pciback_dev_has_slot(libxl__gc *gc, libxl_= device_pci *pcidev) return ERROR_FAIL; } =20 - while(fscanf(f, "%x:%x:%x.%d\n", &dom, &bus, &dev, &func)=3D=3D4) { - if(dom =3D=3D pcidev->domain - && bus =3D=3D pcidev->bus - && dev =3D=3D pcidev->dev - && func =3D=3D pcidev->func) { + while (fscanf(f, "%x:%x:%x.%d\n", &dom, &bus, &dev, &func)=3D=3D4) { + if (dom =3D=3D pci->domain + && bus =3D=3D pci->bus + && dev =3D=3D pci->dev + && func =3D=3D pci->func) { rc =3D 1; goto out; } @@ -649,7 +649,7 @@ out: return rc; } =20 -static int pciback_dev_is_assigned(libxl__gc *gc, libxl_device_pci *pcidev) +static int pciback_dev_is_assigned(libxl__gc *gc, libxl_device_pci *pci) { char * spath; int rc; @@ -665,8 +665,8 @@ static int pciback_dev_is_assigned(libxl__gc *gc, libxl= _device_pci *pcidev) } =20 spath =3D GCSPRINTF(SYSFS_PCIBACK_DRIVER"/"PCI_BDF, - pcidev->domain, pcidev->bus, - pcidev->dev, pcidev->func); + pci->domain, pci->bus, + pci->dev, pci->func); rc =3D lstat(spath, &st); =20 if( rc =3D=3D 0 ) @@ -677,40 +677,40 @@ static int pciback_dev_is_assigned(libxl__gc *gc, lib= xl_device_pci *pcidev) return -1; } =20 -static int pciback_dev_assign(libxl__gc *gc, libxl_device_pci *pcidev) +static int pciback_dev_assign(libxl__gc *gc, libxl_device_pci *pci) { int rc; =20 - if ( (rc=3Dpciback_dev_has_slot(gc, pcidev)) < 0 ) { + if ( (rc =3D pciback_dev_has_slot(gc, pci)) < 0 ) { LOGE(ERROR, "Error checking for pciback slot"); return ERROR_FAIL; } else if (rc =3D=3D 0) { if ( sysfs_write_bdf(gc, SYSFS_PCIBACK_DRIVER"/new_slot", - pcidev) < 0 ) { + pci) < 0 ) { LOGE(ERROR, "Couldn't bind device to pciback!"); return ERROR_FAIL; } } =20 - if ( sysfs_write_bdf(gc, SYSFS_PCIBACK_DRIVER"/bind", pcidev) < 0 ) { + if ( sysfs_write_bdf(gc, SYSFS_PCIBACK_DRIVER"/bind", pci) < 0 ) { LOGE(ERROR, "Couldn't bind device to pciback!"); return ERROR_FAIL; } return 0; } =20 -static int pciback_dev_unassign(libxl__gc *gc, libxl_device_pci *pcidev) +static int pciback_dev_unassign(libxl__gc *gc, libxl_device_pci *pci) { /* Remove from pciback */ - if ( sysfs_dev_unbind(gc, pcidev, NULL) < 0 ) { + if ( sysfs_dev_unbind(gc, pci, NULL) < 0 ) { LOG(ERROR, "Couldn't unbind device!"); return ERROR_FAIL; } =20 /* Remove slot if necessary */ - if ( pciback_dev_has_slot(gc, pcidev) > 0 ) { + if ( pciback_dev_has_slot(gc, pci) > 0 ) { if ( sysfs_write_bdf(gc, SYSFS_PCIBACK_DRIVER"/remove_slot", - pcidev) < 0 ) { + pci) < 0 ) { LOGE(ERROR, "Couldn't remove pciback slot"); return ERROR_FAIL; } @@ -721,49 +721,49 @@ static int pciback_dev_unassign(libxl__gc *gc, libxl_= device_pci *pcidev) #define PCIBACK_INFO_PATH "/libxl/pciback" =20 static void pci_assignable_driver_path_write(libxl__gc *gc, - libxl_device_pci *pcidev, + libxl_device_pci *pci, char *driver_path) { char *path; =20 path =3D GCSPRINTF(PCIBACK_INFO_PATH"/"PCI_BDF_XSPATH"/driver_path", - pcidev->domain, - pcidev->bus, - pcidev->dev, - pcidev->func); + pci->domain, + pci->bus, + pci->dev, + pci->func); if ( libxl__xs_printf(gc, XBT_NULL, path, "%s", driver_path) < 0 ) { LOGE(WARN, "Write of %s to node %s failed.", driver_path, path); } } =20 static char * pci_assignable_driver_path_read(libxl__gc *gc, - libxl_device_pci *pcidev) + libxl_device_pci *pci) { return libxl__xs_read(gc, XBT_NULL, GCSPRINTF( PCIBACK_INFO_PATH "/" PCI_BDF_XSPATH "/driver_p= ath", - pcidev->domain, - pcidev->bus, - pcidev->dev, - pcidev->func)); + pci->domain, + pci->bus, + pci->dev, + pci->func)); } =20 static void pci_assignable_driver_path_remove(libxl__gc *gc, - libxl_device_pci *pcidev) + libxl_device_pci *pci) { libxl_ctx *ctx =3D libxl__gc_owner(gc); =20 /* Remove the xenstore entry */ xs_rm(ctx->xsh, XBT_NULL, GCSPRINTF(PCIBACK_INFO_PATH "/" PCI_BDF_XSPATH, - pcidev->domain, - pcidev->bus, - pcidev->dev, - pcidev->func) ); + pci->domain, + pci->bus, + pci->dev, + pci->func) ); } =20 static int libxl__device_pci_assignable_add(libxl__gc *gc, - libxl_device_pci *pcidev, + libxl_device_pci *pci, int rebind) { libxl_ctx *ctx =3D libxl__gc_owner(gc); @@ -773,10 +773,10 @@ static int libxl__device_pci_assignable_add(libxl__gc= *gc, struct stat st; =20 /* Local copy for convenience */ - dom =3D pcidev->domain; - bus =3D pcidev->bus; - dev =3D pcidev->dev; - func =3D pcidev->func; + dom =3D pci->domain; + bus =3D pci->bus; + dev =3D pci->dev; + func =3D pci->func; =20 /* See if the device exists */ spath =3D GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF, dom, bus, dev, func); @@ -786,7 +786,7 @@ static int libxl__device_pci_assignable_add(libxl__gc *= gc, } =20 /* Check to see if it's already assigned to pciback */ - rc =3D pciback_dev_is_assigned(gc, pcidev); + rc =3D pciback_dev_is_assigned(gc, pci); if ( rc < 0 ) { return ERROR_FAIL; } @@ -796,7 +796,7 @@ static int libxl__device_pci_assignable_add(libxl__gc *= gc, } =20 /* Check to see if there's already a driver that we need to unbind fro= m */ - if ( sysfs_dev_unbind(gc, pcidev, &driver_path ) ) { + if ( sysfs_dev_unbind(gc, pci, &driver_path ) ) { LOG(ERROR, "Couldn't unbind "PCI_BDF" from driver", dom, bus, dev, func); return ERROR_FAIL; @@ -805,9 +805,9 @@ static int libxl__device_pci_assignable_add(libxl__gc *= gc, /* Store driver_path for rebinding to dom0 */ if ( rebind ) { if ( driver_path ) { - pci_assignable_driver_path_write(gc, pcidev, driver_path); + pci_assignable_driver_path_write(gc, pci, driver_path); } else if ( (driver_path =3D - pci_assignable_driver_path_read(gc, pcidev)) !=3D NUL= L ) { + pci_assignable_driver_path_read(gc, pci)) !=3D NULL )= { LOG(INFO, PCI_BDF" not bound to a driver, will be rebound to %= s", dom, bus, dev, func, driver_path); } else { @@ -815,10 +815,10 @@ static int libxl__device_pci_assignable_add(libxl__gc= *gc, dom, bus, dev, func); } } else { - pci_assignable_driver_path_remove(gc, pcidev); + pci_assignable_driver_path_remove(gc, pci); } =20 - if ( pciback_dev_assign(gc, pcidev) ) { + if ( pciback_dev_assign(gc, pci) ) { LOG(ERROR, "Couldn't bind device to pciback!"); return ERROR_FAIL; } @@ -829,7 +829,7 @@ quarantine: * so always pass XEN_DOMCTL_DEV_RDM_RELAXED to avoid assignment being * unnecessarily denied. */ - rc =3D xc_assign_device(ctx->xch, DOMID_IO, pcidev_encode_bdf(pcidev), + rc =3D xc_assign_device(ctx->xch, DOMID_IO, pci_encode_bdf(pci), XEN_DOMCTL_DEV_RDM_RELAXED); if ( rc < 0 ) { LOG(ERROR, "failed to quarantine "PCI_BDF, dom, bus, dev, func); @@ -840,7 +840,7 @@ quarantine: } =20 static int libxl__device_pci_assignable_remove(libxl__gc *gc, - libxl_device_pci *pcidev, + libxl_device_pci *pci, int rebind) { libxl_ctx *ctx =3D libxl__gc_owner(gc); @@ -848,24 +848,24 @@ static int libxl__device_pci_assignable_remove(libxl_= _gc *gc, char *driver_path; =20 /* De-quarantine */ - rc =3D xc_deassign_device(ctx->xch, DOMID_IO, pcidev_encode_bdf(pcidev= )); + rc =3D xc_deassign_device(ctx->xch, DOMID_IO, pci_encode_bdf(pci)); if ( rc < 0 ) { - LOG(ERROR, "failed to de-quarantine "PCI_BDF, pcidev->domain, pcid= ev->bus, - pcidev->dev, pcidev->func); + LOG(ERROR, "failed to de-quarantine "PCI_BDF, pci->domain, pci->bu= s, + pci->dev, pci->func); return ERROR_FAIL; } =20 /* Unbind from pciback */ - if ( (rc=3Dpciback_dev_is_assigned(gc, pcidev)) < 0 ) { + if ( (rc =3D pciback_dev_is_assigned(gc, pci)) < 0 ) { return ERROR_FAIL; } else if ( rc ) { - pciback_dev_unassign(gc, pcidev); + pciback_dev_unassign(gc, pci); } else { LOG(WARN, "Not bound to pciback"); } =20 /* Rebind if necessary */ - driver_path =3D pci_assignable_driver_path_read(gc, pcidev); + driver_path =3D pci_assignable_driver_path_read(gc, pci); =20 if ( driver_path ) { if ( rebind ) { @@ -873,12 +873,12 @@ static int libxl__device_pci_assignable_remove(libxl_= _gc *gc, =20 if ( sysfs_write_bdf(gc, GCSPRINTF("%s/bind", driver_path), - pcidev) < 0 ) { + pci) < 0 ) { LOGE(ERROR, "Couldn't bind device to %s", driver_path); return -1; } =20 - pci_assignable_driver_path_remove(gc, pcidev); + pci_assignable_driver_path_remove(gc, pci); } } else { if ( rebind ) { @@ -890,26 +890,26 @@ static int libxl__device_pci_assignable_remove(libxl_= _gc *gc, return 0; } =20 -int libxl_device_pci_assignable_add(libxl_ctx *ctx, libxl_device_pci *pcid= ev, +int libxl_device_pci_assignable_add(libxl_ctx *ctx, libxl_device_pci *pci, int rebind) { GC_INIT(ctx); int rc; =20 - rc =3D libxl__device_pci_assignable_add(gc, pcidev, rebind); + rc =3D libxl__device_pci_assignable_add(gc, pci, rebind); =20 GC_FREE; return rc; } =20 =20 -int libxl_device_pci_assignable_remove(libxl_ctx *ctx, libxl_device_pci *p= cidev, +int libxl_device_pci_assignable_remove(libxl_ctx *ctx, libxl_device_pci *p= ci, int rebind) { GC_INIT(ctx); int rc; =20 - rc =3D libxl__device_pci_assignable_remove(gc, pcidev, rebind); + rc =3D libxl__device_pci_assignable_remove(gc, pci, rebind); =20 GC_FREE; return rc; @@ -920,7 +920,7 @@ int libxl_device_pci_assignable_remove(libxl_ctx *ctx, = libxl_device_pci *pcidev, * driver. It also initialises a bit-mask of which function numbers are pr= esent * on that device. */ -static int pci_multifunction_check(libxl__gc *gc, libxl_device_pci *pcidev= , unsigned int *func_mask) +static int pci_multifunction_check(libxl__gc *gc, libxl_device_pci *pci, u= nsigned int *func_mask) { struct dirent *de; DIR *dir; @@ -940,11 +940,11 @@ static int pci_multifunction_check(libxl__gc *gc, lib= xl_device_pci *pcidev, unsi =20 if ( sscanf(de->d_name, PCI_BDF, &dom, &bus, &dev, &func) !=3D 4 ) continue; - if ( pcidev->domain !=3D dom ) + if ( pci->domain !=3D dom ) continue; - if ( pcidev->bus !=3D bus ) + if ( pci->bus !=3D bus ) continue; - if ( pcidev->dev !=3D dev ) + if ( pci->dev !=3D dev ) continue; =20 path =3D GCSPRINTF("%s/" PCI_BDF, SYSFS_PCIBACK_DRIVER, dom, bus, = dev, func); @@ -979,7 +979,7 @@ static int pci_ins_check(libxl__gc *gc, uint32_t domid,= const char *state, void } =20 static int qemu_pci_add_xenstore(libxl__gc *gc, uint32_t domid, - libxl_device_pci *pcidev) + libxl_device_pci *pci) { libxl_ctx *ctx =3D libxl__gc_owner(gc); int rc =3D 0; @@ -991,15 +991,15 @@ static int qemu_pci_add_xenstore(libxl__gc *gc, uint3= 2_t domid, path =3D DEVICE_MODEL_XS_PATH(gc, dm_domid, domid, "/state"); state =3D libxl__xs_read(gc, XBT_NULL, path); path =3D DEVICE_MODEL_XS_PATH(gc, dm_domid, domid, "/parameter"); - if (pcidev->vdevfn) { + if (pci->vdevfn) { libxl__xs_printf(gc, XBT_NULL, path, PCI_BDF_VDEVFN","PCI_OPTIONS, - pcidev->domain, pcidev->bus, pcidev->dev, - pcidev->func, pcidev->vdevfn, pcidev->msitranslat= e, - pcidev->power_mgmt); + pci->domain, pci->bus, pci->dev, + pci->func, pci->vdevfn, pci->msitranslate, + pci->power_mgmt); } else { libxl__xs_printf(gc, XBT_NULL, path, PCI_BDF","PCI_OPTIONS, - pcidev->domain, pcidev->bus, pcidev->dev, - pcidev->func, pcidev->msitranslate, pcidev->power= _mgmt); + pci->domain, pci->bus, pci->dev, + pci->func, pci->msitranslate, pci->power_mgmt); } =20 libxl__qemu_traditional_cmd(gc, domid, "pci-ins"); @@ -1010,7 +1010,7 @@ static int qemu_pci_add_xenstore(libxl__gc *gc, uint3= 2_t domid, path =3D DEVICE_MODEL_XS_PATH(gc, dm_domid, domid, "/state"); if ( rc < 0 ) LOGD(ERROR, domid, "qemu refused to add device: %s", vdevfn); - else if ( sscanf(vdevfn, "0x%x", &pcidev->vdevfn) !=3D 1 ) { + else if ( sscanf(vdevfn, "0x%x", &pci->vdevfn) !=3D 1 ) { LOGD(ERROR, domid, "wrong format for the vdevfn: '%s'", vdevfn); rc =3D -1; } @@ -1054,7 +1054,7 @@ typedef struct pci_add_state { libxl__xswait_state xswait; libxl__ev_qmp qmp; libxl__ev_time timeout; - libxl_device_pci *pcidev; + libxl_device_pci *pci; int pci_domid; } pci_add_state; =20 @@ -1072,7 +1072,7 @@ static void pci_add_dm_done(libxl__egc *, =20 static void do_pci_add(libxl__egc *egc, libxl_domid domid, - libxl_device_pci *pcidev, + libxl_device_pci *pci, pci_add_state *pas) { STATE_AO_GC(pas->aodev->ao); @@ -1082,7 +1082,7 @@ static void do_pci_add(libxl__egc *egc, /* init pci_add_state */ libxl__xswait_init(&pas->xswait); libxl__ev_qmp_init(&pas->qmp); - pas->pcidev =3D pcidev; + pas->pci =3D pci; pas->pci_domid =3D domid; libxl__ev_time_init(&pas->timeout); =20 @@ -1128,7 +1128,7 @@ static void pci_add_qemu_trad_watch_state_cb(libxl__e= gc *egc, =20 /* Convenience aliases */ libxl_domid domid =3D pas->domid; - libxl_device_pci *pcidev =3D pas->pcidev; + libxl_device_pci *pci =3D pas->pci; =20 rc =3D check_qemu_running(gc, domid, xswa, rc, state); if (rc =3D=3D ERROR_NOT_READY) @@ -1136,7 +1136,7 @@ static void pci_add_qemu_trad_watch_state_cb(libxl__e= gc *egc, if (rc) goto out; =20 - rc =3D qemu_pci_add_xenstore(gc, domid, pcidev); + rc =3D qemu_pci_add_xenstore(gc, domid, pci); out: pci_add_dm_done(egc, pas, rc); /* must be last */ } @@ -1149,7 +1149,7 @@ static void pci_add_qmp_device_add(libxl__egc *egc, p= ci_add_state *pas) =20 /* Convenience aliases */ libxl_domid domid =3D pas->domid; - libxl_device_pci *pcidev =3D pas->pcidev; + libxl_device_pci *pci =3D pas->pci; libxl__ev_qmp *const qmp =3D &pas->qmp; =20 rc =3D libxl__ev_time_register_rel(ao, &pas->timeout, @@ -1160,14 +1160,14 @@ static void pci_add_qmp_device_add(libxl__egc *egc,= pci_add_state *pas) libxl__qmp_param_add_string(gc, &args, "driver", "xen-pci-passthrough"); QMP_PARAMETERS_SPRINTF(&args, "id", PCI_PT_QDEV_ID, - pcidev->bus, pcidev->dev, pcidev->func); + pci->bus, pci->dev, pci->func); QMP_PARAMETERS_SPRINTF(&args, "hostaddr", - "%04x:%02x:%02x.%01x", pcidev->domain, - pcidev->bus, pcidev->dev, pcidev->func); - if (pcidev->vdevfn) { + "%04x:%02x:%02x.%01x", pci->domain, + pci->bus, pci->dev, pci->func); + if (pci->vdevfn) { QMP_PARAMETERS_SPRINTF(&args, "addr", "%x.%x", - PCI_SLOT(pcidev->vdevfn), - PCI_FUNC(pcidev->vdevfn)); + PCI_SLOT(pci->vdevfn), + PCI_FUNC(pci->vdevfn)); } /* * Version of QEMU prior to the XSA-131 fix did not support @@ -1179,7 +1179,7 @@ static void pci_add_qmp_device_add(libxl__egc *egc, p= ci_add_state *pas) * set the permissive flag if it is true. Users of older QEMU * have no reason to set the flag so this is ok. */ - if (pcidev->permissive) + if (pci->permissive) libxl__qmp_param_add_bool(gc, &args, "permissive", true); =20 qmp->ao =3D pas->aodev->ao; @@ -1230,7 +1230,7 @@ static void pci_add_qmp_query_pci_cb(libxl__egc *egc, int dev_slot, dev_func; =20 /* Convenience aliases */ - libxl_device_pci *pcidev =3D pas->pcidev; + libxl_device_pci *pci =3D pas->pci; =20 if (rc) goto out; =20 @@ -1251,7 +1251,7 @@ static void pci_add_qmp_query_pci_cb(libxl__egc *egc, */ =20 asked_id =3D GCSPRINTF(PCI_PT_QDEV_ID, - pcidev->bus, pcidev->dev, pcidev->func); + pci->bus, pci->dev, pci->func); =20 for (i =3D 0; (bus =3D libxl__json_array_get(response, i)); i++) { devices =3D libxl__json_map_get("devices", bus, JSON_ARRAY); @@ -1283,7 +1283,7 @@ static void pci_add_qmp_query_pci_cb(libxl__egc *egc, } dev_func =3D libxl__json_object_get_integer(o); =20 - pcidev->vdevfn =3D PCI_DEVFN(dev_slot, dev_func); + pci->vdevfn =3D PCI_DEVFN(dev_slot, dev_func); =20 rc =3D 0; goto out; @@ -1331,7 +1331,7 @@ static void pci_add_dm_done(libxl__egc *egc, =20 /* Convenience aliases */ bool starting =3D pas->starting; - libxl_device_pci *pcidev =3D pas->pcidev; + libxl_device_pci *pci =3D pas->pci; bool hvm =3D libxl__domain_type(gc, domid) =3D=3D LIBXL_DOMAIN_TYPE_HV= M; =20 libxl__ev_qmp_dispose(gc, &pas->qmp); @@ -1342,8 +1342,8 @@ static void pci_add_dm_done(libxl__egc *egc, if (isstubdom) starting =3D false; =20 - sysfs_path =3D GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/resource", pcidev->d= omain, - pcidev->bus, pcidev->dev, pcidev->func); + sysfs_path =3D GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/resource", pci->doma= in, + pci->bus, pci->dev, pci->func); f =3D fopen(sysfs_path, "r"); start =3D end =3D flags =3D size =3D 0; irq =3D 0; @@ -1383,8 +1383,8 @@ static void pci_add_dm_done(libxl__egc *egc, } } fclose(f); - sysfs_path =3D GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/irq", pcidev->domain, - pcidev->bus, pcidev->dev, pcidev->func); + sysfs_path =3D GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/irq", pci->domain, + pci->bus, pci->dev, pci->func); f =3D fopen(sysfs_path, "r"); if (f =3D=3D NULL) { LOGED(ERROR, domainid, "Couldn't open %s", sysfs_path); @@ -1411,9 +1411,9 @@ static void pci_add_dm_done(libxl__egc *egc, fclose(f); =20 /* Don't restrict writes to the PCI config space from this VM */ - if (pcidev->permissive) { + if (pci->permissive) { if ( sysfs_write_bdf(gc, SYSFS_PCIBACK_DRIVER"/permissive", - pcidev) < 0 ) { + pci) < 0 ) { LOGD(ERROR, domainid, "Setting permissive for device"); rc =3D ERROR_FAIL; goto out; @@ -1422,14 +1422,14 @@ static void pci_add_dm_done(libxl__egc *egc, =20 out_no_irq: if (!isstubdom) { - if (pcidev->rdm_policy =3D=3D LIBXL_RDM_RESERVE_POLICY_STRICT) { + if (pci->rdm_policy =3D=3D LIBXL_RDM_RESERVE_POLICY_STRICT) { flag &=3D ~XEN_DOMCTL_DEV_RDM_RELAXED; - } else if (pcidev->rdm_policy !=3D LIBXL_RDM_RESERVE_POLICY_RELAXE= D) { + } else if (pci->rdm_policy !=3D LIBXL_RDM_RESERVE_POLICY_RELAXED) { LOGED(ERROR, domainid, "unknown rdm check flag."); rc =3D ERROR_FAIL; goto out; } - r =3D xc_assign_device(ctx->xch, domid, pcidev_encode_bdf(pcidev),= flag); + r =3D xc_assign_device(ctx->xch, domid, pci_encode_bdf(pci), flag); if (r < 0 && (hvm || errno !=3D ENOSYS)) { LOGED(ERROR, domainid, "xc_assign_device failed"); rc =3D ERROR_FAIL; @@ -1438,7 +1438,7 @@ out_no_irq: } =20 if (!starting && !libxl_get_stubdom_id(CTX, domid)) - rc =3D libxl__device_pci_add_xenstore(gc, domid, pcidev, starting); + rc =3D libxl__device_pci_add_xenstore(gc, domid, pci, starting); else rc =3D 0; out: @@ -1493,7 +1493,7 @@ int libxl__device_pci_setdefault(libxl__gc *gc, uint3= 2_t domid, } =20 int libxl_device_pci_add(libxl_ctx *ctx, uint32_t domid, - libxl_device_pci *pcidev, + libxl_device_pci *pci, const libxl_asyncop_how *ao_how) { AO_CREATE(ctx, domid, ao_how); @@ -1504,24 +1504,24 @@ int libxl_device_pci_add(libxl_ctx *ctx, uint32_t d= omid, aodev->action =3D LIBXL__DEVICE_ACTION_ADD; aodev->callback =3D device_addrm_aocomplete; aodev->update_json =3D true; - libxl__device_pci_add(egc, domid, pcidev, false, aodev); + libxl__device_pci_add(egc, domid, pci, false, aodev); return AO_INPROGRESS; } =20 -static int libxl_pcidev_assignable(libxl_ctx *ctx, libxl_device_pci *pcide= v) +static int libxl_pci_assignable(libxl_ctx *ctx, libxl_device_pci *pci) { - libxl_device_pci *pcidevs; + libxl_device_pci *pcis; int num, i; =20 - pcidevs =3D libxl_device_pci_assignable_list(ctx, &num); + pcis =3D libxl_device_pci_assignable_list(ctx, &num); for (i =3D 0; i < num; i++) { - if (pcidevs[i].domain =3D=3D pcidev->domain && - pcidevs[i].bus =3D=3D pcidev->bus && - pcidevs[i].dev =3D=3D pcidev->dev && - pcidevs[i].func =3D=3D pcidev->func) + if (pcis[i].domain =3D=3D pci->domain && + pcis[i].bus =3D=3D pci->bus && + pcis[i].dev =3D=3D pci->dev && + pcis[i].func =3D=3D pci->func) break; } - free(pcidevs); + free(pcis); return i !=3D num; } =20 @@ -1535,7 +1535,7 @@ static void device_pci_add_done(libxl__egc *egc, pci_add_state *, int rc); =20 void libxl__device_pci_add(libxl__egc *egc, uint32_t domid, - libxl_device_pci *pcidev, bool starting, + libxl_device_pci *pci, bool starting, libxl__ao_device *aodev) { STATE_AO_GC(aodev->ao); @@ -1545,9 +1545,9 @@ void libxl__device_pci_add(libxl__egc *egc, uint32_t = domid, int stubdomid =3D 0; pci_add_state *pas; =20 - /* Store *pcidev to be used by callbacks */ - aodev->device_config =3D pcidev; - aodev->device_type =3D &libxl__pcidev_devtype; + /* Store *pci to be used by callbacks */ + aodev->device_config =3D pci; + aodev->device_type =3D &libxl__pci_devtype; =20 GCNEW(pas); pas->aodev =3D aodev; @@ -1556,29 +1556,29 @@ void libxl__device_pci_add(libxl__egc *egc, uint32_= t domid, pas->callback =3D device_pci_add_stubdom_done; =20 if (libxl__domain_type(gc, domid) =3D=3D LIBXL_DOMAIN_TYPE_HVM) { - rc =3D xc_test_assign_device(ctx->xch, domid, pcidev_encode_bdf(pc= idev)); + rc =3D xc_test_assign_device(ctx->xch, domid, pci_encode_bdf(pci)); if (rc) { LOGD(ERROR, domid, "PCI device %04x:%02x:%02x.%u %s?", - pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func, + pci->domain, pci->bus, pci->dev, pci->func, errno =3D=3D EOPNOTSUPP ? "cannot be assigned - no IOMMU" : "already assigned to a different guest"); goto out; } } =20 - rc =3D libxl__device_pci_setdefault(gc, domid, pcidev, !starting); + rc =3D libxl__device_pci_setdefault(gc, domid, pci, !starting); if (rc) goto out; =20 - if (pcidev->seize && !pciback_dev_is_assigned(gc, pcidev)) { - rc =3D libxl__device_pci_assignable_add(gc, pcidev, 1); + if (pci->seize && !pciback_dev_is_assigned(gc, pci)) { + rc =3D libxl__device_pci_assignable_add(gc, pci, 1); if ( rc ) goto out; } =20 - if (!libxl_pcidev_assignable(ctx, pcidev)) { + if (!libxl_pci_assignable(ctx, pci)) { LOGD(ERROR, domid, "PCI device %x:%x:%x.%x is not assignable", - pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func); + pci->domain, pci->bus, pci->dev, pci->func); rc =3D ERROR_FAIL; goto out; } @@ -1589,25 +1589,25 @@ void libxl__device_pci_add(libxl__egc *egc, uint32_= t domid, "cannot determine if device is assigned, refusing to continue= "); goto out; } - if ( is_pcidev_in_array(assigned, num_assigned, pcidev->domain, - pcidev->bus, pcidev->dev, pcidev->func) ) { + if ( is_pci_in_array(assigned, num_assigned, pci->domain, + pci->bus, pci->dev, pci->func) ) { LOGD(ERROR, domid, "PCI device already attached to a domain"); rc =3D ERROR_FAIL; goto out; } =20 - libxl__device_pci_reset(gc, pcidev->domain, pcidev->bus, pcidev->dev, = pcidev->func); + libxl__device_pci_reset(gc, pci->domain, pci->bus, pci->dev, pci->func= ); =20 stubdomid =3D libxl_get_stubdom_id(ctx, domid); if (stubdomid !=3D 0) { - libxl_device_pci *pcidev_s; + libxl_device_pci *pci_s; =20 - GCNEW(pcidev_s); - libxl_device_pci_init(pcidev_s); - libxl_device_pci_copy(CTX, pcidev_s, pcidev); + GCNEW(pci_s); + libxl_device_pci_init(pci_s); + libxl_device_pci_copy(CTX, pci_s, pci); pas->callback =3D device_pci_add_stubdom_wait; =20 - do_pci_add(egc, stubdomid, pcidev_s, pas); /* must be last */ + do_pci_add(egc, stubdomid, pci_s, pas); /* must be last */ return; } =20 @@ -1664,42 +1664,42 @@ static void device_pci_add_stubdom_done(libxl__egc = *egc, /* Convenience aliases */ libxl__ao_device *aodev =3D pas->aodev; libxl_domid domid =3D pas->domid; - libxl_device_pci *pcidev =3D aodev->device_config; + libxl_device_pci *pci =3D aodev->device_config; =20 if (rc) goto out; =20 - orig_vdev =3D pcidev->vdevfn & ~7U; + orig_vdev =3D pci->vdevfn & ~7U; =20 - if ( pcidev->vfunc_mask =3D=3D LIBXL_PCI_FUNC_ALL ) { - if ( !(pcidev->vdevfn >> 3) ) { + if ( pci->vfunc_mask =3D=3D LIBXL_PCI_FUNC_ALL ) { + if ( !(pci->vdevfn >> 3) ) { LOGD(ERROR, domid, "Must specify a v-slot for multi-function d= evices"); rc =3D ERROR_INVAL; goto out; } - if ( pci_multifunction_check(gc, pcidev, &pfunc_mask) ) { + if ( pci_multifunction_check(gc, pci, &pfunc_mask) ) { rc =3D ERROR_FAIL; goto out; } - pcidev->vfunc_mask &=3D pfunc_mask; + pci->vfunc_mask &=3D pfunc_mask; /* so now vfunc_mask =3D=3D pfunc_mask */ }else{ - pfunc_mask =3D (1 << pcidev->func); + pfunc_mask =3D (1 << pci->func); } =20 - for(rc =3D 0, i =3D 7; i >=3D 0; --i) { + for (rc =3D 0, i =3D 7; i >=3D 0; --i) { if ( (1 << i) & pfunc_mask ) { - if ( pcidev->vfunc_mask =3D=3D pfunc_mask ) { - pcidev->func =3D i; - pcidev->vdevfn =3D orig_vdev | i; - }else{ + if ( pci->vfunc_mask =3D=3D pfunc_mask ) { + pci->func =3D i; + pci->vdevfn =3D orig_vdev | i; + } else { /* if not passing through multiple devices in a block make * sure that virtual function number 0 is always used othe= rwise * guest won't see the device */ - pcidev->vdevfn =3D orig_vdev; + pci->vdevfn =3D orig_vdev; } pas->callback =3D device_pci_add_done; - do_pci_add(egc, domid, pcidev, pas); /* must be last */ + do_pci_add(egc, domid, pci, pas); /* must be last */ return; } } @@ -1715,13 +1715,13 @@ static void device_pci_add_done(libxl__egc *egc, EGC_GC; libxl__ao_device *aodev =3D pas->aodev; libxl_domid domid =3D pas->domid; - libxl_device_pci *pcidev =3D aodev->device_config; + libxl_device_pci *pci =3D aodev->device_config; =20 if (rc) { LOGD(ERROR, domid, "libxl__device_pci_add failed for " "PCI device %x:%x:%x.%x (rc %d)", - pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func, + pci->domain, pci->bus, pci->dev, pci->func, rc); } aodev->rc =3D rc; @@ -1733,16 +1733,16 @@ typedef struct { libxl__ao_device *outer_aodev; libxl_domain_config *d_config; libxl_domid domid; -} add_pcidevs_state; +} add_pcis_state; =20 -static void add_pcidevs_done(libxl__egc *, libxl__multidev *, int rc); +static void add_pcis_done(libxl__egc *, libxl__multidev *, int rc); =20 -static void libxl__add_pcidevs(libxl__egc *egc, libxl__ao *ao, uint32_t do= mid, - libxl_domain_config *d_config, - libxl__multidev *multidev) +static void libxl__add_pcis(libxl__egc *egc, libxl__ao *ao, uint32_t domid, + libxl_domain_config *d_config, + libxl__multidev *multidev) { AO_GC; - add_pcidevs_state *apds; + add_pcis_state *apds; int i; =20 /* We need to start a new multidev in order to be able to execute @@ -1752,23 +1752,23 @@ static void libxl__add_pcidevs(libxl__egc *egc, lib= xl__ao *ao, uint32_t domid, apds->outer_aodev =3D libxl__multidev_prepare(multidev); apds->d_config =3D d_config; apds->domid =3D domid; - apds->multidev.callback =3D add_pcidevs_done; + apds->multidev.callback =3D add_pcis_done; libxl__multidev_begin(ao, &apds->multidev); =20 - for (i =3D 0; i < d_config->num_pcidevs; i++) { + for (i =3D 0; i < d_config->num_pcis; i++) { libxl__ao_device *aodev =3D libxl__multidev_prepare(&apds->multide= v); - libxl__device_pci_add(egc, domid, &d_config->pcidevs[i], + libxl__device_pci_add(egc, domid, &d_config->pcis[i], true, aodev); } =20 libxl__multidev_prepared(egc, &apds->multidev, 0); } =20 -static void add_pcidevs_done(libxl__egc *egc, libxl__multidev *multidev, +static void add_pcis_done(libxl__egc *egc, libxl__multidev *multidev, int rc) { EGC_GC; - add_pcidevs_state *apds =3D CONTAINER_OF(multidev, *apds, multidev); + add_pcis_state *apds =3D CONTAINER_OF(multidev, *apds, multidev); =20 /* Convenience aliases */ libxl_domain_config *d_config =3D apds->d_config; @@ -1777,9 +1777,9 @@ static void add_pcidevs_done(libxl__egc *egc, libxl__= multidev *multidev, =20 if (rc) goto out; =20 - if (d_config->num_pcidevs > 0 && !libxl_get_stubdom_id(CTX, domid)) { - rc =3D libxl__create_pci_backend(gc, domid, d_config->pcidevs, - d_config->num_pcidevs); + if (d_config->num_pcis > 0 && !libxl_get_stubdom_id(CTX, domid)) { + rc =3D libxl__create_pci_backend(gc, domid, d_config->pcis, + d_config->num_pcis); if (rc < 0) { LOGD(ERROR, domid, "libxl_create_pci_backend failed: %d", rc); goto out; @@ -1792,7 +1792,7 @@ out: } =20 static int qemu_pci_remove_xenstore(libxl__gc *gc, uint32_t domid, - libxl_device_pci *pcidev, int force) + libxl_device_pci *pci, int force) { libxl_ctx *ctx =3D libxl__gc_owner(gc); char *state; @@ -1804,12 +1804,12 @@ static int qemu_pci_remove_xenstore(libxl__gc *gc, = uint32_t domid, path =3D DEVICE_MODEL_XS_PATH(gc, dm_domid, domid, "/state"); state =3D libxl__xs_read(gc, XBT_NULL, path); path =3D DEVICE_MODEL_XS_PATH(gc, dm_domid, domid, "/parameter"); - libxl__xs_printf(gc, XBT_NULL, path, PCI_BDF, pcidev->domain, - pcidev->bus, pcidev->dev, pcidev->func); + libxl__xs_printf(gc, XBT_NULL, path, PCI_BDF, pci->domain, + pci->bus, pci->dev, pci->func); =20 /* Remove all functions at once atomically by only signalling * device-model for function 0 */ - if ( !force && (pcidev->vdevfn & 0x7) =3D=3D 0 ) { + if ( !force && (pci->vdevfn & 0x7) =3D=3D 0 ) { libxl__qemu_traditional_cmd(gc, domid, "pci-rem"); if (libxl__wait_for_device_model_deprecated(gc, domid, "pci-remove= d", NULL, NULL, NULL) < 0) { @@ -1830,7 +1830,7 @@ static int qemu_pci_remove_xenstore(libxl__gc *gc, ui= nt32_t domid, typedef struct pci_remove_state { libxl__ao_device *aodev; libxl_domid domid; - libxl_device_pci *pcidev; + libxl_device_pci *pci; bool force; bool hvm; unsigned int orig_vdev; @@ -1844,7 +1844,7 @@ typedef struct pci_remove_state { } pci_remove_state; =20 static void libxl__device_pci_remove_common(libxl__egc *egc, - uint32_t domid, libxl_device_pci *pcidev, bool force, + uint32_t domid, libxl_device_pci *pci, bool force, libxl__ao_device *aodev); static void device_pci_remove_common_next(libxl__egc *egc, pci_remove_state *prs, int rc); @@ -1869,7 +1869,7 @@ static void pci_remove_done(libxl__egc *egc, pci_remove_state *prs, int rc); =20 static void do_pci_remove(libxl__egc *egc, uint32_t domid, - libxl_device_pci *pcidev, int force, + libxl_device_pci *pci, int force, pci_remove_state *prs) { STATE_AO_GC(prs->aodev->ao); @@ -1887,8 +1887,8 @@ static void do_pci_remove(libxl__egc *egc, uint32_t d= omid, libxl__ptr_add(gc, assigned); =20 rc =3D ERROR_INVAL; - if ( !is_pcidev_in_array(assigned, num, pcidev->domain, - pcidev->bus, pcidev->dev, pcidev->func) ) { + if ( !is_pci_in_array(assigned, num, pci->domain, + pci->bus, pci->dev, pci->func) ) { LOGD(ERROR, domainid, "PCI device not attached to this domain"); goto out_fail; } @@ -1917,8 +1917,8 @@ static void do_pci_remove(libxl__egc *egc, uint32_t d= omid, } else { assert(type =3D=3D LIBXL_DOMAIN_TYPE_PV); =20 - char *sysfs_path =3D GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/resource",= pcidev->domain, - pcidev->bus, pcidev->dev, pcidev->fun= c); + char *sysfs_path =3D GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/resource",= pci->domain, + pci->bus, pci->dev, pci->func); FILE *f =3D fopen(sysfs_path, "r"); unsigned int start =3D 0, end =3D 0, flags =3D 0, size =3D 0; int irq =3D 0; @@ -1953,8 +1953,8 @@ static void do_pci_remove(libxl__egc *egc, uint32_t d= omid, } fclose(f); skip1: - sysfs_path =3D GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/irq", pcidev->do= main, - pcidev->bus, pcidev->dev, pcidev->func); + sysfs_path =3D GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/irq", pci->domai= n, + pci->bus, pci->dev, pci->func); f =3D fopen(sysfs_path, "r"); if (f =3D=3D NULL) { LOGED(ERROR, domainid, "Couldn't open %s", sysfs_path); @@ -1988,7 +1988,7 @@ static void pci_remove_qemu_trad_watch_state_cb(libxl= __egc *egc, =20 /* Convenience aliases */ libxl_domid domid =3D prs->domid; - libxl_device_pci *const pcidev =3D prs->pcidev; + libxl_device_pci *const pci =3D prs->pci; =20 rc =3D check_qemu_running(gc, domid, xswa, rc, state); if (rc =3D=3D ERROR_NOT_READY) @@ -1996,7 +1996,7 @@ static void pci_remove_qemu_trad_watch_state_cb(libxl= __egc *egc, if (rc) goto out; =20 - rc =3D qemu_pci_remove_xenstore(gc, domid, pcidev, prs->force); + rc =3D qemu_pci_remove_xenstore(gc, domid, pci, prs->force); =20 out: pci_remove_detatched(egc, prs, rc); @@ -2010,7 +2010,7 @@ static void pci_remove_qmp_device_del(libxl__egc *egc, int rc; =20 /* Convenience aliases */ - libxl_device_pci *const pcidev =3D prs->pcidev; + libxl_device_pci *const pci =3D prs->pci; =20 rc =3D libxl__ev_time_register_rel(ao, &prs->timeout, pci_remove_timeout, @@ -2018,7 +2018,7 @@ static void pci_remove_qmp_device_del(libxl__egc *egc, if (rc) goto out; =20 QMP_PARAMETERS_SPRINTF(&args, "id", PCI_PT_QDEV_ID, - pcidev->bus, pcidev->dev, pcidev->func); + pci->bus, pci->dev, pci->func); prs->qmp.callback =3D pci_remove_qmp_device_del_cb; rc =3D libxl__ev_qmp_send(egc, &prs->qmp, "device_del", args); if (rc) goto out; @@ -2080,14 +2080,14 @@ static void pci_remove_qmp_query_cb(libxl__egc *egc, =20 /* Convenience aliases */ libxl__ao *const ao =3D prs->aodev->ao; - libxl_device_pci *const pcidev =3D prs->pcidev; + libxl_device_pci *const pci =3D prs->pci; =20 if (rc) goto out; =20 libxl__ev_qmp_dispose(gc, qmp); =20 asked_id =3D GCSPRINTF(PCI_PT_QDEV_ID, - pcidev->bus, pcidev->dev, pcidev->func); + pci->bus, pci->dev, pci->func); =20 /* query-pci response: * [{ 'devices': [ 'qdev_id': 'str', ... ], ... }] @@ -2135,10 +2135,10 @@ static void pci_remove_timeout(libxl__egc *egc, lib= xl__ev_time *ev, pci_remove_state *prs =3D CONTAINER_OF(ev, *prs, timeout); =20 /* Convenience aliases */ - libxl_device_pci *const pcidev =3D prs->pcidev; + libxl_device_pci *const pci =3D prs->pci; =20 LOGD(WARN, prs->domid, "timed out waiting for DM to remove " - PCI_PT_QDEV_ID, pcidev->bus, pcidev->dev, pcidev->func); + PCI_PT_QDEV_ID, pci->bus, pci->dev, pci->func); =20 /* If we timed out, we might still want to keep destroying the device * (when force=3D=3Dtrue), so let the next function decide what to do = on @@ -2156,7 +2156,7 @@ static void pci_remove_detatched(libxl__egc *egc, bool isstubdom; =20 /* Convenience aliases */ - libxl_device_pci *const pcidev =3D prs->pcidev; + libxl_device_pci *const pci =3D prs->pci; libxl_domid domid =3D prs->domid; =20 /* Cleaning QMP states ASAP */ @@ -2170,30 +2170,30 @@ static void pci_remove_detatched(libxl__egc *egc, isstubdom =3D libxl_is_stubdom(CTX, domid, &domainid); =20 /* don't do multiple resets while some functions are still passed thro= ugh */ - if ( (pcidev->vdevfn & 0x7) =3D=3D 0 ) { - libxl__device_pci_reset(gc, pcidev->domain, pcidev->bus, pcidev->d= ev, pcidev->func); + if ((pci->vdevfn & 0x7) =3D=3D 0) { + libxl__device_pci_reset(gc, pci->domain, pci->bus, pci->dev, pci->= func); } =20 if (!isstubdom) { - rc =3D xc_deassign_device(CTX->xch, domid, pcidev_encode_bdf(pcide= v)); + rc =3D xc_deassign_device(CTX->xch, domid, pci_encode_bdf(pci)); if (rc < 0 && (prs->hvm || errno !=3D ENOSYS)) LOGED(ERROR, domainid, "xc_deassign_device failed"); } =20 stubdomid =3D libxl_get_stubdom_id(CTX, domid); if (stubdomid !=3D 0) { - libxl_device_pci *pcidev_s; + libxl_device_pci *pci_s; libxl__ao_device *const stubdom_aodev =3D &prs->stubdom_aodev; =20 - GCNEW(pcidev_s); - libxl_device_pci_init(pcidev_s); - libxl_device_pci_copy(CTX, pcidev_s, pcidev); + GCNEW(pci_s); + libxl_device_pci_init(pci_s); + libxl_device_pci_copy(CTX, pci_s, pci); =20 libxl__prepare_ao_device(ao, stubdom_aodev); stubdom_aodev->action =3D LIBXL__DEVICE_ACTION_REMOVE; stubdom_aodev->callback =3D pci_remove_stubdom_done; stubdom_aodev->update_json =3D prs->aodev->update_json; - libxl__device_pci_remove_common(egc, stubdomid, pcidev_s, + libxl__device_pci_remove_common(egc, stubdomid, pci_s, prs->force, stubdom_aodev); return; } @@ -2219,14 +2219,14 @@ static void pci_remove_done(libxl__egc *egc, =20 if (rc) goto out; =20 - libxl__device_pci_remove_xenstore(gc, prs->domid, prs->pcidev); + libxl__device_pci_remove_xenstore(gc, prs->domid, prs->pci); out: device_pci_remove_common_next(egc, prs, rc); } =20 static void libxl__device_pci_remove_common(libxl__egc *egc, uint32_t domid, - libxl_device_pci *pcidev, + libxl_device_pci *pci, bool force, libxl__ao_device *aodev) { @@ -2237,7 +2237,7 @@ static void libxl__device_pci_remove_common(libxl__eg= c *egc, GCNEW(prs); prs->aodev =3D aodev; prs->domid =3D domid; - prs->pcidev =3D pcidev; + prs->pci =3D pci; prs->force =3D force; libxl__xswait_init(&prs->xswait); libxl__ev_qmp_init(&prs->qmp); @@ -2247,16 +2247,16 @@ static void libxl__device_pci_remove_common(libxl__= egc *egc, libxl__ev_time_init(&prs->timeout); libxl__ev_time_init(&prs->retry_timer); =20 - prs->orig_vdev =3D pcidev->vdevfn & ~7U; + prs->orig_vdev =3D pci->vdevfn & ~7U; =20 - if ( pcidev->vfunc_mask =3D=3D LIBXL_PCI_FUNC_ALL ) { - if ( pci_multifunction_check(gc, pcidev, &prs->pfunc_mask) ) { + if ( pci->vfunc_mask =3D=3D LIBXL_PCI_FUNC_ALL ) { + if ( pci_multifunction_check(gc, pci, &prs->pfunc_mask) ) { rc =3D ERROR_FAIL; goto out; } - pcidev->vfunc_mask &=3D prs->pfunc_mask; - }else{ - prs->pfunc_mask =3D (1 << pcidev->func); + pci->vfunc_mask &=3D prs->pfunc_mask; + } else { + prs->pfunc_mask =3D (1 << pci->func); } =20 rc =3D 0; @@ -2273,7 +2273,7 @@ static void device_pci_remove_common_next(libxl__egc = *egc, =20 /* Convenience aliases */ libxl_domid domid =3D prs->domid; - libxl_device_pci *const pcidev =3D prs->pcidev; + libxl_device_pci *const pci =3D prs->pci; libxl__ao_device *const aodev =3D prs->aodev; const unsigned int pfunc_mask =3D prs->pfunc_mask; const unsigned int orig_vdev =3D prs->orig_vdev; @@ -2284,13 +2284,13 @@ static void device_pci_remove_common_next(libxl__eg= c *egc, const int i =3D prs->next_func; prs->next_func--; if ( (1 << i) & pfunc_mask ) { - if ( pcidev->vfunc_mask =3D=3D pfunc_mask ) { - pcidev->func =3D i; - pcidev->vdevfn =3D orig_vdev | i; - }else{ - pcidev->vdevfn =3D orig_vdev; + if ( pci->vfunc_mask =3D=3D pfunc_mask ) { + pci->func =3D i; + pci->vdevfn =3D orig_vdev | i; + } else { + pci->vdevfn =3D orig_vdev; } - do_pci_remove(egc, domid, pcidev, prs->force, prs); + do_pci_remove(egc, domid, pci, prs->force, prs); return; } } @@ -2306,7 +2306,7 @@ out: } =20 int libxl_device_pci_remove(libxl_ctx *ctx, uint32_t domid, - libxl_device_pci *pcidev, + libxl_device_pci *pci, const libxl_asyncop_how *ao_how) =20 { @@ -2318,12 +2318,12 @@ int libxl_device_pci_remove(libxl_ctx *ctx, uint32_= t domid, aodev->action =3D LIBXL__DEVICE_ACTION_REMOVE; aodev->callback =3D device_addrm_aocomplete; aodev->update_json =3D true; - libxl__device_pci_remove_common(egc, domid, pcidev, false, aodev); + libxl__device_pci_remove_common(egc, domid, pci, false, aodev); return AO_INPROGRESS; } =20 int libxl_device_pci_destroy(libxl_ctx *ctx, uint32_t domid, - libxl_device_pci *pcidev, + libxl_device_pci *pci, const libxl_asyncop_how *ao_how) { AO_CREATE(ctx, domid, ao_how); @@ -2334,7 +2334,7 @@ int libxl_device_pci_destroy(libxl_ctx *ctx, uint32_t= domid, aodev->action =3D LIBXL__DEVICE_ACTION_REMOVE; aodev->callback =3D device_addrm_aocomplete; aodev->update_json =3D true; - libxl__device_pci_remove_common(egc, domid, pcidev, true, aodev); + libxl__device_pci_remove_common(egc, domid, pci, true, aodev); return AO_INPROGRESS; } =20 @@ -2353,7 +2353,7 @@ static int libxl__device_pci_from_xs_be(libxl__gc *gc, if (s) vdevfn =3D strtol(s, (char **) NULL, 16); =20 - pcidev_struct_fill(pci, domain, bus, dev, func, vdevfn); + pci_struct_fill(pci, domain, bus, dev, func, vdevfn); =20 s =3D libxl__xs_read(gc, XBT_NULL, GCSPRINTF("%s/opts-%d", be_path, nr= )); if (s) { @@ -2398,7 +2398,7 @@ libxl_device_pci *libxl_device_pci_list(libxl_ctx *ct= x, uint32_t domid, int *num GC_INIT(ctx); char *be_path; unsigned int n, i; - libxl_device_pci *pcidevs =3D NULL; + libxl_device_pci *pcis =3D NULL; =20 *num =3D 0; =20 @@ -2407,28 +2407,28 @@ libxl_device_pci *libxl_device_pci_list(libxl_ctx *= ctx, uint32_t domid, int *num if (libxl__device_pci_get_num(gc, be_path, &n)) goto out; =20 - pcidevs =3D calloc(n, sizeof(libxl_device_pci)); + pcis =3D calloc(n, sizeof(libxl_device_pci)); =20 for (i =3D 0; i < n; i++) - libxl__device_pci_from_xs_be(gc, be_path, i, pcidevs + i); + libxl__device_pci_from_xs_be(gc, be_path, i, pcis + i); =20 *num =3D n; out: GC_FREE; - return pcidevs; + return pcis; } =20 void libxl__device_pci_destroy_all(libxl__egc *egc, uint32_t domid, libxl__multidev *multidev) { STATE_AO_GC(multidev->ao); - libxl_device_pci *pcidevs; + libxl_device_pci *pcis; int num, i; =20 - pcidevs =3D libxl_device_pci_list(CTX, domid, &num); - if ( pcidevs =3D=3D NULL ) + pcis =3D libxl_device_pci_list(CTX, domid, &num); + if ( pcis =3D=3D NULL ) return; - libxl__ptr_add(gc, pcidevs); + libxl__ptr_add(gc, pcis); =20 for (i =3D 0; i < num; i++) { /* Force remove on shutdown since, on HVM, qemu will not always @@ -2436,7 +2436,7 @@ void libxl__device_pci_destroy_all(libxl__egc *egc, u= int32_t domid, * devices by the time we even get here! */ libxl__ao_device *aodev =3D libxl__multidev_prepare(multidev); - libxl__device_pci_remove_common(egc, domid, pcidevs + i, true, + libxl__device_pci_remove_common(egc, domid, pcis + i, true, aodev); } } @@ -2449,13 +2449,13 @@ int libxl__grant_vga_iomem_permission(libxl__gc *gc= , const uint32_t domid, if (!libxl_defbool_val(d_config->b_info.u.hvm.gfx_passthru)) return 0; =20 - for (i =3D 0 ; i < d_config->num_pcidevs ; i++) { + for (i =3D 0 ; i < d_config->num_pcis ; i++) { uint64_t vga_iomem_start =3D 0xa0000 >> XC_PAGE_SHIFT; uint32_t stubdom_domid; - libxl_device_pci *pcidev =3D &d_config->pcidevs[i]; + libxl_device_pci *pci =3D &d_config->pcis[i]; unsigned long pci_device_class; =20 - if (sysfs_dev_get_class(gc, pcidev, &pci_device_class)) + if (sysfs_dev_get_class(gc, pci, &pci_device_class)) continue; if (pci_device_class !=3D 0x030000) /* VGA class */ continue; @@ -2494,7 +2494,7 @@ static int libxl_device_pci_compare(const libxl_devic= e_pci *d1, =20 #define libxl__device_pci_update_devid NULL =20 -DEFINE_DEVICE_TYPE_STRUCT_X(pcidev, pci, PCI, +DEFINE_DEVICE_TYPE_STRUCT(pci, PCI, .get_num =3D libxl__device_pci_get_num, .from_xenstore =3D libxl__device_pci_from_xs_be, ); diff --git a/tools/libs/light/libxl_types.idl b/tools/libs/light/libxl_type= s.idl index 9d3f05f399..20f8dd7cfa 100644 --- a/tools/libs/light/libxl_types.idl +++ b/tools/libs/light/libxl_types.idl @@ -940,7 +940,7 @@ libxl_domain_config =3D Struct("domain_config", [ =20 ("disks", Array(libxl_device_disk, "num_disks")), ("nics", Array(libxl_device_nic, "num_nics")), - ("pcidevs", Array(libxl_device_pci, "num_pcidevs")), + ("pcis", Array(libxl_device_pci, "num_pcis")), ("rdms", Array(libxl_device_rdm, "num_rdms")), ("dtdevs", Array(libxl_device_dtdev, "num_dtdevs")), ("vfbs", Array(libxl_device_vfb, "num_vfbs")), diff --git a/tools/libs/util/libxlu_pci.c b/tools/libs/util/libxlu_pci.c index 12fc0b3a7f..1d38fffce3 100644 --- a/tools/libs/util/libxlu_pci.c +++ b/tools/libs/util/libxlu_pci.c @@ -23,15 +23,15 @@ static int hex_convert(const char *str, unsigned int *v= al, unsigned int mask) return 0; } =20 -static int pcidev_struct_fill(libxl_device_pci *pcidev, unsigned int domai= n, - unsigned int bus, unsigned int dev, - unsigned int func, unsigned int vdevfn) +static int pci_struct_fill(libxl_device_pci *pci, unsigned int domain, + unsigned int bus, unsigned int dev, + unsigned int func, unsigned int vdevfn) { - pcidev->domain =3D domain; - pcidev->bus =3D bus; - pcidev->dev =3D dev; - pcidev->func =3D func; - pcidev->vdevfn =3D vdevfn; + pci->domain =3D domain; + pci->bus =3D bus; + pci->dev =3D dev; + pci->func =3D func; + pci->vdevfn =3D vdevfn; return 0; } =20 @@ -47,7 +47,7 @@ static int pcidev_struct_fill(libxl_device_pci *pcidev, u= nsigned int domain, #define STATE_RDM_STRATEGY 10 #define STATE_RESERVE_POLICY 11 #define INVALID 0xffffffff -int xlu_pci_parse_bdf(XLU_Config *cfg, libxl_device_pci *pcidev, const cha= r *str) +int xlu_pci_parse_bdf(XLU_Config *cfg, libxl_device_pci *pci, const char *= str) { unsigned state =3D STATE_DOMAIN; unsigned dom =3D INVALID, bus =3D INVALID, dev =3D INVALID, func =3D I= NVALID, vslot =3D 0; @@ -110,11 +110,11 @@ int xlu_pci_parse_bdf(XLU_Config *cfg, libxl_device_p= ci *pcidev, const char *str } *ptr =3D '\0'; if ( !strcmp(tok, "*") ) { - pcidev->vfunc_mask =3D LIBXL_PCI_FUNC_ALL; + pci->vfunc_mask =3D LIBXL_PCI_FUNC_ALL; }else{ if ( hex_convert(tok, &func, 0x7) ) goto parse_error; - pcidev->vfunc_mask =3D (1 << 0); + pci->vfunc_mask =3D (1 << 0); } tok =3D ptr + 1; } @@ -141,18 +141,18 @@ int xlu_pci_parse_bdf(XLU_Config *cfg, libxl_device_p= ci *pcidev, const char *str state =3D (*ptr =3D=3D ',') ? STATE_OPTIONS_K : STATE_TERM= INAL; *ptr =3D '\0'; if ( !strcmp(optkey, "msitranslate") ) { - pcidev->msitranslate =3D atoi(tok); + pci->msitranslate =3D atoi(tok); }else if ( !strcmp(optkey, "power_mgmt") ) { - pcidev->power_mgmt =3D atoi(tok); + pci->power_mgmt =3D atoi(tok); }else if ( !strcmp(optkey, "permissive") ) { - pcidev->permissive =3D atoi(tok); + pci->permissive =3D atoi(tok); }else if ( !strcmp(optkey, "seize") ) { - pcidev->seize =3D atoi(tok); + pci->seize =3D atoi(tok); } else if (!strcmp(optkey, "rdm_policy")) { if (!strcmp(tok, "strict")) { - pcidev->rdm_policy =3D LIBXL_RDM_RESERVE_POLICY_ST= RICT; + pci->rdm_policy =3D LIBXL_RDM_RESERVE_POLICY_STRIC= T; } else if (!strcmp(tok, "relaxed")) { - pcidev->rdm_policy =3D LIBXL_RDM_RESERVE_POLICY_RE= LAXED; + pci->rdm_policy =3D LIBXL_RDM_RESERVE_POLICY_RELAX= ED; } else { XLU__PCI_ERR(cfg, "%s is not an valid PCI RDM prop= erty" " policy: 'strict' or 'relaxed'.= ", @@ -175,7 +175,7 @@ int xlu_pci_parse_bdf(XLU_Config *cfg, libxl_device_pci= *pcidev, const char *str assert(dom !=3D INVALID && bus !=3D INVALID && dev !=3D INVALID && fun= c !=3D INVALID); =20 /* Just a pretty way to fill in the values */ - pcidev_struct_fill(pcidev, dom, bus, dev, func, vslot << 3); + pci_struct_fill(pci, dom, bus, dev, func, vslot << 3); =20 free(buf2); =20 diff --git a/tools/xl/xl_parse.c b/tools/xl/xl_parse.c index cae8eb679c..0765780d9f 100644 --- a/tools/xl/xl_parse.c +++ b/tools/xl/xl_parse.c @@ -1470,24 +1470,24 @@ void parse_config_data(const char *config_source, } =20 if (!xlu_cfg_get_list (config, "pci", &pcis, 0, 0)) { - d_config->num_pcidevs =3D 0; - d_config->pcidevs =3D NULL; + d_config->num_pcis =3D 0; + d_config->pcis =3D NULL; for(i =3D 0; (buf =3D xlu_cfg_get_listitem (pcis, i)) !=3D NULL; i= ++) { - libxl_device_pci *pcidev; - - pcidev =3D ARRAY_EXTEND_INIT_NODEVID(d_config->pcidevs, - d_config->num_pcidevs, - libxl_device_pci_init); - pcidev->msitranslate =3D pci_msitranslate; - pcidev->power_mgmt =3D pci_power_mgmt; - pcidev->permissive =3D pci_permissive; - pcidev->seize =3D pci_seize; + libxl_device_pci *pci; + + pci =3D ARRAY_EXTEND_INIT_NODEVID(d_config->pcis, + d_config->num_pcis, + libxl_device_pci_init); + pci->msitranslate =3D pci_msitranslate; + pci->power_mgmt =3D pci_power_mgmt; + pci->permissive =3D pci_permissive; + pci->seize =3D pci_seize; /* * Like other pci option, the per-device policy always follows * the global policy by default. */ - pcidev->rdm_policy =3D b_info->u.hvm.rdm.policy; - e =3D xlu_pci_parse_bdf(config, pcidev, buf); + pci->rdm_policy =3D b_info->u.hvm.rdm.policy; + e =3D xlu_pci_parse_bdf(config, pci, buf); if (e) { fprintf(stderr, "unable to parse PCI BDF `%s' for passthrough\n", @@ -1495,7 +1495,7 @@ void parse_config_data(const char *config_source, exit(-e); } } - if (d_config->num_pcidevs && c_info->type =3D=3D LIBXL_DOMAIN_TYPE= _PV) + if (d_config->num_pcis && c_info->type =3D=3D LIBXL_DOMAIN_TYPE_PV) libxl_defbool_set(&b_info->u.pv.e820_host, true); } =20 diff --git a/tools/xl/xl_pci.c b/tools/xl/xl_pci.c index 58345bdae2..34fcf5a4fa 100644 --- a/tools/xl/xl_pci.c +++ b/tools/xl/xl_pci.c @@ -24,20 +24,20 @@ =20 static void pcilist(uint32_t domid) { - libxl_device_pci *pcidevs; + libxl_device_pci *pcis; int num, i; =20 - pcidevs =3D libxl_device_pci_list(ctx, domid, &num); - if (pcidevs =3D=3D NULL) + pcis =3D libxl_device_pci_list(ctx, domid, &num); + if (pcis =3D=3D NULL) return; printf("Vdev Device\n"); for (i =3D 0; i < num; i++) { printf("%02x.%01x %04x:%02x:%02x.%01x\n", - (pcidevs[i].vdevfn >> 3) & 0x1f, pcidevs[i].vdevfn & 0x7, - pcidevs[i].domain, pcidevs[i].bus, pcidevs[i].dev, pcidevs[= i].func); - libxl_device_pci_dispose(&pcidevs[i]); + (pcis[i].vdevfn >> 3) & 0x1f, pcis[i].vdevfn & 0x7, + pcis[i].domain, pcis[i].bus, pcis[i].dev, pcis[i].func); + libxl_device_pci_dispose(&pcis[i]); } - free(pcidevs); + free(pcis); } =20 int main_pcilist(int argc, char **argv) @@ -57,28 +57,28 @@ int main_pcilist(int argc, char **argv) =20 static int pcidetach(uint32_t domid, const char *bdf, int force) { - libxl_device_pci pcidev; + libxl_device_pci pci; XLU_Config *config; int r =3D 0; =20 - libxl_device_pci_init(&pcidev); + libxl_device_pci_init(&pci); =20 config =3D xlu_cfg_init(stderr, "command line"); if (!config) { perror("xlu_cfg_inig"); exit(-1); } =20 - if (xlu_pci_parse_bdf(config, &pcidev, bdf)) { + if (xlu_pci_parse_bdf(config, &pci, bdf)) { fprintf(stderr, "pci-detach: malformed BDF specification \"%s\"\n"= , bdf); exit(2); } if (force) { - if (libxl_device_pci_destroy(ctx, domid, &pcidev, 0)) + if (libxl_device_pci_destroy(ctx, domid, &pci, 0)) r =3D 1; } else { - if (libxl_device_pci_remove(ctx, domid, &pcidev, 0)) + if (libxl_device_pci_remove(ctx, domid, &pci, 0)) r =3D 1; } =20 - libxl_device_pci_dispose(&pcidev); + libxl_device_pci_dispose(&pci); xlu_cfg_destroy(config); =20 return r; @@ -108,24 +108,24 @@ int main_pcidetach(int argc, char **argv) =20 static int pciattach(uint32_t domid, const char *bdf, const char *vs) { - libxl_device_pci pcidev; + libxl_device_pci pci; XLU_Config *config; int r =3D 0; =20 - libxl_device_pci_init(&pcidev); + libxl_device_pci_init(&pci); =20 config =3D xlu_cfg_init(stderr, "command line"); if (!config) { perror("xlu_cfg_inig"); exit(-1); } =20 - if (xlu_pci_parse_bdf(config, &pcidev, bdf)) { + if (xlu_pci_parse_bdf(config, &pci, bdf)) { fprintf(stderr, "pci-attach: malformed BDF specification \"%s\"\n"= , bdf); exit(2); } =20 - if (libxl_device_pci_add(ctx, domid, &pcidev, 0)) + if (libxl_device_pci_add(ctx, domid, &pci, 0)) r =3D 1; =20 - libxl_device_pci_dispose(&pcidev); + libxl_device_pci_dispose(&pci); xlu_cfg_destroy(config); =20 return r; @@ -155,19 +155,19 @@ int main_pciattach(int argc, char **argv) =20 static void pciassignable_list(void) { - libxl_device_pci *pcidevs; + libxl_device_pci *pcis; int num, i; =20 - pcidevs =3D libxl_device_pci_assignable_list(ctx, &num); + pcis =3D libxl_device_pci_assignable_list(ctx, &num); =20 - if ( pcidevs =3D=3D NULL ) + if ( pcis =3D=3D NULL ) return; for (i =3D 0; i < num; i++) { printf("%04x:%02x:%02x.%01x\n", - pcidevs[i].domain, pcidevs[i].bus, pcidevs[i].dev, pcidevs[= i].func); - libxl_device_pci_dispose(&pcidevs[i]); + pcis[i].domain, pcis[i].bus, pcis[i].dev, pcis[i].func); + libxl_device_pci_dispose(&pcis[i]); } - free(pcidevs); + free(pcis); } =20 int main_pciassignable_list(int argc, char **argv) @@ -184,24 +184,24 @@ int main_pciassignable_list(int argc, char **argv) =20 static int pciassignable_add(const char *bdf, int rebind) { - libxl_device_pci pcidev; + libxl_device_pci pci; XLU_Config *config; int r =3D 0; =20 - libxl_device_pci_init(&pcidev); + libxl_device_pci_init(&pci); =20 config =3D xlu_cfg_init(stderr, "command line"); if (!config) { perror("xlu_cfg_init"); exit(-1); } =20 - if (xlu_pci_parse_bdf(config, &pcidev, bdf)) { + if (xlu_pci_parse_bdf(config, &pci, bdf)) { fprintf(stderr, "pci-assignable-add: malformed BDF specification \= "%s\"\n", bdf); exit(2); } =20 - if (libxl_device_pci_assignable_add(ctx, &pcidev, rebind)) + if (libxl_device_pci_assignable_add(ctx, &pci, rebind)) r =3D 1; =20 - libxl_device_pci_dispose(&pcidev); + libxl_device_pci_dispose(&pci); xlu_cfg_destroy(config); =20 return r; @@ -226,24 +226,24 @@ int main_pciassignable_add(int argc, char **argv) =20 static int pciassignable_remove(const char *bdf, int rebind) { - libxl_device_pci pcidev; + libxl_device_pci pci; XLU_Config *config; int r =3D 0; =20 - libxl_device_pci_init(&pcidev); + libxl_device_pci_init(&pci); =20 config =3D xlu_cfg_init(stderr, "command line"); if (!config) { perror("xlu_cfg_init"); exit(-1); } =20 - if (xlu_pci_parse_bdf(config, &pcidev, bdf)) { + if (xlu_pci_parse_bdf(config, &pci, bdf)) { fprintf(stderr, "pci-assignable-remove: malformed BDF specificatio= n \"%s\"\n", bdf); exit(2); } =20 - if (libxl_device_pci_assignable_remove(ctx, &pcidev, rebind)) + if (libxl_device_pci_assignable_remove(ctx, &pci, rebind)) r =3D 1; =20 - libxl_device_pci_dispose(&pcidev); + libxl_device_pci_dispose(&pci); xlu_cfg_destroy(config); =20 return r; diff --git a/tools/xl/xl_sxp.c b/tools/xl/xl_sxp.c index 359a001570..b03e348ffb 100644 --- a/tools/xl/xl_sxp.c +++ b/tools/xl/xl_sxp.c @@ -190,16 +190,16 @@ void printf_info_sexp(int domid, libxl_domain_config = *d_config, FILE *fh) fprintf(fh, "\t)\n"); } =20 - for (i =3D 0; i < d_config->num_pcidevs; i++) { + for (i =3D 0; i < d_config->num_pcis; i++) { fprintf(fh, "\t(device\n"); fprintf(fh, "\t\t(pci\n"); fprintf(fh, "\t\t\t(pci dev %04x:%02x:%02x.%01x@%02x)\n", - d_config->pcidevs[i].domain, d_config->pcidevs[i].bus, - d_config->pcidevs[i].dev, d_config->pcidevs[i].func, - d_config->pcidevs[i].vdevfn); + d_config->pcis[i].domain, d_config->pcis[i].bus, + d_config->pcis[i].dev, d_config->pcis[i].func, + d_config->pcis[i].vdevfn); fprintf(fh, "\t\t\t(opts msitranslate %d power_mgmt %d)\n", - d_config->pcidevs[i].msitranslate, - d_config->pcidevs[i].power_mgmt); + d_config->pcis[i].msitranslate, + d_config->pcis[i].power_mgmt); fprintf(fh, "\t\t)\n"); fprintf(fh, "\t)\n"); } --=20 2.11.0 From nobody Sun May 5 11:10:29 2024 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=1603470228; cv=none; d=zohomail.com; s=zohoarc; b=f+qSd7zovVbzm8kUE/nGZ0cjh2qq3LXuTBtfmSE4wnew3nr0Ip2LNJJfpz86Y7Tcyy1z4mKOXktKLKWn2h8HPkCTFsQm3mXyTm9cj4otW+7FTuhgFMVyKEKCi9XMPOTWG/ppBepNrWMPM+ooJpNJU1qUK8TBO/pGR5RU6iZu9KU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603470228; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=kyqm8nP4Buhsk6mGmHQHc+zCmy1DFqv8sR89/X9OQ0M=; b=NeTh3le2voJMHd12EviKF4nHcMBnaZiCX39e+fGhgj0mGAtxJf5fUrq1sZlT2hfEV7UoWqAh+Cw0bYWsXgEw9X6Wvrj5/F9YttfC/bYJBDv/1Kttl3T8wjzaNc3QyWpwhwJ9Au1Csvtej2c7QKzLTITC3grHksbbNf466rFItU4= 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 16034702280611016.0456032778438; Fri, 23 Oct 2020 09:23:48 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.11159.29573 (Exim 4.92) (envelope-from ) id 1kVzqf-00083B-EP; Fri, 23 Oct 2020 16:23:25 +0000 Received: by outflank-mailman (output) from mailman id 11159.29573; Fri, 23 Oct 2020 16:23:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzqf-000832-Aa; Fri, 23 Oct 2020 16:23:25 +0000 Received: by outflank-mailman (input) for mailman id 11159; Fri, 23 Oct 2020 16:23:23 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzqd-00081j-TW for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:23:23 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 0e91dac0-7484-4bc2-9cda-ec2c9295f15a; Fri, 23 Oct 2020 16:23:23 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzqb-0008J2-Us; Fri, 23 Oct 2020 16:23:21 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqb-000376-NJ; Fri, 23 Oct 2020 16:23:21 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzqd-00081j-TW for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:23:23 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 0e91dac0-7484-4bc2-9cda-ec2c9295f15a; Fri, 23 Oct 2020 16:23:23 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzqb-0008J2-Us; Fri, 23 Oct 2020 16:23:21 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqb-000376-NJ; Fri, 23 Oct 2020 16:23:21 +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" X-Inumbo-ID: 0e91dac0-7484-4bc2-9cda-ec2c9295f15a DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=kyqm8nP4Buhsk6mGmHQHc+zCmy1DFqv8sR89/X9OQ0M=; b=N2imVYaF3AB50X40UqM0wt/DO HWQIc3/cUxNyg3kfuwHs6BsZh5bGinlZ7ysYPmJh6dYQSfjsdfJ7znSdn4vlkU/lA+iFBYpC3mAGq 1/XORhty1j3c92iWiO3Ho9il21i+ONQqJ/0qSbZsG0qsdmHHLqBvan0MTnrpprNmWQT4c=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson , Wei Liu Subject: [PATCH 02/25] libxl: use LIBXL_DEFINE_DEVICE_LIST for pci devices Date: Fri, 23 Oct 2020 16:22:51 +0000 Message-Id: <20201023162314.2235-3-paul@xen.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20201023162314.2235-1-paul@xen.org> References: <20201023162314.2235-1-paul@xen.org> X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paul Durrant Remove open coded definition of libxl_device_pci_list(). NOTE: Using the macro also defines libxl_device_pci_list_free() so a protot= ype for it is added. Subsequent patches will make used of it. Signed-off-by: Paul Durrant Acked-by: Christian Lindig --- Cc: Ian Jackson Cc: Wei Liu --- tools/include/libxl.h | 7 +++++++ tools/libs/light/libxl_pci.c | 27 ++------------------------- 2 files changed, 9 insertions(+), 25 deletions(-) diff --git a/tools/include/libxl.h b/tools/include/libxl.h index fbe4c81ba5..ee52d3cf7e 100644 --- a/tools/include/libxl.h +++ b/tools/include/libxl.h @@ -452,6 +452,12 @@ #define LIBXL_HAVE_CONFIG_PCIS 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 * * The only guarantee which libxl makes regarding 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_pci.c b/tools/libs/light/libxl_pci.c index 2ff1c64a31..515e74fe5a 100644 --- a/tools/libs/light/libxl_pci.c +++ b/tools/libs/light/libxl_pci.c @@ -2393,31 +2393,6 @@ 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) -{ - 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; - - 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; -} - void libxl__device_pci_destroy_all(libxl__egc *egc, uint32_t domid, libxl__multidev *multidev) { @@ -2492,6 +2467,8 @@ static int libxl_device_pci_compare(const libxl_devic= e_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, --=20 2.11.0 From nobody Sun May 5 11:10:29 2024 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=1603470226; cv=none; d=zohomail.com; s=zohoarc; b=JpVF8ZCM+0mReyjH1cZk2S+kzfPkj+TetdEGAOl+Sb6NkIEvZHJSBdHPHmjtFJeiDsWxS0npxjo8LLWsOZLA8wfkeqdpSvppv7DzrvhUs1a5vc0gcf56/xGw7yk3g4ypZUWtVS6GEM48PP5qCwf+0kcXaS89f/JcPoW2nlkR96U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603470226; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=jx3PjnZjVUkMl0nTJ/ptt3J2EPZY9Ep+JNq2r5DzMzg=; b=nf3I05eUlHl8Jtz27l3ySPEBF0G8fgIq5p5KdDodKazQBip0DC6nV4HlW7q7Os+ibps2bvTzmXDINklFfQMYu9rb7Aze7rRElyZgCvnj98sKUtGXEoIW9gF5ZX3mvOD55uVnU7O3JlBHw/HukzL7ZTHI+mS2qqbL+QUwK07hzz4= 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 160347022617289.01624138251395; Fri, 23 Oct 2020 09:23:46 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.11161.29597 (Exim 4.92) (envelope-from ) id 1kVzqk-000885-0Z; Fri, 23 Oct 2020 16:23:30 +0000 Received: by outflank-mailman (output) from mailman id 11161.29597; Fri, 23 Oct 2020 16:23:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzqj-00087y-Tb; Fri, 23 Oct 2020 16:23:29 +0000 Received: by outflank-mailman (input) for mailman id 11161; Fri, 23 Oct 2020 16:23:28 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzqi-00081j-Rz for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:23:28 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 79d71e5c-7d8c-4c80-abe7-635d4a86d4f5; Fri, 23 Oct 2020 16:23:23 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzqc-0008J8-Po; Fri, 23 Oct 2020 16:23:22 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqc-000376-HB; Fri, 23 Oct 2020 16:23:22 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzqi-00081j-Rz for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:23:28 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 79d71e5c-7d8c-4c80-abe7-635d4a86d4f5; Fri, 23 Oct 2020 16:23:23 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzqc-0008J8-Po; Fri, 23 Oct 2020 16:23:22 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqc-000376-HB; Fri, 23 Oct 2020 16:23:22 +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" X-Inumbo-ID: 79d71e5c-7d8c-4c80-abe7-635d4a86d4f5 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=jx3PjnZjVUkMl0nTJ/ptt3J2EPZY9Ep+JNq2r5DzMzg=; b=3S9cR+SJl4FReoaGiBqUu4J0t pVMo50e3/3gUicBPd4w81CCLEVHsqVSIJauT2TLpg9nDfm/otfSMWU9oYPsVbd50aKyobs1fNHMnE g3O+YXXLXQGpysTGjgRPuYFO35oLbcxXnt+ouxc6LwBub93TlsMI5BK+MerK0WG/Mbhvs=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson , Wei Liu Subject: [PATCH 03/25] libxl: use LIBXL_DEFINE_DEVICE_LIST for nic devices Date: Fri, 23 Oct 2020 16:22:52 +0000 Message-Id: <20201023162314.2235-4-paul@xen.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20201023162314.2235-1-paul@xen.org> References: <20201023162314.2235-1-paul@xen.org> X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paul Durrant Remove open-coded definitions of libxl_device_nic_list() and libxl_device_nic_list_free(). Signed-off-by: Paul Durrant Acked-by: Christian Lindig --- Cc: Ian Jackson Cc: Wei Liu This patch is slightly tangential. I just happend to notice the inefficiency while looking at code for various device types. --- tools/libs/light/libxl_nic.c | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/tools/libs/light/libxl_nic.c b/tools/libs/light/libxl_nic.c index 0e5d120ae9..a44058f929 100644 --- a/tools/libs/light/libxl_nic.c +++ b/tools/libs/light/libxl_nic.c @@ -403,24 +403,6 @@ static int libxl__nic_from_xenstore(libxl__gc *gc, con= st char *libxl_path, return rc; } =20 -libxl_device_nic *libxl_device_nic_list(libxl_ctx *ctx, uint32_t domid, in= t *num) -{ - libxl_device_nic *r; - - GC_INIT(ctx); - - r =3D libxl__device_list(gc, &libxl__nic_devtype, domid, num); - - GC_FREE; - - return r; -} - -void libxl_device_nic_list_free(libxl_device_nic* list, int num) -{ - libxl__device_list_free(&libxl__nic_devtype, list, num); -} - int libxl_device_nic_getinfo(libxl_ctx *ctx, uint32_t domid, const libxl_device_nic *nic, libxl_nicinfo *nicinfo) @@ -527,6 +509,7 @@ LIBXL_DEFINE_DEVID_TO_DEVICE(nic) LIBXL_DEFINE_DEVICE_ADD(nic) LIBXL_DEFINE_DEVICES_ADD(nic) LIBXL_DEFINE_DEVICE_REMOVE(nic) +LIBXL_DEFINE_DEVICE_LIST(nic) =20 DEFINE_DEVICE_TYPE_STRUCT(nic, VIF, .update_config =3D libxl_device_nic_update_config, --=20 2.11.0 From nobody Sun May 5 11:10:29 2024 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=1603470231; cv=none; d=zohomail.com; s=zohoarc; b=B24XJ/R/hAZHWJrAFGI9fvYhP1jlYd2uY3iQX1FOfarO7n1At/yWURrv8KkeCZXkYgDJc7geiQfbtAN0X4Qj2EMe471DqkakR/sGBPbGhgAOP4F3Ika+HPN74Yll8iDOduYBUQmrY13IQDcVKEQMJmOmbyl1sNG7cMcX6c0AQw4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603470231; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=Uuq1zUW4SAXAEEW1C7Mx/Yysa/gBiK1oEft0ZGe17wc=; b=jJPw9RWwhvERPF2R5aeYYITxhxcT/cxZd6H7+K5MPnSLyXr5uV5Mjk8pKTKYFIUJak7FawcvcHuRVYv6vnRCy7JrPuSbBKN2VvxwzN1hL6/MN3/43veoBsGxnDCha0jzWUvBgLIw2JRIPQpWYr/12R53em4nGJuzhXk3nIt6peM= 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 1603470231016733.6804009597935; Fri, 23 Oct 2020 09:23:51 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.11163.29621 (Exim 4.92) (envelope-from ) id 1kVzqp-0008G8-NM; Fri, 23 Oct 2020 16:23:35 +0000 Received: by outflank-mailman (output) from mailman id 11163.29621; Fri, 23 Oct 2020 16:23:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzqp-0008Fx-JB; Fri, 23 Oct 2020 16:23:35 +0000 Received: by outflank-mailman (input) for mailman id 11163; Fri, 23 Oct 2020 16:23:33 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzqn-00081j-S5 for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:23:33 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 0477d06b-3336-4a5f-a8a5-3a15c8eb6455; Fri, 23 Oct 2020 16:23:24 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzqd-0008JG-Iu; Fri, 23 Oct 2020 16:23:23 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqd-000376-B2; Fri, 23 Oct 2020 16:23:23 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzqn-00081j-S5 for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:23:33 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 0477d06b-3336-4a5f-a8a5-3a15c8eb6455; Fri, 23 Oct 2020 16:23:24 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzqd-0008JG-Iu; Fri, 23 Oct 2020 16:23:23 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqd-000376-B2; Fri, 23 Oct 2020 16:23:23 +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" X-Inumbo-ID: 0477d06b-3336-4a5f-a8a5-3a15c8eb6455 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=Uuq1zUW4SAXAEEW1C7Mx/Yysa/gBiK1oEft0ZGe17wc=; b=fpFK1KTwSmcH68N2XsSoIj34a T0iSmGw9/zEGiO63+ojlY18FPhklxXidcw/oty9m+CDCoD8l/nMg+cahmy19zlJwv8gIHqIdtyDnL TKlzN5bk8gpkvHJYZftJc7wFr1qDyMnowoYQtDVCkJwaNfQQAf8quea5dQCAZh/xhgLkE=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson , Wei Liu Subject: [PATCH 04/25] libxl: s/domainid/domid/g in libxl_pci.c Date: Fri, 23 Oct 2020 16:22:53 +0000 Message-Id: <20201023162314.2235-5-paul@xen.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20201023162314.2235-1-paul@xen.org> References: <20201023162314.2235-1-paul@xen.org> X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paul Durrant It's pointless having two stack variables to hold exactly the same value. Signed-off-by: Paul Durrant Acked-by: Christian Lindig --- Cc: Ian Jackson Cc: Wei Liu --- tools/libs/light/libxl_pci.c | 43 ++++++++++++++++++++--------------------= --- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/tools/libs/light/libxl_pci.c b/tools/libs/light/libxl_pci.c index 515e74fe5a..58242b5b94 100644 --- a/tools/libs/light/libxl_pci.c +++ b/tools/libs/light/libxl_pci.c @@ -1326,8 +1326,7 @@ static void pci_add_dm_done(libxl__egc *egc, int irq, i; int r; uint32_t flag =3D XEN_DOMCTL_DEV_RDM_RELAXED; - uint32_t domainid =3D domid; - bool isstubdom =3D libxl_is_stubdom(ctx, domid, &domainid); + bool isstubdom =3D libxl_is_stubdom(ctx, domid, &domid); =20 /* Convenience aliases */ bool starting =3D pas->starting; @@ -1349,7 +1348,7 @@ static void pci_add_dm_done(libxl__egc *egc, irq =3D 0; =20 if (f =3D=3D NULL) { - LOGED(ERROR, domainid, "Couldn't open %s", sysfs_path); + LOGED(ERROR, domid, "Couldn't open %s", sysfs_path); rc =3D ERROR_FAIL; goto out; } @@ -1361,7 +1360,7 @@ static void pci_add_dm_done(libxl__egc *egc, if (flags & PCI_BAR_IO) { r =3D xc_domain_ioport_permission(ctx->xch, domid, start, = size, 1); if (r < 0) { - LOGED(ERROR, domainid, + LOGED(ERROR, domid, "xc_domain_ioport_permission 0x%llx/0x%llx (erro= r %d)", start, size, r); fclose(f); @@ -1372,7 +1371,7 @@ static void pci_add_dm_done(libxl__egc *egc, r =3D xc_domain_iomem_permission(ctx->xch, domid, start>>X= C_PAGE_SHIFT, (size+(XC_PAGE_SIZE-1))>>X= C_PAGE_SHIFT, 1); if (r < 0) { - LOGED(ERROR, domainid, + LOGED(ERROR, domid, "xc_domain_iomem_permission 0x%llx/0x%llx (error= %d)", start, size, r); fclose(f); @@ -1387,13 +1386,13 @@ static void pci_add_dm_done(libxl__egc *egc, pci->bus, pci->dev, pci->func); f =3D fopen(sysfs_path, "r"); if (f =3D=3D NULL) { - LOGED(ERROR, domainid, "Couldn't open %s", sysfs_path); + LOGED(ERROR, domid, "Couldn't open %s", sysfs_path); goto out_no_irq; } if ((fscanf(f, "%u", &irq) =3D=3D 1) && irq) { r =3D xc_physdev_map_pirq(ctx->xch, domid, irq, &irq); if (r < 0) { - LOGED(ERROR, domainid, "xc_physdev_map_pirq irq=3D%d (error=3D= %d)", + LOGED(ERROR, domid, "xc_physdev_map_pirq irq=3D%d (error=3D%d)= ", irq, r); fclose(f); rc =3D ERROR_FAIL; @@ -1401,7 +1400,7 @@ static void pci_add_dm_done(libxl__egc *egc, } r =3D xc_domain_irq_permission(ctx->xch, domid, irq, 1); if (r < 0) { - LOGED(ERROR, domainid, + LOGED(ERROR, domid, "xc_domain_irq_permission irq=3D%d (error=3D%d)", irq, r= ); fclose(f); rc =3D ERROR_FAIL; @@ -1414,7 +1413,7 @@ static void pci_add_dm_done(libxl__egc *egc, if (pci->permissive) { if ( sysfs_write_bdf(gc, SYSFS_PCIBACK_DRIVER"/permissive", pci) < 0 ) { - LOGD(ERROR, domainid, "Setting permissive for device"); + LOGD(ERROR, domid, "Setting permissive for device"); rc =3D ERROR_FAIL; goto out; } @@ -1425,13 +1424,13 @@ out_no_irq: if (pci->rdm_policy =3D=3D LIBXL_RDM_RESERVE_POLICY_STRICT) { flag &=3D ~XEN_DOMCTL_DEV_RDM_RELAXED; } else if (pci->rdm_policy !=3D LIBXL_RDM_RESERVE_POLICY_RELAXED) { - LOGED(ERROR, domainid, "unknown rdm check flag."); + LOGED(ERROR, domid, "unknown rdm check flag."); rc =3D ERROR_FAIL; goto out; } r =3D xc_assign_device(ctx->xch, domid, pci_encode_bdf(pci), flag); if (r < 0 && (hvm || errno !=3D ENOSYS)) { - LOGED(ERROR, domainid, "xc_assign_device failed"); + LOGED(ERROR, domid, "xc_assign_device failed"); rc =3D ERROR_FAIL; goto out; } @@ -1877,7 +1876,6 @@ static void do_pci_remove(libxl__egc *egc, uint32_t d= omid, libxl_device_pci *assigned; libxl_domain_type type =3D libxl__domain_type(gc, domid); int rc, num; - uint32_t domainid =3D domid; =20 assigned =3D libxl_device_pci_list(ctx, domid, &num); if (assigned =3D=3D NULL) { @@ -1889,7 +1887,7 @@ static void do_pci_remove(libxl__egc *egc, uint32_t d= omid, rc =3D ERROR_INVAL; if ( !is_pci_in_array(assigned, num, pci->domain, pci->bus, pci->dev, pci->func) ) { - LOGD(ERROR, domainid, "PCI device not attached to this domain"); + LOGD(ERROR, domid, "PCI device not attached to this domain"); goto out_fail; } =20 @@ -1925,7 +1923,7 @@ static void do_pci_remove(libxl__egc *egc, uint32_t d= omid, int i; =20 if (f =3D=3D NULL) { - LOGED(ERROR, domainid, "Couldn't open %s", sysfs_path); + LOGED(ERROR, domid, "Couldn't open %s", sysfs_path); goto skip1; } for (i =3D 0; i < PROC_PCI_NUM_RESOURCES; i++) { @@ -1936,7 +1934,7 @@ static void do_pci_remove(libxl__egc *egc, uint32_t d= omid, if (flags & PCI_BAR_IO) { rc =3D xc_domain_ioport_permission(ctx->xch, domid, st= art, size, 0); if (rc < 0) - LOGED(ERROR, domainid, + LOGED(ERROR, domid, "xc_domain_ioport_permission error 0x%x/0x%x= ", start, size); @@ -1944,7 +1942,7 @@ static void do_pci_remove(libxl__egc *egc, uint32_t d= omid, rc =3D xc_domain_iomem_permission(ctx->xch, domid, sta= rt>>XC_PAGE_SHIFT, (size+(XC_PAGE_SIZE-1)= )>>XC_PAGE_SHIFT, 0); if (rc < 0) - LOGED(ERROR, domainid, + LOGED(ERROR, domid, "xc_domain_iomem_permission error 0x%x/0x%x", start, size); @@ -1957,17 +1955,17 @@ skip1: pci->bus, pci->dev, pci->func); f =3D fopen(sysfs_path, "r"); if (f =3D=3D NULL) { - LOGED(ERROR, domainid, "Couldn't open %s", sysfs_path); + LOGED(ERROR, domid, "Couldn't open %s", sysfs_path); goto skip_irq; } if ((fscanf(f, "%u", &irq) =3D=3D 1) && irq) { rc =3D xc_physdev_unmap_pirq(ctx->xch, domid, irq); if (rc < 0) { - LOGED(ERROR, domainid, "xc_physdev_unmap_pirq irq=3D%d", i= rq); + LOGED(ERROR, domid, "xc_physdev_unmap_pirq irq=3D%d", irq); } rc =3D xc_domain_irq_permission(ctx->xch, domid, irq, 0); if (rc < 0) { - LOGED(ERROR, domainid, "xc_domain_irq_permission irq=3D%d"= , irq); + LOGED(ERROR, domid, "xc_domain_irq_permission irq=3D%d", i= rq); } } fclose(f); @@ -2152,12 +2150,11 @@ static void pci_remove_detatched(libxl__egc *egc, { STATE_AO_GC(prs->aodev->ao); int stubdomid =3D 0; - uint32_t domainid =3D prs->domid; + uint32_t domid =3D prs->domid; bool isstubdom; =20 /* Convenience aliases */ libxl_device_pci *const pci =3D prs->pci; - libxl_domid domid =3D prs->domid; =20 /* Cleaning QMP states ASAP */ libxl__ev_qmp_dispose(gc, &prs->qmp); @@ -2167,7 +2164,7 @@ static void pci_remove_detatched(libxl__egc *egc, if (rc && !prs->force) goto out; =20 - isstubdom =3D libxl_is_stubdom(CTX, domid, &domainid); + isstubdom =3D libxl_is_stubdom(CTX, domid, &domid); =20 /* don't do multiple resets while some functions are still passed thro= ugh */ if ((pci->vdevfn & 0x7) =3D=3D 0) { @@ -2177,7 +2174,7 @@ static void pci_remove_detatched(libxl__egc *egc, if (!isstubdom) { rc =3D xc_deassign_device(CTX->xch, domid, pci_encode_bdf(pci)); if (rc < 0 && (prs->hvm || errno !=3D ENOSYS)) - LOGED(ERROR, domainid, "xc_deassign_device failed"); + LOGED(ERROR, domid, "xc_deassign_device failed"); } =20 stubdomid =3D libxl_get_stubdom_id(CTX, domid); --=20 2.11.0 From nobody Sun May 5 11:10:29 2024 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=1603470227; cv=none; d=zohomail.com; s=zohoarc; b=LgcCdy8bCLa6jREyt6oLvmEjldbrPfW7G7KIN0RnrH8VLEupphvDVxGm/GU31doAH0tELJvv5TeocrNsxal39TrKRTeDtjv+M2dnz+2xcY0tMwIypqbrbgjaI3TPybtuSksvQe5+rNZsJk/LsfKytYtiv9oVnTsAqrys8l51JWs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603470227; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=GJYb7sAQkLDokuXQ2JDjweeTgQOvSRxXD4pmq8a7R7o=; b=JWfeq5FhSs+wO7xYbOBGDRtaIevKJGif43v7crI2QuBaDQM7pg8ZKE9FDjB0jFquwFTSfZhwUqEujYyiqWYIhmmXd9p2QoREUOIsc5R4GnKrMHA13wuNWXw1N9JeTFgeQ8x+JIGnFA/AKOAfYcdU6QSasBV+MNu/EXPsQzd02QI= 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 1603470227967666.0639784847011; Fri, 23 Oct 2020 09:23:47 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.11160.29585 (Exim 4.92) (envelope-from ) id 1kVzqi-00085k-NZ; Fri, 23 Oct 2020 16:23:28 +0000 Received: by outflank-mailman (output) from mailman id 11160.29585; Fri, 23 Oct 2020 16:23:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzqi-00085c-KP; Fri, 23 Oct 2020 16:23:28 +0000 Received: by outflank-mailman (input) for mailman id 11160; Fri, 23 Oct 2020 16:23:27 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzqh-00081e-Bx for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:23:27 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id cf5bee94-46ef-4101-91c2-c55571be3951; Fri, 23 Oct 2020 16:23:25 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzqe-0008JN-CR; Fri, 23 Oct 2020 16:23:24 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqe-000376-4u; Fri, 23 Oct 2020 16:23:24 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzqh-00081e-Bx for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:23:27 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id cf5bee94-46ef-4101-91c2-c55571be3951; Fri, 23 Oct 2020 16:23:25 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzqe-0008JN-CR; Fri, 23 Oct 2020 16:23:24 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqe-000376-4u; Fri, 23 Oct 2020 16:23:24 +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" X-Inumbo-ID: cf5bee94-46ef-4101-91c2-c55571be3951 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=GJYb7sAQkLDokuXQ2JDjweeTgQOvSRxXD4pmq8a7R7o=; b=Mtpt2GuDcvRfR2zgRagk4wS1w /s0dAZ7L5AaFJRUpNbdEAT0qh1lO1iyiUguU6j1tox8ogTlAnt92iKbKzgxhnfi3RwGnQ5q1d2Sd+ CWcJCaFbeQOPTmkG4FhRsAFPQhBM7sFbbtJ9Gi7z9+2LRE/+d9EIzvx7mJEpeXAnWAed8=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson , Wei Liu Subject: [PATCH 05/25] libxl: s/detatched/detached in libxl_pci.c Date: Fri, 23 Oct 2020 16:22:54 +0000 Message-Id: <20201023162314.2235-6-paul@xen.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20201023162314.2235-1-paul@xen.org> References: <20201023162314.2235-1-paul@xen.org> X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paul Durrant Simply spelling correction. Purely cosmetic fix. Signed-off-by: Paul Durrant Acked-by: Christian Lindig --- Cc: Ian Jackson Cc: Wei Liu --- tools/libs/light/libxl_pci.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tools/libs/light/libxl_pci.c b/tools/libs/light/libxl_pci.c index 58242b5b94..3936d60a14 100644 --- a/tools/libs/light/libxl_pci.c +++ b/tools/libs/light/libxl_pci.c @@ -1860,7 +1860,7 @@ static void pci_remove_qmp_query_cb(libxl__egc *egc, libxl__ev_qmp *qmp, const libxl__json_object *response, int rc); static void pci_remove_timeout(libxl__egc *egc, libxl__ev_time *ev, const struct timeval *requested_abs, int rc); -static void pci_remove_detatched(libxl__egc *egc, +static void pci_remove_detached(libxl__egc *egc, pci_remove_state *prs, int rc); static void pci_remove_stubdom_done(libxl__egc *egc, libxl__ao_device *aodev); @@ -1973,7 +1973,7 @@ skip1: skip_irq: rc =3D 0; out_fail: - pci_remove_detatched(egc, prs, rc); /* must be last */ + pci_remove_detached(egc, prs, rc); /* must be last */ } =20 static void pci_remove_qemu_trad_watch_state_cb(libxl__egc *egc, @@ -1997,7 +1997,7 @@ static void pci_remove_qemu_trad_watch_state_cb(libxl= __egc *egc, rc =3D qemu_pci_remove_xenstore(gc, domid, pci, prs->force); =20 out: - pci_remove_detatched(egc, prs, rc); + pci_remove_detached(egc, prs, rc); } =20 static void pci_remove_qmp_device_del(libxl__egc *egc, @@ -2023,7 +2023,7 @@ static void pci_remove_qmp_device_del(libxl__egc *egc, return; =20 out: - pci_remove_detatched(egc, prs, rc); + pci_remove_detached(egc, prs, rc); } =20 static void pci_remove_qmp_device_del_cb(libxl__egc *egc, @@ -2046,7 +2046,7 @@ static void pci_remove_qmp_device_del_cb(libxl__egc *= egc, return; =20 out: - pci_remove_detatched(egc, prs, rc); + pci_remove_detached(egc, prs, rc); } =20 static void pci_remove_qmp_retry_timer_cb(libxl__egc *egc, libxl__ev_time = *ev, @@ -2062,7 +2062,7 @@ static void pci_remove_qmp_retry_timer_cb(libxl__egc = *egc, libxl__ev_time *ev, return; =20 out: - pci_remove_detatched(egc, prs, rc); + pci_remove_detached(egc, prs, rc); } =20 static void pci_remove_qmp_query_cb(libxl__egc *egc, @@ -2122,7 +2122,7 @@ static void pci_remove_qmp_query_cb(libxl__egc *egc, } =20 out: - pci_remove_detatched(egc, prs, rc); /* must be last */ + pci_remove_detached(egc, prs, rc); /* must be last */ } =20 static void pci_remove_timeout(libxl__egc *egc, libxl__ev_time *ev, @@ -2141,12 +2141,12 @@ static void pci_remove_timeout(libxl__egc *egc, lib= xl__ev_time *ev, /* If we timed out, we might still want to keep destroying the device * (when force=3D=3Dtrue), so let the next function decide what to do = on * error */ - pci_remove_detatched(egc, prs, rc); + pci_remove_detached(egc, prs, rc); } =20 -static void pci_remove_detatched(libxl__egc *egc, - pci_remove_state *prs, - int rc) +static void pci_remove_detached(libxl__egc *egc, + pci_remove_state *prs, + int rc) { STATE_AO_GC(prs->aodev->ao); int stubdomid =3D 0; --=20 2.11.0 From nobody Sun May 5 11:10:29 2024 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=1603470231; cv=none; d=zohomail.com; s=zohoarc; b=BGbeTwT/eRZ+QT0JmT/joTiunwZnqp7qnEhrurczkaK3IpIDEg0zy0u3WbUD5c1rsaPPYw9kcLcE8RjCwWTGMuv6n4lm/L+mvE1QorIn+YSlmhcAn6eBwsNqqfvj8G6GQoMgJLYycdjpBzyGdSmua05xCX2xHr3gf4horTuu/kE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603470231; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=d5hhK/pKE8zCFXVC7B3RNGDmz0Oe2e31kzCzkBdDeBM=; b=l016uQyCr2VVf+CxMtGiFn7vV9bN0V97DBuOyIGuqxRSCTDTXP04W20tz8qiZAsf/4oC9p/0NDsUq0dIyZMj2ACEE3VAjdgezutKyzOW7bWbGmbPK6NxRJ2+zksof3PZjiCunECsGapc7GEUM759+BxRcKlQvx9Aichvi7r62X8= 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 1603470230997385.4645475612832; Fri, 23 Oct 2020 09:23:50 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.11162.29609 (Exim 4.92) (envelope-from ) id 1kVzqo-0008DD-A9; Fri, 23 Oct 2020 16:23:34 +0000 Received: by outflank-mailman (output) from mailman id 11162.29609; Fri, 23 Oct 2020 16:23:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzqo-0008D4-6l; Fri, 23 Oct 2020 16:23:34 +0000 Received: by outflank-mailman (input) for mailman id 11162; Fri, 23 Oct 2020 16:23:32 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzqm-00081e-C8 for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:23:32 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 5d74bd44-e25a-4dd0-a026-178d0dc88266; Fri, 23 Oct 2020 16:23:26 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzqf-0008JU-6J; Fri, 23 Oct 2020 16:23:25 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqe-000376-V3; Fri, 23 Oct 2020 16:23:25 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzqm-00081e-C8 for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:23:32 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 5d74bd44-e25a-4dd0-a026-178d0dc88266; Fri, 23 Oct 2020 16:23:26 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzqf-0008JU-6J; Fri, 23 Oct 2020 16:23:25 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqe-000376-V3; Fri, 23 Oct 2020 16:23:25 +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" X-Inumbo-ID: 5d74bd44-e25a-4dd0-a026-178d0dc88266 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=d5hhK/pKE8zCFXVC7B3RNGDmz0Oe2e31kzCzkBdDeBM=; b=BR9viEbkG0CJzaf6Fobq/85Yi QIo8B/2Mvcg7lWD+3Jf4532XLAir3N9SagRDNWRaDo3lk8vgmbIPuIJGS40SmeKVCSnR6wAtn7+1s gf7mAs1QW3Xo31BOFQVI1QatbHKmbicpV67Ws6KA4Ad6SuZQijq0hsPJ2C7FdYXl6x8mQ=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson , Wei Liu Subject: [PATCH 06/25] libxl: remove extraneous arguments to do_pci_remove() in libxl_pci.c Date: Fri, 23 Oct 2020 16:22:55 +0000 Message-Id: <20201023162314.2235-7-paul@xen.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20201023162314.2235-1-paul@xen.org> References: <20201023162314.2235-1-paul@xen.org> X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paul Durrant Both 'domid' and 'pci' are available in 'pci_remove_state' so there is no need to also pass them as separate arguments. Signed-off-by: Paul Durrant Acked-by: Christian Lindig --- Cc: Ian Jackson Cc: Wei Liu --- tools/libs/light/libxl_pci.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tools/libs/light/libxl_pci.c b/tools/libs/light/libxl_pci.c index 3936d60a14..97889fda49 100644 --- a/tools/libs/light/libxl_pci.c +++ b/tools/libs/light/libxl_pci.c @@ -1867,14 +1867,14 @@ static void pci_remove_stubdom_done(libxl__egc *egc, static void pci_remove_done(libxl__egc *egc, pci_remove_state *prs, int rc); =20 -static void do_pci_remove(libxl__egc *egc, uint32_t domid, - libxl_device_pci *pci, int force, - pci_remove_state *prs) +static void do_pci_remove(libxl__egc *egc, pci_remove_state *prs) { STATE_AO_GC(prs->aodev->ao); libxl_ctx *ctx =3D libxl__gc_owner(gc); libxl_device_pci *assigned; + uint32_t domid =3D prs->domid; libxl_domain_type type =3D libxl__domain_type(gc, domid); + libxl_device_pci *pci =3D prs->pci; int rc, num; =20 assigned =3D libxl_device_pci_list(ctx, domid, &num); @@ -2269,7 +2269,6 @@ static void device_pci_remove_common_next(libxl__egc = *egc, EGC_GC; =20 /* Convenience aliases */ - libxl_domid domid =3D prs->domid; libxl_device_pci *const pci =3D prs->pci; libxl__ao_device *const aodev =3D prs->aodev; const unsigned int pfunc_mask =3D prs->pfunc_mask; @@ -2287,7 +2286,7 @@ static void device_pci_remove_common_next(libxl__egc = *egc, } else { pci->vdevfn =3D orig_vdev; } - do_pci_remove(egc, domid, pci, prs->force, prs); + do_pci_remove(egc, prs); return; } } --=20 2.11.0 From nobody Sun May 5 11:10:29 2024 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=1603470238; cv=none; d=zohomail.com; s=zohoarc; b=kPasP8remX/vAKVze3lj1vm93Vdi3KhPMtwXfRQJCM7VLwbf9RAlMtn0EDCnQ8GHq5UpkSfEnPyFFhmUJ7jIcWWN4P2wYwezAKL7HYFyYcnk+YbcsBn3tTPLcncU7rap23qjdPIbUoSdXCC8mc3WoeVN7t5WTSp6dfn53WBcg3Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603470238; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=ORjVh3eyNwRmvhpvuOMksACO9sNjoM6DFI5Mu3lxT+8=; b=mJfvCFX2abzZXwN+EzWW49854GCp0q6BBVUoeC92TQZY7CpWAbw7vIfS6EZa1CQaBUPe5yvmo5YFT85fHHkyLbJ+Z1wWXksbQv6Rdp1IF+bmrza/McvWFyY2URn1F08CVuVP9ZbobrMleI2Wq9CdmKdEpK7nBKRhllkOP+hNzB0= 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 1603470238231283.6598850210796; Fri, 23 Oct 2020 09:23:58 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.11165.29644 (Exim 4.92) (envelope-from ) id 1kVzqu-0008P1-DB; Fri, 23 Oct 2020 16:23:40 +0000 Received: by outflank-mailman (output) from mailman id 11165.29644; Fri, 23 Oct 2020 16:23:40 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzqu-0008Ok-32; Fri, 23 Oct 2020 16:23:40 +0000 Received: by outflank-mailman (input) for mailman id 11165; Fri, 23 Oct 2020 16:23:38 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzqs-00081j-SC for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:23:38 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id aa8e3bea-270a-4ca5-afec-b1e30f05f168; Fri, 23 Oct 2020 16:23:27 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzqg-0008Jb-0D; Fri, 23 Oct 2020 16:23:26 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqf-000376-Ov; Fri, 23 Oct 2020 16:23:25 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzqs-00081j-SC for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:23:38 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id aa8e3bea-270a-4ca5-afec-b1e30f05f168; Fri, 23 Oct 2020 16:23:27 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzqg-0008Jb-0D; Fri, 23 Oct 2020 16:23:26 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqf-000376-Ov; Fri, 23 Oct 2020 16:23:25 +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" X-Inumbo-ID: aa8e3bea-270a-4ca5-afec-b1e30f05f168 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=ORjVh3eyNwRmvhpvuOMksACO9sNjoM6DFI5Mu3lxT+8=; b=jksCA09h/pKmnh61JI897CrQH j+q+5lCplucUTLHgXEa1w6zqNc8qgoZMNAQMRV82qkkjnmGyV3R9uLsQH5dt4SAuLECFD/qKEuCGm TyBuVraoreUmzOvQsDM4RWiugqXUZilSrdtWxAygRvJrsOUV0VNaws/R5UUhwDYY7kL+s=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson , Wei Liu Subject: [PATCH 07/25] libxl: stop using aodev->device_config in libxl__device_pci_add()... Date: Fri, 23 Oct 2020 16:22:56 +0000 Message-Id: <20201023162314.2235-8-paul@xen.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20201023162314.2235-1-paul@xen.org> References: <20201023162314.2235-1-paul@xen.org> X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paul Durrant ... to hold a pointer to the device. There is already a 'pci' field in 'pci_add_state' so simply use that from the start. This also allows the 'pci' (#3) argument to be dropped from do_pci_add(). NOTE: This patch also changes the type of the 'pci_domid' field in 'pci_add_state' from 'int' to 'libxl_domid' which is more appropriate given what the field is used for. Signed-off-by: Paul Durrant Acked-by: Christian Lindig --- Cc: Ian Jackson Cc: Wei Liu --- tools/libs/light/libxl_pci.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/tools/libs/light/libxl_pci.c b/tools/libs/light/libxl_pci.c index 97889fda49..b8d8cc6a69 100644 --- a/tools/libs/light/libxl_pci.c +++ b/tools/libs/light/libxl_pci.c @@ -1055,7 +1055,7 @@ typedef struct pci_add_state { libxl__ev_qmp qmp; libxl__ev_time timeout; libxl_device_pci *pci; - int pci_domid; + libxl_domid pci_domid; } pci_add_state; =20 static void pci_add_qemu_trad_watch_state_cb(libxl__egc *egc, @@ -1072,7 +1072,6 @@ static void pci_add_dm_done(libxl__egc *, =20 static void do_pci_add(libxl__egc *egc, libxl_domid domid, - libxl_device_pci *pci, pci_add_state *pas) { STATE_AO_GC(pas->aodev->ao); @@ -1082,7 +1081,6 @@ static void do_pci_add(libxl__egc *egc, /* init pci_add_state */ libxl__xswait_init(&pas->xswait); libxl__ev_qmp_init(&pas->qmp); - pas->pci =3D pci; pas->pci_domid =3D domid; libxl__ev_time_init(&pas->timeout); =20 @@ -1544,13 +1542,10 @@ void libxl__device_pci_add(libxl__egc *egc, uint32_= t domid, int stubdomid =3D 0; pci_add_state *pas; =20 - /* Store *pci to be used by callbacks */ - aodev->device_config =3D pci; - aodev->device_type =3D &libxl__pci_devtype; - GCNEW(pas); pas->aodev =3D aodev; pas->domid =3D domid; + pas->pci =3D pci; pas->starting =3D starting; pas->callback =3D device_pci_add_stubdom_done; =20 @@ -1604,9 +1599,10 @@ void libxl__device_pci_add(libxl__egc *egc, uint32_t= domid, GCNEW(pci_s); libxl_device_pci_init(pci_s); libxl_device_pci_copy(CTX, pci_s, pci); + pas->pci =3D pci_s; pas->callback =3D device_pci_add_stubdom_wait; =20 - do_pci_add(egc, stubdomid, pci_s, pas); /* must be last */ + do_pci_add(egc, stubdomid, pas); /* must be last */ return; } =20 @@ -1661,9 +1657,8 @@ static void device_pci_add_stubdom_done(libxl__egc *e= gc, int i; =20 /* Convenience aliases */ - libxl__ao_device *aodev =3D pas->aodev; libxl_domid domid =3D pas->domid; - libxl_device_pci *pci =3D aodev->device_config; + libxl_device_pci *pci =3D pas->pci; =20 if (rc) goto out; =20 @@ -1698,7 +1693,7 @@ static void device_pci_add_stubdom_done(libxl__egc *e= gc, pci->vdevfn =3D orig_vdev; } pas->callback =3D device_pci_add_done; - do_pci_add(egc, domid, pci, pas); /* must be last */ + do_pci_add(egc, domid, pas); /* must be last */ return; } } @@ -1714,7 +1709,7 @@ static void device_pci_add_done(libxl__egc *egc, EGC_GC; libxl__ao_device *aodev =3D pas->aodev; libxl_domid domid =3D pas->domid; - libxl_device_pci *pci =3D aodev->device_config; + libxl_device_pci *pci =3D pas->pci; =20 if (rc) { LOGD(ERROR, domid, --=20 2.11.0 From nobody Sun May 5 11:10:29 2024 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=1603470240; cv=none; d=zohomail.com; s=zohoarc; b=n8XAvF+T/1lmttU06pvu1kzQA4G06hIDICnkNZPWRajrSiNWtpp8XVDyoQKpL0hz0M7ZZF+C0GvJIJqQ0LCwPu4ArgPYuuMz0EV5EfJ7nS1ORYU+9wFSayssuFKO29GyydrE2bqxVT/hFjZetQRjsV7mBIl68kdbJxs8jztAuGY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603470240; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=QJzbQ3Np4pSqJz9X+hJwu3xWTD3Y5IwSiZezmKwHDvM=; b=YEkvOJkV43QY4IlZw2llGAe+OO4kd8CnWjqAeBokVV2R1VBXUTH3jzZ3P7XzKhSthfznvEeSDPI3/JGxJ9EzeQfx0MJqN7CH0AnbnhDvr3jaNs7WOzbyaDDEuvixKQpzUahnWEnzGjv06pvH4ntYUgWl17XSfVqJVQzeYDcvWJM= 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 1603470240292998.1924903274452; Fri, 23 Oct 2020 09:24:00 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.11166.29657 (Exim 4.92) (envelope-from ) id 1kVzqx-0008WM-R6; Fri, 23 Oct 2020 16:23:43 +0000 Received: by outflank-mailman (output) from mailman id 11166.29657; Fri, 23 Oct 2020 16:23:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzqx-0008WB-M7; Fri, 23 Oct 2020 16:23:43 +0000 Received: by outflank-mailman (input) for mailman id 11166; Fri, 23 Oct 2020 16:23:42 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzqw-00081e-Ci for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:23:42 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 67bb7164-12ad-405d-bbf8-688efe3dd4bd; Fri, 23 Oct 2020 16:23:27 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzqg-0008Jg-Q9; Fri, 23 Oct 2020 16:23:26 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqg-000376-In; Fri, 23 Oct 2020 16:23:26 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzqw-00081e-Ci for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:23:42 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 67bb7164-12ad-405d-bbf8-688efe3dd4bd; Fri, 23 Oct 2020 16:23:27 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzqg-0008Jg-Q9; Fri, 23 Oct 2020 16:23:26 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqg-000376-In; Fri, 23 Oct 2020 16:23:26 +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" X-Inumbo-ID: 67bb7164-12ad-405d-bbf8-688efe3dd4bd DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=QJzbQ3Np4pSqJz9X+hJwu3xWTD3Y5IwSiZezmKwHDvM=; b=v3MNx6rAv6sCfXHLzOAXuI4BS jVqc+IqLPnZDvdlkmuUlIOFVQu5CSYKu2H0CqZ4m45XCv9FdsAv92CSoCMjz4zu5b92AzZIxMK6ZU LsFNkG9q+u1nM1sTsyoec5xoYz885bfhcz265Mr3Np7oaEeZY+DX/ny5g55DyuYGsLKxs=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson , Wei Liu Subject: [PATCH 08/25] libxl: generalise 'driver_path' xenstore access functions in libxl_pci.c Date: Fri, 23 Oct 2020 16:22:57 +0000 Message-Id: <20201023162314.2235-9-paul@xen.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20201023162314.2235-1-paul@xen.org> References: <20201023162314.2235-1-paul@xen.org> X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paul Durrant For the purposes of re-binding a device to its previous driver libxl__device_pci_assignable_add() writes the driver path into xenstore. This path is then read back in libxl__device_pci_assignable_remove(). The functions that support this writing to and reading from xenstore are currently dedicated for this purpose and hence the node name 'driver_path' is hard-coded. This patch generalizes these utility functions and passes 'driver_path' as an argument. Subsequent patches will invoke them to access other nodes. NOTE: Because functions will have a broader use (other than storing a driver path in lieu of pciback) the base xenstore path is also changed from '/libxl/pciback' to '/libxl/pci'. Signed-off-by: Paul Durrant Acked-by: Christian Lindig --- Cc: Ian Jackson Cc: Wei Liu --- tools/libs/light/libxl_pci.c | 66 +++++++++++++++++++++-------------------= ---- 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/tools/libs/light/libxl_pci.c b/tools/libs/light/libxl_pci.c index b8d8cc6a69..f74203100d 100644 --- a/tools/libs/light/libxl_pci.c +++ b/tools/libs/light/libxl_pci.c @@ -718,48 +718,46 @@ static int pciback_dev_unassign(libxl__gc *gc, libxl_= device_pci *pci) return 0; } =20 -#define PCIBACK_INFO_PATH "/libxl/pciback" +#define PCI_INFO_PATH "/libxl/pci" =20 -static void pci_assignable_driver_path_write(libxl__gc *gc, - libxl_device_pci *pci, - char *driver_path) +static char *pci_info_xs_path(libxl__gc *gc, libxl_device_pci *pci, + const char *node) { - char *path; + return node ? + GCSPRINTF(PCI_INFO_PATH"/"PCI_BDF_XSPATH"/%s", + pci->domain, pci->bus, pci->dev, pci->func, + node) : + GCSPRINTF(PCI_INFO_PATH"/"PCI_BDF_XSPATH, + pci->domain, pci->bus, pci->dev, pci->func); +} + + +static void pci_info_xs_write(libxl__gc *gc, libxl_device_pci *pci, + const char *node, const char *val) +{ + char *path =3D pci_info_xs_path(gc, pci, node); =20 - path =3D GCSPRINTF(PCIBACK_INFO_PATH"/"PCI_BDF_XSPATH"/driver_path", - pci->domain, - pci->bus, - pci->dev, - pci->func); - if ( libxl__xs_printf(gc, XBT_NULL, path, "%s", driver_path) < 0 ) { - LOGE(WARN, "Write of %s to node %s failed.", driver_path, path); + if ( libxl__xs_printf(gc, XBT_NULL, path, "%s", val) < 0 ) { + LOGE(WARN, "Write of %s to node %s failed.", val, path); } } =20 -static char * pci_assignable_driver_path_read(libxl__gc *gc, - libxl_device_pci *pci) +static char *pci_info_xs_read(libxl__gc *gc, libxl_device_pci *pci, + const char *node) { - return libxl__xs_read(gc, XBT_NULL, - GCSPRINTF( - PCIBACK_INFO_PATH "/" PCI_BDF_XSPATH "/driver_p= ath", - pci->domain, - pci->bus, - pci->dev, - pci->func)); + char *path =3D pci_info_xs_path(gc, pci, node); + + return libxl__xs_read(gc, XBT_NULL, path); } =20 -static void pci_assignable_driver_path_remove(libxl__gc *gc, - libxl_device_pci *pci) +static void pci_info_xs_remove(libxl__gc *gc, libxl_device_pci *pci, + const char *node) { + char *path =3D pci_info_xs_path(gc, pci, node); libxl_ctx *ctx =3D libxl__gc_owner(gc); =20 /* Remove the xenstore entry */ - xs_rm(ctx->xsh, XBT_NULL, - GCSPRINTF(PCIBACK_INFO_PATH "/" PCI_BDF_XSPATH, - pci->domain, - pci->bus, - pci->dev, - pci->func) ); + xs_rm(ctx->xsh, XBT_NULL, path); } =20 static int libxl__device_pci_assignable_add(libxl__gc *gc, @@ -805,9 +803,9 @@ static int libxl__device_pci_assignable_add(libxl__gc *= gc, /* Store driver_path for rebinding to dom0 */ if ( rebind ) { if ( driver_path ) { - pci_assignable_driver_path_write(gc, pci, driver_path); + pci_info_xs_write(gc, pci, "driver_path", driver_path); } else if ( (driver_path =3D - pci_assignable_driver_path_read(gc, pci)) !=3D NULL )= { + pci_info_xs_read(gc, pci, "driver_path")) !=3D NULL )= { LOG(INFO, PCI_BDF" not bound to a driver, will be rebound to %= s", dom, bus, dev, func, driver_path); } else { @@ -815,7 +813,7 @@ static int libxl__device_pci_assignable_add(libxl__gc *= gc, dom, bus, dev, func); } } else { - pci_assignable_driver_path_remove(gc, pci); + pci_info_xs_remove(gc, pci, "driver_path"); } =20 if ( pciback_dev_assign(gc, pci) ) { @@ -865,7 +863,7 @@ static int libxl__device_pci_assignable_remove(libxl__g= c *gc, } =20 /* Rebind if necessary */ - driver_path =3D pci_assignable_driver_path_read(gc, pci); + driver_path =3D pci_info_xs_read(gc, pci, "driver_path"); =20 if ( driver_path ) { if ( rebind ) { @@ -878,7 +876,7 @@ static int libxl__device_pci_assignable_remove(libxl__g= c *gc, return -1; } =20 - pci_assignable_driver_path_remove(gc, pci); + pci_info_xs_remove(gc, pci, "driver_path"); } } else { if ( rebind ) { --=20 2.11.0 From nobody Sun May 5 11:10:29 2024 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=1603470242; cv=none; d=zohomail.com; s=zohoarc; b=j9Q+vUlGSguVJoLD9Zsys18BtB29ggvcXY+LNgA1NAgGpMoZTynxBnWb8qQDMO4U1GiEK85h8gzOMyqpZxYJIiRS5ieafFieEN4hV7mUJ3wNMgoZbjXEK38xv6i3GYPPmjyHe0W0VWzcFIXWTX3CnHDEfIB2NCMesJlqY45HojE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603470242; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=DQUDwHY5sR5Fv3fHlALRKj3/AMe6ExqKLpToY1+yr+I=; b=JpXw4C+5aPiwfGMWDGXP9xi8Wlei8ufzez7Oc95N2v98Lw4CN/6v1swOVZNDHOHfcaH+mqcp0I1hZpXihD75IvLhgxk0m1LM4Mjh5GIiwdT0PkeyIW1HWaPQfAwqg/QU1J/jrfRB3rOBR12brLzfE5U0wdn/DemLSlngc6EkCHs= 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 1603470242037940.6001913307987; Fri, 23 Oct 2020 09:24:02 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.11170.29669 (Exim 4.92) (envelope-from ) id 1kVzr2-0000DE-An; Fri, 23 Oct 2020 16:23:48 +0000 Received: by outflank-mailman (output) from mailman id 11170.29669; Fri, 23 Oct 2020 16:23:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzr2-0000Cv-5Y; Fri, 23 Oct 2020 16:23:48 +0000 Received: by outflank-mailman (input) for mailman id 11170; Fri, 23 Oct 2020 16:23:47 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzr1-00081e-D3 for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:23:47 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 45b5f1c7-5366-42f6-873d-8647cb949167; Fri, 23 Oct 2020 16:23:28 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzqh-0008Jp-K8; Fri, 23 Oct 2020 16:23:27 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqh-000376-Ce; Fri, 23 Oct 2020 16:23:27 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzr1-00081e-D3 for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:23:47 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 45b5f1c7-5366-42f6-873d-8647cb949167; Fri, 23 Oct 2020 16:23:28 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzqh-0008Jp-K8; Fri, 23 Oct 2020 16:23:27 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqh-000376-Ce; Fri, 23 Oct 2020 16:23:27 +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" X-Inumbo-ID: 45b5f1c7-5366-42f6-873d-8647cb949167 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=DQUDwHY5sR5Fv3fHlALRKj3/AMe6ExqKLpToY1+yr+I=; b=4XEB77K0rvyyg7sYB7vvSU002 m5vvIMhMYWkEkxgA3OUrYmsAz5r7IvJn5KOC5wnt+15IN9KZVH+eGmW0RFrMUOr3Z4HFw0LJvje0t S0LixHDPrZLZuD6eOnsjpucaEGxejpQY/CCgvFhBd6RM6W7DhjM8sl0BT9wy+XKiuTTcQ=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson , Wei Liu Subject: [PATCH 09/25] libxl: remove unnecessary check from libxl__device_pci_add() Date: Fri, 23 Oct 2020 16:22:58 +0000 Message-Id: <20201023162314.2235-10-paul@xen.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20201023162314.2235-1-paul@xen.org> References: <20201023162314.2235-1-paul@xen.org> X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paul Durrant The code currently checks explicitly whether the device is already assigned, but this is actually unnecessary as assigned devices do not form part of the list returned by libxl_device_pci_assignable_list() and hence the libxl_pci_assignable() test would have already failed. Signed-off-by: Paul Durrant Acked-by: Christian Lindig --- Cc: Ian Jackson Cc: Wei Liu --- tools/libs/light/libxl_pci.c | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/tools/libs/light/libxl_pci.c b/tools/libs/light/libxl_pci.c index f74203100d..0be1b21185 100644 --- a/tools/libs/light/libxl_pci.c +++ b/tools/libs/light/libxl_pci.c @@ -1535,8 +1535,7 @@ void libxl__device_pci_add(libxl__egc *egc, uint32_t = domid, { STATE_AO_GC(aodev->ao); libxl_ctx *ctx =3D libxl__gc_owner(gc); - libxl_device_pci *assigned; - int num_assigned, rc; + int rc; int stubdomid =3D 0; pci_add_state *pas; =20 @@ -1575,19 +1574,6 @@ void libxl__device_pci_add(libxl__egc *egc, uint32_t= domid, goto out; } =20 - rc =3D get_all_assigned_devices(gc, &assigned, &num_assigned); - if ( rc ) { - LOGD(ERROR, domid, - "cannot determine if device is assigned, refusing to continue= "); - goto out; - } - if ( is_pci_in_array(assigned, num_assigned, pci->domain, - pci->bus, pci->dev, pci->func) ) { - LOGD(ERROR, domid, "PCI device already attached to a domain"); - rc =3D ERROR_FAIL; - goto out; - } - libxl__device_pci_reset(gc, pci->domain, pci->bus, pci->dev, pci->func= ); =20 stubdomid =3D libxl_get_stubdom_id(ctx, domid); --=20 2.11.0 From nobody Sun May 5 11:10:29 2024 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=1603470421; cv=none; d=zohomail.com; s=zohoarc; b=WzG4AOOhg1n56lEsmF04ChmNGSyFdSc5Z6Vy8+gK9WjB79gmwwqYi7SJR0eoTPvln86Yr7rsw/fx/dRWJCemddX35cJWDyvJqH9nwUqvehVHhiZsHHHzFZ19bYEDYu5ZAi5RBS/6hszO6YEVKts/8vUe1gp3Km9s0qUo0yMJdkM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603470421; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=M7KyfdRowcfz1Dkb4pOwz/I/UqTxNMMmQHabJ9z5yGE=; b=lj4zSRnT4pz+KOWKcwpXedijnCZD3shQYur2aYJkdxEg9e19N80nHxjTqglRFnmgOsHb1CwSokn16oHrJ6DNausoVVckqZPYE6pDmEDdZVcq+NCKnuOuGE7gGkQ6cdJkBD6XMB/iKEAU0uRx1gcdphYjzREW3tCdkP3M19ilWCE= 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 160347042162285.88726180268577; Fri, 23 Oct 2020 09:27:01 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.11207.29788 (Exim 4.92) (envelope-from ) id 1kVzts-0001RZ-GY; Fri, 23 Oct 2020 16:26:44 +0000 Received: by outflank-mailman (output) from mailman id 11207.29788; Fri, 23 Oct 2020 16:26:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzts-0001RQ-Cg; Fri, 23 Oct 2020 16:26:44 +0000 Received: by outflank-mailman (input) for mailman id 11207; Fri, 23 Oct 2020 16:26:42 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztq-0000v2-Ga for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:26:42 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id cc70f8b5-957c-4ba3-b316-955b4dff14c3; Fri, 23 Oct 2020 16:26:21 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztU-0008Ne-SQ; Fri, 23 Oct 2020 16:26:20 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqi-000376-6X; Fri, 23 Oct 2020 16:23:28 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztq-0000v2-Ga for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:26:42 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id cc70f8b5-957c-4ba3-b316-955b4dff14c3; Fri, 23 Oct 2020 16:26:21 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztU-0008Ne-SQ; Fri, 23 Oct 2020 16:26:20 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqi-000376-6X; Fri, 23 Oct 2020 16:23:28 +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" X-Inumbo-ID: cc70f8b5-957c-4ba3-b316-955b4dff14c3 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=M7KyfdRowcfz1Dkb4pOwz/I/UqTxNMMmQHabJ9z5yGE=; b=xJIIzblZXaqib5gGfqsFtCb8j 7ciGpN8ViuR2DuGP1RRs8bEgfobxQ/q9m908lKlHUEYZY3DzbVEz4nhvqgVElLENk5fm7A9/+TLTB 4Q+/whXZtSVhTIe+4/Pe3V+opXc6pdyN1DJ7YAmZW0C03NW00gSTseKrB3MiLNnSiBamU=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson , Wei Liu Subject: [PATCH 10/25] libxl: remove get_all_assigned_devices() from libxl_pci.c Date: Fri, 23 Oct 2020 16:22:59 +0000 Message-Id: <20201023162314.2235-11-paul@xen.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20201023162314.2235-1-paul@xen.org> References: <20201023162314.2235-1-paul@xen.org> X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paul Durrant Use of this function is a very inefficient way to check whether a device has already been assigned. This patch adds code that saves the domain id in xenstore at the point of assignment, and removes it again when the device id de-assigned (or the domain is destroyed). It is then straightforward to check whether a device has been assigned by checking whether a device has a saved domain id. NOTE: To facilitate the xenstore check it is necessary to move the pci_info_xs_read() earlier in libxl_pci.c. To keep related functions together, the rest of the pci_info_xs_XXX() functions are moved too. Signed-off-by: Paul Durrant Acked-by: Christian Lindig --- Cc: Ian Jackson Cc: Wei Liu --- tools/libs/light/libxl_pci.c | 149 ++++++++++++++++-----------------------= ---- 1 file changed, 55 insertions(+), 94 deletions(-) diff --git a/tools/libs/light/libxl_pci.c b/tools/libs/light/libxl_pci.c index 0be1b21185..879b1b24a0 100644 --- a/tools/libs/light/libxl_pci.c +++ b/tools/libs/light/libxl_pci.c @@ -317,50 +317,6 @@ retry_transaction2: return 0; } =20 -static int get_all_assigned_devices(libxl__gc *gc, libxl_device_pci **list= , int *num) -{ - char **domlist; - unsigned int nd =3D 0, i; - - *list =3D NULL; - *num =3D 0; - - domlist =3D libxl__xs_directory(gc, XBT_NULL, "/local/domain", &nd); - for(i =3D 0; i < nd; i++) { - char *path, *num_devs; - - path =3D GCSPRINTF("/local/domain/0/backend/%s/%s/0/num_devs", - libxl__device_kind_to_string(LIBXL__DEVICE_KIND_P= CI), - domlist[i]); - num_devs =3D libxl__xs_read(gc, XBT_NULL, path); - if ( num_devs ) { - int ndev =3D atoi(num_devs), j; - char *devpath, *bdf; - - for(j =3D 0; j < ndev; j++) { - devpath =3D GCSPRINTF("/local/domain/0/backend/%s/%s/0/dev= -%u", - libxl__device_kind_to_string(LIBXL__DE= VICE_KIND_PCI), - domlist[i], j); - bdf =3D libxl__xs_read(gc, XBT_NULL, devpath); - if ( bdf ) { - unsigned dom, bus, dev, func; - if ( sscanf(bdf, PCI_BDF, &dom, &bus, &dev, &func) != =3D 4 ) - continue; - - *list =3D realloc(*list, sizeof(libxl_device_pci) * ((= *num) + 1)); - if (*list =3D=3D NULL) - return ERROR_NOMEM; - pci_struct_fill(*list + *num, dom, bus, dev, func, 0); - (*num)++; - } - } - } - } - libxl__ptr_add(gc, *list); - - return 0; -} - static int is_pci_in_array(libxl_device_pci *assigned, int num_assigned, int dom, int bus, int dev, int func) { @@ -408,19 +364,58 @@ static int sysfs_write_bdf(libxl__gc *gc, const char = * sysfs_path, return 0; } =20 +#define PCI_INFO_PATH "/libxl/pci" + +static char *pci_info_xs_path(libxl__gc *gc, libxl_device_pci *pci, + const char *node) +{ + return node ? + GCSPRINTF(PCI_INFO_PATH"/"PCI_BDF_XSPATH"/%s", + pci->domain, pci->bus, pci->dev, pci->func, + node) : + GCSPRINTF(PCI_INFO_PATH"/"PCI_BDF_XSPATH, + pci->domain, pci->bus, pci->dev, pci->func); +} + + +static int pci_info_xs_write(libxl__gc *gc, libxl_device_pci *pci, + const char *node, const char *val) +{ + char *path =3D pci_info_xs_path(gc, pci, node); + int rc =3D libxl__xs_printf(gc, XBT_NULL, path, "%s", val); + + if (rc) LOGE(WARN, "Write of %s to node %s failed.", val, path); + + return rc; +} + +static char *pci_info_xs_read(libxl__gc *gc, libxl_device_pci *pci, + const char *node) +{ + char *path =3D pci_info_xs_path(gc, pci, node); + + return libxl__xs_read(gc, XBT_NULL, path); +} + +static void pci_info_xs_remove(libxl__gc *gc, libxl_device_pci *pci, + const char *node) +{ + char *path =3D pci_info_xs_path(gc, pci, node); + libxl_ctx *ctx =3D libxl__gc_owner(gc); + + /* Remove the xenstore entry */ + xs_rm(ctx->xsh, XBT_NULL, path); +} + libxl_device_pci *libxl_device_pci_assignable_list(libxl_ctx *ctx, int *nu= m) { GC_INIT(ctx); - libxl_device_pci *pcis =3D NULL, *new, *assigned; + libxl_device_pci *pcis =3D NULL, *new; struct dirent *de; DIR *dir; - int r, num_assigned; =20 *num =3D 0; =20 - r =3D get_all_assigned_devices(gc, &assigned, &num_assigned); - if (r) goto out; - dir =3D opendir(SYSFS_PCIBACK_DRIVER); if (NULL =3D=3D dir) { if (errno =3D=3D ENOENT) { @@ -436,9 +431,6 @@ libxl_device_pci *libxl_device_pci_assignable_list(libx= l_ctx *ctx, int *num) if (sscanf(de->d_name, PCI_BDF, &dom, &bus, &dev, &func) !=3D 4) continue; =20 - if (is_pci_in_array(assigned, num_assigned, dom, bus, dev, func)) - continue; - new =3D realloc(pcis, ((*num) + 1) * sizeof(*new)); if (NULL =3D=3D new) continue; @@ -448,6 +440,10 @@ libxl_device_pci *libxl_device_pci_assignable_list(lib= xl_ctx *ctx, int *num) =20 memset(new, 0, sizeof(*new)); pci_struct_fill(new, dom, bus, dev, func, 0); + + if (pci_info_xs_read(gc, new, "domid")) /* already assigned */ + continue; + (*num)++; } =20 @@ -718,48 +714,6 @@ static int pciback_dev_unassign(libxl__gc *gc, libxl_d= evice_pci *pci) return 0; } =20 -#define PCI_INFO_PATH "/libxl/pci" - -static char *pci_info_xs_path(libxl__gc *gc, libxl_device_pci *pci, - const char *node) -{ - return node ? - GCSPRINTF(PCI_INFO_PATH"/"PCI_BDF_XSPATH"/%s", - pci->domain, pci->bus, pci->dev, pci->func, - node) : - GCSPRINTF(PCI_INFO_PATH"/"PCI_BDF_XSPATH, - pci->domain, pci->bus, pci->dev, pci->func); -} - - -static void pci_info_xs_write(libxl__gc *gc, libxl_device_pci *pci, - const char *node, const char *val) -{ - char *path =3D pci_info_xs_path(gc, pci, node); - - if ( libxl__xs_printf(gc, XBT_NULL, path, "%s", val) < 0 ) { - LOGE(WARN, "Write of %s to node %s failed.", val, path); - } -} - -static char *pci_info_xs_read(libxl__gc *gc, libxl_device_pci *pci, - const char *node) -{ - char *path =3D pci_info_xs_path(gc, pci, node); - - return libxl__xs_read(gc, XBT_NULL, path); -} - -static void pci_info_xs_remove(libxl__gc *gc, libxl_device_pci *pci, - const char *node) -{ - char *path =3D pci_info_xs_path(gc, pci, node); - libxl_ctx *ctx =3D libxl__gc_owner(gc); - - /* Remove the xenstore entry */ - xs_rm(ctx->xsh, XBT_NULL, path); -} - static int libxl__device_pci_assignable_add(libxl__gc *gc, libxl_device_pci *pci, int rebind) @@ -1574,6 +1528,9 @@ void libxl__device_pci_add(libxl__egc *egc, uint32_t = domid, goto out; } =20 + rc =3D pci_info_xs_write(gc, pci, "domid", GCSPRINTF("%u", domid)); + if (rc) goto out; + libxl__device_pci_reset(gc, pci->domain, pci->bus, pci->dev, pci->func= ); =20 stubdomid =3D libxl_get_stubdom_id(ctx, domid); @@ -1701,6 +1658,7 @@ static void device_pci_add_done(libxl__egc *egc, "PCI device %x:%x:%x.%x (rc %d)", pci->domain, pci->bus, pci->dev, pci->func, rc); + pci_info_xs_remove(gc, pci, "domid"); } aodev->rc =3D rc; aodev->callback(egc, aodev); @@ -2276,6 +2234,9 @@ out: libxl__xswait_stop(gc, &prs->xswait); libxl__ev_time_deregister(gc, &prs->timeout); libxl__ev_time_deregister(gc, &prs->retry_timer); + + if (!rc) pci_info_xs_remove(gc, pci, "domid"); + aodev->rc =3D rc; aodev->callback(egc, aodev); } --=20 2.11.0 From nobody Sun May 5 11:10:29 2024 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=1603470428; cv=none; d=zohomail.com; s=zohoarc; b=iaYYxYmvC84jS5zBIw7r5sBicykXxcHgg5iFS9nynZKJnJYjHx9m+N6KjtC7SjsxfeE/20YzHfzRLngSO4CsVa51I29q2JN/to8pFOjtm3d+7gTSqGgg2DkRcprpgsEF7HkHY2LAE16LLITkigWsKu8Sg33YbQA09fmex/ScnXk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603470428; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=GUr1/jWBqMoyqKCH+//ockHXZ9S72D3qfXA2SoYLOJs=; b=g7SILu1EZYoepPONssGD9wbmQNSHGBKUa3keQUS7HYlD8D7sXC55a+a7yZiOiSeNwlfvnG3FaIWx3dYHSy06Ktsa3BisJc6JC+8iAyUb0drowUFzZbzurI9wRFJFNSWojqSS35VwmEcF7nRRjEe0fxmBQZSb/jIxkzVoeX/PiCg= 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 1603470428333950.244875033771; Fri, 23 Oct 2020 09:27:08 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.11209.29813 (Exim 4.92) (envelope-from ) id 1kVztx-0001d1-G3; Fri, 23 Oct 2020 16:26:49 +0000 Received: by outflank-mailman (output) from mailman id 11209.29813; Fri, 23 Oct 2020 16:26:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztx-0001cp-9a; Fri, 23 Oct 2020 16:26:49 +0000 Received: by outflank-mailman (input) for mailman id 11209; Fri, 23 Oct 2020 16:26:47 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztv-0000v2-Gn for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:26:47 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 15e9921f-64bf-430c-8b85-f3d2e864f4a5; Fri, 23 Oct 2020 16:26:21 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztU-0008NW-O7; Fri, 23 Oct 2020 16:26:20 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqj-000376-3f; Fri, 23 Oct 2020 16:23:29 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztv-0000v2-Gn for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:26:47 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 15e9921f-64bf-430c-8b85-f3d2e864f4a5; Fri, 23 Oct 2020 16:26:21 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztU-0008NW-O7; Fri, 23 Oct 2020 16:26:20 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqj-000376-3f; Fri, 23 Oct 2020 16:23:29 +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" X-Inumbo-ID: 15e9921f-64bf-430c-8b85-f3d2e864f4a5 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=GUr1/jWBqMoyqKCH+//ockHXZ9S72D3qfXA2SoYLOJs=; b=fltJbSQ7mhgz40Z9DOfjMZ85W RQsoLGbyaE54ZzwCBoeIfnI26GSASuInU+DU1+RIw8Fq86Zk0/st1PW6IutuwNYPhoE0Qyna653lt 9BnFkpvVp81qDYSrtGwOPnYRuSIAhkE6fKLA5zDg4j7Aba4ljUmoBBPTvr/BoftPHlZgE=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH 11/25] libxl: make sure callers of libxl_device_pci_list() free the list after use Date: Fri, 23 Oct 2020 16:23:00 +0000 Message-Id: <20201023162314.2235-12-paul@xen.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20201023162314.2235-1-paul@xen.org> References: <20201023162314.2235-1-paul@xen.org> X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paul Durrant A previous patch introduced libxl_device_pci_list_free() which should be us= ed by callers of libxl_device_pci_list() to properly dispose of the exported 'libxl_device_pci' types and the free the memory holding them. Whilst all current callers do ensure the memory is freed, only the code in xl's pcilist() function actually calls libxl_device_pci_dispose(). As it stands this laxity does not lead to any memory leaks, but the simple addition of .e.g. a 'string' into the idl definition of 'libxl_device_pci' would lead to leaks. This patch makes sure all callers of libxl_device_pci_list() can call libxl_device_pci_list_free() by keeping copies of 'libxl_device_pci' structures inline in 'pci_add_state' and 'pci_remove_state' (and also making sure these are properly disposed at the end of the operations) rather than keeping pointers to the structures returned by libxl_device_pci_list(). Signed-off-by: Paul Durrant Acked-by: Christian Lindig --- Cc: Ian Jackson Cc: Wei Liu Cc: Anthony PERARD --- tools/libs/light/libxl_pci.c | 68 ++++++++++++++++++++++++----------------= ---- tools/xl/xl_pci.c | 3 +- 2 files changed, 38 insertions(+), 33 deletions(-) diff --git a/tools/libs/light/libxl_pci.c b/tools/libs/light/libxl_pci.c index 879b1b24a0..3162facb37 100644 --- a/tools/libs/light/libxl_pci.c +++ b/tools/libs/light/libxl_pci.c @@ -1006,7 +1006,7 @@ typedef struct pci_add_state { libxl__xswait_state xswait; libxl__ev_qmp qmp; libxl__ev_time timeout; - libxl_device_pci *pci; + libxl_device_pci pci; libxl_domid pci_domid; } pci_add_state; =20 @@ -1078,7 +1078,7 @@ static void pci_add_qemu_trad_watch_state_cb(libxl__e= gc *egc, =20 /* Convenience aliases */ libxl_domid domid =3D pas->domid; - libxl_device_pci *pci =3D pas->pci; + libxl_device_pci *pci =3D &pas->pci; =20 rc =3D check_qemu_running(gc, domid, xswa, rc, state); if (rc =3D=3D ERROR_NOT_READY) @@ -1099,7 +1099,7 @@ static void pci_add_qmp_device_add(libxl__egc *egc, p= ci_add_state *pas) =20 /* Convenience aliases */ libxl_domid domid =3D pas->domid; - libxl_device_pci *pci =3D pas->pci; + libxl_device_pci *pci =3D &pas->pci; libxl__ev_qmp *const qmp =3D &pas->qmp; =20 rc =3D libxl__ev_time_register_rel(ao, &pas->timeout, @@ -1180,7 +1180,7 @@ static void pci_add_qmp_query_pci_cb(libxl__egc *egc, int dev_slot, dev_func; =20 /* Convenience aliases */ - libxl_device_pci *pci =3D pas->pci; + libxl_device_pci *pci =3D &pas->pci; =20 if (rc) goto out; =20 @@ -1280,7 +1280,7 @@ static void pci_add_dm_done(libxl__egc *egc, =20 /* Convenience aliases */ bool starting =3D pas->starting; - libxl_device_pci *pci =3D pas->pci; + libxl_device_pci *pci =3D &pas->pci; bool hvm =3D libxl__domain_type(gc, domid) =3D=3D LIBXL_DOMAIN_TYPE_HV= M; =20 libxl__ev_qmp_dispose(gc, &pas->qmp); @@ -1496,7 +1496,10 @@ void libxl__device_pci_add(libxl__egc *egc, uint32_t= domid, GCNEW(pas); pas->aodev =3D aodev; pas->domid =3D domid; - pas->pci =3D pci; + + libxl_device_pci_copy(CTX, &pas->pci, pci); + pci =3D &pas->pci; + pas->starting =3D starting; pas->callback =3D device_pci_add_stubdom_done; =20 @@ -1535,12 +1538,6 @@ void libxl__device_pci_add(libxl__egc *egc, uint32_t= domid, =20 stubdomid =3D libxl_get_stubdom_id(ctx, domid); if (stubdomid !=3D 0) { - libxl_device_pci *pci_s; - - GCNEW(pci_s); - libxl_device_pci_init(pci_s); - libxl_device_pci_copy(CTX, pci_s, pci); - pas->pci =3D pci_s; pas->callback =3D device_pci_add_stubdom_wait; =20 do_pci_add(egc, stubdomid, pas); /* must be last */ @@ -1599,7 +1596,7 @@ static void device_pci_add_stubdom_done(libxl__egc *e= gc, =20 /* Convenience aliases */ libxl_domid domid =3D pas->domid; - libxl_device_pci *pci =3D pas->pci; + libxl_device_pci *pci =3D &pas->pci; =20 if (rc) goto out; =20 @@ -1650,7 +1647,7 @@ static void device_pci_add_done(libxl__egc *egc, EGC_GC; libxl__ao_device *aodev =3D pas->aodev; libxl_domid domid =3D pas->domid; - libxl_device_pci *pci =3D pas->pci; + libxl_device_pci *pci =3D &pas->pci; =20 if (rc) { LOGD(ERROR, domid, @@ -1660,6 +1657,7 @@ static void device_pci_add_done(libxl__egc *egc, rc); pci_info_xs_remove(gc, pci, "domid"); } + libxl_device_pci_dispose(pci); aodev->rc =3D rc; aodev->callback(egc, aodev); } @@ -1766,7 +1764,7 @@ static int qemu_pci_remove_xenstore(libxl__gc *gc, ui= nt32_t domid, typedef struct pci_remove_state { libxl__ao_device *aodev; libxl_domid domid; - libxl_device_pci *pci; + libxl_device_pci pci; bool force; bool hvm; unsigned int orig_vdev; @@ -1808,22 +1806,25 @@ static void do_pci_remove(libxl__egc *egc, pci_remo= ve_state *prs) { STATE_AO_GC(prs->aodev->ao); libxl_ctx *ctx =3D libxl__gc_owner(gc); - libxl_device_pci *assigned; + libxl_device_pci *pcis; + bool attached; uint32_t domid =3D prs->domid; libxl_domain_type type =3D libxl__domain_type(gc, domid); - libxl_device_pci *pci =3D prs->pci; + libxl_device_pci *pci =3D &prs->pci; int rc, num; =20 - assigned =3D libxl_device_pci_list(ctx, domid, &num); - if (assigned =3D=3D NULL) { + pcis =3D libxl_device_pci_list(ctx, domid, &num); + if (!pcis) { rc =3D ERROR_FAIL; goto out_fail; } - libxl__ptr_add(gc, assigned); + + attached =3D is_pci_in_array(pcis, num, pci->domain, + pci->bus, pci->dev, pci->func); + libxl_device_pci_list_free(pcis, num); =20 rc =3D ERROR_INVAL; - if ( !is_pci_in_array(assigned, num, pci->domain, - pci->bus, pci->dev, pci->func) ) { + if (!attached) { LOGD(ERROR, domid, "PCI device not attached to this domain"); goto out_fail; } @@ -1923,7 +1924,7 @@ static void pci_remove_qemu_trad_watch_state_cb(libxl= __egc *egc, =20 /* Convenience aliases */ libxl_domid domid =3D prs->domid; - libxl_device_pci *const pci =3D prs->pci; + libxl_device_pci *const pci =3D &prs->pci; =20 rc =3D check_qemu_running(gc, domid, xswa, rc, state); if (rc =3D=3D ERROR_NOT_READY) @@ -1945,7 +1946,7 @@ static void pci_remove_qmp_device_del(libxl__egc *egc, int rc; =20 /* Convenience aliases */ - libxl_device_pci *const pci =3D prs->pci; + libxl_device_pci *const pci =3D &prs->pci; =20 rc =3D libxl__ev_time_register_rel(ao, &prs->timeout, pci_remove_timeout, @@ -2015,7 +2016,7 @@ static void pci_remove_qmp_query_cb(libxl__egc *egc, =20 /* Convenience aliases */ libxl__ao *const ao =3D prs->aodev->ao; - libxl_device_pci *const pci =3D prs->pci; + libxl_device_pci *const pci =3D &prs->pci; =20 if (rc) goto out; =20 @@ -2070,7 +2071,7 @@ static void pci_remove_timeout(libxl__egc *egc, libxl= __ev_time *ev, pci_remove_state *prs =3D CONTAINER_OF(ev, *prs, timeout); =20 /* Convenience aliases */ - libxl_device_pci *const pci =3D prs->pci; + libxl_device_pci *const pci =3D &prs->pci; =20 LOGD(WARN, prs->domid, "timed out waiting for DM to remove " PCI_PT_QDEV_ID, pci->bus, pci->dev, pci->func); @@ -2091,7 +2092,7 @@ static void pci_remove_detached(libxl__egc *egc, bool isstubdom; =20 /* Convenience aliases */ - libxl_device_pci *const pci =3D prs->pci; + libxl_device_pci *const pci =3D &prs->pci; =20 /* Cleaning QMP states ASAP */ libxl__ev_qmp_dispose(gc, &prs->qmp); @@ -2153,7 +2154,7 @@ static void pci_remove_done(libxl__egc *egc, =20 if (rc) goto out; =20 - libxl__device_pci_remove_xenstore(gc, prs->domid, prs->pci); + libxl__device_pci_remove_xenstore(gc, prs->domid, &prs->pci); out: device_pci_remove_common_next(egc, prs, rc); } @@ -2171,7 +2172,10 @@ static void libxl__device_pci_remove_common(libxl__e= gc *egc, GCNEW(prs); prs->aodev =3D aodev; prs->domid =3D domid; - prs->pci =3D pci; + + libxl_device_pci_copy(CTX, &prs->pci, pci); + pci =3D &prs->pci; + prs->force =3D force; libxl__xswait_init(&prs->xswait); libxl__ev_qmp_init(&prs->qmp); @@ -2206,7 +2210,7 @@ static void device_pci_remove_common_next(libxl__egc = *egc, EGC_GC; =20 /* Convenience aliases */ - libxl_device_pci *const pci =3D prs->pci; + libxl_device_pci *const pci =3D &prs->pci; libxl__ao_device *const aodev =3D prs->aodev; const unsigned int pfunc_mask =3D prs->pfunc_mask; const unsigned int orig_vdev =3D prs->orig_vdev; @@ -2237,6 +2241,7 @@ out: =20 if (!rc) pci_info_xs_remove(gc, pci, "domid"); =20 + libxl_device_pci_dispose(pci); aodev->rc =3D rc; aodev->callback(egc, aodev); } @@ -2339,7 +2344,6 @@ void libxl__device_pci_destroy_all(libxl__egc *egc, u= int32_t domid, pcis =3D libxl_device_pci_list(CTX, domid, &num); if ( pcis =3D=3D NULL ) return; - libxl__ptr_add(gc, pcis); =20 for (i =3D 0; i < num; i++) { /* Force remove on shutdown since, on HVM, qemu will not always @@ -2350,6 +2354,8 @@ void libxl__device_pci_destroy_all(libxl__egc *egc, u= int32_t domid, libxl__device_pci_remove_common(egc, domid, pcis + i, true, aodev); } + + libxl_device_pci_list_free(pcis, num); } =20 int libxl__grant_vga_iomem_permission(libxl__gc *gc, const uint32_t domid, diff --git a/tools/xl/xl_pci.c b/tools/xl/xl_pci.c index 34fcf5a4fa..7c0f102ac7 100644 --- a/tools/xl/xl_pci.c +++ b/tools/xl/xl_pci.c @@ -35,9 +35,8 @@ static void pcilist(uint32_t domid) printf("%02x.%01x %04x:%02x:%02x.%01x\n", (pcis[i].vdevfn >> 3) & 0x1f, pcis[i].vdevfn & 0x7, pcis[i].domain, pcis[i].bus, pcis[i].dev, pcis[i].func); - libxl_device_pci_dispose(&pcis[i]); } - free(pcis); + libxl_device_pci_list_free(pcis, num); } =20 int main_pcilist(int argc, char **argv) --=20 2.11.0 From nobody Sun May 5 11:10:29 2024 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=1603470434; cv=none; d=zohomail.com; s=zohoarc; b=eQd5gwP26SS0cc/+jW0cMaT7tcGDcptQ8E1oNme/00vuTSPHQDq2IUUq0PNqKPxtqFekJNcBTca90gkDio74AqqELM9/uADf03phzxVfkins/c5mu/tzywM5lw0knBEI9F6af3h6kPVjasAGfK7buaEoHrfacv5T7gsbeVqu7i8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603470434; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=TwtfBZ1TBMcZx0WwXud6JOyhwZrUvxUUMk2BtEGrrXI=; b=kAdr9Ns9GoDN/4kUzvig8xwZnm4lFtwMK5t0f4+/BcpYoxaGAUq+HivzE0iAam5wPG9HGa4w0ydkcTcvLcs7qd3DFejBAPnLO4bT0AKgyjoVjQ5QbWA/uE2JqoUhTO5hwxhfAKcbqKFp6EPu5+8t8e/ysI/qQ99JxcZ+8Q2/1q4= 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 1603470434429750.0184365083294; Fri, 23 Oct 2020 09:27:14 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.11219.29862 (Exim 4.92) (envelope-from ) id 1kVzu7-0001zr-1n; Fri, 23 Oct 2020 16:26:59 +0000 Received: by outflank-mailman (output) from mailman id 11219.29862; Fri, 23 Oct 2020 16:26:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzu6-0001zO-Mc; Fri, 23 Oct 2020 16:26:58 +0000 Received: by outflank-mailman (input) for mailman id 11219; Fri, 23 Oct 2020 16:26:57 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzu5-0000v2-HE for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:26:57 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id bf6a7257-063a-40c2-9d1c-081ae0f7b8be; Fri, 23 Oct 2020 16:26:22 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztV-0008O2-6X; Fri, 23 Oct 2020 16:26:21 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqk-000376-7K; Fri, 23 Oct 2020 16:23:30 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzu5-0000v2-HE for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:26:57 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id bf6a7257-063a-40c2-9d1c-081ae0f7b8be; Fri, 23 Oct 2020 16:26:22 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztV-0008O2-6X; Fri, 23 Oct 2020 16:26:21 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqk-000376-7K; Fri, 23 Oct 2020 16:23:30 +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" X-Inumbo-ID: bf6a7257-063a-40c2-9d1c-081ae0f7b8be DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=TwtfBZ1TBMcZx0WwXud6JOyhwZrUvxUUMk2BtEGrrXI=; b=PHGk+IBka0LiWVfU4vT9v9Myv iiBrJ0Dt5HDFp9njxUh4fYZt+K+LX+9nJslKhWFaBCjuQWNAx3P5kuxj7ghRjuYGF3/QRxfykH5z6 0YFMvzcH/zj8+AdJBYuAh1XdGGR+U0MLRrew4cPVX56ejNbYmX6a7LEeaatWmU9iNPebU=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson , Wei Liu , Christian Lindig , David Scott , Anthony PERARD Subject: [PATCH 12/25] libxl: add libxl_device_pci_assignable_list_free()... Date: Fri, 23 Oct 2020 16:23:01 +0000 Message-Id: <20201023162314.2235-13-paul@xen.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20201023162314.2235-1-paul@xen.org> References: <20201023162314.2235-1-paul@xen.org> X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paul Durrant ... to be used by callers of libxl_device_pci_assignable_list(). Currently there is no API for callers of libxl_device_pci_assignable_list() to free the list. The xl function pciassignable_list() calls libxl_device_pci_dispose() on each element of the returned list, but libxl_pci_assignable() in libxl_pci.c does not. Neither does the implementa= tion of libxl_device_pci_assignable_list() call libxl_device_pci_init(). This patch adds the new API function, makes sure it is used everywhere and also modifies libxl_device_pci_assignable_list() to initialize list entries rather than just zeroing them. Signed-off-by: Paul Durrant Acked-by: Christian Lindig --- Cc: Ian Jackson Cc: Wei Liu Cc: Christian Lindig Cc: David Scott Cc: Anthony PERARD --- tools/include/libxl.h | 7 +++++++ tools/libs/light/libxl_pci.c | 14 ++++++++++++-- tools/ocaml/libs/xl/xenlight_stubs.c | 3 +-- tools/xl/xl_pci.c | 3 +-- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/tools/include/libxl.h b/tools/include/libxl.h index ee52d3cf7e..8225809d94 100644 --- a/tools/include/libxl.h +++ b/tools/include/libxl.h @@ -458,6 +458,12 @@ #define LIBXL_HAVE_DEVICE_PCI_LIST_FREE 1 =20 /* + * LIBXL_HAVE_DEVICE_PCI_ASSIGNABLE_LIST_FREE indicates that the + * libxl_device_pci_assignable_list_free() function is defined. + */ +#define LIBXL_HAVE_DEVICE_PCI_ASSIGNABLE_LIST_FREE 1 + +/* * libxl ABI compatibility * * The only guarantee which libxl makes regarding ABI compatibility @@ -2369,6 +2375,7 @@ int libxl_device_events_handler(libxl_ctx *ctx, int libxl_device_pci_assignable_add(libxl_ctx *ctx, libxl_device_pci *pci,= int rebind); int libxl_device_pci_assignable_remove(libxl_ctx *ctx, libxl_device_pci *p= ci, int rebind); libxl_device_pci *libxl_device_pci_assignable_list(libxl_ctx *ctx, int *nu= m); +void libxl_device_pci_assignable_list_free(libxl_device_pci *list, int num= ); =20 /* CPUID handling */ int libxl_cpuid_parse_config(libxl_cpuid_policy_list *cpuid, const char* s= tr); diff --git a/tools/libs/light/libxl_pci.c b/tools/libs/light/libxl_pci.c index 3162facb37..e858509609 100644 --- a/tools/libs/light/libxl_pci.c +++ b/tools/libs/light/libxl_pci.c @@ -438,7 +438,7 @@ libxl_device_pci *libxl_device_pci_assignable_list(libx= l_ctx *ctx, int *num) pcis =3D new; new =3D pcis + *num; =20 - memset(new, 0, sizeof(*new)); + libxl_device_pci_init(new); pci_struct_fill(new, dom, bus, dev, func, 0); =20 if (pci_info_xs_read(gc, new, "domid")) /* already assigned */ @@ -453,6 +453,16 @@ out: return pcis; } =20 +void libxl_device_pci_assignable_list_free(libxl_device_pci *list, int num) +{ + int i; + + for (i =3D 0; i < num; i++) + libxl_device_pci_dispose(&list[i]); + + free(list); +} + /* Unbind device from its current driver, if any. If driver_path is non-N= ULL, * store the path to the original driver in it. */ static int sysfs_dev_unbind(libxl__gc *gc, libxl_device_pci *pci, @@ -1470,7 +1480,7 @@ static int libxl_pci_assignable(libxl_ctx *ctx, libxl= _device_pci *pci) pcis[i].func =3D=3D pci->func) break; } - free(pcis); + libxl_device_pci_assignable_list_free(pcis, num); return i !=3D num; } =20 diff --git a/tools/ocaml/libs/xl/xenlight_stubs.c b/tools/ocaml/libs/xl/xen= light_stubs.c index 1181971da4..352a00134d 100644 --- a/tools/ocaml/libs/xl/xenlight_stubs.c +++ b/tools/ocaml/libs/xl/xenlight_stubs.c @@ -894,9 +894,8 @@ value stub_xl_device_pci_assignable_list(value ctx) Field(list, 1) =3D temp; temp =3D list; Store_field(list, 0, Val_device_pci(&c_list[i])); - libxl_device_pci_dispose(&c_list[i]); } - free(c_list); + libxl_device_pci_assignable_list_free(c_list, nb); =20 CAMLreturn(list); } diff --git a/tools/xl/xl_pci.c b/tools/xl/xl_pci.c index 7c0f102ac7..f71498cbb5 100644 --- a/tools/xl/xl_pci.c +++ b/tools/xl/xl_pci.c @@ -164,9 +164,8 @@ static void pciassignable_list(void) for (i =3D 0; i < num; i++) { printf("%04x:%02x:%02x.%01x\n", pcis[i].domain, pcis[i].bus, pcis[i].dev, pcis[i].func); - libxl_device_pci_dispose(&pcis[i]); } - free(pcis); + libxl_device_pci_assignable_list_free(pcis, num); } =20 int main_pciassignable_list(int argc, char **argv) --=20 2.11.0 From nobody Sun May 5 11:10:29 2024 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=1603470416; cv=none; d=zohomail.com; s=zohoarc; b=hOFexeylB/LAkwlEJgt7f0Ge7NSDNYhLLKXTfj9lLd2wN3w4mm+V9jrX2ul3vdWiR1wMPLQhP+BKZ1vlHhMtnELZNScp97OimHleRdaFI+OFkf/nl2g27OPm7lKOXMvDXCfmLkEI/rM8QmJ2NrrgUi1j6VIJj4Sfx6U/W2PnlQw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603470416; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=fKvidaGIqKTgBLgc0mSSzScxrN0OQ+wp9Q7aYF6wsy4=; b=eyTQiJd+kxIO+d6umJtZBaUgOQntufKFRI+VVCWvSSVenq6FfzzJq3g4X/gSf+xmQZ1VuzFj9w+ahnMN84ngBhLq5XdgpF/OSq6yNAnBY3cw1ulTGDnIGsQc7i9YpPUtlc/wb1bSTL/h6K08BqJsmYX/aNfoaHZ9eaMteLTAexw= 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 1603470416281130.53450240269012; Fri, 23 Oct 2020 09:26:56 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.11205.29765 (Exim 4.92) (envelope-from ) id 1kVztn-0001Hu-G9; Fri, 23 Oct 2020 16:26:39 +0000 Received: by outflank-mailman (output) from mailman id 11205.29765; Fri, 23 Oct 2020 16:26:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztn-0001Hj-Ci; Fri, 23 Oct 2020 16:26:39 +0000 Received: by outflank-mailman (input) for mailman id 11205; Fri, 23 Oct 2020 16:26:37 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztl-0000v2-GZ for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:26:37 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 4cf76f40-3f3d-4c0d-98b8-2222d69b0ccd; Fri, 23 Oct 2020 16:26:21 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztU-0008NY-Pa; Fri, 23 Oct 2020 16:26:20 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzql-000376-1D; Fri, 23 Oct 2020 16:23:31 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztl-0000v2-GZ for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:26:37 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 4cf76f40-3f3d-4c0d-98b8-2222d69b0ccd; Fri, 23 Oct 2020 16:26:21 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztU-0008NY-Pa; Fri, 23 Oct 2020 16:26:20 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzql-000376-1D; Fri, 23 Oct 2020 16:23:31 +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" X-Inumbo-ID: 4cf76f40-3f3d-4c0d-98b8-2222d69b0ccd DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=fKvidaGIqKTgBLgc0mSSzScxrN0OQ+wp9Q7aYF6wsy4=; b=dxCpiIUo7fG8UlymJDufun+bR i+OASKtJG3Ot94E9zEZz/u7qMWtKwxWMQ6e5rZ9QBj9uuT3yyyzIQjBfryn2CQVKbbV1YAzZSPuNs 90iWxHAWRMjJpsniUYRG6RvuV6Eb2ANGIbMjvNAP1Wnup2hq9BcLR0FWPZ3hDIhwhUXjo=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson , Wei Liu Subject: [PATCH 13/25] libxl: use COMPARE_PCI() macro is_pci_in_array()... Date: Fri, 23 Oct 2020 16:23:02 +0000 Message-Id: <20201023162314.2235-14-paul@xen.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20201023162314.2235-1-paul@xen.org> References: <20201023162314.2235-1-paul@xen.org> X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paul Durrant ... rather than an open-coded equivalent. This patch tidies up the is_pci_in_array() function, making it take a single 'libxl_device_pci' argument rather than separate domain, bus, device and function arguments. The already-available COMPARE_PCI() macro can then be used and it is also modified to return 'bool' rather than 'int'. The patch also modifies libxl_pci_assignable() to use is_pci_in_array() rat= her than a separate open-coded equivalent, and also modifies it to return a 'bool' rather than an 'int'. NOTE: The COMPARE_PCI() macro is also fixed to include the 'domain' in its comparison, which should always have been the case. Signed-off-by: Paul Durrant Acked-by: Christian Lindig --- Cc: Ian Jackson Cc: Wei Liu --- tools/libs/light/libxl_internal.h | 7 ++++--- tools/libs/light/libxl_pci.c | 38 +++++++++++++----------------------= --- 2 files changed, 17 insertions(+), 28 deletions(-) diff --git a/tools/libs/light/libxl_internal.h b/tools/libs/light/libxl_int= ernal.h index 3e70ff639b..80d7988622 100644 --- a/tools/libs/light/libxl_internal.h +++ b/tools/libs/light/libxl_internal.h @@ -4744,9 +4744,10 @@ void libxl__xcinfo2xlinfo(libxl_ctx *ctx, * devices have same identifier. */ #define COMPARE_DEVID(a, b) ((a)->devid =3D=3D (b)->devid) #define COMPARE_DISK(a, b) (!strcmp((a)->vdev, (b)->vdev)) -#define COMPARE_PCI(a, b) ((a)->func =3D=3D (b)->func && \ - (a)->bus =3D=3D (b)->bus && \ - (a)->dev =3D=3D (b)->dev) +#define COMPARE_PCI(a, b) ((a)->domain =3D=3D (b)->domain && \ + (a)->bus =3D=3D (b)->bus && \ + (a)->dev =3D=3D (b)->dev && \ + (a)->func =3D=3D (b)->func) #define COMPARE_USB(a, b) ((a)->ctrl =3D=3D (b)->ctrl && \ (a)->port =3D=3D (b)->port) #define COMPARE_USBCTRL(a, b) ((a)->devid =3D=3D (b)->devid) diff --git a/tools/libs/light/libxl_pci.c b/tools/libs/light/libxl_pci.c index e858509609..2e8e1c50f1 100644 --- a/tools/libs/light/libxl_pci.c +++ b/tools/libs/light/libxl_pci.c @@ -317,24 +317,17 @@ retry_transaction2: return 0; } =20 -static int is_pci_in_array(libxl_device_pci *assigned, int num_assigned, - int dom, int bus, int dev, int func) +static int is_pci_in_array(libxl_device_pci *pcis, int num, + libxl_device_pci *pci) { int i; =20 - for(i =3D 0; i < num_assigned; i++) { - if ( assigned[i].domain !=3D dom ) - continue; - if ( assigned[i].bus !=3D bus ) - continue; - if ( assigned[i].dev !=3D dev ) - continue; - if ( assigned[i].func !=3D func ) - continue; - return 1; + for(i =3D 0; i < num; i++) { + if (COMPARE_PCI(pci, &pcis[i])) + break; } =20 - return 0; + return i < num; } =20 /* Write the standard BDF into the sysfs path given by sysfs_path. */ @@ -1467,21 +1460,17 @@ int libxl_device_pci_add(libxl_ctx *ctx, uint32_t d= omid, return AO_INPROGRESS; } =20 -static int libxl_pci_assignable(libxl_ctx *ctx, libxl_device_pci *pci) +static bool libxl_pci_assignable(libxl_ctx *ctx, libxl_device_pci *pci) { libxl_device_pci *pcis; - int num, i; + int num; + bool assignable; =20 pcis =3D libxl_device_pci_assignable_list(ctx, &num); - for (i =3D 0; i < num; i++) { - if (pcis[i].domain =3D=3D pci->domain && - pcis[i].bus =3D=3D pci->bus && - pcis[i].dev =3D=3D pci->dev && - pcis[i].func =3D=3D pci->func) - break; - } + assignable =3D is_pci_in_array(pcis, num, pci); libxl_device_pci_assignable_list_free(pcis, num); - return i !=3D num; + + return assignable; } =20 static void device_pci_add_stubdom_wait(libxl__egc *egc, @@ -1829,8 +1818,7 @@ static void do_pci_remove(libxl__egc *egc, pci_remove= _state *prs) goto out_fail; } =20 - attached =3D is_pci_in_array(pcis, num, pci->domain, - pci->bus, pci->dev, pci->func); + attached =3D is_pci_in_array(pcis, num, pci); libxl_device_pci_list_free(pcis, num); =20 rc =3D ERROR_INVAL; --=20 2.11.0 From nobody Sun May 5 11:10:29 2024 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=1603470425; cv=none; d=zohomail.com; s=zohoarc; b=CSNWZuqhF/aaytTAwy9/6RQIwkKFu+7+mkZZq9yP0HUFKWnsRpgIa4Bgbf7Fm783WXK3QgaPPW44OFzt8iOyeeCYoMOzVKeb4yPFo4ZcZLarlJEpk3g+2AUWfQ6//VyTHKnG7uAIfn9Wnn835du2jrZ5FDTnkqye4Mrwdrzp2X0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603470425; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=uoyjLt+gARtd7y51vlGjeKLiscOL3AjdBsOhpLXNLIw=; b=PblfUd/TzQQIsljk5mG0ZLPmCzVYU+LEl4RTJIQvn2C4UNoynnO8Eu79Espibu7NinAdwbHZiGM1w/FEjsItC5Poin5v1NNFLIA1g3EUQlE01dA/ev7klP3PLkPbxfsdbTT3uFsyLcZcfE4TBPehnqS4LB7BwsY96dSTXHTXRr0= 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 1603470425395890.2876362810043; Fri, 23 Oct 2020 09:27:05 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.11210.29819 (Exim 4.92) (envelope-from ) id 1kVzty-0001ex-CP; Fri, 23 Oct 2020 16:26:50 +0000 Received: by outflank-mailman (output) from mailman id 11210.29819; Fri, 23 Oct 2020 16:26:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztx-0001eU-UM; Fri, 23 Oct 2020 16:26:49 +0000 Received: by outflank-mailman (input) for mailman id 11210; Fri, 23 Oct 2020 16:26:47 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztv-0000v3-IC for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:26:47 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 528ee80c-e585-44e9-9d9c-44a3707f41eb; Fri, 23 Oct 2020 16:26:22 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztV-0008O8-7t; Fri, 23 Oct 2020 16:26:21 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzql-000376-RK; Fri, 23 Oct 2020 16:23:32 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztv-0000v3-IC for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:26:47 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 528ee80c-e585-44e9-9d9c-44a3707f41eb; Fri, 23 Oct 2020 16:26:22 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztV-0008O8-7t; Fri, 23 Oct 2020 16:26:21 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzql-000376-RK; Fri, 23 Oct 2020 16:23:32 +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" X-Inumbo-ID: 528ee80c-e585-44e9-9d9c-44a3707f41eb DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=uoyjLt+gARtd7y51vlGjeKLiscOL3AjdBsOhpLXNLIw=; b=Eo22PrB86p+nJTk8ojvcFZIRc U/EWYsurGfPCK+QdMPAdcL8rtyEP0vqJo5RF2acfgCYWlkQVxDoOcfhkUqyN8m+fbnJPdutyhPxID PG1+iiIUBf6pAfdgUWmJjIWIj3PBZPjkQ0W0p8nMzBNyFB/yQBkQ/ErH7Y3EP1+DSCFJY=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson , Wei Liu Subject: [PATCH 14/25] libxl: add/recover 'rdm_policy' to/from PCI backend in xenstore Date: Fri, 23 Oct 2020 16:23:03 +0000 Message-Id: <20201023162314.2235-15-paul@xen.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20201023162314.2235-1-paul@xen.org> References: <20201023162314.2235-1-paul@xen.org> X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paul Durrant Other parameters, such as 'msitranslate' and 'permissive' are dealt with but 'rdm_policy' appears to be have been completely missed. Signed-off-by: Paul Durrant Acked-by: Christian Lindig --- Cc: Ian Jackson Cc: Wei Liu --- tools/libs/light/libxl_pci.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/libs/light/libxl_pci.c b/tools/libs/light/libxl_pci.c index 2e8e1c50f1..c5d73133eb 100644 --- a/tools/libs/light/libxl_pci.c +++ b/tools/libs/light/libxl_pci.c @@ -61,9 +61,9 @@ static void libxl_create_pci_backend_device(libxl__gc *gc, flexarray_append_pair(back, GCSPRINTF("vdevfn-%d", num), GCSPRINTF= ("%x", pci->vdevfn)); flexarray_append(back, GCSPRINTF("opts-%d", num)); flexarray_append(back, - GCSPRINTF("msitranslate=3D%d,power_mgmt=3D%d,permissive=3D%d= ", - pci->msitranslate, pci->power_mgmt, - pci->permissive)); + GCSPRINTF("msitranslate=3D%d,power_mgmt=3D%d,permissive=3D%d= ,rdm_policy=3D%s", + pci->msitranslate, pci->power_mgmt, + pci->permissive, libxl_rdm_reserve_policy_to_strin= g(pci->rdm_policy))); flexarray_append_pair(back, GCSPRINTF("state-%d", num), GCSPRINTF("%d"= , XenbusStateInitialising)); } =20 @@ -2310,6 +2310,9 @@ static int libxl__device_pci_from_xs_be(libxl__gc *gc, } else if (!strcmp(p, "permissive")) { p =3D strtok_r(NULL, ",=3D", &saveptr); pci->permissive =3D atoi(p); + } else if (!strcmp(p, "rdm_policy")) { + p =3D strtok_r(NULL, ",=3D", &saveptr); + libxl_rdm_reserve_policy_from_string(p, &pci->rdm_policy); } } while ((p =3D strtok_r(NULL, ",=3D", &saveptr)) !=3D NULL); } --=20 2.11.0 From nobody Sun May 5 11:10:29 2024 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=1603470407; cv=none; d=zohomail.com; s=zohoarc; b=mQXNi1H4NQ+K7/oNIiAbZlSBLSHyk0dcq/H0Fc3Dr7iMeT0j+1UDj8Xf4Dij4Ixkij1PrKe3uGH8pGR0dwghP75b5OzRUXqVPEhgnkQQ54I71VWXKAhBRQUmcAgCqlSPnknUpdJIjpHQGLPjywhEtPwBihzJBJ7cwHDhtOGnfgU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603470407; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=+xRHgG/V1V6jdrFunRi9DByLVqbO+8Hy1Wezh0jszpM=; b=OdP54GY+79EF/shSBxuWO4z29dRxuFif4grUpxr3mkjTP3j2qPWHtRVkz8ssaOcQaGGMGy1DbU1BlwX2Xu9HTGnHlpwm7cw/vXV0M2J10HomABz1Wtxqh5t1gJ1VGZ6kAxo67yJdLGRXFHAtHiEmRjcNeXz6fNmo0y+K7B0t7Ns= 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 1603470407435736.0757670016349; Fri, 23 Oct 2020 09:26:47 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.11200.29698 (Exim 4.92) (envelope-from ) id 1kVztY-0000vt-De; Fri, 23 Oct 2020 16:26:24 +0000 Received: by outflank-mailman (output) from mailman id 11200.29698; Fri, 23 Oct 2020 16:26:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztY-0000vi-7Z; Fri, 23 Oct 2020 16:26:24 +0000 Received: by outflank-mailman (input) for mailman id 11200; Fri, 23 Oct 2020 16:26:22 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztW-0000v3-JG for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:26:22 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 27f1b87b-7c40-4f94-ba01-9684c636cdd7; Fri, 23 Oct 2020 16:26:21 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztU-0008NS-LH; Fri, 23 Oct 2020 16:26:20 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqm-000376-LC; Fri, 23 Oct 2020 16:23:32 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztW-0000v3-JG for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:26:22 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 27f1b87b-7c40-4f94-ba01-9684c636cdd7; Fri, 23 Oct 2020 16:26:21 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztU-0008NS-LH; Fri, 23 Oct 2020 16:26:20 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqm-000376-LC; Fri, 23 Oct 2020 16:23:32 +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" X-Inumbo-ID: 27f1b87b-7c40-4f94-ba01-9684c636cdd7 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=+xRHgG/V1V6jdrFunRi9DByLVqbO+8Hy1Wezh0jszpM=; b=NkS5oRBEuIIoyTRowqey4tbzc k7H9ApuLG8+2rlTdwtjzRw9hxVTW+OnH4/Pg22zcQk2rwzYu6fsYNHCztfy2E6OtGo+OKH/KBtXKS MKaIjOp5uCu8CKbLbUfSaaiUYgrFO1ijieApbV9Tch6gld8WZWZBkRvQwg40HFvYzyRO4=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson , Wei Liu Subject: [PATCH 15/25] libxl: Make sure devices added by pci-attach are reflected in the config Date: Fri, 23 Oct 2020 16:23:04 +0000 Message-Id: <20201023162314.2235-16-paul@xen.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20201023162314.2235-1-paul@xen.org> References: <20201023162314.2235-1-paul@xen.org> X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paul Durrant Currently libxl__device_pci_add_xenstore() is broken in that does not update the domain's configuration for the first device added (which causes creation of the overall backend area in xenstore). This can be easily obser= ved by running 'xl list -l' after adding a single device: the device will be missing. This patch fixes the problem and adds a DEBUG log line to allow easy verification that the domain configuration is being modified. Signed-off-by: Paul Durrant Acked-by: Christian Lindig --- Cc: Ian Jackson Cc: Wei Liu --- tools/libs/light/libxl_pci.c | 68 +++++++++++++++++++++++-----------------= ---- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/tools/libs/light/libxl_pci.c b/tools/libs/light/libxl_pci.c index c5d73133eb..45685ebec2 100644 --- a/tools/libs/light/libxl_pci.c +++ b/tools/libs/light/libxl_pci.c @@ -79,39 +79,18 @@ static void libxl__device_from_pci(libxl__gc *gc, uint3= 2_t domid, device->kind =3D LIBXL__DEVICE_KIND_PCI; } =20 -static int libxl__create_pci_backend(libxl__gc *gc, uint32_t domid, - const libxl_device_pci *pci, - int num) +static void libxl__create_pci_backend(libxl__gc *gc, uint32_t domid, + flexarray_t *front, flexarray_t *bac= k) { - flexarray_t *front =3D NULL; - flexarray_t *back =3D NULL; - libxl__device device; - int i; - - front =3D flexarray_make(gc, 16, 1); - back =3D flexarray_make(gc, 16, 1); - LOGD(DEBUG, domid, "Creating pci backend"); =20 - /* add pci device */ - libxl__device_from_pci(gc, domid, pci, &device); - flexarray_append_pair(back, "frontend-id", GCSPRINTF("%d", domid)); - flexarray_append_pair(back, "online", "1"); + flexarray_append_pair(back, "online", GCSPRINTF("%d", 1)); flexarray_append_pair(back, "state", GCSPRINTF("%d", XenbusStateInitia= lising)); flexarray_append_pair(back, "domain", libxl__domid_to_name(gc, domid)); =20 - for (i =3D 0; i < num; i++, pci++) - libxl_create_pci_backend_device(gc, back, i, pci); - - flexarray_append_pair(back, "num_devs", GCSPRINTF("%d", num)); flexarray_append_pair(front, "backend-id", GCSPRINTF("%d", 0)); flexarray_append_pair(front, "state", GCSPRINTF("%d", XenbusStateIniti= alising)); - - return libxl__device_generic_add(gc, XBT_NULL, &device, - libxl__xs_kvs_of_flexarray(gc, back), - libxl__xs_kvs_of_flexarray(gc, front), - NULL); } =20 static int libxl__device_pci_add_xenstore(libxl__gc *gc, @@ -119,7 +98,7 @@ static int libxl__device_pci_add_xenstore(libxl__gc *gc, const libxl_device_pci *pci, bool starting) { - flexarray_t *back; + flexarray_t *front, *back; char *num_devs, *be_path; int num =3D 0; xs_transaction_t t =3D XBT_NULL; @@ -127,16 +106,22 @@ static int libxl__device_pci_add_xenstore(libxl__gc *= gc, libxl_domain_config d_config; libxl__flock *lock =3D NULL; bool is_stubdomain =3D libxl_is_stubdom(CTX, domid, NULL); + libxl__device device; + + libxl__device_from_pci(gc, domid, pci, &device); =20 /* Stubdomain doesn't have own config. */ if (!is_stubdomain) libxl_domain_config_init(&d_config); =20 + front =3D flexarray_make(gc, 16, 1); + back =3D flexarray_make(gc, 16, 1); + be_path =3D libxl__domain_device_backend_path(gc, 0, domid, 0, LIBXL__DEVICE_KIND_PCI); num_devs =3D libxl__xs_read(gc, XBT_NULL, GCSPRINTF("%s/num_devs", be_= path)); if (!num_devs) - return libxl__create_pci_backend(gc, domid, pci, 1); + libxl__create_pci_backend(gc, domid, front, back); =20 libxl_domain_type domtype =3D libxl__domain_type(gc, domid); if (domtype =3D=3D LIBXL_DOMAIN_TYPE_INVALID) @@ -147,13 +132,11 @@ static int libxl__device_pci_add_xenstore(libxl__gc *= gc, return ERROR_FAIL; } =20 - back =3D flexarray_make(gc, 16, 1); - LOGD(DEBUG, domid, "Adding new pci device to xenstore"); - num =3D atoi(num_devs); + num =3D num_devs ? atoi(num_devs) : 0; libxl_create_pci_backend_device(gc, back, num, pci); flexarray_append_pair(back, "num_devs", GCSPRINTF("%d", num + 1)); - if (!starting) + if (num && !starting) flexarray_append_pair(back, "state", GCSPRINTF("%d", XenbusStateRe= configuring)); =20 /* @@ -170,6 +153,7 @@ static int libxl__device_pci_add_xenstore(libxl__gc *gc, rc =3D libxl__get_domain_configuration(gc, domid, &d_config); if (rc) goto out; =20 + LOGD(DEBUG, domid, "Adding new pci device to config"); device_add_domain_config(gc, &d_config, &libxl__pci_devtype, pci); =20 @@ -186,7 +170,10 @@ static int libxl__device_pci_add_xenstore(libxl__gc *g= c, if (rc) goto out; } =20 - libxl__xs_writev(gc, t, be_path, libxl__xs_kvs_of_flexarray(gc, ba= ck)); + libxl__device_generic_add(gc, t, &device, + libxl__xs_kvs_of_flexarray(gc, back), + libxl__xs_kvs_of_flexarray(gc, front), + NULL); =20 rc =3D libxl__xs_transaction_commit(gc, &t); if (!rc) break; @@ -1711,8 +1698,23 @@ static void add_pcis_done(libxl__egc *egc, libxl__mu= ltidev *multidev, if (rc) goto out; =20 if (d_config->num_pcis > 0 && !libxl_get_stubdom_id(CTX, domid)) { - rc =3D libxl__create_pci_backend(gc, domid, d_config->pcis, - d_config->num_pcis); + flexarray_t *front, *back; + unsigned int i; + libxl__device device; + + libxl__device_from_pci(gc, domid, &d_config->pcis[0], &device); + + front =3D flexarray_make(gc, 16, 1); + back =3D flexarray_make(gc, 16, 1); + + libxl__create_pci_backend(gc, domid, front, back); + for (i =3D 0; i < d_config->num_pcis; i++) + libxl_create_pci_backend_device(gc, back, i, &d_config->pcis[i= ]); + + rc =3D libxl__device_generic_add(gc, XBT_NULL, &device, + libxl__xs_kvs_of_flexarray(gc, back= ), + libxl__xs_kvs_of_flexarray(gc, fron= t), + NULL); if (rc < 0) { LOGD(ERROR, domid, "libxl_create_pci_backend failed: %d", rc); goto out; --=20 2.11.0 From nobody Sun May 5 11:10:29 2024 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=1603470408; cv=none; d=zohomail.com; s=zohoarc; b=cRxc/dpReFaSG+96F2/w66oicIdW8nIGNGyTFU7A/yX9OjNoyQPEfbldBrIWpGPHdIxziE1FBzNqz3XFIijcp64lA8lb7t6/NVq3ZxZMOQWOND1EIW2cojewClK0tKZxcS6l+oDuiH8e/lfFlCyprYli5Ezdg+7+gXyqxhnP8bA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603470408; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=GMhuBQvWwKt0oiSVX55rbWxIi0temtvls6NwYa6kuYM=; b=Os5eHkOLTGhVjhg+ypdl2vS6umFvYqc4HiGqCVKHfE1IOMSmIyZ3J472ihefbbucrfgAoQ6HC53YKbj38eQY2Yp27ifms54mRsrb8+JGUsUCWJjkq8LNFutOfkUD+fWcmcNZ2pQrEO1apCB4CcfTnpIVGgZOdfV7+j7WqX+0LSg= 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 1603470408813582.0087105059391; Fri, 23 Oct 2020 09:26:48 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.11202.29724 (Exim 4.92) (envelope-from ) id 1kVztd-00011q-8W; Fri, 23 Oct 2020 16:26:29 +0000 Received: by outflank-mailman (output) from mailman id 11202.29724; Fri, 23 Oct 2020 16:26:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztd-00011Z-1K; Fri, 23 Oct 2020 16:26:29 +0000 Received: by outflank-mailman (input) for mailman id 11202; Fri, 23 Oct 2020 16:26:27 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztb-0000v3-HW for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:26:27 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 7828a2f3-b8a2-4ece-86ed-5eb63f846dcb; Fri, 23 Oct 2020 16:26:22 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztV-0008Nq-0h; Fri, 23 Oct 2020 16:26:21 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqn-000376-F3; Fri, 23 Oct 2020 16:23:33 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztb-0000v3-HW for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:26:27 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 7828a2f3-b8a2-4ece-86ed-5eb63f846dcb; Fri, 23 Oct 2020 16:26:22 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztV-0008Nq-0h; Fri, 23 Oct 2020 16:26:21 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqn-000376-F3; Fri, 23 Oct 2020 16:23:33 +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" X-Inumbo-ID: 7828a2f3-b8a2-4ece-86ed-5eb63f846dcb DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=GMhuBQvWwKt0oiSVX55rbWxIi0temtvls6NwYa6kuYM=; b=3uTiqlaer9LfnCLBMURaVX2tb ErERqysULJnoGU2hRi47Z3HIAItwBFoBv12UhCxP12KxZAqc6+xD0TX0Jt4QIaOWHHSUxmwovLGqi Pi73o3sX7oiGdAZYCdxWSyO6oNajpb/3ytdWtzivelnhXfg2EB63GgZ4A5Zb8V5ZG0DkE=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson , Wei Liu Subject: [PATCH 16/25] docs/man: extract documentation of PCI_SPEC_STRING from the xl.cfg manpage... Date: Fri, 23 Oct 2020 16:23:05 +0000 Message-Id: <20201023162314.2235-17-paul@xen.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20201023162314.2235-1-paul@xen.org> References: <20201023162314.2235-1-paul@xen.org> X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paul Durrant ... and put it into a new xl-pci-configuration(5) manpage, akin to the xl-network-configration(5) and xl-disk-configuration(5) manpages. This patch moves the content of the section verbatim. A subsequent patch will improve the documentation, once it is in its new location. Signed-off-by: Paul Durrant Acked-by: Christian Lindig --- Cc: Ian Jackson Cc: Wei Liu --- docs/man/xl-pci-configuration.5.pod | 78 +++++++++++++++++++++++++++++++++= ++++ docs/man/xl.cfg.5.pod.in | 68 +------------------------------- 2 files changed, 79 insertions(+), 67 deletions(-) create mode 100644 docs/man/xl-pci-configuration.5.pod diff --git a/docs/man/xl-pci-configuration.5.pod b/docs/man/xl-pci-configur= ation.5.pod new file mode 100644 index 0000000000..72a27bd95d --- /dev/null +++ b/docs/man/xl-pci-configuration.5.pod @@ -0,0 +1,78 @@ +=3Dencoding utf8 + +=3Dhead1 NAME + +xl-pci-configuration - XL PCI Configuration Syntax + +=3Dhead1 SYNTAX + +This document specifies the format for B which is used by +the L pci configuration option, and related L commands. + +Each B has the form of +B<[DDDD:]BB:DD.F[@VSLOT],KEY=3DVALUE,KEY=3DVALUE,...> where: + +=3Dover 4 + +=3Ditem B<[DDDD:]BB:DD.F> + +Identifies the PCI device from the host perspective in the domain +(B), Bus (B), Device (B
) and Function (B) syntax. This is +the same scheme as used in the output of B for the device in +question. + +Note: by default B will omit the domain (B) if it +is zero and it is optional here also. You may specify the function +(B) as B<*> to indicate all functions. + +=3Ditem B<@VSLOT> + +Specifies the virtual slot where the guest will see this +device. This is equivalent to the B
which the guest sees. In a +guest B and B are C<0000:00>. + +=3Ditem B + +By default pciback only allows PV guests to write "known safe" values +into PCI configuration space, likewise QEMU (both qemu-xen and +qemu-xen-traditional) imposes the same constraint on HVM guests. +However, many devices require writes to other areas of the configuration s= pace +in order to operate properly. This option tells the backend (pciback or Q= EMU) +to allow all writes to the PCI configuration space of this device by this +domain. + +B it gives the guest much +more control over the device, which may have security or stability +implications. It is recommended to only enable this option for +trusted VMs under administrator's control. + +=3Ditem B + +Specifies that MSI-INTx translation should be turned on for the PCI +device. When enabled, MSI-INTx translation will always enable MSI on +the PCI device regardless of whether the guest uses INTx or MSI. Some +device drivers, such as NVIDIA's, detect an inconsistency and do not +function when this option is enabled. Therefore the default is false (0). + +=3Ditem B + +Tells B to automatically attempt to re-assign a device to +pciback if it is not already assigned. + +B If you set this option, B will gladly re-assign a critical +system device, such as a network or a disk controller being used by +dom0 without confirmation. Please use with care. + +=3Ditem B + +B<(HVM only)> Specifies that the VM should be able to program the +D0-D3hot power management states for the PCI device. The default is false = (0). + +=3Ditem B + +B<(HVM/x86 only)> This is the same as the policy setting inside the B +option but just specific to a given device. The default is "relaxed". + +Note: this would override global B option. + +=3Dback diff --git a/docs/man/xl.cfg.5.pod.in b/docs/man/xl.cfg.5.pod.in index 0532739c1f..b00644e852 100644 --- a/docs/man/xl.cfg.5.pod.in +++ b/docs/man/xl.cfg.5.pod.in @@ -1101,73 +1101,7 @@ option is valid only when the B option i= s specified. =3Ditem B =20 Specifies the host PCI devices to passthrough to this guest. -Each B has the form of -B<[DDDD:]BB:DD.F[@VSLOT],KEY=3DVALUE,KEY=3DVALUE,...> where: - -=3Dover 4 - -=3Ditem B<[DDDD:]BB:DD.F> - -Identifies the PCI device from the host perspective in the domain -(B), Bus (B), Device (B
) and Function (B) syntax. This is -the same scheme as used in the output of B for the device in -question. - -Note: by default B will omit the domain (B) if it -is zero and it is optional here also. You may specify the function -(B) as B<*> to indicate all functions. - -=3Ditem B<@VSLOT> - -Specifies the virtual slot where the guest will see this -device. This is equivalent to the B
which the guest sees. In a -guest B and B are C<0000:00>. - -=3Ditem B - -By default pciback only allows PV guests to write "known safe" values -into PCI configuration space, likewise QEMU (both qemu-xen and -qemu-xen-traditional) imposes the same constraint on HVM guests. -However, many devices require writes to other areas of the configuration s= pace -in order to operate properly. This option tells the backend (pciback or Q= EMU) -to allow all writes to the PCI configuration space of this device by this -domain. - -B it gives the guest much -more control over the device, which may have security or stability -implications. It is recommended to only enable this option for -trusted VMs under administrator's control. - -=3Ditem B - -Specifies that MSI-INTx translation should be turned on for the PCI -device. When enabled, MSI-INTx translation will always enable MSI on -the PCI device regardless of whether the guest uses INTx or MSI. Some -device drivers, such as NVIDIA's, detect an inconsistency and do not -function when this option is enabled. Therefore the default is false (0). - -=3Ditem B - -Tells B to automatically attempt to re-assign a device to -pciback if it is not already assigned. - -B If you set this option, B will gladly re-assign a critical -system device, such as a network or a disk controller being used by -dom0 without confirmation. Please use with care. - -=3Ditem B - -B<(HVM only)> Specifies that the VM should be able to program the -D0-D3hot power management states for the PCI device. The default is false = (0). - -=3Ditem B - -B<(HVM/x86 only)> This is the same as the policy setting inside the B -option but just specific to a given device. The default is "relaxed". - -Note: this would override global B option. - -=3Dback +See L for more details. =20 =3Ditem B =20 --=20 2.11.0 From nobody Sun May 5 11:10:29 2024 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=1603470412; cv=none; d=zohomail.com; s=zohoarc; b=GrL8OPdSlMo7TC8Ys3RoQUvDXUWw0krPP5UadnA5j/OLpaSCWO1AF5fiz4ZabvYiJB63CQJNLplfjcefc3DACOitmihd9/PEMWlJPXrfbDS6hyDlOVon8mcygxpqGSlspT1ZRSlTWaKfaAUwELu8zYZjsop5gXAPdJSCjwZaGog= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603470412; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=z6HgaaJxE43aYUfbefthFXj4bV6TUshSIIqyN3QunIw=; b=k88w9JEXwSl9Ei1hXHkaDZ+l5OP8iOCTiruG3UT2+35ihFyEbwVbyyF5DjD36tinycV2OE879vvyAlYfq7WcNNb9Sh7JnHzQ88A+EitsGOs9RlHdgKwN9a1pBlJSU6h4Udbc0A3fdQvGrJFZAo0/hvGxhLPZ5lbJh5bDbsfO5Zo= 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 1603470412872388.83782986521635; Fri, 23 Oct 2020 09:26:52 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.11204.29747 (Exim 4.92) (envelope-from ) id 1kVzti-00019L-3K; Fri, 23 Oct 2020 16:26:34 +0000 Received: by outflank-mailman (output) from mailman id 11204.29747; Fri, 23 Oct 2020 16:26:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzth-000197-RI; Fri, 23 Oct 2020 16:26:33 +0000 Received: by outflank-mailman (input) for mailman id 11204; Fri, 23 Oct 2020 16:26:32 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztg-0000v3-Hx for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:26:32 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id b97d7312-5e9d-4a2e-87ca-00498ffff7bc; Fri, 23 Oct 2020 16:26:22 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztV-0008O0-53; Fri, 23 Oct 2020 16:26:21 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqo-000376-8v; Fri, 23 Oct 2020 16:23:34 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztg-0000v3-Hx for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:26:32 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id b97d7312-5e9d-4a2e-87ca-00498ffff7bc; Fri, 23 Oct 2020 16:26:22 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztV-0008O0-53; Fri, 23 Oct 2020 16:26:21 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqo-000376-8v; Fri, 23 Oct 2020 16:23:34 +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" X-Inumbo-ID: b97d7312-5e9d-4a2e-87ca-00498ffff7bc DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=z6HgaaJxE43aYUfbefthFXj4bV6TUshSIIqyN3QunIw=; b=Zz6BTj1cwZdakGQDRxN1PhsFE SHOWDggs1srSx+88vukhHOKibqNIrfxjy+A5ZtkyXQWRYZdhPJPBh3L0D7qDjEYwbXTY4AFZ+tXdu J9tevDgsgVKi2BzjsnW76OojdsJufMOcS0v3bZHOFDeia8RzNfHZc4gVV/U8iSSKewcEo=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson , Wei Liu Subject: [PATCH 17/25] docs/man: improve documentation of PCI_SPEC_STRING... Date: Fri, 23 Oct 2020 16:23:06 +0000 Message-Id: <20201023162314.2235-18-paul@xen.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20201023162314.2235-1-paul@xen.org> References: <20201023162314.2235-1-paul@xen.org> X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paul Durrant ... and prepare for adding support for non-positional parsing of 'bdf' and 'vslot' in a subsequent patch. Also document 'BDF' as a first-class parameter type and fix the documentati= on to state that the default value of 'rdm_policy' is actually 'strict', not 'relaxed', as can be seen in libxl__device_pci_setdefault(). Signed-off-by: Paul Durrant Acked-by: Christian Lindig --- Cc: Ian Jackson Cc: Wei Liu --- docs/man/xl-pci-configuration.5.pod | 177 ++++++++++++++++++++++++++++++--= ---- 1 file changed, 148 insertions(+), 29 deletions(-) diff --git a/docs/man/xl-pci-configuration.5.pod b/docs/man/xl-pci-configur= ation.5.pod index 72a27bd95d..4dd73bc498 100644 --- a/docs/man/xl-pci-configuration.5.pod +++ b/docs/man/xl-pci-configuration.5.pod @@ -6,32 +6,105 @@ xl-pci-configuration - XL PCI Configuration Syntax =20 =3Dhead1 SYNTAX =20 -This document specifies the format for B which is used by -the L pci configuration option, and related L commands. +This document specifies the format for B and B which= are +used by the L pci configuration option, and related L +commands. =20 -Each B has the form of -B<[DDDD:]BB:DD.F[@VSLOT],KEY=3DVALUE,KEY=3DVALUE,...> where: +A B has the following form: + + [DDDD:]BB:SS.F + +B is the domain number, B is the bus number, B is the device= (or +slot) number, and B is the function number. This is the same scheme as +used in the output of L for the device in question. By default +L will omit the domain (B) if it is zero and hence a zero +value for domain may also be omitted when specifying a B. + +Each B has the one of the forms: + +=3Dover 4 + + [[@,][=3D,]* + [=3D,]* + +=3Dback + +For example, these strings are equivalent: =20 =3Dover 4 =20 -=3Ditem B<[DDDD:]BB:DD.F> + 36:00.0@20,seize=3D1 + 36:00.0,vslot=3D20,seize=3D1 + bdf=3D36:00.0,vslot=3D20,seize=3D1 =20 -Identifies the PCI device from the host perspective in the domain -(B), Bus (B), Device (B
) and Function (B) syntax. This is -the same scheme as used in the output of B for the device in -question. +=3Dback + +More formally, the string is a series of comma-separated keyword/value +pairs, flags and positional parameters. Parameters which are not bare +keywords and which do not contain "=3D" symbols are assigned to the +positional parameters, in the order specified below. The positional +parameters may also be specified by name. + +Each parameter may be specified at most once, either as a positional +parameter or a named parameter. Default values apply if the parameter +is not specified, or if it is specified with an empty value (whether +positionally or explicitly). + +B: In context of B (see L), parameters other t= han +B will be ignored. + +=3Dhead1 Positional Parameters + +=3Dover 4 + +=3Ditem B=3DI + +=3Dover 4 =20 -Note: by default B will omit the domain (B) if it -is zero and it is optional here also. You may specify the function -(B) as B<*> to indicate all functions. +=3Ditem Description =20 -=3Ditem B<@VSLOT> +This identifies the PCI device from the host perspective. =20 -Specifies the virtual slot where the guest will see this -device. This is equivalent to the B
which the guest sees. In a -guest B and B are C<0000:00>. +In the context of a B you may specify the function (B)= as +B<*> to indicate all functions of a multi-function device. =20 -=3Ditem B +=3Ditem Default Value + +None. This parameter is mandatory as it identifies the device. + +=3Dback + +=3Ditem B=3DI + +=3Dover 4 + +=3Ditem Description + +Specifies the virtual slot (device) number where the guest will see this +device. For example, running L in a Linux guest where B +was specified as C<8> would identify the device as C<00:08.0>. Virtual dom= ain +and bus numbers are always 0. + +B This parameter is always parsed as a hexidecimal value. + +=3Ditem Default Value + +None. This parameter is not mandatory. An available B will be selec= ted +if this parameter is not specified. + +=3Dback + +=3Dback + +=3Dhead1 Other Parameters and Flags + +=3Dover 4 + +=3Ditem B=3DI + +=3Dover 4 + +=3Ditem Description =20 By default pciback only allows PV guests to write "known safe" values into PCI configuration space, likewise QEMU (both qemu-xen and @@ -46,33 +119,79 @@ more control over the device, which may have security = or stability implications. It is recommended to only enable this option for trusted VMs under administrator's control. =20 -=3Ditem B +=3Ditem Default Value + +0 + +=3Dback + +=3Ditem B=3DI + +=3Dover 4 + +=3Ditem Description =20 Specifies that MSI-INTx translation should be turned on for the PCI device. When enabled, MSI-INTx translation will always enable MSI on -the PCI device regardless of whether the guest uses INTx or MSI. Some -device drivers, such as NVIDIA's, detect an inconsistency and do not +the PCI device regardless of whether the guest uses INTx or MSI. + +=3Ditem Default Value + +Some device drivers, such as NVIDIA's, detect an inconsistency and do not function when this option is enabled. Therefore the default is false (0). =20 -=3Ditem B +=3Dback + +=3Ditem B=3DI + +=3Dover 4 + +=3Ditem Description =20 -Tells B to automatically attempt to re-assign a device to -pciback if it is not already assigned. +Tells L to automatically attempt to make the device assignable to +guests if that has not already been done by the B +command. =20 -B If you set this option, B will gladly re-assign a critical +B If you set this option, L will gladly re-assign a critical system device, such as a network or a disk controller being used by dom0 without confirmation. Please use with care. =20 -=3Ditem B +=3Ditem Default Value + +0 + +=3Dback + +=3Ditem B=3DI + +=3Dover 4 + +=3Ditem Description =20 B<(HVM only)> Specifies that the VM should be able to program the -D0-D3hot power management states for the PCI device. The default is false = (0). +D0-D3hot power management states for the PCI device. + +=3Ditem Default Value + +0 =20 -=3Ditem B +=3Dback + +=3Ditem B=3DI + +=3Dover 4 + +=3Ditem Description =20 B<(HVM/x86 only)> This is the same as the policy setting inside the B -option but just specific to a given device. The default is "relaxed". +option in L but just specific to a given device. =20 -Note: this would override global B option. +B: This overrides the global B option. + +=3Ditem Default Value + +"strict" + +=3Dback =20 =3Dback --=20 2.11.0 From nobody Sun May 5 11:10:29 2024 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=1603470404; cv=none; d=zohomail.com; s=zohoarc; b=U1MnfjSvJvG+/trU/O7x1hTsH6VxbhqEr1EN35Ca/frropL6FuHe5FGP3bFC+imxT9QTq5lbD0HAZihNL2Ln3ZUX9STrma1otkF6s707up6TZPbFIF2aYL4+VCrRD392Z2yohzmn54Chw8zMwfsBcI/1KLbdLSlNf26sy9Far7Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603470404; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=um7JEb+Wnwt5fiP5c5wstzbmPuQS6pAhcCxDSP4apgk=; b=V99KbYjKcKpt7J+nV6vsiWQj9gJjLNd8UEAHcDMUeMLc+p1IMnsDmPnlS6BoVFtUOu+Lf8WsgjiCHZmevr9+RUhW+0Ly6eN01MPhE1M4ztIZtz9/K03nUbASrfkcde1m2YLzaydSB8cBhjCvvU0cO9vB15RtIqJY1GE6//v7I5c= 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 1603470404054610.7575620787957; Fri, 23 Oct 2020 09:26:44 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.11201.29717 (Exim 4.92) (envelope-from ) id 1kVztc-00010u-Qf; Fri, 23 Oct 2020 16:26:28 +0000 Received: by outflank-mailman (output) from mailman id 11201.29717; Fri, 23 Oct 2020 16:26:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztc-00010m-N8; Fri, 23 Oct 2020 16:26:28 +0000 Received: by outflank-mailman (input) for mailman id 11201; Fri, 23 Oct 2020 16:26:27 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztb-0000v2-GB for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:26:27 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 897b0fc5-8dbf-4bc1-a5d7-e01dd3117c9b; Fri, 23 Oct 2020 16:26:21 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztU-0008NQ-Iu; Fri, 23 Oct 2020 16:26:20 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqp-000376-2n; Fri, 23 Oct 2020 16:23:35 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztb-0000v2-GB for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:26:27 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 897b0fc5-8dbf-4bc1-a5d7-e01dd3117c9b; Fri, 23 Oct 2020 16:26:21 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztU-0008NQ-Iu; Fri, 23 Oct 2020 16:26:20 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqp-000376-2n; Fri, 23 Oct 2020 16:23:35 +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" X-Inumbo-ID: 897b0fc5-8dbf-4bc1-a5d7-e01dd3117c9b DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=um7JEb+Wnwt5fiP5c5wstzbmPuQS6pAhcCxDSP4apgk=; b=h5SsgST+sCAoFHA0FZRabee9q wdqGgTts8Q9LxErYlEfoXtNMvcoMJhvNZ4RqeFk5rNDVjjVyjcTwXGc5dXCmRcc98y0a9vjvMksym 7Zg1ekeRnIeRPdDR8jUG672LLSFypFD7c+SRhcNBHhmJY9ZUp5Il4+ifEae8unb1nexQ4=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson , Wei Liu Subject: [PATCH 18/25] docs/man: fix xl(1) documentation for 'pci' operations Date: Fri, 23 Oct 2020 16:23:07 +0000 Message-Id: <20201023162314.2235-19-paul@xen.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20201023162314.2235-1-paul@xen.org> References: <20201023162314.2235-1-paul@xen.org> X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paul Durrant Currently the documentation completely fails to mention the existence of PCI_SPEC_STRING. This patch tidies things up, specifically clarifying that 'pci-assignable-add/remove' take arguments where as 'pci-attach/detac= h' take arguments (which will be enforced in a subsequent patch). Signed-off-by: Paul Durrant Acked-by: Christian Lindig --- Cc: Ian Jackson Cc: Wei Liu --- docs/man/xl.1.pod.in | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/docs/man/xl.1.pod.in b/docs/man/xl.1.pod.in index 5f7d3a7134..373a52839d 100644 --- a/docs/man/xl.1.pod.in +++ b/docs/man/xl.1.pod.in @@ -1597,14 +1597,18 @@ List virtual network interfaces for a domain. =20 =3Ditem B =20 -List all the assignable PCI devices. +List all the B of assignable PCI devices. See +L for more information. + These are devices in the system which are configured to be available for passthrough and are bound to a suitable PCI backend driver in domain 0 rather than a real driver. =20 =3Ditem B I =20 -Make the device at PCI Bus/Device/Function BDF assignable to guests. +Make the device at B assignable to guests. See +L for more information. + This will bind the device to the pciback driver and assign it to the "quarantine domain". If it is already bound to a driver, it will first be unbound, and the original driver stored so that it can be @@ -1620,8 +1624,10 @@ being used. =20 =3Ditem B [I<-r>] I =20 -Make the device at PCI Bus/Device/Function BDF not assignable to -guests. This will at least unbind the device from pciback, and +Make the device at B not assignable to guests. See +L for more information. + +This will at least unbind the device from pciback, and re-assign it from the "quarantine domain" back to domain 0. If the -r option is specified, it will also attempt to re-bind the device to its original driver, making it usable by Domain 0 again. If the device is @@ -1637,15 +1643,15 @@ As always, this should only be done if you trust th= e guest, or are confident that the particular device you're re-assigning to dom0 will cancel all in-flight DMA on FLR. =20 -=3Ditem B I I +=3Ditem B I I =20 -Hot-plug a new pass-through pci device to the specified domain. -B is the PCI Bus/Device/Function of the physical device to pass-throu= gh. +Hot-plug a new pass-through pci device to the specified domain. See +L for more information. =20 -=3Ditem B [I] I I +=3Ditem B [I] I I =20 -Hot-unplug a previously assigned pci device from a domain. B is the P= CI -Bus/Device/Function of the physical device to be removed from the guest do= main. +Hot-unplug a pci device that was previously passed through to a domain. See +L for more information. =20 B =20 @@ -1660,7 +1666,7 @@ even without guest domain's collaboration. =20 =3Ditem B I =20 -List pass-through pci devices for a domain. +List the B of pci devices passed through to a domain. =20 =3Dback =20 --=20 2.11.0 From nobody Sun May 5 11:10:29 2024 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=1603470425; cv=none; d=zohomail.com; s=zohoarc; b=FEDcl5ESEbZGB8OlzEsjDZc3DSFgUzU5cqwbGoYHqSgfMjQ8tI+eSuhTv8EcjiK+6KtVBYYHBb/pyDP1xDxh8Pe8EGsk490K0rEpwsavKrs5ndNuNyZFIMXju4nW5wx4s4g19GtdL/sC8/NekrJ3XxBj8ACn248QtvuVOuNkyb4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603470425; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=B5YV8ybDELJCpp3SDKwlX7entpb3B/zsUKYNaPdCHGs=; b=BYN7PVsBqzIk035yhNovLvBFBgCyIQtd03VmmBQ+KlPNBxWucCPkuRN3XeLx63x/3Typ+yqcFWYoEglR+K4wkv8Pr7sjbxP0DZB4RD7cvTDEUjajul6z6m4LPNjxwnHvr+2vYZkp0360qJVWN4Yf7BXm84b5IQgmvCRLbd2s0fk= 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 1603470425142980.2733952768995; Fri, 23 Oct 2020 09:27:05 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.11208.29794 (Exim 4.92) (envelope-from ) id 1kVztt-0001Sb-2g; Fri, 23 Oct 2020 16:26:45 +0000 Received: by outflank-mailman (output) from mailman id 11208.29794; Fri, 23 Oct 2020 16:26:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzts-0001SF-O1; Fri, 23 Oct 2020 16:26:44 +0000 Received: by outflank-mailman (input) for mailman id 11208; Fri, 23 Oct 2020 16:26:42 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztq-0000v3-IC for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:26:42 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id cfcfee88-6d13-4832-b2d6-32347057bf74; Fri, 23 Oct 2020 16:26:22 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztU-0008Na-R0; Fri, 23 Oct 2020 16:26:20 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqq-000376-6U; Fri, 23 Oct 2020 16:23:36 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztq-0000v3-IC for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:26:42 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id cfcfee88-6d13-4832-b2d6-32347057bf74; Fri, 23 Oct 2020 16:26:22 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztU-0008Na-R0; Fri, 23 Oct 2020 16:26:20 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqq-000376-6U; Fri, 23 Oct 2020 16:23:36 +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" X-Inumbo-ID: cfcfee88-6d13-4832-b2d6-32347057bf74 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=B5YV8ybDELJCpp3SDKwlX7entpb3B/zsUKYNaPdCHGs=; b=XTq1cg8rSTL6bX0C1eumTX540 pSSOgzfpjL5rjN8lZEzBEmkEOpGBCfEg8RvbgR1yqqdS3w1fJ0Hta6EU1qDCk1PD1gMjO7VsJWq8D tliu43kx57mLYpwrojdfJ+mUDa2htuvPNnpSwIW/B2RE7Oe8iGus5L+tC7eVDm1COEV30=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , George Dunlap , Nick Rosbrook , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH 19/25] libxl: introduce 'libxl_pci_bdf' in the idl... Date: Fri, 23 Oct 2020 16:23:08 +0000 Message-Id: <20201023162314.2235-20-paul@xen.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20201023162314.2235-1-paul@xen.org> References: <20201023162314.2235-1-paul@xen.org> X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paul Durrant ... and use in 'libxl_device_pci' This patch is preparatory work for restricting the type passed to functions that only require BDF information, rather than passing a 'libxl_device_pci' structure which is only partially filled. In this patch only the minimal mechanical changes necessary to deal with the structural changes are made. Subsequent patches will adjust the code to make better use of the new type. Signed-off-by: Paul Durrant Acked-by: Christian Lindig --- Cc: George Dunlap Cc: Nick Rosbrook Cc: Ian Jackson Cc: Wei Liu Cc: Anthony PERARD --- tools/golang/xenlight/helpers.gen.go | 77 ++++++++++++------ tools/golang/xenlight/types.gen.go | 8 +- tools/include/libxl.h | 6 ++ tools/libs/light/libxl_dm.c | 8 +- tools/libs/light/libxl_internal.h | 3 +- tools/libs/light/libxl_pci.c | 148 +++++++++++++++++--------------= ---- tools/libs/light/libxl_types.idl | 16 ++-- tools/libs/util/libxlu_pci.c | 8 +- tools/xl/xl_pci.c | 6 +- tools/xl/xl_sxp.c | 4 +- 10 files changed, 167 insertions(+), 117 deletions(-) diff --git a/tools/golang/xenlight/helpers.gen.go b/tools/golang/xenlight/h= elpers.gen.go index c8605994e7..b7230f693c 100644 --- a/tools/golang/xenlight/helpers.gen.go +++ b/tools/golang/xenlight/helpers.gen.go @@ -1999,6 +1999,41 @@ xc.colo_checkpoint_port =3D C.CString(x.ColoCheckpoi= ntPort)} return nil } =20 +// NewPciBdf returns an instance of PciBdf initialized with defaults. +func NewPciBdf() (*PciBdf, error) { +var ( +x PciBdf +xc C.libxl_pci_bdf) + +C.libxl_pci_bdf_init(&xc) +defer C.libxl_pci_bdf_dispose(&xc) + +if err :=3D x.fromC(&xc); err !=3D nil { +return nil, err } + +return &x, nil} + +func (x *PciBdf) fromC(xc *C.libxl_pci_bdf) error { + x.Func =3D byte(xc._func) +x.Dev =3D byte(xc.dev) +x.Bus =3D byte(xc.bus) +x.Domain =3D int(xc.domain) + + return nil} + +func (x *PciBdf) toC(xc *C.libxl_pci_bdf) (err error){defer func(){ +if err !=3D nil{ +C.libxl_pci_bdf_dispose(xc)} +}() + +xc._func =3D C.uint8_t(x.Func) +xc.dev =3D C.uint8_t(x.Dev) +xc.bus =3D C.uint8_t(x.Bus) +xc.domain =3D C.int(x.Domain) + + return nil + } + // NewDevicePci returns an instance of DevicePci initialized with defaults. func NewDevicePci() (*DevicePci, error) { var ( @@ -2014,10 +2049,9 @@ return nil, err } return &x, nil} =20 func (x *DevicePci) fromC(xc *C.libxl_device_pci) error { - x.Func =3D byte(xc._func) -x.Dev =3D byte(xc.dev) -x.Bus =3D byte(xc.bus) -x.Domain =3D int(xc.domain) + if err :=3D x.Bdf.fromC(&xc.bdf);err !=3D nil { +return fmt.Errorf("converting field Bdf: %v", err) +} x.Vdevfn =3D uint32(xc.vdevfn) x.VfuncMask =3D uint32(xc.vfunc_mask) x.Msitranslate =3D bool(xc.msitranslate) @@ -2033,10 +2067,9 @@ if err !=3D nil{ C.libxl_device_pci_dispose(xc)} }() =20 -xc._func =3D C.uint8_t(x.Func) -xc.dev =3D C.uint8_t(x.Dev) -xc.bus =3D C.uint8_t(x.Bus) -xc.domain =3D C.int(x.Domain) +if err :=3D x.Bdf.toC(&xc.bdf); err !=3D nil { +return fmt.Errorf("converting field Bdf: %v", err) +} xc.vdevfn =3D C.uint32_t(x.Vdevfn) xc.vfunc_mask =3D C.uint32_t(x.VfuncMask) xc.msitranslate =3D C.bool(x.Msitranslate) @@ -2766,13 +2799,13 @@ if err :=3D x.Nics[i].fromC(&v); err !=3D nil { return fmt.Errorf("converting field Nics: %v", err) } } } -x.Pcidevs =3D nil -if n :=3D int(xc.num_pcidevs); n > 0 { -cPcidevs :=3D (*[1<<28]C.libxl_device_pci)(unsafe.Pointer(xc.pcidevs))[:n:= n] -x.Pcidevs =3D make([]DevicePci, n) -for i, v :=3D range cPcidevs { -if err :=3D x.Pcidevs[i].fromC(&v); err !=3D nil { -return fmt.Errorf("converting field Pcidevs: %v", err) } +x.Pcis =3D nil +if n :=3D int(xc.num_pcis); n > 0 { +cPcis :=3D (*[1<<28]C.libxl_device_pci)(unsafe.Pointer(xc.pcis))[:n:n] +x.Pcis =3D make([]DevicePci, n) +for i, v :=3D range cPcis { +if err :=3D x.Pcis[i].fromC(&v); err !=3D nil { +return fmt.Errorf("converting field Pcis: %v", err) } } } x.Rdms =3D nil @@ -2922,13 +2955,13 @@ return fmt.Errorf("converting field Nics: %v", err) } } } -if numPcidevs :=3D len(x.Pcidevs); numPcidevs > 0 { -xc.pcidevs =3D (*C.libxl_device_pci)(C.malloc(C.ulong(numPcidevs)*C.sizeof= _libxl_device_pci)) -xc.num_pcidevs =3D C.int(numPcidevs) -cPcidevs :=3D (*[1<<28]C.libxl_device_pci)(unsafe.Pointer(xc.pcidevs))[:nu= mPcidevs:numPcidevs] -for i,v :=3D range x.Pcidevs { -if err :=3D v.toC(&cPcidevs[i]); err !=3D nil { -return fmt.Errorf("converting field Pcidevs: %v", err) +if numPcis :=3D len(x.Pcis); numPcis > 0 { +xc.pcis =3D (*C.libxl_device_pci)(C.malloc(C.ulong(numPcis)*C.sizeof_libxl= _device_pci)) +xc.num_pcis =3D C.int(numPcis) +cPcis :=3D (*[1<<28]C.libxl_device_pci)(unsafe.Pointer(xc.pcis))[:numPcis:= numPcis] +for i,v :=3D range x.Pcis { +if err :=3D v.toC(&cPcis[i]); err !=3D nil { +return fmt.Errorf("converting field Pcis: %v", err) } } } diff --git a/tools/golang/xenlight/types.gen.go b/tools/golang/xenlight/typ= es.gen.go index b4c5df0f2c..bc62ae8ce9 100644 --- a/tools/golang/xenlight/types.gen.go +++ b/tools/golang/xenlight/types.gen.go @@ -707,11 +707,15 @@ ColoCheckpointHost string ColoCheckpointPort string } =20 -type DevicePci struct { +type PciBdf struct { Func byte Dev byte Bus byte Domain int +} + +type DevicePci struct { +Bdf PciBdf Vdevfn uint32 VfuncMask uint32 Msitranslate bool @@ -896,7 +900,7 @@ CInfo DomainCreateInfo BInfo DomainBuildInfo Disks []DeviceDisk Nics []DeviceNic -Pcidevs []DevicePci +Pcis []DevicePci Rdms []DeviceRdm Dtdevs []DeviceDtdev Vfbs []DeviceVfb diff --git a/tools/include/libxl.h b/tools/include/libxl.h index 8225809d94..5edacccbd1 100644 --- a/tools/include/libxl.h +++ b/tools/include/libxl.h @@ -464,6 +464,12 @@ #define LIBXL_HAVE_DEVICE_PCI_ASSIGNABLE_LIST_FREE 1 =20 /* + * LIBXL_HAVE_PCI_BDF indicates that the 'libxl_pci_bdf' type is defined + * is embedded in the 'libxl_device_pci' type. + */ +#define LIBXL_HAVE_PCI_BDF 1 + +/* * libxl ABI compatibility * * The only guarantee which libxl makes regarding ABI compatibility diff --git a/tools/libs/light/libxl_dm.c b/tools/libs/light/libxl_dm.c index f147a733c8..e7f36a1742 100644 --- a/tools/libs/light/libxl_dm.c +++ b/tools/libs/light/libxl_dm.c @@ -472,10 +472,10 @@ int libxl__domain_device_construct_rdm(libxl__gc *gc, for (i =3D 0; i < d_config->num_pcis; i++) { unsigned int n, nr_entries; =20 - seg =3D d_config->pcis[i].domain; - bus =3D d_config->pcis[i].bus; - devfn =3D PCI_DEVFN(d_config->pcis[i].dev, - d_config->pcis[i].func); + seg =3D d_config->pcis[i].bdf.domain; + bus =3D d_config->pcis[i].bdf.bus; + devfn =3D PCI_DEVFN(d_config->pcis[i].bdf.dev, + d_config->pcis[i].bdf.func); nr_entries =3D 0; rc =3D libxl__xc_device_get_rdm(gc, 0, seg, bus, devfn, &nr_entries, &xrdm); diff --git a/tools/libs/light/libxl_internal.h b/tools/libs/light/libxl_int= ernal.h index 80d7988622..e1cb8404ab 100644 --- a/tools/libs/light/libxl_internal.h +++ b/tools/libs/light/libxl_internal.h @@ -4744,10 +4744,11 @@ void libxl__xcinfo2xlinfo(libxl_ctx *ctx, * devices have same identifier. */ #define COMPARE_DEVID(a, b) ((a)->devid =3D=3D (b)->devid) #define COMPARE_DISK(a, b) (!strcmp((a)->vdev, (b)->vdev)) -#define COMPARE_PCI(a, b) ((a)->domain =3D=3D (b)->domain && \ +#define COMPARE_BDF(a, b) ((a)->domain =3D=3D (b)->domain && \ (a)->bus =3D=3D (b)->bus && \ (a)->dev =3D=3D (b)->dev && \ (a)->func =3D=3D (b)->func) +#define COMPARE_PCI(a, b) COMPARE_BDF(&((a)->bdf), &((b)->bdf)) #define COMPARE_USB(a, b) ((a)->ctrl =3D=3D (b)->ctrl && \ (a)->port =3D=3D (b)->port) #define COMPARE_USBCTRL(a, b) ((a)->devid =3D=3D (b)->devid) diff --git a/tools/libs/light/libxl_pci.c b/tools/libs/light/libxl_pci.c index 45685ebec2..fec77dd270 100644 --- a/tools/libs/light/libxl_pci.c +++ b/tools/libs/light/libxl_pci.c @@ -29,10 +29,10 @@ static unsigned int pci_encode_bdf(libxl_device_pci *pc= i) { unsigned int value; =20 - value =3D pci->domain << 16; - value |=3D (pci->bus & 0xff) << 8; - value |=3D (pci->dev & 0x1f) << 3; - value |=3D (pci->func & 0x7); + value =3D pci->bdf.domain << 16; + value |=3D (pci->bdf.bus & 0xff) << 8; + value |=3D (pci->bdf.dev & 0x1f) << 3; + value |=3D (pci->bdf.func & 0x7); =20 return value; } @@ -41,10 +41,10 @@ static void pci_struct_fill(libxl_device_pci *pci, unsi= gned int domain, unsigned int bus, unsigned int dev, unsigned int func, unsigned int vdevfn) { - pci->domain =3D domain; - pci->bus =3D bus; - pci->dev =3D dev; - pci->func =3D func; + pci->bdf.domain =3D domain; + pci->bdf.bus =3D bus; + pci->bdf.dev =3D dev; + pci->bdf.func =3D func; pci->vdevfn =3D vdevfn; } =20 @@ -54,9 +54,9 @@ static void libxl_create_pci_backend_device(libxl__gc *gc, const libxl_device_pci *pci) { flexarray_append(back, GCSPRINTF("key-%d", num)); - flexarray_append(back, GCSPRINTF(PCI_BDF, pci->domain, pci->bus, pci->= dev, pci->func)); + flexarray_append(back, GCSPRINTF(PCI_BDF, pci->bdf.domain, pci->bdf.bu= s, pci->bdf.dev, pci->bdf.func)); flexarray_append(back, GCSPRINTF("dev-%d", num)); - flexarray_append(back, GCSPRINTF(PCI_BDF, pci->domain, pci->bus, pci->= dev, pci->func)); + flexarray_append(back, GCSPRINTF(PCI_BDF, pci->bdf.domain, pci->bdf.bu= s, pci->bdf.dev, pci->bdf.func)); if (pci->vdevfn) flexarray_append_pair(back, GCSPRINTF("vdevfn-%d", num), GCSPRINTF= ("%x", pci->vdevfn)); flexarray_append(back, GCSPRINTF("opts-%d", num)); @@ -218,8 +218,8 @@ static int libxl__device_pci_remove_xenstore(libxl__gc = *gc, uint32_t domid, libx unsigned int domain =3D 0, bus =3D 0, dev =3D 0, func =3D 0; xsdev =3D libxl__xs_read(gc, XBT_NULL, GCSPRINTF("%s/dev-%d", be_p= ath, i)); sscanf(xsdev, PCI_BDF, &domain, &bus, &dev, &func); - if (domain =3D=3D pci->domain && bus =3D=3D pci->bus && - pci->dev =3D=3D dev && pci->func =3D=3D func) { + if (domain =3D=3D pci->bdf.domain && bus =3D=3D pci->bdf.bus && + pci->bdf.dev =3D=3D dev && pci->bdf.func =3D=3D func) { break; } } @@ -330,8 +330,8 @@ static int sysfs_write_bdf(libxl__gc *gc, const char * = sysfs_path, return ERROR_FAIL; } =20 - buf =3D GCSPRINTF(PCI_BDF, pci->domain, pci->bus, - pci->dev, pci->func); + buf =3D GCSPRINTF(PCI_BDF, pci->bdf.domain, pci->bdf.bus, + pci->bdf.dev, pci->bdf.func); rc =3D write(fd, buf, strlen(buf)); /* Annoying to have two if's, but we need the errno */ if (rc < 0) @@ -351,10 +351,10 @@ static char *pci_info_xs_path(libxl__gc *gc, libxl_de= vice_pci *pci, { return node ? GCSPRINTF(PCI_INFO_PATH"/"PCI_BDF_XSPATH"/%s", - pci->domain, pci->bus, pci->dev, pci->func, + pci->bdf.domain, pci->bdf.bus, pci->bdf.dev, pci->bdf.fu= nc, node) : GCSPRINTF(PCI_INFO_PATH"/"PCI_BDF_XSPATH, - pci->domain, pci->bus, pci->dev, pci->func); + pci->bdf.domain, pci->bdf.bus, pci->bdf.dev, pci->bdf.fu= nc); } =20 =20 @@ -452,10 +452,10 @@ static int sysfs_dev_unbind(libxl__gc *gc, libxl_devi= ce_pci *pci, struct stat st; =20 spath =3D GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/driver", - pci->domain, - pci->bus, - pci->dev, - pci->func); + pci->bdf.domain, + pci->bdf.bus, + pci->bdf.dev, + pci->bdf.func); if ( !lstat(spath, &st) ) { /* Find the canonical path to the driver. */ dp =3D libxl__zalloc(gc, PATH_MAX); @@ -485,7 +485,7 @@ static uint16_t sysfs_dev_get_vendor(libxl__gc *gc, lib= xl_device_pci *pci) { char *pci_device_vendor_path =3D GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/vendor", - pci->domain, pci->bus, pci->dev, pci->func); + pci->bdf.domain, pci->bdf.bus, pci->bdf.dev, pci->bd= f.func); uint16_t read_items; uint16_t pci_device_vendor; =20 @@ -493,7 +493,7 @@ static uint16_t sysfs_dev_get_vendor(libxl__gc *gc, lib= xl_device_pci *pci) if (!f) { LOGE(ERROR, "pci device "PCI_BDF" does not have vendor attribute", - pci->domain, pci->bus, pci->dev, pci->func); + pci->bdf.domain, pci->bdf.bus, pci->bdf.dev, pci->bdf.func); return 0xffff; } read_items =3D fscanf(f, "0x%hx\n", &pci_device_vendor); @@ -501,7 +501,7 @@ static uint16_t sysfs_dev_get_vendor(libxl__gc *gc, lib= xl_device_pci *pci) if (read_items !=3D 1) { LOGE(ERROR, "cannot read vendor of pci device "PCI_BDF, - pci->domain, pci->bus, pci->dev, pci->func); + pci->bdf.domain, pci->bdf.bus, pci->bdf.dev, pci->bdf.func); return 0xffff; } =20 @@ -512,7 +512,7 @@ static uint16_t sysfs_dev_get_device(libxl__gc *gc, lib= xl_device_pci *pci) { char *pci_device_device_path =3D GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/device", - pci->domain, pci->bus, pci->dev, pci->func); + pci->bdf.domain, pci->bdf.bus, pci->bdf.dev, pci->bd= f.func); uint16_t read_items; uint16_t pci_device_device; =20 @@ -520,7 +520,7 @@ static uint16_t sysfs_dev_get_device(libxl__gc *gc, lib= xl_device_pci *pci) if (!f) { LOGE(ERROR, "pci device "PCI_BDF" does not have device attribute", - pci->domain, pci->bus, pci->dev, pci->func); + pci->bdf.domain, pci->bdf.bus, pci->bdf.dev, pci->bdf.func); return 0xffff; } read_items =3D fscanf(f, "0x%hx\n", &pci_device_device); @@ -528,7 +528,7 @@ static uint16_t sysfs_dev_get_device(libxl__gc *gc, lib= xl_device_pci *pci) if (read_items !=3D 1) { LOGE(ERROR, "cannot read device of pci device "PCI_BDF, - pci->domain, pci->bus, pci->dev, pci->func); + pci->bdf.domain, pci->bdf.bus, pci->bdf.dev, pci->bdf.func); return 0xffff; } =20 @@ -539,14 +539,14 @@ static int sysfs_dev_get_class(libxl__gc *gc, libxl_d= evice_pci *pci, unsigned long *class) { char *pci_device_class_path =3D GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/cla= ss", - pci->domain, pci->bus, pci->dev, pci->func); + pci->bdf.domain, pci->bdf.bus, pci->bdf.dev, pci->bdf= .func); int read_items, ret =3D 0; =20 FILE *f =3D fopen(pci_device_class_path, "r"); if (!f) { LOGE(ERROR, "pci device "PCI_BDF" does not have class attribute", - pci->domain, pci->bus, pci->dev, pci->func); + pci->bdf.domain, pci->bdf.bus, pci->bdf.dev, pci->bdf.func); ret =3D ERROR_FAIL; goto out; } @@ -555,7 +555,7 @@ static int sysfs_dev_get_class(libxl__gc *gc, libxl_dev= ice_pci *pci, if (read_items !=3D 1) { LOGE(ERROR, "cannot read class of pci device "PCI_BDF, - pci->domain, pci->bus, pci->dev, pci->func); + pci->bdf.domain, pci->bdf.bus, pci->bdf.dev, pci->bdf.func); ret =3D ERROR_FAIL; } =20 @@ -622,10 +622,10 @@ static int pciback_dev_has_slot(libxl__gc *gc, libxl_= device_pci *pci) } =20 while (fscanf(f, "%x:%x:%x.%d\n", &dom, &bus, &dev, &func)=3D=3D4) { - if (dom =3D=3D pci->domain - && bus =3D=3D pci->bus - && dev =3D=3D pci->dev - && func =3D=3D pci->func) { + if (dom =3D=3D pci->bdf.domain + && bus =3D=3D pci->bdf.bus + && dev =3D=3D pci->bdf.dev + && func =3D=3D pci->bdf.func) { rc =3D 1; goto out; } @@ -651,8 +651,8 @@ static int pciback_dev_is_assigned(libxl__gc *gc, libxl= _device_pci *pci) } =20 spath =3D GCSPRINTF(SYSFS_PCIBACK_DRIVER"/"PCI_BDF, - pci->domain, pci->bus, - pci->dev, pci->func); + pci->bdf.domain, pci->bdf.bus, + pci->bdf.dev, pci->bdf.func); rc =3D lstat(spath, &st); =20 if( rc =3D=3D 0 ) @@ -715,10 +715,10 @@ static int libxl__device_pci_assignable_add(libxl__gc= *gc, struct stat st; =20 /* Local copy for convenience */ - dom =3D pci->domain; - bus =3D pci->bus; - dev =3D pci->dev; - func =3D pci->func; + dom =3D pci->bdf.domain; + bus =3D pci->bdf.bus; + dev =3D pci->bdf.dev; + func =3D pci->bdf.func; =20 /* See if the device exists */ spath =3D GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF, dom, bus, dev, func); @@ -792,8 +792,8 @@ static int libxl__device_pci_assignable_remove(libxl__g= c *gc, /* De-quarantine */ rc =3D xc_deassign_device(ctx->xch, DOMID_IO, pci_encode_bdf(pci)); if ( rc < 0 ) { - LOG(ERROR, "failed to de-quarantine "PCI_BDF, pci->domain, pci->bu= s, - pci->dev, pci->func); + LOG(ERROR, "failed to de-quarantine "PCI_BDF, pci->bdf.domain, pci= ->bdf.bus, + pci->bdf.dev, pci->bdf.func); return ERROR_FAIL; } =20 @@ -882,11 +882,11 @@ static int pci_multifunction_check(libxl__gc *gc, lib= xl_device_pci *pci, unsigne =20 if ( sscanf(de->d_name, PCI_BDF, &dom, &bus, &dev, &func) !=3D 4 ) continue; - if ( pci->domain !=3D dom ) + if ( pci->bdf.domain !=3D dom ) continue; - if ( pci->bus !=3D bus ) + if ( pci->bdf.bus !=3D bus ) continue; - if ( pci->dev !=3D dev ) + if ( pci->bdf.dev !=3D dev ) continue; =20 path =3D GCSPRINTF("%s/" PCI_BDF, SYSFS_PCIBACK_DRIVER, dom, bus, = dev, func); @@ -935,13 +935,13 @@ static int qemu_pci_add_xenstore(libxl__gc *gc, uint3= 2_t domid, path =3D DEVICE_MODEL_XS_PATH(gc, dm_domid, domid, "/parameter"); if (pci->vdevfn) { libxl__xs_printf(gc, XBT_NULL, path, PCI_BDF_VDEVFN","PCI_OPTIONS, - pci->domain, pci->bus, pci->dev, - pci->func, pci->vdevfn, pci->msitranslate, + pci->bdf.domain, pci->bdf.bus, pci->bdf.dev, + pci->bdf.func, pci->vdevfn, pci->msitranslate, pci->power_mgmt); } else { libxl__xs_printf(gc, XBT_NULL, path, PCI_BDF","PCI_OPTIONS, - pci->domain, pci->bus, pci->dev, - pci->func, pci->msitranslate, pci->power_mgmt); + pci->bdf.domain, pci->bdf.bus, pci->bdf.dev, + pci->bdf.func, pci->msitranslate, pci->power_mgmt= ); } =20 libxl__qemu_traditional_cmd(gc, domid, "pci-ins"); @@ -1100,10 +1100,10 @@ static void pci_add_qmp_device_add(libxl__egc *egc,= pci_add_state *pas) libxl__qmp_param_add_string(gc, &args, "driver", "xen-pci-passthrough"); QMP_PARAMETERS_SPRINTF(&args, "id", PCI_PT_QDEV_ID, - pci->bus, pci->dev, pci->func); + pci->bdf.bus, pci->bdf.dev, pci->bdf.func); QMP_PARAMETERS_SPRINTF(&args, "hostaddr", - "%04x:%02x:%02x.%01x", pci->domain, - pci->bus, pci->dev, pci->func); + "%04x:%02x:%02x.%01x", pci->bdf.domain, + pci->bdf.bus, pci->bdf.dev, pci->bdf.func); if (pci->vdevfn) { QMP_PARAMETERS_SPRINTF(&args, "addr", "%x.%x", PCI_SLOT(pci->vdevfn), @@ -1191,7 +1191,7 @@ static void pci_add_qmp_query_pci_cb(libxl__egc *egc, */ =20 asked_id =3D GCSPRINTF(PCI_PT_QDEV_ID, - pci->bus, pci->dev, pci->func); + pci->bdf.bus, pci->bdf.dev, pci->bdf.func); =20 for (i =3D 0; (bus =3D libxl__json_array_get(response, i)); i++) { devices =3D libxl__json_map_get("devices", bus, JSON_ARRAY); @@ -1281,8 +1281,8 @@ static void pci_add_dm_done(libxl__egc *egc, if (isstubdom) starting =3D false; =20 - sysfs_path =3D GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/resource", pci->doma= in, - pci->bus, pci->dev, pci->func); + sysfs_path =3D GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/resource", pci->bdf.= domain, + pci->bdf.bus, pci->bdf.dev, pci->bdf.func); f =3D fopen(sysfs_path, "r"); start =3D end =3D flags =3D size =3D 0; irq =3D 0; @@ -1322,8 +1322,8 @@ static void pci_add_dm_done(libxl__egc *egc, } } fclose(f); - sysfs_path =3D GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/irq", pci->domain, - pci->bus, pci->dev, pci->func); + sysfs_path =3D GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/irq", pci->bdf.domai= n, + pci->bdf.bus, pci->bdf.dev, pci->bdf.func); f =3D fopen(sysfs_path, "r"); if (f =3D=3D NULL) { LOGED(ERROR, domid, "Couldn't open %s", sysfs_path); @@ -1494,7 +1494,7 @@ void libxl__device_pci_add(libxl__egc *egc, uint32_t = domid, if (rc) { LOGD(ERROR, domid, "PCI device %04x:%02x:%02x.%u %s?", - pci->domain, pci->bus, pci->dev, pci->func, + pci->bdf.domain, pci->bdf.bus, pci->bdf.dev, pci->bdf.fun= c, errno =3D=3D EOPNOTSUPP ? "cannot be assigned - no IOMMU" : "already assigned to a different guest"); goto out; @@ -1512,7 +1512,7 @@ void libxl__device_pci_add(libxl__egc *egc, uint32_t = domid, =20 if (!libxl_pci_assignable(ctx, pci)) { LOGD(ERROR, domid, "PCI device %x:%x:%x.%x is not assignable", - pci->domain, pci->bus, pci->dev, pci->func); + pci->bdf.domain, pci->bdf.bus, pci->bdf.dev, pci->bdf.func); rc =3D ERROR_FAIL; goto out; } @@ -1520,7 +1520,7 @@ void libxl__device_pci_add(libxl__egc *egc, uint32_t = domid, rc =3D pci_info_xs_write(gc, pci, "domid", GCSPRINTF("%u", domid)); if (rc) goto out; =20 - libxl__device_pci_reset(gc, pci->domain, pci->bus, pci->dev, pci->func= ); + libxl__device_pci_reset(gc, pci->bdf.domain, pci->bdf.bus, pci->bdf.de= v, pci->bdf.func); =20 stubdomid =3D libxl_get_stubdom_id(ctx, domid); if (stubdomid !=3D 0) { @@ -1601,13 +1601,13 @@ static void device_pci_add_stubdom_done(libxl__egc = *egc, pci->vfunc_mask &=3D pfunc_mask; /* so now vfunc_mask =3D=3D pfunc_mask */ }else{ - pfunc_mask =3D (1 << pci->func); + pfunc_mask =3D (1 << pci->bdf.func); } =20 for (rc =3D 0, i =3D 7; i >=3D 0; --i) { if ( (1 << i) & pfunc_mask ) { if ( pci->vfunc_mask =3D=3D pfunc_mask ) { - pci->func =3D i; + pci->bdf.func =3D i; pci->vdevfn =3D orig_vdev | i; } else { /* if not passing through multiple devices in a block make @@ -1639,7 +1639,7 @@ static void device_pci_add_done(libxl__egc *egc, LOGD(ERROR, domid, "libxl__device_pci_add failed for " "PCI device %x:%x:%x.%x (rc %d)", - pci->domain, pci->bus, pci->dev, pci->func, + pci->bdf.domain, pci->bdf.bus, pci->bdf.dev, pci->bdf.func, rc); pci_info_xs_remove(gc, pci, "domid"); } @@ -1739,8 +1739,8 @@ static int qemu_pci_remove_xenstore(libxl__gc *gc, ui= nt32_t domid, path =3D DEVICE_MODEL_XS_PATH(gc, dm_domid, domid, "/state"); state =3D libxl__xs_read(gc, XBT_NULL, path); path =3D DEVICE_MODEL_XS_PATH(gc, dm_domid, domid, "/parameter"); - libxl__xs_printf(gc, XBT_NULL, path, PCI_BDF, pci->domain, - pci->bus, pci->dev, pci->func); + libxl__xs_printf(gc, XBT_NULL, path, PCI_BDF, pci->bdf.domain, + pci->bdf.bus, pci->bdf.dev, pci->bdf.func); =20 /* Remove all functions at once atomically by only signalling * device-model for function 0 */ @@ -1853,8 +1853,8 @@ static void do_pci_remove(libxl__egc *egc, pci_remove= _state *prs) } else { assert(type =3D=3D LIBXL_DOMAIN_TYPE_PV); =20 - char *sysfs_path =3D GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/resource",= pci->domain, - pci->bus, pci->dev, pci->func); + char *sysfs_path =3D GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/resource",= pci->bdf.domain, + pci->bdf.bus, pci->bdf.dev, pci->bdf.= func); FILE *f =3D fopen(sysfs_path, "r"); unsigned int start =3D 0, end =3D 0, flags =3D 0, size =3D 0; int irq =3D 0; @@ -1889,8 +1889,8 @@ static void do_pci_remove(libxl__egc *egc, pci_remove= _state *prs) } fclose(f); skip1: - sysfs_path =3D GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/irq", pci->domai= n, - pci->bus, pci->dev, pci->func); + sysfs_path =3D GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/irq", pci->bdf.d= omain, + pci->bdf.bus, pci->bdf.dev, pci->bdf.func); f =3D fopen(sysfs_path, "r"); if (f =3D=3D NULL) { LOGED(ERROR, domid, "Couldn't open %s", sysfs_path); @@ -1954,7 +1954,7 @@ static void pci_remove_qmp_device_del(libxl__egc *egc, if (rc) goto out; =20 QMP_PARAMETERS_SPRINTF(&args, "id", PCI_PT_QDEV_ID, - pci->bus, pci->dev, pci->func); + pci->bdf.bus, pci->bdf.dev, pci->bdf.func); prs->qmp.callback =3D pci_remove_qmp_device_del_cb; rc =3D libxl__ev_qmp_send(egc, &prs->qmp, "device_del", args); if (rc) goto out; @@ -2023,7 +2023,7 @@ static void pci_remove_qmp_query_cb(libxl__egc *egc, libxl__ev_qmp_dispose(gc, qmp); =20 asked_id =3D GCSPRINTF(PCI_PT_QDEV_ID, - pci->bus, pci->dev, pci->func); + pci->bdf.bus, pci->bdf.dev, pci->bdf.func); =20 /* query-pci response: * [{ 'devices': [ 'qdev_id': 'str', ... ], ... }] @@ -2074,7 +2074,7 @@ static void pci_remove_timeout(libxl__egc *egc, libxl= __ev_time *ev, libxl_device_pci *const pci =3D &prs->pci; =20 LOGD(WARN, prs->domid, "timed out waiting for DM to remove " - PCI_PT_QDEV_ID, pci->bus, pci->dev, pci->func); + PCI_PT_QDEV_ID, pci->bdf.bus, pci->bdf.dev, pci->bdf.func); =20 /* If we timed out, we might still want to keep destroying the device * (when force=3D=3Dtrue), so let the next function decide what to do = on @@ -2106,7 +2106,7 @@ static void pci_remove_detached(libxl__egc *egc, =20 /* don't do multiple resets while some functions are still passed thro= ugh */ if ((pci->vdevfn & 0x7) =3D=3D 0) { - libxl__device_pci_reset(gc, pci->domain, pci->bus, pci->dev, pci->= func); + libxl__device_pci_reset(gc, pci->bdf.domain, pci->bdf.bus, pci->bd= f.dev, pci->bdf.func); } =20 if (!isstubdom) { @@ -2194,7 +2194,7 @@ static void libxl__device_pci_remove_common(libxl__eg= c *egc, } pci->vfunc_mask &=3D prs->pfunc_mask; } else { - prs->pfunc_mask =3D (1 << pci->func); + prs->pfunc_mask =3D (1 << pci->bdf.func); } =20 rc =3D 0; @@ -2222,7 +2222,7 @@ static void device_pci_remove_common_next(libxl__egc = *egc, prs->next_func--; if ( (1 << i) & pfunc_mask ) { if ( pci->vfunc_mask =3D=3D pfunc_mask ) { - pci->func =3D i; + pci->bdf.func =3D i; pci->vdevfn =3D orig_vdev | i; } else { pci->vdevfn =3D orig_vdev; diff --git a/tools/libs/light/libxl_types.idl b/tools/libs/light/libxl_type= s.idl index 20f8dd7cfa..2c441142fb 100644 --- a/tools/libs/light/libxl_types.idl +++ b/tools/libs/light/libxl_types.idl @@ -769,18 +769,22 @@ libxl_device_nic =3D Struct("device_nic", [ ("colo_checkpoint_port", string) ]) =20 +libxl_pci_bdf =3D Struct("pci_bdf", [ + ("func", uint8), + ("dev", uint8), + ("bus", uint8), + ("domain", integer), + ]) + libxl_device_pci =3D Struct("device_pci", [ - ("func", uint8), - ("dev", uint8), - ("bus", uint8), - ("domain", integer), - ("vdevfn", uint32), + ("bdf", libxl_pci_bdf), + ("vdevfn", uint32), ("vfunc_mask", uint32), ("msitranslate", bool), ("power_mgmt", bool), ("permissive", bool), ("seize", bool), - ("rdm_policy", libxl_rdm_reserve_policy), + ("rdm_policy", libxl_rdm_reserve_policy), ]) =20 libxl_device_rdm =3D Struct("device_rdm", [ diff --git a/tools/libs/util/libxlu_pci.c b/tools/libs/util/libxlu_pci.c index 1d38fffce3..5c107f2642 100644 --- a/tools/libs/util/libxlu_pci.c +++ b/tools/libs/util/libxlu_pci.c @@ -27,10 +27,10 @@ static int pci_struct_fill(libxl_device_pci *pci, unsig= ned int domain, unsigned int bus, unsigned int dev, unsigned int func, unsigned int vdevfn) { - pci->domain =3D domain; - pci->bus =3D bus; - pci->dev =3D dev; - pci->func =3D func; + pci->bdf.domain =3D domain; + pci->bdf.bus =3D bus; + pci->bdf.dev =3D dev; + pci->bdf.func =3D func; pci->vdevfn =3D vdevfn; return 0; } diff --git a/tools/xl/xl_pci.c b/tools/xl/xl_pci.c index f71498cbb5..b6dc7c2840 100644 --- a/tools/xl/xl_pci.c +++ b/tools/xl/xl_pci.c @@ -34,7 +34,8 @@ static void pcilist(uint32_t domid) for (i =3D 0; i < num; i++) { printf("%02x.%01x %04x:%02x:%02x.%01x\n", (pcis[i].vdevfn >> 3) & 0x1f, pcis[i].vdevfn & 0x7, - pcis[i].domain, pcis[i].bus, pcis[i].dev, pcis[i].func); + pcis[i].bdf.domain, pcis[i].bdf.bus, pcis[i].bdf.dev, + pcis[i].bdf.func); } libxl_device_pci_list_free(pcis, num); } @@ -163,7 +164,8 @@ static void pciassignable_list(void) return; for (i =3D 0; i < num; i++) { printf("%04x:%02x:%02x.%01x\n", - pcis[i].domain, pcis[i].bus, pcis[i].dev, pcis[i].func); + pcis[i].bdf.domain, pcis[i].bdf.bus, pcis[i].bdf.dev, + pcis[i].bdf.func); } libxl_device_pci_assignable_list_free(pcis, num); } diff --git a/tools/xl/xl_sxp.c b/tools/xl/xl_sxp.c index b03e348ffb..95180b60df 100644 --- a/tools/xl/xl_sxp.c +++ b/tools/xl/xl_sxp.c @@ -194,8 +194,8 @@ void printf_info_sexp(int domid, libxl_domain_config *d= _config, FILE *fh) fprintf(fh, "\t(device\n"); fprintf(fh, "\t\t(pci\n"); fprintf(fh, "\t\t\t(pci dev %04x:%02x:%02x.%01x@%02x)\n", - d_config->pcis[i].domain, d_config->pcis[i].bus, - d_config->pcis[i].dev, d_config->pcis[i].func, + d_config->pcis[i].bdf.domain, d_config->pcis[i].bdf.bus, + d_config->pcis[i].bdf.dev, d_config->pcis[i].bdf.func, d_config->pcis[i].vdevfn); fprintf(fh, "\t\t\t(opts msitranslate %d power_mgmt %d)\n", d_config->pcis[i].msitranslate, --=20 2.11.0 From nobody Sun May 5 11:10:29 2024 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=1603470419; cv=none; d=zohomail.com; s=zohoarc; b=EoDyM4tTydXD4mAt9VetsLUNJdpcPXvHwqIdG1y1nPpbpiPPmX9LGe0sMDkUFTTZP9brkBovyzD/ZxJuwNLn0SBH2jeBwgS3Rv8hoxl/tTUT3Whlp+RtWh++XZhbCAUJj/eSqWn6YtoeAm1XODXZpB1hJhhJOuSgyo+Jl6WFyLo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603470419; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=FS2lsRq/N5rr0lREQKsZJxqwgY3o2rJbmA8WgHHgsnw=; b=DcEgpDIbHDzXDl2YQdpNnzJYCT5eYy52kFevbsaU20fXtcXutAKbiiOEUsYaKlBQC7A+KJ40v5NQVflbgSsxVqwxQZ9+gUYWbvNC4qltIZoTySIovIZ4NkdQw6silOreYb1UT1/l/pfOj2giQkBK/2m8K1qT7kVUTRqrKhHx0Hw= 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 1603470419579237.64242092338247; Fri, 23 Oct 2020 09:26:59 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.11206.29771 (Exim 4.92) (envelope-from ) id 1kVztn-0001Ii-Te; Fri, 23 Oct 2020 16:26:39 +0000 Received: by outflank-mailman (output) from mailman id 11206.29771; Fri, 23 Oct 2020 16:26:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztn-0001II-Lp; Fri, 23 Oct 2020 16:26:39 +0000 Received: by outflank-mailman (input) for mailman id 11206; Fri, 23 Oct 2020 16:26:37 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztl-0000v3-I5 for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:26:37 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 0d198a79-1aba-45cd-874b-371bd5d50ab7; Fri, 23 Oct 2020 16:26:22 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztV-0008OE-9E; Fri, 23 Oct 2020 16:26:21 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqr-000376-3d; Fri, 23 Oct 2020 16:23:37 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztl-0000v3-I5 for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:26:37 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 0d198a79-1aba-45cd-874b-371bd5d50ab7; Fri, 23 Oct 2020 16:26:22 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztV-0008OE-9E; Fri, 23 Oct 2020 16:26:21 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqr-000376-3d; Fri, 23 Oct 2020 16:23:37 +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" X-Inumbo-ID: 0d198a79-1aba-45cd-874b-371bd5d50ab7 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=FS2lsRq/N5rr0lREQKsZJxqwgY3o2rJbmA8WgHHgsnw=; b=2+w1u1cHA7vnNQpXElGGIByv+ yYiZwwKzcVmCuheAhZgrcCY3UVXQDufQD5+4a0ijPnDc6KGr8N2EksnWk9343oAPveZQAVsLxgIJ9 5eqVu3WDTzy/FM2dCHnb9BqqiBY0R6wAGm/HIE/tV+Lp8SGIs982y4dHnK+mAohz/r55A=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH 20/25] libxlu: introduce xlu_pci_parse_spec_string() Date: Fri, 23 Oct 2020 16:23:09 +0000 Message-Id: <20201023162314.2235-21-paul@xen.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20201023162314.2235-1-paul@xen.org> References: <20201023162314.2235-1-paul@xen.org> X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paul Durrant This patch largely re-writes the code to parse a PCI_SPEC_STRING and enters it via the newly introduced function. The new parser also deals with 'bdf' and 'vslot' as non-positional paramaters, as per the documentation in xl-pci-configuration(5). The existing xlu_pci_parse_bdf() function remains, but now strictly parses BDF values. Some existing callers of xlu_pci_parse_bdf() are modified to call xlu_pci_parse_spec_string() as per the documentation in xl= (1). NOTE: Usage text in xl_cmdtable.c and error messages are also modified appropriately. Fixes: d25cc3ec93eb ("libxl: workaround gcc 10.2 maybe-uninitialized warnin= g") Signed-off-by: Paul Durrant Acked-by: Christian Lindig --- Cc: Ian Jackson Cc: Wei Liu Cc: Anthony PERARD --- tools/include/libxlutil.h | 8 +- tools/libs/util/libxlu_pci.c | 354 +++++++++++++++++++++++----------------= ---- tools/xl/xl_cmdtable.c | 4 +- tools/xl/xl_parse.c | 4 +- tools/xl/xl_pci.c | 37 +++-- 5 files changed, 220 insertions(+), 187 deletions(-) diff --git a/tools/include/libxlutil.h b/tools/include/libxlutil.h index 92e35c5462..cdd6aab4f8 100644 --- a/tools/include/libxlutil.h +++ b/tools/include/libxlutil.h @@ -109,9 +109,15 @@ int xlu_disk_parse(XLU_Config *cfg, int nspecs, const = char *const *specs, */ =20 /* + * PCI BDF + */ +int xlu_pci_parse_bdf(XLU_Config *cfg, libxl_pci_bdf *bdf, const char *str= ); + +/* * PCI specification parsing */ -int xlu_pci_parse_bdf(XLU_Config *cfg, libxl_device_pci *pcidev, const cha= r *str); +int xlu_pci_parse_spec_string(XLU_Config *cfg, libxl_device_pci *pci, + const char *str); =20 /* * RDM parsing diff --git a/tools/libs/util/libxlu_pci.c b/tools/libs/util/libxlu_pci.c index 5c107f2642..a8b6ce5427 100644 --- a/tools/libs/util/libxlu_pci.c +++ b/tools/libs/util/libxlu_pci.c @@ -1,5 +1,7 @@ #define _GNU_SOURCE =20 +#include + #include "libxlu_internal.h" #include "libxlu_disk_l.h" #include "libxlu_disk_i.h" @@ -9,185 +11,213 @@ #define XLU__PCI_ERR(_c, _x, _a...) \ if((_c) && (_c)->report) fprintf((_c)->report, _x, ##_a) =20 -static int hex_convert(const char *str, unsigned int *val, unsigned int ma= sk) +static int parse_bdf(libxl_pci_bdf *bdfp, uint32_t *vfunc_maskp, + const char *str, const char **endp) { - unsigned long ret; - char *end; - - ret =3D strtoul(str, &end, 16); - if ( end =3D=3D str || *end !=3D '\0' ) - return -1; - if ( ret & ~mask ) - return -1; - *val =3D (unsigned int)ret & mask; + const char *ptr =3D str; + unsigned int colons =3D 0; + unsigned int domain, bus, dev, func; + int n; + + /* Count occurrences of ':' to detrmine presence/absence of the 'domai= n' */ + while (isxdigit(*ptr) || *ptr =3D=3D ':') { + if (*ptr =3D=3D ':') + colons++; + ptr++; + } + + ptr =3D str; + switch (colons) { + case 1: + domain =3D 0; + if (sscanf(ptr, "%x:%x.%n", &bus, &dev, &n) !=3D 2) + return ERROR_INVAL; + break; + case 2: + if (sscanf(ptr, "%x:%x:%x.%n", &domain, &bus, &dev, &n) !=3D 3) + return ERROR_INVAL; + break; + default: + return ERROR_INVAL; + } + + if (domain > 0xffff || bus > 0xff || dev > 0x1f) + return ERROR_INVAL; + + ptr +=3D n; + if (*ptr =3D=3D '*') { + if (!vfunc_maskp) + return ERROR_INVAL; + *vfunc_maskp =3D LIBXL_PCI_FUNC_ALL; + func =3D 0; + ptr++; + } else { + if (sscanf(ptr, "%x%n", &func, &n) !=3D 1) + return ERROR_INVAL; + if (func > 7) + return ERROR_INVAL; + if (vfunc_maskp) + *vfunc_maskp =3D 1; + ptr +=3D n; + } + + bdfp->domain =3D domain; + bdfp->bus =3D bus; + bdfp->dev =3D dev; + bdfp->func =3D func; + + if (endp) + *endp =3D ptr; + return 0; } =20 -static int pci_struct_fill(libxl_device_pci *pci, unsigned int domain, - unsigned int bus, unsigned int dev, - unsigned int func, unsigned int vdevfn) +static int parse_vslot(uint32_t *vdevfnp, const char *str, const char **en= dp) { - pci->bdf.domain =3D domain; - pci->bdf.bus =3D bus; - pci->bdf.dev =3D dev; - pci->bdf.func =3D func; - pci->vdevfn =3D vdevfn; + const char *ptr =3D str; + unsigned int val; + int n; + + if (sscanf(ptr, "%x%n", &val, &n) !=3D 1) + return ERROR_INVAL; + + if (val > 0x1f) + return ERROR_INVAL; + + ptr +=3D n; + + *vdevfnp =3D val << 3; + + if (endp) + *endp =3D ptr; + return 0; } =20 -#define STATE_DOMAIN 0 -#define STATE_BUS 1 -#define STATE_DEV 2 -#define STATE_FUNC 3 -#define STATE_VSLOT 4 -#define STATE_OPTIONS_K 6 -#define STATE_OPTIONS_V 7 -#define STATE_TERMINAL 8 -#define STATE_TYPE 9 -#define STATE_RDM_STRATEGY 10 -#define STATE_RESERVE_POLICY 11 -#define INVALID 0xffffffff -int xlu_pci_parse_bdf(XLU_Config *cfg, libxl_device_pci *pci, const char *= str) +static int parse_key_val(char **keyp, char**valp, const char *str, + const char **endp) { - unsigned state =3D STATE_DOMAIN; - unsigned dom =3D INVALID, bus =3D INVALID, dev =3D INVALID, func =3D I= NVALID, vslot =3D 0; - char *buf2, *tok, *ptr, *end, *optkey =3D NULL; + const char *ptr =3D str; + char *key, *val; + + while (*ptr !=3D '=3D' && *ptr !=3D '\0') + ptr++; =20 - if ( NULL =3D=3D (buf2 =3D ptr =3D strdup(str)) ) + if (*ptr =3D=3D '\0') + return ERROR_INVAL; + + key =3D strndup(str, ptr - str); + if (!key) return ERROR_NOMEM; =20 - for(tok =3D ptr, end =3D ptr + strlen(ptr) + 1; ptr < end; ptr++) { - switch(state) { - case STATE_DOMAIN: - if ( *ptr =3D=3D ':' ) { - state =3D STATE_BUS; - *ptr =3D '\0'; - if ( hex_convert(tok, &dom, 0xffff) ) - goto parse_error; - tok =3D ptr + 1; - } - break; - case STATE_BUS: - if ( *ptr =3D=3D ':' ) { - state =3D STATE_DEV; - *ptr =3D '\0'; - if ( hex_convert(tok, &bus, 0xff) ) - goto parse_error; - tok =3D ptr + 1; - }else if ( *ptr =3D=3D '.' ) { - state =3D STATE_FUNC; - *ptr =3D '\0'; - if ( dom & ~0xff ) - goto parse_error; - bus =3D dom; - dom =3D 0; - if ( hex_convert(tok, &dev, 0xff) ) - goto parse_error; - tok =3D ptr + 1; - } - break; - case STATE_DEV: - if ( *ptr =3D=3D '.' ) { - state =3D STATE_FUNC; - *ptr =3D '\0'; - if ( hex_convert(tok, &dev, 0xff) ) - goto parse_error; - tok =3D ptr + 1; - } - break; - case STATE_FUNC: - if ( *ptr =3D=3D '\0' || *ptr =3D=3D '@' || *ptr =3D=3D ',' ) { - switch( *ptr ) { - case '\0': - state =3D STATE_TERMINAL; - break; - case '@': - state =3D STATE_VSLOT; - break; - case ',': - state =3D STATE_OPTIONS_K; - break; - } - *ptr =3D '\0'; - if ( !strcmp(tok, "*") ) { - pci->vfunc_mask =3D LIBXL_PCI_FUNC_ALL; - }else{ - if ( hex_convert(tok, &func, 0x7) ) - goto parse_error; - pci->vfunc_mask =3D (1 << 0); - } - tok =3D ptr + 1; - } - break; - case STATE_VSLOT: - if ( *ptr =3D=3D '\0' || *ptr =3D=3D ',' ) { - state =3D ( *ptr =3D=3D ',' ) ? STATE_OPTIONS_K : STATE_TE= RMINAL; - *ptr =3D '\0'; - if ( hex_convert(tok, &vslot, 0xff) ) - goto parse_error; - tok =3D ptr + 1; - } - break; - case STATE_OPTIONS_K: - if ( *ptr =3D=3D '=3D' ) { - state =3D STATE_OPTIONS_V; - *ptr =3D '\0'; - optkey =3D tok; - tok =3D ptr + 1; - } - break; - case STATE_OPTIONS_V: - if ( *ptr =3D=3D ',' || *ptr =3D=3D '\0' ) { - state =3D (*ptr =3D=3D ',') ? STATE_OPTIONS_K : STATE_TERM= INAL; - *ptr =3D '\0'; - if ( !strcmp(optkey, "msitranslate") ) { - pci->msitranslate =3D atoi(tok); - }else if ( !strcmp(optkey, "power_mgmt") ) { - pci->power_mgmt =3D atoi(tok); - }else if ( !strcmp(optkey, "permissive") ) { - pci->permissive =3D atoi(tok); - }else if ( !strcmp(optkey, "seize") ) { - pci->seize =3D atoi(tok); - } else if (!strcmp(optkey, "rdm_policy")) { - if (!strcmp(tok, "strict")) { - pci->rdm_policy =3D LIBXL_RDM_RESERVE_POLICY_STRIC= T; - } else if (!strcmp(tok, "relaxed")) { - pci->rdm_policy =3D LIBXL_RDM_RESERVE_POLICY_RELAX= ED; - } else { - XLU__PCI_ERR(cfg, "%s is not an valid PCI RDM prop= erty" - " policy: 'strict' or 'relaxed'.= ", - tok); - goto parse_error; - } - } else { - XLU__PCI_ERR(cfg, "Unknown PCI BDF option: %s", optkey= ); - } - tok =3D ptr + 1; - } - default: - break; + str =3D ++ptr; /* skip '=3D' */ + while (*ptr !=3D ',' && *ptr !=3D '\0') + ptr++; + + val =3D strndup(str, ptr - str); + if (!val) { + free(key); + return ERROR_NOMEM; + } + + if (*ptr =3D=3D ',') + ptr++; + + *keyp =3D key; + *valp =3D val; + *endp =3D ptr; + + return 0; +} + +static int parse_rdm_policy(XLU_Config *cfg, libxl_rdm_reserve_policy *pol= icy, + const char *str) +{ + int ret =3D libxl_rdm_reserve_policy_from_string(str, policy); + + if (ret) + XLU__PCI_ERR(cfg, "Unknown RDM policy: %s", str); + + return ret; +} + +int xlu_pci_parse_bdf(XLU_Config *cfg, libxl_pci_bdf *bdf, const char *str) +{ + return parse_bdf(bdf, NULL, str, NULL); +} + +int xlu_pci_parse_spec_string(XLU_Config *cfg, libxl_device_pci *pcidev, + const char *str) +{ + const char *ptr =3D str; + bool bdf_present =3D false; + int ret; + + /* Attempt to parse 'bdf' as positional parameter */ + ret =3D parse_bdf(&pcidev->bdf, &pcidev->vfunc_mask, ptr, &ptr); + if (!ret) { + bdf_present =3D true; + + /* Check whether 'vslot' if present */ + if (*ptr =3D=3D '@') { + ret =3D parse_vslot(&pcidev->vdevfn, ++ptr, &ptr); + if (ret) + return ret; } + if (*ptr =3D=3D ',') + ptr++; + else if (*ptr !=3D '\0') + return ERROR_INVAL; } =20 - if ( tok !=3D ptr || state !=3D STATE_TERMINAL ) - goto parse_error; + /* Parse the rest as 'key=3Dval' pairs */ + while (*ptr !=3D '\0') { + char *key, *val; =20 - assert(dom !=3D INVALID && bus !=3D INVALID && dev !=3D INVALID && fun= c !=3D INVALID); + ret =3D parse_key_val(&key, &val, ptr, &ptr); + if (ret) + return ret; =20 - /* Just a pretty way to fill in the values */ - pci_struct_fill(pci, dom, bus, dev, func, vslot << 3); + if (!strcmp(key, "bdf")) { + ret =3D parse_bdf(&pcidev->bdf, &pcidev->vfunc_mask, val, NULL= ); + bdf_present =3D !ret; + } else if (!strcmp(key, "vslot")) { + ret =3D parse_vslot(&pcidev->vdevfn, val, NULL); + } else if (!strcmp(key, "permissive")) { + pcidev->permissive =3D atoi(val); + } else if (!strcmp(key, "msitranslate")) { + pcidev->msitranslate =3D atoi(val); + } else if (!strcmp(key, "seize")) { + pcidev->seize=3D atoi(val); + } else if (!strcmp(key, "power_mgmt")) { + pcidev->power_mgmt =3D atoi(val); + } else if (!strcmp(key, "rdm_policy")) { + ret =3D parse_rdm_policy(cfg, &pcidev->rdm_policy, val); + } else { + XLU__PCI_ERR(cfg, "Unknown PCI_SPEC_STRING option: %s", key); + ret =3D ERROR_INVAL; + } =20 - free(buf2); + free(key); + free(val); =20 - return 0; + if (ret) + return ret; + } =20 -parse_error: - free(buf2); - return ERROR_INVAL; + if (!bdf_present) + return ERROR_INVAL; + + return 0; } =20 int xlu_rdm_parse(XLU_Config *cfg, libxl_rdm_reserve *rdm, const char *str) { +#define STATE_TYPE 0 +#define STATE_RDM_STRATEGY 1 +#define STATE_RESERVE_POLICY 2 +#define STATE_TERMINAL 3 + unsigned state =3D STATE_TYPE; char *buf2, *tok, *ptr, *end; =20 @@ -227,15 +257,8 @@ int xlu_rdm_parse(XLU_Config *cfg, libxl_rdm_reserve *= rdm, const char *str) if (*ptr =3D=3D ',' || *ptr =3D=3D '\0') { state =3D *ptr =3D=3D ',' ? STATE_TYPE : STATE_TERMINAL; *ptr =3D '\0'; - if (!strcmp(tok, "strict")) { - rdm->policy =3D LIBXL_RDM_RESERVE_POLICY_STRICT; - } else if (!strcmp(tok, "relaxed")) { - rdm->policy =3D LIBXL_RDM_RESERVE_POLICY_RELAXED; - } else { - XLU__PCI_ERR(cfg, "Unknown RDM property policy value: = %s", - tok); + if (!parse_rdm_policy(cfg, &rdm->policy, tok)) goto parse_error; - } tok =3D ptr + 1; } default: @@ -253,6 +276,11 @@ int xlu_rdm_parse(XLU_Config *cfg, libxl_rdm_reserve *= rdm, const char *str) parse_error: free(buf2); return ERROR_INVAL; + +#undef STATE_TYPE +#undef STATE_RDM_STRATEGY +#undef STATE_RESERVE_POLICY +#undef STATE_TERMINAL } =20 /* diff --git a/tools/xl/xl_cmdtable.c b/tools/xl/xl_cmdtable.c index 7da6c1b927..2ee0c49673 100644 --- a/tools/xl/xl_cmdtable.c +++ b/tools/xl/xl_cmdtable.c @@ -90,12 +90,12 @@ struct cmd_spec cmd_table[] =3D { { "pci-attach", &main_pciattach, 0, 1, "Insert a new pass-through pci device", - " [Virtual Slot]", + " ", }, { "pci-detach", &main_pcidetach, 0, 1, "Remove a domain's pass-through pci device", - " ", + " ", }, { "pci-list", &main_pcilist, 0, 0, diff --git a/tools/xl/xl_parse.c b/tools/xl/xl_parse.c index 0765780d9f..6a4703e745 100644 --- a/tools/xl/xl_parse.c +++ b/tools/xl/xl_parse.c @@ -1487,10 +1487,10 @@ void parse_config_data(const char *config_source, * the global policy by default. */ pci->rdm_policy =3D b_info->u.hvm.rdm.policy; - e =3D xlu_pci_parse_bdf(config, pci, buf); + e =3D xlu_pci_parse_spec_string(config, pci, buf); if (e) { fprintf(stderr, - "unable to parse PCI BDF `%s' for passthrough\n", + "unable to parse PCI_SPEC_STRING `%s' for passthro= ugh\n", buf); exit(-e); } diff --git a/tools/xl/xl_pci.c b/tools/xl/xl_pci.c index b6dc7c2840..9c24496cb2 100644 --- a/tools/xl/xl_pci.c +++ b/tools/xl/xl_pci.c @@ -55,7 +55,7 @@ int main_pcilist(int argc, char **argv) return 0; } =20 -static int pcidetach(uint32_t domid, const char *bdf, int force) +static int pcidetach(uint32_t domid, const char *spec_string, int force) { libxl_device_pci pci; XLU_Config *config; @@ -66,8 +66,9 @@ static int pcidetach(uint32_t domid, const char *bdf, int= force) config =3D xlu_cfg_init(stderr, "command line"); if (!config) { perror("xlu_cfg_inig"); exit(-1); } =20 - if (xlu_pci_parse_bdf(config, &pci, bdf)) { - fprintf(stderr, "pci-detach: malformed BDF specification \"%s\"\n"= , bdf); + if (xlu_pci_parse_spec_string(config, &pci, spec_string)) { + fprintf(stderr, "pci-detach: malformed PCI_SPEC_STRING \"%s\"\n", + spec_string); exit(2); } if (force) { @@ -89,7 +90,7 @@ int main_pcidetach(int argc, char **argv) uint32_t domid; int opt; int force =3D 0; - const char *bdf =3D NULL; + const char *spec_string =3D NULL; =20 SWITCH_FOREACH_OPT(opt, "f", NULL, "pci-detach", 2) { case 'f': @@ -98,15 +99,15 @@ int main_pcidetach(int argc, char **argv) } =20 domid =3D find_domain(argv[optind]); - bdf =3D argv[optind + 1]; + spec_string =3D argv[optind + 1]; =20 - if (pcidetach(domid, bdf, force)) + if (pcidetach(domid, spec_string, force)) return EXIT_FAILURE; =20 return EXIT_SUCCESS; } =20 -static int pciattach(uint32_t domid, const char *bdf, const char *vs) +static int pciattach(uint32_t domid, const char *spec_string) { libxl_device_pci pci; XLU_Config *config; @@ -117,8 +118,9 @@ static int pciattach(uint32_t domid, const char *bdf, c= onst char *vs) config =3D xlu_cfg_init(stderr, "command line"); if (!config) { perror("xlu_cfg_inig"); exit(-1); } =20 - if (xlu_pci_parse_bdf(config, &pci, bdf)) { - fprintf(stderr, "pci-attach: malformed BDF specification \"%s\"\n"= , bdf); + if (xlu_pci_parse_spec_string(config, &pci, spec_string)) { + fprintf(stderr, "pci-attach: malformed PCI_SPEC_STRING \"%s\"\n", + spec_string); exit(2); } =20 @@ -135,19 +137,16 @@ int main_pciattach(int argc, char **argv) { uint32_t domid; int opt; - const char *bdf =3D NULL, *vs =3D NULL; + const char *spec_string =3D NULL; =20 SWITCH_FOREACH_OPT(opt, "", NULL, "pci-attach", 2) { /* No options */ } =20 domid =3D find_domain(argv[optind]); - bdf =3D argv[optind + 1]; - - if (optind + 1 < argc) - vs =3D argv[optind + 2]; + spec_string =3D argv[optind + 1]; =20 - if (pciattach(domid, bdf, vs)) + if (pciattach(domid, spec_string)) return EXIT_FAILURE; =20 return EXIT_SUCCESS; @@ -193,8 +192,8 @@ static int pciassignable_add(const char *bdf, int rebin= d) config =3D xlu_cfg_init(stderr, "command line"); if (!config) { perror("xlu_cfg_init"); exit(-1); } =20 - if (xlu_pci_parse_bdf(config, &pci, bdf)) { - fprintf(stderr, "pci-assignable-add: malformed BDF specification \= "%s\"\n", bdf); + if (xlu_pci_parse_bdf(config, &pci.bdf, bdf)) { + fprintf(stderr, "pci-assignable-add: malformed BDF \"%s\"\n", bdf); exit(2); } =20 @@ -235,8 +234,8 @@ static int pciassignable_remove(const char *bdf, int re= bind) config =3D xlu_cfg_init(stderr, "command line"); if (!config) { perror("xlu_cfg_init"); exit(-1); } =20 - if (xlu_pci_parse_bdf(config, &pci, bdf)) { - fprintf(stderr, "pci-assignable-remove: malformed BDF specificatio= n \"%s\"\n", bdf); + if (xlu_pci_parse_bdf(config, &pci.bdf, bdf)) { + fprintf(stderr, "pci-assignable-remove: malformed BDF \"%s\"\n", b= df); exit(2); } =20 --=20 2.11.0 From nobody Sun May 5 11:10:29 2024 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=1603470434; cv=none; d=zohomail.com; s=zohoarc; b=A5YkPv0c0x0ZRDzbgGjaWDJcvrcjeRNU2lLlHsudFAmMtjbPua1v06kK1UGr5D4/xNQ8T6QUQvnkzkCdhg/eb+OGSJwFWSx8y6N8QuGW1Ki0hkgbpyC/gvJuKT0a7woZIf1VnM473kz6qsG53RcSwX2fyHFGUfJwMIoqAyfxW2E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603470434; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=OvopI12UbRrhQAhqN7hvDR3hBLZ7P1RnY9jfoW3jfa8=; b=PoPRiFfqlvUkHWmNUzOzA0mDuTnF7pIybgkcZltPy+5cYxxAdhX/XAxNNmZQnHJhhVby2/sndObZF8zj6aN8Gn8F7GxXpZKLOWJkc14nK8jsbkPoB3SON6kC1x6SxbaCCfcopuqPEq2TFm18jhWOnjX+iN65y1u5XGXEBu+Nejk= 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 1603470434312442.75978744785243; Fri, 23 Oct 2020 09:27:14 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.11215.29843 (Exim 4.92) (envelope-from ) id 1kVzu2-0001pG-L0; Fri, 23 Oct 2020 16:26:54 +0000 Received: by outflank-mailman (output) from mailman id 11215.29843; Fri, 23 Oct 2020 16:26:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzu2-0001op-92; Fri, 23 Oct 2020 16:26:54 +0000 Received: by outflank-mailman (input) for mailman id 11215; Fri, 23 Oct 2020 16:26:52 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzu0-0000v3-IR for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:26:52 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 7d654f5d-4e2a-4f1a-88ec-68c7ff500dd8; Fri, 23 Oct 2020 16:26:22 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztU-0008No-VR; Fri, 23 Oct 2020 16:26:20 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqs-000376-7I; Fri, 23 Oct 2020 16:23:38 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzu0-0000v3-IR for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:26:52 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 7d654f5d-4e2a-4f1a-88ec-68c7ff500dd8; Fri, 23 Oct 2020 16:26:22 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztU-0008No-VR; Fri, 23 Oct 2020 16:26:20 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqs-000376-7I; Fri, 23 Oct 2020 16:23:38 +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" X-Inumbo-ID: 7d654f5d-4e2a-4f1a-88ec-68c7ff500dd8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=OvopI12UbRrhQAhqN7hvDR3hBLZ7P1RnY9jfoW3jfa8=; b=vi73Ud6zHzB7KkLW/mCTovsm/ d8gb0T8FrD/00Tem41RHymTesctebKGvTjQ7GjOgbnKfY56yvK0lLRBmKtVavlRrRU3QdXZxVOs0H hWzRBBndV3AyTGzmRwI0ObRWfFm5hCmhOIhrbZHoFLC9ziIEbxMdbUxs9ZOIFPCUcYt0g=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson , Wei Liu , Christian Lindig , David Scott , Anthony PERARD Subject: [PATCH 21/25] libxl: modify libxl_device_pci_assignable_add/remove/list/list_free()... Date: Fri, 23 Oct 2020 16:23:10 +0000 Message-Id: <20201023162314.2235-22-paul@xen.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20201023162314.2235-1-paul@xen.org> References: <20201023162314.2235-1-paul@xen.org> X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paul Durrant ... to use 'libxl_pci_bdf' rather than 'libxl_device_pci'. This patch modifies the API and callers accordingly. It also modifies several internal functions in libxl_pci.c that support the API to also use 'libxl_pci_bdf'. NOTE: The OCaml bindings are adjusted to contain the interface change. It should therefore not affect compatibility with OCaml-based utilities. Signed-off-by: Paul Durrant Acked-by: Christian Lindig --- Cc: Ian Jackson Cc: Wei Liu Cc: Christian Lindig Cc: David Scott Cc: Anthony PERARD --- tools/include/libxl.h | 15 ++- tools/libs/light/libxl_pci.c | 215 +++++++++++++++++++------------= ---- tools/ocaml/libs/xl/xenlight_stubs.c | 15 ++- tools/xl/xl_pci.c | 32 +++--- 4 files changed, 157 insertions(+), 120 deletions(-) diff --git a/tools/include/libxl.h b/tools/include/libxl.h index 5edacccbd1..5703fdf367 100644 --- a/tools/include/libxl.h +++ b/tools/include/libxl.h @@ -470,6 +470,13 @@ #define LIBXL_HAVE_PCI_BDF 1 =20 /* + * LIBXL_HAVE_PCI_ASSIGNABLE_BDF indicates that the + * libxl_device_pci_assignable_add/remove/list/list_free() functions all + * use the 'libxl_pci_bdf' type rather than 'libxl_device_pci' type. + */ +#define LIBXL_HAVE_PCI_ASSIGNABLE_BDF 1 + +/* * libxl ABI compatibility * * The only guarantee which libxl makes regarding ABI compatibility @@ -2378,10 +2385,10 @@ int libxl_device_events_handler(libxl_ctx *ctx, * added or is not bound, the functions will emit a warning but return * SUCCESS. */ -int libxl_device_pci_assignable_add(libxl_ctx *ctx, libxl_device_pci *pci,= int rebind); -int libxl_device_pci_assignable_remove(libxl_ctx *ctx, libxl_device_pci *p= ci, int rebind); -libxl_device_pci *libxl_device_pci_assignable_list(libxl_ctx *ctx, int *nu= m); -void libxl_device_pci_assignable_list_free(libxl_device_pci *list, int num= ); +int libxl_device_pci_assignable_add(libxl_ctx *ctx, libxl_pci_bdf *pcibdf,= int rebind); +int libxl_device_pci_assignable_remove(libxl_ctx *ctx, libxl_pci_bdf *pcib= df, int rebind); +libxl_pci_bdf *libxl_device_pci_assignable_list(libxl_ctx *ctx, int *num); +void libxl_device_pci_assignable_list_free(libxl_pci_bdf *list, int num); =20 /* CPUID handling */ int libxl_cpuid_parse_config(libxl_cpuid_policy_list *cpuid, const char* s= tr); diff --git a/tools/libs/light/libxl_pci.c b/tools/libs/light/libxl_pci.c index fec77dd270..5104f31448 100644 --- a/tools/libs/light/libxl_pci.c +++ b/tools/libs/light/libxl_pci.c @@ -25,26 +25,33 @@ #define PCI_BDF_XSPATH "%04x-%02x-%02x-%01x" #define PCI_PT_QDEV_ID "pci-pt-%02x_%02x.%01x" =20 -static unsigned int pci_encode_bdf(libxl_device_pci *pci) +static unsigned int pci_encode_bdf(libxl_pci_bdf *pcibdf) { unsigned int value; =20 - value =3D pci->bdf.domain << 16; - value |=3D (pci->bdf.bus & 0xff) << 8; - value |=3D (pci->bdf.dev & 0x1f) << 3; - value |=3D (pci->bdf.func & 0x7); + value =3D pcibdf->domain << 16; + value |=3D (pcibdf->bus & 0xff) << 8; + value |=3D (pcibdf->dev & 0x1f) << 3; + value |=3D (pcibdf->func & 0x7); =20 return value; } =20 +static void pcibdf_struct_fill(libxl_pci_bdf *pcibdf, unsigned int domain, + unsigned int bus, unsigned int dev, + unsigned int func) +{ + pcibdf->domain =3D domain; + pcibdf->bus =3D bus; + pcibdf->dev =3D dev; + pcibdf->func =3D func; +} + static void pci_struct_fill(libxl_device_pci *pci, unsigned int domain, unsigned int bus, unsigned int dev, unsigned int func, unsigned int vdevfn) { - pci->bdf.domain =3D domain; - pci->bdf.bus =3D bus; - pci->bdf.dev =3D dev; - pci->bdf.func =3D func; + pcibdf_struct_fill(&pci->bdf, domain, bus, dev, func); pci->vdevfn =3D vdevfn; } =20 @@ -318,8 +325,8 @@ static int is_pci_in_array(libxl_device_pci *pcis, int = num, } =20 /* Write the standard BDF into the sysfs path given by sysfs_path. */ -static int sysfs_write_bdf(libxl__gc *gc, const char * sysfs_path, - libxl_device_pci *pci) +static int sysfs_write_bdf(libxl__gc *gc, const char *sysfs_path, + libxl_pci_bdf *pcibdf) { int rc, fd; char *buf; @@ -330,8 +337,8 @@ static int sysfs_write_bdf(libxl__gc *gc, const char * = sysfs_path, return ERROR_FAIL; } =20 - buf =3D GCSPRINTF(PCI_BDF, pci->bdf.domain, pci->bdf.bus, - pci->bdf.dev, pci->bdf.func); + buf =3D GCSPRINTF(PCI_BDF, pcibdf->domain, pcibdf->bus, + pcibdf->dev, pcibdf->func); rc =3D write(fd, buf, strlen(buf)); /* Annoying to have two if's, but we need the errno */ if (rc < 0) @@ -346,22 +353,22 @@ static int sysfs_write_bdf(libxl__gc *gc, const char = * sysfs_path, =20 #define PCI_INFO_PATH "/libxl/pci" =20 -static char *pci_info_xs_path(libxl__gc *gc, libxl_device_pci *pci, +static char *pci_info_xs_path(libxl__gc *gc, libxl_pci_bdf *pcibdf, const char *node) { return node ? GCSPRINTF(PCI_INFO_PATH"/"PCI_BDF_XSPATH"/%s", - pci->bdf.domain, pci->bdf.bus, pci->bdf.dev, pci->bdf.fu= nc, + pcibdf->domain, pcibdf->bus, pcibdf->dev, pcibdf->func, node) : GCSPRINTF(PCI_INFO_PATH"/"PCI_BDF_XSPATH, - pci->bdf.domain, pci->bdf.bus, pci->bdf.dev, pci->bdf.fu= nc); + pcibdf->domain, pcibdf->bus, pcibdf->dev, pcibdf->func); } =20 =20 -static int pci_info_xs_write(libxl__gc *gc, libxl_device_pci *pci, +static int pci_info_xs_write(libxl__gc *gc, libxl_pci_bdf *pcibdf, const char *node, const char *val) { - char *path =3D pci_info_xs_path(gc, pci, node); + char *path =3D pci_info_xs_path(gc, pcibdf, node); int rc =3D libxl__xs_printf(gc, XBT_NULL, path, "%s", val); =20 if (rc) LOGE(WARN, "Write of %s to node %s failed.", val, path); @@ -369,28 +376,28 @@ static int pci_info_xs_write(libxl__gc *gc, libxl_dev= ice_pci *pci, return rc; } =20 -static char *pci_info_xs_read(libxl__gc *gc, libxl_device_pci *pci, +static char *pci_info_xs_read(libxl__gc *gc, libxl_pci_bdf *pcibdf, const char *node) { - char *path =3D pci_info_xs_path(gc, pci, node); + char *path =3D pci_info_xs_path(gc, pcibdf, node); =20 return libxl__xs_read(gc, XBT_NULL, path); } =20 -static void pci_info_xs_remove(libxl__gc *gc, libxl_device_pci *pci, +static void pci_info_xs_remove(libxl__gc *gc, libxl_pci_bdf *pcibdf, const char *node) { - char *path =3D pci_info_xs_path(gc, pci, node); + char *path =3D pci_info_xs_path(gc, pcibdf, node); libxl_ctx *ctx =3D libxl__gc_owner(gc); =20 /* Remove the xenstore entry */ xs_rm(ctx->xsh, XBT_NULL, path); } =20 -libxl_device_pci *libxl_device_pci_assignable_list(libxl_ctx *ctx, int *nu= m) +libxl_pci_bdf *libxl_device_pci_assignable_list(libxl_ctx *ctx, int *num) { GC_INIT(ctx); - libxl_device_pci *pcis =3D NULL, *new; + libxl_pci_bdf *pcibdfs =3D NULL, *new; struct dirent *de; DIR *dir; =20 @@ -411,15 +418,15 @@ libxl_device_pci *libxl_device_pci_assignable_list(li= bxl_ctx *ctx, int *num) if (sscanf(de->d_name, PCI_BDF, &dom, &bus, &dev, &func) !=3D 4) continue; =20 - new =3D realloc(pcis, ((*num) + 1) * sizeof(*new)); + new =3D realloc(pcibdfs, ((*num) + 1) * sizeof(*new)); if (NULL =3D=3D new) continue; =20 - pcis =3D new; - new =3D pcis + *num; + pcibdfs =3D new; + new =3D pcibdfs + *num; =20 - libxl_device_pci_init(new); - pci_struct_fill(new, dom, bus, dev, func, 0); + libxl_pci_bdf_init(new); + pcibdf_struct_fill(new, dom, bus, dev, func); =20 if (pci_info_xs_read(gc, new, "domid")) /* already assigned */ continue; @@ -430,32 +437,32 @@ libxl_device_pci *libxl_device_pci_assignable_list(li= bxl_ctx *ctx, int *num) closedir(dir); out: GC_FREE; - return pcis; + return pcibdfs; } =20 -void libxl_device_pci_assignable_list_free(libxl_device_pci *list, int num) +void libxl_device_pci_assignable_list_free(libxl_pci_bdf *list, int num) { int i; =20 for (i =3D 0; i < num; i++) - libxl_device_pci_dispose(&list[i]); + libxl_pci_bdf_dispose(&list[i]); =20 free(list); } =20 /* Unbind device from its current driver, if any. If driver_path is non-N= ULL, * store the path to the original driver in it. */ -static int sysfs_dev_unbind(libxl__gc *gc, libxl_device_pci *pci, +static int sysfs_dev_unbind(libxl__gc *gc, libxl_pci_bdf *pcibdf, char **driver_path) { char * spath, *dp =3D NULL; struct stat st; =20 spath =3D GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/driver", - pci->bdf.domain, - pci->bdf.bus, - pci->bdf.dev, - pci->bdf.func); + pcibdf->domain, + pcibdf->bus, + pcibdf->dev, + pcibdf->func); if ( !lstat(spath, &st) ) { /* Find the canonical path to the driver. */ dp =3D libxl__zalloc(gc, PATH_MAX); @@ -469,7 +476,7 @@ static int sysfs_dev_unbind(libxl__gc *gc, libxl_device= _pci *pci, =20 /* Unbind from the old driver */ spath =3D GCSPRINTF("%s/unbind", dp); - if ( sysfs_write_bdf(gc, spath, pci) < 0 ) { + if ( sysfs_write_bdf(gc, spath, pcibdf) < 0 ) { LOGE(ERROR, "Couldn't unbind device"); return -1; } @@ -607,8 +614,8 @@ bool libxl__is_igd_vga_passthru(libxl__gc *gc, * already exist. */ =20 -/* Scan through /sys/.../pciback/slots looking for pci's BDF */ -static int pciback_dev_has_slot(libxl__gc *gc, libxl_device_pci *pci) +/* Scan through /sys/.../pciback/slots looking for BDF */ +static int pciback_dev_has_slot(libxl__gc *gc, libxl_pci_bdf *pcibdf) { FILE *f; int rc =3D 0; @@ -621,11 +628,11 @@ static int pciback_dev_has_slot(libxl__gc *gc, libxl_= device_pci *pci) return ERROR_FAIL; } =20 - while (fscanf(f, "%x:%x:%x.%d\n", &dom, &bus, &dev, &func)=3D=3D4) { - if (dom =3D=3D pci->bdf.domain - && bus =3D=3D pci->bdf.bus - && dev =3D=3D pci->bdf.dev - && func =3D=3D pci->bdf.func) { + while (fscanf(f, "%x:%x:%x.%d\n", &dom, &bus, &dev, &func) =3D=3D 4) { + if (dom =3D=3D pcibdf->domain + && bus =3D=3D pcibdf->bus + && dev =3D=3D pcibdf->dev + && func =3D=3D pcibdf->func) { rc =3D 1; goto out; } @@ -635,7 +642,7 @@ out: return rc; } =20 -static int pciback_dev_is_assigned(libxl__gc *gc, libxl_device_pci *pci) +static int pciback_dev_is_assigned(libxl__gc *gc, libxl_pci_bdf *pcibdf) { char * spath; int rc; @@ -651,8 +658,8 @@ static int pciback_dev_is_assigned(libxl__gc *gc, libxl= _device_pci *pci) } =20 spath =3D GCSPRINTF(SYSFS_PCIBACK_DRIVER"/"PCI_BDF, - pci->bdf.domain, pci->bdf.bus, - pci->bdf.dev, pci->bdf.func); + pcibdf->domain, pcibdf->bus, + pcibdf->dev, pcibdf->func); rc =3D lstat(spath, &st); =20 if( rc =3D=3D 0 ) @@ -663,40 +670,40 @@ static int pciback_dev_is_assigned(libxl__gc *gc, lib= xl_device_pci *pci) return -1; } =20 -static int pciback_dev_assign(libxl__gc *gc, libxl_device_pci *pci) +static int pciback_dev_assign(libxl__gc *gc, libxl_pci_bdf *pcibdf) { int rc; =20 - if ( (rc =3D pciback_dev_has_slot(gc, pci)) < 0 ) { + if ( (rc =3D pciback_dev_has_slot(gc, pcibdf)) < 0 ) { LOGE(ERROR, "Error checking for pciback slot"); return ERROR_FAIL; } else if (rc =3D=3D 0) { if ( sysfs_write_bdf(gc, SYSFS_PCIBACK_DRIVER"/new_slot", - pci) < 0 ) { + pcibdf) < 0 ) { LOGE(ERROR, "Couldn't bind device to pciback!"); return ERROR_FAIL; } } =20 - if ( sysfs_write_bdf(gc, SYSFS_PCIBACK_DRIVER"/bind", pci) < 0 ) { + if ( sysfs_write_bdf(gc, SYSFS_PCIBACK_DRIVER"/bind", pcibdf) < 0 ) { LOGE(ERROR, "Couldn't bind device to pciback!"); return ERROR_FAIL; } return 0; } =20 -static int pciback_dev_unassign(libxl__gc *gc, libxl_device_pci *pci) +static int pciback_dev_unassign(libxl__gc *gc, libxl_pci_bdf *pcibdf) { /* Remove from pciback */ - if ( sysfs_dev_unbind(gc, pci, NULL) < 0 ) { + if ( sysfs_dev_unbind(gc, pcibdf, NULL) < 0 ) { LOG(ERROR, "Couldn't unbind device!"); return ERROR_FAIL; } =20 /* Remove slot if necessary */ - if ( pciback_dev_has_slot(gc, pci) > 0 ) { + if ( pciback_dev_has_slot(gc, pcibdf) > 0 ) { if ( sysfs_write_bdf(gc, SYSFS_PCIBACK_DRIVER"/remove_slot", - pci) < 0 ) { + pcibdf) < 0 ) { LOGE(ERROR, "Couldn't remove pciback slot"); return ERROR_FAIL; } @@ -705,7 +712,7 @@ static int pciback_dev_unassign(libxl__gc *gc, libxl_de= vice_pci *pci) } =20 static int libxl__device_pci_assignable_add(libxl__gc *gc, - libxl_device_pci *pci, + libxl_pci_bdf *pcibdf, int rebind) { libxl_ctx *ctx =3D libxl__gc_owner(gc); @@ -715,10 +722,10 @@ static int libxl__device_pci_assignable_add(libxl__gc= *gc, struct stat st; =20 /* Local copy for convenience */ - dom =3D pci->bdf.domain; - bus =3D pci->bdf.bus; - dev =3D pci->bdf.dev; - func =3D pci->bdf.func; + dom =3D pcibdf->domain; + bus =3D pcibdf->bus; + dev =3D pcibdf->dev; + func =3D pcibdf->func; =20 /* See if the device exists */ spath =3D GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF, dom, bus, dev, func); @@ -728,7 +735,7 @@ static int libxl__device_pci_assignable_add(libxl__gc *= gc, } =20 /* Check to see if it's already assigned to pciback */ - rc =3D pciback_dev_is_assigned(gc, pci); + rc =3D pciback_dev_is_assigned(gc, pcibdf); if ( rc < 0 ) { return ERROR_FAIL; } @@ -738,7 +745,7 @@ static int libxl__device_pci_assignable_add(libxl__gc *= gc, } =20 /* Check to see if there's already a driver that we need to unbind fro= m */ - if ( sysfs_dev_unbind(gc, pci, &driver_path ) ) { + if ( sysfs_dev_unbind(gc, pcibdf, &driver_path ) ) { LOG(ERROR, "Couldn't unbind "PCI_BDF" from driver", dom, bus, dev, func); return ERROR_FAIL; @@ -747,9 +754,9 @@ static int libxl__device_pci_assignable_add(libxl__gc *= gc, /* Store driver_path for rebinding to dom0 */ if ( rebind ) { if ( driver_path ) { - pci_info_xs_write(gc, pci, "driver_path", driver_path); + pci_info_xs_write(gc, pcibdf, "driver_path", driver_path); } else if ( (driver_path =3D - pci_info_xs_read(gc, pci, "driver_path")) !=3D NULL )= { + pci_info_xs_read(gc, pcibdf, "driver_path")) !=3D NUL= L ) { LOG(INFO, PCI_BDF" not bound to a driver, will be rebound to %= s", dom, bus, dev, func, driver_path); } else { @@ -757,10 +764,10 @@ static int libxl__device_pci_assignable_add(libxl__gc= *gc, dom, bus, dev, func); } } else { - pci_info_xs_remove(gc, pci, "driver_path"); + pci_info_xs_remove(gc, pcibdf, "driver_path"); } =20 - if ( pciback_dev_assign(gc, pci) ) { + if ( pciback_dev_assign(gc, pcibdf) ) { LOG(ERROR, "Couldn't bind device to pciback!"); return ERROR_FAIL; } @@ -771,7 +778,7 @@ quarantine: * so always pass XEN_DOMCTL_DEV_RDM_RELAXED to avoid assignment being * unnecessarily denied. */ - rc =3D xc_assign_device(ctx->xch, DOMID_IO, pci_encode_bdf(pci), + rc =3D xc_assign_device(ctx->xch, DOMID_IO, pci_encode_bdf(pcibdf), XEN_DOMCTL_DEV_RDM_RELAXED); if ( rc < 0 ) { LOG(ERROR, "failed to quarantine "PCI_BDF, dom, bus, dev, func); @@ -782,7 +789,7 @@ quarantine: } =20 static int libxl__device_pci_assignable_remove(libxl__gc *gc, - libxl_device_pci *pci, + libxl_pci_bdf *pcibdf, int rebind) { libxl_ctx *ctx =3D libxl__gc_owner(gc); @@ -790,24 +797,24 @@ static int libxl__device_pci_assignable_remove(libxl_= _gc *gc, char *driver_path; =20 /* De-quarantine */ - rc =3D xc_deassign_device(ctx->xch, DOMID_IO, pci_encode_bdf(pci)); + rc =3D xc_deassign_device(ctx->xch, DOMID_IO, pci_encode_bdf(pcibdf)); if ( rc < 0 ) { - LOG(ERROR, "failed to de-quarantine "PCI_BDF, pci->bdf.domain, pci= ->bdf.bus, - pci->bdf.dev, pci->bdf.func); + LOG(ERROR, "failed to de-quarantine "PCI_BDF, pcibdf->domain, + pcibdf->bus, pcibdf->dev, pcibdf->func); return ERROR_FAIL; } =20 /* Unbind from pciback */ - if ( (rc =3D pciback_dev_is_assigned(gc, pci)) < 0 ) { + if ( (rc =3D pciback_dev_is_assigned(gc, pcibdf)) < 0 ) { return ERROR_FAIL; } else if ( rc ) { - pciback_dev_unassign(gc, pci); + pciback_dev_unassign(gc, pcibdf); } else { LOG(WARN, "Not bound to pciback"); } =20 /* Rebind if necessary */ - driver_path =3D pci_info_xs_read(gc, pci, "driver_path"); + driver_path =3D pci_info_xs_read(gc, pcibdf, "driver_path"); =20 if ( driver_path ) { if ( rebind ) { @@ -815,12 +822,12 @@ static int libxl__device_pci_assignable_remove(libxl_= _gc *gc, =20 if ( sysfs_write_bdf(gc, GCSPRINTF("%s/bind", driver_path), - pci) < 0 ) { + pcibdf) < 0 ) { LOGE(ERROR, "Couldn't bind device to %s", driver_path); return -1; } =20 - pci_info_xs_remove(gc, pci, "driver_path"); + pci_info_xs_remove(gc, pcibdf, "driver_path"); } } else { if ( rebind ) { @@ -832,26 +839,26 @@ static int libxl__device_pci_assignable_remove(libxl_= _gc *gc, return 0; } =20 -int libxl_device_pci_assignable_add(libxl_ctx *ctx, libxl_device_pci *pci, +int libxl_device_pci_assignable_add(libxl_ctx *ctx, libxl_pci_bdf *pcibdf, int rebind) { GC_INIT(ctx); int rc; =20 - rc =3D libxl__device_pci_assignable_add(gc, pci, rebind); + rc =3D libxl__device_pci_assignable_add(gc, pcibdf, rebind); =20 GC_FREE; return rc; } =20 =20 -int libxl_device_pci_assignable_remove(libxl_ctx *ctx, libxl_device_pci *p= ci, +int libxl_device_pci_assignable_remove(libxl_ctx *ctx, libxl_pci_bdf *pcib= df, int rebind) { GC_INIT(ctx); int rc; =20 - rc =3D libxl__device_pci_assignable_remove(gc, pci, rebind); + rc =3D libxl__device_pci_assignable_remove(gc, pcibdf, rebind); =20 GC_FREE; return rc; @@ -1352,7 +1359,7 @@ static void pci_add_dm_done(libxl__egc *egc, /* Don't restrict writes to the PCI config space from this VM */ if (pci->permissive) { if ( sysfs_write_bdf(gc, SYSFS_PCIBACK_DRIVER"/permissive", - pci) < 0 ) { + &pci->bdf) < 0 ) { LOGD(ERROR, domid, "Setting permissive for device"); rc =3D ERROR_FAIL; goto out; @@ -1368,7 +1375,8 @@ out_no_irq: rc =3D ERROR_FAIL; goto out; } - r =3D xc_assign_device(ctx->xch, domid, pci_encode_bdf(pci), flag); + r =3D xc_assign_device(ctx->xch, domid, pci_encode_bdf(&pci->bdf), + flag); if (r < 0 && (hvm || errno !=3D ENOSYS)) { LOGED(ERROR, domid, "xc_assign_device failed"); rc =3D ERROR_FAIL; @@ -1447,15 +1455,28 @@ int libxl_device_pci_add(libxl_ctx *ctx, uint32_t d= omid, return AO_INPROGRESS; } =20 -static bool libxl_pci_assignable(libxl_ctx *ctx, libxl_device_pci *pci) +static int is_bdf_in_array(libxl_pci_bdf *pcibdfs, int num, + libxl_pci_bdf *pcibdf) { - libxl_device_pci *pcis; + int i; + + for(i =3D 0; i < num; i++) { + if (COMPARE_BDF(pcibdf, &pcibdfs[i])) + break; + } + + return i < num; +} + +static bool is_bdf_assignable(libxl_ctx *ctx, libxl_pci_bdf *pcibdf) +{ + libxl_pci_bdf *pcibdfs; int num; bool assignable; =20 - pcis =3D libxl_device_pci_assignable_list(ctx, &num); - assignable =3D is_pci_in_array(pcis, num, pci); - libxl_device_pci_assignable_list_free(pcis, num); + pcibdfs =3D libxl_device_pci_assignable_list(ctx, &num); + assignable =3D is_bdf_in_array(pcibdfs, num, pcibdf); + libxl_device_pci_assignable_list_free(pcibdfs, num); =20 return assignable; } @@ -1490,7 +1511,8 @@ void libxl__device_pci_add(libxl__egc *egc, uint32_t = domid, pas->callback =3D device_pci_add_stubdom_done; =20 if (libxl__domain_type(gc, domid) =3D=3D LIBXL_DOMAIN_TYPE_HVM) { - rc =3D xc_test_assign_device(ctx->xch, domid, pci_encode_bdf(pci)); + rc =3D xc_test_assign_device(ctx->xch, domid, + pci_encode_bdf(&pci->bdf)); if (rc) { LOGD(ERROR, domid, "PCI device %04x:%02x:%02x.%u %s?", @@ -1504,20 +1526,20 @@ void libxl__device_pci_add(libxl__egc *egc, uint32_= t domid, rc =3D libxl__device_pci_setdefault(gc, domid, pci, !starting); if (rc) goto out; =20 - if (pci->seize && !pciback_dev_is_assigned(gc, pci)) { - rc =3D libxl__device_pci_assignable_add(gc, pci, 1); + if (pci->seize && !pciback_dev_is_assigned(gc, &pci->bdf)) { + rc =3D libxl__device_pci_assignable_add(gc, &pci->bdf, 1); if ( rc ) goto out; } =20 - if (!libxl_pci_assignable(ctx, pci)) { + if (!is_bdf_assignable(ctx, &pci->bdf)) { LOGD(ERROR, domid, "PCI device %x:%x:%x.%x is not assignable", pci->bdf.domain, pci->bdf.bus, pci->bdf.dev, pci->bdf.func); rc =3D ERROR_FAIL; goto out; } =20 - rc =3D pci_info_xs_write(gc, pci, "domid", GCSPRINTF("%u", domid)); + rc =3D pci_info_xs_write(gc, &pci->bdf, "domid", GCSPRINTF("%u", domid= )); if (rc) goto out; =20 libxl__device_pci_reset(gc, pci->bdf.domain, pci->bdf.bus, pci->bdf.de= v, pci->bdf.func); @@ -1641,7 +1663,7 @@ static void device_pci_add_done(libxl__egc *egc, "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, "domid"); + pci_info_xs_remove(gc, &pci->bdf, "domid"); } libxl_device_pci_dispose(pci); aodev->rc =3D rc; @@ -2110,7 +2132,8 @@ static void pci_remove_detached(libxl__egc *egc, } =20 if (!isstubdom) { - rc =3D xc_deassign_device(CTX->xch, domid, pci_encode_bdf(pci)); + rc =3D xc_deassign_device(CTX->xch, domid, + pci_encode_bdf(&pci->bdf)); if (rc < 0 && (prs->hvm || errno !=3D ENOSYS)) LOGED(ERROR, domid, "xc_deassign_device failed"); } @@ -2239,7 +2262,7 @@ out: libxl__ev_time_deregister(gc, &prs->timeout); libxl__ev_time_deregister(gc, &prs->retry_timer); =20 - if (!rc) pci_info_xs_remove(gc, pci, "domid"); + if (!rc) pci_info_xs_remove(gc, &pci->bdf, "domid"); =20 libxl_device_pci_dispose(pci); aodev->rc =3D rc; diff --git a/tools/ocaml/libs/xl/xenlight_stubs.c b/tools/ocaml/libs/xl/xen= light_stubs.c index 352a00134d..2388f23869 100644 --- a/tools/ocaml/libs/xl/xenlight_stubs.c +++ b/tools/ocaml/libs/xl/xenlight_stubs.c @@ -840,7 +840,7 @@ value stub_xl_device_pci_assignable_add(value ctx, valu= e info, value rebind) device_pci_val(CTX, &c_info, info); =20 caml_enter_blocking_section(); - ret =3D libxl_device_pci_assignable_add(CTX, &c_info, c_rebind); + ret =3D libxl_device_pci_assignable_add(CTX, &c_info.bdf, c_rebind); caml_leave_blocking_section(); =20 libxl_device_pci_dispose(&c_info); @@ -861,7 +861,7 @@ value stub_xl_device_pci_assignable_remove(value ctx, v= alue info, value rebind) device_pci_val(CTX, &c_info, info); =20 caml_enter_blocking_section(); - ret =3D libxl_device_pci_assignable_remove(CTX, &c_info, c_rebind); + ret =3D libxl_device_pci_assignable_remove(CTX, &c_info.bdf, c_rebind); caml_leave_blocking_section(); =20 libxl_device_pci_dispose(&c_info); @@ -876,7 +876,7 @@ value stub_xl_device_pci_assignable_list(value ctx) { CAMLparam1(ctx); CAMLlocal2(list, temp); - libxl_device_pci *c_list; + libxl_pci_bdf *c_list; int i, nb; uint32_t c_domid; =20 @@ -889,11 +889,18 @@ value stub_xl_device_pci_assignable_list(value ctx) =20 list =3D temp =3D Val_emptylist; for (i =3D 0; i < nb; i++) { + libxl_device_pci pci; + + libxl_device_pci_init(&pci); + libxl_pci_bdf_copy(CTX, &pci.bdf, &c_list[i]); + list =3D caml_alloc_small(2, Tag_cons); Field(list, 0) =3D Val_int(0); Field(list, 1) =3D temp; temp =3D list; - Store_field(list, 0, Val_device_pci(&c_list[i])); + Store_field(list, 0, Val_device_pci(&pci)); + + libxl_device_pci_dispose(&pci); } libxl_device_pci_assignable_list_free(c_list, nb); =20 diff --git a/tools/xl/xl_pci.c b/tools/xl/xl_pci.c index 9c24496cb2..37708b4eb1 100644 --- a/tools/xl/xl_pci.c +++ b/tools/xl/xl_pci.c @@ -154,19 +154,19 @@ int main_pciattach(int argc, char **argv) =20 static void pciassignable_list(void) { - libxl_device_pci *pcis; + libxl_pci_bdf *pcibdfs; int num, i; =20 - pcis =3D libxl_device_pci_assignable_list(ctx, &num); + pcibdfs =3D libxl_device_pci_assignable_list(ctx, &num); =20 - if ( pcis =3D=3D NULL ) + if ( pcibdfs =3D=3D NULL ) return; for (i =3D 0; i < num; i++) { printf("%04x:%02x:%02x.%01x\n", - pcis[i].bdf.domain, pcis[i].bdf.bus, pcis[i].bdf.dev, - pcis[i].bdf.func); + pcibdfs[i].domain, pcibdfs[i].bus, pcibdfs[i].dev, + pcibdfs[i].func); } - libxl_device_pci_assignable_list_free(pcis, num); + libxl_device_pci_assignable_list_free(pcibdfs, num); } =20 int main_pciassignable_list(int argc, char **argv) @@ -183,24 +183,24 @@ int main_pciassignable_list(int argc, char **argv) =20 static int pciassignable_add(const char *bdf, int rebind) { - libxl_device_pci pci; + libxl_pci_bdf pcibdf; XLU_Config *config; int r =3D 0; =20 - libxl_device_pci_init(&pci); + libxl_pci_bdf_init(&pcibdf); =20 config =3D xlu_cfg_init(stderr, "command line"); if (!config) { perror("xlu_cfg_init"); exit(-1); } =20 - if (xlu_pci_parse_bdf(config, &pci.bdf, bdf)) { + if (xlu_pci_parse_bdf(config, &pcibdf, bdf)) { fprintf(stderr, "pci-assignable-add: malformed BDF \"%s\"\n", bdf); exit(2); } =20 - if (libxl_device_pci_assignable_add(ctx, &pci, rebind)) + if (libxl_device_pci_assignable_add(ctx, &pcibdf, rebind)) r =3D 1; =20 - libxl_device_pci_dispose(&pci); + libxl_pci_bdf_dispose(&pcibdf); xlu_cfg_destroy(config); =20 return r; @@ -225,24 +225,24 @@ int main_pciassignable_add(int argc, char **argv) =20 static int pciassignable_remove(const char *bdf, int rebind) { - libxl_device_pci pci; + libxl_pci_bdf pcibdf; XLU_Config *config; int r =3D 0; =20 - libxl_device_pci_init(&pci); + libxl_pci_bdf_init(&pcibdf); =20 config =3D xlu_cfg_init(stderr, "command line"); if (!config) { perror("xlu_cfg_init"); exit(-1); } =20 - if (xlu_pci_parse_bdf(config, &pci.bdf, bdf)) { + if (xlu_pci_parse_bdf(config, &pcibdf, bdf)) { fprintf(stderr, "pci-assignable-remove: malformed BDF \"%s\"\n", b= df); exit(2); } =20 - if (libxl_device_pci_assignable_remove(ctx, &pci, rebind)) + if (libxl_device_pci_assignable_remove(ctx, &pcibdf, rebind)) r =3D 1; =20 - libxl_device_pci_dispose(&pci); + libxl_pci_bdf_dispose(&pcibdf); xlu_cfg_destroy(config); =20 return r; --=20 2.11.0 From nobody Sun May 5 11:10:29 2024 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=1603470408; cv=none; d=zohomail.com; s=zohoarc; b=MQD1z/jT3wbLxNyheY8+Bg0KfXojVvtEj5hTx8xBv8TabAs8rZH9rWaKtHPKXpB7332XNq3LkG/lTUh7jh3zsBSMD5fiuH2BteJvugiVlnF0J/96lduXvBaXX6Qzsd0o66Qj9WVpYQ/jzVcwxjhbVfUV/UoX9HsSVcohCAyK2kA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603470408; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=VqeeOXCaFQ2Ft+b5+Gf0Q+8kwLK5tou/HCVHc7Td96s=; b=dMqzJuYaGXmKdItpYv5NKK1LCigUKCJDYel7+AJMxSr0oWAuuPC8H+VwFBpegGNTHWp8ro5VXfD2yN+aajKVrWXPRh35rX5PxGgMMnHk1m7oUZJZ1QP2ErL+t2ZBZ76KTf4jNjwOM26exduExAipB3R6ezrOQwbOdavK0ZXf2rA= 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 1603470408120720.129379905069; Fri, 23 Oct 2020 09:26:48 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.11203.29741 (Exim 4.92) (envelope-from ) id 1kVzth-00018G-KZ; Fri, 23 Oct 2020 16:26:33 +0000 Received: by outflank-mailman (output) from mailman id 11203.29741; Fri, 23 Oct 2020 16:26:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzth-000188-Fo; Fri, 23 Oct 2020 16:26:33 +0000 Received: by outflank-mailman (input) for mailman id 11203; Fri, 23 Oct 2020 16:26:32 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztg-0000v2-GL for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:26:32 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 1916f930-e166-42b9-ad5b-8280fe52630d; Fri, 23 Oct 2020 16:26:22 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztV-0008Ny-3l; Fri, 23 Oct 2020 16:26:21 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqt-000376-1A; Fri, 23 Oct 2020 16:23:39 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztg-0000v2-GL for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:26:32 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 1916f930-e166-42b9-ad5b-8280fe52630d; Fri, 23 Oct 2020 16:26:22 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztV-0008Ny-3l; Fri, 23 Oct 2020 16:26:21 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqt-000376-1A; Fri, 23 Oct 2020 16:23:39 +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" X-Inumbo-ID: 1916f930-e166-42b9-ad5b-8280fe52630d DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=VqeeOXCaFQ2Ft+b5+Gf0Q+8kwLK5tou/HCVHc7Td96s=; b=rUt3n1yHArGCF4WPFnW3j/Wd2 PHFR/Bih3WQ25luaHKeb1kOE57eN3s0+MXVfRqdyzVRYIVafwQNusxMdY9Fq0b74S+dwfbHDow+Xl KOLEqCZdyWUE7SL9ZM2qhfwRjGiGeLbgzPtYcbxbOZXi5xxIH7DkOZ6XsrxF1l8LpuiF4=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson , Wei Liu Subject: [PATCH 22/25] docs/man: modify xl(1) in preparation for naming of assignable devices Date: Fri, 23 Oct 2020 16:23:11 +0000 Message-Id: <20201023162314.2235-23-paul@xen.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20201023162314.2235-1-paul@xen.org> References: <20201023162314.2235-1-paul@xen.org> X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paul Durrant A subsequent patch will introduce code to allow a name to be specified to 'xl pci-assignable-add' such that the assignable device may be referred to by than name in subsequent operations. Signed-off-by: Paul Durrant Acked-by: Christian Lindig --- Cc: Ian Jackson Cc: Wei Liu --- docs/man/xl.1.pod.in | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/docs/man/xl.1.pod.in b/docs/man/xl.1.pod.in index 373a52839d..a45b423d0f 100644 --- a/docs/man/xl.1.pod.in +++ b/docs/man/xl.1.pod.in @@ -1595,19 +1595,23 @@ List virtual network interfaces for a domain. =20 =3Dover 4 =20 -=3Ditem B +=3Ditem B [I<-n>] =20 List all the B of assignable PCI devices. See -L for more information. +L for more information. If the -n option is +specified then any name supplied when the device was made assignable +will also be displayed. =20 These are devices in the system which are configured to be available for passthrough and are bound to a suitable PCI backend driver in domain 0 rather than a real driver. =20 -=3Ditem B I +=3Ditem B [I<-n NAME>] I =20 Make the device at B assignable to guests. See -L for more information. +L for more information. If the -n option is +supplied then the assignable device entry will the named with the +given B. =20 This will bind the device to the pciback driver and assign it to the "quarantine domain". If it is already bound to a driver, it will @@ -1622,10 +1626,11 @@ not to do this on a device critical to domain 0's o= peration, such as storage controllers, network interfaces, or GPUs that are currently being used. =20 -=3Ditem B [I<-r>] I +=3Ditem B [I<-r>] I|I =20 -Make the device at B not assignable to guests. See -L for more information. +Make a device non-assignable to guests. The device may be identified +either by its B or the B supplied when the device was made +assignable. See L for more information. =20 This will at least unbind the device from pciback, and re-assign it from the "quarantine domain" back to domain 0. If the -r --=20 2.11.0 From nobody Sun May 5 11:10:29 2024 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=1603470441; cv=none; d=zohomail.com; s=zohoarc; b=IUFx5d8yYzW2enkmvhYR9+wJkQEFRaoBkfxbzRAtOvlHf7NLAHDbEqj2AWZVtAQ6Vuc2X3VW7XgzeSyJRlR/m+VQh2xMUhn5jpTqvNAKgkCraz3Op4q1pp9lhg48UgpUqbNEDAQhDgDZ5/aEqFRo0M9GdH2kkdfQ8zZ0X7NeK0M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603470441; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=ILx3JMJce2ioNh3ZqL79hk3Ma28xIlwlj5jXju/NDSo=; b=hFhO91qbl19INZQqbJNvm7I2qgm6tnXDu/QXA6F0+8IfACaCz9uv41vr1ne69LyREKz3J6MZcQSRIpu8zHEJ9BjW+HzxdkmFnHRRsekqjtiQNy5AtsclAVi0/8Fs6l/nA8EMpGGgT9nKnKUwM+BcaLPqYM6o8iethXFnPY2icDE= 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 16034704411301020.6176223442483; Fri, 23 Oct 2020 09:27:21 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.11223.29873 (Exim 4.92) (envelope-from ) id 1kVzuB-00028K-A6; Fri, 23 Oct 2020 16:27:03 +0000 Received: by outflank-mailman (output) from mailman id 11223.29873; Fri, 23 Oct 2020 16:27:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzuB-000282-6D; Fri, 23 Oct 2020 16:27:03 +0000 Received: by outflank-mailman (input) for mailman id 11223; Fri, 23 Oct 2020 16:27:02 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzuA-0000v2-HC for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:27:02 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 8512d213-ebb3-411b-ac50-ba2ab9e66ddb; Fri, 23 Oct 2020 16:26:22 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztV-0008Nu-2M; Fri, 23 Oct 2020 16:26:21 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqu-000376-4o; Fri, 23 Oct 2020 16:23:40 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzuA-0000v2-HC for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:27:02 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 8512d213-ebb3-411b-ac50-ba2ab9e66ddb; Fri, 23 Oct 2020 16:26:22 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztV-0008Nu-2M; Fri, 23 Oct 2020 16:26:21 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqu-000376-4o; Fri, 23 Oct 2020 16:23:40 +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" X-Inumbo-ID: 8512d213-ebb3-411b-ac50-ba2ab9e66ddb DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=ILx3JMJce2ioNh3ZqL79hk3Ma28xIlwlj5jXju/NDSo=; b=yYuFGUw7nDAR/fYCQJIol4etH oHdy36tjOiw6boekQOWzfcXV79tqDBEnc3o8XexFeDJude7uCfQAfcCjZqrYLLQ+ViyjOzUoEIvz0 ZGO5erBs7lSrgDN4iAGqfMDdAJZHJZKkKS/LVeUxjMnhWLE9E+4QtpmDzysYyJpMSLUe0=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson , Wei Liu , Christian Lindig , David Scott , Anthony PERARD Subject: [PATCH 23/25] xl / libxl: support naming of assignable devices Date: Fri, 23 Oct 2020 16:23:12 +0000 Message-Id: <20201023162314.2235-24-paul@xen.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20201023162314.2235-1-paul@xen.org> References: <20201023162314.2235-1-paul@xen.org> X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paul Durrant This patch modifies libxl_device_pci_assignable_add() to take an optional 'name' argument, which (if supplied) is saved into xenstore and can hence be used to refer to the now-assignable BDF in subsequent operations. To facilitate this, a new libxl_device_pci_assignable_name2bdf() function is added. The xl code is modified to allow a name to be specified in the 'pci-assignable-add' operation and also allow an option to be specified to 'pci-assignable-list' requesting that names be displayed. The latter is facilitated by a new libxl_device_pci_assignable_bdf2name() function. Final= ly xl 'pci-assignable-remove' is modified to that either a name or BDF can be supplied. The supplied 'identifier' is first assumed to be a name, but if libxl_device_pci_assignable_name2bdf() fails to find a matching BDF the identifier itself will be parsed as a BDF. Names my only include printable characters and may not include whitespace. Signed-off-by: Paul Durrant Acked-by: Christian Lindig --- Cc: Ian Jackson Cc: Wei Liu Cc: Christian Lindig Cc: David Scott Cc: Anthony PERARD --- tools/include/libxl.h | 19 +++++++- tools/libs/light/libxl_pci.c | 86 ++++++++++++++++++++++++++++++++= +--- tools/ocaml/libs/xl/xenlight_stubs.c | 3 +- tools/xl/xl_cmdtable.c | 12 +++-- tools/xl/xl_pci.c | 84 ++++++++++++++++++++++++--------= --- 5 files changed, 166 insertions(+), 38 deletions(-) diff --git a/tools/include/libxl.h b/tools/include/libxl.h index 5703fdf367..4025d3a3d4 100644 --- a/tools/include/libxl.h +++ b/tools/include/libxl.h @@ -477,6 +477,14 @@ #define LIBXL_HAVE_PCI_ASSIGNABLE_BDF 1 =20 /* + * LIBXL_HAVE_PCI_ASSIGNABLE_NAME indicates that the + * libxl_device_pci_assignable_add() function takes a 'name' argument + * and that the libxl_device_pci_assignable_name2bdf() and + * libxl_device_pci_assignable_bdf2name() functions are defined. + */ +#define LIBXL_HAVE_PCI_ASSIGNABLE_NAME 1 + +/* * libxl ABI compatibility * * The only guarantee which libxl makes regarding ABI compatibility @@ -2385,11 +2393,18 @@ int libxl_device_events_handler(libxl_ctx *ctx, * added or is not bound, the functions will emit a warning but return * SUCCESS. */ -int libxl_device_pci_assignable_add(libxl_ctx *ctx, libxl_pci_bdf *pcibdf,= int rebind); -int libxl_device_pci_assignable_remove(libxl_ctx *ctx, libxl_pci_bdf *pcib= df, int rebind); +int libxl_device_pci_assignable_add(libxl_ctx *ctx, libxl_pci_bdf *pcibdf, + const char *name, int rebind); +int libxl_device_pci_assignable_remove(libxl_ctx *ctx, libxl_pci_bdf *pcib= df, + int rebind); libxl_pci_bdf *libxl_device_pci_assignable_list(libxl_ctx *ctx, int *num); void libxl_device_pci_assignable_list_free(libxl_pci_bdf *list, int num); =20 +libxl_pci_bdf *libxl_device_pci_assignable_name2bdf(libxl_ctx *ctx, + const char *name); +char *libxl_device_pci_assignable_bdf2name(libxl_ctx *ctx, + libxl_pci_bdf *pcibdf); + /* CPUID handling */ int libxl_cpuid_parse_config(libxl_cpuid_policy_list *cpuid, const char* s= tr); int libxl_cpuid_parse_config_xend(libxl_cpuid_policy_list *cpuid, diff --git a/tools/libs/light/libxl_pci.c b/tools/libs/light/libxl_pci.c index 5104f31448..0f7d655aff 100644 --- a/tools/libs/light/libxl_pci.c +++ b/tools/libs/light/libxl_pci.c @@ -713,6 +713,7 @@ static int pciback_dev_unassign(libxl__gc *gc, libxl_pc= i_bdf *pcibdf) =20 static int libxl__device_pci_assignable_add(libxl__gc *gc, libxl_pci_bdf *pcibdf, + const char *name, int rebind) { libxl_ctx *ctx =3D libxl__gc_owner(gc); @@ -721,6 +722,23 @@ static int libxl__device_pci_assignable_add(libxl__gc = *gc, int rc; struct stat st; =20 + /* Sanitise any name that was passed */ + if (name) { + unsigned int i, n =3D strlen(name); + + if (n > 64) { /* Reasonable upper bound on name length */ + LOG(ERROR, "Name too long"); + return ERROR_FAIL; + } + + for (i =3D 0; i < n; i++) { + if (!isgraph(name[i])) { + LOG(ERROR, "Names may only include printable characters"); + return ERROR_FAIL; + } + } + } + /* Local copy for convenience */ dom =3D pcibdf->domain; bus =3D pcibdf->bus; @@ -741,7 +759,7 @@ static int libxl__device_pci_assignable_add(libxl__gc *= gc, } if ( rc ) { LOG(WARN, PCI_BDF" already assigned to pciback", dom, bus, dev, fu= nc); - goto quarantine; + goto name; } =20 /* Check to see if there's already a driver that we need to unbind fro= m */ @@ -772,7 +790,12 @@ static int libxl__device_pci_assignable_add(libxl__gc = *gc, return ERROR_FAIL; } =20 -quarantine: +name: + if (name) + pci_info_xs_write(gc, pcibdf, "name", name); + else + pci_info_xs_remove(gc, pcibdf, "name"); + /* * DOMID_IO is just a sentinel domain, without any actual mappings, * so always pass XEN_DOMCTL_DEV_RDM_RELAXED to avoid assignment being @@ -836,16 +859,18 @@ static int libxl__device_pci_assignable_remove(libxl_= _gc *gc, } } =20 + pci_info_xs_remove(gc, pcibdf, "name"); + return 0; } =20 int libxl_device_pci_assignable_add(libxl_ctx *ctx, libxl_pci_bdf *pcibdf, - int rebind) + const char *name, int rebind) { GC_INIT(ctx); int rc; =20 - rc =3D libxl__device_pci_assignable_add(gc, pcibdf, rebind); + rc =3D libxl__device_pci_assignable_add(gc, pcibdf, name, rebind); =20 GC_FREE; return rc; @@ -864,6 +889,57 @@ int libxl_device_pci_assignable_remove(libxl_ctx *ctx,= libxl_pci_bdf *pcibdf, return rc; } =20 +libxl_pci_bdf *libxl_device_pci_assignable_name2bdf(libxl_ctx *ctx, + const char *name) +{ + GC_INIT(ctx); + char **bdfs; + libxl_pci_bdf *pcibdf; + unsigned int i, n; + + bdfs =3D libxl__xs_directory(gc, XBT_NULL, PCI_INFO_PATH, &n); + if (!n) + goto out; + + pcibdf =3D calloc(1, sizeof(*pcibdf)); + if (!pcibdf) + goto out; + + for (i =3D 0; i < n; i++) { + unsigned dom, bus, dev, func; + const char *tmp; + + if (sscanf(bdfs[i], PCI_BDF_XSPATH, &dom, &bus, &dev, &func) !=3D = 4) + continue; + + pcibdf_struct_fill(pcibdf, dom, bus, dev, func); + + tmp =3D pci_info_xs_read(gc, pcibdf, "name"); + if (tmp && !strcmp(tmp, name)) + goto out; + } + + free(pcibdf); + pcibdf =3D NULL; + +out: + GC_FREE; + return pcibdf; +} + +char *libxl_device_pci_assignable_bdf2name(libxl_ctx *ctx, + libxl_pci_bdf *pcibdf) +{ + GC_INIT(ctx); + char *name =3D NULL, *tmp =3D pci_info_xs_read(gc, pcibdf, "name"); + + if (tmp) + name =3D strdup(tmp); + + GC_FREE; + return name; +} + /* * This function checks that all functions of a device are bound to pciback * driver. It also initialises a bit-mask of which function numbers are pr= esent @@ -1527,7 +1603,7 @@ void libxl__device_pci_add(libxl__egc *egc, uint32_t = domid, if (rc) goto out; =20 if (pci->seize && !pciback_dev_is_assigned(gc, &pci->bdf)) { - rc =3D libxl__device_pci_assignable_add(gc, &pci->bdf, 1); + rc =3D libxl__device_pci_assignable_add(gc, &pci->bdf, NULL, 1); if ( rc ) goto out; } diff --git a/tools/ocaml/libs/xl/xenlight_stubs.c b/tools/ocaml/libs/xl/xen= light_stubs.c index 2388f23869..96bb4655e0 100644 --- a/tools/ocaml/libs/xl/xenlight_stubs.c +++ b/tools/ocaml/libs/xl/xenlight_stubs.c @@ -840,7 +840,8 @@ value stub_xl_device_pci_assignable_add(value ctx, valu= e info, value rebind) device_pci_val(CTX, &c_info, info); =20 caml_enter_blocking_section(); - ret =3D libxl_device_pci_assignable_add(CTX, &c_info.bdf, c_rebind); + ret =3D libxl_device_pci_assignable_add(CTX, &c_info.bdf, NULL, + c_rebind); caml_leave_blocking_section(); =20 libxl_device_pci_dispose(&c_info); diff --git a/tools/xl/xl_cmdtable.c b/tools/xl/xl_cmdtable.c index 2ee0c49673..9e9aa448e2 100644 --- a/tools/xl/xl_cmdtable.c +++ b/tools/xl/xl_cmdtable.c @@ -105,21 +105,25 @@ struct cmd_spec cmd_table[] =3D { { "pci-assignable-add", &main_pciassignable_add, 0, 1, "Make a device assignable for pci-passthru", - "", + "[options] ", + "-n NAME, --name=3DNAME Name the assignable device.\n" "-h Print this help.\n" }, { "pci-assignable-remove", &main_pciassignable_remove, 0, 1, "Remove a device from being assignable", - "[options] ", + "[options] |NAME", "-h Print this help.\n" "-r Attempt to re-assign the device to the\n" - " original driver" + " original driver." }, { "pci-assignable-list", &main_pciassignable_list, 0, 0, "List all the assignable pci devices", - "", + "[options]", + "-h Print this help.\n" + "-n, --show-names Display assignable device names where\n" + " supplied.\n" }, { "pause", &main_pause, 0, 1, diff --git a/tools/xl/xl_pci.c b/tools/xl/xl_pci.c index 37708b4eb1..f1b58b3976 100644 --- a/tools/xl/xl_pci.c +++ b/tools/xl/xl_pci.c @@ -152,7 +152,7 @@ int main_pciattach(int argc, char **argv) return EXIT_SUCCESS; } =20 -static void pciassignable_list(void) +static void pciassignable_list(bool show_names) { libxl_pci_bdf *pcibdfs; int num, i; @@ -162,9 +162,15 @@ static void pciassignable_list(void) if ( pcibdfs =3D=3D NULL ) return; for (i =3D 0; i < num; i++) { - printf("%04x:%02x:%02x.%01x\n", - pcibdfs[i].domain, pcibdfs[i].bus, pcibdfs[i].dev, - pcibdfs[i].func); + libxl_pci_bdf *pcibdf =3D &pcibdfs[i]; + char *name =3D show_names ? + libxl_device_pci_assignable_bdf2name(ctx, pcibdf) : NULL; + + printf("%04x:%02x:%02x.%01x %s\n", + pcibdf->domain, pcibdf->bus, pcibdf->dev, pcibdf->func, + name ?: ""); + + free(name); } libxl_device_pci_assignable_list_free(pcibdfs, num); } @@ -172,16 +178,23 @@ static void pciassignable_list(void) int main_pciassignable_list(int argc, char **argv) { int opt; - - SWITCH_FOREACH_OPT(opt, "", NULL, "pci-assignable-list", 0) { - /* No options */ + static struct option opts[] =3D { + {"show-names", 0, 0, 'n'}, + COMMON_LONG_OPTS + }; + bool show_names =3D false; + + SWITCH_FOREACH_OPT(opt, "n", opts, "pci-assignable-list", 0) { + case 'n': + show_names =3D true; + break; } =20 - pciassignable_list(); + pciassignable_list(show_names); return 0; } =20 -static int pciassignable_add(const char *bdf, int rebind) +static int pciassignable_add(const char *bdf, const char *name, int rebind) { libxl_pci_bdf pcibdf; XLU_Config *config; @@ -197,7 +210,7 @@ static int pciassignable_add(const char *bdf, int rebin= d) exit(2); } =20 - if (libxl_device_pci_assignable_add(ctx, &pcibdf, rebind)) + if (libxl_device_pci_assignable_add(ctx, &pcibdf, name, rebind)) r =3D 1; =20 libxl_pci_bdf_dispose(&pcibdf); @@ -210,39 +223,58 @@ int main_pciassignable_add(int argc, char **argv) { int opt; const char *bdf =3D NULL; - - SWITCH_FOREACH_OPT(opt, "", NULL, "pci-assignable-add", 1) { - /* No options */ + static struct option opts[] =3D { + {"name", 1, 0, 'n'}, + COMMON_LONG_OPTS + }; + const char *name =3D NULL; + + SWITCH_FOREACH_OPT(opt, "n:", opts, "pci-assignable-add", 0) { + case 'n': + name =3D optarg; + break; } =20 bdf =3D argv[optind]; =20 - if (pciassignable_add(bdf, 1)) + if (pciassignable_add(bdf, name, 1)) return EXIT_FAILURE; =20 return EXIT_SUCCESS; } =20 -static int pciassignable_remove(const char *bdf, int rebind) +static int pciassignable_remove(const char *ident, int rebind) { - libxl_pci_bdf pcibdf; + libxl_pci_bdf *pcibdf; XLU_Config *config; int r =3D 0; =20 - libxl_pci_bdf_init(&pcibdf); - config =3D xlu_cfg_init(stderr, "command line"); if (!config) { perror("xlu_cfg_init"); exit(-1); } =20 - if (xlu_pci_parse_bdf(config, &pcibdf, bdf)) { - fprintf(stderr, "pci-assignable-remove: malformed BDF \"%s\"\n", b= df); - exit(2); + pcibdf =3D libxl_device_pci_assignable_name2bdf(ctx, ident); + if (!pcibdf) { + pcibdf =3D calloc(1, sizeof(*pcibdf)); + + if (!pcibdf) { + fprintf(stderr, + "pci-assignable-remove: failed to allocate memory\n"); + exit(2); + } + + libxl_pci_bdf_init(pcibdf); + if (xlu_pci_parse_bdf(config, pcibdf, ident)) { + fprintf(stderr, + "pci-assignable-remove: malformed BDF '%s'\n", ident); + exit(2); + } } =20 - if (libxl_device_pci_assignable_remove(ctx, &pcibdf, rebind)) + if (libxl_device_pci_assignable_remove(ctx, pcibdf, rebind)) r =3D 1; =20 - libxl_pci_bdf_dispose(&pcibdf); + libxl_pci_bdf_dispose(pcibdf); + free(pcibdf); xlu_cfg_destroy(config); =20 return r; @@ -251,7 +283,7 @@ static int pciassignable_remove(const char *bdf, int re= bind) int main_pciassignable_remove(int argc, char **argv) { int opt; - const char *bdf =3D NULL; + const char *ident =3D NULL; int rebind =3D 0; =20 SWITCH_FOREACH_OPT(opt, "r", NULL, "pci-assignable-remove", 1) { @@ -260,9 +292,9 @@ int main_pciassignable_remove(int argc, char **argv) break; } =20 - bdf =3D argv[optind]; + ident =3D argv[optind]; =20 - if (pciassignable_remove(bdf, rebind)) + if (pciassignable_remove(ident, rebind)) return EXIT_FAILURE; =20 return EXIT_SUCCESS; --=20 2.11.0 From nobody Sun May 5 11:10:29 2024 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=1603470400; cv=none; d=zohomail.com; s=zohoarc; b=mPwkRN2H1eJ84A7CEhCzxwRU1edstlo9KQEh3UJ2U+ngSJEMzYi9RFEr0/vJ7S+Nc5JgJYSAWZDObx1GPJdfPDtEEn9Tqag4ppuHLlwxrCW867i5CeUt3T2KNpPrHHR23TEAD6trVenfGSI7J/qReNSArLkBG7wfN/JMC1/dHII= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603470400; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=z+TBph7KfTXS8lKGFLMVlUTRo1VQXbbt6hL6Ha7NBXk=; b=QnArVGGNoc17vcrex3g8e9W4eBsxRf11XZp1X6+uXbNAilUA+4v6xb5JPe/nJqmVJZjl+CRP9styRwBFg1pdJ4gTaZk0tmslXZXydAnlZZBwOIs8Fdc90egU6KbSvjNU2oZILeqxiWjBzSooIr0tgn11ohj2R34stc5srlqZqS0= 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 160347040065470.00929152273216; Fri, 23 Oct 2020 09:26:40 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.11199.29693 (Exim 4.92) (envelope-from ) id 1kVztY-0000vQ-3Z; Fri, 23 Oct 2020 16:26:24 +0000 Received: by outflank-mailman (output) from mailman id 11199.29693; Fri, 23 Oct 2020 16:26:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztX-0000vJ-W8; Fri, 23 Oct 2020 16:26:23 +0000 Received: by outflank-mailman (input) for mailman id 11199; Fri, 23 Oct 2020 16:26:22 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztW-0000v2-HW for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:26:22 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 72fc22ac-891f-40a4-86ba-576ef68e6381; Fri, 23 Oct 2020 16:26:21 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztU-0008NU-Mf; Fri, 23 Oct 2020 16:26:20 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqv-000376-Fq; Fri, 23 Oct 2020 16:23:41 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztW-0000v2-HW for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:26:22 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 72fc22ac-891f-40a4-86ba-576ef68e6381; Fri, 23 Oct 2020 16:26:21 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztU-0008NU-Mf; Fri, 23 Oct 2020 16:26:20 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqv-000376-Fq; Fri, 23 Oct 2020 16:23:41 +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" X-Inumbo-ID: 72fc22ac-891f-40a4-86ba-576ef68e6381 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=z+TBph7KfTXS8lKGFLMVlUTRo1VQXbbt6hL6Ha7NBXk=; b=tT2ajUVtGFDsgz52kOM43g3eY 0D0fZHUPN6CUpJgKqD7RFc01dSyQKnlo3Bgx79oQ0D+1OVNet5uw3aPCIWVDhAOHc+d2dQAb5uUbO BFvszb4tWpOjnr6NcjSUm65EtKkJ1MoSkYqNxSDmZvW7u06HHdHaFS+rQTSc2uh0VbM60=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson , Wei Liu Subject: [PATCH 24/25] docs/man: modify xl-pci-configuration(5) to add 'name' field to PCI_SPEC_STRING Date: Fri, 23 Oct 2020 16:23:13 +0000 Message-Id: <20201023162314.2235-25-paul@xen.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20201023162314.2235-1-paul@xen.org> References: <20201023162314.2235-1-paul@xen.org> X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paul Durrant Since assignable devices can be named, a subsequent patch will support use of a PCI_SPEC_STRING containing a 'name' parameter instead of a 'bdf'. In this case the name will be used to look up the 'bdf' in the list of assigna= ble (or assigned) devices. Signed-off-by: Paul Durrant Acked-by: Christian Lindig --- Cc: Ian Jackson Cc: Wei Liu --- docs/man/xl-pci-configuration.5.pod | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/docs/man/xl-pci-configuration.5.pod b/docs/man/xl-pci-configur= ation.5.pod index 4dd73bc498..db3360307c 100644 --- a/docs/man/xl-pci-configuration.5.pod +++ b/docs/man/xl-pci-configuration.5.pod @@ -51,7 +51,7 @@ is not specified, or if it is specified with an empty val= ue (whether positionally or explicitly). =20 B: In context of B (see L), parameters other t= han -B will be ignored. +B or B will be ignored. =20 =3Dhead1 Positional Parameters =20 @@ -70,7 +70,11 @@ B<*> to indicate all functions of a multi-function devic= e. =20 =3Ditem Default Value =20 -None. This parameter is mandatory as it identifies the device. +None. This parameter is mandatory in its positional form. As a non-positio= nal +parameter it is also mandatory unless a B parameter is present, in +which case B must not be present since the B will be used to fi= nd +the B in the list of assignable devices. See L for more inform= ation +on naming assignable devices. =20 =3Dback =20 @@ -194,4 +198,21 @@ B: This overrides the global B option. =20 =3Dback =20 +=3Ditem B=3DI + +=3Dover 4 + +=3Ditem Description + +This is the name given when the B was made assignable. See L f= or +more information on naming assignable devices. + +=3Ditem Default Value + +None. This parameter must not be present if a B parameter is present. +If a B parameter is not present then B is mandatory as it is +required to look up the B in the list of assignable devices. + +=3Dback + =3Dback --=20 2.11.0 From nobody Sun May 5 11:10:29 2024 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=1603470431; cv=none; d=zohomail.com; s=zohoarc; b=YygEX0Uql1y5o5Ni/XiIPJVYs8uUHu/ojV+77KOhXHtcbRGcMN5cZXFXsfMJjwV1MRkJ1UDsiHvISwAxrsbb9EKFyLQqqo+4+Skd7g8kYX15ev+tBJNbaiX+NcB90fOP9v2CFNbAtI4fO7OyfUdtmob6iVH91RiM1sR/g0x8kw8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603470431; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=xc8Rt4FNyf81W81G3gNl5AS6+YoOb+nL0S+vPdlRodM=; b=DEsV7X48bnup2+v2Qpcr8w8Yfuc95IywYMoUCzebcCUabHc9TH9Cy24nANGUwGgYcZVnLoh3W0cur/Wss5izwovwrmLTzhGTnhRuYvC9y9FVQ9TRrADUSTkzdd1oO4dydDEAs5kHETa06eKc3n8xMMRbGsMPd6DD/e7Oeia6Hz0= 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 1603470430994217.98140915734848; Fri, 23 Oct 2020 09:27:10 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.11214.29837 (Exim 4.92) (envelope-from ) id 1kVzu2-0001nl-0v; Fri, 23 Oct 2020 16:26:54 +0000 Received: by outflank-mailman (output) from mailman id 11214.29837; Fri, 23 Oct 2020 16:26:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzu1-0001nX-Pw; Fri, 23 Oct 2020 16:26:53 +0000 Received: by outflank-mailman (input) for mailman id 11214; Fri, 23 Oct 2020 16:26:52 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzu0-0000v2-Gx for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:26:52 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 1f5ada0d-630a-4352-a9a4-a759950906c0; Fri, 23 Oct 2020 16:26:22 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztU-0008Nk-Tw; Fri, 23 Oct 2020 16:26:20 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqw-000376-Cy; Fri, 23 Oct 2020 16:23:42 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVzu0-0000v2-Gx for xen-devel@lists.xenproject.org; Fri, 23 Oct 2020 16:26:52 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 1f5ada0d-630a-4352-a9a4-a759950906c0; Fri, 23 Oct 2020 16:26:22 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kVztU-0008Nk-Tw; Fri, 23 Oct 2020 16:26:20 +0000 Received: from ec2-18-200-132-236.eu-west-1.compute.amazonaws.com ([18.200.132.236] helo=ip-10-0-185-232.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kVzqw-000376-Cy; Fri, 23 Oct 2020 16:23:42 +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" X-Inumbo-ID: 1f5ada0d-630a-4352-a9a4-a759950906c0 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=xc8Rt4FNyf81W81G3gNl5AS6+YoOb+nL0S+vPdlRodM=; b=jpkOw9P+gXjavbrsUKHlCAFP8 RWwQDAW5Af6QjdsjUWpRZ5pyHuTHZPSbO2dYpetDWaHddBykEDl06tpDFXYMM/YqYGm1IO6Pxp7Sx fnLTMK21Sla90Bv9zkpn2SuDmq6IccqRrzdKxidRr82l/OCUVdhXDNO4JmsgULxHCozjk=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH 25/25] xl / libxl: support 'xl pci-attach/detach' by name Date: Fri, 23 Oct 2020 16:23:14 +0000 Message-Id: <20201023162314.2235-26-paul@xen.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20201023162314.2235-1-paul@xen.org> References: <20201023162314.2235-1-paul@xen.org> X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paul Durrant 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 Acked-by: Christian Lindig --- Cc: Ian Jackson Cc: Wei Liu Cc: Anthony PERARD --- 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 ++++- tools/xl/xl_pci.c | 1 + 5 files changed, 76 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 =20 /* + * 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 0f7d655aff..e5d54732c3 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 *g= c, 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.bu= s, pci->bdf.dev, pci->bdf.func)); flexarray_append(back, GCSPRINTF("dev-%d", num)); @@ -252,6 +256,7 @@ retry_transaction: =20 retry_transaction2: t =3D 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)); @@ -290,6 +295,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 =3D GCSPRINTF("%s/name-%d", be_path, j); + tmp =3D 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 =3D=3D EAGAIN) @@ -1586,6 +1597,23 @@ void libxl__device_pci_add(libxl__egc *egc, uint32_t= domid, pas->starting =3D starting; pas->callback =3D device_pci_add_stubdom_done; =20 + if (pci->name) { + libxl_pci_bdf *pcibdf =3D + libxl_device_pci_assignable_name2bdf(CTX, pci->name); + + if (!pcibdf) { + rc =3D 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) =3D=3D LIBXL_DOMAIN_TYPE_HVM) { rc =3D xc_test_assign_device(ctx->xch, domid, pci_encode_bdf(&pci->bdf)); @@ -1734,11 +1762,19 @@ static void device_pci_add_done(libxl__egc *egc, libxl_device_pci *pci =3D &pas->pci; =20 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.fun= c, + rc); + } pci_info_xs_remove(gc, &pci->bdf, "domid"); } libxl_device_pci_dispose(pci); @@ -2284,6 +2320,23 @@ static void libxl__device_pci_remove_common(libxl__e= gc *egc, libxl__ev_time_init(&prs->timeout); libxl__ev_time_init(&prs->retry_timer); =20 + if (pci->name) { + libxl_pci_bdf *pcibdf =3D + libxl_device_pci_assignable_name2bdf(CTX, pci->name); + + if (!pcibdf) { + rc =3D 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 =3D pci->vdevfn & ~7U; =20 if ( pci->vfunc_mask =3D=3D LIBXL_PCI_FUNC_ALL ) { @@ -2418,6 +2471,10 @@ static int libxl__device_pci_from_xs_be(libxl__gc *g= c, } while ((p =3D strtok_r(NULL, ",=3D", &saveptr)) !=3D NULL); } =20 + s =3D libxl__xs_read(gc, XBT_NULL, GCSPRINTF("%s/name-%d", be_path, nr= )); + if (s) + pci->name =3D strdup(s); + return 0; } =20 diff --git a/tools/libs/light/libxl_types.idl b/tools/libs/light/libxl_type= s.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 =3D Struct("pci_bdf", [ =20 libxl_device_pci =3D 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_de= vice_pci *pcidev, { const char *ptr =3D str; bool bdf_present =3D false; + bool name_present =3D false; int ret; =20 /* Attempt to parse 'bdf' as positional parameter */ @@ -193,6 +194,10 @@ int xlu_pci_parse_spec_string(XLU_Config *cfg, libxl_d= evice_pci *pcidev, pcidev->power_mgmt =3D atoi(val); } else if (!strcmp(key, "rdm_policy")) { ret =3D parse_rdm_policy(cfg, &pcidev->rdm_policy, val); + } else if (!strcmp(key, "name")) { + name_present =3D true; + pcidev->name =3D strdup(val); + if (!pcidev->name) ret =3D ERROR_NOMEM; } else { XLU__PCI_ERR(cfg, "Unknown PCI_SPEC_STRING option: %s", key); ret =3D ERROR_INVAL; @@ -205,7 +210,7 @@ int xlu_pci_parse_spec_string(XLU_Config *cfg, libxl_de= vice_pci *pcidev, return ret; } =20 - if (!bdf_present) + if (!(bdf_present ^ name_present)) return ERROR_INVAL; =20 return 0; diff --git a/tools/xl/xl_pci.c b/tools/xl/xl_pci.c index f1b58b3976..1f89fed6db 100644 --- a/tools/xl/xl_pci.c +++ b/tools/xl/xl_pci.c @@ -71,6 +71,7 @@ static int pcidetach(uint32_t domid, const char *spec_str= ing, int force) spec_string); exit(2); } + if (force) { if (libxl_device_pci_destroy(ctx, domid, &pci, 0)) r =3D 1; --=20 2.11.0