Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7226216imu; Thu, 31 Jan 2019 07:01:58 -0800 (PST) X-Google-Smtp-Source: ALg8bN5Z7FD5FoKC6Nxwq5uOlu8e9JRUz8OFnUugvwrzKKFQ1aBzifTV3PbqHfugQFBCSZhU260A X-Received: by 2002:a63:6442:: with SMTP id y63mr31650324pgb.450.1548946918768; Thu, 31 Jan 2019 07:01:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548946918; cv=none; d=google.com; s=arc-20160816; b=gib5HDY9cznuZhOsofZAD5CBv+hxm7vgXGQI/MOu+HLs722FMK427cFvXSWbVZZadJ h8+ClLfpqxhzxbGVKNAGBPdm/wQm5pCVmhwGUq8zq0EELo7CbXAwmhiAl5Og8ChkY5g2 cWHP4nhe2Nk1l6hvmbHxzpYMj6RwzWKM+09p2GnT3X/bmXtG+TMq2XQ8laQ+RfVYrKzC Atd/WuZhdRHDc9PcMdJa17Ttg1TFMy+klIZ3f8M77u2KE2xJavbOGOos3D/Y+Z9QbiTf eku9kFMkJv7xY5HCO0Oj3+y4EwzWLJnYjiur9WKgWH3FZkLd+QXgG0eaW8cDd7XJ7o0E rLfw== 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=hog1QOMHCQIPFFTmTTj3SlgvO6yB66sdt9Fn8mlOF80=; b=oppARbn/geJZyYRWS2/w6Scx0E+0ngJnvU1NN7Cu6ydK1p6KaptY/sobSmnZM8samS S/eBESURrf9LdAxktRwzU82WIpFXu67VJP6P0a7yMlB+0j+kkkGDLS7e68vvZa2zzCLM 2VTG3UY1J6ZWaDM7v4TfFeI5uIs4eCQ4HzDacg3gfJILlSIulYnNQNcLar4T1IyXAKi0 M/4bmpRCtCLCMqtoiAJHOufB+555hUGiMTJwO+oqOViQN3KikivTC8WlH4+dIoWoQGMZ /mc33Gd8O/lOrnu8e9C2wPHvKT++HprSW09RT2dfYwjDYa0S7e+SqwYk9GJpAkUHvbTi 0xfw== 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 u6si4945361pfb.92.2019.01.31.07.01.42; Thu, 31 Jan 2019 07:01:58 -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 S1732770AbfAaO7l (ORCPT + 99 others); Thu, 31 Jan 2019 09:59:41 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:45574 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732720AbfAaO7k (ORCPT ); Thu, 31 Jan 2019 09:59:40 -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 DBDD480D; Thu, 31 Jan 2019 06:59:39 -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 BF9DA3F59C; Thu, 31 Jan 2019 06:59:37 -0800 (PST) From: Julien Thierry To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, daniel.thompson@linaro.org, joel@joelfernandes.org, marc.zyngier@arm.com, christoffer.dall@arm.com, james.morse@arm.com, catalin.marinas@arm.com, will.deacon@arm.com, mark.rutland@arm.com, Julien Thierry , kvmarm@lists.cs.columbia.edu Subject: [PATCH v10 10/25] arm64: kvm: Unmask PMR before entering guest Date: Thu, 31 Jan 2019 14:58:48 +0000 Message-Id: <1548946743-38979-11-git-send-email-julien.thierry@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1548946743-38979-1-git-send-email-julien.thierry@arm.com> References: <1548946743-38979-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 Interrupts masked by ICC_PMR_EL1 will not be signaled to the CPU. This means that hypervisor will not receive masked interrupts while running a guest. We need to make sure that all maskable interrupts are masked from the time we call local_irq_disable() in the main run loop, and remain so until we call local_irq_enable() after returning from the guest, and we need to ensure that we see no interrupts at all (including pseudo-NMIs) in the middle of the VM world-switch, while at the same time we need to ensure we exit the guest when there are interrupts for the host. We can accomplish this with pseudo-NMIs enabled by: (1) local_irq_disable: set the priority mask (2) enter guest: set PSTATE.I (3) clear the priority mask (4) eret to guest (5) exit guest: set the priotiy mask clear PSTATE.I (and restore other host PSTATE bits) (6) local_irq_enable: clear the priority mask. Signed-off-by: Julien Thierry Acked-by: Catalin Marinas Reviewed-by: Marc Zyngier Reviewed-by: Christoffer Dall Cc: Christoffer Dall Cc: Marc Zyngier Cc: Catalin Marinas Cc: Will Deacon Cc: kvmarm@lists.cs.columbia.edu --- arch/arm64/include/asm/kvm_host.h | 16 ++++++++++++++++ arch/arm64/kvm/hyp/switch.c | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 7732d0b..292c882 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -474,10 +475,25 @@ static inline int kvm_arch_vcpu_run_pid_change(struct kvm_vcpu *vcpu) static inline void kvm_arm_vhe_guest_enter(void) { local_daif_mask(); + + /* + * Having IRQs masked via PMR when entering the guest means the GIC + * will not signal the CPU of interrupts of lower priority, and the + * only way to get out will be via guest exceptions. + * Naturally, we want to avoid this. + */ + if (system_uses_irq_prio_masking()) { + gic_write_pmr(GIC_PRIO_IRQON); + dsb(sy); + } } static inline void kvm_arm_vhe_guest_exit(void) { + /* + * local_daif_restore() takes care to properly restore PSTATE.DAIF + * and the GIC PMR if the host is using IRQ priorities. + */ local_daif_restore(DAIF_PROCCTX_NOIRQ); /* diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c index b0b1478..6a4c2d6 100644 --- a/arch/arm64/kvm/hyp/switch.c +++ b/arch/arm64/kvm/hyp/switch.c @@ -22,6 +22,7 @@ #include +#include #include #include #include @@ -521,6 +522,17 @@ int __hyp_text __kvm_vcpu_run_nvhe(struct kvm_vcpu *vcpu) struct kvm_cpu_context *guest_ctxt; u64 exit_code; + /* + * Having IRQs masked via PMR when entering the guest means the GIC + * will not signal the CPU of interrupts of lower priority, and the + * only way to get out will be via guest exceptions. + * Naturally, we want to avoid this. + */ + if (system_uses_irq_prio_masking()) { + gic_write_pmr(GIC_PRIO_IRQON); + dsb(sy); + } + vcpu = kern_hyp_va(vcpu); host_ctxt = kern_hyp_va(vcpu->arch.host_cpu_context); @@ -573,6 +585,10 @@ int __hyp_text __kvm_vcpu_run_nvhe(struct kvm_vcpu *vcpu) */ __debug_switch_to_host(vcpu); + /* Returning to host will clear PSR.I, remask PMR if needed */ + if (system_uses_irq_prio_masking()) + gic_write_pmr(GIC_PRIO_IRQOFF); + return exit_code; } -- 1.9.1