From patchwork Thu Oct 29 14:56:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 11866585 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=unavailable 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 3B918C4363A for ; Thu, 29 Oct 2020 14:58:59 +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 A3911206E9 for ; Thu, 29 Oct 2020 14:58:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="L467hNnG"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="UTgqNPE3" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A3911206E9 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=L467hNnG6yE3//h2Ahc2JWw+1B 2Stvwj9COde95pfsUzOGCoQpXtecjr1wY/ElxHtr5lQLrMZTEkBHnitgkMQ3VQLH9QsOA1hW5E5Fn Xa6ALVr3pPN3oQu9yZSMRpQTUC1mDpiBbjmmeCFZGxaHJXiTreRvnvcdz4U+X7pI9NMf3TSIT3K9a NWstWBF+u4dfOfdo8W6Tsuvoe1MX6w8UWBQWeFWElcR1uQI37q6fqu3NyntQ5wdq4ONInVzXpDjwi qLy66BmYNxhmvOS0cj6PTZ+qLGwSLL14i36OeRxrnxv/zA8AiUNxMAyzUkTcK7UG+1wnZUejYbM2b QW4rW7+g==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kY9Nc-0004BQ-Rw; Thu, 29 Oct 2020 14:58:20 +0000 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kY9NX-00048o-KR for linux-arm-kernel@lists.infradead.org; Thu, 29 Oct 2020 14:58:16 +0000 Received: by mail-pg1-x541.google.com with SMTP id r186so2568199pgr.0 for ; Thu, 29 Oct 2020 07:58:15 -0700 (PDT) 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=UTgqNPE3CgHTQOjtCEe5fY63HFkau6nwSfU3tebnaMgbLjfmpkzwU3MNlr9pz5gWJD qMUwQe1Q4fhp61u6cOCopwyTIOlaGHGfvhks63Bq50GiF48FjbWprnDTLmANetyQoksf GvwrXmv0bGrCgCX3hB8LMUQ4Jgz5cyl75lVQEKDeBClyligwXBg5roxgNSU6ppUhcjKA BfJkTtEZQWEpcRdQTInYXrt5m7PIWwY4fJ8K7C25pmLV+n9CZ0phyUq8CwILFrvuKa8R r9S61kgqBImKz0XJWw1+ThRUb3yU8XJw1crs+t0qsusYUKrGSvQ5kW8WAccX28ny9FyZ WpIQ== 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=pn39gTgVKD1EFCDhsZg8pGCWOCVnQSMsULVNMVHqpXS+N43XQxpjMD5KXlXIgU5BCk qGH0uGQ6C6tY1nYq4cuFUDS33lNdQgF9Q76c3zbTzyeGv6FnIrrwdoHPDu24/tVkxaUB dKwYJWBGHOE3JrH5WkY9VWG/SESKga9L1lQMESb88b4s+dXP6Io5TJ+Vtj02tUmgpKcJ Uh6uiIDfplM+swdZq0B8PT8fH7Xyv9FNcWuENKoC3wA6fayDUPRBt27+u8nNS4HsKCvK 6CG6TgcKD6LBnNTY9+b380izOlqUDAQ7HbXIM5EjCrQDe2N6f7DWrGRaOhRrXAsaWFH6 /jSA== X-Gm-Message-State: AOAM533DrYy7jKa4G22cLvixOH6VnNhziY72GBIiwK8D/5GRFUGhyejP hLIq5hu4AgHel3WQOgZrnjaO9w== X-Google-Smtp-Source: ABdhPJzIFWYKnl/IyiB31hLlKUzs2X73dexAslUVHzXzamn5QQ6KnGb7yj8QBf0SCIt5ulzti78wvw== X-Received: by 2002:a17:90a:db06:: with SMTP id g6mr194406pjv.156.1603983493976; Thu, 29 Oct 2020 07:58:13 -0700 (PDT) Received: from localhost.localdomain ([117.252.71.231]) by smtp.gmail.com with ESMTPSA id j11sm3085082pfc.64.2020.10.29.07.58.04 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Oct 2020 07:58:13 -0700 (PDT) From: Sumit Garg To: maz@kernel.org, catalin.marinas@arm.com, will@kernel.org Subject: [PATCH v6 1/7] arm64: Add framework to turn IPI as NMI Date: Thu, 29 Oct 2020 20:26:21 +0530 Message-Id: <1603983387-8738-2-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1603983387-8738-1-git-send-email-sumit.garg@linaro.org> References: <1603983387-8738-1-git-send-email-sumit.garg@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201029_105815_850276_3C297B64 X-CRM114-Status: GOOD ( 20.08 ) 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 , daniel.thompson@linaro.org, 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; + } +}