iommu/amd: Restore IRTE.RemapEn bit for amd_iommu_activate_guest_mode
Subsystems (2)
Suravee Suthikulpanit
reviewerPATCH v2 1/1 iommu/amd: Restore IRTE.RemapEn bit for amd_iommu_activate_guest_mode
Commit e52d58d54a32 ("iommu/amd: Use cmpxchg_double() when updating 128-bit IRTE") removed an assumption that modify_irte_ga always set the valid bit, which requires the callers to set the appropriate value for the struct irte_ga.valid bit before calling the function.
Similar to the commit 26e495f34107 ("iommu/amd: Restore IRTE.RemapEn bit after programming IRTE"), which is for the function amd_iommu_deactivate_guest_mode().
The same change is also needed for the amd_iommu_activate_guest_mode(). Otherwise, this could trigger IO_PAGE_FAULT for the VFIO based VMs with AVIC enabled.
--- drivers/iommu/amd/iommu.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/iommu/amd/iommu.c +4 -0
@@ -3900,14 +3900,18 @@ int amd_iommu_activate_guest_mode(void *data) {struct amd_ir_data *ir_data = (struct amd_ir_data *)data;struct irte_ga *entry = (struct irte_ga *) ir_data->entry; +u64 valid;if (!AMD_IOMMU_GUEST_IR_VAPIC (amd_iommu_guest_ir) || !entry || entry->lo.fields_vapic.guest_mode)return 0 ; + valid = entry->lo.fields_vapic.valid; + entry->lo.val =0 ; entry->hi.val =0 ; + entry->lo.fields_vapic.valid = valid; entry->lo.fields_vapic.guest_mode =1 ; entry->lo.fields_vapic.ga_log_intr =1 ; entry->hi.fields.ga_root_ptr = ir_data->ga_root_ptr;
Signature · 6 lines
2.17.1 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Quoted 35 lines · Suravee Suthikulpanit
Commit
e52d58d54a32("iommu/amd: Usecmpxchg_double()when updating 128-bit IRTE") removed an assumption thatmodify_irte_gaalways set the valid bit, which requires the callers to set the appropriate value for the struct irte_ga.valid bit before calling the function.Similar to the commit
26e495f34107("iommu/amd: Restore IRTE.RemapEn bit after programming IRTE"), which is for the functionamd_iommu_deactivate_guest_mode().The same change is also needed for the
amd_iommu_activate_guest_mode(). Otherwise, this could triggerIO_PAGE_FAULTfor the VFIO based VMs with AVIC enabled.Reported-by Maxim Levitsky <[email protected]>Tested-by Maxim Levitsky <[email protected]>Cc Joao Martins <[email protected]>Fixes e52d58d54a321 ("iommu/amd: Use cmpxchg_double() when updating 128-bit IRTE")Signed-off-by Suravee Suthikulpanit <[email protected]>--- drivers/iommu/amd/iommu.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/iommu/amd/iommu.c +1
-0@@ -3900,14 +3900,18 @@ int amd_iommu_activate_guest_mode(void *data) {struct amd_ir_data *ir_data = (struct amd_ir_data *)data;struct irte_ga *entry = (struct irte_ga *) ir_data->entry; +u64 valid;if (!AMD_IOMMU_GUEST_IR_VAPIC (amd_iommu_guest_ir) || !entry || entry->lo.fields_vapic.guest_mode)return 0 ;
drivers/iommu/amd/iommu.c int amd_iommu_activate_guest_mode(void *data) · line 3917
Quoted 10 lines
drivers/iommu/amd/iommu.c +3
-0+ valid = entry->lo.fields_vapic.valid; + entry->lo.val =0 ; entry->hi.val =0 ; + entry->lo.fields_vapic.valid = valid; entry->lo.fields_vapic.guest_mode =1 ; entry->lo.fields_vapic.ga_log_intr =1 ; entry->hi.fields.ga_root_ptr = ir_data->ga_root_ptr;
Best regards,
Maxim Levitsky
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Quoted 36 lines · Suravee Suthikulpanit
Commit
e52d58d54a32("iommu/amd: Usecmpxchg_double()when updating 128-bit IRTE") removed an assumption thatmodify_irte_gaalways set the valid bit, which requires the callers to set the appropriate value for the struct irte_ga.valid bit before calling the function.Similar to the commit
26e495f34107("iommu/amd: Restore IRTE.RemapEn bit after programming IRTE"), which is for the functionamd_iommu_deactivate_guest_mode().The same change is also needed for the
amd_iommu_activate_guest_mode(). Otherwise, this could triggerIO_PAGE_FAULTfor the VFIO based VMs with AVIC enabled.Reported-by Maxim Levitsky <[email protected]>Tested-by Maxim Levitsky <[email protected]>Cc Joao Martins <[email protected]>Fixes e52d58d54a321 ("iommu/amd: Use cmpxchg_double() when updating 128-bit IRTE")Signed-off-by Suravee Suthikulpanit <[email protected]>--- drivers/iommu/amd/iommu.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/iommu/amd/iommu.c +1
-0@@ -3900,14 +3900,18 @@ int amd_iommu_activate_guest_mode(void *data) {struct amd_ir_data *ir_data = (struct amd_ir_data *)data;struct irte_ga *entry = (struct irte_ga *) ir_data->entry; +u64 valid;if (!AMD_IOMMU_GUEST_IR_VAPIC (amd_iommu_guest_ir) || !entry || entry->lo.fields_vapic.guest_mode)return 0 ;
drivers/iommu/amd/iommu.c int amd_iommu_activate_guest_mode(void *data) · line 3917
Quoted 10 lines
drivers/iommu/amd/iommu.c +3
-0+ valid = entry->lo.fields_vapic.valid; + entry->lo.val =0 ; entry->hi.val =0 ; + entry->lo.fields_vapic.valid = valid; entry->lo.fields_vapic.guest_mode =1 ; entry->lo.fields_vapic.ga_log_intr =1 ; entry->hi.fields.ga_root_ptr = ir_data->ga_root_ptr;
FWIW,
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Joerg Roedel
maintainerQuoted 13 lines · Suravee Suthikulpanit
Commit
e52d58d54a32("iommu/amd: Usecmpxchg_double()when updating 128-bit IRTE") removed an assumption thatmodify_irte_gaalways set the valid bit, which requires the callers to set the appropriate value for the struct irte_ga.valid bit before calling the function.Similar to the commit
26e495f34107("iommu/amd: Restore IRTE.RemapEn bit after programming IRTE"), which is for the functionamd_iommu_deactivate_guest_mode().The same change is also needed for the
amd_iommu_activate_guest_mode(). Otherwise, this could triggerIO_PAGE_FAULTfor the VFIO based VMs with AVIC enabled.
Quoted 8 lines
Reported-by Maxim Levitsky <[email protected]>Tested-by Maxim Levitsky <[email protected]>Cc Joao Martins <[email protected]>Fixes e52d58d54a321 ("iommu/amd: Use cmpxchg_double() when updating 128-bit IRTE")Signed-off-by Suravee Suthikulpanit <[email protected]>--- drivers/iommu/amd/iommu.c | 4 ++++ 1 file changed, 4 insertions(+)
Applied for v5.9, thanks.