From patchwork Thu Apr 28 16:53:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Delyan Kratunov X-Patchwork-Id: 12831055 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 71207C433F5 for ; Thu, 28 Apr 2022 16:54:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234883AbiD1Q5T (ORCPT ); Thu, 28 Apr 2022 12:57:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231442AbiD1Q5S (ORCPT ); Thu, 28 Apr 2022 12:57:18 -0400 Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1DBE9D04F for ; Thu, 28 Apr 2022 09:54:03 -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 23SG7bkd026710 for ; Thu, 28 Apr 2022 09:54:02 -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=4zW1P/WA9Uq+rWw89+ehVR/8ZdHNU3/hpyQx5RYl5Mg=; b=it3KouGCvD4gxxSaLCxtx6PR3y19PZd5rx4Fq1fdqoe0r16oPVNvTTxdXTYg4QZbI5Mj REooXBJ2XJAPQmac494ZeMb+MkAPeucJ6y+xhvBdJv4EUYWvXM/HH9mvPyLUNj/wRTgQ 6iHg7EBJF11UFLYK/MEAhSjLq9Yx8QNxHXU= Received: from nam04-mw2-obe.outbound.protection.outlook.com (mail-mw2nam08lp2173.outbound.protection.outlook.com [104.47.73.173]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3fqm5r40r4-7 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 28 Apr 2022 09:54:02 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mk8SPILwv/9hDyXLg/fPl/e6wdoEVl57+bNBU/+6BE6eiX+o+MQgj0/mabky+PplMv+S8KiDUaeHbMyPlJ6VABD1HKb+eBV9LRgbMe8lQsSfMmGbg1ezoxK7PpOYbBW6g/L5XZsjesKF217Se0pFCgWKeCKY5Rg+5oYXZDv01cIlsHX6BT5m8jCwRGSJrc8RfhApZjRU1d+eEO/B5Qf1sf6pTuLx+hcu8G9Ybg3fkdxgjLgmog19OC3tPrRc4ROLeU3daAGc7g4+hxsAue5efKsQR4qRqbUKRR6JgkHZy1vWnUtZQK2Q29xlwf1YsophZGpnWDyPyMIqE/tbE5kqkg== 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=4zW1P/WA9Uq+rWw89+ehVR/8ZdHNU3/hpyQx5RYl5Mg=; b=ejNuN+lwBf6oqJTHCMmZ6TnyFE4LrKnLWcS+5vAQv/3fHZ/x1JxpsGi4Hp4EG2oc24b0tK4cAR96QyoqSFuRkUIro5aRy0EH9wRh0/Uo7bolyWuBEdTQKaxOo3YI9L6POQtA4qet8+peUr+/AMD+JjWX6kkheaKuQT4UU1YsZug6XVelrN134QeS/Xt5DO2D+aLYl4TcXEPxVGFZ1E4pUCQHxOAV3ewdtitvok0x1fcJYKLNz6gQbxYR9r2KkQTpI3Q9Gal/nNHe1+tu566iutbNxQLOXwfw9soVD6EW5MEL7Bzkk+flDhUqdbf5HTQhlbHT/3n3xmAaTfYxb9nz9A== 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 SJ0PR15MB4615.namprd15.prod.outlook.com (2603:10b6:a03:37c::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.13; Thu, 28 Apr 2022 16:53:59 +0000 Received: from SJ0PR15MB5154.namprd15.prod.outlook.com ([fe80::b5e0:1df4:e09d:6b5b]) by SJ0PR15MB5154.namprd15.prod.outlook.com ([fe80::b5e0:1df4:e09d:6b5b%4]) with mapi id 15.20.5186.020; Thu, 28 Apr 2022 16:53:59 +0000 From: Delyan Kratunov To: "daniel@iogearbox.net" , "ast@kernel.org" , "andrii@kernel.org" , "bpf@vger.kernel.org" Subject: [PATCH bpf-next 1/5] bpf: move bpf_prog to bpf.h Thread-Topic: [PATCH bpf-next 1/5] bpf: move bpf_prog to bpf.h Thread-Index: AQHYWyCOlNxLOBniyUiRir4MD0vVGw== Date: Thu, 28 Apr 2022 16:53:59 +0000 Message-ID: <39268f145f9cec5333ddc301448740d96467c9c9.1651103126.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: 044fdc1c-7c01-425c-ce9a-08da2937b0b2 x-ms-traffictypediagnostic: SJ0PR15MB4615: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: hMtXGalki48mHD2lS9vXNuSVttBOVbZL7TgN/NwmRK+KbTeh2RJJqcoR9hl7Z0+SqDzl6BfR4Jf0dkmZr7O1UgDwK8zUzXl2R1g3flAzlnKSGQzdJdPtx/hkUz/g3Wdb8xqhqh2+YUU3ddO40ZBasryhZJ+GCdPxnv82q2K0GusAWiZivc9udVamORLIm0NQknZ4H/3TXXThtPNUBNWx3+w5GM7ym7pdcM81i5mzb7Tn/QJIL5PuxfsNSiZ/y+AGM7ybblW/fF0gNOVk+EGrxY9C1NRXBbtxaERRSGyJQqVKu5odnXd8Nqqh5VFzfQqYsnEulBrDQ7yT32ZprfaxYs1hZz41twORlpWnifYtsonMwgUfBzCfuLvCo/SK+brfmD58h0K2JrqbFHVlsQhlwsJBX2SEN436zuDm837RxdXDeTIkLuMQVxmUE6OIg13yux8OwnKE82y/kA6nCXNSfA94q/b24vUzhEsI06sWfq2l+nGq6ffFpYIpZXgiQonlONS+7w/5OesS3Iqf3yZ7rf5aSfeaczVaRzimDbYjQY9+ZrJcZvJaZdTlFinj/G4e5Rt/4v8Dt1ICugjWoessG03xCh/sHwLdfDFBvU3r1+rGKjiMtwLNXmAH7IFIeBbU6tlkgo3vORq+xf51oBrgkS9WYOiUnahZ+51HNxdgOFan4ctpgYJWqYpwTY7/Muewn4jiQsf35W0Bru2T3aUB4g== 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:(13230001)(366004)(38100700002)(2906002)(36756003)(38070700005)(86362001)(316002)(122000001)(5660300002)(66946007)(8936002)(6506007)(66556008)(76116006)(8676002)(64756008)(66446008)(83380400001)(66476007)(6486002)(71200400001)(186003)(26005)(6512007)(110136005)(2616005)(508600001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?d+xaOnqKk2kGu2YclseVCGl?= =?iso-8859-1?q?i3H+QHgKPV8TCpsA4JKZ6s8UYvOwrgb4/zc8+6xA6qIXvmW7ITvfztEbarm/?= =?iso-8859-1?q?iTt14zLFxBbeQyx+/xH0LyTy/dE859w4y4rUb5gbZvjTenCPFmeLbZ9FzrOn?= =?iso-8859-1?q?Fbj7y7E5l3bya+jdWvhGLX+2gSKWmp7VTRHIUDzEZXwG4gEBQLsqz2UXHxsi?= =?iso-8859-1?q?nf7E5P710HF+Jz+xInObiQbnV4G5+p6lt//2h1JxZSpCcyhuM75CpAFwIRdr?= =?iso-8859-1?q?UobZtRb/R9ux0mExD+PHvycr5QZOr+o4sAcLprAh9AEJzLPXcBodz361c63m?= =?iso-8859-1?q?OboX0tZ1Ufii90H10MR8HpWbGOdgpqju+Mz2OzDNPcJ02A+C6aBsgRST8mfG?= =?iso-8859-1?q?3+pGhht68nsI1shs/PunMvfDmCWeV04Xk8A1I5e4IR8vPrIffdB15H1XTEor?= =?iso-8859-1?q?KehWXl9boer/qLn2eshYgdYBl8Po54vpIWzYS2xbrwtXGLRBNq3cWM9olJhX?= =?iso-8859-1?q?cmxC9+jM1weqxA+D0EuP+0dXF5kVgwelqt0of0wW+gz7htXHmd72xeDjLp0I?= =?iso-8859-1?q?JHgoQKJrtHyNvVpGVyX4zXH8vfNGSoiqq3ExVMJ7cLbcCE1jTZfwq6KdVe6y?= =?iso-8859-1?q?cVK998h6jrJexDXh9ITNweFo2Ug7AyJJud74l49NRtnitJavE7fjwQ0hRCAn?= =?iso-8859-1?q?+Q8K4BDLDgnNb0jiUIuxkFRH9qnmk6cZsZeEFajyoQOFJRe80Ghse6YNIv6q?= =?iso-8859-1?q?pSaegwRxiz6n04AilWXYOduzmTu77wWhvMQaH6FdGHe88UyrAzfnS29oZ1UM?= =?iso-8859-1?q?2H3tjbmfFkkfl5v72stfWmKDUHeDZpbQXIsAMFeSHusEpOnCGHSqg56rLLyU?= =?iso-8859-1?q?qsTtLrs86Nx8sSbpkg26iooTQVxukj94v3aVSRFUXVjq+ympw0fi4jIA5QLM?= =?iso-8859-1?q?Hi+gS2/bnxk8+YaByaPjv0VfFZS4T7at8gVT+7uO8i+frWYnR3EPfYlx65Au?= =?iso-8859-1?q?Q0YbSjL7Zklw58TaXd53wmEwRDMTbiLfEC2yhuqLVD0PeEZZ0a0H3jSyCNCz?= =?iso-8859-1?q?/eOZtvvhnc07YstB3ywPXelY5orJ27mlQGA8ZJcF4u2vrapxQOEobA9aM2Tp?= =?iso-8859-1?q?qe6BWgKn/zDCfZ4pWF52tqDGHp6sHDvVFpV6h/fR5gsWq/OAo9U84FTCWeIE?= =?iso-8859-1?q?N0v0cdMk0OuUCeLD4NYU65X2QkLU9exwSYAua6/HD3kK0+fdJkwMc6C0QTv+?= =?iso-8859-1?q?2ZVGO4y9Tx4+hEkjl/S4U/P0btOi0BzTNdCAorl1KGO2jqxuXBaRYCSVbrhd?= =?iso-8859-1?q?SY4SyYnTB8BUJDfjpng5GVS90n4YkbjN6wZPn8K/R3PEGIjfv+IzFMzT9ZBQ?= =?iso-8859-1?q?movkHy5ivBm/lEuuuJgP4jC/oY+aIr2wLPM5Fc1g5KRIRZuvswjdw994ckqm?= =?iso-8859-1?q?UnB3+fBkuhAyu5/NdxdMx4G/HUuG1cpcpDXg4rM5cZSQfigB8UDy7guu1vN+?= =?iso-8859-1?q?OOO9/A9o+DpJtjgNtLrx/9B8uSM5fx4hw4zOclnmvIy5j1jj2FB00GxtOGne?= =?iso-8859-1?q?bGu9qJkJTR36UyX3PqzFZr9ezmByza3Pyrrsw8kiEBNNPLbIx8oWptiolTVd?= =?iso-8859-1?q?5DIkiFq/Y8jVfCdwgI33Pjd77h8QV4G46g+DT8qshQk4ytZ/2fausUXZ+E0S?= =?iso-8859-1?q?HYIOHl0yJmO1X7CFexpHmAs0pgxyyyEYZqpkKeM61wC+fivDA7C+XuIrpZ50?= =?iso-8859-1?q?JVOW6mZYFh4FPY8WFpJE9cHxFarYvViMcvwLoHZwPfz4GGQ=3D=3D?= 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: 044fdc1c-7c01-425c-ce9a-08da2937b0b2 X-MS-Exchange-CrossTenant-originalarrivaltime: 28 Apr 2022 16:53:59.0638 (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: WLIct9lGc+DJ2NP3N0gHwZWVrPyBCyDvIfrDUDw2Sl3ro5j2VgQznyymt5+cY1RV X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR15MB4615 X-Proofpoint-GUID: GUhnEBh6_v86GEaW4Hh_mwPCM_aE7Viw X-Proofpoint-ORIG-GUID: GUhnEBh6_v86GEaW4Hh_mwPCM_aE7Viw X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-28_02,2022-04-28_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, we need bpf_prog 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(-) -- 2.35.1 diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 7bf441563ffc..7d7f4806f5fb 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 struct bpf_verifier_env; @@ -1019,6 +1021,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 Thu Apr 28 16:54:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Delyan Kratunov X-Patchwork-Id: 12831056 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 1C56DC433FE for ; Thu, 28 Apr 2022 16:54:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235188AbiD1Q5V (ORCPT ); Thu, 28 Apr 2022 12:57:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231442AbiD1Q5U (ORCPT ); Thu, 28 Apr 2022 12:57:20 -0400 Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C816EAAB6D for ; Thu, 28 Apr 2022 09:54:04 -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 23SG7bkf026710 for ; Thu, 28 Apr 2022 09:54:04 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=facebook; bh=ieT8Tf+QwreVVBIPB3fn8rGvo6gr38a6dDeW9euEhFw=; b=mZVwZ5ImfbFT8qU2hZFflt6ZYilb4wHMgLGK15j9sHgyjZ+6bXd8ygYvyRh8z/t9n3J1 OHj3BM4UK0hiWGUjZfjpcAN2RaT4Np+DExaXmB04cNXY0FfuSjGp+6gPx82RPMqlMx87 5PWdIzwfHAE3n7S6S4b2cxlpeuZmqut20Wk= Received: from nam04-mw2-obe.outbound.protection.outlook.com (mail-mw2nam08lp2173.outbound.protection.outlook.com [104.47.73.173]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3fqm5r40r4-9 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 28 Apr 2022 09:54:03 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=L64wkK2lRqokQaXT0zE6vXJN7JXA++M8SEi+Z9GMywi2JCdacIZCtN5FCsh6rV9zP8YZdzBFqW8X8JWRrngIHpdVpUKpZoVWT/Jrj+9gAN3KyqJ0ZOjhB+DdBE6iOneSX3awFgqSs9/WKEWyTOixc7gKDRC8y4P4eZnaVQa/a7jV1Ba/Ta+m4O9dz4ogILQcQ5SkDYa07rE4SzFPWJQMS8zsZ5GCQ+BorLIuo4B8uNbV8P/SCtU7SgWVB1SIMpI3S4TXGPw6Ykskav8bEvI/ToENtb5PcT2zdHj9WDURKC79NpzLbtD/brYgDOT+cpyi7ccDEMw5mVKSS8CGgeMqCw== 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=ieT8Tf+QwreVVBIPB3fn8rGvo6gr38a6dDeW9euEhFw=; b=bgoxhbaqDPOsGeVUupEQ+9qIx7fXp7skPCoi3G3oPDtgE+SIBhQOLwTOsSfPoTIFhYzaFT1vaS67e22vTqfb7abaqDzi/lfsn2Gp2+/PVs8jJPlt9t4WqggYzMb2Eu6ghJCCz7xwG3YxQ2KfbHpY3cpZkBsye1sRM4uucGChps4Gwhl5FXQPO2TUo2QVBgtWjQy9tC0kG7ccB5l2fyfpfzPYjgChDOtGcuFCp/OS3kCgJNGBcXkWhRFthwUd0/EjMKYnijZ9x5S9Uyzv7rglKCtCbKuiInIZk1+yVnzmBqoy65l9ODLt8eF6ZLS6gyqUq2zK1B01krd5/3E7uA5vjg== 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 SJ0PR15MB4615.namprd15.prod.outlook.com (2603:10b6:a03:37c::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.13; Thu, 28 Apr 2022 16:54:00 +0000 Received: from SJ0PR15MB5154.namprd15.prod.outlook.com ([fe80::b5e0:1df4:e09d:6b5b]) by SJ0PR15MB5154.namprd15.prod.outlook.com ([fe80::b5e0:1df4:e09d:6b5b%4]) with mapi id 15.20.5186.020; Thu, 28 Apr 2022 16:54:00 +0000 From: Delyan Kratunov To: "daniel@iogearbox.net" , "ast@kernel.org" , "andrii@kernel.org" , "bpf@vger.kernel.org" CC: "paulmck@kernel.org" Subject: [PATCH bpf-next 2/5] bpf: implement sleepable uprobes by chaining tasks and normal rcu Thread-Topic: [PATCH bpf-next 2/5] bpf: implement sleepable uprobes by chaining tasks and normal rcu Thread-Index: AQHYWyCObZ0QBOT6hkONP5DC6DKxDw== Date: Thu, 28 Apr 2022 16:54:00 +0000 Message-ID: <972caeb1e9338721bb719b118e0e40705f860f50.1651103126.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: fe1f5f15-d701-4064-1984-08da2937b155 x-ms-traffictypediagnostic: SJ0PR15MB4615: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: HSE3J3b8D8DJjpsEuVPWJmE9rYdh3WCXCGau1REZtkLcWavax7hsShifsmJtzTxjK3hqseqvTWNCTNVjR9YXXbA/Ialn0bZs8ccDsYVW6cdHrk7x9M3dtfTRugxZ6dMD4WzyAnWIvWhfF7UoNPrkrMwigCTQI7SNaf92fSK64n9WIf7VSJWrI+O+CikbrbiEOLbf0UvY1dHm9QpagdAuCIQURSYKkVw9IFUkcpzmFx20OGbmzgtkWQGb5Akk9bpF7AChfrs5AKZTJqYbuXAWHPKaWzgoGd6ueLzkGKIzDUi9vZtR9Adtxt6Z/jgUAjcIxp4wfw7v0vAU+Gsj3+H8SZPhD+XrlcbBjfaQz4EMfkGgaF6sP33C0+L6odLjR+N1+x70/Mt2dtvxMZu3JceHc+jmDGnewWz4ONbtHIJaODMYOJKmrVs8X/yO9IdiCJdfsZVh7MO7by0fuFhkSXSySDHUfvA9zfEsgrkVMRkle7FeBcVl0yg8+2I1CIwS+45KsZkKGtifSKGO6CQTNcu5Pfqhu1/gDmq9eOmPMHWb5PzuGkBkE/3YpZV6khcqfXuV+1lCk4dRiDxn0x0hdJ/svfrdnFbtgaqKW59qfuhkBf7E5cldJ3JzfNsRMZj2HKBgP8x8jXAh7Ib/XuZW+wMdNGF0Tog75juSApWZwqkRNuw5wQMH8i7g0uiYNfnuDG25Qf9Y+gxnByOz8fyzURBEZw== 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:(13230001)(366004)(38100700002)(2906002)(36756003)(38070700005)(86362001)(316002)(122000001)(5660300002)(66946007)(4326008)(8936002)(6506007)(66556008)(76116006)(8676002)(64756008)(66446008)(83380400001)(66476007)(6486002)(71200400001)(186003)(26005)(6512007)(110136005)(2616005)(508600001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?FPgY/HdsxopKW8EHzeRI82t?= =?iso-8859-1?q?a5HgZQeBe3u5yLKQwcFLC0kYOLKA7akO3N1cQwNmtaWWISIeaWldiXDqi2CF?= =?iso-8859-1?q?B4JDjIlvMyk4N42a9cxfWtlwuX3PnMTNWJ4wim+5H3WU0/oP4dYZwyYaMDe/?= =?iso-8859-1?q?BxG1KpCkcEoRupkfMOdAa/vSh8okhDykbdIMnTO78sGBMv7DNOGFM4US45bp?= =?iso-8859-1?q?dSuRnQ5xpgLta64UrgEl7WkWaE0giQVKXISkCnERBE/Drlzmq/KFD851LtVr?= =?iso-8859-1?q?KXkFuMEzWa9y72fXWvjq3aqEjiI8uvypAjwBHRGwDnP3m4Gvou4BtAU4FFNh?= =?iso-8859-1?q?0TofMXt+rztmnPmP8rSu1V6KZrhoHvw1z6efY9s04eDu2JuRu/a7hQ9lWzFU?= =?iso-8859-1?q?JqT5VGNTni88WYoouA2jgBFbHCx4EvcNy0CBvZ//lekTGuw9l1LBWTNjNsEV?= =?iso-8859-1?q?u3N6syQy9E0TMeKUefK6w2QARqvOUOtEcifZ1oja5S1+5L9u+tYsPTudzfuZ?= =?iso-8859-1?q?NNxotlGJe7Pm8FpfkBEub9+HKR+TJut5v6gWGTyD6vV0kpRiUrmW93d/zUZL?= =?iso-8859-1?q?NURjRr9kndrKtURGw0SOj+Fe/DaYhyGgl3+M7goi9lu7hFcrsCXy8Sno8tfK?= =?iso-8859-1?q?H6Bu7rJtnRJD1A5dabZ3pq66MPlQ/b0FZcwg8ey/DwfiFXNF5uV4+WnHW6qZ?= =?iso-8859-1?q?ARcGy5ZsOLVRzCmqpEHIz7U/ARygwX1miAfH/YF2JgRiWWN9QEs9KC3Q3K1V?= =?iso-8859-1?q?m2y0wXA2ung/YJBGmmZMRD75Usaxo5LiLyK67FF4tavic0ry/dZD24mrsDPJ?= =?iso-8859-1?q?hJgqpv8xpd8zLG/6ObMABXdwsBQW4sn/ImqOfCgi6jvtvfC9GaPQtPWVwt8M?= =?iso-8859-1?q?AdhpPtMMLtAmO94cl1lHi0N/w9vLg2kNH23F+dcAGu2ijfBixprYJUAh618n?= =?iso-8859-1?q?zaMrwjoMEMJaHFA4HUl4MtWsc10yJtDvLVi1JPJ3cjTbflaIBA39LL34BHtB?= =?iso-8859-1?q?RoIv9mIwXNP+tsaGfzCjNzYOMsvDUehJpKvui+WejCFZZcw0WQEYsyshvqaK?= =?iso-8859-1?q?um9395+Zbf6QlaQnaTMHEiEwtJd3IMNUjrNGyH6BelukEmW+qQ9nmi4GmJ2Y?= =?iso-8859-1?q?eKD3i1PCzl2RPK+OvJdgwqecGZU4pPuNo/qaMTTuaLrqouH4Utz+ZvmopGBm?= =?iso-8859-1?q?7I6PrYG3+8YzYN+VcKPiCgKX8Oa6v69GqbJelE4ldiet6HulS9/uwhJDPZMt?= =?iso-8859-1?q?OpDtYPiqODyEazaJ+pdvsGWFkko2M/leLz7KdlK/fm7apdwQFY3VPgoPQ84R?= =?iso-8859-1?q?XsA2XRnGGh6oO4vlQmu85Nk5ceKunGYjhYP+BqaH8L57Rb9qWplm2b7aJUHf?= =?iso-8859-1?q?DwLfpgfHN3Q85diQHs+dsaB1IZ+rYf3Kaoz0bKOg2G74chfDL9Fh1tGgSMzT?= =?iso-8859-1?q?7CyUguzVb7Lhk1gIQlqJbvISCM7aA+3XKX5HRokcywPRpT2iHSDO6pBdKUft?= =?iso-8859-1?q?dCbek+PfUipoixd0SB+IATe+kuUdoUCULHtXByE0HsOH2WJflJU4f9q71bVC?= =?iso-8859-1?q?RLUzXG6IgVUeSYWRph8LpfEH+AOw1pi+ywXe/hGeYiiS7FV0m7XaUpCsKmA/?= =?iso-8859-1?q?BTwg5zBgYaoh6xRK9m4WHck+E+QNGT7W4hEIaVbCEe6BXMQwyekBJyKdJB7x?= =?iso-8859-1?q?1xAiWCqRAyW1T5rCwkvoxSlqoTkCesmPZI1eXZk00c6mG1uqsSkZs7h36tH8?= =?iso-8859-1?q?oZ1icW4tsUKxdk5LHJ932TXMc5WFGnDc4P2BZDJiaYBGFwA=3D=3D?= 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: fe1f5f15-d701-4064-1984-08da2937b155 X-MS-Exchange-CrossTenant-originalarrivaltime: 28 Apr 2022 16:54:00.0806 (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: MdAvHytQjlmWaLE6sWSfSseHK2Tjkqhj5dIOM3OAxDGDLq8tt/mLP1TBgXQBV8+C X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR15MB4615 X-Proofpoint-GUID: gjy3S3n84HzbkhcuUtl6VaJZ_t39Q5dk X-Proofpoint-ORIG-GUID: gjy3S3n84HzbkhcuUtl6VaJZ_t39Q5dk X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-28_02,2022-04-28_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 user 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 and runs with disabled preemption. In order for uprobe bpf programs to become actually sleepable, we need it to be protected by the tasks_trace rcu flavor instead (and kfree() called after a corresponding grace period). One way to achieve this is by tracking an array-has-contained-sleepable-prog flag in bpf_prog_array and switching rcu flavors based on it. However, this is deemed somewhat unwieldly and the rcu flavor transition would be hard to reason about. Instead, based on Alexei's proposal, we change the free path for bpf_prog_array to chain 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 we take the tasks_trace latency unconditionally but that's deemed acceptable under expected workloads. The other interesting implication is wrt non-sleepable uprobe programs. Because they need access to dynamically sized rcu-protected maps, we conditionally disable preemption and take an rcu read section around them, in addition to the overarching tasks_trace section. Signed-off-by: Delyan Kratunov --- include/linux/bpf.h | 60 ++++++++++++++++++++++++++++++++++++ include/linux/trace_events.h | 1 + kernel/bpf/core.c | 10 +++++- kernel/trace/bpf_trace.c | 23 ++++++++++++++ kernel/trace/trace_uprobe.c | 4 +-- 5 files changed, 94 insertions(+), 4 deletions(-) -- 2.35.1 diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 7d7f4806f5fb..d8692d7176ce 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -25,6 +25,7 @@ #include #include #include +#include struct bpf_verifier_env; struct bpf_verifier_log; @@ -1379,6 +1380,65 @@ 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 trace RCU flavor read section to protect the bpf_prog_array overall. + * Because there are users of bpf_prog_array that only use the normal + * rcu flavor, to avoid tracking a used-for-sleepable-programs bit in the + * array, we chain call_rcu_tasks_trace and kfree_rcu on the free path. + * This is suboptimal if the array is never used for sleepable programs + * but not a cause of concern under expected workloads. + * + * In the case where 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_LOCKDEP_WARN(!rcu_read_lock_held(), "shouldn't be holding rcu lock"); + + migrate_disable(); + rcu_read_lock_trace(); + + array = rcu_dereference(array_rcu); + 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) { + preempt_disable(); + rcu_read_lock(); + } + + run_ctx.bpf_cookie = item->bpf_cookie; + ret &= run_prog(prog, ctx); + item++; + + if (!prog->aux->sleepable) { + rcu_read_unlock(); + preempt_enable(); + } + } + bpf_reset_run_ctx(old_run_ctx); +out: + rcu_read_unlock_trace(); + migrate_enable(); + return ret; +} + #ifdef CONFIG_BPF_SYSCALL DECLARE_PER_CPU(int, bpf_prog_active); extern struct mutex bpf_stats_enabled_mutex; diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h index e6e95a9f07a5..d45889f1210d 100644 --- a/include/linux/trace_events.h +++ b/include/linux/trace_events.h @@ -736,6 +736,7 @@ trace_trigger_soft_disabled(struct trace_event_file *file) #ifdef CONFIG_BPF_EVENTS unsigned int trace_call_bpf(struct trace_event_call *call, void *ctx); +unsigned int uprobe_call_bpf(struct trace_event_call *call, void *ctx); int perf_event_attach_bpf_prog(struct perf_event *event, struct bpf_prog *prog, u64 bpf_cookie); void perf_event_detach_bpf_prog(struct perf_event *event); int perf_event_query_prog_array(struct perf_event *event, void __user *info); diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index 13e9dbeeedf3..a4c301ef2ba1 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -2261,11 +2261,19 @@ struct bpf_prog_array *bpf_prog_array_alloc(u32 prog_cnt, gfp_t flags) return &bpf_empty_prog_array.hdr; } +static void __bpf_prog_array_free_rcu(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(struct bpf_prog_array *progs) { if (!progs || progs == &bpf_empty_prog_array.hdr) return; - kfree_rcu(progs, rcu); + call_rcu_tasks_trace(&progs->rcu, __bpf_prog_array_free_rcu); } int bpf_prog_array_length(struct bpf_prog_array *array) diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index f15b826f9899..6a2291d4b5a0 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -140,6 +140,29 @@ unsigned int trace_call_bpf(struct trace_event_call *call, void *ctx) return ret; } +unsigned int uprobe_call_bpf(struct trace_event_call *call, void *ctx) +{ + unsigned int ret; + + /* + * Instead of moving rcu_read_lock/rcu_dereference/rcu_read_unlock + * to all call sites, we did a bpf_prog_array_valid() there to check + * whether call->prog_array is empty or not, which is + * a heuristic to speed up execution. + * + * If bpf_prog_array_valid() fetched prog_array was + * non-NULL, we go into uprobe_call_bpf() and do the actual + * proper rcu_dereference() under RCU trace lock. + * If it turns out that prog_array is NULL then, we bail out. + * For the opposite, if the bpf_prog_array_valid() fetched pointer + * was NULL, you'll skip the prog_array with the risk of missing + * out of events when it was updated in between this and the + * rcu_dereference() which is accepted risk. + */ + ret = bpf_prog_run_array_sleepable(call->prog_array, ctx, bpf_prog_run); + return ret; +} + #ifdef CONFIG_BPF_KPROBE_OVERRIDE BPF_CALL_2(bpf_override_return, struct pt_regs *, regs, unsigned long, rc) { diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c index 9711589273cd..3eb48897d15b 100644 --- a/kernel/trace/trace_uprobe.c +++ b/kernel/trace/trace_uprobe.c @@ -1346,9 +1346,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 = uprobe_call_bpf(call, regs); if (!ret) return; } From patchwork Thu Apr 28 16:54:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Delyan Kratunov X-Patchwork-Id: 12831057 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 B46B8C433EF for ; Thu, 28 Apr 2022 16:54:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231442AbiD1Q5V (ORCPT ); Thu, 28 Apr 2022 12:57:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235092AbiD1Q5V (ORCPT ); Thu, 28 Apr 2022 12:57:21 -0400 Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F30DAAB6D for ; Thu, 28 Apr 2022 09:54:06 -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 23SG7fRI026890 for ; Thu, 28 Apr 2022 09:54:05 -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=AL1HM9U6MG4YVTMT475SBuv5DdeCESkypH4OVb/bYEs=; b=eYO7KlZLDeimj9yFk0PxCfWj8Pb24bGpz9IchJvrh0kndD5e1YSu/r26ZGZq9gZ16snA x4SOR0gB+SwVBBARrcYDEcfypBUacTh054cfCRlFkhzmkcPEgwasq9CQm0lAZJxV+euG 9zbT22QF9Uifx9ht7GqzT3MvBeT4VJi9kPA= Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2108.outbound.protection.outlook.com [104.47.70.108]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3fqm5r40rn-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 28 Apr 2022 09:54:05 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jChH7dHQTNfmLHJFLVFj+kKxpNgAPRFKWBZsKcOolQdeQPki5nKyor9BlN8mkj8n8cU6EwNRP5dK6pRvuLFUHRF8q/yV0eDHxnXQFZB9Lw8L5BEolrue9UYFRFbS0MB8NH8Y6WucntFc5nQxnPZAWlWakZtf/P2SbVAnN3qWy00KoVLKGycGQLFsbavyIMktd5aWX+6ipN4aFd8dgLR7l6bbPv1c61f8dAOtfImIeGty10BLhOmI/D6IU1xZ6X5UaQL1bCcHZopLw2D2kyBgaF5nGb3WVm56ajnyl/tWGE5EsJLX+XcW0xmjiHcg2aunGeY4X7k2xjFJBfK8SBrOKg== 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=AL1HM9U6MG4YVTMT475SBuv5DdeCESkypH4OVb/bYEs=; b=FU3fShi7GfY4QDRlVsExIuexTYruvFpHT4M5TcAeEMT4saGNXgGUEQ8kq4uQV1wnAO/RcQaTNXsTwieWR8y+IB5Gwe8Gf4jA3IihgBxtgvOrEZRlmNBmB0I5T1YSWkLxMhjMQPqH05EK+q0Ugzne7R5/SZ703QlplwIFfIShPpkjmKZc7O2elgzqcId+y0Xk9X9Kxfj3fhlAPVtUGnBBvykfRnbyGKRQlN3PRTW/G/4bPLQaHD8jeghlo/Xgjk2c1cMR9A0aZq2Ma9c4bbbKtGDVJsP8nlm4rbSFYJuAkpZw9K4jKo0KM6D0qs/nUbvP7ERa/I0etmsX9sSglYVjag== 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 CY4PR15MB1607.namprd15.prod.outlook.com (2603:10b6:903:12e::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.13; Thu, 28 Apr 2022 16:54:02 +0000 Received: from SJ0PR15MB5154.namprd15.prod.outlook.com ([fe80::b5e0:1df4:e09d:6b5b]) by SJ0PR15MB5154.namprd15.prod.outlook.com ([fe80::b5e0:1df4:e09d:6b5b%4]) with mapi id 15.20.5186.020; Thu, 28 Apr 2022 16:54:02 +0000 From: Delyan Kratunov To: "daniel@iogearbox.net" , "ast@kernel.org" , "andrii@kernel.org" , "bpf@vger.kernel.org" Subject: [PATCH bpf-next 3/5] bpf: allow sleepable uprobe programs to attach Thread-Topic: [PATCH bpf-next 3/5] bpf: allow sleepable uprobe programs to attach Thread-Index: AQHYWyCQmbX4YN66pkSH451skVb66Q== Date: Thu, 28 Apr 2022 16:54:02 +0000 Message-ID: <9bae67335d76cfffadf9777be79c32c0f1deb897.1651103126.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: dc90f5c4-0d34-4f9b-19d1-08da2937b2e8 x-ms-traffictypediagnostic: CY4PR15MB1607: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: UtsU9x+sbppgRxAf1wvEBmiY8sLqWLtXbk7d3Py8JaSXUTma70a1njBwLe0Lt2UB8CAfzIlBUxmL+abIJAs+Q18OTsF0xEs3CJ3/FgrKUZLXVtDM56u3CZgL1MyLTlj57KSySf3c8jsfv8M+xEa8ovkkRRYmgRaxwXBPYs9CrmghBZxR0qgKQ40YODYr6WA9kSPY0LrQ4DNA5EUm4BpdOCeWmvtb3s+CpBbYwADk0HWtEqdl2cIfQkz39wTbpyJ7EmXl7PdNymqwkMYpLqkOn7isC9pPpy06fZdBLO4zOiBTRXPxJY7sLP4p82HCq+IKwT8smdHOQKqTXFMh6XUNzzaYfnAXmH8qz5kfXQATiDKUMhDVIgxqU+M0IGxW1wWECOc6pUpHN8aC8UDoMRvUXSY0h++YhSN+iBZm4ch+PIdchb2n/D+/WEnrVLgj6vXU7ZNN1sVME9ucA5hdCjKLW4nubzGb053kOKV892Cb0udEl8x3tVbysPqdjXPKVmMXMnL3LftNMN0Dxg22y3lpLrm4jKoQxaJeYTNG5G7mzJTyPdFIKKPxQBcLAI3szEnhIX7DV8mXT/93pX4mU7yMCx0qMnJ1axFeGbxP0YFn2c3mlE64WQ7JcQFZpuN8VJ/aoWCnAA6nzvR5rOEVFzMIp0zSfbCA53EqFePdWsDPbHnY4pyA0h0nuxLXcseIqbN/iYNPV7+oflHgNL+Dp8K8Eg== 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:(13230001)(366004)(66946007)(2906002)(5660300002)(66556008)(36756003)(76116006)(186003)(66476007)(316002)(83380400001)(66446008)(8676002)(64756008)(8936002)(110136005)(2616005)(71200400001)(86362001)(6486002)(508600001)(38070700005)(38100700002)(122000001)(26005)(6512007)(6506007);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?ehnFIvWllY7KqZy9ujNQxBu?= =?iso-8859-1?q?yllKiC6JSDju+DJKuhSAuPDJ6IH0UWefa5zutsJbVmxyUxZxc5wGki6DTT/z?= =?iso-8859-1?q?MgFtBZdGX7Yt/HIk4U9MGXNM6PqlHDlJ4fBxm+JIL0agivPv3T4xQNZzODBK?= =?iso-8859-1?q?KX9JJiGz1/zpndTG1Imoa+LkDafZ/OSV1N5lsfYa0dA6ldhh4mfj2oHFeDsc?= =?iso-8859-1?q?HVaqj0VlcqOrZ+V0x5wrlreZs3XYjO62ovIr3EWxHquNNdNg/l3YFwP0epDU?= =?iso-8859-1?q?sPRcztTcPBKejg44Q+qOEgJ9nzvrIH1lSQO2ljWWlZc5J3UgkQVhwglmwbpB?= =?iso-8859-1?q?kDBSV6y7UaaBxO2DeDtziMrxS1hu6lv3a/vk4MGHO6d29cEstk2RId71EjC1?= =?iso-8859-1?q?vtUkkxUGqqimX3YEzcNjJudcD4eyxppxPJx2DNVTzQ2Y/IbV4UDkyjGArigE?= =?iso-8859-1?q?Q6F6hH93aTPRuBGe6zICNmVLj6Srz/QehFhzRiBrEQE7xGWpld5A8kTm/QMP?= =?iso-8859-1?q?1YZ5SBAjzdpuiz53FIC0wXC92MaMOk3HJUht6AjDfJ8QOZ9OWIF0P9tMv8q4?= =?iso-8859-1?q?RzIWMcShnCSMjCXG9i88NUMJV/B4nFTY8yOSK93G1tTjnFV665m8zuo266/g?= =?iso-8859-1?q?bLiLr8dQRKoZTdETu+LvYGDAayykJ4fjyy3hUbsGsDvFEY9Bk/BcmZ0GN0wI?= =?iso-8859-1?q?Hu/wnAvoP0GaGp53vaxEld36yP2ekjFnXUGWk79hVxMCCz9uW8DhbRWmziMN?= =?iso-8859-1?q?FHqzVNH5w9zPtIa5t6TTYKZEvVlxbFKHxAKh6xM/FG6NEm63NMhXv43OOoYv?= =?iso-8859-1?q?30gUXwi5HJOaBuTVdEinhCwPRF9jCQK9vvPX5ddpygIQHQq4qH1r2ei+TS3w?= =?iso-8859-1?q?t0wMPqW4vWSu2D2rZk4t8kSt8jD0Oam0vAfWYmJaFNaF2tgFi8Tv3GTX4Ibp?= =?iso-8859-1?q?5qTwoVKdFphiaPHbpBL0IBqdIXWv/IPulN/mg944gsfqpXzOc+hIpFZLzljZ?= =?iso-8859-1?q?bexdw9B8U3IsBMbACLE0AxuRTFsKc8prauO1liv6xVupCzL/y4LcxLxTiv98?= =?iso-8859-1?q?Em8OHLqpDecdzrKTCyYDLYcci15sj3+95UaTjbGJjztNR2ZjZH0/J7xJCGQD?= =?iso-8859-1?q?9NuOJOdWHY2pbA/e0//MzM+BBGAMkSzsVNn1vKgET8xlTowew8/zvNAlsI6i?= =?iso-8859-1?q?EYvqkp/F9SlK7hZ9pnS7laJOIAJ1h08/Q0uzhIalL0lLLlmPipty9c1IGUYH?= =?iso-8859-1?q?A9qegIK5bp+j70Xp4oknmXSriOUxSaY59GJj+eRDcFNi8tdbky4F/igsP958?= =?iso-8859-1?q?Nb02kzhTBgJ3p/46Hh4MF3NFKJDh+rp8s+hX7xoOsrVuTQtzg/7ONu2n7nC6?= =?iso-8859-1?q?ZuPcKsd9mKy36RNmToK41zgl/iWlwHBv1jt9frmH+4E8f3SepObKaqN0exC6?= =?iso-8859-1?q?u1c3ua+NdTeoSITzlMczrbngxTJX3EfqjU8wJ3CQhp+bbMz/vNHH73thPh0X?= =?iso-8859-1?q?bNToZX0zJx3oROJgoG0QxYKtJJB5xh8wnU0pCsn58jv6w1LfnnFtB31Rni2P?= =?iso-8859-1?q?oe4yX8xmxBE70bQW+5oNQ2CSiF91Te8USbM/ZIKDNOVdd+x53SbKdNxw6luR?= =?iso-8859-1?q?qOXhsXoExfsHRODxHJznxw1cT+rqNWEhCU/5Ad/XvYky+mC2RvZNqagTCHOz?= =?iso-8859-1?q?q5vhqfpqD2GbFiIYlI7kOO32CM8zWjIcYEHVQVZADWOpI4KZIcjckdwx6flH?= =?iso-8859-1?q?UED2WVo+NGVpzSKw0RsHZL4aVZuT6u5EsTdHblPTOqreLfQ=3D=3D?= 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: dc90f5c4-0d34-4f9b-19d1-08da2937b2e8 X-MS-Exchange-CrossTenant-originalarrivaltime: 28 Apr 2022 16:54:02.7373 (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: lOFgPt2BXSlPwEwUbHkogzZ2lqBY6ia0dApbZDSrzOjA1Janyqk5J1fdn5OlAdOB X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR15MB1607 X-Proofpoint-GUID: JaooaKt1KyZzbaNyt-rVo1eaPoVCQWKm X-Proofpoint-ORIG-GUID: JaooaKt1KyZzbaNyt-rVo1eaPoVCQWKm X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-28_02,2022-04-28_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, we instead allow sleepable KPROBE programs to load and defer the is-it-actually-a-uprobe-program check to attachment time, where we're already validating the corresponding perf_event. A corollary of this patch is that you can now load a sleepable kprobe program but cannot attach it. Signed-off-by: Delyan Kratunov --- kernel/bpf/syscall.c | 8 ++++++++ kernel/bpf/verifier.c | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) -- 2.35.1 diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index e9e3e49c0eb7..3ce923f489d7 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -3009,6 +3009,14 @@ static int bpf_perf_link_attach(const union bpf_attr *attr, struct bpf_prog *pro } event = perf_file->private_data; + if (prog->aux->sleepable) { + if (!event->tp_event || (event->tp_event->flags & TRACE_EVENT_FL_UPROBE) == 0) { + err = -EINVAL; + bpf_link_cleanup(&link_primer); + goto out_put_file; + } + } + err = perf_event_set_bpf_prog(event, prog, attr->link_create.perf_event.bpf_cookie); if (err) { bpf_link_cleanup(&link_primer); diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 71827d14724a..c6258118dd75 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -14313,8 +14313,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; } From patchwork Thu Apr 28 16:53:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Delyan Kratunov X-Patchwork-Id: 12831053 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 31291C433F5 for ; Thu, 28 Apr 2022 16:54:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234725AbiD1Q5R (ORCPT ); Thu, 28 Apr 2022 12:57:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232001AbiD1Q5Q (ORCPT ); Thu, 28 Apr 2022 12:57:16 -0400 Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 591FBAAB6D for ; Thu, 28 Apr 2022 09:54:01 -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 23SG7bkZ026710 for ; Thu, 28 Apr 2022 09:54:00 -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=U4NO8m8IDGi7so3m0I9LGYCHZWY79T35kWhM4cnGlpQ=; b=NPi79+D9OW/32bu6AksGmaK3LQW3FPnru6dBxXYiTDgPjRUCaiiLtqiH59Z5XONXmjvg nK516PjOIcsSMTWhh9QRzrUbXP0smqZlHSDFVB9SPyfTkEAWndvFfwgv8aqhdumn/ZJN unymSKvvCyEHbaqGwIgfZF+7998M7pU00Rs= Received: from nam04-mw2-obe.outbound.protection.outlook.com (mail-mw2nam08lp2173.outbound.protection.outlook.com [104.47.73.173]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3fqm5r40r4-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 28 Apr 2022 09:54:00 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lYRk2sXdrwy/Lmt+4q8qxLtaM+3WHY1gVMnVPuVHBMBLxhu7jmdQLSB1X1ZJNWSxMUopt5pSseL4RGKizBqrA+sNu9BEHUlsZwp7VJG8p9dDVe0ktV9tYsWqaybntR/u362iCD9uz8xfNktfvolvGfJhGUjLPBYb6wo83qYN+dAHvoXNlEFiO7WNkhzUvO78GiBXwJ++stElYpnEoSsk3ijhD7ChtB1gOMocBei0fh3z4T0msIxRqU9zDuFy+/ZNk3oLIX6UrBR3P3Jx2dSBxN4zbCcG3IZDE00knJEqj09EGytbsBLp6IVpqTd2SH3vzreew835Qx7TkrDgD2LVLg== 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=U4NO8m8IDGi7so3m0I9LGYCHZWY79T35kWhM4cnGlpQ=; b=NZ3HKE6v/wjE0WGiLzXiWuo3jn+odzyojHzL+e2Rxvj5AVG4i7Tj1PtyUfSB8iwg9JbrvJB15Wedd8zJFrNkoGhTW8kg0Sx8CYbMxdrE70sMeTq3dX1bbMVlRHTk9RV+b/6d5VENpAqFwZH7EN3vAK+2FtW0NwgSuq668271paU50jS1InlppSYMeQfbQZNL+avgN8v16dQuuCLTTvEtFkkMtqjk2p2dZGFnx1YGjnXRyhQy/J/jojSHysj+z6dD7d4EbrGkruwrvam3M/vHO2kFABnwBXScBYNuqyeQ0zMqgaEi3lno+mDekenTB1o8viSnG8HVrl6c68tf/NCI2A== 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 SJ0PR15MB4615.namprd15.prod.outlook.com (2603:10b6:a03:37c::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.13; Thu, 28 Apr 2022 16:53:55 +0000 Received: from SJ0PR15MB5154.namprd15.prod.outlook.com ([fe80::b5e0:1df4:e09d:6b5b]) by SJ0PR15MB5154.namprd15.prod.outlook.com ([fe80::b5e0:1df4:e09d:6b5b%4]) with mapi id 15.20.5186.020; Thu, 28 Apr 2022 16:53:55 +0000 From: Delyan Kratunov To: "daniel@iogearbox.net" , "ast@kernel.org" , "andrii@kernel.org" , "bpf@vger.kernel.org" Subject: [PATCH bpf-next 4/5] libbpf: add support for sleepable kprobe and uprobe programs Thread-Topic: [PATCH bpf-next 4/5] libbpf: add support for sleepable kprobe and uprobe programs Thread-Index: AQHYWyCLmUWuy8bCeUK1TVSeHWTI+g== Date: Thu, 28 Apr 2022 16:53:54 +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: 8c8a0781-aad4-42ff-a8ae-08da2937ae59 x-ms-traffictypediagnostic: SJ0PR15MB4615: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: mWwHhUYIwnoPfy9V57Vd2RDdaoFlYy8l9q3nU/NmfPgVa/MqwQYwUZq7kzQkUCbKYiflwnFyyh96LLMVacNCvzMX+dxT7F3x1oYrDhmM4DcUqyiVs18vdcb5wZc9Kj1Lt7bZJJy2erZNb2vl9HPLQa/fWgDHzMlxHx7eliZM5/GwvJq+KMs4r1OFJKE3mO/oMWO60Qf8ExfNd5dWL6Ormx9wZxXD1BstPHeXyLE3wJ5zXYG3BYlj/cUeay4iliLROmZ516w39mUzcdjnWxgK/kBced5BJLiLKzNxPnrqGAaTDGke1HQkw1BAnAtQKSahAmJab19Ro1tw5cKoHjTZ1kl5tdCRBFCiJk6cdh+fH/ISynRIh67MiaL6FT1R0kyQjZdKCrrgwgBZ8ltDP5S/T0DVjg6s9Ibzc6js+6su7i84p33TNxNrIcQ+OZHrEAsjeYCz7cxhyd4S4Z+rXtTtNcmjgVwyS951HCZbG63MfT0396Y9Dgo4STyQXRLMxleJGvHRvyVshFPrHHgn6pumm6XjGDJLr7G3FKnUsQE2DCqJU+De/f6yAZISghAZEM/6IEWcJ1wlPEShU1vxMNx9vzlAFe2+zj5ZryYG3aJD62Er9SPe8yLGO+O/TawNTWbRRlFJMhu6TnNchou1C58mlwK0SVJpzMyJNiD4kR0oXO+nuXGa7T6uGuUHMaMsVi6JL/6Y3TLmDCTPUcELpBOLSw== 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:(13230001)(366004)(38100700002)(2906002)(36756003)(38070700005)(86362001)(316002)(122000001)(5660300002)(66946007)(8936002)(6506007)(66556008)(76116006)(8676002)(64756008)(66446008)(83380400001)(66476007)(6486002)(71200400001)(186003)(26005)(6512007)(110136005)(2616005)(508600001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?/XHmBy8ghjlJEqnPAzMh++4?= =?iso-8859-1?q?8afUnWDmey6gMy/u59XjofwwiQkOdtO4q04mSayM0tiE+6vy+pir/bIrroBv?= =?iso-8859-1?q?QKMnHPyY/EFTlPm1abj/b3n7mUkpPEdEflAJ5iGYj+PXw5AS5gnUZp8UfRAK?= =?iso-8859-1?q?FM4xmil8GzRUZQ0YRbSk5rz+ZMsYzQeDrxybwV5qahfaRtvbVCGEfc63rdh/?= =?iso-8859-1?q?LYpSJKSszu7q0msOUI+DnoOzceYaHKTIypkuDhh5mDM81I1tPufKQDojXcVo?= =?iso-8859-1?q?Q9vHNyGWVg0fGUWZc2IW+QfXwM3ahxYADyrk8tDMZvLu3xLf7yBa1W4xCRo8?= =?iso-8859-1?q?m0w6NJ7Gtwabtdy/vavVDUnEub3FegealzXjHEkblgn/szyDtZxRMtwQrGcY?= =?iso-8859-1?q?4Uq2ysT1ex9RBpsU6bO3xgbkpxFFGquNucXn6NTvCpuE2BsYIGF6TL4IYELD?= =?iso-8859-1?q?5xY947wyYAVGfjvz8vLFH6eCwW6j7gdiRixXqdFDGU1K3em3OgvYMEKWe0iZ?= =?iso-8859-1?q?JBrAQNeG0tP+FV671oh3EU8ADHF/RXOaAtXKnAPGRxSvjlYi5sMTR9WTEnVW?= =?iso-8859-1?q?CJrw/SwYBThdvJwfGjO6hXg0TO3mMHzNXhOOGwVCX0gTWN256PkP0tFgo3Bl?= =?iso-8859-1?q?KGL0VFbWB2KYLudYVRUT7o7czF8kf21ChhxvrxqA2Mm6XgtTQjudJvC6NR9P?= =?iso-8859-1?q?ZxIqjNrVUTrIDkKEv4NieuiuJZqNJMMY8/CI0/+2DckQ/Jc0G6TRaqBogg3X?= =?iso-8859-1?q?rsC3xwSZDE5RSh26nHLnpaKPvNkKiWN3BrCXi3bP7qqABO3WDUl0AzIpGCxu?= =?iso-8859-1?q?D6FalFbsuq5vOjH7sp+hUW7Jw/DtsbzGishh7HOopJZIeeGlSD4VOaI7J88Q?= =?iso-8859-1?q?NSZjvpiuigRRiT4Qz/AvqD4pFASyLc+Z57XWLMAcIVf4RK5KzzbGFkyEMQaX?= =?iso-8859-1?q?Z1nUlMjhw02Ss6/TqvsbyDcutuq7w1vtPL1oY0aDLh3onLw8UeTY1tDpZKUl?= =?iso-8859-1?q?IMCfZkcRet1yWmbK1vr/aW451qNTbq7kkNFk3oSN7g+6TL1zEg5P+dGpq1cR?= =?iso-8859-1?q?BF7yo4NdtQa+BL8sro/FwfgVCpo/7NADSGPKyjBjX4fRAsLTyXFTfVYOy5kp?= =?iso-8859-1?q?28ijlqeDrjKl/5FzGrO4Pk2YTvLoe1b9jjdXzPST2UXyubyBhD1PpSrA63jk?= =?iso-8859-1?q?pPlvapE1BxBxgPTvVod00lpFf8Us73TUOIH2GJU7pSmcYGqdPpkGUfUQPcVs?= =?iso-8859-1?q?R/C4f1h5jl3TdVsvWFcw92CxFBl6eEyJ78DsUgCRKfp0+L8pxf77YzWgfTEV?= =?iso-8859-1?q?SKBWJBuiEjXlA+CFSMD9+ltD4NQ5ixoBCyyDg6LTNKxVcc3UL1PPTV5FjkHD?= =?iso-8859-1?q?OVY9t5lE6VBqjbV9Sjf4HbBhqGrIa/AOTrIFG00qyoGR9+6crXcW1i5fKlaR?= =?iso-8859-1?q?e1tLAzzvIOykjequbZ8a+WWnbtde9Gwrgfz4UAb+Z1zmhu+r/1tZj6uc7gis?= =?iso-8859-1?q?IBV/9jReXuSskB8W2MehwGEkAdLekmud6/Eysk5xKsl+KEYODY1dqlgU62Ye?= =?iso-8859-1?q?stfVtCnkdfWPyFmwXlRqRnyfv+tgvO1YiPkZS6INgf3y3WPEEOIQr5lkx14h?= =?iso-8859-1?q?kL/9G6efSDoe1inaqakHUMnk5iXQgKw1aEju4LuDZp0DatNq48IrzYJnr3Gr?= =?iso-8859-1?q?mYTBWwT6FsTdjZ+BSfq05iYU1VNmceRBtUL3FWFoE8c4C2qJLNFr2PIZExA/?= =?iso-8859-1?q?dvYPAc/mCyNhvS9/ALKN8PI2rmpYUgQM2a0nRfNljeKPalw=3D=3D?= 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: 8c8a0781-aad4-42ff-a8ae-08da2937ae59 X-MS-Exchange-CrossTenant-originalarrivaltime: 28 Apr 2022 16:53:55.1085 (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: Sr7UQMZRdq7D2ynlD96UjSWcjyGhQPH5ZyQJxXigl0/deJpfryQ3txQmcxPeif9m X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR15MB4615 X-Proofpoint-GUID: L4cXZK5rmAoaocwxY_tgn1XKEnmhgiQi X-Proofpoint-ORIG-GUID: L4cXZK5rmAoaocwxY_tgn1XKEnmhgiQi X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-28_02,2022-04-28_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 uprobe.s and kprobe.s programs. The latter cannot currently attach but they're still useful to open and load in order to validate that prohibition. Signed-off-by: Delyan Kratunov --- tools/lib/bpf/libbpf.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 9a213aaaac8a..9e89a478d40e 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -8692,9 +8692,12 @@ static const struct bpf_sec_def section_defs[] = { SEC_DEF("sk_reuseport/migrate", SK_REUSEPORT, BPF_SK_REUSEPORT_SELECT_OR_MIGRATE, SEC_ATTACHABLE | SEC_SLOPPY_PFX), 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("kprobe.s/", KPROBE, 0, SEC_SLEEPABLE, 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), @@ -10432,13 +10435,18 @@ static int attach_kprobe(const struct bpf_program *prog, long cookie, struct bpf const char *func_name; char *func; int n; + bool sleepable = false; opts.retprobe = str_has_pfx(prog->sec_name, "kretprobe/"); + sleepable = str_has_pfx(prog->sec_name, "kprobe.s/"); if (opts.retprobe) func_name = prog->sec_name + sizeof("kretprobe/") - 1; + else if (sleepable) + func_name = prog->sec_name + sizeof("kprobe.s/") - 1; else func_name = prog->sec_name + sizeof("kprobe/") - 1; + n = sscanf(func_name, "%m[a-zA-Z0-9_.]+%li", &func, &offset); if (n < 1) { pr_warn("kprobe name is invalid: %s\n", func_name); @@ -10957,7 +10965,7 @@ 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 = str_has_pfx(probe_type, "uretprobe"); if (opts.retprobe && offset != 0) { pr_warn("prog '%s': uretprobes do not support offset specification\n", prog->name); From patchwork Thu Apr 28 16:53:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Delyan Kratunov X-Patchwork-Id: 12831052 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 AACDBC433EF for ; Thu, 28 Apr 2022 16:54:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234322AbiD1Q5Q (ORCPT ); Thu, 28 Apr 2022 12:57:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231442AbiD1Q5P (ORCPT ); Thu, 28 Apr 2022 12:57:15 -0400 Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF45E9D04F for ; Thu, 28 Apr 2022 09:54:00 -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 23SG7bkY026710 for ; Thu, 28 Apr 2022 09:54:00 -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=qYYfM4jpQsgZ1I4zj/9WHIp6BYyP77ofjCQWx+xmyUY=; b=ezndlwqYX3Ac5Ew5Lz4Kg3Msu4nXH3FCZ1iYugaIupijMUtmZkE79H2dxKKtserz1Y06 BrpGe1eiyCx0aKXd6AW7vO7gvfqLspd0X7puTM1ZXqmtQDjlWFf8VCvtaivVWE56AIuD jvCP8yyFJix/9HgfcrYQFganJHaGtl9CKqY= Received: from nam04-mw2-obe.outbound.protection.outlook.com (mail-mw2nam08lp2173.outbound.protection.outlook.com [104.47.73.173]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3fqm5r40r4-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 28 Apr 2022 09:53:59 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FvDr2Z3exsFPQDHGLx5/UrhMWjxmChbfBUyadc6zoQXP6YN7ZYeZUupK3qS1fbCF00WEOypFm5t1PihesqjR+iWTUT5KPDKgGgZ1rtVb//nSxWtnxlbiNgNdAt4lePpIw063WQRb2qwQrQXkhjdndNTgBqGhmibcDaOOkSyM22fpREv3VYPh4kXu2Qmzi7O+zbIqu9xsLuIJGG7NH+Dth9suf93mdukC5yHcS6b4s84qaKeGoFiptvb6q2ME61q5Tpx02sdV0K6oPTCPpZcWIDkHVghwh25rOn1GpBYndzkgOId2I1OYZGUfyeTcCmXPNtF5dp/0qgvYOdIEVBgaVg== 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=qYYfM4jpQsgZ1I4zj/9WHIp6BYyP77ofjCQWx+xmyUY=; b=LfR+Lu9GQKAgKMtlLi7TtP4FvbHzZMx+63MvkC7u2VAe2LoyOAnphMHrA7y3EBw0ZYvaq9qkPB2hT3Kej4uDv05tDh25MaCHE3+2enDTuLcMO/eLyjlhOf9k+iqNSlb9OuJ+0KoxvKdq/YKyDU8hXxXNrpI7xcmQtq42oNCHE25p5GbucFJ97RIAgSF7LExH8e9OymEG824frx1C37PThV7vouzlKA285b1S91yUkeROS1+QkmjpJ1DBASkfQ6dCdZuM89dchdNnJgKdEhQQaN41RKerMa7v4sofGNIgLWpaRMb+qv+8ilf4RIqLL45zXMqRvLg2lSc28pWsYtFbuA== 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 SJ0PR15MB4615.namprd15.prod.outlook.com (2603:10b6:a03:37c::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.13; Thu, 28 Apr 2022 16:53:56 +0000 Received: from SJ0PR15MB5154.namprd15.prod.outlook.com ([fe80::b5e0:1df4:e09d:6b5b]) by SJ0PR15MB5154.namprd15.prod.outlook.com ([fe80::b5e0:1df4:e09d:6b5b%4]) with mapi id 15.20.5186.020; Thu, 28 Apr 2022 16:53:56 +0000 From: Delyan Kratunov To: "daniel@iogearbox.net" , "ast@kernel.org" , "andrii@kernel.org" , "bpf@vger.kernel.org" Subject: [PATCH bpf-next 5/5] selftests/bpf: add tests for sleepable kprobes and uprobes Thread-Topic: [PATCH bpf-next 5/5] selftests/bpf: add tests for sleepable kprobes and uprobes Thread-Index: AQHYWyCMsgxlJnSFd0GLBqB/JA91PQ== Date: Thu, 28 Apr 2022 16:53:56 +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: 8c8b085e-f00f-4fa3-f3b2-08da2937aefb x-ms-traffictypediagnostic: SJ0PR15MB4615: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: RpLh6jtWv37rydXAnaI64qJKSJZY4hBrNoC/eaT2gbiXCEbK6W4uH0P4wvRVRfZNISImNOf+pXDdxSu769Sj0nmMwg5cLcPhjRjk9JR1kRhsACnbS2pKzGbxqt2TOtlI4/oQFGXvZFY76vPV2+jAwiiAEst3hewcSHqLgL5osOI6a34C1KFMi4kQNaN7uGRImEKlEdAF5/fcnuKaD1rpEV9I/RUJubOJVZtzA791N10cF85Oa7lfNXpJB3OKzAWLJHE7ZH0cdI6cBKuW1XPrY4d+Q5yh7fN51t+P0it3+qzmVQ5wXNdnEYcC65mOjtXbeq/cdqaF8NEyRCTh/wndeN0cjk+t82ZMrEbCxeLzomVVmxGoMUVfOu5fEYK26AZmN9yGKsPZwBR/dDk3fC3vY8tDeyYwgGaJIePG/PQzMztTyXKZBuRiG/7nQ0k1E7tYJfxxrmnEbuKrad2v4Cq9Uw3+g1LyNyJ+Hcl/nPpDX+jPRSFbFumj2mtDr6a27JwFbsN9Bs02a+NVCcX/dak9Nsf+NN8vP2cFzIy7gUQ3EA7XpFfUd0E4JZulM0TtOj2bc22OQtAu309D1We700N9Q7byxoBWHuu67Af0vWK7jqRFeXZIyPsyqxtwYNfzcmf3faSsxvyImUIaNEYdlC+3M2Mka2KlsCoiqwkjL7NRBzcGJwDz1xLKyzHqWvZfO68bAHcEUC5GDAmLEkpGoMIifw== 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:(13230001)(366004)(38100700002)(2906002)(36756003)(38070700005)(86362001)(316002)(122000001)(5660300002)(66946007)(8936002)(6506007)(66556008)(76116006)(8676002)(64756008)(66446008)(83380400001)(66476007)(6486002)(71200400001)(186003)(26005)(6512007)(110136005)(2616005)(508600001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?9Z5UK9LIeRRmAUM2eaeXRUo?= =?iso-8859-1?q?j95FifswRgHoFYJsPA7sM5V1rUkS75L9p9YepMPVXQ9SsR7ZklsbzFo5I8fL?= =?iso-8859-1?q?gTNrx2AtboM8yZ76EUkeDi9ivYTXcib/3/I4q7qe8YptN8DeetehChSuEIjU?= =?iso-8859-1?q?6rS+Xr0ikBHTVmmDMIbIh0T1fRz8a/yk7Zkjaqf8ZqYeG3Cefs5BQcQsa8Vw?= =?iso-8859-1?q?3AXlXX3AfhcwqyT9ewSOBqA86cQ22Tm84a7AA3kOgMOBbWYEHjIV9I7aEc0U?= =?iso-8859-1?q?ubehX2V8rF5KmVG/ePixy+AMFe+c9QrjGMQPnPZ+xxHXWO38zEmayTnqR+co?= =?iso-8859-1?q?KoKNpnsuS3zjD1PcexxlmTYtxqPGuk+rSfr3yO99ig16fncoe07R2HA42tf3?= =?iso-8859-1?q?flfNtrqBZMUsQvIYR4SCEccMALFw6yyUa0+StjYVxDVze5o7aynNrNDDZOsI?= =?iso-8859-1?q?XI4so8Wy/izmbYvJy1UM0u+NpilSBJijO+UFPfQNrHEytOVYM17eXMCePN/S?= =?iso-8859-1?q?5udqqxCnDqowfLjwi0nF51ZFgauZFldE8wtBmbH+xcPK9jkmO2cHE9tiPT85?= =?iso-8859-1?q?S5F03LoXwDHZWEJZzcB2Txeh5A1pakMhMiLWeumtwHa5CYx9pZKjoacZFTU1?= =?iso-8859-1?q?aXEDoXba7mKR0xqCtP4mkA5Rb/+2a2SKZI9/kXGDBG0+ch0o5+/jN2DDzcfD?= =?iso-8859-1?q?qUkW0spsUt5VYt6WLTbNb8EwRNvzKD3NnUwHa2MTh1n6JmeH47B/rGhvIeQ1?= =?iso-8859-1?q?3o1xtY+UfODVXNs5l8T0wCIFpThGcX+XJkk6EKBbPbMztBTy3PiJmZj3tT/Q?= =?iso-8859-1?q?Cr5HUqw7ChpFZ/6etyZQdM67fu9mW35aVY5FOjEQ9A5SueZRLGmXy4EYbEhf?= =?iso-8859-1?q?k7ZXVBSx1F7j8ZWpyD9643sgjk2ksFWu1s19TUYj0ckkhjqkZdL31unGASQq?= =?iso-8859-1?q?EONv6lBzqruW6/sU7Fe1nyavDriE6B7T/xHIPK4BQgV22/JaBBE6GbQVss6q?= =?iso-8859-1?q?0CloPve1zB+fPDQGhMRF0IE6JpOC94YH2ZjKJXs3uHQatgscMIKLSb+G6A+n?= =?iso-8859-1?q?6ggYV9rIzsE18IGu+QfJHiMzf6g2M25wrRJwnAzznwsH3MA/X7w211gIlDXb?= =?iso-8859-1?q?dpRwvzMW1PJkxZqTwQhlR7p3P9pJzG3pVRSzJFT1G70ufIQcOhNB1I76YmXS?= =?iso-8859-1?q?r0SUH1nVLLOmEX1a/9kMctU19/AbHX0S/oEKWPLU+j2iW1JdImidCKsJ4eUx?= =?iso-8859-1?q?C3N5JMk126Dt6UCB9Yull2hVoBMqobGZE02UAW6fnOIsh0lIikPmJZQhEQtF?= =?iso-8859-1?q?uf5Gbe8fAKjhvYO5l1dC1RL6tlp0EE5IIs1HhPuCC70c6BMdccePoSC62u1r?= =?iso-8859-1?q?3rb/Ltdqp2p8R6EJCwPQIXZ2HwyeCdkTxTHvQlSnFKXbbt0AqBLnwHpOTQ2U?= =?iso-8859-1?q?FpLgO6grtPBDGea8m2+YJymaNkahxOJymmzgpHu8wrLRr7a+ZaRA5SO49zD2?= =?iso-8859-1?q?OdPSLHvT8YRqsWqsIX6C/pGoCdEDGPzp6ueWcmHr1butvlT9UlQ9rDhD248K?= =?iso-8859-1?q?P1tntWd/KbQl5/tSrGqV92hBiyCP1x971avC/f9IS03rynA4utYZgnK6wsyy?= =?iso-8859-1?q?7Ev3SOkb/H9lGGUG5xG4lWLOmsR5/g7RbUlnvkUWgIQ+GB3gnr2pq2D4ulEf?= =?iso-8859-1?q?QeUF2Kw/RpHf7LoXZUGanTunN+4WXqLeTp1mdWBt40JZv3XZviSOxhhgYz+U?= =?iso-8859-1?q?IMyFRAvV3358Ho06L6LfcrfbafDkzF9MVpVTigdB7j/v0AA=3D=3D?= 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: 8c8b085e-f00f-4fa3-f3b2-08da2937aefb X-MS-Exchange-CrossTenant-originalarrivaltime: 28 Apr 2022 16:53:56.1877 (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: 93ZxCm+eizIec9Yi9pkyJQT2ikUhszDjj3wxnyX/ysYQyRAAC8DwnKPtPNFiTmsf X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR15MB4615 X-Proofpoint-GUID: W_rs2MFWjGnhyq63fY0mHSI5ZqiBSycP X-Proofpoint-ORIG-GUID: W_rs2MFWjGnhyq63fY0mHSI5ZqiBSycP X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-28_02,2022-04-28_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 kprobe programs cannot attach. Also attach both sleepable and non-sleepable uprobe programs to the same location (i.e. same bpf_prog_array). Signed-off-by: Delyan Kratunov --- .../selftests/bpf/prog_tests/attach_probe.c | 35 +++++++++++++++ .../selftests/bpf/progs/test_attach_probe.c | 44 +++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/attach_probe.c b/tools/testing/selftests/bpf/prog_tests/attach_probe.c index c0c6d410751d..c5c601537eea 100644 --- a/tools/testing/selftests/bpf/prog_tests/attach_probe.c +++ b/tools/testing/selftests/bpf/prog_tests/attach_probe.c @@ -17,6 +17,12 @@ static void trigger_func2(void) asm volatile (""); } +/* attach point for byname sleepable uprobe */ +static void trigger_func3(void) +{ + asm volatile (""); +} + void test_attach_probe(void) { DECLARE_LIBBPF_OPTS(bpf_uprobe_opts, uprobe_opts); @@ -143,6 +149,28 @@ 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_NULL(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; + /* trigger & validate kprobe && kretprobe */ usleep(1); @@ -156,6 +184,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->kretprobe_res, 2, "check_kretprobe_res"); ASSERT_EQ(skel->bss->uprobe_res, 3, "check_uprobe_res"); @@ -164,6 +195,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 af994d16bb10..265a23af74d4 100644 --- a/tools/testing/selftests/bpf/progs/test_attach_probe.c +++ b/tools/testing/selftests/bpf/progs/test_attach_probe.c @@ -14,6 +14,10 @@ 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; SEC("kprobe/sys_nanosleep") int handle_kprobe(struct pt_regs *ctx) @@ -22,6 +26,13 @@ int handle_kprobe(struct pt_regs *ctx) return 0; } +SEC("kprobe.s/sys_nanosleep") +int handle_kprobe_sleepable(struct pt_regs *ctx) +{ + kprobe_res = 2; + return 0; +} + SEC("kretprobe/sys_nanosleep") int BPF_KRETPROBE(handle_kretprobe) { @@ -76,4 +87,37 @@ int handle_uretprobe_byname2(struct pt_regs *ctx) return 0; } +SEC("uprobe.s//proc/self/exe:trigger_func3") +int handle_uprobe_byname3_sleepable(struct pt_regs *ctx) +{ + 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) +{ + 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";