[PATCH] hw/remote/vfio-user: Reset VFU region flags for each BAR

Owen Giles posted 1 patch 1 week, 4 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260914205747.1540492-1-owen.giles@hpe.com
Maintainers: Elena Ufimtseva <elena.ufimtseva@oracle.com>, Jagannathan Raman <jag.raman@oracle.com>
hw/remote/vfio-user-obj.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
[PATCH] hw/remote/vfio-user: Reset VFU region flags for each BAR
Posted by Owen Giles 1 week, 4 days ago
flags is only initialized once before the BAR setup loop, so if a lower
BAR's io_region is read only, every subsequent BAR will have its
flags set as read only despite not being read only. By setting flags to
RW in every iteration, each region is properly assessed and assigned
the proper flag.

Fixes: 3123f93d6b85 ("vfio-user: handle PCI BAR accesses")
Signed-off-by: Owen Giles <owen.giles@hpe.com>
---

Notes:
    The ROM case of the read-only check is okay, as the ROM will always be the
    last in the loop, but the other check is what can result in unintended
    consequences.

 hw/remote/vfio-user-obj.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c
index a0498d218fa..67687c841a6 100644
--- a/hw/remote/vfio-user-obj.c
+++ b/hw/remote/vfio-user-obj.c
@@ -519,14 +519,15 @@ static vfu_region_access_cb_t *vfu_object_bar_handlers[PCI_NUM_REGIONS] = {
  */
 static void vfu_object_register_bars(vfu_ctx_t *vfu_ctx, PCIDevice *pdev)
 {
-    int flags = VFU_REGION_FLAG_RW;
-    int i;
+    int flags, i;
 
     for (i = 0; i < PCI_NUM_REGIONS; i++) {
         if (!pdev->io_regions[i].size) {
             continue;
         }
 
+        flags = VFU_REGION_FLAG_RW;
+
         if ((i == VFU_PCI_DEV_ROM_REGION_IDX) ||
             pdev->io_regions[i].memory->readonly) {
             flags &= ~VFU_REGION_FLAG_WRITE;
-- 
2.34.1
Re: [PATCH] hw/remote/vfio-user: Reset VFU region flags for each BAR
Posted by Jag Raman 1 week, 4 days ago

On Sep 14, 2026, at 5:00 PM, Owen Giles <owen.giles@hpe.com> wrote:


flags is only initialized once before the BAR setup loop, so if a lower BAR's io_region is read only, every subsequent BAR will have its flags set as read only despite not being read only. By setting flags to RW in every iteration, each region


flags is only initialized once before the BAR setup loop, so if a lower
BAR's io_region is read only, every subsequent BAR will have its
flags set as read only despite not being read only. By setting flags to
RW in every iteration, each region is properly assessed and assigned
the proper flag.

Fixes: 3123f93d6b85 ("vfio-user: handle PCI BAR accesses")
Signed-off-by: Owen Giles <owen.giles@hpe.com>


Thank you for the patch!

Reviewed-by: Jagannathan Raman <jag.raman@oracle.com>

---

Notes:
    The ROM case of the read-only check is okay, as the ROM will always be the
    last in the loop, but the other check is what can result in unintended
    consequences.

 hw/remote/vfio-user-obj.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c
index a0498d218fa..67687c841a6 100644
--- a/hw/remote/vfio-user-obj.c
+++ b/hw/remote/vfio-user-obj.c
@@ -519,14 +519,15 @@ static vfu_region_access_cb_t *vfu_object_bar_handlers[PCI_NUM_REGIONS] = {
  */
 static void vfu_object_register_bars(vfu_ctx_t *vfu_ctx, PCIDevice *pdev)
 {
-    int flags = VFU_REGION_FLAG_RW;
-    int i;
+    int flags, i;

     for (i = 0; i < PCI_NUM_REGIONS; i++) {
         if (!pdev->io_regions[i].size) {
             continue;
         }

+        flags = VFU_REGION_FLAG_RW;
+
         if ((i == VFU_PCI_DEV_ROM_REGION_IDX) ||
             pdev->io_regions[i].memory->readonly) {
             flags &= ~VFU_REGION_FLAG_WRITE;
--
2.34.1