Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp3130655pxu; Mon, 19 Oct 2020 04:58:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzBygsrVLy+XsUzS0J8GfI1R7icZHa2HdOt5+442iDBrIB6Sg1FiI0ZmVkrc2eQtKvgtedJ X-Received: by 2002:a17:906:d7ad:: with SMTP id pk13mr16322558ejb.33.1603108709268; Mon, 19 Oct 2020 04:58:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603108709; cv=none; d=google.com; s=arc-20160816; b=QpP2JRVeB5N4ox5jU6YDmqy22TGzaXV06ALGIuLXYazUH+JMaTTPIAY90c7FHSZP0n wi1fCXykdcoa/i6RGXQfn6kUxoJlXiaGg4Q6lHFBBvbCkhEakoEVGNiRyiqr6Xwbutmh 5+rsBNYtKzDiO7UWL+b6mvPjHywZp1I5KO9zJgDwwNlH/0R1lhkWPT5Izs2jbgaYq/Yp paVZwoRaKo87AstIWeXe4TUc9soQOzeLv0stGV1Zpb9piq3XkwyowlN/w+xAYiek5Smc vEAOetp1r4qC/omv0N7+irh0P5Wq4hVUxjs841CwiyZzjlIci1HTzYxgTIaWL/XIvQ/W XQUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:user-agent:references:in-reply-to :subject:cc:to:from:date:content-transfer-encoding:mime-version :dkim-signature; bh=fypM5A4YpJ0QrqEK2gGA2OHLO7YdfMtEwrtz6OEwr3o=; b=E0aY3SiOgtZj8GnQ6SVngQjF6EhNRTmlgo/gpRMPWaShtEJXUhLQZ/L79AgLpbydGm ZqP+WG7qq638qkujQWWuBo/dlpjzyCe2/6n8t5xHlhX5MQj8E8WQki8ZplBi5Fre0KQX RTgnpT9ttyjVpeRvUqCweXNlrhJLVBEqX0LS2/ERaDZM8VU4HYpVSbGgBhQLtD/wgdAj jXadbCQEv5ULfnINc+ej6IA1/r8XDlWt7ODfPwXWPHu+2vSKrtv79ffn7ckT4N9jEce8 bDu5h5oX86/a6EZ9tZ5N3ja/yth5y0IdjZ4jFNwBsCeW1r04byNPdpSMZxpDjzNhjDqC 70ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=unQBLWkR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g10si7671589edy.201.2020.10.19.04.58.07; Mon, 19 Oct 2020 04:58:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=unQBLWkR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728076AbgJSLiD (ORCPT + 99 others); Mon, 19 Oct 2020 07:38:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:36984 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728047AbgJSLhv (ORCPT ); Mon, 19 Oct 2020 07:37:51 -0400 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (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 4239422257; Mon, 19 Oct 2020 11:37:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603107470; bh=TVDVQ/Ab2sgzUQG1yJ1WTN+r2/BeNfiNgFN8blwtyWQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=unQBLWkRwp58+Po18TOtPJ98+Tqudrwp+KOXRX7uvksFnDv6nEf1V2Yd9ZIjjOISl frQMfhKZFBXGWUru+IMPbU5q9mdds04/0JenPN87nynjRZ78fdWG9ZRZGXEfWpgLL6 sbSa/i3c05iDy9bG3vYaC4+49Cr9yiM7h0osGswQ= Received: from disco-boy.misterjones.org ([51.254.78.96] helo=www.loen.fr) by disco-boy.misterjones.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kUTU3-002P16-H1; Mon, 19 Oct 2020 12:37:48 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Mon, 19 Oct 2020 12:37:47 +0100 From: Marc Zyngier To: Sumit Garg Cc: catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, tglx@linutronix.de, jason@lakedaemon.net, mark.rutland@arm.com, julien.thierry.kdev@gmail.com, dianders@chromium.org, daniel.thompson@linaro.org, jason.wessel@windriver.com, msys.mizuma@gmail.com, ito-yuichi@fujitsu.com, kgdb-bugreport@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: Re: [PATCH v5 1/5] arm64: Add framework to turn IPI as NMI In-Reply-To: <1602673931-28782-2-git-send-email-sumit.garg@linaro.org> References: <1602673931-28782-1-git-send-email-sumit.garg@linaro.org> <1602673931-28782-2-git-send-email-sumit.garg@linaro.org> User-Agent: Roundcube Webmail/1.4.9 Message-ID: X-Sender: maz@kernel.org X-SA-Exim-Connect-IP: 51.254.78.96 X-SA-Exim-Rcpt-To: sumit.garg@linaro.org, catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, tglx@linutronix.de, jason@lakedaemon.net, mark.rutland@arm.com, julien.thierry.kdev@gmail.com, dianders@chromium.org, daniel.thompson@linaro.org, jason.wessel@windriver.com, msys.mizuma@gmail.com, ito-yuichi@fujitsu.com, kgdb-bugreport@lists.sourceforge.net, linux-kernel@vger.kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-10-14 12:12, Sumit Garg wrote: > Introduce framework to turn an IPI as NMI using pseudo NMIs. In case a > particular platform doesn't support pseudo NMIs, then request IPI as a > regular IRQ. > > The main motivation for this feature is to have an IPI that can be > leveraged to invoke NMI functions on other CPUs. And current > prospective > users are NMI backtrace and KGDB CPUs round-up whose support is added > via future patches. > > Signed-off-by: Sumit Garg > --- > arch/arm64/include/asm/nmi.h | 16 +++++++++ > arch/arm64/kernel/Makefile | 2 +- > arch/arm64/kernel/ipi_nmi.c | 77 > ++++++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 94 insertions(+), 1 deletion(-) > create mode 100644 arch/arm64/include/asm/nmi.h > create mode 100644 arch/arm64/kernel/ipi_nmi.c > > diff --git a/arch/arm64/include/asm/nmi.h > b/arch/arm64/include/asm/nmi.h > new file mode 100644 > index 0000000..3433c55 > --- /dev/null > +++ b/arch/arm64/include/asm/nmi.h > @@ -0,0 +1,16 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef __ASM_NMI_H > +#define __ASM_NMI_H > + > +#ifndef __ASSEMBLER__ > + > +#include > + > +extern void arch_send_call_nmi_func_ipi_mask(cpumask_t *mask); > + > +void set_smp_ipi_nmi(int ipi); > +void ipi_nmi_setup(int cpu); > +void ipi_nmi_teardown(int cpu); > + > +#endif /* !__ASSEMBLER__ */ > +#endif > diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile > index bbaf0bc..525a1e0 100644 > --- a/arch/arm64/kernel/Makefile > +++ b/arch/arm64/kernel/Makefile > @@ -17,7 +17,7 @@ obj-y := debug-monitors.o entry.o irq.o fpsimd.o \ > return_address.o cpuinfo.o cpu_errata.o \ > cpufeature.o alternative.o cacheinfo.o \ > smp.o smp_spin_table.o topology.o smccc-call.o \ > - syscall.o proton-pack.o > + syscall.o proton-pack.o ipi_nmi.o > > targets += efi-entry.o > > diff --git a/arch/arm64/kernel/ipi_nmi.c b/arch/arm64/kernel/ipi_nmi.c > new file mode 100644 > index 0000000..a959256 > --- /dev/null > +++ b/arch/arm64/kernel/ipi_nmi.c > @@ -0,0 +1,77 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +/* > + * NMI support for IPIs > + * > + * Copyright (C) 2020 Linaro Limited > + * Author: Sumit Garg > + */ > + > +#include > +#include > +#include > + > +#include > + > +static struct irq_desc *ipi_desc __read_mostly; > +static int ipi_id __read_mostly; > +static bool is_nmi __read_mostly; > + > +void arch_send_call_nmi_func_ipi_mask(cpumask_t *mask) > +{ > + if (WARN_ON_ONCE(!ipi_desc)) > + return; > + > + __ipi_send_mask(ipi_desc, mask); > +} > + > +static irqreturn_t ipi_nmi_handler(int irq, void *data) > +{ > + /* nop, NMI handlers for special features can be added here. */ > + > + return IRQ_HANDLED; This definitely is the *wrong* default. If nothing is explicitly handling the interrupt, it should be reported as such to the core code to be disabled if this happens too often. > +} > + > +void ipi_nmi_setup(int cpu) The naming is awful. "ipi" is nowhere specific enough (we already have another 7 of them), and this doesn't necessarily uses pseudo-NMIs, since you are requesting IRQs. > +{ > + if (!ipi_desc) > + return; > + > + if (is_nmi) { > + if (!prepare_percpu_nmi(ipi_id)) > + enable_percpu_nmi(ipi_id, IRQ_TYPE_NONE); > + } else { > + enable_percpu_irq(ipi_id, IRQ_TYPE_NONE); I'm not keen on this. Normal IRQs can't reliably work, so why do you even bother with this? > + } > +} > + > +void ipi_nmi_teardown(int cpu) > +{ > + if (!ipi_desc) > + return; > + > + if (is_nmi) { > + disable_percpu_nmi(ipi_id); > + teardown_percpu_nmi(ipi_id); > + } else { > + disable_percpu_irq(ipi_id); > + } > +} > + > +void __init set_smp_ipi_nmi(int ipi) > +{ > + int err; > + > + err = request_percpu_nmi(ipi, ipi_nmi_handler, "IPI", &cpu_number); > + if (err) { > + err = request_percpu_irq(ipi, ipi_nmi_handler, "IPI", > + &cpu_number); > + WARN_ON(err); > + is_nmi = false; > + } else { > + is_nmi = true; > + } > + > + ipi_desc = irq_to_desc(ipi); > + irq_set_status_flags(ipi, IRQ_HIDDEN); > + ipi_id = ipi; Updating global state without checking for errors doesn't seem like a great move. M. -- Jazz is not dead. It just smells funny...