From patchwork Mon Nov 20 03:25:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 166932 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp1957933vqn; Sun, 19 Nov 2023 19:26:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IFWlH0ncTKTxLL5nVA/dtBv4a8sZcrZLOz4OjyFh7/aQzrZe34zfa/yvF0leqseKtrU9HP6 X-Received: by 2002:a17:90a:a413:b0:280:a4a1:5d03 with SMTP id y19-20020a17090aa41300b00280a4a15d03mr17309440pjp.4.1700450786408; Sun, 19 Nov 2023 19:26:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700450786; cv=none; d=google.com; s=arc-20160816; b=aelp6d8xBWNmawAqOaQYkdxFYpOzws9sFxyCLdwqNok553g8LF+a49UfQFQ963vjX1 LmFONkYHqk8EPd5gllVpN07sxDW+9YbFPpw+ejF/4PFnZSybtXkA/Bj5C/XLxsNcv/Bj qZugP8MjC5sLizDI+y5kk+pAb5LrORSR4erjH9ZbgEoXv0i85ZA65dTip5oqjsrbTYsX RumG278tBOAJMv6zHQcENckCGYIoKDg1nbR/7U9jm0UNO2BDjNQwXWkw5icjxgrRRLWZ fJEiNG0RGUvNy04QzcWTXAA0xyH3UIRuneqasfXAhDaHrq6QBTAIUnI4i7HzSKLBYylJ ZIbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=+VymdBzRpvTEsF3r3W4saDJpuCxv1e2XIK11MThN86Y=; fh=7XeTYLgCRc2aKJ5WMNPNDcxcifoDt1xbtg3WmTLp+x8=; b=vjLJaGpYbl2mOOrBWBVmf+2dQ0v5ZgJeRbR+6KccDRDrjVjOQLZ5GquBqnNFrM7oup scbOY+JHNN2tVcwqenzFArcwDMsZsMeUB2/ZS5hmfLi85AExSPqD1SWocJi3WlAO2Oyk 89IB3n0EqgeebU9cX7HOsRXR2LtmR+f2mhKrAMCq0vxl3PIYrmpbNm8Q2hCCoMNXCUcx bj3DePdRvDI0Bq4YVfI9bR2XpUFGYnl3O69lTjY/ZdZAviLQTS/nuSVWebO8TX/gAiGl IVGQ+BuvTvjY5Tfjk5GYG9xkidZWvcpHBDAo42TDoUWZ3n4OiNOj27swI2W7px2KkQdw yRAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=pvG4sWih; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id rj5-20020a17090b3e8500b0027749a1fe74si7549862pjb.182.2023.11.19.19.26.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Nov 2023 19:26:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=pvG4sWih; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 2595280569B3; Sun, 19 Nov 2023 19:26:24 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231869AbjKTD0O (ORCPT + 28 others); Sun, 19 Nov 2023 22:26:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231848AbjKTD0M (ORCPT ); Sun, 19 Nov 2023 22:26:12 -0500 Received: from out-180.mta1.migadu.com (out-180.mta1.migadu.com [IPv6:2001:41d0:203:375::b4]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1789BD3 for ; Sun, 19 Nov 2023 19:26:07 -0800 (PST) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1700450765; 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; bh=+VymdBzRpvTEsF3r3W4saDJpuCxv1e2XIK11MThN86Y=; b=pvG4sWihLLOWQMeNrUGbVMCed1GK0wWLXgmev8oACdRLvYJ9DrEtcOasNYh/uvpz30av7j SiJkIS6g1AogyFxYNF7I/CeOikgUGuenfDgWlW3eAkihvSm7YZzVkmULdjNBHHGv51t20q 5HtQQxdyGLQggrjxxvz+42ayVBPy3fA= From: chengming.zhou@linux.dev To: axboe@kernel.dk, bvanassche@acm.org Cc: kch@nvidia.com, damien.lemoal@opensource.wdc.com, ming.lei@redhat.com, zhouchengming@bytedance.com, justinstitt@google.com, shinichiro.kawasaki@wdc.com, akinobu.mita@gmail.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, chengming.zhou@linux.dev, syzbot+fcc47ba2476570cbbeb0@syzkaller.appspotmail.com Subject: [PATCH] block/null_blk: Fix double blk_mq_start_request() warning Date: Mon, 20 Nov 2023 03:25:21 +0000 Message-Id: <20231120032521.1012037-1-chengming.zhou@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Sun, 19 Nov 2023 19:26:24 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783051883909565584 X-GMAIL-MSGID: 1783051883909565584 From: Chengming Zhou When CONFIG_BLK_DEV_NULL_BLK_FAULT_INJECTION is enabled, null_queue_rq() would return BLK_STS_RESOURCE or BLK_STS_DEV_RESOURCE for the request, which has been marked as MQ_RQ_IN_FLIGHT by blk_mq_start_request(). Then null_queue_rqs() put these requests in the rqlist, return back to the block layer core, which would try to queue them individually again, so the warning in blk_mq_start_request() triggered. Fix it by splitting the null_queue_rq() into two parts: the first is the preparation of request, the second is the handling of request. We put the blk_mq_start_request() after the preparation part, which may fail and return back to the block layer core. The throttling also belongs to the preparation part, so move it before blk_mq_start_request(). And change the return type of null_handle_cmd() to void, since it always return BLK_STS_OK now. Reported-by: syzbot+fcc47ba2476570cbbeb0@syzkaller.appspotmail.com Closes: https://lore.kernel.org/all/0000000000000e6aac06098aee0c@google.com/ Fixes: d78bfa1346ab ("block/null_blk: add queue_rqs() support") Suggested-by: Bart Van Assche Signed-off-by: Chengming Zhou --- drivers/block/null_blk/main.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c index 22a3cf7f32e2..3021d58ca51c 100644 --- a/drivers/block/null_blk/main.c +++ b/drivers/block/null_blk/main.c @@ -1464,19 +1464,13 @@ blk_status_t null_process_cmd(struct nullb_cmd *cmd, enum req_op op, return BLK_STS_OK; } -static blk_status_t null_handle_cmd(struct nullb_cmd *cmd, sector_t sector, - sector_t nr_sectors, enum req_op op) +static void null_handle_cmd(struct nullb_cmd *cmd, sector_t sector, + sector_t nr_sectors, enum req_op op) { struct nullb_device *dev = cmd->nq->dev; struct nullb *nullb = dev->nullb; blk_status_t sts; - if (test_bit(NULLB_DEV_FL_THROTTLED, &dev->flags)) { - sts = null_handle_throttled(cmd); - if (sts != BLK_STS_OK) - return sts; - } - if (op == REQ_OP_FLUSH) { cmd->error = errno_to_blk_status(null_handle_flush(nullb)); goto out; @@ -1493,7 +1487,6 @@ static blk_status_t null_handle_cmd(struct nullb_cmd *cmd, sector_t sector, out: nullb_complete_cmd(cmd); - return BLK_STS_OK; } static enum hrtimer_restart nullb_bwtimer_fn(struct hrtimer *timer) @@ -1724,8 +1717,6 @@ static blk_status_t null_queue_rq(struct blk_mq_hw_ctx *hctx, cmd->fake_timeout = should_timeout_request(rq) || blk_should_fake_timeout(rq->q); - blk_mq_start_request(rq); - if (should_requeue_request(rq)) { /* * Alternate between hitting the core BUSY path, and the @@ -1738,6 +1729,15 @@ static blk_status_t null_queue_rq(struct blk_mq_hw_ctx *hctx, return BLK_STS_OK; } + if (test_bit(NULLB_DEV_FL_THROTTLED, &nq->dev->flags)) { + blk_status_t sts = null_handle_throttled(cmd); + + if (sts != BLK_STS_OK) + return sts; + } + + blk_mq_start_request(rq); + if (is_poll) { spin_lock(&nq->poll_lock); list_add_tail(&rq->queuelist, &nq->poll_list); @@ -1747,7 +1747,8 @@ static blk_status_t null_queue_rq(struct blk_mq_hw_ctx *hctx, if (cmd->fake_timeout) return BLK_STS_OK; - return null_handle_cmd(cmd, sector, nr_sectors, req_op(rq)); + null_handle_cmd(cmd, sector, nr_sectors, req_op(rq)); + return BLK_STS_OK; } static void null_queue_rqs(struct request **rqlist)