From nobody Tue Sep 29 13:20:33 2026 Received: from va-1-113.ptr.blmpb.com (va-1-113.ptr.blmpb.com [209.127.230.113]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 531BB37DAB1 for ; Fri, 7 Aug 2026 08:15:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.127.230.113 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786090556; cv=none; b=TSQVzCx3BoQ6Tv+ocgxWsCC5LdRr2yv8cIiw8juap+pUkrF/fljd02Y7UAmlRzzzB7Hc16sijgFeM7V4LD83sWfr6slimQr6U/XFWldcDubOuLSCvz1/KAnEX5OQ0Ygn3iCRr02d3VKoUl6fA91nsldyQaINEaq5nfqZwsDgrb0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786090556; c=relaxed/simple; bh=A3hxkj0mnENhQepTkY8vMZbzVGgYvfElGjjdeNE53CU=; h=To:From:Mime-Version:Cc:Subject:Date:References:Content-Type: Message-Id:In-Reply-To; b=R4Fmh9IoWV0vcnPAHJFZ8tuWLSskfJuQkvZJKOiMIdQvkZHtBAf7Fwz+RD0FMSe6Vtg+5PRu/w32rqJ+VPsv4ho4IhbHQhGOZyjBRqhLDhP4uD7Dttwedgf71GY8Ejf+xD/NNlSqu4G2hKnxnjDSuo8esXai3JVLZF3FT5NMI+w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=YHgBUqiz; arc=none smtp.client-ip=209.127.230.113 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="YHgBUqiz" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1786090545; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=+XWYCvGW0LNdiKWYNV9u+HmtX/DOjOYu6CEy4SzeiMU=; b=YHgBUqizm5Bm+JQVIoO5kLmiSSDaMT0NUT92yY/2eVWxkdqgM3ItudqXKMInL1Kv4M/iLr AS5u4y/0kYrtBHzCpyC1p/zJSxloPolOZa/lD2yCG1s+hr7wNBjVc0QDKsh4NrqKmIa0Pe EBl+4KySQEEMMav4npLbjBnF1L9n+CHR2ZxqYMS/qK9M312yZ/ljO4a4eYvZbO34vUejL4 AXiH2hn0gDlYsnLPW8au6DhqRzYq7XMSNEM/wCoY6fcAr2hK4qaYlc9Or6JTYV62jaQSQx G37I00XImZfX70ZrRPjKdlHaa5T/B5b3Z6B/CSeUvDWvcxU2q5Dhq7AK1slq9w== To: "Steven Rostedt" , "Masami Hiramatsu" X-Lms-Return-Path: X-Mailer: git-send-email 2.20.1 From: "Rui Qi" Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Cc: "Mathieu Desnoyers" , "Shuah Khan" , "Heiko Carstens" , , , , "Rui Qi" Subject: [PATCH v2 1/2] selftests/ftrace: Force C locale in ftracetest Date: Fri, 7 Aug 2026 16:15:11 +0800 References: <20260806083101.2651025-1-qirui.001@bytedance.com> <20260807081512.2974757-1-qirui.001@bytedance.com> Message-Id: <20260807081512.2974757-2-qirui.001@bytedance.com> In-Reply-To: <20260807081512.2974757-1-qirui.001@bytedance.com> X-Original-From: Rui Qi Content-Type: text/plain; charset="utf-8" Some ftracetest test cases parse command output by matching English field names. Tools such as readelf may localize their output via gettext, while ftracetest currently inherits the user locale from the environment. If a translated field name is printed, parsing can fail even though the tested kernel behavior is unchanged. For example, add_remove_uprobe can fail to find the ELF entry point and then write a uprobe event with a missing offset. Export LC_ALL=3DC in the top-level ftracetest runner so every test case gets stable command output by default. Signed-off-by: Rui Qi --- tools/testing/selftests/ftrace/ftracetest | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/testing/selftests/ftrace/ftracetest b/tools/testing/self= tests/ftrace/ftracetest index 8ad2c385407e..246d7e1d015c 100755 --- a/tools/testing/selftests/ftrace/ftracetest +++ b/tools/testing/selftests/ftrace/ftracetest @@ -7,6 +7,9 @@ # Written by Masami Hiramatsu # =20 +# Keep command output parsing stable regardless of the user's locale. +export LC_ALL=3DC + usage() { # errno [message] [ ! -z "$2" ] && echo $2 echo "Usage: ftracetest [options] [testcase(s)] [testcase-directory(s)]" --=20 2.20.1 From nobody Tue Sep 29 13:20:33 2026 Received: from va-1-111.ptr.blmpb.com (va-1-111.ptr.blmpb.com [209.127.230.111]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8FEA7399000 for ; Fri, 7 Aug 2026 08:16:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.127.230.111 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786090577; cv=none; b=nH+S1gATvSPfEtFg3o4xBWmG5fZCJVu8schfzk/8EV6EacTM86/GfzcUGS3BTz72o/+dS34XYqorLVBFSwRl9p04x8zS2atTHiOZhbXkKGvlOoWxWvfCVZNDV0XNzJboxMtGShS0c1dV/MUnBCd9gFUJWlFKvqyP9URiqr8bPp4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786090577; c=relaxed/simple; bh=qozgKeqjQY8jqxFJp3ds9EO0gAHwRe1fjjWm2OUEFWo=; h=To:Subject:References:Content-Type:From:Date:In-Reply-To:Cc: Message-Id:Mime-Version; b=iDwpvZQfb/oUu4Hljfboe48tQJB4QT3KAQaG8cJUl5Sy4T3F+/wJ2SdEUQUNwJtjwbjxfhMD+qGdVpBN1HFAJQI1nTYXjrkpWmlyydkEO/MxLuCPB95lpbD5NhVlXPmz+p8/xt8saRMEDz6cwunNsABiFYS22YyDP49q55o3Oqk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=J72SvLHI; arc=none smtp.client-ip=209.127.230.111 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="J72SvLHI" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1786090561; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=m5Q6pj+2aZgVsaFgFCzX1cAV4lDF7uuJhuFlfFc6gII=; b=J72SvLHI4tp8R4BNvyD8aXOZXn3MZmS3nDXuvAon2Uw1wnYHNYhhWfkTx5DtRoWyqyN0ZC oW8N1HtHBiEyJE/1S8n5SuWGYyp68m/CuASaNerLge2AKFpGzHXNIOurnabHwMnZnpcGMu 0Tyn2gnEZYNAh0lCKPELXC0BW/Vi2YlmDJDaWlxaK1Q+DHdgdV09wWZ3X+O1dtxcxZNbmg 5RmBz1O3vGnzq2brPNM5O+VEM+0X5j2rR2iro6PQUohk1IT56aaYwvz9q4y5CD59VzJZlv lV7rj/lEI0031az+INTLJ7y9OpDrKSdNjjawxoxo6kXQjZGK16btrzzb9v6XOQ== To: "Steven Rostedt" , "Masami Hiramatsu" Subject: [PATCH v2 2/2] selftests/ftrace: Convert ELF entry point to file offset in uprobe test X-Lms-Return-Path: References: <20260806083101.2651025-1-qirui.001@bytedance.com> <20260807081512.2974757-1-qirui.001@bytedance.com> From: "Rui Qi" Date: Fri, 7 Aug 2026 16:15:12 +0800 In-Reply-To: <20260807081512.2974757-1-qirui.001@bytedance.com> Cc: "Mathieu Desnoyers" , "Shuah Khan" , "Heiko Carstens" , , , , "Rui Qi" Message-Id: <20260807081512.2974757-3-qirui.001@bytedance.com> Content-Transfer-Encoding: quoted-printable X-Mailer: git-send-email 2.20.1 X-Original-From: Rui Qi Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" The add_remove_uprobe test uses readelf -h to obtain the ELF entry point (e_entry) and passes it directly as the offset to uprobe_events. However, uprobe_events expects a file offset, not a virtual address. For PIE binaries, the virtual address happens to equal the file offset because the first LOAD segment has p_vaddr =3D=3D p_offset, so the test works by coincidence. But for non-PIE executables, e_entry is an absolute virtual address that can far exceed the file size. When the probe is enabled, uprobe_register() checks offset > i_size_read(inode) and rejects it with -EINVAL. Fix this by converting the virtual address to a file offset using the ELF program headers: scan readelf -lW output for the LOAD segment containing the entry point, then compute file_offset =3D e_entry - p_vaddr + p_offset. For PIE binaries the result is unchanged; for non-PIE binaries the offset is correctly translated. The conversion uses only POSIX shell primitives, with no dependency on gawk or perl. Fixes: dc4b165855f2 ("selftests/ftrace: Use readelf to find entry point in = uprobe test") Signed-off-by: Rui Qi --- .../test.d/dynevent/add_remove_uprobe.tc | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/ftrace/test.d/dynevent/add_remove_upro= be.tc b/tools/testing/selftests/ftrace/test.d/dynevent/add_remove_uprobe.tc index f2048c244526..19430bd5864c 100644 --- a/tools/testing/selftests/ftrace/test.d/dynevent/add_remove_uprobe.tc +++ b/tools/testing/selftests/ftrace/test.d/dynevent/add_remove_uprobe.tc @@ -12,9 +12,32 @@ echo 0 > events/enable echo > dynamic_events =20 REALBIN=3D`readlink -f /bin/sh` -ENTRYPOINT=3D`readelf -h ${REALBIN} | grep Entry | sed -e 's/[^0]*//'` =20 -echo "p:myevent ${REALBIN}:${ENTRYPOINT}" >> uprobe_events +# Get the entry point virtual address from ELF header +ENTRY=3D`readelf -hW ${REALBIN} | grep "Entry point" | awk '{print $NF}'` + +# Convert virtual address to file offset: find the LOAD segment containing +# the entry point, then compute file_offset =3D e_entry - p_vaddr + p_offs= et. +# For PIE binaries this is a no-op (vaddr =3D=3D file offset), but for non= -PIE +# executables the virtual address is much larger than the file size and +# must be converted, otherwise uprobe_register() rejects it with -EINVAL. +ENTRY_DEC=3D$(printf '%d' "$ENTRY") +OFFSET=3D$ENTRY +while IFS=3D read -r line; do + set -- $line + [ "$1" =3D "LOAD" ] || continue + VA_DEC=3D$(printf '%d' "$3") + OFF_DEC=3D$(printf '%d' "$2") + FSZ_DEC=3D$(printf '%d' "$5") + if [ "$ENTRY_DEC" -ge "$VA_DEC" ] && [ "$ENTRY_DEC" -lt "$((VA_DEC + F= SZ_DEC))" ]; then + OFFSET=3D$(printf '0x%x' "$((ENTRY_DEC - VA_DEC + OFF_DEC))") + break + fi +done << EOF +$(readelf -lW ${REALBIN} | grep LOAD) +EOF + +echo "p:myevent ${REALBIN}:${OFFSET}" >> uprobe_events =20 grep -q myevent uprobe_events test -d events/uprobes/myevent --=20 2.20.1