Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp961972imm; Fri, 17 Aug 2018 09:26:55 -0700 (PDT) X-Google-Smtp-Source: AA+uWPzMmYX0qZaxCcyQYx/NInsV/8exsP0oKPoKzRwLFnVlSupNRTxXh9ZSKoldJFTiW8n5Dodc X-Received: by 2002:a62:50c3:: with SMTP id g64-v6mr8499940pfj.244.1534523215852; Fri, 17 Aug 2018 09:26:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534523215; cv=none; d=google.com; s=arc-20160816; b=P7jylGPGf/Or87u0nv4iqDRjwPlFm4B4ulhbFdLom8J4pRWnGPBSInm1BK80sLgevX bRI8AtX2OPkILursGCIw6UdyXWC/NOlqZZ9q0IbGxI7zh1UgNE/5JOdMKsJ9RAf2wvOd t3RSnkLVt3GpmxdB4fiSHPDdC54mN7+1nyjqPSha4Jd4pQDQKrvZcY7Ve7uAUzibvkx5 v485T2iMpNS/u4Nh7X3ko1lI8tz1ta59WIfcY39s3Uot3SuMviIw/CHKNfIfTlHHMg8q cWxz/r2Eu/WWpR0+gL+02h9tXl7MEpa7HoLHQotgcRCkm9JkVXi1zvNoGrlLoPJ7wquO M98w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=n0JzlJkgJ/vuWGeGYeJXAWQlVfGEfr2ZSxm60uQWMVA=; b=L01/8+1PImT1d+MSgvfelJY1KzX5za0Bu5GbbsfK2l56rL0TOS3c0CAEteDOYfv+TL hPgKuCyOmIISoyi0XV5oDo1XfEQnm8U2qKViuvOUuiOO71GDILKJ2RnY8qomwPr6ekDC k/tR4jxZoLUI94Zlqa3PdmVwk+zJ8hJw9b6kvVnsDn4IWMf7Jr0zI4hjAZn36irFdHGU vU7/nZTAZRhE7NsKs8fzaRyqvxK5TnXlblfcEKN2izJmqK5RGxIKBNSviqgGk1sYvllX vFiSfnO5Hl+BCPKCIfGZjaZoo98NW1LNRbLc7ZlYwYEskelCbcZGzaXHy+EYV/srLc9R PPaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=sRGLkTBf; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t10-v6si2444394ply.181.2018.08.17.09.26.40; Fri, 17 Aug 2018 09:26:55 -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; dkim=pass header.i=@kernel.org header.s=default header.b=sRGLkTBf; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727707AbeHQT3f (ORCPT + 99 others); Fri, 17 Aug 2018 15:29:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:49078 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727398AbeHQT3f (ORCPT ); Fri, 17 Aug 2018 15:29:35 -0400 Received: from localhost (unknown [69.71.4.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BB26C2154F; Fri, 17 Aug 2018 16:25:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1534523136; bh=v5Q2t5q4kuaLq+L+hzYlFVxuM8+8vALnwBcrMfBdF9A=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=sRGLkTBfXyxKYbYICD3IpIiUFu7kVTCzkezBhaYb0aQ2VLwFh0HTXPTVC6oTg6080 p+B4mSFeQVY1ds86lIGBw/so/tJUQQ1oAkxvpBWxl45InQa9QggOcoY83Yt1/a081c txkEIkLIDHHCn33RG1NzcimfpJIvNrGF6Nyqnro4= Date: Fri, 17 Aug 2018 11:25:34 -0500 From: Bjorn Helgaas To: Benjamin Herrenschmidt 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 Subject: Re: [RFC PATCH 2/6] pci: Set pci_dev->is_added before calling device_add Message-ID: <20180817162534.GD128050@bhelgaas-glaptop.roam.corp.google.com> References: <20180817044902.31420-1-benh@kernel.crashing.org> <20180817044902.31420-3-benh@kernel.crashing.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180817044902.31420-3-benh@kernel.crashing.org> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 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 >