Re: [PATCH 2/3] btrfs: do not init dev stats if we have no dev_root

2021-03-11 Thread Anand Jain

On 12/3/21 12:23 am, Josef Bacik wrote:

Neal reported a panic trying to use -o rescue=all

BUG: kernel NULL pointer dereference, address: 0030
PGD 0 P4D 0
Oops:  [#1] SMP PTI
CPU: 0 PID: 4095 Comm: mount Not tainted 5.11.0-0.rc7.149.fc34.x86_64 #1
RIP: 0010:btrfs_device_init_dev_stats+0x4c/0x1f0
RSP: 0018:a60285fbfb68 EFLAGS: 00010246
RAX:  RBX: 88b88f806498 RCX: 88b82e7a2a10
RDX: a60285fbfb97 RSI: 88b82e7a2a10 RDI: 
RBP: 88b88f806b3c R08:  R09: 
R10: 88b82e7a2a10 R11:  R12: 88b88f806a00
R13: 88b88f806478 R14: 88b88f806a00 R15: 88b82e7a2a10
FS:  7f698be1ec40() GS:88b937e0() knlGS:
CS:  0010 DS:  ES:  CR0: 80050033
CR2: 0030 CR3: 92c9c006 CR4: 003706f0
Call Trace:
? btrfs_init_dev_stats+0x1f/0xf0
btrfs_init_dev_stats+0x62/0xf0
open_ctree+0x1019/0x15ff
btrfs_mount_root.cold+0x13/0xfa
legacy_get_tree+0x27/0x40
vfs_get_tree+0x25/0xb0
vfs_kern_mount.part.0+0x71/0xb0
btrfs_mount+0x131/0x3d0
? legacy_get_tree+0x27/0x40
? btrfs_show_options+0x640/0x640
legacy_get_tree+0x27/0x40
vfs_get_tree+0x25/0xb0
path_mount+0x441/0xa80
__x64_sys_mount+0xf4/0x130
do_syscall_64+0x33/0x40
entry_SYSCALL_64_after_hwframe+0x44/0xa9
RIP: 0033:0x7f698c04e52e

This happens because we unconditionally attempt to init device stats on
mount, but we may not have been able to read the device root.  Fix this
by skipping init'ing the device stats if we do not have a device root.

Reported-by: Neal Gompa 
Signed-off-by: Josef Bacik 


 Reviewed-by: Anand Jain 


[PATCH 2/3] btrfs: do not init dev stats if we have no dev_root

2021-03-11 Thread Josef Bacik
Neal reported a panic trying to use -o rescue=all

BUG: kernel NULL pointer dereference, address: 0030
PGD 0 P4D 0
Oops:  [#1] SMP PTI
CPU: 0 PID: 4095 Comm: mount Not tainted 5.11.0-0.rc7.149.fc34.x86_64 #1
RIP: 0010:btrfs_device_init_dev_stats+0x4c/0x1f0
RSP: 0018:a60285fbfb68 EFLAGS: 00010246
RAX:  RBX: 88b88f806498 RCX: 88b82e7a2a10
RDX: a60285fbfb97 RSI: 88b82e7a2a10 RDI: 
RBP: 88b88f806b3c R08:  R09: 
R10: 88b82e7a2a10 R11:  R12: 88b88f806a00
R13: 88b88f806478 R14: 88b88f806a00 R15: 88b82e7a2a10
FS:  7f698be1ec40() GS:88b937e0() knlGS:
CS:  0010 DS:  ES:  CR0: 80050033
CR2: 0030 CR3: 92c9c006 CR4: 003706f0
Call Trace:
? btrfs_init_dev_stats+0x1f/0xf0
btrfs_init_dev_stats+0x62/0xf0
open_ctree+0x1019/0x15ff
btrfs_mount_root.cold+0x13/0xfa
legacy_get_tree+0x27/0x40
vfs_get_tree+0x25/0xb0
vfs_kern_mount.part.0+0x71/0xb0
btrfs_mount+0x131/0x3d0
? legacy_get_tree+0x27/0x40
? btrfs_show_options+0x640/0x640
legacy_get_tree+0x27/0x40
vfs_get_tree+0x25/0xb0
path_mount+0x441/0xa80
__x64_sys_mount+0xf4/0x130
do_syscall_64+0x33/0x40
entry_SYSCALL_64_after_hwframe+0x44/0xa9
RIP: 0033:0x7f698c04e52e

This happens because we unconditionally attempt to init device stats on
mount, but we may not have been able to read the device root.  Fix this
by skipping init'ing the device stats if we do not have a device root.

Reported-by: Neal Gompa 
Signed-off-by: Josef Bacik 
---
 fs/btrfs/volumes.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 995920fcce9b..d4ca721c1d91 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -7448,6 +7448,9 @@ static int btrfs_device_init_dev_stats(struct 
btrfs_device *device,
int item_size;
int i, ret, slot;
 
+   if (!device->fs_info->dev_root)
+   return 0;
+
key.objectid = BTRFS_DEV_STATS_OBJECTID;
key.type = BTRFS_PERSISTENT_ITEM_KEY;
key.offset = device->devid;
-- 
2.26.2