Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1473036imm; Fri, 17 Aug 2018 20:30:03 -0700 (PDT) X-Google-Smtp-Source: AA+uWPwxX36LZ13kjoe+BPwVZqjSrPHnoWk2ChBAqWYsbU+UZ7qpqi3V6uJFntIEAw3kS2ygtEa4 X-Received: by 2002:a62:642:: with SMTP id 63-v6mr39108226pfg.42.1534563003332; Fri, 17 Aug 2018 20:30:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534563003; cv=none; d=google.com; s=arc-20160816; b=P7Bc1UBxPLh40m3D5e9p7JnTSaXJuzYIgXrQdUyOiU/WaKivJLDl57FslYqV7npvby e6UMIHrIJ9EL1uT9+4XzA2OqXHihyL7Ie/TY+9mfPGTYT0h55xBwXbRpU50QzyKPepbR JP3rpnMpWsmiK/uvMF/cSirWkvw6iGwP4xwvfcBsVzSYgtxDB2AUYkbkk7K6Gc85TjJl iUGTdhSM9uIIuA3IQT4d96FOIvbnmhfJHrF2kNrOBwGdvQcgLT8rL5kyYAZOp/Pw8JRC JalQPzxoFDdEVAKWOUzyOYkBgYsYbbIDD9Kyd+SKUQL1oowKhG+OzpoQyhIExd1u8wyD Mbew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id :arc-authentication-results; bh=J97W8KTYCxcTxpb03QExw5qXk9w4AT0tIUYfwDRKabw=; b=Sphdg7l/FIzKfTeTlr4RCLj2NhHUO3AihhIeNyELSDqAcRkDaAZIrn+vCkCi3nM5qO Iu7M2HGenkZMw7mn0N/WfH2bQZj4TAHygXobaMCp8hrEDUngdouDlM7l1H/pIizcDdWI ydnC1I9Zhqi+DtoAs3vcXDIzAnddynlXpEg2Fq3puVIbdP0o6TWib/rT5Gk9HUZ9hcL6 q5TudHs1Ds1KsvyPCgKZtqop+IKQ90B6yjNm638sqJNCJXhfZo3WBuVq73BoSuB1qRRB oKtr9h4VK/kAhUONAtBCpi4w4fxnot+z5Q0iBktDRuihKvFeZOuOoojpUilGt//VLD7k tZnQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c3-v6si3667893pld.457.2018.08.17.20.29.47; Fri, 17 Aug 2018 20:30:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726272AbeHRGet (ORCPT + 99 others); Sat, 18 Aug 2018 02:34:49 -0400 Received: from gate.crashing.org ([63.228.1.57]:53745 "EHLO gate.crashing.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725862AbeHRGet (ORCPT ); Sat, 18 Aug 2018 02:34:49 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id w7I3SGtp028627; Fri, 17 Aug 2018 22:28:17 -0500 Message-ID: <8dafc92f9c9cefba89ec1ec9839d086540af4557.camel@kernel.crashing.org> Subject: Re: [RFC PATCH 2/6] pci: Set pci_dev->is_added before calling device_add From: Benjamin Herrenschmidt To: Bjorn Helgaas Cc: linux-pci@vger.kernel.org, Hari Vyas , Ray Jui , Srinath Mannam , Guenter Roeck , Jens Axboe , Lukas Wunner , Konstantin Khlebnikov , Marta Rybczynska , Pierre-Yves Kerbrat , linux-kernel@vger.kernel.org Date: Sat, 18 Aug 2018 13:28:15 +1000 In-Reply-To: <20180817162534.GD128050@bhelgaas-glaptop.roam.corp.google.com> References: <20180817044902.31420-1-benh@kernel.crashing.org> <20180817044902.31420-3-benh@kernel.crashing.org> <20180817162534.GD128050@bhelgaas-glaptop.roam.corp.google.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.5 (3.28.5-1.fc28) Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2018-08-17 at 11:25 -0500, Bjorn Helgaas wrote: > On Fri, Aug 17, 2018 at 02:48:58PM +1000, Benjamin Herrenschmidt wrote: > > This re-fixes the bug reported by Hari Vyas > > after my revert of his commit but in a much simpler way. > > > > The main issues is that is_added was being set after the driver > > got bound and started, and thus setting it could race with other > > changes to struct pci_dev. > > The "bind driver, then set dev->added = 1" order seems to have been > there since the beginning of dev->is_added: > > http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=8a1bc9013a03 > > This patch seems reasonable, but I'm a little dubious about the > existence of "is_added" in the first place. As far as I can tell, the > only other buses with something similar are the MEN Chameleon bus and > the Intel Management Engine Interface. > > The PCI uses of "is_added" don't seem *that* critical or unique to > PCI, so I'm not 100% convinced we need it at all. But I haven't > looked into it enough to be able to propose an alternative. This is a whole different conversation you are taking us into :-) is_added is currently needed for a number of reasons, mostly relating to partial hotplug, and historically comes from the fact that we separated the PCI probing & tree construction from the registration with the device-model. This of course comes from the fact that the device model didn't actually exist yet when the PCI code was created :-) So let's keep things separate shall we ? I'd rather fix this correctly now, and get rid of that pesky atomic priv_flags which I think is just going to be a long term add to the mess rather than an improvement, and separately we can discuss whether is_added is something that can go away, but I suspect this will come in the form of either a deeper rework of how we do PCI probing, or simply finding a struct device/kobj field we can use as a hint that we've added the device already for hotplug. > > This fixes it by setting the flag first, which also has the > > advantage of matching the fact that we are clearing it *after* > > unbinding in the remove path, thus the flag is now symtetric > > and always set while the driver code is running. > > > > Signed-off-by: Benjamin Herrenschmidt > > --- > > drivers/pci/bus.c | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c > > index 35b7fc87eac5..48ae63673aa8 100644 > > --- a/drivers/pci/bus.c > > +++ b/drivers/pci/bus.c > > @@ -321,16 +321,16 @@ void pci_bus_add_device(struct pci_dev *dev) > > pci_proc_attach_device(dev); > > pci_bridge_d3_update(dev); > > > > + dev->is_added = 1; > > dev->match_driver = true; > > retval = device_attach(&dev->dev); > > if (retval < 0 && retval != -EPROBE_DEFER) { > > + dev->is_added = 0; > > pci_warn(dev, "device attach failed (%d)\n", retval); > > pci_proc_detach_device(dev); > > pci_remove_sysfs_dev_files(dev); > > return; > > } > > - > > - dev->is_added = 1; > > } > > EXPORT_SYMBOL_GPL(pci_bus_add_device); > > > > -- > > 2.17.1 > >