tpm: fix PPI RAM migration
cover tpm: fix PPI RAM migration
Hi,
The following series fixes a migration issue with the TPM PPI code due to unaligned host RAM pointer.
Marc-André Lureau (2):
RFC: savevm: check RAM is page_size aligned
tpm-ppi: page-align PPI RAM
hw/tpm/tpm_ppi.c | 3 ++- migration/savevm.c | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-)
Signature · 1 line
2.24.0.308.g228f53135a
PATCH 1/2 RFC: savevm: check RAM is page_size aligned
Check the host pointer is correctly aligned, otherwise we may fail during migration in ram_block_discard_range().
--- migration/savevm.c | 5 +++++ 1 file changed, 5 insertions(+)
migration/savevm.c +5 -0
@@ -2910,6 +2910,11 @@ err_drain:void vmstate_register_ram (MemoryRegion *mr,DeviceState *dev) { +RAMBlock *rb = mr->ram_block; +uintptr_t hostaddr = (uintptr_t )qemu_ram_get_host_addr (rb); + +assert ((hostaddr & (qemu_ram_pagesize (rb) -1 )) ==0 ); +qemu_ram_set_idstr (mr->ram_block,memory_region_name (mr), dev);qemu_ram_set_migratable (mr->ram_block);
Signature · 1 line
2.24.0.308.g228f53135a
Re: [PATCH 1/2] RFC: savevm: check RAM is page_size aligned
Hi Marc-André,
Quoted 13 lines · Marc-André Lureau
Check the host pointer is correctly aligned, otherwise we may fail during migration in
ram_block_discard_range().Signed-off-by Marc-André Lureau <[email protected]>--- migration/savevm.c | 5 +++++ 1 file changed, 5 insertions(+)migration/savevm.c +0
-0
migration/savevm.c err_drain: · line 2916
Quoted 7 lines
migration/savevm.c +4
-0@@ -2910,6 +2910,11 @@ err_drain:void vmstate_register_ram (MemoryRegion *mr,DeviceState *dev) { +RAMBlock *rb = mr->ram_block; +uintptr_t hostaddr = (uintptr_t )qemu_ram_get_host_addr (rb); + +assert ((hostaddr & (qemu_ram_pagesize (rb) -1 )) ==0 );
Can we use the QEMU_PTR_IS_ALIGNED() macro instead?
assert(QEMU_PTR_IS_ALIGNED(qemu_ram_get_host_addr(rb),
qemu_ram_pagesize(rb)));Quoted 4 lines
migration/savevm.c +0
-0qemu_ram_set_idstr (mr->ram_block,memory_region_name (mr), dev);qemu_ram_set_migratable (mr->ram_block);
Re: [PATCH 1/2] RFC: savevm: check RAM is page_size aligned
Hi
Quoted 27 lines · Philippe Mathieu-Daudé
Hi Marc-André,
Quoted 13 lines · Marc-André Lureau
Check the host pointer is correctly aligned, otherwise we may fail during migration in
ram_block_discard_range().Signed-off-by Marc-André Lureau <[email protected]>--- migration/savevm.c | 5 +++++ 1 file changed, 5 insertions(+)migration/savevm.c +0
-0migration/savevm.c err_drain: · line 2916
Quoted 7 lines
migration/savevm.c +4
-0@@ -2910,6 +2910,11 @@ err_drain:void vmstate_register_ram (MemoryRegion *mr,DeviceState *dev) { +RAMBlock *rb = mr->ram_block; +uintptr_t hostaddr = (uintptr_t )qemu_ram_get_host_addr (rb); + +assert ((hostaddr & (qemu_ram_pagesize (rb) -1 )) ==0 );Can we use the
QEMU_PTR_IS_ALIGNED()macro instead?
Quoted 3 lines
assert(QEMU_PTR_IS_ALIGNED(qemu_ram_get_host_addr(rb),
qemu_ram_pagesize(rb)));nice, good idea
Quoted 5 lines
Quoted 4 lines
migration/savevm.c +0
-0qemu_ram_set_idstr (mr->ram_block,memory_region_name (mr), dev);qemu_ram_set_migratable (mr->ram_block);
PATCH 2/2 tpm-ppi: page-align PPI RAM
In reply to Marc-André Lureaupost-copy migration fails on destination with error such as:
2019-12-26T10:22:44.714644Z qemu-kvm: ram_block_discard_range:
Unaligned start address: 0x559d2afae9a0
Use qemu_memalign() to constrain the PPI RAM memory alignment.
--- hw/tpm/tpm_ppi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
hw/tpm/tpm_ppi.c +2 -1
@@ -43,7 +43,8 @@ void tpm_ppi_reset(TPMPPI *tpmppi)void tpm_ppi_init (TPMPPI *tpmppi,struct MemoryRegion *m,hwaddr addr,Object *obj) { - tpmppi->buf =g_malloc0 (HOST_PAGE_ALIGN (TPM_PPI_ADDR_SIZE )); + tpmppi->buf =qemu_memalign (qemu_real_host_page_size, +HOST_PAGE_ALIGN (TPM_PPI_ADDR_SIZE ));memory_region_init_ram_device_ptr (&tpmppi->ram, obj,"tpm-ppi" ,TPM_PPI_ADDR_SIZE , tpmppi->buf);vmstate_register_ram (&tpmppi->ram,DEVICE (obj));
Signature · 1 line
2.24.0.308.g228f53135a
Re: [PATCH 2/2] tpm-ppi: page-align PPI RAM
Quoted 8 lines · Marc-André Lureau
post-copy migration fails on destination with error such as:
2019-12-26T10:22:44.714644Z qemu-kvm: ram_block_discard_range:Unaligned start address:
0x559d2afae9a0Use
qemu_memalign()to constrain the PPI RAM memory alignment.Signed-off-by Marc-André Lureau <[email protected]>
Quoted 19 lines
--- hw/tpm/tpm_ppi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)hw/tpm/tpm_ppi.c +2
-1@@ -43,7 +43,8 @@ void tpm_ppi_reset(TPMPPI *tpmppi)void tpm_ppi_init (TPMPPI *tpmppi,struct MemoryRegion *m,hwaddr addr,Object *obj) { - tpmppi->buf =g_malloc0 (HOST_PAGE_ALIGN (TPM_PPI_ADDR_SIZE )); + tpmppi->buf =qemu_memalign (qemu_real_host_page_size, +HOST_PAGE_ALIGN (TPM_PPI_ADDR_SIZE ));memory_region_init_ram_device_ptr (&tpmppi->ram, obj,"tpm-ppi" ,TPM_PPI_ADDR_SIZE , tpmppi->buf);vmstate_register_ram (&tpmppi->ram,DEVICE (obj));