Skip to content

Commit f504e15

Browse files
davidhildenbrandmstsirkin
authored andcommitted
virtio-mem: remove unsafe unplug in Big Block Mode (BBM)
When "unsafe unplug" is enabled, we don't fake-offline all memory ahead of actual memory offlining using alloc_contig_range(). Instead, we rely on offline_pages() to also perform actual page migration, which might fail or take a very long time. In that case, it's possible to easily run into endless loops that cannot be aborted anymore (as offlining is triggered by a workqueue then): For example, a single (accidentally) permanently unmovable page in ZONE_MOVABLE results in an endless loop. For ZONE_NORMAL, races between isolating the pageblock (and checking for unmovable pages) and concurrent page allocation are possible and similarly result in endless loops. The idea of the unsafe unplug mode was to make it possible to more reliably unplug large memory blocks. However, (a) we really should be tackling that differently, by extending the alloc_contig_range()-based mechanism; and (b) this mode is not the default and as far as I know, it's unused either way. So let's simply get rid of it. Signed-off-by: David Hildenbrand <david@redhat.com> Message-Id: <20230713145551.2824980-2-david@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent 8efc365 commit f504e15

File tree

1 file changed

+20
-31
lines changed

1 file changed

+20
-31
lines changed

drivers/virtio/virtio_mem.c

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@ module_param(bbm_block_size, ulong, 0444);
3838
MODULE_PARM_DESC(bbm_block_size,
3939
"Big Block size in bytes. Default is 0 (auto-detection).");
4040

41-
static bool bbm_safe_unplug = true;
42-
module_param(bbm_safe_unplug, bool, 0444);
43-
MODULE_PARM_DESC(bbm_safe_unplug,
44-
"Use a safe unplug mechanism in BBM, avoiding long/endless loops");
45-
4641
/*
4742
* virtio-mem currently supports the following modes of operation:
4843
*
@@ -2111,38 +2106,32 @@ static int virtio_mem_bbm_offline_remove_and_unplug_bb(struct virtio_mem *vm,
21112106
VIRTIO_MEM_BBM_BB_ADDED))
21122107
return -EINVAL;
21132108

2114-
if (bbm_safe_unplug) {
2115-
/*
2116-
* Start by fake-offlining all memory. Once we marked the device
2117-
* block as fake-offline, all newly onlined memory will
2118-
* automatically be kept fake-offline. Protect from concurrent
2119-
* onlining/offlining until we have a consistent state.
2120-
*/
2121-
mutex_lock(&vm->hotplug_mutex);
2122-
virtio_mem_bbm_set_bb_state(vm, bb_id,
2123-
VIRTIO_MEM_BBM_BB_FAKE_OFFLINE);
2109+
/*
2110+
* Start by fake-offlining all memory. Once we marked the device
2111+
* block as fake-offline, all newly onlined memory will
2112+
* automatically be kept fake-offline. Protect from concurrent
2113+
* onlining/offlining until we have a consistent state.
2114+
*/
2115+
mutex_lock(&vm->hotplug_mutex);
2116+
virtio_mem_bbm_set_bb_state(vm, bb_id, VIRTIO_MEM_BBM_BB_FAKE_OFFLINE);
21242117

2125-
for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) {
2126-
page = pfn_to_online_page(pfn);
2127-
if (!page)
2128-
continue;
2118+
for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) {
2119+
page = pfn_to_online_page(pfn);
2120+
if (!page)
2121+
continue;
21292122

2130-
rc = virtio_mem_fake_offline(pfn, PAGES_PER_SECTION);
2131-
if (rc) {
2132-
end_pfn = pfn;
2133-
goto rollback_safe_unplug;
2134-
}
2123+
rc = virtio_mem_fake_offline(pfn, PAGES_PER_SECTION);
2124+
if (rc) {
2125+
end_pfn = pfn;
2126+
goto rollback;
21352127
}
2136-
mutex_unlock(&vm->hotplug_mutex);
21372128
}
2129+
mutex_unlock(&vm->hotplug_mutex);
21382130

21392131
rc = virtio_mem_bbm_offline_and_remove_bb(vm, bb_id);
21402132
if (rc) {
2141-
if (bbm_safe_unplug) {
2142-
mutex_lock(&vm->hotplug_mutex);
2143-
goto rollback_safe_unplug;
2144-
}
2145-
return rc;
2133+
mutex_lock(&vm->hotplug_mutex);
2134+
goto rollback;
21462135
}
21472136

21482137
rc = virtio_mem_bbm_unplug_bb(vm, bb_id);
@@ -2154,7 +2143,7 @@ static int virtio_mem_bbm_offline_remove_and_unplug_bb(struct virtio_mem *vm,
21542143
VIRTIO_MEM_BBM_BB_UNUSED);
21552144
return rc;
21562145

2157-
rollback_safe_unplug:
2146+
rollback:
21582147
for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) {
21592148
page = pfn_to_online_page(pfn);
21602149
if (!page)

0 commit comments

Comments
 (0)