linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] mm: fix xyz_noprof functions calling profiled functions
@ 2024-05-31 20:53 Suren Baghdasaryan
  2024-05-31 21:08 ` Kees Cook
  2024-06-01 20:58 ` Vlastimil Babka
  0 siblings, 2 replies; 3+ messages in thread
From: Suren Baghdasaryan @ 2024-05-31 20:53 UTC (permalink / raw)
  To: akpm
  Cc: kent.overstreet, pasha.tatashin, vbabka, keescook, linux-mm,
	linux-kernel, Suren Baghdasaryan

Grepping /proc/allocinfo for "noprof" reveals several xyz_noprof functions,
which means internally they are calling profiled functions. This should
never happen as such calls move allocation charge from a higher level
location where it should be accounted for into these lower level helpers.
Fix this by replacing profiled function calls with noprof ones.

Fixes: b951aaff5035 ("mm: enable page allocation tagging")
Fixes: e26d8769da6d ("mempool: hook up to memory allocation profiling")
Fixes: 88ae5fb755b0 ("mm: vmalloc: enable memory allocation profiling")
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Cc: Kent Overstreet <kent.overstreet@linux.dev>
---
 mm/filemap.c |  2 +-
 mm/mempool.c |  2 +-
 mm/util.c    | 10 +++++-----
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/mm/filemap.c b/mm/filemap.c
index 9fe5c02ae92e..37061aafd191 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -1000,7 +1000,7 @@ struct folio *filemap_alloc_folio_noprof(gfp_t gfp, unsigned int order)
 		do {
 			cpuset_mems_cookie = read_mems_allowed_begin();
 			n = cpuset_mem_spread_node();
-			folio = __folio_alloc_node(gfp, order, n);
+			folio = __folio_alloc_node_noprof(gfp, order, n);
 		} while (!folio && read_mems_allowed_retry(cpuset_mems_cookie));
 
 		return folio;
diff --git a/mm/mempool.c b/mm/mempool.c
index 6ece63a00acf..3223337135d0 100644
--- a/mm/mempool.c
+++ b/mm/mempool.c
@@ -273,7 +273,7 @@ mempool_t *mempool_create_node_noprof(int min_nr, mempool_alloc_t *alloc_fn,
 {
 	mempool_t *pool;
 
-	pool = kzalloc_node(sizeof(*pool), gfp_mask, node_id);
+	pool = kmalloc_node_noprof(sizeof(*pool), gfp_mask | __GFP_ZERO, node_id);
 	if (!pool)
 		return NULL;
 
diff --git a/mm/util.c b/mm/util.c
index c9e519e6811f..6c3e6710e4de 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -705,7 +705,7 @@ void *kvrealloc_noprof(const void *p, size_t oldsize, size_t newsize, gfp_t flag
 
 	if (oldsize >= newsize)
 		return (void *)p;
-	newp = kvmalloc(newsize, flags);
+	newp = kvmalloc_noprof(newsize, flags);
 	if (!newp)
 		return NULL;
 	memcpy(newp, p, oldsize);
@@ -726,7 +726,7 @@ void *__vmalloc_array_noprof(size_t n, size_t size, gfp_t flags)
 
 	if (unlikely(check_mul_overflow(n, size, &bytes)))
 		return NULL;
-	return __vmalloc(bytes, flags);
+	return __vmalloc_noprof(bytes, flags);
 }
 EXPORT_SYMBOL(__vmalloc_array_noprof);
 
@@ -737,7 +737,7 @@ EXPORT_SYMBOL(__vmalloc_array_noprof);
  */
 void *vmalloc_array_noprof(size_t n, size_t size)
 {
-	return __vmalloc_array(n, size, GFP_KERNEL);
+	return __vmalloc_array_noprof(n, size, GFP_KERNEL);
 }
 EXPORT_SYMBOL(vmalloc_array_noprof);
 
@@ -749,7 +749,7 @@ EXPORT_SYMBOL(vmalloc_array_noprof);
  */
 void *__vcalloc_noprof(size_t n, size_t size, gfp_t flags)
 {
-	return __vmalloc_array(n, size, flags | __GFP_ZERO);
+	return __vmalloc_array_noprof(n, size, flags | __GFP_ZERO);
 }
 EXPORT_SYMBOL(__vcalloc_noprof);
 
@@ -760,7 +760,7 @@ EXPORT_SYMBOL(__vcalloc_noprof);
  */
 void *vcalloc_noprof(size_t n, size_t size)
 {
-	return __vmalloc_array(n, size, GFP_KERNEL | __GFP_ZERO);
+	return __vmalloc_array_noprof(n, size, GFP_KERNEL | __GFP_ZERO);
 }
 EXPORT_SYMBOL(vcalloc_noprof);
 

base-commit: 8e06d6b9274dc504af6021a8bbc2daf6713ceb20
-- 
2.45.1.288.g0e0cd299f1-goog



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/1] mm: fix xyz_noprof functions calling profiled functions
  2024-05-31 20:53 [PATCH 1/1] mm: fix xyz_noprof functions calling profiled functions Suren Baghdasaryan
@ 2024-05-31 21:08 ` Kees Cook
  2024-06-01 20:58 ` Vlastimil Babka
  1 sibling, 0 replies; 3+ messages in thread
From: Kees Cook @ 2024-05-31 21:08 UTC (permalink / raw)
  To: Suren Baghdasaryan
  Cc: akpm, kent.overstreet, pasha.tatashin, vbabka, linux-mm, linux-kernel

On Fri, May 31, 2024 at 01:53:50PM -0700, Suren Baghdasaryan wrote:
> Grepping /proc/allocinfo for "noprof" reveals several xyz_noprof functions,
> which means internally they are calling profiled functions. This should
> never happen as such calls move allocation charge from a higher level
> location where it should be accounted for into these lower level helpers.
> Fix this by replacing profiled function calls with noprof ones.
> 
> Fixes: b951aaff5035 ("mm: enable page allocation tagging")
> Fixes: e26d8769da6d ("mempool: hook up to memory allocation profiling")
> Fixes: 88ae5fb755b0 ("mm: vmalloc: enable memory allocation profiling")
> Signed-off-by: Suren Baghdasaryan <surenb@google.com>

Reviewed-by: Kees Cook <kees@kernel.org>

-- 
Kees Cook


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/1] mm: fix xyz_noprof functions calling profiled functions
  2024-05-31 20:53 [PATCH 1/1] mm: fix xyz_noprof functions calling profiled functions Suren Baghdasaryan
  2024-05-31 21:08 ` Kees Cook
@ 2024-06-01 20:58 ` Vlastimil Babka
  1 sibling, 0 replies; 3+ messages in thread
From: Vlastimil Babka @ 2024-06-01 20:58 UTC (permalink / raw)
  To: Suren Baghdasaryan, akpm
  Cc: kent.overstreet, pasha.tatashin, keescook, linux-mm, linux-kernel

On 5/31/24 10:53 PM, Suren Baghdasaryan wrote:
> Grepping /proc/allocinfo for "noprof" reveals several xyz_noprof functions,
> which means internally they are calling profiled functions. This should
> never happen as such calls move allocation charge from a higher level
> location where it should be accounted for into these lower level helpers.
> Fix this by replacing profiled function calls with noprof ones.
> 
> Fixes: b951aaff5035 ("mm: enable page allocation tagging")
> Fixes: e26d8769da6d ("mempool: hook up to memory allocation profiling")
> Fixes: 88ae5fb755b0 ("mm: vmalloc: enable memory allocation profiling")
> Signed-off-by: Suren Baghdasaryan <surenb@google.com>
> Cc: Kent Overstreet <kent.overstreet@linux.dev>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

> ---
>  mm/filemap.c |  2 +-
>  mm/mempool.c |  2 +-
>  mm/util.c    | 10 +++++-----
>  3 files changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/mm/filemap.c b/mm/filemap.c
> index 9fe5c02ae92e..37061aafd191 100644
> --- a/mm/filemap.c
> +++ b/mm/filemap.c
> @@ -1000,7 +1000,7 @@ struct folio *filemap_alloc_folio_noprof(gfp_t gfp, unsigned int order)
>  		do {
>  			cpuset_mems_cookie = read_mems_allowed_begin();
>  			n = cpuset_mem_spread_node();
> -			folio = __folio_alloc_node(gfp, order, n);
> +			folio = __folio_alloc_node_noprof(gfp, order, n);
>  		} while (!folio && read_mems_allowed_retry(cpuset_mems_cookie));
>  
>  		return folio;
> diff --git a/mm/mempool.c b/mm/mempool.c
> index 6ece63a00acf..3223337135d0 100644
> --- a/mm/mempool.c
> +++ b/mm/mempool.c
> @@ -273,7 +273,7 @@ mempool_t *mempool_create_node_noprof(int min_nr, mempool_alloc_t *alloc_fn,
>  {
>  	mempool_t *pool;
>  
> -	pool = kzalloc_node(sizeof(*pool), gfp_mask, node_id);
> +	pool = kmalloc_node_noprof(sizeof(*pool), gfp_mask | __GFP_ZERO, node_id);
>  	if (!pool)
>  		return NULL;
>  
> diff --git a/mm/util.c b/mm/util.c
> index c9e519e6811f..6c3e6710e4de 100644
> --- a/mm/util.c
> +++ b/mm/util.c
> @@ -705,7 +705,7 @@ void *kvrealloc_noprof(const void *p, size_t oldsize, size_t newsize, gfp_t flag
>  
>  	if (oldsize >= newsize)
>  		return (void *)p;
> -	newp = kvmalloc(newsize, flags);
> +	newp = kvmalloc_noprof(newsize, flags);
>  	if (!newp)
>  		return NULL;
>  	memcpy(newp, p, oldsize);
> @@ -726,7 +726,7 @@ void *__vmalloc_array_noprof(size_t n, size_t size, gfp_t flags)
>  
>  	if (unlikely(check_mul_overflow(n, size, &bytes)))
>  		return NULL;
> -	return __vmalloc(bytes, flags);
> +	return __vmalloc_noprof(bytes, flags);
>  }
>  EXPORT_SYMBOL(__vmalloc_array_noprof);
>  
> @@ -737,7 +737,7 @@ EXPORT_SYMBOL(__vmalloc_array_noprof);
>   */
>  void *vmalloc_array_noprof(size_t n, size_t size)
>  {
> -	return __vmalloc_array(n, size, GFP_KERNEL);
> +	return __vmalloc_array_noprof(n, size, GFP_KERNEL);
>  }
>  EXPORT_SYMBOL(vmalloc_array_noprof);
>  
> @@ -749,7 +749,7 @@ EXPORT_SYMBOL(vmalloc_array_noprof);
>   */
>  void *__vcalloc_noprof(size_t n, size_t size, gfp_t flags)
>  {
> -	return __vmalloc_array(n, size, flags | __GFP_ZERO);
> +	return __vmalloc_array_noprof(n, size, flags | __GFP_ZERO);
>  }
>  EXPORT_SYMBOL(__vcalloc_noprof);
>  
> @@ -760,7 +760,7 @@ EXPORT_SYMBOL(__vcalloc_noprof);
>   */
>  void *vcalloc_noprof(size_t n, size_t size)
>  {
> -	return __vmalloc_array(n, size, GFP_KERNEL | __GFP_ZERO);
> +	return __vmalloc_array_noprof(n, size, GFP_KERNEL | __GFP_ZERO);
>  }
>  EXPORT_SYMBOL(vcalloc_noprof);
>  
> 
> base-commit: 8e06d6b9274dc504af6021a8bbc2daf6713ceb20



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-06-01 20:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-31 20:53 [PATCH 1/1] mm: fix xyz_noprof functions calling profiled functions Suren Baghdasaryan
2024-05-31 21:08 ` Kees Cook
2024-06-01 20:58 ` Vlastimil Babka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox