Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp5996546rwb; Wed, 7 Sep 2022 11:01:51 -0700 (PDT) X-Google-Smtp-Source: AA6agR7kIl/VzN0O3tw40PQIk/oQQ/HaZgDcYvOkyliya2cbZxvKiu2N8nHT31NlhTgZi9WV7Ukb X-Received: by 2002:a62:ed08:0:b0:537:17a6:57aa with SMTP id u8-20020a62ed08000000b0053717a657aamr5283939pfh.6.1662573710960; Wed, 07 Sep 2022 11:01:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662573710; cv=none; d=google.com; s=arc-20160816; b=girsKQ06HSl/xcc2A1Eltgz2pL9DEfTmP4LoWfFmy0fuD0Tai3tr0oliMdER25uq/u gNsOEa8cetH5AqS3oaT3RU9xzWuDCEmAkhgl5IXgteIQ1M1VP7H6jABoXuEaVg4NWgQa ZYkiQqG4gA/tWoUH/AuZSS5AN7Qj78U2hJpQ/ZeJ+WRDutFfvINBn9laO0lx+P5rEUVR SJaMzRLDZJHKmw2QsH1CkHmXAFWXtd9G37fTbBrso+lrBfASzQdIoJNSR98cEPJ/9pf9 XFp74XL1FWuM++gdzDDB0yud+QbCklXGQLn2HbxSAGYuRFu5+ECWrLsHXHyrdPXEsSVt g2xA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=o+vZIo7vWZhi9jMgze8rEVP2MoMz8p7K3ku8PnOZlC8=; b=MrsBXf9N5DbQudo0ERMIy2mnRzfJtJxKQIcA2FbYOo/RfodjFxZaAO9eooy3dfR2xB vmEM94wjKyOHnywvRguYSgo+WkU3FdDcbcJHxR8nh37ZAaLmMLFryE46R7I20xHgwJi4 47K1zHRtg2G12xTU5W/E+1jYj38z8xJEhBrAvrHfzZHY4ePzTAshGXToFPsQ/GmuDJZz v9qscSdOjx3PE85n+yVefRRSa6UebLjcH/t8Z29rX1vHeEg1zqKOWlyT7S4glzCcA0Gp dT3hPa+lInN+mob5CfqfXDy8QdXsCRjHF3ALypr/nsRh+YANhBdZuzQmAXabpsBqE7Fu I+PA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m15-20020a170902f64f00b0016af36d83d7si14861256plg.357.2022.09.07.11.01.37; Wed, 07 Sep 2022 11:01:50 -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; 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 S229943AbiIGRuU (ORCPT + 99 others); Wed, 7 Sep 2022 13:50:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229830AbiIGRuS (ORCPT ); Wed, 7 Sep 2022 13:50:18 -0400 Received: from mail-oa1-f50.google.com (mail-oa1-f50.google.com [209.85.160.50]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDB2C3FA32; Wed, 7 Sep 2022 10:50:15 -0700 (PDT) Received: by mail-oa1-f50.google.com with SMTP id 586e51a60fabf-128121a9851so2546916fac.13; Wed, 07 Sep 2022 10:50:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=o+vZIo7vWZhi9jMgze8rEVP2MoMz8p7K3ku8PnOZlC8=; b=lm69WbKrY8Bc9Ld41bUCgd3UT0V7yUOFQRcTERfXiO3LEmNMfZAd5LhtBy21sgBYb7 BEIy86MQwz0B9H2cz8sdy/b0SlKBgOKzWAUTdm9jT3lBuZBY93zD7ESztyyzTjOdWEQX WQSPZAzIgyTCmhHm5OVXvfOIMilU9kLBMJ5sSJPdGwsl4Ldcoad59vbx0srlAYSpw3nY EiS5z1huJOjr7IBUp5oRzgcRbmfe1iQ/XSh4jwtTt+MxgDSgVUdNE2CLgsdv705+rfsW t4G7cB/p1WCyEAkjiX/3VIwNR6TZC3TOscQpYmycWXz69xBpZeZqfF23ALrqpgj4gRgh daEQ== X-Gm-Message-State: ACgBeo2kQzfuFFENVEV3TUfFdMgQFE8PMxdZOHUdgIDf+U0ykJSBU5n3 MkFbZnqThplnxPzQ17kxL4yGc88B2hiIhDr4P4Kna7pg X-Received: by 2002:a05:6870:a184:b0:116:bd39:7f94 with SMTP id a4-20020a056870a18400b00116bd397f94mr15334457oaf.5.1662573014962; Wed, 07 Sep 2022 10:50:14 -0700 (PDT) MIME-Version: 1.0 References: <20220907050407.2711513-1-namhyung@kernel.org> In-Reply-To: From: Namhyung Kim Date: Wed, 7 Sep 2022 10:50:04 -0700 Message-ID: Subject: Re: [PATCH v2] perf test: Skip sigtrap test on old kernels To: Jiri Olsa Cc: Arnaldo Carvalho de Melo , Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , linux-perf-users , bpf , Marco Elver , Song Liu Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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 On Wed, Sep 7, 2022 at 1:32 AM Jiri Olsa wrote: > > On Tue, Sep 06, 2022 at 10:04:07PM -0700, Namhyung Kim wrote: > > If it runs on an old kernel, perf_event_open would fail because of the > > new fields sigtrap and sig_data. Just skipping the test could miss an > > actual bug in the kernel. > > > > Let's check BTF if it has the perf_event_attr.sigtrap field. > > > > Cc: Marco Elver > > Cc: Song Liu > > Signed-off-by: Namhyung Kim > > --- > > tools/perf/tests/sigtrap.c | 46 +++++++++++++++++++++++++++++++++++++- > > 1 file changed, 45 insertions(+), 1 deletion(-) > > > > diff --git a/tools/perf/tests/sigtrap.c b/tools/perf/tests/sigtrap.c > > index e32ece90e164..32f08ce0f2b0 100644 > > --- a/tools/perf/tests/sigtrap.c > > +++ b/tools/perf/tests/sigtrap.c > > @@ -16,6 +16,8 @@ > > #include > > #include > > > > +#include > > + > > #include "cloexec.h" > > #include "debug.h" > > #include "event.h" > > @@ -54,6 +56,42 @@ static struct perf_event_attr make_event_attr(void) > > return attr; > > } > > > > +static bool attr_has_sigtrap(void) > > +{ > > + bool ret = false; > > + > > +#ifdef HAVE_BPF_SKEL > > + > > + struct btf *btf; > > + const struct btf_type *t; > > + const struct btf_member *m; > > + const char *name; > > + int i, id; > > + > > + /* just assume it doesn't have the field */ > > + btf = btf__load_vmlinux_btf(); > > + if (btf == NULL) > > + return false; > > + > > + id = btf__find_by_name_kind(btf, "perf_event_attr", BTF_KIND_STRUCT); > > + if (id < 0) > > + goto out; > > + > > + t = btf__type_by_id(btf, id); > > + for (i = 0, m = btf_members(t); i < btf_vlen(t); i++, m++) { > > + name = btf__name_by_offset(btf, m->name_off); > > + if (!strcmp(name, "sigtrap")) { > > + ret = true; > > + break; > > + } > > + } > > +out: > > + btf__free(btf); > > +#endif > > would it be easier to call perf_event_open for simple event with > sigtrap set (and perhaps remove_on_exec) ? perf_copy_attr checks > on reserved fields Hmm.. right. we could do that too. But it might still fail if there's a bug in the path handling in sigtrap even for the simple case. I'm not sure if it's a realistic concern though. :) Thanks, Namhyung > > > > + > > + return ret; > > +} > > + > > static void > > sigtrap_handler(int signum __maybe_unused, siginfo_t *info, void *ucontext __maybe_unused) > > { > > @@ -139,7 +177,13 @@ static int test__sigtrap(struct test_suite *test __maybe_unused, int subtest __m > > > > fd = sys_perf_event_open(&attr, 0, -1, -1, perf_event_open_cloexec_flag()); > > if (fd < 0) { > > - pr_debug("FAILED sys_perf_event_open(): %s\n", str_error_r(errno, sbuf, sizeof(sbuf))); > > + if (attr_has_sigtrap()) { > > + pr_debug("FAILED sys_perf_event_open(): %s\n", > > + str_error_r(errno, sbuf, sizeof(sbuf))); > > + } else { > > + pr_debug("perf_event_attr doesn't have sigtrap\n"); > > + ret = TEST_SKIP; > > + } > > goto out_restore_sigaction; > > } > > > > -- > > 2.37.2.789.g6183377224-goog > >