Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4705363imw; Tue, 12 Jul 2022 12:44:36 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tLzWspPK4HqvrGFXqEdnBsHnORXZhgpHu1SQ55dcNNRmG4S8Gk1bwxjB1Lyu1CG84zNH6j X-Received: by 2002:a17:902:d405:b0:16b:f1ee:27c0 with SMTP id b5-20020a170902d40500b0016bf1ee27c0mr24790776ple.10.1657655076259; Tue, 12 Jul 2022 12:44:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657655076; cv=none; d=google.com; s=arc-20160816; b=luvyQoSCL9t1vIT1HlIB3JQD+rw2XOS5+BkxSILkKXfdmZU4Fepphx9kjkf69+dTm1 lJevF+r0/oWIgDMBXIjRERfLln1ObzE6VwEeffSeSlOSkcUyR6goUCEpvNfyOzviBZ+O quKLiU1HvYd+ZXR+YFqtYRSy9shBoJCNJjNrktgj3U1Mew57yOHiZbYxqGDx9TpPerjw S+tegEFJWxC1qrbe0AbDjC+7zCP4sFNeUC84dqUwdPK6kHTlkT/D4y3OG8+PGNOl7V91 lN67eo4MdrzX12PEunghn/1tu4cO1ao7fkjmaMXyXTmrz8bWTLOSBHPIQRC8+cBSWzyx fClw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=5zn6hvHj4eKtfzqRScUEHMiIgZur5MyCCs29W1zBYWo=; b=ZvbzrS6dzPEnKltaGxOz3W8K+JJIdnVqWaHO4oiqkeUw+c8e2kMiyDQEl2lYTAefcl XYT7Dz+li/MUGSb9j/Ge+DZ0LmUXt0AMZJekcXCLPz29CmUDVgdmDuTsR8aUVjg43HG+ BLnq2YN1hBRzh8cZ5ZlRmLbQokcweCK6YGSZwpHctzl7I1x4EBzng7WN1ZFEAdjD5s2i n5iMeANOyjeIofuHFx5wej4eH3Y9A5sErml++nz3rX2WSfB38UXhJG9AxVeP3FKnnqly 7lyFhHsE4hgXwZFtOadIwDuI7vAfEcECcDCZGKv+hisgZOhXwXjX4lWuMvJyb8J0S7Xc aVog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=xxs5oqmr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a63-20020a639042000000b004117cd6d8basi12871870pge.266.2022.07.12.12.44.23; Tue, 12 Jul 2022 12:44:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=xxs5oqmr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231468AbiGLT2z (ORCPT + 99 others); Tue, 12 Jul 2022 15:28:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230191AbiGLT2d (ORCPT ); Tue, 12 Jul 2022 15:28:33 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39F2CE0F5E; Tue, 12 Jul 2022 12:04:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=5zn6hvHj4eKtfzqRScUEHMiIgZur5MyCCs29W1zBYWo=; b=xxs5oqmrZEfO2E2kxTPGNrkRA7 vBxlIZp9V+hqHw7UsxneA0WB6uEnzq62HTiQMSJlzBKphdX/f13tQpG50mucKGSRLyum5pR1eqxDj RFiCrTx/E6tlShgUgl6TZtHLYONAUGmmDpljk3YyL2wNRddKtfsrQFBX31dnnl4UmgIcDQn6Bhiy2 R1AYFBFhR1bQRM6WmKGxKr2aLGpVzm5FLCWYcpg23IdcOzHEdsHa14+A8AmKHKpyw95W/1onf4lBW HyF0WFSv56iDl0v13QjsccAx2nNtGNXoTClDAz2uatbs1mqzeOgB8GGcmUtfCbvtv9ss8P+BrIeKb gVzKuaVA==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1oBLBN-00E3qI-Ub; Tue, 12 Jul 2022 19:04:29 +0000 Date: Tue, 12 Jul 2022 12:04:29 -0700 From: Luis Chamberlain To: Song Liu 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 Message-ID: References: <863A2D5B-976D-4724-AEB1-B2A494AD2BDB@fb.com> <6214B9C9-557B-4DC0-BFDE-77EAC425E577@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: Luis Chamberlain X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 12, 2022 at 05:49:32AM +0000, Song Liu wrote: > > On Jul 11, 2022, at 9:18 PM, Luis Chamberlain wrote: > > > 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 your > > 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 type > > 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. > 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 > modules cannot use 2MiB either. Therefore, vmalloc_rw_exec() doesn't add > much value on top of current module_alloc(). Thanks for the clarification. > > A vmalloc_ro_exec() by definition would imply a text_poke(). > > > > 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 > BPF programs. Then wonderful, we know where to go in terms of a new API then as it can be shared in the future for sure and there are gains. > I haven't looked into all the details with modules, but > given CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC, I think it is also > possible. Sure. > 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, > and bpf programs. That would be nice, if possible, however modules will require likely its own thing, on my system I see about 57 MiB used on coresize alone. lsmod | grep -v Module | cut -f1 -d ' ' | \ xargs sudo modinfo | grep filename | \ grep -o '/.*' | xargs stat -c "%s - %n" | \ awk 'BEGIN {sum=0} {sum+=$1} END {print sum}' 60001272 And so perhaps we need such a pool size to be configurable. > > 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(). Yes fantastic. > 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. Alright. I am not sure if 2 MiB will suffice given what I mentioned above, and what to do to ensure this grows at a reasonable pace. Then, at least for usage for all architectures since not all will support text_poke() we will want to consider a way to make it easy to users to use non huge page fallbacks, but that would be up to those users, so we can wait for that. > The ugly part is @size for vfree_exec(). We need it to share huge > pages. I suppose this will become evident during patch review. > Under the hood, it looks similar to current bpf_prog_pack_alloc > and bpf_prog_pack_free. Groovy. Luis