Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3280179rdh; Mon, 27 Nov 2023 10:07:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IE0Zr/Px0IYytwlMAAeb/WQSxV/pLjqTVVM1brXjZixSMuNClMavV76/1YSzVl/ddNQDowP X-Received: by 2002:a05:6a20:3d09:b0:18c:134c:a658 with SMTP id y9-20020a056a203d0900b0018c134ca658mr11259484pzi.35.1701108464763; Mon, 27 Nov 2023 10:07:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701108464; cv=none; d=google.com; s=arc-20160816; b=F+xQ9on2nYuyuRe6QsGSKdt7HSG2tCy9ruzBcQ3r6dhbUvTkwPhlU3pFlkMh1fyshK 3a+mfWhzWu2wUWkSDDWhCCPudXfTEO0W6oNKg3+IffyFS/ML6iJkbyi8GLdbRqJjQYiH 3dWIRYoUUTCnnWL9iPjQrvjFK1onCULuTzp6x2A8hxXikArlWfnSb4QWn0CC5RiEDm9W l2v17QEmMS/iz/Xu0HOdkRpPaLunrbZlcQiEdC58GtqYJmHgj5yX5gYMpB/96ofAsxkF /siwvh0DM5azuJNkOlEA9BCj8D50CdmVdGGJnYHZ9ZZvyRzv4Ykk5EATP00XEHpAcf7M YMEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ljPY6c+ZVoDaRu9URPSlOl+hj7hixao53nDFvdkaFl0=; fh=EEa+sJURLWZEnqD9Hyn8QWjYtMTvLgI7W2+88mvOrbI=; b=pXMT42J5zJ1NUxGw7Nq+ga8Xr4FcBng65yLikdaEefPgJP35QdKF1EOwh97/BNrzA6 qCpYC0dvxyp+XdddqpyhMul0ERu5HotTcMKZQ7Khgh1mKyPySZx6BNTx/Fc7k5VzSOvs gvszDwaPopwPsc2IxNZ/1r1LIsxr9aeL135hGBxUChgKhWLZc6mr3oOlwJN2XYopt5BQ UsMR5dfVQogpS92r/1KNbfLksGV3dpilt8Yu2EYLZ6R9vLsmjCp+HJY8Gth1Zad52cO6 /sYq351IwX0oIgsEO70H9aWGpwVLr/ULHvEm9RDTHFEFNGuXGDXXlr/48PkJk+yjOQUt 5j4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fx2QF6SB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id 17-20020a631951000000b0057745d87b50si9997834pgz.139.2023.11.27.10.07.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 10:07:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fx2QF6SB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 7E4D38062363; Mon, 27 Nov 2023 10:07:42 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232084AbjK0SHK (ORCPT + 99 others); Mon, 27 Nov 2023 13:07:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230293AbjK0SHI (ORCPT ); Mon, 27 Nov 2023 13:07:08 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA005191 for ; Mon, 27 Nov 2023 10:07:15 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D53BDC433C7; Mon, 27 Nov 2023 18:07:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701108435; bh=C3iVJwmeksjG1jAgFK6vw2pYVe/zJA3lIfqMl4WWsac=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=fx2QF6SBm6idjn5TdulasO2joS/StL0OvmHxjqPckG9XbaDVKVQqLguxJ+olvY9fp ACMHcwPPgjcKunryqyL9FtMNaOBb7xdAIRGon4eElaOX8Wxy63hBHFUB59+NXRjUyt FL1l8BeDv907J+DzcvkrXFbWYeBc/0r6B4uYGno7EmzHMdX9ID3JJKWWm29+w2L3Ms amjd+gzzB1JeYYEHBbzZg2OtWWizp6kalTUrh4Pa1HxKZiiTt/hKcqI3x17EMFBDMY PTSVVm5b4at1yVXypqNr584qNxZRzsZaJAIU3u48Slb40iAqbUPch4eLPHGr/JWCPn rS4hrjKDnJ7Kw== Date: Mon, 27 Nov 2023 11:07:12 -0700 From: Keith Busch To: Bitao Hu Cc: axboe@kernel.dk, hch@lst.de, sagi@grimberg.me, linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, kanie@linux.alibaba.com Subject: Re: [PATCH] nvme: fix deadlock between reset and scan Message-ID: References: <1700737213-110685-1-git-send-email-yaoma@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1700737213-110685-1-git-send-email-yaoma@linux.alibaba.com> X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.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 (groat.vger.email [0.0.0.0]); Mon, 27 Nov 2023 10:07:42 -0800 (PST) On Thu, Nov 23, 2023 at 07:00:13PM +0800, Bitao Hu wrote: > @@ -3631,6 +3631,11 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, struct nvme_ns_info *info) > goto out_unlink_ns; > > down_write(&ctrl->namespaces_rwsem); > + /* preventing adding ns during resetting */ > + if (unlikely(ctrl->state != NVME_CTRL_LIVE)) { We can't rely on ctrl->state for preventing deadlocks. Reading unlocked ctrl->state is often used, but should be considered advisory-only since the state could change immediatly after reading it. > + up_write(&ctrl->namespaces_rwsem); > + goto out_unlink_ns; > + } > nvme_ns_add_to_ctrl_list(ns); > up_write(&ctrl->namespaces_rwsem); > nvme_get_ctrl(ctrl);