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 AAFD7D6B6B4 for ; Wed, 30 Oct 2024 23:42:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2F8526B009B; Wed, 30 Oct 2024 19:42:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2A8B56B009D; Wed, 30 Oct 2024 19:42:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 170796B009E; Wed, 30 Oct 2024 19:42:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id EC1666B009B for ; Wed, 30 Oct 2024 19:42:44 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 57BFD141262 for ; Wed, 30 Oct 2024 23:42:44 +0000 (UTC) X-FDA: 82731895596.28.14DF991 Received: from mail-qt1-f173.google.com (mail-qt1-f173.google.com [209.85.160.173]) by imf26.hostedemail.com (Postfix) with ESMTP id 9B9C7140015 for ; Wed, 30 Oct 2024 23:42:22 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=zFF2z9Fg; spf=pass (imf26.hostedemail.com: domain of surenb@google.com designates 209.85.160.173 as permitted sender) smtp.mailfrom=surenb@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730331631; 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=w2aDKBjnJKpMpnGRXsZpDPEBKe9sKnnzwhleKkdKArc=; b=cgX4siXKjQXYS3jexrrd8V9Ynf7QtvBjVjB2D4XVx266/xAXAfAij3quUH+x7usTvMiWrV qdFWvPzv5Zl0vGZ5nJ99usl0MULNTCkAPoshq/aSuBYLdNnffrXTdJOnLnlTTtXnn7llbH LFOTGn9aNYkg29VA//5bFYzEl/jUHJw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730331631; a=rsa-sha256; cv=none; b=CQyebMpsiLoIvDCKjBdQgclTHRzHnC4L2pwcUPJ2L0EdwdPK3hdBxHFqDrZaAJ63HarfVt 3z1b6jTXRbSGtCaUITulGTH1RpvCniKTLfRdR3aOsx1AcFV0GKTkn6JAi0s9+MEaXxAz7I JnLkWF9IYPnBhDiV/GhvyQUIg507c/A= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=zFF2z9Fg; spf=pass (imf26.hostedemail.com: domain of surenb@google.com designates 209.85.160.173 as permitted sender) smtp.mailfrom=surenb@google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-qt1-f173.google.com with SMTP id d75a77b69052e-460a8d1a9b7so69771cf.1 for ; Wed, 30 Oct 2024 16:42:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730331761; x=1730936561; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=w2aDKBjnJKpMpnGRXsZpDPEBKe9sKnnzwhleKkdKArc=; b=zFF2z9FgSQrGvSlyfrhmPN2IwZkHT5Uby4IOU1WXrG7rPKm0ZNYDdDwvvz97SLMscu V4RwehxI+p4maWWUn5RtHwBt/1CV3u6O2d6cK7gDuObEReW/kQ2xEnSJBJq5WTwSHZ+6 zfvfODH2J5x3s+NHbeuSWVztf1HoQSVf5hLh3YUlmDR/ZiA6sKi0jqbTQMVHAGwM24RG NjFpU2iWhoq6XZ94VC53Hm31mFoFdtgOocdag/7eoR3LOCD6cl/P53X5ShWKU/xeXh7K NUakMJcWKcR98j8Krnd1GT4qjttKuA8Z0uwFIQuH9Y8GXqs8ZbR2bJmenzG7njvHl6BC Apgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730331761; x=1730936561; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=w2aDKBjnJKpMpnGRXsZpDPEBKe9sKnnzwhleKkdKArc=; b=Rg7iSKklo5XJFzgsVU1f6GTakvdSnM4Lp9Fx9ijZ56ruajd1/+2F2+HJ1GYUIxkkUF 5LzxjTqUdCsueP0HhI+Yrz7VO+gENVDDjXqk0fyel8KYCyfloGE5pSAgAybd5ulYW0TK zBp76oPuL+YoyKGhUQZ8ayt2kTE6tRiB9c01imnOj9Q1zjOotQtYVMKG+iQBi78Ku+mC hTueTejgyMeGiXZY68EhR9fsIZfx7maq0RKwpZCegzg68c4AWvmpmOSNPxHXguSmPJkT 5hbIqWsgLA5W1HJYmQTNWduyuHXFJTikcKMDjcuhIHItN5Mx01CuwCIo3q84T7cIaSHh QEFw== X-Forwarded-Encrypted: i=1; AJvYcCVdd7ND2R9SQXGs0Ou8EeKKR54vNAIhnfcRgrGvaPXABfLIWSJYyse7/zClJJHLamI0msFoQ9K0FA==@kvack.org X-Gm-Message-State: AOJu0Ywz7veW9Fuq/cVU7zvh/h0AC3L3vE/VTRMphE5EJ0pUfwAyg+So HdddrxavSI9/vSS+DSXxmoNUfbnHsmGknBb9PROnYtbgSqikJ7AWWAe1S/yEX68yrEfg7Jg2cC2 43g5bX+5puoLRFgNOWbQvInY4zK2k6R06Dii0 X-Gm-Gg: ASbGncsDebCw6TcTLR6va23Ry5ItpdMVn8fvDjGU2cLZOOn/xLPB4zaKGPIF99r+3Ol bEq0almdAXLRd+1GIe6lgWyA4LWDUGEk3jKFe+W5S7OayB0ZZz8/209amNyC9 X-Google-Smtp-Source: AGHT+IFjyYRNzlHVeVeoBdnf9ro1pwJwW6jft94IlHTeeLIgPte6YKRb4BJSO3ylacTRcQWIyngd+f83hBiYQisDOdY= X-Received: by 2002:a05:622a:286:b0:461:70cc:3799 with SMTP id d75a77b69052e-462ad1feb31mr643521cf.21.1730331761193; Wed, 30 Oct 2024 16:42:41 -0700 (PDT) MIME-Version: 1.0 References: <20241028202935.1047017-1-surenb@google.com> In-Reply-To: From: Suren Baghdasaryan Date: Wed, 30 Oct 2024 16:42:28 -0700 Message-ID: Subject: Re: [PATCH 1/1] alloc_tag: avoid execmem_vmap() when !MMU To: Mike Rapoport 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 9B9C7140015 X-Stat-Signature: 4oxj8bfbe4rcts69rrkmxn1xmwhyasx8 X-HE-Tag: 1730331742-430845 X-HE-Meta: U2FsdGVkX1/FPPQSJbn4cREPFw4BdFbqTI3bIqqCb6oiyQ89tvc+CdfvQgLXIMOf7JWdj2q/3jJV5M43GL5ljDBWbmmmU+WnUezX2z0CRY0xJpD9GgbgLweiurjs9dFd/VpidwKZ1NgUb27eyKqd/wTd6gtRFJeufcqJExFY87AdcWeVMyVrgXAwYNm9+lFWNzTcNqvVjMikF8lgu4YqjcrQfSrwcW7rhJo6w9abY0Jyw056oX+nGz2a+gUh5NnDnU/I1r0sJOJgUxtq/+Hk6HlvWsLc5VqrhtXCsB7+pMRRg56QTZVXSiyuCaseZK+BVzG7zpYxy2rawY66VtX2w3UYREhvYIjSEOcakWbxZ3gYvX2c4zXgc5OEY6SMBpxNx5JJNcDlhCsmke7t6bUqIKy6LsKb4KYD7iZ2buJRUPftdqI0FtK7e1BA1Ersncm6/GVvKsWsfZEX9cblyvFyX5eVQtzAFESK/wabzZ5H7CBkgBRhLd/IowPAD03I6mlqIBz21GWNIihiYzqOB2k6wkO9nYk4T8KE3PhiUDI4jXPxsMHkvBrGYKo0Yv57+4/Y7xUcHTetKhmZkEczC2KwILIY1fBFkjNJWbu7SwlawW5mKabEQDKvR4ArRjj99+s6sB6HNkPB1RgZqJFselE+vdKYSrRzMLE2jmJGpPBHeb1du/yaV9EQVJSWEYZjWpDgSkpjlz1DJBEgGixMUVXhStkcG2HpX4uxq4QD6jjsfRkD9nMvNgq5MAXmsl+BhVnmIeUtTsB4WN0amuWnmaRoMmxqP0czmzik1NDdpow2XucdqSqp9KDdsp6RKK4lmkQDj84JlLg09wjE0P/xdPZ/0H302UafXweMszvc+d6NnD1KMNys20csBmyRzceTJ2Nb4Mu1Pt6gqAS8TKriAYoQOD73D8+GQ8Faa15GPGpoQ/l1iFzPrz5bVzPVvl0OVhtkJ6WzLY8ChqCBkviMg3+ ALKonPLC SJCsztXjCER2czb/rSQU5H14MA4xmvjRu6E/n0VBYfr/lwAbk9DNLQZvzGG5KM+6PjfcB4qHDAy/+pWGD58PEnXecX9n+L1rVbFg+iSf35J8IHjuYbG2CAFY2pPL3Day74oCPGapVCAohr29GEI22SBctifBa9uaS0i7QcivWlWBmYwRWhPl9qb1sLY7hSnMYMBZm07MrRhrh2/Z6zs2bH/H7iBrYX8h+QRaFzJ6/FXRZAECPP5oyvaVK6zSYbLS07IxyfYjx319BdXTKkm1o5G2sq+CgkUG4jlaC86IxwKzKlkgf1BI1DpatndebVb8GLxFhW+wBqcfypl7pEhQoWvUK4EI8XriaadXc 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: On Wed, Oct 30, 2024 at 5:46=E2=80=AFAM Mike Rapoport wro= te: > > On Tue, Oct 29, 2024 at 01:03:51PM -0700, Suren Baghdasaryan wrote: > > On Tue, Oct 29, 2024 at 10:13=E2=80=AFAM Mike Rapoport wrote: > > > > > > Hi Suren, > > > > > > On Mon, Oct 28, 2024 at 01:29:35PM -0700, Suren Baghdasaryan wrote: > > > > With CONFIG_MMU=3Dn __get_vm_area_node() is not available and memor= y for the > > > > allocation tags cannot be populated as needed. For this case, popul= ate 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 Sounds good. I'll add the dependency and simplify this fix in my next posti= ng. Thanks! > > > > > 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, siz= e_t size); > > > > */ > > > > void execmem_free(void *ptr); > > > > > > > > +#ifdef CONFIG_MMU > > > > /** > > > > * execmem_vmap - create virtual mapping for EXECMEM_MODULE_DATA m= emory > > > > * @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 =3D MTREE_INIT(mod_area_mt, M= T_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 =3D 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 =3D 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 =3D (unsigned long)vm_module_tags->add= r; > > > > +#else > > > > + /* Allocate space to copy allocation tags */ > > > > + module_tags.start_addr =3D (unsigned long)execmem_alloc(EXECM= EM_MODULE_DATA, > > > > + MODULE_= ALLOC_TAG_VMAP_SIZE); > > > > + if (!module_tags.start_addr) > > > > + return -ENOMEM; > > > > +#endif > > > > module_tags.end_addr =3D module_tags.start_addr + MODULE_ALLO= C_TAG_VMAP_SIZE; > > > > /* Ensure the base is alloc_tag aligned when required for ind= exing */ > > > > module_tags.start_addr =3D 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 =3D 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_rang= e *range, size_t size, > > > > > > > > return p; > > > > } > > > > + > > > > +struct vm_struct *execmem_vmap(size_t size) > > > > +{ > > > > + struct execmem_range *range =3D &execmem_info->ranges[EXECMEM= _MODULE_DATA]; > > > > + struct vm_struct *area; > > > > + > > > > + area =3D __get_vm_area_node(size, range->alignment, PAGE_SHIF= T, VM_ALLOC, > > > > + range->start, range->end, NUMA_NO_N= ODE, > > > > + GFP_KERNEL, __builtin_return_addres= s(0)); > > > > + if (!area && range->fallback_start) > > > > + area =3D __get_vm_area_node(size, range->alignment, P= AGE_SHIFT, VM_ALLOC, > > > > + range->fallback_start, rang= e->fallback_end, > > > > + NUMA_NO_NODE, GFP_KERNEL, _= _builtin_return_address(0)); > > > > + > > > > + return area; > > > > +} > > > > #else > > > > static void *execmem_vmalloc(struct execmem_range *range, size_t s= ize, > > > > 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 =3D &execmem_info->ranges[EXECMEM= _MODULE_DATA]; > > > > - struct vm_struct *area; > > > > - > > > > - area =3D __get_vm_area_node(size, range->alignment, PAGE_SHIF= T, VM_ALLOC, > > > > - range->start, range->end, NUMA_NO_N= ODE, > > > > - GFP_KERNEL, __builtin_return_addres= s(0)); > > > > - if (!area && range->fallback_start) > > > > - area =3D __get_vm_area_node(size, range->alignment, P= AGE_SHIFT, VM_ALLOC, > > > > - range->fallback_start, rang= e->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.