Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp696066rdb; Tue, 23 Jan 2024 11:52:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IF0G0ZurrXVW7tkQXNN1chAydiDTxgVva8DdgiLNhXDK1NO0TOaRwRldZVCZwYwqLIJsUYD X-Received: by 2002:a17:903:11ce:b0:1d5:73d0:eb80 with SMTP id q14-20020a17090311ce00b001d573d0eb80mr4662090plh.64.1706039540285; Tue, 23 Jan 2024 11:52:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706039540; cv=pass; d=google.com; s=arc-20160816; b=e+ksJ4hR2KOwct3TssS5kE7xNzLRbwOZ8URg3NdUPKtZ8XPd3e7HQoOPq971j4E4Oo lXAppxCo5A2psFMdvcBg3FZnyJHWv+GJE8rfs18BkoalOYXBxo8kmylCWMG7GpVPWZA6 x32YVns7DEWs0n90mgv0kYq7x2oZduaJWM2YN5Mai0cFTyK3f+GJowFgPRMv42FvANLr eukv3E3Jgr95Sw44m9ejbj+6ZLHmCDtF9QaMovan7Sx5LnpIOX1hSxdLhCmTzopg5uc+ D3D5UDd7aZd8KUNVVMwPy0K3Ud7lTGEhebT3uHqTLOBVcublH8l5t8+ZWZTioYfaQsCu xBGg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=MJiJcMIQI1iDwNDklvvfzLsvJuPDH8da2+abjrEKSAk=; fh=d1kTOEpYLwj/y7Q40EX+AbQEUzKb/I/xDRU8M4AUp2A=; b=mQmjb0PpNArpYambrD4OgyzW1WqHD7f0c/OJg4wSwLVnaxfHX7pn8RO75kV7HARh7h dB00LWYWCR2MwR2Kh65O304Mqb6JKcw9OMnwo39mnhbewC8/k9tkQ5T6Hj2dTxB4Jvxn 1XoSmcRO6p6J/d75QJwxZK5TTkTDbgtmYcAJ1cdEAOIMq6ByswfO0T/1n9wqst9wv8dj 1USJZcH5b8i8GjCdv9b0DNPURkK4tM0UvEWJYdiweFKE+4YKo/WBQXS0Iwptx1Pjfvva dZXbe3z48M72YufaJfRks5mvm6ZEVBiqzOxT4sg6YOy2c+2KcyXnYw88viXupMZoDBC3 eypg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MsLzpfBz; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-35975-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35975-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id h12-20020a170902f7cc00b001d75e0877d4si2930423plw.616.2024.01.23.11.52.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 11:52:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-35975-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MsLzpfBz; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-35975-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35975-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 857F0B293BD for ; Tue, 23 Jan 2024 19:15:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BE51F82D6B; Tue, 23 Jan 2024 19:14:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MsLzpfBz" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E0C5B50A64; Tue, 23 Jan 2024 19:14:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706037298; cv=none; b=isPE9iDWPoD3GNLi0RSLJ+34BseevENUJDkXYMkpz2JoOlSMHPixSWmx/2xH93gtRsemc3NsOpmrssEF6lcBnikBqzuwRT9jSN9KpqLQXp7aYWXh+DPPeHYGxwMCXZzhdhp1RzQRPj2m17lj0IgdrPNPFOx1NWrnLpyRnqc5w3s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706037298; c=relaxed/simple; bh=yUpKsP8bVl80uJpZfTJsdrlqZYLDIS9nN+AT5h0Y3hs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=rK0tozJFjrGpIrJEZGSURu+ZNiIImo14UpuKZv8Gz5rzAgRJ1JqIG40xAf/8HMR5/zsC+WYQ3pNfESAqe3YInPEL9y/LSvoDTSNVLavY1BVaay5K+Yz8U6+e77MNgQTSQFQBlB9ATRIw68h7vfClcNiBA7PgsPvj8D3QrX3ua0E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MsLzpfBz; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48F18C433F1; Tue, 23 Jan 2024 19:14:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706037297; bh=yUpKsP8bVl80uJpZfTJsdrlqZYLDIS9nN+AT5h0Y3hs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=MsLzpfBz//jNj6WTNX3v/HYwgipRg0uP3mI3V+orEgrXFs6JQUZpUshVL22Av9mqG fQbMT4X/lC2E1T73SebaeykdGxZ5Yccn+xTVCMGMSS7ofCY1OYb5gGb5l97sBhOIby rOgwjOGyLo4sEgiLdwDaDAHIflJoU16D5rG9vRygUVftJGD89pL/5Th/wmF9GwJg2l QgGyyFNwG6KTcoKjMjlAmJ1utyi8MooF0TzmIZNRL52syH8+qkq6Fr66I8TKp1D2Bc 17RNuOI8OXnzqqnW7lVNsRqwKHNiz8PJaeVC3/lilfhP9MihYZmHHOn8HaxUddYF4c iTSJN+9k9184g== Date: Tue, 23 Jan 2024 12:14:53 -0700 From: Keith Busch To: Yi Sun Cc: axboe@kernel.dk, mst@redhat.com, jasowang@redhat.com, xuanzhuo@linux.alibaba.com, pbonzini@redhat.com, stefanha@redhat.com, virtualization@lists.linux.dev, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, zhiguo.niu@unisoc.com, hongyu.jin@unisoc.com, sunyibuaa@gmail.com Subject: Re: [PATCH 1/2] blk-mq: introduce blk_mq_tagset_wait_request_completed() Message-ID: References: <20240122110722.690223-1-yi.sun@unisoc.com> <20240122110722.690223-2-yi.sun@unisoc.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: <20240122110722.690223-2-yi.sun@unisoc.com> On Mon, Jan 22, 2024 at 07:07:21PM +0800, Yi Sun wrote: > In some cases, it is necessary to wait for all requests to become complete > status before performing other operations. Otherwise, these requests will never > be processed successfully. > > For example, when the virtio device is in hibernation, the virtqueues > will be deleted. It must be ensured that virtqueue is not in use before being deleted. > Otherwise the requests in the virtqueue will be lost. This function can ensure > that all requests have been taken out of the virtqueues. > > Prepare for fixing this kind of issue by introducing > blk_mq_tagset_wait_request_completed(). Does blk_mq_freeze_queue() not work for your use case? I think that should work unless you have some driver specific requests entered that don't ever get released. > +static bool blk_mq_tagset_count_inflight_rqs(struct request *rq, void *data) > +{ > + unsigned int *count = data; > + > + if (blk_mq_request_started(rq) && !blk_mq_request_completed(rq)) > + (*count)++; > + return true; > +} > + > +/** > + * blk_mq_tagset_wait_request_completed - Wait for all inflight requests > + * to become completed. > + * > + * Note: This function has to be run after all IO queues are shutdown. > + */ > +void blk_mq_tagset_wait_request_completed(struct blk_mq_tag_set *tagset) > +{ > + while (true) { > + unsigned int count = 0; > + > + blk_mq_tagset_busy_iter(tagset, > + blk_mq_tagset_count_inflight_rqs, &count); If the tagset is shared, then one active user can prevent this from ever completing. It sounds like your use case cares about just one specific request_queue, not all of them. > + if (!count) > + break; > + msleep(20); > + } > +} > +EXPORT_SYMBOL(blk_mq_tagset_wait_request_completed);