Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3000218imu; Mon, 19 Nov 2018 09:11:11 -0800 (PST) X-Google-Smtp-Source: AJdET5e2z4eLJP2BlIaGMrxCG7ck72uugkyTxcX4/kAWkUQ+PuUKXMcB+zh/WC6/NY3V6+HlcEUI X-Received: by 2002:a62:6486:: with SMTP id y128-v6mr24452444pfb.76.1542647471606; Mon, 19 Nov 2018 09:11:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542647471; cv=none; d=google.com; s=arc-20160816; b=Xv2c1A/YNtrOae/Ll34PWqIfM896AZgyOy2bMbJRzvX2a+XOPIha8tOAJln/fkTM2i kPWNxazOOTnW48gWKZhqLvcKMDvEPvaO9Xy2X+miqAN5M4kWs7Ec24TzVb+v80ossxQY jMWI8g3D7zN90ZyP5mZSsjyR2SDDR8LRxMmneySHdsur+/xcMqVGVrG8tPMuROMzo63M 52CJQssVcC+rMCjb8rTqGi8d40Gz/ehBn9z2MGZJ/WcsqwgiXXQyw6sn/0Q40B1UNfHY mYWhich3pnYN60il9kWrh+pVgAA+9jWXQYvmoKbP2oeR1Lszv+P87bJsR1eANk+Onabd K0NQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=Kz7k4B/IVVOLZCLGTn2lOgGQENAa+33XywDLOVydVXo=; b=ryHJ+NsHec15dREvUMGssSF6Evvu++4ZCb74p55aYl8VI6Vmzr5mgbuEPsrzxvQVcj 6/TbPmvpXQzg/FmUEl/aKCSrVqP2++uSGoOvSeYrKe6EzUp8ZWGzlM8vpLCxZVXKodf6 8q9fjDlYEvtzHH3jgVhrqnUbVhX8cJQN3tY6xMWHK20SIebryH7KNXQB2K8U1gVq7RbM WPqSoI3ya5fY8VvwevOgZc3k0dU46kaf/0wlFoH6+mX4ZKpBYmemUhu2ZZeh1aTV9BzD XcITzhVhfZSPiDjlo6a4UNiXS820qUuJpB5dVRaCoXmqfbsCFhUtZzL29AgioZ9knk8E v8AQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e39-v6si44629206plb.369.2018.11.19.09.10.54; Mon, 19 Nov 2018 09:11:11 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2407277AbeKTDca (ORCPT + 99 others); Mon, 19 Nov 2018 22:32:30 -0500 Received: from foss.arm.com ([217.140.101.70]:33312 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406505AbeKTDc3 (ORCPT ); Mon, 19 Nov 2018 22:32:29 -0500 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 C4F2A15AB; Mon, 19 Nov 2018 09:08:11 -0800 (PST) Received: from e112298-lin.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 A8FCC3F5B7; Mon, 19 Nov 2018 09:08:09 -0800 (PST) From: Julien Thierry To: linux-kernel@vger.kernel.org, kvmarm@lists.cs.columbia.edu Cc: marc.zyngier@arm.com, Christoffer.Dall@arm.com, linux-arm-kernel@lists.infradead.org, linux-rt-users@vger.kernel.org, tglx@linutronix.de, rostedt@goodmis.org, bigeasy@linutronix.de, Julien Thierry , Christoffer Dall , stable@vger.kernel.org Subject: [PATCH 1/4] KVM: arm/arm64: vgic: Do not cond_resched_lock() with IRQs disabled Date: Mon, 19 Nov 2018 17:07:56 +0000 Message-Id: <1542647279-46609-2-git-send-email-julien.thierry@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1542647279-46609-1-git-send-email-julien.thierry@arm.com> References: <1542647279-46609-1-git-send-email-julien.thierry@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To change the active state of an MMIO, halt is requested for all vcpus of the affected guest before modifying the IRQ state. This is done by calling cond_resched_lock() in vgic_mmio_change_active(). However interrupts are disabled at this point and running a vcpu cannot get rescheduled. Solve this by waiting for all vcpus to be halted after emmiting the halt request. Fixes commit 6c1b7521f4a07cc63bbe2dfe290efed47cdb780a ("KVM: arm/arm64: Factor out functionality to get vgic mmio requester_vcpu") Signed-off-by: Julien Thierry Suggested-by: Marc Zyngier Cc: Christoffer Dall Cc: Marc Zyngier Cc: stable@vger.kernel.org --- virt/kvm/arm/vgic/vgic-mmio.c | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/virt/kvm/arm/vgic/vgic-mmio.c b/virt/kvm/arm/vgic/vgic-mmio.c index f56ff1c..eefd877 100644 --- a/virt/kvm/arm/vgic/vgic-mmio.c +++ b/virt/kvm/arm/vgic/vgic-mmio.c @@ -313,27 +313,6 @@ static void vgic_mmio_change_active(struct kvm_vcpu *vcpu, struct vgic_irq *irq, spin_lock_irqsave(&irq->irq_lock, flags); - /* - * If this virtual IRQ was written into a list register, we - * have to make sure the CPU that runs the VCPU thread has - * synced back the LR state to the struct vgic_irq. - * - * As long as the conditions below are true, we know the VCPU thread - * may be on its way back from the guest (we kicked the VCPU thread in - * vgic_change_active_prepare) and still has to sync back this IRQ, - * so we release and re-acquire the spin_lock to let the other thread - * sync back the IRQ. - * - * When accessing VGIC state from user space, requester_vcpu is - * NULL, which is fine, because we guarantee that no VCPUs are running - * when accessing VGIC state from user space so irq->vcpu->cpu is - * always -1. - */ - while (irq->vcpu && /* IRQ may have state in an LR somewhere */ - irq->vcpu != requester_vcpu && /* Current thread is not the VCPU thread */ - irq->vcpu->cpu != -1) /* VCPU thread is running */ - cond_resched_lock(&irq->irq_lock); - if (irq->hw) { vgic_hw_irq_change_active(vcpu, irq, active, !requester_vcpu); } else { @@ -368,8 +347,18 @@ static void vgic_mmio_change_active(struct kvm_vcpu *vcpu, struct vgic_irq *irq, */ static void vgic_change_active_prepare(struct kvm_vcpu *vcpu, u32 intid) { - if (intid > VGIC_NR_PRIVATE_IRQS) + if (intid > VGIC_NR_PRIVATE_IRQS) { + struct kvm_vcpu *tmp; + int i; + kvm_arm_halt_guest(vcpu->kvm); + + /* Wait for each vcpu to be halted */ + kvm_for_each_vcpu(i, tmp, vcpu->kvm) { + while (tmp->cpu != -1) + cond_resched(); + } + } } /* See vgic_change_active_prepare */ -- 1.9.1