Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp622832img; Fri, 22 Mar 2019 05:21:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqxsbCBZUeZKHorvFu0wqsRDDDQ9awfazS7N5F6Gld+9DMZVDSipMUDCLLBcSL8LfYEoZhlr X-Received: by 2002:a65:64d5:: with SMTP id t21mr8440676pgv.266.1553257286211; Fri, 22 Mar 2019 05:21:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553257286; cv=none; d=google.com; s=arc-20160816; b=AHKRkBKXKt3d0r0Wc2ttu9OgXjAVatBcZLgLoVuXzYftjqmNzcsa1u/D+TeOBfDKK6 qWfE/PpdamjAeNuvROA5zcNB1hrBoc2xMIcfeLvLtOIXTjOLLWe75B4vvTuQGw8Y6Wkp oeoQdAo2n2DVY2A8m3dbWQ+9LFZlbsOncSuKCSKZIwbSIB6NiGLOz165jQBo01vE+zos iefRw5ihZR3J5kNjntQ8tUB35k4N+wGnwZ56FQE38+Ovje5l2Tf2z2tuXXw6CBRD3KFx Bijv3MVqQFDotpTTBnyOp7yLeYmjJ/+88JvsNharKBbVObC1Cuody665Uqe7NN1L83fu l+Kw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ROUZSoAzSEgbX0VolhpHZmOjKVv6FsACwH8ZwVvukmw=; b=ZuBoBrVZrWy6Rf9L+oqFQHLhSR8I6i2nu3kG+1zmiITEtwbIGCOAtMFkjJzlH2Pk8X QWRo44YDRYsqGuisIabLFdoDifkoPyijaJgm8i7KYlslNWNNOAqHcPDa2LeJYb7BAWLH v3rVI3b+L0DFlXpQoFx2jChCm3p9C4+Kcpn/OH4Uss9Xaapnt+fvPEOsgEdx80pXx0Ow JwWCBT+4pvV2kxe+vzonXNAX0XCn71KCt8CPcvjyMSMm3vH8wdj1sFIW2Y6sq249oPQE etCMXHsNtyCgN7AQEe1n9SVnERJmQToWtJhN2N3RXrUrySmudbmVF4gOWzsFflcD1yHe fjRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=TpG3HiNn; 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 k24si6505616pgj.228.2019.03.22.05.21.10; Fri, 22 Mar 2019 05:21:26 -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; dkim=pass header.i=@kernel.org header.s=default header.b=TpG3HiNn; 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 S2390604AbfCVMUh (ORCPT + 99 others); Fri, 22 Mar 2019 08:20:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:59564 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390405AbfCVMUd (ORCPT ); Fri, 22 Mar 2019 08:20:33 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1B4F521900; Fri, 22 Mar 2019 12:20:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553257232; bh=CORedvOXl+fqqVwM8/EtiE/V1VWwLfIGTVW2i+bxkTg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TpG3HiNnems7d2sRWaUQbhFVtHJwv4Mj3mpBvYwe4TLzFQZ1PlaHIRK3BNxibaW1J zm7np32cPer4MNBnjaYyUYfWPYxnPqqLbqy0J6tZ6hU7h7gVts/dk55TVtlKhjlx2X s8jXHfemRwfLDAqw9GQIkvz40c/82OHOy/r2SqYg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Julien Thierry , Marc Zyngier , James Morse , Arnd Bergmann , Will Deacon , linux-arch@vger.kernel.org, Catalin Marinas Subject: [PATCH 5.0 171/238] arm64: Fix HCR.TGE status for NMI contexts Date: Fri, 22 Mar 2019 12:16:30 +0100 Message-Id: <20190322111308.378002300@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322111258.383569278@linuxfoundation.org> References: <20190322111258.383569278@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 5.0-stable review patch. If anyone has any objections, please let me know. ------------------ From: Julien Thierry commit 5870970b9a828d8693aa6d15742573289d7dbcd0 upstream. When using VHE, the host needs to clear HCR_EL2.TGE bit in order to interact with guest TLBs, switching from EL2&0 translation regime to EL1&0. However, some non-maskable asynchronous event could happen while TGE is cleared like SDEI. Because of this address translation operations relying on EL2&0 translation regime could fail (tlb invalidation, userspace access, ...). Fix this by properly setting HCR_EL2.TGE when entering NMI context and clear it if necessary when returning to the interrupted context. Signed-off-by: Julien Thierry Suggested-by: Marc Zyngier Reviewed-by: Marc Zyngier Reviewed-by: James Morse Cc: Arnd Bergmann Cc: Will Deacon Cc: Marc Zyngier Cc: James Morse Cc: linux-arch@vger.kernel.org Cc: stable@vger.kernel.org Signed-off-by: Catalin Marinas Signed-off-by: Greg Kroah-Hartman --- arch/arm64/include/asm/hardirq.h | 31 +++++++++++++++++++++++++++++++ arch/arm64/kernel/irq.c | 3 +++ include/linux/hardirq.h | 7 +++++++ 3 files changed, 41 insertions(+) --- a/arch/arm64/include/asm/hardirq.h +++ b/arch/arm64/include/asm/hardirq.h @@ -17,8 +17,12 @@ #define __ASM_HARDIRQ_H #include +#include #include +#include #include +#include +#include #define NR_IPI 7 @@ -37,6 +41,33 @@ u64 smp_irq_stat_cpu(unsigned int cpu); #define __ARCH_IRQ_EXIT_IRQS_DISABLED 1 +struct nmi_ctx { + u64 hcr; +}; + +DECLARE_PER_CPU(struct nmi_ctx, nmi_contexts); + +#define arch_nmi_enter() \ + do { \ + if (is_kernel_in_hyp_mode()) { \ + struct nmi_ctx *nmi_ctx = this_cpu_ptr(&nmi_contexts); \ + nmi_ctx->hcr = read_sysreg(hcr_el2); \ + if (!(nmi_ctx->hcr & HCR_TGE)) { \ + write_sysreg(nmi_ctx->hcr | HCR_TGE, hcr_el2); \ + isb(); \ + } \ + } \ + } while (0) + +#define arch_nmi_exit() \ + do { \ + if (is_kernel_in_hyp_mode()) { \ + struct nmi_ctx *nmi_ctx = this_cpu_ptr(&nmi_contexts); \ + if (!(nmi_ctx->hcr & HCR_TGE)) \ + write_sysreg(nmi_ctx->hcr, hcr_el2); \ + } \ + } while (0) + static inline void ack_bad_irq(unsigned int irq) { extern unsigned long irq_err_count; --- a/arch/arm64/kernel/irq.c +++ b/arch/arm64/kernel/irq.c @@ -33,6 +33,9 @@ unsigned long irq_err_count; +/* Only access this in an NMI enter/exit */ +DEFINE_PER_CPU(struct nmi_ctx, nmi_contexts); + DEFINE_PER_CPU(unsigned long *, irq_stack_ptr); int arch_show_interrupts(struct seq_file *p, int prec) --- a/include/linux/hardirq.h +++ b/include/linux/hardirq.h @@ -60,8 +60,14 @@ extern void irq_enter(void); */ extern void irq_exit(void); +#ifndef arch_nmi_enter +#define arch_nmi_enter() do { } while (0) +#define arch_nmi_exit() do { } while (0) +#endif + #define nmi_enter() \ do { \ + arch_nmi_enter(); \ printk_nmi_enter(); \ lockdep_off(); \ ftrace_nmi_enter(); \ @@ -80,6 +86,7 @@ extern void irq_exit(void); ftrace_nmi_exit(); \ lockdep_on(); \ printk_nmi_exit(); \ + arch_nmi_exit(); \ } while (0) #endif /* LINUX_HARDIRQ_H */