From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?iso-8859-1?Q?Ga=EBtan?= Rivet Subject: Re: [PATCH 1/3] bus/pci: update device devargs on each rescan Date: Mon, 5 Nov 2018 17:27:42 +0100 Message-ID: <20181105162742.eako45onrhmjgfab@bidouze.vm.6wind.com> References: <20181105070447.67700-1-dariusz.stojaczyk@intel.com> <20181105141033.z3i3qfjoh6z26f4v@bidouze.vm.6wind.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Cc: "dev@dpdk.org" , "thomas@monjalon.net" , "Zhang, Qi Z" To: "Stojaczyk, Dariusz" Return-path: Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by dpdk.org (Postfix) with ESMTP id 9743014EC for ; Mon, 5 Nov 2018 17:28:02 +0100 (CET) Received: by mail-wr1-f68.google.com with SMTP id k15-v6so7241958wre.12 for ; Mon, 05 Nov 2018 08:28:02 -0800 (PST) Content-Disposition: inline In-Reply-To: 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 Mon, Nov 05, 2018 at 02:52:00PM +0000, Stojaczyk, Dariusz wrote: > Hi Gaetan, > > > -----Original Message----- > > From: Gaëtan Rivet [mailto:gaetan.rivet@6wind.com] > > Subject: Re: [dpdk-dev] [PATCH 1/3] bus/pci: update device devargs on each > > rescan > > > > Hi Darek, > > > > On Mon, Nov 05, 2018 at 08:04:45AM +0100, Darek Stojaczyk wrote: > > > Bus rescan is done e.g. during the device hotplug, > > > where devargs are re-allocated. By not updating the > > > rte_device->devargs pointer we potentially make it > > > a dangling one, as previous devargs could have been > > > (or will be soon) freed. > > > > > > Fixes: 55e411b301c3 ("bus/pci: fix resource mapping override") > > > Cc: qi.z.zhang@intel.com > > > > > > Signed-off-by: Darek Stojaczyk > > > --- > > > drivers/bus/pci/linux/pci.c | 2 +- > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > diff --git a/drivers/bus/pci/linux/pci.c b/drivers/bus/pci/linux/pci.c > > > index f87533c5c..f3172960e 100644 > > > --- a/drivers/bus/pci/linux/pci.c > > > +++ b/drivers/bus/pci/linux/pci.c > > > @@ -349,10 +349,10 @@ pci_scan_one(const char *dirname, const struct > > rte_pci_addr *addr) > > > if (ret < 0) { > > > rte_pci_insert_device(dev2, dev); > > > } else { /* already registered */ > > > + pci_name_set(dev2); > > > > This is rather unfortunate to call pci_name_set() > > to trigger the mapping devargs <-> devices. > > > > pci_devargs_lookup could be made non-static instead, > > if that's sufficient. > > This is unfortunately trigerred by the generic eal device hotplug path which looks as follows: > > da = calloc(sizeof rte_devargs); > [...] > rte_devargs_insert(da); # frees the previous devargs that rte_device still references > da->bus->scan(); # this should update the dangling devargs/name pointer in rte_device > > Instead of making pci_devargs_lookup public, we would have to introduce a new bus callback for updating devargs of only a single device and that would be a really, realy ugly overkill. Thomas already mentioned in the subsequent patch within this series that we might want to re-think the devargs design in the next release. > No, of course, I'm not saying to make pci_devargs_lookup public, only private to the PCI bus, and within the bus, non-static. This way, instead of calling pci_name_set(), you call instead only pci_devargs_lookup(). > > Given that the PCI id matches because the device > > is a duplicate (already registered), then the name itself probably does > > not need to be updated. > > The issue here was that old devargs/name could have been freed. > The new name is the same as the old one, it's just in a different buffer. > > I know calling pci_name_set() on each device during scan is not perfect, but IMO it's enforced by the current rte_devargs design. Besides, this used to be the original behavior before 55e411b301c3 ("bus/pci: fix resource mapping override"). > > Thanks, > D. > > > > > > > > > > -- > > Gaëtan Rivet > > 6WIND -- Gaëtan Rivet 6WIND