Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3415831rwa; Tue, 23 Aug 2022 04:31:55 -0700 (PDT) X-Google-Smtp-Source: AA6agR50dRgVLK6bJPH3upPXNETSJCCxHg+ZMLTUbzf3UfY0Epuci47rXc3bPCK/D0yh2RSgxXnw X-Received: by 2002:a17:906:9755:b0:73d:8eb7:c3f0 with SMTP id o21-20020a170906975500b0073d8eb7c3f0mr4240634ejy.188.1661254218353; Tue, 23 Aug 2022 04:30:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661254218; cv=none; d=google.com; s=arc-20160816; b=yK/R9TcW7gjb9PpGX1pUe7BuuP3ZmVWQvEpKL/xgMhaWXZNX774t3TbUN6ELpJVZsq 5w1Lk6OoHz4o0ymCrxEp5kDCv7HHAM4uHwPQQKETbOewnHhMQXufMSHVdDAzr4wIVzDo xtP2FB+6+o3PZ0kxlfYaNNcuEmsPQCGENpoo7O2Z8XI4tl0YWwRvaTgwsKkYTtocXT0l B2ubXZnMXlgqF0ogKuldFQgRTV27BpsMuSuKDvpLQirYhqZNgSGlmwtyOXtWqY8R9kIJ PnPdG7eQ4RckaY19+MfwB8WNWOKx+tfNqFFIWh1BX7waI8UW9AOOxQ4BuuOCKY2lqw3c wghw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=SQ+/OaxZxfd6H2MTTVRUtDP3i95AO65aWV6VIGRkWNA=; b=oORHxqZ4qyrFqLLmXSNyO1j3mlVFR5wkqdHs5IU8If9jFXjGjfim+1/gi1y/gT7ByG jNPDGD6WCsAD1p9q7tymyVxa4+WYD0oyhjWfL0R5axI1Kge4uqqndsxoN+sY9siCLNDT yJmrrf4p5tTDd7tXA4tXkiAPLIy4aMnk9KNeHBPLvPylz7BjM7kN/xLGBYv7BdabFLAI YXzgh1bLBFcxbemuJQX3cJTsDk4SVDDSwLiB4UIkQqGlrbriwrcjMESaC4DWHU64/qPK rojZWHrtsbvAju2Rp2ENT/4XBFYSLMeW2ixZcDTifB2V0EExOOuOSVGcpuLtUvOvTGlQ laNg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dn4-20020a17090794c400b0073beb963ce6si12696793ejc.345.2022.08.23.04.29.51; Tue, 23 Aug 2022 04:30:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355565AbiHWKns (ORCPT + 99 others); Tue, 23 Aug 2022 06:43:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355037AbiHWKeP (ORCPT ); Tue, 23 Aug 2022 06:34:15 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51516A59B5; Tue, 23 Aug 2022 02:06:52 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A5C236156F; Tue, 23 Aug 2022 09:06:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AE9FDC433C1; Tue, 23 Aug 2022 09:06:48 +0000 (UTC) From: Huacai Chen To: Arnd Bergmann , Huacai Chen Cc: loongarch@lists.linux.dev, linux-arch@vger.kernel.org, Xuefeng Li , Guo Ren , Xuerui Wang , Jiaxun Yang , linux-kernel@vger.kernel.org, Huacai Chen Subject: [PATCH] LoongArch: Add SysRq-x (TLB Dump) support Date: Tue, 23 Aug 2022 17:06:36 +0800 Message-Id: <20220823090636.526090-1-chenhuacai@loongson.cn> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add SysRq-x (TLB Dump) support for LoongArch, which is useful for debugging. Signed-off-by: Huacai Chen --- arch/loongarch/kernel/Makefile | 2 ++ arch/loongarch/kernel/sysrq.c | 65 ++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 arch/loongarch/kernel/sysrq.c diff --git a/arch/loongarch/kernel/Makefile b/arch/loongarch/kernel/Makefile index a213e994db68..7225916dd378 100644 --- a/arch/loongarch/kernel/Makefile +++ b/arch/loongarch/kernel/Makefile @@ -23,6 +23,8 @@ obj-$(CONFIG_SMP) += smp.o obj-$(CONFIG_NUMA) += numa.o +obj-$(CONFIG_MAGIC_SYSRQ) += sysrq.o + obj-$(CONFIG_UNWINDER_GUESS) += unwind_guess.o obj-$(CONFIG_UNWINDER_PROLOGUE) += unwind_prologue.o diff --git a/arch/loongarch/kernel/sysrq.c b/arch/loongarch/kernel/sysrq.c new file mode 100644 index 000000000000..366baef72d29 --- /dev/null +++ b/arch/loongarch/kernel/sysrq.c @@ -0,0 +1,65 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * LoongArch specific sysrq operations. + * + * Copyright (C) 2020-2022 Loongson Technology Corporation Limited + */ +#include +#include +#include +#include +#include + +#include +#include + +/* + * Dump TLB entries on all CPUs. + */ + +static DEFINE_SPINLOCK(show_lock); + +static void sysrq_tlbdump_single(void *dummy) +{ + unsigned long flags; + + spin_lock_irqsave(&show_lock, flags); + + pr_info("CPU%d:\n", smp_processor_id()); + dump_tlb_regs(); + pr_info("\n"); + dump_tlb_all(); + pr_info("\n"); + + spin_unlock_irqrestore(&show_lock, flags); +} + +#ifdef CONFIG_SMP +static void sysrq_tlbdump_othercpus(struct work_struct *dummy) +{ + smp_call_function(sysrq_tlbdump_single, NULL, 0); +} + +static DECLARE_WORK(sysrq_tlbdump, sysrq_tlbdump_othercpus); +#endif + +static void sysrq_handle_tlbdump(int key) +{ + sysrq_tlbdump_single(NULL); +#ifdef CONFIG_SMP + schedule_work(&sysrq_tlbdump); +#endif +} + +static struct sysrq_key_op sysrq_tlbdump_op = { + .handler = sysrq_handle_tlbdump, + .help_msg = "show-tlbs(x)", + .action_msg = "Show TLB entries", + .enable_mask = SYSRQ_ENABLE_DUMP, +}; + +static int __init loongarch_sysrq_init(void) +{ + return register_sysrq_key('x', &sysrq_tlbdump_op); +} +arch_initcall(loongarch_sysrq_init); -- 2.31.1