Skip to content

Commit

Permalink
fs: prevent kernel panic when device is hot-removed
Browse files Browse the repository at this point in the history
We observed kernel crash when a fat device is removed.

[111565.359333] c5    692 Unable to handle kernel NULL pointer dereference at virtual address 000000c8
[111565.359341] c5    692 Mem abort info:
[111565.359344] c5    692   Exception class = DABT (current EL), IL = 32 bits
[111565.359346] c5    692   SET = 0, FnV = 0
[111565.359348] c5    692   EA = 0, S1PTW = 0
[111565.359350] c5    692   FSC = 5
[111565.359352] c5    692 Data abort info:
[111565.359354] c5    692   ISV = 0, ISS = 0x00000005
[111565.359356] c5    692   CM = 0, WnR = 0
[111565.359359] c5    692 user pgtable: 4k pages, 39-bit VAs, pgd = 0000000011af7d86
[111565.359362] c5    692 [00000000000000c8] *pgd=0000000000000000, *pud=0000000000000000
[111565.359366] c5    692 Internal error: Oops: 96000005 [#1] PREEMPT SMP
[111565.359404] c5    692 task: 000000002bd545ae task.stack: 0000000067db34ef
[111565.359414] c5    692 pc : percpu_counter_add_batch+0x20/0x230
[111565.359421] c5    692 lr : generic_make_request_checks+0x50c/0x924
...
[111565.359535] c5    692 Call trace:
[111565.359538] c5    692  percpu_counter_add_batch+0x20/0x230
[111565.359541] c5    692  generic_make_request_checks+0x50c/0x924
[111565.359543] c5    692  generic_make_request+0x40/0x298
[111565.359545] c5    692  submit_bio+0xb0/0x5bc
[111565.359550] c5    692  submit_bh_wbc+0x14c/0x194
[111565.359552] c5    692  __bread_gfp+0x110/0x240
[111565.359556] c5    692  fat_set_state+0x68/0x144
[111565.359558] c5    692  fat_put_super+0x20/0x68
[111565.359562] c5    692  generic_shutdown_super+0x88/0x2a0
[111565.359564] c5    692  kill_block_super+0x20/0x58
[111565.359566] c5    692  deactivate_locked_super+0xc8/0x34c
[111565.359569] c5    692  cleanup_mnt+0x15c/0x324
[111565.359572] c5    692  __cleanup_mnt+0x14/0x20
[111565.359576] c5    692  task_work_run+0x15c/0x1b0
[111565.359579] c5    692  do_notify_resume+0xf94/0x1148
[111565.359583] c5    692  work_pending+0x8/0x10

Bug: 179494045
Test: manually remove OTG storage
Change-Id: Ic9e9ff2b1ea70307cbf1864cd7475481c04959cb
Signed-off-by: Randall Huang <[email protected]>
  • Loading branch information
Randall Huang authored and mukesh22584 committed Jan 24, 2023
1 parent 8601b6f commit 196ed4d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions include/linux/blk-cgroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -707,10 +707,14 @@ static inline bool blkcg_bio_issue_check(struct request_queue *q,
throtl = blk_throtl_bio(q, blkg, bio);

if (!throtl) {
spin_lock_irq(q->queue_lock);
blkg = blkg ?: q->root_blkg;
blkg_rwstat_add(&blkg->stat_bytes, bio->bi_opf,
bio->bi_iter.bi_size);
blkg_rwstat_add(&blkg->stat_ios, bio->bi_opf, 1);
if (blkg) {
blkg_rwstat_add(&blkg->stat_bytes, bio->bi_opf,
bio->bi_iter.bi_size);
blkg_rwstat_add(&blkg->stat_ios, bio->bi_opf, 1);
}
spin_unlock_irq(q->queue_lock);
}

rcu_read_unlock();
Expand Down

0 comments on commit 196ed4d

Please sign in to comment.