summaryrefslogtreecommitdiffstats
path: root/drivers/virtio
diff options
context:
space:
mode:
authorMichael S. Tsirkin <mst@redhat.com>2020-06-08 02:03:15 -0400
committerMichael S. Tsirkin <mst@redhat.com>2020-06-09 06:42:06 -0400
commit544fc7dbbf920a3e64d109c416ee229e8e1763c5 (patch)
tree245dfdd4f99b721b1c4a28a7ac82394dd4f801bf /drivers/virtio
parentb3fb6de7c6019c5d8495c3a115d42a0f118f631c (diff)
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: 5f1f79bbc9e26 ("virtio-mem: Paravirtualized memory hotplug") Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Acked-by: David Hildenbrand <david@redhat.com>
Diffstat (limited to 'drivers/virtio')
-rw-r--r--drivers/virtio/virtio_mem.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c
index 2f357142ea5e..50c689f25045 100644
--- a/drivers/virtio/virtio_mem.c
+++ b/drivers/virtio/virtio_mem.c
@@ -77,7 +77,7 @@ struct virtio_mem {
uint64_t requested_size;
/* The device block size (for communicating with the device). */
- uint32_t device_block_size;
+ uint64_t device_block_size;
/* The translated node id. NUMA_NO_NODE in case not specified. */
int nid;
/* Physical start address of the memory region. */
@@ -86,7 +86,7 @@ struct virtio_mem {
uint64_t region_size;
/* The subblock size. */
- uint32_t subblock_size;
+ uint64_t subblock_size;
/* The number of subblocks per memory block. */
uint32_t nb_sb_per_mb;
@@ -1698,9 +1698,9 @@ static int virtio_mem_init(struct virtio_mem *vm)
* - At least the device block size.
* In the worst case, a single subblock per memory block.
*/
- vm->subblock_size = PAGE_SIZE * 1u << max_t(uint32_t, MAX_ORDER - 1,
- pageblock_order);
- vm->subblock_size = max_t(uint32_t, vm->device_block_size,
+ vm->subblock_size = PAGE_SIZE * 1ul << max_t(uint32_t, MAX_ORDER - 1,
+ pageblock_order);
+ vm->subblock_size = max_t(uint64_t, vm->device_block_size,
vm->subblock_size);
vm->nb_sb_per_mb = memory_block_size_bytes() / vm->subblock_size;
@@ -1713,12 +1713,12 @@ static int virtio_mem_init(struct virtio_mem *vm)
dev_info(&vm->vdev->dev, "start address: 0x%llx", vm->addr);
dev_info(&vm->vdev->dev, "region size: 0x%llx", vm->region_size);
- dev_info(&vm->vdev->dev, "device block size: 0x%x",
- vm->device_block_size);
+ dev_info(&vm->vdev->dev, "device block size: 0x%llx",
+ (unsigned long long)vm->device_block_size);
dev_info(&vm->vdev->dev, "memory block size: 0x%lx",
memory_block_size_bytes());
- dev_info(&vm->vdev->dev, "subblock size: 0x%x",
- vm->subblock_size);
+ dev_info(&vm->vdev->dev, "subblock size: 0x%llx",
+ (unsigned long long)vm->subblock_size);
if (vm->nid != NUMA_NO_NODE)
dev_info(&vm->vdev->dev, "nid: %d", vm->nid);