From patchwork Fri Oct 28 18:01:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 12508 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp971960wru; Fri, 28 Oct 2022 11:09:58 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7+0bUCxLr3GtfFPVJIHtM2QaUqDqJ2ss+5G8GRSnIzJN8w2yrBH2bZaGv5S0HiCQJiUHnn X-Received: by 2002:a05:6402:7c4:b0:462:9bc2:d0d0 with SMTP id u4-20020a05640207c400b004629bc2d0d0mr701594edy.122.1666980598122; Fri, 28 Oct 2022 11:09:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666980598; cv=none; d=google.com; s=arc-20160816; b=axyZiagY2QBq3uNaVw6e/rP0t+J+gKjpNF2BUnua1c5Ct8Uh8Bexcvrv1uO+D/iJwz IsBHeCX+SG3gwZ/vylqADtvUfsWvNzIjitNrSFODKbDOw79OwkwCoItIgDYID24Dl5O8 uf1uWwSSyw5/d/7yzpVlchgaUzzDDG4ZaqXdyKLktN3OjLOAivQCnRCJMKYEilOrtcdd pEwOAVAFcl2QaQ4gkYddafD+ttY8IAEmcogE6Nl9l1W2avThXOsTusPXg7DJSnPKR4Cw ZumOEYXk0+2+SCCYT2RJJqXXgVNRq5/tUjNklCDmHkoC12jL3e6mLtoyTDqFN9+9g276 Erxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=NmGyjkUI3Jx6s05ye5A4TzB4tPD0VcBwkqsa8EyR1XQ=; b=MAJj8NYxi1M3puq82LluSgjuAchZpZE9yLnqyIimbHHwxr4HCdfFdbZQva5idQMYfl 9nHRJNfEcYSUv3w7APeNhV5IZtciMa+o8/jl53O60dRjlBqakTihpALiCW3MP1s4SvSd W1bAfNK65qQu3V1Z99x8MKuoLshSUNasu+NbiRhzjx0MWlkBsP3YEf8xBfB8/7TAeZNF a3tiUyk+6hT2cRWLkFCEZy8zfE5nD2W9yp2wjb7oiRRB+3yZ6o4KbLiQisORPRXKBFnu cdPnKajLT8DrgEXI2O4r1YY4ezO0jO7YbmuH9bJ2//kCshq2OyXLTqi48RsBXF4UEsnF eFuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=hD6Z0lr0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z23-20020a50cd17000000b0044ebf99d6f9si5620822edi.263.2022.10.28.11.09.33; Fri, 28 Oct 2022 11:09:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=hD6Z0lr0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229636AbiJ1SBq (ORCPT + 99 others); Fri, 28 Oct 2022 14:01:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229716AbiJ1SBg (ORCPT ); Fri, 28 Oct 2022 14:01:36 -0400 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B918320FB19; Fri, 28 Oct 2022 11:01:34 -0700 (PDT) Received: by mail-pl1-x62a.google.com with SMTP id f23so5485763plr.6; Fri, 28 Oct 2022 11:01:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=NmGyjkUI3Jx6s05ye5A4TzB4tPD0VcBwkqsa8EyR1XQ=; b=hD6Z0lr0qNzTb/h7xWEEo4kab7blvNR1dkhEaQcP+TQbguozLm/pd3/Wt/YmB4P7VN zVIhEM+5h48c3QkGE9zQvi9LVupqNaK2dYG+Fjcj3Pr7aL4ezJQvVeYbhMFgLxrVws4k +/U90S2XvRrJ/fjOz5Aj6jOZ/7czeOddZDXBXn/Si6nlOVhVnCIDgVibEdsBpWXxKKUu SSE/mFx6NJ3+KSrlM0jnpeBc9ltZsFAL+diDGr6YfNqElfMWiWPcZRC9WYXolLcGNZgW ppVj33Jp3cZ/d+WH9MrzS683eYX9A93CeqZWkFOY1saHh6BMkN5Marchffqlr3qop3zp IF5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=NmGyjkUI3Jx6s05ye5A4TzB4tPD0VcBwkqsa8EyR1XQ=; b=NCkPKbE+jacPLisBJQAxuiH964muzLFrpXZGN0zp8pgn1cntnFw5bJS5pYROn5H+pn 9ssnONagho2m3f1NijusOS3W2mG924YxjW6NK0bmHC+2+VALwV8f5QWMfG5MBh6rMl1D 5qiN4WqhMxNMqFE10wUMNXjZC2IDY2o8C6m0FPBlOupGxTe4Saq8PSquGICsdcTAWaqz zZHkBeShxaLdxuI1ZZY/5D4mOpvb3PCO0s/HajvAYK2FqJdSu6Twkbbh6sUwHUhwm8LQ nE5KHbh8by1iLRGRLrxzhXaTc6c5lq6oO31baHhW01dTZ1/iOOHjWjV6WvtJRJATRTB9 iS2Q== X-Gm-Message-State: ACrzQf11HOA4z6M7N9ZNJ2i08yr4rh5R7NAr12ezDYcRBy/EWdxwcvpa Hr2b2XZKFWo4PM2cgP65IbI= X-Received: by 2002:a17:90b:4f4a:b0:20c:64e2:2bee with SMTP id pj10-20020a17090b4f4a00b0020c64e22beemr18093806pjb.32.1666980093820; Fri, 28 Oct 2022 11:01:33 -0700 (PDT) Received: from youngsil.svl.corp.google.com ([2620:15c:2d4:203:976f:f075:7c14:87a2]) by smtp.gmail.com with ESMTPSA id n3-20020a170903110300b00186b86ed450sm3400236plh.156.2022.10.28.11.01.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Oct 2022 11:01:32 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org Subject: [PATCH 1/4] perf lock contention: Fix memory sanitizer issue Date: Fri, 28 Oct 2022 11:01:25 -0700 Message-Id: <20221028180128.3311491-2-namhyung@kernel.org> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog In-Reply-To: <20221028180128.3311491-1-namhyung@kernel.org> References: <20221028180128.3311491-1-namhyung@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747955847338717101?= X-GMAIL-MSGID: =?utf-8?q?1747955847338717101?= The msan reported a use-of-uninitialized-value warning for the struct lock_contention_data in lock_contention_read(). While it'd be filled by bpf_map_lookup_elem(), let's just initialize it to silence the warning. ==12524==WARNING: MemorySanitizer: use-of-uninitialized-value #0 0x562b0f16b1cd in lock_contention_read util/bpf_lock_contention.c:139:7 #1 0x562b0ef65ec6 in __cmd_contention builtin-lock.c:1737:3 #2 0x562b0ef65ec6 in cmd_lock builtin-lock.c:1992:8 #3 0x562b0ee7f50b in run_builtin perf.c:322:11 #4 0x562b0ee7efc1 in handle_internal_command perf.c:376:8 #5 0x562b0ee7e1e9 in run_argv perf.c:420:2 #6 0x562b0ee7e1e9 in main perf.c:550:3 #7 0x7f065f10e632 in __libc_start_main (/usr/lib64/libc.so.6+0x61632) #8 0x562b0edf2fa9 in _start (perf+0xfa9) SUMMARY: MemorySanitizer: use-of-uninitialized-value (perf+0xe15160) in lock_contention_read Signed-off-by: Namhyung Kim --- tools/perf/util/bpf_lock_contention.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/bpf_lock_contention.c b/tools/perf/util/bpf_lock_contention.c index fc4d613cb979..06466da792e4 100644 --- a/tools/perf/util/bpf_lock_contention.c +++ b/tools/perf/util/bpf_lock_contention.c @@ -110,7 +110,7 @@ int lock_contention_read(struct lock_contention *con) { int fd, stack; s32 prev_key, key; - struct lock_contention_data data; + struct lock_contention_data data = {}; struct lock_stat *st; struct machine *machine = con->machine; u64 stack_trace[con->max_stack]; From patchwork Fri Oct 28 18:01:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 12507 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp971896wru; Fri, 28 Oct 2022 11:09:52 -0700 (PDT) X-Google-Smtp-Source: AMsMyM72/flL+FShYhoTQcOxkx7Am7IcJTsl8/5/QwfgLAPB6FysQ5YFZBku5n7ohtvEt7gwq/6Y X-Received: by 2002:a05:6a00:1707:b0:562:e790:dfc3 with SMTP id h7-20020a056a00170700b00562e790dfc3mr449263pfc.59.1666980591965; Fri, 28 Oct 2022 11:09:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666980591; cv=none; d=google.com; s=arc-20160816; b=ViPa+SdTweVX67HG9U/7nYHY4dhH6TftIRq4OEUFICNjlwmfXw7OmJ7MiYQRZDzDy5 YGb7oij2ieLXQdkq+8TR66ka6GSHOQsQCVtPUIqzg6ajIgvDAoYU2EgtyVNwfDVzYer7 sq3/hnK9gNXUW/wrZl84wg+Spq6kSxCYYyCe3dUd4IP0iG7fNoh3I5nUFYhk4sQhSPcC VopgLogsG2A+H6xnEdnMyoAhNIKuvq05j7smmP3sCP9bFJR1dmxeggkgZ6KoD+xrzuxn GeNHazB39feO4yXLKxDbSk1si8aSuEuPhr5sNZv8oxWEIiHka9TQQEhHPK/Ehsyr7jS7 ELwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=RRaWyTNG36H59bEp88dgewnNjHxw44C35a4VhyGtZjQ=; b=FFrIIOmlZtpBqWHTVcuE1uvCZhuJwxi6otXfQVT3U6auDy/ehE4I30TCUw0LuEF1Fy 9t7xawLoC1QGxm5LRj0ImM8+/jBt/SQinSjoX7TeJYeK/SO2fMXuFaqn/CB/tIrDK07b 0hsCTAlS0UjRwxjKdEhtVRH4u9vnS9MYmpTPYEKdsTlXQU7GdCATj4wCVr6P0zV0TOft UowHqK6LqneO8isPUgDyGNfprLj4OY/bphiU583n4gjUXKpaxP1VFs45ezrlf/RT9MJX leFt1NYLWO235upsTzLF08TSxSRz+lE2QDg4QveLzDMZN0jmMcfRjidmSChSi4US+pbM wSOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=MWTjbjOl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k70-20020a638449000000b0043c8ce98a69si5617357pgd.711.2022.10.28.11.09.37; Fri, 28 Oct 2022 11:09:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=MWTjbjOl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229982AbiJ1SBv (ORCPT + 99 others); Fri, 28 Oct 2022 14:01:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230018AbiJ1SBg (ORCPT ); Fri, 28 Oct 2022 14:01:36 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE1DD20FB1D; Fri, 28 Oct 2022 11:01:35 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id 3-20020a17090a0f8300b00212d5cd4e5eso10527919pjz.4; Fri, 28 Oct 2022 11:01:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=RRaWyTNG36H59bEp88dgewnNjHxw44C35a4VhyGtZjQ=; b=MWTjbjOl5lZi7Xu1Znd5gj0cW3FkMbJFkKKN/mVYofTaIK7sVXhT07pR31GWyqOnl/ 9SR9oSl2m4vw2H4zyeFubiK4coIylPo2pQNNzjHz0tDkBNkP+6C/qnBqSof6VUXLPaM1 D12+rnxDSHhTSMvXTWP4wOoBjBM1Q4c0zz2zas65ePGiwPNVyeN9UfUGHLOD9IdlHKt0 mWWr0YMIXY+25RgHy0noTUbYAnCaqxJ1qDtctIxR3qCOtT7kS1SIZTRedRAHPkpUIgDa AkSKwuY3lm2Rd54tzk9rXY18qB2SzAQf0s+zdI8gEGd1SfjBhN9LNtaNocTvUlJUdDoX NbjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=RRaWyTNG36H59bEp88dgewnNjHxw44C35a4VhyGtZjQ=; b=J/8IIb9V+wdyZMtqP6JaMxgUX1oP/ppuCu2p8B3u+7ygbKRhRbSKhPQ/W2wqq9dCFP 2bFWkuvjN7yPGYFDRsC/lxtSupdd4bpq2yG1DqgPwNrIsNxJ/Dd1bueuDL61akX2v+A3 hu4kx/Rkjxwznbh80BTEwlX54XYUcv83jziwSPqvkpDN1kCOA6AjznF5Bv+kAsyKa+Ix Up42Mtaqv6XgdRX/l7wOf2drt9ce0Pkcn8aYdPVVrgonPTKuWCqR6xalI7amXNvSK0k+ UjYFSZ9NdCPS0F4+1ZwCtqEKhajWJf0Cw9JgpR/NsdiohAgl4WwGPC5KQC46MjRn+Zwq IDRQ== X-Gm-Message-State: ACrzQf3jN1uCD2Rx8dBRG83/q3Yb5HkQ8YVwZ/4oazp6HkQBbAcEGFks niavH8x0MSP4o6AVTD8bCZ8= X-Received: by 2002:a17:902:f710:b0:184:7a4c:fdc1 with SMTP id h16-20020a170902f71000b001847a4cfdc1mr186767plo.27.1666980095311; Fri, 28 Oct 2022 11:01:35 -0700 (PDT) Received: from youngsil.svl.corp.google.com ([2620:15c:2d4:203:976f:f075:7c14:87a2]) by smtp.gmail.com with ESMTPSA id n3-20020a170903110300b00186b86ed450sm3400236plh.156.2022.10.28.11.01.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Oct 2022 11:01:34 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org Subject: [PATCH 2/4] perf lock contention: Check --max-stack option Date: Fri, 28 Oct 2022 11:01:26 -0700 Message-Id: <20221028180128.3311491-3-namhyung@kernel.org> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog In-Reply-To: <20221028180128.3311491-1-namhyung@kernel.org> References: <20221028180128.3311491-1-namhyung@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747955841275693181?= X-GMAIL-MSGID: =?utf-8?q?1747955841275693181?= The --max-stack option is used to allocate the BPF stack map and stack trace array in the userspace. Check the value properly before using. Practically it cannot be greater than the sysctl_perf_event_max_stack. Signed-off-by: Namhyung Kim --- tools/perf/builtin-lock.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index 9722d4ab2e55..f67db60f1de6 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -24,6 +24,7 @@ #include "util/data.h" #include "util/string2.h" #include "util/map.h" +#include "util/util.h" #include #include @@ -1858,6 +1859,29 @@ static int parse_map_entry(const struct option *opt, const char *str, return 0; } +static int parse_max_stack(const struct option *opt, const char *str, + int unset __maybe_unused) +{ + unsigned long *len = (unsigned long *)opt->value; + long val; + char *endptr; + + errno = 0; + val = strtol(str, &endptr, 0); + if (*endptr != '\0' || errno != 0) { + pr_err("invalid max stack depth: %s\n", str); + return -1; + } + + if (val < 0 || val > sysctl__max_stack()) { + pr_err("invalid max stack depth: %ld\n", val); + return -1; + } + + *len = val; + return 0; +} + int cmd_lock(int argc, const char **argv) { const struct option lock_options[] = { @@ -1913,9 +1937,9 @@ int cmd_lock(int argc, const char **argv) "Trace on existing thread id (exclusive to --pid)"), OPT_CALLBACK(0, "map-nr-entries", &bpf_map_entries, "num", "Max number of BPF map entries", parse_map_entry), - OPT_INTEGER(0, "max-stack", &max_stack_depth, - "Set the maximum stack depth when collecting lock contention, " - "Default: " __stringify(CONTENTION_STACK_DEPTH)), + OPT_CALLBACK(0, "max-stack", &max_stack_depth, "num", + "Set the maximum stack depth when collecting lopck contention, " + "Default: " __stringify(CONTENTION_STACK_DEPTH), parse_max_stack), OPT_INTEGER(0, "stack-skip", &stack_skip, "Set the number of stack depth to skip when finding a lock caller, " "Default: " __stringify(CONTENTION_STACK_SKIP)), From patchwork Fri Oct 28 18:01:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 12509 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp972202wru; Fri, 28 Oct 2022 11:10:20 -0700 (PDT) X-Google-Smtp-Source: AMsMyM56H8YMQMQSMh75B8slxOJVGi1UbDQ1Atj0fR4/9lw9EhDmR180fqjfCOycBH+CpTEK8sZO X-Received: by 2002:a17:906:fd85:b0:77b:b538:6472 with SMTP id xa5-20020a170906fd8500b0077bb5386472mr588457ejb.48.1666980620712; Fri, 28 Oct 2022 11:10:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666980620; cv=none; d=google.com; s=arc-20160816; b=V+ojdpN0dihuRP3SCG1V/nVAD3xhR3zNfSA1SeDaPuXsl7XvKXMNES1ZVwbMg8yXCz pMQGeHtIT5/Agvsv1rF03UcsAzdJYfCwyx4+rlZTHJkIkK39IWyb5gsT/B1OiP9Pxv3k i1YdEk1ikXBvoZKhNaCAAwgaDwKKWr/w5TaMk3bBroY1PWJts7OayqdTu4E/6pc2BFBO xx4OOi4csWlz14SEbkIgMhUtfaSK1mdWhmmkoKvKSy7L8jYMSvHEP5735oXk7xr6INVr BLYj0NlDTK8JE9+sB6OmNFMTIWyfGXRNJDHkf+rgnczPOZLK0leT9oAJGArTigFouGqw oU5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=BDQ26YrilcoiUxmd9QdQ1Dk7XFU7csSgsYNB1op6NE8=; b=U4ByJw7Q87zVMJ40CN37lJgMR6ohZA8A6w8Ui9O1Rp7QIzU6rSWvm5ZrlglR0HtWdX ofpMLiMQ/om2EZSRWiOc/r7r37cXx4x3mdZVrJBAupiuTCOiW+KIjY3ex1GanJjBVmYj 2ieAtq5cfXM4FOodaGJHFWamzb+VGyE6R8/oEiiyXVh0CJu3jGKtVf1IQleTAdf80pJY FjcKpoCECeTtcstYUW1oB5IXoYeOEwVOQlNihX2rJW38knzSDy6t4ibuuDoHi23yYb+W 6qWYBQh3wt1UPUtnXVcLzi7mSzaLVPwLlRogyERg0zTB7BLod7ohhyja5ZmyMXquvwgV jFdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=SQ3Z7rvG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o18-20020aa7d3d2000000b0045c0de4b0e9si4182635edr.170.2022.10.28.11.09.56; Fri, 28 Oct 2022 11:10:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=SQ3Z7rvG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230163AbiJ1SBz (ORCPT + 99 others); Fri, 28 Oct 2022 14:01:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229930AbiJ1SBj (ORCPT ); Fri, 28 Oct 2022 14:01:39 -0400 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 936C020FB2B; Fri, 28 Oct 2022 11:01:38 -0700 (PDT) Received: by mail-pj1-x1033.google.com with SMTP id u8-20020a17090a5e4800b002106dcdd4a0so10552262pji.1; Fri, 28 Oct 2022 11:01:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=BDQ26YrilcoiUxmd9QdQ1Dk7XFU7csSgsYNB1op6NE8=; b=SQ3Z7rvGLUrN/t+Hbqt2wDeDYS+lmrdAuACOFCN3M0r2GzZxb/crepMgS5OP/2NbkF cShzFKOVPzUVMu/4Q3R7Bz/pcOtmgyOxVgdcU+PSkvvPXf/mHjwUInz7cX/LFupYbQsF 5fgXhixo3JpdAiOIoqLKejnqonJtnoS8NuHJ8Z16m3ZpXaaFDLjXee+tNGbpTWloi/tz qYP1zAB6XKeJ8lA1jd6b3EyIYqGIPUOyP5PtS0TonCxJDzbiJqq8cVzxqQ9WKHgzdm8/ tEyKfNfcJExD656B2UX8dM/cEOY4pkLpgCRU4vC4t7G3xWFgwSZFqCym2Q/LfDnemOqf szkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=BDQ26YrilcoiUxmd9QdQ1Dk7XFU7csSgsYNB1op6NE8=; b=ji/c5lZiXBorY7XHTCEpMCOUzcIOgIA5Ei1GLUbV46y5Jl2NnztKMVMe1XFviUCDOn BnAo0bWls/53Z3Mj6qZPXgr+Kku3QX0tEeezEn+QHgQ8TiKWSL0h4+ONtEwu1eDNiFEP OeHHQuFl9cVpkNG9n8lxu72Yw9ababNJThyIDzllbck2pzDrvR/g16kIW8kRlM9KcE/u J0dX72tcq7o7yoH3i3eZb4LGUMmWi+JTOIRmVvpI6jZST/GhcpmXfpw+tqLOmMZ7JQ7d sV4nKpoqrL+ry1+hLUgW74cl+xNnhmNrFdVEAiP5zOQnNKvYBHZadZ+NoTUEbuXCypLC 3NLg== X-Gm-Message-State: ACrzQf0mrUCsA/fs63fNQJ2Cgcz6jaBVgQcUGhAuk7340LcZE4W/tK/0 3TdmgA7Ur5m2Lw755i/9dwM= X-Received: by 2002:a17:902:ce0e:b0:17d:a730:3835 with SMTP id k14-20020a170902ce0e00b0017da7303835mr172589plg.131.1666980097967; Fri, 28 Oct 2022 11:01:37 -0700 (PDT) Received: from youngsil.svl.corp.google.com ([2620:15c:2d4:203:976f:f075:7c14:87a2]) by smtp.gmail.com with ESMTPSA id n3-20020a170903110300b00186b86ed450sm3400236plh.156.2022.10.28.11.01.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Oct 2022 11:01:36 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org Subject: [PATCH 3/4] perf lock contention: Avoid variable length arrays Date: Fri, 28 Oct 2022 11:01:27 -0700 Message-Id: <20221028180128.3311491-4-namhyung@kernel.org> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog In-Reply-To: <20221028180128.3311491-1-namhyung@kernel.org> References: <20221028180128.3311491-1-namhyung@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747955871418918610?= X-GMAIL-MSGID: =?utf-8?q?1747955871418918610?= The msan also warns about the use of VLA for stack_trace variable. We can dynamically allocate instead. While at it, simplify the error handle a bit (and fix bugs). Signed-off-by: Namhyung Kim --- tools/perf/util/bpf_lock_contention.c | 41 ++++++++++++++++++--------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/tools/perf/util/bpf_lock_contention.c b/tools/perf/util/bpf_lock_contention.c index 06466da792e4..0deec1178778 100644 --- a/tools/perf/util/bpf_lock_contention.c +++ b/tools/perf/util/bpf_lock_contention.c @@ -108,28 +108,36 @@ int lock_contention_stop(void) int lock_contention_read(struct lock_contention *con) { - int fd, stack; + int fd, stack, err = 0; s32 prev_key, key; struct lock_contention_data data = {}; - struct lock_stat *st; + struct lock_stat *st = NULL; struct machine *machine = con->machine; - u64 stack_trace[con->max_stack]; + u64 *stack_trace; + size_t stack_size = con->max_stack * sizeof(*stack_trace); fd = bpf_map__fd(skel->maps.lock_stat); stack = bpf_map__fd(skel->maps.stacks); con->lost = skel->bss->lost; + stack_trace = zalloc(stack_size); + if (stack_trace == NULL) + return -1; + prev_key = 0; while (!bpf_map_get_next_key(fd, &prev_key, &key)) { struct map *kmap; struct symbol *sym; int idx = 0; + /* to handle errors in the loop body */ + err = -1; + bpf_map_lookup_elem(fd, &key, &data); st = zalloc(sizeof(*st)); if (st == NULL) - return -1; + break; st->nr_contended = data.count; st->wait_time_total = data.total_time; @@ -163,25 +171,32 @@ int lock_contention_read(struct lock_contention *con) st->name = strdup(sym->name); if (ret < 0 || st->name == NULL) - return -1; + break; } else if (asprintf(&st->name, "%#lx", (unsigned long)st->addr) < 0) { - free(st); - return -1; + break; } if (verbose) { - st->callstack = memdup(stack_trace, sizeof(stack_trace)); - if (st->callstack == NULL) { - free(st); - return -1; - } + st->callstack = memdup(stack_trace, stack_size); + if (st->callstack == NULL) + break; } hlist_add_head(&st->hash_entry, con->result); prev_key = key; + + /* we're fine now, reset the values */ + st = NULL; + err = 0; } - return 0; + free(stack_trace); + if (st) { + free(st->name); + free(st); + } + + return err; } int lock_contention_finish(void) From patchwork Fri Oct 28 18:01:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 12510 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp972389wru; Fri, 28 Oct 2022 11:10:40 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4izc9rSeNsIC8pDMuqWHO5dRb6FM/VxCuor/eKH7KYtfkb7k8GZdtkv2DAwB/0xT+fYkNi X-Received: by 2002:a17:906:fd85:b0:77b:b538:6472 with SMTP id xa5-20020a170906fd8500b0077bb5386472mr589734ejb.48.1666980640307; Fri, 28 Oct 2022 11:10:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666980640; cv=none; d=google.com; s=arc-20160816; b=EzuiZvM32yhb0YXpSW7w1azIjEcCcdomBq7zjd28sMdM1YCYoaRd5Xe0QzzTvRL3Nz esrBSg4uerFxA7pJ4HGT5Ug/vG7bC9DtmjQmA4uEt0ZTWIr33a63Q463g/k321R6gMBR DeVVCfc+wihjNkJStnOguoG5ufA3mJ38mqb76E6SI+WEDCXNsnZAioqR392Kk267OMJe alr30HudonkTtiy1ViIsxff24zYO3ufo9j4hT7S74mBaEPz9FWs8Fgi5Hyxi0A+KdMlh BDAufzml5E0hefIwC4uS0I7gtizSu7UtpJD9zov/iF0ux+cqibXXCJCeyIC2gLsJjAtZ w0Ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=bUx8fY5yV5k6b3NAzZ7ONnYGBUoPPnSRBV9IAdB2IcQ=; b=cA0fkJ5T5slmX36l6zzZC1QlFWw4Xj97K5/etu0lJpLMEnzMmcib8AAIw/wOFmLAOQ Cc3cBp1hxXB4BotCP9MUy6kYRHe2vyXhgFGqvSjQeZ5t1fvgNYqWBWEiHcexYP98nwOp 7z3pTcNB2nYkGnqg3whs2v5EHJ2fFcGrfR2wmefHMM/GsIg9BXDyKxXUEYSiPLg8he71 KrFGoZ+eKI1DwdF7sRVVYqz+b1TfAin51NhhjvPNcEDRLog1EyexFoJeMdMMR1aNTJCT cvLsgIxkD9ERVC3QDPSdq9vHsN3A+S5zM4lLjCW8/9wv8f8gm7fvOaQyA4KIavNJ9+Yg 6VwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=R5qTkGNP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k6-20020a170906578600b007948b932e6bsi224180ejq.227.2022.10.28.11.10.16; Fri, 28 Oct 2022 11:10:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=R5qTkGNP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230013AbiJ1SCE (ORCPT + 99 others); Fri, 28 Oct 2022 14:02:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230012AbiJ1SBp (ORCPT ); Fri, 28 Oct 2022 14:01:45 -0400 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24B16211290; Fri, 28 Oct 2022 11:01:40 -0700 (PDT) Received: by mail-pf1-x42c.google.com with SMTP id e4so5416208pfl.2; Fri, 28 Oct 2022 11:01:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=bUx8fY5yV5k6b3NAzZ7ONnYGBUoPPnSRBV9IAdB2IcQ=; b=R5qTkGNPJ2owG22N7vSR56g7SchuiPlUzXI4dNN1k/rvLdTdqG4kadsZfKegVIwN3o TvJ+pVZ2pU3FtvqqRVpQ3m52vnAGIAr95xQetLdYfQ4vq28RiTHw9kdJTuDUysll5xnO 3Tos32ojE0o1gtPF2NjT8CPvwK8nzy+JcYOsS6vVJSWpMIbTbdX6T63xKsDjuBi3Kiu1 eVING4QaSDU1jdHSCxToNVDMQIros4oZD2YpJHGXTO+mfkDRwiM4NmeqUN5cSUCyrQW7 1/kY9mkFENtb2XZzYGnwY+R5EFuLHvnUUHAawQEd0e6id73h9c/3NLyUoYcwZAtB8cSw cPHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=bUx8fY5yV5k6b3NAzZ7ONnYGBUoPPnSRBV9IAdB2IcQ=; b=bscsi6Us4db1wZnhialOlVVYmGLNL28PjeBy+ULBGEDa+nA6hPhf8lLHziaFvl0R6U BMgvYt1X2ocTVAa6vj37pJM4Id/PNUsepAQSzXD8++Ibu9wgwp4Fdxbq9JN5uB3mMtiA R15UCFXLG6sODhBYIWmGJB3Dg9J4PqZF2StFxWXeetGKBkegAXIB+twBNXphPJciUb6a cN5haWj1nSC9dh/y9I+5nmcX26cen/oy+ejxRdsLxGmO43IS4V3V00jYlLfSaCwg2V6F xVgZ3a27pvkuFv1rv/MBkcYxiHc61EqO7GjMtJ7DOxQzxgR7z1LlbtRxRYav9d+9HwMf dD7Q== X-Gm-Message-State: ACrzQf3+u7hfy7izE+tmR8BD8wzoZ7hBH/Wi9cm/rRKh/flH/uV5tO0x MoEAPbRo+et/IADdVYTrT8A= X-Received: by 2002:a63:1308:0:b0:440:5517:c99d with SMTP id i8-20020a631308000000b004405517c99dmr636154pgl.550.1666980100358; Fri, 28 Oct 2022 11:01:40 -0700 (PDT) Received: from youngsil.svl.corp.google.com ([2620:15c:2d4:203:976f:f075:7c14:87a2]) by smtp.gmail.com with ESMTPSA id n3-20020a170903110300b00186b86ed450sm3400236plh.156.2022.10.28.11.01.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Oct 2022 11:01:38 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, Song Liu , bpf@vger.kernel.org Subject: [PATCH 4/4] perf lock contention: Increase default stack skip to 4 Date: Fri, 28 Oct 2022 11:01:28 -0700 Message-Id: <20221028180128.3311491-5-namhyung@kernel.org> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog In-Reply-To: <20221028180128.3311491-1-namhyung@kernel.org> References: <20221028180128.3311491-1-namhyung@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747955891959139432?= X-GMAIL-MSGID: =?utf-8?q?1747955891959139432?= In most configurations, it works well with skipping 4 entries by default. If some systems still have 3 BPF internal stack frames, the next frame should be in a lock function which will be skipped later when it tries to find a caller. So increasing to 4 won't affect such systems too. With --stack-skip=0, I can see something like this: 24 49.84 us 7.41 us 2.08 us mutex bpf_prog_e1b85959d520446c_contention_begin+0x12e 0xffffffffc045040e bpf_prog_e1b85959d520446c_contention_begin+0x12e 0xffffffffc045040e bpf_prog_e1b85959d520446c_contention_begin+0x12e 0xffffffff82ea2071 bpf_trace_run2+0x51 0xffffffff82de775b __bpf_trace_contention_begin+0xb 0xffffffff82c02045 __mutex_lock+0x245 0xffffffff82c019e3 __mutex_lock_slowpath+0x13 0xffffffff82c019c0 mutex_lock+0x20 0xffffffff830a083c kernfs_iop_permission+0x2c Cc: Song Liu Cc: bpf@vger.kernel.org Signed-off-by: Namhyung Kim --- tools/perf/util/lock-contention.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/lock-contention.h b/tools/perf/util/lock-contention.h index b8cb8830b7bc..e3c061b1795b 100644 --- a/tools/perf/util/lock-contention.h +++ b/tools/perf/util/lock-contention.h @@ -91,7 +91,7 @@ struct thread_stat { * Number of stack trace entries to skip when finding callers. * The first few entries belong to the locking implementation itself. */ -#define CONTENTION_STACK_SKIP 3 +#define CONTENTION_STACK_SKIP 4 /* * flags for lock:contention_begin