qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

qcow2: Don't round the L1 table allocation up to the sector size

The L1 table is read from disk using the byte-based bdrv_pread() and
is never accessed beyond its last element, so there's no need to
allocate more memory than that.

Signed-off-by: Alberto Garcia <berto@igalia.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Message-id: b2e27214ec7b03a585931bcf383ee1ac3a641a10.1579374329.git.berto@igalia.com
Signed-off-by: Max Reitz <mreitz@redhat.com>

authored by

Alberto Garcia and committed by
Max Reitz
ef97d608 ce95a15e

+5 -7
+2 -3
block/qcow2-cluster.c
··· 124 124 #endif 125 125 126 126 new_l1_size2 = sizeof(uint64_t) * new_l1_size; 127 - new_l1_table = qemu_try_blockalign(bs->file->bs, 128 - ROUND_UP(new_l1_size2, 512)); 127 + new_l1_table = qemu_try_blockalign(bs->file->bs, new_l1_size2); 129 128 if (new_l1_table == NULL) { 130 129 return -ENOMEM; 131 130 } 132 - memset(new_l1_table, 0, ROUND_UP(new_l1_size2, 512)); 131 + memset(new_l1_table, 0, new_l1_size2); 133 132 134 133 if (s->l1_size) { 135 134 memcpy(new_l1_table, s->l1_table, s->l1_size * sizeof(uint64_t));
+1 -1
block/qcow2-refcount.c
··· 1262 1262 * l1_table_offset when it is the current s->l1_table_offset! Be careful 1263 1263 * when changing this! */ 1264 1264 if (l1_table_offset != s->l1_table_offset) { 1265 - l1_table = g_try_malloc0(ROUND_UP(l1_size2, 512)); 1265 + l1_table = g_try_malloc0(l1_size2); 1266 1266 if (l1_size2 && l1_table == NULL) { 1267 1267 ret = -ENOMEM; 1268 1268 goto fail;
+1 -2
block/qcow2-snapshot.c
··· 1024 1024 return ret; 1025 1025 } 1026 1026 new_l1_bytes = sn->l1_size * sizeof(uint64_t); 1027 - new_l1_table = qemu_try_blockalign(bs->file->bs, 1028 - ROUND_UP(new_l1_bytes, 512)); 1027 + new_l1_table = qemu_try_blockalign(bs->file->bs, new_l1_bytes); 1029 1028 if (new_l1_table == NULL) { 1030 1029 return -ENOMEM; 1031 1030 }
+1 -1
block/qcow2.c
··· 1491 1491 1492 1492 if (s->l1_size > 0) { 1493 1493 s->l1_table = qemu_try_blockalign(bs->file->bs, 1494 - ROUND_UP(s->l1_size * sizeof(uint64_t), 512)); 1494 + s->l1_size * sizeof(uint64_t)); 1495 1495 if (s->l1_table == NULL) { 1496 1496 error_setg(errp, "Could not allocate L1 table"); 1497 1497 ret = -ENOMEM;