Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4253733imw; Thu, 7 Jul 2022 15:39:19 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sbKP7MCwxqlZWiqABdeILTPnDhHLuHB/Dmf/TDV4P/lwyoc1d7NEA69Y3hGjwHl3+nJIcU X-Received: by 2002:aa7:8018:0:b0:528:9759:30f5 with SMTP id j24-20020aa78018000000b00528975930f5mr219766pfi.33.1657233559553; Thu, 07 Jul 2022 15:39:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657233559; cv=none; d=google.com; s=arc-20160816; b=YEo4ub+EzNNmXAhfyyBHRPJzWC5uuGKn3wHN0UXYfY5iL59P+wWPwYUKhVRDdXTtDX rBtUPteHA/vwRU3uRrZTDkqu0VtO3tYGDX3DvA6lnr3MtwOaodu3ca+B5C3X8EAfikop MHwooj75Rq/eUr+EfMCPueIONsZd7veCUjVhxhWjg8ccqZjH02dQQqhvsnA/+yvyr7Jt D0EbdaoYz2Raf0oZDloKumYCG45Sqb9DT3SkJbVuNAlDp7+giOAmjkubIGzOxH2IJZX/ shGz6r76zXSJZJsLe23OYRfwIEfbhHfYSe7wVXrUUMbASOx7HBSQPqxXumDfDUNrYqkj LyzQ== 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=y3hWCNHMEBo4Sf/VCDrsFqEixKayQPeja/oEcOgP5qi1UzcRsynADN7zDdXFZoAWDM 3SeSSXowGMk9wgIl6x15itQ+nd5P45V9BJHLLOtERnSOtg+fdFSL5SS1nz7V1vfBWJhi ajKoyy41VYIQ4l/gEWHZwNhzmzSA+Cx/0UrnYYcMBW6FJtuTAJljPS7566KBglbcEj1z zasebkfy05YUwMgtiCOASUiqtiJmmusmCuL5FDtOEazmq6CjxhuBhYZVZxQU+RXUcPmS We+C50D/sg2LiQjLLc0zkf9fkV7CAJXWHcQ2pzHUi3tyQx3mvNYGh9UipeqQhl680O3N 629g== 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 l16-20020a056a00141000b0052849e93874si26721483pfu.266.2022.07.07.15.39.06; Thu, 07 Jul 2022 15:39:19 -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 S236573AbiGGWgZ convert rfc822-to-8bit (ORCPT + 99 others); Thu, 7 Jul 2022 18:36:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236498AbiGGWgY (ORCPT ); Thu, 7 Jul 2022 18:36:24 -0400 Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 562F3CF3 for ; Thu, 7 Jul 2022 15:36:23 -0700 (PDT) Received: from pps.filterd (m0109332.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 267KPgr9030911 for ; Thu, 7 Jul 2022 15:36:22 -0700 Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3h5nw2f4t0-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 07 Jul 2022 15:36:22 -0700 Received: from twshared0725.22.frc3.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::e) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Thu, 7 Jul 2022 15:36:20 -0700 Received: by devbig932.frc1.facebook.com (Postfix, from userid 4523) id 573139D349C0; Thu, 7 Jul 2022 15:36:02 -0700 (PDT) From: Song Liu To: , , CC: , , , , , , Song Liu Subject: [PATCH v6 bpf-next 1/5] module: introduce module_alloc_huge Date: Thu, 7 Jul 2022 15:35:42 -0700 Message-ID: <20220707223546.4124919-2-song@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220707223546.4124919-1-song@kernel.org> References: <20220707223546.4124919-1-song@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8BIT X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-GUID: ppJdlkVR-KXkW7_QqeH5SFWvvN0yJ9wg X-Proofpoint-ORIG-GUID: ppJdlkVR-KXkW7_QqeH5SFWvvN0yJ9wg 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-07_17,2022-06-28_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