linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Slaby <jslaby@suse.cz>
To: stable@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
	"Christoffer Dall" <christoffer.dall@linaro.org>,
	"Marc Zyngier" <marc.zyngier@arm.com>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Shannon Zhao" <shannon.zhao@linaro.org>,
	"Jiri Slaby" <jslaby@suse.cz>
Subject: [PATCH 3.12 63/63] arm/arm64: KVM: Keep elrsr/aisr in sync with software model
Date: Thu, 30 Apr 2015 14:12:32 +0200	[thread overview]
Message-ID: <b5b655c99dff0fada0e43773025e1805b6726232.1430387326.git.jslaby@suse.cz> (raw)
In-Reply-To: <45aaf85687dd6ac119c55c5ec0dbe0bef0e62235.1430387326.git.jslaby@suse.cz>
In-Reply-To: <cover.1430387326.git.jslaby@suse.cz>

From: Christoffer Dall <christoffer.dall@linaro.org>

3.12-stable review patch.  If anyone has any objections, please let me know.

===============

commit ae705930fca6322600690df9dc1c7d0516145a93 upstream.

There is an interesting bug in the vgic code, which manifests itself
when the KVM run loop has a signal pending or needs a vmid generation
rollover after having disabled interrupts but before actually switching
to the guest.

In this case, we flush the vgic as usual, but we sync back the vgic
state and exit to userspace before entering the guest.  The consequence
is that we will be syncing the list registers back to the software model
using the GICH_ELRSR and GICH_EISR from the last execution of the guest,
potentially overwriting a list register containing an interrupt.

This showed up during migration testing where we would capture a state
where the VM has masked the arch timer but there were no interrupts,
resulting in a hung test.

Cc: Marc Zyngier <marc.zyngier@arm.com>
Reported-by: Alex Bennee <alex.bennee@linaro.org>
Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Acked-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 virt/kvm/arm/vgic.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/virt/kvm/arm/vgic.c b/virt/kvm/arm/vgic.c
index 865a89178c82..ecea20153b42 100644
--- a/virt/kvm/arm/vgic.c
+++ b/virt/kvm/arm/vgic.c
@@ -881,6 +881,7 @@ static bool vgic_queue_irq(struct kvm_vcpu *vcpu, u8 sgi_source_id, int irq)
 			  lr, irq, vgic_cpu->vgic_lr[lr]);
 		BUG_ON(!test_bit(lr, vgic_cpu->lr_used));
 		vgic_cpu->vgic_lr[lr] |= GICH_LR_PENDING_BIT;
+		__clear_bit(lr, (unsigned long *)vgic_cpu->vgic_elrsr);
 		return true;
 	}
 
@@ -894,6 +895,7 @@ static bool vgic_queue_irq(struct kvm_vcpu *vcpu, u8 sgi_source_id, int irq)
 	vgic_cpu->vgic_lr[lr] = MK_LR_PEND(sgi_source_id, irq);
 	vgic_cpu->vgic_irq_lr_map[irq] = lr;
 	set_bit(lr, vgic_cpu->lr_used);
+	__clear_bit(lr, (unsigned long *)vgic_cpu->vgic_elrsr);
 
 	if (!vgic_irq_is_edge(vcpu, irq))
 		vgic_cpu->vgic_lr[lr] |= GICH_LR_EOI;
@@ -1048,6 +1050,14 @@ static bool vgic_process_maintenance(struct kvm_vcpu *vcpu)
 	if (vgic_cpu->vgic_misr & GICH_MISR_U)
 		vgic_cpu->vgic_hcr &= ~GICH_HCR_UIE;
 
+	/*
+	 * In the next iterations of the vcpu loop, if we sync the vgic state
+	 * after flushing it, but before entering the guest (this happens for
+	 * pending signals and vmid rollovers), then make sure we don't pick
+	 * up any old maintenance interrupts here.
+	 */
+	memset(vgic_cpu->vgic_eisr, 0, sizeof(vgic_cpu->vgic_eisr[0]) * 2);
+
 	return level_pending;
 }
 
-- 
2.3.5


  parent reply	other threads:[~2015-04-30 12:14 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-30 12:12 [PATCH 3.12 00/63] 3.12.42-stable review Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 01/63] KVM: ARM: Fix calculation of virtual CPU ID Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 02/63] KVM: ARM: fix the size of TTBCR_{T0SZ,T1SZ} masks Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 03/63] ARM: KVM: Yield CPU when vcpu executes a WFE Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 04/63] ARM: KVM: Fix MPIDR computing to support virtual clusters Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 05/63] KVM: ARM: Update comments for kvm_handle_wfi Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 06/63] ARM: KVM: fix L2CTLR to be per-cluster Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 07/63] arm/arm64: KVM: PSCI: use MPIDR to identify a target CPU Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 08/63] arm64: KVM: Yield CPU when vcpu executes a WFE Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 09/63] arm/arm64: KVM: arch_timer: Initialize cntvoff at kvm_init Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 10/63] ARM: KVM: Allow creating the VGIC after VCPUs Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 11/63] arm/arm64: kvm: Set vcpu->cpu to -1 on vcpu_put Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 12/63] arm64: KVM: Force undefined exception for Guest SMC intructions Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 13/63] arm: KVM: Don't return PSCI_INVAL if waitqueue is inactive Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 14/63] KVM: ARM: Remove duplicate include Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 15/63] arm: kvm: implement CPU PM notifier Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 16/63] arm/arm64: KVM: detect CPU reset on CPU_PM_EXIT Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 17/63] arm64: KVM: force cache clean on page fault when caches are off Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 18/63] arm64: KVM: allows discrimination of AArch32 sysreg access Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 19/63] arm64: KVM: trap VM system registers until MMU and caches are ON Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 20/63] ARM: KVM: introduce kvm_p*d_addr_end Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 21/63] arm64: KVM: flush VM pages before letting the guest enable caches Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 22/63] ARM: KVM: force cache clean on page fault when caches are off Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 23/63] ARM: KVM: fix handling of trapped 64bit coprocessor accesses Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 24/63] ARM: KVM: fix ordering of " Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 25/63] ARM: KVM: introduce per-vcpu HYP Configuration Register Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 26/63] ARM: KVM: add world-switch for AMAIR{0,1} Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 27/63] ARM: KVM: trap VM system registers until MMU and caches are ON Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 28/63] ARM: KVM: fix non-VGIC compilation Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 29/63] ARM: KVM: disable KVM in Kconfig on big-endian systems Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 30/63] KVM: arm/arm64: vgic: fix GICD_ICFGR register accesses Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 31/63] KVM: ARM: vgic: Fix the overlap check action about setting the GICD & GICC base address Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 32/63] arm64: kvm: use inner-shareable barriers for inner-shareable maintenance Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 33/63] kvm: arm64: vgic: fix hyp panic with 64k pages on juno platform Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 34/63] arm/arm64: KVM: Fix and refactor unmap_range Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 35/63] ARM: KVM: Unmap IPA on memslot delete/move Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 36/63] ARM: KVM: user_mem_abort: support stage 2 MMIO page mapping Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 37/63] arm64: KVM: export demux regids as KVM_REG_ARM64 Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 38/63] ARM: virt: fix wrong HSCTLR.EE bit setting Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 39/63] ARM64: KVM: store kvm_vcpu_fault_info est_el2 as word Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 40/63] KVM: ARM/arm64: fix non-const declaration of function returning const Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 41/63] KVM: ARM/arm64: fix broken __percpu annotation Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 42/63] KVM: ARM/arm64: avoid returning negative error code as bool Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 43/63] KVM: vgic: return int instead of bool when checking I/O ranges Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 44/63] ARM/ARM64: KVM: Nuke Hyp-mode tlbs before enabling MMU Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 45/63] arm/arm64: KVM: Complete WFI/WFE instructions Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 46/63] ARM/arm64: KVM: fix use of WnR bit in kvm_is_write_fault() Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 47/63] KVM: ARM: vgic: plug irq injection race Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 48/63] arm/arm64: KVM: Fix VTTBR_BADDR_MASK and pgd alloc Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 49/63] arm: kvm: fix CPU hotplug Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 50/63] arm/arm64: KVM: Ensure memslots are within KVM_PHYS_SIZE Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 51/63] arm: kvm: STRICT_MM_TYPECHECKS fix for user_mem_abort Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 52/63] arm64/kvm: Fix assembler compatibility of macros Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 53/63] arm/arm64: kvm: drop inappropriate use of kvm_is_mmio_pfn() Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 54/63] arm/arm64: KVM: Don't clear the VCPU_POWER_OFF flag Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 55/63] arm/arm64: KVM: Correct KVM_ARM_VCPU_INIT power off option Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 56/63] arm/arm64: KVM: Reset the HCR on each vcpu when resetting the vcpu Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 57/63] arm/arm64: KVM: Introduce stage2_unmap_vm Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 58/63] arm/arm64: KVM: Don't allow creating VCPUs after vgic_initialized Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 59/63] arm/arm64: KVM: Require in-kernel vgic for the arch timers Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 60/63] arm64: KVM: Fix TLB invalidation by IPA/VMID Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 61/63] arm64: KVM: Fix HCR setting for 32bit guests Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 62/63] arm64: KVM: Do not use pgd_index to index stage-2 pgd Jiri Slaby
2015-04-30 12:12 ` Jiri Slaby [this message]
2015-04-30 13:12 ` [PATCH 3.12 00/63] 3.12.42-stable review Guenter Roeck
2015-05-04 13:27   ` Jiri Slaby
2015-04-30 14:26 ` Shuah Khan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b5b655c99dff0fada0e43773025e1805b6726232.1430387326.git.jslaby@suse.cz \
    --to=jslaby@suse.cz \
    --cc=alex.bennee@linaro.org \
    --cc=christoffer.dall@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marc.zyngier@arm.com \
    --cc=shannon.zhao@linaro.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).