linux-mips
[Top] [All Lists]

Re: [PATCH 04/20] KVM/MIPS32: MIPS arch specific APIs for KVM

To: Avi Kivity <avi@redhat.com>
Subject: Re: [PATCH 04/20] KVM/MIPS32: MIPS arch specific APIs for KVM
From: Sanjay Lal <sanjayl@kymasys.com>
Date: Wed, 14 Nov 2012 17:32:38 -0500
Cc: kvm@vger.kernel.org, linux-mips@linux-mips.org
In-reply-to: <509292CD.5030700@redhat.com>
List-archive: <http://www.linux-mips.org/archives/linux-mips/>
List-help: <mailto:ecartis@linux-mips.org?Subject=help>
List-id: linux-mips <linux-mips.eddie.linux-mips.org>
List-owner: <mailto:ralf@linux-mips.org>
List-post: <mailto:linux-mips@linux-mips.org>
List-software: Ecartis version 1.0.0
List-subscribe: <mailto:ecartis@linux-mips.org?subject=subscribe%20linux-mips>
List-unsubscribe: <mailto:ecartis@linux-mips.org?subject=unsubscribe%20linux-mips>
References: <74E3548E-9F3A-4849-BD5A-D1AAE19A0982@kymasys.com> <509292CD.5030700@redhat.com>
Sender: linux-mips-bounce@linux-mips.org
On Nov 1, 2012, at 11:18 AM, Avi Kivity wrote:

>> +
>> +    /* Set the appropriate status bits based on host CPU features, before 
>> we hit the scheduler */
>> +    kvm_mips_set_c0_status();
>> +
>> +    local_irq_enable();
> 
> Ah, so you handle exits with interrupts enabled.  But that's not how we
> usually do it; the standard pattern is
> 
> 
> while (can continue)
>     disable interrupts
>     enter guest
>     enable interrupts
>     process exit

A bit more detail here. KVM/MIPS has its own set of exception handlers which 
are separate from the host kernel's handlers.  We switch between the 2 sets of 
handlers by setting the Exception Base Register (EBASE).  We enable host 
interrupts just before we switch to guest context so that we trap when the host 
gets a timer or I/O interrupt.  

When an exception does occur in guest context, the KVM/MIPS handlers will save 
the guest context, and switch back to the default host kernel exception 
handlers. We enter the "C" handler (kvm_mips_handle_exit()) with interrupts 
disabled, and explicitly enable them there.  This allows the host kernel to 
handle any pending interrupts.

The sequence is as follows
while (can continue)
        disable interrupts
        trampoline code to save host kernel context, load guest context
        enable host interrupts
        enter guest context
        KVM/MIPS trap handler (called with interrupts disabled, per MIPS 
architecture)
        Restore host Linux context, setup stack to handle exception
        Jump to "C" handler
        Enable interrupts before handling VM exit.
        

Regards
Sanjay




<Prev in Thread] Current Thread [Next in Thread>