From patchwork Thu Jun 14 11:42:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Martin X-Patchwork-Id: 10464005 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1F8F36020F for ; Thu, 14 Jun 2018 11:44:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0BABC28A6F for ; Thu, 14 Jun 2018 11:44:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F19A128A78; Thu, 14 Jun 2018 11:44:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6A8B828A6F for ; Thu, 14 Jun 2018 11:44:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=+BpX6aUNFAeDpgphn/znYHPFGxBrAFkM6LSqncVXejI=; b=YwdwAzKAGN8t+5mpoQSc69AHfY r84y4IgUvpsA93IuhdCCi5Zk7QEj72Z3hhTLdgTiHorr0eQHKoLGddUtuyo6XUVWXHC0A6iJCEQrK PyZETY+ISXVWUlPq7dTkQGW/xDV0Z9PZHxy25WFaFgkY9Cm+Bx3SNVwPqidHcCHwkjnL+/hBttjzA h0lXZTk69P/lXT8+tVeVj6ckLg0W+p1RjbRobRqpd05wOazjwsdqblzyJSAQtrvfMX8svOJHeT+ZQ KjZdZGrtTW/zN9lCxnzwGyG89NvhhS4K//Iw2kAbtJ98lekX+bpRvBtJm4p+T1l+YO+6jlrnmWahX qnBK6yqg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fTQfS-0001DJ-QM; Thu, 14 Jun 2018 11:43:54 +0000 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70] helo=foss.arm.com) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fTQeP-0000aM-7R for linux-arm-kernel@lists.infradead.org; Thu, 14 Jun 2018 11:42:51 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3510815AB; Thu, 14 Jun 2018 04:42:38 -0700 (PDT) Received: from e103592.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C6ADF3F59D; Thu, 14 Jun 2018 04:42:36 -0700 (PDT) From: Dave Martin To: kvmarm@lists.cs.columbia.edu Subject: [PATCH 2/4] KVM: arm64: Don't mask softirq with IRQs disabled in vcpu_put() Date: Thu, 14 Jun 2018 12:42:24 +0100 Message-Id: <1528976546-25999-2-git-send-email-Dave.Martin@arm.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1528976546-25999-1-git-send-email-Dave.Martin@arm.com> References: <1528976039-25826-1-git-send-email-Dave.Martin@arm.com> <1528976546-25999-1-git-send-email-Dave.Martin@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180614_044249_277467_12055C27 X-CRM114-Status: GOOD ( 12.69 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Christoffer Dall , Ard Biesheuvel , Marc Zyngier , Catalin Marinas , Will Deacon , Andre Przywara , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Commit e6b673b ("KVM: arm64: Optimise FPSIMD handling to reduce guest/host thrashing") introduces a specific helper kvm_arch_vcpu_put_fp() for saving the vcpu FPSIMD state during vcpu_put(). This function uses local_bh_disable()/_enable() to protect the FPSIMD context manipulation from interruption by softirqs. This approach is not correct, because vcpu_put() can be invoked either from the KVM host vcpu thread (when exiting the vcpu run loop), or via a preempt notifier. In the former case, only preemption is disabled. In the latter case, the function is called from inside __schedule(), which means that IRQs are disabled. Use of local_bh_disable()/_enable() with IRQs disabled is considerd an error, resulting in lockdep splats while running VMs if lockdep is enabled. It is probably possible in theory to relax this restriction on local_bh_disable()/_enable() usage, but for now this patch takes the simple approach of managing softirq masking only if IRQs happen to be enabled when kvm_arch_vcpu_put_fp() is called. Fixes: e6b673b741ea ("KVM: arm64: Optimise FPSIMD handling to reduce guest/host thrashing") Reported-by: Andre Przywara Signed-off-by: Dave Martin --- arch/arm64/kvm/fpsimd.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/arch/arm64/kvm/fpsimd.c b/arch/arm64/kvm/fpsimd.c index dc6ecfa..b51ff80 100644 --- a/arch/arm64/kvm/fpsimd.c +++ b/arch/arm64/kvm/fpsimd.c @@ -90,10 +90,8 @@ void kvm_arch_vcpu_ctxsync_fp(struct kvm_vcpu *vcpu) * disappears and another task or vcpu appears that recycles the same * struct fpsimd_state. */ -void kvm_arch_vcpu_put_fp(struct kvm_vcpu *vcpu) +static void __kvm_arch_vcpu_put_fp(struct kvm_vcpu *vcpu) { - local_bh_disable(); - update_thread_flag(TIF_SVE, vcpu->arch.flags & KVM_ARM64_HOST_SVE_IN_USE); @@ -105,6 +103,16 @@ void kvm_arch_vcpu_put_fp(struct kvm_vcpu *vcpu) /* Ensure user trap controls are correctly restored */ fpsimd_bind_task_to_cpu(); } +} + - local_bh_enable(); +void kvm_arch_vcpu_put_fp(struct kvm_vcpu *vcpu) +{ + if (irqs_disabled()) + __kvm_arch_vcpu_put_fp(vcpu); + else { + local_bh_disable(); + __kvm_arch_vcpu_put_fp(vcpu); + local_bh_enable(); + } }