Skip to contentSkip to conversation

hw/vfio/common: Fix a small boundary issue of a trace

PATCH Superseded chenxiang via 2 participants 3 messages Apr 6, 2022 – Apr 7, 2022

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/vfio/common: Fix a small boundary issue of a trace

From: Xiang Chen <[email protected]>

Right now the trace of vfio_region_sparse_mmap_entry is as follows:
vfio_region_sparse_mmap_entry sparse entry 0 [0x1000 - 0x9000] Actually the range it wants to show is [0x1000 - 0x8fff],so fix it.

---
 hw/vfio/common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/vfio/common.c +1 -1
index 080046e3f5..0b3808caf8 100644
@@ -1546,7 +1546,7 @@ static int vfio_setup_region_sparse_mmaps(VFIORegion *region,
     for (i = 0, j = 0; i < sparse->nr_areas; i++) {
         trace_vfio_region_sparse_mmap_entry(i, sparse->areas[i].offset,
                                             sparse->areas[i].offset +
-                                            sparse->areas[i].size);
+                                            sparse->areas[i].size - 1);
 
         if (sparse->areas[i].size) {
             region->mmaps[j].offset = sparse->areas[i].offset;
Signature · 1 line
2.33.0
#1 lore raw
Quoted 16 lines · chenxiang via

From: Xiang Chen <[email protected]>

Right now the trace of vfio_region_sparse_mmap_entry is as follows:
vfio_region_sparse_mmap_entry sparse entry 0 [0x1000 - 0x9000] Actually the range it wants to show is [0x1000 - 0x8fff],so fix it.

---
  hw/vfio/common.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/vfio/common.c +0 -0
index 080046e3f5..0b3808caf8 100644

hw/vfio/common.c static int vfio_setup_region_sparse_mmaps(VFIORegion *region, · line 1552

Quoted 8 lines
hw/vfio/common.c +1 -1
@@ -1546,7 +1546,7 @@ static int vfio_setup_region_sparse_mmaps(VFIORegion *region,
      for (i = 0, j = 0; i < sparse->nr_areas; i++) {
          trace_vfio_region_sparse_mmap_entry(i, sparse->areas[i].offset,
                                              sparse->areas[i].offset +
-                                            sparse->areas[i].size);
+                                            sparse->areas[i].size - 1);
 
          if (sparse->areas[i].size) {
              region->mmaps[j].offset = sparse->areas[i].offset;

If the size if zero, the trace will be weird with an underflow if offset is zero as well. Maybe just change the trace by inverting the right bracket ?
eg: [0x1000 - 0x9000[
Or don't trace in that case ? (but I am not maintainer of this, so maybe that does not make sense).

--
Damien

#2 lore raw

Hi Damien,

Quoted 14 lines · Damien Hedde
Quoted 11 lines · chenxiang via

From: Xiang Chen <[email protected]>

Right now the trace of vfio_region_sparse_mmap_entry is as follows:
vfio_region_sparse_mmap_entry sparse entry 0 [0x1000 - 0x9000] Actually the range it wants to show is [0x1000 - 0x8fff],so fix it.

---
  hw/vfio/common.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines
Quoted 11 lines
hw/vfio/common.c +0 -0
index 080046e3f5..0b3808caf8 100644
@@ -1546,7 +1546,7 @@ static int 
 vfio_setup_region_sparse_mmaps(VFIORegion *region,
      for (i = 0, j = 0; i < sparse->nr_areas; i++) {
          trace_vfio_region_sparse_mmap_entry(i, 
 sparse->areas[i].offset,

sparse->areas[i].offset +
- sparse->areas[i].size);

Quoted 3 lines
+ sparse->areas[i].size - 1);
            if (sparse->areas[i].size) {
              region->mmaps[j].offset = sparse->areas[i].offset;

If the size if zero, the trace will be weird with an underflow if offset is zero as well.

Yes, that's a issue.

Quoted 3 lines

Maybe just change the trace by inverting the right bracket ?
eg: [0x1000 - 0x9000[
Or don't trace in that case ? (but I am not maintainer of this, so maybe that does not make sense).

But it uses [offset, offset + size - 1] in other places such as trace_vfio_region_region_mmap()/trace_vfio_subregion_unmap()/trace_vfio_region_mmap_fault() in vfio code. Maybe it is better to move this trace to the brace of "if (sparse->areas[i].size)" which ensures size != 0.

Quoted 5 lines
Signature · 3 lines
-- 
Damien
.