qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] intel-iommu: update root_scalable before switching as during post_load
@ 2022-03-17  8:05 Jason Wang
  2022-03-17  8:05 ` [PATCH 2/2] intel-iommu: update iq_dw during post load Jason Wang
  2022-03-18  7:29 ` [PATCH 1/2] intel-iommu: update root_scalable before switching as during post_load Peter Xu
  0 siblings, 2 replies; 4+ messages in thread
From: Jason Wang @ 2022-03-17  8:05 UTC (permalink / raw)
  To: mst, peterx; +Cc: Jason Wang, qemu-devel

We need check whether passthrough is enabled during
vtd_switch_address_space() by checking the context entries. This
requires the root_scalable to be set correctly otherwise we may try to
check legacy rsvd bits instead of scalable ones.

Fixing this by updating root_scalable before switching the address
spaces during post_load.

Fixes: fb43cf739e ("intel_iommu: scalable mode emulation")
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 hw/i386/intel_iommu.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index 32471a44cb..a13cfecfce 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -3052,13 +3052,6 @@ static int vtd_post_load(void *opaque, int version_id)
 {
     IntelIOMMUState *iommu = opaque;
 
-    /*
-     * 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);
-
     /*
      * We don't need to migrate the root_scalable because we can
      * simply do the calculation after the loading is complete.  We
@@ -3068,6 +3061,13 @@ static int vtd_post_load(void *opaque, int version_id)
      */
     vtd_update_scalable_state(iommu);
 
+    /*
+     * 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;
 }
 
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] intel-iommu: update iq_dw during post load
  2022-03-17  8:05 [PATCH 1/2] intel-iommu: update root_scalable before switching as during post_load Jason Wang
@ 2022-03-17  8:05 ` Jason Wang
  2022-03-18  7:30   ` Peter Xu
  2022-03-18  7:29 ` [PATCH 1/2] intel-iommu: update root_scalable before switching as during post_load Peter Xu
  1 sibling, 1 reply; 4+ messages in thread
From: Jason Wang @ 2022-03-17  8:05 UTC (permalink / raw)
  To: mst, peterx; +Cc: Jason Wang, qemu-devel

We need to update iq_dw according to the DMA_IRQ_REG during post
load. Otherwise we may get wrong IOTLB invalidation descriptor after
migration.

Fixes: fb43cf739e ("intel_iommu: scalable mode emulation")
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 hw/i386/intel_iommu.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index a13cfecfce..c58f603b72 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -181,6 +181,18 @@ static void vtd_update_scalable_state(IntelIOMMUState *s)
     }
 }
 
+static void vtd_update_iq_dw(IntelIOMMUState *s)
+{
+    uint64_t val = vtd_get_quad_raw(s, DMAR_IQA_REG);
+
+    if (s->ecap & VTD_ECAP_SMTS &&
+        val & VTD_IQA_DW_MASK) {
+        s->iq_dw = true;
+    } else {
+        s->iq_dw = false;
+    }
+}
+
 /* Whether the address space needs to notify new mappings */
 static inline gboolean vtd_as_has_map_notifier(VTDAddressSpace *as)
 {
@@ -2883,12 +2895,7 @@ static void vtd_mem_write(void *opaque, hwaddr addr,
         } else {
             vtd_set_quad(s, addr, val);
         }
-        if (s->ecap & VTD_ECAP_SMTS &&
-            val & VTD_IQA_DW_MASK) {
-            s->iq_dw = true;
-        } else {
-            s->iq_dw = false;
-        }
+        vtd_update_iq_dw(s);
         break;
 
     case DMAR_IQA_REG_HI:
@@ -3061,6 +3068,8 @@ static int vtd_post_load(void *opaque, int version_id)
      */
     vtd_update_scalable_state(iommu);
 
+    vtd_update_iq_dw(iommu);
+
     /*
      * Memory regions are dynamically turned on/off depending on
      * context entry configurations from the guest. After migration,
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] intel-iommu: update root_scalable before switching as during post_load
  2022-03-17  8:05 [PATCH 1/2] intel-iommu: update root_scalable before switching as during post_load Jason Wang
  2022-03-17  8:05 ` [PATCH 2/2] intel-iommu: update iq_dw during post load Jason Wang
@ 2022-03-18  7:29 ` Peter Xu
  1 sibling, 0 replies; 4+ messages in thread
From: Peter Xu @ 2022-03-18  7:29 UTC (permalink / raw)
  To: Jason Wang; +Cc: qemu-devel, mst

On Thu, Mar 17, 2022 at 04:05:21PM +0800, Jason Wang wrote:
> We need check whether passthrough is enabled during
> vtd_switch_address_space() by checking the context entries. This
> requires the root_scalable to be set correctly otherwise we may try to
> check legacy rsvd bits instead of scalable ones.
> 
> Fixing this by updating root_scalable before switching the address
> spaces during post_load.
> 
> Fixes: fb43cf739e ("intel_iommu: scalable mode emulation")
> Signed-off-by: Jason Wang <jasowang@redhat.com>

Reviewed-by: Peter Xu <peterx@redhat.com>

-- 
Peter Xu



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] intel-iommu: update iq_dw during post load
  2022-03-17  8:05 ` [PATCH 2/2] intel-iommu: update iq_dw during post load Jason Wang
@ 2022-03-18  7:30   ` Peter Xu
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Xu @ 2022-03-18  7:30 UTC (permalink / raw)
  To: Jason Wang; +Cc: qemu-devel, mst

On Thu, Mar 17, 2022 at 04:05:22PM +0800, Jason Wang wrote:
> We need to update iq_dw according to the DMA_IRQ_REG during post
> load. Otherwise we may get wrong IOTLB invalidation descriptor after
> migration.
> 
> Fixes: fb43cf739e ("intel_iommu: scalable mode emulation")
> Signed-off-by: Jason Wang <jasowang@redhat.com>

Reviewed-by: Peter Xu <peterx@redhat.com>

-- 
Peter Xu



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-03-18  7:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-17  8:05 [PATCH 1/2] intel-iommu: update root_scalable before switching as during post_load Jason Wang
2022-03-17  8:05 ` [PATCH 2/2] intel-iommu: update iq_dw during post load Jason Wang
2022-03-18  7:30   ` Peter Xu
2022-03-18  7:29 ` [PATCH 1/2] intel-iommu: update root_scalable before switching as during post_load Peter Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).