Skip to content

Commit 544fc7d

Browse files
committed
virtio_mem: convert device block size into 64bit
If subblock size is large (e.g. 1G) 32 bit math involving it can overflow. Rather than try to catch all instances of that, let's tweak block size to 64 bit. It ripples through UAPI which is an ABI change, but it's not too late to make it, and it will allow supporting >4Gbyte blocks while might become necessary down the road. Fixes: 5f1f79b ("virtio-mem: Paravirtualized memory hotplug") Signed-off-by: Michael S. Tsirkin <[email protected]> Acked-by: David Hildenbrand <[email protected]>
1 parent b3fb6de commit 544fc7d

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

drivers/virtio/virtio_mem.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ struct virtio_mem {
7777
uint64_t requested_size;
7878

7979
/* The device block size (for communicating with the device). */
80-
uint32_t device_block_size;
80+
uint64_t device_block_size;
8181
/* The translated node id. NUMA_NO_NODE in case not specified. */
8282
int nid;
8383
/* Physical start address of the memory region. */
@@ -86,7 +86,7 @@ struct virtio_mem {
8686
uint64_t region_size;
8787

8888
/* The subblock size. */
89-
uint32_t subblock_size;
89+
uint64_t subblock_size;
9090
/* The number of subblocks per memory block. */
9191
uint32_t nb_sb_per_mb;
9292

@@ -1698,9 +1698,9 @@ static int virtio_mem_init(struct virtio_mem *vm)
16981698
* - At least the device block size.
16991699
* In the worst case, a single subblock per memory block.
17001700
*/
1701-
vm->subblock_size = PAGE_SIZE * 1u << max_t(uint32_t, MAX_ORDER - 1,
1702-
pageblock_order);
1703-
vm->subblock_size = max_t(uint32_t, vm->device_block_size,
1701+
vm->subblock_size = PAGE_SIZE * 1ul << max_t(uint32_t, MAX_ORDER - 1,
1702+
pageblock_order);
1703+
vm->subblock_size = max_t(uint64_t, vm->device_block_size,
17041704
vm->subblock_size);
17051705
vm->nb_sb_per_mb = memory_block_size_bytes() / vm->subblock_size;
17061706

@@ -1713,12 +1713,12 @@ static int virtio_mem_init(struct virtio_mem *vm)
17131713

17141714
dev_info(&vm->vdev->dev, "start address: 0x%llx", vm->addr);
17151715
dev_info(&vm->vdev->dev, "region size: 0x%llx", vm->region_size);
1716-
dev_info(&vm->vdev->dev, "device block size: 0x%x",
1717-
vm->device_block_size);
1716+
dev_info(&vm->vdev->dev, "device block size: 0x%llx",
1717+
(unsigned long long)vm->device_block_size);
17181718
dev_info(&vm->vdev->dev, "memory block size: 0x%lx",
17191719
memory_block_size_bytes());
1720-
dev_info(&vm->vdev->dev, "subblock size: 0x%x",
1721-
vm->subblock_size);
1720+
dev_info(&vm->vdev->dev, "subblock size: 0x%llx",
1721+
(unsigned long long)vm->subblock_size);
17221722
if (vm->nid != NUMA_NO_NODE)
17231723
dev_info(&vm->vdev->dev, "nid: %d", vm->nid);
17241724

include/uapi/linux/virtio_mem.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,10 @@ struct virtio_mem_resp {
185185

186186
struct virtio_mem_config {
187187
/* Block size and alignment. Cannot change. */
188-
__u32 block_size;
188+
__u64 block_size;
189189
/* Valid with VIRTIO_MEM_F_ACPI_PXM. Cannot change. */
190190
__u16 node_id;
191-
__u16 padding;
191+
__u8 padding[6];
192192
/* Start address of the memory region. Cannot change. */
193193
__u64 addr;
194194
/* Region size (maximum). Cannot change. */

0 commit comments

Comments
 (0)