Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp983852ybt; Fri, 10 Jul 2020 18:31:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxu6TEpSneveaEtjJq4/PDEIZL7zKODvgcPSC4gRJ3MKelk/W/0bzKB1c8w8nZECHUc/B1d X-Received: by 2002:aa7:da06:: with SMTP id r6mr70294772eds.189.1594431094845; Fri, 10 Jul 2020 18:31:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594431094; cv=none; d=google.com; s=arc-20160816; b=i6XwF7hapcRJyQkwR56TYqI0qA0gIAHOzAH64RILvn/m4B4Zmu7jn78cXVzK8qRnfb lkHL/5zJkv1ZN/1I5PVEdxaQpFEwwXe6MMdYCA3qiX6eu2gD9MyH0scz5AYXgy+XJp32 IQxW/0QwykDYTj2tS8ubDjPMYAq2pe94lnJbuUu6aO+wlsGMIW9Ff4FtR7TcM0jgkN+K 8SLI/qjlNyRbYKw7H+Weym73h9HPv+OMZfJjosWtvgdbdLOFirgwb4ee7SL1fXiKasRo +s8MI85gvPXJQjg0+wG44Byf7fTbTRbFz1/bVvVgFJQicpSm3MuHEGtL5hxbwShXHih1 VPoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:smtp-origin-cluster :cc:to:smtp-origin-hostname:from:smtp-origin-hostprefix :dkim-signature; bh=+7acijKP+ydJH0i9GNfmpy6At+PfvVqznxldN0G+Kyg=; b=e4MFZ5WwlJEN4UQx2IStTnD0jr0OAPyk1BO0KQf0eJmn84XXbr5RGLyE3wX1BfyHbX DgutVapa8rkxVoGA6RgwK0uhq291FhaweqgadprSzPZu8O+LrBs0jDDqu1NNwfefQSD2 lLp3lM+NtwE15qgPUiLQcghmPgiFD0HgtWxd8MLPvQT9trKGuSePbpmDw88cb2MrIyCI 8GB7PH7GSKeON20EyQcun8HPCZ3YqSyJccGVJdso42IRSb8kNNJnjzmEIsbcd4iZCXkl U8BmjbJ8UoLLPBhofhs/u1tIUbvp9vtsGlR8tz27uwu4wzPOAv+OJUAAQMH0jWHKBIXG 8XbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=DPMQQlhC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fb.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dh14si4988157edb.591.2020.07.10.18.31.11; Fri, 10 Jul 2020 18:31:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=DPMQQlhC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fb.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727777AbgGKB3e (ORCPT + 99 others); Fri, 10 Jul 2020 21:29:34 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:62246 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727118AbgGKB3e (ORCPT ); Fri, 10 Jul 2020 21:29:34 -0400 Received: from pps.filterd (m0148461.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 06B1TXgs003173 for ; Fri, 10 Jul 2020 18:29:34 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=+7acijKP+ydJH0i9GNfmpy6At+PfvVqznxldN0G+Kyg=; b=DPMQQlhCmXucNNFx5LOCfjRWJODrT3owbrEDq3m6rdgLSt5pi4/0JbJS6pjDpTWqPtz/ iVTNiMtMR6W3opdqPdxsQBHvPBmIomDfiADj1GhxoM6syxDk+IE6/fhoBvSEY9wsNly1 JfmGszEmqXRx1+AGDAJDj/Sx/uXBzmw29T8= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com with ESMTP id 325k1s5brv-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Fri, 10 Jul 2020 18:29:33 -0700 Received: from intmgw004.03.ash8.facebook.com (2620:10d:c085:208::f) by mail.thefacebook.com (2620:10d:c085:11d::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Fri, 10 Jul 2020 18:29:12 -0700 Received: by devbig006.ftw2.facebook.com (Postfix, from userid 4523) id 298B362E5286; Fri, 10 Jul 2020 18:26:58 -0700 (PDT) Smtp-Origin-Hostprefix: devbig From: Song Liu Smtp-Origin-Hostname: devbig006.ftw2.facebook.com To: , , CC: , , , , , , , Song Liu Smtp-Origin-Cluster: ftw2c04 Subject: [PATCH bpf-next 4/5] selftests/bpf: add get_stackid_cannot_attach Date: Fri, 10 Jul 2020 18:26:38 -0700 Message-ID: <20200711012639.3429622-5-songliubraving@fb.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200711012639.3429622-1-songliubraving@fb.com> References: <20200711012639.3429622-1-songliubraving@fb.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235,18.0.687 definitions=2020-07-10_14:2020-07-10,2020-07-10 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 mlxscore=0 clxscore=1015 malwarescore=0 mlxlogscore=999 priorityscore=1501 suspectscore=0 impostorscore=0 phishscore=0 bulkscore=0 spamscore=0 adultscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007110007 X-FB-Internal: deliver Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This test confirms that BPF program that calls bpf_get_stackid() cannot attach to perf_event with PEBS entry. Signed-off-by: Song Liu --- .../prog_tests/get_stackid_cannot_attach.c | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 tools/testing/selftests/bpf/prog_tests/get_stackid_ca= nnot_attach.c diff --git a/tools/testing/selftests/bpf/prog_tests/get_stackid_cannot_at= tach.c b/tools/testing/selftests/bpf/prog_tests/get_stackid_cannot_attach= .c new file mode 100644 index 0000000000000..ae943c502b62b --- /dev/null +++ b/tools/testing/selftests/bpf/prog_tests/get_stackid_cannot_attach.c @@ -0,0 +1,57 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (c) 2020 Facebook +#include +#include "test_stacktrace_build_id.skel.h" + +void test_get_stackid_cannot_attach(void) +{ + struct perf_event_attr attr =3D { + /* .type =3D PERF_TYPE_SOFTWARE, */ + .type =3D PERF_TYPE_HARDWARE, + .config =3D PERF_COUNT_HW_CPU_CYCLES, + .precise_ip =3D 2, + .sample_type =3D PERF_SAMPLE_IP | PERF_SAMPLE_BRANCH_STACK | + PERF_SAMPLE_CALLCHAIN, + .branch_sample_type =3D PERF_SAMPLE_BRANCH_USER | + PERF_SAMPLE_BRANCH_NO_FLAGS | + PERF_SAMPLE_BRANCH_NO_CYCLES | + PERF_SAMPLE_BRANCH_CALL_STACK, + .sample_period =3D 5000, + .size =3D sizeof(struct perf_event_attr), + }; + struct test_stacktrace_build_id *skel; + __u32 duration =3D 0; + int pmu_fd, err; + + skel =3D test_stacktrace_build_id__open(); + if (CHECK(!skel, "skel_open", "skeleton open failed\n")) + return; + + /* override program type */ + bpf_program__set_perf_event(skel->progs.oncpu); + + err =3D test_stacktrace_build_id__load(skel); + if (CHECK(err, "skel_load", "skeleton load failed: %d\n", err)) + goto cleanup; + + pmu_fd =3D syscall(__NR_perf_event_open, &attr, -1 /* pid */, + 0 /* cpu 0 */, -1 /* group id */, + 0 /* flags */); + if (pmu_fd < 0 && errno =3D=3D ENOENT) { + printf("%s:SKIP:no PERF_COUNT_HW_CPU_CYCLES\n", __func__); + test__skip(); + goto cleanup; + } + if (CHECK(pmu_fd < 0, "perf_event_open", "err %d errno %d\n", + pmu_fd, errno)) + goto cleanup; + + skel->links.oncpu =3D bpf_program__attach_perf_event(skel->progs.oncpu, + pmu_fd); + CHECK(!IS_ERR(skel->links.oncpu), "attach_perf_event", + "should have failed\n"); + close(pmu_fd); + +cleanup: + test_stacktrace_build_id__destroy(skel); +} --=20 2.24.1