[xen staging-4.8] x86/hvm/emulate: make sure rep I/O emulation does not cross GFN boundaries

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[xen staging-4.8] x86/hvm/emulate: make sure rep I/O emulation does not cross GFN boundaries

patchbot
commit 567003960644ba4f80107fb53edcd828f3f280a1
Author:     Paul Durrant <[hidden email]>
AuthorDate: Mon Oct 8 14:51:33 2018 +0200
Commit:     Jan Beulich <[hidden email]>
CommitDate: Mon Oct 8 14:51:33 2018 +0200

    x86/hvm/emulate: make sure rep I/O emulation does not cross GFN boundaries
   
    When emulating a rep I/O operation it is possible that the ioreq will
    describe a single operation that spans multiple GFNs. This is fine as long
    as all those GFNs fall within an MMIO region covered by a single device
    model, but unfortunately the higher levels of the emulation code do not
    guarantee that. This is something that should almost certainly be fixed,
    but in the meantime this patch makes sure that MMIO is truncated at GFN
    boundaries and hence the appropriate device model is re-evaluated for each
    target GFN.
   
    NOTE: This patch does not deal with the case of a single MMIO operation
          spanning a GFN boundary. That is more complex to deal with and is
          deferred to a subsequent patch.
   
    Signed-off-by: Paul Durrant <[hidden email]>
   
    Convert calculations to be 32-bit only.
   
    Signed-off-by: Jan Beulich <[hidden email]>
    master commit: 7626edeaca972e3e823535dcc44338f6b2f0b21f
    master date: 2018-08-16 09:27:30 +0200
---
 xen/arch/x86/hvm/emulate.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/xen/arch/x86/hvm/emulate.c b/xen/arch/x86/hvm/emulate.c
index d8ca3c6334..b6b5bc0175 100644
--- a/xen/arch/x86/hvm/emulate.c
+++ b/xen/arch/x86/hvm/emulate.c
@@ -160,6 +160,24 @@ static int hvmemul_do_io(
         hvmtrace_io_assist(&p);
     }
 
+    /*
+     * Make sure that we truncate rep MMIO at any GFN boundary. This is
+     * necessary to ensure that the correct device model is targetted
+     * or that we correctly handle a rep op spanning MMIO and RAM.
+     */
+    if ( unlikely(p.count > 1) && p.type == IOREQ_TYPE_COPY )
+    {
+        unsigned int off = p.addr & ~PAGE_MASK;
+        unsigned int tail = PAGE_SIZE - off;
+
+        if ( tail < p.size ) /* single rep spans GFN */
+            p.count = 1;
+        else
+            p.count = min(p.count,
+                          (p.df ? (off + p.size) : tail) / p.size);
+    }
+    ASSERT(p.count);
+
     vio->io_req = p;
 
     rc = hvm_io_intercept(&p);
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.8

_______________________________________________
Xen-changelog mailing list
[hidden email]
https://lists.xenproject.org/xen-changelog