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 BB57BC678D5 for ; Tue, 7 Mar 2023 17:31:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231536AbjCGRba (ORCPT ); Tue, 7 Mar 2023 12:31:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230491AbjCGRbO (ORCPT ); Tue, 7 Mar 2023 12:31:14 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6BE69DE19 for ; Tue, 7 Mar 2023 09:26:30 -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 ams.source.kernel.org (Postfix) with ESMTPS id 316EFB8199E for ; Tue, 7 Mar 2023 17:26:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BA7FCC433EF; Tue, 7 Mar 2023 17:26:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678209987; bh=nwgV6eUM/zcDO8pvJ5vNp+15PxZcUreF4iT5zq90cyc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=gWIsFY4/2Qc3yN0FU4YKz2XMwj3gwk/ZzsyI3SgpfNAkzIaWFRSV/baFacoXUHoOs RszngGBJFGqIbUQrIFYf4hXVdR+fHZAq3sBRY2Jh4z262JFZ4eX5flDjzYPOEaRCFk wpS2ygKBb3Nwv9frdeOSOUp3J93DEyjlIS5krJqUYKdP2HxSYidaBr93/LKH8MAiYi HMWIXv08Vu91+AZFvg7x90TJmXOwtn3RdPGX35r6nGoJZJ6xxgK9REdkOV1eVYfkvN 1Rm/9KP+S28tQVSHZppbcgd5CM3XmIV8jg0fewWftJ88DDV64KkdZxesnUTsLvRnOc mUAjg8B3Ct3GA== Date: Tue, 7 Mar 2023 09:26:26 -0800 From: Jaegeuk Kim To: Chao Yu Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Zhiguo Niu Subject: Re: [PATCH] f2fs: fix unaligned field offset in 32-bits platform Message-ID: References: <20230307151408.58490-1-chao@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230307151408.58490-1-chao@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Cc'ed stable. Thanks. On 03/07, Chao Yu wrote: > F2FS-fs (dm-x): inconsistent rbtree, cur(3470333575168) next(3320009719808) > ------------[ cut here ]------------ > kernel BUG at fs/f2fs/gc.c:602! > Internal error: Oops - BUG: 0 [#1] PREEMPT SMP ARM > PC is at get_victim_by_default+0x13c0/0x1498 > LR is at f2fs_check_rb_tree_consistence+0xc4/0xd4 > .... > [] (get_victim_by_default) from [] (f2fs_gc+0x220/0x6cc) > [] (f2fs_gc) from [] (gc_thread_func+0x2ac/0x708) > [] (gc_thread_func) from [] (kthread+0x1a8/0x1b4) > [] (kthread) from [] (ret_from_fork+0x14/0x20) > > The reason is there is __packed attribute in struct rb_entry, but there > is no __packed attribute in struct victim_entry, so wrong offset of key > field will be parsed in struct rb_entry in f2fs_check_rb_tree_consistence, > it describes memory layouts of struct rb_entry and struct victim_entry in > 32-bits platform as below: > > struct rb_entry { > [0] struct rb_node rb_node; > union { > struct {...}; > [12] unsigned long long key; > } __packed; > } > size of struct rb_entry: 20 > > struct victim_entry { > [0] struct rb_node rb_node; > union { > struct {...}; > [16] struct victim_info vi; > }; > [32] struct list_head list; > } > size of struct victim_entry: 40 > > This patch tries to add __packed attribute in below structure: > - discard_info, discard_cmd > - extent_info, extent_node > - victim_info, victim_entry > in order to fix this unaligned field offset issue in 32-bits platform. > > Fixes: 004b68621897 ("f2fs: use rb-tree to track pending discard commands") > Fixes: 13054c548a1c ("f2fs: introduce infra macro and data structure of rb-tree extent cache") > Fixes: 093749e296e2 ("f2fs: support age threshold based garbage collection") > Signed-off-by: Zhiguo Niu > Signed-off-by: Chao Yu > --- > fs/f2fs/f2fs.h | 6 +++--- > fs/f2fs/gc.h | 4 ++-- > 2 files changed, 5 insertions(+), 5 deletions(-) > > diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h > index b0ab2062038a..17fa7572ceed 100644 > --- a/fs/f2fs/f2fs.h > +++ b/fs/f2fs/f2fs.h > @@ -349,7 +349,7 @@ struct discard_info { > block_t lstart; /* logical start address */ > block_t len; /* length */ > block_t start; /* actual start address in dev */ > -}; > +} __packed; > > struct discard_cmd { > struct rb_node rb_node; /* rb node located in rb-tree */ > @@ -361,7 +361,7 @@ struct discard_cmd { > }; > struct discard_info di; /* discard info */ > > - }; > + } __packed; > struct list_head list; /* command list */ > struct completion wait; /* compleation */ > struct block_device *bdev; /* bdev */ > @@ -660,7 +660,7 @@ struct extent_info { > unsigned long long last_blocks; > }; > }; > -}; > +} __packed; > > struct extent_node { > struct rb_node rb_node; /* rb node located in rb-tree */ > diff --git a/fs/f2fs/gc.h b/fs/f2fs/gc.h > index 15bd1d680f67..304937d9a084 100644 > --- a/fs/f2fs/gc.h > +++ b/fs/f2fs/gc.h > @@ -58,7 +58,7 @@ struct gc_inode_list { > struct victim_info { > unsigned long long mtime; /* mtime of section */ > unsigned int segno; /* section No. */ > -}; > +} __packed; > > struct victim_entry { > struct rb_node rb_node; /* rb node located in rb-tree */ > @@ -68,7 +68,7 @@ struct victim_entry { > unsigned int segno; /* segment No. */ > }; > struct victim_info vi; /* victim info */ > - }; > + } __packed; > struct list_head list; > }; > > -- > 2.36.1