From patchwork Mon Oct 24 17:35:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 9946 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp606870wru; Mon, 24 Oct 2022 12:05:32 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7858t6ZMBlvum+Vm0MIX6ly8aX5kRLRTbt4/mfPuID8FvXoVIXev4oBX/Oss/nNYNGOxpP X-Received: by 2002:a63:8bc2:0:b0:464:69c9:9eca with SMTP id j185-20020a638bc2000000b0046469c99ecamr29636348pge.210.1666638332476; Mon, 24 Oct 2022 12:05:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666638332; cv=none; d=google.com; s=arc-20160816; b=uvE++2W2E1G8vK5jDqK33Ptw7HDqfMUN8YD1rfTWH6l/95IDu1RMut8MLWcBT6H+Os /ILYxhfr9UgvfqGPpW1mksubnUYgHfvg9ZP927ymaaB62GeNoUM4i1sPwGlWuDtr4fIJ BUF3nwc3bLaCmDpyK7tXem1S1Mc+UHr/9ADx4cFIagVtjk6JoBoG4eP2bh6oo5XBd4Sq OTfbJ6kXYSCrUhrSxjhQ0zg+Wlxz6SehJQgHwl1cXghI0+USPaDbqfdJb7fvwMzOKVlc vAkDeR+TnxFBI+ti+2WJQwQckdTY+Bo/DH8rG+kjYEknVguyx7EhQHdgnCESwklweHy4 HlRw== 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=yf//nKniGE2IxHdCyFgbypJdJyKGDk5InFKRkZy7usI=; b=lW9z7sD3SaS9JC4/zoGuxZ1DOagD/s+9SmU+RHhXBkwWI5DDDqWu7s6j7tZytJO1X7 1yNBwW/VDVfXzpm/gsvhSf7mYXguHlZx+MWtT3NJPwjTKEnbp7Zd3DaLLlEuzHBFQcq1 IIDYpaj+d3OIvXlYNXbcAL+qH2JgcZq/X7jbs++yG5oHsaxHNj+QGQJSz0D1Niyo7Ss3 uyaXoNK6LWXhjrLB3lPoxLXFVqpVF5cpsc0ncLEdOlPulRnJ4XoMLh3R7VzNwNv9I/7D RONNMO3Pn4Jwon7nudu33WFpR98RCBJ+4IcGerxz/15jE7wD8i+K+Beb9WVewThF1lme lTrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=bkFsx7xR; 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 14-20020a63194e000000b0046ec9d03aaasi261892pgz.589.2022.10.24.12.05.18; Mon, 24 Oct 2022 12:05:32 -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=bkFsx7xR; 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 S232641AbiJXS5Z (ORCPT + 99 others); Mon, 24 Oct 2022 14:57:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232704AbiJXS45 (ORCPT ); Mon, 24 Oct 2022 14:56:57 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B005ACBFDB for ; Mon, 24 Oct 2022 10:36:59 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id q62-20020a25d941000000b006cac1a4000cso4360820ybg.14 for ; Mon, 24 Oct 2022 10:36:59 -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=yf//nKniGE2IxHdCyFgbypJdJyKGDk5InFKRkZy7usI=; b=bkFsx7xRDT4SOzYnBWia39BL6PfxRv41NyEx8ZpXPvEJYtzo9fD7KHXUZq7dZ0kSp+ Cb52tElChTP5b28SYmcB5d9ym6Xy42R3VF0Ln930bKL9ke9DhtRKIIj95iTOkT7ehVgJ hSggoy02P/39UXt24GxVtWyl2QObBaYL2BAmTtIolM+YJ++faLGH2iBBfPtYnK7ZtOUm 0CH2aOJb0eXXsFA0urZ42cb0ZzLHirPS5E5WFPYWibD3/LMGxhPsBWW3gHfyZJl9Fcuu ou2vxzk0+j+CYMcIiAA/4ZOc/qL+YRdYHKuvBaoUeBWquw8scpTG1PNaCPz9/VIf1/+K l6eg== 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=yf//nKniGE2IxHdCyFgbypJdJyKGDk5InFKRkZy7usI=; b=38zy9mWLFXqkXDPXboj3I441nYchHUu6LjfvDSaTiGAkP88xmdF9K8+FFRBzFl5Pra FShNfoZvliZXHrNHHwQjwOL0GFHfqx2/AAZEWZ9zG8uT0KjyQ//S14sN2DyrR6AnrbGE x0qcZfsnBmD2+aSO3UwXNCgyqQ/N/p1nAc6UnZggS/M45+VBO+472lqUX6SRUnT8zK+G M/NibXyHI8xzMZkW02Vqr1a1jogrT2XeJ7ZjXMRoujGFElmQYh4F0nJhnx9pX2my9jym bDAo2291Fe3VbJv4EsRwIddGUdthalJEK55VkJ9VAi754T1x8v7esizoMyf0zG5wQzGI KFuQ== X-Gm-Message-State: ACrzQf1elBXh+1t31O0DaElhfQbbSFtvr2ALF4+O3z4SRoeNN8nLKz4K acImnMUmHFeWJBr1c7Dh51uuBzzsjxT/ X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:b8bc:a57d:a2a2:efdc]) (user=irogers job=sendgmr) by 2002:a25:bd8b:0:b0:6cb:d10:a5b6 with SMTP id f11-20020a25bd8b000000b006cb0d10a5b6mr5711316ybh.173.1666632951410; Mon, 24 Oct 2022 10:35:51 -0700 (PDT) Date: Mon, 24 Oct 2022 10:35:16 -0700 In-Reply-To: <20221024173523.602064-1-irogers@google.com> Message-Id: <20221024173523.602064-2-irogers@google.com> Mime-Version: 1.0 References: <20221024173523.602064-1-irogers@google.com> X-Mailer: git-send-email 2.38.0.135.g90850a2211-goog Subject: [PATCH v1 1/8] perf build: Update to C standard to gnu11 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?1747596956429617115?= X-GMAIL-MSGID: =?utf-8?q?1747596956429617115?= C11 has become the standard for mainstream kernel development [1], allowing it in the perf build enables libraries like stdatomic.h to be assumed to be present. This came up in the context of [2]. [1] https://lore.kernel.org/lkml/CAHk-=whWbENRz-vLY6vpESDLj6kGUTKO3khGtVfipHqwewh2HQ@mail.gmail.com/ [2] https://lore.kernel.org/lkml/20221024011024.462518-1-irogers@google.com/ Signed-off-by: Ian Rogers --- tools/perf/Makefile.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config index 6fd4b1384b97..29c49e6e76a1 100644 --- a/tools/perf/Makefile.config +++ b/tools/perf/Makefile.config @@ -307,7 +307,7 @@ CORE_CFLAGS += -ggdb3 CORE_CFLAGS += -funwind-tables CORE_CFLAGS += -Wall CORE_CFLAGS += -Wextra -CORE_CFLAGS += -std=gnu99 +CORE_CFLAGS += -std=gnu11 CXXFLAGS += -std=gnu++14 -fno-exceptions -fno-rtti CXXFLAGS += -Wall From patchwork Mon Oct 24 17:35:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 9955 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp608556wru; Mon, 24 Oct 2022 12:08:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Afwe/aZpxYmPqxRviFmCyTOw05pJBylTtE3QzvkyP9wuV3HgWZa5d48KLJOtOiiPedTzr X-Received: by 2002:a63:e755:0:b0:46e:c2ac:5fd1 with SMTP id j21-20020a63e755000000b0046ec2ac5fd1mr14260080pgk.184.1666638524843; Mon, 24 Oct 2022 12:08:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666638524; cv=none; d=google.com; s=arc-20160816; b=YxKB9w1kynR6eRFtrNXnCXgw6/Knpx+zxl1PdV8ykf/yUEbgjvAho+B6aMyUbeqIxa Er7cV9bji34caM4My3s7VQDEDz5HwZu7D/RmAK8EQx0Y34sqR6d8A5J3y6N43TRcJs51 Qzhd6vcOQq8Sr3VfCvBbrFh4mOh57WRmqDbku/VHVWNlS8HbzO8lN+oXtcp5bv77dbbX RzY0arA7zBMha6ciDmhS6FX7FvxcAWsw6982SS+kaI4lR5T7wO5cD3p8osuPv40sI5FT 1dS31QYBFa5p9ckdlw5JGCl/MiMwAFjNjiGjZfmfOn70A2Z/tyv2H1Cv24mW3MzueulH qTSA== 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=Cg26NKxObx9cPNlbM/mhAsHD/ehUnl2CM6D2kDhH0JM=; b=ifi5r3l+GiQLepOfKiNa9L3cUhtENNgrKiMmCTujwFPFrZTC65xpGwgABCtz/2fte2 GU1PRMoRqyl/ChzqSVwRXDrhSDU+RwD3BzzUXbq7GMtCX3KFImMW31v5jos2fbkVG3Z6 o8KWBwJP0jbGi0nbs2fEbo8LQXqzdo0Q7YPD4D2NBwwrdXfSwlrX+SkFg1rG11FUNv/P mq4V5YQgQfFpuLKE2ezDxnsT/LGRt74t6QSdECqPToYL4B9pjb7yOyIAdhgl/qCgtHtS IKCBbPi0B22pdMqnRHzgy4F2NBqSnnHUtfhqDrEblz1C9Gj4tcdR0VQLCNHRSYuXxATl Tu4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Hqqahl8o; 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 m4-20020a654c84000000b0043adff6d43dsi278430pgt.583.2022.10.24.12.08.31; Mon, 24 Oct 2022 12:08:44 -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=Hqqahl8o; 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 S232831AbiJXTGF (ORCPT + 99 others); Mon, 24 Oct 2022 15:06:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233757AbiJXTFH (ORCPT ); Mon, 24 Oct 2022 15:05:07 -0400 Received: from mail-oi1-x24a.google.com (mail-oi1-x24a.google.com [IPv6:2607:f8b0:4864:20::24a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20BCF915ED for ; Mon, 24 Oct 2022 10:44:53 -0700 (PDT) Received: by mail-oi1-x24a.google.com with SMTP id j8-20020a056808118800b00354b7e75b46so2220887oil.16 for ; Mon, 24 Oct 2022 10:44:53 -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=Cg26NKxObx9cPNlbM/mhAsHD/ehUnl2CM6D2kDhH0JM=; b=Hqqahl8ovXopQPb7uIKtwoTdJrjEL1o1/d7xnlSnlFSlQ1QzOGUv4npflfCXUCsfYQ AAjlIIk0BZnDAG+ImVC4wa94gcewBYm+zGwO/MaRol3lrxLdrXCJdrVn5H0hyx4Q2OW3 2JqxUZ/TMKXdPIg1AmeE43USOIBlNhP3WN+Je7SXGkLeufqUIh3jdpK19uC+rt/5kA4A hIwKoPwBFPXH3YqBsWW95a4TmH9uh03H8Awp8NyeLq+03n3zMHlDMT1hW7XUXyFENy+M R2ONicYhaHRBoRnx0dbyeFMTdvleVg+NHwPWqZqDGBc/zpZtgZlB1gtjY1pwc3D55Bwo ypDg== 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=Cg26NKxObx9cPNlbM/mhAsHD/ehUnl2CM6D2kDhH0JM=; b=cYcrBHqY2pJmEbekFT0GEhQC41RdoI1KFpDmO0m9stiaFJoJcHskf+5Psu6RhaEoa/ L/Mj0W+6e3lvr36wQ3ltZWVlD0L1uJtbrMQVk7/yUa4Kis8UBCR+Tk3cYxDuzLipbWQr +WCd41zKUrAKa98vKtzDU6zr9VztacTmFgtWXG/Q9BNd+xx56v8Ad3tN2PyD51Qp/p3L rzW1ulyGVhlj7QTrgv4+r6Eh8wvypuJZxvRRmUH5BZ5Ys5aeXcXxftr82jLimH1b3SrC OXqX2E0btrdXX+C+i8NcX00Ji7Q1BEsqA76maxNHZnHxEmvD+cOP4VxvlrUPrNNohRt3 rFYA== X-Gm-Message-State: ACrzQf0/TwOHkeHd2lgJX6U06gpiA6XQp3atcaSCBoJHD8B4a8u1jLoN blbDun9uClf/4UQ8WRXdutSGgRbuMpsJ X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:b8bc:a57d:a2a2:efdc]) (user=irogers job=sendgmr) by 2002:a17:90a:cf82:b0:20b:3525:81ec with SMTP id i2-20020a17090acf8200b0020b352581ecmr39048692pju.42.1666632958899; Mon, 24 Oct 2022 10:35:58 -0700 (PDT) Date: Mon, 24 Oct 2022 10:35:17 -0700 In-Reply-To: <20221024173523.602064-1-irogers@google.com> Message-Id: <20221024173523.602064-3-irogers@google.com> Mime-Version: 1.0 References: <20221024173523.602064-1-irogers@google.com> X-Mailer: git-send-email 2.38.0.135.g90850a2211-goog Subject: [PATCH v1 2/8] perf record: Use sig_atomic_t for signal handlers 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=unavailable 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?1747597157576286843?= X-GMAIL-MSGID: =?utf-8?q?1747597157576286843?= This removes undefined behavior as described in: https://wiki.sei.cmu.edu/confluence/display/c/SIG31-C.+Do+not+access+shared+objects+in+signal+handlers Suggested-by: Leo Yan Signed-off-by: Ian Rogers --- tools/perf/builtin-record.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index e128b855ddde..5332b9c05f28 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -61,6 +61,7 @@ #include #include #include +#include #include #ifndef HAVE_GETTID #include @@ -646,10 +647,10 @@ static int record__pushfn(struct mmap *map, void *to, void *bf, size_t size) return record__write(rec, map, bf, size); } -static volatile int signr = -1; -static volatile int child_finished; +static volatile sig_atomic_t signr = -1; +static volatile sig_atomic_t child_finished; #ifdef HAVE_EVENTFD_SUPPORT -static volatile int done_fd = -1; +static volatile sig_atomic_t done_fd = -1; #endif static void sig_handler(int sig) @@ -1926,7 +1927,7 @@ static void record__read_lost_samples(struct record *rec) } -static volatile int workload_exec_errno; +static volatile sig_atomic_t workload_exec_errno; /* * evlist__prepare_workload will send a SIGUSR1 From patchwork Mon Oct 24 17:35:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 9947 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp607023wru; Mon, 24 Oct 2022 12:05:53 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6nUF7DYPA+t771EX9tT79/jtaZpVcmDypFMw5lPaynPKarCv+dAofORiM/lRcJLn9WJWGj X-Received: by 2002:a17:903:18b:b0:185:43e6:20df with SMTP id z11-20020a170903018b00b0018543e620dfmr34052935plg.4.1666638352978; Mon, 24 Oct 2022 12:05:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666638352; cv=none; d=google.com; s=arc-20160816; b=FQELBx0kFThlzEg+HqqBKPzuAdl5w7bhitgq1lZKskrrwezd9jzQZhD2rpkaYa01c3 oZMWbAdQdSPlFWHkfKaTp6S8w4UPFNfA2hyaHtWeL7lXPLzTwYieUj/eh7GCxcpmu5KN ZKL4nb5k727F1KQSl3ICRTqlAlskng7NJk3jh4jL0SX71pVMtn7VrNUYjTcMmxI1LMzl RU1lPv7lajlRGeySRFbU0jKWhqgvaWETXJ/rdjYThMKofEjvckMqtR/7lDjxh5FhsZIl 3CykLLXqFye3ZJzEAcKqhO/SwQZfxogLChOqHM7QKrFlBTAmSYXBGhPe2R8PHRyn9AWb 024w== 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=3arsizWDDWH+MKNBhUVuOKkALW8L2napp9/1OYe9kXI=; b=hM0IUOE0XS0/RLqp+UU4NNn7FwUJsW2zPnrR82j/seN5kgKMxWOITL2hAMiUxlWrAq xGRMsVvuSsdnoB78Su5nDNRVGDscj7eyotHqFLi6pFQa0y4zXajOHMJmsb62+vBpD6Yn q+2Aoy898/28ve6bxusI1T/xHU73qI+ZaCHGVeoN2Vbl91uA9sx+0bIOG0rN1I+PXbHB 8h9SpA6cACAQWAVm/0kllyZyCdghsrgMD6YkXoO9mVvnA0z3PkQE/77ptXEtjAW99lZl u8PWbQZeEbuvIvGhxUtlVYFDlI/HMZu69us+vo1/kPgusVFzygudrn+ud0aZxfmGk4vq US7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=OlvnzNTW; 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 b6-20020a170902d50600b00172c1c6abc1si387152plg.172.2022.10.24.12.05.23; Mon, 24 Oct 2022 12:05:52 -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=OlvnzNTW; 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 S232948AbiJXS5p (ORCPT + 99 others); Mon, 24 Oct 2022 14:57:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231721AbiJXS5H (ORCPT ); Mon, 24 Oct 2022 14:57:07 -0400 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E73881683 for ; Mon, 24 Oct 2022 10:37:14 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id g6-20020a17090a300600b00212f609f6aeso1681235pjb.9 for ; Mon, 24 Oct 2022 10:37:14 -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=3arsizWDDWH+MKNBhUVuOKkALW8L2napp9/1OYe9kXI=; b=OlvnzNTW+kTD3+3BfP32Lyp4zweV38hpVb3JBzX9Kl8cG8rpDJwS1PNWPBbQM81X7f XKoN0dP+gbL1BoM6bbsYOUT8B0ZSkP05gici5Rw/4uDCV2QhO5VIArmr/WGmb+lyquko MEp9EfBNLkEiRITbcWDMY5AfjBW0VSuakRM0IjX3+ypLC7et5HlFvKeeSZkkUyZ2fgYL qjcqke3JcYNj49+1ewf3HmEDkdr068IEqFDOtG5SXPz6C9CH3xahhFqdnIeu4U93HlqJ Wie9R7uYy/J60mKIfLJXhEBhu94B3NPzKcjwM8I4REAdx2vKxSEgeXC/g4fvTLoMXRJD WwdA== 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=3arsizWDDWH+MKNBhUVuOKkALW8L2napp9/1OYe9kXI=; b=Xg+eQt7YZaFBUIJdDXmocS/w301Tk6xR5FbpsDI9O89RYAVwXlhrncc0NqJi3jWQmb jU5MCuDEfZ7XjRtfH9FI7zxAuQaFlzw3EHEZ75lyVFSXbLscTwB90BRNUabXctjsJekv /0N3ccXfEBp30DozJcsjeZ1APM3xkXjMell07OlEda3BIwujEIebu6zx0Vg5MYkynv/a FyUn7b7xT1KVPpCAapPG6500R/hR74OZ+yBk9fJ+shWaGM5KGsvEehvuIEraaep3G8P7 wdvK/WpCp0hNP5cj41okaFKjhK2urhEg6EhEVS5SrduS7Nr2uUdLf8Y/ORUeFev+vobz GleQ== X-Gm-Message-State: ACrzQf0brpL23ZMuOqa464oem0kZNr67QNPYih9GGjjEo2IvfustYS4m IT7oVOnBESJ5SFmbFnokEoAXe+jQOapP X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:b8bc:a57d:a2a2:efdc]) (user=irogers job=sendgmr) by 2002:a17:90b:38c4:b0:20d:9dfa:4339 with SMTP id nn4-20020a17090b38c400b0020d9dfa4339mr72319030pjb.74.1666632966573; Mon, 24 Oct 2022 10:36:06 -0700 (PDT) Date: Mon, 24 Oct 2022 10:35:18 -0700 In-Reply-To: <20221024173523.602064-1-irogers@google.com> Message-Id: <20221024173523.602064-4-irogers@google.com> Mime-Version: 1.0 References: <20221024173523.602064-1-irogers@google.com> X-Mailer: git-send-email 2.38.0.135.g90850a2211-goog Subject: [PATCH v1 3/8] perf daemon: 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?1747596978033152484?= X-GMAIL-MSGID: =?utf-8?q?1747596978033152484?= Use sig_atomic_t for a variable written to in a signal handler and read elsewhere. 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-daemon.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/perf/builtin-daemon.c b/tools/perf/builtin-daemon.c index 6cb3f6cc36d0..d05084952c09 100644 --- a/tools/perf/builtin-daemon.c +++ b/tools/perf/builtin-daemon.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -105,7 +106,7 @@ static const char * const daemon_usage[] = { NULL }; -static bool done; +static volatile sig_atomic_t done; static void sig_handler(int sig __maybe_unused) { From patchwork Mon Oct 24 17:35:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 9948 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp607049wru; Mon, 24 Oct 2022 12:05:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5u+C6gv8bO5LzkPTXTSRONZVeCW2azAR3XnjXiJenZWmloBpKKbbaJuEayrLb0Qm9WoAvK X-Received: by 2002:a17:902:b589:b0:17f:5756:b3f9 with SMTP id a9-20020a170902b58900b0017f5756b3f9mr34567735pls.14.1666638357662; Mon, 24 Oct 2022 12:05:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666638357; cv=none; d=google.com; s=arc-20160816; b=FALkBQebcACgnSsoCE4pW2CCENOqXvGbQdwJ2Kv37WnH6FNSN+PRUCnfYlDpq0xlCB cDeeoIo5izndDPQzYDAI/+94+MgG01xtGQhiSnHeP1ZcwUtuCDITjBsfHvFxM17Z7d9T bpxiuoSoWOTY3Acal/HMDUP8gCrq9Vj6099ydvvcMeHeApmD06r9Gi43rRfBHTqgJije 8efQM1NdYHKvpP7AlfD+R+WdIvjg9j4r34lpEPSWWXt4pacRZ1L8AZoRH+LwFAHQHTNH yylOVpUQmCVkvdztRMLfV/ALf49LdUx+FfirGpjXXVkJETS9uvbiwykT8HPlgI65wkGS duRQ== 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=anPThKUkfGYO4MityDcRpU1q0+xCNjbPUERJ4hXkoEA=; b=kCoA5h29nXWOtpDu8C8xut3FGR0w2Dvi6h0m3TS6irdFdD+rMEFxY6moRti7ZiFwMx IFGOiuwPD2cYVk/HHvTHazxq7b3ciVEU2vWmsUnRinGhXrsyXYUgWdcmQuM64GMwcavC CDcXGP7oXUgvbhXzjch+Pax1Li7xT1XCgKBCvYCwVYDPoRbyrSLwuLV9aOFQt2XdjnD6 6oVUrQ1lP/rmjv1I4fADS8nWUYf10wSdrxBsYR4kqLsEsa6voJ81eE+ZmqZeRzqwK/xO /28taiJ0jJykTL138hG7OpLWIgbk1w9uT568iwh2LYBM14XfrTk82QsJO+Tu7MtvtzJH XbTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=PfDVYoST; 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 oc16-20020a17090b1c1000b001f0311d12d0si11682590pjb.185.2022.10.24.12.05.43; Mon, 24 Oct 2022 12:05:57 -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=PfDVYoST; 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 S230335AbiJXS5u (ORCPT + 99 others); Mon, 24 Oct 2022 14:57:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231552AbiJXS5N (ORCPT ); Mon, 24 Oct 2022 14:57:13 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8C55B1DFB for ; Mon, 24 Oct 2022 10:37:20 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 130-20020a251188000000b006be249d0a70so9832033ybr.2 for ; Mon, 24 Oct 2022 10:37:20 -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=anPThKUkfGYO4MityDcRpU1q0+xCNjbPUERJ4hXkoEA=; b=PfDVYoSTOvxujmA929mKarnso4WjqFDWW2bmFKktkEtczES8mG4DER2VLr5qv7Autw Q8VBpRY/deX1Dz17HaSk+iFAthZQb0VGSP2gad5/7EnWN575WvXu85aE6KNktQpT7e++ JE6+jyt46d3qWFVVq763Vf48hue5KkqYQzzBw2r6i97cVYGX0Q16Y1gd513g30u7z8fh 7XzpxBvtkSoBTXiUQMt1ymYvIYi1IrpBX85rr5+n82XhYhPyBHfx7wIxgk9JVXSWLkVT NjlWgVTl7f7ad/e2bemq4wNdBELHqDEe3O0B9mmkTKblHddHgxvkgxkGePJDeJCeO9gY snHQ== 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=anPThKUkfGYO4MityDcRpU1q0+xCNjbPUERJ4hXkoEA=; b=EROYbAxKasVjm4OHPlWwx+9Mzs+9wXoh4jRgFpzJllUWsqajfl3V9XOaq8oZN7UDTR /H2W7DUNi92PlVDxYXLY5MerJFZSfMJvTtBi+FYgyebaj4UzJ1z/vyQB3mjzY0ypY8q7 U8HuLVPkV1H4p85zTWYiuFp605A73Vx7/THZWR8xQN6KVcI5wrooX+TRTXk1ZQw5N1cX VTCb7NiQNFw8BV0oGZyX7A1HdLb96wqSTLbpVVWTav3ROPF0oyrWW3WjRcYC9m7w5SZT lbkp0O1MIx/s54EUDHP0hHci4PpLgAlaJggqPWVh1WWH9ci8xQxBWM3zL5I7KlEk81dT 78xg== X-Gm-Message-State: ACrzQf0JhTijz+d+4DeO3/NUB+7R4Y727GDC6GBfiMSI22+Bz5MkNNR3 UPrNK1ER3Ep7ZvBbZVgmJF+tGMtDfybr X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:b8bc:a57d:a2a2:efdc]) (user=irogers job=sendgmr) by 2002:a81:2513:0:b0:368:3de2:7655 with SMTP id l19-20020a812513000000b003683de27655mr22126537ywl.488.1666632974562; Mon, 24 Oct 2022 10:36:14 -0700 (PDT) Date: Mon, 24 Oct 2022 10:35:19 -0700 In-Reply-To: <20221024173523.602064-1-irogers@google.com> Message-Id: <20221024173523.602064-5-irogers@google.com> Mime-Version: 1.0 References: <20221024173523.602064-1-irogers@google.com> X-Mailer: git-send-email 2.38.0.135.g90850a2211-goog Subject: [PATCH v1 4/8] perf ftrace: 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?1747596982521586447?= X-GMAIL-MSGID: =?utf-8?q?1747596982521586447?= Use sig_atomic_t for a variable written to in a signal handler and read elsewhere. 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-ftrace.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c index 7de07bb16d23..d7fe00f66b83 100644 --- a/tools/perf/builtin-ftrace.c +++ b/tools/perf/builtin-ftrace.c @@ -36,8 +36,8 @@ #define DEFAULT_TRACER "function_graph" -static volatile int workload_exec_errno; -static bool done; +static volatile sig_atomic_t workload_exec_errno; +static volatile sig_atomic_t done; static void sig_handler(int sig __maybe_unused) { From patchwork Mon Oct 24 17:35:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 9949 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp607198wru; Mon, 24 Oct 2022 12:06:15 -0700 (PDT) X-Google-Smtp-Source: AMsMyM45mCCd3gkvBteNnKFtlqbMuA5B+QFFlJVK3qdguWidyKpPzOaVTFJK7G4oy8T1rOY6POk1 X-Received: by 2002:a17:90b:2684:b0:213:8a8:b5df with SMTP id pl4-20020a17090b268400b0021308a8b5dfmr8606200pjb.77.1666638375083; Mon, 24 Oct 2022 12:06:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666638375; cv=none; d=google.com; s=arc-20160816; b=rKSTRodj8Wy84Qpj6HY+KQyj+eQXk7N32z0Yuqoiv0utwo86kRNcFulqhSaE1LvtVL ILTtl0s4drivan1j3qlTzOjMKtPwT5yrJ0GAxl8tIbrC/avmWQ9EXT7s3+P74FC2SX3g b/gD2n1lnpcu9149L6/BqMIPnI18FOP4U8D6+JKvBilpeIbVbfE0TpTLvJk2yodq4fFC bh7vv4C0TBnHx86yzk/5JyAnArST077BP6rpo0PefhHq89WyS/lKNIt9bA/e5PZ3E1lP oDjTMeEhE7wX3SzkCyP1YFsdV9fjLMHbXCS8qbl3pMWY6s+FpHtQcVaF9AwbxGRTc2ms r5Xg== 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=hFzbgI1FGJfzvaw1p5CnFtlagUkgu7Ee7Fasb8Aycow=; b=wyq9i7EusU/jTE6bO09/xQDoe8R3D2ECjMXxQLpPWMdV+SN/p72b1La2NMP1dvCE4W hhiqoiNXQLo1epbSaT4xPkuB6RVgzCTzZLyqj+suliGUDyxAggz9P/0QzypHFOetEUtK zPVmTvYNAIOkYejA1XPtTZerxK17TGI768HAwNpMAnlaTGIOR5PfmyDVuuPao8Fa/ek3 ht8mOUcn4RNd8PWQsOSpuC1Og6zLrEbt3+r/Csw8PX6yrbR6XCSwnT0Z/hrweZl5PQFy y7/BpZYRIvQeYE3P/moj3F8W35pJwh3qcI2nCSJc3cNOrs4aQq3IBMMQC3XU9spnTeYu 663w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=g6qsNykj; 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 k8-20020a170902d58800b001865c55049dsi220312plh.570.2022.10.24.12.06.01; Mon, 24 Oct 2022 12:06:15 -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=g6qsNykj; 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 S231403AbiJXS63 (ORCPT + 99 others); Mon, 24 Oct 2022 14:58:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232907AbiJXS5o (ORCPT ); Mon, 24 Oct 2022 14:57:44 -0400 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B5B6105350 for ; Mon, 24 Oct 2022 10:37:44 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id pf1-20020a17090b1d8100b002132a9a6a44so574117pjb.1 for ; Mon, 24 Oct 2022 10:37:43 -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=hFzbgI1FGJfzvaw1p5CnFtlagUkgu7Ee7Fasb8Aycow=; b=g6qsNykjBvc8d3AMtRafZDv5pP5cGaxqxFeoYFGwLROZDHq+3WE2OKYgVBPVOjacpP Su1/KJ1NSg8qrV0haZyA6FY4ifaAtIIXYNxNPiIkdwfQ2D90z+QD1IlGh/RuxOWh7i2c VME/ZGXfkVOKwf52i6LRPxNoVKvaIcqHKhHTOIYGpRhjbjHoJkdkOpvZ88pUkrDAWJbd H9U69WkQT55DQxWyH4w6TKsAKG1luUqFVxlofXfJSOSNZe2uB2cFmt4300lCYBm2gv4L ovqlDuERntsgpv0Q3tM6N97YOvFooB+FhMo3fM41rUO1tHvbFUysFQORJzWsXB8HzkkY q4oA== 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=hFzbgI1FGJfzvaw1p5CnFtlagUkgu7Ee7Fasb8Aycow=; b=qLgndwvs8Zi4xzQsM1KrXlfc7pjMdK7fR1iU9tBkKHgH706/cEo9KCQKQvjjlWSKAX t0RhzA7+0sdMajz0wTyiFgRaj72vSoDZhqQihOoT8davOAcdcat14G4SnESEGSRJjiAH VVbqGAraSVGNXYLfz2q7PHxwagdHuxkTgpBumgLaxENCWysjKyMf476GkPd6AATP0eXO jsc2S71gvdj5gwOEXK3D0XT723HxEQY0T8fpGkNs6uYpKpcPjdBKJVYOvPPNt76vdr2F n/m4o7AkvW33dz6oqKDgtrSNjon+VNidv6dTIfH9xkaisnmyWjnZ3RbbY4hg5RXqDlSc uqAw== X-Gm-Message-State: ACrzQf3AF3HttNy1c+FfqKmoU+eaD5DQv865CjdzSe/w3RJpacSETH9J Zx5JZCnTNCFWy+G3S7dog1kRJTiubjHG X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:b8bc:a57d:a2a2:efdc]) (user=irogers job=sendgmr) by 2002:a17:90b:1b03:b0:20d:ac3b:f1dd with SMTP id nu3-20020a17090b1b0300b0020dac3bf1ddmr65650424pjb.121.1666632982742; Mon, 24 Oct 2022 10:36:22 -0700 (PDT) Date: Mon, 24 Oct 2022 10:35:20 -0700 In-Reply-To: <20221024173523.602064-1-irogers@google.com> Message-Id: <20221024173523.602064-6-irogers@google.com> Mime-Version: 1.0 References: <20221024173523.602064-1-irogers@google.com> X-Mailer: git-send-email 2.38.0.135.g90850a2211-goog Subject: [PATCH v1 5/8] perf session: Change type 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?1747597001020453111?= X-GMAIL-MSGID: =?utf-8?q?1747597001020453111?= session_done is written to inside the signal handler of perf report and script. Switch its type to avoid undefined behavior. Signed-off-by: Ian Rogers --- tools/perf/util/session.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 1a4f10de29ff..ba52cc4092dc 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include +#include #include #include #include @@ -2022,7 +2023,7 @@ static int perf_session__flush_thread_stacks(struct perf_session *session) NULL); } -volatile int session_done; +volatile sig_atomic_t session_done; static int __perf_session__process_decomp_events(struct perf_session *session); From patchwork Mon Oct 24 17:35:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 9953 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp607760wru; Mon, 24 Oct 2022 12:07:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6vn1nq/z1QhRd09C7omjd1jB5vECDcxNSSaIl1B7sQXNsSFYlx/+coQ7135u80h4bI5Ntd X-Received: by 2002:a17:902:ced2:b0:186:9803:76bb with SMTP id d18-20020a170902ced200b00186980376bbmr10988085plg.83.1666638429954; Mon, 24 Oct 2022 12:07:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666638429; cv=none; d=google.com; s=arc-20160816; b=SskDR+X5L8LHLTxySYj7g4HM/NQh5m6Kjt3cpMSp4r46rOQmSRsZ6wL2LOp3+aoXye 2hMlzrEQFK2I6/YGTEnUDKNePMOhuetoywqqE9Wvi9qTobl2uoqy+TdT3YI5NQxDwZ4I YpdlvRU/ajZsEbR3vbQ/ioN8xCwYVhA3/O04fp05lTRLjiHimSg4PLZtBLWKebldEfck RYzMIHaWcHfX1Cbd/IP8YT8MRFD1LHeEGeNn/i28q96pvnP319Kuh+3y+ra1VAkrtPf9 ZnpRvlAKH2nHYL2ZUWEjN9KCOYaOM50Vbx03/ZLW+9PyNo5d2JzCVJ/SXc0jF9lkYEID RoaQ== 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=QEp3gHOpXGArSFAK8kT0WcuQTUqFi2M7wcWMFBGh4Ac=; b=nNT4wHwINnz7/plSf16DGAZkAP8C4uRGLy1aoBESNJwd7c2I1D6ncWkjEZO8v3vmRW OfEIOKIGCMdftEdaIw2zsD7aIkONZ5mWGokb3jIhBteGT9UbLyA6xAJ49gHxcHk8oXZR vBZdFQRHibzVrOu73NaZcNgIN4syxrW5KAuS+3bEk2MM5O/yVYZg2/Kmf0nMl45+ZQ+W 7ngJyMMZy8Q1Cg238AwlDEJtun5YZF3Hs26MnP2sTKej/LHqwodEvniXCInJEAsbpnys oOXU13A/bLqvhlyG9CRvBSPomnh6X1Oa9OkKk7v38NiTEk1aIdO/ssGTdJiJ4VX97GHX SLjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=GN2Lg7Og; 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 v184-20020a6389c1000000b00460358671dfsi273358pgd.513.2022.10.24.12.06.41; Mon, 24 Oct 2022 12:07:09 -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=GN2Lg7Og; 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 S232818AbiJXS60 (ORCPT + 99 others); Mon, 24 Oct 2022 14:58:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232448AbiJXS5o (ORCPT ); Mon, 24 Oct 2022 14:57:44 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6D228E7AB for ; Mon, 24 Oct 2022 10:37:33 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-367f94b9b16so96970197b3.11 for ; Mon, 24 Oct 2022 10:37:33 -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=QEp3gHOpXGArSFAK8kT0WcuQTUqFi2M7wcWMFBGh4Ac=; b=GN2Lg7OgUbAWHRuK4qJUwWr9eJwcQ3WTCuHSeezMa1W1zVxcuWl2iwk3n+jcrOHAEm aifzMeBo3/bJbLMhOZ65l2+B4Y8z+QQrx8f2wvgIkoYFd73QkNXUmkAb32PLV80i5Rr9 TQqCmNn2OyWoR+48I1Y07KAJP4GgmKQGsVCQcgyeHJqiugcQf5osSD0zvchkWCcSA2YM kDCUDfUorZg8uTr7zN65tuziIfMpEqTtmH5deuJbnEkarcE3cB39VApi/RuRKtrJpfm9 R9xOPvysoog3mqKdJL9BY7b5s3Ep/Ygk+IGoOmFvYFejdjcPTB37ya+iwD6plChLNX4g q84A== 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=QEp3gHOpXGArSFAK8kT0WcuQTUqFi2M7wcWMFBGh4Ac=; b=L8Eb0GXzQtNX4HcHIx5pFlMIh8ug2Ndb9JGvOuevhYN1ULfpMiCR8MSG9gLIllSFOo Sur12k4gEBrbyx1GwjFFEQWahpW+YXX+4TpUavZ6WWgiy0kMwnXA5BWYTBbTW/zNqhwO 6w88ycPh3JaitXKYPitIyb+/h4LSbBwaBzyArsuaVJXXJFr4wrUHCGN98yfpySjQGUQA tJKsC3E6v0s78JjimAFbwGBNXZPbWUz8bcNqJp75VdH+IOrr3itAaLbACNYK8lQBpIKt IJiPThbUH91ofR13XGxwV7A+NjaBAZVPgSb/BEKyxHb2Crcin0VHBo0P+yCN0GtnFVUf owfg== X-Gm-Message-State: ACrzQf3a/42VWcEp85srBPcmQHZvImp26xsEPnnMCn8Rfvxruhpio33K NYuUKLC6mfIs9xhNijHi36fNzrKC0FsJ X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:b8bc:a57d:a2a2:efdc]) (user=irogers job=sendgmr) by 2002:a0d:eb92:0:b0:36b:bf3:d56 with SMTP id u140-20020a0deb92000000b0036b0bf30d56mr11423120ywe.28.1666632990914; Mon, 24 Oct 2022 10:36:30 -0700 (PDT) Date: Mon, 24 Oct 2022 10:35:21 -0700 In-Reply-To: <20221024173523.602064-1-irogers@google.com> Message-Id: <20221024173523.602064-7-irogers@google.com> Mime-Version: 1.0 References: <20221024173523.602064-1-irogers@google.com> X-Mailer: git-send-email 2.38.0.135.g90850a2211-goog Subject: [PATCH v1 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=unavailable 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?1747597058136738957?= X-GMAIL-MSGID: =?utf-8?q?1747597058136738957?= 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 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 265b05157972..13bb8508d228 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -83,6 +83,7 @@ #include #include #include +#include #include #include #include @@ -173,7 +174,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 +209,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 +570,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 +1030,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) { From patchwork Mon Oct 24 17:35:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 9950 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp607248wru; Mon, 24 Oct 2022 12:06:21 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7OOCjZ1vGlgStwGmFW/T/cVa+/YmevGTQk0fXNJznddp0/sGuiHN29KkS2SOR26fzsNtqG X-Received: by 2002:a17:902:b117:b0:186:a1fd:c3df with SMTP id q23-20020a170902b11700b00186a1fdc3dfmr7987545plr.23.1666638380983; Mon, 24 Oct 2022 12:06:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666638380; cv=none; d=google.com; s=arc-20160816; b=NXOvrEae6fVYbiq1awvp6fQefF1TZi5TxUVCw35yb360VShIGqgcjly6ugcojCLaCD 96B+oP4qXF7w4rABa3MJf3vRtB9D7A9VereJLoeRtM9Boeu8Q/ZYLpK5/CCta0zrKtrT GW2L+zjmMkljq2bIDhpdOQJmV27XT91iBGKpmo5u+20B/IkIdQY6yeSjcv4DRfY5HUY7 5VMRclCc3qaTdavELOAXavJDMyu/j/joP6OtRgufWKH3UWDKeL76j6Xon80XNTAeeq3c bCoQXuYzipKugC2r5QTgWcyKmEsU27w63EbZ/C+tbftgEx5stzjYwOJd+FLe08awlWNN wrxw== 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=kzKQRTEXGqt08SGBdEhLKezf4NlN9FWNmZKirRw+wNE=; b=IekR1mElh565LJ2S5FypD0082+sNQtu+2qL/vTrAb+I6Gt75PQRieBUsWyu0n5rpei kFPnUWhTeivG5FUqRihdvSPBtofKoK6uHbViU3s6ab2uNy3Zh1HvW6I6NRty4VKrh0Sj GGzTfxJl7VPEYayhLcHOyxZ5WR5wNeeZk2Jmv9CSCbLmILvsl/2Fs/81Quw2uEcVyDeb 4ImNrAZBS6GDCddtMZ7Of0WY45VorV+7utKqL9G7WjBCeqxd4vo69RovXat2ms11z33v VVd6PPpah0LcYVOuonuV/xzSu4JNZs05+yGkew9VQrdREg6KhZTafOa6x3Z87pA3oYXk IpOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=j+74AYOx; 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 b3-20020a639303000000b004612e8df649si252709pge.784.2022.10.24.12.06.05; Mon, 24 Oct 2022 12:06: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=@google.com header.s=20210112 header.b=j+74AYOx; 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 S232936AbiJXS6i (ORCPT + 99 others); Mon, 24 Oct 2022 14:58:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231484AbiJXS6N (ORCPT ); Mon, 24 Oct 2022 14:58:13 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A55F0B8C1A for ; Mon, 24 Oct 2022 10:37:54 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 204-20020a2510d5000000b006be7970889cso9905439ybq.21 for ; Mon, 24 Oct 2022 10:37:54 -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=kzKQRTEXGqt08SGBdEhLKezf4NlN9FWNmZKirRw+wNE=; b=j+74AYOxCaajozdBfiO5kv/80FZYXYndelThFiPyXfTn5d+15h0iTwKi762lYKKt3M wXCC92m2LibdA4uqtYnNfy0lNPA1tSrSqmtmmO/doOPBrPkkUDb1C+6ElrbnmtRX6M5R Fe4V2jfcpE6ePzNLE+3Q84vJggdtywVZ5+x9VA7CLp2obDtqoh5VLeHIPpob6Jn8w+Ql 10SMYYl33WZclEXBIpVktcohFEvcfz1wo01/cPGUwMJ93DIY41SmmQ9P9CV7Z9X3QhGp KZqbj05kQPns4meT8vTk/c7Ym60Ec3DoHoiaqN39sC/PReynUtjWH61qFKOotqnS6Nw9 pgPQ== 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=kzKQRTEXGqt08SGBdEhLKezf4NlN9FWNmZKirRw+wNE=; b=mqmM+Zo9zzVYoVFTxwUGgeRwEF0iDGDMrtQzTpb+mkhGKQsFcuFki9BUpSFHPn2yyt 0euEsEI7MfdbQKIYm5c6hD0Ccfb0oivATdS1lUSLeXHPqTRM14qbKkn13LyS1fC5XVZF xCHgZPX+eNCaHO2G17SHBwt6IBpLBV7R90bxQUNMwHMS18xMTJDXmybPjuAlIqrWz4cg RNEIMQng5D6TKafXrapSzn64qqosnQrxfyUq04r1sDC3Rusr+7W8NzlraK/RN0aEmYBd SgUYA0EL4zlekJPJ8jXCHujB+v5WKyAXqf1L9AJd6mHBIFMzyjE0QwGBMI6nPYJiRRP1 eLzA== X-Gm-Message-State: ACrzQf1+aQa7/5PCKsbSd4uAeUu2WNCTs2Um9O83zyBVkr8TMNGczXxJ yrweYbHYi+ymoUknR4Yj7OCvklvX/lS0 X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:b8bc:a57d:a2a2:efdc]) (user=irogers job=sendgmr) by 2002:a25:dd2:0:b0:6c0:7938:5b43 with SMTP id 201-20020a250dd2000000b006c079385b43mr30564176ybn.280.1666632998495; Mon, 24 Oct 2022 10:36:38 -0700 (PDT) Date: Mon, 24 Oct 2022 10:35:22 -0700 In-Reply-To: <20221024173523.602064-1-irogers@google.com> Message-Id: <20221024173523.602064-8-irogers@google.com> Mime-Version: 1.0 References: <20221024173523.602064-1-irogers@google.com> X-Mailer: git-send-email 2.38.0.135.g90850a2211-goog Subject: [PATCH v1 7/8] perf top: 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=unavailable 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?1747597006709411972?= X-GMAIL-MSGID: =?utf-8?q?1747597006709411972?= 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-top.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 4b3ff7687236..bb5bd241246b 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -87,8 +87,8 @@ #include #include -static volatile int done; -static volatile int resize; +static volatile sig_atomic_t done; +static volatile sig_atomic_t resize; #define HEADER_LINE_NR 5 From patchwork Mon Oct 24 17:35:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 9952 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp607453wru; Mon, 24 Oct 2022 12:06:42 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7BlhGOCgDCOX559tgVcDuYoWYa4MPNbhuwKBvzwmZ92hDFaxAH3je9P8uUVKVbcb4j8zOC X-Received: by 2002:aa7:9298:0:b0:56b:b6dc:988a with SMTP id j24-20020aa79298000000b0056bb6dc988amr8823475pfa.5.1666638401974; Mon, 24 Oct 2022 12:06:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666638401; cv=none; d=google.com; s=arc-20160816; b=cCyF/RXs/A4hwSjq/5PKwwr7XaqbclmxN4lzJLYbotX5Z0CkaaY7cO+zteSb3EAXfa IOKjTfcrdVxOgmYeny8vTrCrYNC/NduyEgAolhr2ztzhDWscZRNuuQO8Pvx5khYCwPKB 7QGrxeziFHBdgentbj5qU8ev/weT0MgS5FXI+3eQxvIKprwGchwrxPZxbAnjTpleNRNT 2HQT9BrrrXucJV/g0Fn7DGBuPAwOTN2Go33qWb6xwcygGqQOHDZtbo8mF0fwd2Wnw8tJ 9+I8FTUPP65+ORj3e0vznxMrDWg58kiw0Kc2oB2BwZTPFIz2mALDLeZqhe6qbnePQlsT c3HQ== 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=sJwUbAas6HwUpEbmohIDJ22IirHP0xTxc+7b+i3VB6U=; b=cPVrqjHMhGdFw4+nQfGFcKjpdO8Fps5EQNSOn+HdhCeTbnnvNknyq5EqJb268E/tTD I4sexFilBgRc7J2OKA+3VGwDp8MSqAIEXRyOxmsT/h92ChO9FRLZShVdnrPN24GPafYO 53ive2RIPbdE4atzgbwgHopnNevz9H05v/Wjro6QT9SWvVFKWvZTlwDW3bFuJmjDH4vA Yp3VCLijTJVcTBgBOstF48znU9hosFR+Yv8FJXrMjSELOQmXohkANyhN/IURYF9WqWWi 49dTieYufeM1C0s3u7P0Xf7hvkWB//HCkFN5uLsNGeUnE5EcP/YQu3Ru+hdf5yaWE4KG nPXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=WNe4EQee; 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 e18-20020a170902f11200b00174418919a6si231328plb.513.2022.10.24.12.06.25; Mon, 24 Oct 2022 12:06:41 -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=WNe4EQee; 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 S231829AbiJXS7g (ORCPT + 99 others); Mon, 24 Oct 2022 14:59:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233176AbiJXS7G (ORCPT ); Mon, 24 Oct 2022 14:59:06 -0400 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69F5918E32 for ; Mon, 24 Oct 2022 10:38:59 -0700 (PDT) Received: by mail-pf1-f202.google.com with SMTP id f13-20020a62380d000000b0056a7486d9a1so4572409pfa.4 for ; Mon, 24 Oct 2022 10:38:59 -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=sJwUbAas6HwUpEbmohIDJ22IirHP0xTxc+7b+i3VB6U=; b=WNe4EQeeykspT4w/Io584+kx9lh/QeoAHLehl3suvkUCe1Cp12l+MOrLPerfCGXYSl tkULm4/+1vo92FIS6jrd4ShA6Wd+GOg80wHhdUNFIbzKf+CrNIIAjHCwi3oT8c+RDn7I rLm16gXSUTHOzSc+IjDqbYXGp+Ssc+Z1x7rQuGXozqHAd2ZYNYN/Kv/ikwNHa7nd1L3T s3B9IpBNSrLhMbYoAfN4Qscgo0OjOPVbDyLFGAVmU0arJMtRwsJa2A7QotYaDgvYOkvw vgWeT/2lmLHaADWBVOZkK6uIAlE1BLHzV2/bDmUo59pB6FYxwRynWnYrLYqSpkif8lzg yngg== 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=sJwUbAas6HwUpEbmohIDJ22IirHP0xTxc+7b+i3VB6U=; b=Dk0AKvX/eZvXXck6R6Jsiobwdg/W9QN/SMkgA81icyCF0nQvQRtJwElcb/CX71JvbX aG5GiOxluM8EMtP6wRf+pmCIksGheq7+/suqrg475yZYi2ip+Bo8w2m1pso0lS3XTTpi OSq2LRzBBmJ3+Z+WaSld7xPMnikmA2d4vZxLY5WNJLDROtJhcN5q+lQQiCKSEm8QNHW9 U4nSn641lzI79sUc3X7DtHuBpzlVQZwfiHh4MsC3n7wmkuBu/n0+xF9yd56BovvnoWDK W6UpB9QGTdJ73TmvEJAwqKZ6P82BtHWSHY9JbWWWzN4zlwV1MB7jY6F8ru8cPA+TYkMG qnRQ== X-Gm-Message-State: ACrzQf2scORKVbiegnMKmygjxv3AcdPLCzM3uYtvjqmalsb7UMtWMd8i rMTMlRN/g7tVBK/O0/KryBXZxmC6dtgy X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:b8bc:a57d:a2a2:efdc]) (user=irogers job=sendgmr) by 2002:a17:90b:e90:b0:213:2708:8dc3 with SMTP id fv16-20020a17090b0e9000b0021327088dc3mr233702pjb.2.1666633007051; Mon, 24 Oct 2022 10:36:47 -0700 (PDT) Date: Mon, 24 Oct 2022 10:35:23 -0700 In-Reply-To: <20221024173523.602064-1-irogers@google.com> Message-Id: <20221024173523.602064-9-irogers@google.com> Mime-Version: 1.0 References: <20221024173523.602064-1-irogers@google.com> X-Mailer: git-send-email 2.38.0.135.g90850a2211-goog Subject: [PATCH v1 8/8] perf trace: 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, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=unavailable 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?1747597028641675059?= X-GMAIL-MSGID: =?utf-8?q?1747597028641675059?= 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-trace.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index d3c757769b96..72991528687e 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -1535,8 +1535,8 @@ static size_t trace__fprintf_tstamp(struct trace *trace, u64 tstamp, FILE *fp) } static pid_t workload_pid = -1; -static bool done = false; -static bool interrupted = false; +static volatile sig_atomic_t done = false; +static volatile sig_atomic_t interrupted = false; static void sighandler_interrupt(int sig __maybe_unused) {