hw/tpm: fix tpm-tis-device backward migration on aarch64
cover hw/tpm: fix tpm-tis-device backward migration on aarch64
46cd2c1050f0 ("hw/tpm: add PPI support to tpm-tis-device for ARM64 virt") unconditionally registers a "tpm-ppi" RAMBlock when the TPM TIS sysbus device is realized. This breaks backward migration: a QEMU with PPI support cannot migrate to an older QEMU without it:
Unknown ramblock "tpm-ppi", cannot accept migration
The failure is 100% reproducible on any aarch64 guest that uses tpm-tis-device when migrating to a host whose QEMU predates the PPI commit.
Fix by gating the PPI memory region behind a new "ppi" device property, and disabling it via hw_compat_11_0[] for machine types <= virt-11.0.
Mohammadfaiz Bawa (2):
hw/tpm: gate PPI support on tpm-tis-device behind a device property hw/core/machine: disable tpm-tis-device PPI for machine type <= 11.0
hw/core/machine.c | 1 + hw/tpm/tpm_tis.h | 1 + hw/tpm/tpm_tis_sysbus.c | 16 +++++++++++----- 3 files changed, 13 insertions(+), 5 deletions(-)
Signature · 1 line
2.54.0
PATCH 1/2 hw/tpm: gate PPI support on tpm-tis-device behind a device property
Add a "ppi" boolean property (default: true) to tpm-tis-device. When ppi=off the RAMBlock is never registered and the migration stream omits "tpm-ppi", restoring backward compatibility.
When disabled, realizefn initializes the region with zero size so the platform bus skips it and ACPI PPI tables are omitted.
--- hw/tpm/tpm_tis.h | 1 + hw/tpm/tpm_tis_sysbus.c | 16 +++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-)
hw/tpm/tpm_tis.h +1 -0
@@ -76,6 +76,7 @@ typedef struct TPMState {size_t be_buffer_size;TPMPPI ppi; +bool ppi_enabled; } TPMState;extern const VMStateDescription vmstate_locty;
hw/tpm/tpm_tis_sysbus.c +11 -5
@@ -94,6 +94,7 @@ static void tpm_tis_sysbus_reset(DeviceState *dev)static const Property tpm_tis_sysbus_properties[] = {DEFINE_PROP_UINT32 ("irq" , TPMStateSysBus, state.irq_num,TPM_TIS_IRQ ),DEFINE_PROP_TPMBE ("tpmdev" , TPMStateSysBus, state.be_driver), +DEFINE_PROP_BOOL ("ppi" , TPMStateSysBus, state.ppi_enabled, true), };static void tpm_tis_sysbus_initfn (Object *obj)
@@ -122,14 +123,19 @@ static void tpm_tis_sysbus_realizefn(DeviceState *dev, Error **errp)return ; } - s->ppi.buf =qemu_memalign (host_page_size, -ROUND_UP (TPM_PPI_ADDR_SIZE , host_page_size));memory_region_init_io (&s->mmio,OBJECT (dev), &tpm_tis_memory_ops, s,"tpm-tis-mmio" ,TPM_TIS_NUM_LOCALITIES <<TPM_TIS_LOCALITY_SHIFT ); -memory_region_init_ram_device_ptr (&s->ppi.ram,OBJECT (dev),"tpm-ppi" , -TPM_PPI_ADDR_SIZE , s->ppi.buf); -vmstate_register_ram (&s->ppi.ram, dev); + +if (s->ppi_enabled) { + s->ppi.buf =qemu_memalign (host_page_size, +ROUND_UP (TPM_PPI_ADDR_SIZE , host_page_size)); +memory_region_init_ram_device_ptr (&s->ppi.ram,OBJECT (dev),"tpm-ppi" , +TPM_PPI_ADDR_SIZE , s->ppi.buf); +vmstate_register_ram (&s->ppi.ram, dev); + }else { +memory_region_init (&s->ppi.ram,OBJECT (dev),"tpm-ppi" ,0 ); + } }static void tpm_tis_sysbus_class_init (ObjectClass *klass,const void *data)
Signature · 1 line
2.54.0
Re: [PATCH 1/2] hw/tpm: gate PPI support on tpm-tis-device behind a device property
Quoted 51 lines · Mohammadfaiz Bawa
Add a "ppi" boolean property (default: true) to tpm-tis-device. When ppi=off the RAMBlock is never registered and the migration stream omits "tpm-ppi", restoring backward compatibility.
When disabled, realizefn initializes the region with zero size so the platform bus skips it and ACPI PPI tables are omitted.
Fixes 46cd2c1050f0 ("hw/tpm: add PPI support to tpm-tis-device for ARM64 virt")Signed-off-by Mohammadfaiz Bawa <[email protected]>--- hw/tpm/tpm_tis.h | 1 + hw/tpm/tpm_tis_sysbus.c | 16 +++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-)hw/tpm/tpm_tis.h +1
-0@@ -76,6 +76,7 @@ typedef struct TPMState {size_t be_buffer_size;TPMPPI ppi; +bool ppi_enabled; } TPMState;extern const VMStateDescription vmstate_locty;hw/tpm/tpm_tis_sysbus.c +1
-5@@ -94,6 +94,7 @@ static void tpm_tis_sysbus_reset(DeviceState *dev)static const Property tpm_tis_sysbus_properties[] = {DEFINE_PROP_UINT32 ("irq" , TPMStateSysBus, state.irq_num,TPM_TIS_IRQ ),DEFINE_PROP_TPMBE ("tpmdev" , TPMStateSysBus, state.be_driver), +DEFINE_PROP_BOOL ("ppi" , TPMStateSysBus, state.ppi_enabled, true), };static void tpm_tis_sysbus_initfn (Object *obj)@@ -122,14 +123,19 @@ static void tpm_tis_sysbus_realizefn(DeviceState *dev, Error **errp)return ; } - s->ppi.buf =qemu_memalign (host_page_size, -ROUND_UP (TPM_PPI_ADDR_SIZE , host_page_size));memory_region_init_io (&s->mmio,OBJECT (dev), &tpm_tis_memory_ops, s,"tpm-tis-mmio" ,TPM_TIS_NUM_LOCALITIES <<TPM_TIS_LOCALITY_SHIFT ); -memory_region_init_ram_device_ptr (&s->ppi.ram,OBJECT (dev),"tpm-ppi" , -TPM_PPI_ADDR_SIZE , s->ppi.buf); -vmstate_register_ram (&s->ppi.ram, dev);
hw/tpm/tpm_tis_sysbus.c static void tpm_tis_sysbus_realizefn(DeviceState *dev, Error **errp) · line 138
Quoted 10 lines
hw/tpm/tpm_tis_sysbus.c +10
-0+ +if (s->ppi_enabled) { + s->ppi.buf =qemu_memalign (host_page_size, +ROUND_UP (TPM_PPI_ADDR_SIZE , host_page_size)); +memory_region_init_ram_device_ptr (&s->ppi.ram,OBJECT (dev),"tpm-ppi" , +TPM_PPI_ADDR_SIZE , s->ppi.buf); +vmstate_register_ram (&s->ppi.ram, dev); + }else { +memory_region_init (&s->ppi.ram,OBJECT (dev),"tpm-ppi" ,0 ); + }
Is it valid to create a 0-size memory region? I think the more usual approach here would be to not expose the 2nd MMIO region if the device was configured with PPI disabled.
This device also very weirdly calls sysbus_init_mmio() in its initfn, before it has actually set up the MR, which it is doing here in realize. I think that also needs to be fixed (especially since the property will only be available in realize). It happens to work since all sysbus_init_mmio() is doing is putting the pointer into its data structure, but it doesn't make much logical sense to do it that way around.
thanks
-- PMM
Re: [PATCH 1/2] hw/tpm: gate PPI support on tpm-tis-device behind a device property
Quoted 76 lines · Peter Maydell
Quoted 51 lines · Mohammadfaiz Bawa
Add a "ppi" boolean property (default: true) to tpm-tis-device. When ppi=off the RAMBlock is never registered and the migration stream omits "tpm-ppi", restoring backward compatibility.
When disabled, realizefn initializes the region with zero size so the platform bus skips it and ACPI PPI tables are omitted.
Fixes 46cd2c1050f0 ("hw/tpm: add PPI support to tpm-tis-device for ARM64 virt")Signed-off-by Mohammadfaiz Bawa <[email protected]>--- hw/tpm/tpm_tis.h | 1 + hw/tpm/tpm_tis_sysbus.c | 16 +++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-)hw/tpm/tpm_tis.h +1
-0@@ -76,6 +76,7 @@ typedef struct TPMState {size_t be_buffer_size;TPMPPI ppi; +bool ppi_enabled; } TPMState;extern const VMStateDescription vmstate_locty;hw/tpm/tpm_tis_sysbus.c +1
-5@@ -94,6 +94,7 @@ static void tpm_tis_sysbus_reset(DeviceState *dev)static const Property tpm_tis_sysbus_properties[] = {DEFINE_PROP_UINT32 ("irq" , TPMStateSysBus, state.irq_num,TPM_TIS_IRQ ),DEFINE_PROP_TPMBE ("tpmdev" , TPMStateSysBus, state.be_driver), +DEFINE_PROP_BOOL ("ppi" , TPMStateSysBus, state.ppi_enabled, true), };static void tpm_tis_sysbus_initfn (Object *obj)@@ -122,14 +123,19 @@ static void tpm_tis_sysbus_realizefn(DeviceState *dev, Error **errp)return ; } - s->ppi.buf =qemu_memalign (host_page_size, -ROUND_UP (TPM_PPI_ADDR_SIZE , host_page_size));memory_region_init_io (&s->mmio,OBJECT (dev), &tpm_tis_memory_ops, s,"tpm-tis-mmio" ,TPM_TIS_NUM_LOCALITIES <<TPM_TIS_LOCALITY_SHIFT ); -memory_region_init_ram_device_ptr (&s->ppi.ram,OBJECT (dev),"tpm-ppi" , -TPM_PPI_ADDR_SIZE , s->ppi.buf); -vmstate_register_ram (&s->ppi.ram, dev);hw/tpm/tpm_tis_sysbus.c static void tpm_tis_sysbus_realizefn(DeviceState *dev, Error **errp) · line 138
Quoted 10 lines
hw/tpm/tpm_tis_sysbus.c +10
-0+ +if (s->ppi_enabled) { + s->ppi.buf =qemu_memalign (host_page_size, +ROUND_UP (TPM_PPI_ADDR_SIZE , host_page_size)); +memory_region_init_ram_device_ptr (&s->ppi.ram,OBJECT (dev),"tpm-ppi" , +TPM_PPI_ADDR_SIZE , s->ppi.buf); +vmstate_register_ram (&s->ppi.ram, dev); + }else { +memory_region_init (&s->ppi.ram,OBJECT (dev),"tpm-ppi" ,0 ); + }Is it valid to create a 0-size memory region? I think the more usual approach here would be to not expose the 2nd MMIO region if the device was configured with PPI disabled.
This device also very weirdly calls
sysbus_init_mmio()in its initfn, before it has actually set up the MR, which it is doing here in realize. I think that also needs to be fixed (especially since the property will only be available in realize). It happens to work since allsysbus_init_mmio()is doing is putting the pointer into its data structure, but it doesn't make much logical sense to do it that way around.
Quoted 3 lines
thanks
-- PMM
Agreed. I initially considered not exposing the 2nd MMIO region at all when PPI is disabled, but I followed the existing pattern in initfn. You're right that it's cleaner to just not register it.
I'll move both sysbus_init_mmio() calls to realizefn so the MR are properly initialized before being registered, and only expose the PPI region when ppi=on.
Is it fine to include this refactoring (moving sysbus_init_mmio() to realizefn) in this same series, or would it be preferable as a separate patch?
Will send a v2.
Thanks,
Faiz
Re: [PATCH 1/2] hw/tpm: gate PPI support on tpm-tis-device behind a device property
Quoted 82 lines · Mohammadfaiz Bawa
Quoted 68 lines · Peter Maydell
Quoted 51 lines · Mohammadfaiz Bawa
Add a "ppi" boolean property (default: true) to tpm-tis-device. When ppi=off the RAMBlock is never registered and the migration stream omits "tpm-ppi", restoring backward compatibility.
When disabled, realizefn initializes the region with zero size so the platform bus skips it and ACPI PPI tables are omitted.
Fixes 46cd2c1050f0 ("hw/tpm: add PPI support to tpm-tis-device for ARM64 virt")Signed-off-by Mohammadfaiz Bawa <[email protected]>--- hw/tpm/tpm_tis.h | 1 + hw/tpm/tpm_tis_sysbus.c | 16 +++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-)hw/tpm/tpm_tis.h +1
-0@@ -76,6 +76,7 @@ typedef struct TPMState {size_t be_buffer_size;TPMPPI ppi; +bool ppi_enabled; } TPMState;extern const VMStateDescription vmstate_locty;hw/tpm/tpm_tis_sysbus.c +1
-5@@ -94,6 +94,7 @@ static void tpm_tis_sysbus_reset(DeviceState *dev)static const Property tpm_tis_sysbus_properties[] = {DEFINE_PROP_UINT32 ("irq" , TPMStateSysBus, state.irq_num,TPM_TIS_IRQ ),DEFINE_PROP_TPMBE ("tpmdev" , TPMStateSysBus, state.be_driver), +DEFINE_PROP_BOOL ("ppi" , TPMStateSysBus, state.ppi_enabled, true), };static void tpm_tis_sysbus_initfn (Object *obj)@@ -122,14 +123,19 @@ static void tpm_tis_sysbus_realizefn(DeviceState *dev, Error **errp)return ; } - s->ppi.buf =qemu_memalign (host_page_size, -ROUND_UP (TPM_PPI_ADDR_SIZE , host_page_size));memory_region_init_io (&s->mmio,OBJECT (dev), &tpm_tis_memory_ops, s,"tpm-tis-mmio" ,TPM_TIS_NUM_LOCALITIES <<TPM_TIS_LOCALITY_SHIFT ); -memory_region_init_ram_device_ptr (&s->ppi.ram,OBJECT (dev),"tpm-ppi" , -TPM_PPI_ADDR_SIZE , s->ppi.buf); -vmstate_register_ram (&s->ppi.ram, dev);hw/tpm/tpm_tis_sysbus.c static void tpm_tis_sysbus_realizefn(DeviceState *dev, Error **errp) · line 138
Quoted 10 lines
hw/tpm/tpm_tis_sysbus.c +10
-0+ +if (s->ppi_enabled) { + s->ppi.buf =qemu_memalign (host_page_size, +ROUND_UP (TPM_PPI_ADDR_SIZE , host_page_size)); +memory_region_init_ram_device_ptr (&s->ppi.ram,OBJECT (dev),"tpm-ppi" , +TPM_PPI_ADDR_SIZE , s->ppi.buf); +vmstate_register_ram (&s->ppi.ram, dev); + }else { +memory_region_init (&s->ppi.ram,OBJECT (dev),"tpm-ppi" ,0 ); + }Is it valid to create a 0-size memory region? I think the more usual approach here would be to not expose the 2nd MMIO region if the device was configured with PPI disabled.
Quoted 7 lines
This device also very weirdly calls
sysbus_init_mmio()in its initfn, before it has actually set up the MR, which it is doing here in realize. I think that also needs to be fixed (especially since the property will only be available in realize). It happens to work since allsysbus_init_mmio()is doing is putting the pointer into its data structure, but it doesn't make much logical sense to do it that way around.Agreed. I initially considered not exposing the 2nd MMIO region at all when PPI is disabled, but I followed the existing pattern in initfn. You're right that it's cleaner to just not register it.
Quoted 6 lines
I'll move both
sysbus_init_mmio()calls to realizefn so the MR are properly initialized before being registered, and only expose the PPI region when ppi=on.Is it fine to include this refactoring (moving
sysbus_init_mmio()to realizefn) in this same series, or would it be preferable as a separate patch?
Either is OK, I think -- it's only moving two lines of code.
-- PMM
PATCH 2/2 hw/core/machine: disable tpm-tis-device PPI for machine type <= 11.0
In reply to Mohammadfaiz BawaSet ppi=off in hw_compat_11_0[] so that older machine types do not register the "tpm-ppi" RAMBlock, restoring backward migration.
--- hw/core/machine.c | 1 + 1 file changed, 1 insertion(+)
hw/core/machine.c +1 -0
@@ -44,6 +44,7 @@ GlobalProperty hw_compat_11_0[] = { { "chardev-vc", "encoding", "cp437" }, { "tpm-crb", "cap-chunk", "off" }, { "tpm-crb", "x-allow-chunk-migration", "off" }, + { "tpm-tis-device", "ppi", "off" }, { TYPE_ARM_SMMUV3, "ats", "off" }, { TYPE_ARM_SMMUV3, "ril", "on" }, { TYPE_ARM_SMMUV3, "ssidsize", "0" },
Signature · 1 line
2.54.0