Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp993920ybt; Fri, 26 Jun 2020 17:27:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4nMOzwTKwO9rVnuld3MAjvpIHBuDFou5yXkzsd/ySOHdRDPhRCuxM0Ga8tB2aSh3vIK8s X-Received: by 2002:a05:6402:17f6:: with SMTP id t22mr6260016edy.141.1593217628730; Fri, 26 Jun 2020 17:27:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593217628; cv=none; d=google.com; s=arc-20160816; b=JI4Ec8H6fRKakexNLnRcQmLB4aNayOLEDXZlWGBnStDNTV0vNn/sj90+R0ff5N+amm bwsxLeQp5ygPCBl+pnYk0BFm9yfk3Yk0L/3wrJWexE+DqMdgRxwXztHMLPm3WaxWwUAk zWqxAueFCK9ovfgv0/E641zZHjOw0G0Qx8zW/2+hfY2LwauhMSBYWIvbCkrLCN17jMU3 3nsBsi9oEa300a7lMWHbtWjiE4+IPBSlYLqGDl89BLAwmDjwNRKEhwetYoeCgVFAO0EX v7/8GG3aC8FtJMWLXO+MRw/XtXwzityH9MCqt6dncaJWo9od1EJ4s/9zdA8h3LQr65L7 w/sg== 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=EAJkxsNtexKjSp+KcY5IBffLZgA2IuM2cxuG6XehJ/c=; b=m5V80TBydevbItDgXY0GZnmHqmgT4cDjDPO736hDk7cntDSIrbM3c0NESedd1Jx9JF 5Wq+HDGjSFtIYxwNXGLBDubv/d8gOt3AV5jj47X+7sIeoHyFljKUHlqXDg4B2LwmxkI8 RhZfRJfCji5xQi7fH6rFajahNPQCBbS5cHe+dWd+imGB2M6zcuQ9RAIO9Srjrt/IGHq7 Gr1mESHWWRVFIA/eihugO1ogD8BEuj0XclSUjkBFOHada/m6m5qLket+q3tAVbKqk1CS pdx1MR2UXUEXGls/PkNYYgzFcD9Eic0h8P84vDiPPYBz61Ut4DzcNAPiiStiSaBTJKlQ fJPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=M06SN2nX; 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 q7si17761438ejb.504.2020.06.26.17.26.45; Fri, 26 Jun 2020 17:27:08 -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=M06SN2nX; 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 S1726551AbgF0A0d (ORCPT + 99 others); Fri, 26 Jun 2020 20:26:33 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:7932 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726521AbgF0A03 (ORCPT ); Fri, 26 Jun 2020 20:26:29 -0400 Received: from pps.filterd (m0148460.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 05R0Eu9A014979 for ; Fri, 26 Jun 2020 17:26:28 -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=EAJkxsNtexKjSp+KcY5IBffLZgA2IuM2cxuG6XehJ/c=; b=M06SN2nX7KtRsa5NPRG+fsS8Zhhi3sqEqKz3AXCtvxYv06KXJbEVgRn4n4Z6ol0r6VJ1 91BFLRXfrh1c6RKQ1ZvDXskqZ90781qKjV1TR3zBj7pt776aztkPOlaPZehgku1fbAfp UBEDc44KUv8dPnYVZRpNi9yuiEAF1N8J4NU= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 31ux1f06am-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Fri, 26 Jun 2020 17:26:28 -0700 Received: from intmgw004.03.ash8.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::e) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Fri, 26 Jun 2020 17:26:27 -0700 Received: by devbig006.ftw2.facebook.com (Postfix, from userid 4523) id 6E0F362E4FC1; Fri, 26 Jun 2020 17:26:22 -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 v3 bpf-next 4/4] selftests/bpf: add bpf_iter test with bpf_get_task_stack() Date: Fri, 26 Jun 2020 17:26:09 -0700 Message-ID: <20200627002609.3222870-6-songliubraving@fb.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200627002609.3222870-1-songliubraving@fb.com> References: <20200627002609.3222870-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.216,18.0.687 definitions=2020-06-26_12:2020-06-26,2020-06-26 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 lowpriorityscore=0 clxscore=1015 cotscore=-2147483648 spamscore=0 mlxlogscore=999 bulkscore=0 adultscore=0 phishscore=0 priorityscore=1501 malwarescore=0 mlxscore=0 suspectscore=8 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006270000 X-FB-Internal: deliver Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The new test is similar to other bpf_iter tests. Signed-off-by: Song Liu --- .../selftests/bpf/prog_tests/bpf_iter.c | 17 ++++++ .../selftests/bpf/progs/bpf_iter_task_stack.c | 53 +++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/bpf_iter_task_stack= .c diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_iter.c b/tools/te= sting/selftests/bpf/prog_tests/bpf_iter.c index 1e2e0fced6e81..fed42755416db 100644 --- a/tools/testing/selftests/bpf/prog_tests/bpf_iter.c +++ b/tools/testing/selftests/bpf/prog_tests/bpf_iter.c @@ -5,6 +5,7 @@ #include "bpf_iter_netlink.skel.h" #include "bpf_iter_bpf_map.skel.h" #include "bpf_iter_task.skel.h" +#include "bpf_iter_task_stack.skel.h" #include "bpf_iter_task_file.skel.h" #include "bpf_iter_tcp4.skel.h" #include "bpf_iter_tcp6.skel.h" @@ -110,6 +111,20 @@ static void test_task(void) bpf_iter_task__destroy(skel); } =20 +static void test_task_stack(void) +{ + struct bpf_iter_task_stack *skel; + + skel =3D bpf_iter_task_stack__open_and_load(); + if (CHECK(!skel, "bpf_iter_task_stack__open_and_load", + "skeleton open_and_load failed\n")) + return; + + do_dummy_read(skel->progs.dump_task_stack); + + bpf_iter_task_stack__destroy(skel); +} + static void test_task_file(void) { struct bpf_iter_task_file *skel; @@ -452,6 +467,8 @@ void test_bpf_iter(void) test_bpf_map(); if (test__start_subtest("task")) test_task(); + if (test__start_subtest("task_stack")) + test_task_stack(); if (test__start_subtest("task_file")) test_task_file(); if (test__start_subtest("tcp4")) diff --git a/tools/testing/selftests/bpf/progs/bpf_iter_task_stack.c b/to= ols/testing/selftests/bpf/progs/bpf_iter_task_stack.c new file mode 100644 index 0000000000000..39b21df17c3ee --- /dev/null +++ b/tools/testing/selftests/bpf/progs/bpf_iter_task_stack.c @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2020 Facebook */ +/* "undefine" structs in vmlinux.h, because we "override" them below */ +#define bpf_iter_meta bpf_iter_meta___not_used +#define bpf_iter__task bpf_iter__task___not_used +#include "vmlinux.h" +#undef bpf_iter_meta +#undef bpf_iter__task +#include +#include + +char _license[] SEC("license") =3D "GPL"; + +struct bpf_iter_meta { + struct seq_file *seq; + __u64 session_id; + __u64 seq_num; +} __attribute__((preserve_access_index)); + +struct bpf_iter__task { + struct bpf_iter_meta *meta; + struct task_struct *task; +} __attribute__((preserve_access_index)); + +#define MAX_STACK_TRACE_DEPTH 64 +unsigned long entries[MAX_STACK_TRACE_DEPTH]; +#define SIZE_OF_ULONG (sizeof(unsigned long)) + +SEC("iter/task") +int dump_task_stack(struct bpf_iter__task *ctx) +{ + struct seq_file *seq =3D ctx->meta->seq; + struct task_struct *task =3D ctx->task; + long i, retlen; + + if (task =3D=3D (void *)0) + return 0; + + retlen =3D bpf_get_task_stack(task, entries, + MAX_STACK_TRACE_DEPTH * SIZE_OF_ULONG, 0); + if (retlen < 0) + return 0; + + BPF_SEQ_PRINTF(seq, "pid: %8u num_entries: %8u\n", task->pid, + retlen / SIZE_OF_ULONG); + for (i =3D 0; i < MAX_STACK_TRACE_DEPTH; i++) { + if (retlen > i * SIZE_OF_ULONG) + BPF_SEQ_PRINTF(seq, "[<0>] %pB\n", (void *)entries[i]); + } + BPF_SEQ_PRINTF(seq, "\n"); + + return 0; +} --=20 2.24.1