Page MenuHomeFreeBSD

D49571.id152957.diff
No OneTemporary

D49571.id152957.diff

diff --git a/sys/compat/linuxkpi/common/include/linux/slab.h b/sys/compat/linuxkpi/common/include/linux/slab.h
--- a/sys/compat/linuxkpi/common/include/linux/slab.h
+++ b/sys/compat/linuxkpi/common/include/linux/slab.h
@@ -95,6 +95,7 @@
void *lkpi___kmalloc(size_t size, gfp_t flags);
void *lkpi___kmalloc_node(size_t size, gfp_t flags, int node);
#define __kmalloc(_s, _f) lkpi___kmalloc(_s, _f)
+void *lkpi_krealloc(void *, size_t, gfp_t);
static inline gfp_t
linux_check_m_flags(gfp_t flags)
@@ -149,6 +150,21 @@
return (kmalloc_array_node(n, size, flags, node));
}
+static inline void *
+krealloc(void *ptr, size_t size, gfp_t flags)
+{
+ return (lkpi_krealloc(ptr, size, flags));
+}
+
+static inline void *
+krealloc_array(void *ptr, size_t n, size_t size, gfp_t flags)
+{
+ if (WOULD_OVERFLOW(n, size))
+ return NULL;
+
+ return (krealloc(ptr, n * size, flags));
+}
+
static inline void *
__vmalloc(size_t size, gfp_t flags, int other)
{
@@ -174,21 +190,6 @@
return (kmalloc_array(n, size, linux_check_m_flags(flags)));
}
-static inline void *
-krealloc(void *ptr, size_t size, gfp_t flags)
-{
- return (realloc(ptr, size, M_KMALLOC, linux_check_m_flags(flags)));
-}
-
-static inline void *
-krealloc_array(void *ptr, size_t n, size_t size, gfp_t flags)
-{
- if (WOULD_OVERFLOW(n, size))
- return NULL;
-
- return (realloc(ptr, n * size, M_KMALLOC, linux_check_m_flags(flags)));
-}
-
extern void linux_kfree_async(void *);
static inline void
diff --git a/sys/compat/linuxkpi/common/src/linux_slab.c b/sys/compat/linuxkpi/common/src/linux_slab.c
--- a/sys/compat/linuxkpi/common/src/linux_slab.c
+++ b/sys/compat/linuxkpi/common/src/linux_slab.c
@@ -234,6 +234,40 @@
0, -1UL, PAGE_SIZE, 0));
}
+void *
+lkpi_krealloc(void *ptr, size_t size, gfp_t flags)
+{
+ void *nptr;
+ size_t osize;
+
+ /*
+ * First handle invariants based on function arguments.
+ */
+ if (ptr == NULL)
+ return (kmalloc(size, flags));
+
+ osize = ksize(ptr);
+ if (size <= osize)
+ return (ptr);
+
+ /*
+ * We know the new size > origonal size. realloc(9) does not (and cannot)
+ * know about our requirements for physically contiguous memory, so we can
+ * only call it up-to including PAGE_SIZE and otherwise have to replicate
+ * its functionality using kmalloc to get the contigmalloc(9) backing.
+ */
+ if (size <= PAGE_SIZE)
+ return (realloc(ptr, size, M_KMALLOC, linux_check_m_flags(flags)));
+
+ nptr = kmalloc(size, flags);
+ if (nptr == NULL)
+ return (NULL);
+
+ memcpy(nptr, ptr, osize);
+ kfree(ptr);
+ return (nptr);
+}
+
struct lkpi_kmalloc_ctx {
size_t size;
gfp_t flags;
diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c
--- a/sys/kern/kern_malloc.c
+++ b/sys/kern/kern_malloc.c
@@ -1142,6 +1142,9 @@
case SLAB_COOKIE_MALLOC_LARGE:
size = malloc_large_size(slab);
break;
+ case SLAB_COOKIE_CONTIG_MALLOC:
+ size = round_page(contigmalloc_size(slab));
+ break;
default:
__assert_unreachable();
size = 0;

File Metadata

Mime Type
text/plain
Expires
Mon, May 18, 9:05 PM (2 h, 8 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
33268563
Default Alt Text
D49571.id152957.diff (2 KB)

Event Timeline