From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751383AbdBOP4n (ORCPT ); Wed, 15 Feb 2017 10:56:43 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:35429 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750806AbdBOP4l (ORCPT ); Wed, 15 Feb 2017 10:56:41 -0500 Subject: Re: [PATCH] KVM: race-free exit from KVM_RUN without POSIX signals To: Christian Borntraeger , linux-kernel@vger.kernel.org, kvm@vger.kernel.org References: <1487169821-14806-1-git-send-email-pbonzini@redhat.com> <2f9cd5cd-1bb5-0d9e-cb84-26615b211523@de.ibm.com> Cc: james.hogan@imgtec.com, marc.zyngier@arm.com, kvm-ppc@vger.kernel.org, paulus@samba.org, cornelia.huck@de.ibm.com, kvmarm@lists.cs.columbia.edu From: Paolo Bonzini Message-ID: <1359d10f-1bee-e295-912d-8cdc5bf7a98c@redhat.com> Date: Wed, 15 Feb 2017 16:56:42 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 MIME-Version: 1.0 In-Reply-To: <2f9cd5cd-1bb5-0d9e-cb84-26615b211523@de.ibm.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 15/02/2017 16:24, Christian Borntraeger wrote: > On 02/15/2017 03:43 PM, Paolo Bonzini wrote: >> The purpose of the KVM_SET_SIGNAL_MASK API is to let userspace "kick" >> a VCPU out of KVM_RUN through a POSIX signal. A signal is attached >> to a dummy signal handler; by blocking the signal outside KVM_RUN and >> unblocking it inside, this possible race is closed: >> >> VCPU thread service thread >> -------------------------------------------------------------- >> check flag >> set flag >> raise signal >> (signal handler does nothing) >> KVM_RUN >> >> However, one issue with KVM_SET_SIGNAL_MASK is that it has to take >> tsk->sighand->siglock on every KVM_RUN. This lock is often on a >> remote NUMA node, because it is on the node of a thread's creator. >> Taking this lock can be very expensive if there are many userspace >> exits (as is the case for SMP Windows VMs without Hyper-V reference >> time counter). >> >> As an alternative, we can put the flag directly in kvm_run so that >> KVM can see it: >> >> VCPU thread service thread >> -------------------------------------------------------------- >> raise signal >> signal handler >> set run->immediate_exit >> KVM_RUN >> check run->immediate_exit >> >> Signed-off-by: Paolo Bonzini > > > Generic parts, the concept and the s390 parts looks good. (not tested yet, though) Note that this series doesn't work (due to David's suggestion) with the patches I posted last week. Paolo From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paolo Bonzini Date: Wed, 15 Feb 2017 15:56:42 +0000 Subject: Re: [PATCH] KVM: race-free exit from KVM_RUN without POSIX signals Message-Id: <1359d10f-1bee-e295-912d-8cdc5bf7a98c@redhat.com> List-Id: References: <1487169821-14806-1-git-send-email-pbonzini@redhat.com> <2f9cd5cd-1bb5-0d9e-cb84-26615b211523@de.ibm.com> In-Reply-To: <2f9cd5cd-1bb5-0d9e-cb84-26615b211523@de.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Christian Borntraeger , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: james.hogan@imgtec.com, marc.zyngier@arm.com, kvm-ppc@vger.kernel.org, paulus@samba.org, cornelia.huck@de.ibm.com, kvmarm@lists.cs.columbia.edu On 15/02/2017 16:24, Christian Borntraeger wrote: > On 02/15/2017 03:43 PM, Paolo Bonzini wrote: >> The purpose of the KVM_SET_SIGNAL_MASK API is to let userspace "kick" >> a VCPU out of KVM_RUN through a POSIX signal. A signal is attached >> to a dummy signal handler; by blocking the signal outside KVM_RUN and >> unblocking it inside, this possible race is closed: >> >> VCPU thread service thread >> -------------------------------------------------------------- >> check flag >> set flag >> raise signal >> (signal handler does nothing) >> KVM_RUN >> >> However, one issue with KVM_SET_SIGNAL_MASK is that it has to take >> tsk->sighand->siglock on every KVM_RUN. This lock is often on a >> remote NUMA node, because it is on the node of a thread's creator. >> Taking this lock can be very expensive if there are many userspace >> exits (as is the case for SMP Windows VMs without Hyper-V reference >> time counter). >> >> As an alternative, we can put the flag directly in kvm_run so that >> KVM can see it: >> >> VCPU thread service thread >> -------------------------------------------------------------- >> raise signal >> signal handler >> set run->immediate_exit >> KVM_RUN >> check run->immediate_exit >> >> Signed-off-by: Paolo Bonzini > > > Generic parts, the concept and the s390 parts looks good. (not tested yet, though) Note that this series doesn't work (due to David's suggestion) with the patches I posted last week. Paolo