]> xenbits.xensource.com Git - xen.git/commitdiff
x86/HVM: reduce recursion in linear_{read,write}()
authorJan Beulich <jbeulich@suse.com>
Mon, 17 Feb 2025 12:17:45 +0000 (13:17 +0100)
committerJan Beulich <jbeulich@suse.com>
Mon, 17 Feb 2025 12:17:45 +0000 (13:17 +0100)
Let's make explicit what the compiler may or may not do on our behalf:
The 2nd of the recursive invocations each can fall through rather than
re-invoking the function. This will save us from adding yet another
parameter (or more) to the function, just for the recursive invocations.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
master commit: 18053054b7583810dd356efc8d7018bbc8720f36
master date: 2024-09-09 13:40:47 +0200

xen/arch/x86/hvm/emulate.c

index 02e378365b4040a359594c2517b6874370124499..9e62b2f184056429f8bc69f48345d66317e1e661 100644 (file)
@@ -1147,7 +1147,7 @@ static int linear_read(unsigned long addr, unsigned int bytes, void *p_data,
     pagefault_info_t pfinfo;
     struct hvm_vcpu_io *hvio = &current->arch.hvm.hvm_io;
     unsigned int offset = addr & ~PAGE_MASK;
-    int rc = HVMTRANS_bad_gfn_to_mfn;
+    int rc;
 
     if ( offset + bytes > PAGE_SIZE )
     {
@@ -1155,12 +1155,16 @@ static int linear_read(unsigned long addr, unsigned int bytes, void *p_data,
 
         /* Split the access at the page boundary. */
         rc = linear_read(addr, part1, p_data, pfec, hvmemul_ctxt);
-        if ( rc == X86EMUL_OKAY )
-            rc = linear_read(addr + part1, bytes - part1, p_data + part1,
-                             pfec, hvmemul_ctxt);
-        return rc;
+        if ( rc != X86EMUL_OKAY )
+            return rc;
+
+        addr += part1;
+        bytes -= part1;
+        p_data += part1;
     }
 
+    rc = HVMTRANS_bad_gfn_to_mfn;
+
     /*
      * If there is an MMIO cache entry for the access then we must be re-issuing
      * an access that was previously handled as MMIO. Thus it is imperative that
@@ -1202,7 +1206,7 @@ static int linear_write(unsigned long addr, unsigned int bytes, void *p_data,
     pagefault_info_t pfinfo;
     struct hvm_vcpu_io *hvio = &current->arch.hvm.hvm_io;
     unsigned int offset = addr & ~PAGE_MASK;
-    int rc = HVMTRANS_bad_gfn_to_mfn;
+    int rc;
 
     if ( offset + bytes > PAGE_SIZE )
     {
@@ -1210,12 +1214,16 @@ static int linear_write(unsigned long addr, unsigned int bytes, void *p_data,
 
         /* Split the access at the page boundary. */
         rc = linear_write(addr, part1, p_data, pfec, hvmemul_ctxt);
-        if ( rc == X86EMUL_OKAY )
-            rc = linear_write(addr + part1, bytes - part1, p_data + part1,
-                              pfec, hvmemul_ctxt);
-        return rc;
+        if ( rc != X86EMUL_OKAY )
+            return rc;
+
+        addr += part1;
+        bytes -= part1;
+        p_data += part1;
     }
 
+    rc = HVMTRANS_bad_gfn_to_mfn;
+
     /*
      * If there is an MMIO cache entry for the access then we must be re-issuing
      * an access that was previously handled as MMIO. Thus it is imperative that