From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B715930275C for ; Tue, 18 Nov 2025 02:07:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763431660; cv=none; b=okFqfh6X8P7JcbPou+gpY3/YIXjAUPOmCAyLxBf2s5fyfQ8C/Qw9ivCcpwasYVWKr8+XCdZJP/duDPKR/u3g/HUEco0fp0Bir0smu3660u7Nd6L6B8Tf4dsHpFu6mIPShSaaEtTAHs8qBTbjnzGpX3IpkTLYZqgbPt40Vvm2mc0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763431660; c=relaxed/simple; bh=6P73Fu2n2ybgpsjg+frMe8gtm50pWSpVSEfs0WoHSt8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ELfOAjRdsqm9zpBSyooH4vujg2ZIwZf1bYkXIWLoyf1AJ4iXD8fyKEPeGAbdkNG2r+8SFYk/GxwobKG8UasYvX3mjz+4r5lNJkcGKhxRuDlmdS94ITxqdGE3zzHShb/Wvnb3ocXZwRNxEsTrqGMKv6yRqzefXqRdwf0nM52yS0M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com; spf=fail smtp.mailfrom=purestorage.com; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b=NQgwTUdj; arc=none smtp.client-ip=209.85.208.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=purestorage.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b="NQgwTUdj" Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-641677916b5so8899358a12.0 for ; Mon, 17 Nov 2025 18:07:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1763431657; x=1764036457; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=S97KCJ0/M+iebNYM5SPjKQEoYZVp3EkSmik6GozuJgM=; b=NQgwTUdjsWEVevkgCp19cjP5jI7BTCR2IvRwsDks7D4gFmo4rGOuQwsXD4/q3gzeF7 mEGuHuVfVHmESOzxEfNiISrGnDRMAbtgCQonQPY+lSFZKu7sHyfv6jmoyMNoUk5T6J/1 bwbQa6AA9k0uv2WeYkY1x9oEsCxtsh1Aayq3Ek0VvmEqihr1SgNlgmCwYa/ED/xc8/Jq sJR18iUESjbNbSSi2kgwvYTfA84u/4D2KXvf2oWkkLGPHjUvn7Q0qUlJHzFwGyy826G+ zuS+wqXs/xMibb7WR8ZF3FVXWyvuQJmhXPRB/XXA4elSX3cB7+YjFZepCLYutasznMay hxSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763431657; x=1764036457; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=S97KCJ0/M+iebNYM5SPjKQEoYZVp3EkSmik6GozuJgM=; b=pjba9haQU6uWAeGefbcxxl2Ixbafjxx0PZtWu0JJ68+QB4IdGC36EoyJtP4aYHCdOh mPX8fSSppSHQizKZK6upnls/ismdFt3HIqh5Ux07YHzmuMQk+bItThyxxiJuu7bYUFk4 FmFqE7+xkjdy0eIreDPOorNkbve7cDRL4/d5sqC7Om7eVKHLBxcphHzedNlx1L6jxe2x I4k3da0mn9/gBSvnHRj7w8WDjqxeassKK526mD3J8+Qq79yfmNqJ8m06GMWSQrBhq7JN 477sFc5Dq4KvjsU7TrAs6ffNa15r+96iLTr/W0Asnmb/fTuzMFZmkZN/fsUZQsHRtAFk jeTA== X-Forwarded-Encrypted: i=1; AJvYcCUR+Xz5b7Sxm5i/wksEfNQakUVzNfgXuLe93eiBtb9Lrf0dWh/FknDoY0gBdj2I9a4be/8hs9PkZcyN0U4=@vger.kernel.org X-Gm-Message-State: AOJu0YyZTgucPJfSB+ZqLaD4AkCzckCn2X0wGfXldD0g5AC6LHMHbDgT GMgD8+q4ApvcFFaLMqUjCYY6GsspDv/lignVnp7E4CZ35xj+VhtWkUQZq0mwFLO652k= X-Gm-Gg: ASbGncvc2agAtycdclco6mCPv5Yowv2oG+yTEHWRnIoyHHnE3yHfpA22pq8eavDjlC+ dNQWzcsWAkY02E+zhuT/eB7MqDpH9s+zTkcnIgqUKk1WxTZNHPvh6cSHEoYhA7E3DqJZUhIiN7t gItZ57NBD1olmdQ8avtx/8N9PA+YYE87SSu5oYrTL37K8ZEvVjULCLGI9VOgP2fX4iHIA2hlUPQ giB6UYaNcoAxZdM8IG5pwlMRUvpx/FD52RrEkF8OwLW7bUJ/HsM579Kr5rKCfIpIUNvyxwmBaYY 2qb2HX13bW98Z1E0R2L703pBbYXn2KUNqzRosADt7QXF6GYzoMOqA8NuaRgfczo2IDy3MUeiVfr Btsy2aAiEg5z/WQRSRIV+nsNabJOUm8p23OmM9E5bH3sMEUOC59yVsq8kYzqnaV+tfKdp6/UVqT JElaSuh+HRFPiYcU8yGl0B/GKXP3kCjug= X-Google-Smtp-Source: AGHT+IFbl3JzHP+VT8lA2rcee7YupyauKZyKg+dpdXz8GrX8My5LD9qHQc9USZ3iiBkLaLHMiT9+uw== X-Received: by 2002:a17:907:6d29:b0:b73:8b7f:8c48 with SMTP id a640c23a62f3a-b738b7f8f60mr843574666b.37.1763431656972; Mon, 17 Nov 2025 18:07:36 -0800 (PST) Received: from medusa.lab.kspace.sh ([208.88.152.253]) by smtp.googlemail.com with UTF8SMTPSA id a640c23a62f3a-b734fa80cb6sm1224468466b.7.2025.11.17.18.07.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Nov 2025 18:07:34 -0800 (PST) Date: Mon, 17 Nov 2025 18:07:31 -0800 From: Mohamed Khalfella To: Hillf Danton Cc: Jens Axboe , Ming Lei , Waiman Long , linux-nvme@lists.infradead.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/1] nvme: Convert tag_list mutex to rwsemaphore to avoid deadlock Message-ID: <20251118020731.GB2197103-mkhalfella@purestorage.com> References: <20251117202414.4071380-1-mkhalfella@purestorage.com> <20251118013442.9414-1-hdanton@sina.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20251118013442.9414-1-hdanton@sina.com> On Tue 2025-11-18 09:34:41 +0800, Hillf Danton wrote: > On Mon, 17 Nov 2025 12:23:53 -0800 Mohamed Khalfella wrote: > > static void blk_mq_del_queue_tag_set(struct request_queue *q) > > { > > struct blk_mq_tag_set *set = q->tag_set; > > + struct request_queue *firstq; > > + unsigned int memflags; > > > > - mutex_lock(&set->tag_list_lock); > > + down_write(&set->tag_list_rwsem); > > list_del(&q->tag_set_list); > > - if (list_is_singular(&set->tag_list)) { > > - /* just transitioned to unshared */ > > - set->flags &= ~BLK_MQ_F_TAG_QUEUE_SHARED; > > - /* update existing queue */ > > - blk_mq_update_tag_set_shared(set, false); > > + if (!list_is_singular(&set->tag_list)) { > > + up_write(&set->tag_list_rwsem); > > + goto out; > > } > > - mutex_unlock(&set->tag_list_lock); > > + > > + /* > > + * Transitioning the remaining firstq to unshared. > > + * Also, downgrade the semaphore to avoid deadlock > > + * with blk_mq_quiesce_tagset() while waiting for > > + * firstq to be frozen. > > + */ > > + set->flags &= ~BLK_MQ_F_TAG_QUEUE_SHARED; > > + downgrade_write(&set->tag_list_rwsem); > > If the first lock waiter is for write, it could ruin your downgrade trick. How is that possible? If the first waiter or the only waiter is for write then they should not take the semaphore because it has not been fully released yet, right?