From patchwork Thu Dec 1 18:09:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Gruenbacher X-Patchwork-Id: 13061720 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1979EC4321E for ; Thu, 1 Dec 2022 18:11:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230089AbiLASLf (ORCPT ); Thu, 1 Dec 2022 13:11:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230083AbiLASLQ (ORCPT ); Thu, 1 Dec 2022 13:11:16 -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 35DABB7DE1 for ; Thu, 1 Dec 2022 10:10:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669918212; 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=ccikLn8J4gP2KDC9qMgjNNPYwlDVurjNkJq1durMHs18rHOVOEoZL3LaUJEiUfR9v9bTv/ aSR4jGffdb0Hxrt98PuoXZaOdJDb3YrCulTCwc8rWctrm93cLy8o8ZPUgtQGGer2nqg7G4 s/miIAIFyfduWmR+U9pI1OLpaiuLTH0= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-583-40vpE01EONeRkvjW54PyJg-1; Thu, 01 Dec 2022 13:10:09 -0500 X-MC-Unique: 40vpE01EONeRkvjW54PyJg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5EB9E2A59540; Thu, 1 Dec 2022 18:10:08 +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 048F0C15BB4; Thu, 1 Dec 2022 18:10:05 +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 v2 3/3] gfs2: Fix race between shrinker and gfs2_iomap_folio_done Date: Thu, 1 Dec 2022 19:09:57 +0100 Message-Id: <20221201180957.1268079-4-agruenba@redhat.com> In-Reply-To: <20221201160619.1247788-1-agruenba@redhat.com> References: <20221201160619.1247788-1-agruenba@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@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 = {