Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp6020962pxb; Mon, 14 Feb 2022 13:18:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJytOo6YdXqNHqtO/2F6XMAwVyYExYufxiVE5qeDHo1OuqmE7tz1bVNSVpnOyhry0MBgjkiQ X-Received: by 2002:a63:4e14:: with SMTP id c20mr791765pgb.594.1644873529017; Mon, 14 Feb 2022 13:18:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644873529; cv=none; d=google.com; s=arc-20160816; b=rTWzh+xE8TGa1Rl7W5XDhzMmhIPmGJRyyN8pLU981esOOobXsxM+7rMk1vMt5fTCYQ bscPuy/9gs1ir0lNTRP32VMa6ww13cj8MRdlFMtNGcDsj9H8ZWENuawLkNlnxLb6zF/u FHs/eCPOtKj8CWNjRkUYMa/dzZzds9/297Rr0//mMGwu8ybUR8lB6RBuK/4TN8tCq3ar nbkHy/eMmEywt9DQAnu2phqPRKePMD0XGePOiZ72mNfdDaOKa/x8RjP/wzETDuh7syGD ucujXI/sVCqMS6BAHlKEJzm6TUnXzkxFLKsdJKK8r6IC9TU0LIsYWfIF56MjgbePo2Ku St9Q== 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=CNCoO+x4RLN5aoBqPktye5eCw7IGYBEpt+ybYPz/9sU=; b=PLsvgyXTOCrtykYKH3vrBRLUy8uuwQAaZf99/reJ04jY7bdFI5g5OiuB3mc/OZ8CV8 LAvA6rJwicK7DTfW/hWKKW2G4vQkSiBBcRcSKWGybneP3MEwVuMallTl4kR9AMjEtEae ljDvDJ1YqHZopmqPPgKa6g5nVa4YxJviRI6b2rOAeBWRMv1QwV9EPrldK49XOt+gDy5J FXNJuYYnO/FnJYTdrBaJTzok14+6HmL7+yJ047rfLrV5kv0F1j9Kvj+lfTLA5IhNa2AO 89qXFpYJH+foPOgDa8hdPPX2lzh1yCo0WcCO6Vi2heFEzkLQCvPJ/O68zWfvPNq29dML jwVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CdQO1uR8; 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 qe5si3045940pjb.66.2022.02.14.13.18.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Feb 2022 13:18:49 -0800 (PST) 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=CdQO1uR8; 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 312391A76CD; Mon, 14 Feb 2022 12:36:37 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347069AbiBNKb2 (ORCPT + 99 others); Mon, 14 Feb 2022 05:31:28 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:37374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348057AbiBNKap (ORCPT ); Mon, 14 Feb 2022 05:30:45 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 334C39BF51; Mon, 14 Feb 2022 01:59:18 -0800 (PST) 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 E122260A6B; Mon, 14 Feb 2022 09:59:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B1183C340EF; Mon, 14 Feb 2022 09:59:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644832741; bh=OEDJNIYHkJ6QNba+OjECjhNgSeZq5mr0y+XWi/DAICA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CdQO1uR8O2vYV9zRw5PrP59xIgrOHYS8V5zbSv7uBiXSzY5+PVhvmp9VAnSrtHofd BHT++CtC/Llydbm9vngq62QoRVo/QudTpbLJg2HNpvasbbsKcGHmBe5UgibMW4D2Bv Owfo3NAS0vavLiHL/bP7hRYtnggfOKlrPI9T+LzI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bob Peterson , Andreas Gruenbacher Subject: [PATCH 5.16 078/203] gfs2: Fix gfs2_release for non-writers regression Date: Mon, 14 Feb 2022 10:25:22 +0100 Message-Id: <20220214092512.927908552@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220214092510.221474733@linuxfoundation.org> References: <20220214092510.221474733@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: Bob Peterson commit d3add1a9519dcacd6e644ecac741c56cf18b67f5 upstream. When a file is opened for writing, the vfs code (do_dentry_open) calls get_write_access for the inode, thus incrementing the inode's write count. That writer normally then creates a multi-block reservation for the inode (i_res) that can be re-used by other writers, which speeds up writes for applications that stupidly loop on open/write/close. When the writes are all done, the multi-block reservation should be deleted when the file is closed by the last "writer." Commit 0ec9b9ea4f83 broke that concept when it moved the call to gfs2_rs_delete before the check for FMODE_WRITE. Non-writers have no business removing the multi-block reservations of writers. In fact, if someone opens and closes the file for RO while a writer has a multi-block reservation, the RO closer will delete the reservation midway through the write, and this results in: kernel BUG at fs/gfs2/rgrp.c:677! (or thereabouts) which is: BUG_ON(rs->rs_requested); from function gfs2_rs_deltree. This patch moves the check back inside the check for FMODE_WRITE. Fixes: 0ec9b9ea4f83 ("gfs2: Check for active reservation in gfs2_release") Cc: stable@vger.kernel.org # v5.12+ Signed-off-by: Bob Peterson Signed-off-by: Andreas Gruenbacher Signed-off-by: Greg Kroah-Hartman --- fs/gfs2/file.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) --- a/fs/gfs2/file.c +++ b/fs/gfs2/file.c @@ -704,10 +704,11 @@ static int gfs2_release(struct inode *in kfree(file->private_data); file->private_data = NULL; - if (gfs2_rs_active(&ip->i_res)) - gfs2_rs_delete(ip, &inode->i_writecount); - if (file->f_mode & FMODE_WRITE) + if (file->f_mode & FMODE_WRITE) { + if (gfs2_rs_active(&ip->i_res)) + gfs2_rs_delete(ip, &inode->i_writecount); gfs2_qa_put(ip); + } return 0; }