Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp755149pxb; Tue, 5 Apr 2022 21:55:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw2t9Wmfs1qrl0HZx0zLeIXoGxtqrKpUSZc3TFcfVjFgU7xVqdlHVMxf/KXGYN3kmJm3ltX X-Received: by 2002:a63:330a:0:b0:398:22e4:3e34 with SMTP id z10-20020a63330a000000b0039822e43e34mr5665614pgz.349.1649220941548; Tue, 05 Apr 2022 21:55:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649220941; cv=none; d=google.com; s=arc-20160816; b=xL7b38TA0AkXs2Y/lr2O19bV0VyF/zMOZcOT+E+ylWuGLtPLjZ7wCOGxGZObdLIuRx CkhaC/FiL0qLXoKedjBKHEHvELiWPtDvePmZ8X5DTAL8HTRSE9/jOLTk6CJ8PHfn4Fko t87ti7k3NUOHTFovJbv8YZaMbYrqHgshG7CeqTIQHc2RtQnohcZy7pMkU4c3Fz8C89Tt l0HSEjBvawWg9PArnSBNgm0K2symxJQ4XC3wHZm2aZEaExzFzCdJh+Dp6kIfKqvS/K+s WqPX+Ozt9jUgUfYj7CRdsJ7A8ybXxKpR6PZ/LqlwTxYzeLDC4bPiDq7qoCYw7qKcvvEC m2Iw== 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=NVodlOthSY4JeEhMxV1DJYoRUgAQYknLlHJGn0KKyd4=; b=D6/gyyDLRLFpCUmd7MzqrB2uPZyt1LS8KceLYJA4PwV6R6mGrDKu/VWFd65LmX+Uv8 JcDWSlWvu4LO/9vqO9YVMhR5WBQfSn77tHshAQcajl5rQRmC2uLETLVFdbRH6Q/qdaJx KrE05jHu04m6aXXJClcQ2whrLlVPUakqN11YhRPZSakyna8I5p5YCZzWGMtZgO2zworc O6rklsPg5zm1yuYrDbHdsy+0PeXfaz/5T0UkJrY4MFasO9hR0uX7oVd2dtYGRulqkwG8 lKYIM9uOQXgE20HpNqPa3+0P1AdXXT6vILWm+DojKhg6ftDsE3w5TLlUAuiE2i99hafJ F+xA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="T66MgC/E"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id j12-20020a056a00174c00b004fa7d166af8si14715591pfc.52.2022.04.05.21.55.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 21:55:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="T66MgC/E"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6F51A15F57F; Tue, 5 Apr 2022 20:16:11 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353701AbiDEKI6 (ORCPT + 99 others); Tue, 5 Apr 2022 06:08:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241066AbiDEIcq (ORCPT ); Tue, 5 Apr 2022 04:32:46 -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 03877B82DB; Tue, 5 Apr 2022 01:26:26 -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 952646117D; Tue, 5 Apr 2022 08:26:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A13DBC385A4; Tue, 5 Apr 2022 08:26:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649147185; bh=zVgmbBw35MWRGTT+EfHtGi8B5Mtyr+4PZ6lxdw8c/1o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T66MgC/EW1dq5hZNoNnnDRxdiUkD1T2ivrQ0qDvdDAxzie7JK8kuMGKZHw1/joUFJ PHmbaMLo01s7nEC9Ayr2VmhMnGCutVs2QPf6Cgp6VRvZjSA0QBo5DX9cptqCwf2S/K /RHavxGkzuifSVshob5e4kMdPLjTIhPcvbJBeSPY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrew Price , Andreas Gruenbacher Subject: [PATCH 5.17 1031/1126] gfs2: Make sure FITRIM minlen is rounded up to fs block size Date: Tue, 5 Apr 2022 09:29:38 +0200 Message-Id: <20220405070437.740382682@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070407.513532867@linuxfoundation.org> References: <20220405070407.513532867@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=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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: Andrew Price commit 27ca8273fda398638ca994a207323a85b6d81190 upstream. Per fstrim(8) we must round up the minlen argument to the fs block size. The current calculation doesn't take into account devices that have a discard granularity and requested minlen less than 1 fs block, so the value can get shifted away to zero in the translation to fs blocks. The zero minlen passed to gfs2_rgrp_send_discards() then allows sb_issue_discard() to be called with nr_sects == 0 which returns -EINVAL and results in gfs2_rgrp_send_discards() returning -EIO. Make sure minlen is never < 1 fs block by taking the max of the requested minlen and the fs block size before comparing to the device's discard granularity and shifting to fs blocks. Fixes: 076f0faa764ab ("GFS2: Fix FITRIM argument handling") Signed-off-by: Andrew Price Signed-off-by: Andreas Gruenbacher Signed-off-by: Greg Kroah-Hartman --- fs/gfs2/rgrp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/fs/gfs2/rgrp.c +++ b/fs/gfs2/rgrp.c @@ -1416,7 +1416,8 @@ int gfs2_fitrim(struct file *filp, void start = r.start >> bs_shift; end = start + (r.len >> bs_shift); - minlen = max_t(u64, r.minlen, + minlen = max_t(u64, r.minlen, sdp->sd_sb.sb_bsize); + minlen = max_t(u64, minlen, q->limits.discard_granularity) >> bs_shift; if (end <= start || minlen > sdp->sd_max_rg_data)