linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: (k)vrealloc: document concurrency restrictions
@ 2024-07-25 12:54 Danilo Krummrich
  2024-07-26  9:31 ` Vlastimil Babka (SUSE)
  0 siblings, 1 reply; 2+ messages in thread
From: Danilo Krummrich @ 2024-07-25 12:54 UTC (permalink / raw)
  To: akpm, urezki, hch; +Cc: linux-kernel, linux-mm, Danilo Krummrich

Document that concurrent calls to vrealloc() with itself or vfree() for
the same memory allocation are not permitted, since it leads to undefined
behavior.

Consequently, the same applies for kvrealloc(), hence also document it
for kvrealloc().

Suggested-by: Christoph Hellwig <hch@infradead.org>
Suggested-by: Uladzislau Rezki <urezki@gmail.com>
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
---
 mm/util.c    | 3 +++
 mm/vmalloc.c | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/mm/util.c b/mm/util.c
index 0ff5898cc6de..29ae93f6344f 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -732,6 +732,9 @@ EXPORT_SYMBOL(kvfree_sensitive);
  * If @p is %NULL, kvrealloc() behaves exactly like kvmalloc(). If @size is 0
  * and @p is not a %NULL pointer, the object pointed to is freed.
  *
+ * This function must not be called concurrently with itself or kvfree() for the
+ * same memory allocation.
+ *
  * Return: pointer to the allocated memory or %NULL in case of error
  */
 void *kvrealloc_noprof(const void *p, size_t size, gfp_t flags)
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index caf032f0bd69..2a6d4ce57b73 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -4049,6 +4049,9 @@ EXPORT_SYMBOL(vzalloc_node_noprof);
  * If @p is %NULL, vrealloc() behaves exactly like vmalloc(). If @size is 0 and
  * @p is not a %NULL pointer, the object pointed to is freed.
  *
+ * This function must not be called concurrently with itself or vfree() for the
+ * same memory allocation.
+ *
  * Return: pointer to the allocated memory; %NULL if @size is zero or in case of
  *         failure
  */

base-commit: d270beaca6818349b2aed7e6034b800a777087cc
-- 
2.45.2



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

* Re: [PATCH] mm: (k)vrealloc: document concurrency restrictions
  2024-07-25 12:54 [PATCH] mm: (k)vrealloc: document concurrency restrictions Danilo Krummrich
@ 2024-07-26  9:31 ` Vlastimil Babka (SUSE)
  0 siblings, 0 replies; 2+ messages in thread
From: Vlastimil Babka (SUSE) @ 2024-07-26  9:31 UTC (permalink / raw)
  To: Danilo Krummrich, akpm, urezki, hch; +Cc: linux-kernel, linux-mm

On 7/25/24 2:54 PM, Danilo Krummrich wrote:
> Document that concurrent calls to vrealloc() with itself or vfree() for
> the same memory allocation are not permitted, since it leads to undefined
> behavior.
> 
> Consequently, the same applies for kvrealloc(), hence also document it
> for kvrealloc().
> 
> Suggested-by: Christoph Hellwig <hch@infradead.org>
> Suggested-by: Uladzislau Rezki <urezki@gmail.com>
> Signed-off-by: Danilo Krummrich <dakr@kernel.org>

Huh, did anyone ever assume otherwise and why?

> ---
>  mm/util.c    | 3 +++
>  mm/vmalloc.c | 3 +++
>  2 files changed, 6 insertions(+)
> 
> diff --git a/mm/util.c b/mm/util.c
> index 0ff5898cc6de..29ae93f6344f 100644
> --- a/mm/util.c
> +++ b/mm/util.c
> @@ -732,6 +732,9 @@ EXPORT_SYMBOL(kvfree_sensitive);
>   * If @p is %NULL, kvrealloc() behaves exactly like kvmalloc(). If @size is 0
>   * and @p is not a %NULL pointer, the object pointed to is freed.
>   *
> + * This function must not be called concurrently with itself or kvfree() for the
> + * same memory allocation.
> + *
>   * Return: pointer to the allocated memory or %NULL in case of error
>   */
>  void *kvrealloc_noprof(const void *p, size_t size, gfp_t flags)
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index caf032f0bd69..2a6d4ce57b73 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -4049,6 +4049,9 @@ EXPORT_SYMBOL(vzalloc_node_noprof);
>   * If @p is %NULL, vrealloc() behaves exactly like vmalloc(). If @size is 0 and
>   * @p is not a %NULL pointer, the object pointed to is freed.
>   *
> + * This function must not be called concurrently with itself or vfree() for the
> + * same memory allocation.
> + *
>   * Return: pointer to the allocated memory; %NULL if @size is zero or in case of
>   *         failure
>   */
> 
> base-commit: d270beaca6818349b2aed7e6034b800a777087cc



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

end of thread, other threads:[~2024-07-26  9:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-25 12:54 [PATCH] mm: (k)vrealloc: document concurrency restrictions Danilo Krummrich
2024-07-26  9:31 ` Vlastimil Babka (SUSE)

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