From patchwork Sat Sep 2 05:14:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rong Tao X-Patchwork-Id: 13373001 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 22C7BCA0FF6 for ; Sat, 2 Sep 2023 05:16:46 +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=Cnoe+0R3W48Z29LV2hohFLWzj3FIFMXR6eBlSpH0s+w=; b=0WGeswlEp5xU8X WtVypKcrdiltg2LaYWZfoEhV7/dSGtE99v1I4ZwolwSeje1FCNRgosV3XbWX0G0CH+/JPcQlcfViF oNQdgvR8k8vpVg9FtNYGI1hU1+6QUFfRbM0d9vq09Jz1MKHD7/OlaEu2kyvXUVxMGdGszx/dhDtmz /V7LH4XTomaILyssX6pERG61MGpjVDrgMSY1uVWMRk3VjOLwjuknb1Vc5QhXZLn4riZWHB4KP7lI6 IDxc7TNll+MZiVJHJ30hCgz7PMg7UYc0CO3bxrvjmXPc1GsYMe8mgaq2HeVGL5JhrVVFgjwMzJYT4 e3iVKtnIJcFeU9sf8mIA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qcIzc-0014pC-2F; Sat, 02 Sep 2023 05:16:20 +0000 Received: from out162-62-58-211.mail.qq.com ([162.62.58.211]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qcIzZ-0014oW-1d for linux-arm-kernel@lists.infradead.org; Sat, 02 Sep 2023 05:16:19 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1693631761; bh=VDeJU94IWnvseyKaMxC4IUln27g8AmHmoNXDqEplCe8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=y98HrSljU15JiM4eaxs4iPQ85bCyaOAwK51n36h4MBI17vJXGmmWzMKvHnAKpvB0Y De7nRbXL+INgiwL1YV1poTb9pTre1cNVHbvmbL8l/yd/TdxUSw7gAtmLkWnWltX3+d +/TEgY7xqCtDRjy0xjiVOCidefICoTdu2vyAm+e8= Received: from rtoax.lan ([120.245.114.63]) by newxmesmtplogicsvrsza12-0.qq.com (NewEsmtp) with SMTP id 3EA29043; Sat, 02 Sep 2023 13:15:42 +0800 X-QQ-mid: xmsmtpt1693631746tb9aw2kru Message-ID: X-QQ-XMAILINFO: NKv2G1wnhDBne0mgP5e8Y2tcHeHRdNu5Q0RL7PHJuVBIhlza8+x+J6yuCnozKQ Bd9sjr0FaoV3Ewulrh4ofynlPvtSqJj0N4bqDCnALENDC7cLq6+A6XtJqom7ARNR2SI7KUkW+2Px YE/2Rl1vGzdus6T9H6+OP/gXEI8S/YvhxThr0D+xcwzUHWlkEGbdwY6Ca3TmU++IwmyV8xkgRwb+ s/9p2A9q9kCFxnfiri24XCl5v+SWlPslQl4GBZRDnjv3o+ijfsedpZVLK+Sfn4X9ygwK/rBQ0zDR RzIoP91t9hgg4Tp9nTmngcMAV6LM5VG+/6dAhVTARq+GjVtzSO7IdWzp5pVmCMz/PExE+itSKo0g 8u8JLQxnT4o3xu28ixiB4h5CoB5hle4/zsPwJ8zb4Y1AzedwWwTiJajaWZi5tM5tgwUa1+aNCTW+ IRFRyzcvsTa9z6SPrDcGrm46oXQb9tqxKq6Ai4rj/I9CgTIeAMaaFsbYUWntyzAPpJa5C/JbsVFo LJb9j4jikTBh0JwRLT3CTKQSzURW1rWwMnkgJ8SF92le7JklBvN4J0ylrHl1p+fugu1dlLOUy14d pQcBOyACmcepJSi1qiLQdn7rGZ3VHRzWr/A1iwgsk4h6wegkus95GtWUFjTMSZqHLGJfNAQLB2j3 S9XZ9PNno6wsJT4Y8+tkQio4kiymt6z0KKi+963FWUG1n0STvHxYspD8fvzR7GVQMwl7DUZe7GQq mCVS5spq0myogqsAcP7UeMUc35ExqE5i7Kb92sbS3rIyqddty+UilEWe8l+/IDdcKbqPUEyy/L0t QHhRmXWV9MM1RnB5URGv/ATDhJ9H/NJPBaC7iQJDV2s+04cu5/1SSoOyhMD6lm3OvSoNqg7fWw8L UvJP4IuoevqrBUrG1CNtsH2r8PLOkWimwODo1iALnhKNI2Q/zPNpW5pQwCof8PVvkU5SJdOTtszh MHlQLJzim8Nx39r/oI0RAlFb5levTZV9AsZhT+bAV9R6Y+eEi6vbkZIeS/nzykbn/clWHFTKrIPb 1+I6SV8yfZAXm895L7 X-QQ-XMRINFO: M/715EihBoGSf6IYSX1iLFg= From: Rong Tao To: olsajiri@gmail.com, andrii@kernel.org, daniel@iogearbox.net, sdf@google.com Cc: Rong Tao , Alexei Starovoitov , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Hao Luo , Jiri Olsa , 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 v10 2/2] selftests/bpf: trace_helpers.c: Add a global ksyms initialization mutex Date: Sat, 2 Sep 2023 13:14:05 +0800 X-OQ-MSGID: <20230902051421.139040-2-rtoax@foxmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230902051421.139040-1-rtoax@foxmail.com> References: <20230902051421.139040-1-rtoax@foxmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230901_221618_072798_6AD9AC0D X-CRM114-Status: UNSURE ( 8.74 ) 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/ 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 d64c4ef336e1..500b60226e5e 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) @@ -115,8 +117,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; }