Skip to contentSkip to conversation

tpr optimization: clear the vapic area on boot

PATCH In review Avi Kivity 1 participant 2 messages Nov 16, 2010 KVM

lore
Share & tools
lore

Avi Kivity

author
#0 lore raw

PATCH 1/1 tpr optimization: clear the vapic area on boot

If the option rom is loaded with rep/insb (as newer seabios versions do), then the writes to the vapic area may be corrupted by the kernel.

Fix by explicitly clearing the vapic area on option rom startup.

---
 pc-bios/bios.bin          |  Bin 131072 -> 131072 bytes
 pc-bios/optionrom/vapic.S |   11 +++++++++++
 2 files changed, 11 insertions(+), 0 deletions(-)
pc-bios/bios.bin binary +0 -0
index f79c342264ebfce9b393d5809079cb4ec3c3a899..d0d4b6aa43b8f306062797b8e53ce469f8c2820f 100644
GIT binary patch
pc-bios/optionrom/vapic.S +11 -0
index afe98a9..3c8dcf1 100644
@@ -4,6 +4,17 @@
 _start:
 	.short 0xaa55
 	.byte (_end - _start) / 512
+	# clear vapic area: firmware load using rep insb may cause
+	# stale tpr/isr/irr data to corrupt the vapic area.
+	push %es
+	push %cs
+	pop %es
+	xor %ax, %ax
+	mov $vapic_size/2, %cx
+	lea vapic, %di
+	cld
+	rep stosw
+	pop %es
 	mov $vapic_base, %ax
 	out %ax, $0x7e
 	lret
Signature · 1 line
1.7.3.1
author
#1 lore raw
Quoted 8 lines · Avi Kivity

If the option rom is loaded with rep/insb (as newer seabios versions do), then the writes to the vapic area may be corrupted by the kernel.

Fix by explicitly clearing the vapic area on option rom startup.

---
  pc-bios/bios.bin          |  Bin 131072 ->  131072 bytes

This bit was unintended.

Quoted 12 lines
pc-bios/optionrom/vapic.S +4 -0
index afe98a9..3c8dcf1 100644
@@ -4,6 +4,17 @@
  _start:
  	.short 0xaa55
  	.byte (_end - _start) / 512
+	# clear vapic area: firmware load using rep insb may cause
+	# stale tpr/isr/irr data to corrupt the vapic area.
+	push %es
+	push %cs

pc-bios/optionrom/vapic.S line 20

Quoted 10 lines
pc-bios/optionrom/vapic.S +7 -0
+	pop %es
+	xor %ax, %ax
+	mov $vapic_size/2, %cx
+	lea vapic, %di
+	cld
+	rep stosw
+	pop %es
  	mov $vapic_base, %ax
  	out %ax, $0x7e
  	lret

This is the interesting part.

Signature · 1 line
error compiling committee.c: too many arguments to function