Skip to contentSkip to conversation

mm: (k)vrealloc: document concurrency restrictions

PATCH In review Danilo Krummrich 2 participants 2 messages Jul 25, 2024 – Jul 26, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: (k)vrealloc: document concurrency restrictions

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().

---
 mm/util.c    | 3 +++
 mm/vmalloc.c | 3 +++
 2 files changed, 6 insertions(+)
mm/util.c +3 -0
index 0ff5898cc6de..29ae93f6344f 100644
@@ -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)
mm/vmalloc.c +3 -0
index caf032f0bd69..2a6d4ce57b73 100644
@@ -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

Signature · 1 line
2.45.2
#1 lore raw
Quoted 10 lines · 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().

Huh, did anyone ever assume otherwise and why?

Quoted 35 lines
---
 mm/util.c    | 3 +++
 mm/vmalloc.c | 3 +++
 2 files changed, 6 insertions(+)
mm/util.c +3 -0
index 0ff5898cc6de..29ae93f6344f 100644
@@ -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)
mm/vmalloc.c +3 -0
index caf032f0bd69..2a6d4ce57b73 100644
@@ -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