From patchwork Wed Apr 22 14:35:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 185697 Delivered-To: patches@linaro.org Received: by 2002:a92:3d9a:0:0:0:0:0 with SMTP id k26csp833816ilf; Wed, 22 Apr 2020 07:36:04 -0700 (PDT) X-Received: by 2002:a9d:6302:: with SMTP id q2mr6943307otk.181.1587566164362; Wed, 22 Apr 2020 07:36:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587566164; cv=none; d=google.com; s=arc-20160816; b=wiF7wnIiXJbaLPeMKUJiGc4NxM1HqeD06n+G/ktF+3TEU6YkJ961f4v4ZME+0tC1C8 cixDT9zf2lbeaO+XTdWL/M130J+8udvveO9rX9nRHlqZ0EW4JPGyp7j4tljhr4M3qWqQ HLOQcCIYzELOxGIdQeBs1ca6igSlgNJgGpaUOOeh/ADsenCGMtbSf7qMhZrjHpetrThu NCldZTCyqimNz/eN8Tv15VR7UFo7w7AM54iUskXYEavhnKVZgqLQCnAPyD2Y51i3rsfb KR0xxswNNnMxrfxMsA568X2ZXnSV+kqx5OLxFFssXvMyPjkvdZx9Lj0fzgIPZD3u8F3B CowA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=tC4rQoO7pOMrbHgj3hoz18UuBgFHtPdML5UTOcQ928s=; b=yAf6bE87UR/GG8mPKQOhdUyeC6wGzkaw/6ifM8EYR+Q0wgz9uuB5Gw/zUSgJ1X9hxT COUH460rax6fZOnuOkcoo3Tcmgw4d7M46QW3h+zuZCyN+1JNHaOfIEiGt1U4V9DXkxu0 wbonbpIMG33mk/kP1mbZQ9Htvuc9WpFsz+0/FKscMI7Qwon7ky8cSKGvTLPXQYVd2jbv KMiVpNglADxmFfAbDuvxlMUhSQ7WNeDwB8WioyToJGtW3cYFx1mrVJpkCtns0SliIFG9 yF427fUGgV6uvnSQVmib3AKGPWZSJsme9iXHgXCt7PFe47AOLNerK9iYjyHd6e6hUvmD LlVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Rv94Azr6; spf=pass (google.com: domain of sumit.garg@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=sumit.garg@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id p2sor4649513otq.52.2020.04.22.07.36.04 for (Google Transport Security); Wed, 22 Apr 2020 07:36:04 -0700 (PDT) Received-SPF: pass (google.com: domain of sumit.garg@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Rv94Azr6; spf=pass (google.com: domain of sumit.garg@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=sumit.garg@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=tC4rQoO7pOMrbHgj3hoz18UuBgFHtPdML5UTOcQ928s=; b=Rv94Azr6weHWGOFhI/CSlZZJf+ibgxneVZKMYLXDZ/hgqS1/yZSqbbs+7O6kjMFhfe R6ctPpHL+XqbQ+ebUra5iCuiYENiMUuz67nMF6O0HDxIXLHHFacbIYPTFF049Qc8lSh1 qjE2haos7NtaDV+Hd17qGXXOfshWa2XC2KB8cFnf7JQkfVLywngWLSsvkXeoXwPQ7Whr 4O8JbVqeOez+WeI8ZwC8tbHTwmx4vgCzfT8sDUfIRfF50pbId8p2pO1Q5UKZ6TqBJhki Mm2Zd/Lt6/JLcwL7s3gAPGG0bESoMjw8ktJKLEoB+gr26DFYGWJ+ij71+MkPUZAJDcqX kdlg== 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=tC4rQoO7pOMrbHgj3hoz18UuBgFHtPdML5UTOcQ928s=; b=EfsyB9NKhpoG8JNusRHv54+jUDkJXnaU0O1DvwT48CN6ghOZ0kW2mRlKJYSCxK0Yz+ yOyW+ekNcfr4yLuh6PfqJMc2+zO3fLWXl3xBngAUpY5WLCEr1XYsqvSmhuY8q0qXKcqL UVqCbJJNRqVm5UUKXwRNNGmc9B+QepD5W9hVF3H+cMY1NJK8/Ft+D5gCUEXOZfDgJ8+d 6uQ8jwO9k8zPpA8bRCjeIvkWiVsWVidiCYCf0P+iWB5WTvWygC7acqWAUQKwJevvi3/s CAULR/zrvHdA6Ba/cKIc05glrcYku87NT4NqXheU2NldcC9pscW/F9veruqwqjEXu6WM Y4qQ== X-Gm-Message-State: AGi0Pua5XpXz0Mh2HwbWH+z/KWU63VmUmNlqxGLEZ/j5/MgKVR+E3H36 QosrJb7RGp9xb5JweigoSNfcRYt8 X-Google-Smtp-Source: APiQypLH5DBE6FuhH6+JxXzLb8Tjnc+FNRFQbMIsfNJ+Yqh6YbnAGK5ivF+fkypqujhvSfzEguw8fg== X-Received: by 2002:a17:902:d716:: with SMTP id w22mr27545017ply.200.1587566163976; Wed, 22 Apr 2020 07:36:03 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([117.252.71.186]) by smtp.gmail.com with ESMTPSA id j13sm5723573pje.1.2020.04.22.07.36.00 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Apr 2020 07:36:03 -0700 (PDT) From: Sumit Garg To: daniel.thompson@linaro.org Cc: patches@linaro.org, Sumit Garg Subject: [RFC 4/4] arm64: kgdb: Round up cpus using IPI_CALL_NMI_FUNC Date: Wed, 22 Apr 2020 20:05:23 +0530 Message-Id: <1587566123-9935-5-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1587566123-9935-1-git-send-email-sumit.garg@linaro.org> References: <1587566123-9935-1-git-send-email-sumit.garg@linaro.org> arm64 platforms with GICv3 or later supports pseudo NMIs which can be leveraged to round up CPUs which are stuck in hard lockup state with interrupts disabled that wouldn't be possible with a normal IPI. So instead switch to round up CPUs using IPI_CALL_NMI_FUNC. And in case a particular arm64 platform doesn't supports pseudo NMIs, IPI_CALL_NMI_FUNC will act as a normal IPI which maintains existing kgdb functionality. Also, one thing to note here is that with CPUs running in NMI context, kernel has special handling for printk() which involves CPU specific buffers and defering printk() until exit from NMI context. But with kgdb we don't want to defer printk() especially backtrace on corresponding CPUs. So switch to normal printk() context instead prior to entering kgdb context. Signed-off-by: Sumit Garg --- arch/arm64/kernel/kgdb.c | 12 ++++++++++++ arch/arm64/kernel/smp.c | 17 ++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) -- 2.7.4 diff --git a/arch/arm64/kernel/kgdb.c b/arch/arm64/kernel/kgdb.c index 4311992..d6be647 100644 --- a/arch/arm64/kernel/kgdb.c +++ b/arch/arm64/kernel/kgdb.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -353,3 +354,14 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt) return aarch64_insn_write((void *)bpt->bpt_addr, *(u32 *)bpt->saved_instr); } + +#ifdef CONFIG_SMP +void kgdb_roundup_cpus(void) +{ + struct cpumask mask; + + cpumask_copy(&mask, cpu_online_mask); + cpumask_clear_cpu(raw_smp_processor_id(), &mask); + arch_send_call_nmi_func_ipi_mask(&mask); +} +#endif diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c index 27c8ee1..c7158f6e8 100644 --- a/arch/arm64/kernel/smp.c +++ b/arch/arm64/kernel/smp.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -976,9 +977,19 @@ void handle_IPI(int ipinr, struct pt_regs *regs) /* Handle it as a normal interrupt if not in NMI context */ if (!in_nmi()) irq_enter(); - - /* nop, IPI handlers for special features can be added here. */ - +#ifdef CONFIG_KGDB + if (atomic_read(&kgdb_active) != -1) { + /* + * For kgdb to work properly, we need printk to operate + * in normal context. + */ + if (in_nmi()) + printk_nmi_exit(); + kgdb_nmicallback(raw_smp_processor_id(), regs); + if (in_nmi()) + printk_nmi_enter(); + } +#endif if (!in_nmi()) irq_exit(); break;