From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3A775A0350; Fri, 29 May 2020 19:47:39 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id AAF5B1DA0C; Fri, 29 May 2020 19:47:37 +0200 (CEST) Received: from mail-pj1-f67.google.com (mail-pj1-f67.google.com [209.85.216.67]) by dpdk.org (Postfix) with ESMTP id 3393F1D9E4 for ; Fri, 29 May 2020 19:47:36 +0200 (CEST) Received: by mail-pj1-f67.google.com with SMTP id h95so772864pje.4 for ; Fri, 29 May 2020 10:47:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vyPb81JceFW5JCAkIJCOCGvsoQaBKqbIC+jhQg9ox1g=; b=Jx/oLByiT2y9o5APhF3Goe8be0H0eq699mHJ01jK1s5I6/tUXSOcgUv5S+xlQ5xoO2 wNuyHGx4//whBwNsPnTEO4ACMxJcwocxNASTz+ANO0f2QIx4/OM513FMYldjcokAm0B4 OY+nSZRqcXzC9bz75IgxLb3jSu5Z0/GssMLLJ+dSuSFC2WuZAsammYZ3rj1VKmmkCu3/ 4FX2BsKvHs43lYW1ZEspS7Zx33oA4Ca4TW47jWMhQJaOv/gjOhu8qc9A24JcLb+CqLkz 1wApjCTRdYrj+R8A9n0XJOsGF5fVaniRnJnMoGdIPjD4OSe3mRDZtGNFR+/3nbbgi9au /Biw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vyPb81JceFW5JCAkIJCOCGvsoQaBKqbIC+jhQg9ox1g=; b=dCAFwC7z/rm6w5aUl9OnAjMj0ELarmk8kD+OgngIPMzfuGFJbRK69CdCb37jpgsFFL j9cTM1dVS1fYPrSXuSU4KEIZSRbK6LuC6lGMOryk6yMXNIQX/d43Jilh3turfNuvk8dL g7+m/k23bzeIyj3L8skcsfdPDnnTqG7i3z1qZYy83WYr9s+VTZ1RqZZO8XiQ9+w6b7qt bo9yodOAPbs0VIqUWgF1M/tcJSS4oUiHz0WUcS009LS+Jn+so/HMxOfsGUhF3b42KrfU MMLpx/jLlJR7Szuilw4d6gnoUepoR12OdDhynDZSeBFTf9v0j6O3TvOsHgal0sIVf7pc FOuw== X-Gm-Message-State: AOAM531nDqaUuOj4/W77SUPswD+xycRItlWG8Bxnv7s4PndJmbPlGd5C t2ljv4nMGrm3RV0bYWI5+XdNeA== X-Google-Smtp-Source: ABdhPJwDEZUq+hFltCHQ695uYVxWemMcaFg/4p4U/yOgXX7wGx/b5UA3h9cH11M8gJufEdVNZC4aIA== X-Received: by 2002:a17:90b:503:: with SMTP id r3mr10534699pjz.69.1590774455041; Fri, 29 May 2020 10:47:35 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id mu17sm84831pjb.53.2020.05.29.10.47.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2020 10:47:34 -0700 (PDT) Date: Fri, 29 May 2020 10:47:26 -0700 From: Stephen Hemminger To: wangyunjian Cc: , , , , Message-ID: <20200529104726.0a76d7bf@hermes.lan> In-Reply-To: <768c74d06680b93b2ce6bbf0813d1910666888dc.1590666521.git.wangyunjian@huawei.com> References: <768c74d06680b93b2ce6bbf0813d1910666888dc.1590666521.git.wangyunjian@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Subject: Re: [dpdk-dev] [PATCH] bus/vmbus: fix wrong allocation for device.name X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On Thu, 28 May 2020 20:03:07 +0800 wangyunjian wrote: > From: Yunjian Wang >=20 > We do not need and should not allocate memory for device.name. > The device.name should be set point to the devargs->name. >=20 > Fixes: 831dba47bd36 ("bus/vmbus: add Hyper-V virtual bus support") > Cc: stable@dpdk.org >=20 > Signed-off-by: Yunjian Wang The correct fix is more complex. The code needs to act more like PCI. The name should be in the vmbus_device structure (like PCI). And the devargs logic needs to be more involved and also handle whitelist/blacklisting. Here is a very rough idea what that would look like: =46rom edf90357a99c7970546ef00941a9593bca46d08e Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Fri, 29 May 2020 10:45:26 -0700 Subject: [PATCH] vmbus: support whitelist/blacklist This makes VMBus work like PCI and support blacklist and whitelist command line arguments. It also moves the vmbus device name into the internal structure. This is compile tested only. Signed-off-by: Stephen Hemminger --- drivers/bus/vmbus/linux/vmbus_bus.c | 30 ++++++++-------- drivers/bus/vmbus/private.h | 5 ++- drivers/bus/vmbus/rte_bus_vmbus.h | 2 +- drivers/bus/vmbus/vmbus_common.c | 53 ++++++++++++++++++++++++++--- 4 files changed, 67 insertions(+), 23 deletions(-) diff --git a/drivers/bus/vmbus/linux/vmbus_bus.c b/drivers/bus/vmbus/linux/= vmbus_bus.c index 3c924eee1412..9162b30bb46c 100644 --- a/drivers/bus/vmbus/linux/vmbus_bus.c +++ b/drivers/bus/vmbus/linux/vmbus_bus.c @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include @@ -230,7 +229,7 @@ rte_vmbus_unmap_device(struct rte_vmbus_device *dev) =20 /* Scan one vmbus sysfs entry, and fill the devices list from it. */ static int -vmbus_scan_one(const char *name) +vmbus_scan_one(rte_uuid_t id, const char *name) { struct rte_vmbus_device *dev, *dev2; char filename[PATH_MAX]; @@ -242,14 +241,10 @@ vmbus_scan_one(const char *name) return -1; =20 dev->device.bus =3D &rte_vmbus_bus.bus; - dev->device.name =3D strdup(name); - if (!dev->device.name) - goto error; + rte_uuid_copy(dev->device_id, id); =20 /* sysfs base directory * /sys/bus/vmbus/devices/7a08391f-f5a0-4ac0-9802-d13fd964f8df - * or on older kernel - * /sys/bus/vmbus/devices/vmbus_1 */ snprintf(dirname, sizeof(dirname), "%s/%s", SYSFS_VMBUS_DEVICES, name); @@ -265,11 +260,6 @@ vmbus_scan_one(const char *name) return 0; } =20 - /* get device id */ - snprintf(filename, sizeof(filename), "%s/device_id", dirname); - if (parse_sysfs_uuid(filename, dev->device_id) < 0) - goto error; - /* get relid */ snprintf(filename, sizeof(filename), "%s/id", dirname); if (eal_parse_sysfs_value(filename, &tmp) < 0) @@ -295,9 +285,6 @@ vmbus_scan_one(const char *name) dev->device.numa_node =3D SOCKET_ID_ANY; } =20 - dev->device.devargs =3D vmbus_devargs_lookup(dev); - - /* device is valid, add in list (sorted) */ VMBUS_LOG(DEBUG, "Adding vmbus device %s", name); =20 TAILQ_FOREACH(dev2, &rte_vmbus_bus.device_list, next) { @@ -346,10 +333,21 @@ rte_vmbus_scan(void) } =20 while ((e =3D readdir(dir)) !=3D NULL) { + rte_uuid_t id; + if (e->d_name[0] =3D=3D '.') continue; =20 - if (vmbus_scan_one(e->d_name) < 0) + if (rte_uuid_parse(e->d_name, id) !=3D 0) { + VMBUS_LOG(DEBUG, "ignore '%s' non-uuid in vmbus/devices", + e->d_name); + continue; + } + + if (vmbus_ignore_device(id)) + continue; + + if (vmbus_scan_one(id, e->d_name) < 0) goto error; } closedir(dir); diff --git a/drivers/bus/vmbus/private.h b/drivers/bus/vmbus/private.h index f19b14e4a657..dd6a17c7238c 100644 --- a/drivers/bus/vmbus/private.h +++ b/drivers/bus/vmbus/private.h @@ -71,12 +71,15 @@ struct vmbus_channel { #define VMBUS_MAX_CHANNELS 64 =20 struct rte_devargs * -vmbus_devargs_lookup(struct rte_vmbus_device *dev); +vmbus_devargs_lookup(rte_uuid_t device_id); + +void vmbus_name_set(struct rte_vmbus_device *dev); =20 int vmbus_chan_create(const struct rte_vmbus_device *device, uint16_t relid, uint16_t subid, uint8_t monitor_id, struct vmbus_channel **new_chan); =20 +bool vmbus_ignore_device(rte_uuid_t device_id); void vmbus_add_device(struct rte_vmbus_device *vmbus_dev); void vmbus_insert_device(struct rte_vmbus_device *exist_vmbus_dev, struct rte_vmbus_device *new_vmbus_dev); diff --git a/drivers/bus/vmbus/rte_bus_vmbus.h b/drivers/bus/vmbus/rte_bus_= vmbus.h index 4cf73ce81513..62d067f19179 100644 --- a/drivers/bus/vmbus/rte_bus_vmbus.h +++ b/drivers/bus/vmbus/rte_bus_vmbus.h @@ -73,7 +73,7 @@ struct rte_vmbus_device { uint32_t *int_page; /**< VMBUS interrupt page */ struct vmbus_channel *primary; /**< VMBUS primary channel */ struct vmbus_mon_page *monitor_page; /**< VMBUS monitor page */ - + char name[RTE_UUID_STRLEN]; /**< VMBUS uuid (ASCII) */ struct rte_intr_handle intr_handle; /**< Interrupt handle */ struct rte_mem_resource resource[VMBUS_MAX_RESOURCE]; }; diff --git a/drivers/bus/vmbus/vmbus_common.c b/drivers/bus/vmbus/vmbus_com= mon.c index 3adef01c95de..ee2180f1d10c 100644 --- a/drivers/bus/vmbus/vmbus_common.c +++ b/drivers/bus/vmbus/vmbus_common.c @@ -61,6 +61,21 @@ vmbus_unmap_resource(void *requested_addr, size_t size) requested_addr); } =20 +void +vmbus_name_set(struct rte_vmbus_device *dev) +{ + struct rte_devargs *devargs; + + devargs =3D vmbus_devargs_lookup(dev->device_id); + rte_uuid_unparse(dev->device_id, dev->name, sizeof(dev->name)); + + /* if the device is not blacklisted, no rte_devargs exists for it. */ + if (devargs) + dev->device.name =3D dev->device.devargs->name; + else + dev->device.name =3D dev->name; +} + /** * Match the VMBUS driver and device using UUID table * @@ -85,6 +100,7 @@ vmbus_match(const struct rte_vmbus_driver *dr, =20 return false; } + /* * If device ID match, call the devinit() function of the driver. */ @@ -99,10 +115,18 @@ vmbus_probe_one_driver(struct rte_vmbus_driver *dr, return 1; /* not supported */ =20 rte_uuid_unparse(dev->device_id, guid, sizeof(guid)); - VMBUS_LOG(INFO, "VMBUS device %s on NUMA socket %i", + VMBUS_LOG(DEBUG, "VMBUS device %s on NUMA socket %i", guid, dev->device.numa_node); =20 - /* TODO add blacklisted */ + if (dev->device.devargs !=3D NULL && + dev->device.devargs->policy =3D=3D RTE_DEV_BLACKLISTED) { + VMBUS_LOG(INFO, " Device is blacklisted, not initializing\n"); + return 1; + } + + /* Older kernel versions do not report NUMA node for vmbus */ + if (dev->device.numa_node < 0) + dev->device.numa_node =3D 0; =20 /* map resources for device */ ret =3D rte_vmbus_map_device(dev); @@ -210,15 +234,16 @@ vmbus_parse(const char *name, void *addr) * -w 'vmbus:635a7ae3-091e-4410-ad59-667c4f8c04c3,latency=3D20' */ struct rte_devargs * -vmbus_devargs_lookup(struct rte_vmbus_device *dev) +vmbus_devargs_lookup(rte_uuid_t device_id) { struct rte_devargs *devargs; - rte_uuid_t addr; =20 RTE_EAL_DEVARGS_FOREACH("vmbus", devargs) { + rte_uuid_t addr; + vmbus_parse(devargs->name, &addr); =20 - if (rte_uuid_compare(dev->device_id, addr) =3D=3D 0) + if (rte_uuid_compare(device_id, addr) =3D=3D 0) return devargs; } return NULL; @@ -285,6 +310,24 @@ vmbus_find_device(const struct rte_device *start, rte_= dev_cmp_t cmp, return NULL; } =20 +bool +vmbus_ignore_device(rte_uuid_t device_id) +{ + struct rte_devargs *devargs =3D vmbus_devargs_lookup(device_id); + + switch (rte_vmbus_bus.bus.conf.scan_mode) { + case RTE_BUS_SCAN_WHITELIST: + if (devargs && devargs->policy =3D=3D RTE_DEV_WHITELISTED) + return false; + break; + case RTE_BUS_SCAN_UNDEFINED: + case RTE_BUS_SCAN_BLACKLIST: + if (devargs =3D=3D NULL || devargs->policy !=3D RTE_DEV_BLACKLISTED) + return false; + break; + } + return true; +} =20 struct rte_vmbus_bus rte_vmbus_bus =3D { .bus =3D { --=20 2.26.2