From patchwork Wed Jan 10 08:57:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artem Savkov X-Patchwork-Id: 186721 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp663724dyi; Wed, 10 Jan 2024 00:58:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IGf4QytB1nA+zbye/kEMmrRD5bOkXcdeAHrwTv71CbdadcIhA+vZs+sKsuZKRTZBDQ9+4v3 X-Received: by 2002:a05:6a21:279e:b0:199:729f:bbdd with SMTP id rn30-20020a056a21279e00b00199729fbbddmr339739pzb.80.1704877091027; Wed, 10 Jan 2024 00:58:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704877091; cv=none; d=google.com; s=arc-20160816; b=AZ/c9MRFxxHGMpR+/ZoWRIFS7avzqo4YnHZu6KN2N4KXFfW+w9U1h9hsGAbiqJQqzs hpeaF8QKTnqKAsAoFAsvU1KeyPi5Z5Gt0HnnXcV22hxzvkTt7Cw2whGLHLO+xpbIslpn 9uNwmy1Hxhx6muiMPigpVU1Y+MOCnVD0ABbi8JiJkx0PWymYSxSRTZ7FWCYhJ7EzXKnC J76LwhbKe/aTaNhaEDaMxWbNI+qB/4fvQD+FdUA1xV0YbFDK+amtWgqpBq9eghCb1Iz1 TVg/bkyW0RXdB91NarKHtt5UFTUBb/kq/5RVOeDErVoTkS4W8DUJoelQ2/897B3jbbNa YBvA== 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-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21867-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id l9-20020a170902d34900b001cff34e87a0si3230508plk.600.2024.01.10.00.58.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 00:58:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-21867-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; 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-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21867-ouuuleilei=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 CCCFF289786 for ; Wed, 10 Jan 2024 08:58:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A3BEC3B19C; Wed, 10 Jan 2024 08:57:53 +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 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787631917513482673 X-GMAIL-MSGID: 1787693200838830529 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 Acked-by: Jiri Olsa --- 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); }