Received: by 10.213.65.68 with SMTP id h4csp1196129imn; Wed, 21 Mar 2018 05:12:16 -0700 (PDT) X-Google-Smtp-Source: AG47ELs5k8SZUBtQlPmh0bxy/XsaU/tDghux/DJShasqvr+HCGtp8SY6dqbQA4WSSZGRdty6aFJX X-Received: by 10.99.109.75 with SMTP id i72mr9510028pgc.403.1521634336151; Wed, 21 Mar 2018 05:12:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521634336; cv=none; d=google.com; s=arc-20160816; b=tFkyGFbw/hVU05DjUQIFEasGxNe9rX2c57FWzfi+BelzwgR/6GEDHQc1GTtxDAynAs RcBOtRl1dNsZl/Mj/P7oL8/TDfXwXl+zJi67GsO/yTx1oecOCulSDCAu7vceP4H0iKAD ameS14h+AGAfj5MfsMKzrYoLOFZsylQ6mkJ4/bphQ78Lx96KLswWcOAAOOIv38ieRGD7 yn2l2LNdtdbMyDaZedIjk63rOCHP3JlzQ77Yz4Zx/GLFHGRYdHALSyTh/yWWspu3J9oZ GasXxcmLlbt3fHY82PU5fxWeOk03IEQPyZ0pF28dGej+4aExsDk8wKsPnebPtHZjWtW5 NgRg== 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=yoYxHOKOSlH3ir4Ln+jR5ROV7o68rFHkq7VKWU+wrT8=; b=birx7IRu25a3h4zREtnSTFbIevqcwGsG35rVF9dS8soWX1RgpameoIi3VxtR8Qe0HN cftsGYByODlqC56+fxEGSCiP4NUSXIWs8rO8u38se7nxjDvSbjXXEMtChCEdJkGmXayO Y2zFPnwJm0CdNEyLciweUYz9sBjpSvrh8UdzBNAf2FKNUPpgK8NE325zxpPIRE97v/9H mCPp5sflTfBW2+xbfkFs3Q0Pcq9ASqdt62efUEYgEKWjqJc/NHITInzPpLV3UPbHe2cg RpEkqXnYBbIeITUd5zkSOECo3B3n6ZLL8o/w5+36aqPpYDg4T1WmIXu5pV+8DoOk2e1I Xqkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kalray.eu header.s=32AE1B44-9502-11E5-BA35-3734643DEF29 header.b=AbPYH2Bv; 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 n66si2975701pfa.17.2018.03.21.05.12.01; Wed, 21 Mar 2018 05:12:16 -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=AbPYH2Bv; 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 S1751978AbeCUMKg (ORCPT + 99 others); Wed, 21 Mar 2018 08:10:36 -0400 Received: from zimbra1.kalray.eu ([92.103.151.219]:40052 "EHLO zimbra1.kalray.eu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751712AbeCUMKd (ORCPT ); Wed, 21 Mar 2018 08:10:33 -0400 Received: from localhost (localhost [127.0.0.1]) by zimbra1.kalray.eu (Postfix) with ESMTP id E5795280092; Wed, 21 Mar 2018 13:10:31 +0100 (CET) Received: from zimbra1.kalray.eu ([127.0.0.1]) by localhost (zimbra1.kalray.eu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id DdtfPRsXrL8C; Wed, 21 Mar 2018 13:10:31 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by zimbra1.kalray.eu (Postfix) with ESMTP id 8331F2800C0; Wed, 21 Mar 2018 13:10:31 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.9.2 zimbra1.kalray.eu 8331F2800C0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kalray.eu; s=32AE1B44-9502-11E5-BA35-3734643DEF29; t=1521634231; bh=yoYxHOKOSlH3ir4Ln+jR5ROV7o68rFHkq7VKWU+wrT8=; h=Date:From:To:Message-ID:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding; b=AbPYH2BvJy4WWazhUEG++mEGoTafUc00GehZT1yYNfUkEC0eEAgLQbELXMNqtgz70 siURCLANszwlsxbRvDa+9dc0uOaeDnHAqZHNdFgtnFWHUCcfxIUhkTpVUeivOMNM86 pP1js86DqZiH6Y8rm8RORpOaIUPUMEWeiVHi+XWg= X-Virus-Scanned: amavisd-new at kalray.eu Received: from zimbra1.kalray.eu ([127.0.0.1]) by localhost (zimbra1.kalray.eu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id c1pejC_j5GIb; Wed, 21 Mar 2018 13:10:31 +0100 (CET) Received: from zimbra1.kalray.eu (localhost [127.0.0.1]) by zimbra1.kalray.eu (Postfix) with ESMTP id 65937280092; Wed, 21 Mar 2018 13:10:31 +0100 (CET) Date: Wed, 21 Mar 2018 13:10:31 +0100 (CET) From: Marta Rybczynska To: Ming Lei Cc: keith busch , axboe@fb.com, hch@lst.de, sagi@grimberg.me, linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, bhelgaas@google.com, linux-pci@vger.kernel.org, Pierre-Yves Kerbrat Message-ID: <464125757.5843583.1521634231341.JavaMail.zimbra@kalray.eu> In-Reply-To: <20180321115037.GA26083@ming.t460p> References: <744877924.5841545.1521630049567.JavaMail.zimbra@kalray.eu> <20180321115037.GA26083@ming.t460p> Subject: Re: [RFC PATCH] nvme: avoid race-conditions when enabling devices MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [192.168.40.201] X-Mailer: Zimbra 8.6.0_GA_1182 (ZimbraWebClient - FF45 (Linux)/8.6.0_GA_1182) Thread-Topic: nvme: avoid race-conditions when enabling devices Thread-Index: wnfMsSM1imrqGZKFoiQyJor/pqOrIQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Wed, Mar 21, 2018 at 12:00:49PM +0100, Marta Rybczynska wrote: >> NVMe driver uses threads for the work at device reset, including enabling >> the PCIe device. When multiple NVMe devices are initialized, their reset >> works may be scheduled in parallel. Then pci_enable_device_mem can be >> called in parallel on multiple cores. >> >> This causes a loop of enabling of all upstream bridges in >> pci_enable_bridge(). pci_enable_bridge() causes multiple operations >> including __pci_set_master and architecture-specific functions that >> call ones like and pci_enable_resources(). Both __pci_set_master() >> and pci_enable_resources() read PCI_COMMAND field in the PCIe space >> and change it. This is done as read/modify/write. >> >> Imagine that the PCIe tree looks like: >> A - B - switch - C - D >> \- E - F >> >> D and F are two NVMe disks and all devices from B are not enabled and bus >> mastering is not set. If their reset work are scheduled in parallel the two >> modifications of PCI_COMMAND may happen in parallel without locking and the >> system may end up with the part of PCIe tree not enabled. > > Then looks serialized reset should be used, and I did see the commit > 79c48ccf2fe ("nvme-pci: serialize pci resets") fixes issue of 'failed > to mark controller state' in reset stress test. > > But that commit only covers case of PCI reset from sysfs attribute, and > maybe other cases need to be dealt with in similar way too. > It seems to me that the serialized reset works for multiple resets of the same device, doesn't it? Our problem is linked to resets of different devices that share the same PCIe tree. You're right that the problem we face might also come with manual resets under certain conditions (I think that all devices in a subtree would need to be disabled). Thanks, Marta