Browse Source

[prefix] Pad .text16 and .data16 segment sizes at build time

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>
tags/v1.20.1
Michael Brown 9 years ago
parent
commit
7ecfe7159f
2 changed files with 7 additions and 10 deletions
  1. 5
    8
      src/arch/i386/prefix/libprefix.S
  2. 2
    2
      src/arch/i386/scripts/i386.lds

+ 5
- 8
src/arch/i386/prefix/libprefix.S View File

558
 	shlw	$6, %ax
558
 	shlw	$6, %ax
559
 
559
 
560
 	/* Calculate .data16 segment address */
560
 	/* Calculate .data16 segment address */
561
-	subw	$_data16_memsz_pgh, %ax
561
+	subw	$_data16_memsz_ppgh, %ax
562
 	pushw	%ax
562
 	pushw	%ax
563
 
563
 
564
-	/* Calculate .text16 segment address.  Round down to ensure
565
-	 * low bits are zero, to speed up mode transitions under KVM.
566
-	 */
567
-	subw	$_text16_memsz_pgh, %ax
568
-	andb	$~0x03, %al
564
+	/* Calculate .text16 segment address */
565
+	subw	$_text16_memsz_ppgh, %ax
569
 	pushw	%ax
566
 	pushw	%ax
570
 
567
 
571
 	/* Update FBMS */
568
 	/* Update FBMS */
616
 
613
 
617
 	/* OK to free memory */
614
 	/* OK to free memory */
618
 	movw	%cs, %ax
615
 	movw	%cs, %ax
619
-	addw	$_text16_memsz_pgh, %ax
620
-	addw	$_data16_memsz_pgh, %ax
616
+	addw	$_text16_memsz_ppgh, %ax
617
+	addw	$_data16_memsz_ppgh, %ax
621
 	shrw	$6, %ax
618
 	shrw	$6, %ax
622
 	movw	%ax, %fs:0x13
619
 	movw	%ax, %fs:0x13
623
 	xorw	%ax, %ax
620
 	xorw	%ax, %ax

+ 2
- 2
src/arch/i386/scripts/i386.lds View File

247
      * Values calculated to save code from doing it
247
      * Values calculated to save code from doing it
248
      *
248
      *
249
      */
249
      */
250
-    _text16_memsz_pgh	= ( ( _text16_memsz + 15 ) / 16 );
251
-    _data16_memsz_pgh	= ( ( _data16_memsz + 15 ) / 16 );
250
+    _text16_memsz_ppgh	= ( ( ( _text16_memsz + 63 ) / 64 ) * 4 );
251
+    _data16_memsz_ppgh	= ( ( ( _data16_memsz + 63 ) / 64 ) * 4 );
252
     _textdata_memsz_pgh	= ( ( _textdata_memsz + 15 ) / 16 );
252
     _textdata_memsz_pgh	= ( ( _textdata_memsz + 15 ) / 16 );
253
     _textdata_memsz_kb	= ( ( _textdata_memsz + 1023 ) / 1024 );
253
     _textdata_memsz_kb	= ( ( _textdata_memsz + 1023 ) / 1024 );
254
 }
254
 }

Loading…
Cancel
Save