Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp341761imm; Thu, 16 Aug 2018 21:59:22 -0700 (PDT) X-Google-Smtp-Source: AA+uWPzlYUjEqj27rR0w5jetyqWYlIWyWFSeTSaR7+FAwcSNfBgGJTDNh9raJ8ETtox3RJa5X4Ut X-Received: by 2002:a62:fccd:: with SMTP id e196-v6mr35048628pfh.245.1534481962199; Thu, 16 Aug 2018 21:59:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534481962; cv=none; d=google.com; s=arc-20160816; b=GYHtXvNGh/xNwmOph94kfxj8yLuHDdP4QYnhJhCJz8BKDU/OUIgyVm2dQHy0hC743I 76qK1PmFLTxfC9e+1aPrzkQ1iatxnAvqaTG0ZCgiPEjDoaPW0iAK9LNkcuSVoefkKONa RB514PWlisaHYNcT2x/fbOh1LLvWSEpUBsS12fDQMVkIpFb5MnOJ/9uqffdXv6w+OosO AAmfhQ3zVKSujLKP/orHR0ZDYMCcXdGQ45/t6/v8NSa4+5QeTDk4iHOe+bo5hAjUHua2 W31inK/UjJBuYJrVqOM+xPxWSes+a94yqDUHhALVEwH87GdYjfny5zYrLnsNHArfFTrE 6nfg== 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=tFDt5OUmTv6E8U6r0ZEiRCTHnYFc3rxDs8LMcuAaSVc=; b=fW220v7UF157SthJiCVVLARHJW2WDhAhW39a1Of+sZZe4sa3f0+43UhZTXtaHerHxo M3iM6Ngf+14IehSXqT+vXXQeIMan9M3kmd5jYnemYhDkhapBkqMSpy0x5FMAwV7bF12d iAfM+zv6mcryz8ecbKidEuBGcBu3Ncd4eUap8RWCaLHnBabu3w1Ku/y97w+I/9J4SERG emVBoio9EpqIbYzxVxjoogqDmuraFzDl6sq6RBAfoGoEyS00XMGBgImMghcUmZb1UpY5 j4lENC5QhFxSyKrBBWUTgn7o5ZbD95VSJ3sgauoCyOVvG2wYkVf630oLoLn04mv//tMb icvQ== 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 i2-v6si1094605pgh.565.2018.08.16.21.59.07; Thu, 16 Aug 2018 21:59:22 -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 S1726360AbeHQH7z (ORCPT + 99 others); Fri, 17 Aug 2018 03:59:55 -0400 Received: from gate.crashing.org ([63.228.1.57]:34205 "EHLO gate.crashing.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725789AbeHQH7z (ORCPT ); Fri, 17 Aug 2018 03:59:55 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id w7H4vegw017530; Thu, 16 Aug 2018 23:57:42 -0500 Message-ID: <8b11e45e969c8407bf063c4d515305eab2b0769d.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 , linux-pci@vger.kernel.org Cc: 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: Fri, 17 Aug 2018 14:57:40 +1000 In-Reply-To: <20180817044902.31420-3-benh@kernel.crashing.org> References: <20180817044902.31420-1-benh@kernel.crashing.org> <20180817044902.31420-3-benh@kernel.crashing.org> 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 s/device_add/device_attach .. ugh. On Fri, 2018-08-17 at 14:48 +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. > > 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); >