Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp254780imw; Thu, 14 Jul 2022 00:47:01 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vPRyxAya/JoobHHoTZiPavlyXe39PpipVNfGbLs6BPF/2H8ijQwPiKIfH/B0d73W/Ft8Of X-Received: by 2002:a05:6402:3807:b0:435:20fb:318d with SMTP id es7-20020a056402380700b0043520fb318dmr10255537edb.272.1657784821756; Thu, 14 Jul 2022 00:47:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657784821; cv=none; d=google.com; s=arc-20160816; b=gBCPRYl/oU+N4U8Tg49TnbNWfBZQNxW0kEbsLsOd5YWheEfLL99yuW8JoWkZHyAbot itfFpUdQW4sZgp40nOiCkiV/lonIGXqXJfjNB91+Pe+76eOZPPj6GJtYRpHjuECGb4RQ Jk908kqRb2MGzuVJB4sL//jlUkdmgOuL2QP7YxYdjv8bKcm38od9FwVXHTSXR+HvGHHe ADoaSz8ZMNhpvKadA620Rv8os+9nWS64Q3Eafx16xZUb2zDgu11RhXwt5zWrg5Trl5vJ QhBkZ/L2L9D5UCo7sbamrn0836y1Vv0NuKl/ixPrtPAtWqiUBMIzSE3x2X4FakpfLVut 9dow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=MxjTs9nuJ3FmUOtUGZD4K0rKKYlzahKqtMX7rQs+RMQ=; b=EBtq8/Rs3MnahEDKyt8IokvHEoMWGci+iyPSzBgwyHK5spEY8bUUjH5c6FT6fx49LC isjnBQ82yKpocSsrBqrsKoIgTW7XWiOK5qT8yUNg0vKc/t/LcSy2/2Xv/irE7gvt7N9G x2aAs6ktqILhfK4oxDStPHmRye/sY7lWxVs/H8G7tDMUx9qIxLEQMN5HvrwDet3OrBK7 Zc85ZjY1lkHmXjxGkzN2Bjn6dgaAwXXfWMUpIOEj1QViGcQ0z9ySWPxRS/3rgTog9HTm n8jZmq4DTtv7Sf0wDDBXuUS5cIMfV2eneFZsdRdRPNJPZFz9wFYluoBrRxEnLLEJUP8o RRPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=P+HF2qea; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kl8-20020a170907994800b006f40efd4b88si1291150ejc.812.2022.07.14.00.46.37; Thu, 14 Jul 2022 00:47:01 -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=desiato.20200630 header.b=P+HF2qea; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234446AbiGNH1E (ORCPT + 99 others); Thu, 14 Jul 2022 03:27:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229699AbiGNH1D (ORCPT ); Thu, 14 Jul 2022 03:27:03 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8543A1A828; Thu, 14 Jul 2022 00:27:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=MxjTs9nuJ3FmUOtUGZD4K0rKKYlzahKqtMX7rQs+RMQ=; b=P+HF2qeaBGfEDHrWZkyaJPn3IB QiNrtA//HWV+0ORiO+86u7mo74SlcDdcVqFoIgZCWMGIoxYPaVQGU+72wQPOBiQ0vqF2fr+XRsVbn nG4Lm56rEpjCfhHtpiCFZf03XpUsAJZgKdFlccUm7lCAO3u1M/WuvVAV2x9aOziByeZBhRqtX/9ft 5DZmULcqm2l89KTXWlaN47QZXt8XCD3bthIsytQv8r1CKT3O3kx6tAfz7rw9SYprDq1RXGJq2pCc/ jB9UMMQ/l8jzUSCKC6r6Bmgb5It5ci3rvZPoHr5b7OlcWI/3C+MzPHmlXP8EX53pPhhfRJrmH2Fyh PzeRPolA==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=worktop.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1oBtEs-003mx0-U9; Thu, 14 Jul 2022 07:26:23 +0000 Received: by worktop.programming.kicks-ass.net (Postfix, from userid 1000) id D0146980083; Thu, 14 Jul 2022 09:26:22 +0200 (CEST) Date: Thu, 14 Jul 2022 09:26:22 +0200 From: Peter Zijlstra To: Christoph Hellwig Cc: Song Liu , bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-modules@vger.kernel.org, mcgrof@kernel.org, rostedt@goodmis.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, mhiramat@kernel.org, naveen.n.rao@linux.ibm.com, davem@davemloft.net, anil.s.keshavamurthy@intel.com, keescook@chromium.org, dave@stgolabs.net, daniel@iogearbox.net, kernel-team@fb.com, x86@kernel.org, dave.hansen@linux.intel.com, rick.p.edgecombe@intel.com, akpm@linux-foundation.org Subject: Re: [PATCH bpf-next 1/3] mm/vmalloc: introduce vmalloc_exec which allocates RO+X memory Message-ID: References: <20220713071846.3286727-1-song@kernel.org> <20220713071846.3286727-2-song@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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 Wed, Jul 13, 2022 at 10:16:36PM -0700, Christoph Hellwig wrote: > On Wed, Jul 13, 2022 at 12:20:09PM +0200, Peter Zijlstra wrote: > > Start by adding VM_TOPDOWN_VMAP, which instead of returning the lowest > > (leftmost) vmap_area that fits, picks the higests (rightmost). > > > > Then add module_alloc_data() that uses VM_TOPDOWN_VMAP and make > > ARCH_WANTS_MODULE_DATA_IN_VMALLOC use that instead of vmalloc (with a > > weak function doing the vmalloc). > > > > This gets you bottom of module range is RO+X only, top is shattered > > between different !X types. > > > > Then track the boundary between X and !X and ensure module_alloc_data() > > and module_alloc() never cross over and stay strictly separated. > > > > Then change all module_alloc() users to expect RO+X memory, instead of > > RW. > > > > Then make sure any extention of the X range is 2M aligned. > > > > And presto, *everybody* always uses 2M TLB for text, modules, bpf, > > ftrace, the lot and nobody is tracking chunks. > > > > Maybe migration can be eased by instead providing module_alloc_text() > > and ARCH_WANTS_MODULE_ALLOC_TEXT. > > This all looks pretty sensible. How are we going to do the initial > write to the executable memory, though? With something like text_poke_memcpy(). I suppose that the proposed ARCH_WANTS_MODULE_ALLOC_TEXT needs to imply availability of that too. If the 4K copy thing ends up being a bottleneck we can easily extend that to have a 2M option as well.