[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xen master] x86/boot: Simplify size calculations in move_memory()



commit 2c3294775e9578065a096a525efe1b514527d0f5
Author:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
AuthorDate: Tue Oct 22 18:48:30 2024 +0100
Commit:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
CommitDate: Wed Oct 23 10:27:36 2024 +0100

    x86/boot: Simplify size calculations in move_memory()
    
    While both src and dst are similar, src is mapped only accounting for src's
    size, while dst is mapped based on the minimum of both.  This means that in
    some cases, an overly large mapping is requested for src.
    
    Rework the sz calcuation to be symmetric, and leave an explanation of how
    logic works.
    
    No functional change.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
    Reviewed-by: Daniel P. Smith <dpsmith@xxxxxxxxxxxxxxxxxxxx>
---
 xen/arch/x86/setup.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
index ce28e77060..8ad957f3d1 100644
--- a/xen/arch/x86/setup.c
+++ b/xen/arch/x86/setup.c
@@ -492,23 +492,22 @@ static void __init move_memory(
 
     while ( size )
     {
-        unsigned int end   /* mapsz */;
         unsigned int soffs = src & mask;
         unsigned int doffs = dst & mask;
         unsigned int sz;
         void *d, *s;
 
-        end = soffs + size;
-        if ( end > blksz )
-            end = blksz;
-        sz = end - soffs;
-        s = bootstrap_map_addr(src, src + sz);
+        /*
+         * We're copying between two arbitrary buffers, as they fall within
+         * 2M-aligned regions with a maximum bound of blksz.
+         *
+         * For [ds]offs + size <= blksz, sz = size.
+         * For [ds]offs + size >  blksz, sz = blksz - [ds]offs.
+         */
+        sz = max(soffs, doffs);
+        sz = min(sz + size, blksz) - sz;
 
-        end = doffs + size;
-        if ( end > blksz )
-            end = blksz;
-        if ( sz > end - doffs )
-            sz = end - doffs;
+        s = bootstrap_map_addr(src, src + sz);
         d = bootstrap_map_addr(dst, dst + sz);
 
         memmove(d, s, sz);
--
generated by git-patchbot for /home/xen/git/xen.git#master



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.