From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2CACD364043 for ; Mon, 22 Jun 2026 09:26:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782120412; cv=none; b=J+XQQgT5zmi1kJQ3z6tsMUX1PW5lelKN0uOpCGysmRXrlZtoryYZDl7yxMZkrG3dcpWZXOFh/6tzMtXeQWv58zz+OdKtyVx6WQEQJwqUrudNZ2p5x/6HERnnm/YeePocf4pGGXtzM9kgTV8e2xdyAGKDzc+49nduaIDhAIMi6T0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782120412; c=relaxed/simple; bh=npI3TVsu1vh7fGTNyCtoIBJnX6XRntxiFxQ9DfWsP78=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=JRM4cKhNOlWxUBRIuQprPdBnXb92etk+E4fNkfGg6rggBLhkzo/BZ5hWYy1QzzIKCGRjVlH5Hx4Fqu1t6ICZr1479x9vHTBKihFDoQbUNnkErAxEkI+lyUtksrvaD0+B3cufTegY+3Bnmg+9vpbKqA/lgttuS4G4+SDCFVYyi5A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=JhvnA7dz; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=ecgFKfiW; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="JhvnA7dz"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="ecgFKfiW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1782120407; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8lxJZaHJqq3JLhs8WTyThOEkpx9pQImBFkOjkr1hHfk=; b=JhvnA7dzhFQqUu3JMvkVeYugPn1z/CeXj0t40lbY6IDf64v6+qVT5ZysQYcpcbFH0KIjD/ Y4U4hy/epMaY6cui9UdKGMfzr8nmuF2m72fsKB42bcG1h1HT/K4A0v00HCzvkJPXdHhAyG iOXdbZN20NifXXz+QpPA4UtXBYkz1Oo= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-389-Tz5rTcRPNqicjz9ZpyvxxQ-1; Mon, 22 Jun 2026 05:26:41 -0400 X-MC-Unique: Tz5rTcRPNqicjz9ZpyvxxQ-1 X-Mimecast-MFC-AGG-ID: Tz5rTcRPNqicjz9ZpyvxxQ_1782120399 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-49244130073so15197705e9.1 for ; Mon, 22 Jun 2026 02:26:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1782120399; x=1782725199; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=8lxJZaHJqq3JLhs8WTyThOEkpx9pQImBFkOjkr1hHfk=; b=ecgFKfiWuvVlwpFMU9XkSvxTFljuT1NrBaRT9zg+YgfB/WiihP0otPi0UvCubIu8Gl RogccjOvXHrqW4ry1TBFIypMq6gRaMaWn1Imo9c3+GSyVRhYgUNOZyYk4tdkfbGgCDOV qiwU5KkvNN5MvAQcb8kv3MFiD1JyJU4f8kmEZaudaUW9boeougzu1SZ5X98cXEBwEFoO PziMq6S1FIilvkj3zqjzPo2G//gckHHvA8UonLn4NrXe/lFrjMW+cnRn7rh9DMwZ3C4X +9wtVn2jJLzRmWm6NVQHujnWqiIkMRVW1bjTjWgU0Jqc8Z/HJvyeyUptU5uINu6E1VqK t97A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782120399; x=1782725199; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=8lxJZaHJqq3JLhs8WTyThOEkpx9pQImBFkOjkr1hHfk=; b=tKZBk7oAoc0nRD17qlu54z3zdUHFi4xEv6zy7xbIAV73XzYKEV4le8rT1d2CDkyyGc UlT8Z2ZV4DK+STKGpz4mkD7zTMu2Z1MASWripV4F7TONGlJYUeezxGjkEIoyeto5PIeQ rJnQ3dib0++8Z6xz9YtIdwFCeiL8pxkNphHMUby7iudWXYiSE5Yrv5Caht/83pkrh3HQ v2cgqoehxFkxDGu5u62FQb3cTbaaqDov5ufaOSNoXZ5aZMowcErAdfcTGL6fsgVdnexS DM20ylWiVlvO1To1D9F+oEYG7i9cv7yu17kZeGb2RagOgk8LE7qsv1TtDbnZufL94nPt qZnQ== X-Forwarded-Encrypted: i=1; AFNElJ8i+Hnl8tc5KETVmg8QvJb4h4LwzypWalupl7NoTqnSY1D+C+Yms6z1MfyG8u9ZxKuSAzO2Zyq7DAZTue0=@vger.kernel.org X-Gm-Message-State: AOJu0Yw5HeZIyAcsEPO7vdAx7hOl26Liyc8/setcQclpeuXs6mKqk1Pe EKN2V/Ud4zBeqW94HrxbXzUCHbgLdaY9jtz+N1Bdl4guAMdfMiL4MBAhEXch+udIjtlPXekw6m2 g4JoF6JHK3flU74z0R4dyGEGgiQYtFfsYpBPZ3F8UAQ0gdmVykXntd0H12F4k7zhhiJU80u3egg == X-Gm-Gg: AfdE7cn5Rx9jGkRTWdzo1IJvs8LjVx4khYkOVwiHX2NKPMfOMTZ6rKsSY2VrknshL1h P1x9rkNtClyuHi4BR9yT+eU+COw91oHxVrYZW0rGxXZAw170F11hy6secpBrlXBimyI0gzSl366 Ub7zV9bZU+zLMkUpOYqtSdnrwXxts+Rz4vTicbqXSwQTDJcm24z8un0AJ3eisnZMs6Cp2rw3MS8 uL9khGjDdGn1R0j7J34IBoRIP5LVeOxZQhA04huL0Ia/EMrW4IPuGYTvx49EfpxrJhK/zvsBDU2 LzUO2QH3undTwTxX43CxgIcPVHVU2aTyExlGN0stDePFxOu29GCVFyxgf95u3uSi5WVPBNfRik6 uRDIjhb4PlnLnVto= X-Received: by 2002:a05:600c:c3cc:20b0:492:4363:e7d6 with SMTP id 5b1f17b1804b1-4924363e904mr131158455e9.37.1782120399080; Mon, 22 Jun 2026 02:26:39 -0700 (PDT) X-Received: by 2002:a05:600c:c3cc:20b0:492:4363:e7d6 with SMTP id 5b1f17b1804b1-4924363e904mr131158065e9.37.1782120398551; Mon, 22 Jun 2026 02:26:38 -0700 (PDT) Received: from [192.168.1.167] ([185.168.96.228]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-46666c57afasm25162038f8f.29.2026.06.22.02.26.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jun 2026 02:26:38 -0700 (PDT) Message-ID: Subject: Re: [PATCH v3 9/9] selftests/verification: add tlob selftests From: Gabriele Monaco To: wen.yang@linux.dev Cc: Steven Rostedt , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Date: Mon, 22 Jun 2026 11:26:37 +0200 In-Reply-To: <4aeb668c8446a9f6366d92e218df386bef7bc965.1780847473.git.wen.yang@linux.dev> References: <4aeb668c8446a9f6366d92e218df386bef7bc965.1780847473.git.wen.yang@linux.dev> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.60.2 (3.60.2-1.fc44) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On Mon, 2026-06-08 at 00:13 +0800, wen.yang@linux.dev wrote: > From: Wen Yang >=20 > +grep -qE "^p ${UPROBE_TARGET}:0x[0-9a-f]+ 0x[0-9a-f]+ threshold=3D[0- > 9]+$" "$TLOB_MONITOR" > +grep -q "threshold=3D5000000000" "$TLOB_MONITOR" > + > +! echo "p ${UPROBE_TARGET}:${busy_offset} ${stop_offset} > threshold=3D9999000" > "$TLOB_MONITOR" 2>/dev/null > + > +echo "-${UPROBE_TARGET}:${busy_offset}" > "$TLOB_MONITOR" > +! grep -q "^p .*:0x${busy_offset#0x} " "$TLOB_MONITOR" ... > +! grep -q "error_env_tlob" /sys/kernel/tracing/trace There is a widespread misconception under selftests that ! cmd with set -e fails if the command succeeds, so you can use it to expect a program failur= e. That isn't the case though [1], errexit (what set -e does), skips commands = starting with ! where the result isn't checked. Essentially if you want to say exit if the command succeeds, you can do: cmd && exit 1 # explicit ! cmd || exit 1 # explicit or still exploiting errexit cmd && false ! cmd || false I'm going to fix it in existing selftests using the last variant, but keep this in mind in your selftests as well. (Variants with ! are preferred beca= use they also return 0 if cmd fails, as you'd expect, I personally prefer to us= e false instead of explicit exit, but that's up to you). Thanks, Gabriele [1] - https://www.shellcheck.net/wiki/SC2251 > +echo 0 > monitors/tlob/enable > +echo 0 > /sys/kernel/tracing/events/rv/error_env_tlob/enable > +echo > /sys/kernel/tracing/trace > diff --git > a/tools/testing/selftests/verification/test.d/tlob/uprobe_violation.t > c > b/tools/testing/selftests/verification/test.d/tlob/uprobe_violation.t > c > new file mode 100644 > index 000000000000..d210d9c3a92d > --- /dev/null > +++ > b/tools/testing/selftests/verification/test.d/tlob/uprobe_violation.t > c > @@ -0,0 +1,67 @@ > +#!/bin/sh > +# SPDX-License-Identifier: GPL-2.0-or-later > +# description: Test tlob monitor budget violation (error_env_tlob > and detail_env_tlob fire with correct fields) > +# requires: tlob:monitor > + > +RV_BINDIR=3D"${RV_BINDIR:-$(realpath "$(dirname "${1:-$0}")")}" > +UPROBE_TARGET=3D"${RV_BINDIR}/tlob_target" > +TLOB_SYM=3D"${RV_BINDIR}/tlob_sym" > +[ -x "$UPROBE_TARGET" ] || exit_unsupported > +[ -x "$TLOB_SYM" ]=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 || exit_unsupported > +TLOB_MONITOR=3Dmonitors/tlob/monitor > + > +busy_offset=3D$("$TLOB_SYM" sym_offset "$UPROBE_TARGET" tlob_busy_work > 2>/dev/null) > +stop_offset=3D$("$TLOB_SYM" sym_offset "$UPROBE_TARGET" > tlob_busy_work_done 2>/dev/null) > +[ -n "$busy_offset" ] || exit_unsupported > +[ -n "$stop_offset" ] || exit_unsupported > + > +"$UPROBE_TARGET" 30000 & > +busy_pid=3D$! > +sleep 0.05 > + > +echo 1 > /sys/kernel/tracing/events/rv/error_env_tlob/enable > +echo 1 > /sys/kernel/tracing/events/rv/detail_env_tlob/enable > +echo 1 > /sys/kernel/tracing/tracing_on > +echo 1 > monitors/tlob/enable > +echo > /sys/kernel/tracing/trace > + > +# 10 =C2=B5s budget - fires almost immediately; task is busy-spinning on= - > CPU. > +echo "p ${UPROBE_TARGET}:${busy_offset} ${stop_offset} > threshold=3D10000" > "$TLOB_MONITOR" > + > +# wait up to 2 s for detail_env_tlob > +found=3D0; i=3D0 > +while [ "$i" -lt 20 ]; do > + sleep 0.1 > + grep -q "detail_env_tlob" /sys/kernel/tracing/trace && { > found=3D1; break; } > + i=3D$((i+1)) > +done > + > +echo "-${UPROBE_TARGET}:${busy_offset}" > "$TLOB_MONITOR" > 2>/dev/null > +kill "$busy_pid" 2>/dev/null || true; wait "$busy_pid" 2>/dev/null > || true > +echo 0 > /sys/kernel/tracing/events/rv/error_env_tlob/enable > +echo 0 > /sys/kernel/tracing/events/rv/detail_env_tlob/enable > +echo 0 > monitors/tlob/enable > + > +[ "$found" =3D "1" ] > + > +# error_env_tlob must carry the clk_elapsed environment field. > +# The event label is "budget_exceeded" when detected by the hrtimer > callback, > +# or the triggering sched event name when detected by the constraint > path on a > +# preemption that races with the timer (common on PREEMPT_RT / VM).=C2= =A0 > Both are > +# valid detections; check the env field instead of the label. > +grep "error_env_tlob" /sys/kernel/tracing/trace | head -n 1 | grep - > q "clk_elapsed=3D" > + > +# detail_env_tlob must have all five fields with the correct > threshold > +line=3D$(grep "detail_env_tlob" /sys/kernel/tracing/trace | head -n 1) > +echo "$line" | grep -q "pid=3D" > +echo "$line" | grep -q "threshold_ns=3D10000" > +echo "$line" | grep -q "running_ns=3D" > +echo "$line" | grep -q "waiting_ns=3D" > +echo "$line" | grep -q "sleeping_ns=3D" > + > +# Busy-spin keeps the task on-CPU: running_ns must exceed > sleeping_ns. > +running=3D$(echo "$line" | sed 's/.*running_ns=3D\([0-9]*\).*/\1/') > +sleeping=3D$(echo "$line" | sed 's/.*sleeping_ns=3D\([0-9]*\).*/\1/') > +[ "$running" -gt "$sleeping" ] > + > +echo > /sys/kernel/tracing/trace