From patchwork Mon Oct 28 20:29:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13854106 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C93E6D5B149 for ; Mon, 28 Oct 2024 20:29:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4CBE36B00A1; Mon, 28 Oct 2024 16:29:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 47B796B00A2; Mon, 28 Oct 2024 16:29:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 343EE6B00A3; Mon, 28 Oct 2024 16:29:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 124916B00A1 for ; Mon, 28 Oct 2024 16:29:42 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id BFF4AA9DDD for ; Mon, 28 Oct 2024 20:29:41 +0000 (UTC) X-FDA: 82724151090.12.931CFC1 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf18.hostedemail.com (Postfix) with ESMTP id AAB291C000A for ; Mon, 28 Oct 2024 20:29:29 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=rhTWfGrr; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf18.hostedemail.com: domain of 3M_QfZwYKCNoOQNAJ7CKKCHA.8KIHEJQT-IIGR68G.KNC@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3M_QfZwYKCNoOQNAJ7CKKCHA.8KIHEJQT-IIGR68G.KNC@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730147251; a=rsa-sha256; cv=none; b=v4EjMRa3EiJzX5Tur2Eoze/PGLLA5DRE3QWbq+O1vfHe4YGKxiL05K7RrPBVc/S+3UlMci dGn2N5kNFc8h9l8ioLt0d53/y/Twg7NiGREIWXd8ujqUgEK4Apkc0I74mSPip9quE5vpTj Qf3TD0fwhBYWpmRsNLYdodEcxDnn1rs= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=rhTWfGrr; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf18.hostedemail.com: domain of 3M_QfZwYKCNoOQNAJ7CKKCHA.8KIHEJQT-IIGR68G.KNC@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3M_QfZwYKCNoOQNAJ7CKKCHA.8KIHEJQT-IIGR68G.KNC@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730147251; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=AQu7lVPjZfxagsQISUssNV39w+zFZe7vUI/ZMaqhOHY=; b=OKnbqoW6l0fg1anLRbb9qLG6KIXm0+k/C9fcbEsq968EFbOeDb3L0xgU3sqnjg9ehoeT6i 5epa7zQvjRkNQ1EEz3S3onjA9kciweajDvnBkhCGqpadhfxuyYTxB1WoYJ5IeQbtRFdyBI WdZ7JkkXsfYpD5A5u0n/xnfYmUWeBBQ= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e376aa4586so85747657b3.1 for ; Mon, 28 Oct 2024 13:29:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730147379; x=1730752179; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=AQu7lVPjZfxagsQISUssNV39w+zFZe7vUI/ZMaqhOHY=; b=rhTWfGrrOufrMni+z9vkqDKmE+8y1UD2nwlozBVNzzAtfxMnboj0jYZfG7IcZK3QEr x613IuH/+QONLdZx7s5/ccrfb1MxvPsk7rw0cOrIqtfH7GDTNHClrAS5nS023PPFQ002 3fEde3lGme0wmuzeqYS+3WhBy3anNo05X7W3A3i9TjXk4Thr7I6P6BISSKIN3Bofdsw+ 0W1iRhaz8Z8JQTwPooW9feDysiXbU1jH22mEPDfG8dukD398xs1/PP0yLA/FTjEidRLl /uPLaOHWtiFCCqUYfY071xdjEac2/H+tAT3zPbEt2lWYYDKZO6vA7VuqJhTCzEiVvCjE TcEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730147379; x=1730752179; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=AQu7lVPjZfxagsQISUssNV39w+zFZe7vUI/ZMaqhOHY=; b=Z8Sbm0+Tn2ObmPHE/GW3UFASPbLnlvikWVJwxk0bpVlKlaxfh5GvOnO7HB8hSzW/m4 3OcQrz35AlWetyqVjxLKKsrGXQvKSh3YcDPkmZ2Vvg9naKUexhsvDkvkIEtboPunGJZv 0VPlC9Rf+nxmOGpPbffWZauOFTTv23git/Vv3a/pPg8OQjbdjMxHGE9Am99WR3H98MVU 3ekPMHewup9yWd5OfDUq3uLTeUv4aOKAxKr2wFkEXXr0g5CjTAiMvFmn0D75pQ+lkq10 ep3/+J69a0OOJkmbV1MboNiKcJL0votj83zSFcq4T/eJBNlhhH780y+qQT3njjZUI6yV MbOg== X-Forwarded-Encrypted: i=1; AJvYcCVovvVAlaZDLCkbA9bOLyfB8zJGRhS459avrJatgIseYKIgAv5u2GG/de9bZfEpkTWTzVYxUNEOnQ==@kvack.org X-Gm-Message-State: AOJu0YywHsTp2UPdmaNgA/WRJm2hBQfVYMplRCH39fAaozzoHGRl1X2T 2W18q1Rmcgq5JVrcRW5y8mpxcHattJkuGxDZtsk3lJUzxyTLryeplm+buaNwkQvirTfxVgLJK9s +hA== X-Google-Smtp-Source: AGHT+IHCn/Js3lcT5veuAC24+CSLFRcHwssAV+kTrC2tEk8mKNMzHsJA6QhYnulIRBhR9Zrky3OLa9mceqs= X-Received: from surenb-desktop.mtv.corp.google.com ([2a00:79e0:2e3f:8:1cfe:d46c:cf07:a219]) (user=surenb job=sendgmr) by 2002:a81:f10a:0:b0:648:fc8a:cd23 with SMTP id 00721157ae682-6e9d893d125mr2401967b3.2.1730147379090; Mon, 28 Oct 2024 13:29:39 -0700 (PDT) Date: Mon, 28 Oct 2024 13:29:35 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Message-ID: <20241028202935.1047017-1-surenb@google.com> Subject: [PATCH 1/1] alloc_tag: avoid execmem_vmap() when !MMU From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: arnd@kernel.org, arnd@arndb.de, rppt@kernel.org, pasha.tatashin@soleen.com, mcgrof@kernel.org, song@kernel.org, mhiramat@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, surenb@google.com, kernel test robot X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: AAB291C000A X-Stat-Signature: x3cdnruzbp6sznphazfkx16qpib9g76x X-Rspam-User: X-HE-Tag: 1730147369-130170 X-HE-Meta: U2FsdGVkX18wxuFI4FsB1cKotr3Auri8uWCaPlgYMeoAQ9uqhXgqmR1O2bvoLUzdihzvi95y2eM9RILEFojqS5yzxdgcY12F4tNUyqE6wrp/ZKA0Y/yzlhUFs8dLRSCRb4e9owheeMU4mqBdjDObsBk8ixOAlllWSVSzH9AKw74uHviEvc2oAMVtiNWBzDTywmCfBLu+EAbj4KEQU9db4AzTm6+um7DJW4BXEyP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TROc5YyttDjZj6kDdFMALQd9dK8lLtCnbio99OcQzj50dYkFMbpUKfu1Onm1cSZZum0aOuy1CaTuS+vGqyBaZWhV3yBPXA0erVSz8uKPQTUJyjlspVziYzeM4mkr5hVzKSj1HkoMv8VLu5hCr+4QBb667ii49PWwOAoUnl5qrFR3/SlSkSxgJy6lVAfQy18ZH1pCY5mkT/IU0o2CPf/+EBF3aTnHUOmplAW3GHMfMgyHXXUL2w0CUUQcNdJlQ80+WoUSCNt4Y+v0eiG6FDa5fry3+pBnTmNEZIGzGkxvrlJCmlblMVSVTHi25xYoau9FF9OPNz4/9rKUPWwTb3GuioNKdnEnO3mqUmzG6suy6cQFNSiJ7vcK4I= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: With CONFIG_MMU=n __get_vm_area_node() is not available and memory for the allocation tags cannot be populated as needed. For this case, populate the required memory at initialization time. Fixes: 57bc3834fb6f ("alloc_tag: populate memory for module tags as needed") Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202410250808.dQGyYjlk-lkp@intel.com/ Closes: https://lore.kernel.org/oe-lkp/202410251525.9f85854d-oliver.sang@intel.com Closes: https://lore.kernel.org/oe-kbuild-all/202410261016.IO7C6Cml-lkp@intel.com/ Closes: https://lore.kernel.org/oe-kbuild-all/202410270919.LebQlmxD-lkp@intel.com/ Cc: Arnd Bergmann Cc: Mike Rapoport (Microsoft) Signed-off-by: Suren Baghdasaryan --- include/linux/execmem.h | 2 ++ lib/alloc_tag.c | 23 ++++++++++++++++++++++- mm/execmem.c | 32 ++++++++++++++++---------------- 3 files changed, 40 insertions(+), 17 deletions(-) base-commit: 92409df3e00a17d6fd5bb27732fa186749725ed5 diff --git a/include/linux/execmem.h b/include/linux/execmem.h index 5a5e2917f870..64130ae19690 100644 --- a/include/linux/execmem.h +++ b/include/linux/execmem.h @@ -139,6 +139,7 @@ void *execmem_alloc(enum execmem_type type, size_t size); */ void execmem_free(void *ptr); +#ifdef CONFIG_MMU /** * execmem_vmap - create virtual mapping for EXECMEM_MODULE_DATA memory * @size: size of the virtual mapping in bytes @@ -148,6 +149,7 @@ void execmem_free(void *ptr); * Return: the area descriptor on success or %NULL on failure. */ struct vm_struct *execmem_vmap(size_t size); +#endif /** * execmem_update_copy - copy an update to executable memory diff --git a/lib/alloc_tag.c b/lib/alloc_tag.c index c1ddac2d29f0..1c74942e6dfd 100644 --- a/lib/alloc_tag.c +++ b/lib/alloc_tag.c @@ -268,7 +268,6 @@ void __init alloc_tag_sec_init(void) #ifdef CONFIG_MODULES static struct maple_tree mod_area_mt = MTREE_INIT(mod_area_mt, MT_FLAGS_ALLOC_RANGE); -static struct vm_struct *vm_module_tags; /* A dummy object used to indicate an unloaded module */ static struct module unloaded_mod; /* A dummy object used to indicate a module prepended area */ @@ -391,6 +390,9 @@ static bool find_aligned_area(struct ma_state *mas, unsigned long section_size, return false; } +#ifdef CONFIG_MMU +static struct vm_struct *vm_module_tags; + static int vm_module_tags_populate(void) { unsigned long phys_size = vm_module_tags->nr_pages << PAGE_SHIFT; @@ -417,6 +419,13 @@ static int vm_module_tags_populate(void) return 0; } +#else +static int vm_module_tags_populate(void) +{ + /* Memory was already allocated */ + return 0; +} +#endif static void *reserve_module_tags(struct module *mod, unsigned long size, unsigned int prepend, unsigned long align) @@ -561,6 +570,7 @@ static void replace_module(struct module *mod, struct module *new_mod) static int __init alloc_mod_tags_mem(void) { +#ifdef CONFIG_MMU /* Map space to copy allocation tags */ vm_module_tags = execmem_vmap(MODULE_ALLOC_TAG_VMAP_SIZE); if (!vm_module_tags) { @@ -578,6 +588,13 @@ static int __init alloc_mod_tags_mem(void) } module_tags.start_addr = (unsigned long)vm_module_tags->addr; +#else + /* Allocate space to copy allocation tags */ + module_tags.start_addr = (unsigned long)execmem_alloc(EXECMEM_MODULE_DATA, + MODULE_ALLOC_TAG_VMAP_SIZE); + if (!module_tags.start_addr) + return -ENOMEM; +#endif module_tags.end_addr = module_tags.start_addr + MODULE_ALLOC_TAG_VMAP_SIZE; /* Ensure the base is alloc_tag aligned when required for indexing */ module_tags.start_addr = alloc_tag_align(module_tags.start_addr); @@ -587,6 +604,7 @@ static int __init alloc_mod_tags_mem(void) static void __init free_mod_tags_mem(void) { +#ifdef CONFIG_MMU int i; module_tags.start_addr = 0; @@ -594,6 +612,9 @@ static void __init free_mod_tags_mem(void) __free_page(vm_module_tags->pages[i]); kfree(vm_module_tags->pages); free_vm_area(vm_module_tags); +#else + execmem_free((void *)module_tags.start_addr); +#endif } #else /* CONFIG_MODULES */ diff --git a/mm/execmem.c b/mm/execmem.c index 5c0f9f2d6f83..317b6a8d35be 100644 --- a/mm/execmem.c +++ b/mm/execmem.c @@ -64,6 +64,22 @@ static void *execmem_vmalloc(struct execmem_range *range, size_t size, return p; } + +struct vm_struct *execmem_vmap(size_t size) +{ + struct execmem_range *range = &execmem_info->ranges[EXECMEM_MODULE_DATA]; + struct vm_struct *area; + + area = __get_vm_area_node(size, range->alignment, PAGE_SHIFT, VM_ALLOC, + range->start, range->end, NUMA_NO_NODE, + GFP_KERNEL, __builtin_return_address(0)); + if (!area && range->fallback_start) + area = __get_vm_area_node(size, range->alignment, PAGE_SHIFT, VM_ALLOC, + range->fallback_start, range->fallback_end, + NUMA_NO_NODE, GFP_KERNEL, __builtin_return_address(0)); + + return area; +} #else static void *execmem_vmalloc(struct execmem_range *range, size_t size, pgprot_t pgprot, unsigned long vm_flags) @@ -368,22 +384,6 @@ void execmem_free(void *ptr) vfree(ptr); } -struct vm_struct *execmem_vmap(size_t size) -{ - struct execmem_range *range = &execmem_info->ranges[EXECMEM_MODULE_DATA]; - struct vm_struct *area; - - area = __get_vm_area_node(size, range->alignment, PAGE_SHIFT, VM_ALLOC, - range->start, range->end, NUMA_NO_NODE, - GFP_KERNEL, __builtin_return_address(0)); - if (!area && range->fallback_start) - area = __get_vm_area_node(size, range->alignment, PAGE_SHIFT, VM_ALLOC, - range->fallback_start, range->fallback_end, - NUMA_NO_NODE, GFP_KERNEL, __builtin_return_address(0)); - - return area; -} - void *execmem_update_copy(void *dst, const void *src, size_t size) { return text_poke_copy(dst, src, size);