Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp693170pxb; Tue, 5 Apr 2022 19:02:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzojzoRqpenNMZ8qpn4oVrcAfHNwDv+2i02OUapJofmG0XGihQdufuMkHMHYpebqTDwhzDn X-Received: by 2002:a17:90b:4f4d:b0:1c7:5324:c6a0 with SMTP id pj13-20020a17090b4f4d00b001c75324c6a0mr7447160pjb.160.1649210572643; Tue, 05 Apr 2022 19:02:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649210572; cv=none; d=google.com; s=arc-20160816; b=rTwgfOSVsDBjzd88CTSLXJYF43cVZY4/fDm6g7928UKs0mG4RDHyh7MmuwPvSSE/fx wDDf3KGVk6LO5BM7zLfwk3UvGCI8XqIbOW7gVzWR09F6blEmwbjJGgMMXGk7oROml0GI 0ZgFZPH1U6VSB+atVBOPIrGXBe5/3DmAo8uKLmp1uZFGOfmFD1Jfw5xT3m4smd9+VVPT qjGApw8YvHA+D07w7EfBKKbGdbHVOSYG+atFyX6eKx0u4lt35WS6RdCgXaVAwuOPvrdu 2irnYE8BSRMltTvPMBHGNIVL+yVq1ZqhDkrbWsZADRp7cjkmMzNgoix+4MgiG8Vifwvy gS6w== 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=LoeL4NqwniIhCcP2Gvi5MmblQZGn4/pj2bWwqqorD07ydmfAVHMX0ORjJMYn1Td0iH ufLvinMpngCbUFe4OyfPdWBUO2av0AAifbzlOjnO/wEkLtwSGvr5QdSRS7FxAE9fCNbw 2KWt3UM/4AxKZwxjihu1DtANUxV9xJcjmBpAktaZBW85lAxiM8cDJXXjL445X2VP0GBX mbXkWWrtXF75NzSUGiSI5ApKwycSyxaC8pwGnF8GSflHcpvXuY5mwDnm7kpeyUshOrs1 Dl7YNf7Pb1RR3ykj3ei8YUIMCHBYJvJRdRLFgxqa+AJ6MT8DFe+X+jKk4hTIt+9pe9L5 TNjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xBJNFwWH; 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 e15-20020a17090301cf00b00153b2d163fcsi15068884plh.4.2022.04.05.19.02.36; Tue, 05 Apr 2022 19:02:52 -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=xBJNFwWH; 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 S1345149AbiDENoW (ORCPT + 99 others); Tue, 5 Apr 2022 09:44:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346846AbiDEJYp (ORCPT ); Tue, 5 Apr 2022 05:24:45 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EDBDC387A7; Tue, 5 Apr 2022 02:14:09 -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 ams.source.kernel.org (Postfix) with ESMTPS id 536AAB818F3; Tue, 5 Apr 2022 09:13:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9D0B9C385A3; Tue, 5 Apr 2022 09:13:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649150036; bh=zVgmbBw35MWRGTT+EfHtGi8B5Mtyr+4PZ6lxdw8c/1o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xBJNFwWHfdoqUJhkPRIhqCE5I4XD9DNcUGE1vhhfgE82Dkyr2uffafmeCNK/0LVQs GT70nNmchfvQXZUX125MKW+B/v3UXQ4FDj4Q9Ob3ZFED9bCUXpyPyrpuc/8BXaZnBu XslUZNo5+61pCR6ffsbIZK9StH2bXQMUpd7Zp05Q= 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.16 0932/1017] gfs2: Make sure FITRIM minlen is rounded up to fs block size Date: Tue, 5 Apr 2022 09:30:45 +0200 Message-Id: <20220405070421.879803634@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@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.1 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 @@ -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)