From patchwork Mon Oct 24 18:19:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 10114 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp632659wru; Mon, 24 Oct 2022 13:12:07 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5hOZe4dPsw9/zKMj3NanTy7RUQUieR11MWJKXtEOm8c98Amjfdqn6oXRF1uF/FGeOfKBBt X-Received: by 2002:a17:906:7621:b0:750:c4a3:8fcd with SMTP id c1-20020a170906762100b00750c4a38fcdmr30533392ejn.180.1666642327181; Mon, 24 Oct 2022 13:12:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666642327; cv=none; d=google.com; s=arc-20160816; b=I3HkUCNn1EAcFwIRFgcSIAigjH3PAJil7RdS9YNtjWKiRe5CcxRN8Zvx8A9HPTBr9n R53svS7NoD9oXmxwjB0gKTE9Q4iMF3DtuHX5RMo2Kq7vw/G3TyFkC6ouukVwZKMCbIl4 fpDCe+NlQ4i2HSND7RteSsBjDTiiCh7GxNwtxHN56wF19yEFCMvudg8y1NSTFDs7MZg2 pQ39zZ1sFrNFmoEq/7vHDHucOoyM5mbXtpsqF6v0YNlk2x489J5MNWhudQFFfMXkdcFE 8HJrm51dcYLCZ1KDh0fr7bUW4xXASR/xftHUDr22mfVL3fqPRRLjLf/b5ehAtN4ukViy NXTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=IO66rWb82Ym5SFWEwsbpBF8A8iB7JwCydGL2I5mbLFY=; b=sYXdxRNKltYGiNuV5gLoGaXQmmOn/0sZtI6EK/3+GIKhyaFm+qVl4NBxdM31szOrE/ f5AghdS8xC7AGQyVhGilkmX8dbTIuhLiNhnGYk023wbWgy/CtGwjNYuSWmlm3Dm5YH9F AGAgRiVUEjjiXjkweaJeJ/yxvkjq1fhNvH0tz1mfcnaPacOPpYm4ZYVfU1JIxPr675kB Lk/z0p3EcnRjF6jb2z1RiUnxGHZwRTE42DXiTNACPFLTuklXmm4aWKG3XiyIgjixPNLD der0ZZ3QKgHdW7tKvWbmEgqnj9sWqa3EBdy6OlZim91E6WugKAmRdXd6DrgD7/R8NSGF BKbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=hds5L9pq; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dz13-20020a0564021d4d00b004619453ac91si775616edb.499.2022.10.24.13.11.41; Mon, 24 Oct 2022 13:12:07 -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=@google.com header.s=20210112 header.b=hds5L9pq; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233050AbiJXUAB (ORCPT + 99 others); Mon, 24 Oct 2022 16:00:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233971AbiJXT6o (ORCPT ); Mon, 24 Oct 2022 15:58:44 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 220AB280EF8 for ; Mon, 24 Oct 2022 11:21:16 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id n1-20020a170902f60100b00179c0a5c51fso6773979plg.7 for ; Mon, 24 Oct 2022 11:21:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=IO66rWb82Ym5SFWEwsbpBF8A8iB7JwCydGL2I5mbLFY=; b=hds5L9pq39xD5mOs2wSydg/fTH9JKNsJ7Rbx4+Zwar0mwCiXd1hUG54QUFgvXIy46C 0Nuybfzj2CtB9cQ87gNkJHD4MHJc113lhZZBc1ReSEFoxUjqpdWMir9O2DRmqD7ls/MW /M7P7UwALSMn681ZAGb7ZMYNuscUeK/5z2yD2R3faeyxN9tYpOCOSvAqSfBITEHXq4aM ZDekWbhsSEyGVKC9MlqoG8fW1+//MdAC2v70eHWLCMBgzcrePSjc7sMpNZJTy3eIjYJP auJ5eWSlKWzOox1BEvLJHFG/Y3irC2WZBoMDi9LvpgiZ1ZpS38/wuu4xWHW7ZGO8vbV7 Bo+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=IO66rWb82Ym5SFWEwsbpBF8A8iB7JwCydGL2I5mbLFY=; b=AdPCszGK82yHO3jDmhpLy4IS+JWtW6c3nX734VvYrh/BDpbn4FfowkUL5PX75Dxei6 dS02nNYIc1fVHSTscWDQeUvgG2d3T/4YCYZt8LbjUn1+qxMQJaefdie9TLRvtAzJ6y1d 0+Ft/n63PWs7/hg4NrE6TuXF0EGTP+eKr8xF9fj2VlPQuZNupbeB33WaqEHgJBHtE1r+ izUdgftq60sv6af/10+E94HxJoBEeGdHkKAxpTz9PQqeY00h5U1NNQNq0iSw3jfLpLSy edbLTWavCYjH0RjyleUblncHrgwzr7HT+ovG5wOXPqXhOjhrArC8aYa2Jv1q5tV64iGL BbrA== X-Gm-Message-State: ACrzQf2T/lDVAv4/bvEUf7aP6EDEI4qr7hmBYpbUZ1cpoCcUu8wwsuXc FXDQSD6e3SfiIsx8NvKsXqaq6aznNqOK X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:b8bc:a57d:a2a2:efdc]) (user=irogers job=sendgmr) by 2002:a17:90a:7a85:b0:20d:2891:15f with SMTP id q5-20020a17090a7a8500b0020d2891015fmr40660039pjf.107.1666635626193; Mon, 24 Oct 2022 11:20:26 -0700 (PDT) Date: Mon, 24 Oct 2022 11:19:11 -0700 In-Reply-To: <20221024181913.630986-1-irogers@google.com> Message-Id: <20221024181913.630986-7-irogers@google.com> Mime-Version: 1.0 References: <20221024181913.630986-1-irogers@google.com> X-Mailer: git-send-email 2.38.0.135.g90850a2211-goog Subject: [PATCH v2 6/8] perf stat: Use sig_atomic_t to avoid UB From: Ian Rogers To: Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Alexey Bayduraev , German Gomez , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Stephane Eranian , Ian Rogers X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham 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?1747601145236682296?= X-GMAIL-MSGID: =?utf-8?q?1747601145236682296?= Use sig_atomic_t for variables written/accessed in signal handlers. This is undefined behavior as per: https://wiki.sei.cmu.edu/confluence/display/c/SIG31-C.+Do+not+access+shared+objects+in+signal+handlers Signed-off-by: Ian Rogers --- tools/perf/builtin-stat.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 265b05157972..e1a5605adb97 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -173,7 +173,7 @@ static struct target target = { #define METRIC_ONLY_LEN 20 -static volatile pid_t child_pid = -1; +static volatile sig_atomic_t child_pid = -1; static int detailed_run = 0; static bool transaction_run; static bool topdown_run = false; @@ -208,7 +208,7 @@ struct perf_stat { static struct perf_stat perf_stat; #define STAT_RECORD perf_stat.record -static volatile int done = 0; +static volatile sig_atomic_t done = 0; static struct perf_stat_config stat_config = { .aggr_mode = AGGR_GLOBAL, @@ -569,7 +569,7 @@ static void disable_counters(void) } } -static volatile int workload_exec_errno; +static volatile sig_atomic_t workload_exec_errno; /* * evlist__prepare_workload will send a SIGUSR1 @@ -1029,7 +1029,7 @@ static void print_counters(struct timespec *ts, int argc, const char **argv) evlist__print_counters(evsel_list, &stat_config, &target, ts, argc, argv); } -static volatile int signr = -1; +static volatile sig_atomic_t signr = -1; static void skip_signal(int signo) {