From patchwork Tue Sep 5 14:04:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rong Tao X-Patchwork-Id: 13374496 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 55E9AC83F3E for ; Tue, 5 Sep 2023 14:12:09 +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=z03DI4NI4jN1Hl6EvIOdt/Xiyzu8rumhUgH0SQArWVc=; b=kcVTjyLPV6Tz3E 9VixXRoB/rdwISM7VP9RcvomQeCUiy5dar4Uuk4GMceHL7EJLl0Ma5JGfj1StFuVn4qLifVV7MxWt Bc0PCEUGT1KG5rZKJJeFximbvwkRs359XuEje8Pyv+2vgj2wLPgdzr+zhKZF0lY5xiMWRNALfkNEt GKmLZuHJNFaSPI61YdKYBBijHPv8KqA0WtRvpv4HDHz9yFBBa2OpeYQlYt8dUU5ZPrOVW7sxdtGd7 7a5IeRBPXyKKgCQxwpxZPf0sgm4dlixPw/URuIz1KITtxU12fYI3+qLQBIld/+tW7osTehXd1WV9J Sp7oyl6rnNzYMYo/rDAg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qdWmH-006972-0Z; Tue, 05 Sep 2023 14:11:37 +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 1qdWmF-00696r-1w for linux-arm-kernel@bombadil.infradead.org; Tue, 05 Sep 2023 14:11:35 +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=8KlD3VW8L/5ayf8Ou0ZPfzGKalOanhbYs3ssojj7Rzo=; b=kmOS8L2ZYW3DO0c9eMxnigiQCI Ai0hz7ydnR242BMv2tp+P28jxvuc42HBxG9Y5vrpQWcpGlGSuUfqdQgX3uBXA0WK3eKGUnI9EcdlS Z3rmDyhCecavI656JYAsM+pJyHeOhxGBdo0Onae/WbVEnDnZcsoQfj6qLPq9o9HcpcO+Jt5LmKmwP Ch70HfXMunDlvrMA9xhDWQ1jFOiLeMv+Kx/RqjWQc7PCVudcf5qVl84c2xL2vyasRjTicwH+B9o0L gXZ5QYHZU4riZZcsgfreB6JuB7UeDMNpd4N1KYespZfewiYEbbOWKkKvmiEOL0p1D+gZeWIxZenVl Pftqt/Mw==; Received: from out203-205-221-235.mail.qq.com ([203.205.221.235]) by casper.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1qdWm9-00ALnW-IG for linux-arm-kernel@lists.infradead.org; Tue, 05 Sep 2023 14:11:33 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1693923075; bh=8KlD3VW8L/5ayf8Ou0ZPfzGKalOanhbYs3ssojj7Rzo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=qjLmJ7iqniP4zBvIV1ncC6uXslDq/yQ8ISl3iGiKk9i4vTzWWZucj2bgK9xKbDcdB 9H65YGJ+JZy/RRjIPLp01TFAgSo3Rt5HBrGndw427zt0Um2Kj8FPx6CcvRRK5q13Xy mEZG2NfPhipmZjsYujwoNVIBEUFdnMdrenoPUNTY= Received: from rtoax.lan ([120.245.114.157]) by newxmesmtplogicsvrszc2-0.qq.com (NewEsmtp) with SMTP id 12C80033; Tue, 05 Sep 2023 22:04:44 +0800 X-QQ-mid: xmsmtpt1693922699t0dv0dw9r Message-ID: X-QQ-XMAILINFO: OUMxvQDaATieCv4GzYM8TxrYu4PTLFyfFshfV5c5Zjsi/jYVNr1yaBkldHod6j lYb/2nctmJPtCLSeVterfhWNKVaSC1Hw1IXm43J7JQKHcZIHEC9/ml08GA/RSOOeoNzFyUEefE+G EcbQwZL+CtmgWlY1tjnHgI5jqlM7igrBcNXLotQDNdy5OzBrGYwgf6k4JeyF0ecgqV+DhVnSHl5n 6W7lM0BN4e/QdFYJ7r1V1lLKkjc6iKJeGKMpY9v09jTX2frjav0WIJUBfJyoVLqewoumV1fFJ9f0 BjCrtVPjE5S7tYSI4mPRBc/ikuw021AYVYfeWA6r04p0/3j06WyA7o2pFG8yxA59plf/l2eucODK 6An1iUGxxsciTjCmIRqwtTpOuHyAxgB/cCJR1D7wghzgtsNhRG/9BGUCsJ+iYwXWxJOpJB7EEHNT bUE7o/v/mPmH+2UZHR+zKDSEbHXdjX8fNHF77RXU0cTe17g/AdlYz8YSzIWzI4TnKHWMPtNYiJLo Z70i7AQlD+Us/ppjvPnz+OeSH24eMqUwPpqUhQRNYv3VXA9CpN9Ie2nslF7+YHK1b7pHHAHDtDUp OIH0ODulB6EktMufPvGYl1gni9Sfi0K7YQAJ8IdzEO30axwlkYFhuwzmHrYattgHmdWqYe5sQoYg 6DyVDjIWY8VMSjs693sQJG7Z8z6Yoj3PHu3CbkERAE5/kQbR4E/DcVbBIT8E70up71mZ+YWjGbvt eFexZLgVTmf2sr5VSQwAji+5jgtjLwWQUM4z4x3XU3O7/uHtHluy+nxAU8doCLvYhrV8ejNAdD/2 BFafAQZYJqO1AGuvtio+OjbA6aIfOEdV372IlMFvxpQRrx3TNbvGho+r3bZSu1KTB/6aewSIrVDj EiUd3ONBwTPXksWhId9V1Yqb+holqTA+CJglFgFPvsa/YQOw318nFbLHlFnlGX0mAXLOoIrTzaGt yf2hthNx0TYpClbb7kny+hHDO2iXTLOlYdc9Gf2FjBdZXYmGbooTzu+Kl02Wwc X-QQ-XMRINFO: NS+P29fieYNw95Bth2bWPxk= 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 v11 2/2] selftests/bpf: trace_helpers.c: Add a global ksyms initialization mutex Date: Tue, 5 Sep 2023 22:04:19 +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-20230905_151130_326719_914FFB18 X-CRM114-Status: UNSURE ( 8.54 ) 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 7d026c128252..411f87d5aac7 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) @@ -110,8 +112,10 @@ struct ksyms *load_kallsyms_local(struct ksyms *ksyms) int load_kallsyms(void) { + pthread_mutex_lock(&ksyms_mutex); if (!ksyms) ksyms = load_kallsyms_local(NULL); + pthread_mutex_unlock(&ksyms_mutex); return ksyms ? 0 : 1; }