TID tracking
authorMateusz Majewski <m.majewski2@samsung.com>
Mon, 22 Aug 2022 13:43:13 +0000 (15:43 +0200)
committerMateusz Majewski <m.majewski2@samsung.com>
Wed, 24 Aug 2022 08:09:06 +0000 (10:09 +0200)
Change-Id: I55e0735135979de826cb9eb69ba2b8cf34901560

kernel/vlogger/vlogger.c

index 25469799222871023cfe3427afb9e0e00a678e83..8dd4901e36b0ecf540ef720eaaae7852932c759e 100644 (file)
@@ -246,6 +246,7 @@ static int vlog_task(void *user_data)
                        // TODO: g_start_time should be under some kind of mutex.
                        if (blk && get_block(blk)->head.ts < g_start_time) {
                                mutex_lock(&g_block_mutex);
+                               get_block(blk)->head.tid = 0;
                                queue_push(&g_free_q, blk);
                                g_threads[i].block = 0;
                                // TODO: The userspace might very well be using this block right now.
@@ -309,11 +310,11 @@ static long alloc_block_for_thread(void)
                queue_push(&g_free_q, blk);
        blk = queue_pop(&g_free_q);
        g_threads[tid].block = blk;
-       mutex_unlock(&g_block_mutex);
 
        if (!blk) {
                if ((g_err_count++ % 10000) < 3)
                        pr_info("[NO MEMORY] tid:%d free:%d err:%d", tid, g_free_q.count, g_err_count);
+               mutex_unlock(&g_block_mutex);
                return -ENOMEM;
        }
 
@@ -327,6 +328,7 @@ static long alloc_block_for_thread(void)
        block->head.tid = tid;
        block->head.offset = 0;
        block->head.ts = g_start_time;
+       mutex_unlock(&g_block_mutex);
 
        return (long)blk;
 }
@@ -400,8 +402,7 @@ static int vlogger_mmap(struct file *filep, struct vm_area_struct *vma)
        if (p)
                page = virt_to_page((unsigned long)p);
        else
-               // TODO: There is no reason for people to be able to write to g_threads.
-               page = virt_to_page((unsigned long)g_threads);
+               return -EINVAL;
 
        return remap_pfn_range(vma, vma->vm_start, page_to_pfn(page), size, vma->vm_page_prot);
 }