From mboxrd@z Thu Jan 1 00:00:00 1970 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2FF8C433EF for ; Tue, 12 Jul 2022 05:50:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B317894004A; Tue, 12 Jul 2022 01:50:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AE215940033; Tue, 12 Jul 2022 01:50:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9338B94004A; Tue, 12 Jul 2022 01:50:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 81342940033 for ; Tue, 12 Jul 2022 01:50:18 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 4B68733D34 for ; Tue, 12 Jul 2022 05:50:18 +0000 (UTC) X-FDA: 79677372516.07.B564B08 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by imf16.hostedemail.com (Postfix) with ESMTP id AF523180057 for ; Tue, 12 Jul 2022 05:50:17 +0000 (UTC) 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 26BNCLwE029001; Mon, 11 Jul 2022 22:49:35 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-id : content-transfer-encoding : mime-version; s=facebook; bh=68Rkt/xyvNvra5g5IZ+9xxwRVuxlsCpiH7rRWJS2nAk=; b=fetXY+poMFvXlyR49IoJZzruO8Qqn2B93HpeQ0NJCFRH2eMyMt/2PWQKhystKplXtDPm PFSo4lOD426WjV9J77vOzT++4Y/+6vwZWVozIrgqsjz5v0PkOQHGrYL09MtzXjIgobNG waR/x7aC8x3CAYq78mwsu4hwQUTw0WxXyAM= Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2176.outbound.protection.outlook.com [104.47.56.176]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3h8nndcvfq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 11 Jul 2022 22:49:35 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ckn4Ax+1JMpxT52RncTKnTs1iM5jfXgZzbHzlABh39SPGq1kixAE6RNg4P12B+sWux+17CTgh/JZeCRkpoLL0L0H4I5ty9+KYSGt63g1FzQZ7MGf7o0rluiU4Q4czc88GzJQp7pPjCzQgEKuKBqI2wLlTV03LBm9m+mI/vaCLYdii8MkeTCRPtopYp6Iat+EB9HOsq+3syo1ZmPZDrg0Dp+d+QLlzd4quQvalX/BDO7/kDtHjp/QR4wfFqGh1Mm0qWRDRdAiP9osxgC/SBHDU+Khw1QZG06D5oqxgpInPUfvMU8qN7bv6MG6ogNykodE1chL4buEgrB7tobTG/uuNQ== 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=68Rkt/xyvNvra5g5IZ+9xxwRVuxlsCpiH7rRWJS2nAk=; b=EZ4dI9BQgnDEHzjgMjesG6zG0r1qn5kqBGuNjMPTRUqp2Dczsr3o+xcjdPc/ZltPpszkpPPaNTUjLw6viOvyvasPsUwaAa7KDAW3oxdDdelu5GgNeXbaFPzAX4IuXRSmGcnD9J2o+JKjw5XE8VdF0OA2j9tjXCPLVpiSVTNtSj/jJhyDzy1j0hPDGG8qC4+QT2kfNowyKuCiw+VwHigj84IF46TCR7tUbMsCOwSSOPs23VZsqxDisxrIAXpxtfQxyNl5CGVNlgiEWiWNAFkp8Ng+KshxXT3Fx6DO4HXsWUMq7DbtxZ0qn/K7tqibXZkShlmAfTIOcTctvAa0Jpr6gw== 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 SA1PR15MB5109.namprd15.prod.outlook.com (2603:10b6:806:1dc::10) by SJ0PR15MB4187.namprd15.prod.outlook.com (2603:10b6:a03:2e4::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5417.26; Tue, 12 Jul 2022 05:49:32 +0000 Received: from SA1PR15MB5109.namprd15.prod.outlook.com ([fe80::e8cd:89e9:95b6:e19a]) by SA1PR15MB5109.namprd15.prod.outlook.com ([fe80::e8cd:89e9:95b6:e19a%8]) with mapi id 15.20.5417.026; Tue, 12 Jul 2022 05:49:32 +0000 From: Song Liu To: Luis Chamberlain CC: Peter Zijlstra , Steven Rostedt , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Masami Hiramatsu , "Naveen N. Rao" , "David S. Miller" , Anil S Keshavamurthy , Kees Cook , Song Liu , bpf , Christoph Hellwig , Davidlohr Bueso , lkml , Linux-MM , Daniel Borkmann , Kernel Team , "x86@kernel.org" , "dave.hansen@linux.intel.com" , "rick.p.edgecombe@intel.com" , "linux-modules@vger.kernel.org" Subject: Re: [PATCH v6 bpf-next 0/5] bpf_prog_pack followup Thread-Topic: [PATCH v6 bpf-next 0/5] bpf_prog_pack followup Thread-Index: AQHYklIC37qezjyxh0moueFgoO/pNa1zhdgAgAAO4YCAABD0AIAAC/MAgADwxACAAEM5AIAAKMMAgAAvboCABOqLgIAAGVQA Date: Tue, 12 Jul 2022 05:49:32 +0000 Message-ID: References: <20220707223546.4124919-1-song@kernel.org> <863A2D5B-976D-4724-AEB1-B2A494AD2BDB@fb.com> <6214B9C9-557B-4DC0-BFDE-77EAC425E577@fb.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: Apple Mail (2.3696.100.31) x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: f1e399bb-bfb0-4ee8-3d3f-08da63ca4b7b x-ms-traffictypediagnostic: SJ0PR15MB4187:EE_ 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: 7iaLjseLnkTAysLtbrkh7Onl3+Lh2s/edeiPFdxHMX0vICoyNFxSVtMFpYhzH5yvytTYvuGHqndb/0FrjVUDAVO2lcdsyvC5Bqk9kLBgy1yTh8F73i2pFGkiO3wBF+jcIJveVG8+eigDDAw7PQgrFzg78i8KNtEaZdVS9n8Wc0JfOx4v5pVReGt5P5w2xAwce0vFnAfFJ/KcRFsvEVUQiqkRhJCD/6RBuo88k9i/6HKoPqJD5W+Qqf6Xa0g5OLtY5GLIHwiUnEvxw/c/Ym3u/La9dRIOcZTldQClTxbTzBg4oXXCtjUR4Eho/4YcTrBHo0n981KSEaL+2e3es/AjM3jhWa5YlCA2dTPpZOiFblnffw9HbIyU7aunTl5XVSzfsLT96hleAOF1Oxs+cJwE5q5uwm2o04OSDCToBWtIek3Cc2tive2I3K/LCgm+A/HPRUU8zXrEgCDkjt36NfJwC0jiE2poUfy0TBF3UDjZ9Xv2MRlo5IuK9jLbZ99B4EzC+IL9C9op0xh7/0Zfnz08lU4Tbp/bD9a6DCDAvND2R0i9k/j71MCVZqyIAXbptTYKUB06suRVs3njtNEIFhfjlHPfziezDC0iQkq0+lVw+/TMuLDYRO3l9omr5FWMvpGMCHS8kpv2vnXf46IEyLNSN5biGKcJPbTPWy5ZJylX4y2n4O9pLg8rRDNNKejbltcySmRL+ANg9eIh9gxSlpqQG+gPlLA9CQ7qUUywlxwOXa2DBuqV6NEYH083SR+Xp3cge8RkENc+8dDJrje+lc3wl+Lw6nqomMTLghRXpD9EPtbf61MdQJ1bL1re1RodlAccH/1z1EvvzGARk74nzCQa999LN2K8nscXzSrF4ROz6Ek= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SA1PR15MB5109.namprd15.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(4636009)(366004)(136003)(396003)(39860400002)(346002)(376002)(66556008)(71200400001)(64756008)(8676002)(76116006)(53546011)(66446008)(66476007)(54906003)(2906002)(66946007)(86362001)(4326008)(38070700005)(41300700001)(2616005)(6506007)(6486002)(186003)(7416002)(8936002)(5660300002)(122000001)(316002)(33656002)(36756003)(38100700002)(91956017)(6512007)(478600001)(6916009)(45980500001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?44ZAj86K2qJdkELXlLTIePAzXKfucdWml4gsf5ZUglcXZZZoeYi9hyZtWUHp?= =?us-ascii?Q?lx3Hzn4JrNGSebtt8ydOhSXWOdFOmPcyQA0i0lnBuajpgEYxkdheJjd7yEbV?= =?us-ascii?Q?T+V72glX4d6VvqqKn+Sr+NowVSUeNJRWOmHeJGaMRoLlBbxhAfw6KQ4b3mp6?= =?us-ascii?Q?e3i/bfYWX5UN5Ot4y2DrD9enDTs+yJR9UKLXYMf7QOIJMpYCMrkchVBZllXH?= =?us-ascii?Q?RbuFfK0we4SfMBgzFDp10v6liDCELA20T+EmPau6r4wXNpgT7Lf6B76AlCZI?= =?us-ascii?Q?SSPR6LW2fFqNNY3awJoUgYU6Kry0fynjWhzindD5sxY9u0WqVM2qfPB6Tyqb?= =?us-ascii?Q?Unkh5sp8qO0dRdkSYOctOG61APF52TvFwqvHDk+W/wM2tD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MEnTIQHpT2M44a//2Z1PySCFQF8iYkMV8v0GsUwaz?= =?us-ascii?Q?7r7+EFtXAOK2xxRmSdZlH1hhsHUCHu14pO1r0Bd4+s1RFfHloLysfT1/A/6i?= =?us-ascii?Q?XS0EMdOcB695534bO6adc7JeiGcisfPp9FQYT4lE/4RtOs58vqSuVXRoZlr2?= =?us-ascii?Q?YFUODkJXEfV3eF7J2WghMFEsF9AEWom355aNOZRrNIWprpTrvtpPa1tzeu5Y?= =?us-ascii?Q?7CbMcureWNBjcP+461Knb4AgREKcuAkipHsn0D/nGqfV0avZBTJMlJ7qbhIO?= =?us-ascii?Q?R87ZwiNYSAPsLAGWIBr0jfSL6YomOL8Fsm1RGnRwGR1XUEm+4KhY09JA66xC?= =?us-ascii?Q?pnziV3ZF1jbNEuKnLMen3q4=3D?= Content-Type: text/plain; charset="us-ascii" Content-ID: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: fb.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: SA1PR15MB5109.namprd15.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: f1e399bb-bfb0-4ee8-3d3f-08da63ca4b7b X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Jul 2022 05:49:32.6945 (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: UNS1J8s24yXhcDyHXIQ/8SBBKFY4aQDGOczhj3geK5NwgeQ4N8PP8CfpEnAl/8R9bTqyFitQqSQ0viF5hv9qrQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR15MB4187 X-Proofpoint-GUID: ZpJvgOMD4388xJhJRKxZ_vt5tKHgcvWp X-Proofpoint-ORIG-GUID: ZpJvgOMD4388xJhJRKxZ_vt5tKHgcvWp X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-07-12_03,2022-07-08_01,2022-06-22_01 ARC-Authentication-Results: i=2; imf16.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=fetXY+po; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf16.hostedemail.com: domain of "prvs=81920abf3d=songliubraving@fb.com" has no SPF policy when checking 67.231.145.42) smtp.mailfrom="prvs=81920abf3d=songliubraving@fb.com"; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657605017; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=68Rkt/xyvNvra5g5IZ+9xxwRVuxlsCpiH7rRWJS2nAk=; b=mFbyb+13ikxPHCxSkX0RCppBQufnDrcbfPQzMa5UcbyFRb6mZZovt8Qjb8Y17nrw/zFJL4 mPl94OgVj3SgT9upE8iXQemKp/Pl+Z6+ahPei+Lli6G2Py/mcB5aTtmR50D3mnkS0TWORS 1n5O7+64YiLcsJWAyQIPtmjr55BPoUQ= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1657605017; a=rsa-sha256; cv=pass; b=VXqCkIcrdlXLdTDf4X0pemgT3SPOsMsSGcucU5lBH0pgtkzJnS7GOtNE+t0RSDExjG7oMU K5ES6JAh8Bgb1vhKJCXVmAoxpcya4o72HRvMXJrnXz3m5QMR5jodqrBi6Ac14PRRzVdYR7 7Eeb4EnXLEqdOkPKi9KYPcgH6fuqATs= X-Rspam-User: Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=fetXY+po; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf16.hostedemail.com: domain of "prvs=81920abf3d=songliubraving@fb.com" has no SPF policy when checking 67.231.145.42) smtp.mailfrom="prvs=81920abf3d=songliubraving@fb.com"; arc=pass ("microsoft.com:s=arcselector9901:i=1") X-Stat-Signature: 4yshysxoqn6dxak8bjnoyx5dze4ddfj9 X-Rspamd-Queue-Id: AF523180057 X-Rspamd-Server: rspam04 X-HE-Tag: 1657605017-904324 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: > On Jul 11, 2022, at 9:18 PM, Luis Chamberlain wrote: >=20 > On Sat, Jul 09, 2022 at 01:14:23AM +0000, Song Liu wrote: >>> On Jul 8, 2022, at 3:24 PM, Luis Chamberlain wrote: >>>=20 >>>> 1) Rename module_alloc_huge as module_alloc_text_huge(); >>>=20 >>> module_alloc_text_huge() is too long, but I've suggested names before >>> which are short and generic, and also suggested that if modules are >>> not the only users this needs to go outside of modules and so >>> vmalloc_text_huge() or whatever. >>>=20 >>> To do this right it begs the question why we don't do that for the >>> existing module_alloc(), as the users of this code is well outside of >>> modules now. Last time a similar generic name was used all the special >>> arch stuff was left to be done by the module code still, but still >>> non-modules were still using that allocator. From my perspective the >>> right thing to do is to deal with all the arch stuff as well in the >>> generic handler, and have the module code *and* the other users which >>> use module_alloc() to use that new caller as well. >>=20 >> The key difference between module_alloc() and the new API is that the=20 >> API will return RO+X memory, and the user need text-poke like API to >> modify this buffer. Archs that do not support text-poke will not be >> able to use the new API. Does this sound like a reasonable design? [...] > I believe you are mentioning requiring text_poke() because the way > eBPF code uses the module_alloc() is different. Correct me if I'm > wrong, but from what I gather is you use the text_poke_copy() as the data > is already RO+X, contrary module_alloc() use cases. You do this since you= r > bpf_prog_pack_alloc() calls set_memory_ro() and set_memory_x() after > module_alloc() and before you can use this memory. This is a different ty= pe > of allocator. And, again please correct me if I'm wrong but now you want = to > share *one* 2 MiB huge-page for multiple BPF programs to help with the > impact of TLB misses. Yes, sharing 1x 2MiB huge page is the main reason to require text_poke.=20 OTOH, 2MiB huge pages without sharing is not really useful. Both kprobe and ftrace only uses a fraction of a 4kB page. Most BPF programs and=20 modules cannot use 2MiB either. Therefore, vmalloc_rw_exec() doesn't add much value on top of current module_alloc().=20 > A vmalloc_ro_exec() by definition would imply a text_poke(). >=20 > Can kprobes, ftrace and modules use it too? It would be nice > so to not have to deal with the loose semantics on the user to > have to use set_vm_flush_reset_perms() on ro+x later, but > I think this can be addressed separately on a case by case basis. I am pretty confident that kprobe and ftrace can share huge pages with=20 BPF programs. I haven't looked into all the details with modules, but=20 given CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC, I think it is also=20 possible.=20 Once this is done, a regular system (without huge BPF program or huge modules) will just use 1x 2MB page for text from module, ftrace, kprobe,=20 and bpf programs.=20 >=20 > But a vmalloc_ro_exec() with a respective free can remove the > requirement to do set_vm_flush_reset_perms(). Removing the requirement to set_vm_flush_reset_perms() is the other reason to go directly to vmalloc_ro_exec().=20 My current version looks like this: void *vmalloc_exec(unsigned long size); void vfree_exec(void *ptr, unsigned int size); ro is eliminated as there is no rw version of the API.=20 The ugly part is @size for vfree_exec(). We need it to share huge=20 pages.=20 Under the hood, it looks similar to current bpf_prog_pack_alloc and bpf_prog_pack_free.=20 Thanks, Song