Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp505277pxj; Tue, 18 May 2021 08:11:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfG29+dfKfZ8PHsiaLLIQJRqsQ0fvfNHBqSlHPXUBXyEwlpMiwxDoE0xf6Egk9DBzM30v/ X-Received: by 2002:a17:906:685:: with SMTP id u5mr6510978ejb.449.1621350697688; Tue, 18 May 2021 08:11:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621350697; cv=none; d=google.com; s=arc-20160816; b=OxKCgOdY9/U2a+cCTYEiTLGc2/2Toaewj4ENskEDkBSA8tBuO+Pub5L2gaMdvvC+SR Utx/FNDhNlpDtDwksNUD/KpJBnkUsA9xI81Pr2H7HCCEZnPJNObUgZWuXrY1l6bdpPTf tn2N/+3GsFNwZjACkRXCqI7CtdE/TjnlpWKC+pM4R/cctJGhtFHJqqgL+IootqOgTPSd tn7CpVWljn8no4EmpVXLcnoUY8nFH+vtDcQm1pGUHBSMutjz4P0lWRG+D2zmhsBl5QMH Y5cPf3426r7mC0R8CwjsSGbk+aw85EnwvAdkd81O7UDcp/pkEQXc0wzyvGPSYDj7015I FStQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Kjlkt0EEhX2BlMIn6TBTHs/lJo6PhfWQUdhfvy1PwT4=; b=TbNBSlVp3QPHSKL3LIgbux5ULytN9K+HlEZkhoGWp/HhYUGxgCocjzHvd/yPdjGpsG P8wVFMcULMoBLBCVmEQ3/4zdbhIyplSeWo/i9NKzv1urRiFfBwFbsB56cOYKeh77BPhw 24veXlFINa4vv/eeSONOi02Om2oP9UHnZsuNYW8wNYRVvLPeBI8TRjRofXtuPtDTJSJk u1NXTHZy9Yy6gVhi2xt2JkED5vHwQw1QQaMibZUIP/WzXyWd+4j3QJAzjhKjiKPy+VT5 Lw2C7HvmWFeAqXsEOqSbx1h2JLv0DkQ+kWxBrPM5aLY7ez96JoODHB64ON52b/HCppqn 5JjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zUPsXAUs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m1si20504331ejj.214.2021.05.18.08.11.11; Tue, 18 May 2021 08:11:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zUPsXAUs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343797AbhEQPx1 (ORCPT + 99 others); Mon, 17 May 2021 11:53:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:38868 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243460AbhEQPf7 (ORCPT ); Mon, 17 May 2021 11:35:59 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5301361CE7; Mon, 17 May 2021 14:39:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621262391; bh=bBZdnNjDGJVADnWg/L62VTsJidFCmRulnLAs2KUCXjQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zUPsXAUs05aLlNeVr8yqUSCgVgbPqTxwW2oqpzg+h6RmGOzK43j4Zk1BCDOvRpmZu CA4bN1cp85k8u+L8FmpeJzNwEHqX0HliYXX9jRT8WHO7iSxKOUhsW7Vx+za35XlHbi YNTBcNg7z9ohOhv07d0exgSF6S4ot1I90UoRSsgo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chaitanya Kulkarni , Sagi Grimberg , Christoph Hellwig , Sasha Levin Subject: [PATCH 5.11 272/329] nvmet: fix inline bio check for bdev-ns Date: Mon, 17 May 2021 16:03:03 +0200 Message-Id: <20210517140311.322849945@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.043055203@linuxfoundation.org> References: <20210517140302.043055203@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Chaitanya Kulkarni [ Upstream commit 608a969046e6e0567d05a166be66c77d2dd8220b ] When handling rw commands, for inline bio case we only consider transfer size. This works well when req->sg_cnt fits into the req->inline_bvec, but it will result in the warning in __bio_add_page() when req->sg_cnt > NVMET_MAX_INLINE_BVEC. Consider an I/O size 32768 and first page is not aligned to the page boundary, then I/O is split in following manner :- [ 2206.256140] nvmet: sg->length 3440 sg->offset 656 [ 2206.256144] nvmet: sg->length 4096 sg->offset 0 [ 2206.256148] nvmet: sg->length 4096 sg->offset 0 [ 2206.256152] nvmet: sg->length 4096 sg->offset 0 [ 2206.256155] nvmet: sg->length 4096 sg->offset 0 [ 2206.256159] nvmet: sg->length 4096 sg->offset 0 [ 2206.256163] nvmet: sg->length 4096 sg->offset 0 [ 2206.256166] nvmet: sg->length 4096 sg->offset 0 [ 2206.256170] nvmet: sg->length 656 sg->offset 0 Now the req->transfer_size == NVMET_MAX_INLINE_DATA_LEN i.e. 32768, but the req->sg_cnt is (9) > NVMET_MAX_INLINE_BIOVEC which is (8). This will result in the following warning message :- nvmet_bdev_execute_rw() bio_add_page() __bio_add_page() WARN_ON_ONCE(bio_full(bio, len)); This scenario is very hard to reproduce on the nvme-loop transport only with rw commands issued with the passthru IOCTL interface from the host application and the data buffer is allocated with the malloc() and not the posix_memalign(). Fixes: 73383adfad24 ("nvmet: don't split large I/Os unconditionally") Signed-off-by: Chaitanya Kulkarni Reviewed-by: Sagi Grimberg Signed-off-by: Christoph Hellwig Signed-off-by: Sasha Levin --- drivers/nvme/target/io-cmd-bdev.c | 2 +- drivers/nvme/target/nvmet.h | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/target/io-cmd-bdev.c b/drivers/nvme/target/io-cmd-bdev.c index 23095bdfce06..6a9626ff0713 100644 --- a/drivers/nvme/target/io-cmd-bdev.c +++ b/drivers/nvme/target/io-cmd-bdev.c @@ -258,7 +258,7 @@ static void nvmet_bdev_execute_rw(struct nvmet_req *req) sector = nvmet_lba_to_sect(req->ns, req->cmd->rw.slba); - if (req->transfer_len <= NVMET_MAX_INLINE_DATA_LEN) { + if (nvmet_use_inline_bvec(req)) { bio = &req->b.inline_bio; bio_init(bio, req->inline_bvec, ARRAY_SIZE(req->inline_bvec)); } else { diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h index 8776dd1a0490..7f8712de77e0 100644 --- a/drivers/nvme/target/nvmet.h +++ b/drivers/nvme/target/nvmet.h @@ -613,4 +613,10 @@ static inline sector_t nvmet_lba_to_sect(struct nvmet_ns *ns, __le64 lba) return le64_to_cpu(lba) << (ns->blksize_shift - SECTOR_SHIFT); } +static inline bool nvmet_use_inline_bvec(struct nvmet_req *req) +{ + return req->transfer_len <= NVMET_MAX_INLINE_DATA_LEN && + req->sg_cnt <= NVMET_MAX_INLINE_BIOVEC; +} + #endif /* _NVMET_H */ -- 2.30.2