From patchwork Mon Aug 29 19:20:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kui-Feng Lee X-Patchwork-Id: 12958369 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 580CAECAAD2 for ; Mon, 29 Aug 2022 19:21:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229647AbiH2TVJ (ORCPT ); Mon, 29 Aug 2022 15:21:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229453AbiH2TVI (ORCPT ); Mon, 29 Aug 2022 15:21:08 -0400 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B06870E72 for ; Mon, 29 Aug 2022 12:21:06 -0700 (PDT) Received: from pps.filterd (m0044012.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27TJ5wlU024890 for ; Mon, 29 Aug 2022 12:21:06 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : content-type : content-transfer-encoding : mime-version; s=facebook; bh=dhZbyATImo8ncvRkrNaMek1HVF9urvQAiOoigkL9z10=; b=aA8jxFVMJGojsglGY2ZMubjj0VOWOfPp+qAzV7UIchhQYBPdyVR0Ks9sSLLcEiVnTnAJ Tva+8vCq1bdah4aD5r0wQ2+cGNIO5cJhT3XiWTKia0xw4eXQV/AxyY9zM/FnPDgGrKCX JvtpZJDl7j/Mlv80LxgJPNrsZugVI+dX71U= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3j7gypbrfy-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 29 Aug 2022 12:21:06 -0700 Received: from twshared25017.14.frc2.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:83::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 29 Aug 2022 12:21:04 -0700 Received: by devbig931.frc1.facebook.com (Postfix, from userid 460691) id BDE4B749E95F; Mon, 29 Aug 2022 12:20:59 -0700 (PDT) From: Kui-Feng Lee To: , , , , , CC: Kui-Feng Lee , Subject: [PATCH bpf-next v8 0/5] Attach a cookie to a tracing program. Date: Mon, 29 Aug 2022 12:20:46 -0700 Message-ID: <20220829192051.475894-1-kuifeng@fb.com> X-Mailer: git-send-email 2.30.2 X-FB-Internal: Safe X-Proofpoint-GUID: _7idIr3iIdlv98ITZrZR8l7fEuC--ffb X-Proofpoint-ORIG-GUID: _7idIr3iIdlv98ITZrZR8l7fEuC--ffb X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-29_09,2022-08-25_01,2022-06-22_01 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Allow users to attach a 64-bits cookie to a bpf_link of fentry, fexit, or fmod_ret. This patchset includes several major changes. - Define struct bpf_tramp_links to replace bpf_tramp_prog. struct bpf_tramp_links collects bpf_links of a trampoline - Generate a trampoline to call bpf_progs of given bpf_links. - Trampolines always set/reset bpf_run_ctx before/after calling/leaving a tracing program. - Attach a cookie to a bpf_link of fentry/fexit/fmod_ret/lsm. The value will be available when running the associated bpf_prog. Th major differences from v6: - bpf_link_create() can create links of BPF_LSM_MAC attach type. - Add a test for lsm. - Add function proto of bpf_get_attach_cookie() for lsm. - Check BPF_LSM_MAC in bpf_prog_has_trampoline(). - Adapt to the changes of LINK_CREATE made by Andrii. The major differences from v7: - Change stack_size instead of pushing/popping run_ctx. - Move cookie to bpf_tramp_link from bpf_tracing_link.. v1: https://lore.kernel.org/all/20220126214809.3868787-1-kuifeng@fb.com/ v2: https://lore.kernel.org/bpf/20220316004231.1103318-1-kuifeng@fb.com/ v3: https://lore.kernel.org/bpf/20220407192552.2343076-1-kuifeng@fb.com/ v4: https://lore.kernel.org/bpf/20220411173429.4139609-1-kuifeng@fb.com/ v5: https://lore.kernel.org/bpf/20220412165555.4146407-1-kuifeng@fb.com/ v6: https://lore.kernel.org/bpf/20220416042940.656344-1-kuifeng@fb.com/ v7: https://lore.kernel.org/bpf/20220508032117.2783209-1-kuifeng@fb.com/ Kui-Feng Lee (5): bpf, x86: Generate trampolines from bpf_tramp_links bpf, x86: Create bpf_tramp_run_ctx on the caller thread's stack bpf, x86: Attach a cookie to fentry/fexit/fmod_ret/lsm. libbpf: Assign cookies to links in libbpf. selftest/bpf: The test cses of BPF cookie for fentry/fexit/fmod_ret/lsm. arch/x86/net/bpf_jit_comp.c | 76 ++++++++----- include/linux/bpf.h | 54 +++++++--- include/linux/bpf_types.h | 1 + include/uapi/linux/bpf.h | 10 ++ kernel/bpf/bpf_lsm.c | 17 +++ kernel/bpf/bpf_struct_ops.c | 71 +++++++++---- kernel/bpf/syscall.c | 42 ++++---- kernel/bpf/trampoline.c | 100 +++++++++++------- kernel/trace/bpf_trace.c | 17 +++ net/bpf/bpf_dummy_struct_ops.c | 24 ++++- tools/bpf/bpftool/link.c | 1 + tools/include/uapi/linux/bpf.h | 10 ++ tools/lib/bpf/bpf.c | 8 ++ tools/lib/bpf/bpf.h | 3 + tools/lib/bpf/libbpf.c | 19 +++- tools/lib/bpf/libbpf.h | 12 +++ tools/lib/bpf/libbpf.map | 1 + .../selftests/bpf/prog_tests/bpf_cookie.c | 89 ++++++++++++++++ .../selftests/bpf/progs/test_bpf_cookie.c | 52 +++++++-- 19 files changed, 469 insertions(+), 138 deletions(-)