From patchwork Wed Dec 11 15:39:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amal Raj T X-Patchwork-Id: 849656 Received: from mail-qt1-f170.google.com (mail-qt1-f170.google.com [209.85.160.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF9921A4F22; Wed, 11 Dec 2024 15:39:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733931600; cv=none; b=BAetw7shd4nTskt7ZmaTJZ1l6I2wu3psc60Ykhfq3+ztvX5tlOWj7A8t48NYErIxitRmQJUQpd82LCeJDLtteCxi+Jza4dRirf9HRVVWM0RQ7+8u+2cL+m1YkNaR9orV+IPT+XVQdnfgqiHF2v7nejTVQTui5dyznZEsqbnKcII= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733931600; c=relaxed/simple; bh=bK/LnE7gV1izWYMHECvFCMWCwCay1mdcdg4l2UtGcYM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p8KY5mYVN5OqePXq0eP+PC3T+LN9brAXs4aZ0OZtvoiMT8pCBF3mZ5UQDVDQ9bRTovnrCorrEtdpY7jfpOkVDxCRZ6E9uSfiDf12LrUHJXdnv2xY2lJNG09IsvfYbHuy/iGxrpRPMlNqxj+0uxveI63lv8zRPAULjXQee3Ncq0U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=bB49Zi80; arc=none smtp.client-ip=209.85.160.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bB49Zi80" Received: by mail-qt1-f170.google.com with SMTP id d75a77b69052e-4676e708aeaso26088781cf.1; Wed, 11 Dec 2024 07:39:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733931598; x=1734536398; darn=vger.kernel.org; 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=k5g7lXWcRcM3HNMmQpadh/PSrKzcaUKwuppIIByAAAY=; b=bB49Zi80MZNywcl176hYpapwbBk3v6G7N8RdXHIQQs97mFMLG0ddUN1oRmmpCbwpba bWHQl9AkNgrZpSujZybMzlXkXkEhrcyXGLVDIt0cSTkHGpOb8S14iMiwKC0XlAWAmmIR F6eAxZjfiSR8a6OxPkuQq4rsHCKrcNPLWs901nVJ5FD7A7LiMzrO3/3PPxy3mUtGpVrp DGc4P6Dx/jMwEav4tk/qXNlJC4SnBSyvR9P0kzc8awTXt1UNa0uel9MBdvSb61C7Y4zR Vkf6HwVUYRO+6NLmKciBB5syRDPswmqmdJTrWPWgF3bpqThutFHypshU92yjy8JsovUT KMMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733931598; x=1734536398; 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=k5g7lXWcRcM3HNMmQpadh/PSrKzcaUKwuppIIByAAAY=; b=Mls16sz1j65KbBOVLy2YdcWtJQOLdbseFXyEvvxGVs89W2Gb/c7y1kIm/hNQlV8Kgj VqR/UyMZLuWMe0iI/oOXI8cH6HoBDUSfBbd/OCHKQQgv9PVUS4V+KtShKLulihM2wuiK hH3eILf6G1hlv17pxp2rgGLjbdFzHWnp0/aNbRao7lf65R/+mrC31Bx+YabKt6lz2UjE X+2GpNrVMmgogtDMrqaHxWTiFKA8a7xthJlEAYcoQQtjksr2MFQ3Dl7EQFOy8yczySyI DDCTTfDDfncPDLa+6vOtXS94fowxMYAOsA3zK8nTLHXM725YarjZ4S2m3SHKP5SeCDQM VVPQ== X-Forwarded-Encrypted: i=1; AJvYcCWq9aEklDEho1Au2ZiPpSfNUQlMqc9aXy2ye5Ox4QaF9VmERObMdQ4xm+GJfpcpL4mvpJwc6vZRsjPBGm8BRFw=@vger.kernel.org, AJvYcCXmg8K/E8b5WgjaVWZH/yFlBycpCPGoreArXuwQU/QcLbO5M86mx/zTAtGLfYPpELyAs2r99eNOf9OhBaYR@vger.kernel.org X-Gm-Message-State: AOJu0YxXEyvyv0YXN7FNOwuCEchNyanh//NKnfic1ZTmT97PnCwYietY Bz+Pw0KzsbTfco7c3RnZuqOhsUs1k1cr//G1b+Sqn6jTzi99006U X-Gm-Gg: ASbGncucBKn4knJ0LSrdjpye9rQOWqWCAFl08nV/qG4zIXk7d7tOieuqIBmeHszxTAP g71cuUWEnWpwmirTJHDUETpB/hcXVyDckwJrz/qinbBTqVYnl+F2bqmiLQMnyrnIAUWTdxelNQM Hl0qH+hUqeLN0JgQ1gJUCSgJ+mrFs8IN+YdESpaVakFEWpQ/tUFvFdOKfiQvHoy5coQOCSy2Bss TNEOdbg0/dtIv8Dwu/HNZtB7mkN6DUf8LLYGTDbUjVQ6WM= X-Google-Smtp-Source: AGHT+IFFLNsQdk6dvD0dZBjIsUu+IjGKHxOJT/DadpFaifHqYZURdCbfbL+/qV3TIxCfAhTl4mu94A== X-Received: by 2002:ac8:7fc6:0:b0:461:2616:84c3 with SMTP id d75a77b69052e-467892a2539mr63734041cf.8.1733931597600; Wed, 11 Dec 2024 07:39:57 -0800 (PST) Received: from localhost ([2a03:2880:20ff:13::]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4677fd42b1csm16184971cf.82.2024.12.11.07.39.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 07:39:57 -0800 (PST) From: Amal Raj T To: danielt@kernel.org, dianders@chromium.org, jason.wessel@windriver.com, stephen.s.brennan@oracle.com Cc: tjarlama@gmail.com, amalrajt@meta.com, osandov@osandov.com, linux-debuggers@vger.kernel.org, linux-serial@vger.kernel.org, kgdb-bugreport@lists.sourceforge.net Subject: [PATCH v2 1/3] kgdb: Add kgdb_mem2ebin function for converting memory to binary format Date: Wed, 11 Dec 2024 07:39:53 -0800 Message-ID: <20241211153955.33518-2-tjarlama@gmail.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241211153955.33518-1-tjarlama@gmail.com> References: <20241211153955.33518-1-tjarlama@gmail.com> Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Amal Raj T Add a new function kgdb_mem2ebin that converts memory to binary format, escaping special characters ('$', '#', and '}'). kgdb_mem2ebin function ensures that memory data is properly formatted and escaped before being sent over the wire. Additionally, this function reduces the amount of data exchanged between debugger compared to hex. Signed-off-by: Amal Raj T --- include/linux/kgdb.h | 1 + kernel/debug/gdbstub.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h index 76e891ee9e37..fa3cf38a14de 100644 --- a/include/linux/kgdb.h +++ b/include/linux/kgdb.h @@ -322,6 +322,7 @@ extern struct kgdb_io *dbg_io_ops; extern int kgdb_hex2long(char **ptr, unsigned long *long_val); extern char *kgdb_mem2hex(char *mem, char *buf, int count); +extern char *kgdb_mem2ebin(char *mem, char *buf, int count); extern int kgdb_hex2mem(char *buf, char *mem, int count); extern int kgdb_isremovedbreak(unsigned long addr); diff --git a/kernel/debug/gdbstub.c b/kernel/debug/gdbstub.c index f625172d4b67..6198d2eb49c4 100644 --- a/kernel/debug/gdbstub.c +++ b/kernel/debug/gdbstub.c @@ -257,6 +257,37 @@ char *kgdb_mem2hex(char *mem, char *buf, int count) return buf; } +/* + * Convert memory to binary format for GDB remote protocol + * transmission, escaping special characters ($, #, and }). + */ +char *kgdb_mem2ebin(char *mem, char *buf, int count) +{ + char *tmp; + int err; + + tmp = buf + count; + + err = copy_from_kernel_nofault(tmp, mem, count); + if (err) + return NULL; + while (count > 0) { + unsigned char c = *tmp; + + if (c == 0x7d || c == 0x23 || c == 0x24) { + *buf++ = 0x7d; + *buf++ = c ^ 0x20; + } else { + *buf++ = c; + } + count -= 1; + tmp += 1; + } + *buf = 0; + + return buf; +} + /* * Convert the hex array pointed to by buf into binary to be placed in * mem. Return a pointer to the character AFTER the last byte From patchwork Tue Dec 10 13:34:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amal Raj T X-Patchwork-Id: 849086 Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1FAB21A0AFA; Tue, 10 Dec 2024 13:34:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733837694; cv=none; b=FytyGgYe5bVvJ4XwPGjHdhMjCDF2mLkO4ZznPd+xY5q7q0mrif0BqIRrD0DCDOhROmxVf4S9p/5QloubvuF7+s9oCQCWSbQlc8MDP0BzH94oX4nV1S7iAYS00ahAGnIugqEErAwrkcnqG07RgdnOZHzXy3Fq+Ojko0I+h4OL8Ek= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733837694; c=relaxed/simple; bh=j7Fkm8miyQPUo4Agej6+DrddHMm2KEKk/d9sikhmlAU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GwBYAuan3zl753ami2Oyh+ACJ3cXsUOP44/jrTrsfEJujGjRIPRO5UZOAULNNJQaj0YT+3WhkbsSTywxxxQNKI1MNwDiFjnhuqwmyEOoh60RoX/XyMv6gryG6tf3/p+KzNoH4D0YCFIC0AescDhFqfZDtuaeedNQs9BpmwEec2g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=KvNj0jZe; arc=none smtp.client-ip=209.85.222.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KvNj0jZe" Received: by mail-qk1-f177.google.com with SMTP id af79cd13be357-7b6d6fe8b16so168749485a.1; Tue, 10 Dec 2024 05:34:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733837692; x=1734442492; darn=vger.kernel.org; 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=1uDre2BrjFxoUxEXQwHK6Feq1hadBUS1xU/z2vBEIrg=; b=KvNj0jZe3gToEHpEd3UVr72o5IC8jvzq7/2wPWeviOA1mszIE0cdMFYMvVVPEsoqC5 Lj0DS24QRldNK9zouSu+pnDqKzKgf8EFpeYeqz8g7yBnR2+zgY4NrG/AE93C16WIuFNp ahJ/1DxVu3mVwqGTulMatgCZcGf/V8on+G1YRlcy/34gQJsb4BD9QBQ547rzbykP+x89 0mp1uehc7WyvzwM2HtFuQWSw2uD/U6Am3Ep7uViMVCm/K6w7FGyjwhPy55DM20wmpKBC mzGlLCx/H1pUENvAx7JaUs+0mOQ3564oWkSZevI3ikdvnbBanPB4tdOy9qV/87NhwjBl ztkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733837692; x=1734442492; 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=1uDre2BrjFxoUxEXQwHK6Feq1hadBUS1xU/z2vBEIrg=; b=kSAOx/mipvlqXJcSkhT6aCB6+Q/GahYWd/eeJu/WIipW6yxz0/x+fjvfI8ZBCzGuFD 2RQtJj6Cz9EGsbk9AZl5+XQxz9CI/tIlzNeq3xFRsXYPV7T5M7RTPfiwFEF0e7t9Pgdx pelOEo8rIR0OLMUUdi9faLrrA192zhDAi7AMnuKHfkuKE0l4m1jshLPfQ6Pw3XgEyJhH tPjTLOBOg0FOX207WUa3COcPLPAg7IFk+ORYG7mWSgvBQ+MSpPTjJbd7DiP020EC2HRk TwQcEiH7Vb3btQqN7XsBLzRTI0+CnLShPgHnC44IDXstOZ0N9/nJVXMTMhLykjf4TZ9M QIHA== X-Forwarded-Encrypted: i=1; AJvYcCXnASLg7EAp8Uzo7ELHEvIq5B8b4uuiDMbUUqfzr1GcvqfHVfNSUdGODLDQaPRdPAboZE/b1NhbbnExItkt5IQ=@vger.kernel.org, AJvYcCXx91rE9CS9nhfm67vwf8oel5804fJE1Zd2TazGlDi5BfEW6U+cITnmr/Fq3l/zHCXDlkAE10C5HqHqit8O@vger.kernel.org X-Gm-Message-State: AOJu0Yzw4ty5OhChy+y/1W/VlXcx+smDMt3GT7ujb4B8fmUsUcfdMtCm l6nm4UmRuZe0fnhCRucyz/+NNDJcCk3bDhssD9sAgObedBu8Ke9j X-Gm-Gg: ASbGnct+iF+xTmrkVHQlZvuwp3l1WYyBoNF18gV00TWi0jlfl7wyQIocqSLXACkFLTU nZ0WWi9eyCPcRkk2Ur/HjfBV/z/fL1Mub3mIKpAUaSu7E9RWo40tIsxJupLxdzdv4bBW/L+1mr6 CWvloEPRkfbTJdqaEaot8NlPO5OuHb4Nq0+JxE3jlL9rxtJZ5Yysglo/YwdpZdnXLV5mghCwPQV itXRqZkU8+Zuek3SbYB3nNtzz8O1BAZwzJFICAy8y+fpRo= X-Google-Smtp-Source: AGHT+IFhEt3JFKJeFHXMMTm5hZ+k51UoMVNS8Vmaq6IsF5DsUiU5odOY4K1Yt2onZJG8ZB9YcXEnYg== X-Received: by 2002:a05:6214:e87:b0:6d8:a1fe:7298 with SMTP id 6a1803df08f44-6d91e433d68mr68947826d6.41.1733837691981; Tue, 10 Dec 2024 05:34:51 -0800 (PST) Received: from localhost ([2a03:2880:20ff:74::]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d9162133aasm18175056d6.129.2024.12.10.05.34.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 05:34:51 -0800 (PST) From: Amal Raj T To: danielt@kernel.org, dianders@chromium.org, jason.wessel@windriver.com, stephen.s.brennan@oracle.com Cc: tjarlama@gmail.com, amalrajt@meta.com, osandov@osandov.com, linux-debuggers@vger.kernel.org, linux-serial@vger.kernel.org, kgdb-bugreport@lists.sourceforge.net Subject: [PATCH 2/3] serial: Move LF -> CRLF replacement from serial console to kdb Date: Tue, 10 Dec 2024 05:34:47 -0800 Message-ID: <20241210133448.3684593-3-tjarlama@gmail.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241210133448.3684593-1-tjarlama@gmail.com> References: <20241210133448.3684593-1-tjarlama@gmail.com> Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Amal Raj T The current implementation of `poll_put_char` in the serial console driver performs LF -> CRLF replacement, which can corrupt binary data. Since kdb is the only user of `poll_put_char`, this patch moves the LF -> CRLF replacement logic to kdb. Link: https://lore.kernel.org/linux-debuggers/Zy093jVKPs9gSVx2@telecaster/ Signed-off-by: Amal Raj T --- drivers/tty/serial/serial_core.c | 4 ---- kernel/debug/kdb/kdb_io.c | 2 ++ 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index 74fa02b23772..ed18492b7f8f 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -2142,8 +2142,6 @@ void uart_console_write(struct uart_port *port, const char *s, unsigned int i; for (i = 0; i < count; i++, s++) { - if (*s == '\n') - putchar(port, '\r'); putchar(port, *s); } } @@ -2738,8 +2736,6 @@ static void uart_poll_put_char(struct tty_driver *driver, int line, char ch) if (!port) return; - if (ch == '\n') - port->ops->poll_put_char(port, '\r'); port->ops->poll_put_char(port, ch); uart_port_deref(port); } diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index 6a77f1c779c4..43a7c8ad741a 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -572,6 +572,8 @@ static void kdb_msg_write(const char *msg, int msg_len) len = msg_len; while (len--) { + if (*cp == '\n') + dbg_io_ops->write_char('\r'); dbg_io_ops->write_char(*cp); cp++; } From patchwork Wed Dec 11 15:39:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amal Raj T X-Patchwork-Id: 849655 Received: from mail-qk1-f173.google.com (mail-qk1-f173.google.com [209.85.222.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 19A051D5CF4; Wed, 11 Dec 2024 15:40:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733931602; cv=none; b=r1rkuJpdrkZjq2xxPtsM4FVRQfT7Q7Mf/MeK6K7oQ1ZbUXhdnHuUdMlkaBOlMEeogac12jZHaxTkoJu8xq02XIJ85KuTuzVM1yz7Z1A9LAIUfWws/lsKE/IG86fGzc1YTXiDWRAsNxIzHnzei0KRSbwHgxNh0HnJLB0EaCFwfEo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733931602; c=relaxed/simple; bh=xCNtIGvZnNIu5/QbFT3pZymo7sFLzI6Gj4+mZZnRzu4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mINhvLwbOP3XARO3f9WmbScffmE5epm1WRPBiZwi2myy/92ODCykylJChtppkxmG9eGoSLtXCuQSO7iFJzk+yVuyJtbipkJT0mR92qcIXhkIZZS4ZUVNA/pzzqsc9ZNVZ/doOzbSIubQG5qN8oGFv2OzrXH5wbShze3oFRd3WMY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=SUPsRsit; arc=none smtp.client-ip=209.85.222.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SUPsRsit" Received: by mail-qk1-f173.google.com with SMTP id af79cd13be357-7b6e8fe401eso119476985a.2; Wed, 11 Dec 2024 07:40:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733931600; x=1734536400; darn=vger.kernel.org; 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=bKV6ykmIkdoQNyGHHuYy+sKRiD2AqpahzC1WLoezEII=; b=SUPsRsit9LBznlpQcKiLduap3C4ToWncklG6WbOg7bvstElChikpAtbBnttGaFIrSP gqTTEmgehTpTtNK3RKm2jU0PfxRy7IqpBsDulhEqODUW4s0JjKd/xHZJYIZ4LJxb9dQt cv6ObqE/UlQ5P6C/VQpIyKtYj+Qz4i2Vs5iqbxOnBD5I7L9vYcbHa8oHjlahBwEdwdx9 BPCn4W7ZvL8SOjkC1LKLrcybVLgzkRtCDMAZosbidtIgwzVIxl8Jelw2tjpFvRyjHoaZ yuQmQxSoi6fqzxDuHQmmrHy/Ly1kfMIr5kRzY/E3O6hIp7shcllCwg2ETN8V+ScbAjN/ 3fQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733931600; x=1734536400; 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=bKV6ykmIkdoQNyGHHuYy+sKRiD2AqpahzC1WLoezEII=; b=Brp8xcVRqS+EIoPSC6UkI4kvBhj9Uw7Po3UEnpNKjleAmkIVYB16BpN3vfZJHiajjI gG1a0IqFSFkUSUVZfxApsKWxq/HNJwjj5ftuY8p9QdZjV5OtfLykxSdK/KTxkLc6aUZe 63qjb/JLwoKBQBpdfCqS0y+R6WpUJRNh4iJaBXdlUel/xWsBIUNoQUqa29QiOgAjvhjV t3VYvn8YIMtFdDvzYAN6RC2RV5XRiFEQarWG0cQmH+xkfJCYgsAE798ke81xb9LmJHqL gnXz38Tz7nLAWdJQfQ0jU47GmIbjjVHvAgs3ern7J8sZ9b6hduh562qcnHUVQCZzp4ij F2rw== X-Forwarded-Encrypted: i=1; AJvYcCVXDn21jW7U7WmsW1pp5Hfxh/UhsjQQh68FqSZqTlBE87smDnZD4CvQ/pIjQQHEWKHBKZufahZu75zMMzXa@vger.kernel.org, AJvYcCXSCa4P6N9o2TmrRfUMqIHT4EDtCDETAz4x++38RQ8Zte3HNBuy34y56qXOEoq88xNFQZ1rQB1cWkwsUTCiUXo=@vger.kernel.org X-Gm-Message-State: AOJu0YwGvlzoLQvzrQXfE0E0hJofS9HzTcy0yEJRoPgWgXP91KhRGt6S QyIq4P2M8X4YP1rJtlJ+MYsUq0Kbz/VrHznZ+T6JBQfHVcW3FRzq X-Gm-Gg: ASbGncuj1wUrAEBXgoUb/QFZp4v9wKgnu/5LzWhWbbTjs7dqdvWG4EiNmN3XZPRocqM zD6xpygjDAjAGmUP4Tlmm4AnLGB6LmUy25iYDmzEERpuN3zfAtRjw7/tgWssClUdwlS/l8vdWpK tL0roKTgOdkfi0nwSqFQs0zTTvO0BMWEPIg8msApNb5BEOLTmYpA7PMGpG1dIOkQM/vOLKB+Seb eqMGyVGUW+t1vgCqGp03tTKaAgUDE5bn2vRYUkn2wx/xGc= X-Google-Smtp-Source: AGHT+IFSPqOSxpGMChdT2H6lTn5vsbQE4pfhlqzSy7VLPkTfCcuKn0I6YHYQWdwVHrD5XqsqWDeEIA== X-Received: by 2002:a05:620a:2814:b0:7b6:cf48:ed5 with SMTP id af79cd13be357-7b6eb42fa43mr490786985a.7.1733931599686; Wed, 11 Dec 2024 07:39:59 -0800 (PST) Received: from localhost ([2a03:2880:20ff:16::]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b6de8a8caesm186786385a.43.2024.12.11.07.39.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 07:39:59 -0800 (PST) From: Amal Raj T To: danielt@kernel.org, dianders@chromium.org, jason.wessel@windriver.com, stephen.s.brennan@oracle.com Cc: tjarlama@gmail.com, amalrajt@meta.com, osandov@osandov.com, linux-debuggers@vger.kernel.org, linux-serial@vger.kernel.org, kgdb-bugreport@lists.sourceforge.net Subject: [PATCH v2 3/3] kgdb: Add command linux.vmcoreinfo to kgdb Date: Wed, 11 Dec 2024 07:39:55 -0800 Message-ID: <20241211153955.33518-4-tjarlama@gmail.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241211153955.33518-1-tjarlama@gmail.com> References: <20241211153955.33518-1-tjarlama@gmail.com> Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Amal Raj T Add a new query `linux.vmcoreinfo` to kgdb that returns vmcoreinfo to the client using the mem2ebin encoding. Maximum size of output buffer is set to 3X the maximum size of VMCOREINFO_BYTES (kgdb_mem2ebin() requires 1x for the temporary copy plus up to 2x for the escaped data). Signed-off-by: Amal Raj T --- kernel/debug/gdbstub.c | 10 +++++++++- lib/Kconfig.kgdb | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/kernel/debug/gdbstub.c b/kernel/debug/gdbstub.c index 6198d2eb49c4..5bec444fc6d3 100644 --- a/kernel/debug/gdbstub.c +++ b/kernel/debug/gdbstub.c @@ -34,13 +34,14 @@ #include #include #include +#include #include "debug_core.h" #define KGDB_MAX_THREAD_QUERY 17 /* Our I/O buffers. */ static char remcom_in_buffer[BUFMAX]; -static char remcom_out_buffer[BUFMAX]; +static char remcom_out_buffer[MAX(VMCOREINFO_BYTES*3, BUFMAX)]; static int gdbstub_use_prev_in_buf; static int gdbstub_prev_in_buf_pos; @@ -768,6 +769,13 @@ static void gdb_cmd_query(struct kgdb_state *ks) *(--ptr) = '\0'; break; + case 'l': + if (memcmp(remcom_in_buffer + 1, "linux.vmcoreinfo", 16) == 0) { + remcom_out_buffer[0] = 'Q'; + kgdb_mem2ebin(vmcoreinfo_data, remcom_out_buffer + 1, vmcoreinfo_size); + } + break; + case 'C': /* Current thread id */ strcpy(remcom_out_buffer, "QC"); diff --git a/lib/Kconfig.kgdb b/lib/Kconfig.kgdb index 537e1b3f5734..012529eee79e 100644 --- a/lib/Kconfig.kgdb +++ b/lib/Kconfig.kgdb @@ -12,6 +12,7 @@ menuconfig KGDB bool "KGDB: kernel debugger" depends on HAVE_ARCH_KGDB depends on DEBUG_KERNEL + select VMCORE_INFO help If you say Y here, it will be possible to remotely debug the kernel using gdb. It is recommended but not required, that