From patchwork Wed Mar 5 09:11:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 14002147 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 lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 68B40C19F32 for ; Wed, 5 Mar 2025 09:14:59 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1tpkqA-0002lz-AR; Wed, 05 Mar 2025 09:14:59 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1tpkq9-0002ln-NF for linux-f2fs-devel@lists.sourceforge.net; Wed, 05 Mar 2025 09:14:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=i5vHusaYUSWI9OZwHQkxFSO+96wqrtyy1Ejxhqsa0Dk=; b=bp6mdjN32I9rrw0L2QO9OJzXqB nJFtPse2caAQCQXKQ41+9bokaBKxnx6Ok5Kh1MgQ+F0vNojpUc2TUeVJDRewwr41Lzd2+XXqj/1Nl 65QvmmPHxs7MB9z4TOorLb+5mfiYqRS99besk5F9sbfjmAkKMXZy1SxnqzGSsEYbHJU4=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=i5vHusaYUSWI9OZwHQkxFSO+96wqrtyy1Ejxhqsa0Dk=; b=LLoU+kGa0FzFlMT8TL4xLoMVp9 a8Ajrdho0tb3G/wCgXJIMVynPeownfL2tSioNh/LCp/nIwjEA6nkVLWyCs/L7JX3zWSJEgnRF0gV8 XedNxDo62PS46DtnGuxHkxOeT6ShTzCJkT9RKK6ccqdGFOw8kCwVdCaBw3ZaMxzn7ydc=; Received: from dfw.source.kernel.org ([139.178.84.217]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1tpkpz-0000Sy-O2 for linux-f2fs-devel@lists.sourceforge.net; Wed, 05 Mar 2025 09:14:58 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 894B85C670D for ; Wed, 5 Mar 2025 09:12:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D0116C4CEEB; Wed, 5 Mar 2025 09:14:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741166082; bh=DitxeJ2gqXUOYGkIW/ENapU+8NKt4Y/c0heOSDT7o6k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K5yxKNAINde+X1rTymy+myu0Ib76rwex+icxkG0FpXHVBSakHS/YLWwuRY4a00n/Z hzaVzzRudSmj3A0FTBdrcrp6mp58V879yKNVnlm8A1CMqZVH7aLi42PYFZsO3IP5J6 6eexgB7YN2WA2luGHZTsrdFPe368rYk8EBCOpfLGXoebUEyAeLScfO9CH99N+USNk5 JCweJGR3DiTOJ6/keFU+MuPV1sEwqXsiAb88goJYGVUTTBs8htkjUlaUksdfJ733If 2d2PY23LSWJpoMN6pdfa1yFlwKIYWxQXGHPryg149UXVjdsYeO6Y6Lt1f2WhHdAdnK IEuC/LH5IcWVg== To: jaegeuk@kernel.org Date: Wed, 5 Mar 2025 17:11:47 +0800 Message-ID: <20250305091148.2086015-2-chao@kernel.org> X-Mailer: git-send-email 2.49.0.rc0.332.g42c0ae87b1-goog In-Reply-To: <20250305091148.2086015-1-chao@kernel.org> References: <20250305091148.2086015-1-chao@kernel.org> MIME-Version: 1.0 X-Headers-End: 1tpkpz-0000Sy-O2 Subject: [f2fs-dev] [PATCH v2 2/3] f2fs: do sanity check on xattr node footer in f2fs_get_xnode_page() X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Chao Yu via Linux-f2fs-devel From: Chao Yu Reply-To: Chao Yu Cc: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net This patch introduces a new wrapper f2fs_get_xnode_page(), then, caller can use it to load xattr block to page cache, meanwhile it will do sanity check on xattr node footer. Signed-off-by: Chao Yu --- v2: - no changes fs/f2fs/f2fs.h | 1 + fs/f2fs/node.c | 14 ++++++++++++-- fs/f2fs/node.h | 1 + fs/f2fs/xattr.c | 4 ++-- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 9df20576c22b..b43aaa9e4ae5 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -3702,6 +3702,7 @@ void f2fs_ra_node_page(struct f2fs_sb_info *sbi, nid_t nid); struct page *f2fs_get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid); struct folio *f2fs_get_inode_folio(struct f2fs_sb_info *sbi, pgoff_t ino); struct page *f2fs_get_inode_page(struct f2fs_sb_info *sbi, pgoff_t ino); +struct page *f2fs_get_xnode_page(struct f2fs_sb_info *sbi, pgoff_t xnid); struct page *f2fs_get_node_page_ra(struct page *parent, int start); int f2fs_move_node_page(struct page *node_page, int gc_type); void f2fs_flush_inline_data(struct f2fs_sb_info *sbi); diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index 789457af059c..439690f40d2b 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c @@ -1245,7 +1245,7 @@ int f2fs_truncate_xattr_node(struct inode *inode) if (!nid) return 0; - npage = f2fs_get_node_page(sbi, nid); + npage = f2fs_get_xnode_page(sbi, nid); if (IS_ERR(npage)) return PTR_ERR(npage); @@ -1461,7 +1461,9 @@ static int sanity_check_node_footer(struct f2fs_sb_info *sbi, enum node_type ntype) { if (unlikely(nid != nid_of_node(page) || - (ntype == NODE_TYPE_INODE && !IS_INODE(page)))) { + (ntype == NODE_TYPE_INODE && !IS_INODE(page)) || + (ntype == NODE_TYPE_XATTR && + !f2fs_has_xattr_block(ofs_of_node(page))))) { f2fs_warn(sbi, "inconsistent node block, node_type:%d, nid:%lu, " "node_footer[nid:%u,ino:%u,ofs:%u,cpver:%llu,blkaddr:%u]", ntype, nid, nid_of_node(page), ino_of_node(page), @@ -1551,6 +1553,14 @@ struct page *f2fs_get_inode_page(struct f2fs_sb_info *sbi, pgoff_t ino) return &folio->page; } +struct page *f2fs_get_xnode_page(struct f2fs_sb_info *sbi, pgoff_t xnid) +{ + struct folio *folio = __get_node_folio(sbi, xnid, NULL, 0, + NODE_TYPE_XATTR); + + return &folio->page; +} + struct page *f2fs_get_node_page_ra(struct page *parent, int start) { struct f2fs_sb_info *sbi = F2FS_P_SB(parent); diff --git a/fs/f2fs/node.h b/fs/f2fs/node.h index 5079c6a2298d..103a437e6425 100644 --- a/fs/f2fs/node.h +++ b/fs/f2fs/node.h @@ -56,6 +56,7 @@ enum { enum node_type { NODE_TYPE_REGULAR, NODE_TYPE_INODE, + NODE_TYPE_XATTR, }; /* diff --git a/fs/f2fs/xattr.c b/fs/f2fs/xattr.c index d5b42e1005d8..c691b35618ad 100644 --- a/fs/f2fs/xattr.c +++ b/fs/f2fs/xattr.c @@ -303,7 +303,7 @@ static int read_xattr_block(struct inode *inode, void *txattr_addr) void *xattr_addr; /* The inode already has an extended attribute block. */ - xpage = f2fs_get_node_page(sbi, xnid); + xpage = f2fs_get_xnode_page(sbi, xnid); if (IS_ERR(xpage)) return PTR_ERR(xpage); @@ -475,7 +475,7 @@ static inline int write_all_xattrs(struct inode *inode, __u32 hsize, /* write to xattr node block */ if (F2FS_I(inode)->i_xattr_nid) { - xpage = f2fs_get_node_page(sbi, F2FS_I(inode)->i_xattr_nid); + xpage = f2fs_get_xnode_page(sbi, F2FS_I(inode)->i_xattr_nid); if (IS_ERR(xpage)) { err = PTR_ERR(xpage); f2fs_alloc_nid_failed(sbi, new_nid);