Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2363638lqp; Sun, 24 Mar 2024 15:55:15 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVZF1MYPtTERVdnDwLfIwy2+BS1jzKPN3NvaQGHGSckO5Kq5FxjOBMkfqzCTvk+zZ9aVHhS1veZMf2VSnhm1KiYMEuKPoCXEMYovo/xpg== X-Google-Smtp-Source: AGHT+IGHgZz5KwooQNXryE+71qn18TqRvhTNEHWieXkwrlSYRndgwNGstBG9rCysl0s8EqTwZMHt X-Received: by 2002:a05:6512:2083:b0:513:a738:20f1 with SMTP id t3-20020a056512208300b00513a73820f1mr4407514lfr.25.1711320914991; Sun, 24 Mar 2024 15:55:14 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711320914; cv=pass; d=google.com; s=arc-20160816; b=CY7U+AuGnChrJgbbrkxEHKSLC1C6+LfG4Y2TcCNSzpao0ZUnjPwX+TQdMhyuwhhkuw FA4MZ0yNvS1v/u4LnjhmxHliF+yyqwXGQ00ce7lzUnVVtZIngwRIGqbF3I9IX9KclD5L OB8ac7YcFQamAoM+gb7qb00IECtxbBc96OWenSq1+Yt/Svm30/7l/tubFVTFB0HBxiTe IRgzJR5P5SSAqLElGeizs1T8LANrZIjf2JiRSqEqrrOZt1lw/u6khdE70pUcQpJvblHf l+gpHuPIru5/GMkAgmXlQ1e0qPqXii1zQnrc4gPie24eAkQfgqHLw9fOtwdkv180HQHC mIfA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=tm3e+Cc6gJp37if7z1E8QwcvG+HX55JTJpwE/tFk5Dw=; fh=6o8V2wLEb3XnYs2Y6EVkL42pIxNFOcNMRw/G9/GDt1s=; b=hqLwbmHmKVLTVBANOpME528kgObAE9JXANPewA9nHkNZAfr2VCDyoCgWKFBwUmlhOw JC8qrpuwII7LyDKEm7JS0DKvuPkODtTu4vKkbvjVQqMoALbzLl9+DvQb/mTQ7PI7ou1g YmfjFWBeINEWKNavfEX5X/CgAZnejKJcirJvtv8L5brA5LIpa1KFNJP6QmgBfqlFp9Kb 70HMSqQEFHh8Y8HuNcx4kGQQPqOtyi6KYa97K+AagdrKzCfE1gy8K9G1APk4ZL7sh3IR Hnl22qH3722aEBz8emWv0L2NLB0P5KWg9rUww3zzn8AQlZb1JW3ECn3TQR6nLKFbBpSj G2VA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kltgbURj; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-112971-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112971-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 11-20020a170906318b00b00a4659a27d65si1942180ejy.846.2024.03.24.15.55.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 15:55:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-112971-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kltgbURj; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-112971-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112971-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id AB2FA1F216B9 for ; Sun, 24 Mar 2024 22:55:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 971FC12A17B; Sun, 24 Mar 2024 22:36:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kltgbURj" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE24F12A163; Sun, 24 Mar 2024 22:36:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711319783; cv=none; b=jdMVUXQar8iXlOTRKFZVbrxmOOicW/kmkf/+o4JEFfVf4G8KYKBwmHq/SZsF7YGFx9UVPd1/Id37NZWqBCkkJj8VPV7GUr9gQKhQAcx/cj4Qa2bwS0ZciNwIuXeH+xJcadibzpUbFW1SWFiZn66lPiZl+0Ch56Jvv5wdTyqQLAM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711319783; c=relaxed/simple; bh=S5lSRSEl+8Ri8IPAHVMzY1VhWNuSPB/Hjn9uxUE1cn0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VxPLAnwK0+iSSsuvL2F5nyLkPnCzxBOfDeByinP53L75n4QRHKpBguPnX5cS+xFkGl7cCNNSsaodfwEwcVDvc/2GMv5Ype5rFOoq5XsyOOarxGnxdPNm3Vpjhyuj9QLiGSs6qwgP8EgVJ4OCfFoN3kgiqMPZPc0ogPPjQvERQNA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kltgbURj; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 64B33C43390; Sun, 24 Mar 2024 22:36:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711319783; bh=S5lSRSEl+8Ri8IPAHVMzY1VhWNuSPB/Hjn9uxUE1cn0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kltgbURjUKeboxIP1kBM8O1ZHWmCE/sqLWloRTlDeFhffeJ97j/43s2nTKPyaX1Pf p2McEbfHzcjcwkgIIVeP8ZbCN0KLUphB4LNvchyzgz6nqmVFJJLDiV+BCxvBh2Yd5k FNYE0SlvLlQyefmnVZ0KpSM+vJtLOTv6+0Otm29Wr7yBO5sUAj2SruFjLUXKWr4VKJ B9nbU94c78168yLbr+4Qq1251c1xpGC4pcYzI7MCvDFkE9pD3qVSoVTvCt4jHYcOQz mldvqBV5uYolCM6v7JczMHEblqht45cjJCmu+FAygghJRNPRjMv8RKRUTenGGTVkdW O4PtQLbJxQ05w== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Artem Savkov , Daniel Borkmann , Yonghong Song , Jiri Olsa , Alexei Starovoitov , Sasha Levin Subject: [PATCH 6.8 084/715] selftests/bpf: Fix potential premature unload in bpf_testmod Date: Sun, 24 Mar 2024 18:24:23 -0400 Message-ID: <20240324223455.1342824-85-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Artem Savkov [ Upstream commit d177c1be06ce28aa8c8710ac55be1b5ad3f314c6 ] It is possible for bpf_kfunc_call_test_release() to be called from bpf_map_free_deferred() when bpf_testmod is already unloaded and perf_test_stuct.cnt which it tries to decrease is no longer in memory. This patch tries to fix the issue by waiting for all references to be dropped in bpf_testmod_exit(). The issue can be triggered by running 'test_progs -t map_kptr' in 6.5, but is obscured in 6.6 by d119357d07435 ("rcu-tasks: Treat only synchronous grace periods urgently"). Fixes: 65eb006d85a2 ("bpf: Move kernel test kfuncs to bpf_testmod") Signed-off-by: Artem Savkov Signed-off-by: Daniel Borkmann Acked-by: Yonghong Song Cc: Jiri Olsa Link: https://lore.kernel.org/bpf/82f55c0e-0ec8-4fe1-8d8c-b1de07558ad9@linux.dev Link: https://lore.kernel.org/bpf/20240110085737.8895-1-asavkov@redhat.com Signed-off-by: Alexei Starovoitov Signed-off-by: Sasha Levin --- tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c index 91907b321f913..e7c9e1c7fde04 100644 --- a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c +++ b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c @@ -2,6 +2,7 @@ /* Copyright (c) 2020 Facebook */ #include #include +#include #include #include #include @@ -544,6 +545,14 @@ static int bpf_testmod_init(void) static void bpf_testmod_exit(void) { + /* Need to wait for all references to be dropped because + * bpf_kfunc_call_test_release() which currently resides in kernel can + * be called after bpf_testmod is unloaded. Once release function is + * moved into the module this wait can be removed. + */ + while (refcount_read(&prog_test_struct.cnt) > 1) + msleep(20); + return sysfs_remove_bin_file(kernel_kobj, &bin_attr_bpf_testmod_file); } -- 2.43.0