From patchwork Wed Oct 30 12:42:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 13856463 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 5871B1E411D for ; Wed, 30 Oct 2024 12:42:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730292180; cv=none; b=GKPFL5Zl5RkZPXnCIZUuAL6jQefQfz/8O+t8cD/mrqeWs+O3t9RqYXc0XPpzlVknPz1fnWoxA+32jbUBLcMpL1A+gKomhx/YmLUxQQ5sO4lwe98beNxIdz11ya0X93tg+kuFJNiuRSjMHa8vb0Rd0msD+vaqHaIQQDQYv+4BHmE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730292180; c=relaxed/simple; bh=AB85rTZ5YPUJXxdwH7AeqhFiZd1VN69oG+BBqjTfOME=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S6ZCM25zYGma7F1XlMMzNrlUVtCdK/I+RNDK6uMx1pMD0M1fsS4Nk2tt9kS6A1y9YMFpyS/vEfbfthBQld4OvlJ2fovWcsRuJZRkXq8zI1cYe6aPzKNJWXIkgWrFLtsZzX/rO8zSmCkqwBe2BQeQCXGOgXeMb1RIVolywW+b9H4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=HfedK+G8; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HfedK+G8" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730292177; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Gj51ZyDnTf64k5sb/MgIMzO8F3KLT7gNACXbK+gTyKU=; b=HfedK+G8DVl35sXRpnSAd8CXs6AtYABgO826aWchBfbXNtt8Dh816yTusSci0p+KBc6umj RnAIrNzI/Z+be9XKvMGjfvn7moyxJA70S5cQkj2nSBiSfdZUi5HSlc/KdLOsqv+JM8ALGq cs7jygQXXkFe1FA2Ba0vff7yLYxgRHk= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-442-UPKqMo2jNWigriaMOavfjw-1; Wed, 30 Oct 2024 08:42:55 -0400 X-MC-Unique: UPKqMo2jNWigriaMOavfjw-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CCCEA1955DAF; Wed, 30 Oct 2024 12:42:54 +0000 (UTC) Received: from localhost (unknown [10.72.116.140]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 67D5B19560AA; Wed, 30 Oct 2024 12:42:52 +0000 (UTC) From: Ming Lei To: Jens Axboe , linux-block@vger.kernel.org Cc: Christoph Hellwig , Ming Lei Subject: [PATCH 1/5] block: remove blk_freeze_queue() Date: Wed, 30 Oct 2024 20:42:33 +0800 Message-ID: <20241030124240.230610-2-ming.lei@redhat.com> In-Reply-To: <20241030124240.230610-1-ming.lei@redhat.com> References: <20241030124240.230610-1-ming.lei@redhat.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 No one use blk_freeze_queue(), so remove it and the obsolete comment. Signed-off-by: Ming Lei Reviewed-by: Christoph Hellwig --- block/blk-mq.c | 22 +--------------------- block/blk.h | 1 - 2 files changed, 1 insertion(+), 22 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 4ae7eb335fbd..5f4496220432 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -161,31 +161,11 @@ int blk_mq_freeze_queue_wait_timeout(struct request_queue *q, } EXPORT_SYMBOL_GPL(blk_mq_freeze_queue_wait_timeout); -/* - * Guarantee no request is in use, so we can change any data structure of - * the queue afterward. - */ -void blk_freeze_queue(struct request_queue *q) +void blk_mq_freeze_queue(struct request_queue *q) { - /* - * In the !blk_mq case we are only calling this to kill the - * q_usage_counter, otherwise this increases the freeze depth - * and waits for it to return to zero. For this reason there is - * no blk_unfreeze_queue(), and blk_freeze_queue() is not - * exported to drivers as the only user for unfreeze is blk_mq. - */ blk_freeze_queue_start(q); blk_mq_freeze_queue_wait(q); } - -void blk_mq_freeze_queue(struct request_queue *q) -{ - /* - * ...just an alias to keep freeze and unfreeze actions balanced - * in the blk_mq_* namespace - */ - blk_freeze_queue(q); -} EXPORT_SYMBOL_GPL(blk_mq_freeze_queue); bool __blk_mq_unfreeze_queue(struct request_queue *q, bool force_atomic) diff --git a/block/blk.h b/block/blk.h index 63d5df0dc29c..ac48b79cbf80 100644 --- a/block/blk.h +++ b/block/blk.h @@ -35,7 +35,6 @@ struct blk_flush_queue *blk_alloc_flush_queue(int node, int cmd_size, gfp_t flags); void blk_free_flush_queue(struct blk_flush_queue *q); -void blk_freeze_queue(struct request_queue *q); bool __blk_mq_unfreeze_queue(struct request_queue *q, bool force_atomic); bool blk_queue_start_drain(struct request_queue *q); bool __blk_freeze_queue_start(struct request_queue *q); From patchwork Wed Oct 30 12:42:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 13856464 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 5B6001E411D for ; Wed, 30 Oct 2024 12:43:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730292186; cv=none; b=sYLdGL9b+rD9haHkh1DAc6buMduSmba0KyEPTjTlglnKPtjHj6HTZZxuALS+Hzlv3u3V1rQqOinISlWr8TXvBqAwzLFdnKuJUY47yXy6wdacITZRRDUGR0YRTbmqZlI1UiMftEQKT92VOz0v8s417SE6KS4gsnHpGzgSUxyvIro= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730292186; c=relaxed/simple; bh=cIpm7/Mv1/Dm5u3a5E2sIF9GhrybngbpYo4cGeWviDo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NrMVqpWsBcwGTFQ+Qn1fa/i+RS9bdUzPaVe0Ro4LdNUGm3ByAH4XS1CCrKaWAfP6UZxlfsQRdvwUuFgkEsPt4vwoGlvCRpX4HsgUGsatqq3cgiiFHHhtCPzcfKTSrK37cEVx5bN4ltKOUsUqOltUFT/fZ4TV+uP6DkIv+khgXdc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=JoP+bus6; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="JoP+bus6" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730292183; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ApEMFDOrNDD/+MWPH551HnF0S8o5RB1vvdhPKMCWkUc=; b=JoP+bus6JKtVwZ6s6Xy7fetJhqqvk0E1+xp4xCwfTLm9nuPyUDZZPRuF7QnXEk50BfZqpw zug1iB8OW9pU2co+Ytc6T2LmzqK8/Wg5yyilrXw7peETny1obRgyOWyM/XDCVlhqHVB5kj DkYPbbeuxRWY6u7Fnwr6HBlX733QLGI= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-158-MBdBJgmvN2iYW6NZ53nfyA-1; Wed, 30 Oct 2024 08:43:00 -0400 X-MC-Unique: MBdBJgmvN2iYW6NZ53nfyA-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5628019560BF; Wed, 30 Oct 2024 12:42:59 +0000 (UTC) Received: from localhost (unknown [10.72.116.140]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DDDFB19560AA; Wed, 30 Oct 2024 12:42:57 +0000 (UTC) From: Ming Lei To: Jens Axboe , linux-block@vger.kernel.org Cc: Christoph Hellwig , Ming Lei Subject: [PATCH 2/5] blk-mq: add non_owner variant of blk_mq_freeze_queue API Date: Wed, 30 Oct 2024 20:42:34 +0800 Message-ID: <20241030124240.230610-3-ming.lei@redhat.com> In-Reply-To: <20241030124240.230610-1-ming.lei@redhat.com> References: <20241030124240.230610-1-ming.lei@redhat.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 Add non_owner variant of blk_mq_freeze_queue API for rbd. Signed-off-by: Ming Lei --- block/blk-mq.c | 14 +++++++++++--- include/linux/blk-mq.h | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 5f4496220432..8e18284ede8f 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -195,12 +195,20 @@ void blk_mq_unfreeze_queue(struct request_queue *q) EXPORT_SYMBOL_GPL(blk_mq_unfreeze_queue); /* - * non_owner variant of blk_freeze_queue_start + * non_owner variant of blk_mq_freeze_queue * - * Unlike blk_freeze_queue_start, the queue doesn't need to be unfrozen - * by the same task. This is fragile and should not be used if at all + * Unlike blk_mq_freeze_queue, the queue doesn't need to be unfrozen by + * the same task. This is fragile and should not be used if at all * possible. */ +void blk_mq_freeze_queue_non_owner(struct request_queue *q) +{ + __blk_freeze_queue_start(q); + blk_mq_freeze_queue_wait(q); +} +EXPORT_SYMBOL_GPL(blk_mq_freeze_queue_non_owner); + +/* non_owner variant of blk_freeze_queue_start */ void blk_freeze_queue_start_non_owner(struct request_queue *q) { __blk_freeze_queue_start(q); diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h index 2035fad3131f..ed15dc2e7bd6 100644 --- a/include/linux/blk-mq.h +++ b/include/linux/blk-mq.h @@ -919,6 +919,7 @@ void blk_freeze_queue_start(struct request_queue *q); void blk_mq_freeze_queue_wait(struct request_queue *q); int blk_mq_freeze_queue_wait_timeout(struct request_queue *q, unsigned long timeout); +void blk_mq_freeze_queue_non_owner(struct request_queue *q); void blk_mq_unfreeze_queue_non_owner(struct request_queue *q); void blk_freeze_queue_start_non_owner(struct request_queue *q); From patchwork Wed Oct 30 12:42:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 13856465 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 391F11E411D for ; Wed, 30 Oct 2024 12:43:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730292190; cv=none; b=HaEcLu+P47x82pzy+MAno68l4SRUUmau7rjkOiY+VpJE+GhtV7biQAPnHhc4TAAPHtSDClvfxVCbUcvAa8XL8nfEsUq3cLvcAoMUB1/+Yg3PcB7ZFwPxJ6gpzSRBpE+MgJ0icpkbwsE1u6zkHAhDQk5GmKkKw9VvePvMvZS8mRo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730292190; c=relaxed/simple; bh=xIDDJ2iriMWUvhnOBPwvhMViDw2wqRXR4WaxMM2XkGg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g1ErkIK/C3qef2luVdw/DNromJKQ3+UwHAIAEHw+lpTRfMxBymHKz64EiZw3bAHiDbjyPFDm/9REWNfLa26zJJGAbXfZq45eQhjVYzwh3O2UwQYwJ/63VRl4eqDLOkDL5fHeC1/vBvcNThumaKryJpoG2FXVAlvFfpb18hQpseA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=TGqMTh2c; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TGqMTh2c" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730292186; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EkQqbAAQxUN8KVTJJir8/kNitbMwZ9QU4FyTIn53bVw=; b=TGqMTh2cl9zqevcFqI35YOEkz481cXdKV9RqLTRq/UCx5FMU09NUWfrZhi6mgREIdIYZYu DgtccYFVDUkoTBykQvFeYS+0cMZrEK4hu6pjzNecBUzi7o592xuPJV7dK1z1Y9TLr93xGr RQutmDtYhplzw5T0nHkcBn6Ik+DSrLw= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-543-TP-ektvbMBSzS6pFAFBjqA-1; Wed, 30 Oct 2024 08:43:04 -0400 X-MC-Unique: TP-ektvbMBSzS6pFAFBjqA-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8DD551955D5F; Wed, 30 Oct 2024 12:43:03 +0000 (UTC) Received: from localhost (unknown [10.72.116.140]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6F4DC19560A2; Wed, 30 Oct 2024 12:43:01 +0000 (UTC) From: Ming Lei To: Jens Axboe , linux-block@vger.kernel.org Cc: Christoph Hellwig , Ming Lei , Ilya Dryomov Subject: [PATCH 3/5] rbd: convert to blk_mq_freeze_queue_non_owner Date: Wed, 30 Oct 2024 20:42:35 +0800 Message-ID: <20241030124240.230610-4-ming.lei@redhat.com> In-Reply-To: <20241030124240.230610-1-ming.lei@redhat.com> References: <20241030124240.230610-1-ming.lei@redhat.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 rbd just calls blk_mq_freeze_queue() only, and doesn't unfreeze queue in current context, so convert to blk_mq_freeze_queue_non_owner(). Cc: Ilya Dryomov Signed-off-by: Ming Lei --- drivers/block/rbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 9c8b19a22c2a..63c183ecdad9 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -7282,7 +7282,7 @@ static ssize_t do_rbd_remove(const char *buf, size_t count) * Prevent new IO from being queued and wait for existing * IO to complete/fail. */ - blk_mq_freeze_queue(rbd_dev->disk->queue); + blk_mq_freeze_queue_non_owner(rbd_dev->disk->queue); blk_mark_disk_dead(rbd_dev->disk); } From patchwork Wed Oct 30 12:42:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 13856466 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 585A11E411D for ; Wed, 30 Oct 2024 12:43:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730292195; cv=none; b=Le3La77m3WwZCQLgFwkKr73xziNsf5z5avOWKi1IwmARJ3NHujR55WSy2ozjg5UPl2kbpbe12HHgHodpmJshIBVcAlbzU4PaWV4ed6DpTrdW6bZmyGtPkgG88GWWMMKSXgrfN6wO6pEufI8G1wY1cwdUarTwTtlEwoPeN5Jo2co= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730292195; c=relaxed/simple; bh=6fTXXss0/F3172O6krhVlRuOkwCp8dxYxXn5hpoaLx4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Numy+rSPdC1SJpnqrKNQr6ZN28iXC75fscFk72ORTem59wkTS2bJ+u40TJVhkP5jcvlk7NHaLrx4Mz9pXalT/zL/RN/jc6al4lzzB53cXNl4tdcu4n+zPoXs/UKYtIKqSqrt1/3OmbUExYSlBG/+sBPCfDq/Isn19o1Ienq/JNo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Ad7wuOsP; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Ad7wuOsP" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730292192; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=o88gQXk6bKDn3xWx+KbliHNR53IEZiC2j3ghNu9LYVM=; b=Ad7wuOsPv50SjTUSxEYJW6E6OHyiL7j59MT53L1C6OhKZdtuEZFBMDLgldTQ1NPBP4zZyg +76AQjsPrRtjx0ZpnBOJ27nKD/8OHGs/w5FQy17TutHKGVouk8XmpTUvihmnxM1oobv+vj mqV04t3kcJGhSCKCYRMpnV43/ZyA0eo= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-140-qyuPjcYfOiO6Ok5Le34WfA-1; Wed, 30 Oct 2024 08:43:09 -0400 X-MC-Unique: qyuPjcYfOiO6Ok5Le34WfA-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EB58B1955F29; Wed, 30 Oct 2024 12:43:07 +0000 (UTC) Received: from localhost (unknown [10.72.116.140]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BA9B119560A3; Wed, 30 Oct 2024 12:43:06 +0000 (UTC) From: Ming Lei To: Jens Axboe , linux-block@vger.kernel.org Cc: Christoph Hellwig , Ming Lei Subject: [PATCH 4/5] block: always verify unfreeze lock on the owner task Date: Wed, 30 Oct 2024 20:42:36 +0800 Message-ID: <20241030124240.230610-5-ming.lei@redhat.com> In-Reply-To: <20241030124240.230610-1-ming.lei@redhat.com> References: <20241030124240.230610-1-ming.lei@redhat.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 commit f1be1788a32e ("block: model freeze & enter queue as lock for supporting lockdep") tries to apply lockdep for verifying freeze & unfreeze. However, the verification is only done the outmost freeze and unfreeze. This way is actually not correct because q->mq_freeze_depth still may drop to zero on other task instead of the freeze owner task. Fix this issue by always verifying the last unfreeze lock on the owner task context, and freeze lock is still verified on the outmost one. Fixes: f1be1788a32e ("block: model freeze & enter queue as lock for supporting lockdep") Signed-off-by: Ming Lei --- block/blk-core.c | 2 +- block/blk-mq.c | 64 ++++++++++++++++++++++++++++++++++++------ block/blk.h | 3 +- include/linux/blkdev.h | 4 +++ 4 files changed, 62 insertions(+), 11 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index 09d10bb95fda..4f791a3114a1 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -287,7 +287,7 @@ bool blk_queue_start_drain(struct request_queue *q) * entering queue, so we call blk_freeze_queue_start() to * prevent I/O from crossing blk_queue_enter(). */ - bool freeze = __blk_freeze_queue_start(q); + bool freeze = __blk_freeze_queue_start(q, current); if (queue_is_mq(q)) blk_mq_wake_waiters(q); /* Make blk_queue_enter() reexamine the DYING flag. */ diff --git a/block/blk-mq.c b/block/blk-mq.c index 8e18284ede8f..0ec3b2db1d00 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -120,20 +120,66 @@ void blk_mq_in_flight_rw(struct request_queue *q, struct block_device *part, inflight[1] = mi.inflight[1]; } -bool __blk_freeze_queue_start(struct request_queue *q) +#ifdef CONFIG_LOCKDEP +static bool blk_freeze_set_owner(struct request_queue *q, + struct task_struct *owner) { - int freeze; + if (!owner) + return false; + + if (!q->mq_freeze_depth) { + q->mq_freeze_owner = owner; + q->mq_freeze_owner_depth = 1; + return true; + } + + if (owner == q->mq_freeze_owner) + q->mq_freeze_owner_depth += 1; + return false; +} + +/* verify the last unfreeze in owner context */ +static bool blk_unfreeze_check_owner(struct request_queue *q) +{ + if (!q->mq_freeze_owner) + return false; + if (q->mq_freeze_owner != current) + return false; + if (--q->mq_freeze_owner_depth == 0) { + q->mq_freeze_owner = NULL; + return true; + } + return false; +} + +#else + +static bool blk_freeze_set_owner(struct request_queue *q, + struct task_struct *owner) +{ + return false; +} + +static bool blk_unfreeze_check_owner(struct request_queue *q) +{ + return false; +} +#endif + +bool __blk_freeze_queue_start(struct request_queue *q, + struct task_struct *owner) +{ + bool freeze; mutex_lock(&q->mq_freeze_lock); + freeze = blk_freeze_set_owner(q, owner); if (++q->mq_freeze_depth == 1) { percpu_ref_kill(&q->q_usage_counter); mutex_unlock(&q->mq_freeze_lock); if (queue_is_mq(q)) blk_mq_run_hw_queues(q, false); - freeze = true; } else { mutex_unlock(&q->mq_freeze_lock); - freeze = false; } return freeze; @@ -141,7 +187,7 @@ bool __blk_freeze_queue_start(struct request_queue *q) void blk_freeze_queue_start(struct request_queue *q) { - if (__blk_freeze_queue_start(q)) + if (__blk_freeze_queue_start(q, current)) blk_freeze_acquire_lock(q, false, false); } EXPORT_SYMBOL_GPL(blk_freeze_queue_start); @@ -170,7 +216,7 @@ EXPORT_SYMBOL_GPL(blk_mq_freeze_queue); bool __blk_mq_unfreeze_queue(struct request_queue *q, bool force_atomic) { - int unfreeze = false; + bool unfreeze; mutex_lock(&q->mq_freeze_lock); if (force_atomic) @@ -180,8 +226,8 @@ bool __blk_mq_unfreeze_queue(struct request_queue *q, bool force_atomic) if (!q->mq_freeze_depth) { percpu_ref_resurrect(&q->q_usage_counter); wake_up_all(&q->mq_freeze_wq); - unfreeze = true; } + unfreeze = blk_unfreeze_check_owner(q); mutex_unlock(&q->mq_freeze_lock); return unfreeze; @@ -203,7 +249,7 @@ EXPORT_SYMBOL_GPL(blk_mq_unfreeze_queue); */ void blk_mq_freeze_queue_non_owner(struct request_queue *q) { - __blk_freeze_queue_start(q); + __blk_freeze_queue_start(q, NULL); blk_mq_freeze_queue_wait(q); } EXPORT_SYMBOL_GPL(blk_mq_freeze_queue_non_owner); @@ -211,7 +257,7 @@ EXPORT_SYMBOL_GPL(blk_mq_freeze_queue_non_owner); /* non_owner variant of blk_freeze_queue_start */ void blk_freeze_queue_start_non_owner(struct request_queue *q) { - __blk_freeze_queue_start(q); + __blk_freeze_queue_start(q, NULL); } EXPORT_SYMBOL_GPL(blk_freeze_queue_start_non_owner); diff --git a/block/blk.h b/block/blk.h index ac48b79cbf80..57fc035620d6 100644 --- a/block/blk.h +++ b/block/blk.h @@ -37,7 +37,8 @@ void blk_free_flush_queue(struct blk_flush_queue *q); bool __blk_mq_unfreeze_queue(struct request_queue *q, bool force_atomic); bool blk_queue_start_drain(struct request_queue *q); -bool __blk_freeze_queue_start(struct request_queue *q); +bool __blk_freeze_queue_start(struct request_queue *q, + struct task_struct *owner); int __bio_queue_enter(struct request_queue *q, struct bio *bio); void submit_bio_noacct_nocheck(struct bio *bio); void bio_await_chain(struct bio *bio); diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 7bfc877e159e..379cd8eebdd9 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -575,6 +575,10 @@ struct request_queue { struct throtl_data *td; #endif struct rcu_head rcu_head; +#ifdef CONFIG_LOCKDEP + struct task_struct *mq_freeze_owner; + int mq_freeze_owner_depth; +#endif wait_queue_head_t mq_freeze_wq; /* * Protect concurrent access to q_usage_counter by From patchwork Wed Oct 30 12:42:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 13856467 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 630171E8856 for ; Wed, 30 Oct 2024 12:43:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730292200; cv=none; b=K1VfTFsWoMh1TpqjIApw9cR9OI/RVs/g5C1Hp7Lol/2pSoVggP7Q5A1wOVqoYArc+sUQyVyIV/rsYpdPotYDrZ2LDT1nmhwN+EJquXS3u3NZb1ty+QWJcTTMbOCKD+7qTCZou/8Fpd21+DVKhgN43qqri534v3n2XXO2uHG+B0g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730292200; c=relaxed/simple; bh=xopeGar8I6d2qbQvKK+7htZZJ0sxX1mU9VTKipdNz18=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GgEkVwghl+YPlAuFsEJ4oN4h2y0kClzRbBHhc66JIqIycJlq3LLS25gOTboGrD6O2g1OtY6tDgcYP8/xCYhInV1CUHx2RBBW2yu1BpUtHvzozQlbD6ssKiQuZdIK5nouAU7b8HT12abTyTaUD1vKUFQDAAVHF4uwJHzNgRbqKKo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=H6MK+rNG; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="H6MK+rNG" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730292197; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yGypw63MlEWNsiDIekauJsXlP0auZsXeVrPz767tCm0=; b=H6MK+rNGFoRDHmpy0K+rOrWL9vyds3KzmajmocIimwE5KNUtep/NugH+tZMdF2iHZu5lz1 dXUyAjTBrwiDhIHENlCriU2Csk/16plfcX5bCffpCyKLqsQ1pML+vCw7fgMd2tepbXjzjI W7YrzrQ3v8x3V+I9MViAlsSEa4G/j7M= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-465-8Zn2BNm6O7ac-zYHdYOVNw-1; Wed, 30 Oct 2024 08:43:14 -0400 X-MC-Unique: 8Zn2BNm6O7ac-zYHdYOVNw-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A804E1955BC1; Wed, 30 Oct 2024 12:43:12 +0000 (UTC) Received: from localhost (unknown [10.72.116.140]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 29ACF300018D; Wed, 30 Oct 2024 12:43:10 +0000 (UTC) From: Ming Lei To: Jens Axboe , linux-block@vger.kernel.org Cc: Christoph Hellwig , Ming Lei , Marek Szyprowski , Lai Yi Subject: [PATCH 5/5] block: don't verify IO lock for freeze/unfreeze in elevator_init_mq() Date: Wed, 30 Oct 2024 20:42:37 +0800 Message-ID: <20241030124240.230610-6-ming.lei@redhat.com> In-Reply-To: <20241030124240.230610-1-ming.lei@redhat.com> References: <20241030124240.230610-1-ming.lei@redhat.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 elevator_init_mq() is only called at the entry of add_disk_fwnode() when disk IO isn't allowed yet. So not verify io lock(q->io_lockdep_map) for freeze & unfreeze in elevator_init_mq(). Reported-by: Marek Szyprowski Reported-by: Lai Yi Fixes: f1be1788a32e ("block: model freeze & enter queue as lock for supporting lockdep") Signed-off-by: Ming Lei --- block/elevator.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/block/elevator.c b/block/elevator.c index f169f4bae917..a02bf911d3ca 100644 --- a/block/elevator.c +++ b/block/elevator.c @@ -598,13 +598,17 @@ void elevator_init_mq(struct request_queue *q) * drain any dispatch activities originated from passthrough * requests, then no need to quiesce queue which may add long boot * latency, especially when lots of disks are involved. + * + * Disk isn't added yet, so verifying queue lock only manually. */ - blk_mq_freeze_queue(q); + blk_mq_freeze_queue_non_owner(q); + blk_freeze_acquire_lock(q, true, false); blk_mq_cancel_work_sync(q); err = blk_mq_init_sched(q, e); - blk_mq_unfreeze_queue(q); + blk_unfreeze_release_lock(q, true, false); + blk_mq_unfreeze_queue_non_owner(q); if (err) { pr_warn("\"%s\" elevator initialization failed, "