intel_iommu: fix migration breakage on mr switch
PATCH 1/1 intel_iommu: fix migration breakage on mr switch
Migration is broken after the vfio integration work:
qemu-kvm: AHCI: Failed to start FIS receive engine: bad FIS receive buffer address
qemu-kvm: Failed to load ich9_ahci:ahci
qemu-kvm: error while loading state for instance 0x0 of device '0000:00:1f.2/ich9_ahci'
qemu-kvm: load of migration failed: Operation not permitted
The problem is that vfio work introduced dynamic memory region switching (actually it is also used for future PT mode), and this memory region layout is not properly delivered to destination when migration happens. Solution is to rebuild the layout in post_load.
--- hw/i386/intel_iommu.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
hw/i386/intel_iommu.c +17 -0
@@ -2332,11 +2332,28 @@ static void vtd_iommu_notify_flag_changed(MemoryRegion *iommu, } } +static int vtd_post_load (void *opaque,int version_id) +{ +IntelIOMMUState *iommu = opaque; + +/* +* Since commit 558e00 ("intel_iommu: allow dynamic switch of +* IOMMU region"), memory regions are dynamically turned on/off +* depending on context entry configurations from the guest. After +* migration, we need to make sure the memory regions are still +* correct. +*/ +vtd_switch_address_space_all (iommu); + +return 0 ; +} +static const VMStateDescription vtd_vmstate = { .name ="iommu-intel" , .version_id =1 , .minimum_version_id =1 , .priority =MIG_PRI_IOMMU , + .post_load = vtd_post_load, .fields = (VMStateField []) {VMSTATE_UINT64 (root, IntelIOMMUState),VMSTATE_UINT64 (intr_root, IntelIOMMUState),
Signature · 1 line
2.7.4
Quoted 24 lines · Peter Xu
Migration is broken after the vfio integration work:
qemu-kvm: AHCI: Failed to start FIS receive engine: bad FIS receive buffer address
qemu-kvm: Failed to load ich9_ahci:ahci
qemu-kvm: error while loading state for instance0x0of device '0000:00:1f.2/ich9_ahci'
qemu-kvm: load of migration failed: Operation not permittedThe problem is that vfio work introduced dynamic memory region switching (actually it is also used for future PT mode), and this memory region layout is not properly delivered to destination when migration happens. Solution is to rebuild the layout in
post_load.Fixes 558e0024 ("intel_iommu: allow dynamic switch of IOMMU region")Signed-off-by Peter Xu <[email protected]>--- hw/i386/intel_iommu.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)hw/i386/intel_iommu.c +0
-0
hw/i386/intel_iommu.c static void vtd_iommu_notify_flag_changed(MemoryRegion *iommu, · line 2341
Quoted 10 lines
hw/i386/intel_iommu.c +7
-0@@ -2332,11 +2332,28 @@ static void vtd_iommu_notify_flag_changed(MemoryRegion *iommu, } } +static int vtd_post_load (void *opaque,int version_id) +{ +IntelIOMMUState *iommu = opaque; + +/* +* Since commit 558e00 ("intel_iommu: allow dynamic switch of +* IOMMU region"),
I would drop this part of the comment. It isn't of interest to people reading code directly, while people reading git history see the commit log.
Quoted 21 lines
memory regions are dynamically turned on/off
hw/i386/intel_iommu.c +10
-0+* depending on context entry configurations from the guest. After +* migration, we need to make sure the memory regions are still +* correct. +*/ +vtd_switch_address_space_all (iommu); + +return 0 ; +} +static const VMStateDescription vtd_vmstate = { .name ="iommu-intel" , .version_id =1 , .minimum_version_id =1 , .priority =MIG_PRI_IOMMU , + .post_load = vtd_post_load, .fields = (VMStateField []) {VMSTATE_UINT64 (root, IntelIOMMUState),VMSTATE_UINT64 (intr_root, IntelIOMMUState),Signature · 1 line
2.7.4
Quoted 28 lines · Michael S. Tsirkin
Quoted 27 lines · Peter Xu
Migration is broken after the vfio integration work:
qemu-kvm: AHCI: Failed to start FIS receive engine: bad FIS receive buffer address
qemu-kvm: Failed to load ich9_ahci:ahci
qemu-kvm: error while loading state for instance0x0of device '0000:00:1f.2/ich9_ahci'
qemu-kvm: load of migration failed: Operation not permittedThe problem is that vfio work introduced dynamic memory region switching (actually it is also used for future PT mode), and this memory region layout is not properly delivered to destination when migration happens. Solution is to rebuild the layout in
post_load.Fixes 558e0024 ("intel_iommu: allow dynamic switch of IOMMU region")Signed-off-by Peter Xu <[email protected]>--- hw/i386/intel_iommu.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)hw/i386/intel_iommu.c +0
-0@@ -2332,11 +2332,28 @@ static void vtd_iommu_notify_flag_changed(MemoryRegion *iommu, } }
Quoted 11 lines
hw/i386/intel_iommu.c static void vtd_iommu_notify_flag_changed(MemoryRegion *iommu,
Quoted 7 lines
hw/i386/intel_iommu.c +7
-0+static int vtd_post_load (void *opaque,int version_id) +{ +IntelIOMMUState *iommu = opaque; + +/* +* Since commit 558e00 ("intel_iommu: allow dynamic switch of +* IOMMU region"), I would drop this part of the comment. It isn't of interest to people reading code directly, while people reading git history see the commit log.
Ok. Will resend. Thanks.
Signature · 1 line
Peter Xu
Quoted 42 lines · Peter Xu
Migration is broken after the vfio integration work:
qemu-kvm: AHCI: Failed to start FIS receive engine: bad FIS receive buffer address
qemu-kvm: Failed to load ich9_ahci:ahci
qemu-kvm: error while loading state for instance0x0of device '0000:00:1f.2/ich9_ahci'
qemu-kvm: load of migration failed: Operation not permittedThe problem is that vfio work introduced dynamic memory region switching (actually it is also used for future PT mode), and this memory region layout is not properly delivered to destination when migration happens. Solution is to rebuild the layout in
post_load.Fixes 558e0024 ("intel_iommu: allow dynamic switch of IOMMU region")Signed-off-by Peter Xu <[email protected]>--- hw/i386/intel_iommu.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)hw/i386/intel_iommu.c +15
-0@@ -2332,11 +2332,28 @@ static void vtd_iommu_notify_flag_changed(MemoryRegion *iommu, } } +static int vtd_post_load (void *opaque,int version_id) +{ +IntelIOMMUState *iommu = opaque; + +/* +* Since commit 558e00 ("intel_iommu: allow dynamic switch of +* IOMMU region"), memory regions are dynamically turned on/off +* depending on context entry configurations from the guest. After +* migration, we need to make sure the memory regions are still +* correct. +*/ +vtd_switch_address_space_all (iommu); + +return 0 ; +}
hw/i386/intel_iommu.c static void vtd_iommu_notify_flag_changed(MemoryRegion *iommu, · line 2359
Quoted 10 lines
hw/i386/intel_iommu.c +2
-0+static const VMStateDescription vtd_vmstate = { .name ="iommu-intel" , .version_id =1 , .minimum_version_id =1 , .priority =MIG_PRI_IOMMU , + .post_load = vtd_post_load, .fields = (VMStateField []) {VMSTATE_UINT64 (root, IntelIOMMUState),VMSTATE_UINT64 (intr_root, IntelIOMMUState),