From patchwork Thu Sep 7 01:59:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rong Tao X-Patchwork-Id: 13376084 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C9E0DEE14AA for ; Thu, 7 Sep 2023 02:07:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Date:Subject:Cc:To:From:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=9ROA6/vMYhaBmqqvjGN2kVIEzC67dKV4TZOpFG1O9Sk=; b=dj8jI+wdGQhmf/ kdJEfp+010fG5COr0ZZeCV/zdI5hlAcFedUsRcHyjDgqJZcc6e0RQfM69E08tlxAoPUHtABZnDYsm omp3jc0E5VDkrKqLRM9pUg1fuXHO/jU2mbrD3lMBJWbxM412wKQHUzvSCyQ3kLSJZQYqupn0dC/8e y396DBJdIUkFvLLLxQ8Ti3C5Ko1AXaqUFU291kCivXEs++n9PEYizOFEsednfpn9AYjaSA4w3nlDJ f2VraV5HjkyD1P55dqYoYNqmDTg/YhW90tG/4MzlKrdS0guS9B/oGv8TfGZ0lhNespETZV0jKCfMi /EPVY0i81udBMKUjEkHQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qe4Q4-00BAo7-0o; Thu, 07 Sep 2023 02:06:56 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qe4Q2-00BAnf-1R for linux-arm-kernel@bombadil.infradead.org; Thu, 07 Sep 2023 02:06:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Date:Subject:Cc:To:From:Message-ID:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=Lhf4n1nBq4VAEDet52XCaOndkj8vQcHGv7waBa1OZl0=; b=wDwE3GoUixo8DmAshPZfxFLgwX EvvxwQCjGl0KQo+4BfPW7DPEOgoK8Svoqhy+B5WPkcxgV6LkIxJAUsDB3v5dJda8V1U5AY+p2110s 9NYXcYojDHo40s8jTGJ/goWAAsVHCsrfyosBsXYEH6PwiZTwRDHugKnkM4x4jyPKuTfEfd226eOwp 1CHZimr0m+mG4fhIr6H3QTf0n/xA2cwk9cB/0rIOKaZxcnJXxJF9U37Rhd/A7QBS2hq3RQyMOlTE/ ytSbL7NAYRSKUxSSmgtrPqqxoIy9aThJyfecdXP1IWms3NVbTBxBLvKUC5qbGoe0pH6uwIzLsWZ6w pGnIyxQg==; Received: from xmbg7.mail.qq.com ([101.91.43.121]) by casper.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1qe4Pu-007NB4-4g for linux-arm-kernel@lists.infradead.org; Thu, 07 Sep 2023 02:06:51 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1694052383; bh=Lhf4n1nBq4VAEDet52XCaOndkj8vQcHGv7waBa1OZl0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=gkFKOV+7Bz9RTg3GVZzDIMVzjd+5nSRLI9zPI/yjzLceZSq6QAuHcsJpabaYSRdlj DS6NVw48ioRpop1YKziVbZ+kv4G2WOjAWUAalzh4ews/7qsiL21qSzroppgJSHtcEK f89ZvlVDd3KIsC6J7b6gDXDQiSoyOqU+LeE06X/c= Received: from RT-NUC.. ([39.156.73.12]) by newxmesmtplogicsvrszc2-0.qq.com (NewEsmtp) with SMTP id EEB27808; Thu, 07 Sep 2023 09:59:43 +0800 X-QQ-mid: xmsmtpt1694052001t6cwiynfr Message-ID: X-QQ-XMAILINFO: NQR8mRxMnur9GVejZOqymyOCfTJKiLGmBPL7+7quQyquwS3OB2Gq/OewjNcZQa R3UmyCZo5Q1bz9iL/9q5RpvMvv/uWpt0ZY4mNaaQEQlqJ1plAMs4Y8okMUK1FFfRqp9rgx5lhcOQ k1N7nMMXe6ZG7OZKFmSRKsaE24N8BGGkoTmMfVrMYfwjCOfTfyCn8tSgzKca7MR4palCrkZk+L8h 5azCXhUrb28MpbEcbt86qGaIZJtWgP7R1AymBcVyVaJOgSRq0RgAdIyNcxB/fry2nEiv7qfxjRUN kzFfxTR6Rj+N7j8bsoC31krlbyUpmK3YBbyulMOF8Oy20H6/o658+DWsE+vySGOa++4OGyhyVRRx 6YBPAbYu+3sz+7ceWTCTN8C4Sen3vjcwoJfRHRhXAfHXGNP4eJAOtU+LQaxrcwZkBag9c3Pv4NyG O4DjGMgBg2UUzN6WsGNJnhwo9b3Q4vURldACPNGHIQ3CiMTpTuTr2l6lsh+NFhu6ZXZ72TAojscq L+9gJkTE/5QCpuwsfDfhYtB9jcbtOhXy4ms43Ll76rSo+ZYsIghKEUijqpllCUaYXHrm3s7GnFnD vpfyGA+mlRe8n7Q4xKHw4qe01LKUbBDxX8nh0N34VwFhFannpTTneQ9tLuS2Mq33q63jz3gBin6q b8Bz4SPvBtfsgZnkX3jSibCJ7FMR4JQFUi8gqFSXSnZR6iOd5xlxPvS8lca86br+fZHd9PjJedO1 bHgCyKlugrYH+Y4hpIor4soYylEJPksG833jeAfNV7Vw5qycDsqCcPNaqVwdkkSs7vhNTI0t231d 7+/we2ZLeX7QlfmzbsdlbcUZ13ZtKzMa5GvLFXnNFDZtVyk97ve6ZfB2c+MnXI/fELPJJmAADVCK mtuNlioTc29T4+MnwbMrgiARcOURhupGt2BNumJXBqcuTkdm3/wLwz2Zv23Z+QZ0HZ1on0xYG0oe L58wBOAYye2i1rJgmYRUnL9khIWydDgS6a/kkpjo3a2g0M9c/yEjC1aXuF/zQZUb65yOQmENs= X-QQ-XMRINFO: NyFYKkN4Ny6FSmKK/uo/jdU= From: Rong Tao To: olsajiri@gmail.com, andrii@kernel.org, daniel@iogearbox.net Cc: Rong Tao , Jiri Olsa , Alexei Starovoitov , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Mykola Lysenko , Shuah Khan , Maxime Coquelin , Alexandre Torgue , Yafang Shao , bpf@vger.kernel.org (open list:BPF [GENERAL] (Safe Dynamic Programs and Tools)), linux-kernel@vger.kernel.org (open list), linux-kselftest@vger.kernel.org (open list:KERNEL SELFTEST FRAMEWORK), linux-stm32@st-md-mailman.stormreply.com (moderated list:ARM/STM32 ARCHITECTURE), linux-arm-kernel@lists.infradead.org (moderated list:ARM/STM32 ARCHITECTURE) Subject: [PATCH bpf-next v12 2/2] selftests/bpf: trace_helpers.c: Add a global ksyms initialization mutex Date: Thu, 7 Sep 2023 09:59:14 +0800 X-OQ-MSGID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230907_030646_815055_B83CAA97 X-CRM114-Status: UNSURE ( 8.78 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Rong Tao As Jirka said [0], we just need to make sure that global ksyms initialization won't race. [0] https://lore.kernel.org/lkml/ZPCbAs3ItjRd8XVh@krava/ Acked-by: Jiri Olsa Signed-off-by: Rong Tao --- tools/testing/selftests/bpf/trace_helpers.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/testing/selftests/bpf/trace_helpers.c b/tools/testing/selftests/bpf/trace_helpers.c index dc4efaf538ae..4faa898ff7fc 100644 --- a/tools/testing/selftests/bpf/trace_helpers.c +++ b/tools/testing/selftests/bpf/trace_helpers.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -26,6 +27,7 @@ struct ksyms { }; static struct ksyms *ksyms; +static pthread_mutex_t ksyms_mutex = PTHREAD_MUTEX_INITIALIZER; static int ksyms__add_symbol(struct ksyms *ksyms, const char *name, unsigned long addr) @@ -109,8 +111,10 @@ struct ksyms *load_kallsyms_local(void) int load_kallsyms(void) { + pthread_mutex_lock(&ksyms_mutex); if (!ksyms) ksyms = load_kallsyms_local(); + pthread_mutex_unlock(&ksyms_mutex); return ksyms ? 0 : 1; }