From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [PATCH 0/7] Consolidate vcpu ioctl locking Date: Sat, 15 May 2010 09:16:54 +0300 Message-ID: <4BEE3C56.2070007@redhat.com> References: <1273749459-622-1-git-send-email-avi@redhat.com> <4BEBEA25.8080309@redhat.com> <4BEBEA7E.80202@redhat.com> <4BEBEAAE.9030502@redhat.com> <24423079-CDE0-4DEA-BC73-3B6976BE0CA6@suse.de> <4BEBF0BF.2020404@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Cc: Marcelo Tosatti , "kvm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org" , "kvm-ia64-u79uwXL29TY76Z2rM5mHXA@public.gmane.org" , "kvm-ppc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org" , "carsteno-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org" To: Alexander Graf Return-path: In-Reply-To: Sender: kvm-ppc-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org List-Id: kvm.vger.kernel.org On 05/13/2010 10:49 PM, Alexander Graf wrote: > > Am 13.05.2010 um 14:29 schrieb Avi Kivity : > >> On 05/13/2010 03:18 PM, Alexander Graf wrote: >>> >>>> [PATCH 0/7] Consolidate vcpu ioctl locking >>>> >>>> In general, all vcpu ioctls need to take the vcpu mutex, but each >>>> one does it >>>> (or not) individually. This is cumbersome and error prone. >>>> >>>> This patchset moves all locking to a central place. This is >>>> complicated >>>> by the fact that ppc's KVM_INTERRUPT and s390's KVM_S390_INTERRUPT >>>> break >>>> the convention and need to run unlocked. >>>> >>> Why is the x86 non-kernel-pic path different? >>> >> >> Userspace issues the ioctl from a vcpu thread. >> >> It has to, btw, since whether an interrupt can be injected or not >> depends on vcpu-synchronous registers: eflags.if and tpr/cr8. > > On ppc we don't have a tpr, but eflags.if is basically the same as > msr.ee. > > The major difference apparently is that on ppc we KVM_INTERRUPT pulls > the interrupt line. On vcpu_run we then check whether msr.ee is set > and if so, trigger the interrupt. > > I wonder why we don't do the same for x86. The current limitation on > userspace checking eflags and the tpr seems cumbersome. On x86 eflags.if is freely changeable by the guest, so if we want to queue an interrupt we have to IPI the vcpu to force it out of guest mode, so we can inspect eflags. This means the vcpu thread has to be interrupted one way or another. The tpr (really ppr) is even more problematic as it is maintained in userspace, not in the kernel (for non-kernel-irqchip). It could in theory be inspected by another thread, but we wouldn't gain anything by it due to the requirement to IPI. > void kvmppc_book3s_queue_irqprio(struct kvm_vcpu *vcpu, unsigned int vec) > { > vcpu->stat.queue_intr++; > > set_bit(kvmppc_book3s_vec2irqprio(vec), > &vcpu->arch.pending_exceptions); > #ifdef EXIT_DEBUG > printk(KERN_INFO "Queueing interrupt %x\n", vec); > #endif > } Isn't this missing an IPI if the vcpu is in guest mode? -- Do not meddle in the internals of kernels, for they are subtle and quick to panic.