Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4318702rdh; Tue, 28 Nov 2023 19:29:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IGk+fNSffG7ghzjxGFK9yoUVUZiahQqjbW9nj712gXRd/7qXWXI0JrwyHj2tS69jSSGK6he X-Received: by 2002:a05:6358:52cf:b0:16e:12c:16b8 with SMTP id z15-20020a05635852cf00b0016e012c16b8mr22656953rwz.7.1701228553490; Tue, 28 Nov 2023 19:29:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701228553; cv=none; d=google.com; s=arc-20160816; b=XURozVoZjPs8sig0oAlyR+qayM4CffcOtqQ6vA/eXMlSUOhBUWgWPQc7gIzsA+240Z QqU9AAG8RFKjW04pzNlg3Kzjbq9B56CPqHpODPaY0i+HQBN0xzoFGFGrmqbkjv18OT+5 VslzvsOqUk3tA9+LfElV/bzuBf2jqcnvTM8i4wXIWMzP/l7LNilJpTqEuu/yGU3X0tl6 zPcSxbKirpU4bfAgOSoHLQgk6cy33G5hsu/cwe71QLKU+iCDnzT03yhhhj30MA3WDWAn c4tZd9Jg+lCXCORr7bbWrgvXXK5ALY00+dgiWPrnSiUMYGIW6u2Eai8jf0srMKvZ06Jt IExw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=m1BAbGX4MaRyjkntvz2pGzUXlU2g/9i8HVsKhs58iRk=; fh=Cu6iZeMq6GYjr07R2Xm4i9FwHMnSpMeAQ1PfS7DFzFo=; b=uvaxN9RM4Lz/BV0Eh3wD8VrwYnZHPr+cfL0+HGkBz6ytMjC7Q/mQ1N3c5kRMh/BwaX vSrAqFt1o+yl20sZHpkOkxOpCPGycL+8zljZrgruNHxggzKLXroaLdUFF5jblFisC6O8 lopKFgz9wrxKAfYuN4M+utVzeIC1Geu8Mrc6seAsfEPBGreWLzC6bNg0hyLbjMIDwI1c BfdAkGcAJiq/rW2cyfcz8szm2MERvWgRZnWMX5qiIBK6QdIQuXzddbZ408efBCfaUH6v ZNRsDDJE7xah0JVJSOXhKjuaVR9Xs3Wd6BJgku5E05S6UrQwbdHBCno7SYdhxAURz8ZX 9HmQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id y17-20020a634b11000000b005c5e2ac7c3csi3439502pga.732.2023.11.28.19.29.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 19:29:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 90AEC81C8D88; Tue, 28 Nov 2023 19:29:10 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230187AbjK2D2v (ORCPT + 99 others); Tue, 28 Nov 2023 22:28:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229880AbjK2D2t (ORCPT ); Tue, 28 Nov 2023 22:28:49 -0500 Received: from out30-113.freemail.mail.aliyun.com (out30-113.freemail.mail.aliyun.com [115.124.30.113]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 734BE1AD for ; Tue, 28 Nov 2023 19:28:48 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R501e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046060;MF=yaoma@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0VxMeem7_1701228524; Received: from 30.178.67.199(mailfrom:yaoma@linux.alibaba.com fp:SMTPD_---0VxMeem7_1701228524) by smtp.aliyun-inc.com; Wed, 29 Nov 2023 11:28:46 +0800 Message-ID: Date: Wed, 29 Nov 2023 11:28:40 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH] nvme: fix deadlock between reset and scan Content-Language: en-US To: Sagi Grimberg , Keith Busch Cc: axboe@kernel.dk, hch@lst.de, linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, kanie@linux.alibaba.com References: <1700737213-110685-1-git-send-email-yaoma@linux.alibaba.com> <65b0c372-b308-46dd-c2f2-a5ddb50adb10@linux.alibaba.com> From: yaoma In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Tue, 28 Nov 2023 19:29:10 -0800 (PST) On 2023/11/28 18:13, Sagi Grimberg wrote: > > > On 11/28/23 08:22, yaoma wrote: >> Hi Keith Busch >> >> Thanks for your reply. >> >> The idea to avoid such a deadlock between nvme_reset and nvme_scan is >> to ensure that no namespace can be added to ctrl->namespaces after >> nvme_start_freeze has already been called. We can achieve this goal by >> assessing the ctrl->state after we have already acquired the >> ctrl->namespaces_rwsem lock, to decide whether to add the namespace to >> the list or not. >> 1. After we determine that ctrl->state is LIVE, it may be immediately >> changed to another state. However, since we have already acquired the >> lock, other tasks cannot access ctrl->namespace, so we can still >> safely add the namespace to the list. After acquiring the lock, >> nvme_start_freeze will freeze all ns->q in the list, including any >> newly added namespaces. >> 2. Before the completion of nvme_reset, ctrl->state will not be >> changed to LIVE, so we will not add any more namespaces to the list. >> All ns->q in the list is frozen, so nvme_wait_freeze can exit normally. > > I agree with the analysis, there is a hole between start_freeze and > freeze_wait that a scan may add a ns to the ctrl ns list. > I think your proposal is nice, and I will test it. > However the fix should be to mark the ctrl with say NVME_CTRL_FROZEN > flag set in nvme_freeze_start and cleared in nvme_unfreeze (similar > to what we did with quiesce). Then the scan can check it before adding > the new namespace (under the namespaces_rwsem).