Skip to contentSkip to conversation

x86: constrain sub-page access length in mmio_ro_emulated_write()

PATCH In review Jan Beulich 3 participants 3 messages Apr 25, 2025 – Apr 28, 2025

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 x86: constrain sub-page access length in mmio_ro_emulated_write()

Without doing so we could trigger the ASSERT_UNREACHABLE() in subpage_mmio_write_emulate(). A comment there actually says this validation would already have been done ...

Fixes 8847d6e23f97 ("x86/mm: add API for marking only part of a MMIO page read only")

---
v2: Emit a warning message otherwise.

xen/arch/x86/mm.c +7 -2
@@ -5195,8 +5195,13 @@ int cf_check mmio_ro_emulated_write(
         return X86EMUL_UNHANDLEABLE;
     }
 
-    subpage_mmio_write_emulate(mmio_ro_ctxt->mfn, PAGE_OFFSET(offset),
-                               p_data, bytes);
+    if ( bytes <= 8 )
+        subpage_mmio_write_emulate(mmio_ro_ctxt->mfn, PAGE_OFFSET(offset),
+                                   p_data, bytes);
+    else if ( subpage_mmio_find_page(mmio_ro_ctxt->mfn) )
+        gprintk(XENLOG_WARNING,
+                "unsupported %u-byte write to R/O MMIO 0x%"PRI_mfn"%03lx\n",
+                bytes, mfn_x(mmio_ro_ctxt->mfn), PAGE_OFFSET(offset));
 
     return X86EMUL_OKAY;
 }
Reviewed-by on v2 1/1
#1 lore raw
Quoted 6 lines · Jan Beulich

Without doing so we could trigger the ASSERT_UNREACHABLE() in subpage_mmio_write_emulate(). A comment there actually says this validation would already have been done ...

Fixes 8847d6e23f97 ("x86/mm: add API for marking only part of a MMIO page read only")

Thanks,
Jason

Reviewed-by on v2 1/1
#2 lore raw
In reply to Jan Beulich
Quoted 6 lines · Jan Beulich

Without doing so we could trigger the ASSERT_UNREACHABLE() in subpage_mmio_write_emulate(). A comment there actually says this validation would already have been done ...

Fixes 8847d6e23f97 ("x86/mm: add API for marking only part of a MMIO page read only")
Quoted 8 lines

---
v2: Emit a warning message otherwise.

xen/arch/x86/mm.c +0 -0
@@ -5195,8 +5195,13 @@ int cf_check mmio_ro_emulated_write(
         return X86EMUL_UNHANDLEABLE;
     }

xen/arch/x86/mm.c int cf_check mmio_ro_emulated_write( · line 5204

Quoted 10 lines
xen/arch/x86/mm.c +7 -2
 
-    subpage_mmio_write_emulate(mmio_ro_ctxt->mfn, PAGE_OFFSET(offset),
-                               p_data, bytes);
+    if ( bytes <= 8 )
+        subpage_mmio_write_emulate(mmio_ro_ctxt->mfn, PAGE_OFFSET(offset),
+                                   p_data, bytes);
+    else if ( subpage_mmio_find_page(mmio_ro_ctxt->mfn) )
+        gprintk(XENLOG_WARNING,
+                "unsupported %u-byte write to R/O MMIO 0x%"PRI_mfn"%03lx\n",
+                bytes, mfn_x(mmio_ro_ctxt->mfn), PAGE_OFFSET(offset));

It feels more natural to me to use:

"unsupported %u-byte write to r/o MMIO %#lx\n", bytes, mfn_to_maddr(mmio_ro_ctxt->mfn) + PAGE_OFFSET(offset)

As it simplifies the printf format string, but that's just my taste.

Thanks, Roger.