From patchwork Sun Feb 4 23:02:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kumar Kartikeya Dwivedi X-Patchwork-Id: 13544866 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-ed1-f67.google.com (mail-ed1-f67.google.com [209.85.208.67]) (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 B449FBE58 for ; Sun, 4 Feb 2024 23:02:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.67 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707087758; cv=none; b=JdcSbHFL7ZCcodDHuZ33hPtwPZ3BED+Y0B7+m5Nf5Kz8Xueow9EwpqDvj+wVzrLbeJTocqbjBr7boak/blMdAC76nwU2/9xQf/cNQNy0tSU1TcKuL64sJHG12rCWzx0JJw3r6ghBssdDfCRovsOmG1UfpEFHe4WJMc4MhGvzglQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707087758; c=relaxed/simple; bh=Y5sEagRMtUu3cf9U/alxyUA+rjezKQ4qrByKo82xLK4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iZ9M0YwSrOvz1ikxdpWE0TmNE8UcbfiEfIVS9+hs/vg8BPZAsnaCxTLeebzFj2q4ChieLVt6mjYyF3+xPbl56gBFCBMV07I4NmGQtlNF93APhAyvDxbuqq+nqJIr5eZQskU4rFzlHiqZbsv67WITHmrVf/bROtY7wZWQ3UuEy78= 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=QJtWd/5W; arc=none smtp.client-ip=209.85.208.67 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="QJtWd/5W" Received: by mail-ed1-f67.google.com with SMTP id 4fb4d7f45d1cf-55ee686b5d5so5039840a12.0 for ; Sun, 04 Feb 2024 15:02:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707087754; x=1707692554; 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=/bV35qLxXpRlEdi7mclokQh7x+DCnPlJaBu7Zs3RypI=; b=QJtWd/5WmT21chdLaNhhNVj26Jpe5Px6ltosQkn52o6dh+IHWnOgdlestu0PWygsK1 06o4yANV1GL6VpEldB4fbQjy8thg50K0zLguNpTNFpBbUPj3ViF3FOHS66xxFTrejYe3 ixnvcRF0xNIKj9AziPlFlzZizw4WASJGCWxdBuykGaCjjNIbPXfzO20DYiBDGBiVRjen Jhm0E9YveLEKvZBxOni5iruPUJHJdryrLHF4P3LcDfohpOpTUkQA6F9X83iN8uFvaHdE e5PEe/ktiJby7ZdqOpQyZlLlL8pX8RLJikcywcg3NTaQKa2sW0UWaC+wgOjdSA4M+HYE l5Kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707087754; x=1707692554; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/bV35qLxXpRlEdi7mclokQh7x+DCnPlJaBu7Zs3RypI=; b=DkN06U9abITMZ7y0z5TGIhQSGWHVj8LWAHzu92uhjYqxv28ROTSeRL0+THNd+wjd00 G9/sXwlJsTCuVHAbptRnjQzhWDLOo4uzoU8d6YqscoxS76D3pG6pSQc+SVt6H0+dGKqr k8Ic65OgnznoQHY4OMTa5GJE35HNe2eEE/soIe4ibI0aIuM/mdldr6CAVxZ8vZ+Ur3yR qFfBadCwQJUaj+5aXiKCcDhvr1g8gjdbNBf/KEa2gUvh326wD7nKdF/1q/gOoDgGdoWQ 7IcSecEYuMe0zUzhFLOt4cP+DMFtMsfSQybdIT1eO3t8dHOdaiiXUTbrdJqzFMzXcXyO burQ== X-Gm-Message-State: AOJu0YyliZMmijScbFTSn2+BZFUkR/BmFLgkzEN3eO+yEupInnP8Xtco 0t2nbIxruLO7J8bSF2GGOeI85xMA2bXU/k7qbigqFQe8uVhyZ2RYOL/1SFyUTV0= X-Google-Smtp-Source: AGHT+IFHi8p7VTc0QAY/X1T4fNUwzzyr1i9Z/Jofr+YvvGN3qH7/3YDOO6H+XD6hIapNYbjZ7MlrhA== X-Received: by 2002:a05:6402:3416:b0:560:87f:3215 with SMTP id k22-20020a056402341600b00560087f3215mr3437252edc.12.1707087754104; Sun, 04 Feb 2024 15:02:34 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCV0VwJ89ylD9mEAWbYGaVp/2ooe9Xf8HimcAzaCtVkM4oEvTk/oEC9Q4Y2HIzD2RSzAqAvw7mWYVlptu7CopQrz9MEo7xoI3mbdun19E1SEyK1LMHJjmvo7Dna6LZj3vedLfH6BvJEs9KkzDEhvXLx5Rf6QZdn6fs/v5+pCYrddbxEowHvjFoXWRb0bu+QLY7oHOodvdBRczgmK6PXT6tlDpEcdDDaV Received: from localhost (nat-icclus-192-26-29-3.epfl.ch. [192.26.29.3]) by smtp.gmail.com with ESMTPSA id v23-20020aa7d657000000b0056020849adfsm1881172edr.26.2024.02.04.15.02.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Feb 2024 15:02:33 -0800 (PST) From: Kumar Kartikeya Dwivedi To: bpf@vger.kernel.org Cc: David Vernet , Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann , Martin KaFai Lau , Yonghong Song , Tejun Heo Subject: [PATCH bpf-next v1 1/2] bpf: Transfer RCU lock state between subprog calls Date: Sun, 4 Feb 2024 23:02:30 +0000 Message-Id: <20240204230231.1013964-2-memxor@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240204230231.1013964-1-memxor@gmail.com> References: <20240204230231.1013964-1-memxor@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1441; i=memxor@gmail.com; h=from:subject; bh=Y5sEagRMtUu3cf9U/alxyUA+rjezKQ4qrByKo82xLK4=; b=owEBbQKS/ZANAwAKAUzgyIZIvxHKAcsmYgBlwBeATk8jBgpvsCp5lsDq0axRXSCLbgN7meumU dcxDWG8mmKJAjMEAAEKAB0WIQRLvip+Buz51YI8YRFM4MiGSL8RygUCZcAXgAAKCRBM4MiGSL8R yuBsD/4qRAXgXZu319g2K2q5C17DDjyddcFUf/FgUWenMw9ZtQNFznJWE+kXIwi3xqTgAS9cjdb wgTp9vvkK5/a+fNxtfE++K/K2gYPwL6w1QxSFIixNpmzJJX3UcLv/deBWnuOeEKgMmsP/rjexot VEFKSvPIGHfYkKYYHOjgoA6HPHzLe6sBnPzRsh+H3D5CfrKaucGQFUsvMIilCkS6Aun9I+t+Qnz 6CDXJVzv+J4S/AoKd0JCN0G9JYbPEZTqG4Z32kviX8xjNz6X5BQfPQ0UceWRM3ooz/6r89XDvLn CQEuNkPgGqqpadBWL9mjuEsRUH0XpzkkZCF7QFQnIEWOTdQiT5ERX/9tPE/viDs7RV4DZaijSQz Kx04iH5ewfTWrsSJ4bJAOnc4pHFtcE4rqURpT8heQYEE7Aun3eGZOmQZvKWHwTkK4dgrRIdOC/a osrSJvnlj6PxG3Fwvub09qIs/vcRzj+cltdfrWJ9rbQr9wQ+jumqnhy42U2txxloaNNDGyMUBWz wLulwEbm4YO9xiDNFQjcqmD3boWraVDwfprmOJqJgkyR0RbVNLmacnq8y9QSoLhKopl1Q5D1YAB yYemEaGgIpVQCTH9IOdcBxadp8P6mgyQuPU2ghtWiihJovAXrJuNNrWboeXQKCFo+uQoE9Pbess qVOGKK0WvhsLffw== X-Developer-Key: i=memxor@gmail.com; a=openpgp; fpr=4BBE2A7E06ECF9D5823C61114CE0C88648BF11CA X-Patchwork-Delegate: bpf@iogearbox.net Allow transferring an imbalanced RCU lock state between subprog calls during verification. This allows patterns where a subprog call returns with an RCU lock held, or a subprog call releases an RCU lock held by the caller. Currently, the verifier would end up complaining if the RCU lock is not released when processing an exit from a subprog, which is non-ideal if its execution is supposed to be enclosed in an RCU read section of the caller. Instead, simply only check whether we are processing exit for frame#0 and do not complain on an active RCU lock otherwise. We only need to update the check when processing BPF_EXIT insn, as copy_verifier_state is already set up to do the right thing. Suggested-by: David Vernet Signed-off-by: Kumar Kartikeya Dwivedi Tested-by: Yafang Shao Acked-by: Yonghong Song --- kernel/bpf/verifier.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 64fa188d00ad..993712b9996b 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -17698,8 +17698,7 @@ static int do_check(struct bpf_verifier_env *env) return -EINVAL; } - if (env->cur_state->active_rcu_lock && - !in_rbtree_lock_required_cb(env)) { + if (env->cur_state->active_rcu_lock && !env->cur_state->curframe) { verbose(env, "bpf_rcu_read_unlock is missing\n"); return -EINVAL; } From patchwork Sun Feb 4 23:02:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kumar Kartikeya Dwivedi X-Patchwork-Id: 13544867 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-ej1-f67.google.com (mail-ej1-f67.google.com [209.85.218.67]) (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 2616F8BED for ; Sun, 4 Feb 2024 23:02:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.67 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707087759; cv=none; b=dElrNPYp8NFFN1MsPavlucjIChFCPp8yQkBXMP0Kc9oFj9PolP03o/H9d1bP0WYQ8c3FrhLpOsFA9O2plFkjAAYgNhwVHkS5SeyZrkZ1OoISnCHuijPnCHuCEKOwLbjXBaAMD1cjavfxHLs2vSNWaeOvOHBJCHll4HHnaynI6Hg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707087759; c=relaxed/simple; bh=kcoCOUAvN8uaN3f2XE2jamXmVxpANNdQmyUVm3sohRs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=P5NymiXBNxcW7UnrHEk+gZ7C5P2VVXZUE9hv1UAg09ZWceyFAjpm2sg0jXN3gkBE0uHJljJ3kfQYxWLaL05Pw9vsc/V+L+oayy3E0U4eP3M5Z2NI4CzMDD4yhFTbJfd8bsC9qxacBkjUHwXjPiWyj+9v5cd/jFh1H0z8lrpo9n4= 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=QsSSPCK0; arc=none smtp.client-ip=209.85.218.67 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="QsSSPCK0" Received: by mail-ej1-f67.google.com with SMTP id a640c23a62f3a-a3796032418so50055966b.3 for ; Sun, 04 Feb 2024 15:02:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707087755; x=1707692555; 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=dTTEhJ9kCTPFs/k8C02v/lZcWvhwj/Gv3hSJ8xCLEBQ=; b=QsSSPCK0v8UJUvfg9dUv6Ee5Jpv9YTR9KZxzyjV1UDKhdpz+r+WcuiSJI5eANiWvHF hI7r9AGCJChiCpbyh7HUkMfLKFpIAB9cnZ0uNg5YzxVSsWpf36jbIQqsS6ru4zWBEOk9 ivmakC+pT23paSkvjUFjk2DZbxgjhsWBZ/tP6e9fYKyrKwD7OYsQajD8DLtXZNRY6ziD ilbiFa74pyUY+Eba8tqm16HERc6BwXALoMmFb2v5Mfzae4tiNiszwtGVN6ICIoev7ESi yFjmToGKx2oJiu4ScdLkfPieNnWSPvFXQ7sDdskH6cn+aj+aGaDv35cgf+pdgpvINIF/ qvtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707087755; x=1707692555; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dTTEhJ9kCTPFs/k8C02v/lZcWvhwj/Gv3hSJ8xCLEBQ=; b=tYL3oepozHVb6m8YY6cALXuz4iPZwanD+A157w5QbRG/O3Fm7j57B9V3uYxDsDfEH+ e4nfNlMKSc1uorQMVOvCwugc4DB7PeFhg7RH5rIaxS10v8d2efagcoxzRZ4jhTZ4rgwY XY2wkWEmGsOAY9t8/e2M+xI2u4cBfySTvOZCea7t53lJVkrEdYSA+xBqCXp8qxOL8yT1 qItCBP4WAvSURwmdO1zNKLEIwxccfVMmh3Okhoh66qWPizWr/vNroC2io2/ODwkwLbKy 5k047yKeFWkgQavOQemORhhJDVF914QZ00HcLQluHV4KA53LPKA7gGpNG9L01he43aNS gTaQ== X-Gm-Message-State: AOJu0YzOswYHTPrWB+J0Xla5GOKEK9j7vWG3onlX8WyG0zePCnHaFWwu M6o2M5fTbdTeixP2Gbkr/uDlxAAs7txzAjQCyV4zKiCUIUv9HbNTQ1IBsLpc7D4= X-Google-Smtp-Source: AGHT+IFNhq28ooP3hyY7GaqGcUjBhpElF7ZXXEhh2E2ULTk5qTA6Yvjp5IuNrhv112OofDuhlTg6JA== X-Received: by 2002:a17:906:185:b0:a36:1c9e:9169 with SMTP id 5-20020a170906018500b00a361c9e9169mr5874893ejb.2.1707087755484; Sun, 04 Feb 2024 15:02:35 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCX/gZeidEhsuONbmBPzfSvKXRZaO9E4sJ3o9581q7FdlyTlchs0qblVEmlSwNsyBnLLPpMBZadncIk0PHyV0HcGqwH7rYAHy06VGJIF/9uh1fp+sBUzqzxCVPeCMcBmwMTnNTTKAplVmR+3bkrIsi4A57HeVQ6qEN9GwFWgB+VAKtdsVv3u1ZGwsmhZe4Qp7pRE5iFJyG5U6u59UnZByvLR2IbKR41991I7NA== Received: from localhost (nat-icclus-192-26-29-3.epfl.ch. [192.26.29.3]) by smtp.gmail.com with ESMTPSA id ps11-20020a170906bf4b00b00a3785efe1c4sm1334332ejb.85.2024.02.04.15.02.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Feb 2024 15:02:34 -0800 (PST) From: Kumar Kartikeya Dwivedi To: bpf@vger.kernel.org Cc: Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann , Martin KaFai Lau , Yonghong Song , David Vernet , Tejun Heo Subject: [PATCH bpf-next v1 2/2] selftests/bpf: Add tests for RCU lock transfer between subprogs Date: Sun, 4 Feb 2024 23:02:31 +0000 Message-Id: <20240204230231.1013964-3-memxor@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240204230231.1013964-1-memxor@gmail.com> References: <20240204230231.1013964-1-memxor@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2980; i=memxor@gmail.com; h=from:subject; bh=kcoCOUAvN8uaN3f2XE2jamXmVxpANNdQmyUVm3sohRs=; b=owEBbQKS/ZANAwAKAUzgyIZIvxHKAcsmYgBlwBeBaq0ENkEcVtJiSPaqy+6EPTy47UoSai95i e3wpfKfn3qJAjMEAAEKAB0WIQRLvip+Buz51YI8YRFM4MiGSL8RygUCZcAXgQAKCRBM4MiGSL8R yml7EAC+5FYgCOGk+p9bK4VEy/NtTzyfLEMvM7SISGIf8siEAcW5c9z7mBRz7l+yq+fykL8YIO9 X1H8q0LpUpAG3XlEY6PPQu7VJfSOmBx0f5elapb08mYs3ONRiW6ovCtMlTiCCe3+34YgCvM8KeM T4gv07NtlPl+QqmnWLMIT4grNn64znksE9LBMCDXBcnluZqjIxBHOPr3O0mS8B8WLpWsjlapD/m bCGteH92TjIY2BNGAe0yyR3o7qMXKJaQaT6Qz97M+kn+CbwhErGfJVZimi9MkoPJse26qiqBo/2 Tt/FHEosZLYG+5ub3N8DLpqFfvOM4FT9tJ/ae6Ki4yA1NqWgIUE7TqB2qiNoWpEftn0ZXp3Pgz9 H8BkzqdcpwHYUsYf35MQL8d/THAqnJEKTT1y1EC+Uo7CZDAtpnqCXIx3yvv3LeQvY0/szt/GEzV uIvVcLo8a8i7BZJvM/JynzSSA5iWAHty67d9Knhwod98jmnJ8ObyeyygdIPjmPv33Rh7BhqxHR+ CBAm7HAN88b0EetclfYHMsPyRfPRkTM4MPrue+DqBA39pcjYytaMnbH+74mb0S4rKUUorKYsVgH Pz455TfGpwJjsJAjRjJe/GVGs2nmHS/rS2l7Mi6FvpP+uazD1xWzcokBj0/r78+iwWCV2Y526SJ MCjn7mZ3A99q86g== X-Developer-Key: i=memxor@gmail.com; a=openpgp; fpr=4BBE2A7E06ECF9D5823C61114CE0C88648BF11CA X-Patchwork-Delegate: bpf@iogearbox.net Add selftests covering the following cases: - A static subprog called from within a RCU read section works - A static subprog taking an RCU read lock which is released in caller works - A static subprog releasing the caller's RCU read lock works Signed-off-by: Kumar Kartikeya Dwivedi Acked-by: Yonghong Song --- .../selftests/bpf/prog_tests/rcu_read_lock.c | 3 + .../selftests/bpf/progs/rcu_read_lock.c | 64 +++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/rcu_read_lock.c b/tools/testing/selftests/bpf/prog_tests/rcu_read_lock.c index 3f1f58d3a729..328a25e031d8 100644 --- a/tools/testing/selftests/bpf/prog_tests/rcu_read_lock.c +++ b/tools/testing/selftests/bpf/prog_tests/rcu_read_lock.c @@ -29,6 +29,9 @@ static void test_success(void) bpf_program__set_autoload(skel->progs.non_sleepable_1, true); bpf_program__set_autoload(skel->progs.non_sleepable_2, true); bpf_program__set_autoload(skel->progs.task_trusted_non_rcuptr, true); + bpf_program__set_autoload(skel->progs.rcu_read_lock_subprog, true); + bpf_program__set_autoload(skel->progs.rcu_read_lock_subprog_lock, true); + bpf_program__set_autoload(skel->progs.rcu_read_lock_subprog_unlock, true); err = rcu_read_lock__load(skel); if (!ASSERT_OK(err, "skel_load")) goto out; diff --git a/tools/testing/selftests/bpf/progs/rcu_read_lock.c b/tools/testing/selftests/bpf/progs/rcu_read_lock.c index 14fb01437fb8..687df026feb0 100644 --- a/tools/testing/selftests/bpf/progs/rcu_read_lock.c +++ b/tools/testing/selftests/bpf/progs/rcu_read_lock.c @@ -319,3 +319,67 @@ int cross_rcu_region(void *ctx) bpf_rcu_read_unlock(); return 0; } + +__noinline +static int static_subprog(void *ctx) +{ + volatile int ret = 0; + + if (bpf_get_prandom_u32()) + return ret + 42; + return ret + bpf_get_prandom_u32(); +} + +__noinline +static int static_subprog_lock(void *ctx) +{ + volatile int ret = 0; + + bpf_rcu_read_lock(); + if (bpf_get_prandom_u32()) + return ret + 42; + return ret + bpf_get_prandom_u32(); +} + +__noinline +static int static_subprog_unlock(void *ctx) +{ + volatile int ret = 0; + + bpf_rcu_read_unlock(); + if (bpf_get_prandom_u32()) + return ret + 42; + return ret + bpf_get_prandom_u32(); +} + +SEC("?fentry.s/" SYS_PREFIX "sys_getpgid") +int rcu_read_lock_subprog(void *ctx) +{ + volatile int ret = 0; + + bpf_rcu_read_lock(); + if (bpf_get_prandom_u32()) + ret += static_subprog(ctx); + bpf_rcu_read_unlock(); + return 0; +} + +SEC("?fentry.s/" SYS_PREFIX "sys_getpgid") +int rcu_read_lock_subprog_lock(void *ctx) +{ + volatile int ret = 0; + + ret += static_subprog_lock(ctx); + bpf_rcu_read_unlock(); + return 0; +} + +SEC("?fentry.s/" SYS_PREFIX "sys_getpgid") +int rcu_read_lock_subprog_unlock(void *ctx) +{ + volatile int ret = 0; + + bpf_rcu_read_lock(); + ret += static_subprog_unlock(ctx); + return 0; +}