From patchwork Mon Nov 13 09:17:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10055427 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 2F4526029B for ; Mon, 13 Nov 2017 09:38:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0C99929191 for ; Mon, 13 Nov 2017 09:38:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 00CBA29246; Mon, 13 Nov 2017 09:38:12 +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=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.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 A10EC29191 for ; Mon, 13 Nov 2017 09:38:12 +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=IC4ThnOA3XvNaPmN9LWW7cRjTImDdrewUESVVlI6p8k=; b=rUMWR/iycaaW9Cwc8in+kqdhGX MZG2oRvSLj+KpR7rq2jgYM8QGcVtVmEoQRRZtw3irhQ+t2GYoKBq3e0FM/FdKQxQH3gB1Uwg6AX8g jVpAPRpfq2T+UsXjFHDjLW3BeFSJsXfnqLy93NB04nHvTaniIaMYqEyGe1DeBxeDa5jHRyCaAdIQa aL700SJaxDrFJ1OSRTV9IE/fmtanBB8uj8zwV7ukZ5Hz2M1BSgxRMqi3lNSiH7ZtQ3zGZt/YnZVFD nqkemN4kwbaLlxdayr8KoyFUDRhpYZLmUI+1sldWS+Sax4fq32zIEVKSEXGCIo9VsMiEKdWGhrk7V oIxPAYTA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eEBBv-0005xI-Sg; Mon, 13 Nov 2017 09:38:07 +0000 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eEAtE-0002Oq-3U for linux-arm-kernel@lists.infradead.org; Mon, 13 Nov 2017 09:18:54 +0000 Received: by mail-wm0-x242.google.com with SMTP id t139so13646912wmt.1 for ; Mon, 13 Nov 2017 01:18:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=YH6/HKIrWeVnINzrEzLTiq5wlBSDLicUOnawVgxbKE8=; b=UO1xHYEhUskN1mxzbQh2kE9jzb80sMASK2S3/yK0JwbDwPEFoyrZ/kXcmFSdozK6fD yzmYeRF9f1oKntq4m2Pfuc80vBh9R+YNfzA8s/JoSYuQJEiQWmDjUrm/ojQ5VAwMarzT 69muM+G0ty4bcjBRZGK+vKXOC9lRpFvo8J81g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=YH6/HKIrWeVnINzrEzLTiq5wlBSDLicUOnawVgxbKE8=; b=IgsNnAlqcwKrngepN7AofDMBiSSp9PICtydOmQx0b2EZds+w+q2mXZpjWz+fjHXWL+ XpEg4wjUFq+VpnDK1nSqdWLUKrpoxQ8OEPkoiNDlO0J9OxeQJ7AmM5uu2jxscP0EH4Hf H1pjEHuWxNahQ5Z9Sql7g7yuBWpPjkSjChn35n08GXeBFdTRRZnNNPub7bCipU+3YsrY fVBWED7zn7S9/LdK26jSxW5zF7cOnWOt++uMyo9eMGlOqnz6iPeB0sDfoyHcNkzFNaF2 jkpEs8FyhYfFp0Vgfht8uH8bV1CkbRV8NTINNVq0ykjbiN3jTqeev0fiNsRHjhYQzAyw /DWA== X-Gm-Message-State: AJaThX5XndjFXLCuOitU2IDol75NGe6Fngng/R6qkRLwBJXBtr0uDrCh PU/MQtB6aqWAo/XU8bo6sXAy3w== X-Google-Smtp-Source: AGs4zMZadRiEantKwged76y5r5zwqhc9arr204xznuuOHOS1biPOcbQvGSc9i2TNLf2oVFD1sjFfJw== X-Received: by 10.28.69.8 with SMTP id s8mr5006270wma.65.1510564706056; Mon, 13 Nov 2017 01:18:26 -0800 (PST) Received: from localhost.localdomain (xd93dd96b.cust.hiper.dk. [217.61.217.107]) by smtp.gmail.com with ESMTPSA id x63sm9651399wma.39.2017.11.13.01.18.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 13 Nov 2017 01:18:25 -0800 (PST) From: Christoffer Dall To: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Subject: [PULL 20/27] KVM: arm/arm64: GICv4: Hook vPE scheduling into vgic flush/sync Date: Mon, 13 Nov 2017 10:17:45 +0100 Message-Id: <20171113091752.10663-21-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171113091752.10663-1-christoffer.dall@linaro.org> References: <20171113091752.10663-1-christoffer.dall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171113_011849_072592_0DB8DD0D X-CRM114-Status: GOOD ( 15.26 ) 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: Marc Zyngier , Christoffer Dall , kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.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 From: Marc Zyngier The redistributor needs to be told which vPE is about to be run, and tells us whether there is any pending VLPI on exit. Let's add the scheduling calls to the vgic flush/sync functions, allowing the VLPIs to be delivered to the guest. Reviewed-by: Christoffer Dall Signed-off-by: Marc Zyngier Signed-off-by: Christoffer Dall --- virt/kvm/arm/vgic/vgic-v4.c | 39 +++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.c | 4 ++++ virt/kvm/arm/vgic/vgic.h | 2 ++ 3 files changed, 45 insertions(+) diff --git a/virt/kvm/arm/vgic/vgic-v4.c b/virt/kvm/arm/vgic/vgic-v4.c index 1375a53054b9..c9cec01008c2 100644 --- a/virt/kvm/arm/vgic/vgic-v4.c +++ b/virt/kvm/arm/vgic/vgic-v4.c @@ -131,6 +131,45 @@ void vgic_v4_teardown(struct kvm *kvm) its_vm->vpes = NULL; } +int vgic_v4_sync_hwstate(struct kvm_vcpu *vcpu) +{ + if (!vgic_supports_direct_msis(vcpu->kvm)) + return 0; + + return its_schedule_vpe(&vcpu->arch.vgic_cpu.vgic_v3.its_vpe, false); +} + +int vgic_v4_flush_hwstate(struct kvm_vcpu *vcpu) +{ + int irq = vcpu->arch.vgic_cpu.vgic_v3.its_vpe.irq; + int err; + + if (!vgic_supports_direct_msis(vcpu->kvm)) + return 0; + + /* + * Before making the VPE resident, make sure the redistributor + * corresponding to our current CPU expects us here. See the + * doc in drivers/irqchip/irq-gic-v4.c to understand how this + * turns into a VMOVP command at the ITS level. + */ + err = irq_set_affinity(irq, cpumask_of(smp_processor_id())); + if (err) + return err; + + err = its_schedule_vpe(&vcpu->arch.vgic_cpu.vgic_v3.its_vpe, true); + if (err) + return err; + + /* + * Now that the VPE is resident, let's get rid of a potential + * doorbell interrupt that would still be pending. + */ + err = irq_set_irqchip_state(irq, IRQCHIP_STATE_PENDING, false); + + return err; +} + static struct vgic_its *vgic_get_its(struct kvm *kvm, struct kvm_kernel_irq_routing_entry *irq_entry) { diff --git a/virt/kvm/arm/vgic/vgic.c b/virt/kvm/arm/vgic/vgic.c index d29e91215366..b168a328a9e0 100644 --- a/virt/kvm/arm/vgic/vgic.c +++ b/virt/kvm/arm/vgic/vgic.c @@ -718,6 +718,8 @@ void kvm_vgic_sync_hwstate(struct kvm_vcpu *vcpu) { struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; + WARN_ON(vgic_v4_sync_hwstate(vcpu)); + /* An empty ap_list_head implies used_lrs == 0 */ if (list_empty(&vcpu->arch.vgic_cpu.ap_list_head)) return; @@ -730,6 +732,8 @@ void kvm_vgic_sync_hwstate(struct kvm_vcpu *vcpu) /* Flush our emulation state into the GIC hardware before entering the guest. */ void kvm_vgic_flush_hwstate(struct kvm_vcpu *vcpu) { + WARN_ON(vgic_v4_flush_hwstate(vcpu)); + /* * If there are no virtual interrupts active or pending for this * VCPU, then there is no work to do and we can bail out without diff --git a/virt/kvm/arm/vgic/vgic.h b/virt/kvm/arm/vgic/vgic.h index bf03a9648fbb..efbcf8f96f9c 100644 --- a/virt/kvm/arm/vgic/vgic.h +++ b/virt/kvm/arm/vgic/vgic.h @@ -244,5 +244,7 @@ struct vgic_its *vgic_msi_to_its(struct kvm *kvm, struct kvm_msi *msi); bool vgic_supports_direct_msis(struct kvm *kvm); int vgic_v4_init(struct kvm *kvm); void vgic_v4_teardown(struct kvm *kvm); +int vgic_v4_sync_hwstate(struct kvm_vcpu *vcpu); +int vgic_v4_flush_hwstate(struct kvm_vcpu *vcpu); #endif