Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp352365imm; Thu, 16 Aug 2018 22:13:07 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxhqhL7mWH0X/yFu3jSH9QzixGuJA2vz298r/69kiQEDbR077uRND+HCN3u2MB542nHJXBz X-Received: by 2002:a17:902:b58b:: with SMTP id a11-v6mr31601088pls.34.1534482787643; Thu, 16 Aug 2018 22:13:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534482787; cv=none; d=google.com; s=arc-20160816; b=SmrvDv7+Q8CBZaW3wnezdi481XQFg/VhmLQh1sZLpd0COLGV1NgNI8VFFgL652V3K1 NBiFBsmq1XzJFe71loo7FckjE41CntXXU0bDCPAlyOq6k8jAS8bRXQpvu7ciBQHKfrNQ F88Df4ldMyX4v5mmQF4Q8sSl4RXSgXV9Mt65mMQGqa1+tZaag13RESZJP4zHiGx6j7XT eKKK9FYa0iUQkcUD/QNX4Y7nfJi3abrXo8lW7NQuMNZvboDdxmTkFILn8mP+X02JA9sL Y+TFivJjW2CUb0/m9y+zz3fL9p5zbivEOwQ0t/rI78Mza0lUX6p3XnD0btKRdG2udjqU X7Fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=Atkjx48JCklmskIkEogP7v0WDdTt11Vi2+Oh5bNbSOM=; b=UEMoVjvNNWOUnxLzb/YlXqIUXdlHwzruy9h7VTRc24wxyJv1cfiebvFpnWGjEOxddd rtT0VzQaBugKKW3k7AeIUinvsI3zg5E05y8Zkp8tAv6v1HvJlvakpUgyCZ0OiA+duwul 6gpZbGRnoKajQhLI7NHST98i/2MHH5KbNibwT+tgo5l9eT/ZTQbne4U1MVVMEEndi0xq D4cHz2aUZzNNUSO0/wgQAB8NXDQlo9fc+jQ7pTjSzumpHLIlTp1Ayo8gwWsT2/4QDeRJ 1JMgnRugjbXp+58Cf1iCFPbhqURCbxv3fhueER10gbMIdxzhnHr0ptlikdpI6WJHb8pU 71Ig== 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 f40-v6si1294867plb.504.2018.08.16.22.12.51; Thu, 16 Aug 2018 22:13:07 -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 S1726423AbeHQIN3 (ORCPT + 99 others); Fri, 17 Aug 2018 04:13:29 -0400 Received: from gate.crashing.org ([63.228.1.57]:57649 "EHLO gate.crashing.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726134AbeHQIN3 (ORCPT ); Fri, 17 Aug 2018 04:13:29 -0400 Received: from pasglop.ozlabs.ibm.com (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id w7H4nAsF017258; Thu, 16 Aug 2018 23:49:22 -0500 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, Benjamin Herrenschmidt Subject: [RFC PATCH 2/6] pci: Set pci_dev->is_added before calling device_add Date: Fri, 17 Aug 2018 14:48:58 +1000 Message-Id: <20180817044902.31420-3-benh@kernel.crashing.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180817044902.31420-1-benh@kernel.crashing.org> References: <20180817044902.31420-1-benh@kernel.crashing.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); -- 2.17.1