Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3750868imm; Mon, 20 Aug 2018 04:13:57 -0700 (PDT) X-Google-Smtp-Source: AA+uWPz9993rcRXxtV8hbcG0KN3yRvMFNYMex9rTEvKo0hBmhOZhSHZ9QJnH9rjGKIdVV4QqhCWA X-Received: by 2002:a65:4849:: with SMTP id i9-v6mr42510568pgs.350.1534763637081; Mon, 20 Aug 2018 04:13:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534763637; cv=none; d=google.com; s=arc-20160816; b=ymJ7kqrm5haAdAZ6DGk0/sA6maswl63TetaOYDnJcRScYjQM/ShNgXWlgo2u4Nu30c 5tKuBwUZSFQwnRnVzRxdp07ucX37W1RO2XBMPhxkkqMIT/P6/lSD5o3a+Iz+jZhv15dM bakBafo65KbdYIjAl6TwwZf/YeEYkuPD79Pyu1jzq1FlRZ+pgxz1QqEUjDSie3uFq/U4 mMYvxdkTH31aD5+yeLiT+zKuB5OUiQqBFO+OwGWTtpaXM9lOEzOhzJCL84rLihKKqfoe YfdXL+YKWlRirrPawbbEb8Ht5E2RB6UEscWi/Gd56vhRhj6Bo6W3W/HTtmS/MqEva0yY JQNQ== 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=b1xWl/wqpqs6lqykPtmM7b6sutK0qY9VsQcKpdpT2RY=; b=WkiVnzXT3xzb6bgZ7tzthwqXE2ebs0/ZT4hVvUeaWksDA4FEQmqMUh0x30wpw4xNuf xUsENoY9PJ7DkhsOAjESXtE9gNpK6NkeE9IOT7KQ/PNwJe0+ClgLKzq3WQmBjq4MXOb5 F3yYmDRWG64Uk11Q0dppzrtJ+Jh6PpiLbM+++isuGgiByY+7mqEh+PhlcsCA9QUgX3wV 9KDbEdeLGytyDt5KIl59kUjrKYWT22ESBLN4DLZ7PdozVzrwnvadgy2y2pkTV9zcTY9O IR6LJn3K7f50YIhn6i2mnM78awbHgP/LsYskfDSArnoyHCjFoQn/fo+BoXb43J3sRp14 m8lA== 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 v84-v6si10016555pfa.103.2018.08.20.04.13.42; Mon, 20 Aug 2018 04:13:57 -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 S1726268AbeHTO1t (ORCPT + 99 others); Mon, 20 Aug 2018 10:27:49 -0400 Received: from gate.crashing.org ([63.228.1.57]:50140 "EHLO gate.crashing.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725948AbeHTO1t (ORCPT ); Mon, 20 Aug 2018 10:27:49 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id w7KBC7DX031088; Mon, 20 Aug 2018 06:12:08 -0500 Message-ID: <61e3dfcf831fab4443b86579f39d4f08c6200c41.camel@kernel.crashing.org> Subject: Re: [RFC PATCH 1/6] Revert "PCI: Fix is_added/is_busmaster race condition" From: Benjamin Herrenschmidt To: Lukas Wunner Cc: Bjorn Helgaas , linux-pci@vger.kernel.org, Hari Vyas , Ray Jui , Srinath Mannam , Guenter Roeck , Jens Axboe , Konstantin Khlebnikov , Marta Rybczynska , Pierre-Yves Kerbrat , linux-kernel@vger.kernel.org Date: Mon, 20 Aug 2018 21:12:07 +1000 In-Reply-To: <20180820071703.hnsyhb5pz4svb7jg@wunner.de> References: <20180817044902.31420-1-benh@kernel.crashing.org> <20180817044902.31420-2-benh@kernel.crashing.org> <20180817154431.GC128050@bhelgaas-glaptop.roam.corp.google.com> <06c1233b71dea08b1fc32334acefc48c32c46557.camel@kernel.crashing.org> <20180819022440.GG128050@bhelgaas-glaptop.roam.corp.google.com> <4d777ed8c17b479e59b16cc0b4e9a3f6537f9884.camel@kernel.crashing.org> <20180820071703.hnsyhb5pz4svb7jg@wunner.de> 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 Mon, 2018-08-20 at 09:17 +0200, Lukas Wunner wrote: > On Mon, Aug 20, 2018 at 12:10:59PM +1000, Benjamin Herrenschmidt wrote: > > I chose to create a new mutex which we should be able to address other > > similar races if we find them. The other solutions that I dismissed > > were: > > > > - Using the device_lock. A explained previously, this is tricky, I > > prefer not using this for anything other than locking against > > concurrent add/remove. The main issue is that drivers will be sometimes > > called in context where that's already held, so we can't take it inside > > pci_enable_device() and I'd rather not add new constraints such as > > "pci_enable_device() must be only called from probe() unless you also > > take the device lock". It would be tricky to audit everybody... > > > > - Using a global mutex. We could move the bridge lock from AER to core > > code for example, and use that. But it doesn't buy us much, and > > slightly redecuces parallelism. It also makes it a little bit more > > messy to walk up the bridge chain, we'd have to do a > > pci_enable_device_unlocked or something, messy. > > +1 from my side for adding a struct mutex to struct pci_dev to protect > state changes. Ok thanks. This is what my patch proposes. We can use it later to protect more things if we wish to do so. > The device_lock() primarily protects binding / unbinding of the device > and pci_dev state may have to be changed while binding / unbinding. Yup, precisely. > A global lock invites deadlocks if multiple devices are added / removed > concurrently where one is a parent of the other. (Think hot-removal of > multiple devices on a Thunderbolt daisy-chain.) Yes. > As said I'd also welcome folding PCI_DEV_DISCONNECTED into enum > pci_channel_state, either as an additional state or by using > pci_channel_io_perm_failure. Ok. I have that in my tentative series but I think for robustness, I should make the error_state field atomically updated in order to ensure that no transition out of "disconnected" can happen while racing with concurrent error_state updates at interrupt time (at least with EEH, it can be updated from any read{b,w,l,q}). I'll do a bit more work on the patches this week as time permits and send a non-RFC series. Cheers, Ben. > Thanks, > > Lukas