From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A41D8C16A69 for ; Wed, 22 May 2019 05:39:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 787BA20815 for ; Wed, 22 May 2019 05:39:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=fb.com header.i=@fb.com header.b="ey5UBAoZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727453AbfEVFjK (ORCPT ); Wed, 22 May 2019 01:39:10 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:53238 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725796AbfEVFjK (ORCPT ); Wed, 22 May 2019 01:39:10 -0400 Received: from pps.filterd (m0001303.ppops.net [127.0.0.1]) by m0001303.ppops.net (8.16.0.27/8.16.0.27) with SMTP id x4M5Wcaj002651 for ; Tue, 21 May 2019 22:39:08 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : mime-version : content-type; s=facebook; bh=4XcjYewWSwgYkRjzUtZdBoQW5AGgzw4iFMY1kru+Vs4=; b=ey5UBAoZTRdmWxSoFkr+vt7SieMiLaBOooovkdBXFVKPyCmZKLTubZu+jXp4Zf+d4Yd3 6u0npxlVfSnFEjgu9SOV/XAwStfHKoZINg5la3+/K/4r8lU0p2zmAAYPPWTC+KuTioHS CbUQ5vK8Y7mZgpgNOTyd5NU2bYQF1httOoE= Received: from maileast.thefacebook.com ([163.114.130.16]) by m0001303.ppops.net with ESMTP id 2smcnpuuv7-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 21 May 2019 22:39:08 -0700 Received: from mx-out.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::d) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Tue, 21 May 2019 22:39:03 -0700 Received: by devbig003.ftw2.facebook.com (Postfix, from userid 128203) id BB89C3702E2B; Tue, 21 May 2019 22:39:00 -0700 (PDT) Smtp-Origin-Hostprefix: devbig From: Yonghong Song Smtp-Origin-Hostname: devbig003.ftw2.facebook.com To: , CC: Alexei Starovoitov , Daniel Borkmann , , Peter Zijlstra , Yonghong Song Smtp-Origin-Cluster: ftw2c04 Subject: [PATCH bpf-next v2 0/3] bpf: implement bpf_send_signal() helper Date: Tue, 21 May 2019 22:39:00 -0700 Message-ID: <20190522053900.1663459-1-yhs@fb.com> X-Mailer: git-send-email 2.17.1 X-FB-Internal: Safe MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-05-22_02:,, signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 priorityscore=1501 malwarescore=0 suspectscore=8 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=969 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1905220040 X-FB-Internal: deliver Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org This patch tries to solve the following specific use case. Currently, bpf program can already collect stack traces through kernel function get_perf_callchain() when certain events happens (e.g., cache miss counter or cpu clock counter overflows). But such stack traces are not enough for jitted programs, e.g., hhvm (jited php). To get real stack trace, jit engine internal data structures need to be traversed in order to get the real user functions. bpf program itself may not be the best place to traverse the jit engine as the traversing logic could be complex and it is not a stable interface either. Instead, hhvm implements a signal handler, e.g. for SIGALARM, and a set of program locations which it can dump stack traces. When it receives a signal, it will dump the stack in next such program location. This patch implements bpf_send_signal() helper to send a signal to hhvm in real time, resulting in intended stack traces. Patch #1 implemented the bpf_send_helper() in the kernel, Patch #2 synced uapi header bpf.h to tools directory. Patch #3 added a self test which covers tracepoint and perf_event bpf programs. Changelogs: RFC v1 => v2: . previous version allows to send signal to an arbitrary pid. This version just sends the signal to current task to avoid unstable pid and potential races between sending signals and task state changes for the pid. Yonghong Song (3): bpf: implement bpf_send_signal() helper tools/bpf: sync bpf uapi header bpf.h to tools directory tools/bpf: add a selftest for bpf_send_signal() helper include/uapi/linux/bpf.h | 17 +- kernel/trace/bpf_trace.c | 67 ++++++ tools/include/uapi/linux/bpf.h | 17 +- tools/testing/selftests/bpf/Makefile | 3 +- tools/testing/selftests/bpf/bpf_helpers.h | 1 + .../bpf/progs/test_send_signal_kern.c | 51 +++++ .../selftests/bpf/test_send_signal_user.c | 212 ++++++++++++++++++ 7 files changed, 365 insertions(+), 3 deletions(-) create mode 100644 tools/testing/selftests/bpf/progs/test_send_signal_kern.c create mode 100644 tools/testing/selftests/bpf/test_send_signal_user.c -- 2.17.1