From patchwork Thu Aug 24 15:30:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 13364379 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 8C27BC27C40 for ; Thu, 24 Aug 2023 15:33:42 +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=RTwtIm5lJG0wAkIBXYVC15fzsPK0xsUbgV/Opl7lZrs=; b=5CyB98Ds8BQQVC 94duKGF1ayoHyHXAUrTrjS+zhP4Bv+gCUS6dVAtaWXFxebKEbWgiEv+9bcYyckTAwFzp6IiPMcdOY IkYGKaIUlmagKIukMRU07nSPzSvLko9StermNFARVA0ep47GxGI9vfqoG876MVBB56lgwiOdLTG68 Y/r/2FnexM8csCs/XHBghmN9M3U0hSjLs423avrSqBhWPX8lkUYkeFcKUQn2Iour+uCa5wFhoQPN7 QvAH+tFXJSZEw+V31OuaPTPsDE/RWI01Jh/cJGVXtPjQungvzB7kZ8xIzwsy/VcvHWHop7rL1J+Um 3+0D+7NVbURRN7R+VNnA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qZCKX-003NGw-0a; Thu, 24 Aug 2023 15:33:05 +0000 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qZCKT-003NFr-0I for linux-arm-kernel@lists.infradead.org; Thu, 24 Aug 2023 15:33:02 +0000 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-68a1af910e0so3908796b3a.2 for ; Thu, 24 Aug 2023 08:33:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1692891180; x=1693495980; 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=1heW6OffuAP0ul2AbuPI0sVn5slQ3SwOx99vGjvV2yE=; b=fBfgs6F5QbNoASGEkqDOvmfsUp2ZgJsd9gK29T2AgR+9lx9Yq7YZdG+5S+jWL1Ds2L L7hjIkWXBUxSIJXaMwzSoam755X4W6vIteQnXKcxGZmTYZCkw5GFtKx1tT9F/ANcOWk1 8PEeSJACjjp6Atyt9LSoOox6fdWBPuU5AhAeA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692891180; x=1693495980; 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=1heW6OffuAP0ul2AbuPI0sVn5slQ3SwOx99vGjvV2yE=; b=BcupVsPB2dTss0tk04eTK7PIupVAmVmJg9VYvQVmM+FGpfJgRr6pTPkJO7X6E+joTM Aup8wE55iwY60JkHtvoKYTILz+KnCL+mmZzIdNuQ+T9iCsTf4/FD4dPuvKi8B4eIsHq4 n0I5ZSVA3WPVY0RaoXhSN+cNyCvTYcOSrdKEbuUe8Qk+MeNAD1owEey3CbXRu8p2Zybd mELRWa8pLTGJvyrZVHUh9v3Oq+L55m8fZiqLznUQIARljTQCpo6nqYFPuv3nRMt7twOp P/LaVt9ZGqfJ8HdPt24C84/jLJwNQ9gAnXj9qHeF5kZqKNYt6EmekDARAM4tPFzbbo+3 +fvA== X-Gm-Message-State: AOJu0Yx786HWE4R7+ieCSmRPcm6JP2qsE3K7uoi5WOSi5nzngfEBbJNz GHz/il/eVhcXtDurz7hP9BPexA== X-Google-Smtp-Source: AGHT+IEv4M4LGNkfwmqZe1my0PmiiMeAPofLo901bcZKMxOHhBpmHlVQlwJgkcS2WXcsvHS/2b0mrw== X-Received: by 2002:a05:6a00:248d:b0:68b:ee34:9729 with SMTP id c13-20020a056a00248d00b0068bee349729mr2610258pfv.24.1692891180526; Thu, 24 Aug 2023 08:33:00 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:9d:2:afa3:fcf5:1b7f:f7e2]) by smtp.gmail.com with ESMTPSA id m30-20020a63711e000000b0056365ee8603sm11631337pgc.67.2023.08.24.08.32.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Aug 2023 08:32:59 -0700 (PDT) From: Douglas Anderson To: Mark Rutland , Catalin Marinas , Will Deacon , Sumit Garg , Daniel Thompson , Marc Zyngier Cc: "Rafael J . Wysocki" , Ard Biesheuvel , Thomas Gleixner , kgdb-bugreport@lists.sourceforge.net, Lecopzer Chen , linux-perf-users@vger.kernel.org, Masayoshi Mizuma , Chen-Yu Tsai , linux-arm-kernel@lists.infradead.org, ito-yuichi@fujitsu.com, Stephen Boyd , Peter Zijlstra , Douglas Anderson , linux-kernel@vger.kernel.org Subject: [PATCH v11 1/6] irqchip/gic-v3: Enable support for SGIs to act as NMIs Date: Thu, 24 Aug 2023 08:30:27 -0700 Message-ID: <20230824083012.v11.1.I1223c11c88937bd0cbd9b086d4ef216985797302@changeid> X-Mailer: git-send-email 2.42.0.rc1.204.g551eb34607-goog In-Reply-To: <20230824153233.1006420-1-dianders@chromium.org> References: <20230824153233.1006420-1-dianders@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230824_083301_129722_4A37DFFB X-CRM114-Status: GOOD ( 23.29 ) 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 As of commit 6abbd6988971 ("irqchip/gic, gic-v3: Make SGIs use handle_percpu_devid_irq()") SGIs are treated the same as PPIs/EPPIs and use handle_percpu_devid_irq() by default. Unfortunately, handle_percpu_devid_irq() isn't NMI safe, and so to run in an NMI context those should use handle_percpu_devid_fasteoi_nmi(). In order to accomplish this, we just have to make room for SGIs in the array of refcounts that keeps track of which interrupts are set as NMI. We also rename the array and create a new indexing scheme that accounts for SGIs. Also, enable NMI support prior to gic_smp_init() as allocation of SGIs as IRQs/NMIs happen as part of this routine. Co-developed-by: Sumit Garg Signed-off-by: Sumit Garg Signed-off-by: Douglas Anderson --- In v10 I removed the previous Reviewed-by and Tested-by tags since the patch contents changed pretty drastically. I'll also note that this change is a little more black magic to me than others in this series. I don't have a massive amounts of familiarity with all the moving parts of gic-v3, so I mostly just followed Mark Rutland's advice [1]. Please pay extra attention to make sure I didn't do anything too terrible. Mark's advice wasn't a full patch and I ended up doing a bit of work to translate it to reality, so I did not add him as "Co-developed-by" here. Mark: if you would like this tag then please provide it and your Signed-off-by. I certainly won't object. [1] https://lore.kernel.org/r/ZNC-YRQopO0PaIIo@FVFF77S0Q05N.cambridge.arm.com (no changes since v10) Changes in v10: - Rewrite as needed for 5.11+ as per Mark Rutland and Sumit. drivers/irqchip/irq-gic-v3.c | 54 ++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/drivers/irqchip/irq-gic-v3.c b/drivers/irqchip/irq-gic-v3.c index eedfa8e9f077..49d18cf3f636 100644 --- a/drivers/irqchip/irq-gic-v3.c +++ b/drivers/irqchip/irq-gic-v3.c @@ -78,6 +78,8 @@ static DEFINE_STATIC_KEY_TRUE(supports_deactivate_key); #define GIC_LINE_NR min(GICD_TYPER_SPIS(gic_data.rdists.gicd_typer), 1020U) #define GIC_ESPI_NR GICD_TYPER_ESPIS(gic_data.rdists.gicd_typer) +#define SGI_NR 16 + /* * The behaviours of RPR and PMR registers differ depending on the value of * SCR_EL3.FIQ, and the behaviour of non-secure priority registers of the @@ -125,8 +127,8 @@ EXPORT_SYMBOL(gic_nonsecure_priorities); __priority; \ }) -/* ppi_nmi_refs[n] == number of cpus having ppi[n + 16] set as NMI */ -static refcount_t *ppi_nmi_refs; +/* rdist_nmi_refs[n] == number of cpus having the rdist interrupt n set as NMI */ +static refcount_t *rdist_nmi_refs; static struct gic_kvm_info gic_v3_kvm_info __initdata; static DEFINE_PER_CPU(bool, has_rss); @@ -519,9 +521,22 @@ static u32 __gic_get_ppi_index(irq_hw_number_t hwirq) } } -static u32 gic_get_ppi_index(struct irq_data *d) +static u32 __gic_get_rdist_idx(irq_hw_number_t hwirq) +{ + switch (__get_intid_range(hwirq)) { + case SGI_RANGE: + case PPI_RANGE: + return hwirq; + case EPPI_RANGE: + return hwirq - EPPI_BASE_INTID + 32; + default: + unreachable(); + } +} + +static u32 gic_get_rdist_idx(struct irq_data *d) { - return __gic_get_ppi_index(d->hwirq); + return __gic_get_rdist_idx(d->hwirq); } static int gic_irq_nmi_setup(struct irq_data *d) @@ -545,11 +560,14 @@ static int gic_irq_nmi_setup(struct irq_data *d) /* desc lock should already be held */ if (gic_irq_in_rdist(d)) { - u32 idx = gic_get_ppi_index(d); + u32 idx = gic_get_rdist_idx(d); - /* Setting up PPI as NMI, only switch handler for first NMI */ - if (!refcount_inc_not_zero(&ppi_nmi_refs[idx])) { - refcount_set(&ppi_nmi_refs[idx], 1); + /* + * Setting up a percpu interrupt as NMI, only switch handler + * for first NMI + */ + if (!refcount_inc_not_zero(&rdist_nmi_refs[idx])) { + refcount_set(&rdist_nmi_refs[idx], 1); desc->handle_irq = handle_percpu_devid_fasteoi_nmi; } } else { @@ -582,10 +600,10 @@ static void gic_irq_nmi_teardown(struct irq_data *d) /* desc lock should already be held */ if (gic_irq_in_rdist(d)) { - u32 idx = gic_get_ppi_index(d); + u32 idx = gic_get_rdist_idx(d); /* Tearing down NMI, only switch handler for last NMI */ - if (refcount_dec_and_test(&ppi_nmi_refs[idx])) + if (refcount_dec_and_test(&rdist_nmi_refs[idx])) desc->handle_irq = handle_percpu_devid_irq; } else { desc->handle_irq = handle_fasteoi_irq; @@ -1279,10 +1297,10 @@ static void gic_cpu_init(void) rbase = gic_data_rdist_sgi_base(); /* Configure SGIs/PPIs as non-secure Group-1 */ - for (i = 0; i < gic_data.ppi_nr + 16; i += 32) + for (i = 0; i < gic_data.ppi_nr + SGI_NR; i += 32) writel_relaxed(~0, rbase + GICR_IGROUPR0 + i / 8); - gic_cpu_config(rbase, gic_data.ppi_nr + 16, gic_redist_wait_for_rwp); + gic_cpu_config(rbase, gic_data.ppi_nr + SGI_NR, gic_redist_wait_for_rwp); /* initialise system registers */ gic_cpu_sys_reg_init(); @@ -1939,12 +1957,13 @@ static void gic_enable_nmi_support(void) return; } - ppi_nmi_refs = kcalloc(gic_data.ppi_nr, sizeof(*ppi_nmi_refs), GFP_KERNEL); - if (!ppi_nmi_refs) + rdist_nmi_refs = kcalloc(gic_data.ppi_nr + SGI_NR, + sizeof(*rdist_nmi_refs), GFP_KERNEL); + if (!rdist_nmi_refs) return; - for (i = 0; i < gic_data.ppi_nr; i++) - refcount_set(&ppi_nmi_refs[i], 0); + for (i = 0; i < gic_data.ppi_nr + SGI_NR; i++) + refcount_set(&rdist_nmi_refs[i], 0); pr_info("Pseudo-NMIs enabled using %s ICC_PMR_EL1 synchronisation\n", gic_has_relaxed_pmr_sync() ? "relaxed" : "forced"); @@ -2061,6 +2080,7 @@ static int __init gic_init_bases(phys_addr_t dist_phys_base, gic_dist_init(); gic_cpu_init(); + gic_enable_nmi_support(); gic_smp_init(); gic_cpu_pm_init(); @@ -2073,8 +2093,6 @@ static int __init gic_init_bases(phys_addr_t dist_phys_base, gicv2m_init(handle, gic_data.domain); } - gic_enable_nmi_support(); - return 0; out_free: From patchwork Thu Aug 24 15:30:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 13364380 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 83631C3DA6F for ; Thu, 24 Aug 2023 15:33:48 +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=RFqpj3p1e8C2LP/pF4dluN9fqTSozLpg0AQiDA83O9g=; b=Gd+R46Q8whKMEG Vq0EBrUrRgTBddYIv0+nwDdCwklqOCUwglcwtenMEyssKi3oItKjMCUa26Li/0uoYSVhbJ9u+4kHJ C7kfwNWxyIS2FLSItvM2ucSXvElGgQQf9LvkNM0bvahPvSjOp/gH+yPfVG5NlN0PDkh5OlGLmO5vw Gxvo9+DzyCJdj+eM0b5RnI1Uv3ReFT9naSY/lUdgAqjkJFt4l1nSNO8Khux5NcVmzvQg+pAPBTsyA AOKaEgaorZQ8Alf/P3jrjwENqZU6wxvYZ4Tgek5RKuVAoJngNmJcV0eMKjctZkpzns4js3zb/eqwm vXqfuKFBjrxZWPpNdK+Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qZCKl-003NLl-2C; Thu, 24 Aug 2023 15:33:19 +0000 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qZCKY-003NGn-0X for linux-arm-kernel@lists.infradead.org; Thu, 24 Aug 2023 15:33:07 +0000 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-68bec3a81c4so3158b3a.1 for ; Thu, 24 Aug 2023 08:33:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1692891183; x=1693495983; 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=S8LQV3FZTWxLTg8jNgV7yvfSpimnidUcb0tZukELwI8=; b=lNensNrtbZ1/JO69cv/X7s17yyTO9pvyYki4jYqN0gNJwZSYaEv3k4Lrs/SWiERqSR MVf/1Ic8euWeBn106GsnAPicEAQZXm8K0jrbF94OgDjO8enkM6T2K63rkyzfF4S+v9HW fV2hiAqantxQwPP3J2uQWDI4t+aiqsMaMaFuo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692891183; x=1693495983; 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=S8LQV3FZTWxLTg8jNgV7yvfSpimnidUcb0tZukELwI8=; b=FcWGy/hYBNm6f6YJnZYeVn1i4z6rmvG2zSHmJs4wzQQxtDkU4oiF7Zaw0C8KzR026V Gf7LQzw5WRamZlG72ItOwVnS3/Cs9vm1NCHt2rYx8VhhWjv2SoKqVbA35eh1bC8Mg/9N Rn6U95fjuDAGxWUFdyBbS0jSw70yzYTJTFZsMWksH0u+oHNnsOwqTRfEiXPkOIFLZdFA TOGGw2VMtdbV9wTcEJn216sXyJeI2dsUUn9zI7rBFIveQxB+N5EZSnvtghf4mrTtagxq 05iymFnUOEb+VB10cdjLe57yeFPxUaFP0AME7Z34M4BF8SVfAkvt7xrjaKnbSHi55Obu UwZQ== X-Gm-Message-State: AOJu0YxfC0OVk/TuIdN8AHhU+WBMX9/IsOXoj6km4anAyF/iJGjhaXSr 0hRX2oE7uUn/3KsbHi6IMpDlLiuf3Oe2+WcjY+qzTAtc X-Google-Smtp-Source: AGHT+IHtE7/RbB67nJdYB/Ae0mTQ0RJ8uJ9wBeYpGrn270z6LtX1u8780/eo8q0EyT04aZwzQcfYQg== X-Received: by 2002:a05:6a20:9187:b0:125:4d74:cd6a with SMTP id v7-20020a056a20918700b001254d74cd6amr22207369pzd.3.1692891182940; Thu, 24 Aug 2023 08:33:02 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:9d:2:afa3:fcf5:1b7f:f7e2]) by smtp.gmail.com with ESMTPSA id m30-20020a63711e000000b0056365ee8603sm11631337pgc.67.2023.08.24.08.33.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Aug 2023 08:33:02 -0700 (PDT) From: Douglas Anderson To: Mark Rutland , Catalin Marinas , Will Deacon , Sumit Garg , Daniel Thompson , Marc Zyngier Cc: "Rafael J . Wysocki" , Ard Biesheuvel , Thomas Gleixner , kgdb-bugreport@lists.sourceforge.net, Lecopzer Chen , linux-perf-users@vger.kernel.org, Masayoshi Mizuma , Chen-Yu Tsai , linux-arm-kernel@lists.infradead.org, ito-yuichi@fujitsu.com, Stephen Boyd , Peter Zijlstra , Douglas Anderson , Frederic Weisbecker , Guo Ren , Ingo Molnar , linux-kernel@vger.kernel.org Subject: [PATCH v11 2/6] arm64: idle: Tag the arm64 idle functions as __cpuidle Date: Thu, 24 Aug 2023 08:30:28 -0700 Message-ID: <20230824083012.v11.2.I4baba13e220bdd24d11400c67f137c35f07f82c7@changeid> X-Mailer: git-send-email 2.42.0.rc1.204.g551eb34607-goog In-Reply-To: <20230824153233.1006420-1-dianders@chromium.org> References: <20230824153233.1006420-1-dianders@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230824_083306_254585_361F16BC X-CRM114-Status: GOOD ( 18.79 ) 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 As per the (somewhat recent) comment before the definition of `__cpuidle`, the tag is like `noinstr` but also marks a function so it can be identified by cpu_in_idle(). Let's add these markings to arm64 cpuidle functions With this change we get useful backtraces like: NMI backtrace for cpu N skipped: idling at cpu_do_idle+0x94/0x98 instead of useless backtraces when dumping all processors using nmi_cpu_backtrace(). NOTE: this patch won't make cpu_in_idle() work perfectly for arm64, but it doesn't hurt and does catch some cases. Specifically an example that wasn't caught in my testing looked like this: gic_cpu_sys_reg_init+0x1f8/0x314 gic_cpu_pm_notifier+0x40/0x78 raw_notifier_call_chain+0x5c/0x134 cpu_pm_notify+0x38/0x64 cpu_pm_exit+0x20/0x2c psci_enter_idle_state+0x48/0x70 cpuidle_enter_state+0xb8/0x260 cpuidle_enter+0x44/0x5c do_idle+0x188/0x30c Acked-by: Mark Rutland Reviewed-by: Stephen Boyd Signed-off-by: Douglas Anderson Acked-by: Sumit Garg --- Changes in v11: - Updated commit message as per Stephen. Changes in v9: - Added to commit message that this doesn't catch all cases. Changes in v8: - "Tag the arm64 idle functions as __cpuidle" new for v8 arch/arm64/kernel/idle.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kernel/idle.c b/arch/arm64/kernel/idle.c index c1125753fe9b..05cfb347ec26 100644 --- a/arch/arm64/kernel/idle.c +++ b/arch/arm64/kernel/idle.c @@ -20,7 +20,7 @@ * ensure that interrupts are not masked at the PMR (because the core will * not wake up if we block the wake up signal in the interrupt controller). */ -void noinstr cpu_do_idle(void) +void __cpuidle cpu_do_idle(void) { struct arm_cpuidle_irq_context context; @@ -35,7 +35,7 @@ void noinstr cpu_do_idle(void) /* * This is our default idle handler. */ -void noinstr arch_cpu_idle(void) +void __cpuidle arch_cpu_idle(void) { /* * This should do all the clock switching and wait for interrupt From patchwork Thu Aug 24 15:30:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 13364383 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 A0651C3DA6F for ; Thu, 24 Aug 2023 15:33:56 +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=1XEaipu1jWtZuGaJQIuc9JRm1yVzYPEgpDimxKvNkSQ=; b=hgphErRvr5kq+p +hzvlQGlpjl+730Ubq7QkhCUB5yxLQS6xMhAyu9noMbKJ4HPGkatjCralthmtgJlEkn2B/zEClw+i t2+xT1RNrOvBM9AmUMYJhHvoiAlUDnWPhDbORy5VT8ESTVoX7yTlqEw7M0MReyrZ5fYBWQNfPFY6J +70OB5tiKU/apS/Vmc1OCCXI7IUrRlPF9jOvbFoV4du1iwZmrj/7JtqHwKjNF8MZah4NgApzrmVPG 36edxkNCTWLPAjmzuWqkC4ba9f8XZxQAAxrsLoKwHDi22CL0eADfcuKxjSyl7QsGs11tT6EdaKxFI JBfn5qwXY7PZa6d0IrEw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qZCKm-003NM4-0f; Thu, 24 Aug 2023 15:33:20 +0000 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qZCKa-003NHV-1t for linux-arm-kernel@lists.infradead.org; Thu, 24 Aug 2023 15:33:10 +0000 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-68a529e1974so3446331b3a.3 for ; Thu, 24 Aug 2023 08:33:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1692891185; x=1693495985; 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=2aMgOf9t5wZdItqfD8SuPWRf/5pRJuQTcqZyNhidj2Y=; b=AZcePvBBhLgkuuo3km02W9zjKJl2IhG7RrpVAOMkpvOcG/2wlGtsOJ8VGUvm88K+0I ULFKV0H5DtB2Ugyi5Um/HOZQERkOQQyNxdBF88kTbiY3YXfvVrp7vkL90VTn6aa6Mfo2 6ad6p5cCSR9M5b7zvmTZ06V8Uk4jid4du5IE8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692891185; x=1693495985; 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=2aMgOf9t5wZdItqfD8SuPWRf/5pRJuQTcqZyNhidj2Y=; b=QgINYeCyTQ4m+PI6O0Fqz+6q03N/eq/mtZagiO2IQBgEwswYWiQM0k64QVk/MTahTa wlut1lLlRB3fgJe0BPu4e5Zs0px76eKRyY0w7W1xxQ6V/Z/DG5awyUbbuvLL/iGCqTQ1 BCeya5ifb6zoD1/EX7rV1r51U0fgZIGbFutn+JAjs2SsOTLWBaLIFOMydZMyi36VdNb3 b5R+wlpQGWgN3f/njY7E56VOCrYLIFvBgVKWCnc1pil6mvMuTQCAYHtngQ5fQ2qY5OWJ 8YWwryX1ibez6zAcdmWyTu/xKIip9Tuvq4zdD4YkkewWgk/y1q/aUgrrhe3Vj/fcbkOH cs9A== X-Gm-Message-State: AOJu0Yy5wCfUqBYWMwO4xawJrI/zKDd062JDNAgstxk0VMo6WgriOHBx BnBpFZxUDFMjYfDMD/gz/LW5mA== X-Google-Smtp-Source: AGHT+IE49YAPoY25JDom7a5S38XfT+jTZ7unVGsTuJC6+qpZJdGADROO+tI9gqgujK1/LGuMovHWQg== X-Received: by 2002:a05:6a20:7354:b0:140:3775:3086 with SMTP id v20-20020a056a20735400b0014037753086mr14235980pzc.59.1692891185652; Thu, 24 Aug 2023 08:33:05 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:9d:2:afa3:fcf5:1b7f:f7e2]) by smtp.gmail.com with ESMTPSA id m30-20020a63711e000000b0056365ee8603sm11631337pgc.67.2023.08.24.08.33.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Aug 2023 08:33:05 -0700 (PDT) From: Douglas Anderson To: Mark Rutland , Catalin Marinas , Will Deacon , Sumit Garg , Daniel Thompson , Marc Zyngier Cc: "Rafael J . Wysocki" , Ard Biesheuvel , Thomas Gleixner , kgdb-bugreport@lists.sourceforge.net, Lecopzer Chen , linux-perf-users@vger.kernel.org, Masayoshi Mizuma , Chen-Yu Tsai , linux-arm-kernel@lists.infradead.org, ito-yuichi@fujitsu.com, Stephen Boyd , Peter Zijlstra , Douglas Anderson , D Scott Phillips , Josh Poimboeuf , Kees Cook , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Sami Tolvanen , Valentin Schneider , linux-kernel@vger.kernel.org Subject: [PATCH v11 3/6] arm64: smp: Remove dedicated wakeup IPI Date: Thu, 24 Aug 2023 08:30:29 -0700 Message-ID: <20230824083012.v11.3.I7209db47ef8ec151d3de61f59005bbc59fe8f113@changeid> X-Mailer: git-send-email 2.42.0.rc1.204.g551eb34607-goog In-Reply-To: <20230824153233.1006420-1-dianders@chromium.org> References: <20230824153233.1006420-1-dianders@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230824_083308_626382_9AE7B7B4 X-CRM114-Status: GOOD ( 21.79 ) 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: Mark Rutland To enable NMI backtrace and KGDB's NMI cpu roundup, we need to free up at least one dedicated IPI. On arm64 the IPI_WAKEUP IPI is only used for the ACPI parking protocol, which itself is only used on some very early ARMv8 systems which couldn't implement PSCI. Remove the IPI_WAKEUP IPI, and rely on the IPI_RESCHEDULE IPI to wake CPUs from the parked state. This will cause a tiny amonut of redundant work to check the thread flags, but this is miniscule in relation to the cost of taking and handling the IPI in the first place. We can safely handle redundant IPI_RESCHEDULE IPIs, so there should be no functional impact as a result of this change. Signed-off-by: Mark Rutland Signed-off-by: Douglas Anderson Cc: Catalin Marinas Cc: Marc Zyngier Cc: Sumit Garg Cc: Will Deacon Reviewed-by: Stephen Boyd Reviewed-by: Sumit Garg --- I have no idea how to test this. I just took Mark's patch and jammed it into my series. Logicially the patch seems reasonable to me. Changes in v11: - arch_send_wakeup_ipi() now takes an unsigned int. Changes in v10: - ("arm64: smp: Remove dedicated wakeup IPI") new for v10. arch/arm64/include/asm/smp.h | 4 ++-- arch/arm64/kernel/acpi_parking_protocol.c | 2 +- arch/arm64/kernel/smp.c | 28 +++++++++-------------- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/arch/arm64/include/asm/smp.h b/arch/arm64/include/asm/smp.h index 9b31e6d0da17..efb13112b408 100644 --- a/arch/arm64/include/asm/smp.h +++ b/arch/arm64/include/asm/smp.h @@ -89,9 +89,9 @@ extern void arch_send_call_function_single_ipi(int cpu); extern void arch_send_call_function_ipi_mask(const struct cpumask *mask); #ifdef CONFIG_ARM64_ACPI_PARKING_PROTOCOL -extern void arch_send_wakeup_ipi_mask(const struct cpumask *mask); +extern void arch_send_wakeup_ipi(unsigned int cpu); #else -static inline void arch_send_wakeup_ipi_mask(const struct cpumask *mask) +static inline void arch_send_wakeup_ipi(unsigned int cpu) { BUILD_BUG(); } diff --git a/arch/arm64/kernel/acpi_parking_protocol.c b/arch/arm64/kernel/acpi_parking_protocol.c index b1990e38aed0..e1be29e608b7 100644 --- a/arch/arm64/kernel/acpi_parking_protocol.c +++ b/arch/arm64/kernel/acpi_parking_protocol.c @@ -103,7 +103,7 @@ static int acpi_parking_protocol_cpu_boot(unsigned int cpu) &mailbox->entry_point); writel_relaxed(cpu_entry->gic_cpu_id, &mailbox->cpu_id); - arch_send_wakeup_ipi_mask(cpumask_of(cpu)); + arch_send_wakeup_ipi(cpu); return 0; } diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c index 960b98b43506..a5848f1ef817 100644 --- a/arch/arm64/kernel/smp.c +++ b/arch/arm64/kernel/smp.c @@ -72,7 +72,6 @@ enum ipi_msg_type { IPI_CPU_CRASH_STOP, IPI_TIMER, IPI_IRQ_WORK, - IPI_WAKEUP, NR_IPI }; @@ -764,7 +763,6 @@ static const char *ipi_types[NR_IPI] __tracepoint_string = { [IPI_CPU_CRASH_STOP] = "CPU stop (for crash dump) interrupts", [IPI_TIMER] = "Timer broadcast interrupts", [IPI_IRQ_WORK] = "IRQ work interrupts", - [IPI_WAKEUP] = "CPU wake-up interrupts", }; static void smp_cross_call(const struct cpumask *target, unsigned int ipinr); @@ -797,13 +795,6 @@ void arch_send_call_function_single_ipi(int cpu) smp_cross_call(cpumask_of(cpu), IPI_CALL_FUNC); } -#ifdef CONFIG_ARM64_ACPI_PARKING_PROTOCOL -void arch_send_wakeup_ipi_mask(const struct cpumask *mask) -{ - smp_cross_call(mask, IPI_WAKEUP); -} -#endif - #ifdef CONFIG_IRQ_WORK void arch_irq_work_raise(void) { @@ -897,14 +888,6 @@ static void do_handle_IPI(int ipinr) break; #endif -#ifdef CONFIG_ARM64_ACPI_PARKING_PROTOCOL - case IPI_WAKEUP: - WARN_ONCE(!acpi_parking_protocol_valid(cpu), - "CPU%u: Wake-up IPI outside the ACPI parking protocol\n", - cpu); - break; -#endif - default: pr_crit("CPU%u: Unknown IPI message 0x%x\n", cpu, ipinr); break; @@ -979,6 +962,17 @@ void arch_smp_send_reschedule(int cpu) smp_cross_call(cpumask_of(cpu), IPI_RESCHEDULE); } +#ifdef CONFIG_ARM64_ACPI_PARKING_PROTOCOL +void arch_send_wakeup_ipi(unsigned int cpu) +{ + /* + * We use a scheduler IPI to wake the CPU as this avoids the need for a + * dedicated IPI and we can safely handle spurious scheduler IPIs. + */ + arch_smp_send_reschedule(cpu); +} +#endif + #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST void tick_broadcast(const struct cpumask *mask) { From patchwork Thu Aug 24 15:30:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 13364382 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 40DC0C7EE2C for ; Thu, 24 Aug 2023 15:33:50 +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=3D6OMfH98H9wdw1rtK2fxX8fWpcfSZgcJV0f6Lb2HxM=; b=3LxwtPrhKCmjIh KQOIdq7+b7bo3+z/xC9VJWPONPSFhkqhM4tb8b/GHuWMlOg4DC+a+Rb0Kw1PaZ5KA1pCgvgLvkAHo q7SJ3VE8mtXBPsOzGag2SfL1s15sfHInhcgIpxgUqUysGN1W+y6ma59I7mM+R2de7t0oMLeK9DSZw yRU5WjdXJCWwOubIbC27gz1CXputIQVNj9tWXqiqgQdJjiH5Wlrlmstiso9Hu0EMcdVRWi7zu7zJb YIre5OSD0gzCWxusMahdGLkVLqdbgijrmK5Re61i4+CgzBH6mC7ttLJ2c5k1DVi/y/kAr3FvZDzC+ FVYt/pKXN4qfLfDiO+GA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qZCKm-003NMb-2S; Thu, 24 Aug 2023 15:33:20 +0000 Received: from mail-oi1-x22d.google.com ([2607:f8b0:4864:20::22d]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qZCKc-003NIZ-0I for linux-arm-kernel@lists.infradead.org; Thu, 24 Aug 2023 15:33:12 +0000 Received: by mail-oi1-x22d.google.com with SMTP id 5614622812f47-3a412653335so5050211b6e.1 for ; Thu, 24 Aug 2023 08:33:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1692891188; x=1693495988; 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=T9bVyGzTH2zmR0WPmuHA6a+YW0a3OEEqHcUXZPEfFW0=; b=ntnbrUTRct0Yxi4YCkMx7kj2ghFSLE7fgcjgZVQbVU7WAl+4rynlWJzEse/LIKmhFr g/EQvsC4XMZojs3+UnMW7ceP0Yiw5Yg9jXZh6pX66ukm1uKuQiSohpCSn0rgtaFBbr8G DCjJZW8Z2aXewsz/BkmhFRRxrbzHVKqvcI0RA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692891188; x=1693495988; 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=T9bVyGzTH2zmR0WPmuHA6a+YW0a3OEEqHcUXZPEfFW0=; b=D3G2YEqiYza3fyZLru6nNww+EVGK0OuHXtloq1nG8GJo5/4E0BCoN6TRNkcJpsinHO WiBcvIr3sGkVUcDbTisK2hMh43LxGY4l26stkVJ1wT/FJuAPOQF7cP/mUoKP70DtzzwB uuh/8783UZL4A352R/YQIOENjqaYiREoPfrIkmkjnG5DtPfiG3A15OK4YLqlBD9mOPmV fIGhFE2Cp5p5UlPzkJeI739T8/NuFkpTjHUzhfE2SaJjVArueR2OedWQX1pcXFaXEUvF T9jG/7G79IAfWjwexOOIWHL4X3ypCdir0TCUQd+MlrzWIpZHYVAVIvjnt7OAv7p37wH8 hvJQ== X-Gm-Message-State: AOJu0YxB7MKVQ50Y4+DZ1DvWHzRtBtCOyXIdpaM3+CZ7dAL1vR6852cJ SQsrV8G55T+Hdb5xQnELTgCPWQ== X-Google-Smtp-Source: AGHT+IEvJ4H0vINg/6XE+RVOX5JgXx5/xrn+YtCi8eZp4rHBsIvH9UestC6Ui9GwBkNR+4c1v0L4cg== X-Received: by 2002:a05:6808:1a06:b0:3a7:5d6e:dce9 with SMTP id bk6-20020a0568081a0600b003a75d6edce9mr79504oib.23.1692891187929; Thu, 24 Aug 2023 08:33:07 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:9d:2:afa3:fcf5:1b7f:f7e2]) by smtp.gmail.com with ESMTPSA id m30-20020a63711e000000b0056365ee8603sm11631337pgc.67.2023.08.24.08.33.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Aug 2023 08:33:07 -0700 (PDT) From: Douglas Anderson To: Mark Rutland , Catalin Marinas , Will Deacon , Sumit Garg , Daniel Thompson , Marc Zyngier Cc: "Rafael J . Wysocki" , Ard Biesheuvel , Thomas Gleixner , kgdb-bugreport@lists.sourceforge.net, Lecopzer Chen , linux-perf-users@vger.kernel.org, Masayoshi Mizuma , Chen-Yu Tsai , linux-arm-kernel@lists.infradead.org, ito-yuichi@fujitsu.com, Stephen Boyd , Peter Zijlstra , Douglas Anderson , D Scott Phillips , Ingo Molnar , Josh Poimboeuf , Valentin Schneider , linux-kernel@vger.kernel.org Subject: [PATCH v11 4/6] arm64: smp: Add arch support for backtrace using pseudo-NMI Date: Thu, 24 Aug 2023 08:30:30 -0700 Message-ID: <20230824083012.v11.4.Ie6c132b96ebbbcddbf6954b9469ed40a6960343c@changeid> X-Mailer: git-send-email 2.42.0.rc1.204.g551eb34607-goog In-Reply-To: <20230824153233.1006420-1-dianders@chromium.org> References: <20230824153233.1006420-1-dianders@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230824_083310_177672_C05E651F X-CRM114-Status: GOOD ( 28.30 ) 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 Enable arch_trigger_cpumask_backtrace() support on arm64. This enables things much like they are enabled on arm32 (including some of the funky logic around NR_IPI, nr_ipi, and MAX_IPI) but with the difference that, unlike arm32, we'll try to enable the backtrace to use pseudo-NMI. NOTE: this patch is a squash of the little bit of code adding the ability to mark an IPI to try to use pseudo-NMI plus the little bit of code to hook things up for kgdb. This approach was decided upon in the discussion of v9 [1]. This patch depends on commit 36759e343ff9 ("nmi_backtrace: allow excluding an arbitrary CPU") since that commit changed the prototype of arch_trigger_cpumask_backtrace(), which this patch implements. [1] https://lore.kernel.org/r/ZORY51mF4alI41G1@FVFF77S0Q05N Co-developed-by: Sumit Garg Signed-off-by: Sumit Garg Co-developed-by: Mark Rutland Signed-off-by: Mark Rutland Signed-off-by: Douglas Anderson Reviewed-by: Stephen Boyd --- Changes in v11: - Adjust comment about NR_IPI/MAX_IPI. - Don't use confusing "backed by" idiom in comment. - Made arm64_backtrace_ipi() static. Changes in v10: - Backtrace now directly supported in smp.c - Squash backtrace into patch adding support for pseudo-NMI IPIs. Changes in v9: - Added comments that we might not be using NMI always. - 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. - arch_trigger_cpumask_backtrace() no longer returns bool Changes in v8: - Removed "#ifdef CONFIG_SMP" since arm64 is always SMP - debug_ipi_setup() and debug_ipi_teardown() no longer take cpu param arch/arm64/include/asm/irq.h | 3 ++ arch/arm64/kernel/smp.c | 86 +++++++++++++++++++++++++++++++----- 2 files changed, 78 insertions(+), 11 deletions(-) diff --git a/arch/arm64/include/asm/irq.h b/arch/arm64/include/asm/irq.h index fac08e18bcd5..50ce8b697ff3 100644 --- a/arch/arm64/include/asm/irq.h +++ b/arch/arm64/include/asm/irq.h @@ -6,6 +6,9 @@ #include +void arch_trigger_cpumask_backtrace(const cpumask_t *mask, int exclude_cpu); +#define arch_trigger_cpumask_backtrace arch_trigger_cpumask_backtrace + struct pt_regs; int set_handle_irq(void (*handle_irq)(struct pt_regs *)); diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c index a5848f1ef817..c8896cbc5327 100644 --- a/arch/arm64/kernel/smp.c +++ b/arch/arm64/kernel/smp.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -72,12 +73,18 @@ enum ipi_msg_type { IPI_CPU_CRASH_STOP, IPI_TIMER, IPI_IRQ_WORK, - NR_IPI + NR_IPI, + /* + * Any enum >= NR_IPI and < MAX_IPI is special and not tracable + * with trace_ipi_* + */ + IPI_CPU_BACKTRACE = NR_IPI, + MAX_IPI }; static int ipi_irq_base __read_mostly; static int nr_ipi __read_mostly = NR_IPI; -static struct irq_desc *ipi_desc[NR_IPI] __read_mostly; +static struct irq_desc *ipi_desc[MAX_IPI] __read_mostly; static void ipi_setup(int cpu); @@ -845,6 +852,22 @@ static void __noreturn ipi_cpu_crash_stop(unsigned int cpu, struct pt_regs *regs #endif } +static void arm64_backtrace_ipi(cpumask_t *mask) +{ + __ipi_send_mask(ipi_desc[IPI_CPU_BACKTRACE], mask); +} + +void arch_trigger_cpumask_backtrace(const cpumask_t *mask, int exclude_cpu) +{ + /* + * NOTE: though nmi_trigger_cpumask_backtrace has "nmi_" in the name, + * nothing about it truly needs to be implemented using an NMI, it's + * just that it's _allowed_ to work with NMIs. If ipi_should_be_nmi() + * returned false our backtrace attempt will just use a regular IPI. + */ + nmi_trigger_cpumask_backtrace(mask, exclude_cpu, arm64_backtrace_ipi); +} + /* * Main handler for inter-processor interrupts */ @@ -888,6 +911,14 @@ static void do_handle_IPI(int ipinr) break; #endif + case IPI_CPU_BACKTRACE: + /* + * NOTE: in some cases this _won't_ be NMI context. See the + * comment in arch_trigger_cpumask_backtrace(). + */ + nmi_cpu_backtrace(get_irq_regs()); + break; + default: pr_crit("CPU%u: Unknown IPI message 0x%x\n", cpu, ipinr); break; @@ -909,6 +940,19 @@ static void smp_cross_call(const struct cpumask *target, unsigned int ipinr) __ipi_send_mask(ipi_desc[ipinr], target); } +static bool ipi_should_be_nmi(enum ipi_msg_type ipi) +{ + if (!system_uses_irq_prio_masking()) + return false; + + switch (ipi) { + case IPI_CPU_BACKTRACE: + return true; + default: + return false; + } +} + static void ipi_setup(int cpu) { int i; @@ -916,8 +960,14 @@ static void ipi_setup(int cpu) if (WARN_ON_ONCE(!ipi_irq_base)) return; - for (i = 0; i < nr_ipi; i++) - enable_percpu_irq(ipi_irq_base + i, 0); + for (i = 0; i < nr_ipi; i++) { + if (ipi_should_be_nmi(i)) { + prepare_percpu_nmi(ipi_irq_base + i); + enable_percpu_nmi(ipi_irq_base + i, 0); + } else { + enable_percpu_irq(ipi_irq_base + i, 0); + } + } } #ifdef CONFIG_HOTPLUG_CPU @@ -928,8 +978,14 @@ static void ipi_teardown(int cpu) if (WARN_ON_ONCE(!ipi_irq_base)) return; - for (i = 0; i < nr_ipi; i++) - disable_percpu_irq(ipi_irq_base + i); + for (i = 0; i < nr_ipi; i++) { + if (ipi_should_be_nmi(i)) { + disable_percpu_nmi(ipi_irq_base + i); + teardown_percpu_nmi(ipi_irq_base + i); + } else { + disable_percpu_irq(ipi_irq_base + i); + } + } } #endif @@ -937,15 +993,23 @@ void __init set_smp_ipi_range(int ipi_base, int n) { int i; - WARN_ON(n < NR_IPI); - nr_ipi = min(n, NR_IPI); + WARN_ON(n < MAX_IPI); + nr_ipi = min(n, MAX_IPI); for (i = 0; i < nr_ipi; i++) { int err; - err = request_percpu_irq(ipi_base + i, ipi_handler, - "IPI", &cpu_number); - WARN_ON(err); + if (ipi_should_be_nmi(i)) { + err = request_percpu_nmi(ipi_base + i, ipi_handler, + "IPI", &cpu_number); + WARN(err, "Could not request IPI %d as NMI, err=%d\n", + i, err); + } else { + err = request_percpu_irq(ipi_base + i, ipi_handler, + "IPI", &cpu_number); + WARN(err, "Could not request IPI %d as IRQ, err=%d\n", + i, err); + } ipi_desc[i] = irq_to_desc(ipi_base + i); irq_set_status_flags(ipi_base + i, IRQ_HIDDEN); From patchwork Thu Aug 24 15:30:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 13364384 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 161C8C27C40 for ; Thu, 24 Aug 2023 15:34:01 +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=6ThHziErb1TppdqzpbAY8pgOD5snKnMO3jC06ixV478=; b=bRvLpHQiEd42jz E6XH70Nu7nMc93qJlEyxaBLVpwQKD+QIpQkBZZ0pMjtbVpPTf9r/N6tLZKbyVp9usRxxGV7eVkuC6 F+aW2vyS8xfrU+V2lztRHtv+fJNx2oMdBdWUDQUw0PJp2AkACqCCJ45hi1WYsPjwXsLYt9HYpAEYv 2HbHnw/sd5ay5LY12kyQ5XXq42obzl/15IxjxBqTuIuGW7fBLaEbBN3NwrKYqeKn7L8e9CTVWt92B Wv7psxfeDkyJa6qYmfl1zL1gGdwm0smGfWJwoETooxOuA413DB72zynUUtPkobTZ/R/4i67IA27Z4 xJaD8dFWrdWIBF2eUNTA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qZCKn-003NN3-17; Thu, 24 Aug 2023 15:33:21 +0000 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qZCKe-003NJo-0y for linux-arm-kernel@lists.infradead.org; Thu, 24 Aug 2023 15:33:13 +0000 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-68a402c1fcdso3409091b3a.1 for ; Thu, 24 Aug 2023 08:33:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1692891190; x=1693495990; 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=+U+ZFko4eaNVS/k5E5YRzxI9X7/KmekX/8rZmWNkCMw=; b=cS5jIetqAgvoNwttMKW4WTIdVltP+nOpZ6stPUmuzAoBmw/eX/rT/dZLOJ/PnUdndx 3mg0vSOMLBUhFA54TJJKRCLbXxOTgJJLu2+gL3A90a8w+BPukvfIq7bN6HtW0VmGnhFw 6NSUkj9cgyvYTfuGsfZ/V/hb/l98o3t6zQmQI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692891190; x=1693495990; 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=+U+ZFko4eaNVS/k5E5YRzxI9X7/KmekX/8rZmWNkCMw=; b=Sp/ezyB1pAp3S5CsMK4arQ0x9HWSUC9tA6JrkGaJ+Lks4wqWYcRfOwG4mHTmMBgAXU XpuJcLZsj8a89hBP4p/FvCOlZ5g9qsIlN0jJ6utVPgBD+RsKcJfDCKUQcZ21vLRXK/Bg 21pApTrv17W2d0rqidjV4kpv03zcdOxkudITJnauUjWiqqiA6IubUbwMflSAckx1KFOS B6YTBmmwbp00fN82sLXED4dFP+alJknJZOIUV5BEaXcWj4SuWRDovV9S5G7ePwfnq4pG p4u5VQKKiXVbOJcj57ZCI5jicbNa6eSA2u4EKkR6PFhuDXrmAfX6tHHl/EGNWZXgxxwC u48Q== X-Gm-Message-State: AOJu0YzKe6faGt0NLOUf5BlLWaz5MxfEgTKa/gmvFoCV0xg9a9cfakvx KSDlb2XyX2d3Vov8Zs/ra1S46A== X-Google-Smtp-Source: AGHT+IHaSpjbeAQ9UzHqXXC2nf4Z9xB3fbVm9xxQZ6RsAAdQhINpMo2utUL4uLzKK7MxM211qE78FA== X-Received: by 2002:a05:6a00:124b:b0:68a:582b:44c4 with SMTP id u11-20020a056a00124b00b0068a582b44c4mr9603241pfi.3.1692891190414; Thu, 24 Aug 2023 08:33:10 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:9d:2:afa3:fcf5:1b7f:f7e2]) by smtp.gmail.com with ESMTPSA id m30-20020a63711e000000b0056365ee8603sm11631337pgc.67.2023.08.24.08.33.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Aug 2023 08:33:09 -0700 (PDT) From: Douglas Anderson To: Mark Rutland , Catalin Marinas , Will Deacon , Sumit Garg , Daniel Thompson , Marc Zyngier Cc: "Rafael J . Wysocki" , Ard Biesheuvel , Thomas Gleixner , kgdb-bugreport@lists.sourceforge.net, Lecopzer Chen , linux-perf-users@vger.kernel.org, Masayoshi Mizuma , Chen-Yu Tsai , linux-arm-kernel@lists.infradead.org, ito-yuichi@fujitsu.com, Stephen Boyd , Peter Zijlstra , Douglas Anderson , D Scott Phillips , Ingo Molnar , Josh Poimboeuf , Valentin Schneider , linux-kernel@vger.kernel.org Subject: [PATCH v11 5/6] arm64: smp: IPI_CPU_STOP and IPI_CPU_CRASH_STOP should try for NMI Date: Thu, 24 Aug 2023 08:30:31 -0700 Message-ID: <20230824083012.v11.5.Ifadbfd45b22c52edcb499034dd4783d096343260@changeid> X-Mailer: git-send-email 2.42.0.rc1.204.g551eb34607-goog In-Reply-To: <20230824153233.1006420-1-dianders@chromium.org> References: <20230824153233.1006420-1-dianders@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230824_083312_374774_4E2E0B3E X-CRM114-Status: GOOD ( 12.52 ) 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 There's no reason why IPI_CPU_STOP and IPI_CPU_CRASH_STOP can't be handled as NMI. They are very simple and everything in them is NMI-safe. Mark them as things to use NMI for if NMI is available. Suggested-by: Mark Rutland Reviewed-by: Stephen Boyd Signed-off-by: Douglas Anderson Reviewed-by: Sumit Garg --- I don't actually have any good way to test/validate this patch. It's added to the series at Mark's request. (no changes since v10) Changes in v10: - ("IPI_CPU_STOP and IPI_CPU_CRASH_STOP should try for NMI") new for v10. arch/arm64/kernel/smp.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c index c8896cbc5327..4566934aaf9f 100644 --- a/arch/arm64/kernel/smp.c +++ b/arch/arm64/kernel/smp.c @@ -946,6 +946,8 @@ static bool ipi_should_be_nmi(enum ipi_msg_type ipi) return false; switch (ipi) { + case IPI_CPU_STOP: + case IPI_CPU_CRASH_STOP: case IPI_CPU_BACKTRACE: return true; default: From patchwork Thu Aug 24 15:30:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 13364381 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 71D4CC27C40 for ; Thu, 24 Aug 2023 15:33:49 +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=8ETbjvK8vQWz/XpdvzTd0hmtHuSI9igzN1u7sIg4BFQ=; b=Ol5Mn65bwfmeMp thQna35peibplS8zKdAsTK1GsYbPZkvviJEq2qbzu9MEX9xOW+oDCMbR5LOxmwj4X6Ie7UfOqAJMf 4PE0Oip9QS1SHYF4s1IDT6DJLVXWngo9hd/kiMkpyttVO5Bk67CjxIqrNmlZKgO1lfPXS8cwSZx+u QMKVUAjfTTQ3xyLlqmQgkZwIfuCCxYeV1oQ0fa/wH/+J79LF15gwe1pv/Mu7RcZWeyFg9ug61qd62 ZsJ5B9ZYvg20cRfM/DbBodkScyi4u1CryATRW/St84e+18398w2Uhog3E1380v9bbxLhw9UPj2MFx hoSPfIxm9GycY8FmgBfw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qZCKn-003NNW-2l; Thu, 24 Aug 2023 15:33:21 +0000 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qZCKf-003NKF-0p for linux-arm-kernel@lists.infradead.org; Thu, 24 Aug 2023 15:33:14 +0000 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-68bec3a81c4so3278b3a.1 for ; Thu, 24 Aug 2023 08:33:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1692891193; x=1693495993; 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=PpvKkEI/e7qDOTO7kkwnbGAWQL/h1j/QJekiYZuCdi8=; b=Eqf7ZSxJom24lSCPPItZp0Jzzsgydj3wjWNxBG8UNQBsegWpHjaQtL61A3HiBfuCSo J6ml8OZW3onJcqmoTMruSdhqZm2KlF9FZfDEflnZQcMt0G9ngDavylngBuvI7gJwipef +GFSyITHnIR+HkAukdoTDl81UHsm3QEZjrhug= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692891193; x=1693495993; 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=PpvKkEI/e7qDOTO7kkwnbGAWQL/h1j/QJekiYZuCdi8=; b=kGE4pjEor0SkmiUEK/QpXHSnDfkDKdIjjT/M7aiO0pljpxuVdsL3CaK2kQob+cIv0T cUeL1q/esfs4aCLnptkC1klMW54k8aR9qTrmmKi/BaRLj5heZI2OAmnqmNFTYvtgrmjV NjWZAPVD8iTHqACsFzkqDV+CuDr0qdOpTvR5sRm68Ywyb3bEl8j97VqB7iwUZmfD8Iea MwS0kB2AWcmKrYXrb1QE8iLT5mP7Jq0c+i44rZfu+iZU0YnrFGaNRmR4ME/5/M5CqATk JK4zb6998vEmOWjqZ0XqfKklQ0C9cU2RRWLAyMhZ04zjWYIppdmZq6gqy0N5FhbtmqDl B1AQ== X-Gm-Message-State: AOJu0YyFn6w2S14gNpZcy5atT2jFsESPghD8KAow+OfVfTrWrjw5IyBU m5ao/BsJTIOzP14Ech1QNhrfQQ== X-Google-Smtp-Source: AGHT+IH3Wlo4UhfEjU/WdEk/Y/44LnzFs3Gaq+1amqWxjKrBJ8EosqQauQzhM/dQC7jvUfImtbjO5A== X-Received: by 2002:a05:6a00:ccd:b0:68a:45a1:c0f7 with SMTP id b13-20020a056a000ccd00b0068a45a1c0f7mr20902029pfv.8.1692891192681; Thu, 24 Aug 2023 08:33:12 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:9d:2:afa3:fcf5:1b7f:f7e2]) by smtp.gmail.com with ESMTPSA id m30-20020a63711e000000b0056365ee8603sm11631337pgc.67.2023.08.24.08.33.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Aug 2023 08:33:12 -0700 (PDT) From: Douglas Anderson To: Mark Rutland , Catalin Marinas , Will Deacon , Sumit Garg , Daniel Thompson , Marc Zyngier Cc: "Rafael J . Wysocki" , Ard Biesheuvel , Thomas Gleixner , kgdb-bugreport@lists.sourceforge.net, Lecopzer Chen , linux-perf-users@vger.kernel.org, Masayoshi Mizuma , Chen-Yu Tsai , linux-arm-kernel@lists.infradead.org, ito-yuichi@fujitsu.com, Stephen Boyd , Peter Zijlstra , Douglas Anderson , D Scott Phillips , Josh Poimboeuf , Valentin Schneider , linux-kernel@vger.kernel.org Subject: [PATCH v11 6/6] arm64: kgdb: Implement kgdb_roundup_cpus() to enable pseudo-NMI roundup Date: Thu, 24 Aug 2023 08:30:32 -0700 Message-ID: <20230824083012.v11.6.I2ef26d1b3bfbed2d10a281942b0da7d9854de05e@changeid> X-Mailer: git-send-email 2.42.0.rc1.204.g551eb34607-goog In-Reply-To: <20230824153233.1006420-1-dianders@chromium.org> References: <20230824153233.1006420-1-dianders@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230824_083313_291772_DF656BCA X-CRM114-Status: GOOD ( 22.96 ) 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 Up until now we've been using the generic (weak) implementation for kgdb_roundup_cpus() when using kgdb on arm64. Let's move to a custom one. The advantage here is that, when pseudo-NMI is enabled on a device, we'll be able to round up CPUs using pseudo-NMI. This allows us to debug CPUs that are stuck with interrupts disabled. If pseudo-NMIs are not enabled then we'll fallback to just using an IPI, which is still slightly better than the generic implementation since it avoids the potential situation described in the generic kgdb_call_nmi_hook(). Co-developed-by: Sumit Garg Signed-off-by: Sumit Garg Signed-off-by: Douglas Anderson Reviewed-by: Daniel Thompson Reviewed-by: Stephen Boyd --- I debated whether this should be in "arch/arm64/kernel/smp.c" or if I should try to find a way for it to go into "arch/arm64/kernel/kgdb.c". In the end this is so little code that it didn't seem worth it to find a way to export the IPI defines or to otherwise come up with some API between kgdb.c and smp.c. If someone has strong feelings and wants this to change, please shout and give details of your preferred solution. FWIW, it seems like ~half the other platforms put this in "smp.c" with an ifdef for KGDB and the other half put it in "kgdb.c" with an ifdef for SMP. :-P (no changes since v10) Changes in v10: - Don't allocate the cpumask on the stack; just iterate. - Moved kgdb calls to smp.c to avoid needing to export IPI info. - kgdb now has its own IPI. Changes in v9: - Remove fallback for when debug IPI isn't available. - Renamed "NMI IPI" to "debug IPI" since it might not be backed by NMI. arch/arm64/kernel/smp.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c index 4566934aaf9f..d440c8b21ea7 100644 --- a/arch/arm64/kernel/smp.c +++ b/arch/arm64/kernel/smp.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -79,6 +80,7 @@ enum ipi_msg_type { * with trace_ipi_* */ IPI_CPU_BACKTRACE = NR_IPI, + IPI_KGDB_ROUNDUP, MAX_IPI }; @@ -868,6 +870,22 @@ void arch_trigger_cpumask_backtrace(const cpumask_t *mask, int exclude_cpu) nmi_trigger_cpumask_backtrace(mask, exclude_cpu, arm64_backtrace_ipi); } +#ifdef CONFIG_KGDB +void kgdb_roundup_cpus(void) +{ + int this_cpu = raw_smp_processor_id(); + int cpu; + + for_each_online_cpu(cpu) { + /* No need to roundup ourselves */ + if (cpu == this_cpu) + continue; + + __ipi_send_single(ipi_desc[IPI_KGDB_ROUNDUP], cpu); + } +} +#endif + /* * Main handler for inter-processor interrupts */ @@ -919,6 +937,10 @@ static void do_handle_IPI(int ipinr) nmi_cpu_backtrace(get_irq_regs()); break; + case IPI_KGDB_ROUNDUP: + kgdb_nmicallback(cpu, get_irq_regs()); + break; + default: pr_crit("CPU%u: Unknown IPI message 0x%x\n", cpu, ipinr); break; @@ -949,6 +971,7 @@ static bool ipi_should_be_nmi(enum ipi_msg_type ipi) case IPI_CPU_STOP: case IPI_CPU_CRASH_STOP: case IPI_CPU_BACKTRACE: + case IPI_KGDB_ROUNDUP: return true; default: return false;