hw/arm/smmuv3: Live migration for accel=on
cover hw/arm/smmuv3: Live migration for accel=on
Hi,
This series adds live migration support for an accelerated SMMUv3 (-device arm-smmuv3,accel=on) with vfio-pci endpoints on the iommufd backend.
The destination replays rather than receives. The stream table, the STEs, the CDs and the Stage 1 page tables all live in guest RAM, so once that and the registers are restored, the destination walks the stream table again and rebuilds the vDEVICE and the nested HWPT for every device.
What the series does:
- drains the kernel vEVENTQ into the guest event queue when the VM stops, so that pending fault events are not lost (1, 2)
- migrates the resolved SMMUv3 feature set in a new smmuv3/accel subsection and fails the load if the two ends differ (3)
- replays the guest stream table on the destination and restores the vEVENTQ and the GBPA HWPT (4, 5)
- asks VFIO for dirty tracking on the Stage 2 nesting parent (6)
- replaces the accel migration blocker with one scoped to CMDQV, which cannot be migrated for now (7)
This depends on the host kernel supporting dirty tracking on the Stage 2 nesting parent, for assigned devices that cannot track dirty pages themselves. A branch based on Jason's iommu page table work is here [0].
Big caveat:
This is not yet tested with a real device that supports migration as I do not have a test setup for that. Folks who do have such a setup have reached out and are copied here, so hopefully this RFC lets them give it a spin and provide some early feedback.
QEMU branch is here:
https://github.com/shamiali2008/qemu-master/tree/smmuv3-accel-live-migrn-rfcv1
Please let me know your feedback.
Thanks,
Shameer
[0]: https://github.com/shamiali2008/linux/commits/iommu_pt_arm64_s2_dbm/
Shameer Kolothum (7):
hw/arm/smmuv3-accel: Factor out the single vEVENT read hw/arm/smmuv3-accel: Drain the vEVENTQ when the VM stops hw/arm/smmuv3: Migrate the accelerator feature set hw/arm/smmuv3-accel: Add a helper to replay all STEs hw/arm/smmuv3-accel: Restore accelerator state on incoming migration hw/arm/smmuv3-accel: Request dirty tracking on the nesting parent hw/arm/smmuv3: Support migration with accel=on
hw/arm/smmuv3-accel.h | 2 + include/hw/arm/smmuv3.h | 7 +- hw/arm/smmuv3-accel-stubs.c | 17 ++++ hw/arm/smmuv3-accel.c | 192 ++++++++++++++++++++++++++++++++++-- hw/arm/smmuv3.c | 6 +- 5 files changed, 210 insertions(+), 14 deletions(-)
Signature · 1 line
2.43.0
RFC PATCH 1/7 hw/arm/smmuv3-accel: Factor out the single vEVENT read
Move the body of smmuv3_accel_event_read() into a new helper, smmuv3_accel_event_read_one(), that reads one vEVENT and tells the caller whether it propagated an event, found the queue empty, or failed.
Subsequent patch will make use of the helper to drain the queue.
No functional change intended.
--- hw/arm/smmuv3-accel.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-)
hw/arm/smmuv3-accel.c +20 -10
@@ -484,28 +484,38 @@ int smmuv3_accel_event_read_validate(IOMMUFDVeventq *veventq, uint32_t type,return 0 ; } -static void smmuv3_accel_event_read (void *opaque) +/* +* Read one pending vEVENT and propagate it to the guest event queue. +* Returns 0 if an event was propagated, 1 if the queue is drained, -1 on +* error with @errp set. +*/ +static int smmuv3_accel_event_read_one (SMMUv3State *s,Error **errp) { -SMMUv3State *s = opaque;IOMMUFDVeventq *veventq = s->s_accel->veventq;struct {struct iommufd_vevent_header hdr;struct iommu_vevent_arm_smmuv3 vevent; } buf; -Error *local_err =NULL ;int ret; ret =smmuv3_accel_event_read_validate (veventq,IOMMU_VEVENTQ_TYPE_ARM_SMMUV3 , &buf, -sizeof (buf), &local_err); -if (ret <0 ) { -warn_report_err_once (local_err); -return ; - } -if (ret >0 ) { -return ;/* EAGAIN/EINTR */ +sizeof (buf), errp); +if (ret) { +return ret; }smmuv3_propagate_event (s, (Evt *)&buf.vevent); +return 0 ; +} + +static void smmuv3_accel_event_read (void *opaque) +{ +SMMUv3State *s = opaque; +Error *local_err =NULL ; + +if (smmuv3_accel_event_read_one (s, &local_err) <0 ) { +warn_report_err_once (local_err); + } }static void smmuv3_accel_free_veventq (SMMUv3AccelState *accel)
Signature · 1 line
2.43.0
Re: [RFC PATCH 1/7] hw/arm/smmuv3-accel: Factor out the single vEVENT read
Hi Shameer,
Quoted 3 lines · Shameer Kolothum
Move the body of
smmuv3_accel_event_read()into a new helper,smmuv3_accel_event_read_one(), that reads one vEVENT and tells the caller whether it propagated an event, found the queue empty, or failed.
it is not totally obvious that "queue empty" reason matches EAGAIN/EINTR.
Quoted 53 lines
Subsequent patch will make use of the helper to drain the queue.
No functional change intended.
Signed-off-by Shameer Kolothum <[email protected]>--- hw/arm/smmuv3-accel.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-)hw/arm/smmuv3-accel.c +13
-10@@ -484,28 +484,38 @@ int smmuv3_accel_event_read_validate(IOMMUFDVeventq *veventq, uint32_t type,return 0 ; } -static void smmuv3_accel_event_read (void *opaque) +/* +* Read one pending vEVENT and propagate it to the guest event queue. +* Returns 0 if an event was propagated, 1 if the queue is drained, -1 on +* error with @errp set. +*/ +static int smmuv3_accel_event_read_one (SMMUv3State *s,Error **errp) { -SMMUv3State *s = opaque;IOMMUFDVeventq *veventq = s->s_accel->veventq;struct {struct iommufd_vevent_header hdr;struct iommu_vevent_arm_smmuv3 vevent; } buf; -Error *local_err =NULL ;int ret; ret =smmuv3_accel_event_read_validate (veventq,IOMMU_VEVENTQ_TYPE_ARM_SMMUV3 , &buf, -sizeof (buf), &local_err); -if (ret <0 ) { -warn_report_err_once (local_err); -return ; - } -if (ret >0 ) { -return ;/* EAGAIN/EINTR */ +sizeof (buf), errp); +if (ret) { +return ret; }smmuv3_propagate_event (s, (Evt *)&buf.vevent); +return 0 ; +} + +static void smmuv3_accel_event_read (void *opaque)
hw/arm/smmuv3-accel.c int smmuv3_accel_event_read_validate(IOMMUFDVeventq *veventq, uint32_t type, · line 521
Quoted 10 lines
hw/arm/smmuv3-accel.c +7
-0+{ +SMMUv3State *s = opaque; +Error *local_err =NULL ; + +if (smmuv3_accel_event_read_one (s, &local_err) <0 ) { +warn_report_err_once (local_err); + } }static void smmuv3_accel_free_veventq (SMMUv3AccelState *accel)
Otherwise looks good to me
Eric
RFC PATCH 2/7 hw/arm/smmuv3-accel: Drain the vEVENTQ when the VM stops
In reply to Shameer KolothumFault events sit in the kernel vEVENTQ until smmuv3_accel_event_read() moves them into the emulated event queue. The vEVENTQ is an iommufd object that is not migrated, so anything left in it when the source stops is lost.
Drain it from a VM state change handler, which runs before any state is saved. Propagating an event writes the record into guest RAM and raises the event queue interrupt, and both guest RAM and the GIC are saved before the SMMUv3 device state. A pre_save hook would run after both, hence using qemu_add_vm_change_state_handler().
--- hw/arm/smmuv3-accel.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)
hw/arm/smmuv3-accel.c +35 -0
@@ -18,6 +18,7 @@#include "smmuv3-internal.h" #include "smmuv3-accel.h" +#include "system/runstate.h" #include "system/system.h" #include "tegra241-cmdqv.h"
@@ -518,6 +519,37 @@ static void smmuv3_accel_event_read(void *opaque) } } +/* +* Drain the kernel vEVENTQ into the guest event queue whenever the VM stops, +* so that a migration does not strand events in an object it does not carry. +* Propagating an event writes the record into guest RAM and raises the event +* queue interrupt, both of which are saved before the SMMUv3 device state, so +* a pre_save hook would be too late for either. +* +* VFIO registers at a higher priority and the stop path runs in descending +* priority, so the devices are already in STOP by the time this runs. +*/ +static void smmuv3_accel_vm_state_change (void *opaque,bool running, +RunState state) +{ +SMMUv3State *s = opaque; +SMMUv3AccelState *accel = s->s_accel; +Error *local_err =NULL ; +int ret; + +if (running || !accel || !accel->veventq) { +return ; + } + +do { + ret =smmuv3_accel_event_read_one (s, &local_err); + }while (!ret); + +if (ret <0 ) { +warn_report_err (local_err); + } +} +static void smmuv3_accel_free_veventq (SMMUv3AccelState *accel) {IOMMUFDVeventq *veventq = accel->veventq;
@@ -1146,5 +1178,8 @@ bool smmuv3_accel_init(SMMUv3State *s, Error **errp)qemu_add_machine_init_done_notifier (&s->machine_done); } +/* For migartion of vEVENTQ pending events */ +qemu_add_vm_change_state_handler (smmuv3_accel_vm_state_change, s); +return true; }
Signature · 1 line
2.43.0
Re: [RFC PATCH 2/7] hw/arm/smmuv3-accel: Drain the vEVENTQ when the VM stops
Hi Shameer,
Quoted 28 lines · Shameer Kolothum
Fault events sit in the kernel vEVENTQ until
smmuv3_accel_event_read()moves them into the emulated event queue. The vEVENTQ is an iommufd object that is not migrated, so anything left in it when the source stops is lost.Drain it from a VM state change handler, which runs before any state is saved. Propagating an event writes the record into guest RAM and raises the event queue interrupt, and both guest RAM and the GIC are saved before the SMMUv3 device state. A
pre_savehook would run after both, hence usingqemu_add_vm_change_state_handler().Signed-off-by Shameer Kolothum <[email protected]>--- hw/arm/smmuv3-accel.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)hw/arm/smmuv3-accel.c +1
-0@@ -18,6 +18,7 @@#include "smmuv3-internal.h" #include "smmuv3-accel.h" +#include "system/runstate.h" #include "system/system.h" #include "tegra241-cmdqv.h"
hw/arm/smmuv3-accel.c static void smmuv3_accel_event_read(void *opaque) · line 527
Quoted 9 lines
hw/arm/smmuv3-accel.c +6
-0@@ -518,6 +519,37 @@ static void smmuv3_accel_event_read(void *opaque) } } +/* +* Drain the kernel vEVENTQ into the guest event queue whenever the VM stops, +* so that a migration does not strand events in an object it does not carry. +* Propagating an event writes the record into guest RAM and raises the event +* queue interrupt, both of which are saved before the SMMUv3 device state, so +* a pre_save hook would be too late for either.
I prefered the description in the commit msg:
"and both guest RAM and the GIC are saved before the
SMMUv3 device state" which sounds clearer to me.. A pre_save hook would run after both , which would be too late hence the choice of this VM state change handler.
Quoted 29 lines
hw/arm/smmuv3-accel.c +25
-0+* +* VFIO registers at a higher priority and the stop path runs in descending +* priority, so the devices are already in STOP by the time this runs. +*/ +static void smmuv3_accel_vm_state_change (void *opaque,bool running, +RunState state) +{ +SMMUv3State *s = opaque; +SMMUv3AccelState *accel = s->s_accel; +Error *local_err =NULL ; +int ret; + +if (running || !accel || !accel->veventq) { +return ; + } + +do { + ret =smmuv3_accel_event_read_one (s, &local_err); + }while (!ret); + +if (ret <0 ) { +warn_report_err (local_err); + } +} +static void smmuv3_accel_free_veventq (SMMUv3AccelState *accel) {IOMMUFDVeventq *veventq = accel->veventq;
hw/arm/smmuv3-accel.c bool smmuv3_accel_init(SMMUv3State *s, Error **errp) · line 1181
Quoted 4 lines
hw/arm/smmuv3-accel.c +1
-0@@ -1146,5 +1178,8 @@ bool smmuv3_accel_init(SMMUv3State *s, Error **errp)qemu_add_machine_init_done_notifier (&s->machine_done); } +/* For migartion of vEVENTQ pending events */
migration
hw/arm/smmuv3-accel.c bool smmuv3_accel_init(SMMUv3State *s, Error **errp) · line 1185
Quoted 4 lines
hw/arm/smmuv3-accel.c +2
-0+qemu_add_vm_change_state_handler (smmuv3_accel_vm_state_change, s); +return true; }
Otherwise looks good to me
Eric
RFC PATCH 3/7 hw/arm/smmuv3: Migrate the accelerator feature set
In reply to Shameer KolothumAdd a subsection carrying idr[0] to idr[5], needed when accel=on. pre_load saves the locally resolved values and post_load fails the migration if the incoming ones differ. Accepting the source values would leave QEMU advertising features the destination host cannot provide.
--- hw/arm/smmuv3-accel.h | 1 + include/hw/arm/smmuv3.h | 7 ++++- hw/arm/smmuv3-accel-stubs.c | 12 ++++++++ hw/arm/smmuv3-accel.c | 58 +++++++++++++++++++++++++++++++++++++ hw/arm/smmuv3.c | 1 + 5 files changed, 78 insertions(+), 1 deletion(-)
hw/arm/smmuv3-accel.h +1 -0
@@ -99,6 +99,7 @@ void smmuv3_accel_idr_override(SMMUv3State *s);bool smmuv3_accel_alloc_veventq (SMMUv3State *s,Error **errp);int smmuv3_accel_event_read_validate (IOMMUFDVeventq *veventq,uint32_t type,void *buf,size_t size,Error **errp); +extern const VMStateDescription vmstate_smmuv3_accel;void smmuv3_accel_reset (SMMUv3State *s);SMMUv3AccelCmdqvType smmuv3_accel_cmdqv_type (Object *obj);
include/hw/arm/smmuv3.h +6 -1
@@ -26,6 +26,9 @@#define TYPE_SMMUV3_IOMMU_MEMORY_REGION "smmuv3-iommu-memory-region" +/* Number of IDR registers, IDR0 to IDR5 */ +#define SMMU_NUM_IDR 6 + typedef struct SMMUQueue { uint64_t base; /* base register */ uint32_t prod;
@@ -41,7 +44,9 @@ struct SMMUv3State {uint8_t sid_size;uint8_t sid_split; -uint32_t idr[6 ]; +uint32_t idr[SMMU_NUM_IDR ]; +/* Locally resolved IDRs, saved by pre_load for post_load to check */ +uint32_t local_idr[SMMU_NUM_IDR ];uint32_t iidr;uint32_t aidr;uint32_t cr[3 ];
hw/arm/smmuv3-accel-stubs.c +12 -0
@@ -8,6 +8,7 @@#include "qapi/error.h" #include "hw/arm/smmuv3.h" #include "hw/arm/smmuv3-accel.h" +#include "migration/vmstate.h" bool smmuv3_accel_init (SMMUv3State *s,Error **errp) {
@@ -53,6 +54,17 @@ int smmuv3_accel_event_read_validate(IOMMUFDVeventq *veventq, uint32_t type,return 0 ; } +static bool smmuv3_accel_vmstate_needed (void *opaque) +{ +return false; +} + +const VMStateDescription vmstate_smmuv3_accel = { + .name ="smmuv3/accel" , + .version_id =1 , + .minimum_version_id =1 , + .needed = smmuv3_accel_vmstate_needed, +};void smmuv3_accel_reset (SMMUv3State *s) {
hw/arm/smmuv3-accel.c +58 -0
70 lines not on this page · raw message
hw/arm/smmuv3.c +1 -0
@@ -2137,6 +2137,7 @@ static const VMStateDescription vmstate_smmuv3 = { }, .subsections = (const VMStateDescription * const []) { &vmstate_gbpa, + &vmstate_smmuv3_accel,NULL } };
Signature · 1 line
2.43.0
Re: [RFC PATCH 3/7] hw/arm/smmuv3: Migrate the accelerator feature set
Hi Shameer,
Quoted 1 line · Shameer Kolothum
Add a subsection carrying idr[0] to idr[5], needed when accel=on.
pre_load
I would explain what you try to achieve before the how.
Quoted 117 lines
saves the locally resolved values and
post_loadfails the migration if the incoming ones differ. Accepting the source values would leave QEMU advertising features the destination host cannot provide.Signed-off-by Shameer Kolothum <[email protected]>--- hw/arm/smmuv3-accel.h | 1 + include/hw/arm/smmuv3.h | 7 ++++- hw/arm/smmuv3-accel-stubs.c | 12 ++++++++ hw/arm/smmuv3-accel.c | 58 +++++++++++++++++++++++++++++++++++++ hw/arm/smmuv3.c | 1 + 5 files changed, 78 insertions(+), 1 deletion(-)hw/arm/smmuv3-accel.h +1
-0@@ -99,6 +99,7 @@ void smmuv3_accel_idr_override(SMMUv3State *s);bool smmuv3_accel_alloc_veventq (SMMUv3State *s,Error **errp);int smmuv3_accel_event_read_validate (IOMMUFDVeventq *veventq,uint32_t type,void *buf,size_t size,Error **errp); +extern const VMStateDescription vmstate_smmuv3_accel;void smmuv3_accel_reset (SMMUv3State *s);SMMUv3AccelCmdqvType smmuv3_accel_cmdqv_type (Object *obj);include/hw/arm/smmuv3.h +6
-1@@ -26,6 +26,9 @@#define TYPE_SMMUV3_IOMMU_MEMORY_REGION "smmuv3-iommu-memory-region" +/* Number of IDR registers, IDR0 to IDR5 */ +#define SMMU_NUM_IDR 6 + typedef struct SMMUQueue { uint64_t base; /* base register */ uint32_t prod;@@ -41,7 +44,9 @@ struct SMMUv3State {uint8_t sid_size;uint8_t sid_split; -uint32_t idr[6 ]; +uint32_t idr[SMMU_NUM_IDR ]; +/* Locally resolved IDRs, saved by pre_load for post_load to check */ +uint32_t local_idr[SMMU_NUM_IDR ];uint32_t iidr;uint32_t aidr;uint32_t cr[3 ];hw/arm/smmuv3-accel-stubs.c +12
-0@@ -8,6 +8,7 @@#include "qapi/error.h" #include "hw/arm/smmuv3.h" #include "hw/arm/smmuv3-accel.h" +#include "migration/vmstate.h" bool smmuv3_accel_init (SMMUv3State *s,Error **errp) {@@ -53,6 +54,17 @@ int smmuv3_accel_event_read_validate(IOMMUFDVeventq *veventq, uint32_t type,return 0 ; } +static bool smmuv3_accel_vmstate_needed (void *opaque) +{ +return false; +} + +const VMStateDescription vmstate_smmuv3_accel = { + .name ="smmuv3/accel" , + .version_id =1 , + .minimum_version_id =1 , + .needed = smmuv3_accel_vmstate_needed, +};void smmuv3_accel_reset (SMMUv3State *s) {hw/arm/smmuv3-accel.c +22
-0@@ -18,6 +18,7 @@#include "smmuv3-internal.h" #include "smmuv3-accel.h" +#include "migration/vmstate.h" #include "system/runstate.h" #include "system/system.h" #include "tegra241-cmdqv.h" @@ -1096,6 +1097,63 @@ bool smmuv3_accel_attach_gbpa_hwpt(SMMUv3State *s, Error **errp)return all_ok; } +static bool smmuv3_accel_vmstate_pre_load (void *opaque,Error **errp) +{ +SMMUv3State *s = opaque; + +if (!s->s_accel) { +error_setg (errp,"Incoming stream carries SMMUv3 accelerator state " +"but this arm-smmuv3 has accel=off" ); +return false; + } + +/* Save the locally resolved IDRs before the stream overwrites them. */ +memcpy (s->local_idr, s->idr,sizeof (s->idr)); +return true; +} + +static bool smmuv3_accel_vmstate_post_load (void *opaque,int version_id, +Error **errp) +{ +ERRP_GUARD (); +SMMUv3State *s = opaque; +int i;
hw/arm/smmuv3-accel.c bool smmuv3_accel_attach_gbpa_hwpt(SMMUv3State *s, Error **errp) · line 1130
Quoted 10 lines
hw/arm/smmuv3-accel.c +10
-0+ +for (i =0 ; i <ARRAY_SIZE (s->idr); i++) { +if (s->idr[i] == s->local_idr[i]) { +continue ; + } +error_setg (errp,"SMMUv3 IDR%d mismatch: source 0x%08x, " +"destination 0x%08x" , i, s->idr[i], + s->local_idr[i]); +error_append_hint (errp,"ril, ats, oas and ssidsize must resolve to " +"the same values on source and destination.\n" );
don't you want to be more precise then and just check the corresponding fields?
Quoted 34 lines
hw/arm/smmuv3-accel.c +26
-0+return false; + } + +return true; +} + +static bool smmuv3_accel_vmstate_needed (void *opaque) +{ +SMMUv3State *s = opaque; + +return s->accel; +} + +const VMStateDescription vmstate_smmuv3_accel = { + .name ="smmuv3/accel" , + .version_id =1 , + .minimum_version_id =1 , + .needed = smmuv3_accel_vmstate_needed, + .pre_load_errp = smmuv3_accel_vmstate_pre_load, + .post_load_errp = smmuv3_accel_vmstate_post_load, + .fields = (const VMStateField []) { +VMSTATE_UINT32_ARRAY (idr, SMMUv3State,SMMU_NUM_IDR ), +VMSTATE_END_OF_LIST () + } +}; +void smmuv3_accel_reset (SMMUv3State *s) {SMMUv3AccelState *accel = s->s_accel;hw/arm/smmuv3.c +0
-0
hw/arm/smmuv3.c static const VMStateDescription vmstate_smmuv3 = { · line 2143
Quoted 7 lines
hw/arm/smmuv3.c +1
-0@@ -2137,6 +2137,7 @@ static const VMStateDescription vmstate_smmuv3 = { }, .subsections = (const VMStateDescription * const []) { &vmstate_gbpa, + &vmstate_smmuv3_accel,NULL } };
Thanks
Eric
RFC PATCH 4/7 hw/arm/smmuv3-accel: Add a helper to replay all STEs
In reply to Shameer KolothumAdd smmuv3_accel_replay_stes(). It walks the guest stream table and calls smmuv3_accel_install_ste() for every device behind an accelerated SMMUv3, which rebuilds the vDEVICE and the nested HWPT. The incoming migration path uses this instead of transferring per device host state, all of which can be derived from guest RAM once strtab_base and CR0 are restored.
No caller yet.
--- hw/arm/smmuv3-accel.h | 1 + hw/arm/smmuv3-accel-stubs.c | 5 +++++ hw/arm/smmuv3-accel.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+)
hw/arm/smmuv3-accel.h +1 -0
@@ -92,6 +92,7 @@ bool smmuv3_accel_install_ste(SMMUv3State *s, SMMUDevice *sdev, int sid, Error **errp);bool smmuv3_accel_install_ste_range (SMMUv3State *s,SMMUSIDRange *range,Error **errp); +bool smmuv3_accel_replay_stes (SMMUv3State *s,Error **errp);bool smmuv3_accel_attach_gbpa_hwpt (SMMUv3State *s,Error **errp);bool smmuv3_accel_issue_inv_cmd (SMMUv3State *s,void *cmd,SMMUDevice *sdev,Error **errp);
hw/arm/smmuv3-accel-stubs.c +5 -0
@@ -28,6 +28,11 @@ bool smmuv3_accel_install_ste_range(SMMUv3State *s, SMMUSIDRange *range,return true; } +bool smmuv3_accel_replay_stes (SMMUv3State *s,Error **errp) +{ +return true; +} +bool smmuv3_accel_attach_gbpa_hwpt (SMMUv3State *s,Error **errp) {return true;
hw/arm/smmuv3-accel.c +34 -0
@@ -407,6 +407,40 @@ bool smmuv3_accel_install_ste_range(SMMUv3State *s, SMMUSIDRange *range,return all_ok; } +/* +* Install the STE again for every device behind this accelerated SMMUv3, by +* reading the guest stream table once more. Stops at the first failure. +*/ +bool smmuv3_accel_replay_stes (SMMUv3State *s,Error **errp) +{ +ERRP_GUARD (); +SMMUv3AccelState *accel = s->s_accel; +SMMUv3AccelDevice *accel_dev; + +if (!accel || !accel->viommu) { +return true; + } + + QLIST_FOREACH(accel_dev, &accel->device_list, next) { +uint32_t sid =smmu_get_sid (&accel_dev->sdev); +SMMUEventInfo event = {.type =SMMU_EVT_NONE , .sid = sid, + .inval_ste_allowed = true}; +STE ste; + +/* Skip a device the guest has not programmed */ +if (smmu_find_ste (s, sid, &ste, &event)) { +continue ; + } + +if (!smmuv3_accel_install_ste (s, &accel_dev->sdev, sid, errp)) { +error_prepend (errp,"Device 0x%x: Failed to install STE: " , sid); +return false; + } + } + +return true; +} +/* * This issues the invalidation cmd to the host SMMUv3. *
Signature · 1 line
2.43.0
Re: [RFC PATCH 4/7] hw/arm/smmuv3-accel: Add a helper to replay all STEs
Hi Shameer,
Quoted 56 lines · Shameer Kolothum
Add
smmuv3_accel_replay_stes(). It walks the guest stream table and callssmmuv3_accel_install_ste()for every device behind an accelerated SMMUv3, which rebuilds the vDEVICE and the nested HWPT. The incoming migration path uses this instead of transferring per device host state, all of which can be derived from guest RAM oncestrtab_baseand CR0 are restored.No caller yet.
Signed-off-by Shameer Kolothum <[email protected]>--- hw/arm/smmuv3-accel.h | 1 + hw/arm/smmuv3-accel-stubs.c | 5 +++++ hw/arm/smmuv3-accel.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+)hw/arm/smmuv3-accel.h +1
-0@@ -92,6 +92,7 @@ bool smmuv3_accel_install_ste(SMMUv3State *s, SMMUDevice *sdev, int sid, Error **errp);bool smmuv3_accel_install_ste_range (SMMUv3State *s,SMMUSIDRange *range,Error **errp); +bool smmuv3_accel_replay_stes (SMMUv3State *s,Error **errp);bool smmuv3_accel_attach_gbpa_hwpt (SMMUv3State *s,Error **errp);bool smmuv3_accel_issue_inv_cmd (SMMUv3State *s,void *cmd,SMMUDevice *sdev,Error **errp);hw/arm/smmuv3-accel-stubs.c +5
-0@@ -28,6 +28,11 @@ bool smmuv3_accel_install_ste_range(SMMUv3State *s, SMMUSIDRange *range,return true; } +bool smmuv3_accel_replay_stes (SMMUv3State *s,Error **errp) +{ +return true; +} +bool smmuv3_accel_attach_gbpa_hwpt (SMMUv3State *s,Error **errp) {return true;hw/arm/smmuv3-accel.c +5
-0@@ -407,6 +407,40 @@ bool smmuv3_accel_install_ste_range(SMMUv3State *s, SMMUSIDRange *range,return all_ok; } +/* +* Install the STE again for every device behind this accelerated SMMUv3, by +* reading the guest stream table once more. Stops at the first failure. +*/ +bool smmuv3_accel_replay_stes (SMMUv3State *s,Error **errp)
hw/arm/smmuv3-accel.c bool smmuv3_accel_install_ste_range(SMMUv3State *s, SMMUSIDRange *range, · line 424
Quoted 10 lines
hw/arm/smmuv3-accel.c +10
-0+{ +ERRP_GUARD (); +SMMUv3AccelState *accel = s->s_accel; +SMMUv3AccelDevice *accel_dev; + +if (!accel || !accel->viommu) { +return true; + } + + QLIST_FOREACH(accel_dev, &accel->device_list, next) {
What if you have different device topology on src and dest. Is it detected?
hw/arm/smmuv3-accel.c bool smmuv3_accel_install_ste_range(SMMUv3State *s, SMMUSIDRange *range, · line 436
Quoted 12 lines
hw/arm/smmuv3-accel.c +12
-0+uint32_t sid =smmu_get_sid (&accel_dev->sdev); +SMMUEventInfo event = {.type =SMMU_EVT_NONE , .sid = sid, + .inval_ste_allowed = true}; +STE ste; + +/* Skip a device the guest has not programmed */ +if (smmu_find_ste (s, sid, &ste, &event)) { +continue ; + } + +if (!smmuv3_accel_install_ste (s, &accel_dev->sdev, sid, errp)) { +error_prepend (errp,"Device 0x%x: Failed to install STE: " , sid);
maybe, from a user point of view it is not obvious why we get this error as migration load is not mentionned.
hw/arm/smmuv3-accel.c bool smmuv3_accel_install_ste_range(SMMUv3State *s, SMMUSIDRange *range, · line 446
Quoted 10 lines
hw/arm/smmuv3-accel.c +7
-0+return false; + } + } + +return true; +} +/* * This issues the invalidation cmd to the host SMMUv3. *
Thanks
Eric
RE: [RFC PATCH 4/7] hw/arm/smmuv3-accel: Add a helper to replay all STEs
Hi Eric,
Quoted 80 lines
-----Original Message-----
From: Eric Auger <[email protected]>
Sent: 01 October 2026 17:18
To: Shameer Kolothum Thodi <[email protected]>; qemu- [email protected]; [email protected]
Cc: [email protected]; Nicolin Chen <[email protected]>; Nathan Chen <[email protected]>; Matt Ochs <[email protected]>; Jiandi An <[email protected]>; [email protected]; Ankit Agrawal <[email protected]>; Aniket Agashe <[email protected]>; [email protected]; [email protected]
Subject: Re: [RFC PATCH 4/7] hw/arm/smmuv3-accel: Add a helper to replay all STEsExternal email: Use caution opening links or attachments
Hi Shameer,
Quoted 2 lines · Shameer Kolothum
Add
smmuv3_accel_replay_stes(). It walks the guest stream table and callssmmuv3_accel_install_ste()for every device behind an acceleratedSMMUv3,
Quoted 1 line
which rebuilds the vDEVICE and the nested HWPT. The incoming migration
path
hw/arm/smmuv3-accel.h bool smmuv3_accel_install_ste(SMMUv3State *s,
Quoted 17 lines
uses this instead of transferring per device host state, all of which can be derived from guest RAM once
strtab_baseand CR0 are restored.No caller yet.
Signed-off-by Shameer Kolothum <[email protected]>--- hw/arm/smmuv3-accel.h | 1 + hw/arm/smmuv3-accel-stubs.c | 5 +++++ hw/arm/smmuv3-accel.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+)hw/arm/smmuv3-accel.h +0
-0@@ -92,6 +92,7 @@ bool smmuv3_accel_install_ste(SMMUv3State *s,SMMUDevice *sdev, int sid,
hw/arm/smmuv3-accel.h bool smmuv3_accel_install_ste(SMMUv3State *s, · line 93
Quoted 2 lines
hw/arm/smmuv3-accel.h +0
-0Error **errp); bool smmuv3_accel_install_ste_range(SMMUv3State *s, SMMUSIDRange*range,
hw/arm/smmuv3-accel.h bool smmuv3_accel_install_ste(SMMUv3State *s, SMMUDevice *sdev, int sid,
Quoted 4 lines
hw/arm/smmuv3-accel.h +1
-0Error **errp); +bool smmuv3_accel_replay_stes (SMMUv3State *s,Error **errp);bool smmuv3_accel_attach_gbpa_hwpt (SMMUv3State *s,Error **errp); bool smmuv3_accel_issue_inv_cmd(SMMUv3State *s, void *cmd,SMMUDevice *sdev,
hw/arm/smmuv3-accel-stubs.c bool smmuv3_accel_install_ste_range(SMMUv3State
Quoted 6 lines
hw/arm/smmuv3-accel.h +0
-0Error **errp);hw/arm/smmuv3-accel-stubs.c +0
-0@@ -28,6 +28,11 @@ bool smmuv3_accel_install_ste_range(SMMUv3State*s, SMMUSIDRange *range,
hw/arm/smmuv3-accel.c bool
Quoted 16 lines
hw/arm/smmuv3-accel-stubs.c +5
-0return true; } +bool smmuv3_accel_replay_stes (SMMUv3State *s,Error **errp) +{ +return true; +} +bool smmuv3_accel_attach_gbpa_hwpt (SMMUv3State *s,Error **errp) {return true;hw/arm/smmuv3-accel.c +0
-0@@ -407,6 +407,40 @@ boolsmmuv3_accel_install_ste_range(SMMUv3State *s, SMMUSIDRange *range,
hw/arm/smmuv3-accel.c bool smmuv3_accel_install_ste_range(SMMUv3State *s, SMMUSIDRange *range,
Quoted 5 lines
hw/arm/smmuv3-accel.c +2
-0return all_ok; } +/* +* Install the STE again for every device behind this accelerated SMMUv3, by
Quoted 14 lines
hw/arm/smmuv3-accel.c bool smmuv3_accel_install_ste_range(SMMUv3State *s, SMMUSIDRange *range, · line 424
Quoted 13 lines
hw/arm/smmuv3-accel.c +13
-0+* reading the guest stream table once more. Stops at the first failure. +*/ +bool smmuv3_accel_replay_stes (SMMUv3State *s,Error **errp) +{ +ERRP_GUARD (); +SMMUv3AccelState *accel = s->s_accel; +SMMUv3AccelDevice *accel_dev; + +if (!accel || !accel->viommu) { +return true; + } + + QLIST_FOREACH(accel_dev, &accel->device_list, next) {What if you have different device topology on src and dest. Is it detected?
Not by this helper. However, IIUC, VFIO registers its savevm handler under the qdev path, so a device that is not at the same place on the destination fails the load at the start of the stream, before we get here.
Tried it with the device under a different root port on the destination:
qemu-system-aarch64: Unknown section or instance '0000:01:01.0:00.0:00.0/vfio' 0. Make sure that your current VM setup matches your saved VM setup, including any hotplugged devices
An extra device on the destination is not detected. The guest has no STE for it, so the replay skips it and it stays on the GBPA HWPT, same as before the guest driver touches it. The usual rule applies, the command lines have to match.
Quoted 6 lines
Quoted 6 lines
hw/arm/smmuv3-accel.c +6
-0+uint32_t sid =smmu_get_sid (&accel_dev->sdev); +SMMUEventInfo event = {.type =SMMU_EVT_NONE , .sid = sid, + .inval_ste_allowed = true}; +STE ste; + +/* Skip a device the guest has not programmed */
Quoted 8 lines
hw/arm/smmuv3-accel.c bool smmuv3_accel_install_ste_range(SMMUv3State *s, SMMUSIDRange *range, · line 436
Quoted 6 lines
hw/arm/smmuv3-accel.c +6
-0+if (smmu_find_ste (s, sid, &ste, &event)) { +continue ; + } + +if (!smmuv3_accel_install_ste (s, &accel_dev->sdev, sid, errp)) { +error_prepend (errp,"Device 0x%x: Failed to install STE: " , sid);maybe, from a user point of view it is not obvious why we get this error as migration load is not mentionned.
Ok, will reword.
Thanks,
Shameer
RFC PATCH 5/7 hw/arm/smmuv3-accel: Restore accelerator state on incoming migration
In reply to Shameer KolothumExtend the accel subsection post_load, after the IDR check, to bring the host side back in line. It allocates the vEVENTQ, which the A_CR0 write handler normally does, using the restored s->eventq.log2size. It attaches the HWPT for the restored GBPA to every device. Then it replays the STEs, which overrides that HWPT wherever the guest has a usable entry.
--- hw/arm/smmuv3-accel.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
hw/arm/smmuv3-accel.c +22 -0
@@ -1165,6 +1165,28 @@ static bool smmuv3_accel_vmstate_post_load(void *opaque, int version_id,return false; } +if (!s->s_accel->viommu) { +return true; + } + +/* Normally done by the A_CR0 write handler, which is not replayed. */ +if (!smmuv3_accel_alloc_veventq (s, errp)) { +error_prepend (errp,"Failed to restore the vEVENTQ: " ); +return false; + } + +/* smmuv3/gbpa is listed before this subsection, so it is in place */ +if (!smmuv3_accel_attach_gbpa_hwpt (s, errp)) { +error_prepend (errp,"Failed to restore the GBPA HWPT: " ); +return false; + } + +/* Everything else comes from guest memory, which is already restored. */ +if (!smmuv3_accel_replay_stes (s, errp)) { +error_prepend (errp,"Failed to replay the stream table: " ); +return false; + } +return true; }
Signature · 1 line
2.43.0
Re: [RFC PATCH 5/7] hw/arm/smmuv3-accel: Restore accelerator state on incoming migration
Hi Shameer,
Quoted 24 lines · Shameer Kolothum
Extend the accel subsection
post_load, after the IDR check, to bring the host side back in line. It allocates the vEVENTQ, which theA_CR0write handler normally does, using the restoreds->eventq.log2size. It attaches the HWPT for the restored GBPA to every device. Then it replays the STEs, which overrides that HWPT wherever the guest has a usable entry.Signed-off-by Shameer Kolothum <[email protected]>--- hw/arm/smmuv3-accel.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)hw/arm/smmuv3-accel.c +5
-0@@ -1165,6 +1165,28 @@ static bool smmuv3_accel_vmstate_post_load(void *opaque, int version_id,return false; } +if (!s->s_accel->viommu) { +return true; + } + +/* Normally done by the A_CR0 write handler, which is not replayed. */
hw/arm/smmuv3-accel.c static bool smmuv3_accel_vmstate_post_load(void *opaque, int version_id, · line 1182
Quoted 10 lines
hw/arm/smmuv3-accel.c +10
-0+if (!smmuv3_accel_alloc_veventq (s, errp)) { +error_prepend (errp,"Failed to restore the vEVENTQ: " ); +return false; + } + +/* smmuv3/gbpa is listed before this subsection, so it is in place */ +if (!smmuv3_accel_attach_gbpa_hwpt (s, errp)) { +error_prepend (errp,"Failed to restore the GBPA HWPT: " ); +return false; + }
I would recommend to document the order of operations somewhere, ie. registers first, data structures in guest RAM and also list all the host resources that need to be reconstructed
Looks almost too simple :-)
Eric
hw/arm/smmuv3-accel.c static bool smmuv3_accel_vmstate_post_load(void *opaque, int version_id, · line 1192
Quoted 10 lines
hw/arm/smmuv3-accel.c +7
-0+ +/* Everything else comes from guest memory, which is already restored. */ +if (!smmuv3_accel_replay_stes (s, errp)) { +error_prepend (errp,"Failed to replay the stream table: " ); +return false; + } +return true; }
Eric
RFC PATCH 6/7 hw/arm/smmuv3-accel: Request dirty tracking on the nesting parent
In reply to Shameer KolothumWith accel=on the guest owns Stage 1, so the Stage 2 nesting parent is the only page table the host can track guest writes through.
VFIO only asks for IOMMU_HWPT_ALLOC_DIRTY_TRACKING on the nesting parent when the vIOMMU sets VIOMMU_FLAG_WANT_NESTING_DIRTY_TRACKING, which smmuv3-accel does not, so the parent is allocated plain.
Set the flag.
--- hw/arm/smmuv3-accel.c | 6 ++++++ 1 file changed, 6 insertions(+)
hw/arm/smmuv3-accel.c +6 -0
@@ -1037,6 +1037,12 @@ static uint64_t smmuv3_accel_get_viommu_flags(void *opaque)SMMUState *bs = opaque;SMMUv3State *s =ARM_SMMUV3 (bs); +/* +* The guest owns Stage 1, so the Stage 2 parent is the only page table +* the host can track guest writes through. +*/ + flags |=VIOMMU_FLAG_WANT_NESTING_DIRTY_TRACKING ; +if (smmuv3_pasid_supported (s)) { flags |=VIOMMU_FLAG_PASID_SUPPORTED ; }
Signature · 1 line
2.43.0
Re: [RFC PATCH 6/7] hw/arm/smmuv3-accel: Request dirty tracking on the nesting parent
Quoted 10 lines · Shameer Kolothum
With accel=on the guest owns Stage 1, so the Stage 2 nesting parent is the only page table the host can track guest writes through.
VFIO only asks for
IOMMU_HWPT_ALLOC_DIRTY_TRACKINGon the nesting parent when the vIOMMU setsVIOMMU_FLAG_WANT_NESTING_DIRTY_TRACKING, which smmuv3-accel does not, so the parent is allocated plain.Set the flag.
Signed-off-by Shameer Kolothum <[email protected]>
Eric
Quoted 21 lines
--- hw/arm/smmuv3-accel.c | 6 ++++++ 1 file changed, 6 insertions(+)hw/arm/smmuv3-accel.c +6
-0@@ -1037,6 +1037,12 @@ static uint64_t smmuv3_accel_get_viommu_flags(void *opaque)SMMUState *bs = opaque;SMMUv3State *s =ARM_SMMUV3 (bs); +/* +* The guest owns Stage 1, so the Stage 2 parent is the only page table +* the host can track guest writes through. +*/ + flags |=VIOMMU_FLAG_WANT_NESTING_DIRTY_TRACKING ; +if (smmuv3_pasid_supported (s)) { flags |=VIOMMU_FLAG_PASID_SUPPORTED ; }
RFC PATCH 7/7 hw/arm/smmuv3: Support migration with accel=on
In reply to Shameer KolothumWith the restore path in place, allow migration of an accelerated SMMUv3.
Replace the blocker installed unconditionally at realize with one scoped to CMDQV, installed where CMDQV is actually selected.
CMDQV migration support is not enabled now.
--- hw/arm/smmuv3-accel.c | 11 +++++++++++ hw/arm/smmuv3.c | 5 ----- 2 files changed, 11 insertions(+), 5 deletions(-)
hw/arm/smmuv3-accel.c +11 -0
@@ -18,6 +18,7 @@#include "smmuv3-internal.h" #include "smmuv3-accel.h" +#include "migration/blocker.h" #include "migration/vmstate.h" #include "system/runstate.h" #include "system/system.h"
@@ -801,6 +802,16 @@ smmuv3_accel_select_cmdqv(SMMUv3State *s, HostIOMMUDeviceIOMMUFD *idev,return false; } s->s_accel->cmdqv_ops = ops; + +/* No support for CMDQV migration for now */ +if (ops) { +error_setg (&s->migration_blocker, +"Migration is not supported with SMMUv3 CMDQV enabled" ); +if (migrate_add_blocker (&s->migration_blocker, errp) <0 ) { +return false; + } + } +return true; }
hw/arm/smmuv3.c +0 -5
@@ -2047,11 +2047,6 @@ static void smmu_realize(DeviceState *d, Error **errp)if (!smmuv3_accel_init (s, errp)) {return ; } -error_setg (&s->migration_blocker,"Migration not supported with SMMUv3 " -"accelerator mode enabled" ); -if (migrate_add_blocker (&s->migration_blocker, errp) <0 ) { -return ; - } } c->parent_realize (d, &local_err);
Signature · 1 line
2.43.0
Re: [RFC PATCH 7/7] hw/arm/smmuv3: Support migration with accel=on
Quoted 8 lines · Shameer Kolothum
With the restore path in place, allow migration of an accelerated SMMUv3.
Replace the blocker installed unconditionally at realize with one scoped to CMDQV, installed where CMDQV is actually selected.
CMDQV migration support is not enabled now.
Signed-off-by Shameer Kolothum <[email protected]>
Eric
Quoted 50 lines
--- hw/arm/smmuv3-accel.c | 11 +++++++++++ hw/arm/smmuv3.c | 5 ----- 2 files changed, 11 insertions(+), 5 deletions(-)hw/arm/smmuv3-accel.c +11
-0@@ -18,6 +18,7 @@#include "smmuv3-internal.h" #include "smmuv3-accel.h" +#include "migration/blocker.h" #include "migration/vmstate.h" #include "system/runstate.h" #include "system/system.h" @@ -801,6 +802,16 @@ smmuv3_accel_select_cmdqv(SMMUv3State *s, HostIOMMUDeviceIOMMUFD *idev,return false; } s->s_accel->cmdqv_ops = ops; + +/* No support for CMDQV migration for now */ +if (ops) { +error_setg (&s->migration_blocker, +"Migration is not supported with SMMUv3 CMDQV enabled" ); +if (migrate_add_blocker (&s->migration_blocker, errp) <0 ) { +return false; + } + } +return true; }hw/arm/smmuv3.c +0
-5@@ -2047,11 +2047,6 @@ static void smmu_realize(DeviceState *d, Error **errp)if (!smmuv3_accel_init (s, errp)) {return ; } -error_setg (&s->migration_blocker,"Migration not supported with SMMUv3 " -"accelerator mode enabled" ); -if (migrate_add_blocker (&s->migration_blocker, errp) <0 ) { -return ; - } } c->parent_realize (d, &local_err);
Hi Shameer,
Quoted 27 lines · Shameer Kolothum
Hi,
This series adds live migration support for an accelerated SMMUv3 (-device arm-smmuv3,accel=on) with vfio-pci endpoints on the iommufd backend.
The destination replays rather than receives. The stream table, the STEs, the CDs and the Stage 1 page tables all live in guest RAM, so once that and the registers are restored, the destination walks the stream table again and rebuilds the vDEVICE and the nested HWPT for every device.
What the series does:
- drains the kernel vEVENTQ into the guest event queue when the VM stops, so that pending fault events are not lost (1, 2)
- migrates the resolved SMMUv3 feature set in a new smmuv3/accel subsection and fails the load if the two ends differ (3)
- replays the guest stream table on the destination and restores the vEVENTQ and the GBPA HWPT (4, 5)
- asks VFIO for dirty tracking on the Stage 2 nesting parent (6)
- replaces the accel migration blocker with one scoped to CMDQV, which cannot be migrated for now (7)This depends on the host kernel supporting dirty tracking on the Stage 2 nesting parent, for assigned devices that cannot track dirty pages themselves. A branch based on Jason's iommu page table work is here [0].
Quoted 6 lines
Big caveat:
This is not yet tested with a real device that supports migration as I do not have a test setup for that. Folks who do have such a setup have reached out and are copied here, so hopefully this RFC lets them give it a spin and provide some early feedback.
Please could you clarify all the requirements for supporting this migration scenario (at EP, SMMU and kernel level)?
Thanks in advance
Eric
Quoted 27 lines
QEMU branch is here:
https://github.com/shamiali2008/qemu-master/tree/smmuv3-accel-live-migrn-rfcv1
Please let me know your feedback.
Thanks,
Shameer
[0]: https://github.com/shamiali2008/linux/commits/iommu_pt_arm64_s2_dbm/Shameer Kolothum (7):
hw/arm/smmuv3-accel: Factor out the single vEVENT read hw/arm/smmuv3-accel: Drain the vEVENTQ when the VM stops hw/arm/smmuv3: Migrate the accelerator feature set hw/arm/smmuv3-accel: Add a helper to replay all STEs hw/arm/smmuv3-accel: Restore accelerator state on incoming migration hw/arm/smmuv3-accel: Request dirty tracking on the nesting parent hw/arm/smmuv3: Support migration with accel=onhw/arm/smmuv3-accel.h | 2 + include/hw/arm/smmuv3.h | 7 +- hw/arm/smmuv3-accel-stubs.c | 17 ++++ hw/arm/smmuv3-accel.c | 192 ++++++++++++++++++++++++++++++++++-- hw/arm/smmuv3.c | 6 +- 5 files changed, 210 insertions(+), 14 deletions(-)
Quoted 49 lines
-----Original Message-----
From: Eric Auger <[email protected]>
Sent: 01 October 2026 17:41
To: Shameer Kolothum Thodi <[email protected]>; qemu- [email protected]; [email protected]
Cc: [email protected]; Nicolin Chen <[email protected]>; Nathan Chen <[email protected]>; Matt Ochs <[email protected]>; Jiandi An <[email protected]>; [email protected]; Ankit Agrawal <[email protected]>; Aniket Agashe <[email protected]>; [email protected]; [email protected]
Subject: Re: [RFC PATCH 0/7] hw/arm/smmuv3: Live migration for accel=onExternal email: Use caution opening links or attachments
Hi Shameer,
Quoted 10 lines · Shameer Kolothum
Hi,
This series adds live migration support for an accelerated SMMUv3 (-device arm-smmuv3,accel=on) with vfio-pci endpoints on the iommufd backend.
The destination replays rather than receives. The stream table, the STEs, the CDs and the Stage 1 page tables all live in guest RAM, so once that and the registers are restored, the destination walks the stream table again and rebuilds the vDEVICE and the nested HWPT for every
device.
Quoted 19 lines
What the series does:
- drains the kernel vEVENTQ into the guest event queue when the VM stops, so that pending fault events are not lost (1, 2)
- migrates the resolved SMMUv3 feature set in a new smmuv3/accel subsection and fails the load if the two ends differ (3)
- replays the guest stream table on the destination and restores the vEVENTQ and the GBPA HWPT (4, 5)
- asks VFIO for dirty tracking on the Stage 2 nesting parent (6)
- replaces the accel migration blocker with one scoped to CMDQV, which cannot be migrated for now (7)This depends on the host kernel supporting dirty tracking on the Stage 2 nesting parent, for assigned devices that cannot track dirty pages themselves. A branch based on Jason's iommu page table work is here [0].
Big caveat:
Quoted 7 lines
Quoted 4 lines
This is not yet tested with a real device that supports migration as I do not have a test setup for that. Folks who do have such a setup have reached out and are copied here, so hopefully this RFC lets them give it a spin and provide some early feedback.
Please could you clarify all the requirements for supporting this migration scenario (at EP, SMMU and kernel level)?
For a minimum we need:
EP:
- A device with migration support and a vfio variant driver that implements VFIO migration, the same as for migration without a vIOMMU.
Host SMMUv3:
- Dirty tracking on the Stage 2 nesting parent. Stage 2 maps GPA to PA, so the dirty bits it sets are already in guest physical terms. That needs HTTU (IDR0.HTTU reporting HD) and coherent table walks, which is what arm_smmu_dbm_capable() checks and iommufd reports as IOMMU_HW_CAP_DIRTY_TRACKING. Without it VFIO adds its usual blocker.
Host Kernel:
- IOMMU_HWPT_ALLOC_DIRTY_TRACKING on a nesting parent domain. Upstream arm-smmu-v3 returns EOPNOTSUPP for that combination. The branch in [0] enables it on top of Jason's iommu page table work, by setting S2HA and S2HD in the STE and using the DBM support in the generic page table code.
Thanks,
Shameer
Quoted 33 lines
Quoted 4 lines
QEMU branch is here:
https://github.com/shamiali2008/qemu-master/tree/smmuv3-accel-live-
mig
Quoted 8 lines
rn-rfcv1
Please let me know your feedback.
Thanks,
Shameer
[0]:https://github.com/shamiali2008/linux/commits/iommu_pt_arm64_s2_dbm
/Quoted 10 lines
Shameer Kolothum (7):
hw/arm/smmuv3-accel: Factor out the single vEVENT read hw/arm/smmuv3-accel: Drain the vEVENTQ when the VM stops hw/arm/smmuv3: Migrate the accelerator feature set hw/arm/smmuv3-accel: Add a helper to replay all STEs hw/arm/smmuv3-accel: Restore accelerator state on incoming migration hw/arm/smmuv3-accel: Request dirty tracking on the nesting parent hw/arm/smmuv3: Support migration with accel=onQuoted 4 lines
hw/arm/smmuv3-accel.h | 2 + include/hw/arm/smmuv3.h | 7 +- hw/arm/smmuv3-accel-stubs.c | 17 ++++ hw/arm/smmuv3-accel.c | 192++++++++++++++++++++++++++++++++++--
Quoted 3 lines
hw/arm/smmuv3.c | 6 +- 5 files changed, 210 insertions(+), 14 deletions(-)
Quoted 53 lines · Shameer Kolothum
Hi,
This series adds live migration support for an accelerated SMMUv3 (-device arm-smmuv3,accel=on) with vfio-pci endpoints on the iommufd backend.
The destination replays rather than receives. The stream table, the STEs, the CDs and the Stage 1 page tables all live in guest RAM, so once that and the registers are restored, the destination walks the stream table again and rebuilds the vDEVICE and the nested HWPT for every device.
What the series does:
- drains the kernel vEVENTQ into the guest event queue when the VM stops, so that pending fault events are not lost (1, 2)
- migrates the resolved SMMUv3 feature set in a new smmuv3/accel subsection and fails the load if the two ends differ (3)
- replays the guest stream table on the destination and restores the vEVENTQ and the GBPA HWPT (4, 5)
- asks VFIO for dirty tracking on the Stage 2 nesting parent (6)
- replaces the accel migration blocker with one scoped to CMDQV, which cannot be migrated for now (7)This depends on the host kernel supporting dirty tracking on the Stage 2 nesting parent, for assigned devices that cannot track dirty pages themselves. A branch based on Jason's iommu page table work is here [0].
Big caveat:
This is not yet tested with a real device that supports migration as I do not have a test setup for that. Folks who do have such a setup have reached out and are copied here, so hopefully this RFC lets them give it a spin and provide some early feedback.
QEMU branch is here:
https://github.com/shamiali2008/qemu-master/tree/smmuv3-accel-live-migrn-rfcv1
Please let me know your feedback.
Thanks,
Shameer
[0]: https://github.com/shamiali2008/linux/commits/iommu_pt_arm64_s2_dbm/Shameer Kolothum (7):
hw/arm/smmuv3-accel: Factor out the single vEVENT read hw/arm/smmuv3-accel: Drain the vEVENTQ when the VM stops hw/arm/smmuv3: Migrate the accelerator feature set hw/arm/smmuv3-accel: Add a helper to replay all STEs hw/arm/smmuv3-accel: Restore accelerator state on incoming migration hw/arm/smmuv3-accel: Request dirty tracking on the nesting parent hw/arm/smmuv3: Support migration with accel=on
Quoted 7 lines
hw/arm/smmuv3-accel.h | 2 + include/hw/arm/smmuv3.h | 7 +- hw/arm/smmuv3-accel-stubs.c | 17 ++++ hw/arm/smmuv3-accel.c | 192 ++++++++++++++++++++++++++++++++++-- hw/arm/smmuv3.c | 6 +- 5 files changed, 210 insertions(+), 14 deletions(-)
Hi Shameer,
Thanks for the series. I tested it on a KunPeng 920 with a HiSilicon ZIP VF passed through via VFIO, using the non-SVA accel=on path.
Environment:
- Intra-host migration only, cross-host migration not tested.
- QEMU: your smmuv3-accel-live-migrn-rfcv1 branch.
- Host kernel: your iommu_pt_arm64_s2_dbm branch, plus one local change in arm_smmu_get_httu() to fall back to the hardware IDR0 value when ACPI IORT reports HTTU as 0. No other kernel changes.
- Guest: openEuler 24.03
QEMU config (source; destination differs only by BDF and -incoming):
qemu-system-aarch64 -machine
virt,kernel_irqchip=on,gic-version=3,nvdimm=on \
-accel kvm -net none \
-device arm-smmuv3,primary-bus=pcie.0,id=smmuv3.0,accel=on \
-object iommufd,id=iommufd0 \
-device pcie-root-port,id=rp0,bus=pcie.0 \
-device vfio-pci,host=0000:31:00.1,iommufd=iommufd0,bus=rp0,enable-migration=on
Two non-SVA workloads ran in the background during migration:
# (a) sustained load:
uadk_tool benchmark --alg gzip --mode nosva --opt 0 --sync --pktlen
4096 --seconds 60 --thread 2 --multi 1
# (b) integrity: compress during migration, decompress after, sha256
compare:
kp_utools k_acc -a comp -n "compress-deflate" -s 1 -i big.bin -o
out.gz -P -l 60
kp_utools k_acc -a comp -n "decompress-deflate" -s 1 -i out.gz -o
restored
Results:
=== 1) IDR matching (normal) scenarios ===
- Patch 3: matching IDRs migrate successfully, including between two different SMMU instances.
- Patches 1/2/4/5/7: live migration under sustained non-SVA load completes; no SMMU event storm or event loss observed; STE replay and accel state restore work.
- Patch 6: S2 dirty-tracking integrity passed. The device kept doing DMA writes during migration, and the decompressed output matched the original input byte-for-byte (sha256 equal). This device has no self dirty tracking and relies on host-side S2 dirty tracking.
- Repeated/ping-pong migration on the same host also completed and the device worked afterwards.
=== 2) IDR mismatch (negative) scenario ===
- Patch 3: with mismatched IDR3 (source ril=off, destination default ril=on), the destination correctly rejects the load with "SMMUv3 IDR3 mismatch".
No errors were observed in the guest or on the host.
Quoted 149 lines
-----Original Message-----
From: Tian Zheng <[email protected]>
Sent: 31 October 2026 13:38
To: Shameer Kolothum Thodi <[email protected]>; qemu- [email protected]; [email protected]
Cc: [email protected]; [email protected]; Nicolin Chen <[email protected]>; Nathan Chen <[email protected]>; Matt Ochs <[email protected]>; Jiandi An <[email protected]>; [email protected]; Ankit Agrawal <[email protected]>; Aniket Agashe <[email protected]>; [email protected]; [email protected]; liuyonglong <[email protected]>; [email protected]
Subject: Re: [RFC PATCH 0/7] hw/arm/smmuv3: Live migration for accel=onExternal email: Use caution opening links or attachments
Quoted 6 lines · Shameer Kolothum
Hi,
This series adds live migration support for an accelerated SMMUv3 (-device arm-smmuv3,accel=on) with vfio-pci endpoints on the iommufd backend.
Quoted 8 lines
The destination replays rather than receives. The stream table, the STEs, the CDs and the Stage 1 page tables all live in guest RAM, so once that and the registers are restored, the destination walks the stream table again and rebuilds the vDEVICE and the nested HWPT for every device.
What the series does:
- drains the kernel vEVENTQ into the guest event queue when the VM
stops,
Quoted 13 lines
so that pending fault events are not lost (1, 2)
- migrates the resolved SMMUv3 feature set in a new smmuv3/accel subsection and fails the load if the two ends differ (3)
- replays the guest stream table on the destination and restores the vEVENTQ and the GBPA HWPT (4, 5)
- asks VFIO for dirty tracking on the Stage 2 nesting parent (6)
- replaces the accel migration blocker with one scoped to CMDQV, which cannot be migrated for now (7)This depends on the host kernel supporting dirty tracking on the Stage 2 nesting parent, for assigned devices that cannot track dirty pages themselves. A branch based on Jason's iommu page table work is here [0].
Quoted 10 lines
Big caveat:
This is not yet tested with a real device that supports migration as I do not have a test setup for that. Folks who do have such a setup have reached out and are copied here, so hopefully this RFC lets them give it a spin and provide some early feedback.
QEMU branch is here:
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub
.com%2Fshamiali2008%2Fqemu-master%2Ftree%2Fsmmuv3-accel-live- migrn- rfcv1&data=05%7C02%7Cskolothumtho%40nvidia.com%7C1686c4874d5c4be 3e7fe08df37543fa0%7C43083d15727340c1b7db39efd9ccc17a%7C0%7C0%7C 639290507158409428%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOn RydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ %3D%3D%7C0%7C%7C%7C&sdata=M30uWfAzPcqdeQifvQlNcaOmZzHQbalNJ uNtB9DhDPQ%3D&reserved=0Quoted 6 lines
Please let me know your feedback.
Thanks,
Shameer
[0]:https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub
.com%2Fshamiali2008%2Flinux%2Fcommits%2Fiommu_pt_arm64_s2_dbm% 2F&data=05%7C02%7Cskolothumtho%40nvidia.com%7C1686c4874d5c4be3e 7fe08df37543fa0%7C43083d15727340c1b7db39efd9ccc17a%7C0%7C0%7C63 9290507158463751%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRy dWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3 D%3D%7C0%7C%7C%7C&sdata=HO9UHPTS%2FWKbQnGf8DKsDy6oGrFYvNB uw%2BZ4uh3ZDJ8%3D&reserved=0Quoted 10 lines
Shameer Kolothum (7):
hw/arm/smmuv3-accel: Factor out the single vEVENT read hw/arm/smmuv3-accel: Drain the vEVENTQ when the VM stops hw/arm/smmuv3: Migrate the accelerator feature set hw/arm/smmuv3-accel: Add a helper to replay all STEs hw/arm/smmuv3-accel: Restore accelerator state on incoming migration hw/arm/smmuv3-accel: Request dirty tracking on the nesting parent hw/arm/smmuv3: Support migration with accel=onQuoted 4 lines
hw/arm/smmuv3-accel.h | 2 + include/hw/arm/smmuv3.h | 7 +- hw/arm/smmuv3-accel-stubs.c | 17 ++++ hw/arm/smmuv3-accel.c | 192++++++++++++++++++++++++++++++++++--
Quoted 3 lines
hw/arm/smmuv3.c | 6 +- 5 files changed, 210 insertions(+), 14 deletions(-)Hi Shameer,
Thanks for the series. I tested it on a KunPeng 920 with a HiSilicon ZIP VF passed through via VFIO, using the non-SVA accel=on path.
Environment:
- Intra-host migration only, cross-host migration not tested.
- QEMU: your smmuv3-accel-live-migrn-rfcv1 branch.
- Host kernel: youriommu_pt_arm64_s2_dbmbranch, plus one local change inarm_smmu_get_httu()to fall back to the hardware IDR0 value when ACPI IORT reports HTTU as 0. No other kernel changes.
- Guest: openEuler 24.03QEMU config (source; destination differs only by BDF and -incoming):
qemu-system-aarch64 -machinevirt,kernel_irqchip=on,gic-version=3,nvdimm=on \ -accel kvm -net none \ -device arm-smmuv3,primary-bus=pcie.0,id=smmuv3.0,accel=on \ -object iommufd,id=iommufd0 \ -device pcie-root-port,id=rp0,bus=pcie.0 \ -devicevfio-pci,host=0000:31:00.1,iommufd=iommufd0,bus=rp0,enable- migration=on
Two non-SVA workloads ran in the background during migration:
# (a) sustained load:uadk_tool benchmark --alg gzip --mode nosva --opt 0 --sync --pktlen4096 --seconds 60 --thread 2 --multi 1
# (b) integrity: compress during migration, decompress after, sha256
compare:
kp_utoolsk_acc-a comp -n "compress-deflate" -s 1 -i big.bin -o
out.gz -P -l 60
kp_utoolsk_acc-a comp -n "decompress-deflate" -s 1 -i out.gz -o
restoredResults:
=== 1) IDR matching (normal) scenarios ===
- Patch 3: matching IDRs migrate successfully, including between two different SMMU instances.
- Patches 1/2/4/5/7: live migration under sustained non-SVA load completes; no SMMU event storm or event loss observed; STE replay and accel state restore work.
- Patch 6: S2 dirty-tracking integrity passed. The device kept doing DMA writes during migration, and the decompressed output matched the original input byte-for-byte (sha256 equal). This device has no self dirty tracking and relies on host-side S2 dirty tracking.
- Repeated/ping-pong migration on the same host also completed and the device worked afterwards.
Quoted 8 lines
=== 2) IDR mismatch (negative) scenario ===
- Patch 3: with mismatched IDR3 (source ril=off, destination default ril=on), the destination correctly rejects the load with "SMMUv3 IDR3 mismatch".No errors were observed in the guest or on the host.
Tested-by Tian Zheng <[email protected]>
Hi Tian,
Thanks for testing and the detailed results. Good to see this working with a real device. I will refresh the series, addressing Eric's feedback as well.
Thanks,
Shameer
Quoted 158 lines · Shameer Kolothum Thodi
Quoted 149 lines
-----Original Message-----
From: Tian Zheng <[email protected]>
Sent: 31 October 2026 13:38
To: Shameer Kolothum Thodi <[email protected]>; qemu- [email protected]; [email protected]
Cc: [email protected]; [email protected]; Nicolin Chen <[email protected]>; Nathan Chen <[email protected]>; Matt Ochs <[email protected]>; Jiandi An <[email protected]>; [email protected]; Ankit Agrawal <[email protected]>; Aniket Agashe <[email protected]>; [email protected]; [email protected]; liuyonglong <[email protected]>; [email protected]
Subject: Re: [RFC PATCH 0/7] hw/arm/smmuv3: Live migration for accel=onExternal email: Use caution opening links or attachments
Quoted 6 lines · Shameer Kolothum
Hi,
This series adds live migration support for an accelerated SMMUv3 (-device arm-smmuv3,accel=on) with vfio-pci endpoints on the iommufd backend.
Quoted 8 lines
The destination replays rather than receives. The stream table, the STEs, the CDs and the Stage 1 page tables all live in guest RAM, so once that and the registers are restored, the destination walks the stream table again and rebuilds the vDEVICE and the nested HWPT for every device.
What the series does:
- drains the kernel vEVENTQ into the guest event queue when the VM
stops,
Quoted 13 lines
so that pending fault events are not lost (1, 2)
- migrates the resolved SMMUv3 feature set in a new smmuv3/accel subsection and fails the load if the two ends differ (3)
- replays the guest stream table on the destination and restores the vEVENTQ and the GBPA HWPT (4, 5)
- asks VFIO for dirty tracking on the Stage 2 nesting parent (6)
- replaces the accel migration blocker with one scoped to CMDQV, which cannot be migrated for now (7)This depends on the host kernel supporting dirty tracking on the Stage 2 nesting parent, for assigned devices that cannot track dirty pages themselves. A branch based on Jason's iommu page table work is here [0].
Quoted 10 lines
Big caveat:
This is not yet tested with a real device that supports migration as I do not have a test setup for that. Folks who do have such a setup have reached out and are copied here, so hopefully this RFC lets them give it a spin and provide some early feedback.
QEMU branch is here:
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub
.com%2Fshamiali2008%2Fqemu-master%2Ftree%2Fsmmuv3-accel-live- migrn- rfcv1&data=05%7C02%7Cskolothumtho%40nvidia.com%7C1686c4874d5c4be 3e7fe08df37543fa0%7C43083d15727340c1b7db39efd9ccc17a%7C0%7C0%7C 639290507158409428%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOn RydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ %3D%3D%7C0%7C%7C%7C&sdata=M30uWfAzPcqdeQifvQlNcaOmZzHQbalNJ uNtB9DhDPQ%3D&reserved=0Quoted 6 lines
Please let me know your feedback.
Thanks,
Shameer
[0]:https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub
.com%2Fshamiali2008%2Flinux%2Fcommits%2Fiommu_pt_arm64_s2_dbm% 2F&data=05%7C02%7Cskolothumtho%40nvidia.com%7C1686c4874d5c4be3e 7fe08df37543fa0%7C43083d15727340c1b7db39efd9ccc17a%7C0%7C0%7C63 9290507158463751%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRy dWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3 D%3D%7C0%7C%7C%7C&sdata=HO9UHPTS%2FWKbQnGf8DKsDy6oGrFYvNB uw%2BZ4uh3ZDJ8%3D&reserved=0Quoted 10 lines
Shameer Kolothum (7):
hw/arm/smmuv3-accel: Factor out the single vEVENT read hw/arm/smmuv3-accel: Drain the vEVENTQ when the VM stops hw/arm/smmuv3: Migrate the accelerator feature set hw/arm/smmuv3-accel: Add a helper to replay all STEs hw/arm/smmuv3-accel: Restore accelerator state on incoming migration hw/arm/smmuv3-accel: Request dirty tracking on the nesting parent hw/arm/smmuv3: Support migration with accel=onQuoted 4 lines
hw/arm/smmuv3-accel.h | 2 + include/hw/arm/smmuv3.h | 7 +- hw/arm/smmuv3-accel-stubs.c | 17 ++++ hw/arm/smmuv3-accel.c | 192++++++++++++++++++++++++++++++++++--
Quoted 3 lines
hw/arm/smmuv3.c | 6 +- 5 files changed, 210 insertions(+), 14 deletions(-)Hi Shameer,
Thanks for the series. I tested it on a KunPeng 920 with a HiSilicon ZIP VF passed through via VFIO, using the non-SVA accel=on path.
Environment:
- Intra-host migration only, cross-host migration not tested.
- QEMU: your smmuv3-accel-live-migrn-rfcv1 branch.
- Host kernel: youriommu_pt_arm64_s2_dbmbranch, plus one local change inarm_smmu_get_httu()to fall back to the hardware IDR0 value when ACPI IORT reports HTTU as 0. No other kernel changes.
- Guest: openEuler 24.03QEMU config (source; destination differs only by BDF and -incoming):
qemu-system-aarch64 -machinevirt,kernel_irqchip=on,gic-version=3,nvdimm=on \ -accel kvm -net none \ -device arm-smmuv3,primary-bus=pcie.0,id=smmuv3.0,accel=on \ -object iommufd,id=iommufd0 \ -device pcie-root-port,id=rp0,bus=pcie.0 \ -devicevfio-pci,host=0000:31:00.1,iommufd=iommufd0,bus=rp0,enable- migration=on
Two non-SVA workloads ran in the background during migration:
# (a) sustained load:
uadk_toolbenchmark --alg gzip --mode nosva --opt 0 --sync --pktlen
4096 --seconds 60 --thread 2 --multi 1
# (b) integrity: compress during migration, decompress after, sha256
compare:
kp_utoolsk_acc-a comp -n "compress-deflate" -s 1 -i big.bin -o
out.gz -P -l 60
kp_utoolsk_acc-a comp -n "decompress-deflate" -s 1 -i out.gz -o
restoredResults:
=== 1) IDR matching (normal) scenarios ===
- Patch 3: matching IDRs migrate successfully, including between two different SMMU instances.
- Patches 1/2/4/5/7: live migration under sustained non-SVA load completes; no SMMU event storm or event loss observed; STE replay and accel state restore work.
- Patch 6: S2 dirty-tracking integrity passed. The device kept doing DMA writes during migration, and the decompressed output matched the original input byte-for-byte (sha256 equal). This device has no self dirty tracking and relies on host-side S2 dirty tracking.
- Repeated/ping-pong migration on the same host also completed and the device worked afterwards.Quoted 8 lines
=== 2) IDR mismatch (negative) scenario ===
- Patch 3: with mismatched IDR3 (source ril=off, destination default ril=on), the destination correctly rejects the load with "SMMUv3 IDR3 mismatch".No errors were observed in the guest or on the host.
Tested-by Tian Zheng <[email protected]>
Quoted 8 lines
Hi Tian,
Thanks for testing and the detailed results. Good to see this working with a real device. I will refresh the series, addressing Eric's feedback as well.
Thanks,
Shameer
Hi Shameer,
Thanks for the update. Glad the testing was useful. I'd be happy to re-test the refreshed series once it's posted. Please keep me Cc'ed and I'll report back.
Thanks,
Tian