From nobody Fri May 26 13:54:29 2023 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 4QSRHT6Yqxz4WmDQ; Fri, 26 May 2023 13:54:29 +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 4QSRHT4C9fz3kJ5; Fri, 26 May 2023 13:54:29 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1685109269; 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=K4YX8M3rFwmuidb6AqqbIeW4uPCqC/KySiDSYrPolWc=; b=fFC9wUUd/AEUXwiGcybyehHXVqaOjUgQz7LJL5e591zmg1kwvosl4XIX9FaP231f7n3Qv5 LQucGD1iKI+Hm3uzGfsNYhGBHKrALTsbT0ggAMq+g0dyQxS7kzhs2uDqctW+n2mSNhvzbx YMQnKuvmK0bj4NR+LKwGO9AgYRWbnA4fP8qMAr+uaCJudvbZY0RV4lfwuwW/B/C6wUSwGw p7ZfIU0GGepBup1n21Bx/A/mAGiVRUW4b44j2KPKEGkOvgEmbJhiVE/cr8Eiu7hkNXA32n fKyGnh672h+P3qhzPkuT3P+sQnZwUCnBVEI3Bk14fRObY7Tq9jA/4pI6PLbxRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1685109269; 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=K4YX8M3rFwmuidb6AqqbIeW4uPCqC/KySiDSYrPolWc=; b=weFyhQhSaaErzcFeWCq4d3S5NWIRt95vTAwVEBzaXwwjwNnJwjikZ4p9zPk+nrC3eu71Y3 80VQYhhUvA6ejd/zTDbMdnwSm4PWpM3evOd8UHq/YX6hglr3glE+rmn4gRwIbxx7y9aFWL Pdri6OY2tG4M6pG3EajI5KvTtFaJQNPWnG7JMZetxcKYSKF7WBxIGBVxH94Ctt2mmSck1Z Hf71JbFhve3twXiJFFpJo7+nnmxAxJ0vow4lWmRHKIejYKBRqbzsMKAcPzo25Poa8cJfm9 5Z+VCus+Tlzk+BVqExRt0AjXEQmJD57S2Gj94SfYdPdnuUAACTeJIWpIhWDFgg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1685109269; a=rsa-sha256; cv=none; b=JsSWgJ7j4WgPdX51lacBBS659e2uUnqw/zcs91W0fO88oFQuOsvmGemRRJ2/XegoyFWA0V poJc+avFTuuZyuFRMD1s0rcnj8mleCRJh43hINltQX9eIJGS5xamp5+j/vkHukhb0zs4Cf zdWwbw1qv8SKZK0JSFyCeh460lOzkKBazGuyb17IwiTMSugPGAsbM27OCiVzGohOdUdTfe TLp3wYtuodMH6Q1DJGMbI/Iw2JDHoxxM0vFAtpDtJ6+dByS3mN2g1OeSIqYAGtFKgsmhGP kzR+faDT5Os0uqAAFEAC+qCRuNcSseA0Bt/Zb2TeaUUFfWdToJQwlBjb7fYonw== 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 4QSRHT3HKQz18gg; Fri, 26 May 2023 13:54:29 +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 34QDsTjR088265; Fri, 26 May 2023 13:54:29 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 34QDsTE8088264; Fri, 26 May 2023 13:54:29 GMT (envelope-from git) Date: Fri, 26 May 2023 13:54:29 GMT Message-Id: <202305261354.34QDsTE8088264@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Christos Margiolis Subject: git: 9c80ad6839cd - main - kinst: add kinst_excluded() 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: christos X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 9c80ad6839cd30ecfeff2fb946d86888815da600 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=9c80ad6839cd30ecfeff2fb946d86888815da600 commit 9c80ad6839cd30ecfeff2fb946d86888815da600 Author: Christos Margiolis AuthorDate: 2023-05-26 13:54:08 +0000 Commit: Christos Margiolis CommitDate: 2023-05-26 13:54:08 +0000 kinst: add kinst_excluded() Exclude functions that are not safe-to-trace. Reviewed by: markj Approved by: markj (mentor) Sponsored by: The FreeBSD Foundation ifferential Revision: https://reviews.freebsd.org/D39229 --- sys/cddl/dev/kinst/amd64/kinst_isa.c | 13 +++++++++- sys/cddl/dev/kinst/kinst.c | 50 ++++++++++++++++++++++++++++++++++++ sys/cddl/dev/kinst/kinst.h | 2 ++ 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/sys/cddl/dev/kinst/amd64/kinst_isa.c b/sys/cddl/dev/kinst/amd64/kinst_isa.c index 5035f43be440..7aba79c1d481 100644 --- a/sys/cddl/dev/kinst/amd64/kinst_isa.c +++ b/sys/cddl/dev/kinst/amd64/kinst_isa.c @@ -500,7 +500,9 @@ kinst_make_probe(linker_file_t lf, int symindx, linker_symval_t *symval, pd = opaque; func = symval->name; - if (strcmp(func, pd->kpd_func) != 0 || strcmp(func, "trap_check") == 0) + if (kinst_excluded(func)) + return (0); + if (strcmp(func, pd->kpd_func) != 0) return (0); instr = (uint8_t *)symval->value; @@ -605,3 +607,12 @@ kinst_md_deinit(void) } } } + +/* + * Exclude machine-dependent functions that are not safe-to-trace. + */ +int +kinst_md_excluded(const char *name) +{ + return (0); +} diff --git a/sys/cddl/dev/kinst/kinst.c b/sys/cddl/dev/kinst/kinst.c index 8c9872ba86c8..46b9bf2f41e8 100644 --- a/sys/cddl/dev/kinst/kinst.c +++ b/sys/cddl/dev/kinst/kinst.c @@ -65,6 +65,56 @@ static dtrace_provider_id_t kinst_id; struct kinst_probe_list *kinst_probetab; static struct cdev *kinst_cdev; +int +kinst_excluded(const char *name) +{ + if (kinst_md_excluded(name)) + return (1); + + /* + * Anything beginning with "dtrace_" may be called from probe context + * unless it explicitly indicates that it won't be called from probe + * context by using the prefix "dtrace_safe_". + */ + if (strncmp(name, "dtrace_", strlen("dtrace_")) == 0 && + strncmp(name, "dtrace_safe_", strlen("dtrace_safe_")) != 0) + return (1); + + /* + * Omit instrumentation of functions that are probably in DDB. It + * makes it too hard to debug broken kinst. + * + * NB: kdb_enter() can be excluded, but its call to printf() can't be. + * This is generally OK since we're not yet in debugging context. + */ + if (strncmp(name, "db_", strlen("db_")) == 0 || + strncmp(name, "kdb_", strlen("kdb_")) == 0) + return (1); + + /* + * Lock owner methods may be called from probe context. + */ + if (strcmp(name, "owner_mtx") == 0 || + strcmp(name, "owner_rm") == 0 || + strcmp(name, "owner_rw") == 0 || + strcmp(name, "owner_sx") == 0) + return (1); + + /* + * When DTrace is built into the kernel we need to exclude the kinst + * functions from instrumentation. + */ +#ifndef _KLD_MODULE + if (strncmp(name, "kinst_", strlen("kinst_")) == 0) + return (1); +#endif + + if (strcmp(name, "trap_check") == 0) + return (1); + + return (0); +} + void kinst_probe_create(struct kinst_probe *kp, linker_file_t lf) { diff --git a/sys/cddl/dev/kinst/kinst.h b/sys/cddl/dev/kinst/kinst.h index b7abfd1e61e0..ee756dc87d09 100644 --- a/sys/cddl/dev/kinst/kinst.h +++ b/sys/cddl/dev/kinst/kinst.h @@ -46,6 +46,8 @@ extern struct kinst_probe_list *kinst_probetab; struct linker_file; struct linker_symval; +int kinst_excluded(const char *); +int kinst_md_excluded(const char *); int kinst_invop(uintptr_t, struct trapframe *, uintptr_t); int kinst_make_probe(struct linker_file *, int, struct linker_symval *, void *);