Revert "ANDROID: add task_dma_buf_record and allocation preload facilities"

This reverts commit 65a74eb47e09bbbd6061b00fea2e3d586014a385.

Bug: 439083203
Bug: 435308937
Signed-off-by: T.J. Mercier <tjmercier@google.com>
(cherry picked from https://android-review.googlesource.com/q/commit:87b9d836c3d8e52e3b6119a11a5cd5bcabe93d2c)
Merged-In: I4931c1b0556112dd9308d44e9589e0768d5befdc
Change-Id: I4931c1b0556112dd9308d44e9589e0768d5befdc
diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
index 2539846..fbe8a07 100644
--- a/drivers/dma-buf/dma-buf.c
+++ b/drivers/dma-buf/dma-buf.c
@@ -160,127 +160,6 @@ static struct file_system_type dma_buf_fs_type = {
 	.kill_sb = kill_anon_super,
 };
 
-struct task_dma_buf_record_preload {
-	local_lock_t lock;
-	size_t size;
-	struct list_head list;
-};
-
-static DEFINE_PER_CPU(struct task_dma_buf_record_preload, dmabuf_rec_reloads);
-
-static struct kmem_cache *task_dmabuf_record_cachep;
-
-static void __init init_task_dmabuf_record_pool(void)
-{
-	int cpu;
-
-	task_dmabuf_record_cachep = kmem_cache_create("task_dmabuf_record",
-			sizeof(struct task_dma_buf_record), 0,
-			SLAB_PANIC | SLAB_ACCOUNT, NULL);
-
-	for_each_possible_cpu(cpu) {
-		struct task_dma_buf_record_preload *preload;
-
-		preload = &per_cpu(dmabuf_rec_reloads, cpu);
-		local_lock_init(&preload->lock);
-		INIT_LIST_HEAD(&preload->list);
-		preload->size = 0;
-	}
-}
-
-/*
- * Load up this CPU's task_dma_buf_record_preload list with requested number of
- * records. On success, returns true, with preemption disabled. On error,
- * return false with preemption not disabled.
- */
-static bool task_dmabuf_records_preload(size_t count)
-{
-	struct task_dma_buf_record_preload *preload;
-
-	local_lock(&dmabuf_rec_reloads.lock);
-	preload = this_cpu_ptr(&dmabuf_rec_reloads);
-	while (preload->size < count) {
-		struct task_dma_buf_record *rec;
-
-		local_unlock(&dmabuf_rec_reloads.lock);
-		rec = kmem_cache_alloc(task_dmabuf_record_cachep, GFP_KERNEL);
-		if (!rec)
-			return false;
-
-		local_lock(&dmabuf_rec_reloads.lock);
-		preload = this_cpu_ptr(&dmabuf_rec_reloads);
-		if (preload->size < count) {
-			list_add(&rec->node, &preload->list);
-			preload->size++;
-		} else {
-			kmem_cache_free(task_dmabuf_record_cachep, rec);
-		}
-	}
-
-	return true;
-}
-
-static inline void task_dmabuf_records_preload_end(void)
-{
-	local_unlock(&dmabuf_rec_reloads.lock);
-}
-
-static struct task_dma_buf_record *alloc_task_dmabuf_record(void)
-{
-	struct task_dma_buf_record_preload *preload;
-	struct task_dma_buf_record *rec = NULL;
-
-	lockdep_assert_held(&dmabuf_rec_reloads.lock);
-	preload = this_cpu_ptr(&dmabuf_rec_reloads);
-	if (preload->size > 0) {
-		rec = list_first_entry(&preload->list, typeof(*rec), node);
-		list_del(&rec->node);
-		preload->size--;
-	}
-
-	return rec;
-}
-
-#define MAX_PCP_POOL_SIZE 32
-
-static void free_task_dmabuf_record(struct task_dma_buf_record *rec)
-{
-	struct task_dma_buf_record_preload *preload;
-
-	local_lock(&dmabuf_rec_reloads.lock);
-	preload = this_cpu_ptr(&dmabuf_rec_reloads);
-	if (preload->size < MAX_PCP_POOL_SIZE) {
-		list_add(&rec->node, &preload->list);
-		preload->size++;
-	} else {
-		kmem_cache_free(task_dmabuf_record_cachep, rec);
-	}
-	local_unlock(&dmabuf_rec_reloads.lock);
-}
-
-static void trim_task_dmabuf_records_locked(void)
-{
-	struct task_dma_buf_record_preload *preload;
-
-	lockdep_assert_held(&dmabuf_rec_reloads.lock);
-	preload = this_cpu_ptr(&dmabuf_rec_reloads);
-	while (preload->size > MAX_PCP_POOL_SIZE) {
-		struct task_dma_buf_record *rec;
-
-		rec = list_first_entry(&preload->list, typeof(*rec), node);
-		list_del(&rec->node);
-		preload->size--;
-		kmem_cache_free(task_dmabuf_record_cachep, rec);
-	}
-}
-
-static void trim_task_dmabuf_records(void)
-{
-	local_lock(&dmabuf_rec_reloads.lock);
-	trim_task_dmabuf_records_locked();
-	local_unlock(&dmabuf_rec_reloads.lock);
-}
-
 static int dma_buf_mmap_internal(struct file *file, struct vm_area_struct *vma)
 {
 	struct dma_buf *dmabuf;
diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h
index bbdaa16..94ffc5c 100644
--- a/include/linux/dma-buf.h
+++ b/include/linux/dma-buf.h
@@ -23,9 +23,6 @@
 #include <linux/dma-fence.h>
 #include <linux/wait.h>
 #include <linux/android_kabi.h>
-#ifndef __GENKSYMS__
-#include <linux/refcount.h>
-#endif
 
 struct device;
 struct dma_buf;
@@ -641,22 +638,6 @@ struct dma_buf_export_info {
 };
 
 /**
- * struct task_dma_buf_record - Holds the number of (VMA and FD) references to a
- * dmabuf by a collection of tasks that share both mm_struct and files_struct.
- * This is the list entry type for @task_dma_buf_info dmabufs list.
- *
- * @node: Stores the list this record is on.
- * @dmabuf: The dmabuf this record is for.
- * @refcnt: The number of VMAs and FDs that reference @dmabuf by the tasks that
- *          share this record.
- */
-struct task_dma_buf_record {
-	struct list_head node;
-	struct dma_buf *dmabuf;
-	unsigned long refcnt;
-};
-
-/**
  * DEFINE_DMA_BUF_EXPORT_INFO - helper macro for exporters
  * @name: export-info name
  *