Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp3400690pxb; Tue, 19 Apr 2022 01:24:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyISjcLSLhuwEpkMJt/wppPQ0tCxq6Umm9U7rVQiDcgFJDv/+YVXza8dvtFD7Z5HZ16UzDn X-Received: by 2002:a17:907:2cc4:b0:6ef:8108:ad11 with SMTP id hg4-20020a1709072cc400b006ef8108ad11mr10874024ejc.20.1650356657854; Tue, 19 Apr 2022 01:24:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650356657; cv=none; d=google.com; s=arc-20160816; b=NH6rPOXKk/qpIq5v63kxz6QgfqRWfTAcB46OtdH+tdotlospcX3Rb4uIZtULaKR340 p2pOI+pKg/lS4d8ttJ86G/6cw5ky7iA7/oB0uJ7gxBic3pVNLJFVEONxrHDZxnkIDSpQ CrRhUJJk5v1sbbsuuXMZTCY4PIKQ5j9t5WCcKPWOvuQg1zDghY3gOU5fmWQPpybH8uv+ Udjl3CXzsBLoHlaT1hwXumZlmvhwxRRVugY9VmXWCHmfbu+jwQlR+98Wu2km3fJxk3Qd AYzk2uKzI/eh1guXkpdm8QP5g+IRyr84gnAjT4D30REI6WsReYeMq68WhxW+/4gDm4mQ SgAQ== 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=Kr771VJ7sCxGP6iVr3db+zS8Nb7ga6vPvbNFImxliCw=; b=ciYjUO2DAc5e6MWZXi+zt9QIqoDuYhQ/77BV+CUqlxBMK/Jae9Czw5eXLzlARfgUug zPPy4paGYLAXT/Ti7KVFXoCL3Nhl4LPb4eWleUwGlT/fKzotGvScOOdaxqphQnXyRY4S 1mYmR07RUDv7bGx5nH5C5SlPPEqK5qgysVTeCxQSkaslz+8tPaVB7hJslHA4OpIlbRjh SLsLS1gp2Cio8QXcUiy/X7l/66TlzGINQaj4hLaWYAZG7BUYM5+9bO0gHEZzg8AHH6S8 EnEHMA+LoV+zVWQv5YXDX6FgLOGeXgavftP92uej6dzMRvcEaAGvHGLjep4zliEDKZxy 5lxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lQX+TmUT; 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 a5-20020a17090682c500b006e7efa5c4fbsi7016291ejy.173.2022.04.19.01.23.54; Tue, 19 Apr 2022 01:24:17 -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=lQX+TmUT; 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 S244295AbiDRNz0 (ORCPT + 99 others); Mon, 18 Apr 2022 09:55:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244880AbiDRNbA (ORCPT ); Mon, 18 Apr 2022 09:31:00 -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 EC8D32A5; Mon, 18 Apr 2022 05:56:57 -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 87D11612BB; Mon, 18 Apr 2022 12:56:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7B388C385A9; Mon, 18 Apr 2022 12:56:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650286617; bh=ASvl4kzOlN2JBFPVcDkp6qC7onoQI+kOPopbQo3QmCk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lQX+TmUTToZ5sfVUS/vL60b8Cc2mKayvZkYWw+xqjnbTuzIUCR7QtGJ8EKmW3L8HS ZV4r7DgDsGmGWxfS74DiviQRznIV3rWgL8Ng0x5X0qLmtx3Nr6ERHCykg8o7Ix03J3 RFPOvV0C6EWXCCq2zYFjJmCa6QCURv7zKaL/fgxQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrew Price , Andreas Gruenbacher Subject: [PATCH 4.14 191/284] gfs2: Make sure FITRIM minlen is rounded up to fs block size Date: Mon, 18 Apr 2022 14:12:52 +0200 Message-Id: <20220418121217.165187102@linuxfoundation.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220418121210.689577360@linuxfoundation.org> References: <20220418121210.689577360@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=-7.7 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: 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 @@ -1380,7 +1380,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)