Skip to contentSkip to conversation

exec: address space translation cleanups

PATCH Applied Peter Xu 4 participants 20 messages May 15, 2017 – May 17, 2017

lore
Share & tools
lore

Peter Xu

author
#0 lore raw

cover exec: address space translation cleanups

The problem is that, address_space_get_iotlb_entry() shares a lot with address_space_translate(). This patch tries to abstract the shared elements.

Originally, this work is derived from discussion from VT-d passthrough series discussions [1]. But for sure we can just see this series as a standalone cleanup. So I posted it separately here.

Smoke tests are done with general VM boots, IOs, especially with vhost dmar configurations.

I believe with current series I can throw away the old patch [1], which may be good. But before that, please kindly review. Thanks.

References:

[1] https://lists.gnu.org/archive/html/qemu-devel/2017-05/msg02335.html

Peter Xu (4):
exec: simplify phys_page_find() params
exec: rename resolve_subpage
exec: further use is_mmio
exec: abstract address_space_do_translate()

 exec.c | 122 ++++++++++++++++++++++++++++++++++++++++-------------------------
 1 file changed, 76 insertions(+), 46 deletions(-)
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH 1/4 exec: simplify phys_page_find() params

It really only plays with the dispatchers, so the parameter list does not need that complexity. This helps for readability at least.

---
 exec.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
exec.c +6 -7
index eac6085..1d76c63 100644
@@ -371,10 +371,11 @@ static inline bool section_covers_addr(const MemoryRegionSection *section,
                              int128_getlo(section->size), addr);
 }
 
-static MemoryRegionSection *phys_page_find(PhysPageEntry lp, hwaddr addr,
-                                           Node *nodes, MemoryRegionSection *sections)
+static MemoryRegionSection *phys_page_find(AddressSpaceDispatch *d, hwaddr addr)
 {
-    PhysPageEntry *p;
+    PhysPageEntry lp = d->phys_map, *p;
+    Node *nodes = d->map.nodes;
+    MemoryRegionSection *sections = d->map.sections;
     hwaddr index = addr >> TARGET_PAGE_BITS;
     int i;
 
@@ -412,8 +413,7 @@ static MemoryRegionSection *address_space_lookup_region(AddressSpaceDispatch *d,
         section_covers_addr(section, addr)) {
         update = false;
     } else {
-        section = phys_page_find(d->phys_map, addr, d->map.nodes,
-                                 d->map.sections);
+        section = phys_page_find(d, addr);
         update = true;
     }
     if (resolve_subpage && section->mr->subpage) {
@@ -1246,8 +1246,7 @@ static void register_subpage(AddressSpaceDispatch *d, MemoryRegionSection *secti
     subpage_t *subpage;
     hwaddr base = section->offset_within_address_space
         & TARGET_PAGE_MASK;
-    MemoryRegionSection *existing = phys_page_find(d->phys_map, base,
-                                                   d->map.nodes, d->map.sections);
+    MemoryRegionSection *existing = phys_page_find(d, base);
     MemoryRegionSection subsection = {
         .offset_within_address_space = base,
         .size = int128_make64(TARGET_PAGE_SIZE),
Signature · 1 line
2.7.4
Reviewed-by on v1 1/4
#2 lore raw

Re: [Qemu-devel] [PATCH 1/4] exec: simplify phys_page_find() params

Quoted 4 lines · Peter Xu

It really only plays with the dispatchers, so the parameter list does not need that complexity. This helps for readability at least.

Quoted 43 lines
---
 exec.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
exec.c +6 -7
index eac6085..1d76c63 100644
@@ -371,10 +371,11 @@ static inline bool section_covers_addr(const MemoryRegionSection *section,
                              int128_getlo(section->size), addr);
 }
 
-static MemoryRegionSection *phys_page_find(PhysPageEntry lp, hwaddr addr,
-                                           Node *nodes, MemoryRegionSection *sections)
+static MemoryRegionSection *phys_page_find(AddressSpaceDispatch *d, hwaddr addr)
 {
-    PhysPageEntry *p;
+    PhysPageEntry lp = d->phys_map, *p;
+    Node *nodes = d->map.nodes;
+    MemoryRegionSection *sections = d->map.sections;
     hwaddr index = addr >> TARGET_PAGE_BITS;
     int i;
 
@@ -412,8 +413,7 @@ static MemoryRegionSection *address_space_lookup_region(AddressSpaceDispatch *d,
         section_covers_addr(section, addr)) {
         update = false;
     } else {
-        section = phys_page_find(d->phys_map, addr, d->map.nodes,
-                                 d->map.sections);
+        section = phys_page_find(d, addr);
         update = true;
     }
     if (resolve_subpage && section->mr->subpage) {
@@ -1246,8 +1246,7 @@ static void register_subpage(AddressSpaceDispatch *d, MemoryRegionSection *secti
     subpage_t *subpage;
     hwaddr base = section->offset_within_address_space
         & TARGET_PAGE_MASK;
-    MemoryRegionSection *existing = phys_page_find(d->phys_map, base,
-                                                   d->map.nodes, d->map.sections);
+    MemoryRegionSection *existing = phys_page_find(d, base);
     MemoryRegionSection subsection = {
         .offset_within_address_space = base,
         .size = int128_make64(TARGET_PAGE_SIZE),
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#3 lore raw

Re: [Qemu-devel] [PATCH 1/4] exec: simplify phys_page_find() params

Quoted 7 lines · David Gibson
Quoted 4 lines · Peter Xu

It really only plays with the dispatchers, so the parameter list does not need that complexity. This helps for readability at least.

Queued, thanks.

Paolo

Quoted 45 lines
Quoted 44 lines
---
 exec.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
exec.c +6 -7
index eac6085..1d76c63 100644
@@ -371,10 +371,11 @@ static inline bool section_covers_addr(const MemoryRegionSection *section,
                              int128_getlo(section->size), addr);
 }
 
-static MemoryRegionSection *phys_page_find(PhysPageEntry lp, hwaddr addr,
-                                           Node *nodes, MemoryRegionSection *sections)
+static MemoryRegionSection *phys_page_find(AddressSpaceDispatch *d, hwaddr addr)
 {
-    PhysPageEntry *p;
+    PhysPageEntry lp = d->phys_map, *p;
+    Node *nodes = d->map.nodes;
+    MemoryRegionSection *sections = d->map.sections;
     hwaddr index = addr >> TARGET_PAGE_BITS;
     int i;
 
@@ -412,8 +413,7 @@ static MemoryRegionSection *address_space_lookup_region(AddressSpaceDispatch *d,
         section_covers_addr(section, addr)) {
         update = false;
     } else {
-        section = phys_page_find(d->phys_map, addr, d->map.nodes,
-                                 d->map.sections);
+        section = phys_page_find(d, addr);
         update = true;
     }
     if (resolve_subpage && section->mr->subpage) {
@@ -1246,8 +1246,7 @@ static void register_subpage(AddressSpaceDispatch *d, MemoryRegionSection *secti
     subpage_t *subpage;
     hwaddr base = section->offset_within_address_space
         & TARGET_PAGE_MASK;
-    MemoryRegionSection *existing = phys_page_find(d->phys_map, base,
-                                                   d->map.nodes, d->map.sections);
+    MemoryRegionSection *existing = phys_page_find(d, base);
     MemoryRegionSection subsection = {
         .offset_within_address_space = base,
         .size = int128_make64(TARGET_PAGE_SIZE),
author
#4 lore raw

PATCH 2/4 exec: rename resolve_subpage

In reply to Peter Xu

It is not easy for people to know "what this parameter does" before knowing "what is subpage". Let's use "is_mmio" to make it easier to understand.

---
 exec.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
exec.c +4 -4
index 1d76c63..0adae94 100644
@@ -403,7 +403,7 @@ bool memory_region_is_unassigned(MemoryRegion *mr)
 /* Called from RCU critical section */
 static MemoryRegionSection *address_space_lookup_region(AddressSpaceDispatch *d,
                                                         hwaddr addr,
-                                                        bool resolve_subpage)
+                                                        bool is_mmio)
 {
     MemoryRegionSection *section = atomic_read(&d->mru_section);
     subpage_t *subpage;
@@ -416,7 +416,7 @@ static MemoryRegionSection *address_space_lookup_region(AddressSpaceDispatch *d,
         section = phys_page_find(d, addr);
         update = true;
     }
-    if (resolve_subpage && section->mr->subpage) {
+    if (is_mmio && section->mr->subpage) {
         subpage = container_of(section->mr, subpage_t, iomem);
         section = &d->map.sections[subpage->sub_section[SUBPAGE_IDX(addr)]];
     }
@@ -429,13 +429,13 @@ static MemoryRegionSection *address_space_lookup_region(AddressSpaceDispatch *d,
 /* Called from RCU critical section */
 static MemoryRegionSection *
 address_space_translate_internal(AddressSpaceDispatch *d, hwaddr addr, hwaddr *xlat,
-                                 hwaddr *plen, bool resolve_subpage)
+                                 hwaddr *plen, bool is_mmio)
 {
     MemoryRegionSection *section;
     MemoryRegion *mr;
     Int128 diff;
 
-    section = address_space_lookup_region(d, addr, resolve_subpage);
+    section = address_space_lookup_region(d, addr, is_mmio);
     /* Compute offset within MemoryRegionSection */
     addr -= section->offset_within_address_space;
 
Signature · 1 line
2.7.4
#5 lore raw

Re: [Qemu-devel] [PATCH 2/4] exec: rename resolve_subpage

Quoted 5 lines · Peter Xu

It is not easy for people to know "what this parameter does" before knowing "what is subpage". Let's use "is_mmio" to make it easier to understand.

Maybe invert the direction and call it for_iotlb?

Paolo

Quoted 43 lines
---
 exec.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
exec.c +4 -4
index 1d76c63..0adae94 100644
@@ -403,7 +403,7 @@ bool memory_region_is_unassigned(MemoryRegion *mr)
 /* Called from RCU critical section */
 static MemoryRegionSection *address_space_lookup_region(AddressSpaceDispatch *d,
                                                         hwaddr addr,
-                                                        bool resolve_subpage)
+                                                        bool is_mmio)
 {
     MemoryRegionSection *section = atomic_read(&d->mru_section);
     subpage_t *subpage;
@@ -416,7 +416,7 @@ static MemoryRegionSection *address_space_lookup_region(AddressSpaceDispatch *d,
         section = phys_page_find(d, addr);
         update = true;
     }
-    if (resolve_subpage && section->mr->subpage) {
+    if (is_mmio && section->mr->subpage) {
         subpage = container_of(section->mr, subpage_t, iomem);
         section = &d->map.sections[subpage->sub_section[SUBPAGE_IDX(addr)]];
     }
@@ -429,13 +429,13 @@ static MemoryRegionSection *address_space_lookup_region(AddressSpaceDispatch *d,
 /* Called from RCU critical section */
 static MemoryRegionSection *
 address_space_translate_internal(AddressSpaceDispatch *d, hwaddr addr, hwaddr *xlat,
-                                 hwaddr *plen, bool resolve_subpage)
+                                 hwaddr *plen, bool is_mmio)
 {
     MemoryRegionSection *section;
     MemoryRegion *mr;
     Int128 diff;
 
-    section = address_space_lookup_region(d, addr, resolve_subpage);
+    section = address_space_lookup_region(d, addr, is_mmio);
     /* Compute offset within MemoryRegionSection */
     addr -= section->offset_within_address_space;
 
author
#6 lore raw

Re: [Qemu-devel] [PATCH 2/4] exec: rename resolve_subpage

Quoted 10 lines · Paolo Bonzini
Quoted 5 lines · Peter Xu

It is not easy for people to know "what this parameter does" before knowing "what is subpage". Let's use "is_mmio" to make it easier to understand.

Maybe invert the direction and call it for_iotlb?

I wasn't aware that tcg is using resolve_subpage==false always. Then at least is_mmio does not suite here. I am not sure whether for-iotlb suites here either... So maybe I will just drop this patch as well, just like patch 3.

Thanks for reviewing it!

Signature · 1 line
Peter Xu
author
#7 lore raw

PATCH 3/4 exec: further use is_mmio

In reply to Peter Xu

This is MMIO-specific tunes on the size. Let's skip it for non-MMIO translations.

---
 exec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
exec.c +1 -1
index 0adae94..32e5394 100644
@@ -455,7 +455,7 @@ address_space_translate_internal(AddressSpaceDispatch *d, hwaddr addr, hwaddr *x
      * everything works fine.  If the incoming length is large, however,
      * the caller really has to do the clamping through memory_access_size.
      */
-    if (memory_region_is_ram(mr)) {
+    if (is_mmio && memory_region_is_ram(mr)) {
         diff = int128_sub(section->size, int128_make64(addr));
         *plen = int128_get64(int128_min(diff, int128_make64(*plen)));
     }
Signature · 1 line
2.7.4
#8 lore raw

Re: [Qemu-devel] [PATCH 3/4] exec: further use is_mmio

Quoted 2 lines · Peter Xu

This is MMIO-specific tunes on the size. Let's skip it for non-MMIO translations.

Can you explain this better? This is not specific to MMIO, in fact it's for RAM...

Paolo

Quoted 17 lines
---
 exec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
exec.c +1 -1
index 0adae94..32e5394 100644
@@ -455,7 +455,7 @@ address_space_translate_internal(AddressSpaceDispatch *d, hwaddr addr, hwaddr *x
      * everything works fine.  If the incoming length is large, however,
      * the caller really has to do the clamping through memory_access_size.
      */
-    if (memory_region_is_ram(mr)) {
+    if (is_mmio && memory_region_is_ram(mr)) {
         diff = int128_sub(section->size, int128_make64(addr));
         *plen = int128_get64(int128_min(diff, int128_make64(*plen)));
author
#9 lore raw

Re: [Qemu-devel] [PATCH 3/4] exec: further use is_mmio

Quoted 8 lines · Paolo Bonzini
Quoted 2 lines · Peter Xu

This is MMIO-specific tunes on the size. Let's skip it for non-MMIO translations.

Can you explain this better? This is not specific to MMIO, in fact it's for RAM...

Yes, I misread the codes and comments, sorry...

Please ignore this patch.

Signature · 1 line
Peter Xu
author
#10 lore raw

PATCH 4/4 exec: abstract address_space_do_translate()

In reply to Peter Xu

This function is an abstraction helper for address_space_translate() and address_space_get_iotlb_entry(). It does the lookup of address into memory region section, then do proper IOMMU translation if necessary. With that, refactor the two existing functions a bit to use it.

---
 exec.c | 99 +++++++++++++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 65 insertions(+), 34 deletions(-)
exec.c +65 -34
index 32e5394..efc80a8 100644
@@ -463,18 +463,20 @@ address_space_translate_internal(AddressSpaceDispatch *d, hwaddr addr, hwaddr *x
 }
 
 /* Called from RCU critical section */
-IOMMUTLBEntry address_space_get_iotlb_entry(AddressSpace *as, hwaddr addr,
-                                            bool is_write)
+static MemoryRegionSection address_space_do_translate(AddressSpace *as,
+                                                      hwaddr addr,
+                                                      hwaddr *xlat,
+                                                      hwaddr *plen,
+                                                      bool is_write,
+                                                      bool is_mmio)
 {
-    IOMMUTLBEntry iotlb = {0};
+    IOMMUTLBEntry iotlb;
     MemoryRegionSection *section;
     MemoryRegion *mr;
 
     for (;;) {
         AddressSpaceDispatch *d = atomic_rcu_read(&as->dispatch);
-        section = address_space_lookup_region(d, addr, false);
-        addr = addr - section->offset_within_address_space
-               + section->offset_within_region;
+        section = address_space_translate_internal(d, addr, &addr, plen, is_mmio);
         mr = section->mr;
 
         if (!mr->iommu_ops) {
@@ -482,55 +484,84 @@ IOMMUTLBEntry address_space_get_iotlb_entry(AddressSpace *as, hwaddr addr,
         }
 
         iotlb = mr->iommu_ops->translate(mr, addr, is_write);
+        addr = ((iotlb.translated_addr & ~iotlb.addr_mask)
+                | (addr & iotlb.addr_mask));
+        *plen = MIN(*plen, (addr | iotlb.addr_mask) - addr + 1);
         if (!(iotlb.perm & (1 << is_write))) {
-            iotlb.target_as = NULL;
-            break;
+            goto translate_fail;
         }
 
-        addr = ((iotlb.translated_addr & ~iotlb.addr_mask)
-                | (addr & iotlb.addr_mask));
         as = iotlb.target_as;
     }
 
-    return iotlb;
+    *xlat = addr;
+
+    return *section;
+
+translate_fail:
+    return (MemoryRegionSection) { .mr = &io_mem_unassigned };
 }
 
 /* Called from RCU critical section */
-MemoryRegion *address_space_translate(AddressSpace *as, hwaddr addr,
-                                      hwaddr *xlat, hwaddr *plen,
-                                      bool is_write)
+IOMMUTLBEntry address_space_get_iotlb_entry(AddressSpace *as, hwaddr addr,
+                                            bool is_write)
 {
-    IOMMUTLBEntry iotlb;
-    MemoryRegionSection *section;
-    MemoryRegion *mr;
+    MemoryRegionSection section;
+    hwaddr xlat, plen;
 
-    for (;;) {
-        AddressSpaceDispatch *d = atomic_rcu_read(&as->dispatch);
-        section = address_space_translate_internal(d, addr, &addr, plen, true);
-        mr = section->mr;
+    /* Try to get maximum page mask during translation. */
+    plen = (hwaddr)-1;
 
-        if (!mr->iommu_ops) {
-            break;
-        }
+    /* This can never be MMIO. */
+    section = address_space_do_translate(as, addr, &xlat, &plen,
+                                         is_write, false);
 
-        iotlb = mr->iommu_ops->translate(mr, addr, is_write);
-        addr = ((iotlb.translated_addr & ~iotlb.addr_mask)
-                | (addr & iotlb.addr_mask));
-        *plen = MIN(*plen, (addr | iotlb.addr_mask) - addr + 1);
-        if (!(iotlb.perm & (1 << is_write))) {
-            mr = &io_mem_unassigned;
-            break;
-        }
+    /* Illegal translation */
+    if (section.mr == &io_mem_unassigned) {
+        goto iotlb_fail;
+    }
 
-        as = iotlb.target_as;
+    if (plen == (hwaddr)-1) {
+        /*
+         * We use default page size here. Logically it only happens
+         * for identity mappings.
+         */
+        plen = TARGET_PAGE_SIZE;
     }
 
+    /* Convert to address mask */
+    plen -= 1;
+
+    return (IOMMUTLBEntry) {
+        .target_as = section.address_space,
+        .iova = addr & ~plen,
+        .translated_addr = xlat & ~plen,
+        .addr_mask = plen,
+        /* IOTLBs are for DMAs, and DMA only allows on RAMs. */
+        .perm = IOMMU_RW,
+    };
+
+iotlb_fail:
+    return (IOMMUTLBEntry) {0};
+}
+
+/* Called from RCU critical section */
+MemoryRegion *address_space_translate(AddressSpace *as, hwaddr addr,
+                                      hwaddr *xlat, hwaddr *plen,
+                                      bool is_write)
+{
+    MemoryRegion *mr;
+    MemoryRegionSection section;
+
+    /* This can be MMIO, so setup MMIO bit. */
+    section = address_space_do_translate(as, addr, xlat, plen, is_write, true);
+    mr = section.mr;
+
     if (xen_enabled() && memory_access_is_direct(mr, is_write)) {
         hwaddr page = ((addr & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE) - addr;
         *plen = MIN(page, *plen);
     }
 
-    *xlat = addr;
     return mr;
 }
 
Signature · 1 line
2.7.4
Tested-by on the v1 series
#11 lore raw
In reply to Peter Xu
Quoted 8 lines · Peter Xu

The problem is that, address_space_get_iotlb_entry() shares a lot with address_space_translate(). This patch tries to abstract the shared elements.

Originally, this work is derived from discussion from VT-d passthrough series discussions [1]. But for sure we can just see this series as a standalone cleanup. So I posted it separately here.

Quoted 5 lines

Smoke tests are done with general VM boots, IOs, especially with vhost dmar configurations.

I believe with current series I can throw away the old patch [1], which may be good. But before that, please kindly review. Thanks.

I faced the problem the old patch fixes when declaring and attaching an IOMMU device, but booting the kernel with intel_iommu=off.

I tested again with patches 1 & 4 of your series, and I confirm it fixes the issue:

Thanks!
Maxime

Quoted 14 lines

References:

[1] https://lists.gnu.org/archive/html/qemu-devel/2017-05/msg02335.html

Peter Xu (4):
exec: simplify phys_page_find() params
exec: rename resolve_subpage
exec: further use is_mmio
exec: abstract address_space_do_translate()

  exec.c | 122 ++++++++++++++++++++++++++++++++++++++++-------------------------
  1 file changed, 76 insertions(+), 46 deletions(-)
#12 lore raw

Hi Peter,

Quoted 14 lines · Maxime Coquelin
Quoted 11 lines · Peter Xu

The problem is that, address_space_get_iotlb_entry() shares a lot with address_space_translate(). This patch tries to abstract the shared elements.

Originally, this work is derived from discussion from VT-d passthrough series discussions [1]. But for sure we can just see this series as a standalone cleanup. So I posted it separately here.

Smoke tests are done with general VM boots, IOs, especially with vhost dmar configurations.

Quoted 7 lines
Quoted 2 lines

I believe with current series I can throw away the old patch [1], which may be good. But before that, please kindly review. Thanks.

I faced the problem the old patch fixes when declaring and attaching an IOMMU device, but booting the kernel with intel_iommu=off.

I tested again with patches 1 & 4 of your series, and I confirm it fixes the issue:

I did some more testing with my "vhost-user IOMMU" setup, and the series actually breaks with IOMMU device attached, and intel_iommu=on.

The main difference with the previous passing test is the guest RAM size. In the working setup, it is 2G of 2M hugepages, vs. 4G of 2M hugepages in the failing one. Note that I also reproduce with vhost-kernel backend.

The error happens in the first vhost_device_iotlb_miss() call:
qemu-system-x86_64: Fail to lookup the translated address b5d7c000

I don't have the root cause yet, I'll keep you updated.

Maxime

Quoted 19 lines

Thanks!
Maxime

Quoted 15 lines

References:

[1] https://lists.gnu.org/archive/html/qemu-devel/2017-05/msg02335.html

Peter Xu (4):
exec: simplify phys_page_find() params
exec: rename resolve_subpage
exec: further use is_mmio
exec: abstract address_space_do_translate()

  exec.c | 122 
++++++++++++++++++++++++++++++++++++++++-------------------------
  1 file changed, 76 insertions(+), 46 deletions(-)
#13 lore raw
Quoted 16 lines · Maxime Coquelin
Quoted 7 lines

I faced the problem the old patch fixes when declaring and attaching an IOMMU device, but booting the kernel with intel_iommu=off.

I tested again with patches 1 & 4 of your series, and I confirm it fixes the issue:

I did some more testing with my "vhost-user IOMMU" setup, and the series actually breaks with IOMMU device attached, and intel_iommu=on.

The main difference with the previous passing test is the guest RAM size. In the working setup, it is 2G of 2M hugepages, vs. 4G of 2M hugepages in the failing one. Note that I also reproduce with vhost-kernel backend.

Quoted 4 lines

The error happens in the first vhost_device_iotlb_miss() call:
qemu-system-x86_64: Fail to lookup the translated address b5d7c000

I don't have the root cause yet, I'll keep you updated.

I suppose it is patch 4?

Paolo

#14 lore raw
Quoted 19 lines · Paolo Bonzini
Quoted 16 lines · Maxime Coquelin
Quoted 7 lines

I faced the problem the old patch fixes when declaring and attaching an IOMMU device, but booting the kernel with intel_iommu=off.

I tested again with patches 1 & 4 of your series, and I confirm it fixes the issue:

I did some more testing with my "vhost-user IOMMU" setup, and the series actually breaks with IOMMU device attached, and intel_iommu=on.

The main difference with the previous passing test is the guest RAM size. In the working setup, it is 2G of 2M hugepages, vs. 4G of 2M hugepages in the failing one. Note that I also reproduce with vhost-kernel backend.

Quoted 6 lines
Quoted 4 lines

The error happens in the first vhost_device_iotlb_miss() call:
qemu-system-x86_64: Fail to lookup the translated address b5d7c000

I don't have the root cause yet, I'll keep you updated.

I suppose it is patch 4?

Yes it is.

Maxime

author
#15 lore raw
In reply to Maxime Coquelin
Quoted 35 lines · Maxime Coquelin

Hi Peter,

Quoted 17 lines · Maxime Coquelin
Quoted 8 lines · Peter Xu

The problem is that, address_space_get_iotlb_entry() shares a lot with address_space_translate(). This patch tries to abstract the shared elements.

Originally, this work is derived from discussion from VT-d passthrough series discussions [1]. But for sure we can just see this series as a standalone cleanup. So I posted it separately here.

Quoted 5 lines

Smoke tests are done with general VM boots, IOs, especially with vhost dmar configurations.

I believe with current series I can throw away the old patch [1], which may be good. But before that, please kindly review. Thanks.

Quoted 6 lines

I faced the problem the old patch fixes when declaring and attaching an IOMMU device, but booting the kernel with intel_iommu=off.

I tested again with patches 1 & 4 of your series, and I confirm it fixes the issue:

I did some more testing with my "vhost-user IOMMU" setup, and the series actually breaks with IOMMU device attached, and intel_iommu=on.

The main difference with the previous passing test is the guest RAM size. In the working setup, it is 2G of 2M hugepages, vs. 4G of 2M hugepages in the failing one. Note that I also reproduce with vhost-kernel backend.

Quoted 4 lines

The error happens in the first vhost_device_iotlb_miss() call:
qemu-system-x86_64: Fail to lookup the translated address b5d7c000

I don't have the root cause yet, I'll keep you updated.

Maxime,

Thanks a lot for help testing this series!

I reproduced this problem, and this is not a problem obvious enough for me. Let me investigate as well.

Signature · 1 line
Peter Xu
author
#16 lore raw
Quoted 39 lines · Peter Xu
Quoted 38 lines · Maxime Coquelin

Hi Peter,

Quoted 17 lines · Maxime Coquelin
Quoted 8 lines · Peter Xu

The problem is that, address_space_get_iotlb_entry() shares a lot with address_space_translate(). This patch tries to abstract the shared elements.

Originally, this work is derived from discussion from VT-d passthrough series discussions [1]. But for sure we can just see this series as a standalone cleanup. So I posted it separately here.

Quoted 5 lines

Smoke tests are done with general VM boots, IOs, especially with vhost dmar configurations.

I believe with current series I can throw away the old patch [1], which may be good. But before that, please kindly review. Thanks.

Quoted 6 lines

I faced the problem the old patch fixes when declaring and attaching an IOMMU device, but booting the kernel with intel_iommu=off.

I tested again with patches 1 & 4 of your series, and I confirm it fixes the issue:

I did some more testing with my "vhost-user IOMMU" setup, and the series actually breaks with IOMMU device attached, and intel_iommu=on.

The main difference with the previous passing test is the guest RAM size. In the working setup, it is 2G of 2M hugepages, vs. 4G of 2M hugepages in the failing one. Note that I also reproduce with vhost-kernel backend.

The error happens in the first vhost_device_iotlb_miss() call:
qemu-system-x86_64: Fail to lookup the translated address b5d7c000

Quoted 11 lines
Quoted 1 line

I don't have the root cause yet, I'll keep you updated.

Maxime,

Thanks a lot for help testing this series!

I reproduced this problem, and this is not a problem obvious enough for me. Let me investigate as well.

Signature · 1 line
Peter Xu

Maxime,

Could you help try adding this change upon current to see whether problem solved?

exec.c +4 -0
index 697d902..68576a2 100644
@@ -521,6 +521,10 @@ IOMMUTLBEntry address_space_get_iotlb_entry(AddressSpace *as, hwaddr addr,
         goto iotlb_fail;
     }
 
+    /* Convert memory region offset into address space offset */
+    xlat += section.offset_within_address_space -
+        section.offset_within_region;
+
     if (plen == (hwaddr)-1) {
         /*
          * We use default page size here. Logically it only happens

Thanks in advance,

Signature · 1 line
Peter Xu
#17 lore raw
Quoted 49 lines · Peter Xu
Quoted 48 lines · Peter Xu
Quoted 35 lines · Maxime Coquelin

Hi Peter,

Quoted 17 lines · Maxime Coquelin
Quoted 8 lines · Peter Xu

The problem is that, address_space_get_iotlb_entry() shares a lot with address_space_translate(). This patch tries to abstract the shared elements.

Originally, this work is derived from discussion from VT-d passthrough series discussions [1]. But for sure we can just see this series as a standalone cleanup. So I posted it separately here.

Quoted 5 lines

Smoke tests are done with general VM boots, IOs, especially with vhost dmar configurations.

I believe with current series I can throw away the old patch [1], which may be good. But before that, please kindly review. Thanks.

Quoted 6 lines

I faced the problem the old patch fixes when declaring and attaching an IOMMU device, but booting the kernel with intel_iommu=off.

I tested again with patches 1 & 4 of your series, and I confirm it fixes the issue:

I did some more testing with my "vhost-user IOMMU" setup, and the series actually breaks with IOMMU device attached, and intel_iommu=on.

The main difference with the previous passing test is the guest RAM size. In the working setup, it is 2G of 2M hugepages, vs. 4G of 2M hugepages in the failing one. Note that I also reproduce with vhost-kernel backend.

Quoted 4 lines

The error happens in the first vhost_device_iotlb_miss() call:
qemu-system-x86_64: Fail to lookup the translated address b5d7c000

I don't have the root cause yet, I'll keep you updated.

Maxime,

Thanks a lot for help testing this series!

I reproduced this problem, and this is not a problem obvious enough for me. Let me investigate as well.

Quoted 7 lines
Quoted 2 lines
Signature · 1 line
Peter Xu

Maxime,

Could you help try adding this change upon current to see whether problem solved?

Hi Peter,

Yes, problem is solved with below change.

Thanks!
Maxime

Quoted 18 lines
exec.c +4 -0
index 697d902..68576a2 100644
@@ -521,6 +521,10 @@ IOMMUTLBEntry address_space_get_iotlb_entry(AddressSpace *as, hwaddr addr,
          goto iotlb_fail;
      }
 
+    /* Convert memory region offset into address space offset */
+    xlat += section.offset_within_address_space -
+        section.offset_within_region;
+
      if (plen == (hwaddr)-1) {
          /*
           * We use default page size here. Logically it only happens

Thanks in advance,

#18 lore raw
Quoted 62 lines · Maxime Coquelin
Quoted 59 lines · Peter Xu
Quoted 57 lines · Peter Xu
Quoted 42 lines · Maxime Coquelin

Hi Peter,

Quoted 20 lines · Maxime Coquelin
Quoted 10 lines · Peter Xu

The problem is that, address_space_get_iotlb_entry() shares a lot with
address_space_translate(). This patch tries to abstract the shared elements.

Originally, this work is derived from discussion from VT-d passthrough
series discussions [1]. But for sure we can just see this series as a standalone cleanup. So I posted it separately here.

Quoted 6 lines

Smoke tests are done with general VM boots, IOs, especially with vhost
dmar configurations.

I believe with current series I can throw away the old patch [1], which may be good. But before that, please kindly review. Thanks.

Quoted 8 lines

I faced the problem the old patch fixes when declaring and attaching an
IOMMU device, but booting the kernel with intel_iommu=off.

I tested again with patches 1 & 4 of your series, and I confirm it fixes
the issue:

I did some more testing with my "vhost-user IOMMU" setup, and the series
actually breaks with IOMMU device attached, and intel_iommu=on.

The main difference with the previous passing test is the guest RAM size. In the working setup, it is 2G of 2M hugepages, vs. 4G of 2M hugepages in the failing one. Note that I also reproduce with vhost-kernel
backend.

Quoted 4 lines

The error happens in the first vhost_device_iotlb_miss() call:
qemu-system-x86_64: Fail to lookup the translated address b5d7c000

I don't have the root cause yet, I'll keep you updated.

Maxime,

Thanks a lot for help testing this series!

I reproduced this problem, and this is not a problem obvious enough for me. Let me investigate as well.

Signature · 1 line
Peter Xu
Quoted 8 lines
Quoted 4 lines

Maxime,

Could you help try adding this change upon current to see whether problem solved?

Hi Peter,

Yes, problem is solved with below change.

Cool---Peter, please send the new patch 4 as toplevel message!

Thanks,

Paolo

author
#19 lore raw
Quoted 67 lines · Paolo Bonzini
Quoted 64 lines · Maxime Coquelin
Quoted 61 lines · Peter Xu
Quoted 46 lines · Peter Xu
Quoted 45 lines · Maxime Coquelin

Hi Peter,

Quoted 20 lines · Maxime Coquelin
Quoted 10 lines · Peter Xu

The problem is that, address_space_get_iotlb_entry() shares a lot with
address_space_translate(). This patch tries to abstract the shared elements.

Originally, this work is derived from discussion from VT-d passthrough
series discussions [1]. But for sure we can just see this series as a standalone cleanup. So I posted it separately here.

Quoted 6 lines

Smoke tests are done with general VM boots, IOs, especially with vhost
dmar configurations.

I believe with current series I can throw away the old patch [1], which may be good. But before that, please kindly review. Thanks.

Quoted 8 lines

I faced the problem the old patch fixes when declaring and attaching an
IOMMU device, but booting the kernel with intel_iommu=off.

I tested again with patches 1 & 4 of your series, and I confirm it fixes
the issue:

I did some more testing with my "vhost-user IOMMU" setup, and the series
actually breaks with IOMMU device attached, and intel_iommu=on.

The main difference with the previous passing test is the guest RAM size. In the working setup, it is 2G of 2M hugepages, vs. 4G of 2M hugepages in the failing one. Note that I also reproduce with vhost-kernel
backend.

The error happens in the first vhost_device_iotlb_miss() call:
qemu-system-x86_64: Fail to lookup the translated address b5d7c000

Quoted 11 lines
Quoted 1 line

I don't have the root cause yet, I'll keep you updated.

Maxime,

Thanks a lot for help testing this series!

I reproduced this problem, and this is not a problem obvious enough for me. Let me investigate as well.

Signature · 1 line
Peter Xu

Maxime,

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Could you help try adding this change upon current to see whether problem solved?

Hi Peter,

Yes, problem is solved with below change.

Cool---Peter, please send the new patch 4 as toplevel message!

Will do. Thanks!

Signature · 1 line
Peter Xu