From nobody Sat Apr 4 00:07:14 2026 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (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 7D97F2EC0BF for ; Sat, 21 Mar 2026 21:41:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774129263; cv=none; b=RJHx5zGzW8M9gXr2VVEADSo3qzn1bwoV8NT0bzKcZI+38P4OMGFZ9SWRX9xVgizZ305It0oj4Q6GzXS6fypq6IHYwJldpxBkz88xI1uuE5BGzJjgnKUWXRVe38GNNxFThwtpu/ILZLuv0Jl7jrYRu3MiJSOXcvLArKwUc+LlvuY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774129263; c=relaxed/simple; bh=W9b8mkn2d/QQvmPyUvmCfl2ZxykFL2NGsclhDR8Pjuc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FRTPCnjsNyRJdVHGEG+lqnbKEKTjDkQItNRbDbv5c1IOb+WTudfLRNPfbEr1NZNUapNEWzVBEPt+CWbs9AIQ220bUzKv0q1+COcJ47HBUgSCN7/rw8lxTeDrjDerqpoDfuqLBHLUIfeeN5OPQ2c2dyEr28DRZLK0RHLPd2DaTHU= 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=BYKxDf5O; arc=none smtp.client-ip=209.85.210.181 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="BYKxDf5O" Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-82c20b9fb16so550688b3a.0 for ; Sat, 21 Mar 2026 14:41:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1774129261; x=1774734061; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RzaWyJv8683y0pAKjfQ2NLFdvOf3yhLbEHEYZka/WkI=; b=BYKxDf5O8jiwehcQd/REf5tbmDu3H7e99QhZlMfeVg7HULmfMQ1ZLoiPHJMvjlhQ7N UjS0xUwJAz/7u3GNsVCfAOv3lD79RDO0ZE2DLyKpY6k0qI6HyjuQ7GFccaeWY/9ivgK9 rJ2AAE1GVUw4HUkFgqSTVUznnRHBx4tIkkHxZKouOevdSJgO8Da3DvfmltDMD/88n4EV +aVWE3Yn4W5mHh74e2O+u5azZRnS/t+H1QSlJFTiOXx66kqb/XFWG1tVamiv79uPN+LZ mgcku+Ioe5A76fTVGhdtKdgqhLlt6Ztf2L4DlgzK9BxuphDuhgIPypAkox4xP+XJXP+O d9yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774129261; x=1774734061; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=RzaWyJv8683y0pAKjfQ2NLFdvOf3yhLbEHEYZka/WkI=; b=Ot4IWz8vvSv818puAwqiGnH6IGtFoAJz55JN3+3K5JyTBk0Ac3oB+O1KXC5WJ5hqS8 NXqxrNDTATx6PimQdU3R5k+UBHE39TJFAugCKLNWKZL9gAWMfwopk+5uKOHaR1038UAT 4kDnRZWJs4mjfolyjtLKYfnZgkRChRly5APFQtFBDeO/+OMMhumaaRqKSRUklAh291Yv UBs1N5+MldSQ8QQbzOe45c+QzAUvXT6F6PK574KqrxeHoBZnJMQRSA2TVWFBjBluWy2y iEUDJU5GZS2/gevF6+l2Vqa9KwrBSeVliq6WDDHTqev06T5TQh6vLTpWmBAHKVtyOfFp cqAw== X-Forwarded-Encrypted: i=1; AJvYcCUVvZsWcXIhYhJSQkM339JQqK79xaodNu5Urowl0gLVMQX7Z/IrVCz9flLZj8/cXHIF/Qau2l6kbGHqW6A=@vger.kernel.org X-Gm-Message-State: AOJu0YycdAYQPeYs6ZNKDb92brk047ip9qk8WO3Be6Ll//MD2G6wmOxv JiA14QB6H2nNjUAikSNHJGTIOeA4nmQzBtIytPWU2XzMGf9NZ3K43MiD X-Gm-Gg: ATEYQzxIQE9DY7jiFXPtdtmK0ycU6gOEIOO+D6GWsOnMgZQwbb4jOy4KlA/Sd8cqNAc eiptuskrSumZBmC6LBlSGVmy9Oe50rwpmpEzLBgyWsvvGKX9lrluTc3Fzx4xZBdMBnnD3RFdLQx JcUDzWHGf6rQfu63kCJ/LT3srWPGDhVOICBEGL+mnkt632R+yBzU8xjLPlVvppEF9+mCpcRvYC6 zONbHVE8xeXW6wYYO6k6bWoLiDUSIauyCiS+9O39/Heh/rLsStgmiNAFumne/qV8yfcr5hUQd6g MWzKSu3vnSRFp+Qr2JGGWAn72bGJw6ifTrDuX4DNpfQdjHjefe9lh4igxujKqHbPnFV8z6DM1wC W64eKj1xKsQsSazU12SdjDPb+jebDcIabHQz5hT2gmD4ziJLH0Ec8eeZF8xZgISONTyskeR/pWD qPUyJfURIZ0UQh/T6MRwmWIz6W+CBE4tLmWwnK0S/ONn+xAHS6ktZr7HAOUAGewjZo5kBp X-Received: by 2002:a05:6a00:bc93:b0:82a:7f1a:758c with SMTP id d2e1a72fcca58-82a8c247f22mr5291810b3a.11.1774129260608; Sat, 21 Mar 2026 14:41:00 -0700 (PDT) Received: from computer.goose-salary.ts.net ([2a09:bac5:40b2:277d::3ef:49]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82b03bc6745sm5475471b3a.23.2026.03.21.14.40.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Mar 2026 14:40:59 -0700 (PDT) From: Varun R Mallya To: keisuke.nishimura@inria.fr Cc: ameryhung@gmail.com, andrii@kernel.org, ast@kernel.org, bpf@vger.kernel.org, daniel@iogearbox.net, eddyz87@gmail.com, haoluo@google.com, john.fastabend@gmail.com, jolsa@kernel.org, kpsingh@kernel.org, linux-kernel@vger.kernel.org, martin.lau@linux.dev, sdf@fomichev.me, song@kernel.org, yonghong.song@linux.dev, Varun R Mallya Subject: [PATCH bpf-next] selftests/bpf: Add test for struct_ops __ref argument in any position Date: Sun, 22 Mar 2026 03:10:38 +0530 Message-ID: <20260321214038.80479-1-varunrmallya@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260320130219.63711-1-keisuke.nishimura@inria.fr> References: <20260320130219.63711-1-keisuke.nishimura@inria.fr> 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 Content-Type: text/plain; charset="utf-8" Add a selftest to verify that the verifier correctly identifies refcounted arguments in struct_ops programs, even when they are not the first argument. This ensures that the restriction on tail calls for programs with __ref arguments is properly enforced regardless of which argument they appear in. This test verifies the fix for check_struct_ops_btf_id() proposed by Keisuke Nishimura [0], which corrected a bug where only the first argument was checked for the refcounted flag. The test includes: - An update to bpf_testmod to add 'test_refcounted_multi', an operator with three arguments where the third is tagged with "__ref". - A BPF program 'test_refcounted_multi' that attempts a tail call. - A test runner that asserts the verifier rejects the program with "program with __ref argument cannot tail call". [0]: https://lore.kernel.org/bpf/20260320130219.63711-1-keisuke.nishimura@i= nria.fr/ Signed-off-by: Varun R Mallya --- .../prog_tests/test_struct_ops_multi_args.c | 9 +++++ .../bpf/progs/struct_ops_multi_args.c | 35 +++++++++++++++++++ .../selftests/bpf/test_kmods/bpf_testmod.c | 7 ++++ .../selftests/bpf/test_kmods/bpf_testmod.h | 3 ++ 4 files changed, 54 insertions(+) create mode 100644 tools/testing/selftests/bpf/prog_tests/test_struct_ops_= multi_args.c create mode 100644 tools/testing/selftests/bpf/progs/struct_ops_multi_args= .c diff --git a/tools/testing/selftests/bpf/prog_tests/test_struct_ops_multi_a= rgs.c b/tools/testing/selftests/bpf/prog_tests/test_struct_ops_multi_args.c new file mode 100644 index 000000000000..0f321e889862 --- /dev/null +++ b/tools/testing/selftests/bpf/prog_tests/test_struct_ops_multi_args.c @@ -0,0 +1,9 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include "struct_ops_multi_args.skel.h" + +void test_struct_ops_multi_args(void) +{ + RUN_TESTS(struct_ops_multi_args); +} diff --git a/tools/testing/selftests/bpf/progs/struct_ops_multi_args.c b/to= ols/testing/selftests/bpf/progs/struct_ops_multi_args.c new file mode 100644 index 000000000000..c62be15757f0 --- /dev/null +++ b/tools/testing/selftests/bpf/progs/struct_ops_multi_args.c @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2026 Varun R Mallya */ + +#include +#include +#include +#include "../test_kmods/bpf_testmod.h" +#include "bpf_misc.h" + +char _license[] SEC("license") =3D "GPL"; + +struct { + __uint(type, BPF_MAP_TYPE_PROG_ARRAY); + __uint(max_entries, 1); + __uint(key_size, sizeof(__u32)); + __uint(value_size, sizeof(__u32)); +} prog_array SEC(".maps"); + +SEC("struct_ops/test_refcounted_multi") +__failure __msg("program with __ref argument cannot tail call") +int test_refcounted_multi(unsigned long long *ctx) +{ + /* ctx[2] is used because the refcounted variable is the third argument */ + struct task_struct *refcounted_task =3D (struct task_struct *)ctx[2]; + + bpf_task_release(refcounted_task); + bpf_tail_call(ctx, &prog_array, 0); + + return 0; +} + +SEC(".struct_ops.link") +struct bpf_testmod_ops testmod_ref_acquire =3D { + .test_refcounted_multi =3D (void *)test_refcounted_multi, +}; diff --git a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c b/tools/t= esting/selftests/bpf/test_kmods/bpf_testmod.c index 94edbd2afa67..297b02372fa6 100644 --- a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c +++ b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c @@ -1411,6 +1411,12 @@ static int bpf_testmod_ops__test_refcounted(int dumm= y, return 0; } =20 +static int bpf_testmod_ops__test_refcounted_multi(int dummy, struct task_s= truct *task__nullable, + struct task_struct *task__ref) +{ + return 0; +} + static struct task_struct * bpf_testmod_ops__test_return_ref_kptr(int dummy, struct task_struct *task_= _ref, struct cgroup *cgrp) @@ -1423,6 +1429,7 @@ static struct bpf_testmod_ops __bpf_testmod_ops =3D { .test_2 =3D bpf_testmod_test_2, .test_maybe_null =3D bpf_testmod_ops__test_maybe_null, .test_refcounted =3D bpf_testmod_ops__test_refcounted, + .test_refcounted_multi =3D bpf_testmod_ops__test_refcounted_multi, .test_return_ref_kptr =3D bpf_testmod_ops__test_return_ref_kptr, }; =20 diff --git a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.h b/tools/t= esting/selftests/bpf/test_kmods/bpf_testmod.h index f6e492f9d042..863fd10f1619 100644 --- a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.h +++ b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.h @@ -39,6 +39,9 @@ struct bpf_testmod_ops { int (*unsupported_ops)(void); /* Used to test ref_acquired arguments. */ int (*test_refcounted)(int dummy, struct task_struct *task); + /* Used to test checking of __ref arguments when it not the first argumen= t. */ + int (*test_refcounted_multi)(int dummy, struct task_struct *task, + struct task_struct *task2); /* Used to test returning referenced kptr. */ struct task_struct *(*test_return_ref_kptr)(int dummy, struct task_struct= *task, struct cgroup *cgrp); --=20 2.53.0