Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp506578imm; Fri, 17 Aug 2018 01:38:23 -0700 (PDT) X-Google-Smtp-Source: AA+uWPy3/INQIt7RY6UBWBh9/YZiwCOl30cCYLAwvkzBoWH/12LwGs7l+ou9gGI/qkis2P8oFWsM X-Received: by 2002:a17:902:9a83:: with SMTP id w3-v6mr32889254plp.75.1534495103050; Fri, 17 Aug 2018 01:38:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534495103; cv=none; d=google.com; s=arc-20160816; b=PxIAcNIxXJzBi+Zc264zBf1RESEyCwpE+VyoRjNDybBUtshZGl96B08ibsaHlrBxi8 iqJwrYTwiNqcA4g19DP4iSF86XPnD4IrZdbK9DNdFXO7hlxbzCBt/3AKcVryONAm1Msn lezQ6FxQDjsClMcQOi7uEWrVJr+l/BqXW4+gVdaJsL4g/ULXc5YKP+Nf3l/NU91YV1zu YsaA+2PYIjQpPKiOem2j9TwiYhFL/v6UBhDz21sz0OL4AlygmAk93JZqwLFgVvbJYvKm pektqwTiWF+itx0DRkqOMjfH3v0FJL2HwRhgQOr7lOSpTxP6w8s4IP/T2AtfcXGdSWP/ nY7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:thread-index:thread-topic :content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date:dkim-signature:dkim-filter :arc-authentication-results; bh=jGfxbTGJ/dKQwnGDcvNSMBgkYF5uLMA32G3+ccRAUZw=; b=HlpPovSqR5z0iPjOW1vpaU3Mr65dBOZm1lUx9A0gO+zmffTV8nhzAUDmlELgYy3RqJ p69GaFN/IS4wvd1RWeQn/c5iL/L41wg5qvEUuvXYGwWjECf+gBo2tY5tQls6dITUarv/ 9OO6rRG4HC1LAJl1PB09DF8Dpd0EbydhqMnUr9SA+jviAxdDrlWpekzreg3DCNbqgxXe 9YTZszaZb3+P8ztooGh9V45T4Ol6k514gKNc1XSnkxvxrhBZkaBmlK5c/C5ZuPNzHVCA HCzOHL8BG+5xeh2WF2Zz5AC11nnnDsKN4c4WTFbt9Q+zQqP1twu4A3OHxHT8MEffVU4d ryLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kalray.eu header.s=32AE1B44-9502-11E5-BA35-3734643DEF29 header.b="bcIR/uj8"; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=kalray.eu Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e1-v6si1702807pld.408.2018.08.17.01.38.07; Fri, 17 Aug 2018 01:38: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; dkim=pass header.i=@kalray.eu header.s=32AE1B44-9502-11E5-BA35-3734643DEF29 header.b="bcIR/uj8"; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=kalray.eu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726667AbeHQLUm (ORCPT + 99 others); Fri, 17 Aug 2018 07:20:42 -0400 Received: from zimbra1.kalray.eu ([92.103.151.219]:49350 "EHLO zimbra2.kalray.eu" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1726349AbeHQLUl (ORCPT ); Fri, 17 Aug 2018 07:20:41 -0400 X-Greylist: delayed 504 seconds by postgrey-1.27 at vger.kernel.org; Fri, 17 Aug 2018 07:20:40 EDT Received: from localhost (localhost [127.0.0.1]) by zimbra2.kalray.eu (Postfix) with ESMTP id DA3E427E02EF; Fri, 17 Aug 2018 10:09:50 +0200 (CEST) Received: from zimbra2.kalray.eu ([127.0.0.1]) by localhost (zimbra2.kalray.eu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id uZn_rMdbLe72; Fri, 17 Aug 2018 10:09:50 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by zimbra2.kalray.eu (Postfix) with ESMTP id 6A5F327E02F0; Fri, 17 Aug 2018 10:09:50 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.10.3 zimbra2.kalray.eu 6A5F327E02F0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kalray.eu; s=32AE1B44-9502-11E5-BA35-3734643DEF29; t=1534493390; bh=jGfxbTGJ/dKQwnGDcvNSMBgkYF5uLMA32G3+ccRAUZw=; h=Date:From:To:Message-ID:MIME-Version; b=bcIR/uj8GaScV4fap5sS0/RO4+1JfI+oAjY7WJnQEZHBlPn09zrltVoRG0YI5Mh9z xmqwRrU8QCcEoFzSHq/VjV7VDeXHC9YIFJhie0OF8Y0V6wOmJgpD3Rzft2xo0KasdI oVROrDVOX5Xj3HA6yamVRZOVnfh+lQecAU3bONao= X-Virus-Scanned: amavisd-new at zimbra2.kalray.eu Received: from zimbra2.kalray.eu ([127.0.0.1]) by localhost (zimbra2.kalray.eu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id zCJgA2p3INuH; Fri, 17 Aug 2018 10:09:50 +0200 (CEST) Received: from zimbra2.kalray.eu (zimbra2.kalray.eu [192.168.40.202]) by zimbra2.kalray.eu (Postfix) with ESMTP id 4C63827E02EF; Fri, 17 Aug 2018 10:09:50 +0200 (CEST) Date: Fri, 17 Aug 2018 10:09:50 +0200 (CEST) From: Marta Rybczynska To: Benjamin Herrenschmidt Cc: Bjorn Helgaas , linux-pci@vger.kernel.org, Hari Vyas , Ray Jui , Srinath Mannam , Guenter Roeck , Jens Axboe , Lukas Wunner , Konstantin Khlebnikov , Pierre-Yves Kerbrat , linux-kernel@vger.kernel.org Message-ID: <66577784.13494160.1534493390262.JavaMail.zimbra@kalray.eu> In-Reply-To: <20180817044902.31420-6-benh@kernel.crashing.org> References: <20180817044902.31420-1-benh@kernel.crashing.org> <20180817044902.31420-6-benh@kernel.crashing.org> Subject: Re: [RFC PATCH 5/6] pci: Protect the enable/disable state of pci_dev using the state mutex MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [192.168.40.202] X-Mailer: Zimbra 8.8.8_GA_3008 (ZimbraWebClient - FF57 (Linux)/8.8.8_GA_1703) Thread-Topic: Protect the enable/disable state of pci_dev using the state mutex Thread-Index: QDBJGu64Fqg2Igvbl8Y4Q13tS1Paiw== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- On 17 Aug, 2018, at 06:49, Benjamin Herrenschmidt benh@kernel.crashing.org wrote: > This protects enable/disable operations using the state mutex to > avoid races with, for example, concurrent enables on a bridge. > > The bus hierarchy is walked first before taking the lock to > avoid lock nesting (though it would be ok if we ensured that > we always nest them bottom-up, it is better to just avoid the > issue alltogether, especially as we might find cases where > we want to take it top-down later). > > Signed-off-by: Benjamin Herrenschmidt > > static void pci_enable_bridge(struct pci_dev *dev) > { > struct pci_dev *bridge; > - int retval; > + int retval, enabled; > > bridge = pci_upstream_bridge(dev); > if (bridge) > pci_enable_bridge(bridge); > > - if (pci_is_enabled(dev)) { > - if (!dev->is_busmaster) > - pci_set_master(dev); > + /* Already enabled ? */ > + pci_dev_state_lock(dev); > + enabled = pci_is_enabled(dev); > + if (enabled && !dev->is_busmaster) > + pci_set_master(dev); > + pci_dev_state_unlock(dev); > + if (enabled) > return; > - } > This looks complicated too me especially with the double locking. What do you think about a function doing that check that used an unlocked version of pcie_set_master? Like: dev_state_lock(dev); enabled = pci_is_enabled(dev); if (enabled && !dev->is_busmaster) pci_set_master_unlocked(); pci_dev_state_unlock(dev); BTW If I remember correctly the code today can set bus mastering multiple times without checking if already done. Marta