From nobody Tue Mar 28 12:52:27 2023 X-Original-To: freebsd-dtrace@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 4Pm8jQ6Kssz41tH5 for ; Tue, 28 Mar 2023 12:52:42 +0000 (UTC) (envelope-from christos@freebsd.org) Received: from margiolis.net (mail.margiolis.net [95.179.159.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA512) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4Pm8jP5tF9z4Shx; Tue, 28 Mar 2023 12:52:41 +0000 (UTC) (envelope-from christos@freebsd.org) Authentication-Results: mx1.freebsd.org; dkim=pass header.d=margiolis.net header.s=default header.b=p+rOZCVX; spf=softfail (mx1.freebsd.org: 95.179.159.8 is neither permitted nor denied by domain of christos@freebsd.org) smtp.mailfrom=christos@freebsd.org; dmarc=none DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=default; bh=peV78Zs6wykt xrsewpFSajgQAo+OlTiU6UB8WYGu/jc=; h=subject:cc:to:from:date; d=margiolis.net; b=p+rOZCVXCmAv3AHt1LsYGuHohV6a9l2KaXIHcCVYq7pnlzkUcE5 tURs2Tj505u3FFohNp6iGI6jtqQbC+tXsPJqrG5n/QfG1uFr0Ze7eZekWGUXxTPFYzC2AF VzwrlnMlusL4TbXwTcEyx4dk2R1zsdnNVOWVMBIpH/93FJMQD4= Received: from pleb (ppp-94-66-59-63.home.otenet.gr [94.66.59.63]) by margiolis.net (OpenSMTPD) with ESMTPSA id 1b917f8f (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Tue, 28 Mar 2023 12:52:32 +0000 (UTC) Date: Tue, 28 Mar 2023 15:52:27 +0300 From: Christos Margiolis To: status-updates@freebsdfoundation.org Cc: freebsd-dtrace@freebsd.org, markj@freebsd.org, jrm@freebsd.org Subject: [Development report #6] Improve the kinst DTrace provider Message-ID: <20230328125227.zz35ufmmkocnpfdi@pleb> List-Id: A discussion list for developers working on DTrace in FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-dtrace List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-dtrace@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spamd-Result: default: False [-2.80 / 15.00]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-1.00)[-1.000]; MID_RHS_NOT_FQDN(0.50)[]; R_DKIM_ALLOW(-0.20)[margiolis.net:s=default]; MIME_GOOD(-0.10)[text/plain]; MLMMJ_DEST(0.00)[freebsd-dtrace@freebsd.org]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; DKIM_TRACE(0.00)[margiolis.net:+]; ASN(0.00)[asn:20473, ipnet:95.179.144.0/20, country:US]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_SOME(0.00)[]; DMARC_NA(0.00)[freebsd.org]; RCVD_COUNT_TWO(0.00)[2]; FREEFALL_USER(0.00)[christos]; ARC_NA(0.00)[]; R_SPF_SOFTFAIL(0.00)[~all:c]; FROM_HAS_DN(0.00)[]; TO_DN_NONE(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; RCVD_TLS_ALL(0.00)[] X-Rspamd-Queue-Id: 4Pm8jP5tF9z4Shx X-Spamd-Bar: -- X-ThisMailContainsUnwantedMimeParts: N The past few days I've been working on various bug fixes both in kinst and in libdtrace. Inline function tracing is almost done [1]. libdtrace now parses all loaded kernel modules, instead of just `kernel`. This makes it compatible with kinst, which also searches all loaded modules. After some testing I noticed that it is possible to have both a non-inline and an inline definition of the same function in a kernel module. If libdtrace finds such a case, it creates an additional FBT probe for the non-inline definition: # dtrace -dn 'kinst::cam_strvis_flag:entry' kinst::cam_strvis:25, kinst::cam_strvis_flag:0, fbt::cam_strvis_flag:entry { } dtrace: description 'kinst::cam_strvis_flag:entry' matched 3 probes For inline tracing, I implemented the algorithm described here [2] (markj@ has also implemented it in lib/libproc/proc_sym.c) to make sure that both the modules' ELF and debug files are up to date (i.e the module has been built with `DEBUG_FLAGS=-g`), otherwise we might run into version mismatches between functions. If such a mismatch is found, libdtrace prints a warning and skips that module. I wrote a few Kyua tests for kinst and made use of sys/dev/dtrace/dtrace_test.c (see inline tracing PR). In my previous email I mentioned that I modified kinst to search for `push %rbp` anywhere in a function, and skip the function if no `push %rbp` is found. Since this affects safe-to-trace functions that do not `push %rbp`, I'm working on an experimental change to exclude only exception handlers, and not search for `push %rbp` at all [3]. However, I'm still not sure this is 100% fail-proof, and I will need to do some more testing to make sure there are no accidental crashes. [1] https://reviews.freebsd.org/D38825 [2] https://sourceware.org/gdb/onlinedocs/gdb/Separate-Debug-Files.html [3] https://reviews.freebsd.org/D39229