Skip to content

Commit 425bec0

Browse files
davidhildenbrandtorvalds
authored andcommitted
virtio-mem: fix sleeping in RCU read side section in virtio_mem_online_page_cb()
virtio_mem_set_fake_offline() might sleep now, and we call it under rcu_read_lock(). To fix it, simply move the rcu_read_unlock() further up, as we're done with the device. Reported-by: Dan Carpenter <[email protected]> Fixes: 6cc26d7: "virtio-mem: use page_offline_(start|end) when setting PageOffline() Cc: "Michael S. Tsirkin" <[email protected]> Cc: Jason Wang <[email protected]> Cc: Andrew Morton <[email protected]> Cc: [email protected] Signed-off-by: David Hildenbrand <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 5a61b7a commit 425bec0

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

drivers/virtio/virtio_mem.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1242,12 +1242,19 @@ static void virtio_mem_online_page_cb(struct page *page, unsigned int order)
12421242
do_online = virtio_mem_bbm_get_bb_state(vm, id) !=
12431243
VIRTIO_MEM_BBM_BB_FAKE_OFFLINE;
12441244
}
1245+
1246+
/*
1247+
* virtio_mem_set_fake_offline() might sleep, we don't need
1248+
* the device anymore. See virtio_mem_remove() how races
1249+
* between memory onlining and device removal are handled.
1250+
*/
1251+
rcu_read_unlock();
1252+
12451253
if (do_online)
12461254
generic_online_page(page, order);
12471255
else
12481256
virtio_mem_set_fake_offline(PFN_DOWN(addr), 1 << order,
12491257
false);
1250-
rcu_read_unlock();
12511258
return;
12521259
}
12531260
rcu_read_unlock();

0 commit comments

Comments
 (0)