From nobody Sat Oct 01 16:00:15 2022 X-Original-To: freebsd-hackers@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 4MfsJl4pMzz4ctcF for ; Sat, 1 Oct 2022 16:00:55 +0000 (UTC) (envelope-from christos@freebsd.org) Received: from christos (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 4MfsJk3xb4z3t0W; Sat, 1 Oct 2022 16:00:54 +0000 (UTC) (envelope-from christos@freebsd.org) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=default; bh=jaXL8L8tKT7N 67OOaxequzQphrPQ2caX+YY/JhYE4Yk=; h=subject:cc:to:from:date; d=margiolis.net; b=WDx26kasqhsE+t8MYPcVrYKzPnJzVqkLca8Kenzq+IwKbiLKCdS BBAlCL+IKNyZgGa+lVSel3Rp4PKdB/fpS8Z+QkanoRhO1sEEfBVjJegQN8WihY7PN1Bujf UkVPB/fZpkLBxTHkWCk5csIRlizAmhgyaq5wfQ0osxlmk4wWrM= Received: from pleb (ppp-94-66-59-136.home.otenet.gr [94.66.59.136]) by christos (OpenSMTPD) with ESMTPSA id fe0d493a (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Sat, 1 Oct 2022 16:00:46 +0000 (UTC) Date: Sat, 1 Oct 2022 19:00:15 +0300 From: Christos Margiolis To: freebsd-hackers@freebsd.org Cc: markj@freebsd.org Subject: Instruction-level dynamic tracing Message-ID: <20221001160015.sce47pwwtqu62vcr@pleb> List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Rspamd-Queue-Id: 4MfsJk3xb4z3t0W X-Spamd-Bar: / Authentication-Results: mx1.freebsd.org; dkim=pass header.d=margiolis.net header.s=default header.b=WDx26kas; dmarc=none; 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 X-Spamd-Result: default: False [0.27 / 15.00]; HFILTER_HELO_5(3.00)[christos]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.93)[-0.927]; MID_RHS_NOT_FQDN(0.50)[]; R_DKIM_ALLOW(-0.20)[margiolis.net:s=default]; MIME_GOOD(-0.10)[text/plain]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCPT_COUNT_TWO(0.00)[2]; ASN(0.00)[asn:20473, ipnet:95.179.144.0/20, country:US]; MLMMJ_DEST(0.00)[freebsd-hackers@freebsd.org]; DKIM_TRACE(0.00)[margiolis.net:+]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_SPF_SOFTFAIL(0.00)[~all:c]; FREEFALL_USER(0.00)[christos]; ARC_NA(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FROM_HAS_DN(0.00)[]; TO_DN_NONE(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DMARC_NA(0.00)[freebsd.org]; RCVD_TLS_ALL(0.00)[] X-ThisMailContainsUnwantedMimeParts: N Hello, Me and markj@ implemented a new DTrace provider (kinst) that allows for arbitrary kernel instruction tracing. The provider is currently implemented only for amd64, but we plan to port it to other architectures in the future as well. kinst probes take the form of: kinst::: where "function" is the kernel function to be traced, and "offset" is the offset to a specific instruction. This offset can be obtained from the function's disassembly using kgdb. For example, if I want to trace the second instruction in amd64_syscall(), I first need to figure out the offset to the second instruction: # kgdb (kgdb) disas /r amd64_syscall Dump of assembler code for function amd64_syscall: 0xffffffff809256c0 <+0>: 55 push %rbp 0xffffffff809256c1 <+1>: 48 89 e5 mov %rsp,%rbp 0xffffffff809256c4 <+4>: 41 57 push %r15 The offset is 1. To trace it: # dtrace -n 'kinst::amd64_syscall:1' Final code review: https://reviews.freebsd.org/D36851 Any review of the code would be appreciated. Christos