From patchwork Mon Feb 5 05:56:45 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: 13544994 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-ed1-f65.google.com (mail-ed1-f65.google.com [209.85.208.65]) (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 45B47BA22 for ; Mon, 5 Feb 2024 05:56:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.65 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707112613; cv=none; b=tXD1SXpk6Oz9fXWky+tBpLp4HtJ864uiCERshD3uSxruP4EVyWEUjM3rDNFe4nR8fH8h+91hq33Rtsxj3fAoQX4OFBNHJh5FdIftaCm8tnk0vwcMG3Zq2WldbC8We1IhGMgFtoWH5WA+SymH6rCEEDTK+CCcDGX/cch5X3zmxic= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707112613; c=relaxed/simple; bh=izf/2Br1SywPls5d/eso9728cVQxXGhwEd0AVvcYmA4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pAvDN1uaCG9uEXYTX/7sgnjAVjbClISsvQMDIGhab/LE0ol+d3ftLZ62Tos37oWbD7OjXGIkcVtRUrcHQd+wVA3jxGfciFzEEvGHAlYQ1g1CrRcxgWfR18exIb/5lrE7BtmOeM3Xpq2hFCKqZ4NIBjRI0vrPc5Mf6fE3N8ZwcVI= 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=kQRUBouF; arc=none smtp.client-ip=209.85.208.65 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="kQRUBouF" Received: by mail-ed1-f65.google.com with SMTP id 4fb4d7f45d1cf-5606f2107ebso606825a12.1 for ; Sun, 04 Feb 2024 21:56:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707112610; x=1707717410; 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=cr05milfNRiA7y5yelFNvnWvkanfWghTvjzm1/74DEY=; b=kQRUBouF5fj454J3MjrgnSCk+B/cw3t5Z0DPYeQ9yCMpWHJNzLe/QnsYX+MdU28paU E0m8b7ePJ1TR8Tn0OPbsXevZHxd5qrT7t7x9+rVJFY7o12c3B6jShfsAEd/pCilZmRvW QRpNH9EvEqEaGkMN9lVduZdMdRoK+2Z9GI+VLt4jn7lDIp6aFANJG27USD+F1/PdHXdc FIxaSC69ul4l/nG/LIwo3YPZA3jFx/IIqzq/AKq0uaVKzwLC7T71tna3diHULJIEmLBI AQGq1Z776jYGfhBFVj1rxeLk0IpLMMbgSAyaNBUi/RwmPxCKOQjmRD/Pxe7NWlsIgjW8 j3nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707112610; x=1707717410; 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=cr05milfNRiA7y5yelFNvnWvkanfWghTvjzm1/74DEY=; b=rWsLznMIPSnTst1tcbF6SnqJ1KkxcTKFuLlwj5Ul4w1pEzLBx942/pGotwwkw4OtzC nFgxWekUKvSZZH4c678CTpiA3uK+FIpdMmRgGTpcRcRaPIFKachU9k9XHQPNAGderLe0 F3Q8eEt1Wx/5Mhg74b+PelUQUIh8QeQLXZ3+baLLtuzbu6iTiohC+zpfT7eqavd1QgTD s0PN1RLA4wqB2LD78fCY68/wQLIah3fmgvI6en6GIasmwYckuTfiM1IDcTj2XiJhVVyz IWGzbR3A5YiXI7LjCM9XKfu4ooARb/7Fn0X288OMtGymFMKW/I/vH44dzSvX4PtNT7Aj DmbA== X-Gm-Message-State: AOJu0YwX0Aauvbd5VcxogHJ1CTa9Nkg4xSOij6OBVg+NVC4tzGMdFdOI urlk6ZP9tmqPMHIA6TczKNmozwYqXMWlELRoQdFRSUcUWNn3oLg4JAKvtI92NIA= X-Google-Smtp-Source: AGHT+IE5hBXa2yOTHpQve+0PQk9UVdR8Xfed/XYuYX410AnXMAQOPOWw8MlbcxzxLc3/1+2XsB2aNw== X-Received: by 2002:a17:906:2b12:b0:a37:e824:e3ca with SMTP id a18-20020a1709062b1200b00a37e824e3camr33846ejg.0.1707112609586; Sun, 04 Feb 2024 21:56:49 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCXy35YhkT8LYyp4Bs69rOeixhhzvHRnREn4+T6ZMIuvTYCN8K43KAbmPEkcp13ZJGgWrxqIc8L6tsA8FlYTSnAoxIQ0YqGBZJEdfBSPc1tsegHTMgo9dEllQ10r+7A9/C84aK0PGNZAXy46hN0aH0g3WSmmW14DwfIbquE3plVoema8B3Ydp2DsMGmQG5/ou080CGthTRW7uGWW1LOt5o1JBrEVFSnS2OfRiZduGTRb19af1M9qj1T9RkmU2A== Received: from localhost (nat-icclus-192-26-29-3.epfl.ch. [192.26.29.3]) by smtp.gmail.com with ESMTPSA id sf5-20020a1709078a8500b00a373202928bsm3015546ejc.8.2024.02.04.21.56.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Feb 2024 21:56:48 -0800 (PST) From: Kumar Kartikeya Dwivedi To: bpf@vger.kernel.org Cc: David Vernet , Yafang Shao , Yonghong Song , Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann , Martin KaFai Lau , Tejun Heo Subject: [PATCH bpf-next v2 1/2] bpf: Transfer RCU lock state between subprog calls Date: Mon, 5 Feb 2024 05:56:45 +0000 Message-Id: <20240205055646.1112186-2-memxor@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205055646.1112186-1-memxor@gmail.com> References: <20240205055646.1112186-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=1539; i=memxor@gmail.com; h=from:subject; bh=izf/2Br1SywPls5d/eso9728cVQxXGhwEd0AVvcYmA4=; b=owEBbQKS/ZANAwAKAUzgyIZIvxHKAcsmYgBlwHiNPtxb8cuSGU9VzIY9AP1Nia5hm4t5GsD0O mFE42lkOGiJAjMEAAEKAB0WIQRLvip+Buz51YI8YRFM4MiGSL8RygUCZcB4jQAKCRBM4MiGSL8R ygK5EACTYfhivHUDWZFamwoO4fIv0ptKrpiBto08wsS4WURUdkTK3A0jT4aop93Xle8IMmWj7dW AfbxEkrszNx7fZzmK5vkvVkW5VmUyD6DITsbYngLB53KO5/wU3pFa06m8zhm43MDhmb04TgG5pD 95G8e1sYU9KGpePVcDI1KGrGZ1MJ3wtQj/GoRznD0853OppQkH9J2X6A5oU3byL7gXpTdtdhKOp H7g4qj0RYWxYDINn8BsoAlEbGRRegSHa9t3LVoL8P9R9IYGFIbPrX6eSS6ZfIqocI4sZHKreJAp 4j/aFQr8bdFtAw8e5STHqYoXDiFv8GMkxlJzVRLXhYg0B4fTM8B3+YFSrV0yVtghDR8CuVcEUwz a8ihThuxx/wzomHX2rBYF3NduCYUr9aAmx+H85aJRYs+/JgLtxbu4470LN38H1zqUKft4g2aJpQ nI6SGtR0GejADxM+RMQQHBSLUtwdQioojjAbTBTWHfMswvUMg6YTgCWrPYMGOvCRZ+SZzo2UW7D 8IW3rR/JE7jyjGXgPj4+KjSed0WVPoh3TdEYoKsBCj8DnJt+9jlbHx5AOKvKLwaGphNXgdyxsfT SSv7eIjwLZH15rSMCMyCPHzeQhDu54Gb1rd9Y3/zJz6Ll8zozzBcz3vdlszI+TOyJyK39tHWm8Q 7V5EXiM70A4bXJQ== 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 Tested-by: Yafang Shao Acked-by: Yonghong Song Signed-off-by: Kumar Kartikeya Dwivedi Acked-by: David Vernet --- 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 Mon Feb 5 05:56:46 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: 13544995 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-ed1-f65.google.com (mail-ed1-f65.google.com [209.85.208.65]) (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 15FD7BA2B for ; Mon, 5 Feb 2024 05:56:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.65 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707112614; cv=none; b=HcLicEEONxI/kKnJ1aUmgIMdZEdw0DIH44vyalITt210bUQFXm1fC8RSaJ7hQ/UIpeRxmPDbBaQ3CGy9o6ObS3nYluIIyJmU90oRHZ8kQGWckWes0SIc9y15U4GcTeE+UnP+ap1vhVUO0zRKSrqAI8gQtOFsyk1uuPERxeShSIA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707112614; c=relaxed/simple; bh=uPolwFOWZrLSR7ucnZw/wszGGQLzlNk8nHmYIWHlCOk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=W38pBWzVXNw7Q7sV8IxPjQ/8gA9F6cdg5ArplXZmo0o2fmY0+neUoQT8Ku8Zqd8akNGJZImhmG/J1F/7TvmRNrJb3eDhpW7+x+qnzyEWJVvHNw+9jODXxwOyQSsBvvabDXD58EixApGfW4QCFfgvns/7daHGflSYZCPkQsJyeJM= 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=dY/h711c; arc=none smtp.client-ip=209.85.208.65 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="dY/h711c" Received: by mail-ed1-f65.google.com with SMTP id 4fb4d7f45d1cf-56001d49cc5so2500037a12.2 for ; Sun, 04 Feb 2024 21:56:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707112611; x=1707717411; 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=CdhiqsY5bgO5ntSsFoFWqk97+TR+0qV2jK0xfkBgUyA=; b=dY/h711cxbFMEBaeCUJg5hUDcestYijhTzAFhLnpl02m2xNzEDuttviz+6w54N6QB1 uFdPlbSRSUaMPhGPKOsZFKYgTRADSoT76td3A5cIWjfbRmQESL9h6EIpqPw8JV6LRUwN 37o4A52GjhggbDLNBvTurBGWZ5dNEkjW2lXgEbuuKvmjKExqntiTutPZPnu/Gy3lEWjM HcRDGE/kOCIaDnNLF0qLZ4Mgs3Am95mCnmLA0/+kfxg/jmePW51njss6HP7BbR+QPHpA uzJW7/yEpprwyzXkJpOSVEdVSlf8JH43mBX1oNgdSGhvEVcCgZHciEiy1W7bB6dmmHr9 wufA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707112611; x=1707717411; 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=CdhiqsY5bgO5ntSsFoFWqk97+TR+0qV2jK0xfkBgUyA=; b=hg4DxgpIFkGQ+j65ihrLitTjHR90ExD6u4JByp7iLQW/Olfhat3GxdSH8ok58eFmcU SL2DNbIL1eFkbaEY/BApQtZRZi6yFcQyDo4XtlAhaKjn1eFOBDw8IPkVpoC71GVQjBCU kmadFYfAfaJRQbWwMOac/UyxxlUr+IsqojTPirhrM1G46NS6vrsYdQ0+OY0ALO6vonx0 m7+0HTTLX1ByoGBkp35BQgmc126HQ2zUk+SyV5efF1SmI3mnZtxprWy9Z636Mw1tjhWW R0LECKAV41EskVyEVf+cJHk+fbELjDptPofZT+6mMFYGwOmBkgtpdC7oyA+WPEWklarL XHZA== X-Gm-Message-State: AOJu0Yxtg3JG1bWa1Dn/CXDKy1wVwL8cZ2Dc0h0+wgNC903vaDJH0o/P 8/O1LePY65m0XS06qwY5U6WnSd1ItSpaY9ROfarf91fWH/MGuzgwXP261Y6HZRU= X-Google-Smtp-Source: AGHT+IFhYAZ/DNJz8hyDy112/NYb77iK8VZWHecgf0dsx3KCUiixzBAoWpb5aR+KQESEUHMI/rCfHQ== X-Received: by 2002:aa7:d804:0:b0:55d:3d64:3ba6 with SMTP id v4-20020aa7d804000000b0055d3d643ba6mr4222322edq.29.1707112611063; Sun, 04 Feb 2024 21:56:51 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCWtqcVSAiz86Clts7jC0UT78pnwUwRG3wWlhshYExK/5YMBr3Vp6g7kLs/eF1bi2ZdNakblnW64j1P0+vYKxeIZyMFBGqHAsjOvBc04gq6Imim7ItDq7/K2w871NVdfIJgEFyS8hL4H1u25q5DRJzXFYTgWY2GWT/3QwAP6MiGf0YcOkm3uYA2fim57akOqV+hUyZ68bokWhWpH9LITiTX4p6k8zuQSwX6dJ9j2qRgcBzxcDQgDjRQ= Received: from localhost (nat-icclus-192-26-29-3.epfl.ch. [192.26.29.3]) by smtp.gmail.com with ESMTPSA id ek23-20020a056402371700b0055ff9299f71sm3099676edb.46.2024.02.04.21.56.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Feb 2024 21:56:50 -0800 (PST) From: Kumar Kartikeya Dwivedi To: bpf@vger.kernel.org Cc: Yonghong Song , Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann , Martin KaFai Lau , Yafang Shao , David Vernet , Tejun Heo Subject: [PATCH bpf-next v2 2/2] selftests/bpf: Add tests for RCU lock transfer between subprogs Date: Mon, 5 Feb 2024 05:56:46 +0000 Message-Id: <20240205055646.1112186-3-memxor@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205055646.1112186-1-memxor@gmail.com> References: <20240205055646.1112186-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=4617; i=memxor@gmail.com; h=from:subject; bh=uPolwFOWZrLSR7ucnZw/wszGGQLzlNk8nHmYIWHlCOk=; b=owEBbQKS/ZANAwAKAUzgyIZIvxHKAcsmYgBlwHiNS70kPLLBLij5xB/QsDpmavWdRD2HnmtRE /IM8yJuTb6JAjMEAAEKAB0WIQRLvip+Buz51YI8YRFM4MiGSL8RygUCZcB4jQAKCRBM4MiGSL8R ygcwD/oCAcrr3bDu4DeZimVd7PCbTsXafwyh88g/tCVu3itx24m3rCCh8VDA2GoZoa1CPU678M1 keS3TrejyQY7WbyBKFSH9zl0GsHsD47W4Iw+Pc7Rie/N918aMrhy8XAPxKoRDuOCTBYFV+X4C3q j5fUWo1gIxhKDCN4/F8mslxvnEmQjkJBa0HiKkH86FieebFyRT3gFLZOOae5YHUWCr2p80QPJE3 WfTyMP4zOz7yv9NBffCphhx/07y+EG6dqMnI8JQM2jFya8StVhlvBh0rqv/wBT4tB6BVK0h3ISi xPmKrb4UIGAbn6HAIS9lMveg89MYRt6hgM2uq0xYNIZytr/MdkKDW5ly0thTnKe/shNOcjlIFBJ P5gW3tS2sKeJl+hNZEvATxGlNLKmQnduvlP+mibvRkhA9domAG7DVaV9XWmR05TwuqdilB7WSnz rZQSRtNu58HQ5vbIkezsG8PuNt0dNqQHpEFsZhwTNIBsh9+K9xECXzKFLoJ8/VVXXU3ZHm3quxS 8oBZqP78vLFtq1Mi35LfqSKDfvWrwank02Dv4TyvrgYrU+lIIXOEWqIjRDT4tGqRx8S0JC2KEga 0fvsRf+wMvR3+rodC4bUTodahbmuB/YEbqy2NTlB/t4gqRiNYWIaYM8CpmlXyto1ODqzsrLa3HR EegHBIh2ibgjeJA== 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 or global 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 Global subprogs that leave the lock in an imbalanced state will not work, as they are verified separately, so ensure those cases fail as well. Acked-by: Yonghong Song Signed-off-by: Kumar Kartikeya Dwivedi Acked-by: David Vernet --- .../selftests/bpf/prog_tests/rcu_read_lock.c | 6 + .../selftests/bpf/progs/rcu_read_lock.c | 120 ++++++++++++++++++ 2 files changed, 126 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..a1f7e7378a64 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,10 @@ 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_global_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; @@ -75,6 +79,8 @@ static const char * const inproper_region_tests[] = { "inproper_sleepable_helper", "inproper_sleepable_kfunc", "nested_rcu_region", + "rcu_read_lock_global_subprog_lock", + "rcu_read_lock_global_subprog_unlock", }; static void test_inproper_region(void) diff --git a/tools/testing/selftests/bpf/progs/rcu_read_lock.c b/tools/testing/selftests/bpf/progs/rcu_read_lock.c index 14fb01437fb8..ab3a532b7dd6 100644 --- a/tools/testing/selftests/bpf/progs/rcu_read_lock.c +++ b/tools/testing/selftests/bpf/progs/rcu_read_lock.c @@ -319,3 +319,123 @@ 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 +int global_subprog(u64 a) +{ + volatile int ret = a; + + return ret + static_subprog(NULL); +} + +__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 +int global_subprog_lock(u64 a) +{ + volatile int ret = a; + + return ret + static_subprog_lock(NULL); +} + +__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(); +} + +__noinline +int global_subprog_unlock(u64 a) +{ + volatile int ret = a; + + return ret + static_subprog_unlock(NULL); +} + +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_global_subprog(void *ctx) +{ + volatile int ret = 0; + + bpf_rcu_read_lock(); + if (bpf_get_prandom_u32()) + ret += global_subprog(ret); + 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_global_subprog_lock(void *ctx) +{ + volatile int ret = 0; + + ret += global_subprog_lock(ret); + 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; +} + +SEC("?fentry.s/" SYS_PREFIX "sys_getpgid") +int rcu_read_lock_global_subprog_unlock(void *ctx) +{ + volatile int ret = 0; + + bpf_rcu_read_lock(); + ret += global_subprog_unlock(ret); + return 0; +}