From patchwork Tue Apr 28 10:32:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Borntraeger X-Patchwork-Id: 465472 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 208001401DA for ; Tue, 28 Apr 2015 20:33:00 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933220AbbD1Kc6 (ORCPT ); Tue, 28 Apr 2015 06:32:58 -0400 Received: from e06smtp11.uk.ibm.com ([195.75.94.107]:42947 "EHLO e06smtp11.uk.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933164AbbD1Kc6 (ORCPT ); Tue, 28 Apr 2015 06:32:58 -0400 Received: from /spool/local by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 28 Apr 2015 11:32:56 +0100 Received: from d06dlp02.portsmouth.uk.ibm.com (9.149.20.14) by e06smtp11.uk.ibm.com (192.168.101.141) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 28 Apr 2015 11:32:53 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id 1251E2190056; Tue, 28 Apr 2015 11:32:36 +0100 (BST) Received: from d06av04.portsmouth.uk.ibm.com (d06av04.portsmouth.uk.ibm.com [9.149.37.216]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t3SAWrNO50790540; Tue, 28 Apr 2015 10:32:53 GMT Received: from d06av04.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av04.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t3SAWobi024871; Tue, 28 Apr 2015 04:32:52 -0600 Received: from tuxmaker.boeblingen.de.ibm.com (tuxmaker.boeblingen.de.ibm.com [9.152.85.9]) by d06av04.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id t3SAWnoC024841; Tue, 28 Apr 2015 04:32:49 -0600 Received: by tuxmaker.boeblingen.de.ibm.com (Postfix, from userid 25651) id BE27A1224435; Tue, 28 Apr 2015 12:32:49 +0200 (CEST) From: Christian Borntraeger To: Paolo Bonzini Cc: KVM , kvm-ppc@vger.kernel.org, kvmarm@lists.cs.columbia.edu, linux-mips@linux-mips.org, Cornelia Huck , Alexander Graf , Christian Borntraeger Subject: [PATCH/RFC 1/2] KVM: Push down irq_save to architectures before kvm_guest_enter Date: Tue, 28 Apr 2015 12:32:47 +0200 Message-Id: <1430217168-25504-2-git-send-email-borntraeger@de.ibm.com> X-Mailer: git-send-email 2.3.0 In-Reply-To: <1430217168-25504-1-git-send-email-borntraeger@de.ibm.com> References: <1430217168-25504-1-git-send-email-borntraeger@de.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15042810-0041-0000-0000-00000438DC37 Sender: kvm-ppc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm-ppc@vger.kernel.org local_irq_disable can be cheaper than local_irq_save, especially when done only once instead of twice. We can push down the local_irq_save (and replace it with local_irq_disable) to save some cycles. x86, mips and arm already disable the interrupts before calling kvm_guest_enter. Here we save one local_irq_save/restore pair. power and s390 are reworked to disable the interrupts before calling kvm_guest_enter. s390 saves a preempt_disable/enable pair but also saves some cycles as local_irq_disable/enable can be cheaper than local_irq_save/restore on some machines. power should be almost a no-op change (interrupts are disabled slighty longer). Signed-off-by: Christian Borntraeger --- arch/powerpc/kvm/book3s_hv.c | 2 ++ arch/s390/kvm/kvm-s390.c | 4 ++-- include/linux/kvm_host.h | 14 ++++++++------ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c index de74756..a5f392d 100644 --- a/arch/powerpc/kvm/book3s_hv.c +++ b/arch/powerpc/kvm/book3s_hv.c @@ -1779,7 +1779,9 @@ static void kvmppc_run_core(struct kvmppc_vcore *vc) spin_unlock(&vc->lock); + local_irq_disable(); kvm_guest_enter(); + local_irq_enable(); srcu_idx = srcu_read_lock(&vc->kvm->srcu); diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c index 46f37df..9f4c954 100644 --- a/arch/s390/kvm/kvm-s390.c +++ b/arch/s390/kvm/kvm-s390.c @@ -2010,9 +2010,9 @@ static int __vcpu_run(struct kvm_vcpu *vcpu) * As PF_VCPU will be used in fault handler, between * guest_enter and guest_exit should be no uaccess. */ - preempt_disable(); + local_irq_disable(); kvm_guest_enter(); - preempt_enable(); + local_irq_enable(); exit_reason = sie64a(vcpu->arch.sie_block, vcpu->run->s.regs.gprs); kvm_guest_exit(); diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index d12b210..a34bf6ed 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -751,13 +751,15 @@ static inline void kvm_iommu_unmap_pages(struct kvm *kvm, static inline void kvm_guest_enter(void) { - unsigned long flags; - - BUG_ON(preemptible()); - - local_irq_save(flags); + /* + * guest_enter needs disabled irqs and rcu_virt_note_context_switch + * wants disabled preemption. Ensure that the caller has disabled + * irqs for kvm_guest_enter. Please note: Some architectures (e.g. + * s390) will reenable irqs before entering the guest, but this is + * ok. We just need a stable CPU for the accounting itself. + */ + WARN_ON(!irqs_disabled()); guest_enter(); - local_irq_restore(flags); /* KVM does not hold any references to rcu protected data when it * switches CPU into a guest mode. In fact switching to a guest mode