From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by dpdk.org (Postfix) with ESMTP id 2B71C1B202 for ; Thu, 22 Nov 2018 10:54:42 +0100 (CET) Received: by mail-wr1-f67.google.com with SMTP id 96so8608747wrb.2 for ; Thu, 22 Nov 2018 01:54:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=DUdFYbG8vjPRaTkkhO9CusEiDq/wbDguY3HR28sRR2Y=; b=T3BFHR6oOJ4gpoo/hC6KboQ/eSsT5pIIF98WfZxRtywsmo90UPNjEVLayUFYmI+mJT dxMwP3wIaQ/Yva/WXWcCuhV6kOLARSHYtYMaTS8Wo7UCGoxws8kpND1F6Hnh7M6QRHSh M6G4wr48rdpEPJiiSjjxg4riznyXN7+VsdKekfWaJ7zMYZBbfO6mou+kKfKF5QjqbUYy NcRN7t6BF2IIcF7d0emEPlRdfRLUQCX2TjvzmO82aY8CD9Wzlo5Gf/6Ct796Xg9iqslW Azn+OpAvK7jLAQmSeAyj0XOTXY8iCK5RzcpUOjLg9tVX4m8oeIhLVh3W+Wc/GGhM051U SGIA== 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:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=DUdFYbG8vjPRaTkkhO9CusEiDq/wbDguY3HR28sRR2Y=; b=ESi5iwaEWIYCyH1OxfdJAVHObNNBPcuBYFhD4W7WwzydGeqb7wH4Zg2FLnNomtQtzu MMykQKNd+qxaODU5LGi4IXBMJZtNdkYinBL2tlEgZQLsmmrLXnffWw4HhJYBPljdJPDo +jw/p0RaHgOXiC9Yxj3R2n2O5iutBaifqrNBm5HTGjqCqUwQO12fGE6ViyCw7xx9Ecgy BmsszQAEqtDrk/uBuJAK66eqwhHSCwsPqPS0kNMu7dM9Mhg0bi1g8HtDtuPBo2qdLE2V zv3CuGMuNzy1M8KaLK3tVcmPVnRtujrih+AqniDYIiCTIXXUcwXnV1Xm5wvUllTW+kME Bziw== X-Gm-Message-State: AA+aEWZQfUNOqBioAXyYh+9yVm+FUNnl6qfex6sh3aZI8eiYrB6FzE4T 4s8l3Eiz7Uw62XAwRgOqQy4InA== X-Google-Smtp-Source: AFSGD/Uh7DeNN7Tb3GXCB0nRbMEudF5peNdkAw32hdjRo/W2l8cvNgCDgVdVZYMmoSbGsQXOfrlwEg== X-Received: by 2002:a5d:60cc:: with SMTP id x12mr8660576wrt.193.1542880481582; Thu, 22 Nov 2018 01:54:41 -0800 (PST) Received: from bidouze.vm.6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id f15sm3776141wrt.10.2018.11.22.01.54.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 22 Nov 2018 01:54:40 -0800 (PST) Date: Thu, 22 Nov 2018 10:54:20 +0100 From: =?iso-8859-1?Q?Ga=EBtan?= Rivet To: Darek Stojaczyk Cc: dev@dpdk.org, thomas@monjalon.net Message-ID: <20181122095420.kmxulb6jpwblbkbd@bidouze.vm.6wind.com> References: <20181121183750.33796-1-dariusz.stojaczyk@intel.com> <20181121193827.62540-1-dariusz.stojaczyk@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20181121193827.62540-1-dariusz.stojaczyk@intel.com> User-Agent: NeoMutt/20170113 (1.7.2) Subject: Re: [dpdk-dev] [PATCH v2] dev: don't remove devargs that are still referenced 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: Thu, 22 Nov 2018 09:54:42 -0000 On Wed, Nov 21, 2018 at 08:38:27PM +0100, Darek Stojaczyk wrote: > Even if a device failed to plug, it's still a device > object that references the devargs. Those devargs will > be freed automatically together with the device, but > freeing them any earlier - like it's done in the hotplug > error handling path right now - will give us a dangling > pointer and a segfault scenario. > > Consider the following case: > * secondary process receives the hotplug request IPC message > * devargs are either created or updated > * the bus is scanned > * a new device object is created with the latest devargs > * the device can't be plugged for whatever reason, > bus->plug returns error > * the devargs are freed, even though they're still referenced > by the device object on the bus > > For PCI devices, the generic device name comes from > a buffer within the devargs. Freeing those will make > EAL segfault whenever the device name is checked. > > This patch just prevents the hotplug error handling > path from removing the devargs when there's a device > that references them. This is done by simply exiting > early from the hotplug function. As mentioned in the > beginning, those devargs will be freed later, together > with the device itself. > This seems ok in conjunction with Thomas' patch on overwriting devargs on insertion. The only place a device will be freed is the unplug bus ops, it already does remove the device devargs. > Fixes: 7e8b26650146 ("eal: fix hotplug add / remove") > Cc: gaetan.rivet@6wind.com > Cc: thomas@monjalon.net > > Signed-off-by: Darek Stojaczyk > --- > lib/librte_eal/common/eal_common_dev.c | 9 ++++----- > 1 file changed, 4 insertions(+), 5 deletions(-) > > diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c > index 1fdc9ab17..b6fc5e437 100644 > --- a/lib/librte_eal/common/eal_common_dev.c > +++ b/lib/librte_eal/common/eal_common_dev.c > @@ -169,11 +169,10 @@ local_dev_probe(const char *devargs, struct rte_device **new_dev) > > ret = dev->bus->plug(dev); > if (ret) { > - if (rte_dev_is_probed(dev)) /* if already succeeded earlier */ > - return ret; /* no rollback */ > - RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n", > - dev->name); > - goto err_devarg; > + if (!rte_dev_is_probed(dev)) /* if hasn't succeeded earlier */ > + RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n", > + dev->name); Maybe a comment here to describe that the devargs is still the responsibility of the rte_device and should not be removed. > + return ret; > } > > *new_dev = dev; > -- > 2.17.1 > -- Gaëtan Rivet 6WIND