From patchwork Fri Aug 17 04:48:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Herrenschmidt X-Patchwork-Id: 10568433 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A0F7D109C for ; Fri, 17 Aug 2018 04:49:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 80C942B620 for ; Fri, 17 Aug 2018 04:49:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7110A2B64E; Fri, 17 Aug 2018 04:49:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 482CD2B620 for ; Fri, 17 Aug 2018 04:49:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725837AbeHQHvh (ORCPT ); Fri, 17 Aug 2018 03:51:37 -0400 Received: from gate.crashing.org ([63.228.1.57]:46710 "EHLO gate.crashing.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725833AbeHQHvh (ORCPT ); Fri, 17 Aug 2018 03:51:37 -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 w7H4nAsD017258; Thu, 16 Aug 2018 23:49:11 -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 Subject: [RFC PATCH 0/6] pci: Rework is_added race fix and address bridge enable races Date: Fri, 17 Aug 2018 14:48:56 +1000 Message-Id: <20180817044902.31420-1-benh@kernel.crashing.org> X-Mailer: git-send-email 2.17.1 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This is really two series but since they conflict a bit separately here they are in one: First we undo the mess of those atomic priv_flags. The atomicity doesn't provide any security since there's no locking against the other state pertaining to those flags, it only protects the flags themselves. The is_added mess is fixed much more simply by moving the assignment of the flag to before we start the driver. This is in line with the rest of the PCI code: until bound to the device model, we are essentially assuming a single threaded environment. is_added is a flag that is logically owned by that part of the PCI code, and thus should be set and cleared within that "safer" environment. This removes the horrid relative includes in the powerpc code as well. The second part aims at fixing the enable/disable/set_master races, and does so by providing a framework for future device state locking issues. It introduces a pci_dev->state_mutex which is used at a lower level than the device_lock (the device lock isn't suitable, as explained in the cset comments) and uses it to protect enablement and set_master.