From patchwork Mon Nov 2 11:44:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 11873681 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 441F1C00A89 for ; Mon, 2 Nov 2020 11:46:42 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DB24D223BD for ; Mon, 2 Nov 2020 11:46:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="kQ8hIk0A"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="E0zlvuCR" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DB24D223BD Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:References:In-Reply-To:Message-Id:Date:Subject:To: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=nq1GVWKhwcdJ5kz6MDasxF3+tUyaeIaMS9wEpFwhlVk=; b=kQ8hIk0Ak8Tw+uLsDc/3IDjmqZ 13IRPDqHa7pRCWEzwO6pNSfwtkPYTpwNXpDymHfTpWSNEICi4ZfHQOBw10HQ9eARmPJqsPbd4wlmh EsdeMnWxL4irM/IcwHbeUl8r0bvrf3yN4d36/mu88LX4i4i80xI1xaD+OJvJBlC9Up/5nHh7o988P taJX1tB8X32W+iMnxCt9+SIwA0Q6XVToICAHmidRuIvoLoR9uaniD4y58hwTO04MEyF3/b5PjP6aC G8Jc2ZNguR9TMMEZXstxRyIeNS1ubDZSScdoUbtJ29R+Xggnc9jmH17Qv9KMVjOtMXdY41GYmRqjF 44whQcaQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kZYHh-0007CT-P4; Mon, 02 Nov 2020 11:46:01 +0000 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kZYHZ-00079R-VD for linux-arm-kernel@lists.infradead.org; Mon, 02 Nov 2020 11:45:57 +0000 Received: by mail-pg1-x542.google.com with SMTP id 62so3282375pgg.12 for ; Mon, 02 Nov 2020 03:45:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=TBLIKfpsklTZAlEASF12NJyKPiqj9Rqie6gj0u/aah0=; b=E0zlvuCR88oHQsE4WYprnL6Cyxa8vZWkrCSnRxyAkYmj/8JBrBP6Y8xASUQayvZAR5 Yg8kWJ1lQk2tLGfyJCZ9Hu1sPRIkpt5zxfYG6KqV6+2vTYwD5ERfO42Yixd29XgwT5ST AiP8f8DUKEFz+d2LlXJbTiH+nSAw3u987NNCPUZhpcLOmUMmr4BqWikHwrgdAfBTQg0I ZlnjA8CvgHaizhr2X9PyB0in3prA9L/haL55wNR5TTTLOf4HwW1YU3B8QNIUrj4Ybhk6 8P3eMbb0DrTdQimvjHb09bmR2EVMPE0D9R6oChUQ9i1Jxts44Yli9lrPgxIlALJCE1KU 4aiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=TBLIKfpsklTZAlEASF12NJyKPiqj9Rqie6gj0u/aah0=; b=te6kvO5ak+JU66NOytYlOOJB08o0QEPJrbancbgXK46Fh7P2GTZ7BUYte/BAPkZScn 1H2IajGXsD+/UjavfUvP3d8iezm3OL4x9HabGIkEzwa7dvdVqflWM4px4sICTrVkQRjF kKaDm8mL/Z+B6ZFEDKdT6tnInfDnVArtRgdE7wAgSr/kqSdHzj9tlvQXWklCU45p/0tf NYbWdiC6iArbkJ8cqx70wF2+wiNYcFGeK1XlTk2Raw9tKeMBmamcSFP2r9G9qyhCoy60 fnpEQbzQON8BPv076sBaQVNUpp1U8YB1DV/VKBgyA/7qTA9Jtd2hyQEhnnJ3pq6a1JvN 5J8A== X-Gm-Message-State: AOAM530S6jOtCST5TDtlQGXriOdC8i9eLJHmIDlmTKRCpYqCrHqoQ71J W/+2b6LncoLxSeyF6hIaauTEfQ== X-Google-Smtp-Source: ABdhPJzeSbWyx0zTDhLxg+mHYiTpnkodIkCYGRCeMEkqtHqivG6UrK+sVI8IK1jDmCGe66Wo9QvQaw== X-Received: by 2002:a17:90a:5d8e:: with SMTP id t14mr15827085pji.199.1604317549868; Mon, 02 Nov 2020 03:45:49 -0800 (PST) Received: from localhost.localdomain ([122.173.169.225]) by smtp.gmail.com with ESMTPSA id y5sm14276184pfq.79.2020.11.02.03.45.42 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Nov 2020 03:45:49 -0800 (PST) From: Sumit Garg To: maz@kernel.org, catalin.marinas@arm.com, will@kernel.org, daniel.thompson@linaro.org Subject: [PATCH v7 1/7] arm64: Add framework to turn IPI as NMI Date: Mon, 2 Nov 2020 17:14:41 +0530 Message-Id: <1604317487-14543-2-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1604317487-14543-1-git-send-email-sumit.garg@linaro.org> References: <1604317487-14543-1-git-send-email-sumit.garg@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201102_064554_072790_03091D62 X-CRM114-Status: GOOD ( 20.70 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, Sumit Garg , tsbogend@alpha.franken.de, linux-kernel@vger.kernel.org, jason@lakedaemon.net, ito-yuichi@fujitsu.com, mpe@ellerman.id.au, x86@kernel.org, linux@armlinux.org.uk, dianders@chromium.org, mingo@redhat.com, bp@alien8.de, julien.thierry.kdev@gmail.com, jason.wessel@windriver.com, kgdb-bugreport@lists.sourceforge.net, tglx@linutronix.de, msys.mizuma@gmail.com, davem@davemloft.net, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Introduce framework to turn an IPI as NMI using pseudo NMIs. 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 | 17 ++++++++++++ arch/arm64/kernel/Makefile | 2 +- arch/arm64/kernel/ipi_nmi.c | 65 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 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..4cd14b6 --- /dev/null +++ b/arch/arm64/include/asm/nmi.h @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ASM_NMI_H +#define __ASM_NMI_H + +#ifndef __ASSEMBLER__ + +#include + +extern bool arm64_supports_nmi(void); +extern void arm64_send_nmi(cpumask_t *mask); + +void set_smp_dynamic_ipi(int ipi); +void dynamic_ipi_setup(int cpu); +void dynamic_ipi_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..a945dcf --- /dev/null +++ b/arch/arm64/kernel/ipi_nmi.c @@ -0,0 +1,65 @@ +// 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_nmi_desc __read_mostly; +static int ipi_nmi_id __read_mostly; + +bool arm64_supports_nmi(void) +{ + if (ipi_nmi_desc) + return true; + + return false; +} + +void arm64_send_nmi(cpumask_t *mask) +{ + if (WARN_ON_ONCE(!ipi_nmi_desc)) + return; + + __ipi_send_mask(ipi_nmi_desc, mask); +} + +static irqreturn_t ipi_nmi_handler(int irq, void *data) +{ + /* nop, NMI handlers for special features can be added here. */ + + return IRQ_NONE; +} + +void dynamic_ipi_setup(int cpu) +{ + if (!ipi_nmi_desc) + return; + + if (!prepare_percpu_nmi(ipi_nmi_id)) + enable_percpu_nmi(ipi_nmi_id, IRQ_TYPE_NONE); +} + +void dynamic_ipi_teardown(int cpu) +{ + if (!ipi_nmi_desc) + return; + + disable_percpu_nmi(ipi_nmi_id); + teardown_percpu_nmi(ipi_nmi_id); +} + +void __init set_smp_dynamic_ipi(int ipi) +{ + if (!request_percpu_nmi(ipi, ipi_nmi_handler, "IPI", &cpu_number)) { + ipi_nmi_desc = irq_to_desc(ipi); + ipi_nmi_id = ipi; + } +}