Skip to content

Commit

Permalink
virtio-mem: fix sleeping in RCU read side section in virtio_mem_onlin…
Browse files Browse the repository at this point in the history
…e_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 <dan.carpenter@oracle.com>
Fixes: 6cc26d7: "virtio-mem: use page_offline_(start|end) when setting PageOffline()
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Jason Wang <jasowang@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: virtualization@lists.linux-foundation.org
Signed-off-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
David Hildenbrand authored and Linus Torvalds committed Aug 27, 2021
1 parent 5a61b7a commit 425bec0
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion drivers/virtio/virtio_mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -1242,12 +1242,19 @@ static void virtio_mem_online_page_cb(struct page *page, unsigned int order)
do_online = virtio_mem_bbm_get_bb_state(vm, id) !=
VIRTIO_MEM_BBM_BB_FAKE_OFFLINE;
}

/*
* virtio_mem_set_fake_offline() might sleep, we don't need
* the device anymore. See virtio_mem_remove() how races
* between memory onlining and device removal are handled.
*/
rcu_read_unlock();

if (do_online)
generic_online_page(page, order);
else
virtio_mem_set_fake_offline(PFN_DOWN(addr), 1 << order,
false);
rcu_read_unlock();
return;
}
rcu_read_unlock();
Expand Down

0 comments on commit 425bec0

Please sign in to comment.