public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
To: Omar Khan <okhan-e94Sedi4moU@public.gmane.org>
Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Subject: Re: unix lite
Date: Tue, 24 Apr 2007 11:41:06 +0300	[thread overview]
Message-ID: <462DC2A2.2000403@qumranet.com> (raw)
In-Reply-To: <loom.20070423T164130-191-eS7Uydv5nfjZ+VzJOa5vwg@public.gmane.org>

Omar Khan wrote:
> hi,
>    
>    I am trying to run unix like operating system (mainly meant for educational
> purposes) on kvm called "Unix Lite" (http://www.unixlite.org/). It runs fine on
> qemu but on kvm it gives the unhandled vm exit 0x9. This is caused by the
> hardware task switch that is used in unix lite. The code for the switch is :
>
> void gdt_t::swtch(tss_t * from, tss_t * to)
> {
>         /* also clear "busy tss" flag */
>         tss[0].init(X86AVL386TSS, (u32_t)from, sizeof(tss_t)-1);
>         tss[1].init(X86AVL386TSS, (u32_t)to, sizeof(tss_t)-1);
>         asm volatile(
>                 "ltr %w0\n\t"
>                 "ljmp %1,$0\n\t"
>                 ::"r"(TSS0SEL),"i"(TSS1SEL));
> }
>
> As you can see the code is basically saving the context of one task and loading
> from the next. The unhandled exit is caused by the ljmp which causes the switch.
> What would be a good way to convert this to a software switch only? Just
> manually push the current state on the outgoing task state segment(we have the
> pointers to this) and load from the incoming task's state segment? I am new to
> this therefore I am not sure how to save the current CS:IP pair and whether this
> is the way to do it or not, any help/hints will be welcomed.
>   

There are two ways that you can go about this.

First, tying to change the code.  For that you need to find out exactly
what state is changed on the task switch.  If the different contexts map
the kernel differently, then you can't really change the code.  If they
don't, just follow the study task switching in the manuals and perform
the same actions in software.

Changing esp and eip is not too difficult, see Linux__switch_to() in
include/asm-i386/system.h.

Second, you can teach kvm about task switching.  Code the actions that
the processor takes into a kvm_task_switch() function and wire the
vmexit handlers accordingly.


-- 
Do not meddle in the internals of kernels, for they are subtle and quick to panic.


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

      parent reply	other threads:[~2007-04-24  8:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-23 14:57 unix lite Omar Khan
     [not found] ` <loom.20070423T164130-191-eS7Uydv5nfjZ+VzJOa5vwg@public.gmane.org>
2007-04-24  8:41   ` Avi Kivity [this message]

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=462DC2A2.2000403@qumranet.com \
    --to=avi-atkuwr5tajbwk0htik3j/w@public.gmane.org \
    --cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    --cc=okhan-e94Sedi4moU@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