From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by dpdk.org (Postfix) with ESMTP id 31F09239 for ; Thu, 8 Nov 2018 00:21:10 +0100 (CET) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id C0ACA220E0; Wed, 7 Nov 2018 18:21:09 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 07 Nov 2018 18:21:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; s=mesmtp; bh=/AFukrkELAQK2x69YPWlxOy /k42k565IAkKZG7vRPy4=; b=kZHe2s2EeZ2YAhlfHZFQ0dm0CNB3uf/KxR0eem0 kzM/o6EHWaN3vJuukbDagZj1UMHmE8HhYX1lZRlAvUKlev73KxjyZdVTWxE3Wkgk 2+cGbAenm89OFFQyW5fg0azr/oNkXpCK3BJg/rrhaYWoxypoxpr5/GrFYWVjDSvp 9plQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :message-id:mime-version:subject:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=/AFukrkELAQK2x69Y PWlxOy/k42k565IAkKZG7vRPy4=; b=w/Clf4bqx02w2juTonERRDYQs8J0krTwQ YbBcCjXRN/bA03P0yA3fzIJF2+UgSnFXIQdCqoV7tCNFacofK916zT5Rr0fuQQ22 jPMBopwyciYGP6fobZTXr/zFriHKZ2/L1LpaspeBFSD9oS35++jwHtvlA5yoXmNG zX8SA92OxR2VevAj2OjEyYhrHs2zudCa9yCgYXpMA6t+pNxhWao12gXSQ3MZSBRE LMincSa8l161ffgyR6q02HkcyvYNbgcE4LiTmTmlablFMe6f8l7Ua3f1NW9XUwmh uPcHkfm2Orm8zwHwStwS3s3P7w+Yfkft/qPBW/zXEcR4dHyadtOgg== X-ME-Sender: X-ME-Proxy: Received: from xps.mtl.com (184.203.134.77.rev.sfr.net [77.134.203.184]) by mail.messagingengine.com (Postfix) with ESMTPA id 5B131E4619; Wed, 7 Nov 2018 18:21:08 -0500 (EST) From: Thomas Monjalon To: dev@dpdk.org Cc: gaetan.rivet@6wind.com, qi.z.zhang@intel.com, jia.guo@intel.com, dariusz.stojaczyk@intel.com Date: Thu, 8 Nov 2018 00:21:05 +0100 Message-Id: <20181107232105.19187-1-thomas@monjalon.net> X-Mailer: git-send-email 2.19.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH] devargs: do not replace already inserted devargs 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: , X-List-Received-Date: Wed, 07 Nov 2018 23:21:10 -0000 The devargs of a device can be replaced by a newly allocated one when trying to probe again the same device (multi-process or multi-ports scenarios). This is breaking some pointer references. It can be avoided by copying the new content, freeing the new devargs, and returning the already inserted pointer. Signed-off-by: Thomas Monjalon --- This patch is not tested, I want to share the idea as soon as possible. I hope it can fix some of the issues recently raised. I think there are some mess in: - scan functions and devargs - vdev hotplug We can revisit these areas in 19.02, and consider this patch as a simple fix for 18.11. --- drivers/bus/vdev/vdev.c | 6 ++-- lib/librte_eal/common/eal_common_dev.c | 3 +- lib/librte_eal/common/eal_common_devargs.c | 37 +++++++++++++++++---- lib/librte_eal/common/include/rte_devargs.h | 4 ++- 4 files changed, 39 insertions(+), 11 deletions(-) diff --git a/drivers/bus/vdev/vdev.c b/drivers/bus/vdev/vdev.c index 9c66bdc78..2c03ca418 100644 --- a/drivers/bus/vdev/vdev.c +++ b/drivers/bus/vdev/vdev.c @@ -224,7 +224,6 @@ insert_vdev(const char *name, const char *args, } dev->device.bus = &rte_vdev_bus; - dev->device.devargs = devargs; dev->device.numa_node = SOCKET_ID_ANY; dev->device.name = devargs->name; @@ -238,9 +237,10 @@ insert_vdev(const char *name, const char *args, goto fail; } - TAILQ_INSERT_TAIL(&vdev_device_list, dev, next); if (init) - rte_devargs_insert(devargs); + rte_devargs_insert(&devargs); + dev->device.devargs = devargs; + TAILQ_INSERT_TAIL(&vdev_device_list, dev, next); if (p_dev) *p_dev = dev; diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c index 5759ec2d8..1fdc9ab17 100644 --- a/lib/librte_eal/common/eal_common_dev.c +++ b/lib/librte_eal/common/eal_common_dev.c @@ -150,10 +150,11 @@ local_dev_probe(const char *devargs, struct rte_device **new_dev) goto err_devarg; } - ret = rte_devargs_insert(da); + ret = rte_devargs_insert(&da); if (ret) goto err_devarg; + /* the rte_devargs will be referenced in the matching rte_device */ ret = da->bus->scan(); if (ret) goto err_devarg; diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c index b7b9cb69e..0f8d997c8 100644 --- a/lib/librte_eal/common/eal_common_devargs.c +++ b/lib/librte_eal/common/eal_common_devargs.c @@ -263,14 +263,39 @@ rte_devargs_parsef(struct rte_devargs *da, const char *format, ...) } int __rte_experimental -rte_devargs_insert(struct rte_devargs *da) +rte_devargs_insert(struct rte_devargs **da) { - int ret; + struct rte_devargs *listed_da; + void *tmp; + + if (*da == NULL || (*da)->bus == NULL) + return -1; + + TAILQ_FOREACH_SAFE(listed_da, &devargs_list, next, tmp) { + if (listed_da == *da) + /* devargs already in the list */ + return 0; + if (strcmp(listed_da->bus->name, (*da)->bus->name) == 0 && + strcmp(listed_da->name, (*da)->name) == 0) { + /* device already in devargs list, must be updated */ + listed_da->type = (*da)->type; + listed_da->policy = (*da)->policy; + free(listed_da->args); + listed_da->args = (*da)->args; + listed_da->bus = (*da)->bus; + listed_da->cls = (*da)->cls; + listed_da->bus_str = (*da)->bus_str; + listed_da->cls_str = (*da)->cls_str; + listed_da->data = (*da)->data; + /* replace provided devargs with found one */ + free(*da); + *da = listed_da; + return 0; + } + } - ret = rte_devargs_remove(da); - if (ret < 0) - return ret; - TAILQ_INSERT_TAIL(&devargs_list, da, next); + /* new devargs in the list */ + TAILQ_INSERT_TAIL(&devargs_list, *da, next); return 0; } diff --git a/lib/librte_eal/common/include/rte_devargs.h b/lib/librte_eal/common/include/rte_devargs.h index b1f121f83..29b3fb7c8 100644 --- a/lib/librte_eal/common/include/rte_devargs.h +++ b/lib/librte_eal/common/include/rte_devargs.h @@ -146,6 +146,8 @@ __attribute__((format(printf, 2, 0))); * * @param da * The devargs structure to insert. + * If a devargs for the same device is already inserted, + * it will be updated and returned. It means *da pointer can change. * * @return * - 0 on success @@ -153,7 +155,7 @@ __attribute__((format(printf, 2, 0))); */ __rte_experimental int -rte_devargs_insert(struct rte_devargs *da); +rte_devargs_insert(struct rte_devargs **da); /** * Add a device to the user device list -- 2.19.0