Skip to contentSkip to conversation

Add Interrupt handling to kvm power kernel

PATCH In review Jerone Young 2 participants 2 messages Jan 22, 2008 – Jan 23, 2008

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add Interrupt handling to kvm power kernel

# HG changeset patch
# User Jerone Young <[email protected]>
# Date 1201042425 21600
# Node ID 7398b53dfa146c5d6931a2849bd597f43515f90c # Parent 420601e87d0e0b09f0fbafd0c48ff67e5ac0bd46 Add Interrupt handling to kvm power kernel.

This patch adds initial interrupt handling code to the kvm powerpc port.

The code works, but it a little slow. Need to do more debugging.

arch/powerpc/boot/dts/bamboo.dts +1 -1
@@ -139,7 +139,7 @@
 		   		clock-frequency = <0>; /* Filled in by zImage */
 		   		current-speed = <1c200>;
 		   		interrupt-parent = <&UIC0>;
-		   		/* interrupts = <0 4>; */
+		   		interrupts = <0 4>;
 	   		};
 
 			UART1: serial@ef600400 {
arch/powerpc/kvm/emulate.c +3 -0
@@ -632,5 +632,8 @@ int kvmppc_emulate_instruction(struct kv
 	if ((emulated = EMULATE_DONE) && advance)
 		vcpu->arch.pc += 4; /* Advance past emulated instruction. */
 
+	if (vcpu->arch.pending_ee && (vcpu->arch.guest_msr & MSR_EE))
+		kvmppc_sync_interrupt(vcpu, PPC44x_INTERRUPT_EXTERNAL);
+	
 	return emulated;
 }
arch/powerpc/kvm/powerpc.c +42 -20

93 lines not on this page · raw message

include/asm-powerpc/kvm_host.h +2 -0
@@ -125,6 +125,8 @@ struct kvm_vcpu_arch {
 
 	struct timer_list dec_timer;
 	int pending_dec;
+	int pending_ee; /* endicate pending external interrupts */
+
 };
 
 struct kvm_tlb {

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
kvm-ppc-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/kvm-ppc-devel

#1 lore raw

Re: [kvm-ppc-devel] [PATCH] Add Interrupt handling to kvm power

I'm concerned about taking two interrupts at once, which would clobber SRR0/1. Consider this case (all within a single exit):

        PC = foo (somewhere in guest)
        <external interrupt>
        SRR0 = foo
        PC = 0x500
        <decrementer interrupt>
        SRR0 = 0x500
        PC = 0x900
        resume guest

Now you can never get back to PC=foo, since SRR0 was overwritten.

So we should probably only deliver an interrupt when considering all pending interrupts. In other words, extend the test at the bottom of kvm_handle_exit() that checks pending_dec.

We probably need to remove all callers of kvmppc_sync_interrupt() and instead set the appropriate flag in a "pending" mask. Then, just before returning to the guest, do something like this:

        can_deliver(vcpu, priority) {
                return vcpu->arch.msr & priority_enabled[priority];
        }

        priority = find_first_bit(vcpu->arch.pending);
        while (priority) {
                if (can_deliver(vcpu, priority)) {
                        interrupt = priority_to_interrupt[priority];
                        kvmppc_deliver_interrupt(interrupt);
                        break;
                }
                        
                priority = find_next_bit(vcpu->arch.pending, priority);
        }

"arch.pending" would need to be in priority order. According to the architecture, when there are multiple exceptions pending (e.g. program interrupt and decrementer and external all fire at the same time), there is a well-defined list of priorities. Of course, we'd also need a table of MSR masks to check, since you can disable all these things in the MSR.

(Rename kvmppc_sync_interrupt() to kvmppc_deliver_interrupt(), since I was wrong in thinking that we could handle synchronous interrupts immediately and only defer asynchronous ones.)

Once you do that, kvm_vcpu_ioctl_interrupt() just becomes

        vcpu->arch.pending |= PRIORITY_EXTERNAL;

and all the magic happens on the subsequent KVM_RUN command. Well, I guess we'd need to insert similar magic on the RUN path (the above was on the "handle exit" path).

Signature · 13 lines
Hollis Blanchard
IBM Linux Technology Center



-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
kvm-ppc-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/kvm-ppc-devel