Skip to contentSkip to conversation

memcpy failed when __bch2_accounting_mem_mod_slowpath

DISCUSSION Hongbo Li 2 participants 4 messages Jun 4, 2024

lore
Share & tools
lore

Hongbo Li

author
#0 lore raw

I found the following issue on:

HEAD commit: 587f7f5a4765a76f9ea05159963d14f8967cb45b(cmd_list_journal: open with noexcl, so we can work on mounted filesystems)

git tree: master
git repo: https://github.com/koverstreet/bcachefs-tools.git
util-linux: 2.37.2

IMPORTANT: If someone fix this issue, please kindly add the following tag to the commit:

[Tue Jun  4 09:16:44 2024] bcachefs (loop1): mounting version 1.9: disk_accounting_v2
[Tue Jun  4 09:16:44 2024] bcachefs (loop1): initializing new filesystem
[Tue Jun  4 09:16:44 2024] bcachefs (loop1): going read-write
[Tue Jun  4 09:16:44 2024] bcachefs (loop1): marking superblocks
[Tue Jun  4 09:16:44 2024] ------------[ cut here ]------------
[Tue Jun  4 09:16:44 2024] memcpy: detected field-spanning write (size 4) of single field "r" at fs/bcachefs/disk_accounting.c:185 (size 3)
[Tue Jun  4 09:16:44 2024] WARNING: CPU: 6 PID: 11 at fs/bcachefs/disk_accounting.c:185 __bch2_accounting_mem_mod_slowpath+0x39f/0x3d0
[Tue Jun  4 09:16:44 2024] Modules linked in: loop nft_fib_inet nft_fib_ipv4 nft_fib_ipv6 nft_fib nft_reject_inet nf_reject_ipv4 nf_reject_ipv6 nft_reject nft_ct nft_chain_nat ip6table_nat ip6table_mangle ip6table_raw ip6table_security iptable_nat nf_nat nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4 iptable_mangle iptable_raw iptable_security rfkill ip_set nf_tables nfnetlink ip6table_filter ip6_tables iptable_filter ip_tables intel_rapl_msr intel_rapl_common nfit libnvdimm kvm_intel ppdev kvm rapl joydev bochs drm_vram_helper sg drm_ttm_helper parport_pc parport ttm drm_kms_helper i2c_piix4 pcspkr drm fuse ext4 mbcache jbd2 sr_mod cdrom ata_generic ata_piix crct10dif_pclmul crc32_pclmul virtio_net crc32c_intel net_failover ghash_clmulni_intel failover serio_raw libata sha512_ssse3 virtio_blk virtio_console dimlib dm_mirror dm_region_hash dm_log dm_mod
[Tue Jun  4 09:16:44 2024] CPU: 6 PID: 11 Comm: kworker/u32:0 Kdump: loaded Not tainted 6.10.0-rc2+ #4
[Tue Jun  4 09:16:44 2024] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1 04/01/2014
[Tue Jun  4 09:16:44 2024] Workqueue: btree_update btree_interior_update_work
[Tue Jun  4 09:16:44 2024] RIP: 0010:__bch2_accounting_mem_mod_slowpath+0x39f/0x3d0
[Tue Jun  4 09:16:44 2024] Code: 01 00 0f 85 11 ff ff ff b9 03 00 00 00 48 c7 c2 e0 af 99 ad 4c 89 f6 48 c7 c7 e8 d7 95 ad c6 05 58 d0 d6 01 01 e8 81 92 b4 ff <0f> 0b e9 e8 fe ff ff 8b 06 41 89 01 42 8b 44 36 fc 43 89 44 31 fc
[Tue Jun  4 09:16:44 2024] RSP: 0018:ff765b4d40063bb8 EFLAGS: 00010282
[Tue Jun  4 09:16:44 2024] RAX: 0000000000000000 RBX: ff4cd701434d88b8 RCX: 0000000000000027
[Tue Jun  4 09:16:44 2024] RDX: ff4cd7103fd20bc8 RSI: 0000000000000001 RDI: ff4cd7103fd20bc0
[Tue Jun  4 09:16:44 2024] RBP: ff765b4d40063c50 R08: 0000000000000000 R09: ff765b4d40063a70
[Tue Jun  4 09:16:44 2024] R10: ff765b4d40063a68 R11: ffffffffae3d5728 R12: ff4cd70186f80000
[Tue Jun  4 09:16:44 2024] R13: 0000000000000000 R14: 0000000000000004 R15: ff4cd701434d88b8
[Tue Jun  4 09:16:44 2024] FS:  0000000000000000(0000) GS:ff4cd7103fd00000(0000) knlGS:0000000000000000
[Tue Jun  4 09:16:44 2024] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[Tue Jun  4 09:16:44 2024] CR2: 00005606add87000 CR3: 0000000a9fa1a002 CR4: 0000000000771ef0
[Tue Jun  4 09:16:44 2024] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
[Tue Jun  4 09:16:44 2024] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
[Tue Jun  4 09:16:44 2024] PKRU: 55555554
[Tue Jun  4 09:16:44 2024] Call Trace:
[Tue Jun  4 09:16:44 2024]  <TASK>
[Tue Jun  4 09:16:44 2024]  ? __warn+0x83/0x130
[Tue Jun  4 09:16:44 2024]  ? __bch2_accounting_mem_mod_slowpath+0x39f/0x3d0
[Tue Jun  4 09:16:44 2024]  ? __report_bug+0xea/0x100
[Tue Jun  4 09:16:44 2024]  ? report_bug+0x24/0x70
[Tue Jun  4 09:16:44 2024]  ? handle_bug+0x3c/0x70
[Tue Jun  4 09:16:44 2024]  ? exc_invalid_op+0x18/0x70
[Tue Jun  4 09:16:44 2024]  ? asm_exc_invalid_op+0x1a/0x20
[Tue Jun  4 09:16:44 2024]  ? __bch2_accounting_mem_mod_slowpath+0x39f/0x3d0
[Tue Jun  4 09:16:44 2024]  ? __bch2_accounting_mem_mod_slowpath+0x39f/0x3d0
[Tue Jun  4 09:16:44 2024]  ? _raw_spin_unlock_irq+0xe/0x30
[Tue Jun  4 09:16:44 2024]  ? rcu_sync_enter+0x8c/0x100
[Tue Jun  4 09:16:44 2024]  ? bch2_printbuf_exit+0x20/0x30
[Tue Jun  4 09:16:44 2024]  bch2_accounting_mem_mod_slowpath+0x6b/0x100
[Tue Jun  4 09:16:44 2024] bch2_trans_commit_write_locked.constprop.0+0x3e0/0xb00
[Tue Jun  4 09:16:44 2024]  do_bch2_trans_commit.isra.0+0xfa/0x550
[Tue Jun  4 09:16:44 2024]  __bch2_trans_commit+0x380/0x880
[Tue Jun  4 09:16:44 2024]  btree_update_nodes_written+0x525/0x850
[Tue Jun  4 09:16:44 2024]  ? btree_update_nodes_written+0x116/0x850
[Tue Jun  4 09:16:44 2024]  btree_interior_update_work+0x55/0x60
[Tue Jun  4 09:16:44 2024]  process_one_work+0x184/0x3b0
[Tue Jun  4 09:16:44 2024]  worker_thread+0x2f9/0x380
[Tue Jun  4 09:16:44 2024]  ? __pfx_worker_thread+0x10/0x10
[Tue Jun  4 09:16:44 2024]  kthread+0xd0/0x100
[Tue Jun  4 09:16:44 2024]  ? __pfx_kthread+0x10/0x10
[Tue Jun  4 09:16:44 2024]  ret_from_fork+0x31/0x50
[Tue Jun  4 09:16:44 2024]  ? __pfx_kthread+0x10/0x10
[Tue Jun  4 09:16:44 2024]  ret_from_fork_asm+0x1a/0x30
[Tue Jun  4 09:16:44 2024]  </TASK>
[Tue Jun  4 09:16:44 2024] ---[ end trace 0000000000000000 ]---
[Tue Jun  4 09:16:44 2024] bcachefs (loop1): initializing freespace
[Tue Jun  4 09:16:44 2024] bcachefs (loop1): done initializing freespace
[Tue Jun  4 09:16:44 2024] bcachefs (loop1): reading snapshots table
[Tue Jun  4 09:16:44 2024] bcachefs (loop1): reading snapshots done
[Tue Jun  4 09:16:44 2024] bcachefs (loop1): done starting filesystem

It can be reproduced by:

reboot
bcachefs format $BCACHEFS_DEV
mount -t bcachefs $BCACHEFS_DEV /mnt/bcachefs

Thanks,
Hongbo

author
#1 lore raw
Quoted 7 lines · Hongbo Li

I found the following issue on:

HEAD commit: 587f7f5a4765a76f9ea05159963d14f8967cb45b(cmd_list_journal: open with noexcl, so we can work on mounted filesystems)

git tree: master
git repo: https://github.com/koverstreet/bcachefs-tools.git
util-linux: 2.37.2

Update git info:

- For bcachefs:
HEAD commit: fb33234c7540e8f1f91413e3c6f25c7fd5801636(bcachefs: Eytzinger accumulation for accounting keys) git tree: master
git repo: https://github.com/koverstreet/bcachefs.git

- For bcachefs-tools:
HEAD commit: 587f7f5a4765a76f9ea05159963d14f8967cb45b(cmd_list_journal: open with noexcl, so we can work on mounted filesystems) git tree: master
git repo: https://github.com/koverstreet/bcachefs-tools.git

- For mount:
util-linux: 2.37.2

Thanks,
Hongbo

Quoted 78 lines

IMPORTANT: If someone fix this issue, please kindly add the following tag to the commit:

[Tue Jun  4 09:16:44 2024] bcachefs (loop1): mounting version 1.9: disk_accounting_v2
[Tue Jun  4 09:16:44 2024] bcachefs (loop1): initializing new filesystem
[Tue Jun  4 09:16:44 2024] bcachefs (loop1): going read-write
[Tue Jun  4 09:16:44 2024] bcachefs (loop1): marking superblocks
[Tue Jun  4 09:16:44 2024] ------------[ cut here ]------------
[Tue Jun  4 09:16:44 2024] memcpy: detected field-spanning write (size 4) of single field "r" at fs/bcachefs/disk_accounting.c:185 (size 3)
[Tue Jun  4 09:16:44 2024] WARNING: CPU: 6 PID: 11 at fs/bcachefs/disk_accounting.c:185 __bch2_accounting_mem_mod_slowpath+0x39f/0x3d0
[Tue Jun  4 09:16:44 2024] Modules linked in: loop nft_fib_inet nft_fib_ipv4 nft_fib_ipv6 nft_fib nft_reject_inet nf_reject_ipv4 nf_reject_ipv6 nft_reject nft_ct nft_chain_nat ip6table_nat ip6table_mangle ip6table_raw ip6table_security iptable_nat nf_nat nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4 iptable_mangle iptable_raw iptable_security rfkill ip_set nf_tables nfnetlink ip6table_filter ip6_tables iptable_filter ip_tables intel_rapl_msr intel_rapl_common nfit libnvdimm kvm_intel ppdev kvm rapl joydev bochs drm_vram_helper sg drm_ttm_helper parport_pc parport ttm drm_kms_helper i2c_piix4 pcspkr drm fuse ext4 mbcache jbd2 sr_mod cdrom ata_generic ata_piix crct10dif_pclmul crc32_pclmul virtio_net crc32c_intel net_failover ghash_clmulni_intel failover serio_raw libata sha512_ssse3 virtio_blk virtio_console dimlib dm_mirror dm_region_hash dm_log dm_mod
[Tue Jun  4 09:16:44 2024] CPU: 6 PID: 11 Comm: kworker/u32:0 Kdump: loaded Not tainted 6.10.0-rc2+ #4
[Tue Jun  4 09:16:44 2024] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1 04/01/2014
[Tue Jun  4 09:16:44 2024] Workqueue: btree_update btree_interior_update_work
[Tue Jun  4 09:16:44 2024] RIP: 0010:__bch2_accounting_mem_mod_slowpath+0x39f/0x3d0
[Tue Jun  4 09:16:44 2024] Code: 01 00 0f 85 11 ff ff ff b9 03 00 00 00 48 c7 c2 e0 af 99 ad 4c 89 f6 48 c7 c7 e8 d7 95 ad c6 05 58 d0 d6 01 01 e8 81 92 b4 ff <0f> 0b e9 e8 fe ff ff 8b 06 41 89 01 42 8b 44 36 fc 43 89 44 31 fc
[Tue Jun  4 09:16:44 2024] RSP: 0018:ff765b4d40063bb8 EFLAGS: 00010282
[Tue Jun  4 09:16:44 2024] RAX: 0000000000000000 RBX: ff4cd701434d88b8 RCX: 0000000000000027
[Tue Jun  4 09:16:44 2024] RDX: ff4cd7103fd20bc8 RSI: 0000000000000001 RDI: ff4cd7103fd20bc0
[Tue Jun  4 09:16:44 2024] RBP: ff765b4d40063c50 R08: 0000000000000000 R09: ff765b4d40063a70
[Tue Jun  4 09:16:44 2024] R10: ff765b4d40063a68 R11: ffffffffae3d5728 R12: ff4cd70186f80000
[Tue Jun  4 09:16:44 2024] R13: 0000000000000000 R14: 0000000000000004 R15: ff4cd701434d88b8
[Tue Jun  4 09:16:44 2024] FS:  0000000000000000(0000) GS:ff4cd7103fd00000(0000) knlGS:0000000000000000
[Tue Jun  4 09:16:44 2024] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[Tue Jun  4 09:16:44 2024] CR2: 00005606add87000 CR3: 0000000a9fa1a002 CR4: 0000000000771ef0
[Tue Jun  4 09:16:44 2024] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
[Tue Jun  4 09:16:44 2024] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
[Tue Jun  4 09:16:44 2024] PKRU: 55555554
[Tue Jun  4 09:16:44 2024] Call Trace:
[Tue Jun  4 09:16:44 2024]  <TASK>
[Tue Jun  4 09:16:44 2024]  ? __warn+0x83/0x130
[Tue Jun  4 09:16:44 2024]  ? __bch2_accounting_mem_mod_slowpath+0x39f/0x3d0
[Tue Jun  4 09:16:44 2024]  ? __report_bug+0xea/0x100
[Tue Jun  4 09:16:44 2024]  ? report_bug+0x24/0x70
[Tue Jun  4 09:16:44 2024]  ? handle_bug+0x3c/0x70
[Tue Jun  4 09:16:44 2024]  ? exc_invalid_op+0x18/0x70
[Tue Jun  4 09:16:44 2024]  ? asm_exc_invalid_op+0x1a/0x20
[Tue Jun  4 09:16:44 2024]  ? __bch2_accounting_mem_mod_slowpath+0x39f/0x3d0
[Tue Jun  4 09:16:44 2024]  ? __bch2_accounting_mem_mod_slowpath+0x39f/0x3d0
[Tue Jun  4 09:16:44 2024]  ? _raw_spin_unlock_irq+0xe/0x30
[Tue Jun  4 09:16:44 2024]  ? rcu_sync_enter+0x8c/0x100
[Tue Jun  4 09:16:44 2024]  ? bch2_printbuf_exit+0x20/0x30
[Tue Jun  4 09:16:44 2024]  bch2_accounting_mem_mod_slowpath+0x6b/0x100
[Tue Jun  4 09:16:44 2024] bch2_trans_commit_write_locked.constprop.0+0x3e0/0xb00
[Tue Jun  4 09:16:44 2024]  do_bch2_trans_commit.isra.0+0xfa/0x550
[Tue Jun  4 09:16:44 2024]  __bch2_trans_commit+0x380/0x880
[Tue Jun  4 09:16:44 2024]  btree_update_nodes_written+0x525/0x850
[Tue Jun  4 09:16:44 2024]  ? btree_update_nodes_written+0x116/0x850
[Tue Jun  4 09:16:44 2024]  btree_interior_update_work+0x55/0x60
[Tue Jun  4 09:16:44 2024]  process_one_work+0x184/0x3b0
[Tue Jun  4 09:16:44 2024]  worker_thread+0x2f9/0x380
[Tue Jun  4 09:16:44 2024]  ? __pfx_worker_thread+0x10/0x10
[Tue Jun  4 09:16:44 2024]  kthread+0xd0/0x100
[Tue Jun  4 09:16:44 2024]  ? __pfx_kthread+0x10/0x10
[Tue Jun  4 09:16:44 2024]  ret_from_fork+0x31/0x50
[Tue Jun  4 09:16:44 2024]  ? __pfx_kthread+0x10/0x10
[Tue Jun  4 09:16:44 2024]  ret_from_fork_asm+0x1a/0x30
[Tue Jun  4 09:16:44 2024]  </TASK>
[Tue Jun  4 09:16:44 2024] ---[ end trace 0000000000000000 ]---
[Tue Jun  4 09:16:44 2024] bcachefs (loop1): initializing freespace
[Tue Jun  4 09:16:44 2024] bcachefs (loop1): done initializing freespace
[Tue Jun  4 09:16:44 2024] bcachefs (loop1): reading snapshots table
[Tue Jun  4 09:16:44 2024] bcachefs (loop1): reading snapshots done
[Tue Jun  4 09:16:44 2024] bcachefs (loop1): done starting filesystem

It can be reproduced by:

reboot
bcachefs format $BCACHEFS_DEV
mount -t bcachefs $BCACHEFS_DEV /mnt/bcachefs

Thanks,
Hongbo

#2 lore raw
In reply to Hongbo Li
Quoted 14 lines · Hongbo Li

I found the following issue on:

HEAD commit: 587f7f5a4765a76f9ea05159963d14f8967cb45b(cmd_list_journal: open with noexcl, so we can work on mounted filesystems)

git tree: master
git repo: https://github.com/koverstreet/bcachefs-tools.git
util-linux: 2.37.2

IMPORTANT: If someone fix this issue, please kindly add the following tag to the commit:

Quoted 9 lines
[Tue Jun  4 09:16:44 2024] bcachefs (loop1): mounting version 1.9:
disk_accounting_v2
[Tue Jun  4 09:16:44 2024] bcachefs (loop1): initializing new filesystem
[Tue Jun  4 09:16:44 2024] bcachefs (loop1): going read-write
[Tue Jun  4 09:16:44 2024] bcachefs (loop1): marking superblocks
[Tue Jun  4 09:16:44 2024] ------------[ cut here ]------------
[Tue Jun  4 09:16:44 2024] memcpy: detected field-spanning write (size 4) of
single field "r" at fs/bcachefs/disk_accounting.c:185 (size 3)
[Tue Jun  4 09:16:44 2024] WARNING: CPU: 6 PID: 11 at

Thanks, this just needs an unsafe_memcpy() annotation

commit 1c39379a4cddbf8d68c588ac9df7149840b9e4ff

Author: Kent Overstreet <[email protected]>
Date:   Mon Jun 3 22:01:25 2024 -0400

fixup! bcachefs: Disk space accounting rewrite

fs/bcachefs/disk_accounting.c +3 -1
index 48d68db286a3..f118d5614e3a 100644
@@ -182,7 +182,9 @@ static inline bool accounting_to_replicas(struct bch_replicas_entry_v1 *r, struc
 
 	switch (acc_k.type) {
 	case BCH_DISK_ACCOUNTING_replicas:
-		memcpy(r, &acc_k.replicas, replicas_entry_bytes(&acc_k.replicas));
+		unsafe_memcpy(r, &acc_k.replicas,
+			      replicas_entry_bytes(&acc_k.replicas),
+			      "variable length struct");
 		return true;
 	default:
 		return false;
author
#3 lore raw
Quoted 39 lines · Kent Overstreet
Quoted 14 lines · Hongbo Li

I found the following issue on:

HEAD commit: 587f7f5a4765a76f9ea05159963d14f8967cb45b(cmd_list_journal: open with noexcl, so we can work on mounted filesystems)

git tree: master
git repo: https://github.com/koverstreet/bcachefs-tools.git
util-linux: 2.37.2

IMPORTANT: If someone fix this issue, please kindly add the following tag to the commit:

Quoted 9 lines
[Tue Jun  4 09:16:44 2024] bcachefs (loop1): mounting version 1.9:
disk_accounting_v2
[Tue Jun  4 09:16:44 2024] bcachefs (loop1): initializing new filesystem
[Tue Jun  4 09:16:44 2024] bcachefs (loop1): going read-write
[Tue Jun  4 09:16:44 2024] bcachefs (loop1): marking superblocks
[Tue Jun  4 09:16:44 2024] ------------[ cut here ]------------
[Tue Jun  4 09:16:44 2024] memcpy: detected field-spanning write (size 4) of
single field "r" at fs/bcachefs/disk_accounting.c:185 (size 3)
[Tue Jun  4 09:16:44 2024] WARNING: CPU: 6 PID: 11 at

Thanks, this just needs an unsafe_memcpy() annotation

commit 1c39379a4cddbf8d68c588ac9df7149840b9e4ff

Author: Kent Overstreet <[email protected]>
Date:   Mon Jun 3 22:01:25 2024 -0400

fixup! bcachefs: Disk space accounting rewrite

fs/bcachefs/disk_accounting.c +0 -0
index 48d68db286a3..f118d5614e3a 100644

fs/bcachefs/disk_accounting.c static inline bool accounting_to_replicas(struct bch_replicas_entry_v1 *r, struc · line 187

Quoted 7 lines
fs/bcachefs/disk_accounting.c +3 -1
@@ -182,7 +182,9 @@ static inline bool accounting_to_replicas(struct bch_replicas_entry_v1 *r, struc
 
  	switch (acc_k.type) {
  	case BCH_DISK_ACCOUNTING_replicas:
-		memcpy(r, &acc_k.replicas, replicas_entry_bytes(&acc_k.replicas));
+		unsafe_memcpy(r, &acc_k.replicas,
+			      replicas_entry_bytes(&acc_k.replicas),
+			      "variable length struct");

I have tested it on this patch. It Looks good! Feel free to add:

Thanks,
Hongbo

Quoted 4 lines
fs/bcachefs/disk_accounting.c +0 -0
  		return true;
  	default:
  		return false;