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: 12834876 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 AC206C4332F for ; Mon, 2 May 2022 23:09:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230207AbiEBXNO (ORCPT ); Mon, 2 May 2022 19:13:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229445AbiEBXNM (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 852412ED63 for ; Mon, 2 May 2022 16:09:41 -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 242LsRMd014107 for ; Mon, 2 May 2022 16:09:40 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : subject : date : message-id : content-type : content-transfer-encoding : mime-version; s=facebook; bh=TNf+IQ09Gjz6rb8bSK4JtbJ13TmCtXagw8Lhl09KJY0=; b=rVUVVOs3CVEVBf0TVGHmAxMC9NHP/a/qVRqg1k81hxtT7ajI0sHvZAC06Kk0i+gmCXZf ad/cTUya+2a51BOmnDrwgtHbKsYz9/xVS/EGvjLtk7BIOyaFQozU4rkbU+XEv1k13vOG hMZeVWeKYjD7qcYx+OvKBEReIhfCPCLUyy8= 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-6 (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=WKtd9wkg5PdAwe5cP8E8sVaaBe1/4FF5thBH8r1sTWEOBwAvswV35tcF1RROGj+czYzoYU2BXVLxQy5cust8p5Bc86MO2AK6L6gcn6yeVbUj6pBrYNsTZj+aNoq2ZzTTmKSUO57NSepvACtTqGpGQBUCFnVZ4QrAi/e0O5gWNHVEQv6Cs+Ywne9a++HlhbiNVYjgsnKY0nsWgifX+lNkml3lXRsjgGO/oJEe0TXr8sWzLbJuS49SXpmgdoLppwFemnEJuTETQPd7UAIcV3badKGNVHPQT3FiVu6FTWnWbHiwpl5fZXZ2rpZ3z7InKbtcAih9ObUU3al642qcZ6Tg+A== 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=TNf+IQ09Gjz6rb8bSK4JtbJ13TmCtXagw8Lhl09KJY0=; b=HTb9SDmynUNAe+tt3QVLGFR82YyZ64KP9QGznUeOlqGCk339lp3NQVuQop1NGTs75/qKgjl0enXD1lcHR0qXUZnoLJLr2hraHKhIEJLU14tnKBvI6zRWP/Ktqi2N2IkGl61fS8zBtOCnzf81DhgtDPOcnjLzBEIUAqVoYUFY/sSv8P3YYKAdHrCPJbEaDO+8RocDTJJSOJgmTPHtBZI5l8JN6AKfQZaf/JqvyTRLu1tJWA9dLF0QRQ2sOvweAQ8lWzx97GKlQ9FZ0M33A584mHpiwFIbw1eUBN0QYsiYekM78i/VsPJBeMp8SpcXOu+oq0rERg62OgdEgGNWRUPfdw== 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: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 0/5] sleepable uprobe support Thread-Topic: [PATCH bpf-next v2 0/5] sleepable uprobe support Thread-Index: AQHYXnmxb4Q1FBwR4kSk/iWJwTXT9A== Date: Mon, 2 May 2022 23:09:36 +0000 Message-ID: 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: 3885a146-c121-47f9-5caf-08da2c90d413 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: JAXqMUdASHQN2zfIT+pN1PgReCKUA3i9KtH7I8wrdnshaL81ETXE5DtV7Tn3WKeYj4hm4hAenlxV2sptWrqtdBY6ObcJZxL2hu+gKjZwD4kT1RCP6xfKc5hGj9pPgA4ZeQ6mRn5UVfbnqQgU7IGXFWBuR0mrJBY72cimO4j6g198meOyKTMWNqwOB/yylnoTwKitkHcdXcFnXDhyt2F+G/A4u4BlLWKd0G9sFl6KwyQubdyDYNvA3Mat/kh3JKCoP7FBxC0QK8Pi7NZvZuzb30vFxm0OlNm/894uM3osCc7VzCwUYCKU0ztuR9sivFal3ruHDGWjftixPBsf1OagobkfvZVaCeWnnXKoCNTGovKSJ3fuLzCtuY7YWPXWn2Il6ZN3BtuBkGJIOu2MPhfPR231E94ps7ZTv6OnGhcxR9dTBTY5WdN40X1l/42pwcRXPMtKaj4MlAZdiRIbwD1jUfB0bZfsmbrnIM9i0HrNC4LPF+4moDWSoU1hUzBSKOy/X99zpz+oIoYzp/AygE9xUln2HlFpSBXZ6k/WfQh5vbwuBy7v64n+HW9VkjvagdrCjT6bA9HPE8Sib8FSOg/nZNLpD5vaJKfIn3Hq6eR+/72tkSXPfkX3d6YDamVSiZIMBf/bOkcjixHTvTdjjFuIUE9dn0QypOY7PEs+3QsBsFcE8JKQnZ/U4iO+gzMQYMhaOqiAOFvHc4NBQVWALn3GG+kjWCEqjkWMnCWXD/Mfl6eY5vQdxYTYH5qMf0Gvw2m/k94ht8IiBsX2HqWZHhx5CqIt8ee2syvju3bqSKm3Sjo= 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)(966005)(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?XTjj91TcPq7QIrtQQBIYg+d?= =?iso-8859-1?q?MbZpKpI3nN6f9paq14HLVpq1C28CX5owSc8kMWSc2iQcahEifGC+6ngVTLr/?=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orOrg: 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: 3885a146-c121-47f9-5caf-08da2c90d413 X-MS-Exchange-CrossTenant-originalarrivaltime: 02 May 2022 23:09:36.9266 (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: wx8t4k+ZBs2JTxjrtr8INwRo6g8eG0qkZyJJ6roPtCUn0AAa48gznBdAB1Lv3bQS X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR15MB1903 X-Proofpoint-GUID: KVNLCSHiLxupRBODOijR_CgExTswzOQL X-Proofpoint-ORIG-GUID: KVNLCSHiLxupRBODOijR_CgExTswzOQL X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.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 This series implements support for sleepable uprobe programs. Key work is in patches 2 and 3, the rest is plumbing and tests. The main observation is that the only obstacle in the way of sleepable uprobe programs is not the uprobe infrastructure, which already runs in a user context, but the rcu usage around bpf_prog_array. Details are in patch 2 but the tl;dr is that we chain trace_tasks and normal rcu grace periods when releasing to array to accommodate users of either rcu type. This introduces latency for non-sleepable users (kprobe, tp) but that's deemed acceptable, given recent benchmarks by Andrii [1]. We're a couple of orders of magnitude under the rate of bpf_prog_array churn that would raise flags (~1MM/s per Paul). [1]: https://lore.kernel.org/bpf/CAEf4BzbpjN6ca7D9KOTiFPOoBYkciYvTz0UJNp5c-_3ptm=Mrg@mail.gmail.com/ v1 -> v2: * Fix lockdep annotations in bpf_prog_run_array_sleepable * Chain rcu grace periods only for perf_event-attached programs. This limits the additional latency on the free path to use cases where we know it won't be a problem. * Add tests calling helpers only available in sleepable programs. * Remove kprobe.s support from libbpf. Delyan Kratunov (5): bpf: move bpf_prog to bpf.h bpf: implement sleepable uprobes by chaining tasks_trace and normal rcu bpf: allow sleepable uprobe programs to attach libbpf: add support for sleepable kprobe and uprobe programs selftests/bpf: add tests for sleepable kprobes and uprobes include/linux/bpf.h | 93 +++++++++++++++++++ include/linux/filter.h | 34 ------- include/linux/trace_events.h | 1 + kernel/bpf/core.c | 15 +++ kernel/bpf/verifier.c | 4 +- kernel/events/core.c | 16 ++-- kernel/trace/bpf_trace.c | 27 +++++- kernel/trace/trace_uprobe.c | 4 +- tools/lib/bpf/libbpf.c | 6 +- .../selftests/bpf/prog_tests/attach_probe.c | 51 +++++++++- .../selftests/bpf/progs/test_attach_probe.c | 58 ++++++++++++ 11 files changed, 260 insertions(+), 49 deletions(-) --- 2.35.1