From nobody Wed Jun 22 11:41:00 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 7852087180D; Wed, 22 Jun 2022 11:41:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4LShKT2zXNz4sK2; Wed, 22 Jun 2022 11:41:01 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655898061; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=tlJAkIs8JoqY86TomKA1kH8g2VxM8Q1ib8alO+7CFoc=; b=oKMNDoKiZDLst6iWRYqTTGfxAtHbUaf9DcAQP8PdRoUnXDe0+Afk44Qoxrv0mTlpbtaG5b SJ9Wv8ze4VE8lunS1rEvGuWfk7onC+vo1rILr8qC7Jw6o4Xe3+v7RVTeWCnaqzzWJb81it laccWRz4IS+4BwiYCtHm0wEgow2ArtIItbSbkRe0OzRkBQTbULfZl5UzOW5hIfuR3KbnId nvKWYzzBAP87lEM0fiWIszvkvHdncJWuBU5MALiuyNYTEa8BCEjlHgO/bOtWSXNBqvVuW8 jC93L79Arh7mFMTUlQLUnnkL28IeJDK8BSjEfPHcRCmnMmJy8tx7ijxT3Wj9UQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 09B7A2571B; Wed, 22 Jun 2022 11:41:01 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 25MBf09x023682; Wed, 22 Jun 2022 11:41:00 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 25MBf0Be023681; Wed, 22 Jun 2022 11:41:00 GMT (envelope-from git) Date: Wed, 22 Jun 2022 11:41:00 GMT Message-Id: <202206221141.25MBf0Be023681@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dmitry Chagin Subject: git: 8a0f6d8cfdb7 - main - kdump: Add preliminary support for decoding Linux syscalls List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dchagin X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 8a0f6d8cfdb75a9484c456984ff55192f8b16886 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655898061; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=tlJAkIs8JoqY86TomKA1kH8g2VxM8Q1ib8alO+7CFoc=; b=UwidLKsR2/4zPFgleI4gIMOMaIocCJ51rb+tndQ+1VKpM/LoQCF97AYM5D0jWGwYlWKYYx A2CmLvCp8pe6vPDvYglJm9PHBfXITSM8wLUjFVoJBm2tDze4r9jOjfRv5yHAL3ZeOFjlJn Fll/R+MRfty+4N0kFOavD0cTLQnv+VVak83cR9AojbTKTOmRB66KiRsGCX0/M1uMnE0QqC qXp9d6UbAzuM1EDbi6AEmvAKGSuHnaVALYXiIENyHyM4x42eFgF4QZ+aROjluBBsbWBP7/ MUcZ0GxQfuRV6qOIF7Sb5PYrRYMqYibJ7PnP1llQnvJfG2Q3pyARJE0+MjpQFw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1655898061; a=rsa-sha256; cv=none; b=e1LyzvHmnnvNgOI9+XSnYGugalgUWvYpAXSxnbxPaqdpaXMBvUxbM/TotrCSDf3C2pb60i wMubQwxE0i+QXjXGy2cOk7vbnO418/SwdWXRMcOG1lX2jEDJEoRJheMhK8ht38ped3x7sd ssy9Nv0Zr6jcAeAkROshUbvPmTtpOHD5m1ZHyqZE6Rx0gLwnUhT92URwn44vC/0HWeuZqD BH8hvM2D1HjBHpK5+dZ40D47IjIXqLOg7uZ+Y7WJZOK5lYOPFIntzgtwtuZIejG6brOhqP NM/IMe1X7FTLpC3xjj0NxsF/Jls4aXZetd2tMwkxXjvpuR/gRTfGRatsooaXsg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=8a0f6d8cfdb75a9484c456984ff55192f8b16886 commit 8a0f6d8cfdb75a9484c456984ff55192f8b16886 Author: Dmitry Chagin AuthorDate: 2022-06-22 11:03:56 +0000 Commit: Dmitry Chagin CommitDate: 2022-06-22 11:03:56 +0000 kdump: Add preliminary support for decoding Linux syscalls Reviewed by: jhb Differential revision: https://reviews.freebsd.org/D35216 MFC after: 2 weeks --- usr.bin/kdump/Makefile | 7 ++ usr.bin/kdump/kdump.c | 57 +++++++++++---- usr.bin/kdump/kdump.h | 9 +++ usr.bin/kdump/linux.c | 185 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 245 insertions(+), 13 deletions(-) diff --git a/usr.bin/kdump/Makefile b/usr.bin/kdump/Makefile index e826ac2d6dbf..c6e03347e097 100644 --- a/usr.bin/kdump/Makefile +++ b/usr.bin/kdump/Makefile @@ -17,4 +17,11 @@ LIBADD+= cap_pwd CFLAGS+=-DWITH_CASPER .endif +.if ${MACHINE_CPUARCH} == "aarch64" || ${MACHINE_CPUARCH} == "amd64" || \ + ${MACHINE_CPUARCH} == "i386" +SRCS+= linux.c +.endif + +CFLAGS.linux.c+= -I${SRCTOP}/sys + .include diff --git a/usr.bin/kdump/kdump.c b/usr.bin/kdump/kdump.c index e54f8ec1deb5..79a5007bd1ec 100644 --- a/usr.bin/kdump/kdump.c +++ b/usr.bin/kdump/kdump.c @@ -124,6 +124,8 @@ void ktrfaultend(struct ktr_faultend *); void ktrkevent(struct kevent *); void ktrstructarray(struct ktr_struct_array *, size_t); void ktrbitset(char *, struct bitset *, size_t); +void ktrsyscall_freebsd(struct ktr_syscall *ktr, register_t **resip, + int *resnarg, char *resc, u_int sv_flags); void usage(void); #define TIMESTAMP_NONE 0x0 @@ -766,19 +768,52 @@ print_signal(int signo) void ktrsyscall(struct ktr_syscall *ktr, u_int sv_flags) +{ + int narg = ktr->ktr_narg; + register_t *ip; + + syscallname(ktr->ktr_code, sv_flags); + ip = &ktr->ktr_args[0]; + if (narg) { + char c = '('; + if (fancy) { + switch (sv_flags & SV_ABI_MASK) { + case SV_ABI_FREEBSD: + ktrsyscall_freebsd(ktr, &ip, &narg, &c, + sv_flags); + break; +#ifdef SYSDECODE_HAVE_LINUX + case SV_ABI_LINUX: +#ifdef __amd64__ + if (sv_flags & SV_ILP32) + ktrsyscall_linux32(ktr, &ip, + &narg, &c); + else +#endif + ktrsyscall_linux(ktr, &ip, &narg, &c); + break; +#endif /* SYSDECODE_HAVE_LINUX */ + } + } + while (narg > 0) + print_number(ip, narg, c); + putchar(')'); + } + putchar('\n'); +} + +void +ktrsyscall_freebsd(struct ktr_syscall *ktr, register_t **resip, + int *resnarg, char *resc, u_int sv_flags) { int narg = ktr->ktr_narg; register_t *ip, *first; intmax_t arg; int quad_align, quad_slots; - syscallname(ktr->ktr_code, sv_flags); ip = first = &ktr->ktr_args[0]; - if (narg) { - char c = '('; - if (fancy && - (sv_flags == 0 || - (sv_flags & SV_ABI_MASK) == SV_ABI_FREEBSD)) { + char c = *resc; + quad_align = 0; if (sv_flags & SV_ILP32) { #ifdef __powerpc__ @@ -1510,13 +1545,9 @@ ktrsyscall(struct ktr_syscall *ktr, u_int sv_flags) narg--; break; } - } - while (narg > 0) { - print_number(ip, narg, c); - } - putchar(')'); - } - putchar('\n'); + *resc = c; + *resip = ip; + *resnarg = narg; } void diff --git a/usr.bin/kdump/kdump.h b/usr.bin/kdump/kdump.h index faf8e03e541d..dc0515397f48 100644 --- a/usr.bin/kdump/kdump.h +++ b/usr.bin/kdump/kdump.h @@ -76,4 +76,13 @@ void print_mask_argul(bool (*decoder)(FILE *, u_long, u_long *), bool print_mask_arg_part(bool (*decoder)(FILE *, int, int *), int value, int *rem); +#ifdef SYSDECODE_HAVE_LINUX +void ktrsyscall_linux(struct ktr_syscall *ktr, register_t **resip, + int *resnarg, char *resc); +#ifdef __amd64__ +void ktrsyscall_linux32(struct ktr_syscall *ktr, register_t **resip, + int *resnarg, char *resc); +#endif +#endif /* SYSDECODE_HAVE_LINUX */ + #endif /* !__KDUMP_H__ */ diff --git a/usr.bin/kdump/linux.c b/usr.bin/kdump/linux.c new file mode 100644 index 000000000000..e584b54db36c --- /dev/null +++ b/usr.bin/kdump/linux.c @@ -0,0 +1,185 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2022 Dmitry Chagin + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include + +#include "kdump.h" + +#ifdef __amd64__ +#include +#include +#elif __aarch64__ +#include +#elif __i386__ +#include +#endif + +static void +print_linux_signal(int signo) +{ + const char *signame; + + signame = sysdecode_linux_signal(signo); + if (signame != NULL) + printf("%s", signame); + else + printf("SIG %d", signo); +} + +void +ktrsyscall_linux(struct ktr_syscall *ktr, register_t **resip, + int *resnarg, char *resc) +{ + int narg = ktr->ktr_narg; + register_t *ip, *first; + int quad_align, quad_slots; + char c; + + ip = first = &ktr->ktr_args[0]; + c = *resc; + quad_align = 0; + quad_slots = 1; + switch (ktr->ktr_code) { + case LINUX_SYS_linux_clock_gettime: + case LINUX_SYS_linux_clock_settime: + case LINUX_SYS_linux_clock_getres: + case LINUX_SYS_linux_timer_create: + putchar('('); + sysdecode_linux_clockid(stdout, *ip); + c = ','; + ip++; + narg--; + break; + case LINUX_SYS_linux_kill: + case LINUX_SYS_linux_tkill: + case LINUX_SYS_linux_rt_sigqueueinfo: + print_number(ip, narg, c); + putchar(','); + print_linux_signal(*ip); + ip++; + narg--; + break; + case LINUX_SYS_linux_tgkill: + case LINUX_SYS_linux_rt_tgsigqueueinfo: + print_number(ip, narg, c); + print_number(ip, narg, c); + putchar(','); + print_linux_signal(*ip); + ip++; + narg--; + break; + case LINUX_SYS_linux_rt_sigaction: + putchar('('); + print_linux_signal(*ip); + ip++; + narg--; + c = ','; + break; + case LINUX_SYS_linux_ftruncate: + case LINUX_SYS_linux_truncate: + print_number(ip, narg, c); + print_number64(first, ip, narg, c); + break; + } + *resc = c; + *resip = ip; + *resnarg = narg; +} + +#if defined(__amd64__) +void +ktrsyscall_linux32(struct ktr_syscall *ktr, register_t **resip, + int *resnarg, char *resc) +{ + int narg = ktr->ktr_narg; + register_t *ip, *first; + int quad_align, quad_slots; + char c; + + ip = first = &ktr->ktr_args[0]; + c = *resc; + quad_align = 0; + quad_slots = 2; + switch (ktr->ktr_code) { + case LINUX32_SYS_linux_clock_gettime: + case LINUX32_SYS_linux_clock_settime: + case LINUX32_SYS_linux_clock_getres: + case LINUX32_SYS_linux_timer_create: + case LINUX32_SYS_linux_clock_gettime64: + case LINUX32_SYS_linux_clock_settime64: + case LINUX32_SYS_linux_clock_getres_time64: + putchar('('); + sysdecode_linux_clockid(stdout, *ip); + c = ','; + ip++; + narg--; + break; + case LINUX32_SYS_linux_kill: + case LINUX32_SYS_linux_tkill: + case LINUX32_SYS_linux_rt_sigqueueinfo: + print_number(ip, narg, c); + putchar(','); + print_linux_signal(*ip); + ip++; + narg--; + break; + case LINUX32_SYS_linux_tgkill: + case LINUX32_SYS_linux_rt_tgsigqueueinfo: + print_number(ip, narg, c); + print_number(ip, narg, c); + putchar(','); + print_linux_signal(*ip); + ip++; + narg--; + break; + case LINUX32_SYS_linux_signal: + case LINUX32_SYS_linux_sigaction: + case LINUX32_SYS_linux_rt_sigaction: + putchar('('); + print_linux_signal(*ip); + ip++; + narg--; + c = ','; + break; + case LINUX32_SYS_linux_ftruncate: + case LINUX32_SYS_linux_truncate: + print_number(ip, narg, c); + print_number64(first, ip, narg, c); + break; + } + *resc = c; + *resip = ip; + *resnarg = narg; +} +#endif /* __amd64__ */