Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp789561rwb; Thu, 1 Dec 2022 08:23:00 -0800 (PST) X-Google-Smtp-Source: AA0mqf62cOK4aqJYadh5lLlIAhznWOzC4YHNp8E2GVKau5ENehn+5ZnNfpxz0Ovi2BUFoQ9wV4c4 X-Received: by 2002:a17:906:4309:b0:78d:36d7:92ae with SMTP id j9-20020a170906430900b0078d36d792aemr40747778ejm.113.1669911780192; Thu, 01 Dec 2022 08:23:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669911780; cv=none; d=google.com; s=arc-20160816; b=cabuc9UqGRSwNRFeBDU5ZEYvvnSNCs99pdOwMYs+xN82og/qrW/ym51diTFTavhR60 rA208KBtepeWWN1nwWla2gcW7YGPH1HYps5zbZ4nKOrOopdz7zmd9bjzJs8nnJ0ROoAn luI5PIITZ0QpALrroKyF6+aWg/ah5i6M/iHNrvugJ7NmqUHzcHwLZgW0hMDDzqmtt3WD PAT1dSk686hOnAple8uXmj+kdcbt443AN1DKM1F9IBKZbwAX/TNVPTw5aMKwVoiuCgaQ PYcXl/x7WRyZMyGXAeBZ/hUrAqH2YaphAGv8y91HTrGan2urdneNXsN2MBKbEjG7uLjv yDtQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=qqommci96us+QVDcXaQm47rsizn+sT4z8GqL5KIOQ8U=; b=nvSmT5NRh3u6o3jB8YomvAX9wVt1EnK+C0tc/hAW0uSY3tw5C9/bpzmalbx3Jx2Z6V qe/nm3P35rd/Bi44M2ipwUQdBTcjgjXTb0tc7m2Atr9L5S5boh+v8yjFKDjCpaYvdkmn iBXon3tr6t54YclLoM2xlkWnC1ZKCVqw0Ghaz36827Y4AKi+8+KvdtEuVKsGakeOhT9k /QJEdiJRxKXf8BubdBa1lxMXKoM9MRxarDG1gV/IBOpFVJ3F8g/KPI3v65nBUG2mH+fd 3odhKC2BOlGro/zrj0EtSEANY3suCt6+6qfwfwpwc/QkW9ukNiw4RhyeFJY86qJUWVE9 H7Qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cpWvE8dz; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e9-20020a17090658c900b007806964b2fcsi4616812ejs.447.2022.12.01.08.22.35; Thu, 01 Dec 2022 08:23:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-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=@redhat.com header.s=mimecast20190719 header.b=cpWvE8dz; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231893AbiLAQIh (ORCPT + 99 others); Thu, 1 Dec 2022 11:08:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231860AbiLAQIc (ORCPT ); Thu, 1 Dec 2022 11:08:32 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B59BE06 for ; Thu, 1 Dec 2022 08:07:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669910853; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qqommci96us+QVDcXaQm47rsizn+sT4z8GqL5KIOQ8U=; b=cpWvE8dzRHKOwYzlO21+zYypfvxvbzzRYkzOZoxQ/rQru8l4P3s5QEp239qHmGaH+3NXu3 3MRAGtNUXZ0LS/EnlDdYSk5G3BKpq9JQ1mVTufDadwqK6QwKRD3VGmw1ZBcHix2l7e8j5g jyXT/IjOoyI664YBoOOE+v0i1N7gb28= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-369-qMK60ov8MSi3UZwPT7S-dA-1; Thu, 01 Dec 2022 11:07:00 -0500 X-MC-Unique: qMK60ov8MSi3UZwPT7S-dA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 30959800186; Thu, 1 Dec 2022 16:06:29 +0000 (UTC) Received: from pasta.redhat.com (ovpn-192-141.brq.redhat.com [10.40.192.141]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2AB4D111E3FA; Thu, 1 Dec 2022 16:06:27 +0000 (UTC) From: Andreas Gruenbacher To: Christoph Hellwig , "Darrick J . Wong" , Alexander Viro , Matthew Wilcox Cc: Andreas Gruenbacher , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, cluster-devel@redhat.com Subject: [RFC 3/3] gfs2: Fix race between shrinker and gfs2_iomap_folio_done Date: Thu, 1 Dec 2022 17:06:19 +0100 Message-Id: <20221201160619.1247788-4-agruenba@redhat.com> In-Reply-To: <20221201160619.1247788-1-agruenba@redhat.com> References: <20221201160619.1247788-1-agruenba@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE 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-ext4@vger.kernel.org In gfs2_iomap_folio_done(), add the modified buffer heads to the current transaction while the folio is still locked. Otherwise, the shrinker can come in and free them before we get to gfs2_page_add_databufs(). Signed-off-by: Andreas Gruenbacher --- fs/gfs2/bmap.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index 18dcaa95408e..d8d9ee843ac9 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -990,18 +990,17 @@ gfs2_iomap_folio_done(struct inode *inode, struct folio *folio, struct gfs2_inode *ip = GFS2_I(inode); struct gfs2_sbd *sdp = GFS2_SB(inode); - folio_unlock(folio); - if (!gfs2_is_stuffed(ip)) gfs2_page_add_databufs(ip, &folio->page, offset_in_page(pos), copied); + folio_unlock(folio); + folio_put(folio); + if (tr->tr_num_buf_new) __mark_inode_dirty(inode, I_DIRTY_DATASYNC); gfs2_trans_end(sdp); - - folio_put(folio); } static const struct iomap_folio_ops gfs2_iomap_folio_ops = { -- 2.38.1