From patchwork Fri May 13 01:22: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: 12848279 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 AD9C1C433EF for ; Fri, 13 May 2022 01:22:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376297AbiEMBWq (ORCPT ); Thu, 12 May 2022 21:22:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359866AbiEMBWn (ORCPT ); Thu, 12 May 2022 21:22:43 -0400 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E32375468A for ; Thu, 12 May 2022 18:22:41 -0700 (PDT) Received: from pps.filterd (m0109333.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24CNMMKP023307 for ; Thu, 12 May 2022 18:22: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=M9Q/n+Ot9L1GEPwpFHfJyKZAmawudyNltWLxg/yWo7M=; b=iUCZNgOTWz30tPudgtPmT36udOaQBs7JLvx9L2sBfy6UKMJLKUTng14jH+rn7Ea4M6uF DemI21dKVqEJPNroTV5Z9/bODusn6iwss0eOTFJk+6Hbfm1/qFuzB8TIKwxhfA2eDab/ baSKRSSkz7GZydvELivlbRMCeN70HSqaCWw= Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2177.outbound.protection.outlook.com [104.47.59.177]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3g17vytvss-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 12 May 2022 18:22:41 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OXKotopHq3UH7/XYFrPsVhoiTUtv/Zem4EhmSBsTnJfH0jKATdgYnIstdXlc6hQ+wSRJOQIsBxYmyyi1F54yZsK2owNkBAMYnC8mldo+iWFjNVbs/RnDJnYhuWCFCQ0CwuT3TGW4nODi2A5flYlO2PMSum/pWm0ZDB7Pq00mp27Fuz/nrB1vLXIVKzdfNKqPu2yp+HWJEVe8eCvtUhWIHHEUFXLgF84boQGsycaqt8BOePK9LQrAVlbha5hJULmQhI+/iROGsMDEFI2oQ8GBLNJMhAlFO42I6r/Uk2iVUB97dDcNP59EjURMvBhA0RPmMI0GxRhSJ16OnGTGFIXLFQ== 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=M9Q/n+Ot9L1GEPwpFHfJyKZAmawudyNltWLxg/yWo7M=; b=ngcONoFOeh0gxEnefeOjzqKEp2+ImWgGZ/I+glK2c2+8YMNXMf5AvaJGpHGNGteLJEkAhlVbLHpnFmgpDr98r9jvoMy2rBuvNZmij1+hDml/I22TvJu5wkobbEB5U4+gKr6rhLqkEvkEMhZUlt7FkuZ+x/eRSeAxVrs7G8Nj7XGJwg/p1yxfJ0I9r8YksVLxVhRHmNNdV53SvQ3uI+ujOMFxxMwVxTJb7TxObIWBPtHFmKh4buUH9NI3eOgMaH/gwfcRQb1uYhTqzwPHErAQ0HxO6+LJaL6pjhMu9KcE1LtnXHHVVudksjjhdM9ziuJN1CslDciss/uun94wbmVzUA== 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 DM5PR15MB1610.namprd15.prod.outlook.com (2603:10b6:3:127::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5250.14; Fri, 13 May 2022 01:22: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%4]) with mapi id 15.20.5227.023; Fri, 13 May 2022 01:22:38 +0000 From: Delyan Kratunov To: "daniel@iogearbox.net" , "ast@kernel.org" , "andrii@kernel.org" , "bpf@vger.kernel.org" Subject: [PATCH bpf-next v3 1/5] bpf: move bpf_prog to bpf.h Thread-Topic: [PATCH bpf-next v3 1/5] bpf: move bpf_prog to bpf.h Thread-Index: AQHYZmfu2xlqSOScpkSeB2xmTf4Fhw== Date: Fri, 13 May 2022 01:22:38 +0000 Message-ID: <529c88e0c8438db4bfd9768ed5d1fee508fabbfb.1652404870.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: b20caa63-70f8-4585-445d-08da347f1188 x-ms-traffictypediagnostic: DM5PR15MB1610: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: +9Gi6mP1W7sCsqvE+uNMkBd+8xU4sStfGbs9w5o7h0ARPszehHWNjhPR3as6Kixo7yz18+CJSJbKyykd1KparAaVFNDmOyIgSh/pe9sJlioT85Bmt39pbh14UvyZ77ysis/HhnH34Szcza4uMICfSZawCGcYNDz/xE72RmQiby4en0a2zhLzAW2SwQbVODrojRtZ9uYXOMMlnzepXrpt4H4enNh2OnO5w8M55+cJvz9YMy8IA4/odYsEj/ytSGneDwTYNGgCjiNZLnd3l46kUGogYrFNFzKKahhWFrAfX4M1mSZKXTFuVR2Pc5yIOLkwFgzl+x4U9j7s6f1lNfv8Q3sTm6uIqzDmGQADXWTM8t4pCeXeIIZfGOaqJIwpJgFPxDHpL7EHaQvSDHVlfRSBRu9xNss07pO+wrOWcfxjguPhtnuG4G+SOoTeKOs+L+J4mKy3wAMoFb8reeCwOKy+Ly928Sgvb6KiRY0/Ic6mx9eowt2BOPJvEph+/Tobnoa3KcPHHWSQmuH/d7WRTpnnwaz+eetou6frf1bVy6kIHERkQj9SFvDUcxK99H0b83UxBqz/CTzlzEkh29bt0PuE08bGKPUUhxlQ1ov/euL2l779PwekxW7l5miuuTKBoUM4ftERKcgff6umv9yLKNbzvCdVb8i2vVUcjypMjbz396MhmuBzZ52FAq6K4fKhluMauWH7l9HMq42VUy50IdHKWA== 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)(4636009)(366004)(83380400001)(110136005)(2906002)(66446008)(6512007)(5660300002)(38100700002)(38070700005)(8936002)(508600001)(91956017)(2616005)(76116006)(66556008)(66946007)(66476007)(36756003)(186003)(316002)(8676002)(86362001)(71200400001)(6506007)(122000001)(6486002)(64756008);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?0eqRivG5h3BFzkmMiJ+fqG9?= =?iso-8859-1?q?fuMRPyL7zljvom3FJUl1x7kDSn8ekkKRucVpPZGXBpKFdP+86W48MB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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: b20caa63-70f8-4585-445d-08da347f1188 X-MS-Exchange-CrossTenant-originalarrivaltime: 13 May 2022 01:22:38.3950 (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: NsJ5T40SiI5S7YuQVIlmwcyz3tYbRJ75PjtZFGohYa+pdBrs8cHI+ohEC3YZed6C X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR15MB1610 X-Proofpoint-ORIG-GUID: 3AteVasVSJJcqnqbnw_UAcuMOjLhkAQz X-Proofpoint-GUID: 3AteVasVSJJcqnqbnw_UAcuMOjLhkAQz 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-12_19,2022-05-12_01,2022-02-23_01 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net In order to add a version of bpf_prog_run_array which accesses the bpf_prog->aux member, bpf_prog needs to be more than a forward declaration inside bpf.h. Given that filter.h already includes bpf.h, this merely reorders the type declarations for filter.h users. bpf.h users now have access to bpf_prog internals. Signed-off-by: Delyan Kratunov --- include/linux/bpf.h | 36 ++++++++++++++++++++++++++++++++++++ include/linux/filter.h | 34 ---------------------------------- 2 files changed, 36 insertions(+), 34 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 5061ccd8b2dc..b67893b47da4 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 @@ -1072,6 +1074,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 Fri May 13 01:22:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Delyan Kratunov X-Patchwork-Id: 12848281 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 EDFFBC433F5 for ; Fri, 13 May 2022 01:22:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376323AbiEMBWt (ORCPT ); Thu, 12 May 2022 21:22:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351943AbiEMBWp (ORCPT ); Thu, 12 May 2022 21:22:45 -0400 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCBDC5E172 for ; Thu, 12 May 2022 18:22:43 -0700 (PDT) Received: from pps.filterd (m0148461.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24D0ZN8w009739 for ; Thu, 12 May 2022 18:22:43 -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=fgyAYxmsGBCeGQ/ofQK8xnKhS5gvUza9sIsPeETkAsQ=; b=qVJkw6dTnTsEZPaQb0xZ2jiUl5lbjIsGBMCVL6YH0HUhDZhEXVXIq72ike0If4pHmo9D Oof1t5iGBd5Xk9evjHHc0wWk1WxuH2A5NTJeStrhgui5VOAXZBxljON4Qk45PioQ0osA Ei6L4oRXm3UJGKc96oWqlwDAkHtJbr6CGbw= Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2169.outbound.protection.outlook.com [104.47.56.169]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3g1cwx85wn-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 12 May 2022 18:22:43 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gQ0l/T76yzP5RStjMV5LmTwHyN9lEYqHeCxdRy3DOfG+WrV2lJnWUyYC/3dCWEX7yqv5PxcpsuIt7NC9aiR9sdFpV4eZE+qLPybhCJDMJNLNo9w7pdxPs5xnscAbK1P+pjHibjanQ2IuLI+C2bPg8UXYEamnkHSJLP66XBc2AJWRjaQ3YiYubLEXkFG6s9JSD9HLPeR7hcHnwWgb4P8n5xFheHBNlf2jzY6tgK4mNfOf9Cg7gNaMk8U5UzXAjTKakuA08BYRh0roakyFLBUMQkaC7++6mxNNsybSA4E8fhoIR/GmgD639krklq5be5ZMXhl9L4CUy8VyV1lTL8jmOg== 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=fgyAYxmsGBCeGQ/ofQK8xnKhS5gvUza9sIsPeETkAsQ=; b=LZJfCZe1//DZ6ObgMFUbnpnPI+KCPhnuPDNErFqZ+qhWOxjnLDKACZgg8wsjdxRY5jSkbf2r5F1+HcJW11Ziw1uNOcaqEKqBgody4pJsQnXF7k6gbFMwaUiT/017EXDWISt/WaJkWZlOP8h6F+kypZgSnxFLao26xclBCJR/Gr1yRID8XbMTK7Fte2XWFPfi4K1LqbKPBzJXqBtPXwdKmFLh5l4y5P2oOctP5LlVhXD9kZdgtw17CplncBuzsESDCGN5jonhrG7GTF8nBVexPXniC045wg2z0A3OhbvbQCIc2F0fwSDZTPpupCnaca3kibkC1EUVyjBWSLA0ieO5pA== 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 CY4PR15MB1208.namprd15.prod.outlook.com (2603:10b6:903:10a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5250.14; Fri, 13 May 2022 01:22:40 +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.5227.023; Fri, 13 May 2022 01:22:40 +0000 From: Delyan Kratunov To: "daniel@iogearbox.net" , "ast@kernel.org" , "andrii@kernel.org" , "bpf@vger.kernel.org" Subject: [PATCH bpf-next v3 2/5] bpf: implement sleepable uprobes by chaining gps Thread-Topic: [PATCH bpf-next v3 2/5] bpf: implement sleepable uprobes by chaining gps Thread-Index: AQHYZmfvguvoJCxIhUOr//cQtqUQ+A== Date: Fri, 13 May 2022 01:22:40 +0000 Message-ID: <1b9c462226d2d7b97293e19ed2d578eb573a4544.1652404870.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: a4da4ce4-12fb-40d6-8ce8-08da347f1268 x-ms-traffictypediagnostic: CY4PR15MB1208: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: clgmKcjp4RXvHWzube+R0cvlpbRE405GfKePevTLIx7WQne5jphm7q9HGJXIYvnT1wZCBrOAo87xmzMDQn86PXYiFp/+wNczXctm78aQ4rU+ylHhbzBnvSYZNx0ohpER6VNe+ms3GEKhXRD/9AC1b294NAmYEJDu6JLwg7bZOu/knxjTFS+9XOjrihswy0DQWWV/grax+9so6Y6b3tDGyEL8Tzl2zW8oakwUfc7Gj48p3yM36QtBnhIsiUlsFT2votbvnVddoRZxbudvjgkHh/I6Dj03idEc4/Pk2uXw0XlwLTAL65M7OmrtrgzREvn04RHf+dsIDha9R9Jv0menKT+c1sBWZG59ycxkvPYenvyIl368n7bJKdTREs6a+vXw8ioMxGIGPyxqv26hkfjeukIc8/4sJ/K/3LtbXxF4eU60Jt/fx/+xSZIk56aYbUUOPRcQ02Xu+fuvjzFnTaKInUyY+3hEMB+VEbAzuY4UGVraRt4rk3uzbubGizLABv21SO4UFBCDAtg3ApY+ap92Ly12g8YE4NMpXkdLA0eDRaVesUjtVQNwttjwFJhaXJ3f+WSRG60lE10EU0tvnS1K7erAW6cxYAiFo2pX24C6cSlTFa2dK9d0MbIkChB2HIyDg5TpvuX+SUCVUti+7rsI+ygE/MdaarVW13XMQjrfa34bIw3Ihs0hJJY/2/RqhwSeH/HQPponO7BEn+lcbKdF6A== 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)(4636009)(366004)(110136005)(122000001)(38070700005)(38100700002)(36756003)(316002)(8676002)(71200400001)(76116006)(186003)(64756008)(66476007)(91956017)(66556008)(5660300002)(66446008)(66946007)(6506007)(83380400001)(8936002)(2616005)(86362001)(6486002)(508600001)(2906002)(6512007);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?a+zuivUplDRAg6/rNlBZYDH?= =?iso-8859-1?q?RpH8JwJdUHfNFqo6u0LqrmVPxrKiB13ovjb88IRltRrwh9EnBgJEgh2ZSBd0?= =?iso-8859-1?q?b00qwVvVGBBxghInNrED4wrRTxmH+YcKzfgwhIl3WhpomxfSIqwXRDP438GG?= =?iso-8859-1?q?rKLn55pDq2oz8qoeJI4qKnurLZm/T0vYh8hCyft1EzohFaLwZrHSiDBQr2DB?= =?iso-8859-1?q?YNFSl5VLCsw6as72rldeh0Jh/YoLQ6JvjVy+woKx6ymWNavrGnZ1By6azR0K?= =?iso-8859-1?q?umXoMn/UyRBaBYeI4muf/y2XhlWBDX8qssRehvhLCSgTdpvIMvqrQejMUJ/4?= =?iso-8859-1?q?XY4KTwMd5MxAEjsyaEM+JYazMN0CJTSHO31BIsUgXH3keNPSc/7dkx5BVvGY?= =?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AR/4s/LVLwjZTL7WZ4iM+lYLXhOSdS+9D/Mtz3TcHcxj/23BeKz5?= =?iso-8859-1?q?bO08slXkYNNeVUxZ5+5ohx1YZW0RkF48h/wt15tvT4bdzzRUYY4RZjYWu/E3?= =?iso-8859-1?q?vIsDu6wDQgJVar/EQQs80D0zcvJryVrDVM4ZSDeuCeZlgtyT/3Cp1XZ2BRZi?= =?iso-8859-1?q?1qrsZEDobZo6ls7t2xj1NVlGwo1zQDGE33LjJtXN7A9XqYPCo16KjmTYFDIA?= =?iso-8859-1?q?Ur+X6aeHC0tXRONg7/PVwbzfQ+xOf+8J4NyR5vQ9VKb5u4hopKldAFwPXaEl?= =?iso-8859-1?q?0iTsmCsrVVEcLiDk8EuX2rvUGIEBbx0DaX+O2MHc73M+hqCmdyP4uUA6Zk3U?= =?iso-8859-1?q?fQDNq6nZfenqmqUe59xaCmsasIftKJVDRh+Cw4/b9n2PRxM53lywZBJpHpJg?= =?iso-8859-1?q?PKMqmYbEFh+jSo+SUX2stWMudAMbNa1NiTvN8GmZWO0kdsjx+kWvZ+HdYw/N?= =?iso-8859-1?q?Fk/Zq07GrqXw4ggfiTfh2ZmaVT8bvu8ZJdxSLG/YsGgcy0RqBj4SFszYXt3L?= =?iso-8859-1?q?anuKkngYwd8CQ3vpf7Q61eOiE+XVZ?= 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: a4da4ce4-12fb-40d6-8ce8-08da347f1268 X-MS-Exchange-CrossTenant-originalarrivaltime: 13 May 2022 01:22:40.0522 (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: ndVhUrV0sonVjtCbRq/nSOXv4Y3Qpyf36kd7hvgpuq8QTaM2ZO6YuI5VGQLCWOUG X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR15MB1208 X-Proofpoint-GUID: KaAEMelYcQm6DRzXBeaTzaXISO2HwSev X-Proofpoint-ORIG-GUID: KaAEMelYcQm6DRzXBeaTzaXISO2HwSev 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-12_19,2022-05-12_01,2022-02-23_01 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net uprobes work by raising a trap, setting a task flag from within the interrupt handler, and processing the actual work for the uprobe on the way back to userspace. As a result, uprobe handlers already execute in a might_fault/_sleep context. The primary obstacle to sleepable bpf uprobe programs is therefore on the bpf side. Namely, the bpf_prog_array attached to the uprobe is protected by normal rcu. In order for uprobe bpf programs to become sleepable, it has to be protected by the tasks_trace rcu flavor instead (and kfree() called after a corresponding grace period). Therefore, the free path for bpf_prog_array now chains a tasks_trace and normal grace periods one after the other. Users who iterate under tasks_trace read section would be safe, as would users who iterate under normal read sections (from non-sleepable locations). The downside is that the tasks_trace latency affects all perf_event-attached bpf programs (and not just uprobe ones). This is deemed safe given the possible attach rates for kprobe/uprobe/tp programs. Separately, non-sleepable programs need access to dynamically sized rcu-protected maps, so bpf_run_prog_array_sleepables now conditionally takes an rcu read section, in addition to the overarching tasks_trace section. Signed-off-by: Delyan Kratunov --- include/linux/bpf.h | 53 +++++++++++++++++++++++++++++++++++++ kernel/bpf/core.c | 15 +++++++++++ kernel/trace/bpf_trace.c | 4 +-- kernel/trace/trace_uprobe.c | 5 ++-- 4 files changed, 72 insertions(+), 5 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index b67893b47da4..77ba90d654e7 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; @@ -1360,6 +1361,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, @@ -1451,6 +1454,56 @@ bpf_prog_run_array(const struct bpf_prog_array *array, return ret; } +/** + * Notes on RCU design for bpf_prog_arrays containing sleepable programs: + * + * We use the tasks_trace rcu flavor read section to protect the bpf_prog_array + * overall. As a result, we must use the bpf_prog_array_free_sleepable + * in order to use the tasks_trace rcu grace period. + * + * When a non-sleepable program is inside the array, we take the rcu read + * section and disable preemption for that program alone, so it can access + * rcu-protected dynamically sized maps. + */ +static __always_inline u32 +bpf_prog_run_array_sleepable(const struct bpf_prog_array __rcu *array_rcu, + const void *ctx, bpf_prog_run_fn run_prog) +{ + const struct bpf_prog_array_item *item; + const struct bpf_prog *prog; + const struct bpf_prog_array *array; + struct bpf_run_ctx *old_run_ctx; + struct bpf_trace_run_ctx run_ctx; + u32 ret = 1; + + might_fault(); + + rcu_read_lock_trace(); + migrate_disable(); + + array = rcu_dereference_check(array_rcu, rcu_read_lock_trace_held()); + if (unlikely(!array)) + goto out; + old_run_ctx = bpf_set_run_ctx(&run_ctx.run_ctx); + item = &array->items[0]; + while ((prog = READ_ONCE(item->prog))) { + if (!prog->aux->sleepable) + rcu_read_lock(); + + run_ctx.bpf_cookie = item->bpf_cookie; + ret &= run_prog(prog, ctx); + item++; + + if (!prog->aux->sleepable) + rcu_read_unlock(); + } + bpf_reset_run_ctx(old_run_ctx); +out: + migrate_enable(); + rcu_read_unlock_trace(); + return ret; +} + #ifdef CONFIG_BPF_SYSCALL DECLARE_PER_CPU(int, bpf_prog_active); extern struct mutex bpf_stats_enabled_mutex; diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index 76f68d0a7ae8..9c2175b06b38 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 7141ca8a1c2d..f74c53dba64e 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -1934,7 +1934,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); @@ -1960,7 +1960,7 @@ void perf_event_detach_bpf_prog(struct perf_event *event) bpf_prog_array_delete_safe(old_array, event->prog); } else { rcu_assign_pointer(event->tp_event->prog_array, new_array); - bpf_prog_array_free(old_array); + bpf_prog_array_free_sleepable(old_array); } bpf_prog_put(event->prog); diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c index 9711589273cd..0282c119b1b2 100644 --- a/kernel/trace/trace_uprobe.c +++ b/kernel/trace/trace_uprobe.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "trace_dynevent.h" #include "trace_probe.h" @@ -1346,9 +1347,7 @@ static void __uprobe_perf_func(struct trace_uprobe *tu, if (bpf_prog_array_valid(call)) { u32 ret; - preempt_disable(); - ret = trace_call_bpf(call, regs); - preempt_enable(); + ret = bpf_prog_run_array_sleepable(call->prog_array, regs, bpf_prog_run); if (!ret) return; } From patchwork Fri May 13 01:22: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: 12848278 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 EC455C433FE for ; Fri, 13 May 2022 01:22:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244317AbiEMBWo (ORCPT ); Thu, 12 May 2022 21:22:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351943AbiEMBWl (ORCPT ); Thu, 12 May 2022 21:22:41 -0400 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADFF521B152 for ; Thu, 12 May 2022 18:22:40 -0700 (PDT) Received: from pps.filterd (m0109333.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24CNMMKN023307 for ; Thu, 12 May 2022 18:22:40 -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=lQmCkwPQVqujht18gkgc5bHZJJpoqUQTn/pVU8kz10E=; b=GNGXgnm5Xt5/E5I8hohjy+uyKNeJ0X6SJZINTkvJ2GIfDFn/Ow0BdhAvVpJ3AXYSj+Ba 6dbQrRC2KUtMscrwJrC53yhxq4GAszBXfEYi4QFYmuDOsxl7DG267r1jh6DCJL8sDyq5 uGomzOFFFA5NIonkqFEa+i5I2tzSGwBYWbE= Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2177.outbound.protection.outlook.com [104.47.59.177]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3g17vytvss-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 12 May 2022 18:22:40 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YlrSGTGA03L5QMVvzRF4y5rJs13TjyCvhPvmaRtQHupHodg8lFO1onxfLknTv9EBk/MWJI0lP37WX9vNQxqfBAz41cwP7PJ5QLnU+Hv8sNmB8uRvmRYcc4nXvOAOsSIwv7jdp2ifjiLfmpv8UhS7FAv0FPfmMhoTPj3OU4eD4+85+a9pjWD3TIfmDFJZSRcBK7+I6+w+D9GMtAT7OFhxnou/0qqIPwoDIL0WdufnnjuLQ3itYD8ursRy73apgjXqosu5+CY+R3oa31U8knwnTrY6o9jOysCopflTdZ0fsI4FsPQ18GRkw1BTqyMWuXICO5e9RyzHL8ppPB6wPA/s3Q== 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=lQmCkwPQVqujht18gkgc5bHZJJpoqUQTn/pVU8kz10E=; b=WU1tX6c6KKI+s9yQJ63Tzmliu1AFY81nwN3UAHB1Xz43zQEJ8g8jxPpZ0etiRseD/by4I+U4jy/BFoA0iVxVvl5Mgma+IWRAXgf+vqJ1Qe/TETy9SJL60+gqNIx+xW+ijqOX+yVRGxWbWJwofaEACP1HHGMUwtxBFzkGX09DkLPX7EEYluBn4m2Nbj1JzGZc+wyuseDNATQec2UvH5oAhfTJx8J778Mb96FD7T6MbUGo5YkQmF1VunPNmlPMu+/C1aaFZGZpDC7Fran7GbHRWO1PBAOl/IGBMZvIpm43ooL0OU+VJUna5IzovebVY9QWkWvNVkdfCq0H5pLUdQCerw== 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 DM5PR15MB1610.namprd15.prod.outlook.com (2603:10b6:3:127::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5250.14; Fri, 13 May 2022 01:22: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%4]) with mapi id 15.20.5227.023; Fri, 13 May 2022 01:22:37 +0000 From: Delyan Kratunov To: "daniel@iogearbox.net" , "ast@kernel.org" , "andrii@kernel.org" , "bpf@vger.kernel.org" Subject: [PATCH bpf-next v3 3/5] bpf: allow sleepable uprobe programs to attach Thread-Topic: [PATCH bpf-next v3 3/5] bpf: allow sleepable uprobe programs to attach Thread-Index: AQHYZmfub4Q7c0nCgU+gOIXpXZW04g== Date: Fri, 13 May 2022 01:22:37 +0000 Message-ID: <7a75cad55074dc230c2ecb451336d02ed7d79d6a.1652404870.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: 8ab66256-bfde-4388-17ce-08da347f10f2 x-ms-traffictypediagnostic: DM5PR15MB1610: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: GjG3+MzZrjb9JHM+5tdgDLWulloQTJcG6ZuHaQAT1uf92R41exsbJoMrOaPTBaplUzPwiRjRNcmN+c8T5zumMFiuxZhE46t7ni9ovSPvBjosvOGeSdsN1jP6LgFkT1dR3pXpBZRt/FW7U2A8GeT12AlaAJFFeLsH3pFxnOI5Yc6nQ9bl3x9c8YNTplnj03TGno/VYQK3OOMWpol88HnIzv3Rep1W7qxKksh/T2bphs+lW1zkTLJ1gQi61lb1jy+lW4Rob3RhUQ+11rWFhfte0lCkISrLK7cZ5N442xkH1WliyV1DOqyr4NIIbohsl7dUE12KvTwAygy89p/punLnHnalqcP0Zx1uIiu2WC07ZJYj6uLKi2615ycPBLbvYjTgu91Rf5avnO+bpDrI3KdADDu2AY9yk0gGfhUR7tIaGeKl6YZ3iXOwv7jvmnbqLy6aXG31jYJoB3zfk19Pyw8jJmnsbGjfb+IAAtv+Iudp1a2JMd/Ofr8MzCCWS7eccN/KkKHJczu5WL7z3OJ5B7TKNlox7iSMOq5SZRcHMtkgbxuj9FBFw6V6hkJt9HWMbAKHYJ9KZF2FfvI13hczyk8rl1BHVoCro7UBpPcnPwq/BgJ2uapiZV2pOrs9k+IBWT93l+5WrQFWRWkkKkiA5Kb4IadrHAlhWjNR0WrXD2msHvQHGJexJKn2y4IxsTXMFcyg61la7XoBGqrwZXGLpWy0oA== 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)(4636009)(366004)(83380400001)(110136005)(2906002)(66446008)(6512007)(5660300002)(38100700002)(38070700005)(8936002)(508600001)(91956017)(2616005)(76116006)(66556008)(66946007)(66476007)(36756003)(186003)(316002)(8676002)(86362001)(71200400001)(6506007)(122000001)(6486002)(64756008);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?A0QU0bTiva8r7oFeTLDaKLc?= =?iso-8859-1?q?NubhAXnywTgWQAsFIVzthYsl1mlSBw2fCDz69HyC9OIR+tTSbXdaS06jZfc/?= =?iso-8859-1?q?m/gH8w3l/aNKC89mJ3uDhUKPC/caOW1s6IHpusejdxPlsIeSfgfHvGCvmGfP?= =?iso-8859-1?q?h/3DK3qJZqQ025oiZ0GF7QA1GSi/UDObDsZRuhLT3nXyIkk6ZMTMX2kcjdDc?= =?iso-8859-1?q?CZvfla18tYUx+QrMf3RnjVUrSany8bTvYPmj8/aaaTp03Uj0Ipe3XHiIh2bs?= =?iso-8859-1?q?xZ1QdZgcCUdmhBVbaLoT5vITVfNLUMs1XMp6aW1uQ8aYVafkw0X0mpPeF9p/?= =?iso-8859-1?q?6E6GPVMmtXjZlgSR3qbSEXSzKbbhwSwN9dz1xGKd5fAqmNis/sNtDUhWub45?= =?iso-8859-1?q?74h3LXE5dNyvu0H+1pa42oSkOvLBCvcLKu2Xz1P6BOrx4YE3l2XNWT2v/miC?= =?iso-8859-1?q?1X9eFQrdAO4pk6bsGfeNG6Ec8mQ2J8U9kOvMf+EHI6EGnjGHzmeQen2aZcw2?= =?iso-8859-1?q?o1OVTJ2wZwIPsFPB7c+sJtDpRf9IGRIV2jkOs64ooAh9Dci30AKvLOxFTZfK?= =?iso-8859-1?q?Tbk8iWNR0p6S3YAn3fmiCO7mFUWSYsinFtPrFCp7vba2HGQxRHklewmLmdNC?= =?iso-8859-1?q?HptumR8ECZU5P/AodhDwc5hPEuCdOonHuDa7o1kDDGmQx1aYDH9ZAYG3iznC?= =?iso-8859-1?q?Oeek52KeyTWsylj9AA+ld2oECPNgrjjLudcU1HFb6haXionD8LD0xrDFe6Jk?= =?iso-8859-1?q?CKkTtMlQOMnArrZgu7cJQ1kLKVwyUnW1APLhpdKJ0tJrcgZCE9/y7LIUGzmO?= =?iso-8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Tfiydy1KZtMLnaFCT1KTFfkb5kq1Mee/NKQL?= =?iso-8859-1?q?rSPpc2GujEp2EWjn3nL9xkfGZVH51Et3V3nxasUnwNqHoGN/O3U4TYSI0Cdg?= =?iso-8859-1?q?MILhW7VSF8vo07NFG2cJNm4wf0Zyy?= 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: 8ab66256-bfde-4388-17ce-08da347f10f2 X-MS-Exchange-CrossTenant-originalarrivaltime: 13 May 2022 01:22:37.5670 (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: Oj9Y9oDi4c8Hsl1hL8sJjxVek+r7L6LbOkDsALYVP9TPWLnAeH/5YfoHtt34bEYe X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR15MB1610 X-Proofpoint-ORIG-GUID: HBARcu89p2_Oc_kaBa5fCWeL_3GmYYgQ X-Proofpoint-GUID: HBARcu89p2_Oc_kaBa5fCWeL_3GmYYgQ 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-12_19,2022-05-12_01,2022-02-23_01 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net uprobe and kprobe programs have the same program type, KPROBE, which is currently not allowed to load sleepable programs. To avoid adding a new UPROBE type, instead allow sleepable KPROBE programs to load and defer the is-it-actually-a-uprobe-program check to attachment time, where there's already validation of the corresponding perf_event. A corollary of this patch is that you can now load a sleepable kprobe program but cannot attach it. Acked-by: Andrii Nakryiko Signed-off-by: Delyan Kratunov --- kernel/bpf/verifier.c | 4 ++-- kernel/events/core.c | 16 ++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 05c1b6656824..ed446ce5ad79 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -14583,8 +14583,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 Fri May 13 01:22:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Delyan Kratunov X-Patchwork-Id: 12848280 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 522DDC433FE for ; Fri, 13 May 2022 01:22:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359866AbiEMBWr (ORCPT ); Thu, 12 May 2022 21:22:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376272AbiEMBWn (ORCPT ); Thu, 12 May 2022 21:22:43 -0400 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C9A4222C28 for ; Thu, 12 May 2022 18:22:42 -0700 (PDT) Received: from pps.filterd (m0109333.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24CNMMKR023307 for ; Thu, 12 May 2022 18:22: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=lHtBKkfETCynWSNeWawNr5pR4Qsr14vpU29bRyCSVho=; b=jrJ5Gic6i5EmQC/qVFBbPzjoBuQbaI/+vOCw8CkVvTXUhAy9R47uQN3I4snkI5d9HGXA oN/s+Q5dwt87+Gcq7Qs0wQ2CEfxS7FtnSqUNNn8fS2pfRDoevPaia3kJmlb74+b1GQM9 AUkpCJI9l6573y/fapFJrZJzOctj1wpmSAQ= Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2177.outbound.protection.outlook.com [104.47.59.177]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3g17vytvss-6 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 12 May 2022 18:22:42 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IS6yNUBTJZPsy513ub7a+QAj1dcUzmp3cUozJruJOdEAWQkK2Tmg12mNBAoBhNZ7RXOnfqx3SB7oTzAHsPhbub0gfq4bpTSfxXDKr3x8k6GOVu58/I3D9sD4zvxR8aYeaRFlS/pdcaVTAlMB1FQkhPfbzWWWCXQ/EU7S+hndBTg3n28PQsLSsHMLW4YTXae6VsfCbr/RxRe+2u9ajGOq+lMxmJC5g5rTz8LNeA+HuHfh+JBVOwSlqGEwU+ZlsXZR9/De8Ckk6WEWTof28zfihdUkQioEfILAYn5LarPrydnDILmz7sWQESV+HV+2EQ2dS5e2qB4YN8Tjn1D3lpIFvA== 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=lHtBKkfETCynWSNeWawNr5pR4Qsr14vpU29bRyCSVho=; b=cgDprRqjBhj6PyV3gt2XVkIKxEnmABMOX1J7f8WezXnH3Ud9F59AykOegShkiMbK3QObJcKEkwRciSD/0WsaXBLc8JG2mHwRRzDlDErDC0FJInX514vZjnoDfBOSz641s75wjvG9gCuhkBT34uCCbdML5ZYArQOMni5xSuNGk7c2ZLPSsIsgl4LLHQgOtBfbo32stah+lr3EAk8hXuQ/89sCItf9hSky192TMUzx8H/3ficoqDJuIDKA3SGWHGQuptMr9jzmwQyzoAwcMzK9Q/lnTMiFvc0C8Sa3aiVtzOQFtIWRJLGulAb2tAuJixhWEF9EvgHnErNgxa+fKNiOIA== 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 DM5PR15MB1610.namprd15.prod.outlook.com (2603:10b6:3:127::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5250.14; Fri, 13 May 2022 01:22:39 +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.5227.023; Fri, 13 May 2022 01:22:39 +0000 From: Delyan Kratunov To: "daniel@iogearbox.net" , "ast@kernel.org" , "andrii@kernel.org" , "bpf@vger.kernel.org" Subject: [PATCH bpf-next v3 4/5] libbpf: add support for sleepable uprobe programs Thread-Topic: [PATCH bpf-next v3 4/5] libbpf: add support for sleepable uprobe programs Thread-Index: AQHYZmfvOb5TNJ9xM0uvUmh9bzHu5g== Date: Fri, 13 May 2022 01:22:39 +0000 Message-ID: <3dc6d472dcb2c50846cda776f122fc99a0e3e277.1652404870.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: ff7d182e-f5be-4227-621a-08da347f11ec x-ms-traffictypediagnostic: DM5PR15MB1610: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: v1/yDrBqsVdEVC8/CGm/q+IyZKCyi55thLXxeKrh5Cve1B1HBuI9s7HOPJ88EWtVItqk+d3Gyg0Fj0mPNaR7S+Ikg4IOrkM9Xr7XNuAOh4zjTTyh2heZ7X1ssFXu0cXZWwtYQIK5Jy/NbXj6lJMA3BbrH/aEXhrZlb/0W63y4q5eH4dx2Z0C3KyYf8IGTAVa0ttan1HVav54lXWwr9p2BMtqkNj9zmZilkUFPo58YZ2qKNItgYaajdm1fSurgX3v3BIHpbpam316GBoF5T3HmEl2xOmaxjy2SnsGpgbROTzrcHME6OnmNUnXe1p4vJloO6FyHjuilDROtfYjHbv54UKJu1m5yegPMt3tXP9ISRmobfV5FVMqG/zJJyoRHVjkZzuS5FVM9DSqtfaYmfYbh7tiRkg3MmUfKiVrjr76q5dP4LUEdDZGPj4lasW66/AXOq+1RqA6KQ0dLwUfJogN9bnAY3saOjCmLLOyTiOVmiIffJJIsYF/skb5QLtb6PY54WiN5S5/575ZrJo9Za1Cca5jok1yon27LEFyT0ryyQMUGreG1hq21D+m6GYmJXc8p7pgecRlffI3ayUyXTqUL0YaCphunyDGA9ly7m2Y8VV1KHcoGhB/pCRhTEScFTspFMt0UfAVRpuN5q485aL24+0CaQ/ApFf9kNAQh59sSX6Y9CYIwseBB2h3vAl9HNJ65HeaexXxJNh/hM+d4w825w== 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)(4636009)(366004)(83380400001)(110136005)(2906002)(66446008)(6512007)(5660300002)(38100700002)(38070700005)(8936002)(508600001)(91956017)(2616005)(76116006)(66556008)(66946007)(66476007)(36756003)(186003)(316002)(8676002)(86362001)(71200400001)(6506007)(122000001)(6486002)(64756008);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?23zmdWnG4R8uMjHeomorxE8?= =?iso-8859-1?q?RSVpqZkz6ZYUQabZf3c5TVhTzdj7t2/S/JOl0ALix53qw5wpH2840CJW4zFC?= =?iso-8859-1?q?c1Ha/FSjxWwEKf1kwgAuuReeXtaHWV0L/OGGqTVx/KPflApgnq7ECR3v1phm?= =?iso-8859-1?q?iamy2kc5NKXYoTaKtosVYFi+Y9e6ivM1ps0CpTt7kd06f+yGLzdE9UZdLIXP?= =?iso-8859-1?q?r+o+Ue2N32oxgOwCq50ywc2WkNJldpSYgiIsBhnsZ1x3D+txGnt6wyjLe640?= =?iso-8859-1?q?mljzMpF9x0NnIC4DrbonEdVT09B8GmewsCj4YlKRDq8oFcDoksMZbKxlS305?= =?iso-8859-1?q?IdLUZepVV/OVAYzF+6wl0FfBpq6MmmcsWyEml/t9rtD2Tle0SK4SAiv0uk+N?= =?iso-8859-1?q?ZPRKLfmuoVvQR/bSymtaBHJX2S7SJfCA9t4EL0PR43oDebA0MFlFDiuYGCUZ?= =?iso-8859-1?q?R7P9aWP1BSWBbaLgbxn6dgh26dN20OQALKXB0Uhzd8uBQbdeX1VfM1JfB7tW?= =?iso-8859-1?q?iWpJV7RNmegLSHRmiboUlFuDQ/w8BJ6IbjLv6ZpTCZOLbfJWmVBSWtYYIgTg?= =?iso-8859-1?q?aHNZsOQpEBafb408Lrew5B7bJ5VVnTu4g8sBzEfLVEXJfxzocb0zRRCsWVHW?= =?iso-8859-1?q?iNPZU5CwrLHPRoh1bKf8Ce2YA/7TAZuLXM97t2/arTHPvnmCGSGxRG9NuOe0?= =?iso-8859-1?q?iBW5/3zGHo0/kuaSunyl/PMasi3GnFJSicXdgxwl/aYfQtq7x2RHHRm54KE6?= =?iso-8859-1?q?BwyYTH65Va8kFEFqyUNZMDPwqB0qBPlZDNEEQU304Z0vl+LaZGTUZyiP0Zj5?= =?iso-8859-1?q?L5DEEdaR8SGXg/N9pzFXwfh/LWP1KdEjIW2i3qvX0ILg6mi+6V538E9nR69f?= =?iso-8859-1?q?r4URh65hhFF3yjDZFaMxafJwA5aILvVmktyHYYyZkrxtT2lm9eTgyDRULznV?= =?iso-8859-1?q?xjS8aFHKZ+l0tTrLT+UUp8EGXvit5zHUcbu31GMZVhf6zLI52O8rWCe0+V5O?= =?iso-8859-1?q?SzOXoXLLzixacq1mc7KO8kk4E4izgm2790kvn7kNSxPncVvr6IWqfTaJMzcn?= =?iso-8859-1?q?q+m5IQWT8GS5c59UT7LogGV+Ks5nYa/C9mHsy/DQqBl9fK0stIzV5qDD+KDL?= =?iso-8859-1?q?DfaqsuHsZ04eFOlg+Uj9H5Jyp5Obp2EOcxrypo51rSikwt140zZKLNoZWuAG?= =?iso-8859-1?q?nibgLE1RW7SbNshidV5brLMFjhP0wKdqnd9M6IoaBOZoOCgcVxCZ7f0y6W+f?= =?iso-8859-1?q?wpb06r8iXRiErXDXavef8kdJBEvbEEJYg6U8yaKtDLbCLcvb1/gl/+NUx2t8?= =?iso-8859-1?q?aBPCRghpRYiK9n+mTSBeFkPZA8Z/GGjGAZViReArgXpT+fteV4M96l+xKxgk?= =?iso-8859-1?q?Dy75JAKnzQo7kPpCAJvxR6ZljzpxbSG4bTuWwIIyCFCoYxD31KGq9pZqCyPk?= =?iso-8859-1?q?UvCXuDp3aBgg9J3NspwzK8NKt0nNlMmZpjT5Y/lcpwoK95YfkhdVLZ3WdrhO?= =?iso-8859-1?q?6qEpS3XVivW/d/YqG685w+xO+kTIw2EDROwANxSNKBN39R0PiVbWew5WxlKa?= =?iso-8859-1?q?Z/NwsscbtpzP6SKKjL36hjcYYRP0VHK0RQ+ImZ1+V8a5vEVtm4OLQ+SfAuOA?= =?iso-8859-1?q?Wj2LGtTHVgltcgQVbrq1Nl0z3Q9ZV4wbc+jJSt1Y55dHxDutfAYg2r6vWIFZ?= =?iso-8859-1?q?ev+E6EaVKezVy0U+SzCIysdwzkDk/6me5EvUvxWYfXCHr+kd2iSzwfdxs8iB?= =?iso-8859-1?q?r7ujA1eeifO6u13I4Of9GRZIqrR+y0MXc4957YMwRHXt2aq/2Rrh7s+hZnbE?= =?iso-8859-1?q?fKr4+ayiyX3/neDI5rErYrIgi+1Ua?= 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: ff7d182e-f5be-4227-621a-08da347f11ec X-MS-Exchange-CrossTenant-originalarrivaltime: 13 May 2022 01:22:39.2229 (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: s5CohWll6YsEqy+/t4BPHxTKHi7YUZaqyHKMiG/dJVCw3COvwiu63onb2/9vNBO8 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR15MB1610 X-Proofpoint-ORIG-GUID: KU0TqfNcbfLPPhwFZw37lRtBXaTq1W1H X-Proofpoint-GUID: KU0TqfNcbfLPPhwFZw37lRtBXaTq1W1H 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-12_19,2022-05-12_01,2022-02-23_01 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Add section mappings for u(ret)probe.s programs. Acked-by: Andrii Nakryiko Signed-off-by: Delyan Kratunov --- tools/lib/bpf/libbpf.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 4867a930628b..54ee6e422f60 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -9005,8 +9005,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), @@ -11282,7 +11284,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 Fri May 13 01:22:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Delyan Kratunov X-Patchwork-Id: 12848282 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 7E190C433EF for ; Fri, 13 May 2022 01:22:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351943AbiEMBWu (ORCPT ); Thu, 12 May 2022 21:22:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352238AbiEMBWq (ORCPT ); Thu, 12 May 2022 21:22:46 -0400 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6A855468A for ; Thu, 12 May 2022 18:22:44 -0700 (PDT) Received: from pps.filterd (m0148461.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24D0ZN90009739 for ; Thu, 12 May 2022 18:22:44 -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=Cv5Cj2GGOTH6YHFhMyXgNukmieyHPUty3NmmOaaRfg4=; b=dB3vNEC8hS7yrzUgMRzxCU3jBzGLg/8Jp7U11CXCoRzoSRHfmV/63vcB+7dvgAmZ3gRV MoGOrnwU+ZW1xcUKN89aVw0MbDnnmeAvLgdPNoQ5McjslGXaiK6DmMhSeTUDeQZM2GyK T1kkN6Nautm3vN36vfsMR2uWXUTfmCVfqLA= Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2169.outbound.protection.outlook.com [104.47.56.169]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3g1cwx85wn-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 12 May 2022 18:22:44 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MqDOz2oPJyIng0AThR5sQIP+QP9omjZFVPXXYqM3OuRVUGVoeGhRp1jYsMJPpFglksqiBaW/yZKHA2DSXHARMNhbkWHfVvRcfVu9Um4spW5icECsQPSR3RYZgwbSm9zgplg3pu1UuS9npzIJcBrILsctP7+uJfkpUUXT8MYXcbrNx5ADGKeD+YoMRMo5VImU7lOLb/xtTl1nhkAhhlG0VAGj1R3CatMnxK2qCGbdK911gZxbsU9U6h4lujR9V41990fsM1VeLYL2DNsgFcY76RrITEQKoDPEz01j6YuX1XSm8PRePyNQgd57sQlu2AudtdDAgVFJQKr3WQP5MSN9gA== 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=Cv5Cj2GGOTH6YHFhMyXgNukmieyHPUty3NmmOaaRfg4=; b=IKiItGIoA4dKIllX28yrWVwklGZzWsE5YUbeCnOuEI66DslmAteoseFZCfWXds7X9Ur0fiUvXOIoFctLvsKToJZUKreuOT+QMvpCcYsOnxiRFXU5afOx9UNZZpPUN+S972th5tVahQhJV0vgXb9ewAoiFo/zERfN5lmH8MgvrjMbH5ip98crxCxonmemRJr7Wa/4iqY46XFrDbREy8cjeDUt1GtHmpBrowvRaKNb5fV0l32tM0xXq1m6tH6C1Hi+WpGugTmTg4vkZhLMdmvdqlzifEp3LKO/bc/0MmnXKXQnkd2AyLDHbmtb14SHFWg42c0Z0j5bJV28ke6/c7u49Q== 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 CY4PR15MB1208.namprd15.prod.outlook.com (2603:10b6:903:10a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5250.14; Fri, 13 May 2022 01:22:40 +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.5227.023; Fri, 13 May 2022 01:22:40 +0000 From: Delyan Kratunov To: "daniel@iogearbox.net" , "ast@kernel.org" , "andrii@kernel.org" , "bpf@vger.kernel.org" Subject: [PATCH bpf-next v3 5/5] selftests/bpf: add tests for sleepable (uk)probes Thread-Topic: [PATCH bpf-next v3 5/5] selftests/bpf: add tests for sleepable (uk)probes Thread-Index: AQHYZmfwI3KO3DjPKUqkzc2Qe37WDQ== Date: Fri, 13 May 2022 01:22:40 +0000 Message-ID: <0a7d4944b0952e92a8bb75a312a59ff975c6bac1.1652404870.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: 1415796e-4519-499d-1b13-08da347f12e2 x-ms-traffictypediagnostic: CY4PR15MB1208: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: WqI496NxIoSULUbheQ1sNjx2GVcxpJU7GVGHR3Ic9U90Zydkkavj/2BQoX/NKz2XNcHKk64/QzWj7uc58fHPa+nkgk6qeP4JtaERqJezebuRzXYwfEjhSl4DUoIixxUyremD0lft+8W0OFu1QdZw+QdL72+acnCVsSSx5XTV4EJQCAw0shkDM4AQ8KM/8rYUSJoYBXIz6Tf8UBliHbabl7JEKMH03TfHhIV/woclyDiLeFFH1ZNqQGBtBfCw0OuRcZcT/EUbTsIktB/nR/0h8mBbTX6MjYtsz8pLqw5+CoV6UJNQXHV0YSEzYaNqp4MuVkzNvYB9EDtwpeXfwKrkDz7kPJMbBroQmEXPab7fsDOfoKQP55fw5IBf7OyQET1mk3pe+n/gKHX1tx26rJG2KW+b3mmF1SX1ZFG5g0HNixhm7c3CUA2K8Jv04rZM+UAeoRiO3ilEjbRU5FkL5bt7yx5zU3Hx3atyCdZk7R9KhE0mRT8ot+MXfe4EcI0U60ZZUyOWi+LYVFlxGwT8wfDEt1PFv9RvZr7lplPhOqvTGWcoVLVtei15tRHZ7EazilfB9zhTMV0QE97qu7J6EbfNY9NJWj7J3AwGy6OcIg/wrpOGAf2/UgJX8zecAft1jQS1Rk8bg78wwwU3t1DjgLkjE5BhE6upZHvYYaHZjb3alSWANKXMdsevpqm6lQP9fo3aAlFxRWa/rzoKuQQvyr2kxg== 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)(4636009)(366004)(110136005)(122000001)(38070700005)(38100700002)(36756003)(316002)(8676002)(71200400001)(76116006)(186003)(64756008)(66476007)(91956017)(66556008)(5660300002)(66446008)(66946007)(6506007)(83380400001)(8936002)(2616005)(86362001)(6486002)(508600001)(2906002)(6512007);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?gooHFL32b2BbIS4MCU6TCvQ?= =?iso-8859-1?q?nUXsI6sIQkrafT8oXWtZNvZ/Od25SP4QP7ddh7CSxjUWAv9mdQx4oBfahk1i?= =?iso-8859-1?q?sz98VzNWB+xJcnN8qHgCl4n+M46YSw/lLLWGte1BBICV87n6uccNdq8hMmY5?= =?iso-8859-1?q?tip4PWvLJeR7ETO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CIj/VIuKEu4ijXSRzpxUiRPOnt?= =?iso-8859-1?q?ghue14vU4NUdobJhvlE4Zk7w5oc3+86ZvLgXcu57d27Zuu4TzN2lWgOrtpXd?= =?iso-8859-1?q?bhabrIRjTC9aV174SKGz34wXlw7i8S15vlhwX0EUdBntf4Oq3R9XhrVa51Vp?= =?iso-8859-1?q?KG23kLp5OkK0A5OD7fBMFC+NkZ9kFdngn1gRo4vC7ChLo2VtlucfSUrP7pVB?= =?iso-8859-1?q?5+q5VU/SYiq0PwUCV7dOv1Zho4MI82ZD1QtSDbWWqod7NNDHaNSLful3+LJd?= =?iso-8859-1?q?YQF2vTjbTDHD2jir34CNWTjm3FikpPOrcLknr+2sofBckOGmDr0Ag27bJvA+?= =?iso-8859-1?q?ToZsDmpP4RZ3G16Ar9+F+PCweogJRsfJRSPL2p6Z7XoAYauv10cjvNcnVnWd?= =?iso-8859-1?q?rbA58GxAJ6IKXmdgjxy1pBeAbN9WNVusswFcUApR1ea/x4VC4/O/7gJWJInq?= =?iso-8859-1?q?lZ1B9smqGj/u/BaggeoMP1fs86w5B5qxApyUondtVZxZ66fCRAcau28wPOhE?= =?iso-8859-1?q?kAQgv85+oGb1V1wa5OEU+JPM+KE0DAsSBDIx6O6rUCL98OrT0Zrmb0j420fE?= =?iso-8859-1?q?YykDFNZLN481K5Rgs7Tkyf0eZFbejiPAeUl2HsmVqB+aSbRpa9SxQmrcLjUz?= =?iso-8859-1?q?Mx7dfsXnogDF4jQS+UdVyE6UOnHhBzRLvle6YrhL6ytOiIQ6re/RpLToUNvl?= =?iso-8859-1?q?7x+VyIj31Dy7kS/nCv8qrkhdwQh8lMd9AXvpW54L+NpYRN1+8V7xUk3cJ8de?= =?iso-8859-1?q?mPHNzttMR37uVB/i3fNe/4vf47S6/?= 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: 1415796e-4519-499d-1b13-08da347f12e2 X-MS-Exchange-CrossTenant-originalarrivaltime: 13 May 2022 01:22:40.8021 (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: fou3Oxm0Vr8cyMOjxxt+KtVT/1sjj6G5fGox3tAp7qcpKkJ9B3QG0Sr2+PTLdkfy X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR15MB1208 X-Proofpoint-GUID: ku2xmQkiNV0dwRspBtMx5WyXxZ4XLuKI X-Proofpoint-ORIG-GUID: ku2xmQkiNV0dwRspBtMx5WyXxZ4XLuKI 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-12_19,2022-05-12_01,2022-02-23_01 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Add tests that ensure sleepable uprobe programs work correctly. Add tests that ensure sleepable kprobe programs cannot attach. Also add tests that attach both sleepable and non-sleepable uprobe programs to the same location (i.e. same bpf_prog_array). Acked-by: Andrii Nakryiko Signed-off-by: Delyan Kratunov --- .../selftests/bpf/prog_tests/attach_probe.c | 49 ++++++++++++++- .../selftests/bpf/progs/test_attach_probe.c | 60 +++++++++++++++++++ 2 files changed, 108 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/prog_tests/attach_probe.c b/tools/testing/selftests/bpf/prog_tests/attach_probe.c index 08c0601b3e84..0b899d2d8ea7 100644 --- a/tools/testing/selftests/bpf/prog_tests/attach_probe.c +++ b/tools/testing/selftests/bpf/prog_tests/attach_probe.c @@ -17,6 +17,14 @@ static void trigger_func2(void) asm volatile (""); } +/* attach point for byname sleepable uprobe */ +static void trigger_func3(void) +{ + asm volatile (""); +} + +static char test_data[] = "test_data"; + void test_attach_probe(void) { DECLARE_LIBBPF_OPTS(bpf_uprobe_opts, uprobe_opts); @@ -49,9 +57,17 @@ void test_attach_probe(void) if (!ASSERT_GE(ref_ctr_offset, 0, "ref_ctr_offset")) return; - skel = test_attach_probe__open_and_load(); + skel = test_attach_probe__open(); if (!ASSERT_OK_PTR(skel, "skel_open")) return; + + /* sleepable kprobe test case needs flags set before loading */ + if (!ASSERT_OK(bpf_program__set_flags(skel->progs.handle_kprobe_sleepable, + BPF_F_SLEEPABLE), "kprobe_sleepable_flags")) + goto cleanup; + + if (!ASSERT_OK(test_attach_probe__load(skel), "skel_load")) + goto cleanup; if (!ASSERT_OK_PTR(skel->bss, "check_bss")) goto cleanup; @@ -151,6 +167,30 @@ void test_attach_probe(void) if (!ASSERT_OK_PTR(skel->links.handle_uretprobe_byname2, "attach_uretprobe_byname2")) goto cleanup; + /* sleepable kprobes should not attach successfully */ + skel->links.handle_kprobe_sleepable = bpf_program__attach(skel->progs.handle_kprobe_sleepable); + if (!ASSERT_ERR_PTR(skel->links.handle_kprobe_sleepable, "attach_kprobe_sleepable")) + goto cleanup; + + /* test sleepable uprobe and uretprobe variants */ + skel->links.handle_uprobe_byname3_sleepable = bpf_program__attach(skel->progs.handle_uprobe_byname3_sleepable); + if (!ASSERT_OK_PTR(skel->links.handle_uprobe_byname3_sleepable, "attach_uprobe_byname3_sleepable")) + goto cleanup; + + skel->links.handle_uprobe_byname3 = bpf_program__attach(skel->progs.handle_uprobe_byname3); + if (!ASSERT_OK_PTR(skel->links.handle_uprobe_byname3, "attach_uprobe_byname3")) + goto cleanup; + + skel->links.handle_uretprobe_byname3_sleepable = bpf_program__attach(skel->progs.handle_uretprobe_byname3_sleepable); + if (!ASSERT_OK_PTR(skel->links.handle_uretprobe_byname3_sleepable, "attach_uretprobe_byname3_sleepable")) + goto cleanup; + + skel->links.handle_uretprobe_byname3 = bpf_program__attach(skel->progs.handle_uretprobe_byname3); + if (!ASSERT_OK_PTR(skel->links.handle_uretprobe_byname3, "attach_uretprobe_byname3")) + goto cleanup; + + skel->bss->user_ptr = test_data; + /* trigger & validate kprobe && kretprobe */ usleep(1); @@ -164,6 +204,9 @@ void test_attach_probe(void) /* trigger & validate uprobe attached by name */ trigger_func2(); + /* trigger & validate sleepable uprobe attached by name */ + trigger_func3(); + ASSERT_EQ(skel->bss->kprobe_res, 1, "check_kprobe_res"); ASSERT_EQ(skel->bss->kprobe2_res, 11, "check_kprobe_auto_res"); ASSERT_EQ(skel->bss->kretprobe_res, 2, "check_kretprobe_res"); @@ -174,6 +217,10 @@ void test_attach_probe(void) ASSERT_EQ(skel->bss->uretprobe_byname_res, 6, "check_uretprobe_byname_res"); ASSERT_EQ(skel->bss->uprobe_byname2_res, 7, "check_uprobe_byname2_res"); ASSERT_EQ(skel->bss->uretprobe_byname2_res, 8, "check_uretprobe_byname2_res"); + ASSERT_EQ(skel->bss->uprobe_byname3_sleepable_res, 9, "check_uprobe_byname3_sleepable_res"); + ASSERT_EQ(skel->bss->uprobe_byname3_res, 10, "check_uprobe_byname3_res"); + ASSERT_EQ(skel->bss->uretprobe_byname3_sleepable_res, 11, "check_uretprobe_byname3_sleepable_res"); + ASSERT_EQ(skel->bss->uretprobe_byname3_res, 12, "check_uretprobe_byname3_res"); cleanup: test_attach_probe__destroy(skel); diff --git a/tools/testing/selftests/bpf/progs/test_attach_probe.c b/tools/testing/selftests/bpf/progs/test_attach_probe.c index ce9acf4db8d2..75d2b0492122 100644 --- a/tools/testing/selftests/bpf/progs/test_attach_probe.c +++ b/tools/testing/selftests/bpf/progs/test_attach_probe.c @@ -5,6 +5,7 @@ #include #include #include +#include #include "bpf_misc.h" int kprobe_res = 0; @@ -17,6 +18,11 @@ int uprobe_byname_res = 0; int uretprobe_byname_res = 0; int uprobe_byname2_res = 0; int uretprobe_byname2_res = 0; +int uprobe_byname3_sleepable_res = 0; +int uprobe_byname3_res = 0; +int uretprobe_byname3_sleepable_res = 0; +int uretprobe_byname3_res = 0; +void *user_ptr = 0; SEC("kprobe") int handle_kprobe(struct pt_regs *ctx) @@ -32,6 +38,17 @@ int BPF_KPROBE(handle_kprobe_auto) return 0; } +/** + * This program will be manually made sleepable on the userspace side + * and should thus be unattachable. + */ +SEC("kprobe/" SYS_PREFIX "sys_nanosleep") +int handle_kprobe_sleepable(struct pt_regs *ctx) +{ + kprobe_res = 2; + return 0; +} + SEC("kretprobe") int handle_kretprobe(struct pt_regs *ctx) { @@ -93,4 +110,47 @@ int handle_uretprobe_byname2(struct pt_regs *ctx) return 0; } +static inline bool verify_sleepable_user_copy(void) +{ + char data[9]; + + bpf_copy_from_user(data, sizeof(data), user_ptr); + return bpf_strncmp(data, sizeof(data), "test_data") == 0; +} + +SEC("uprobe.s//proc/self/exe:trigger_func3") +int handle_uprobe_byname3_sleepable(struct pt_regs *ctx) +{ + if (verify_sleepable_user_copy()) + uprobe_byname3_sleepable_res = 9; + return 0; +} + +/** + * same target as the uprobe.s above to force sleepable and non-sleepable + * programs in the same bpf_prog_array + */ +SEC("uprobe//proc/self/exe:trigger_func3") +int handle_uprobe_byname3(struct pt_regs *ctx) +{ + uprobe_byname3_res = 10; + return 0; +} + +SEC("uretprobe.s//proc/self/exe:trigger_func3") +int handle_uretprobe_byname3_sleepable(struct pt_regs *ctx) +{ + if (verify_sleepable_user_copy()) + uretprobe_byname3_sleepable_res = 11; + return 0; +} + +SEC("uretprobe//proc/self/exe:trigger_func3") +int handle_uretprobe_byname3(struct pt_regs *ctx) +{ + uretprobe_byname3_res = 12; + return 0; +} + + char _license[] SEC("license") = "GPL";