Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp5376306rwb; Wed, 7 Sep 2022 01:40:23 -0700 (PDT) X-Google-Smtp-Source: AA6agR7HNmqgho9lZFMCc0pl2Duk5ZucW8M+lATWVI71FiF9SsCRVLyWrUao0RkVDfSo8QZZUkBz X-Received: by 2002:a05:6402:27ca:b0:43e:ce64:ca07 with SMTP id c10-20020a05640227ca00b0043ece64ca07mr2297781ede.66.1662540023453; Wed, 07 Sep 2022 01:40:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662540023; cv=none; d=google.com; s=arc-20160816; b=qRgAruFEvqkzJUj1eGRtZsz59nd+bQJ6D/FpBf8CaDHe2oAufguHUFSkDT25/Qv+gn aPqBSZ26oVlVAFbK/HKcepYJ6vrAt8pL4B/8XvvSzYkROrf/LODy+uCjAvokOTSG3IHJ b87p5u4k2bOtQi53iBwdReSNggt7AwyH7S2ym8xAxmZ5BvZJIlX6qVvYi37FYto5eK2Q P46OucQvbUYoZqm7KQRq4krmZ18LeJ99WPgtRsk6ZJkV6+aFfXOPe4yv2HTCzEXptbFu L2RW4+kvpVYnuaSYBL9rtuMjL7eUsNPJS5COHR3LR9B5yJBexaNLo0Yns/8/L6V4oT5R Zh5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:date:from:dkim-signature; bh=oNhXNN48XioBo9TdpjvtJUsMY1FigZdVdgZ98bYIOdo=; b=bKCa+jcdb6DWjWVBLZcSHEkGeBvBAWw1aPyrEooV2Z42OTjwwoaXcuYn/Zbw3uHhiG ZCetEgoyxSXs7nwBkXpXAQhLvipDU6DBpFNsQYKNNCqis6Ec3zbIGeO69dlOKB59AWto CDHQ850M8J/EMopwhARL9P9NY1QFy40oAoklxQOHRQc5yAkevJg+rfEE5xGJ1mnnt0cV zwJBb+iuwduacOnMWhYtq9o6ziAXEJ0g/x95O/u3iKIm3G4KrDkHWeS5izlCCSBMhdRA V10gQ8FYa1mA7l0RYxpIPOu0MNXQuTZwuBE/z4iiw559Bhqjym7pe6cow32lAXfOLL2t fiDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=nJpwq+gH; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gn22-20020a1709070d1600b0073d9daaf4f3si13589548ejc.693.2022.09.07.01.39.58; Wed, 07 Sep 2022 01:40:23 -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=nJpwq+gH; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229980AbiIGIcv (ORCPT + 99 others); Wed, 7 Sep 2022 04:32:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229589AbiIGIct (ORCPT ); Wed, 7 Sep 2022 04:32:49 -0400 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5B7F9DB69; Wed, 7 Sep 2022 01:32:48 -0700 (PDT) Received: by mail-ej1-x62b.google.com with SMTP id kg20so1887750ejc.12; Wed, 07 Sep 2022 01:32:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:from:to:cc:subject:date; bh=oNhXNN48XioBo9TdpjvtJUsMY1FigZdVdgZ98bYIOdo=; b=nJpwq+gHDtRIMVL7mDIoX+pB/1iJhaSnYn1uo5g1bEu7GAqi6bpDVsjAMHOJVEdP/R +3NebSOUiO9iKD4vNfY5x3wyrzNe28ZAh8oJskQkw/l9ctk4a/dFVLXIAPPAzrZT6l6I Jc9ND3UyiyYlFdClN3bM6iBLqGXI0BOSERUK9X1pmO0NoldME0Y7Xj4Fy26ZyCfvDC+B R+xMIjsoRPx1dvcj9IBa1C+OYk2lirivddKGLuo9XPYdVlL6gmRbIqvqfrBqwhmTY8Td nE3V6kz3eBIVRr7dfkPeI8cgZMIldBoiuD8WcVWi2hGRoaLXvTQY7rpuOUBWQpywcwpy X/4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:x-gm-message-state:from:to:cc:subject:date; bh=oNhXNN48XioBo9TdpjvtJUsMY1FigZdVdgZ98bYIOdo=; b=WbHvUrCiVd0r0ND8KJWhKu9zWgQ+SFHKP3+yJj5mlPBrFUKScxLs1uMYKALK4qBvBo VhH8T2S3QvyfzMv4NRMEUCH3k3J15nUiW9ekkj4Co+vZPsYQ80QIrI0oyyBpMkNih4Yk Rbqjsvmb2NdXr9en/0VwLPQp20w2RhKQNoCrHX3Ucf8w9YNjoKNmx/r0jo7B18YBmzgk 82cTlSM2IEe39vFywsD8AW8AkKjVxl03NAR5r0SeGV3b4eInt68zww4ikp7MFT4V95Zo pg3Ue2KzBZw2EB7XfBnjQD4hsxb80b7GELuGvHfWSF7kdUwGKYADqxkyXmD8fllVK09d r4Wg== X-Gm-Message-State: ACgBeo3JGdY4i/TKzEUDwuiQ+8McehkYT9TPedCX1Ap05H+dNg0V6BAi CPl4GD+rmbnE2g8hD4bppBH5/R0+QqemXw== X-Received: by 2002:a17:906:847c:b0:73f:d7cf:bf2d with SMTP id hx28-20020a170906847c00b0073fd7cfbf2dmr1591785ejc.327.1662539567297; Wed, 07 Sep 2022 01:32:47 -0700 (PDT) Received: from krava ([193.85.244.190]) by smtp.gmail.com with ESMTPSA id i10-20020a170906264a00b0073cf8e0355fsm7750137ejc.208.2022.09.07.01.32.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Sep 2022 01:32:47 -0700 (PDT) From: Jiri Olsa X-Google-Original-From: Jiri Olsa Date: Wed, 7 Sep 2022 10:32:45 +0200 To: Namhyung Kim Cc: Arnaldo Carvalho de Melo , Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , linux-perf-users@vger.kernel.org, bpf@vger.kernel.org, Marco Elver , Song Liu Subject: Re: [PATCH v2] perf test: Skip sigtrap test on old kernels Message-ID: References: <20220907050407.2711513-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220907050407.2711513-1-namhyung@kernel.org> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 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 jirka > + > + 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 >