From patchwork Sat Sep 2 04:40: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: 13372979 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 2E552CA0FF8 for ; Sat, 2 Sep 2023 04:51:21 +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=uMFfUJY3NtRSUI QRqOCPvpNPf84KJQw5jWKQwr7l0c7fLLiPtCz4Jux5yIjV/tvZr08tcV/ZmmG632kHVB7JbhPiGFe /h24UqBg01vOFBHRzAYYllJRSQn9CudXLKWQGdiz/5QiI83cmrsaYzno+tbwovL+snhHZsnvHZmVt +jG7oGK3pXf81SW30q+ypaf2NfxFsM/EJ/qQpT2bshUcsw1Ys0pdfwE7LKleH77S3Zn20oXsLKBXX /IuEzSv0Fb0Onnp4qhW9lW4NVkdKO+7ita1UqPypBovRD9qtgYE9xHwLNY8TeFK5UFsocDTZ8gpkt cJxpYjP9RTukZF6f7mag==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qcIb0-0013eS-0B; Sat, 02 Sep 2023 04:50:54 +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 1qcIay-0013eL-2x for linux-arm-kernel@bombadil.infradead.org; Sat, 02 Sep 2023 04:50:52 +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=VDeJU94IWnvseyKaMxC4IUln27g8AmHmoNXDqEplCe8=; b=Ot/jBPl+TKjYh3qzKADPm22J03 nemrkBEeJwtmy0K8PFG8+0HU6IidhaHg1qwWVyRr3cCuEUVkjncm5NZwtt973Ta64aZMDP+0BH2rf cfxlFDMQkekjGhBtmv4DvG496DE05OljMdQgTTqIMbkvKBNKjO8tsXB8KJ6z96+igJXUT46wBBFnP 5uBj5NMvvsC2mi6J7zE5H8UYaFSXXssc4YPXOcrySUXoLnvDjMf1tEsVpoZcUp9UmRz7bR5kvt3QK Md1/BvXcuDpSXKqXUFHSGGRgcn++vFOPT0O7sR9IJMOsyVt8BxQg5TZQ5LNIQ1OwbuDgw8fUQ1Mtp Od/NoT4g==; Received: from out162-62-58-216.mail.qq.com ([162.62.58.216]) by casper.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1qcIat-00C2jZ-C3 for linux-arm-kernel@lists.infradead.org; Sat, 02 Sep 2023 04:50:51 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1693630233; bh=VDeJU94IWnvseyKaMxC4IUln27g8AmHmoNXDqEplCe8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=OQUO0UDI1aP8K1liUiSAZcuaSazehRQAd6In4LCG+ES5LekVem+Glqqf8z0UkM+9W ehfzpQfKvAYHxFcmpYCl794+dNc34RlUH0jck1unxIPTvp6g/2UoLmKG3u69xfYOa3 1TYsRjm1Y+btstH6sQzUFG5GuFcRNPE2GAGIo6EE= Received: from rtoax.lan ([120.245.114.63]) by newxmesmtplogicsvrsza12-0.qq.com (NewEsmtp) with SMTP id A4223C8B; Sat, 02 Sep 2023 12:41:02 +0800 X-QQ-mid: xmsmtpt1693629710t5d0r7m38 Message-ID: X-QQ-XMAILINFO: OUUXHEo9i1ukFJYgSO1dj9mwONQKPyftWMC5kUq9pKAIUP2tf+OHYc6I9HtYAo 0f/3PO0B89VA74pYjo2DdVEIauYDaRoTfC/fxGDITJPujGHJDeyNGhoELfvoSafZFrz8N0I1Iwx/ b5wnVASGROPcyRToyEOmu4Rz028wqnA91sDkamJRvqvJvToBng6ow7WFal2FSRl+iz4DHAekn27S Y+Aev9kKWjxfNh1atT9Io/mpSrNg/0kJt8jZxG1jFnLlMT13jT0/nfcJ9zlaSEHNsrYCdkmbfAjo uBsgsbn/tv04U5TqmT0zGJBMvSLOgS6iEcbL42cKYqeEVieSCrkTYZgb9J1aw5ZgRrAUyC1mxpOR qJs9KF8nyVoMOTq0Jd/MJNXQjmwqQPENuk3/oeVwcWsU79j0AhKwWnYdDbF1z6AIEHDQZwamJ3Ek b6I7Qs891Z6CYjheDKyVdJBourSAfgfnaWgQ3W6TCPa7F2LJdvndwY1fxm1v9zrT+i24FnxsKijV 47P+BPxXknxt5RgTMvkfHeWAdPyKw1crODvsOsEGU19La88qzRmwO24wussXD982sNjJTgf11jGY m6He9LF8i6XHshm80wZCvObkHjBdStTOBcs/4qYBLZf1Wshi6+uOKj2aPVzRC1c5qp5BwfEnB9dZ awYQEjtmuLXBglrdOLZzBLnHlgVEmhe38VTjqVNA3LA4+Mp8jXpQuawh1zvvtLyLzAI15Oyomg/1 nWl9De49ikMIlgXQCobvBWVPATu3h0eCf4W89BVufWF0xl6OX0NMwAaU+DN7LdhbS7QfD/JBXEh9 qXyQI6uSl4rCI+i8lBE10blxb+5WFO/IsECuJQnc1d3vBo646W4+sspxPh7MHZlt9AszkWq01rZP wg1yWqZ7AoUx+54hGZ61gWlbaj42ncOHAF+xl+duHm7YkKvgFZtL+Yy+Q2Dl98tK7d69w+sIv2DW crF9/kDKBIcbyZGxJDCldrA6qnI/E0o9n2Uqj+X5BbpGES4l3JNp10kQFsdZTLTxTHJavji3zW1n IPf1Xi53Pw+YzJ+55e X-QQ-XMRINFO: MPJ6Tf5t3I/ycC2BItcBVIA= 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 12:40:19 +0800 X-OQ-MSGID: <20230902044040.137804-3-rtoax@foxmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230902044040.137804-1-rtoax@foxmail.com> References: <20230902044040.137804-1-rtoax@foxmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230902_055047_885874_C56EE581 X-CRM114-Status: UNSURE ( 8.35 ) 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; }