]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[prefix] Pad .text16 and .data16 segment sizes at build time
authorMichael Brown <mcb30@ipxe.org>
Fri, 12 Feb 2016 13:59:06 +0000 (13:59 +0000)
committerMichael Brown <mcb30@ipxe.org>
Fri, 12 Feb 2016 14:04:51 +0000 (14:04 +0000)
Commit c64747d ("[librm] Speed up real-to-protected mode transition
under KVM") rounded down the .text16 segment address calculated in
alloc_basemem() to a multiple of 64 bytes in order to speed up mode
transitions under KVM.

This creates a potential discrepancy between alloc_basemem() and
free_basemem(), meaning that free_basemem() may free less memory than
was allocated by alloc_basemem().

Fix by padding the calculated sizes of both .text16 and .data16 to a
multiple of 64 bytes at build time.

Debugged-by: Yossef Efraim <yossefe@mellanox.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/arch/i386/prefix/libprefix.S
src/arch/i386/scripts/i386.lds

index 7d5c1ed53c716d7aa121f127b868ed3261d339e6..3cdb6ec9a466bc1695ad62a8f29062f5b54808c4 100644 (file)
@@ -558,14 +558,11 @@ alloc_basemem:
        shlw    $6, %ax
 
        /* Calculate .data16 segment address */
-       subw    $_data16_memsz_pgh, %ax
+       subw    $_data16_memsz_ppgh, %ax
        pushw   %ax
 
-       /* Calculate .text16 segment address.  Round down to ensure
-        * low bits are zero, to speed up mode transitions under KVM.
-        */
-       subw    $_text16_memsz_pgh, %ax
-       andb    $~0x03, %al
+       /* Calculate .text16 segment address */
+       subw    $_text16_memsz_ppgh, %ax
        pushw   %ax
 
        /* Update FBMS */
@@ -616,8 +613,8 @@ free_basemem:
 
        /* OK to free memory */
        movw    %cs, %ax
-       addw    $_text16_memsz_pgh, %ax
-       addw    $_data16_memsz_pgh, %ax
+       addw    $_text16_memsz_ppgh, %ax
+       addw    $_data16_memsz_ppgh, %ax
        shrw    $6, %ax
        movw    %ax, %fs:0x13
        xorw    %ax, %ax
index 38c89e14b172a19a03c3173934f894ddfe48f16c..865591ae2e456acf60ec50aa2ef5b3625ea1ac2d 100644 (file)
@@ -247,8 +247,8 @@ SECTIONS {
      * Values calculated to save code from doing it
      *
      */
-    _text16_memsz_pgh  = ( ( _text16_memsz + 15 ) / 16 );
-    _data16_memsz_pgh  = ( ( _data16_memsz + 15 ) / 16 );
+    _text16_memsz_ppgh = ( ( ( _text16_memsz + 63 ) / 64 ) * 4 );
+    _data16_memsz_ppgh = ( ( ( _data16_memsz + 63 ) / 64 ) * 4 );
     _textdata_memsz_pgh        = ( ( _textdata_memsz + 15 ) / 16 );
     _textdata_memsz_kb = ( ( _textdata_memsz + 1023 ) / 1024 );
 }