Skip to content

Commit 500817b

Browse files
davidhildenbrandmstsirkin
authored andcommitted
virtio-mem: don't read big block size in Sub Block Mode
We are reading a Big Block Mode value while in Sub Block Mode when initializing. Fortunately, vm->bbm.bb_size maps to some counter in the vm->sbm.mb_count array, which is 0 at that point in time. No harm done; still, this was unintended and is not future-proof. Fixes: 4ba50cd ("virtio-mem: Big Block Mode (BBM) memory hotplug") Signed-off-by: David Hildenbrand <david@redhat.com> Link: https://lore.kernel.org/r/20210602185720.31821-2-david@redhat.com Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent efa08cb commit 500817b

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

drivers/virtio/virtio_mem.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2420,6 +2420,10 @@ static int virtio_mem_init(struct virtio_mem *vm)
24202420
dev_warn(&vm->vdev->dev,
24212421
"Some device memory is not addressable/pluggable. This can make some memory unusable.\n");
24222422

2423+
/* Prepare the offline threshold - make sure we can add two blocks. */
2424+
vm->offline_threshold = max_t(uint64_t, 2 * memory_block_size_bytes(),
2425+
VIRTIO_MEM_DEFAULT_OFFLINE_THRESHOLD);
2426+
24232427
/*
24242428
* We want subblocks to span at least MAX_ORDER_NR_PAGES and
24252429
* pageblock_nr_pages pages. This:
@@ -2466,14 +2470,11 @@ static int virtio_mem_init(struct virtio_mem *vm)
24662470
vm->bbm.bb_size - 1;
24672471
vm->bbm.first_bb_id = virtio_mem_phys_to_bb_id(vm, addr);
24682472
vm->bbm.next_bb_id = vm->bbm.first_bb_id;
2469-
}
24702473

2471-
/* Prepare the offline threshold - make sure we can add two blocks. */
2472-
vm->offline_threshold = max_t(uint64_t, 2 * memory_block_size_bytes(),
2473-
VIRTIO_MEM_DEFAULT_OFFLINE_THRESHOLD);
2474-
/* In BBM, we also want at least two big blocks. */
2475-
vm->offline_threshold = max_t(uint64_t, 2 * vm->bbm.bb_size,
2476-
vm->offline_threshold);
2474+
/* Make sure we can add two big blocks. */
2475+
vm->offline_threshold = max_t(uint64_t, 2 * vm->bbm.bb_size,
2476+
vm->offline_threshold);
2477+
}
24772478

24782479
dev_info(&vm->vdev->dev, "start address: 0x%llx", vm->addr);
24792480
dev_info(&vm->vdev->dev, "region size: 0x%llx", vm->region_size);

0 commit comments

Comments
 (0)