From patchwork Mon May 9 17:39:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 67368 Delivered-To: patches@linaro.org Received: by 10.140.92.199 with SMTP id b65csp1712240qge; Mon, 9 May 2016 10:39:42 -0700 (PDT) X-Received: by 10.28.16.17 with SMTP id 17mr11786722wmq.17.1462815581959; Mon, 09 May 2016 10:39:41 -0700 (PDT) Return-Path: Received: from mail-wm0-x22d.google.com (mail-wm0-x22d.google.com. [2a00:1450:400c:c09::22d]) by mx.google.com with ESMTPS id a201si27138562wme.35.2016.05.09.10.39.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 May 2016 10:39:41 -0700 (PDT) Received-SPF: pass (google.com: domain of daniel.thompson@linaro.org designates 2a00:1450:400c:c09::22d as permitted sender) client-ip=2a00:1450:400c:c09::22d; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: domain of daniel.thompson@linaro.org designates 2a00:1450:400c:c09::22d as permitted sender) smtp.mailfrom=daniel.thompson@linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by mail-wm0-x22d.google.com with SMTP id a17so199956198wme.0 for ; Mon, 09 May 2016 10:39:41 -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; bh=EDUYDt7Gminp0pybeCXe+oCHVHAHjQhIWRYVc7BHsGA=; b=Fywv8uziqKtUhVNoMlLLW+6n/VwLlT5Mr1KCMse2QXLYTx4mrVS5VYpJ6sqv06W/Uo BRPtrmDas1h1oLXn5oOWcD+wV0KDHZX04kk7oMzogNw7y3WGH0p79hFK9wjWUxHBPXT0 SJ2xHSNkMBEgh01TOJcvoYfhTUA4/a+uPo0W0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=EDUYDt7Gminp0pybeCXe+oCHVHAHjQhIWRYVc7BHsGA=; b=AiRzuhQYxjgcH49LoP0F54rX0GjXwOl+w9lRNlyKVoVkKudkn6ZvjVInnknvVF9ZVE A1Gj+M0NSZNNT0XvGYKcaBKZigBD1wg72r7Zf/M902cEeW17YIQV6vyWNXcarfJcanAK KN8mj+JsNhhlV3n3e6SMn6LcdJmrhf/12ihBUPf/9cQJk1i1ORJ2JODR1dKiJVf8U+Dw e+4oQ+WP9cWQt9shUD3O+fK4KStNB4abpTPJMCawl6crRew1wgW3UfqAXID8EvYVh8F6 SOtLx+HesLCLCbwS9KNZTX4BHEu17GQbvv7kQpx+YUq8BRKakocqmLYWMoxwCufUIUru dRew== X-Gm-Message-State: AOPr4FUBJ/uv21uzvJz8q0h8uDFnAH3U4O2Kv49kVhsvP3hlLHer52YyCl+IyGc+uc1D09b1A6c= X-Received: by 10.194.139.104 with SMTP id qx8mr33745828wjb.14.1462815581612; Mon, 09 May 2016 10:39:41 -0700 (PDT) Return-Path: Received: from wychelm.lan (cpc4-aztw19-0-0-cust71.18-1.cable.virginm.net. [82.33.25.72]) by smtp.gmail.com with ESMTPSA id az2sm32354885wjc.6.2016.05.09.10.39.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 May 2016 10:39:40 -0700 (PDT) From: Daniel Thompson To: Catalin Marinas , Will Deacon Cc: Daniel Thompson , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, patches@linaro.org, linaro-kernel@lists.linaro.org, Jason Wessel , Dave P Martin , Mark Rutland , Vijaya Kumar K Subject: [PATCH] arm64: kgdb: Match pstate size with gdbserver protocol Date: Mon, 9 May 2016 18:39:26 +0100 Message-Id: <1462815566-15086-1-git-send-email-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.5.5 Current versions of gdb do not interoperate cleanly with kgdb on arm64 systems because gdb and kgdb do not use the same register description. This patch modifies kgdb to work with recent releases of gdb (>= 7.8.1). Compatibility with gdb (after the patch is applied) is as follows: gdb-7.6 and earlier Ok gdb-7.7 series Works if user provides custom target description gdb-7.8(.0) Works if user provides custom target description gdb-7.8.1 and later Ok When commit 44679a4f142b ("arm64: KGDB: Add step debugging support") was introduced it was paired with a gdb patch that made an incompatible change to the gdbserver protocol. This patch was eventually merged into the gdb sources: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=a4d9ba85ec5597a6a556afe26b712e878374b9dd The change to the protocol was mostly made to simplify big-endian support inside the kernel gdb stub. Unfortunately the gdb project released gdb-7.7.x and gdb-7.8.0 before the protocol incompatibility was identified and reversed: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=bdc144174bcb11e808b4e73089b850cf9620a7ee This leaves us in a position where kgdb still uses the no-longer-used protocol; gdb-7.8.1, which restored the original behaviour,If was released on 2014-10-29. I don't believe it is possible to detect/correct the protocol incompatiblity which means the kernel must take a view about which version of the gdb remote protocol is "correct". This patch takes the view that the original/current version of the protocol is correct and that version found in gdb-7.7.x and gdb-7.8.0 is anomalous. Signed-off-by: Daniel Thompson --- Notes: Vijaya: I really hope I have the history lesson in the commit message correct! I've done a fair bit of archeology to unpick things. arch/arm64/include/asm/kgdb.h | 13 +++++-------- arch/arm64/kernel/kgdb.c | 7 ++++++- 2 files changed, 11 insertions(+), 9 deletions(-) -- 2.5.5 diff --git a/arch/arm64/include/asm/kgdb.h b/arch/arm64/include/asm/kgdb.h index f69f69c8120c..326fa8f44da5 100644 --- a/arch/arm64/include/asm/kgdb.h +++ b/arch/arm64/include/asm/kgdb.h @@ -43,20 +43,17 @@ extern int kgdb_fault_expected; * General purpose regs: * r0-r30: 64 bit * sp,pc : 64 bit - * pstate : 64 bit - * Total: 34 + * pstate : 32 bit + * Total: 33 + 1 * FPU regs: * f0-f31: 128 bit - * Total: 32 - * Extra regs * fpsr & fpcr: 32 bit - * Total: 2 - * + * Total: 32 + 2 */ -#define _GP_REGS 34 +#define _GP_REGS 33 #define _FP_REGS 32 -#define _EXTRA_REGS 2 +#define _EXTRA_REGS 3 /* * general purpose registers size in bytes. * pstate is only 4 bytes. subtract 4 bytes diff --git a/arch/arm64/kernel/kgdb.c b/arch/arm64/kernel/kgdb.c index b67531a13136..ec62a4e3c190 100644 --- a/arch/arm64/kernel/kgdb.c +++ b/arch/arm64/kernel/kgdb.c @@ -58,7 +58,11 @@ struct dbg_reg_def_t dbg_reg_def[DBG_MAX_REG_NUM] = { { "x30", 8, offsetof(struct pt_regs, regs[30])}, { "sp", 8, offsetof(struct pt_regs, sp)}, { "pc", 8, offsetof(struct pt_regs, pc)}, - { "pstate", 8, offsetof(struct pt_regs, pstate)}, + { "pstate", 4, offsetof(struct pt_regs, pstate) +#ifdef CONFIG_CPU_BIG_ENDIAN + + 4 +#endif + }, { "v0", 16, -1 }, { "v1", 16, -1 }, { "v2", 16, -1 }, @@ -128,6 +132,7 @@ sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *task) memset((char *)gdb_regs, 0, NUMREGBYTES); thread_regs = task_pt_regs(task); memcpy((void *)gdb_regs, (void *)thread_regs->regs, GP_REG_BYTES); + dbg_get_reg(33, gdb_regs + GP_REG_BYTES, thread_regs); } void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long pc)