Skip to contentSkip to conversation

plugins: Fix physical address calculation for IO regions

PATCH Applied Aaron Lindsay 3 participants 4 messages Jul 20, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 plugins: Fix physical address calculation for IO regions

The address calculation for IO regions introduced by

commit 787148bf928a54b5cc86f5b434f9399e9737679c
Author: Aaron Lindsay <[email protected]>
plugins: Expose physical addresses instead of device offsets

is not always accurate. Use the more correct
MemoryRegionSection.offset_within_address_space.

---
 plugins/api.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
plugins/api.c +1 -1
index 5c1a413928..ba14e6f2b2 100644
@@ -319,7 +319,7 @@ uint64_t qemu_plugin_hwaddr_phys_addr(const struct qemu_plugin_hwaddr *haddr)
             return block->offset + offset + block->mr->addr;
         } else {
             MemoryRegionSection *mrs = haddr->v.io.section;
-            return haddr->v.io.offset + mrs->mr->addr;
+            return mrs->offset_within_address_space + haddr->v.io.offset;
         }
     }
 #endif
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Aaron Lindsay

The address calculation for IO regions introduced by

commit 787148bf928a54b5cc86f5b434f9399e9737679c
Author: Aaron Lindsay <[email protected]>
plugins: Expose physical addresses instead of device offsets

is not always accurate.

Indeed unlikely accurate in case of aliases (at least).

Quoted 20 lines

Use the more correct
MemoryRegionSection.offset_within_address_space.

---
 plugins/api.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
plugins/api.c +1 -1
index 5c1a413928..ba14e6f2b2 100644
@@ -319,7 +319,7 @@ uint64_t qemu_plugin_hwaddr_phys_addr(const struct qemu_plugin_hwaddr *haddr)
             return block->offset + offset + block->mr->addr;
         } else {
             MemoryRegionSection *mrs = haddr->v.io.section;
-            return haddr->v.io.offset + mrs->mr->addr;
+            return mrs->offset_within_address_space + haddr->v.io.offset;
         }
     }
 #endif
#2 lore raw
In reply to Aaron Lindsay

For reference, this patch is intended to address this conversation:
https://lists.nongnu.org/archive/html/qemu-devel/2021-07/msg01293.html

This appears to be better than the previous version in my testing, but I absolutely welcome being told there is a better way to solve this!

Thanks!

-Aaron

Quoted 8 lines · Aaron Lindsay

The address calculation for IO regions introduced by

commit 787148bf928a54b5cc86f5b434f9399e9737679c
Author: Aaron Lindsay <[email protected]>
plugins: Expose physical addresses instead of device offsets

is not always accurate. Use the more correct
MemoryRegionSection.offset_within_address_space.

Whoops, forgot my:

Quoted 20 lines
---
 plugins/api.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
plugins/api.c +1 -1
index 5c1a413928..ba14e6f2b2 100644
@@ -319,7 +319,7 @@ uint64_t qemu_plugin_hwaddr_phys_addr(const struct qemu_plugin_hwaddr *haddr)
             return block->offset + offset + block->mr->addr;
         } else {
             MemoryRegionSection *mrs = haddr->v.io.section;
-            return haddr->v.io.offset + mrs->mr->addr;
+            return mrs->offset_within_address_space + haddr->v.io.offset;
         }
     }
 #endif
Signature · 1 line
2.17.1
Applied
#3 lore raw
In reply to Aaron Lindsay
Quoted 5 lines · Aaron Lindsay

The address calculation for IO regions introduced by

commit 787148bf928a54b5cc86f5b434f9399e9737679c
Author: Aaron Lindsay <[email protected]>
plugins: Expose physical addresses instead of device offsets

Queued to for-6.1/fixes-for-rc1, thanks.

Quoted 20 lines

is not always accurate. Use the more correct
MemoryRegionSection.offset_within_address_space.

---
 plugins/api.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
plugins/api.c +1 -1
index 5c1a413928..ba14e6f2b2 100644
@@ -319,7 +319,7 @@ uint64_t qemu_plugin_hwaddr_phys_addr(const struct qemu_plugin_hwaddr *haddr)
             return block->offset + offset + block->mr->addr;
         } else {
             MemoryRegionSection *mrs = haddr->v.io.section;
-            return haddr->v.io.offset + mrs->mr->addr;
+            return mrs->offset_within_address_space + haddr->v.io.offset;
         }
     }
 #endif
Signature · 1 line
Alex Bennée