public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Anthony Liguori <anthony-rdkfGonbjUSkNkDKm+mE6A@public.gmane.org>
To: Avi Kivity <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
Cc: kvm-devel
	<kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>,
	Steffen Winterfeldt <snwint-l3A5Bk7waGM@public.gmane.org>
Subject: Re: [GFXBOOT] [PATCH] When switching to real-mode, pass SS in a GP register
Date: Sun, 30 Sep 2007 02:08:03 -0500	[thread overview]
Message-ID: <46FF4B53.5070807@codemonkey.ws> (raw)
In-Reply-To: <46FF3DF3.7040503-atKUWr5tajBWk0Htik3J/w@public.gmane.org>

[-- Attachment #1: Type: text/plain, Size: 2411 bytes --]

Avi Kivity wrote:
> Anthony Liguori wrote:
>   
>> Hi Steffen,
>>
>> As Avi pointed out, VT requires that SS.RPL == CS.RPL.  We're seeing
>> gfxboot fail under KVM because ss = 0x5761 while cs = 0x4004 during
>> the transition from real mode to protected mode.  The attached patch
>> passes the value of ss through ebx since KVM has to sanitize the value
>> of ss to make VT happy.
>>
>> I've tested this with a remastered Ubuntu Gutsy install CD.  I
>> couldn't find the right gfxboot theme for the openSuSE install CD I
>> have so I wasn't able to test it.
>>
>> I suspect that Xen should have a very similar problem as I can't think
>> of a possible way to work around this.
>>
>>     
>
>   
>> diff -ur a/bincode.asm b/bincode.asm
>> --- a/bincode.asm	2007-07-24 05:49:46.000000000 -0500
>> +++ b/bincode.asm	2007-09-29 22:14:35.000000000 -0500
>> @@ -15519,6 +15519,7 @@
>>  switch_to_pm:
>>  		pushf
>>  		push eax
>> +		push ebx
>>  
>>  		mov eax,cr0
>>  
>> @@ -15534,6 +15535,11 @@
>>  		mov word [cs:rm_seg.fs],fs
>>  		mov word [cs:rm_seg.gs],gs
>>  
>> +		;; ss:rpl must equal cs:rpl in PM for VT.  we can't rely on ss
>> +		;; maintaining it's value after the transition so we have to
>> +		;; pass it in a GP register
>> +		mov ebx,ss
>> +	
>>  		or al,1
>>  		o32 lgdt [cs:pm_gdt]
>>  		o32 lidt [cs:pm_idt]
>> @@ -15546,7 +15552,7 @@
>>  		mov ax,pm_seg.prog_d16
>>  		mov ds,ax
>>  
>> -		mov eax,ss
>> +		mov eax,ebx
>>  		and esp,0ffffh
>>  		shl eax,4
>>   
>>     
>
> This is subtly wrong, I think.  First, note that 'mov eax,ss' only
> affects ax, not the high 16 bits.  The note that the original code
> happily shifts eax which is half ss, half garbage left by 4 bits and
> uses that to generate a 32-bit result.
>
> The reason it worked before was that bits 16-29 of eax are already clear
> by virtue of having come from cr0.  But now you're using ebx which
> hasn't had that magic clearing.
>   

You're right.  Good catch!

> In your comment to the kvm bug you say that the patch allows you to
> boot, so perhaps bits 16-29 of ebx are already clear here, or my
> analysis is mistaken.
>   

Yeah, I just got lucky with ebx I guess :-)  Attached is an updated 
patch that fixes this problem.

Regards,

Anthony Liguori

>>  		add esp,eax
>> @@ -15557,6 +15563,7 @@
>>  		mov fs,ax
>>  		mov gs,ax
>>  
>> +		pop ebx
>>  		pop eax
>>  		popfw
>>  		o16 ret
>>   
>>     
>
>
>
>   


[-- Attachment #2: gfxboot-3.3.38-vt-1.diff --]
[-- Type: text/x-patch, Size: 792 bytes --]

diff -ur a/bincode.asm b/bincode.asm
--- a/bincode.asm	2007-07-24 05:49:46.000000000 -0500
+++ b/bincode.asm	2007-09-30 01:56:48.000000000 -0500
@@ -15519,6 +15519,7 @@
 switch_to_pm:
 		pushf
 		push eax
+		push ebx
 
 		mov eax,cr0
 
@@ -15534,6 +15535,11 @@
 		mov word [cs:rm_seg.fs],fs
 		mov word [cs:rm_seg.gs],gs
 
+		;; ss:rpl must equal cs:rpl in PM for VT.  we can't rely on ss
+		;; maintaining it's value after the transition so we have to
+		;; pass it in a GP register
+		mov ebx,ss
+	
 		or al,1
 		o32 lgdt [cs:pm_gdt]
 		o32 lidt [cs:pm_idt]
@@ -15546,7 +15552,7 @@
 		mov ax,pm_seg.prog_d16
 		mov ds,ax
 
-		mov eax,ss
+		mov ax,bx
 		and esp,0ffffh
 		shl eax,4
 		add esp,eax
@@ -15557,6 +15563,7 @@
 		mov fs,ax
 		mov gs,ax
 
+		pop ebx
 		pop eax
 		popfw
 		o16 ret

[-- Attachment #3: Type: text/plain, Size: 228 bytes --]

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

[-- Attachment #4: Type: text/plain, Size: 186 bytes --]

_______________________________________________
kvm-devel mailing list
kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/kvm-devel

  parent reply	other threads:[~2007-09-30  7:08 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-30  4:29 [GFXBOOT] [PATCH] When switching to real-mode, pass SS in a GP register Anthony Liguori
     [not found] ` <46FF262C.9000900-rdkfGonbjUSkNkDKm+mE6A@public.gmane.org>
2007-09-30  6:10   ` Avi Kivity
     [not found]     ` <46FF3DF3.7040503-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-09-30  7:08       ` Anthony Liguori [this message]
     [not found]         ` <46FF4B53.5070807-rdkfGonbjUSkNkDKm+mE6A@public.gmane.org>
2007-10-08 10:52           ` Steffen Winterfeldt
     [not found]             ` <Pine.LNX.4.64.0710081237050.22177-128n8RpADxRbpigZmTR7Iw@public.gmane.org>
2007-10-11 14:53               ` Anthony Liguori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=46FF4B53.5070807@codemonkey.ws \
    --to=anthony-rdkfgonbjusknkdkm+me6a@public.gmane.org \
    --cc=avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org \
    --cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    --cc=snwint-l3A5Bk7waGM@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox