From patchwork Tue Jun 14 23:10:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Delyan Kratunov X-Patchwork-Id: 12881693 X-Patchwork-Delegate: bpf@iogearbox.net 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 A3A8EC43334 for ; Tue, 14 Jun 2022 23:10:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229572AbiFNXKw (ORCPT ); Tue, 14 Jun 2022 19:10:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239660AbiFNXKv (ORCPT ); Tue, 14 Jun 2022 19:10:51 -0400 Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9543352E55 for ; Tue, 14 Jun 2022 16:10:47 -0700 (PDT) Received: from pps.filterd (m0148460.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25EMd1rW002772 for ; Tue, 14 Jun 2022 16:10:46 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=facebook; bh=GMdUAw8wuRykvY/1Ylxh/osEmvf28cBu/w57NOBRb3U=; b=PmzP1iAhB+zSznDvQmP/SyE76apOyHWT9rcoBB2t2RgXjEujPwoec74N3/UqU+q+mU3X Mqqbzwp5T1xFH0oQPR8urwb1rbuOopsozMLHlT1C6DAFXmnAE+gQhHXkObkv+O7uuNkA Ui90oyO6y3/t1+xuNKhV1sQfHUQ5lB8jmnQ= Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2173.outbound.protection.outlook.com [104.47.59.173]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3gp8aw1uet-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 14 Jun 2022 16:10:46 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HVzhhyHykRk2QYyGf+maUPIvAS/yPyJKMqDH3J4DbZdkK1SqM2XawH9OYxNKMV3nI8ZWg8JGGhfCpD/9aMGg7fKU8Wyx78b96IHYrqzZM/Vvv3hD/QzFhv8613HcdGHEr4xcqAKQWbriIdofvd1ip6yTBsBMxSB5eX7iMDakWNcT96J9g+ifFFxdwPGiCG7EAgMoaLRE1BzIO+4nuJXCAbfZxGJqsApfRt4i3sLlxw+/84P9f9oKZLyO58F/nPwL1Upd0OVxHmPJNnMOJaw+tql724Yf/all6XhVWC8zEr53b8YQhRWTM+5N74W88XKUarMXRjcbJSsg/VXluxf5Yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=GMdUAw8wuRykvY/1Ylxh/osEmvf28cBu/w57NOBRb3U=; b=hUOfbDLEtiCXao04pCFuqt0usk1Nw//5rn95+dSGSLsq6ciNpUs5O0xVsrYDYTxCShii/BX5S5Cj9FE2Yir7tBW9NL8kg2//SPVq/t4wf9KNIOzlpAHdYQnj9Pvh2eE0IDo2JT5kDtZ7Qdtl7Z9NFlHY0FDE76+CSYfdnEe0vsA1aJV7hT2OtSN6cPnuAg75yvuPjPYqwizolT5ozgh0f1I4N/fHx7BRMU5T54tWHlQ2us1tB/J5oy3SgZzk35wqA+u3YHodRc5v7FBRLQnezKYgQ44sWpB8TfYkl9hCMNCxswTM0U/d3wVLHGFAMqvIfRRtYsUVFnfre7V4tf0CcQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=fb.com; dmarc=pass action=none header.from=fb.com; dkim=pass header.d=fb.com; arc=none Received: from SJ0PR15MB5154.namprd15.prod.outlook.com (2603:10b6:a03:423::6) by MW5PR15MB5220.namprd15.prod.outlook.com (2603:10b6:303:1a0::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.20; Tue, 14 Jun 2022 23:10:43 +0000 Received: from SJ0PR15MB5154.namprd15.prod.outlook.com ([fe80::8910:e73d:9868:600b]) by SJ0PR15MB5154.namprd15.prod.outlook.com ([fe80::8910:e73d:9868:600b%9]) with mapi id 15.20.5332.016; Tue, 14 Jun 2022 23:10:42 +0000 From: Delyan Kratunov To: "daniel@iogearbox.net" , "ast@kernel.org" , "andrii@kernel.org" , "bpf@vger.kernel.org" Subject: [PATCH bpf-next v4 1/5] bpf: move bpf_prog to bpf.h Thread-Topic: [PATCH bpf-next v4 1/5] bpf: move bpf_prog to bpf.h Thread-Index: AQHYgEP46wQKNvzaCkWGNLX/L1XEsA== Date: Tue, 14 Jun 2022 23:10:42 +0000 Message-ID: <3ed7824e3948f22d84583649ccac0ff0d38b6b58.1655248076.git.delyank@fb.com> References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 193da1b8-9bc9-4792-792a-08da4e5b1afe x-ms-traffictypediagnostic: MW5PR15MB5220:EE_ x-microsoft-antispam-prvs: x-fb-source: Internal x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: p4vEF2ETX5UtbxxZTmqe0Y/RdPxDFGqbIdjGnihq20F5jdJD3DrVfGReCvJo/6l100CUve8i0Urt+L5V4ncjaHexZWyyFFrFiOu3AFf34oVd9PfNeCbh6yR7GbHv5D2WaBthEuPjYHeM6LNQIEm+5N+QVrSVxMNmKqJhAVj2uXAtCfDyBu6k3fFPMLxfFA70qVLGnaNurS/Vu1iSHxxw4V9NcOS4SdDEJZjLfCYBn+VbDlrxbEnkbBRuhumikViFSAUqk6YosYX+lUIxP+TZZ5gHsvxDJE1X8PSSB1UrHqeNaRQcibpQoDz1M4cRUSjvCn3WrrJtYk4KmSpsEUuk0O0f75ftWp4tRgxfyCdV4PrS1CYYGlZ9NgVJvuX52c0xJ0TaHjiLrXFIk7qqYaWOYvQIdhiaN3SMfwcYb++/JT89XUJpPhboMeS+TIZzzwoyN3nxJKqzw6IdLtvhXfmfJ1tbPxqhtsXzmF4bLpxLYgeW5Qzfr2Q1WGly/kzrvsy8Vu7lu020GXvvsGnzWzpqH6h5LNmcVqlGx+yzE8dmSOJAj7Vm8OA1pusQJbbZXb1KaF8DtZA+CChui1DfbW3drnnmCcST2GJt7f2Hb1D+Qj6dT3UjkHLXs1d9dIFJEhYhT5ovKgXozCk6YY/5LhLLhjnrFfuJadSTxS1yKiRxPeELH4kSD8oQX7O/lQ5qYx8hg9lpeR+6r63pE1awB+wVDg== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR15MB5154.namprd15.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(4636009)(366004)(186003)(8936002)(5660300002)(122000001)(38100700002)(83380400001)(6506007)(6486002)(36756003)(508600001)(38070700005)(6512007)(71200400001)(66946007)(316002)(66476007)(2616005)(2906002)(64756008)(66446008)(76116006)(8676002)(91956017)(66556008)(86362001)(110136005);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?Ef/wOsMeJ6BrtU2PUZxlOiC?= =?iso-8859-1?q?2pnxSyFYxM3k10urEpvPCLwRRbo2oCL1X8HdOoiiozYVGWMKblUk1MdvQkos?= =?iso-8859-1?q?AVZOhTtM/QrOSZRGPnqGjSrpBw4S0AnC9ecscBlweKD9PNfeavFILd/76vyY?= =?iso-8859-1?q?3Jl3fTBTwTTiKpbY3lsfufDFAn1VH50tnKvp8T06/K7caefzSCqtgtxzrjQy?= =?iso-8859-1?q?zd6LfGAA2hv8N1ta6soRz6tPOX5JRKWehWm29FNww0Gdv3WhLXq+T50KOEyM?= =?iso-8859-1?q?9lgA+l9gGLgm4bMkTRHZhyJkRB7dvAT3cK57nH/pDsvDm7fWU70Pcl6sl2rk?= =?iso-8859-1?q?73d0AlwfrvTSh0gX/6pczCS1SoWXnVMFaeKhi01GW13JA9yldwiBAxnrtEEM?= =?iso-8859-1?q?cNLUr2jF2vWjXOQIO0rscs67AHGb5VPW0bfHFct3y7XMk7lSABKKn5Nt6Uwl?= =?iso-8859-1?q?udCYijWnoUFNvoLL7rNOh1Ju+FLXQRcsCo92KcMXrz7UsJuq2UYDLR6Fe9wN?= =?iso-8859-1?q?jvst9WCBjKyQkB96XAeAFnbNBH93UGDRNWVcSh3oODL6pKx0Vh6/FO4S2BqI?= =?iso-8859-1?q?MT3RHJ3SzNHKlrhvHoxBSGJwgZyppSIWNpMqe1lx8H+6a+9FppW//qtCQ7qa?= =?iso-8859-1?q?GuKesWRznFVlsGvH0s1KB/d7x1UY4TrgI1curLezk5qN6+ZOo76dBH6Lx0a/?= =?iso-8859-1?q?UACtXzcV9HfA6ABn/haklUXrczo6QPXRMnOm/GCilwAXacQe4q2NuHhXZxb/?= =?iso-8859-1?q?hwmbPIlK58EhdOj25Mm2yZwE2D1fHT9BoUq/mM6KV5vsqLkbh/DhKnz3lxMG?= =?iso-8859-1?q?9lAUFQwgITWpEHsJ1NMgkR2rssWXLQPZQEFqPK5XKS9lT4WAGkGyUYTfBGXB?= =?iso-8859-1?q?z+fhcweOznOOONycj8x6oWzWBH1ow9iGOXJm/EW8192SBaHc2+pK71H+8Tm6?= =?iso-8859-1?q?FBTqDfBSDDTxbsLcT6wuxyc5f+Tb5oBipqXnDJPqFqjFqjA9MWrNNJpRgEn3?= =?iso-8859-1?q?1MkcB0TmOTq1rWXmhegTcKS5JxleGcMzT0PPhQxfyJFD85jCxeLeHm44AI71?= =?iso-8859-1?q?wrQawYK0H6G2xhUgcneUlvZfuMgll2nEqn6bHGCfao7L4c2HmnQR7ffcJDvp?= =?iso-8859-1?q?3nsb06qjqy3N1czuJ8J1WIo8S1TQUkdAbFk4IrEu0Yk/TF+pNqXKlhbkue55?= =?iso-8859-1?q?FQMLzuCDBRzK0OKsi4LZwM10/8uMRytIO/bA231glJr2oC64rxvv7wmUsxZ1?= =?iso-8859-1?q?Ii54lCHTc4LrggF9EcWA/98UZujGouSawKglHww05fQDxKi/gFwdpfsnj4Yr?= =?iso-8859-1?q?ICvZbd46tSTtvIWTYhoe+kaMabFQLPA3SbLbNZRzC5elJVG9Bolx5l07DtUB?= =?iso-8859-1?q?d7gcuB7aR3YQTMAkt0ONEdRh/krqKAFIhWIt1L1Ky+5A9Lg+fKb5RAvDx1v1?= =?iso-8859-1?q?FevNia69xiFZqe35lp3NaA462PvovOvat6GiHd+NgKPmYctxGPZivq0lef33?= =?iso-8859-1?q?GhUe8pJozvtLSvMYiW7EzbrB/mOdOBbpT2DFUdlb/SNYlmiO10nC0BfA3Tvv?= =?iso-8859-1?q?u4T/AfmER/wbVcpvGDIEbS5Nmqc+egPQpHd5Nqy9oSCxoCrxbSkBOSWE4A6y?= =?iso-8859-1?q?z/Gqc0brWnwjdRJZLStSqWJ/+Z4XmCeJxo/wgCV7fxLjVP+VVGpZi8XaJkD6?= =?iso-8859-1?q?KZzKeofPjK3rpPabVeznEwWbnPZCVyKqtxkGza+VXy8h0f4cMoywPNT6vhR4?= =?iso-8859-1?q?HnqEitQTjVGZ6m5XD8sb64gfAIsdp8su7R9B5LsIYsyt7IOaxEkyQbqDwzv8?= =?iso-8859-1?q?noDtQXH1TBkfv0GZN8Mleki6PJRLX?= MIME-Version: 1.0 X-OriginatorOrg: fb.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: SJ0PR15MB5154.namprd15.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 193da1b8-9bc9-4792-792a-08da4e5b1afe X-MS-Exchange-CrossTenant-originalarrivaltime: 14 Jun 2022 23:10:42.7909 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 6hG/mL60f6L97dO7RRMu1AjmPjiyIost7br9tLKCUtPNGkuG69bOxx58yfu6DWql X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW5PR15MB5220 X-Proofpoint-GUID: 07wj0KUjo4ZkBvokf6IWrD5VBr9F81Zp X-Proofpoint-ORIG-GUID: 07wj0KUjo4ZkBvokf6IWrD5VBr9F81Zp X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-14_10,2022-06-13_01,2022-02-23_01 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net In order to add a version of bpf_prog_run_array which accesses the bpf_prog->aux member, bpf_prog needs to be more than a forward declaration inside bpf.h. Given that filter.h already includes bpf.h, this merely reorders the type declarations for filter.h users. bpf.h users now have access to bpf_prog internals. Signed-off-by: Delyan Kratunov --- include/linux/bpf.h | 36 ++++++++++++++++++++++++++++++++++++ include/linux/filter.h | 34 ---------------------------------- 2 files changed, 36 insertions(+), 34 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 8e6092d0ea95..69106ae46464 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -5,6 +5,7 @@ #define _LINUX_BPF_H 1 #include +#include #include #include @@ -22,6 +23,7 @@ #include #include #include +#include #include #include @@ -1084,6 +1086,40 @@ struct bpf_prog_aux { }; }; +struct bpf_prog { + u16 pages; /* Number of allocated pages */ + u16 jited:1, /* Is our filter JIT'ed? */ + jit_requested:1,/* archs need to JIT the prog */ + gpl_compatible:1, /* Is filter GPL compatible? */ + cb_access:1, /* Is control block accessed? */ + dst_needed:1, /* Do we need dst entry? */ + blinding_requested:1, /* needs constant blinding */ + blinded:1, /* Was blinded */ + is_func:1, /* program is a bpf function */ + kprobe_override:1, /* Do we override a kprobe? */ + has_callchain_buf:1, /* callchain buffer allocated? */ + enforce_expected_attach_type:1, /* Enforce expected_attach_type checking at attach time */ + call_get_stack:1, /* Do we call bpf_get_stack() or bpf_get_stackid() */ + call_get_func_ip:1, /* Do we call get_func_ip() */ + tstamp_type_access:1; /* Accessed __sk_buff->tstamp_type */ + enum bpf_prog_type type; /* Type of BPF program */ + enum bpf_attach_type expected_attach_type; /* For some prog types */ + u32 len; /* Number of filter blocks */ + u32 jited_len; /* Size of jited insns in bytes */ + u8 tag[BPF_TAG_SIZE]; + struct bpf_prog_stats __percpu *stats; + int __percpu *active; + unsigned int (*bpf_func)(const void *ctx, + const struct bpf_insn *insn); + struct bpf_prog_aux *aux; /* Auxiliary fields */ + struct sock_fprog_kern *orig_prog; /* Original BPF program */ + /* Instructions for interpreter */ + union { + DECLARE_FLEX_ARRAY(struct sock_filter, insns); + DECLARE_FLEX_ARRAY(struct bpf_insn, insnsi); + }; +}; + struct bpf_array_aux { /* Programs with direct jumps into programs part of this array. */ struct list_head poke_progs; diff --git a/include/linux/filter.h b/include/linux/filter.h index ed0c0ff42ad5..d0cbb31b1b4d 100644 --- a/include/linux/filter.h +++ b/include/linux/filter.h @@ -559,40 +559,6 @@ struct bpf_prog_stats { struct u64_stats_sync syncp; } __aligned(2 * sizeof(u64)); -struct bpf_prog { - u16 pages; /* Number of allocated pages */ - u16 jited:1, /* Is our filter JIT'ed? */ - jit_requested:1,/* archs need to JIT the prog */ - gpl_compatible:1, /* Is filter GPL compatible? */ - cb_access:1, /* Is control block accessed? */ - dst_needed:1, /* Do we need dst entry? */ - blinding_requested:1, /* needs constant blinding */ - blinded:1, /* Was blinded */ - is_func:1, /* program is a bpf function */ - kprobe_override:1, /* Do we override a kprobe? */ - has_callchain_buf:1, /* callchain buffer allocated? */ - enforce_expected_attach_type:1, /* Enforce expected_attach_type checking at attach time */ - call_get_stack:1, /* Do we call bpf_get_stack() or bpf_get_stackid() */ - call_get_func_ip:1, /* Do we call get_func_ip() */ - tstamp_type_access:1; /* Accessed __sk_buff->tstamp_type */ - enum bpf_prog_type type; /* Type of BPF program */ - enum bpf_attach_type expected_attach_type; /* For some prog types */ - u32 len; /* Number of filter blocks */ - u32 jited_len; /* Size of jited insns in bytes */ - u8 tag[BPF_TAG_SIZE]; - struct bpf_prog_stats __percpu *stats; - int __percpu *active; - unsigned int (*bpf_func)(const void *ctx, - const struct bpf_insn *insn); - struct bpf_prog_aux *aux; /* Auxiliary fields */ - struct sock_fprog_kern *orig_prog; /* Original BPF program */ - /* Instructions for interpreter */ - union { - DECLARE_FLEX_ARRAY(struct sock_filter, insns); - DECLARE_FLEX_ARRAY(struct bpf_insn, insnsi); - }; -}; - struct sk_filter { refcount_t refcnt; struct rcu_head rcu; From patchwork Tue Jun 14 23:10:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Delyan Kratunov X-Patchwork-Id: 12881694 X-Patchwork-Delegate: bpf@iogearbox.net 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 9CAD1CCA47B for ; Tue, 14 Jun 2022 23:10:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239660AbiFNXKx (ORCPT ); Tue, 14 Jun 2022 19:10:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235852AbiFNXKv (ORCPT ); Tue, 14 Jun 2022 19:10:51 -0400 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A1D150B2D for ; Tue, 14 Jun 2022 16:10:50 -0700 (PDT) Received: from pps.filterd (m0109333.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25EMcqs2006248 for ; Tue, 14 Jun 2022 16:10:50 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=facebook; bh=dYXhyYNUU6QlU3s2VrtJhEeZ8UHskZN6vKNhpBYMOFE=; b=R7WphPP7gUD5rg6q+fGSGattTk3fbommk+Af5gyhVYLb/MahHNa/6QeW6qr8JmP80+m+ ljAlPFRnt+IhxHID0KIDH4fjJdUv2B/JIXl75fGEFDXZL8031rkKMHyghpXNTG/ePL3k 5LAnT8vjXfaZ7DcuwBtNg1kBJJK4TurKdIA= Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2176.outbound.protection.outlook.com [104.47.59.176]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3gpht16dws-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 14 Jun 2022 16:10:49 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AIYZTK5MzGxrr5ry2dMiLLbTJ9AoxRVEswQ4WOW8+bqkrv3PWQOAnyyWuCrQnW5EvZwB/JrxXjEXjpoywA3jc2I+oX4AGCO5mSme5tKojFb9gi1Uv59Cf7FfsUxNpnpmtFpqJTFRuOIK3+AVcA3+Avm5anMpuHQYL21+hB9+oA4x3zZZgfYkVptyv1eIfaSmN70/W1+Ry5hP0utdpgMSLxXLReXjbD0sVVbFKVKe+Y4d2wvqnND+xb98c3R0Syzry040FG/azM9FL4GSC6HcrHqY2VfuY+/QAL2v5jYXU4flmkUEzqseEsD7OazMtcjmZHAVaobjvfSg/u1n8VwdWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=dYXhyYNUU6QlU3s2VrtJhEeZ8UHskZN6vKNhpBYMOFE=; b=g3wpWIgrxMZkwUahp7qr1vynvCR7d7jx4Ta603JbrRBWdWDulxhQoVh5dfQJDc+3bqqfSssH3W51vByWGlBl82T3GEdcvZCHDdcdvGrBProJnuvKOLDDpUGO5eGB/yFzUrn82EV1mjpNknf1Pg6JvzHpwaur9McICe5u7W46m8OLsHzxSD9rj4gjkO5q1PZYBT5dyLJlqEUTfBrMgXZJeFFCc/QcKpoSS76sHxPX6cTx3TS9BfvdGQWwdunNNqylUBv8A7rSfWofOorXlJsn1KOJWAHNcN7UdzLeuDVW7VoDzdQDKnbswltfI/1MV9jSWYDFF60+cPMKYNETKa63MQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=fb.com; dmarc=pass action=none header.from=fb.com; dkim=pass header.d=fb.com; arc=none Received: from SJ0PR15MB5154.namprd15.prod.outlook.com (2603:10b6:a03:423::6) by DM6PR15MB2665.namprd15.prod.outlook.com (2603:10b6:5:1a7::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.20; Tue, 14 Jun 2022 23:10:47 +0000 Received: from SJ0PR15MB5154.namprd15.prod.outlook.com ([fe80::8910:e73d:9868:600b]) by SJ0PR15MB5154.namprd15.prod.outlook.com ([fe80::8910:e73d:9868:600b%9]) with mapi id 15.20.5332.016; Tue, 14 Jun 2022 23:10:46 +0000 From: Delyan Kratunov To: "daniel@iogearbox.net" , "ast@kernel.org" , "andrii@kernel.org" , "bpf@vger.kernel.org" Subject: [PATCH bpf-next v4 2/5] bpf: implement sleepable uprobes by chaining gps Thread-Topic: [PATCH bpf-next v4 2/5] bpf: implement sleepable uprobes by chaining gps Thread-Index: AQHYgEP6z21FSZhSH0KwohIX05SbaA== Date: Tue, 14 Jun 2022 23:10:46 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 1a4e2f9b-2760-4f4e-4923-08da4e5b1d57 x-ms-traffictypediagnostic: DM6PR15MB2665:EE_ x-microsoft-antispam-prvs: x-fb-source: Internal x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: eJvR99Z0lqED7/rnmf00/UTbAdPYLH4n2RRurfdTw6uGXbQ9MEkirIpZW3FzX373OqSzh/6sgSOs4GI0fwLbqJ2SflRLXO0m/ALYA3+vRdn6OgNkQJ/G1LIVjRQ5GgBtgTACoFfPLsByRxYzdzQQkIAcrnb1Fw5Hw3HW4dv+Luk3othWzk5LC6BZdBSm8P37MoZaT+O9sp9RLjazTZVmd4inhxjuoOgYTDUcJdKMI9kP23w0BRGY4KdfaafjB2pYfKjk/iRoJQQkUEeyAq0HQ8RsyaJe6GZEYN7kqlQ0NMTZf9Pc72RAKICfaMPm5xKA5DzjQ15PJ3TXjmU9jVr4lXuKeBKv4zHL1HCeZPKEsvzJuJsJQ3Yqtr6QgOhmHLxzHMPDVABqZdV5lbs2zQEnMz9k44nxM1ifitCwaNu96OvIt0WAYUfk0xKfbgtUuLLKhH9jBZnejazmE8gGLogOCqbiIKKboi2iLOqLGBReilAl5FRDKFZK3c8yj1QbS5UiLflMgUU800TihCj+lk0632RRa5p2a0YGB4zNFI1SVrpMnhl5XqLB0TsAh+szkJNo1lWG2QfA4+IpU34/H40J929PqQxBQ6xdrs79FPWKsqRFz+THDrRgtye5Bk+OioCVo0a6C0qufvP9MSyL+HoTAZ0pKGPl6CYQ5Xu0QAcJ7Q6aQu7ahI6KgLspG/J0bcTEwLXow+eEr0DoPLF8ErxeRg== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR15MB5154.namprd15.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(4636009)(366004)(8936002)(5660300002)(508600001)(71200400001)(6486002)(36756003)(38100700002)(6506007)(110136005)(76116006)(86362001)(66946007)(38070700005)(64756008)(66476007)(66556008)(91956017)(122000001)(2906002)(8676002)(316002)(2616005)(6512007)(66446008)(186003)(83380400001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?gcLr1VTJI3jpzRok/dAF2Vb?= =?iso-8859-1?q?4O+SWA6c4o+t+F7Kqv24zR9V7dZI8DQ+Xbf2wVuA3X+CSS6jmqXnVvWEFpZ6?= =?iso-8859-1?q?nD5apORccbCslAgYAryiR+FhPIJzEixqYHKekLV8gJPJI+f+HaHmZjOTb8Pd?= =?iso-8859-1?q?Zm0s+cqffIwcaVeu8n+ww56sCeIVl0FDnB/0g+5ULe7xelDKOQTjZnIrAJpf?= =?iso-8859-1?q?2NI7KAWje1Sb3TsYVfQs7St93hIxbwL67LRJo4UiWDoq1CFSD/XN4BfhXLs5?= =?iso-8859-1?q?/NSi/eQ++R+0LxKM363pkj1CV7Dq+9QvMkvHKpDl9fAEZ9SLclRfo11edtv1?= =?iso-8859-1?q?bjTqEJvHnw9YDDRREgeh0wEISX66pvr8jF9AriwdzZggsKWwl1tiSXmZcq6x?= =?iso-8859-1?q?q0uG8MMDA85UvKy7gTbVB2iElo3Ry6ZHUnmOJU3uVepGf/FHQaKDqkTDosV0?= =?iso-8859-1?q?zVuYK9HddEJkX2pbp/YmgzsvQssfq7soKt7S+zRxFz/kxdv3pwvE+xZUp0Vs?= =?iso-8859-1?q?EcspgCl/q/wApJNSc8SXFFDbs/QgqiefAJD9IURhw6KEjOVLYQN5WIllw/Ai?= =?iso-8859-1?q?JnvDBmu6YbQqItSZHskLxbeC9vDFJY0SP77EfTmil1N6IMNiP5hAllLS0o1f?= =?iso-8859-1?q?od3d1QhsMCk+d/kiMrtHOysxPnJXsOyEEhX61aXN94HajjL+L9iP1bkeu6qr?= =?iso-8859-1?q?AOV3EUxusMrrMCyagh8ftkCwNvFEd0lEhhi/8rYEgXZ8tuMlnURXdxR/bSpa?= =?iso-8859-1?q?YFYfr32xncAJ98RbeJWKcHiu90fJNWj3wvx5mk9mcpJJXEw7kZmquPU4Io7c?= =?iso-8859-1?q?I/emT8blpSWhq3vGmNKtwxYpznn4SENHRJo0uLt99ZRX82493BTqcecPzlGp?= =?iso-8859-1?q?n5BwK7OgHFdwqExkWBLGzdt4kkJcKgoAqbB2U6AFN9kbtszGXFLf0hQIfg+I?= =?iso-8859-1?q?+vMxml5caVrRsdIlV6WU601rJcEhJXMaarTJOSAYp2aiCIv3sYPuIcrOBfEk?= =?iso-8859-1?q?k1SopMsnCk0uxrfzhYAAb0DaWmkclL2oCrlvxYhMSKiyWB0elmV+JrG4p0bT?= =?iso-8859-1?q?J5HtGOqzEFUlowBgRQjPrwPKslF9XwhECTdvktBD8faaCxTeiHFEeERAAMKV?= =?iso-8859-1?q?eAklq5Q879SktcPGK9EYZoAp3pVsReG1H/gWFaVmk2e9cHPNkMKe5aezgXrm?= =?iso-8859-1?q?7z4jXFuwYeBfu9KElekcufg+BMklHa/AimWwv1gt9wRa3XLPxwq++++EEccU?= =?iso-8859-1?q?SnrwwGV2dhkr1DoosH5xnzEOAlzslh5OZoGMHbBXh23inMwZC8gn4tFf9ZVL?= =?iso-8859-1?q?gX3kZlx0Ifc220DjW4IZaGP16XO1C4inkifYoULBLGXg7Zh+BoCOtvmFzvlk?= =?iso-8859-1?q?OAhD0wuH935Ka5rMJIqtCUYVberRxfr1W1vRYWYuKQ69ophRMh8XWJyEBx3J?= =?iso-8859-1?q?pwPyUBnwOzMWIEQjmHb9r1zgDSTRbDC6LePSRoGGUGjM8002Cnik2B90I73r?= =?iso-8859-1?q?ME2a/ZOQVxQZ0hefMZq/QHUdBH1b42bNorSetNoO16i3ibPIWuVbCnXZtsyS?= =?iso-8859-1?q?fLt859q6LeIA35AUOD6GCPcArqLw9Qoo3q1jOgYGufGrX0KFcTaepjeFujrf?= =?iso-8859-1?q?Jt1pX3bqcdQN9Tq0Wrb+ANMsxbyB/rGiALV+L9QR/95WUYd46L6FBKxajEbR?= =?iso-8859-1?q?CR36qgHNITl3I9nEbE9yFgLtMskPdb7WlIr4LcW8PfDsUcMm8KfGlOI8Fafp?= =?iso-8859-1?q?Bg41J9xYgTZRdSHZsn9H0/05Ck9go+tBCATkxrWum2PPDfkPh7/4XHsGF7TY?= =?iso-8859-1?q?m0FUVVVjIneODOFaCydSmVo1cCOC3?= MIME-Version: 1.0 X-OriginatorOrg: fb.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: SJ0PR15MB5154.namprd15.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1a4e2f9b-2760-4f4e-4923-08da4e5b1d57 X-MS-Exchange-CrossTenant-originalarrivaltime: 14 Jun 2022 23:10:46.6971 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: +rDcu9J3uyKdKtCHuDoUQpMh03G5zdYCw7LL9NGJOBxh4nZCXF057SwcI8Qh8nq2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR15MB2665 X-Proofpoint-GUID: IjXujJGMF8I_MDIxvnc9-hY-ugjS5Fwq X-Proofpoint-ORIG-GUID: IjXujJGMF8I_MDIxvnc9-hY-ugjS5Fwq X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-14_10,2022-06-13_01,2022-02-23_01 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net uprobes work by raising a trap, setting a task flag from within the interrupt handler, and processing the actual work for the uprobe on the way back to userspace. As a result, uprobe handlers already execute in a might_fault/_sleep context. The primary obstacle to sleepable bpf uprobe programs is therefore on the bpf side. Namely, the bpf_prog_array attached to the uprobe is protected by normal rcu. In order for uprobe bpf programs to become sleepable, it has to be protected by the tasks_trace rcu flavor instead (and kfree() called after a corresponding grace period). Therefore, the free path for bpf_prog_array now chains a tasks_trace and normal grace periods one after the other. Users who iterate under tasks_trace read section would be safe, as would users who iterate under normal read sections (from non-sleepable locations). The downside is that the tasks_trace latency affects all perf_event-attached bpf programs (and not just uprobe ones). This is deemed safe given the possible attach rates for kprobe/uprobe/tp programs. Separately, non-sleepable programs need access to dynamically sized rcu-protected maps, so bpf_run_prog_array_sleepables now conditionally takes an rcu read section, in addition to the overarching tasks_trace section. Signed-off-by: Delyan Kratunov --- include/linux/bpf.h | 52 +++++++++++++++++++++++++++++++++++++ kernel/bpf/core.c | 15 +++++++++++ kernel/trace/bpf_trace.c | 4 +-- kernel/trace/trace_uprobe.c | 5 ++-- 4 files changed, 71 insertions(+), 5 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 69106ae46464..f3e88afdaffe 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -26,6 +26,7 @@ #include #include #include +#include struct bpf_verifier_env; struct bpf_verifier_log; @@ -1372,6 +1373,8 @@ extern struct bpf_empty_prog_array bpf_empty_prog_array; struct bpf_prog_array *bpf_prog_array_alloc(u32 prog_cnt, gfp_t flags); void bpf_prog_array_free(struct bpf_prog_array *progs); +/* Use when traversal over the bpf_prog_array uses tasks_trace rcu */ +void bpf_prog_array_free_sleepable(struct bpf_prog_array *progs); int bpf_prog_array_length(struct bpf_prog_array *progs); bool bpf_prog_array_is_empty(struct bpf_prog_array *array); int bpf_prog_array_copy_to_user(struct bpf_prog_array *progs, @@ -1463,6 +1466,55 @@ bpf_prog_run_array(const struct bpf_prog_array *array, return ret; } +/* Notes on RCU design for bpf_prog_arrays containing sleepable programs: + * + * We use the tasks_trace rcu flavor read section to protect the bpf_prog_array + * overall. As a result, we must use the bpf_prog_array_free_sleepable + * in order to use the tasks_trace rcu grace period. + * + * When a non-sleepable program is inside the array, we take the rcu read + * section and disable preemption for that program alone, so it can access + * rcu-protected dynamically sized maps. + */ +static __always_inline u32 +bpf_prog_run_array_sleepable(const struct bpf_prog_array __rcu *array_rcu, + const void *ctx, bpf_prog_run_fn run_prog) +{ + const struct bpf_prog_array_item *item; + const struct bpf_prog *prog; + const struct bpf_prog_array *array; + struct bpf_run_ctx *old_run_ctx; + struct bpf_trace_run_ctx run_ctx; + u32 ret = 1; + + might_fault(); + + rcu_read_lock_trace(); + migrate_disable(); + + array = rcu_dereference_check(array_rcu, rcu_read_lock_trace_held()); + if (unlikely(!array)) + goto out; + old_run_ctx = bpf_set_run_ctx(&run_ctx.run_ctx); + item = &array->items[0]; + while ((prog = READ_ONCE(item->prog))) { + if (!prog->aux->sleepable) + rcu_read_lock(); + + run_ctx.bpf_cookie = item->bpf_cookie; + ret &= run_prog(prog, ctx); + item++; + + if (!prog->aux->sleepable) + rcu_read_unlock(); + } + bpf_reset_run_ctx(old_run_ctx); +out: + migrate_enable(); + rcu_read_unlock_trace(); + return ret; +} + #ifdef CONFIG_BPF_SYSCALL DECLARE_PER_CPU(int, bpf_prog_active); extern struct mutex bpf_stats_enabled_mutex; diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index e78cc5eea4a5..b5ffebcce6cc 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -2279,6 +2279,21 @@ void bpf_prog_array_free(struct bpf_prog_array *progs) kfree_rcu(progs, rcu); } +static void __bpf_prog_array_free_sleepable_cb(struct rcu_head *rcu) +{ + struct bpf_prog_array *progs; + + progs = container_of(rcu, struct bpf_prog_array, rcu); + kfree_rcu(progs, rcu); +} + +void bpf_prog_array_free_sleepable(struct bpf_prog_array *progs) +{ + if (!progs || progs == &bpf_empty_prog_array.hdr) + return; + call_rcu_tasks_trace(&progs->rcu, __bpf_prog_array_free_sleepable_cb); +} + int bpf_prog_array_length(struct bpf_prog_array *array) { struct bpf_prog_array_item *item; diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index 10b157a6d73e..d1c22594dbf9 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -1936,7 +1936,7 @@ int perf_event_attach_bpf_prog(struct perf_event *event, event->prog = prog; event->bpf_cookie = bpf_cookie; rcu_assign_pointer(event->tp_event->prog_array, new_array); - bpf_prog_array_free(old_array); + bpf_prog_array_free_sleepable(old_array); unlock: mutex_unlock(&bpf_event_mutex); @@ -1962,7 +1962,7 @@ void perf_event_detach_bpf_prog(struct perf_event *event) bpf_prog_array_delete_safe(old_array, event->prog); } else { rcu_assign_pointer(event->tp_event->prog_array, new_array); - bpf_prog_array_free(old_array); + bpf_prog_array_free_sleepable(old_array); } bpf_prog_put(event->prog); diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c index 9711589273cd..0282c119b1b2 100644 --- a/kernel/trace/trace_uprobe.c +++ b/kernel/trace/trace_uprobe.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "trace_dynevent.h" #include "trace_probe.h" @@ -1346,9 +1347,7 @@ static void __uprobe_perf_func(struct trace_uprobe *tu, if (bpf_prog_array_valid(call)) { u32 ret; - preempt_disable(); - ret = trace_call_bpf(call, regs); - preempt_enable(); + ret = bpf_prog_run_array_sleepable(call->prog_array, regs, bpf_prog_run); if (!ret) return; } From patchwork Tue Jun 14 23:10:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Delyan Kratunov X-Patchwork-Id: 12881696 X-Patchwork-Delegate: bpf@iogearbox.net 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 5EEDBC43334 for ; Tue, 14 Jun 2022 23:10:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240106AbiFNXKz (ORCPT ); Tue, 14 Jun 2022 19:10:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240108AbiFNXKv (ORCPT ); Tue, 14 Jun 2022 19:10:51 -0400 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA8C652B0D for ; Tue, 14 Jun 2022 16:10:46 -0700 (PDT) Received: from pps.filterd (m0109333.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25EMcqrw006248 for ; Tue, 14 Jun 2022 16:10:46 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=facebook; bh=VZNTSQJbvvTtEpRIh+e++fhF/w6C3GTaVRh+vwDGskA=; b=EzbzSXeUCQedV6h9bomitBcS8SEcbZqDGbctIe00EUsRag8JNrSIvnP4wy6Z8XSsMP+C ufSPiubadkcVzTcmt7piWlU8X+awwIHu0nZVYebnVJicd2kjoqbItzmDrzGTlHG0GeCw hpbcR34UyI5RGypAsjzfJNZ5bAZ/7YbQxc8= Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2169.outbound.protection.outlook.com [104.47.59.169]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3gpht16dwf-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 14 Jun 2022 16:10:46 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AQEUYzG52OJcFaBP0cz22sxBM/2l3ESg9wvGl3bn+wcq9vTKRwv7jukrKfZFH0egINjM0gZkDaZwXxk3KRaCxDP0k8WJN7Gx9MalW2pSQOSpngd1ot7FSv1XocQ/5z8Mwvr3Imck0TDUmqTf1tHADw76FELHaaqu789C+YU+YG3Ac2xSRmGhGV6ItFqG33t1MwDe2NWeQu3qBVuf1gCFQl6rzfwqr8zae9UNTUBCU7P22z0f5WwN7/W+fIDxTDJleX2drHgShyJCoj/CBQQMTOlCFjkwdb1VqbvzPrnfuzaBctaVvn/4sYZN2TuyOUyVl/0+2AgnZvZCekFB6wDAJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=VZNTSQJbvvTtEpRIh+e++fhF/w6C3GTaVRh+vwDGskA=; b=X5Adqx+eWx8TqC6/6RLlF/SfZMNZ8nDqsb9xFdnvM78XJN5nhWoH6DozYl4a9rZf24xoie9qe80cwloX+zwBRETaAE2kk7wwFuxdqMZrf74zVOHZDkZr93G/DnODdbCKA3D6UKzXGy9MNFuwkwF3ShqJuem5uu2quzH+HNogx8kKJFyvCTJOoZAbSxV3b2e0bqO2tl42cwwBOqrZvuO3ZrtU8a2uWXZSeYjK21tLXoDTpKD//fbL0RU1MV1k4Kjgar1XFeFWIKUzygjXdwPcg3HMGXX0FhKY/sTf2+guQd9pJ2zPEP273P58c2QP+vB04llze9UrZNSggJcBcgNt3g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=fb.com; dmarc=pass action=none header.from=fb.com; dkim=pass header.d=fb.com; arc=none Received: from SJ0PR15MB5154.namprd15.prod.outlook.com (2603:10b6:a03:423::6) by MW5PR15MB5220.namprd15.prod.outlook.com (2603:10b6:303:1a0::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.20; Tue, 14 Jun 2022 23:10:43 +0000 Received: from SJ0PR15MB5154.namprd15.prod.outlook.com ([fe80::8910:e73d:9868:600b]) by SJ0PR15MB5154.namprd15.prod.outlook.com ([fe80::8910:e73d:9868:600b%9]) with mapi id 15.20.5332.016; Tue, 14 Jun 2022 23:10:43 +0000 From: Delyan Kratunov To: "daniel@iogearbox.net" , "ast@kernel.org" , "andrii@kernel.org" , "bpf@vger.kernel.org" Subject: [PATCH bpf-next v4 3/5] bpf: allow sleepable uprobe programs to attach Thread-Topic: [PATCH bpf-next v4 3/5] bpf: allow sleepable uprobe programs to attach Thread-Index: AQHYgEP56LrMDqiRekeDa7Qk18mVcg== Date: Tue, 14 Jun 2022 23:10:43 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 48f7cb0b-22e1-465e-4d5f-08da4e5b1b8d x-ms-traffictypediagnostic: MW5PR15MB5220:EE_ x-microsoft-antispam-prvs: x-fb-source: Internal x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: ZRlLaWa27XK/+/WfVySwsVuNleWGi8KjHNW28jiu2/eN+WdjvyK0YzOpapt612tzTxPesFtw2CuowH1ruGGeMQEuIIQVqtHNat/5W5hf+BhHehlg7ohPctt7dh/xGxWiRRro/7anAAT6gi+qjDxj46FSOcIs9I+RMQS1WhYE7ARZA93dZSLgLYvSEEiOHbi/2bZUVuje72dU4aC2tQldXqk6wadPbrJJcFUVDkDP+2R5heUSrg2oWSAcuvapoHYbytMHN7Gm0veCmOaw9pxwzUsajUohJiL0wNzEWXPo/pyQ1ICDk85SXNVTa7Wh6JEJxu7lheVNG3y7miIU9dXJ9G43zOvxXVz+zeQ/LzSG/P9QqwNaYJi/3NUvlygQPQqScOphJCHmMn1GQUBuhcGgDRn0TFiiLp9fbtTZm96//L5F9qe9/R6YdVr8rU4EXNpk9Hz34apnYutD81X1sIhenZV6ijHaAm6ttDBbiCvfuR4fNdpPgr7V4IaYHvACSFOf5dXQSFGJ0nGAAzV023JmEecNa0NClTw5DC/jzFyzkPbvIcLKe5AI1NwhTv9pVVJm+k2XEkapvM5kmPVopVUqlFPPMkXDGfQAMd1/graQk+5YBFnFyUP3dhfwphYD/tgJ9aN4uKSnkz5ehW5orHNKFXJBAhucq77Anoz5Ymn+wbZf1IPIrFRKu+Vtg4dMlamLn4jXJaWo6jujPs8wUkSg5w== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR15MB5154.namprd15.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(4636009)(366004)(186003)(8936002)(5660300002)(122000001)(38100700002)(83380400001)(6506007)(6486002)(36756003)(508600001)(38070700005)(6512007)(71200400001)(66946007)(316002)(66476007)(2616005)(2906002)(64756008)(66446008)(76116006)(8676002)(91956017)(66556008)(86362001)(110136005);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?0Za+tulDjfcIAN1tc/FsBG4?= =?iso-8859-1?q?3LAXn6ZHvu+RrUJMjdcYA/slpEbV1sCdEHrVJM0OaxvNCTEPLAwTorXwkgZd?= =?iso-8859-1?q?vDhcGaStduKozLOlN3E2/usBGVkkjbR7dRtGKLTxdQuMklvpUjo+Xd5romQQ?= =?iso-8859-1?q?UAbhkAydc2Mh1mSOAtddbC6w8c/tJ1d4iSaXeSZYrnTPDBDXZuwNZ5bDTfWC?= =?iso-8859-1?q?cLyBKBqgINbcbes9fjU5qcTQFloaujQ4H9XqR/QAI95AG7Hn2PhHVpiScPve?= =?iso-8859-1?q?ixunc5wTDxRyIvJmvhgHe+6iWsQAGIRItkL4kO5wcp6+JnDK9hMrHOj8eyPV?= =?iso-8859-1?q?NUREDbAVJqoCSDCmsfGKyMTqX9k4a9J5Xtl1xmUOAJB2RXx3jWlfpXHR6Ma7?= =?iso-8859-1?q?iM2kUtbIWVh0jQpYJs1U9CaOtc5mwz4zMxXgBd1EzuhUYV2uNTVxrrHrH7t7?= =?iso-8859-1?q?qOjNsusRDAyHtgGuuypGxQHzG/+kZMPjWFN04S67mcQhCLluNiZI6puAToI0?= =?iso-8859-1?q?Y+GNwmeyDBdhL5zn/b6bIOFSvDxpolGXF55wMnsUqV1f2uwzQJ0qrHvnzR8J?= =?iso-8859-1?q?cc0r3TwjxZHjeeXxCKOOyNCxOpJo+FExkP7PQ0kILEEz8lg+3zHw7AHyWVSv?= =?iso-8859-1?q?9fb/U+BLFS2qz1trQgrQgsDMPiUKAKIYSmMpncAypfPQ486wPX4Ar/Fu5+xL?= =?iso-8859-1?q?t38ywz/d3KpwFLWGupLpqkcSD1o8id5HKBPJOB6GCfMeuMZG181fDQ0nnBWl?= =?iso-8859-1?q?f51rfyTgk2mXWN9MNggL1/fwq7qI0UFO/aP2gwQccMZOihjq7G0Jq+W8L2YN?= =?iso-8859-1?q?S7h6UBy/ZS459+LMWs4lQmy4uB3KGqOlPYfgX58keGkON8294cbk8unH4d93?= =?iso-8859-1?q?2CuQkjD+9wMxBJuKuHiBkzt/f8w8HwnA8uQW5xmxNgoQV/FFdo7pxOMyNH3t?= =?iso-8859-1?q?/2+1KYl3N9A8HiTHZsCDtZUxou7D0AWY6smUWH2XJGuTOlQtLRtfPWSk0GEU?= =?iso-8859-1?q?48eaTYp81dGMzfqWvtjsn4rTgvmjKVwKuOOf28ZSC+sVPaFTdFP/LL/8T65E?= =?iso-8859-1?q?aQChxxfugAM/B27LHUgMa3NvHU7dE5v9do+ZTizo6m5Qp0SljgHXg48+BZa7?= =?iso-8859-1?q?V0Rb4CEmJmB2ZPOqoBK5nOkaJZ4bNh7QR1R13bGjSJjMAn2cmHXhDVbk21m5?= =?iso-8859-1?q?y5rF4Gyuc3GlTNK4Q6jxCBebhiUoekDIK6ANvXqsSyYq52YDs6gK/3xUfFHn?= =?iso-8859-1?q?TJbIE+xM6QYNfqoMzsbm7oZB8hdpKWi46RcHF1WFeAS/vchP+xQx61bsyRnu?= =?iso-8859-1?q?uCi+TSyTnqbqoeuCLY/69bfABUKxoGQTlsFLm0Wa8NFyQPMnd12hpwaPGMZH?= =?iso-8859-1?q?wrDDZ/GSkIWFKT7MgoFnmwFb4G38bMrMR7iEzGFpoFxQ7Bz80PkhOtnr00AU?= =?iso-8859-1?q?9tw7jlU0Im1gcagY4iRxLDwUlTi+OfMk240u4Ca5gTiNwMAtXjPQL/XrOefh?= =?iso-8859-1?q?I8UBbdAeJLjZVSGPgWnT+bzw/TyN8d+uDcOXpbJwQH7aMQj0wlhWE1g+F4dJ?= =?iso-8859-1?q?Ok0vkhGAnMJMIYaf6AaQNVV/npVihRXmn5NF//VHa3HNJ7HpmR/TGmpa//ld?= =?iso-8859-1?q?vUDohOGjHaSiRfgXrra24PTYnQnleg0I8DSoO/DGDrSBl2o5k5d4tWBPYv2H?= =?iso-8859-1?q?trpW/ovepOC6cSPgsKq+5liIgwoY9UItpa9cBLYoc49hXu5uOzFyA0pDyPrp?= =?iso-8859-1?q?PmJFdVfgt7fwrmmLoQNmN5T+iNNFuzERzZOnNqY6INeecu9nvLxceUaziUr3?= =?iso-8859-1?q?jSmV1sYE3b+plKLS30OykzH6ZRhkF?= MIME-Version: 1.0 X-OriginatorOrg: fb.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: SJ0PR15MB5154.namprd15.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 48f7cb0b-22e1-465e-4d5f-08da4e5b1b8d X-MS-Exchange-CrossTenant-originalarrivaltime: 14 Jun 2022 23:10:43.7269 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 0SNOo9ii3AhpYV/IRBznKQLOqeeycfjm2Cu97FeagusG3HHTL13W1IuM7qowA/Y/ X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW5PR15MB5220 X-Proofpoint-GUID: HE9qvUEyOt2qPn2Bp-6bDALoLGOYCC0J X-Proofpoint-ORIG-GUID: HE9qvUEyOt2qPn2Bp-6bDALoLGOYCC0J X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-14_10,2022-06-13_01,2022-02-23_01 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net uprobe and kprobe programs have the same program type, KPROBE, which is currently not allowed to load sleepable programs. To avoid adding a new UPROBE type, instead allow sleepable KPROBE programs to load and defer the is-it-actually-a-uprobe-program check to attachment time, where there's already validation of the corresponding perf_event. A corollary of this patch is that you can now load a sleepable kprobe program but cannot attach it. Acked-by: Andrii Nakryiko Signed-off-by: Delyan Kratunov --- kernel/bpf/verifier.c | 4 ++-- kernel/events/core.c | 16 ++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 2d2872682278..eadc23a8452c 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -14829,8 +14829,8 @@ static int check_attach_btf_id(struct bpf_verifier_env *env) } if (prog->aux->sleepable && prog->type != BPF_PROG_TYPE_TRACING && - prog->type != BPF_PROG_TYPE_LSM) { - verbose(env, "Only fentry/fexit/fmod_ret and lsm programs can be sleepable\n"); + prog->type != BPF_PROG_TYPE_LSM && prog->type != BPF_PROG_TYPE_KPROBE) { + verbose(env, "Only fentry/fexit/fmod_ret, lsm, and kprobe/uprobe programs can be sleepable\n"); return -EINVAL; } diff --git a/kernel/events/core.c b/kernel/events/core.c index 950b25c3f210..deee6815bdd3 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -10069,26 +10069,30 @@ static inline bool perf_event_is_tracing(struct perf_event *event) int perf_event_set_bpf_prog(struct perf_event *event, struct bpf_prog *prog, u64 bpf_cookie) { - bool is_kprobe, is_tracepoint, is_syscall_tp; + bool is_kprobe, is_uprobe, is_tracepoint, is_syscall_tp; if (!perf_event_is_tracing(event)) return perf_event_set_bpf_handler(event, prog, bpf_cookie); - is_kprobe = event->tp_event->flags & TRACE_EVENT_FL_UKPROBE; + is_kprobe = event->tp_event->flags & TRACE_EVENT_FL_KPROBE; + is_uprobe = event->tp_event->flags & TRACE_EVENT_FL_UPROBE; is_tracepoint = event->tp_event->flags & TRACE_EVENT_FL_TRACEPOINT; is_syscall_tp = is_syscall_trace_event(event->tp_event); - if (!is_kprobe && !is_tracepoint && !is_syscall_tp) + if (!is_kprobe && !is_uprobe && !is_tracepoint && !is_syscall_tp) /* bpf programs can only be attached to u/kprobe or tracepoint */ return -EINVAL; - if ((is_kprobe && prog->type != BPF_PROG_TYPE_KPROBE) || + if (((is_kprobe || is_uprobe) && prog->type != BPF_PROG_TYPE_KPROBE) || (is_tracepoint && prog->type != BPF_PROG_TYPE_TRACEPOINT) || (is_syscall_tp && prog->type != BPF_PROG_TYPE_TRACEPOINT)) return -EINVAL; + if (prog->type == BPF_PROG_TYPE_KPROBE && prog->aux->sleepable && !is_uprobe) + /* only uprobe programs are allowed to be sleepable */ + return -EINVAL; + /* Kprobe override only works for kprobes, not uprobes. */ - if (prog->kprobe_override && - !(event->tp_event->flags & TRACE_EVENT_FL_KPROBE)) + if (prog->kprobe_override && !is_kprobe) return -EINVAL; if (is_tracepoint || is_syscall_tp) { From patchwork Tue Jun 14 23:10:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Delyan Kratunov X-Patchwork-Id: 12881697 X-Patchwork-Delegate: bpf@iogearbox.net 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 E7243CCA47C for ; Tue, 14 Jun 2022 23:10:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242696AbiFNXK4 (ORCPT ); Tue, 14 Jun 2022 19:10:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240980AbiFNXKv (ORCPT ); Tue, 14 Jun 2022 19:10:51 -0400 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17192527F2 for ; Tue, 14 Jun 2022 16:10:50 -0700 (PDT) Received: from pps.filterd (m0109333.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25EMcqs4006248 for ; Tue, 14 Jun 2022 16:10:50 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=facebook; bh=6d3FTVA62oasVrN0pczUu55GUIMYv2ffORmmEYzsSeU=; b=kdMViffFAt9kuDlomeJHnZKszV6Ff/oxJ87zJfoODA+EEjpQOZvLgo8kpUswwfWmPTC8 ZJkX9nXYVo9/u8VI0ax5sZZ1WN+ACPPzvGdLw2vIfEk1LlNG/ZsnxXwmOhr+fZcIY04k yhWnKiVBCjwHV4tfcv2J+m4vt7/eZ3W84go= Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2176.outbound.protection.outlook.com [104.47.59.176]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3gpht16dws-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 14 Jun 2022 16:10:50 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SiGjiiVbTXh7q6CJUi0XSkDTc8x+lgEhJHBixZ07+sMuZA35IAlMdx1HI+jxJVF2uNxRnSu0fHyoNoRKiQy+wldmYWuR9jgP+WUaj2McJHU/jFFlhV5eeJt8B98vWP9sW+rMbZpnyWD6KeIH/dSvIln5lVJrF2Oj+B+l5b+suiD+fy4UVbPK1CV5qNJ1OzLE8LqUqjg0jexgBRYS3t2CEyQZc7a+G5N7PrND5fnptmvCS9cDePLQsdEBojXiPHfUdDLyx/RzOEa8m353kZtYdznICB3swc30A/anZvaXacnYurGcHAh70fpoBWkOeWll9lcKwtF90737JpuyIMARqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=6d3FTVA62oasVrN0pczUu55GUIMYv2ffORmmEYzsSeU=; b=F56viOOUS6DIKRXAnpA+pTdQBRWbM6A5rV5GAMLtYKDF02g3/GuZlqqpmCnbhV9pmeNvRCJ4RBvbMn03wXXDqDYve4pIiM+c1wnTEKjpdOGk/4FaLjMEoQXTjX5XXc18/YpXEaz+8Zzj1aqeBRTnndGkvo3qvxs5Vv82DENe7BjDTzWYjfLUVn8L1xnqsd+FOb+D+WymhbOBxOUS2bV1vB49yHbwu3ceD/BuM+TwvpJByVxmpGER179drKC3i9fgyR5mx+dq95CwiE+L10Np0hd3GVA46nQLdyJrn6PBjmB/aW+bNj8CVDvxyUWF/iGt/tLXqWdtFFc38+eNplp+cA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=fb.com; dmarc=pass action=none header.from=fb.com; dkim=pass header.d=fb.com; arc=none Received: from SJ0PR15MB5154.namprd15.prod.outlook.com (2603:10b6:a03:423::6) by DM6PR15MB2665.namprd15.prod.outlook.com (2603:10b6:5:1a7::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.20; Tue, 14 Jun 2022 23:10:47 +0000 Received: from SJ0PR15MB5154.namprd15.prod.outlook.com ([fe80::8910:e73d:9868:600b]) by SJ0PR15MB5154.namprd15.prod.outlook.com ([fe80::8910:e73d:9868:600b%9]) with mapi id 15.20.5332.016; Tue, 14 Jun 2022 23:10:47 +0000 From: Delyan Kratunov To: "daniel@iogearbox.net" , "ast@kernel.org" , "andrii@kernel.org" , "bpf@vger.kernel.org" Subject: [PATCH bpf-next v4 4/5] libbpf: add support for sleepable uprobe programs Thread-Topic: [PATCH bpf-next v4 4/5] libbpf: add support for sleepable uprobe programs Thread-Index: AQHYgEP7nAv/h4b5pkmwqzqFkW2DZg== Date: Tue, 14 Jun 2022 23:10:47 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: a315fc8b-7124-43e8-c156-08da4e5b1dfb x-ms-traffictypediagnostic: DM6PR15MB2665:EE_ x-microsoft-antispam-prvs: x-fb-source: Internal x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 381OoFRyeOosKmF4lpBmgrywCZAIhmkgcBhpuFDiSWkRHm6hJ/8F40P7zV2Zp5RJOcytU18fYSTa6Ocoh6I+MU4Oi11L0WRaO5Bht3aGjCzuTfc59XVO5S5V0SdJrGxEPQ3QOfwtfucJLbdw+Pudgp3FHZ/zKGjA6kH+gwXKzUth1T9qezPyD4iztIPuoDY5GIbadyb0RAVuk/9oN+CO71qWstmZn6KrI/TMMiVjpB8NqS8alFUPk3bahxaN/ZShtx8Sr0zkRoi22O4H0zMveTRgRFFVykd6BaRa7HthZICnq6amWPxbNemWSlm1oV/0ZdfNMZ6WskxySg5wzHczMiPPhRgM5fBph98dY/+wi3VYh+6NhnzVxm8QMd91odUkMJbrGFIgf9SAbTKKEYLely0HeIfG+69uYXcpVSK46AaKmysjSqNW5+D1z67Ako78iyx8DcJ3svVgYZt+3Fe3c2m22DdhheD8RzcxrYPBtbLX1dQeWkeaWIWCnG7PvLEp8o0eTkhOQq7/FaHclGMwqrqfxUfaHJAflBRjtDOQCFZ2NRw2ZXvZ/5Tew/6Yj8Ls26Bm1f0XtkH2Jy+SUob4XfS57TqrNOpsJPpLRGp9CySab6ydE7nze/cPQpNGnN2UOBXt8tQB+rXCLGC+DnJOCIA1vWM0atrOfyMJjeqIa5Xgye4qkkQ5FkE2fQwPQEyCPDRYWcbo49Y1Obqs/layqA== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR15MB5154.namprd15.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(4636009)(366004)(8936002)(5660300002)(508600001)(71200400001)(6486002)(36756003)(38100700002)(6506007)(110136005)(76116006)(86362001)(66946007)(38070700005)(64756008)(66476007)(66556008)(91956017)(122000001)(2906002)(8676002)(316002)(2616005)(6512007)(66446008)(186003)(83380400001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?dKqKMCVujxYnwN3wk8GV65/?= =?iso-8859-1?q?LtenwcYZWSz/mfIsIJco/XAfoO4W0TjUk3Jlnsy6Vc4vWiMGxE4Nv6YcPF4F?= =?iso-8859-1?q?obkiK7MFCM96cJbJ0EULmo97bpcahJ4jW8rSuaoCmYmLZad5WTYbPtFpDGt+?= =?iso-8859-1?q?aEeqP/LdLleLNqXJlDXMjO8DX7KGz26d0e04yuiWz2aMbg5/6FgRl8o7TUjz?= =?iso-8859-1?q?47b9JxC/p53PRI1a/VqsN6kHHZrTpm+DEzIfYUA26SilRiJmHyDYlsqXPfQ7?= =?iso-8859-1?q?X9gbfBb9Z7ZzGAieSVtQaIni73gsHwhSBtFKc08KZsPOI+4XewYBaTBduUh4?= =?iso-8859-1?q?8fBSdInfMMn54cKlasQ6t4YhkYWyWZ4RCxH0p2xMVOAs2xOlYMinSb+P4rmg?= =?iso-8859-1?q?95IKWgvj1JZldBF7BxHuTp4Ne27dbz5dNYZp24lc3T7v2AWg35fJetslvJ3z?= =?iso-8859-1?q?IrQNnpNG86y/nAk0G8bGKFwtuUk+ROaBLNCEh508FRaUtFkSfPN9GoDWU3Cb?= =?iso-8859-1?q?aHzJDoAsmCWuP9XKuzhnN7HA07iC/06Y1XDpJLN98q+1p+sbg1bk8Z3GPbzd?= =?iso-8859-1?q?10W9eg2K+fkXHRSEPs9L5rB3BdORBpyiVDfj5CJdVOETV3Oxn4pL+PYHcseW?= =?iso-8859-1?q?uCtvDlNrOvU1boScnJbd4leW6IieoIKBKjiOk6Q6SdhgquW7trzmqxF8EzhM?= =?iso-8859-1?q?yIRYDKP1hCbPbH4oV+sWdk83u7Jt9crYPU68p/WJGfvqhUpna6sY0gI7ft9g?= =?iso-8859-1?q?oyUdge7KIyiSlEvWGnTl54WiXB6niTzIjKQkjz/NHoCvHC7ct4jiTKAu6mJx?= =?iso-8859-1?q?g0Bt65RZdysk3u5r9qe9hUq3s7dzpc4d3iEd+gQ690nGfj+WOHmQj2bIGunb?= =?iso-8859-1?q?0aBP9TsmO1wg1vvtvQRcMMbMjoGHnRTCt0lJkdLVtVtwKifBadv+mVsDmvyG?= =?iso-8859-1?q?kb7l2pDoE7HlRievjIBdJyh6UmTczu2N4XRZ2ZYHYhVP6X1TiyeAhWYt3MXq?= =?iso-8859-1?q?YyY2EMaQXI1L1oqKz95Lj/d5REBM89oIcBnuNvZcm28nvwU8ztCaB391d8+T?= =?iso-8859-1?q?DpRW3Ob0+BaDIzRrRf5UE379tGCUEMlSs2Mw77rwWxuNO/k3vmDdxaEtYpRT?= =?iso-8859-1?q?t6wbq8QQH9lZvj0pRDEzyniTr97+JxqRDTkHZ2APBf25qpCKnUZ/ExtnTIe0?= =?iso-8859-1?q?2GrhPNKtglEixGbKXH0w/b3nYIWDk4pByRCJ8cLpJZLgUO/3QvigSornpdk/?= =?iso-8859-1?q?A0dWe6CL+bUjpjYy7bBJ/eHsYIIX4HrVyOmaxPjqubfT+QvlIwU8RG/7uORQ?= =?iso-8859-1?q?cgsLFK15j8FLQaFpwKEkq7fgfQQEMlmJl4Ybz//Zry7adNewNkkj/9si4awN?= =?iso-8859-1?q?mEFiErk8i00mZ8+rU3Cv4PPVp2jCNJEoxKd5qKmI59Jo0OaisRZazbGWI8Bf?= =?iso-8859-1?q?IDk5qhDvkCbcMYmkJupW0AejTZqCMxdnT861+SDDBOqql06g5MzdeekyHFAB?= =?iso-8859-1?q?U9AXiR8FeH16R3/an5pVnPkZQNBhAswWagtbJkfFNbAGKV1Pgbuk9POzpKQI?= =?iso-8859-1?q?QKqq19MtbDG1XmLmNcLM6xKaFYWasi9L8KF2eytSOzF9bI9b/5oKCCP69F4t?= =?iso-8859-1?q?BvWwaiGktFd4YGSe0riJYl+GTM0PMSR4czrBx46NB/PsDpRLw2d3mOcB/0gb?= =?iso-8859-1?q?iaJO3TPRB0rJu9pIF8AaQT/OtF4GKKtd9HP0ScKeDcKIae+tJLbmEf8/r5Pb?= =?iso-8859-1?q?EfpUzT2cC7Jis/0W8fZT2BlsBAptE4fdxCq7eyTkM/6td4yjVj9M1r8MYLxW?= =?iso-8859-1?q?/sveAHw1thAf0kRVec+nR3eWm3nqz?= MIME-Version: 1.0 X-OriginatorOrg: fb.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: SJ0PR15MB5154.namprd15.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: a315fc8b-7124-43e8-c156-08da4e5b1dfb X-MS-Exchange-CrossTenant-originalarrivaltime: 14 Jun 2022 23:10:47.8062 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: usT8JuoBTIY5SQHancEXEmIBGtegREz/sZhsho4SClShUGArYI+3ddiIhjWA8Kee X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR15MB2665 X-Proofpoint-GUID: 1pQ-OdMRlijNBBj2Nm5tBXSRqK6wuYKz X-Proofpoint-ORIG-GUID: 1pQ-OdMRlijNBBj2Nm5tBXSRqK6wuYKz X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-14_10,2022-06-13_01,2022-02-23_01 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Add section mappings for u(ret)probe.s programs. Acked-by: Andrii Nakryiko Signed-off-by: Delyan Kratunov --- tools/lib/bpf/libbpf.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index d989b0a17a89..49e359cd34df 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -9177,8 +9177,10 @@ static const struct bpf_sec_def section_defs[] = { SEC_DEF("sk_reuseport", SK_REUSEPORT, BPF_SK_REUSEPORT_SELECT, SEC_ATTACHABLE | SEC_SLOPPY_PFX), SEC_DEF("kprobe+", KPROBE, 0, SEC_NONE, attach_kprobe), SEC_DEF("uprobe+", KPROBE, 0, SEC_NONE, attach_uprobe), + SEC_DEF("uprobe.s+", KPROBE, 0, SEC_SLEEPABLE, attach_uprobe), SEC_DEF("kretprobe+", KPROBE, 0, SEC_NONE, attach_kprobe), SEC_DEF("uretprobe+", KPROBE, 0, SEC_NONE, attach_uprobe), + SEC_DEF("uretprobe.s+", KPROBE, 0, SEC_SLEEPABLE, attach_uprobe), SEC_DEF("kprobe.multi+", KPROBE, BPF_TRACE_KPROBE_MULTI, SEC_NONE, attach_kprobe_multi), SEC_DEF("kretprobe.multi+", KPROBE, BPF_TRACE_KPROBE_MULTI, SEC_NONE, attach_kprobe_multi), SEC_DEF("usdt+", KPROBE, 0, SEC_NONE, attach_usdt), @@ -11571,7 +11573,8 @@ static int attach_uprobe(const struct bpf_program *prog, long cookie, struct bpf break; case 3: case 4: - opts.retprobe = strcmp(probe_type, "uretprobe") == 0; + opts.retprobe = strcmp(probe_type, "uretprobe") == 0 || + strcmp(probe_type, "uretprobe.s") == 0; if (opts.retprobe && offset != 0) { pr_warn("prog '%s': uretprobes do not support offset specification\n", prog->name); From patchwork Tue Jun 14 23:10:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Delyan Kratunov X-Patchwork-Id: 12881692 X-Patchwork-Delegate: bpf@iogearbox.net 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 26859C433EF for ; Tue, 14 Jun 2022 23:10:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240987AbiFNXKw (ORCPT ); Tue, 14 Jun 2022 19:10:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229572AbiFNXKv (ORCPT ); Tue, 14 Jun 2022 19:10:51 -0400 Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1993152E61 for ; Tue, 14 Jun 2022 16:10:48 -0700 (PDT) Received: from pps.filterd (m0148460.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25EMd1rX002772 for ; Tue, 14 Jun 2022 16:10:47 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=facebook; bh=cB8sizYRRXgjN+ikxvaI+bHUBq5x93jbXv0psJ5INXE=; b=RCo3o68uz3rq/scmdAhGN/DeTC/f05HSSdCv9awJQUbkrUV8N402/A8hjM7Bkh1oGsmX dP+L8AhPFo9T+BVUQCQLM8h6cwdcKNXnIO+mzcupnbpKwQWpmJbdoD+8yQCtGFAjFZkD vekYgX5hfGwBhS0TUTHblKe4WkUA7oGouw8= Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2173.outbound.protection.outlook.com [104.47.59.173]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3gp8aw1uet-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 14 Jun 2022 16:10:47 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cyi8aCMCYLb3OqO79lHmEcojK2PsJ9JCZsozLIAlMGnlkDJJEfwTB76T9rl2vrKfyVW3DwbBp57zFDBUJi1Zn/MrCP6nlya5GjjTcCk6aeHHRT2IoskP1rtxG/4UvdJASPpxNSRfDn+C6Ycx00mi/pEpNgadhEF8s/y+CIKQA+zOf3MfjXtGcMIGjZdYQ/bIZl97jgPu10PEQBVcU4xepEs/LfEYWrXzdjr6EbJ0Y1+sN0mk1rd+4MpayEBu2Wjeo69y7wl9GLYH5JkyrejS0kWXVzIjNULBsgHWMCf01oKHu3qJ4Jd/j+Zs5AZsAtaGfakKFdgkQ0Gde/CmvF6mQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=cB8sizYRRXgjN+ikxvaI+bHUBq5x93jbXv0psJ5INXE=; b=UPEoU6d5VdSpRPqbVWqEbUAQiGtPfAichowqOsH50OuVcALgC6cwS0iKWUw7gCBy6MMk4KBDh2tsY72T1YiLN0kCQS2G7ECAGxyZj1znSAMnOJRTFHHeOt+PTOdu4hez7zjHHvRbcqbt6AO5KO/FHTKTlxrgHY+Im18ABWC3thM0zvs/nv4Y//CXLEldNC4lhmOfcDMnsqT8uQbj5F5QgCyshzq9P184zS2eBEKYrSs9IDGt3WBzIhrS46VtA0YVRLrJVcEb4VhxbZiiFWlr7qPG6vXLrG26S2L1yjfj79I8c9WAFGyMWdk4MRrSm43B+MxXr6SLkysZS2Xc9PtI0Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=fb.com; dmarc=pass action=none header.from=fb.com; dkim=pass header.d=fb.com; arc=none Received: from SJ0PR15MB5154.namprd15.prod.outlook.com (2603:10b6:a03:423::6) by MW5PR15MB5220.namprd15.prod.outlook.com (2603:10b6:303:1a0::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.20; Tue, 14 Jun 2022 23:10:45 +0000 Received: from SJ0PR15MB5154.namprd15.prod.outlook.com ([fe80::8910:e73d:9868:600b]) by SJ0PR15MB5154.namprd15.prod.outlook.com ([fe80::8910:e73d:9868:600b%9]) with mapi id 15.20.5332.016; Tue, 14 Jun 2022 23:10:44 +0000 From: Delyan Kratunov To: "daniel@iogearbox.net" , "ast@kernel.org" , "andrii@kernel.org" , "bpf@vger.kernel.org" Subject: [PATCH bpf-next v4 5/5] selftests/bpf: add tests for sleepable (uk)probes Thread-Topic: [PATCH bpf-next v4 5/5] selftests/bpf: add tests for sleepable (uk)probes Thread-Index: AQHYgEP54lQ4LSHYi0Wwb6FAljTYOg== Date: Tue, 14 Jun 2022 23:10:44 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: f7667d21-7c15-4338-0d2e-08da4e5b1c39 x-ms-traffictypediagnostic: MW5PR15MB5220:EE_ x-microsoft-antispam-prvs: x-fb-source: Internal x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: wosHdTjTXtIgRySljgUAbSxHbC9xF4jkNR2Ooj2Bi8zJTNX5ACpKYzGpjnKExhOEyvN2aimWkGng797mEwBOWpH2wII1W0i3ieMbk3dzsJXAbtTCnkdIEFFEuT3NrwiGvRdz521gVHw2BYlEcfJMLAqbj1b/PtaUtHYBpe5nlwvTIRKkvUo8VmeRPeTLUvgk+0BoqIgSjgg3FSA2AJTsrwegezn0wb3lInUUqYzMnEqjRan8Fs37c+XvpdTUlo1Ignq6gJ31kLPQGO1GUIl9sFn10tjDytq7WtIycV2zkY+5cOgSpD3hQMIhJYyz7Tw7HrlKU/rncioLt+YZC4O7qk/vpmWodev2V7L8V+qpYAO4GxwWym74UPaEzXv+1AKhX00vct/eMq6d8YjkH6QZHPjbrwtv/qyj98fz8ulfSjVTYnBoAcPmutdojqOOLYXfJBV8+W1GWMVeHg7ADZeK+79nyMT79z7mV3xXo3BegAK8zoFyAYeNcXAXgaNmukkVrW8HmnduoxXL5HoXilPNScBsVtt0a/UI1+vLn8Db67GwWUKBVs26QEwuraapQCl6p+DWIW3E6F0Qar9oQxTsCGBie/6dpcFt8NYeGQVWl9OSwgHix0lpbgBwbyeAs96NnxNlJ2slCXAMJSTZsJ/SoqYKeXRQOXE3UPSQHvqOvXSsqBJHwlZ1OIv8pmZMZBUyhCBc9E32lLQrVrJc9OndTg== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR15MB5154.namprd15.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(4636009)(366004)(186003)(8936002)(5660300002)(122000001)(38100700002)(83380400001)(6506007)(6486002)(36756003)(508600001)(38070700005)(6512007)(71200400001)(66946007)(316002)(66476007)(2616005)(2906002)(64756008)(66446008)(76116006)(8676002)(91956017)(66556008)(86362001)(110136005);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?6SMu0u3ovHWibWU8prOJM2Y?= =?iso-8859-1?q?LKYunbXK+Qlp+2dtL/C+WMjWZfV02KIZZm66/+5+/6aLEVwpenJLzt0W8VtO?= =?iso-8859-1?q?fy3XuH/nj+w9GKjyE/9piipL6Ew7Q0Y7U9FrW8CMl+cHKBC3mxXy7d+OZ7TJ?= =?iso-8859-1?q?USyYloIM4AmCKYouMU9APlrmQhZbTtm0uK8Oln705NlhbmNYx36AIfr6GZ2f?= =?iso-8859-1?q?zmZHZzGe0aTESt8xqmb+XscUfNjMMXIbpyIYVJBl4yUK5BnE8l3hZEmiK+nq?= =?iso-8859-1?q?uNU83yJv7igddXabmy+Sv+eQLi6qt19U6nQnI240Ipg2uTEq2pMXprw/cEpb?= =?iso-8859-1?q?QmWyxqikVnNN3eH6mVKvJOjxzXteY79FM6IiZ+ez8KLyd5g0qUwmON3Nv/Ny?= =?iso-8859-1?q?IiwEuxsnrCKlRzvzY5RFsjZr4rZvadauKf/tzU8Ks+zxnk4bKYw8OJoclDDF?= =?iso-8859-1?q?aMDGTAS2YeTsdKDoe4QKEOx62KR+XtsbZAFoFiuNNYHT9TmAjC9CJjAJHb8a?= =?iso-8859-1?q?Oozl7xGYkRp3+sjdXg0wPL3KpF40yGmgzgEVrnNRRqdimG/800LZnVE4UV1p?= =?iso-8859-1?q?JZ13pu/gGa+LfImbMuPaVEp8k/UjtfPGLSe76ObHsemIzixcxI0sYSJ6dB8w?= =?iso-8859-1?q?aS9SG6n8ZqeGIT6tdPpy5rn+96EFkCkRiZMRU0tUzoNBRcEm4jceHDLiDTJk?= =?iso-8859-1?q?xRCdR1vEd/OtXmNw8KmViUJlesRZWxTGAPyRw9kePsNW4C8CIA/u0UMQsUCo?= =?iso-8859-1?q?jbWZ1qnxG+ZSksLtRik8HffHrjYUi8/EKhlsmKVBJ3gjYu+SPgy9CXt7lvH7?= =?iso-8859-1?q?cxh2KpQqxnllH4ihSN5Oyozc/e4p+wBYQ6IGJUdaUeQSo00GRESS1QWNBNMs?= =?iso-8859-1?q?px/9qW7UUa9mWMBQeZZOmT0x97jlaeYDNl7N0BFsuO2vWbsABJJXOwkBFl6S?= =?iso-8859-1?q?B3kTN9PP8iKLQyqZ2vXo+AkwM5QR9ov6GU59iesiJoezixDlUOowbQc1tPqa?= =?iso-8859-1?q?Phokq0zZMyMDlU4Xw6PuZFt5txMRb8hLDNv/68adDBttaXH0XKpElU+E3dO0?= =?iso-8859-1?q?nyeBSTM34uJv730Q/wbavkMMTfe+BzmLFISZGKKMBPAjK05inCjtot7lRHwW?= =?iso-8859-1?q?RpkPB82SL7g/4RK7jzpZvLpkq5iBS7g8NPc9IUCWL6P+M1bfOo/O3BzVrQZn?= =?iso-8859-1?q?qAt+ZSnBrlxm/gy2FTYU9XY/244768Zh/RddR9Ylh4nnO/NEroyIQNYsignG?= =?iso-8859-1?q?2WhkajOf7SqK62+2DMNp6SJTUiK488vXXqrS2jERUSw7tcB5HR55IverLvtj?= =?iso-8859-1?q?PLHLH63TWhUZ0C0zRniFYxmrkMBoHm+5pVo54JsDeInRQ/2CqOZnK34vOoxT?= =?iso-8859-1?q?D50XcCS5Cdx1oetYTCR524A30s3AVdaq8GkOprn8i0UtzXr0DaKex+B3FyM3?= =?iso-8859-1?q?WMEq1jrhozXZ6ilBEmffjJfRpS/+WhdT94PlR/nJkwtf5u+Za0KroxREJaPk?= =?iso-8859-1?q?oxdDCoPz4PcPxc7sqW9yrNDs4CoMm8YCuwwIiFO+kQpZYVwLpsY2f+xavS70?= =?iso-8859-1?q?DuLZc57a/rTBet6jN0BP3j7shiZScZIXfSbMBKInixdYTPPUGk3lBJ7ftivc?= =?iso-8859-1?q?1rcDWdnQZs5wP2t2pk0/iKanYJg5kfGUTo68hL9tRGNop3Qwwv1CgLi9HoK2?= =?iso-8859-1?q?8kBCXpnAuBh5WIxcD7kmehO7vo3xSIGy7kad0d4Dil3Or7UWznkYM3u7cSAv?= =?iso-8859-1?q?kdRG4D9ulJEsch8sSrjzlegeKeviH/g3vGzNSHAd4Bire51RTxLcoSjqT6YD?= =?iso-8859-1?q?YcAjXlMw+jmt3UVxa64zHl07P9VD8?= MIME-Version: 1.0 X-OriginatorOrg: fb.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: SJ0PR15MB5154.namprd15.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: f7667d21-7c15-4338-0d2e-08da4e5b1c39 X-MS-Exchange-CrossTenant-originalarrivaltime: 14 Jun 2022 23:10:44.8681 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: bBjgE3z0fty1337U+N8R5vvwcUbwMeIZ7KCp5MOO9MBhVIx+jN1TVzIm1apj4IDb X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW5PR15MB5220 X-Proofpoint-GUID: n4I0jkmRS-WEA263CQj94NSPzogmjxe0 X-Proofpoint-ORIG-GUID: n4I0jkmRS-WEA263CQj94NSPzogmjxe0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-14_10,2022-06-13_01,2022-02-23_01 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Add tests that ensure sleepable uprobe programs work correctly. Add tests that ensure sleepable kprobe programs cannot attach. Also add tests that attach both sleepable and non-sleepable uprobe programs to the same location (i.e. same bpf_prog_array). Acked-by: Andrii Nakryiko Signed-off-by: Delyan Kratunov --- .../selftests/bpf/prog_tests/attach_probe.c | 49 ++++++++++++++- .../selftests/bpf/progs/test_attach_probe.c | 60 +++++++++++++++++++ 2 files changed, 108 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/prog_tests/attach_probe.c b/tools/testing/selftests/bpf/prog_tests/attach_probe.c index 08c0601b3e84..0b899d2d8ea7 100644 --- a/tools/testing/selftests/bpf/prog_tests/attach_probe.c +++ b/tools/testing/selftests/bpf/prog_tests/attach_probe.c @@ -17,6 +17,14 @@ static void trigger_func2(void) asm volatile (""); } +/* attach point for byname sleepable uprobe */ +static void trigger_func3(void) +{ + asm volatile (""); +} + +static char test_data[] = "test_data"; + void test_attach_probe(void) { DECLARE_LIBBPF_OPTS(bpf_uprobe_opts, uprobe_opts); @@ -49,9 +57,17 @@ void test_attach_probe(void) if (!ASSERT_GE(ref_ctr_offset, 0, "ref_ctr_offset")) return; - skel = test_attach_probe__open_and_load(); + skel = test_attach_probe__open(); if (!ASSERT_OK_PTR(skel, "skel_open")) return; + + /* sleepable kprobe test case needs flags set before loading */ + if (!ASSERT_OK(bpf_program__set_flags(skel->progs.handle_kprobe_sleepable, + BPF_F_SLEEPABLE), "kprobe_sleepable_flags")) + goto cleanup; + + if (!ASSERT_OK(test_attach_probe__load(skel), "skel_load")) + goto cleanup; if (!ASSERT_OK_PTR(skel->bss, "check_bss")) goto cleanup; @@ -151,6 +167,30 @@ void test_attach_probe(void) if (!ASSERT_OK_PTR(skel->links.handle_uretprobe_byname2, "attach_uretprobe_byname2")) goto cleanup; + /* sleepable kprobes should not attach successfully */ + skel->links.handle_kprobe_sleepable = bpf_program__attach(skel->progs.handle_kprobe_sleepable); + if (!ASSERT_ERR_PTR(skel->links.handle_kprobe_sleepable, "attach_kprobe_sleepable")) + goto cleanup; + + /* test sleepable uprobe and uretprobe variants */ + skel->links.handle_uprobe_byname3_sleepable = bpf_program__attach(skel->progs.handle_uprobe_byname3_sleepable); + if (!ASSERT_OK_PTR(skel->links.handle_uprobe_byname3_sleepable, "attach_uprobe_byname3_sleepable")) + goto cleanup; + + skel->links.handle_uprobe_byname3 = bpf_program__attach(skel->progs.handle_uprobe_byname3); + if (!ASSERT_OK_PTR(skel->links.handle_uprobe_byname3, "attach_uprobe_byname3")) + goto cleanup; + + skel->links.handle_uretprobe_byname3_sleepable = bpf_program__attach(skel->progs.handle_uretprobe_byname3_sleepable); + if (!ASSERT_OK_PTR(skel->links.handle_uretprobe_byname3_sleepable, "attach_uretprobe_byname3_sleepable")) + goto cleanup; + + skel->links.handle_uretprobe_byname3 = bpf_program__attach(skel->progs.handle_uretprobe_byname3); + if (!ASSERT_OK_PTR(skel->links.handle_uretprobe_byname3, "attach_uretprobe_byname3")) + goto cleanup; + + skel->bss->user_ptr = test_data; + /* trigger & validate kprobe && kretprobe */ usleep(1); @@ -164,6 +204,9 @@ void test_attach_probe(void) /* trigger & validate uprobe attached by name */ trigger_func2(); + /* trigger & validate sleepable uprobe attached by name */ + trigger_func3(); + ASSERT_EQ(skel->bss->kprobe_res, 1, "check_kprobe_res"); ASSERT_EQ(skel->bss->kprobe2_res, 11, "check_kprobe_auto_res"); ASSERT_EQ(skel->bss->kretprobe_res, 2, "check_kretprobe_res"); @@ -174,6 +217,10 @@ void test_attach_probe(void) ASSERT_EQ(skel->bss->uretprobe_byname_res, 6, "check_uretprobe_byname_res"); ASSERT_EQ(skel->bss->uprobe_byname2_res, 7, "check_uprobe_byname2_res"); ASSERT_EQ(skel->bss->uretprobe_byname2_res, 8, "check_uretprobe_byname2_res"); + ASSERT_EQ(skel->bss->uprobe_byname3_sleepable_res, 9, "check_uprobe_byname3_sleepable_res"); + ASSERT_EQ(skel->bss->uprobe_byname3_res, 10, "check_uprobe_byname3_res"); + ASSERT_EQ(skel->bss->uretprobe_byname3_sleepable_res, 11, "check_uretprobe_byname3_sleepable_res"); + ASSERT_EQ(skel->bss->uretprobe_byname3_res, 12, "check_uretprobe_byname3_res"); cleanup: test_attach_probe__destroy(skel); diff --git a/tools/testing/selftests/bpf/progs/test_attach_probe.c b/tools/testing/selftests/bpf/progs/test_attach_probe.c index ce9acf4db8d2..f1c88ad368ef 100644 --- a/tools/testing/selftests/bpf/progs/test_attach_probe.c +++ b/tools/testing/selftests/bpf/progs/test_attach_probe.c @@ -5,6 +5,7 @@ #include #include #include +#include #include "bpf_misc.h" int kprobe_res = 0; @@ -17,6 +18,11 @@ int uprobe_byname_res = 0; int uretprobe_byname_res = 0; int uprobe_byname2_res = 0; int uretprobe_byname2_res = 0; +int uprobe_byname3_sleepable_res = 0; +int uprobe_byname3_res = 0; +int uretprobe_byname3_sleepable_res = 0; +int uretprobe_byname3_res = 0; +void *user_ptr = 0; SEC("kprobe") int handle_kprobe(struct pt_regs *ctx) @@ -32,6 +38,17 @@ int BPF_KPROBE(handle_kprobe_auto) return 0; } +/** + * This program will be manually made sleepable on the userspace side + * and should thus be unattachable. + */ +SEC("kprobe/" SYS_PREFIX "sys_nanosleep") +int handle_kprobe_sleepable(struct pt_regs *ctx) +{ + kprobe_res = 2; + return 0; +} + SEC("kretprobe") int handle_kretprobe(struct pt_regs *ctx) { @@ -93,4 +110,47 @@ int handle_uretprobe_byname2(struct pt_regs *ctx) return 0; } +static __always_inline bool verify_sleepable_user_copy(void) +{ + char data[9]; + + bpf_copy_from_user(data, sizeof(data), user_ptr); + return bpf_strncmp(data, sizeof(data), "test_data") == 0; +} + +SEC("uprobe.s//proc/self/exe:trigger_func3") +int handle_uprobe_byname3_sleepable(struct pt_regs *ctx) +{ + if (verify_sleepable_user_copy()) + uprobe_byname3_sleepable_res = 9; + return 0; +} + +/** + * same target as the uprobe.s above to force sleepable and non-sleepable + * programs in the same bpf_prog_array + */ +SEC("uprobe//proc/self/exe:trigger_func3") +int handle_uprobe_byname3(struct pt_regs *ctx) +{ + uprobe_byname3_res = 10; + return 0; +} + +SEC("uretprobe.s//proc/self/exe:trigger_func3") +int handle_uretprobe_byname3_sleepable(struct pt_regs *ctx) +{ + if (verify_sleepable_user_copy()) + uretprobe_byname3_sleepable_res = 11; + return 0; +} + +SEC("uretprobe//proc/self/exe:trigger_func3") +int handle_uretprobe_byname3(struct pt_regs *ctx) +{ + uretprobe_byname3_res = 12; + return 0; +} + + char _license[] SEC("license") = "GPL";