summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorJonathan Gray <jsg@cvs.openbsd.org>2021-01-13 01:04:50 +0000
committerJonathan Gray <jsg@cvs.openbsd.org>2021-01-13 01:04:50 +0000
commitea55ad9cad280247c63df8f3ac1bed7d4f163437 (patch)
tree31448eb63366bb0e1ea5416260e76f9b0271d28e /sys
parentb9107794775cc27637dd2dd94854b92963829697 (diff)
revert drm vmalloc changes
It is suspected they were to blame for a machine with inteldrm running X (xterms and chromium) running out of resources after a few days. ok kettenis@
Diffstat (limited to 'sys')
-rw-r--r--sys/dev/pci/drm/drm_linux.c111
-rw-r--r--sys/dev/pci/drm/include/linux/mm.h29
-rw-r--r--sys/dev/pci/drm/include/linux/vmalloc.h25
3 files changed, 39 insertions, 126 deletions
diff --git a/sys/dev/pci/drm/drm_linux.c b/sys/dev/pci/drm/drm_linux.c
index a893c4de89b..55462ad34a7 100644
--- a/sys/dev/pci/drm/drm_linux.c
+++ b/sys/dev/pci/drm/drm_linux.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: drm_linux.c,v 1.75 2021/01/08 23:02:09 kettenis Exp $ */
+/* $OpenBSD: drm_linux.c,v 1.76 2021/01/13 01:04:49 jsg Exp $ */
/*
* Copyright (c) 2013 Jonathan Gray <jsg@openbsd.org>
* Copyright (c) 2015, 2016 Mark Kettenis <kettenis@openbsd.org>
@@ -430,111 +430,6 @@ dmi_check_system(const struct dmi_system_id *sysid)
return (num);
}
-struct vmalloc_entry {
- const void *addr;
- size_t size;
- RBT_ENTRY(vmalloc_entry) vmalloc_node;
-};
-
-struct pool vmalloc_pool;
-RBT_HEAD(vmalloc_tree, vmalloc_entry) vmalloc_tree;
-
-RBT_PROTOTYPE(vmalloc_tree, vmalloc_entry, vmalloc_node, vmalloc_compare);
-
-static inline int
-vmalloc_compare(const struct vmalloc_entry *a, const struct vmalloc_entry *b)
-{
- vaddr_t va = (vaddr_t)a->addr;
- vaddr_t vb = (vaddr_t)b->addr;
-
- return va < vb ? -1 : va > vb;
-}
-
-RBT_GENERATE(vmalloc_tree, vmalloc_entry, vmalloc_node, vmalloc_compare);
-
-bool
-is_vmalloc_addr(const void *addr)
-{
- struct vmalloc_entry key;
- struct vmalloc_entry *entry;
-
- key.addr = addr;
- entry = RBT_FIND(vmalloc_tree, &vmalloc_tree, &key);
- return (entry != NULL);
-}
-
-void *
-vmalloc(unsigned long size)
-{
- struct vmalloc_entry *entry;
- void *addr;
-
- size = round_page(size);
- addr = km_alloc(size, &kv_any, &kp_dirty, &kd_waitok);
- if (addr) {
- entry = pool_get(&vmalloc_pool, PR_WAITOK);
- entry->addr = addr;
- entry->size = size;
- RBT_INSERT(vmalloc_tree, &vmalloc_tree, entry);
- }
-
- return addr;
-}
-
-void *
-vzalloc(unsigned long size)
-{
- struct vmalloc_entry *entry;
- void *addr;
-
- size = round_page(size);
- addr = km_alloc(size, &kv_any, &kp_zero, &kd_waitok);
- if (addr) {
- entry = pool_get(&vmalloc_pool, PR_WAITOK);
- entry->addr = addr;
- entry->size = size;
- RBT_INSERT(vmalloc_tree, &vmalloc_tree, entry);
- }
-
- return addr;
-}
-
-void
-vfree(const void *addr)
-{
- struct vmalloc_entry key;
- struct vmalloc_entry *entry;
-
- key.addr = addr;
- entry = RBT_FIND(vmalloc_tree, &vmalloc_tree, &key);
- if (entry == NULL)
- panic("%s: non vmalloced addr %p", __func__, addr);
-
- RBT_REMOVE(vmalloc_tree, &vmalloc_tree, entry);
- km_free((void *)addr, entry->size, &kv_any, &kp_dirty);
- pool_put(&vmalloc_pool, entry);
-}
-
-void *
-kvmalloc(size_t size, gfp_t flags)
-{
- if ((flags & M_NOWAIT) || size < PAGE_SIZE)
- return malloc(size, M_DRM, flags);
- if (flags & M_ZERO)
- return vzalloc(size);
- else
- return vmalloc(size);
-}
-
-void
-kvfree(const void *addr)
-{
- if (is_vmalloc_addr(addr))
- vfree(addr);
- else
- free((void *)addr, M_DRM, 0);
-}
-
struct vm_page *
alloc_pages(unsigned int gfp_mask, unsigned int order)
{
@@ -2044,10 +1939,6 @@ drm_linux_init(void)
pool_init(&idr_pool, sizeof(struct idr_entry), 0, IPL_TTY, 0,
"idrpl", NULL);
-
- pool_init(&vmalloc_pool, sizeof(struct vmalloc_entry), 0, IPL_NONE, 0,
- "vmallocpl", NULL);
- RBT_INIT(vmalloc_tree, &vmalloc_tree);
}
void
diff --git a/sys/dev/pci/drm/include/linux/mm.h b/sys/dev/pci/drm/include/linux/mm.h
index 6c3a0c640d5..f7d84207793 100644
--- a/sys/dev/pci/drm/include/linux/mm.h
+++ b/sys/dev/pci/drm/include/linux/mm.h
@@ -30,31 +30,38 @@
#define PFN_DOWN(x) ((x) >> PAGE_SHIFT)
#define PFN_PHYS(x) ((x) << PAGE_SHIFT)
-bool is_vmalloc_addr(const void *);
+#define is_vmalloc_addr(ptr) true
-void *kvmalloc(size_t, gfp_t);
-void kvfree(const void *);
+static inline void *
+kvmalloc(size_t size, gfp_t flags)
+{
+ return malloc(size, M_DRM, flags);
+}
static inline void *
-kvmalloc_array(size_t n, size_t size, gfp_t flags)
+kvmalloc_array(size_t n, size_t size, int flags)
{
if (n != 0 && SIZE_MAX / n < size)
return NULL;
- return kvmalloc(n * size, flags);
+ return malloc(n * size, M_DRM, flags);
}
static inline void *
-kvcalloc(size_t n, size_t size, gfp_t flags)
+kvcalloc(size_t n, size_t size, int flags)
{
- if (n != 0 && SIZE_MAX / n < size)
- return NULL;
- return kvmalloc(n * size, flags | M_ZERO);
+ return kvmalloc_array(n, size, flags | M_ZERO);
}
static inline void *
-kvzalloc(size_t size, gfp_t flags)
+kvzalloc(size_t size, int flags)
+{
+ return malloc(size, M_DRM, flags | M_ZERO);
+}
+
+static inline void
+kvfree(const void *objp)
{
- return kvmalloc(size, flags | M_ZERO);
+ free((void *)objp, M_DRM, 0);
}
static inline long
diff --git a/sys/dev/pci/drm/include/linux/vmalloc.h b/sys/dev/pci/drm/include/linux/vmalloc.h
index fd6cc54b7db..53ba42e2d18 100644
--- a/sys/dev/pci/drm/include/linux/vmalloc.h
+++ b/sys/dev/pci/drm/include/linux/vmalloc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: vmalloc.h,v 1.2 2021/01/08 23:02:09 kettenis Exp $ */
+/* $OpenBSD: vmalloc.h,v 1.3 2021/01/13 01:04:49 jsg Exp $ */
/*
* Copyright (c) 2013, 2014, 2015 Mark Kettenis
*
@@ -25,10 +25,25 @@
#include <linux/overflow.h>
void *vmap(struct vm_page **, unsigned int, unsigned long, pgprot_t);
-void vunmap(void *, size_t);
+void vunmap(void *, size_t);
+
+static inline void *
+vmalloc(unsigned long size)
+{
+ return malloc(size, M_DRM, M_WAITOK | M_CANFAIL);
+}
+
+static inline void *
+vzalloc(unsigned long size)
+{
+ return malloc(size, M_DRM, M_WAITOK | M_CANFAIL | M_ZERO);
+}
+
+static inline void
+vfree(void *objp)
+{
+ free(objp, M_DRM, 0);
+}
-void *vmalloc(unsigned long);
-void *vzalloc(unsigned long);
-void vfree(const void *);
#endif