All of lore.kernel.org
 help / color / mirror / Atom feed
* VMX Assist and x86 segment registers
@ 2006-05-31  6:41 Randy Thelen
  2006-05-31  9:02 ` Petersson, Mats
  2006-05-31 15:07 ` Anthony Liguori
  0 siblings, 2 replies; 12+ messages in thread
From: Randy Thelen @ 2006-05-31  6:41 UTC (permalink / raw)
  To: xen-devel

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

Executive summary --

If you're interested in running FreeBSD in an HVM domain on VT-x  
hardware, please EXPERIMENT with the attached patch.  However, the  
patch is not in and of itself a fix.  I'm simply looking for more  
help on solving this bigger problem and pushing the patch to the Xen  
community is the best way I could think of to get more insight into  
the problem.

If you're still interested, please continue reading.

Folks --

Here's an esoteric topic: x86 segment registers and their emulation  
with vmxassist.  Anybody interested in engaging in this one? ;-)

Here's the story.  FreeBSD doesn't boot on Intel processors with VT-x  
hardware in an HVM domain.  It turns out I'm dependent upon that  
functionality.  So, I began to investigate.  Dragons lie in them thar  
hills.  (Snakes, spiders, whatever: I -hate- segmentation and I - 
hate- segment registers.  So you can imagine the frustration I had as  
I realized I needed to become intimately familiar with them to solve  
my problem.)

Here's the deal, the x86 processor allows segment registers to be set  
in one mode (e.g., "real mode") and the used in another mode (e.g.,  
"protected mode").  For an example of how this trick is utilized,  
peruse subject 15:  Accessing 4 Gigs of Memory in Real Mode:

http://www.cs.uu.nl/wais/html/na-dir/assembly-language/x86/general/ 
part2.html

(Be prepared to be completely disgusted.)

At any rate, between my own debugging and reading articles of the  
sort above, I realized that vmxassist was incorrectly handling  
segment registers.

I've made a patch that I've attached but I am -NOT- recommending this  
for general consumption.  This patch is -ONLY- recommended for those  
who want to run FreeBSD on VT-x hardware and those who are willing to  
work through additional bugs to solve interesting problems.  (If you  
have an interest in running other OSes on VT-x hardware, you're free  
to try the patch, but I can't say that I'll spend much time trying to  
solve the problems you bump into.)

I believe that the current handling of segment registers in vmxassist  
isn't quite right.  A more complicated model needs to be developed.   
I'm not sure exactly how different it needs to be or exactly in what  
ways it needs to be modified.

But, if this topic interests you, I'd be interested in continuing  
this discussion.

Once you apply the patch, you'll need to perform a make in the xen/ 
tools/firmware directory.  That will cause a new hvmloader to be  
constructed.  You can either install it (I don't recommend it) or you  
can modify your configuration file(s) so that the "kernel" is this  
new hvmloader file:

kernel = "/usr/src/xen-3.0-testing/tools/firmware/hvmloader/hvmloader"

If you've read this far, you might take interest in rereading my post  
on this problem:

http://lists.xensource.com/archives/html/xen-devel/2006-05/msg01300.html

-- Randy Thelen

[-- Attachment #2: v86-segment.patch --]
[-- Type: application/octet-stream, Size: 1044 bytes --]

diff -r edefe24d78bd tools/firmware/vmxassist/vm86.c
--- a/tools/firmware/vmxassist/vm86.c	Tue Apr 11 12:51:48 2006 +0100
+++ b/tools/firmware/vmxassist/vm86.c	Tue May 30 23:17:06 2006 -0700
@@ -749,8 +749,22 @@ load_seg(unsigned long sel, uint32_t *ba
 		return 0;
 
 	if (sel == 0) {
-		arbytes->fields.null_bit = 1;
-		return 1;
+		/*
+		 * Create an entry with the following properties:
+		 * base = 0, limit = 1MB
+		 * Present, DPL = 0, granularity = 4KB
+		 * seg type = data, grow up, writable, not accessed.
+		 * 32 bit code in the segment.
+		 * This segment may not be an ideal segment descriptor
+		 * but I selected it (from FreeBSD, in fact) because
+		 * with a selector in 16 bit mode with a value of 0,
+		 * that means that the 1MB starting at address 0 is
+		 * available to the code.  This simply tries to
+		 * immitate that behavior.
+		 */
+		entry = 0x00cf92000000ffffULL;
+	} else {
+		entry =  ((unsigned long long *) oldctx.gdtr_base)[sel >> 3];
 	}
 
 	entry =  ((unsigned long long *) oldctx.gdtr_base)[sel >> 3];

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

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

^ permalink raw reply	[flat|nested] 12+ messages in thread
* RE: VMX Assist and x86 segment registers
@ 2006-06-02  2:02 Kamble, Nitin A
  2006-06-02 15:30 ` Leendert Van Doorn
  0 siblings, 1 reply; 12+ messages in thread
From: Kamble, Nitin A @ 2006-06-02  2:02 UTC (permalink / raw)
  To: Khoa Huynh, aliguori, Leendert Van Doorn
  Cc: Yu, Wilfred, Mallick, Asit K, xen-devel, Nakajima, Jun

Khoa,
  Before vmxassist we were using Gunnison emulator inside Intel to do
the real mode emulation. We still have that code around. 
  I would like to know what is your time line for completing the qemu-dm
task?

Thanks & Regards,
Nitin
------------------------------------------------------------------------
-----------
Open Source Technology Center, Intel Corp

>-----Original Message-----
>From: xen-devel-bounces@lists.xensource.com [mailto:xen-devel-
>bounces@lists.xensource.com] On Behalf Of Khoa Huynh
>Sent: Wednesday, May 31, 2006 9:20 AM
>To: aliguori@us.ibm.com
>Cc: Randy Thelen; xen-devel@lists.xensource.com; xen-devel-
>bounces@lists.xensource.com
>Subject: Re: [Xen-devel] VMX Assist and x86 segment registers
>
>
>
>aliguori@us.ltcfwd.linux.ibm.com wrote on 05/31/2006 10:07:08 AM:
>
>> Big real mode is definitely a problem in vm86 mode.  FreeBSD is also
>> notorious for its use of segmentation :-)  I think it has been
proposed
>> that a potential solution is to do away with vmxassist entirely and
>> instead use qemu to emulate 16 bit mode (or another emulator if
>> available).  Not sure if anyone is actually working on that yet
though.
>> It seems to be the most promising solution.
>
>Yes, we are thinking of putting a full instruction emulator into
>qemu-dm and emulating 16-bit stuff in qemu-dm instead of using
>vmxassist (vmxassist will go away).  Leendert van Doorn and I are
>working on this.  Thanks.
>
>Regards,
>Khoa
>
>
>_______________________________________________
>Xen-devel mailing list
>Xen-devel@lists.xensource.com
>http://lists.xensource.com/xen-devel

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2006-06-02 15:30 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-05-31  6:41 VMX Assist and x86 segment registers Randy Thelen
2006-05-31  9:02 ` Petersson, Mats
2006-05-31 15:07 ` Anthony Liguori
2006-05-31 16:19   ` Khoa Huynh
2006-05-31 17:07     ` Randy Thelen
2006-05-31 17:16       ` Petersson, Mats
2006-05-31 19:31       ` Anthony Liguori
2006-05-31 22:22         ` Randy Thelen
2006-06-01  9:33         ` Petersson, Mats
2006-06-01 20:48           ` Anthony Liguori
  -- strict thread matches above, loose matches on Subject: below --
2006-06-02  2:02 Kamble, Nitin A
2006-06-02 15:30 ` Leendert Van Doorn

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.