Skip to contentSkip to conversation

virtio-mem: fix sleeping in RCU read side section in virtio_mem_online_page_cb()

PATCH New David Hildenbrand 1 participant 1 message Aug 25, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

Fixes 6cc26d77613a: "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 Linus Torvalds <[email protected]>

---

The problematic commit is in v5.14-rc1 .. v5.14-rc7, but it suspect might be too late for v5.14.

The original commit went upstream via Andrews tree, we could take this fix via Andrews tree as well or via the vhost tree (MST), I don't particularly care. (putting Linus on CC just in case)

---
 drivers/virtio/virtio_mem.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/virtio/virtio_mem.c +8 -1
index 09ed55de07d7..b91bc810a87e 100644
@@ -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();
Signature · 1 line
2.31.1