From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yw1-f194.google.com (mail-yw1-f194.google.com [209.85.128.194]) (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 AFDD92676F4 for ; Wed, 7 Jan 2026 06:44:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.194 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767768251; cv=none; b=UdI9hWa1uGgan1iEqqSctxX2xzbF98eTCzwqZOn2F9tXFVkyCy1hpLEDBy/bBEaV3VX/20CpXjfkauvhfHXMLJA1k/5kpIfk1HpEWE3uPEDd4f7s3iGLeGIYqrPIgCq0XQoqITILt6q60NzQ7AnAC6OIM+Ry+gleM/lGcoO2EYY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767768251; c=relaxed/simple; bh=9gy/ixQGGTG3ec3T1KjcigVwdzyN8R0jhqw3GqeqAH4=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=o9iFq6BzyK7H21jRQ5E6AVk1wb70PouDWxNuLmmSr1AI6UbKsGGbTIrZdJSm1qd84O984NcfAjiwSxImSj2NZSpYd7nBmb7oZGC5liRqruonmZSzOGc3OVNUBmEltUS+9CAOqodo9q+dCUE5IAsbod27U7CpibfN3oj/+BW5HsY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ZxP7X+W0; arc=none smtp.client-ip=209.85.128.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZxP7X+W0" Received: by mail-yw1-f194.google.com with SMTP id 00721157ae682-78fc0f33998so18585437b3.0 for ; Tue, 06 Jan 2026 22:44:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767768248; x=1768373048; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=E4xKVDlMDT5KTbpiffDI1wT4+UFxNi3Yn19G0UDCh8M=; b=ZxP7X+W0CAZScy+gfmWTCJuI1mjzfGDNBiYBKMyZKV++7M50Hhkmz1jkGDVPp6gZR8 eEusrV8AwuHYIyS9dGi0f54AihsmSan5Y+SzhhG7auIiAX+OcBVzNBG4toBtL0xmminZ 8D32+I9nRtk01d/PlBX4BvUYXSEZKEq7JuYoXv1xKranZgoBdVGaeD6SY9sygYgOK153 eXekTyRn+d+avbUWa4JDY38Lu6SQvNSRFfW6s/k6Wsxc1o1ym9WHH8N7dRQiL/Sd7Qcv PC1d1we9SMKscGnD5uRj83+QP4qpRDWm6gES6yMyXFgTH7oI7dNgquyWwc1F6LsN02Oc sAYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767768248; x=1768373048; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=E4xKVDlMDT5KTbpiffDI1wT4+UFxNi3Yn19G0UDCh8M=; b=KfLdG4bJdy81FGmJLJVCMfdUl0IS5VZEPn+JXNkmPaMv82RfZTKsc2jHDWI1tGjeBn 4efU83uRzenlrhtttcr8d+S1rLnS0xRjy9V/5SOt1bdf92mSkPeieBPeW9JJw0+Y0hsX ApaHzrx9U0V9aq+De2mN/yJKkRP4Q1HPf5hgUqU1/SCSM6psXgQaASK20V3Ij3BXJDPi AnmjLt1qHNOgsYKBAmOXna+A6Qg+AoljwqcrhcXcnn9l+4xouoC5NZj0BJ9qcz4d6ji9 wmyGYscoy+1m0C2OdHCXNFrgKkEgur6NJbqGT50BTvYKOK799qHl6sUjA0b+JjTFheQF OYUg== X-Forwarded-Encrypted: i=1; AJvYcCVMW0EC5RY3noTvZ5HJM7smLk0aILAiuprv+Yijj+v1WInkVfKA2cQAlBeqi5VQ+mhrX0TSg28=@vger.kernel.org X-Gm-Message-State: AOJu0YwufYYe7RDdolxBNToQpcU5PmZH0VYT/YYuMTdcelm0zfJFeLzL J9zXmCdLo5gfbb3h9Jz4yujD58y5lMx8t+m5qZxBqj5qVhAafb60PU5f X-Gm-Gg: AY/fxX7pcP3CuC6OiKCG2KyMjmEaF0i0VC9MpYnk5VLv3z+FzflEzQEK9+7/Npl+5cS Sh1PKz6ap7lMauhsx0aFKRVv1/MAsrdCBxQd6psbQ3hLbg4CtuqU5ZqG4deNhggFW+2DG5yFf39 pa+bb6zszGxUZD2ydTEnVR2bXQHkDNrnbUjTVrh/z+rUW0R3TbwdMViQ2DdC9+nK/mo/2x962cc XT17Jaz9YGJ/75RRzP6StvONkmlVNjBFGPyAQ1K+NmsGXOTF5By2B+G9pJrtg20QWNWBWfWdTVN GiFD/WiT3AayTLynsVFyjiukRn8kehqG/7MOA8VQSaBlPWlHlTPephzFe/4qloDWsw4rQ8UeQRP f+XoYRIvYBSP4zCdCQELn5WFoZuHcdOy5BZY2g11jzCFGxq9qkIIzSXkkATkB73G0VNAYYBfDwK e16kgXOCY= X-Google-Smtp-Source: AGHT+IGvmTFjLbD48Z9+kavs9ZjAbnZnjPvuXHejAJ9QhYT/i+BLOrNbo73UOWrqZujpn8h618cytA== X-Received: by 2002:a05:690c:730a:b0:787:f043:1f10 with SMTP id 00721157ae682-790b584a5ffmr34795207b3.66.1767768248409; Tue, 06 Jan 2026 22:44:08 -0800 (PST) Received: from 7940hx ([23.94.188.235]) by smtp.gmail.com with ESMTPSA id 00721157ae682-790b1be88dcsm9635047b3.47.2026.01.06.22.43.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jan 2026 22:44:08 -0800 (PST) From: Menglong Dong X-Google-Original-From: Menglong Dong To: ast@kernel.org, andrii@kernel.org Cc: daniel@iogearbox.net, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, davem@davemloft.net, dsahern@kernel.org, tglx@linutronix.de, mingo@redhat.com, jiang.biao@linux.dev, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, bpf@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next v7 00/11] bpf: fsession support Date: Wed, 7 Jan 2026 14:43:41 +0800 Message-ID: <20260107064352.291069-1-dongml2@chinatelecom.cn> X-Mailer: git-send-email 2.52.0 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Hi, all. No changes in this version, just a rebase to deal with conflicts. overall ------- Sometimes, we need to hook both the entry and exit of a function with TRACING. Therefore, we need define a FENTRY and a FEXIT for the target function, which is not convenient. Therefore, we add a tracing session support for TRACING. Generally speaking, it's similar to kprobe session, which can hook both the entry and exit of a function with a single BPF program. We allow the usage of bpf_get_func_ret() to get the return value in the fentry of the tracing session, as it will always get "0", which is safe enough and is OK. Session cookie is also supported with the kfunc bpf_session_cookie(). In order to limit the stack usage, we limit the maximum number of cookies to 4. kfunc design ------------ In order to keep consistency with existing kfunc, we don't introduce new kfunc for fsession. Instead, we reuse the existing kfunc bpf_session_cookie() and bpf_session_is_return(). The prototype of bpf_session_cookie() and bpf_session_is_return() don't satisfy our needs, so we change their prototype by adding the argument "void *ctx" to them. We introduce the function bpf_fsession_is_return() and bpf_fsession_cookie(), and change the calling to bpf_session_cookie() and bpf_session_is_return() to them in verifier for fsession. architecture ------------ The fsession stuff is arch related, so the -EOPNOTSUPP will be returned if it is not supported yet by the arch. In this series, we only support x86_64. And later, other arch will be implemented. Changes since v6: * change the prototype of bpf_session_cookie() and bpf_session_is_return(), and reuse them instead of introduce new kfunc for fsession. Changes since v5: * No changes in this version, just a rebase to deal with conflicts. Changes since v4: * use fsession terminology consistently in all patches * 1st patch: - use more explicit way in __bpf_trampoline_link_prog() * 4th patch: - remove "cookie_cnt" in struct bpf_trampoline * 6th patch: - rename nr_regs to func_md - define cookie_off in a new line * 7th patch: - remove the handling of BPF_TRACE_SESSION in legacy fallback path for BPF_RAW_TRACEPOINT_OPEN Changes since v3: * instead of adding a new hlist to progs_hlist in trampoline, add the bpf program to both the fentry hlist and the fexit hlist. * introduce the 2nd patch to reuse the nr_args field in the stack to store all the information we need(except the session cookies). * limit the maximum number of cookies to 4. * remove the logic to skip fexit if the fentry return non-zero. Changes since v2: * squeeze some patches: - the 2 patches for the kfunc bpf_tracing_is_exit() and bpf_fsession_cookie() are merged into the second patch. - the testcases for fsession are also squeezed. * fix the CI error by move the testcase for bpf_get_func_ip to fsession_test.c Changes since v1: * session cookie support. In this version, session cookie is implemented, and the kfunc bpf_fsession_cookie() is added. * restructure the layout of the stack. In this version, the session stuff that stored in the stack is changed, and we locate them after the return value to not break bpf_get_func_ip(). * testcase enhancement. Some nits in the testcase that suggested by Jiri is fixed. Meanwhile, the testcase for get_func_ip and session cookie is added too. Menglong Dong (11): bpf: add fsession support bpf: use last 8-bits for the nr_args in trampoline bpf: change prototype of bpf_session_{cookie,is_return} bpf: support fsession for bpf_session_is_return bpf: support fsession for bpf_session_cookie bpf,x86: introduce emit_st_r0_imm64() for trampoline bpf,x86: add fsession support for x86_64 libbpf: add fsession support selftests/bpf: add testcases for fsession selftests/bpf: add testcases for fsession cookie selftests/bpf: test fsession mixed with fentry and fexit arch/x86/net/bpf_jit_comp.c | 48 ++++- include/linux/bpf.h | 40 ++++ include/uapi/linux/bpf.h | 1 + kernel/bpf/btf.c | 2 + kernel/bpf/syscall.c | 18 +- kernel/bpf/trampoline.c | 53 ++++- kernel/bpf/verifier.c | 79 +++++-- kernel/trace/bpf_trace.c | 50 +++-- net/bpf/test_run.c | 1 + net/core/bpf_sk_storage.c | 1 + tools/bpf/bpftool/common.c | 1 + tools/include/uapi/linux/bpf.h | 1 + tools/lib/bpf/bpf.c | 1 + tools/lib/bpf/libbpf.c | 3 + tools/testing/selftests/bpf/bpf_kfuncs.h | 4 +- .../selftests/bpf/prog_tests/fsession_test.c | 115 ++++++++++ .../bpf/prog_tests/tracing_failure.c | 2 +- .../selftests/bpf/progs/fsession_test.c | 198 ++++++++++++++++++ .../bpf/progs/kprobe_multi_session_cookie.c | 12 +- .../bpf/progs/uprobe_multi_session.c | 4 +- .../bpf/progs/uprobe_multi_session_cookie.c | 12 +- .../progs/uprobe_multi_session_recursive.c | 8 +- 22 files changed, 583 insertions(+), 71 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/fsession_test.c create mode 100644 tools/testing/selftests/bpf/progs/fsession_test.c -- 2.52.0