Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp822986iog; Fri, 24 Jun 2022 15:12:22 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tb4irXa3PdbnpGOmoS3eN9c6dVgRyg/hKLcma3dNPvqtnhGjAOdrgWCHlP04oP0O+92h7G X-Received: by 2002:a17:902:eb92:b0:168:911c:5946 with SMTP id q18-20020a170902eb9200b00168911c5946mr1162728plg.167.1656108742719; Fri, 24 Jun 2022 15:12:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656108742; cv=none; d=google.com; s=arc-20160816; b=LFQosDohDM7rK4EMT+6quSgblpMRRgY0m1UZ14VwuH9Wu59evvRpcDtgtxc1lYhGeO jhLs6oIUt2dWgSZkVTXTCsScztau03Z+2j00l+1O3IhSfccStP2x2SrsI9Hu5oBc5icV 6kH2TiGtCwOujpzc31ZXT6Z5ojqvIOyi74nAEF/1sGEwM1Lr+KUIGudG73K5T1jkQQK9 mFq/wLvinO6l/rbrPKlw4UsPeH2FLCQjFfLnOpF4H939/rRjiT3R1l8ZiFUZIQyUPDJ8 0A9Xtoi2QQx8E/zDEWsZ5cT3kTY9BkeLEGAaO1VX/xNaRnUWm8D7HM+tMvs5KTXPjh7r X59g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=szOZY6l34fQyNW7FNYZbHFoHqk+qlX3MABtFq61itlA=; b=B5EsY+pJQyzRAHUePh1Mge4FjOIS0sRu/Pnf6T7VPN3eM5ZJcJm6XGr10h9xrQBC2d uZeBhOQH1c201kk/+ELl8mQAO7LtOpQOkp+lzo+QyEYhhZvmJPjg2Jfwm7Rhmv6JAyzP l0OhPZkrIaPtlrV+CMfR3NOks4AgThGufGoIunM/CrwgqQP/9nzqkHGLpk+ZmiLDbw0e 1nV8q7kTBSl3+CUHpF4YiOaKC8+OEIOarF8VbGHC2uvO1JYVxUV5T2KM1Dz/z7aCrqUc iUiyQ3u/tgQ+gdBbB9dQip2INXDVkV0ZDg/YsaghyKZq7N5FDS6pW6uw3cqrHjM7p2ef cUPg== ARC-Authentication-Results: i=1; mx.google.com; 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 l186-20020a6391c3000000b003ff3d0bc82bsi4259292pge.729.2022.06.24.15.12.07; Fri, 24 Jun 2022 15:12:22 -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; 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 S231895AbiFXV5i convert rfc822-to-8bit (ORCPT + 99 others); Fri, 24 Jun 2022 17:57:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231875AbiFXV5h (ORCPT ); Fri, 24 Jun 2022 17:57:37 -0400 Received: from mx0a-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5D5187D40 for ; Fri, 24 Jun 2022 14:57:36 -0700 (PDT) Received: from pps.filterd (m0089730.ppops.net [127.0.0.1]) by m0089730.ppops.net (8.17.1.5/8.17.1.5) with ESMTP id 25OLaEJw009784 for ; Fri, 24 Jun 2022 14:57:36 -0700 Received: from maileast.thefacebook.com ([163.114.130.16]) by m0089730.ppops.net (PPS) with ESMTPS id 3gvce85n9b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Fri, 24 Jun 2022 14:57:35 -0700 Received: from twshared14818.18.frc3.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:83::4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Fri, 24 Jun 2022 14:57:35 -0700 Received: by devbig932.frc1.facebook.com (Postfix, from userid 4523) id C6D2094C3A15; Fri, 24 Jun 2022 14:57:22 -0700 (PDT) From: Song Liu To: , , CC: , , , , , Song Liu Subject: [PATCH v5 bpf-next 1/5] module: introduce module_alloc_huge Date: Fri, 24 Jun 2022 14:57:08 -0700 Message-ID: <20220624215712.3050672-2-song@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220624215712.3050672-1-song@kernel.org> References: <20220624215712.3050672-1-song@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8BIT X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-GUID: d_1pDiTBwkvdh0rssHm3ZmQwF_GiVnJt X-Proofpoint-ORIG-GUID: d_1pDiTBwkvdh0rssHm3ZmQwF_GiVnJt 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-06-24_09,2022-06-24_01,2022-06-22_01 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,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 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 --- 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; +} + #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