Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp158871pxp; Wed, 16 Mar 2022 02:53:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy7KIMrbJFdyM5MtrKnLtpNIlZVhLrRNfo437/XDNnxZS63tH3p8o2OMIejeRvAcR8m1r9s X-Received: by 2002:a17:90a:77c6:b0:1bd:5ce1:1966 with SMTP id e6-20020a17090a77c600b001bd5ce11966mr9139614pjs.230.1647424424557; Wed, 16 Mar 2022 02:53:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647424424; cv=none; d=google.com; s=arc-20160816; b=G0Tm7bjV6ui9qYi9SvSCtxtQ8bK8ZSJcyZiv7ZIgHSdAi6+kn6ZHb6kdcUJGFy894c OcSoQnpYr/LK1p+VlOYAuVvVIrqMBX6wLeH/adkSTwvQ4tAbogiKsoLBZt9w0ceMWcF4 pJRoZlJ+OL9Gzdt/n62IYnBbsxrScq6qLatr7Dgi4eUiWxCl7Mnxh0w0yVHJLssfVx5H T28CroQy492sPGUPX3rw0Qp+4HmpsRabPX4uxaobtwcl6jXj9u5DlhTu7SjF+rt9ePMo XgN20akZGDTHp5BoFsbJ4X+j0GkHbiWzVf3B1si2kJN8hO+yjTpDdaeO4ar7V8yzsR4D DOcQ== 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=KISg2W3B6FFmCt7XeEfc55/gePr9Lx5KDSHtT5XzmdE=; b=GsSBgWeUig7QwIkiLubZH/8Vp6UmUVGSvC878+l/QPK/etWxU/WGmGu2AZengGe+6U VC7noqPl+Nj2vCuQQVpyJqG7V428JmGwkYSDPxjNLi8+vKTk1Q+jnolFCnypI1MhnHns ai7RpA4YNxUF5unNmJg2aNjddtM7Qp35giCTmn/BJHxd9d3NdGsYnJdK511lHabyJ8v7 torlldfDt1UquHag8kBp1Zz88ya3IWNnS1MdTd6MNFssEfbQOCezi3d63B3N72d2v2BH Ahfp9UoCd6I6z1i7i6wVhRxhL4ai/JTxMJE2Ek38badTDav5Gjxsvq2KVpig/0fOhLMg jjOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=d4Ytoh73; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v8-20020a17090331c800b001538b03ac21si1266049ple.210.2022.03.16.02.53.32; Wed, 16 Mar 2022 02:53:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=d4Ytoh73; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S241835AbiCNM2F (ORCPT + 99 others); Mon, 14 Mar 2022 08:28:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243351AbiCNMUe (ORCPT ); Mon, 14 Mar 2022 08:20:34 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2D25344F2; Mon, 14 Mar 2022 05:15:48 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 780E4608C4; Mon, 14 Mar 2022 12:15:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 111E3C340E9; Mon, 14 Mar 2022 12:15:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1647260147; bh=vIM6AUwnOl+uW/m2jIG6QnLVc2yWJTjJ5mdHCQ0xwYc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d4Ytoh73pVsG11ScPCMHKzTZCPqlYbMXFXloecOCbwoAAc/5wsXZ1fqxP9TKElugh H5QYcVWKZwNep5vp3dhZ/JSf97CHz2I/RPAnLnwQYCmbBh/cFqehmMdnJtFpC/m0sF SUx87KxB+4G+seCglZ0dT7Ru84tpyvQtpNKwiS9g= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christoph Hellwig , Xie Yongji , Max Gurtovoy , "Michael S. Tsirkin" , Sasha Levin Subject: [PATCH 5.16 019/121] virtio-blk: Remove BUG_ON() in virtio_queue_rq() Date: Mon, 14 Mar 2022 12:53:22 +0100 Message-Id: <20220314112744.664541917@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220314112744.120491875@linuxfoundation.org> References: <20220314112744.120491875@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xie Yongji [ Upstream commit e030759a1ddcbf61d42b6e996bfeb675e0032d8b ] Currently we have a BUG_ON() to make sure the number of sg list does not exceed queue_max_segments() in virtio_queue_rq(). However, the block layer uses queue_max_discard_segments() instead of queue_max_segments() to limit the sg list for discard requests. So the BUG_ON() might be triggered if virtio-blk device reports a larger value for max discard segment than queue_max_segments(). To fix it, let's simply remove the BUG_ON() which has become unnecessary after commit 02746e26c39e("virtio-blk: avoid preallocating big SGL for data"). And the unused vblk->sg_elems can also be removed together. Fixes: 1f23816b8eb8 ("virtio_blk: add discard and write zeroes support") Suggested-by: Christoph Hellwig Signed-off-by: Xie Yongji Reviewed-by: Max Gurtovoy Link: https://lore.kernel.org/r/20220304100058.116-2-xieyongji@bytedance.com Signed-off-by: Michael S. Tsirkin Signed-off-by: Sasha Levin --- drivers/block/virtio_blk.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c index 87f239eb0a99..b3df5e5452a7 100644 --- a/drivers/block/virtio_blk.c +++ b/drivers/block/virtio_blk.c @@ -76,9 +76,6 @@ struct virtio_blk { */ refcount_t refs; - /* What host tells us, plus 2 for header & tailer. */ - unsigned int sg_elems; - /* Ida index - used to track minor number allocations. */ int index; @@ -322,8 +319,6 @@ static blk_status_t virtio_queue_rq(struct blk_mq_hw_ctx *hctx, blk_status_t status; int err; - BUG_ON(req->nr_phys_segments + 2 > vblk->sg_elems); - status = virtblk_setup_cmd(vblk->vdev, req, vbr); if (unlikely(status)) return status; @@ -783,8 +778,6 @@ static int virtblk_probe(struct virtio_device *vdev) /* Prevent integer overflows and honor max vq size */ sg_elems = min_t(u32, sg_elems, VIRTIO_BLK_MAX_SG_ELEMS - 2); - /* We need extra sg elements at head and tail. */ - sg_elems += 2; vdev->priv = vblk = kmalloc(sizeof(*vblk), GFP_KERNEL); if (!vblk) { err = -ENOMEM; @@ -796,7 +789,6 @@ static int virtblk_probe(struct virtio_device *vdev) mutex_init(&vblk->vdev_mutex); vblk->vdev = vdev; - vblk->sg_elems = sg_elems; INIT_WORK(&vblk->config_work, virtblk_config_changed_work); @@ -854,7 +846,7 @@ static int virtblk_probe(struct virtio_device *vdev) set_disk_ro(vblk->disk, 1); /* We can handle whatever the host told us to handle. */ - blk_queue_max_segments(q, vblk->sg_elems-2); + blk_queue_max_segments(q, sg_elems); /* No real sector limit. */ blk_queue_max_hw_sectors(q, -1U); @@ -932,7 +924,7 @@ static int virtblk_probe(struct virtio_device *vdev) * handled it. */ if (!v) - v = sg_elems - 2; + v = sg_elems; blk_queue_max_discard_segments(q, min(v, MAX_DISCARD_SEGMENTS)); -- 2.34.1