From patchwork Mon May 2 23:09:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Delyan Kratunov X-Patchwork-Id: 12834878 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 374C1C433EF for ; Mon, 2 May 2022 23:09:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230379AbiEBXNQ (ORCPT ); Mon, 2 May 2022 19:13:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230447AbiEBXNO (ORCPT ); Mon, 2 May 2022 19:13:14 -0400 Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 097A92ED7E for ; Mon, 2 May 2022 16:09:42 -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 242LsdoI001183 for ; Mon, 2 May 2022 16:09:42 -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=/bQJZdrw6shcur37B7xG/iyZg9wSsyZ1GsCDoVWhVlw=; b=oS56sxmpWpsehBjfDsi4n7FNuIrRCCoSl081jbgq2aGRn8V4VtIFTs5g7v70n/zMKey2 Wtzw1Sl++PKRqsCvrKnQJG845s9vq48K1V7Hm/k2hrPRlx4qoVcU7HepN3JbgCx8tkPN zxC0QfnTtzw11ghF2pb4Uqa5yYMktNhKAIw= Received: from nam04-mw2-obe.outbound.protection.outlook.com (mail-mw2nam08lp2172.outbound.protection.outlook.com [104.47.73.172]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3fs2mxchjh-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 02 May 2022 16:09:41 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Uz2hqRdrjHXMlWkMmJmBv9gMGiDKHnWtph/6xBtS30RaTzRbFMJL37t5vaSxFlijLhvtJSip0dLlWl+eGNmhS1oPEFNQJUNPBGjIaYVNh1+DbYizDUrDr6K+buhzIT9ejvnV6X3nqk0BQBGt+tSWjUssFqb2QYzXLau40SC75Acce3J9srD/oWv8FHcNlWZwH6HLeebM3i8jGS8gGlA0sm/i7qs0/ZGCao+Hy9xYGgRo9faZNNig2Dnov6/iIgKPPl0xGk/JvmtAoBd8bZlV+cTWcrvIZgtCPuJ8QSoX1WrFvGzX5AlRepwxAAqijbD8cngj3mz/vpOfphRDiNo3AA== 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=/bQJZdrw6shcur37B7xG/iyZg9wSsyZ1GsCDoVWhVlw=; b=caWXDTeTVIgiJBny/3MHQoeVIjMIftsAksu+cZuL6PsJUCKtQsIALeSIbeWtH4X7QZ6hnoXH66RBUj3PHkQT5T6deHrGdm05S0iONLERDxRx7AtyKAXvd2PKd6tuq+2w1dD/FVCAF2lxgwvwLGwt4UxgaFAIw56+/StPxaFXR+v/tY4ctkARqnfUFIr16HQmVnPsREJB1F9EN7OO6oPKuNDSlWiSaKYJ3qsxpxNgRGMURfSx9h1ZHpA2eCuEktWBbYmcJ7LBDKBWaKi00GDHmehspmfBxrIv/mbw+rRcZVWzotK1/BtxTHtqcvIl3RpqHnoQMsXHpx0e1zsIJR++QQ== 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 BYAPR15MB3141.namprd15.prod.outlook.com (2603:10b6:a03:f5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Mon, 2 May 2022 23:09:38 +0000 Received: from SJ0PR15MB5154.namprd15.prod.outlook.com ([fe80::b5e0:1df4:e09d:6b5b]) by SJ0PR15MB5154.namprd15.prod.outlook.com ([fe80::b5e0:1df4:e09d:6b5b%5]) with mapi id 15.20.5186.028; Mon, 2 May 2022 23:09:38 +0000 From: Delyan Kratunov To: "daniel@iogearbox.net" , "ast@kernel.org" , "andrii@kernel.org" , "bpf@vger.kernel.org" Subject: [PATCH bpf-next v2 1/5] bpf: move bpf_prog to bpf.h Thread-Topic: [PATCH bpf-next v2 1/5] bpf: move bpf_prog to bpf.h Thread-Index: AQHYXnmyxbkRSEhIiESP57CBJDNDWA== Date: Mon, 2 May 2022 23:09:38 +0000 Message-ID: <616c50d61de26eacd49fbb641d3122a85ca478fc.1651532419.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: 772246e4-fb78-4728-c944-08da2c90d4db x-ms-traffictypediagnostic: BYAPR15MB3141: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: xr0yAaPTa7VSwteiZRb0ntC4Mm8+3tBruPNbEVHGk7V/4dDkSLytKX6Iv038ndq0hY7a8fpj+xx5brAxXqk/RPOfIXkCZLQGBwoMKN7v36cXBPNfJU9h/4+Gi2Ovhq9HC5qJL9ZwN5K9tWJ2+84WfwiHin+HarDfy9qr/UtGuMg4muUL1KBZzjiJAAEWUyVRLIOLcNuPRZJzBHGO4iEmpq1uVS4xy0d8dXoKffWm5ZFS1w63sdU8NnuElbqxpQbxu9yE6ts4QXELRKmJfC2UCGJriBHNCZp7H/wdxYEX9dEjsl51q8SFmbqtn0sZm5mT+eHpMiC3roS9LPe3OVcqin+o3vSAodqVuarHltJb0AC53iHO0xp37XTyMdFLR39zFx8Ra3lXEjkJvPYsrKo/3IQWlCWZAl7ygulaQandsojQEMfYqgQT+AUzzJTvIkxLwL3ac8Q9Gvy1urkAbTGF7WkJpepJ0piFNHTR9O+IcASyM0XKu6zAHMsYIdyxEQ8binRNDT4oQo2kwqbU1FKd0PN6pc4GYjEJHmSp6bBvzOP4dybMcfLTdI5eJTnsR993HQ6qoMdiF4QXTc2l5wYm0rW//My/8VAn8JhYkepPl3rkY7tGMeH3zMidYkFoyocY1FUdDDvCIpJ6ne5ykOBIXRwZkVAoCarQYknEgUSYZScFQKF/rBTT18Dzn3/Gfd5wyToxaNFBBjhki4lKx5zARw== 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)(36756003)(122000001)(186003)(110136005)(38100700002)(6506007)(38070700005)(5660300002)(316002)(64756008)(76116006)(66946007)(83380400001)(8676002)(66476007)(8936002)(66446008)(66556008)(71200400001)(86362001)(508600001)(2906002)(2616005)(6486002)(6512007);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?YCXYObt6xkFlmQv5oeZIlai?= =?iso-8859-1?q?dXQTuwH9Be3mS4OhPnz8omYx07jS07ZSnwWsCdvx3Es05bmm3L24tOcRphf5?= =?iso-8859-1?q?f03NamD8MiOqSkO99SFDW5DMcYNiRU0jvRREWvE7U85Vyf2EddIvJir6wZK9?= =?iso-8859-1?q?rJx4lHV8sr9uNwEZH5CixtGcVK9FF1JO442XQ5+ni6g5WMU98aI5w/ITxxOg?= =?iso-8859-1?q?ROYmXAllnicBR88eIlp5WD6Hts1ZCzw9PH15qwRuW947ANfzt4H2laAdld3U?= =?iso-8859-1?q?Ni/zJuo6/fuRiXlzlJXeUSCPHg4RfCPG1SUWkH2CTRnNbUZgXEpYqHcGRaRA?= =?iso-8859-1?q?nN3MQC464hzHkASL1OhL/Df1aYuURhI9kxXUUqtQSliBhqIANaduVONnx1fZ?= =?iso-8859-1?q?/FHDo0IaRDt/yO8Xw/l3BKlNOs6Mz8Nag1CBgESmFkRvT8GDyxR/CBHTMNyg?= =?iso-8859-1?q?e390vI49/P6clov7gMyYnvQ+kOC767H2YfaT7OJz+w8NIwpB6pcJv/wCsMot?= =?iso-8859-1?q?MqLihuOoe/Jf8ubBEGL/OdbhB7LtRc3GuVJkaDhoVT0pHQUo/fIdgMnEzqef?= =?iso-8859-1?q?bIWyPl/uafbrg3qSRZbTC4Klek9Fqp7GMPXjuFx4hG+Odp/TKgt7YSewuGwX?= =?iso-8859-1?q?6KwoWW//MU23cKoYyr4S+4/kQemZ9gf9T5RLQXlYZhuUQs5pwr5rO1YA68qF?= =?iso-8859-1?q?C+Yitvi8mUeqyruJ7uqPIa0iQO/IqYkMEh7/oH0dGqijfbuc8U6+7BRFqk/w?= =?iso-8859-1?q?ykY6NbnW2kPcYyA0i8ryXc11/fKO7yPfDfer8sM0PIYBCRfC6Kn3O1NUwSNw?= =?iso-8859-1?q?cvqx6awfLYQiorQqASnFhskgTgIgqRKm5WRB0ZfhvH8l1YJeBs6G/ddYKS+a?= =?iso-8859-1?q?o2FDaGaHoTuEVs3BbL1BK9OQOtNY/ZDdeVjkIS5cuTej19a/9B411XIx8Pn+?= =?iso-8859-1?q?E1WRsvucZHpJFscAJMYmO30BJMXyjiNUmPECAsSziQKjbrQ+ANbpIH5DZIno?= =?iso-8859-1?q?q/tYKxioH5/T9g5kDkDbuOOqKv3HqQ4O0KMuhE/YXs+OYXQheUt3ULp2IGfN?= =?iso-8859-1?q?K+BejMRGZBBWMHRGyeR/IOiV/Y926jqJSEg8nWMCzRfGbNXJBU48+WKlSpvT?= =?iso-8859-1?q?5AU+H8F7xfbNboBuic/O5sODyTVxViXS6YQFjinAxxeyQH8H8RutdwI3SORs?= =?iso-8859-1?q?HyYX2eKapi0ZVdrEMlstFzMxrF1kao+V9cG+3WINLnYnrnbxwMUjvKJbmIX7?= =?iso-8859-1?q?052LZqhmGBOI3WympWVJqVF122kWssyxJAXsl/kXJHjz2wTq59+48YnRPZtt?= =?iso-8859-1?q?eSt/Fk2K/o40tv4lehzH0pzwpRiTUrgaVko/5ZTRz3DUiu99HLm0DnLJfaoT?= =?iso-8859-1?q?D4Q5/4zdvPfvLgn2yaOVtEg7Yy4ljuQjcztYoYFvc6LULeKXyxfR2iTAa0Ib?= =?iso-8859-1?q?m6m+ezVno7Twy8Bg4OSJQj2e1fzPJRLVXMdxAuS3PVJJLOOC2dWkUO2Xmoxt?= =?iso-8859-1?q?Nq9mzH53NHzbZP4tVgbNuQVdE0/G4DlnJt+J8PoFjYd/tzjVMPUpfD9Lk3f9?= =?iso-8859-1?q?NjTj7xiWPhDPluq8YEk2VGQcumLnOP+HROcLGmaKmh9ST3FqTcEoFrpcUisp?= =?iso-8859-1?q?j8XyZV1BMC4lgBk+NE3Jf1Z/M/m7/DQC5won9c1MiidvO0aRlAEH9lWz5AUT?= =?iso-8859-1?q?YQ+r6oOpHFnFVjgNv1dvd9GYPUnjrpvIgnrCntnQJaPNwMwPzgQ2xuhCTi1S?= =?iso-8859-1?q?HcslZ5FZDiIsKrFqRmL6vgR3wzOFGX+alq4RUBSO7AEY5YeCSjV6VXQvAo6S?= =?iso-8859-1?q?VoA/8hyVpMXWywerw8wsST+XhUSG9?= 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: 772246e4-fb78-4728-c944-08da2c90d4db X-MS-Exchange-CrossTenant-originalarrivaltime: 02 May 2022 23:09:38.2558 (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: AuBN7Rx7No2BypH+tlG0nz7YYRx731ysojIA0ZqwIYQKzaZmMMtFxh0AMgA7A6Uh X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR15MB3141 X-Proofpoint-GUID: wqsiyyZVfBdfMVLUhCZ7GVV2VIUBNnj6 X-Proofpoint-ORIG-GUID: wqsiyyZVfBdfMVLUhCZ7GVV2VIUBNnj6 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-05-02_08,2022-05-02_03,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(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index be94833d390a..57ec619cf729 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 @@ -1068,6 +1070,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 Mon May 2 23:09:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Delyan Kratunov X-Patchwork-Id: 12834877 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 88028C433FE for ; Mon, 2 May 2022 23:09:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229445AbiEBXNP (ORCPT ); Mon, 2 May 2022 19:13:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230379AbiEBXNN (ORCPT ); Mon, 2 May 2022 19:13:13 -0400 Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 572A62F023 for ; Mon, 2 May 2022 16:09:42 -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 242LsdoH001183 for ; Mon, 2 May 2022 16:09:41 -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=TiauhuQgoZUrngSfov53exe9RchItISFGYggMsssLLM=; b=QUQ0yNjQ+mb1y++qX8Wc7WNiZz7+xMfrz5q1qo+GrFUcFvgE49b0a6rV0/q9Ish2sNyp TvwFxVGnoF1gR3tgXM0ixip+vJihxG7mT1S03Uf6DkYR76Z/GxGVwlATtQWU/qvVkQv0 PZQtGjOue+R2k3gzvVhTwi5UmsEzosNe86I= Received: from nam04-mw2-obe.outbound.protection.outlook.com (mail-mw2nam08lp2172.outbound.protection.outlook.com [104.47.73.172]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3fs2mxchjh-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 02 May 2022 16:09:41 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Rzy8KsUFufdXXe8D+RAr944fzwIbr7qBhDp0+RV8FH8a0QYC4YV4gEtOrTTvOoBIKd3hxrjCOAu6pK9AJZQWyyVPlf1ePAmfN18PeTxq8VUehwgUzhFBKAlEudidONA+sBX7e6qVVJXWHS/oYx4D/NvDOhR1iy1sjvka5U0vTA8+/hnurObWza1mXqNl61J0+5IjsOpEgFa3zJ9z8XNjnJoGvIsfowoZKXeJ24+WwyWnINdGpbtU8lc+5afXp8sYE5kk5YnkoMJjxthMMP1/uaPFytirCS9k5ZTB1aSO/j/d/5QApWzfbGLJz4SLqzVDL69BAOeRH7Pvx90/R3Yg2A== 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=TiauhuQgoZUrngSfov53exe9RchItISFGYggMsssLLM=; b=BETzgxdiu/SpH1OT6/KXPRAMSdMfGg1nGwwPn5ksI6hR/hgKUpXDFEaTuwmCo+ngRt07+x8r26JJgGkN+sEqIggN7fOqKz2InbBRbNqTMqo0rvVqpbBZk0JA7DJBqBzDA5nWKKVHN4Ibe5J00gKSoin+YBfViU6a5J7xtXzOeC4j5eX7jRZ5ihxNtn2OavmDZ4CB0HnywuKf9khrl0gk7d2tn40TO8nJqZBRfZFvUtQIVDdJS3seWJb7AfLtZ+WzatywBjYiqVdog92HX0KNHy1cs3fpJ3ZgJu6ABkIXGY0vn2iziHEYZ6nlh9eag0aS9YRECrSDOabGZig7ufVyKA== 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 BYAPR15MB3141.namprd15.prod.outlook.com (2603:10b6:a03:f5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Mon, 2 May 2022 23:09:37 +0000 Received: from SJ0PR15MB5154.namprd15.prod.outlook.com ([fe80::b5e0:1df4:e09d:6b5b]) by SJ0PR15MB5154.namprd15.prod.outlook.com ([fe80::b5e0:1df4:e09d:6b5b%5]) with mapi id 15.20.5186.028; Mon, 2 May 2022 23:09:37 +0000 From: Delyan Kratunov To: "daniel@iogearbox.net" , "ast@kernel.org" , "andrii@kernel.org" , "bpf@vger.kernel.org" Subject: [PATCH bpf-next v2 2/5] bpf: implement sleepable uprobes by chaining tasks_trace and normal rcu Thread-Topic: [PATCH bpf-next v2 2/5] bpf: implement sleepable uprobes by chaining tasks_trace and normal rcu Thread-Index: AQHYXnmxxCe8fRcUS0a8mA9+CnJfNg== Date: Mon, 2 May 2022 23:09:37 +0000 Message-ID: <588dd77e9e7424e0abc0e0e624524ef8a2c7b847.1651532419.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: ba10f5cd-7629-4daa-d5fb-08da2c90d45f x-ms-traffictypediagnostic: BYAPR15MB3141: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: WB+xWpf5BMDhitSYRmKLPowtySsnH31Dn1gUhUZ3jpYTjPgSmUthGuPvibS9vxPnUS9PNFnJChyj4QdReNazLyE/LDrwfaH6OcgD/1GSFIOHdXu5+iyU9QYwxdbsJVolqAJaTwOMyz20h9DwCM34ms6f/oEzY6f1W8F/9FuESmPsVCFWdmFOjpwOPCrVN6i4FMVKcssMJgmsONzeLm5y3Dz6KdBq9OKH0WJeamorDOh6Bfplg1USZ77y3eOtKtVKJY2gQx2uNh+Eoi2ImadsyguAFNvQpBl8B5Fa5J9OEU09rNb4DtRPEWTcMdDjJTVRlHVhtsFPvKi4Wvn1wLw7yPiod0vZ0tqGqTnXvwksCmQhwRo9FJ7CDIKSxSwfTF7KmM4KFz7raNLPygF1sDoos9YI+VRkqvDQWvkmbWX2pYMrKzYZWoGclrmdfmJ9lQE+1yF1OZ4sJ9OXfkdF3tFgMyFBnvJNfxo5Qof8FQ5Dfd4A2ItzCu1kGAsvByJ3E0W7s7bQ1NcgO8cNVGJu/u0onUKFUyc4nr3dSWKi39RL/tSr25wlYsuIPSPN97DDyOEVewYW7D+6IGbo1RWzfh+FomOBquTm8Vw95Dicn7MsAGiaUgeHxW3t3BFP35IGE373EKYXFdvVynQFZ7cXkTpeR1Hu8zptyhyZpLhRYatDEmtMqRL7ZtLhMuiRNKmPbJV26ivDuNNd950CVWNGiEkxig== 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)(36756003)(122000001)(186003)(110136005)(38100700002)(6506007)(38070700005)(5660300002)(316002)(64756008)(76116006)(66946007)(83380400001)(8676002)(66476007)(8936002)(66446008)(66556008)(71200400001)(86362001)(508600001)(2906002)(2616005)(6486002)(6512007);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?xxRHFVC1EY2eeUkfGdHQrKS?= =?iso-8859-1?q?McqHAQWynZEZZbg17r9Rcmq0hyj9aOCwLAwKLOdEl6wGyLhsu8tp48Yjq2qb?= =?iso-8859-1?q?s2XVwg44rWWfyTTaoMVB+jaDk4bsG7727aY4AofwkKyidUtbrccX1CMnknym?= =?iso-8859-1?q?60s1paA6JSTabDdp5VvV3Fg0n+n9xOQdy5Pg7Oi7rBleb9IbLIx6n1ER4ltv?= =?iso-8859-1?q?XBhBMQEn4oc7Zj6KMh1dcSJdvZdvjB7AriEqq+XfSFlDRlA0mk1HvwCXnv3E?= =?iso-8859-1?q?I//PXdCi9pJHvWgixaXNiMmZP4lpPZfA5KEl5yhNlYiR3NZbYCC3LoI2CDQn?= =?iso-8859-1?q?/FdDTOV+DLz05W4sk0qFpOkt8Xjt6TBpQQ9OE6F8IK8X1D3NohJeoFSC77PK?= =?iso-8859-1?q?0FemyNfFeEUXC0A8VMs5y5FeQ/ENnY6+K1QF2CXe23u8wD5qa2RNxhV5GQKC?= =?iso-8859-1?q?LKmUpmb97UpBF8rRgfmkgxDg6WSVvJ27CV0fGX6H3WThCJKWjz/oBDvhcjvi?= =?iso-8859-1?q?00u0e0s/5FVMHYjQ6gBc2wjNh1RxTtvSHGYBqHEnpLLEbOfkCo5XwXqzWtyx?= =?iso-8859-1?q?ovl3LWvdZsfk/22tYtmR9JZQ0l8NJqo7Wj4xAs6EuI1tqcb2ODSn+I3OFDJ9?= =?iso-8859-1?q?7QK6aVT1bg6AaBcGx9GpyIEYM+7KdMSF4zYd8Z1ptVDa0V3p7rLatLizx4HI?= =?iso-8859-1?q?tPcoq5BNbwHYGusUkMXqe8SNv8EzAoB3S9QtLOqLj1/ynSO++Ljypb4wWjWr?= =?iso-8859-1?q?n/vEKE/73boit12a+HNv5XOhpColPf3RbY2RNb0aJkfr6s8PI74PieeBQ2tt?= =?iso-8859-1?q?hHj6jDV4koZp52HKyxyZJNZZRjNTSOaMjq2yRZShyCxU38taO8upinHDITrV?= =?iso-8859-1?q?KIIN0g4p7BkfuF7Lb0xhqPtoMb3/HLbobtGqPyBA2YxlKUvRll/sujBrvtiP?= =?iso-8859-1?q?U891UOnmQHDd+gBlFRUnAK2ZWLyi8Cm2yoPmm37Cd4UMh/qjzzTyx/4+RpGt?= =?iso-8859-1?q?Axk+BhKzi0nPzD5o/pIruog0r4a8xGVAy+CgUDK7z8l4qsbxQv7lESl83nbh?= =?iso-8859-1?q?2fyPKRY+U6Sl0tlrhFv99BVy15dql1w687OVUeICEWi8TcwKeGX5Q3gsR8Dr?= =?iso-8859-1?q?iCzqnRGHfU6bgB2J0lc/19H9D0oMycrbp15NAcn9Ev6Wf2Bkfyh2KTF4kz0p?= =?iso-8859-1?q?tAN1MajI1HwR74Q4INeHqHU+tW4y6DwdDda1g8xVeDXTvTcsjbaTO0KFILS4?= =?iso-8859-1?q?j+3wRoQkFzzAgpfjRzebRXrQKFZJZ/YfS3BVuahStZ3A9+mUmYilnK0GHUvi?= =?iso-8859-1?q?jUAybD9PMhU2xlhc0Cc6cW/12HUeWrucuf2RN870Y4bemccgyYqTFt8qadXq?= =?iso-8859-1?q?NHdkbUz68EdOTxxXqEQway6Ld5zgFYqhMbPPAWqHCjXIpi3bXwpZhpG5/U8p?= =?iso-8859-1?q?P8tUJVehrJf0jKi9q7QpYg9+bVbZnCioLvGFOc21NWLhF4Lt1PU4Z3kMqvIu?= =?iso-8859-1?q?PSKwYYQvwNmaXTJnSicLDrauvR/Sob7IM4Xwy+WlMWPIL7XNuKF1M5pJD/rk?= =?iso-8859-1?q?3B8XthYf2qAN9ILT8W3alFUrOrPwCoDC3unxJFLVTA3DwLLRI3dgx3AjIhm2?= =?iso-8859-1?q?fPUKEltElFLO6AJwUEfSJPM6IFTvxmJS3BHiyL99gthx18L9zi5L5zv3oCul?= =?iso-8859-1?q?5QIipjkwtoXBCZx/VhWFqRPC3gn2nQ5slyeKqF48nLO7K50UGhOgwMLv+sHi?= =?iso-8859-1?q?RE8+R0esNsorMdC/8rSaFxkBG1pCDoItJtsGQYjJdtXrBmlVc/PBU35zwQ2E?= =?iso-8859-1?q?a6uZbQFxM9WbCDFX48mImz5bEAZpc?= 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: ba10f5cd-7629-4daa-d5fb-08da2c90d45f X-MS-Exchange-CrossTenant-originalarrivaltime: 02 May 2022 23:09:37.3483 (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: 1A72QtRVQspLX+aYC04nEP5pjGZFhtoCTYRaSUToAR4ag8cA9/VkOOlUZiEmTb5s X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR15MB3141 X-Proofpoint-GUID: jjfHr_S5zoJR0peNXnt1Cd_5oPt5O3qj X-Proofpoint-ORIG-GUID: jjfHr_S5zoJR0peNXnt1Cd_5oPt5O3qj 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-05-02_08,2022-05-02_03,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). 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 for all perf_event-attached bpf programs (and not just uprobe ones) but 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 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 Reported-by: kernel test robot Reported-by: kernel test robot --- include/linux/bpf.h | 57 ++++++++++++++++++++++++++++++++++++ include/linux/trace_events.h | 1 + kernel/bpf/core.c | 15 ++++++++++ kernel/trace/bpf_trace.c | 27 +++++++++++++++-- kernel/trace/trace_uprobe.c | 4 +-- 5 files changed, 99 insertions(+), 5 deletions(-) -- 2.35.1 diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 57ec619cf729..592886115011 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; @@ -1343,6 +1344,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, @@ -1428,6 +1431,60 @@ 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(); + + migrate_disable(); + rcu_read_lock_trace(); + + 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) { + 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..9271b708807a 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -2268,6 +2268,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 f15b826f9899..582a6171e096 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) { @@ -1915,7 +1938,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); @@ -1941,7 +1964,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..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 Mon May 2 23:09:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Delyan Kratunov X-Patchwork-Id: 12834873 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 18B08C433F5 for ; Mon, 2 May 2022 23:09:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229556AbiEBXNL (ORCPT ); Mon, 2 May 2022 19:13:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229445AbiEBXNK (ORCPT ); Mon, 2 May 2022 19:13:10 -0400 Received: from mx0a-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96DEF2F386 for ; Mon, 2 May 2022 16:09:39 -0700 (PDT) Received: from pps.filterd (m0001303.ppops.net [127.0.0.1]) by m0001303.ppops.net (8.17.1.5/8.17.1.5) with ESMTP id 242LsRMZ014107 for ; Mon, 2 May 2022 16:09:38 -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=cOQEdGfjFBc0fQXLFHIZS2Djpy7PTKGsd2sNcXs+11A=; b=XHVaaNr99juL9TBA7/qYV/PS1876K8h/dgqZmWUidbhuQriPqwilC+teMp7Rm1vnlzrw BfwicAQ8qhGVEfTyKErErXlf5DPMpfF4lqyyms+X1LNtjkvFd1yxMf4NynVQFCsQe/BJ A/P2hDk4d9tGlXobBaKQJhG2plxQsu8rIjo= Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam07lp2047.outbound.protection.outlook.com [104.47.56.47]) by m0001303.ppops.net (PPS) with ESMTPS id 3fs0sucuq2-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 02 May 2022 16:09:38 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Vc486X38OgcLVeLCemoPEqy2ER0SSjFDVSh6BQDb1XkiVugAZ/cNBjXn8TWQAOVAUYpdgzCcS93fF2YuULy0+Z3U/qc5G00/ScESiKueoNGLkBoPoA6IVwErUgUXZJdxsG66GyjG9RlsEnPzrj2edOXLekKD3jNQjh55zwxz2Fu4S2o/bLvY1Gz7AA/71ENaInUf1Kvn8W+he0dSrkFKW3v5IxXknoVb3YoqFDCEYDqQU7GYYcBFCRozNkv8wqBc1GzdDQt36G7iZcYSr1pogmEzup7eMHJVC2gedxbD6p/ZKA3Ltpy56Y7S8FfUreLS8o7wj+/8aJ62BktnMKQf6g== 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=cOQEdGfjFBc0fQXLFHIZS2Djpy7PTKGsd2sNcXs+11A=; b=WdgVpjliGnzvw6DzXrHqkOQOXV6n7ApVz6eF7Y3d3SghfCPfeKaOXbFIYtgPBH/0wU8YmMhC7rB1ll6+F+/uuHy/Dam5DVN6B7ts0x8ZOecZ8U4GrGtKS0GhC0RH+DquUH6APfAzyxrxiZIGTCg1xjATolyzPMTjtgx0eMnJzpFTLjkqI8V9TDSNdLigoVwdd6miWvGpXZ4ZDYBpYaLZF+Bv2t2ntJhDMKIXWODsbh7Pmtl7XG+Qb8gUmVDvt2JHvvqxseMjGztRw52RXGpFcW4ccjXxAJNDY2SxlFunkfvpVe3cLWJ62zh6ZcAxWPs8VJDp7m0BVNQaPFkFiTANzQ== 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 MWHPR15MB1903.namprd15.prod.outlook.com (2603:10b6:301:59::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.28; Mon, 2 May 2022 23:09:36 +0000 Received: from SJ0PR15MB5154.namprd15.prod.outlook.com ([fe80::b5e0:1df4:e09d:6b5b]) by SJ0PR15MB5154.namprd15.prod.outlook.com ([fe80::b5e0:1df4:e09d:6b5b%5]) with mapi id 15.20.5186.028; Mon, 2 May 2022 23:09:36 +0000 From: Delyan Kratunov To: "daniel@iogearbox.net" , "ast@kernel.org" , "andrii@kernel.org" , "bpf@vger.kernel.org" Subject: [PATCH bpf-next v2 3/5] bpf: allow sleepable uprobe programs to attach Thread-Topic: [PATCH bpf-next v2 3/5] bpf: allow sleepable uprobe programs to attach Thread-Index: AQHYXnmw6LimKPj6okKMdit4AKAiIA== Date: Mon, 2 May 2022 23:09:35 +0000 Message-ID: <611d4629dc959f9d327693180b0d106dcefe949f.1651532419.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: 36ddf96c-6815-46c6-2df8-08da2c90d376 x-ms-traffictypediagnostic: MWHPR15MB1903: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: FJ8JIty3RU0yLHXfPRA7eDiAiJQfMx/QdB8TqDUcdEwQi+ZBnLckLPcbLspktLv65kM2A5grOFPTEPRTPMRzCa9LP1Q3fHDhiuLseAt6xWhsC19AX/FYLAU6KyzyZB3Vqe9aNSen9Q3vtyyTFKjaTeuvBWYvvkbXJEbwYV9cSvb/3ay1PPf9qHuqBXW9j9eew/jzx2fnA1PGuQpGjez+I3BozSiPLkxsfaInhHqw4yvHbv/zjVnuhilTBaST9zbJk5TwjTy7R4GBttb+lXaKEU8vut3EdTNl78ZYRXRFZ0nmSbHQ8Zps7+TI4HszrjIQdRUHS58/FKAD6xN9S1rII9ffeIhtpsjsWGstnUAsaCscorki150/TvmFjI3v/W9wlpIdgIini906k8qXwf3jLThi05SXWtHAEwq78f7+V1SN+89m+6UmxgmLNxWQwY11wN5GChKi3QAlT5imWcLhFWDXx3lFF9UYpt7nKeRJYvbBSoS5HSoxMeLD7MCJo4EInSqbLFYjb2dzLM86s5V04d7I03v7bwBzIMR4rVACfJz+BXEwrVH3Z4OSh8P91xvGjLr76edMuIxTjYEAU9fAnXOOrFfLqwu8fZCVrG/T/1bcmcd2hhYn+3JzJFMY49Iwd8olBZr2mscxrdzA4TQ2vcIZ4vfcYjRMQ5BjrTU8rlTGqkALDCqbcw1CXycVnbxuXGWRciRyC5dA62T2ZbMN9A== 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)(2616005)(36756003)(6512007)(83380400001)(186003)(2906002)(66446008)(8676002)(76116006)(86362001)(5660300002)(71200400001)(66946007)(6506007)(8936002)(316002)(66476007)(66556008)(64756008)(38070700005)(6486002)(122000001)(508600001)(110136005)(38100700002);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?vW9rPiZ7uq+l92C+Rjgy6+S?= =?iso-8859-1?q?Ph/vAt7Q95pzA9BaaotQN4s9WObvZzVDM5u4z3kDyU3l4eoH1pwNtI05oxRc?= =?iso-8859-1?q?1hFREGH/XEJ5MSQKmJyGAeq536IVqw5v9V+LO4MYdYKFHIn7ScDxcBUy53zw?= =?iso-8859-1?q?p6W1nv3CxcRReDsvKMqkOMG9ScDbXziO37wLz9rhcyAaQLm1iZPZDLyDbooV?= =?iso-8859-1?q?KGz34azqZY5QvoR0B0II+xfTjGa455R32jiyb7DjqJg+Lekbdj5jHvH2+PKl?= =?iso-8859-1?q?sDyimMl9bQB3ShDPEFuuyiNi0HEjoLg/z8damXDpG3ZANzVjMNjOfIMKQQyt?= =?iso-8859-1?q?DUIuenC1EnPgyUXtpOP1Xa/Ye7Bzjv55X4TOFJnl1isYI0l2lZ4dK+ykqkbr?= =?iso-8859-1?q?xu1+HDO7nSXPLodDLrdflNZfRhJK66N0OAHAziVY3zuy99NLZENzS41uFVF+?= =?iso-8859-1?q?BFhwINm4IPYE+iDgtT5qwrhZehDP3wDHbVqIe6sGX/K8LDnfCX4+K2eGFiLK?= =?iso-8859-1?q?WjS3+FdJmzauYxHV9ovhYAOa+6JZdXKnu6BIimcH6ZujY44zTHitySKdP4Ud?= =?iso-8859-1?q?oaTD8G46wK0EYQosYGU2ikD09ZkBdW+C74mXw/qcnbkoEJ56lAxbVJFt+ZdD?= =?iso-8859-1?q?GJ8FmSMYdK/sX+uU/yTEexNI4DS0NLcrySsg9wU0u/vAch9s4zNufZI5KmBZ?= =?iso-8859-1?q?YiUe5lG1EvsKYUcRYBMlnBu9J/xv+kmnoyyof3nyiCTqG4o1d2avpXW8kAzN?= =?iso-8859-1?q?GKBdGnm5CTyTc2uVrS5RWlDTyJ7kybpSfE6IXDhoc3s1WwnHCHOX2NSq2QoG?= =?iso-8859-1?q?HRvW3wFFArKUxSP3Fw9xmQin2audxSvUZrMb8g+75774t9ZmpISYQbw4653q?= =?iso-8859-1?q?et/6Y42Ld90ziF4fX48Sw/Txswu6noAplmfU5AMvFLtN0gkmyxDcysNpjOA4?= =?iso-8859-1?q?Hpg4tZrZeqXpAdbcJyiNvgM67TXWHdqidgmO7xOfZIuJbJgB76RzQ39p+Kry?= =?iso-8859-1?q?CKFcnfnn5MvBBt3gI1wiQd/NHx3QY6/0AURDPKRUDZP553ZWzjVb5S6rJJPs?= =?iso-8859-1?q?E3ma5qQLBdR5g5diVseLMCYGzergH8PR3SOrIHqXTl/Luhwxc5icmse4JsVn?= =?iso-8859-1?q?BM3iSBaj6ARq2M6+CpzhV/r3b4unR1FV3e0FVapUFztwW3z6/WeajHDGb81c?= =?iso-8859-1?q?H2Lq/3sf7+w5CbSbd2vAInMSrVJKjYfONYk5GKI2+ijCsSGPyXuTcWPDXYRB?= =?iso-8859-1?q?gCXQqsDtYg31IDLM+MnU+HdQGkFeEwLgr+MXNkF82ni8JWSwDGcZzLWKoRMa?= =?iso-8859-1?q?VclRILjpklvDkjt8OlUUlxdSVsFTgAnJ6ZigtfVYGC49149w5nj7j1T2TqVk?= =?iso-8859-1?q?cJT9X5w22UpWm/LSG9nRYBfqQV/ehLZS3e7HZzQmwj2XRbMBvpDATFrYnZUG?= =?iso-8859-1?q?o54UQUq5XVtf2TrZJZPRUe+QX3F7vHxCkXbkw8am6h217lCmAqtuhKUnRqMU?= =?iso-8859-1?q?1bWY5FO1LkNRS3n7aBsqnS/S6gXvhdyYUrSMonWWD4vwSxl1xLSkR2V3dwyF?= =?iso-8859-1?q?Iw602ohVV37wZjKIHzi2O3KxwsNlLX15xRJMDQ2ZUYe+R1pEfEgj1GuHfaz5?= =?iso-8859-1?q?j07JyjzylYvdSl7lRcoLBsqzkgGEoYt8PkevGbdPWuELDl+vOslxoDsmOVNR?= =?iso-8859-1?q?uu3eUQhfsHx25XhGPXghbIpGoX+KTxPWdzICUrToPmLtjJpbvLtzMn0MJCCt?= =?iso-8859-1?q?62AmY6YnruguGOmfsSWVxi/QEY3L4qgj366+G43Y8oKc69srNr6YV08uuIfP?= =?iso-8859-1?q?Jt7ufeUNAW5FzTyVbqI1PB/UO9P3V?= 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: 36ddf96c-6815-46c6-2df8-08da2c90d376 X-MS-Exchange-CrossTenant-originalarrivaltime: 02 May 2022 23:09:36.0372 (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: akjbHCtb8h1hZOoU+vUZl3ZwDIrWDIw6Q6CepF+oy7drsD2j9g2AY5Mo4a8kqvzJ X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR15MB1903 X-Proofpoint-GUID: Zoy16mtMueSGGrAulwo_-NPxBkHxmloa X-Proofpoint-ORIG-GUID: Zoy16mtMueSGGrAulwo_-NPxBkHxmloa 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-05-02_08,2022-05-02_03,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 Acked-by: Andrii Nakryiko --- 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 813f6ee80419..82b37a1a8a33 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -14571,8 +14571,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 23bb19716ad3..bd09c4152a3b 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 Mon May 2 23:09:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Delyan Kratunov X-Patchwork-Id: 12834874 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 DE918C433EF for ; Mon, 2 May 2022 23:09:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230305AbiEBXNN (ORCPT ); Mon, 2 May 2022 19:13:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229585AbiEBXNM (ORCPT ); Mon, 2 May 2022 19:13:12 -0400 Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0D632ED78 for ; Mon, 2 May 2022 16:09:41 -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 242LsdoG001183 for ; Mon, 2 May 2022 16:09:41 -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=jVyssEgTJJ9C9I0Q04yH7v/dhvwLDX9rRjAdoj6a63E=; b=VMpp9eBi8W5EC5HE8NwerWA4ZT0p1z5PxXSDw2BhuhOkbkcnrJBIcxoITzjCy1HB+UEB FXu9mszU8W2Dmau1H2f2EhDLH3/j6s4+ABIX1KgZ1D1nzKM/3l2JmkT23S3eJmYFJNR8 UqolHcUSwEh7I0xIEq+/pVnOtYmgWflbTEg= Received: from nam04-mw2-obe.outbound.protection.outlook.com (mail-mw2nam08lp2172.outbound.protection.outlook.com [104.47.73.172]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3fs2mxchjh-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 02 May 2022 16:09:40 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PnLmT9g1Pnpr5++WW4NRwNNaNmRjwY1KMtOambWghXUXUR90nHy8ibV+cyJJ5CG3SVCA7ERM0ZNhtx0/7DYiWnSUp2PxCGh/RTe2Ja9nmbuP/G6es/7FLq8WfdEBKRDwjnX/hfBo6GXtLg5qzriQDZBqiNlATrJMExbqJt7coGe4C9UXhf0wtqBdVtwRyk0S+e6hMMguMNV+hut3MNEPi0Tws4a5PySWEKKdR80T631f8/gCUhd6UCLdjmxG1qWxjJfkmvTiKDJvmx1KphkOdyE889vF3i58+RS8tEoJTDahsh/UdjaQDbUAdlSukujFwesyCZndF+uDaahCCJ6iIQ== 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=jVyssEgTJJ9C9I0Q04yH7v/dhvwLDX9rRjAdoj6a63E=; b=czMlqTT2KVjJSa9KDhBn3v5tMiSpepr84+D9cPOIJhmZLZ1rnd2bwUrZZVUZs5wrvgLApy++xjOvgW0UIBFA23b1cgOvFjXsLBJa/r8sCEKI+RaTRrvDbr6qAVhJVlaZHrsd8xi8DH39RcDicCnhZUZg93R2LqE05TfNDrtJkp3RCT+EdiXfM6yE7o7eDBjWcFM7gMwC74ReRUMguu0BYtuX3IaZIcT4Gd9nTbUmUxMg9THVNyoq5BHkXtC4+Gmv8GPcMNJI0wI4lvvQ6id5BIMiAJqarJJaWv+Yk9aZsgf4iul66XjjN2lhrO1V3/gDCbYb3C+aPeYiBGoagLt1KA== 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 BYAPR15MB3141.namprd15.prod.outlook.com (2603:10b6:a03:f5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Mon, 2 May 2022 23:09:38 +0000 Received: from SJ0PR15MB5154.namprd15.prod.outlook.com ([fe80::b5e0:1df4:e09d:6b5b]) by SJ0PR15MB5154.namprd15.prod.outlook.com ([fe80::b5e0:1df4:e09d:6b5b%5]) with mapi id 15.20.5186.028; Mon, 2 May 2022 23:09:38 +0000 From: Delyan Kratunov To: "daniel@iogearbox.net" , "ast@kernel.org" , "andrii@kernel.org" , "bpf@vger.kernel.org" Subject: [PATCH bpf-next v2 4/5] libbpf: add support for sleepable kprobe and uprobe programs Thread-Topic: [PATCH bpf-next v2 4/5] libbpf: add support for sleepable kprobe and uprobe programs Thread-Index: AQHYXnmx21JjhfMhQ0etNT+Dye61yw== Date: Mon, 2 May 2022 23:09:37 +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: da80a80a-46a9-489f-df26-08da2c90d4b0 x-ms-traffictypediagnostic: BYAPR15MB3141: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: ztZ6mUviKm48AEZ4b7rQknWKKU6NaMmXt5/XApJQSWde3L1FdN1tR+ngE6Zfl1xbKp3XMtOepEr9qy6mzxzLWvvLcVslbdO9uXz3egEY3HE7ZrQNkeWImnbnho6w2xxR+o0VZML4L3FgNsnITS+5hEUUu2YaEHHyVbOHz5Hez0kTxYPltBlEbvnXHydCqtRgPduq4rOC8uOZ9ZAtRQq7gGzFsTG2LLT6oH0I/fkUNNEn5IUOoIU8eNsY/mtsuB6rmy17mvx8iQeLUVXe3h+/7KNMXvs91WSRT9xf+lb16nuEP+mIpyLE0i2wVqOVgbVVN2iQb2GwvTQFq6jx22YllEwbZJAAyX4b+xz2eOuccHJVvi1F8Ktdob7ucnq7HZDVs69wSRtkTblXuc12vxPvjPrPdNVrXu73NQ+zV1Wud8o18CHXPRHj6fxfZkYxC06FXXwmaADOyrzD/SBMAv+OL0Y4MqaDcykuXxYj8zUI0rmOy6IA8BJIgX5ncaUtsIGp3VYtQNN1pTDuXgeAe4h0D5R70nWnOOfiQY6bTRWUBXktEGlDKK9OsiloSLu/ibFB30sOw7DvhskfMykW5z2ebuVAb0qMB1ZiLpoYaQIb9swgwvXgJ+Q+ORAdb5OeG68XkFXm2V2oDaVOg7aevWvM8ysZ18Qz4anlo6yEq8wRViGhUdAQe2ZcAozQ2xIhGyCp21T5XehLOX2uND6YDbrgQw== 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)(36756003)(122000001)(186003)(110136005)(38100700002)(6506007)(38070700005)(5660300002)(316002)(64756008)(76116006)(66946007)(83380400001)(8676002)(66476007)(8936002)(66446008)(66556008)(71200400001)(86362001)(508600001)(2906002)(2616005)(6486002)(6512007);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?yNKbSHhTNhqCwnbzw8sRdyt?= =?iso-8859-1?q?dGC7Es4hDkC5LitngJBu32WPpTtgH5n3K0JXlUJK+u518bKf8qupCDa/stt7?= =?iso-8859-1?q?FXs1w+zuCg8RsJisAP/YQBVsjL4Kxqn2fBElIHXkzpAD+CGQ4+OzQ+RUi4+Y?= =?iso-8859-1?q?vGJA9wjgr2UxMlyODLGTR54+5kA8HnkDJak0MAapDZNBSsk3V9j1rH86niBx?= =?iso-8859-1?q?DpSJYQIAhBrb5JEukjYUNNMYFDgTWhM5MQAP75PnLqXssMBV7XltlSfGTBQv?= =?iso-8859-1?q?9hHaONwHqXRPLeHFp06JakPrXHM4BMuEvd/ZwH7D7ppnsy1YDMmR5JiG4Cdp?= =?iso-8859-1?q?NVwOycbpJyc4OV2hF+btzhxR0FyRm8Mctf+2TtKDSYmx9biuy7PxHER1ivLs?= =?iso-8859-1?q?uQR0RQ/7v9kFbOk7HobdQzPIs3Ex9PUoTsxssb2Mne4VB9JpTjpKxFehsixp?= =?iso-8859-1?q?K5Zxmj7m5UGEi6kTp7UR+mVU+gEqWKGpt6E8edwBOlfg6c1APDnM3IOoAQRu?= =?iso-8859-1?q?JQYkno9uDh9D/uWyDVPTrCBcEHpR02S2Mei/20iqqS07dZb360URZhf3VT1w?= =?iso-8859-1?q?xpiWKXesNaPGyciNOcWiybKpXeWiBT8gIQn/L3jB5oEDz03ecWsbY9UZ71CO?= =?iso-8859-1?q?0Wv+Nr76g/eBYTfk0pvaohd44cD7Wytyo7TjybhHSaCSdIkusZmVFBikK7pT?= =?iso-8859-1?q?pthzGBhAGs9J+mAsAxYB4URx4NcbC2D8w8kynclZa3UtB/LY+Xn5E3KKiiu5?= =?iso-8859-1?q?lvV+nIxiv/Ue79rCWkRATNRrUAlw4Fnj4lMrt61XIy7p3Jwr/EnmxvhMTDz0?= =?iso-8859-1?q?jH0qoudlfyaymwLiyk7nmH6kXFnwNoRDLcWulnQd10zA9kQPzpakQnm/Cs8l?= =?iso-8859-1?q?cqgWyV0FBbl53scBHkGsNdMCtpOyaHcGmyIM9QWN6sZT+vNHkK+fhWBLg6g0?= =?iso-8859-1?q?CVP7mtsRUqpGh0Y7IgAaGAncKF7ohhK1wu41JICJp/XSg1XlwiIIX+21IDIA?= =?iso-8859-1?q?/jxg91NOftSdSi3ZJRTT8sA+zhe0HmKKVBFIrtcsu10cQexKPYu2lEoOdLf1?= =?iso-8859-1?q?H16Zq+eXg7guBlrwy4VDD5k4X7N9GBYkhRQ0Xv1xt6iNedMwZtRLUDZkifnG?= =?iso-8859-1?q?aF7ZHK9UrQAW2FGHKQmSUgV1UCZNQtyxCeCrJ63cYyuaxXehoY8v4P/8z6y0?= =?iso-8859-1?q?KFAyTZfo10oZSv4+4v98vjEcecXJRKGiMNtaOYuDSMBqLr96AShAsjKS9oP7?= =?iso-8859-1?q?FF1WVx5n70d00W2pBAJTOfMA9N2M8Rm3dkMSJY02xCpvEWON3gE+o7ObYwJF?= =?iso-8859-1?q?Oy4YHyoO21jSw+x5Z2Ry/SSlFvzs3rbYr0UvkkQaZOanoGX1GbNcsBNg3hfJ?= =?iso-8859-1?q?C4RJDxGLdOXzEHEPYAZbRZur/XuF+ne0tHU5OnWS2mEsit9RWrlsLD2WntaL?= =?iso-8859-1?q?k8TF33/OTsxhNiGShzoCN9EmiCGaJlsktIZ/+eglXLeR3WRBCbMyUDiKpAxO?= =?iso-8859-1?q?cb69KiS9fUpKWKmMp2MSGRI2VlPBRRM+QYs0LRVYfGPs69OUap8w9R8DwhsU?= =?iso-8859-1?q?52bJHccYWawejXs/KBXZmUKCsG7nS5j5OSKba+bkF5MrQTdWf9tAq4IVJg5a?= =?iso-8859-1?q?0FU2e5JZ59Ui7AF797fBhOlpCWF+3/t89ORa3quDhr7G3Msl+CWTulkeQRAx?= =?iso-8859-1?q?2g4JhGorWXd5u1NIgHLry6CX/ndGymSpl9Pu/fgm+T8j5e3vkHgQAsqmdfSE?= =?iso-8859-1?q?THiTlpsfmQicCd81P3tRik+V+xU0SgEPsD+PJVM12xr1JtMPYZotD8rPze97?= =?iso-8859-1?q?L8SZxmAFbOywToB3YAwaMD5o77D7X?= 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: da80a80a-46a9-489f-df26-08da2c90d4b0 X-MS-Exchange-CrossTenant-originalarrivaltime: 02 May 2022 23:09:37.7558 (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: qo9Wz38p0JSgvy5+SzEoCEVUQLHIqDzA12tsBl3mQ9SGUYkT7XvcfNviL6FNRR+t X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR15MB3141 X-Proofpoint-GUID: -prmlwM8vQo6TtIeOhqfPWa0yCxbRjKM X-Proofpoint-ORIG-GUID: -prmlwM8vQo6TtIeOhqfPWa0yCxbRjKM 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-05-02_08,2022-05-02_03,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 Acked-by: Andrii Nakryiko --- tools/lib/bpf/libbpf.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 63c0f412266c..d89529c9b52d 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -8945,8 +8945,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), @@ -10697,6 +10699,7 @@ static int attach_kprobe(const struct bpf_program *prog, long cookie, struct bpf 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); @@ -11222,7 +11225,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 Mon May 2 23:09:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Delyan Kratunov X-Patchwork-Id: 12834875 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 04AD6C433F5 for ; Mon, 2 May 2022 23:09:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229585AbiEBXNO (ORCPT ); Mon, 2 May 2022 19:13:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230207AbiEBXNM (ORCPT ); Mon, 2 May 2022 19:13:12 -0400 Received: from mx0a-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A1FB2FE56 for ; Mon, 2 May 2022 16:09:40 -0700 (PDT) Received: from pps.filterd (m0001303.ppops.net [127.0.0.1]) by m0001303.ppops.net (8.17.1.5/8.17.1.5) with ESMTP id 242LsRMb014107 for ; Mon, 2 May 2022 16:09:39 -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=HMfablRoep+/y1w7Tny77t3kBHOCjdFo/7gm23hCUK8=; b=ZcdMdoHGRXzHNQdMRZ48boupvzfW7F+vSrcNyO69+Xz5ovTKdD45c7byVY68x4ser1ea fvn4HPhOW9MUzHWVLqA5s+iv9d79sa3nxPRM8Y72etuRLCNaIJDy9+f5COz/uqP0hfzN GyHFMbkdT2eIoPN5pPbr4uu8GGjODmZBmqQ= Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam07lp2047.outbound.protection.outlook.com [104.47.56.47]) by m0001303.ppops.net (PPS) with ESMTPS id 3fs0sucuq2-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 02 May 2022 16:09:39 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Hl5hONbLKAVQ37pEGpfGfLNPfR0sWgKdVfhzBi2PahgLHP4oeFC02Ai62ZbCr1vU07jdYV8A38GZmqbG3rDpIFmMbqLU39zyRrPCBKEOkFrjOt5enBs3KKwvNiWYh5tAvyMVx7q2ToY2nKeUTstfSjjSG0WtLu1cgUQLSZaYlks8dkzJi+O6H9IUUFxRgcFqDH3+y1EbNCtBLDcofVhDJgwRDD4m1eJDnyij6f69TxJ1V5G+fKwGip92l3PKPcwfoRnBt48vehoE52TOp66bKswKW3WRk4uAovblPSbDC3KFD44OWaUhoXcMDDOGOw+jpmuyYuEzRsaNTmh53LHrUA== 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=HMfablRoep+/y1w7Tny77t3kBHOCjdFo/7gm23hCUK8=; b=irOVyl3SWKb95zN1w3fbw7841H8E5rzHrWZs8//2yXDoihtea/p5136QL1qZ6kdK/ZU/Yc82b4ra7J3U4/kbV8TYLUVYxJ9k9jX7wS8cFBOzR8PFZq768cbyMUOjDUu6S2kyUPtdRbEdb6Lvs6rz836SbeXYU0FCLrs0nVm14HI0AAF1231k7I2KZbRJL6WDMh0R4QhSSutALwWON9KXojRdguB1nvNRLFjKMR3QidbggpScKWQtMpP6i0dqfkG8lcPbudLu2czCYlDZPPn28wkNoA8yH63KxvHYqsP2mid836L7wKC3YqfeBwzoklbPZuONxRd4BvCEGoeYPashQw== 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 MWHPR15MB1903.namprd15.prod.outlook.com (2603:10b6:301:59::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.28; Mon, 2 May 2022 23:09:36 +0000 Received: from SJ0PR15MB5154.namprd15.prod.outlook.com ([fe80::b5e0:1df4:e09d:6b5b]) by SJ0PR15MB5154.namprd15.prod.outlook.com ([fe80::b5e0:1df4:e09d:6b5b%5]) with mapi id 15.20.5186.028; Mon, 2 May 2022 23:09:36 +0000 From: Delyan Kratunov To: "daniel@iogearbox.net" , "ast@kernel.org" , "andrii@kernel.org" , "bpf@vger.kernel.org" Subject: [PATCH bpf-next v2 5/5] selftests/bpf: add tests for sleepable kprobes and uprobes Thread-Topic: [PATCH bpf-next v2 5/5] selftests/bpf: add tests for sleepable kprobes and uprobes Thread-Index: AQHYXnmxf32KBia6pUayDYxFbYIsLw== Date: Mon, 2 May 2022 23:09:36 +0000 Message-ID: <50290e7abc06f4aa7ea355a7aeb64f059a998c7f.1651532419.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: fb5c8021-7a72-4524-24ec-08da2c90d3d3 x-ms-traffictypediagnostic: MWHPR15MB1903: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: 0eqNKzjugUBybJpFqhvhJydgdav9GupiTF6zHfI5dlX/r4Z0nBEipbe9gzHXzCxdY1thsXoaklJCb+tovtd3OoVdO5f8s0wqT+2ng/drd7bxHzfLnd0AoVIA6ZnwnSEsN4Oo+B/HwCU5L+rZlG1HKbuc13cUU1b4njma7sAcO9e6xDSFsCD9ammOaSctGtZPZKyOO0t1CXHGK6EbsSTJ272q7c+HUU0aXTVQfzK6LpXf5bQnZnHtrKX16VtAJDGOE5I2Em/IvDzXf8OySxklxiBMdZ9X19sgyh8Db996UoaqvjwI7/HMVgsAMK0vKx5SQaGzh14Dx66/mFsozkM3GAl9zB/u7AKqJl+AdwrFTwnyT7l/QfxZelCIT5eTwJKB6LGyxewFjT03F6ndCErVQ6MYXX28I5zfiX2Bw0w+oFodhr5k2opjaIHuCSa/cSoqBsDLrsKFCUrT1WflF5UyB6tCh9EBbGzWaOVHlKYMjLcJX1+qk/6DmPGsVNWiT+JpedPwHqMJTHVckvD2rlgQGhYYMMjbLYDqpAY7d3ZzQQnmgunapdxLKtQCeeasdX0Mzh+fEFqfUmnGkBg/8E+2gRuHNkh4BQhcrwoQreq5U9bcVx4LLBHx/iDgjxlY+VZy9g7W3RSY72toWypTYjl+TGw9dXktbn9P/ix6JTAjM5YMU2YAJzT1aW1gvCIQRUrCbUbiNgJRE4PvDnxU5Hus1g== 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)(2616005)(36756003)(6512007)(83380400001)(186003)(2906002)(66446008)(8676002)(76116006)(86362001)(5660300002)(71200400001)(66946007)(6506007)(8936002)(316002)(66476007)(66556008)(64756008)(38070700005)(6486002)(122000001)(508600001)(110136005)(38100700002);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?0ui4LuqjBo/GNudpzLpkcTl?= =?iso-8859-1?q?giCS/E8sBA348akuT3uB9jsTvHogkOsxoB9B47hekhnaFeGf9vSpdI1yqO7m?= =?iso-8859-1?q?1hyuqjjbCQPifAseyOD4Y+RKPLEOnkfdgJY7BpscAqVswLyXJ5K/+6xALSPk?= =?iso-8859-1?q?dCxAkN0dZ4bFRTmY6SfwmlnugNmdtW8StlgNhnahc2LKNy+y+lWIlIWUQlcZ?= =?iso-8859-1?q?HzfSOX2uQmn85mzb3TqYp7qvY9zMy3/HNJed+Y+Nde1esVjBPiyiG3gsJ8sZ?= =?iso-8859-1?q?PzTBLr2oaDn31lCZ/3QDpkDCpI5p56MxT2xhyA0SHbcyfHy6U1wnUnk28xT/?= =?iso-8859-1?q?5HxhW/HnA99RM4TUuPKTrFif8U+wX1BKzlgyQ3ktG/gGG3yeWqkyQHgCh6X2?= =?iso-8859-1?q?0zKzJnWe7CI+pQT9Uc8Tta2YKbEsAeUoC1keyJi+0G21zorKj97HFO8MZzih?= =?iso-8859-1?q?uiuQUb3ffHg7Tg6QW5hUoXh0f//iIXQwV+eUnsHXAXB9293DDdf2r3ij1Zse?= =?iso-8859-1?q?H4aOReU5zUrEb9wo7rCyyVzrVXW+i7XUvDaSYij/vHKrTUm1zhKGSKI4kuAt?= =?iso-8859-1?q?R2Jyxp7BsPGKXCNYy8dOZfGu2mm1ZuUyQ74X0zeOz/OOnhe6Vo9KoLOC3zlK?= =?iso-8859-1?q?6edrPP/4UG3sMI8L6y4qskbjSdncPw2vXgWhe8ug1SOakcG/pTd4iJOiXYNc?= =?iso-8859-1?q?mfsMOAJS3mXi07gm7G+63jObrKocVqaz4WZ5kfvztXyY8tPgg5Dg/oi5UuA/?= =?iso-8859-1?q?Xksj/wzRKms4LYFNaWfz8lweyCPOJlz2k98qP1M0iurP694lJRFYmvCMFV42?= =?iso-8859-1?q?HUBru+OSPCuC7GtlWCrsFOpIPHQJ2UvROoEj4nRen1GIQBzgMb/uL9XSH2bn?= =?iso-8859-1?q?97i575E3KEiEI+ziTZ0pN4zt94dC0cmQWmqbMZXC4xXV4MaAmuq9jjO95Cw0?= =?iso-8859-1?q?BR+Ni7PSlmVs7y7Gz3YfhJalRg/Cs68g4ig8QWRUOfFqqd7FPTCG6rgdm9Db?= =?iso-8859-1?q?AzU0eZ+IdY4nSBQsAAWnlAZCG27oQTR/0XhGHkNp8i8AaatRz4B854UPZMSa?= =?iso-8859-1?q?eVFjQuHci68wogv26Cmk/0IECLSP0/xChaPP9lbgy6S49TP5KQvTfJ7UE3dG?= =?iso-8859-1?q?tulHq1Lf2uqoOXJMFiokZPhf0ZoWpAfkL2FmTkZzbPMHV2bquYulJgxGNcLM?= =?iso-8859-1?q?yFBVzOE4tluFHtdu7sI8K0nb6bNZVZKvhEn0jPGmOjCoR4JIEfSbG0X9jHhb?= =?iso-8859-1?q?15POYJ16g7YJOgNgsLu/xTUw9/dWN1VSOL/hPV+XYM7JTN+VkybtUUg+PTz5?= =?iso-8859-1?q?eubb/TKN9w2ybMVckmeYfbYFvsxMXrM6/Ogc1zTjpFzhwM7zmuOfvBpEVIuh?= =?iso-8859-1?q?AuRGgldr7ZjhZYMFpbSaHIaWpe21rFofs2EUatLbUtuzxhFUyBTX4ZytsIUS?= =?iso-8859-1?q?SohSuzjvcQpjF8i0JelgDcqIN05AGkFSwGwIndmP6t2RkM5njrGBSepayKau?= =?iso-8859-1?q?dkAGu7vCTKA+an7N09dJy3o6Vbdh9hWlPOT1qi9lintaBlhRlTsXkdJGxs5q?= =?iso-8859-1?q?GEoaFH4oNh1Ga2CN64R2z68kWp9WVgGm6yUZIGjPce5/BU9V2FxvB3nfeMvp?= =?iso-8859-1?q?aY+rcnvl3IJbEgTRZGAZZowtgLox9fX46T23QmI0qsqoUBT2wWhLqX3Zt2R9?= =?iso-8859-1?q?MbbQ8RVfrQ5BLMcltMdPMQj9LomF+OgLwOotbgoyRNJz95C6zbl7iaEMMMdS?= =?iso-8859-1?q?YMDVXlSiYYfLoy5MkfxvVYaavfYCUs0N/oHtBkd7LlyBGmHYkwgF1RW+6Ybs?= =?iso-8859-1?q?E8LNZfrjiGfuepRvMau/oZnygjre7?= 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: fb5c8021-7a72-4524-24ec-08da2c90d3d3 X-MS-Exchange-CrossTenant-originalarrivaltime: 02 May 2022 23:09:36.4902 (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: ek4aITUiOmJ8CqalmCgaOHUCVQ74SPPzZi8dqBk2dzUP+7kKhlqKA55U41nzhZCp X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR15MB1903 X-Proofpoint-GUID: DJ_FnMlJhV3PaR0dfiYzwsh4QEH7_J-T X-Proofpoint-ORIG-GUID: DJ_FnMlJhV3PaR0dfiYzwsh4QEH7_J-T 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-05-02_08,2022-05-02_03,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 Acked-by: Andrii Nakryiko --- .../selftests/bpf/prog_tests/attach_probe.c | 51 +++++++++++++++- .../selftests/bpf/progs/test_attach_probe.c | 58 +++++++++++++++++++ 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..cddb17ab0588 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); @@ -27,6 +35,7 @@ void test_attach_probe(void) struct bpf_link *uprobe_err_link; bool legacy; char *mem; + int kprobe_s_flags; /* Check if new-style kprobe/uprobe API is supported. * Kernels that support new FD-based kprobe and uprobe BPF attachment @@ -49,9 +58,18 @@ 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 */ + kprobe_s_flags = bpf_program__flags(skel->progs.handle_kprobe_sleepable); + if (!ASSERT_OK(bpf_program__set_flags(skel->progs.handle_kprobe_sleepable, + kprobe_s_flags | 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 +169,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 +206,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 +219,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..5bcaab2c0c54 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,45 @@ int handle_uretprobe_byname2(struct pt_regs *ctx) return 0; } +static inline bool verify_sleepable_user_copy() { + 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";