Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp847066rdd; Wed, 10 Jan 2024 00:58:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IGArPUXYzQhR0Ao+6X/Fk5r9eSauEc7kEtx/DLM0tIMivCeghonqb1OuzDEI/HdCjuP+xIn X-Received: by 2002:a05:6808:d46:b0:3bd:4c0a:85ae with SMTP id w6-20020a0568080d4600b003bd4c0a85aemr196609oik.74.1704877083309; Wed, 10 Jan 2024 00:58:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704877083; cv=none; d=google.com; s=arc-20160816; b=xPBct5hn2M6otcpIl+FK6Fs/DjCe4eiola5pvJhoQFFCMS/cIKhycc1dc3hV7PeN7O 9DOTdMWjB7kmJ9/ERR7dJoJXaQR1kNVANXiyL0eQCWpP3xpiymXwnkkdqT9JKpHopK94 apC3oHlTCJbnWDx4qtv+tbl4GIdxpesH86w/tyX5B2Fx/VbHzlYNyVMyFMgGrC2j3cJg sbe2r0hJsOjKxeBIJ3tuIbRec9lYTbgOYYVxVkTrUv58syDr6i4xoXgju61uFmk22O6J ec4WjIjIXMymiA+Q5G8Muau9HUgnwbLnk5LEmHe/pkdo+9gZkAREsF0l8DHrDw+sh/mw agpw== 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=XsFJ64qhgo8dpCR3ZN8nHJuU62Q+ROyJhHepqFzOWSQ=; fh=LRaOpg/H2zZe4Sx/588ZcDqczGHtrV00FTW4paWEmxo=; b=Hz+y0/Eh9Z7PO70/TOxGlTiuL66hW/VgsqY750v/Oy1+x99nu/Z634rGxRtXXqEsUB nllcJZqvQb5mgdXGETtz2/FaoPZHODg2WzsVkSRUVuUd1cFKLRX4udiUI2M0BAPxTppz hVefvLITrC9ugvWuOeT8M/GKwITNqaQ/4uLDSnk6zt1Smhay5Y1itkIPF7MYXYskhgj8 j150pkRMVzGJy9SNX9w/QIg2iQZaoEMRb3G3oSb0jI3w/x4xGKiRmnbVtqfrl5kIDdF2 xIuza+ed3gKzordrZzQBehUWKZgFV2mvuKDcMDR9sa+JwZQPqNVGjsjlxTjPHefqjy7a xmkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="T/V2nNTz"; spf=pass (google.com: domain of linux-kernel+bounces-21867-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21867-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id j16-20020a056a00235000b006d9a562c7d5si3355618pfj.83.2024.01.10.00.58.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 00:58:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-21867-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="T/V2nNTz"; spf=pass (google.com: domain of linux-kernel+bounces-21867-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21867-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id CCFAA289908 for ; Wed, 10 Jan 2024 08:58:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CCF503B185; Wed, 10 Jan 2024 08:57:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="T/V2nNTz" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 CE4A239859 for ; Wed, 10 Jan 2024 08:57:48 +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=1704877067; 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: in-reply-to:in-reply-to:references:references; bh=XsFJ64qhgo8dpCR3ZN8nHJuU62Q+ROyJhHepqFzOWSQ=; b=T/V2nNTz1KkBmRf3HTfs/xzoALTkTkobeeYFxldshDdPfmGrMn2TUjEy28StCeYakuI/kF P2LYe5c0xNamY+MMBDR5mUmmsoBr5ltgaAdObtf71KsbHO2F1HkUroqdU767yzRSg27pqZ QC/rxTaFdraRsBzKQ2QS1Lt8xreT2Ng= 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-515-Rwth6r8GNb-AXO8Dgvsk6A-1; Wed, 10 Jan 2024 03:57:42 -0500 X-MC-Unique: Rwth6r8GNb-AXO8Dgvsk6A-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 185543C0F185; Wed, 10 Jan 2024 08:57:42 +0000 (UTC) Received: from alecto.usersys.redhat.com (unknown [10.45.226.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0A26BC15E6A; Wed, 10 Jan 2024 08:57:39 +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 , Yonghong Song Subject: [PATCH bpf-next v2] selftests/bpf: fix potential premature unload in bpf_testmod Date: Wed, 10 Jan 2024 09:57:37 +0100 Message-ID: <20240110085737.8895-1-asavkov@redhat.com> In-Reply-To: <82f55c0e-0ec8-4fe1-8d8c-b1de07558ad9@linux.dev> References: <82f55c0e-0ec8-4fe1-8d8c-b1de07558ad9@linux.dev> 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.8 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") Signed-off-by: Artem Savkov Acked-by: Yonghong Song --- 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