From owner-freebsd-dtrace@freebsd.org Wed Nov 6 15:36:34 2019 Return-Path: Delivered-To: freebsd-dtrace@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 897D11B8E65 for ; Wed, 6 Nov 2019 15:36:34 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: from mail-qk1-x741.google.com (mail-qk1-x741.google.com [IPv6:2607:f8b0:4864:20::741]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 477Vxs45yGz4GfY for ; Wed, 6 Nov 2019 15:36:33 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: by mail-qk1-x741.google.com with SMTP id h15so15237066qka.13 for ; Wed, 06 Nov 2019 07:36:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=dygdajoKchBIWd8iq+2s+/qhGOQtCNkQH7qRadXzvNQ=; b=iJiJH95KmZ0FCf2Zr29Yvgmyml1ai/tOpTq+gB/eNd4pO2yWVfGJgw98Ok8Vi7jgxz wpuYbJRCvGfPizurEA4cjvmPfwjAa0DCOCGjJWOLgpX2vTymk6fpItNh7ZcS39fwdPKi QYX+C2U54tgScYM+ZOqUvGcjUwZVAEw2YCCwFqxRmlPzmqGHQMsSWhCSUvl2kLubgcXN Uv+L8VqMLGt58MM1qvqciseLJyt/WE1g7/lbZD9gaPHu5edJLUV3wwZTaZ5BPjK+Rtu3 LsWREfJcBxGVXMACif0k/qJhZVVNn6HAkdvFhYHXNYZE/tuxd0F6sFKAIinnqcqXELqa pEcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=dygdajoKchBIWd8iq+2s+/qhGOQtCNkQH7qRadXzvNQ=; b=jAxpbjVRUApWudaln8oNRPzOP/qUMI13OFuKIdQjMY8oYaa3qhJeJF5bH3S51fvkkd qguc8tr6YH3TO6RX3KvMSq4UIChx5KEoxS89vN1MlTd3HJ8M/ICr1EJALygNwsHLc4Sg xXYnZa28C1stPv77WYUZMQoVsF/AZrXHmEGuuVMbvLIZ6VVAAX7rVP5++lOSqyaBTxP6 17eSpQRxm/gA2Z7lAE5u0nxIxdyg3f1YsJmb7g/EsSJDbexjN7sWanudiUQgjjz9nU9E RHHjZ1xcFR6moOCzj7t0Q7kb8V7/aU1GA9CwF+NTtm97JYKKyZAyfOHcG1AgjVefa/GM oSUg== X-Gm-Message-State: APjAAAX1Ub2cJabYB/SCq8zZkkLUTvn0iVWj5IKqXoHtRRPQiNiI6+EH anajyiqjzUHHeLdu6Mq4Gm43G0lTTN4= X-Google-Smtp-Source: APXvYqzGq6T4Dt/odDIM1hjllMbYXsGAvH2JSPCqGVc/KHr2YPHtanmrG7sB16San3JEYhCLItvBbw== X-Received: by 2002:a37:4f4e:: with SMTP id d75mr2628669qkb.490.1573054592120; Wed, 06 Nov 2019 07:36:32 -0800 (PST) Received: from raichu (toroon0560w-lp130-05-69-158-183-252.dsl.bell.ca. [69.158.183.252]) by smtp.gmail.com with ESMTPSA id z17sm3667137qtq.69.2019.11.06.07.36.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Nov 2019 07:36:31 -0800 (PST) Sender: Mark Johnston Date: Wed, 6 Nov 2019 10:36:29 -0500 From: Mark Johnston To: "Bjoern A. Zeeb" Cc: freebsd-dtrace@freebsd.org Subject: Re: dtrace script matching lot of probes simply resets on i386 Message-ID: <20191106153629.GC65703@raichu> References: <71FB27F2-31DD-4646-BAA8-69E686D811DE@lists.zabbadoz.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <71FB27F2-31DD-4646-BAA8-69E686D811DE@lists.zabbadoz.net> User-Agent: Mutt/1.12.2 (2019-09-21) X-Rspamd-Queue-Id: 477Vxs45yGz4GfY X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20161025 header.b=iJiJH95K; dmarc=none; spf=pass (mx1.freebsd.org: domain of markjdb@gmail.com designates 2607:f8b0:4864:20::741 as permitted sender) smtp.mailfrom=markjdb@gmail.com X-Spamd-Result: default: False [-2.09 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20161025]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+ip6:2607:f8b0:4000::/36:c]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-dtrace@freebsd.org]; DMARC_NA(0.00)[freebsd.org]; RCVD_COUNT_THREE(0.00)[3]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_SOME(0.00)[]; DKIM_TRACE(0.00)[gmail.com:+]; RCPT_COUNT_TWO(0.00)[2]; RCVD_IN_DNSWL_NONE(0.00)[1.4.7.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.4.6.8.4.0.b.8.f.7.0.6.2.list.dnswl.org : 127.0.5.0]; IP_SCORE(-0.39)[ip: (2.45), ipnet: 2607:f8b0::/32(-2.35), asn: 15169(-2.01), country: US(-0.05)]; FORGED_SENDER(0.30)[markj@freebsd.org,markjdb@gmail.com]; MID_RHS_NOT_FQDN(0.50)[]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; FROM_NEQ_ENVFROM(0.00)[markj@freebsd.org,markjdb@gmail.com]; RCVD_TLS_ALL(0.00)[] X-BeenThere: freebsd-dtrace@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "A discussion list for developers working on DTrace in FreeBSD." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 Nov 2019 15:36:34 -0000 On Tue, Nov 05, 2019 at 11:23:28AM +0000, Bjoern A. Zeeb wrote: > Hi, > > I had an i386 kernel (amd64 machine) simply going to POST. After a lot > of “doh” I realised that it was a dtrace script which was matching a > lot of probes running as part of some automated stuff. > > The problematic part from the middle of that script was a section which > I can reduce to > > fbt:kernel::entry # or simply ::: > /self->foo == 1/ > { > > printf(“Hello\n”); > } > > Anyone wants to investigate this or should I open a PR? Can you test this patch? I only tried to compile it. Basically, we must handle FBT probes before calling trap(). diff --git a/sys/i386/i386/exception.s b/sys/i386/i386/exception.s index b288543dafe1..8a8de5fb1d09 100644 --- a/sys/i386/i386/exception.s +++ b/sys/i386/i386/exception.s @@ -175,7 +175,7 @@ alltraps_with_regs_pushed: FAKE_MCOUNT(TF_EIP(%esp)) calltrap: pushl %esp - movl $trap,%eax + movl $trap_check,%eax call *%eax add $4, %esp @@ -317,7 +317,7 @@ dbg_user: movl $handle_ibrs_entry,%eax call *%eax pushl %esp - movl $trap,%eax + movl $trap_check,%eax call *%eax add $4, %esp movl $T_RESERVED, TF_TRAPNO(%esp) diff --git a/sys/i386/i386/trap.c b/sys/i386/i386/trap.c index bb71317de000..83ac97887feb 100644 --- a/sys/i386/i386/trap.c +++ b/sys/i386/i386/trap.c @@ -112,6 +112,7 @@ PMC_SOFT_DEFINE( , , page_fault, write); #endif void trap(struct trapframe *frame); +void trap_check(struct trapframe *frame); void syscall(struct trapframe *frame); static int trap_pfault(struct trapframe *, bool, vm_offset_t, int *, int *); @@ -186,6 +187,21 @@ SYSCTL_INT(_machdep, OID_AUTO, uprintf_signal, CTLFLAG_RW, &uprintf_signal, 0, "Print debugging information on trap signal to ctty"); +/* + * Ensure that we ignore any DTrace-induced faults. This function cannot + * be instrumented, so it cannot generate such faults itself. + */ +void +trap_check(struct trapframe *frame) +{ +#ifdef KDTRACE_HOOKS + if (dtrace_trap_func != NULL && + (*dtrace_trap_func)(frame, frame->tf_trapno)) + return; +#endif + trap(frame); +} + /* * Exception, fault, and trap interface to the FreeBSD kernel. * This common code is called from assembly language IDT gate entry @@ -260,19 +276,6 @@ trap(struct trapframe *frame) return; } -#ifdef KDTRACE_HOOKS - /* - * A trap can occur while DTrace executes a probe. Before - * executing the probe, DTrace blocks re-scheduling and sets - * a flag in its per-cpu flags to indicate that it doesn't - * want to fault. On returning from the probe, the no-fault - * flag is cleared and finally re-scheduling is enabled. - */ - if ((type == T_PROTFLT || type == T_PAGEFLT) && - dtrace_trap_func != NULL && (*dtrace_trap_func)(frame, type)) - return; -#endif - /* * We must not allow context switches until %cr2 is read. * Also, for some Cyrix CPUs, %cr2 is clobbered by interrupts.