Received: by 2002:ac0:cd04:0:0:0:0:0 with SMTP id w4csp360135imn; Fri, 1 Jul 2022 17:19:04 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sqZlPm93E5W7c7FXf4JHEhb/AbsVUeMGzcdqS2pmlI9nl9Yu+SMQe972p81LYBoW1Ey/0k X-Received: by 2002:a17:902:e850:b0:16a:209a:971a with SMTP id t16-20020a170902e85000b0016a209a971amr23730598plg.163.1656721143863; Fri, 01 Jul 2022 17:19:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656721143; cv=none; d=google.com; s=arc-20160816; b=oQpWxHh4c5NVqz0t+rxthF2K6Yer/pPJK2GhkBkUmOoVkMm4SibSDJiDw4/n1TMZLq vbaxoHvD1i8Tf5JumwWoqe8KXxrJ9EuAZBDBhDwClSQhFYhHg/NuXS9FqP5/9+itV3wC 8rKwVg0MiOc7ul0ToBCDPf7DbfNF+tKP4sC2g5GXCiSLAdVgHUmw5YSuEnmzTnI0VyZ1 xEL6JgGRZ/T4zKB8co0vPgBqIUyUnWr2VOCJHqn/JAwoCaVagjqcXeB0kC4ozSseDJ1y hIOIbc0gGMD/wtFfJydqHCWM32EcgAENvSmZUe6mowD33G5vTQCQMMD11yhj5itXemVY mgAg== 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=8B/HM3ptEJgCCgROywH5nKBQG04ILNP2c9THBpwMy1E=; b=O0EMB2rZER9S9dV/Upo4xaQypE8/+kKymI5WmZkBwQV5n6ibI6As8aY4U1Htr3zMZD dsgj4mSxcn6gBujmjvw8Q/G47OKcftcSzJAgrbyhCJhPbAWthrR4Nhul9I/0esLklL1+ fAW+Js1AthzUqoVbmbnqFwcBSbA1+EXYE16+5dwzILy8k65TSzNw/JN4oJ5E6Pjd3DII hyJSw52OYf0YuUT08HCQ1b3h3ZysAI8clcQE7lzB0FRdh74Wru7X98xe4EIzjI0LQKAH g52Ex0bgS+1tqQE4yAzOONQQ8pPmb8x1DL+2j3i2YI10Dvs8QmuQ0jupQYqR4JZYkISI Tn5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=qiyDwZOk; 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 u17-20020a170902e5d100b0016a04a664fasi29512028plf.8.2022.07.01.17.18.49; Fri, 01 Jul 2022 17:19:03 -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=qiyDwZOk; 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 S231819AbiGAXU6 (ORCPT + 99 others); Fri, 1 Jul 2022 19:20:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230320AbiGAXU5 (ORCPT ); Fri, 1 Jul 2022 19:20:57 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79F1071BCF; Fri, 1 Jul 2022 16:20:56 -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=8B/HM3ptEJgCCgROywH5nKBQG04ILNP2c9THBpwMy1E=; b=qiyDwZOkrvOmJOoe2FwDFbTzFM K/d9ILfyE80Adsq2huKQqv752UIZTaV+hTXUS//Gcquo/ncQJr6sXzLf+OauLpeLiNkd268e3kkq6 uk3l6mgAFRcLLg5WVDcGJtO5DvfjaNgQ6CMhTzlQoZ/c+YzFruH6viS5XgXK+A23UW9jfL6ifivfA oZs6oECzIgv/RuYmuJ9eRXH0ySFS5uCcQYKLA22Plhr5AKVsyKOTE0dcplyb2aNcA8bjuZ+gp1e20 e07JtJcocOG0f0dJ8nMOUPv/o/W/06KI9Eg8bd9GUE11LyOXOu0LgvQ38HTVZeWVdLuc3uubuQqZ3 7Rk2xVVg==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1o7PwV-007P44-2w; Fri, 01 Jul 2022 23:20:55 +0000 Date: Fri, 1 Jul 2022 16:20:55 -0700 From: Luis Chamberlain To: Song Liu Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, x86@vger.kernel.org, dave.hansen@linux.intel.com, rick.p.edgecombe@intel.com, kernel-team@fb.com, daniel@iogearbox.net Subject: Re: [PATCH v5 bpf-next 1/5] module: introduce module_alloc_huge Message-ID: References: <20220624215712.3050672-1-song@kernel.org> <20220624215712.3050672-2-song@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220624215712.3050672-2-song@kernel.org> Sender: Luis Chamberlain X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 Fri, Jun 24, 2022 at 02:57:08PM -0700, Song Liu wrote: > Introduce module_alloc_huge, which allocates huge page backed memory in > module memory space. The primary user of this memory is bpf_prog_pack > (multiple BPF programs sharing a huge page). > > Signed-off-by: Song Liu I see mm not Cc'd. I'd like review from them. > --- > arch/x86/kernel/module.c | 21 +++++++++++++++++++++ > include/linux/moduleloader.h | 5 +++++ > kernel/module/main.c | 8 ++++++++ > 3 files changed, 34 insertions(+) > > diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c > index b98ffcf4d250..63f6a16c70dc 100644 > --- a/arch/x86/kernel/module.c > +++ b/arch/x86/kernel/module.c > @@ -86,6 +86,27 @@ void *module_alloc(unsigned long size) > return p; > } > > +void *module_alloc_huge(unsigned long size) > +{ > + gfp_t gfp_mask = GFP_KERNEL; > + void *p; > + > + if (PAGE_ALIGN(size) > MODULES_LEN) > + return NULL; > + > + p = __vmalloc_node_range(size, MODULE_ALIGN, > + MODULES_VADDR + get_module_load_offset(), > + MODULES_END, gfp_mask, PAGE_KERNEL, > + VM_DEFER_KMEMLEAK | VM_ALLOW_HUGE_VMAP, > + NUMA_NO_NODE, __builtin_return_address(0)); > + if (p && (kasan_alloc_module_shadow(p, size, gfp_mask) < 0)) { > + vfree(p); > + return NULL; > + } > + > + return p; > +} 1) When things like kernel/bpf/core.c start using a module alloc it is time to consider genearlizing this. 2) How we free is important, and each arch does something funky for this. This is not addressed here. And yes I welcome generalizing generic module_alloc() too as suggested before. The concern on my part is the sloppiness this enables. Luis > + > #ifdef CONFIG_X86_32 > int apply_relocate(Elf32_Shdr *sechdrs, > const char *strtab, > diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h > index 9e09d11ffe5b..d34743a88938 100644 > --- a/include/linux/moduleloader.h > +++ b/include/linux/moduleloader.h > @@ -26,6 +26,11 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section); > sections. Returns NULL on failure. */ > void *module_alloc(unsigned long size); > > +/* Allocator used for allocating memory in module memory space. If size is > + * greater than PMD_SIZE, allow using huge pages. Returns NULL on failure. > + */ > +void *module_alloc_huge(unsigned long size); > + > /* Free memory returned from module_alloc. */ > void module_memfree(void *module_region); > > diff --git a/kernel/module/main.c b/kernel/module/main.c > index fed58d30725d..349b2a8bd20f 100644 > --- a/kernel/module/main.c > +++ b/kernel/module/main.c > @@ -1613,6 +1613,14 @@ void * __weak module_alloc(unsigned long size) > NUMA_NO_NODE, __builtin_return_address(0)); > } > > +void * __weak module_alloc_huge(unsigned long size) > +{ > + return __vmalloc_node_range(size, 1, VMALLOC_START, VMALLOC_END, > + GFP_KERNEL, PAGE_KERNEL_EXEC, > + VM_FLUSH_RESET_PERMS | VM_ALLOW_HUGE_VMAP, > + NUMA_NO_NODE, __builtin_return_address(0)); > +} > + > bool __weak module_init_section(const char *name) > { > return strstarts(name, ".init"); > -- > 2.30.2 >