From patchwork Thu Jun 1 21:31:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 13264462 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 64676C7EE2F for ; Thu, 1 Jun 2023 21:37:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ADajAyQExL+we9AinmB7nMGW4DHD+FQM2gXq2P4+CKc=; b=rBJoWTIZSiImlu GTCA8z5ZN87kTaGVJ7nFnJOkpN60pp00WxkowDy6iO+rP01YhpetTiC+gdww8Hi866CfkBk0L533h WGIh0nxvsc1jSJZ5bjUTFwhg7ZygduozQIZFU8sXaDRI3OUZW7wE96bUUpGV0HrYK5ZCtxfmr5OJJ a+Bag071AHt+tZbqVSB22LkVOSE1eYDh8tLs0q/Ao12mzuHpQYKlOLjeDY95Hq3DjCdxV6j4Wnxj+ q2s1PYAJJspn5MfM0bOa9RD08tZ6oGhfWb7gZzY8SPnjJZJsag2aCzZTesjdTwmfDyDomnonDuZmi DkK/e+CAwsIuOKOEixmg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q4pyv-0050ll-0m; Thu, 01 Jun 2023 21:37:17 +0000 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q4pyq-0050i8-2M for linux-arm-kernel@lists.infradead.org; Thu, 01 Jun 2023 21:37:15 +0000 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-652699e72f7so471382b3a.3 for ; Thu, 01 Jun 2023 14:37:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1685655432; x=1688247432; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VxngL/nWZ9CvmSVXwg8pkM18NqkUW/hq6cWY9xHbU50=; b=aXtBMJsuEHVcZIKV7cLRpp9gJah5t0XCzX6mPhaAfDBP1dJ5ow0nIMbyHBqXyExXs/ iONAnH757E2JdGKhPAJpJ0T+0at+owiwzn2oTUIqycF0fDPlNwbji/qaAjIXJsOAh/DF EzBp3VrZJfcftxuQAMYGMNArokNyBuLgHVwN8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685655432; x=1688247432; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VxngL/nWZ9CvmSVXwg8pkM18NqkUW/hq6cWY9xHbU50=; b=WulxU5arhBMcoIkCmQTYL5YORPUAzZhnRsUMpZ8Nsd6LTRshuszD1TFXlHX4n9Dxca VikLLaWO4RIhoESfifv5pwjjENE2O5Ge1wyPrO2FdZpsL0afjHqBNSl2PI6PXSheHTSJ fuLZt78ls18O0INRxAuZ1WgciidATEkTkobzQ6BZ7sxTxEyTr+IZk90kEnw+PD02U6f4 d/Pwjy7D2OAwihb2BEC+krsipuL4UE8q9DsYZT6lareXj5XLPl9JFW+wgOe34znHQ4R/ gOW6PEcfl4kMItFxEMYYSI+bTjrq455+D3lzsiYzLOhp0UVXTcI55709hTyjO4Vgqg4s awmQ== X-Gm-Message-State: AC+VfDwviO2m2PYJgjg0WSTIypOwZ81VHtDlhmX08G9EkvCXmrhTLktg +WMQpH7iVHoNADqwNH+nGMmLAw== X-Google-Smtp-Source: ACHHUZ5ef/rtEIYJxyW1OxKT1bSL//A95UwWPCmZBbTCdj36TOdor4jNJCZmCSlkwGKN3QsCenCWSg== X-Received: by 2002:a05:6a00:8ca:b0:64c:b45f:fc86 with SMTP id s10-20020a056a0008ca00b0064cb45ffc86mr10767019pfu.17.1685655432123; Thu, 01 Jun 2023 14:37:12 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:9d:2:11b8:2d2:7e02:6bff]) by smtp.gmail.com with ESMTPSA id g22-20020aa78756000000b0064d48d98260sm5319534pfo.156.2023.06.01.14.37.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jun 2023 14:37:11 -0700 (PDT) From: Douglas Anderson To: Mark Rutland , Catalin Marinas , Will Deacon , Sumit Garg , Daniel Thompson , Marc Zyngier Cc: linux-perf-users@vger.kernel.org, ito-yuichi@fujitsu.com, Chen-Yu Tsai , Ard Biesheuvel , Stephen Boyd , Peter Zijlstra , Thomas Gleixner , linux-arm-kernel@lists.infradead.org, kgdb-bugreport@lists.sourceforge.net, Masayoshi Mizuma , "Rafael J . Wysocki" , Lecopzer Chen , Douglas Anderson , Andrey Konovalov , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH v9 3/7] arm64: Add framework for a debug IPI Date: Thu, 1 Jun 2023 14:31:47 -0700 Message-ID: <20230601143109.v9.3.Ie6c132b96ebbbcddbf6954b9469ed40a6960343c@changeid> X-Mailer: git-send-email 2.41.0.rc2.161.g9c6817b8e7-goog In-Reply-To: <20230601213440.2488667-1-dianders@chromium.org> References: <20230601213440.2488667-1-dianders@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230601_143712_775192_48D83F3B X-CRM114-Status: GOOD ( 24.98 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Sumit Garg Introduce a framework for an IPI that will be used for debug purposes. The primary use case of this IPI will be to generate stack crawls on other CPUs, but it will also be used to round up CPUs for kgdb. When possible, we try to allocate this debug IPI as an NMI (or a pseudo NMI). If that fails (due to CONFIG, an incompatible interrupt controller, a quirk, missing the "irqchip.gicv3_pseudo_nmi=1" kernel parameter, etc) we fall back to a normal IPI. NOTE: hooking this up for CPU backtrace / kgdb will happen in a future patch, this just adds the framework. Signed-off-by: Sumit Garg Signed-off-by: Douglas Anderson Signed-off-by: Mark Rutland --- I didn't get any feedback from v8 patch #10 [1], but I went ahead and folded it in here anyway since it really simplfies things. If people don't like the fallback to regular IPI, I can also undo it. [1] https://lore.kernel.org/r/20230419155341.v8.10.Ic3659997d6243139d0522fc3afcdfd88d7a5f030@changeid/ Changes in v9: - Fold in v8 patch #10 ("Fallback to a regular IPI if NMI isn't enabled") - Moved header file out of "include" since it didn't need to be there. - Remove arm64_supports_nmi() - Renamed "NMI IPI" to "debug IPI" since it might not be backed by NMI. Changes in v8: - debug_ipi_setup() and debug_ipi_teardown() no longer take cpu param arch/arm64/kernel/Makefile | 2 +- arch/arm64/kernel/ipi_debug.c | 76 +++++++++++++++++++++++++++++++++++ arch/arm64/kernel/ipi_debug.h | 13 ++++++ 3 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 arch/arm64/kernel/ipi_debug.c create mode 100644 arch/arm64/kernel/ipi_debug.h diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index cc22011ab66a..737838f803b7 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -34,7 +34,7 @@ obj-y := debug-monitors.o entry.o irq.o fpsimd.o \ cpufeature.o alternative.o cacheinfo.o \ smp.o smp_spin_table.o topology.o smccc-call.o \ syscall.o proton-pack.o idreg-override.o idle.o \ - patching.o + patching.o ipi_debug.o obj-$(CONFIG_COMPAT) += sys32.o signal32.o \ sys_compat.o diff --git a/arch/arm64/kernel/ipi_debug.c b/arch/arm64/kernel/ipi_debug.c new file mode 100644 index 000000000000..b57833e31eaf --- /dev/null +++ b/arch/arm64/kernel/ipi_debug.c @@ -0,0 +1,76 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Debug IPI support + * + * Copyright (C) 2020 Linaro Limited + * Author: Sumit Garg + */ + +#include +#include +#include + +#include "ipi_debug.h" + +static struct irq_desc *ipi_debug_desc __read_mostly; +static int ipi_debug_id __read_mostly; +static bool is_nmi; + +void arm64_debug_ipi(cpumask_t *mask) +{ + if (WARN_ON_ONCE(!ipi_debug_desc)) + return; + + __ipi_send_mask(ipi_debug_desc, mask); +} + +static irqreturn_t ipi_debug_handler(int irq, void *data) +{ + /* nop, NMI handlers for special features can be added here. */ + + return IRQ_NONE; +} + +void debug_ipi_setup(void) +{ + if (!ipi_debug_desc) + return; + + if (is_nmi) { + if (!prepare_percpu_nmi(ipi_debug_id)) + enable_percpu_nmi(ipi_debug_id, IRQ_TYPE_NONE); + } else { + enable_percpu_irq(ipi_debug_id, IRQ_TYPE_NONE); + } +} + +void debug_ipi_teardown(void) +{ + if (!ipi_debug_desc) + return; + + if (is_nmi) { + disable_percpu_nmi(ipi_debug_id); + teardown_percpu_nmi(ipi_debug_id); + } else { + disable_percpu_irq(ipi_debug_id); + } +} + +void __init set_smp_debug_ipi(int ipi) +{ + int err; + + if (!request_percpu_nmi(ipi, ipi_debug_handler, "IPI", &cpu_number)) { + is_nmi = true; + } else { + err = request_percpu_irq(ipi, ipi_debug_handler, "IPI", &cpu_number); + if (WARN_ON(err)) + return; + + irq_set_status_flags(ipi, IRQ_HIDDEN); + } + + ipi_debug_desc = irq_to_desc(ipi); + ipi_debug_id = ipi; +} diff --git a/arch/arm64/kernel/ipi_debug.h b/arch/arm64/kernel/ipi_debug.h new file mode 100644 index 000000000000..f6011a09282f --- /dev/null +++ b/arch/arm64/kernel/ipi_debug.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ASM_NMI_H +#define __ASM_NMI_H + +#include + +void arm64_debug_ipi(cpumask_t *mask); + +void set_smp_debug_ipi(int ipi); +void debug_ipi_setup(void); +void debug_ipi_teardown(void); + +#endif