Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp7258356imm; Tue, 28 Aug 2018 08:54:28 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZFBVzZUuIwVYyIN8Ugn4uQ/IHZaDTkiY4WEaemQ9ZQTkAJT8RsrCUY+Xp0B8+9iwpgF9n4 X-Received: by 2002:a17:902:904c:: with SMTP id w12-v6mr2136125plz.95.1535471668790; Tue, 28 Aug 2018 08:54:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535471668; cv=none; d=google.com; s=arc-20160816; b=hrdPDKV0M6NX/mPJsGx1T2Cnv0P7tUTAGZfrd81MjqY7/xtPFMFaucGfrNXLAQNATz KlgDWeIUI01qD00h/R4QKerN9i+hg+Hse7B89PoRoCVGe/M/Hmmq7IZ1n4JSXqNzWoO+ bUVlZcnY/am23CgFK+Gaswexah/Md2ZZCGXgeOjvrdl8dGqBXgRW1ExXJ7+5S58KxvFp XYoGipmrdTaDzEsWq7t/f1/6wQmPojhrcIWzj8f7EZdh0zkdzv7Q7n4f+U3La5h3U6Ik LTQsEYDgmqu59+LNPStHLcj6vRYqWNWhY6a1UmDtM93C/R/Q6hMDcJbddGcNrUczTJBU NdLQ== 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:arc-authentication-results; bh=GMEOIHpdtAlGy2/74F/3JNMeXaQAS7nVEcwOvO03/lo=; b=JzhwgNBCn543K8bvIJvkSRp4RR0IDgXNJSY0eEZJ34RdCc31+OYn3PiclkVTFXCXHd 4VHfwUtTqUMvbAumtFASzklrvKdDpq4nCGG/OYLhN9uHPyOS1JSvozrhoyhWZWkjbLEw LpPJjw2sxF3YP07ymHG4r85KVE8o1tbI2d4mdfPDSgA1jlKOlYIt0Tp/HJvIYt9cH1op WxvgRQpd2ymKoh1aqLqJ4Hr1vQgBaNTOZ11elVkd3eiDMJcREKko3gvs0/kwI8wtX3+k XCUV6T3bK/BVTB7rpsdJ+GvnMxmrm4pssVscYxHgvgysOIgIh38gnyeCK/sqgKfuPZYw S0dg== 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 q65-v6si1372663pga.283.2018.08.28.08.54.13; Tue, 28 Aug 2018 08:54:28 -0700 (PDT) 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 S1727677AbeH1Toj (ORCPT + 99 others); Tue, 28 Aug 2018 15:44:39 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:41052 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726383AbeH1Toh (ORCPT ); Tue, 28 Aug 2018 15:44:37 -0400 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 4D35AED1; Tue, 28 Aug 2018 08:52:21 -0700 (PDT) Received: from e112298-lin.Emea.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 3BB273F557; Tue, 28 Aug 2018 08:52:19 -0700 (PDT) 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, mark.rutland@arm.com, christoffer.dall@arm.com, james.morse@arm.com, catalin.marinas@arm.com, will.deacon@arm.com, Julien Thierry , kvmarm@lists.cs.columbia.edu Subject: [PATCH v5 14/27] arm64: kvm: Unmask PMR before entering guest Date: Tue, 28 Aug 2018 16:51:24 +0100 Message-Id: <1535471497-38854-15-git-send-email-julien.thierry@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1535471497-38854-1-git-send-email-julien.thierry@arm.com> References: <1535471497-38854-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. Avoid this by making sure ICC_PMR_EL1 is unmasked when we enter a guest. Tested-by: Daniel Thompson Signed-off-by: Julien Thierry 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 | 12 ++++++++++++ arch/arm64/kvm/hyp/switch.c | 17 +++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index f26055f..9689592 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 @@ -466,6 +467,17 @@ 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 (gic_prio_masking_enabled()) { + gic_write_pmr(ICC_PMR_EL1_UNMASKED); + dsb(sy); + } } static inline void kvm_arm_vhe_guest_exit(void) diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c index d496ef5..074ab21 100644 --- a/arch/arm64/kvm/hyp/switch.c +++ b/arch/arm64/kvm/hyp/switch.c @@ -22,6 +22,7 @@ #include +#include #include #include #include @@ -533,6 +534,19 @@ int __hyp_text __kvm_vcpu_run_nvhe(struct kvm_vcpu *vcpu) struct kvm_cpu_context *host_ctxt; struct kvm_cpu_context *guest_ctxt; u64 exit_code; + u32 host_pmr = ICC_PMR_EL1_UNMASKED; + + /* + * 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 (gic_prio_masking_enabled()) { + host_pmr = gic_read_pmr(); + gic_write_pmr(ICC_PMR_EL1_UNMASKED); + dsb(sy); + } vcpu = kern_hyp_va(vcpu); @@ -586,6 +600,9 @@ int __hyp_text __kvm_vcpu_run_nvhe(struct kvm_vcpu *vcpu) */ __debug_switch_to_host(vcpu); + if (gic_prio_masking_enabled()) + gic_write_pmr(host_pmr); + return exit_code; } -- 1.9.1