From nobody Fri May 3 17:53:33 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=1609868824; cv=none; d=zohomail.com; s=zohoarc; b=hJb9zhTsJRqZoiPO1PyOCjG3Q70CBhrYuwImfcETM8cBfgzO/M6CD+sisAwYQQVnjyB/DdZh1svPekUaoOGs70WLKzpc2JNTlsJLvg3yWQqzzgGxHXg4yl/4nEhuHtn7M7dCEjGrVjgHCAnt+S4FvmJYW/E4yxddtKwz7KFbdEY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609868824; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=Y8PbmtYpQowGDJUtA704ovt/LSU9vc1pqSwcHoxEmjg=; b=JrLkWYphvGF0bD9j1gQYb8tvrENQ7woSWtlXwzuIr39tKoKUpkFj4alkXLnyo5usebPqxI1NOOnOTXFnvzBE6F7OZs/BnMACcKWwuH++fMVh01XFOv5lou7lNmTjJar8VxgsTXTCcOEUsYKdXiCz0JZVUwAHdFupReG29pTQ7LM= 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 1609868824736868.733078855813; Tue, 5 Jan 2021 09:47:04 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.62110.109777 (Exim 4.92) (envelope-from ) id 1kwqPx-0005PA-HM; Tue, 05 Jan 2021 17:46:49 +0000 Received: by outflank-mailman (output) from mailman id 62110.109777; Tue, 05 Jan 2021 17:46: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 1kwqPx-0005P2-Db; Tue, 05 Jan 2021 17:46:49 +0000 Received: by outflank-mailman (input) for mailman id 62110; Tue, 05 Jan 2021 17:46:48 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwqPw-0005OQ-4N for xen-devel@lists.xenproject.org; Tue, 05 Jan 2021 17:46:48 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwqPv-0006IJ-Ps; Tue, 05 Jan 2021 17:46:47 +0000 Received: from ec2-34-243-106-223.eu-west-1.compute.amazonaws.com ([34.243.106.223] helo=ip-10-0-70-185.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 1kwqPv-0008Uy-IE; Tue, 05 Jan 2021 17:46:47 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=Y8PbmtYpQowGDJUtA704ovt/LSU9vc1pqSwcHoxEmjg=; b=hkac7kaicppGsyHdEXWkiMd4e 1cr9lH9OTqO3WutvRnnpP9xDVvqzOjGuzjkMob5DcmdQA7yrmFd4i5KO6heS+aZy2gUdR5v9bVzWF IaJeV3iSc4MPHO7lzWfrr2LL7vIJE8+LH/c13NV1bMP+xlNzvEDehUXtn/OffCm7RmcSE=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson Subject: [PATCH v7 1/7] docs/man: modify xl(1) in preparation for naming of assignable devices Date: Tue, 5 Jan 2021 17:46:36 +0000 Message-Id: <20210105174642.2754-2-paul@xen.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20210105174642.2754-1-paul@xen.org> References: <20210105174642.2754-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: Wei Liu --- Cc: Ian Jackson --- 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 af31d2b572..f4779d8fd6 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 Fri May 3 17:53:33 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=1609868829; cv=none; d=zohomail.com; s=zohoarc; b=kuAyd/xeE1JllESv/kO/ob7IpF89eyqs6cIj3rdroAABkArcn5W0Gfhnj7iKV110KZ1ilx0ZyJKgikoLDQBVVI7VGbRSkoTuEVLDXJNXUN9vlXiGOAZBh5Bgsa6PAITTsAvIce03jchiGFGMIlbuL3o2IP81yxllHd/AJoPA/Oc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609868829; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=oVtJ/C3vayU/ao/I9CuvP/SpK2XVKc9hIKIhYK8WrYE=; b=Y6UAfyUFfUuCCGrVVvEJjJdQ0kgDVo/7RA4/61nKIe7JDBOdFMUNEwbBs2Mhx0FcmP7F1oNFv/tRNpXuUi2DANmy/IrtPsYWbBnsBcbt8UX3Y2b9SWflOBwCvXxPKXsyM5UvXja0hpnODbu5neTTvFdVKcV/zzhFd7kXGxO4oGY= 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 1609868829022666.9660904533017; Tue, 5 Jan 2021 09:47:09 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.62112.109789 (Exim 4.92) (envelope-from ) id 1kwqPy-0005RB-SX; Tue, 05 Jan 2021 17:46:50 +0000 Received: by outflank-mailman (output) from mailman id 62112.109789; Tue, 05 Jan 2021 17:46: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 1kwqPy-0005R0-OW; Tue, 05 Jan 2021 17:46:50 +0000 Received: by outflank-mailman (input) for mailman id 62112; Tue, 05 Jan 2021 17:46:48 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwqPw-0005Op-Sl for xen-devel@lists.xenproject.org; Tue, 05 Jan 2021 17:46:48 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwqPw-0006IO-Lp; Tue, 05 Jan 2021 17:46:48 +0000 Received: from ec2-34-243-106-223.eu-west-1.compute.amazonaws.com ([34.243.106.223] helo=ip-10-0-70-185.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 1kwqPw-0008Uy-B7; Tue, 05 Jan 2021 17:46:48 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=oVtJ/C3vayU/ao/I9CuvP/SpK2XVKc9hIKIhYK8WrYE=; b=ZCYAMT7wuRRttdcXN6y6Vy5nA wF5yw+CFQsUZkPFLUW729hkEknJcLsF9q4yt+vYlyUS7lhgkgRBdyQEDCnYiDXo+b5mxqyEI37oRQ AgczVoKVMPd0DpvW93zu9nI8Z6C7m7dKhKvK/WT8FVL9caTSTw+nMRJvzR4mDevNE2m30=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson , Anthony PERARD Subject: [PATCH v7 2/7] libxlu: introduce xlu_pci_parse_spec_string() Date: Tue, 5 Jan 2021 17:46:37 +0000 Message-Id: <20210105174642.2754-3-paul@xen.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20210105174642.2754-1-paul@xen.org> References: <20210105174642.2754-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. As a side-effect this patch also fixes a bug where using '*' to speci= fy all functions would lead to an assertion failure at the end of xlu_pci_parse_bdf(). Fixes: d25cc3ec93eb ("libxl: workaround gcc 10.2 maybe-uninitialized warnin= g") Signed-off-by: Paul Durrant Acked-by: Wei Liu --- Cc: Ian Jackson Cc: Anthony PERARD v7: - Minor modifications now that the 'libxl_pci_bdf' type no longer exists - Modifications are largely mechanical so Wei's A-b is retained --- tools/include/libxlutil.h | 8 +- tools/libs/util/libxlu_pci.c | 348 +++++++++++++++++++++++----------------= ---- tools/xl/xl_cmdtable.c | 4 +- tools/xl/xl_parse.c | 4 +- tools/xl/xl_pci.c | 33 ++-- 5 files changed, 213 insertions(+), 184 deletions(-) diff --git a/tools/include/libxlutil.h b/tools/include/libxlutil.h index 92e35c5462..4dd3c5e92b 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_device_pci *pci, 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 1d38fffce3..05472a0bd1 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,209 @@ #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_device_pci *pci, 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; - return 0; -} + 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 '*') { + pci->vfunc_mask =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; + pci->vfunc_mask =3D 1; + ptr +=3D n; + } =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) -{ pci->domain =3D domain; pci->bus =3D bus; pci->dev =3D dev; pci->func =3D func; - pci->vdevfn =3D vdevfn; + + 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_vslot(uint32_t *vdevfnp, const char *str, const char **en= dp) { - 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; + 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; +} + +static int parse_key_val(char **keyp, char**valp, const char *str, + const char **endp) +{ + const char *ptr =3D str; + char *key, *val; + + while (*ptr !=3D '=3D' && *ptr !=3D '\0') + ptr++; + + if (*ptr =3D=3D '\0') + return ERROR_INVAL; =20 - if ( NULL =3D=3D (buf2 =3D ptr =3D strdup(str)) ) + 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_device_pci *pci, const char *= str) +{ + return parse_bdf(pci, str, NULL); +} + +int xlu_pci_parse_spec_string(XLU_Config *cfg, libxl_device_pci *pci, + 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(pci, ptr, &ptr); + if (!ret) { + bdf_present =3D true; + + /* Check whether 'vslot' if present */ + if (*ptr =3D=3D '@') { + ret =3D parse_vslot(&pci->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(pci, val, NULL); + if (!ret) bdf_present =3D true; + } else if (!strcmp(key, "vslot")) { + ret =3D parse_vslot(&pci->vdevfn, val, NULL); + } else if (!strcmp(key, "permissive")) { + pci->permissive =3D atoi(val); + } else if (!strcmp(key, "msitranslate")) { + pci->msitranslate =3D atoi(val); + } else if (!strcmp(key, "seize")) { + pci->seize=3D atoi(val); + } else if (!strcmp(key, "power_mgmt")) { + pci->power_mgmt =3D atoi(val); + } else if (!strcmp(key, "rdm_policy")) { + ret =3D parse_rdm_policy(cfg, &pci->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 +253,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 +272,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 6ab5e47da3..30e17a2848 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 4ebf39620a..867e4d068a 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 f71498cbb5..9a66494bb5 100644 --- a/tools/xl/xl_pci.c +++ b/tools/xl/xl_pci.c @@ -54,7 +54,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; @@ -65,8 +65,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) { @@ -88,7 +89,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': @@ -97,15 +98,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; @@ -116,8 +117,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 @@ -134,19 +136,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; @@ -192,7 +191,7 @@ static int pciassignable_add(const char *bdf, int rebin= d) 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); + fprintf(stderr, "pci-assignable-add: malformed BDF \"%s\"\n", bdf); exit(2); } =20 @@ -234,7 +233,7 @@ static int pciassignable_remove(const char *bdf, int re= bind) 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); + fprintf(stderr, "pci-assignable-remove: malformed BDF \"%s\"\n", b= df); exit(2); } =20 --=20 2.11.0 From nobody Fri May 3 17:53:33 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=1609868826; cv=none; d=zohomail.com; s=zohoarc; b=nGTX9DqrVIJIBl3peS0G6rwVPaStb2/eqLPeCCyOb7HPwY1qlpIpNMoxrkTHWVcnf+jeej/Z219fpTAcpEOC3h6uK+Z/kymyfM/z/4kvRPLweCHaogSwRUbT68/VqMr6p61eJc9fVOQA8CUYgdBv6Um5DYqVrqYjEBOB5PD6EXg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609868826; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=K1MwrGPkpl0wTZhvU83OdsZZBnyluFntSpoxzfHcZw4=; b=bMSkaIwVmKqeHYv5NC+iUVv57xyslYR2gj01SOmRWE2AUFrLXP+dhvWscahLXWzcZgiL+t09j4W7cZPD3dmhiLtT2xpNsb6FMV98PyUNowXcEAAWlNh2WQb0eC/lyF7f3+oWkhIu1jQ7Q3Fm99SCZBRrBI9aI+ZJFSj/NX8p5PM= 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 1609868826437757.520921172953; Tue, 5 Jan 2021 09:47:06 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.62113.109801 (Exim 4.92) (envelope-from ) id 1kwqQ0-0005TR-5s; Tue, 05 Jan 2021 17:46:52 +0000 Received: by outflank-mailman (output) from mailman id 62113.109801; Tue, 05 Jan 2021 17:46:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwqQ0-0005TI-1D; Tue, 05 Jan 2021 17:46:52 +0000 Received: by outflank-mailman (input) for mailman id 62113; Tue, 05 Jan 2021 17:46:50 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwqPy-0005QY-2Y for xen-devel@lists.xenproject.org; Tue, 05 Jan 2021 17:46:50 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwqPx-0006IT-Ed; Tue, 05 Jan 2021 17:46:49 +0000 Received: from ec2-34-243-106-223.eu-west-1.compute.amazonaws.com ([34.243.106.223] helo=ip-10-0-70-185.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 1kwqPx-0008Uy-7J; Tue, 05 Jan 2021 17:46:49 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=K1MwrGPkpl0wTZhvU83OdsZZBnyluFntSpoxzfHcZw4=; b=pd3UgDS6lRoHTpLQ0b54nnhKA aniOe2Zq5KlCR8r94pnJAmP+utCoUQgQ4e8y4Jstfh2OKiHy6aWe8P0J7FFE8wEP/5cvtZ50+OT6c ZQ9mTOp2tThWwb7xS3pzX/Lk2PZ7hESE/haYOPJdw8EaP/ltr9ZLdkc31RxBKhS6tBSmM=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH v7 3/7] libxl: stop setting 'vdevfn' in pci_struct_fill() Date: Tue, 5 Jan 2021 17:46:38 +0000 Message-Id: <20210105174642.2754-4-paul@xen.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20210105174642.2754-1-paul@xen.org> References: <20210105174642.2754-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 There are only two call-sites. One always sets it to 0 (which is unnecessary as the structure is already initialized to zero) and the other can simply s= et the 'vdevfn' field directly (after proper structure initialization), avoidi= ng the need for a local variable. A subsequent patch will also make use of pci_struct_fill() in a context where 'vdevfn' may already have been set. Signed-off-by: Paul Durrant Acked-by: Wei Liu --- Cc: Ian Jackson Cc: Wei Liu Cc: Anthony PERARD v7: - New in v7 --- tools/libs/light/libxl_pci.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tools/libs/light/libxl_pci.c b/tools/libs/light/libxl_pci.c index 74c2196ae3..6feedadc62 100644 --- a/tools/libs/light/libxl_pci.c +++ b/tools/libs/light/libxl_pci.c @@ -39,13 +39,12 @@ static unsigned int pci_encode_bdf(libxl_device_pci *pc= i) =20 static void pci_struct_fill(libxl_device_pci *pci, unsigned int domain, unsigned int bus, unsigned int dev, - unsigned int func, unsigned int vdevfn) + unsigned int func) { 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, @@ -451,7 +450,7 @@ libxl_device_pci *libxl_device_pci_assignable_list(libx= l_ctx *ctx, int *num) new =3D pcis + *num; =20 libxl_device_pci_init(new); - pci_struct_fill(new, dom, bus, dev, func, 0); + pci_struct_fill(new, dom, bus, dev, func); =20 if (pci_info_xs_read(gc, new, "domid")) /* already assigned */ continue; @@ -2288,17 +2287,19 @@ static int libxl__device_pci_from_xs_be(libxl__gc *= gc, libxl_devid nr, void *data) { char *s; - unsigned int domain =3D 0, bus =3D 0, dev =3D 0, func =3D 0, vdevfn = =3D 0; + unsigned int domain =3D 0, bus =3D 0, dev =3D 0, func =3D 0; libxl_device_pci *pci =3D data; =20 + libxl_device_pci_init(pci); + s =3D libxl__xs_read(gc, XBT_NULL, GCSPRINTF("%s/dev-%d", be_path, nr)= ); sscanf(s, PCI_BDF, &domain, &bus, &dev, &func); =20 + pci_struct_fill(pci, domain, bus, dev, func); + s =3D libxl__xs_read(gc, XBT_NULL, GCSPRINTF("%s/vdevfn-%d", be_path, = nr)); if (s) - vdevfn =3D strtol(s, (char **) NULL, 16); - - pci_struct_fill(pci, domain, bus, dev, func, vdevfn); + pci->vdevfn =3D strtol(s, (char **) NULL, 16); =20 s =3D libxl__xs_read(gc, XBT_NULL, GCSPRINTF("%s/opts-%d", be_path, nr= )); if (s) { --=20 2.11.0 From nobody Fri May 3 17:53:33 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=1609868827; cv=none; d=zohomail.com; s=zohoarc; b=dMnIm3MdR5VPhOsk20pRtm6z0zD5yvCdwSyNOhLHCsjInP0stz5HVHsCR64hN7MOZYlaBEOIQm5p5IVON7tZKvCIWgzIJWcs3Rr3vKCGgXaJvEZkgANN86K739MFdXwLi2g05H6qZd7tBBbac95XgtR76en8NOI263Ajx/ip7qU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609868827; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=cuL69JTKNTU5sfYZEI8VcKnFuX1xEw0L2aW+VMRrfNo=; b=Nf0xI0NVt4cqtn64xKbGEwjeUHLLcik4ZR+BRr8zqDpJDp1PUC+RJWGx6qnUHfJmXSOA8Erf801OkgDmMQ8Evc3NMDrNFOA2Imz0sK/5oZdkwfn0ZaWa4X+GYkz5puCHQYvs+wsSLzv+N8UH7GpE48P4tzMKLEy4v/h+fOUBLJk= 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 1609868827483342.1136240220902; Tue, 5 Jan 2021 09:47:07 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.62114.109810 (Exim 4.92) (envelope-from ) id 1kwqQ0-0005VQ-Ui; Tue, 05 Jan 2021 17:46:52 +0000 Received: by outflank-mailman (output) from mailman id 62114.109810; Tue, 05 Jan 2021 17:46:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwqQ0-0005V5-MP; Tue, 05 Jan 2021 17:46:52 +0000 Received: by outflank-mailman (input) for mailman id 62114; Tue, 05 Jan 2021 17:46:51 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwqPz-0005Rr-39 for xen-devel@lists.xenproject.org; Tue, 05 Jan 2021 17:46:51 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwqPy-0006Ia-Am; Tue, 05 Jan 2021 17:46:50 +0000 Received: from ec2-34-243-106-223.eu-west-1.compute.amazonaws.com ([34.243.106.223] helo=ip-10-0-70-185.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 1kwqPy-0008Uy-3L; Tue, 05 Jan 2021 17:46:50 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=cuL69JTKNTU5sfYZEI8VcKnFuX1xEw0L2aW+VMRrfNo=; b=MSDIID+qu8oMZY9IJLtYhrYPc ccCg3xWDOH9W2iOU9WYsh0qwSeCIJCUuanWKnE6CmqnjXLqz6zOjvBOqTiOxbSwFI49gu/aZwHH6R ng3BrMPBvKnQYO6/62vNddDZR3fRf2eJFI12JKJoxxlSzyGiGyzscS9S7q0F9Tq6fKT28=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH v7 4/7] libxl: add 'name' field to 'libxl_device_pci' in the IDL... Date: Tue, 5 Jan 2021 17:46:39 +0000 Message-Id: <20210105174642.2754-5-paul@xen.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20210105174642.2754-1-paul@xen.org> References: <20210105174642.2754-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 modify libxl_pci_bdf_assignable_add/remove/list() to make use of it. libxl_pci_bdf_assignable_add() will store the name of the device in xenstore if the field is specified (i.e. non-NULL) and libxl_pci_bdf_assignable_remo= ve() will remove devices specified only by name, looking up the BDF as necessary. libxl_pci_bdf_assignable_list() will also populate the 'name' field if a na= me was stored by libxl_pci_bdf_assignable_add(). NOTE: This patch also fixes whitespace in the declaration of 'libxl_device_= pci' in the IDL. Signed-off-by: Paul Durrant Acked-by: Wei Liu --- Cc: Ian Jackson Cc: Wei Liu Cc: Anthony PERARD v7: - New in v7 --- tools/include/libxl.h | 6 ++++ tools/libs/light/libxl_pci.c | 77 ++++++++++++++++++++++++++++++++++++= ++-- tools/libs/light/libxl_types.idl | 13 +++---- 3 files changed, 87 insertions(+), 9 deletions(-) diff --git a/tools/include/libxl.h b/tools/include/libxl.h index 3433c950f9..3488fbf56f 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_DEVICE_PCI_NAME indicates that the libxl_device_pci type + * has a name field. + */ +#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 6feedadc62..9e3a90dcda 100644 --- a/tools/libs/light/libxl_pci.c +++ b/tools/libs/light/libxl_pci.c @@ -438,7 +438,9 @@ libxl_device_pci *libxl_device_pci_assignable_list(libx= l_ctx *ctx, int *num) } =20 while((de =3D readdir(dir))) { - unsigned dom, bus, dev, func; + unsigned int dom, bus, dev, func; + char *name; + if (sscanf(de->d_name, PCI_BDF, &dom, &bus, &dev, &func) !=3D 4) continue; =20 @@ -455,6 +457,9 @@ libxl_device_pci *libxl_device_pci_assignable_list(libx= l_ctx *ctx, int *num) if (pci_info_xs_read(gc, new, "domid")) /* already assigned */ continue; =20 + name =3D pci_info_xs_read(gc, new, "name"); + if (name) new->name =3D strdup(name); + (*num)++; } =20 @@ -742,6 +747,7 @@ static int libxl__device_pci_assignable_add(libxl__gc *= gc, libxl_ctx *ctx =3D libxl__gc_owner(gc); unsigned dom, bus, dev, func; char *spath, *driver_path =3D NULL; + const char *name; int rc; struct stat st; =20 @@ -750,6 +756,24 @@ static int libxl__device_pci_assignable_add(libxl__gc = *gc, bus =3D pci->bus; dev =3D pci->dev; func =3D pci->func; + name =3D pci->name; + + /* Sanitise any name that is set */ + 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; + } + } + } =20 /* See if the device exists */ spath =3D GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF, dom, bus, dev, func); @@ -765,7 +789,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 */ @@ -796,7 +820,12 @@ static int libxl__device_pci_assignable_add(libxl__gc = *gc, return ERROR_FAIL; } =20 -quarantine: +name: + if (name) + pci_info_xs_write(gc, pci, "name", name); + else + pci_info_xs_remove(gc, pci, "name"); + /* * DOMID_IO is just a sentinel domain, without any actual mappings, * so always pass XEN_DOMCTL_DEV_RDM_RELAXED to avoid assignment being @@ -812,6 +841,40 @@ quarantine: return 0; } =20 +static int name2bdf(libxl__gc *gc, libxl_device_pci *pci) +{ + char **bdfs; + unsigned int i, n; + int rc =3D ERROR_NOTFOUND; + + bdfs =3D libxl__xs_directory(gc, XBT_NULL, PCI_INFO_PATH, &n); + if (!n) + goto out; + + for (i =3D 0; i < n; i++) { + unsigned dom, bus, dev, func; + char *name; + + if (sscanf(bdfs[i], PCI_BDF_XSPATH, &dom, &bus, &dev, &func) !=3D = 4) + continue; + + pci_struct_fill(pci, dom, bus, dev, func); + + name =3D pci_info_xs_read(gc, pci, "name"); + if (name && !strcmp(name, pci->name)) { + rc =3D 0; + break; + } + } + +out: + if (!rc) + LOG(DETAIL, "'%s' -> " PCI_BDF, pci->name, pci->domain, + pci->bus, pci->dev, pci->func); + + return rc; +} + static int libxl__device_pci_assignable_remove(libxl__gc *gc, libxl_device_pci *pci, int rebind) @@ -820,6 +883,12 @@ static int libxl__device_pci_assignable_remove(libxl__= gc *gc, int rc; char *driver_path; =20 + /* If the device is named then we need to look up the BDF */ + if (pci->name) { + rc =3D name2bdf(gc, pci); + if (rc) return rc; + } + /* De-quarantine */ rc =3D xc_deassign_device(ctx->xch, DOMID_IO, pci_encode_bdf(pci)); if ( rc < 0 ) { @@ -860,6 +929,8 @@ static int libxl__device_pci_assignable_remove(libxl__g= c *gc, } } =20 + pci_info_xs_remove(gc, pci, "name"); + return 0; } =20 diff --git a/tools/libs/light/libxl_types.idl b/tools/libs/light/libxl_type= s.idl index 05324736b7..b4a9076b85 100644 --- a/tools/libs/light/libxl_types.idl +++ b/tools/libs/light/libxl_types.idl @@ -771,17 +771,18 @@ libxl_device_nic =3D Struct("device_nic", [ ]) =20 libxl_device_pci =3D Struct("device_pci", [ - ("func", uint8), - ("dev", uint8), - ("bus", uint8), - ("domain", integer), - ("vdevfn", uint32), + ("func", uint8), + ("dev", uint8), + ("bus", uint8), + ("domain", integer), + ("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), + ("name", string), ]) =20 libxl_device_rdm =3D Struct("device_rdm", [ --=20 2.11.0 From nobody Fri May 3 17:53:33 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=1609868827; cv=none; d=zohomail.com; s=zohoarc; b=lmLDxtABDgDug9QWYv5ntnv42kjWYLZVsDHhhco7k45VnZpav3+dVZq8hd0MSRRI39Qo4lilRUyuWe3NbXBSt4NVQooUV+HNSkGX+OZkag9auFO1Qaaf3mtHRaD0LHu+snOPYMbMKdKpRySteNZYhqUHeO6PmtCmIF3pBUE0YX4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609868827; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=mp9JJogkbVM9zNQc7dIMuCQa7vYObqg8Lb80h6tIDAc=; b=EO9wEZX2vWpyGQGa0IfNtc6gvbL8ACs4+Ia5FngC5T3QMoMR05QAuSkD+b67e4byhnizJRibqc3fazzOjOr3zgY/uJS2aE9MLf7TGEARzzuUaGBURn7eHMQwYLosAQ9vguLftqa2dKpAyVwFFyaKgi3x/SKpwN9/t1LV3a+eSUs= 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 1609868827875995.7400962412734; Tue, 5 Jan 2021 09:47:07 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.62115.109816 (Exim 4.92) (envelope-from ) id 1kwqQ1-0005Wu-Ih; Tue, 05 Jan 2021 17:46:53 +0000 Received: by outflank-mailman (output) from mailman id 62115.109816; Tue, 05 Jan 2021 17:46: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 1kwqQ1-0005WT-6T; Tue, 05 Jan 2021 17:46:53 +0000 Received: by outflank-mailman (input) for mailman id 62115; Tue, 05 Jan 2021 17:46:51 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwqPz-0005T6-Ro for xen-devel@lists.xenproject.org; Tue, 05 Jan 2021 17:46:51 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwqPz-0006Ih-7j; Tue, 05 Jan 2021 17:46:51 +0000 Received: from ec2-34-243-106-223.eu-west-1.compute.amazonaws.com ([34.243.106.223] helo=ip-10-0-70-185.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 1kwqPy-0008Uy-Vd; Tue, 05 Jan 2021 17:46:51 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=mp9JJogkbVM9zNQc7dIMuCQa7vYObqg8Lb80h6tIDAc=; b=34pAiUW+C7SGyVpGexlMOQrom G6dbYwXlOZ+3a4zr9P/ihHiC/uYZRqBRjBmgE0UMEX+a1K6oGHnrBb7eNTRG6B0yqgy5iKXkxrnEx SDpgYLpGewRafwjTvt+kQ/H3xURQWBtwRGg60QEpKeENX6/vzcrc9EktPaFbQ2RDfPADs=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH v7 5/7] xl: support naming of assignable devices Date: Tue, 5 Jan 2021 17:46:40 +0000 Message-Id: <20210105174642.2754-6-paul@xen.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20210105174642.2754-1-paul@xen.org> References: <20210105174642.2754-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 With this patch applied 'xl pci-assignable-add' will take an optional '--na= me' parameter, 'xl pci-assignable-remove' can be passed either a BDF or a name = and 'xl pci-assignable-list' will take a optional '--show-names' flag which determines whether names are displayed in its output. Signed-off-by: Paul Durrant Acked-by: Wei Liu --- Cc: Ian Jackson Cc: Wei Liu Cc: Anthony PERARD v7: - Heavily re-worked, bearing only some resemblance to similarly named v6 p= atch --- tools/xl/xl_cmdtable.c | 12 ++++--- tools/xl/xl_pci.c | 89 ++++++++++++++++++++++++++++++++++++----------= ---- 2 files changed, 73 insertions(+), 28 deletions(-) diff --git a/tools/xl/xl_cmdtable.c b/tools/xl/xl_cmdtable.c index 30e17a2848..bd8af12ff3 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 9a66494bb5..b1c3ae2a72 100644 --- a/tools/xl/xl_pci.c +++ b/tools/xl/xl_pci.c @@ -151,7 +151,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_device_pci *pcis; int num, i; @@ -161,8 +161,12 @@ static void pciassignable_list(void) if ( pcis =3D=3D NULL ) 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); + libxl_device_pci *pci =3D &pcis[i]; + char *name =3D show_names ? pci->name : NULL; + + printf("%04x:%02x:%02x.%01x %s\n", + pci->domain, pci->bus, pci->dev, pci->func, + name ?: ""); } libxl_device_pci_assignable_list_free(pcis, num); } @@ -170,20 +174,27 @@ 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_device_pci pci; XLU_Config *config; - int r =3D 0; + int r; =20 libxl_device_pci_init(&pci); =20 @@ -195,8 +206,15 @@ static int pciassignable_add(const char *bdf, int rebi= nd) exit(2); } =20 - if (libxl_device_pci_assignable_add(ctx, &pci, rebind)) - r =3D 1; + if (name) { + pci.name =3D strdup(name); + if (!pci.name) { + fprintf(stderr, "pci-assignable-add: memory allocation failure= \n"); + exit(2); + } + } + + r =3D libxl_device_pci_assignable_add(ctx, &pci, rebind); =20 libxl_device_pci_dispose(&pci); xlu_cfg_destroy(config); @@ -208,38 +226,61 @@ 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", 1) { + 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_device_pci pci; XLU_Config *config; - int r =3D 0; + int r; =20 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, &pci, bdf)) { - fprintf(stderr, "pci-assignable-remove: malformed BDF \"%s\"\n", b= df); + /* Try remove-by-name first */ + pci.name =3D strdup(ident); + if (!pci.name) { + fprintf(stderr, "pci-assignable-add: memory allocation failure\n"); exit(2); } =20 - if (libxl_device_pci_assignable_remove(ctx, &pci, rebind)) - r =3D 1; + r =3D libxl_device_pci_assignable_remove(ctx, &pci, rebind); + if (!r || r !=3D ERROR_NOTFOUND) + goto out; + + /* If remove-by-name failed to find the device, try remove-by-BDF */ + free(pci.name); + pci.name =3D NULL; =20 + if (xlu_pci_parse_bdf(config, &pci, ident)) { + fprintf(stderr, + "pci-assignable-remove: malformed BDF '%s'\n", ident); + exit(2); + } + + r =3D libxl_device_pci_assignable_remove(ctx, &pci, rebind); + +out: libxl_device_pci_dispose(&pci); xlu_cfg_destroy(config); =20 @@ -249,7 +290,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) { @@ -258,9 +299,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 Fri May 3 17:53:33 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=1609868830; cv=none; d=zohomail.com; s=zohoarc; b=LSVNdf/1hT0YFxNuV2Z4sDTVIdOx3HfGoARcNEVgx+xqvxaOehcSxpLeK9kbDrDMWoMzP9xp32L4yl6Eh/NnzZTriCmxeoEbrffJNqkP2sSy4L4kLuugjCb8ExL96cl+Ysr87hwgZhPO6uQua4U6hnZuujY09jQO1pRKmto6TWI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609868830; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=kCDNFExz7caMqoa/GRwLckQ/hpkMYS+RIjR1+0+OLts=; b=jrxOanswFmjZ2sdK4dhyYhHBNZsaFsjTSrFogfJHp2atMreNQ5qNhCJ8pvk7IrQNazJhF6ylgD3TR3h0X9ybc4rfO6e2BOajI1h/xIIOU9b5TxFOjKQZdPAEKqam42L0z35JX/o+zttLpTHztCVqSXF/Rj64eeOge60xC4tqoaI= 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 1609868830512126.16672185305515; Tue, 5 Jan 2021 09:47:10 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.62116.109829 (Exim 4.92) (envelope-from ) id 1kwqQ2-0005Yl-LL; Tue, 05 Jan 2021 17:46:54 +0000 Received: by outflank-mailman (output) from mailman id 62116.109829; Tue, 05 Jan 2021 17:46: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 1kwqQ1-0005Y6-TB; Tue, 05 Jan 2021 17:46:53 +0000 Received: by outflank-mailman (input) for mailman id 62116; Tue, 05 Jan 2021 17:46:52 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwqQ0-0005UW-FE for xen-devel@lists.xenproject.org; Tue, 05 Jan 2021 17:46:52 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwqPz-0006In-Sa; Tue, 05 Jan 2021 17:46:51 +0000 Received: from ec2-34-243-106-223.eu-west-1.compute.amazonaws.com ([34.243.106.223] helo=ip-10-0-70-185.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 1kwqPz-0008Uy-LV; Tue, 05 Jan 2021 17:46:51 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=kCDNFExz7caMqoa/GRwLckQ/hpkMYS+RIjR1+0+OLts=; b=yXQGO5iKab1X8C+EqFA20cOgR hPcJBxk/HguAHgN8+HEBJQYb2+YrpdJVFUtxBlC17jfuh9qIcqvHTBupUwqV3OC3AMZNMarDmIUrW 4mnLgdVgn/HMwDi+SRW7yHtc5aOSaRKRmvueg23DGsxOqBYKQZOk+0slFrkOAfeWomObM=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson Subject: [PATCH v7 6/7] docs/man: modify xl-pci-configuration(5) to add 'name' field to PCI_SPEC_STRING Date: Tue, 5 Jan 2021 17:46:41 +0000 Message-Id: <20210105174642.2754-7-paul@xen.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20210105174642.2754-1-paul@xen.org> References: <20210105174642.2754-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: Wei Liu --- Cc: Ian Jackson --- 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 Fri May 3 17:53:33 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=1609868829; cv=none; d=zohomail.com; s=zohoarc; b=KCRFkK2FTlt8tbRCYuJtqAAi0eu7lanDYHZWQk73g43OremA8muJeu1tGere691AZAXLnJgf8V2dLTLgG3ZLAp8dPUg3GUriLoRovZuzGQU8DAidfpyS25nJcO+vKUyCdfDQTlUcnGgQ6vsybXmH8MZr60+fzBHxppSfoxBRjHQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609868829; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=3UwAO3+6UIsalZmR5nIJ2Wrt6//kBgYPmyOdrIp1odM=; b=MnMeoh7pctsPTFEtIERE83HyuD2khJWEusuf0uQl3d7hL2Sc6SAxlKbF0jrhigfkun9WjA0p0w+38Dc/YaFT3JkQvGrfMwaGORF6QDwetNM/Sj5Up8f+FtMqLghLEncnmUU7NnKe2OXQJHXpIHbnwBFol6iON1ykGUZ+0SlpbW4= 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 1609868829827305.1692934690767; Tue, 5 Jan 2021 09:47:09 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.62117.109849 (Exim 4.92) (envelope-from ) id 1kwqQ4-0005g5-R4; Tue, 05 Jan 2021 17:46:56 +0000 Received: by outflank-mailman (output) from mailman id 62117.109849; Tue, 05 Jan 2021 17:46:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwqQ4-0005fp-Kz; Tue, 05 Jan 2021 17:46:56 +0000 Received: by outflank-mailman (input) for mailman id 62117; Tue, 05 Jan 2021 17:46:53 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwqQ1-0005XS-ID for xen-devel@lists.xenproject.org; Tue, 05 Jan 2021 17:46:53 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwqQ0-0006Iu-On; Tue, 05 Jan 2021 17:46:52 +0000 Received: from ec2-34-243-106-223.eu-west-1.compute.amazonaws.com ([34.243.106.223] helo=ip-10-0-70-185.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 1kwqQ0-0008Uy-HX; Tue, 05 Jan 2021 17:46:52 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=3UwAO3+6UIsalZmR5nIJ2Wrt6//kBgYPmyOdrIp1odM=; b=Dx3y9Zm4sNBzfbKi16OuVAR3u dHnXh1vOWxN50fD0hCfV3y+hNphTVnCNUHVRPNk20R3FGI1gRmhk7EuR0L0p6cRmO2nSe6yiVDhT9 n+InEBbiKyZjW4Km7K6fhk+9SoAO6u121rKcaoN/2VEQ+EVyH3uUqU6bXhpGaMZ4av+GM=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Wei Liu , Ian Jackson , Anthony PERARD Subject: [PATCH v7 7/7] libxl / libxlu: support 'xl pci-attach/detach' by name Date: Tue, 5 Jan 2021 17:46:42 +0000 Message-Id: <20210105174642.2754-8-paul@xen.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20210105174642.2754-1-paul@xen.org> References: <20210105174642.2754-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 libxlu_pci_parse_spec_string() to parse the new 'name' parameter of PCI_SPEC_STRING detailed in the updated documention in xl-pci-configuration(5) and populate the 'name' field of 'libxl_device_pci'. 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: Wei Liu --- Cc: Wei Liu Cc: Ian Jackson Cc: Anthony PERARD v7: - Re-worked (mainly because 'libxl_device_pci' already has a 'name' field) - Dropped Wei's A-b because of the re-work v6: - Re-base - Slight modification to the patch name - Kept Wei's A-b since modifications are small --- tools/libs/light/libxl_pci.c | 43 ++++++++++++++++++++++++++++++++++++++--= --- tools/libs/util/libxlu_pci.c | 7 ++++++- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/tools/libs/light/libxl_pci.c b/tools/libs/light/libxl_pci.c index 9e3a90dcda..1a1c263080 100644 --- a/tools/libs/light/libxl_pci.c +++ b/tools/libs/light/libxl_pci.c @@ -58,6 +58,8 @@ static void libxl_create_pci_backend_device(libxl__gc *gc, 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)); + if (pci->name) + flexarray_append_pair(back, GCSPRINTF("name-%d", num), GCSPRINTF("= %s", pci->name)); flexarray_append(back, GCSPRINTF("opts-%d", num)); flexarray_append(back, GCSPRINTF("msitranslate=3D%d,power_mgmt=3D%d,permissive=3D%d= ,rdm_policy=3D%s", @@ -282,6 +284,7 @@ retry_transaction2: xs_rm(ctx->xsh, t, GCSPRINTF("%s/vdev-%d", be_path, i)); xs_rm(ctx->xsh, t, GCSPRINTF("%s/opts-%d", be_path, i)); xs_rm(ctx->xsh, t, GCSPRINTF("%s/vdevfn-%d", be_path, i)); + xs_rm(ctx->xsh, t, GCSPRINTF("%s/name-%d", be_path, i)); libxl__xs_printf(gc, t, num_devs_path, "%d", num - 1); for (j =3D i + 1; j < num; j++) { tmppath =3D GCSPRINTF("%s/state-%d", be_path, j); @@ -314,6 +317,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) @@ -1589,6 +1598,12 @@ void libxl__device_pci_add(libxl__egc *egc, uint32_t= domid, libxl_device_pci_copy(CTX, &pas->pci, pci); pci =3D &pas->pci; =20 + /* If the device is named then we need to look up the BDF */ + if (pci->name) { + rc =3D name2bdf(gc, pci); + if (rc) goto out; + } + pas->starting =3D starting; pas->callback =3D device_pci_add_stubdom_done; =20 @@ -1739,11 +1754,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->domain, pci->bus, pci->dev, pci->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->domain, pci->bus, pci->dev, pci->func, + rc); + } pci_info_xs_remove(gc, pci, "domid"); } libxl_device_pci_dispose(pci); @@ -2250,6 +2273,12 @@ static void libxl__device_pci_remove_common(libxl__e= gc *egc, libxl_device_pci_copy(CTX, &prs->pci, pci); pci =3D &prs->pci; =20 + /* If the device is named then we need to look up the BDF */ + if (pci->name) { + rc =3D name2bdf(gc, pci); + if (rc) goto out; + } + prs->force =3D force; libxl__xswait_init(&prs->xswait); libxl__ev_qmp_init(&prs->qmp); @@ -2372,6 +2401,10 @@ static int libxl__device_pci_from_xs_be(libxl__gc *g= c, if (s) pci->vdevfn =3D strtol(s, (char **) NULL, 16); =20 + s =3D libxl__xs_read(gc, XBT_NULL, GCSPRINTF("%s/name-%d", be_path, nr= )); + if (s) + pci->name =3D strdup(s); + s =3D libxl__xs_read(gc, XBT_NULL, GCSPRINTF("%s/opts-%d", be_path, nr= )); if (s) { char *saveptr; diff --git a/tools/libs/util/libxlu_pci.c b/tools/libs/util/libxlu_pci.c index 05472a0bd1..ad88fee088 100644 --- a/tools/libs/util/libxlu_pci.c +++ b/tools/libs/util/libxlu_pci.c @@ -147,6 +147,7 @@ int xlu_pci_parse_spec_string(XLU_Config *cfg, libxl_de= vice_pci *pci, { 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 */ @@ -189,6 +190,10 @@ int xlu_pci_parse_spec_string(XLU_Config *cfg, libxl_d= evice_pci *pci, pci->power_mgmt =3D atoi(val); } else if (!strcmp(key, "rdm_policy")) { ret =3D parse_rdm_policy(cfg, &pci->rdm_policy, val); + } else if (!strcmp(key, "name")) { + name_present =3D true; + pci->name =3D strdup(val); + if (!pci->name) ret =3D ERROR_NOMEM; } else { XLU__PCI_ERR(cfg, "Unknown PCI_SPEC_STRING option: %s", key); ret =3D ERROR_INVAL; @@ -201,7 +206,7 @@ int xlu_pci_parse_spec_string(XLU_Config *cfg, libxl_de= vice_pci *pci, return ret; } =20 - if (!bdf_present) + if (!(bdf_present ^ name_present)) return ERROR_INVAL; =20 return 0; --=20 2.11.0