From mboxrd@z Thu Jan 1 00:00:00 1970 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 BAB66D5CCA6 for ; Wed, 30 Oct 2024 12:47:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 24C3E8D0002; Wed, 30 Oct 2024 08:47:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1F3FB8D0001; Wed, 30 Oct 2024 08:47:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0812C8D0002; Wed, 30 Oct 2024 08:47:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id D87B58D0001 for ; Wed, 30 Oct 2024 08:47:00 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 7CFC5A0B7A for ; Wed, 30 Oct 2024 12:47:00 +0000 (UTC) X-FDA: 82730242896.18.88CB9D8 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf25.hostedemail.com (Postfix) with ESMTP id 1DA39A001B for ; Wed, 30 Oct 2024 12:46:39 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="W/vmigNA"; spf=pass (imf25.hostedemail.com: domain of rppt@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730292363; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=1AJ0zpfYXzU7XoPgwYgc9mUesp7bTB3Ol4xsAXyMyfM=; b=nxhPk+b3FYIG5LlBp7tSD5emP1lrIvGe5WhPvk+DATG1slNmy9CtOoywEChHD2kcgypsiA k68vP29K69Z4yOO3GTMhoz0/wnbLkLYC9E6uOkqWFWwUccF7sfTcR+MzQ92U+H0tccY0gT qV0pM4x6etjdZuAs02tCsXALal5raZI= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="W/vmigNA"; spf=pass (imf25.hostedemail.com: domain of rppt@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730292363; a=rsa-sha256; cv=none; b=ZxKuDiStl7icTOiL4MQyffwUEfWeYm2MiWzbWSGlZB8ns0k7czY9vJeJl1xSBTN7G07v22 Ry+AYK+c//1BJyR4qulED/tDyJul+LRxeWCxgnwMGjX72uO/7NsNAKypSqUkMb7pB1K2v6 9249kJw5jjo2gOMUL6V48bDyYtuOiOc= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id D419BA40128; Wed, 30 Oct 2024 12:45:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4DC7C4CEE3; Wed, 30 Oct 2024 12:46:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730292417; bh=XO41anE+XMroSY1tEikHX5Rj9NNO7E3eB2ew5PJOOso=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=W/vmigNA+uvwPREdLWxs1c+Jj/ylmiNXQIaksBl63brZ4lq8ZDoJp549LnkqL1R8T YnmdJT3iZzgdQij+FdUmA7KsY55mDFDZ30rMn9CexRaskXBOaEEg64RxwCu8ehQT/6 rgaf938cRo0YIwZBrBp0IN4hRvonUcNh2MB5Y/Y5JQ8JXqtvsy/Ht7oC46LtxA0mc6 Pxs9mGCGaetFnn2bGyX8JmMwTKGwJ59z6Wa4IOgHFhh2wtIiAHkw/vWgr8y0fRGCxf y/3HmAWJpRtUo6Em9S7wvuoXu5cX0k1qK1UdnsH0646xyOLTpgH5xa4nlR5kXGD1Wh rPOz2RMIi7Ruw== Date: Wed, 30 Oct 2024 14:43:00 +0200 From: Mike Rapoport To: Suren Baghdasaryan Cc: akpm@linux-foundation.org, arnd@kernel.org, arnd@arndb.de, pasha.tatashin@soleen.com, mcgrof@kernel.org, song@kernel.org, mhiramat@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel test robot Subject: Re: [PATCH 1/1] alloc_tag: avoid execmem_vmap() when !MMU Message-ID: References: <20241028202935.1047017-1-surenb@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Rspam-User: X-Stat-Signature: hrfiejwhnkui5yohgraxkwn9e4n8wf19 X-Rspamd-Queue-Id: 1DA39A001B X-Rspamd-Server: rspam11 X-HE-Tag: 1730292399-151027 X-HE-Meta: U2FsdGVkX1+YhC8vHGFQ+ue/zbu35iTu/5X7wpuONuqY8k5bP2uj2fl5aUucjmk/P11y2yL1TQBynB4IlV9gdVGUbHQ9xDvFIgoP+OaCU60vSwnvgxRh7hwr4+RBBZgH1H8GalGzhwoN1NR20hl0Ifn0Io/cw+H8FHbRCuBo+td8YMeNNj3PIvJqZIp7lIrgQA3tS8PNhEKzbSnh1wCbvf85LYatkqXBrY0jpdW4iiNQszDuKMonf96erRiRn9bY6lMw/iuHLAr7HXEo8Z82avkU8j20hGqU0Rh87SWPP9HR0H2ZmHIhl3JN/lMxCWWzvYHo+HmSINJNG2AhIv2G+TRxWX5V+DT79ec/mE26obZEPy3WBpk5b/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ity=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: On Tue, Oct 29, 2024 at 01:03:51PM -0700, Suren Baghdasaryan wrote: > On Tue, Oct 29, 2024 at 10:13 AM Mike Rapoport wrote: > > > > Hi Suren, > > > > On Mon, Oct 28, 2024 at 01:29:35PM -0700, Suren Baghdasaryan wrote: > > > 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. > > > > Do we care that much to have alloc_tags on !MMU configs? > > > > Your patch is great, but it would have been a lot easier to make > > MEM_ALLOC_PROFILING depend on MMU. > > I didn't want to prevent !MMU users from using allocation profiling > but I'm not aware of any current !MMU users. Therefore I have no > objections to making MEM_ALLOC_PROFILING dependent on MMU if we indeed > don't care about !MMU && MEM_ALLOC_PROFILING configuration. > I'll be posting v5 tomorrow with all these fixes, so please let me > know which way you prefer. Thanks! I think if nommu users would want that feature, we can add the ifdefery later > > > 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(-) > > > > > > 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); > > > > > > base-commit: 92409df3e00a17d6fd5bb27732fa186749725ed5 > > > -- > > > 2.47.0.163.g1226f6d8fa-goog > > > > > > > -- > > Sincerely yours, > > Mike. -- Sincerely yours, Mike.