From nobody Wed Apr 8 09:41:48 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A84F3C38A2D for ; Mon, 24 Oct 2022 20:00:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233905AbiJXUAD (ORCPT ); Mon, 24 Oct 2022 16:00:03 -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-Google-Smtp-Source: AMsMyM7mr42p3I5oH5NEpSHkDYBQ44el74P+LK4ELUYR9780/JS2/SSKzlney3clKu0vyZWDA8Pxbn80JtQY 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 =3D { =20 #define METRIC_ONLY_LEN 20 =20 -static volatile pid_t child_pid =3D -1; +static volatile sig_atomic_t child_pid =3D -1; static int detailed_run =3D 0; static bool transaction_run; static bool topdown_run =3D false; @@ -208,7 +208,7 @@ struct perf_stat { static struct perf_stat perf_stat; #define STAT_RECORD perf_stat.record =20 -static volatile int done =3D 0; +static volatile sig_atomic_t done =3D 0; =20 static struct perf_stat_config stat_config =3D { .aggr_mode =3D AGGR_GLOBAL, @@ -569,7 +569,7 @@ static void disable_counters(void) } } =20 -static volatile int workload_exec_errno; +static volatile sig_atomic_t workload_exec_errno; =20 /* * evlist__prepare_workload will send a SIGUSR1 @@ -1029,7 +1029,7 @@ static void print_counters(struct timespec *ts, int a= rgc, const char **argv) evlist__print_counters(evsel_list, &stat_config, &target, ts, argc, argv); } =20 -static volatile int signr =3D -1; +static volatile sig_atomic_t signr =3D -1; =20 static void skip_signal(int signo) { --=20 2.38.0.135.g90850a2211-goog