Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp442823rdd; Tue, 9 Jan 2024 08:43:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IH7KzD71if8G0+AOeEGHF3H+qH5opSao0X99b3bLt+1Kg2SHU4YecaYGhKUdwhonMfZ412f X-Received: by 2002:a05:6214:2261:b0:67f:5db:f4f2 with SMTP id gs1-20020a056214226100b0067f05dbf4f2mr7520242qvb.52.1704818627233; Tue, 09 Jan 2024 08:43:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704818627; cv=none; d=google.com; s=arc-20160816; b=wkLy/B4jg8mZBJbqhSBF+PNaA69/uhvkIlKCvYXxKTMJKhY5o/J++DE3Vw4En+gmvp OB7RPH7ssvnCdSMJnNsY/Uqcy2TwFFD0v+cJwupIwRNL734OM6epHxfv3okmoKvKSUb8 dgFPc7HoxxrbD1QlhhMlHnGPX7cvwA+Ooj8Es3nYttrO/LQV2I7R4rHYhUQCdCbaCQUz 6zOJonu+FCwnsHxX95Jr9AUmNgOhp/XGUPJlaRlxMJN85gW+p6TKgQz5rfsoGnDi8dS7 c4nn+CG0Om8QcdQc/v1Omq3p6+C3YdBV3F95S5o2ydg331mBeZuvUWiROYDFCRtwGaRx UIzg== ARC-Message-Signature: i=1; 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:message-id:date:subject:cc:to :from:dkim-signature; bh=nwZE6djCSMlJ+VRm2x3lAYqf79cV0k+KDTXbOaHEb1o=; fh=bEJ5O7v4tXTst3cJEb5TGX8sFhAOKh+R2nG8r5Z27K8=; b=JDKu65nVG7KUHLasnfPYnmLhEXwVSGnqcvBOUGSsJKYPP1uAdg8sGUtcPssV2h6dn8 WymTsM92okHvbtKiXnE9vrnyLch2uO0LFRxYDYb3bQs6UsimASqo7DovjhNZRJSQFIo2 44km1WVxXXfN6p9Vx/Qae7pt/QFOTAZr1f/h6c60rrW06bmQSG1NdXV/BsjAZRGtQ7FZ yGGPg4Vj4dDh89j7oT8oqcS7RM7LRxshUlNIafU8BzhsJ9Qc5lIIJ/lnTnQrrgWFo1jy +wBQvqy/Ey4BR5vEGNDvTreoOQ17h08rMpluqTqJe6+6NYtgyWvthHydlTLmh2w/cRhB ICiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=feTCm2m0; spf=pass (google.com: domain of linux-kernel+bounces-21121-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21121-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id b18-20020a0cc992000000b00681035928fasi2577928qvk.555.2024.01.09.08.43.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 08:43:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-21121-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=feTCm2m0; spf=pass (google.com: domain of linux-kernel+bounces-21121-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21121-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id E048C1C24864 for ; Tue, 9 Jan 2024 16:43:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CA8693A8EA; Tue, 9 Jan 2024 16:43:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="feTCm2m0" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 867273A294 for ; Tue, 9 Jan 2024 16:43:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704818605; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=nwZE6djCSMlJ+VRm2x3lAYqf79cV0k+KDTXbOaHEb1o=; b=feTCm2m0+b/XMGBuOqq6rmm3iWrRpLQEhrEHXujPnQeZb2gwPO1d4TWgEl+Mk9HgRVpTyA Q4WfRm1JJeRS52AaApgr9uoBzzZyjO1gFe+YdTEa+b8/1mGj2EwxCTbsfrCt4r5BsKbR9y cjcrUsDzPttr16INLX13dTWv2E9Fh2c= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-140-q87lt0BTMCS_eqIMFxCJwg-1; Tue, 09 Jan 2024 11:43:22 -0500 X-MC-Unique: q87lt0BTMCS_eqIMFxCJwg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DEADA1C051A0; Tue, 9 Jan 2024 16:43:21 +0000 (UTC) Received: from alecto.usersys.redhat.com (unknown [10.45.224.76]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0E22B2026D66; Tue, 9 Jan 2024 16:43:19 +0000 (UTC) From: Artem Savkov To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , bpf@vger.kernel.org, netdev@vger.kernel.org, jolsa@kernel.org Cc: linux-kernel@vger.kernel.org, Artem Savkov Subject: [PATCH bpf-next] selftests/bpf: fix potential premature unload in bpf_testmod Date: Tue, 9 Jan 2024 17:43:17 +0100 Message-ID: <20240109164317.16371-1-asavkov@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 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: 65eb006d85a2a ("bpf: Move kernel test kfuncs to bpf_testmod") --- tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c | 4 ++++ 1 file changed, 4 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..63f0dbd016703 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,9 @@ static int bpf_testmod_init(void) static void bpf_testmod_exit(void) { + 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