This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/TDA2HG: [OpenGL] How to debug the memory usage by OpenGL

Part Number: TDA2HG


Tool/software: TI C/C++ Compiler

Hi:

  we are working on visionsdk 3.05 with QT 5.6. we are suffering the memory leak when our AVM application quit normally. we are also use the valgrind to check the memory by nothing found. see the attachment.

each time, when we start&quit the application, the free of system memory will decrease by 16M( we trace the memory usage by free cmd), repeat several time, will run out of the memory, and our application can't be spawned by OOM).

  so we wounder if we could not release the memory from the OpengGL, so our question is how we can trace the memory usage of OpenGL and convinient for use to debug such problem.

thanks.mem_leak.log 


  • Hi Andy,
    cat /sys/kernel/debug/dri/0/gem

    will show you the gem buffers allocated.
    Can you check any of the gem object remains during exit of an application?

    Thanks
    RamPrasad

  • Hi RamPrasad:

    just found that the memory leak happen when we call " ret = ioctl(devBufFD, DBUFIOC_EXPORT_VIRTMEM, &exp);"

    here just convert a normal linux memory to dmafd. when we comment out ExportDmaBuf(), free memory is ok.

    any help??

    int TEgl::ExportDmaBuf(void * vAddr, int size, uint32_t *fdBuf)
    {
        int ret = -1;
        struct dmabuf_vmem_export exp;
        exp.vaddr = (unsigned long)vAddr;
        exp.size = size;
    
        if(devBufFD > 0)
        {
            /* Export as DMAbuf handle */
            ret = ioctl(devBufFD, DBUFIOC_EXPORT_VIRTMEM, &exp);
            if(ret == 0)
            {
                *fdBuf = exp.fd;
            }
            else
            {
                printf(" exportDmaBuf failed retVal=%d errno %s  addr %p size %d \n",ret,strerror(errno),vAddr,size);
            }
        }
    return ret;
    }

    	 auto found = TextureSuracePool.find(addr);
    	 if(found !=TextureSuracePool.end()){
    		 printf("texture suface exited \n");
    		 outTex = found->second;
    		 return true;	 
    		 
    	 }
    	 uint32_t dmaFd;
    	ExportDmaBuf(addr,width*height*3/2,&dmaFd);
    	printf("dma fd 0x%x \n",dmaFd);
    
        return false;
    	if(0!=CreateYUVTextureImg(width,height,dmaFd,&outTex)){
    		return false;
    			
    	}
        printf("outTex 0x%x \n",outTex);

  • Hi andy,

    Look like you are not calling close(exp.fd) at the end. 

    This must be causing the memory leak.

    Please refer gbm_allocator_get_native_buffer() in ./links_fw/src/hlos/system/system_gbm_allocator.c

    Thanks

    Ram

  •   Hi ram:

    we call close, but the memory is not release, when go into the source code we find the pages i==0, so no memory would be release,.

    static void vmem_exp_dmabuf_ops_release(struct dma_buf *dbuf)
    {
    	struct vmem_exp_buf *buf = dbuf->priv;
    	struct sg_table *sgt = &buf->sgt;
    	int i = buf->num_pages;
         printk(KERN_ALERT "vmem_exp_dmabuf_ops_release\n");
    	if (atomic_dec_and_test(&buf->refcount)) {
    		DEFINE_DMA_ATTRS(attrs);
    
    		dma_set_attr(DMA_ATTR_SKIP_CPU_SYNC, &attrs);
    		dma_unmap_sg_attrs(buf->dev, sgt->sgl, sgt->orig_nents,
    				buf->dma_dir, &attrs);
     printk(KERN_ALERT "vmem_exp_dmabuf_ops_release  pages %d \n",i);;
    		while (--i >= 0) {
    			if (buf->dma_dir == DMA_FROM_DEVICE) {
    				set_page_dirty_lock(buf->pages[i]);
    				__free_page(buf->pages[i]);
    			}
    		}
    		sg_free_table(&buf->sgt);
    		kfree(buf->pages);
    		kfree(buf);
    	}
    }

    if we add    buf->num_pages = ret;

    	ret = sg_alloc_from_vaddr(sgt, &buf->pages, vaddr, size, buf->offset);
    	if (ret <= 0) {
    		dev_err(dev, "sg_alloc_from_vaddr failed\n");
    		goto fail;
    	}
        buf->num_pages = ret;
    	dma_set_attr(DMA_ATTR_SKIP_CPU_SYNC, &attrs);
    	ret = dma_map_sg_attrs(dev, sgt->sgl, sgt->orig_nents, dma_dir, &attrs);
    	if (!ret) {
    		dev_err(dev, "failed to map scatterlist\n");
    		goto fail;
    	}

    then kernel will crash 

    ifconfig eth2 192.168.8.10
    root@dra7xx-evm:~# ifconfig eth2 192.168.8.10
    root@dra7xx-evm:~# echo "8" > /proc/sys/kernel/printk
    root@dra7xx-evm:~# [   59.827737] dma_buf_release 
    [   59.830713] dmabuf->ops->release
    [   59.834159] vmem_exp_dmabuf_ops_release
    [   59.842563] vmem_exp_dmabuf_ops_release  pages 384 
    [   59.849107] dma_buf_release 
    [   59.856806] dmabuf->ops->release
    [   59.861271] vmem_exp_dmabuf_ops_release
    [   59.868503] vmem_exp_dmabuf_ops_release  pages 384 
    [   59.875112] dma_buf_release 
    [   59.881532] dmabuf->ops->release
    [   59.894894] vmem_exp_dmabuf_ops_release
    [   59.899423] vmem_exp_dmabuf_ops_release  pages 384 
    [   59.904485] dma_buf_release 
    [   59.907714] dmabuf->ops->release
    [   59.911233] vmem_exp_dmabuf_ops_release
    [   59.915120] vmem_exp_dmabuf_ops_release  pages 2 
    [   59.920583] dma_buf_release 
    [   59.923610] dmabuf->ops->release
    [   59.927044] vmem_exp_dmabuf_ops_release
    [   59.931104] vmem_exp_dmabuf_ops_release  pages 384 
    [   59.936302] dma_buf_release 
    [   59.939439] dmabuf->ops->release
    [   59.942882] vmem_exp_dmabuf_ops_release
    [   59.946976] vmem_exp_dmabuf_ops_release  pages 384 
    [   59.952122] dma_buf_release 
    [   59.955201] dmabuf->ops->release
    [   59.958663] vmem_exp_dmabuf_ops_release
    [   59.962832] vmem_exp_dmabuf_ops_release  pages 384 
    [   59.967837] Unable to handle kernel NULL pointer dereference at virtual address 00000004
    [   59.975964] pgd = d6d38000
    [   59.976287] Unable to handle kernel NULL pointer dereference at virtual address 00000300
    [   59.976290] pgd = eb340000
    [   59.976296] [00000300] *pgd=00000000
    [   59.976306] Internal error: Oops: 5 [#1] PREEMPT SMP ARM
    [   59.976382] Modules linked in: vmouse(O) cmemk(O) memcache(O) ax88179_178a usbnet bc_example(O) xhci_plat_hcd xhci_hcd usbcore rpmsg_proto rpmsg_rpc dwc3 udc_core virtio_rpmsg_bus extcon_usb_gpio pvrsrvkm(O) omap_aes_driver c_can_platform c_can omap_sham can_dev ahci_platform libahci_platform libahci libata scsi_mod dwc3_omap extcon rtc_omap omap_des omap_rng rng_core omap_remoteproc remoteproc virtio virtio_ring sch_fq_codel
    [   59.976393] CPU: 1 PID: 1092 Comm: Thrift service  Tainted: G           O    4.4.84 #6
    [   59.976396] Hardware name: Generic DRA74X (Flattened Device Tree)
    [   59.976401] task: ed144800 ti: eb38c000 task.ti: eb38c000
    [   59.976427] PC is at vsync_timer+0xe8/0x2a0
    [   59.976433] LR is at vsync_timer+0x30/0x2a0
    [   59.976440] pc : [<c03b2438>]    lr : [<c03b2380>]    psr: 60000193
    [   59.976440] sp : eb38dcd0  ip : 00000000  fp : eb38dd34
    [   59.976443] r10: c03b2350  r9 : 00000003  r8 : ee81f328
    [   59.976447] r7 : ee81f360  r6 : 00000001  r5 : 00000100  r4 : ee81f338
    [   59.976451] r3 : ee81f360  r2 : ee6a8800  r1 : 00000e8b  r0 : 20000193
    [   59.976457] Flags: nZCv  IRQs off  FIQs on  Mode SVC_32  ISA ARM  Segment none
    [   59.976461] Control: 10c5387d  Table: ab34006a  DAC: 00000051
    [   59.976465] Process Thrift service  (pid: 1092, stack limit = 0xeb38c210)
    [   59.976469] Stack: (0xeb38dcd0 to 0xeb38e000)
    [   59.976476] dcc0:                                     c0078d74 c008a104 ed144848 ee81f328
    [   59.976483] dce0: ef63cc4c ef63cc00 eb38dd14 eb38dcf8 ee81f324 20000193 00000100 ee81f000
    [   59.976490] dd00: ef63cc00 00000000 eb38dd34 ef63cc00 ee81f328 ef63cc40 00000000 ef63cc4c
    [   59.976497] dd20: 00000003 c03b2350 eb38dd7c eb38dd38 c0093668 c03b235c f68dbb5b 0000000d
    [   59.976504] dd40: c082bb18 c09890f6 f68dbb5b 0000000d 00000400 ef63cc00 00000003 ffffffff
    [   59.976511] dd60: ef63cc14 ef63cc98 ef63ccb8 ef63cc78 eb38ddd4 eb38dd80 c0093cf8 c0093558
    [   59.976517] dd80: ef63ccb8 00000001 f68dbb5b 0000000d 00000000 7fffffff eb38de4c eb38dda8
    [   59.976524] dda0: f68dbb5b 0000000d 00aee9c5 ef641b80 ef005d80 c0959708 ef0455c0 00000012
    [   59.976531] ddc0: 00000000 c09b1470 eb38dde4 eb38ddd8 c050195c c0093c58 eb38de0c eb38dde8
    [   59.976538] dde0: c0085b60 c0501930 c093640c 00000012 00000000 00000000 ef008000 00000000
    [   59.976545] de00: eb38de1c eb38de10 c0081674 c0085af8 eb38de44 eb38de20 c008194c c0081654
    [   59.976552] de20: c093c8e4 fa21200c eb38de70 fa212000 fa213000 00000000 eb38de6c eb38de48
    [   59.976558] de40: c00094f0 c00818f4 c0092e04 a0000013 ffffffff eb38dea4 0000c350 00000000
    [   59.976565] de60: eb38decc eb38de70 c0014854 c00094bc eb38df28 00000000 000cf764 ef63cc00
    [   59.976572] de80: eb38df28 eb38df28 0000c350 00000000 0000c350 00000000 c09b1470 eb38decc
    [   59.976579] dea0: 00000000 eb38dec0 c009348c c0092e04 a0000013 ffffffff 00000051 0000c350
    [   59.976586] dec0: eb38deec eb38ded0 c009348c c0092ddc c0688148 c0687a94 eb38df28 eb38c000
    [   59.976592] dee0: eb38df24 eb38def0 c068b1e4 c0093480 0000c350 00000001 c093c100 0000c350
    [   59.976599] df00: 00000000 000186a0 00000000 00000001 b43fd584 00000000 eb38df84 eb38df28
    [   59.976606] df20: c0094254 c068b138 eb38df28 00000000 00000000 00000000 f68d85d3 0000000d
    [   59.976612] df40: f68cc283 0000000d c009328c ef63cc40 00000000 00000000 00000000 c0039934
    [   59.976619] df60: b43fd584 00000051 00000000 000000a2 c000fe24 eb38c000 eb38dfa4 eb38df88
    [   59.976626] df80: c009437c c00941b4 00000000 0000c350 00000000 00000000 00000000 eb38dfa8
    [   59.976632] dfa0: c000fc60 c00942e8 00000000 00000000 b43fd584 b43fd584 b43fe0a4 00000000
    [   59.976639] dfc0: 00000000 00000000 00000000 000000a2 7fffffff b43fd654 b43fd6e8 00000004
    [   59.976646] dfe0: 00000000 b43fd578 00000000 b6ee74c0 800f0030 b43fd584 00000000 00000000
    [   59.976649] Backtrace: 
    [   59.976665] [<c03b2350>] (vsync_timer) from [<c0093668>] (__hrtimer_run_queues+0x11c/0x1ac)
    [   59.976678]  r10:c03b2350 r9:00000003 r8:ef63cc4c r7:00000000 r6:ef63cc40 r5:ee81f328
    [   59.976681]  r4:ef63cc00
    [   59.976690] [<c009354c>] (__hrtimer_run_queues) from [<c0093cf8>] (hrtimer_interrupt+0xac/0x1fc)
    [   59.976702]  r10:ef63cc78 r9:ef63ccb8 r8:ef63cc98 r7:ef63cc14 r6:ffffffff r5:00000003
    [   59.976706]  r4:ef63cc00
    [   59.976721] [<c0093c4c>] (hrtimer_interrupt) from [<c050195c>] (arch_timer_handler_phys+0x38/0x40)
    [   59.976733]  r10:c09b1470 r9:00000000 r8:00000012 r7:ef0455c0 r6:c0959708 r5:ef005d80
    [   59.976737]  r4:ef641b80
    [   59.976746] [<c0501924>] (arch_timer_handler_phys) from [<c0085b60>] (handle_percpu_devid_irq+0x74/0x8c)
    [   59.976757] [<c0085aec>] (handle_percpu_devid_irq) from [<c0081674>] (generic_handle_irq+0x2c/0x3c)
    [   59.976769]  r9:00000000 r8:ef008000 r7:00000000 r6:00000000 r5:00000012 r4:c093640c
    [   59.976777] [<c0081648>] (generic_handle_irq) from [<c008194c>] (__handle_domain_irq+0x64/0xbc)
    [   59.976788] [<c00818e8>] (__handle_domain_irq) from [<c00094f0>] (gic_handle_irq+0x40/0x7c)
    [   59.976799]  r9:00000000 r8:fa213000 r7:fa212000 r6:eb38de70 r5:fa21200c r4:c093c8e4
    [   59.976807] [<c00094b0>] (gic_handle_irq) from [<c0014854>] (__irq_svc+0x54/0x90)
    [   59.976810] Exception stack(0xeb38de70 to 0xeb38deb8)
    [   59.976815] de60:                                     eb38df28 00000000 000cf764 ef63cc00
    [   59.976822] de80: eb38df28 eb38df28 0000c350 00000000 0000c350 00000000 c09b1470 eb38decc
    [   59.976828] dea0: 00000000 eb38dec0 c009348c c0092e04 a0000013 ffffffff
    [   59.976840]  r9:00000000 r8:0000c350 r7:eb38dea4 r6:ffffffff r5:a0000013 r4:c0092e04
    [   59.976848] [<c0092dd0>] (hrtimer_active) from [<c009348c>] (hrtimer_try_to_cancel+0x18/0xb4)
    [   59.976862] [<c0093474>] (hrtimer_try_to_cancel) from [<c068b1e4>] (do_nanosleep+0xb8/0x130)
    [   59.976868]  r5:eb38c000 r4:eb38df28
    [   59.976876] [<c068b12c>] (do_nanosleep) from [<c0094254>] (hrtimer_nanosleep+0xac/0x134)
    [   59.976887]  r10:00000000 r9:b43fd584 r8:00000001 r7:00000000 r6:000186a0 r5:00000000
    [   59.976891]  r4:0000c350
    [   59.976898] [<c00941a8>] (hrtimer_nanosleep) from [<c009437c>] (SyS_nanosleep+0xa0/0xd4)
    [   59.976910]  r9:eb38c000 r8:c000fe24 r7:000000a2 r6:00000000 r5:00000051 r4:b43fd584
    [   59.976920] [<c00942dc>] (SyS_nanosleep) from [<c000fc60>] (ret_fast_syscall+0x0/0x3c)
    [   59.976925]  r5:00000000 r4:00000000
    [   59.976933] Code: e1550007 e2435028 1affffdf e51b503c (e5b54200) 
    [   59.976942] ---[ end trace 4ab3edbdb4b98d27 ]---
    [   59.976947] Kernel panic - not syncing: Fatal exception in interrupt
    [   60.569544] [00000004] *pgd=96c7c831, *pte=00000000, *ppte=00000000
    [   60.575862] Internal error: Oops: 817 [#2] PREEMPT SMP ARM
    [   60.581368] Modules linked in: vmouse(O) cmemk(O) memcache(O) ax88179_178a usbnet bc_example(O) xhci_plat_hcd xhci_hcd usbcore rpmsg_proto rpmsg_rpc dwc3 udc_core virtio_rpmsg_bus extcon_usb_gpio pvrsrvkm(O) omap_aes_driver c_can_platform c_can omap_sham can_dev ahci_platform libahci_platform libahci libata scsi_mod dwc3_omap extcon rtc_omap omap_des omap_rng rng_core omap_remoteproc remoteproc virtio virtio_ring sch_fq_codel
    [   60.619531] CPU: 0 PID: 1767 Comm: avm_qt_app Tainted: G      D    O    4.4.84 #6
    [   60.627044] Hardware name: Generic DRA74X (Flattened Device Tree)
    [   60.633162] task: ee7c5a00 ti: d6d20000 task.ti: d6d20000
    [   60.638586] PC is at vmemexp_release+0x48/0x80
    [   60.643047] LR is at 0xd1a36904
    [   60.646201] pc : [<c0413d20>]    lr : [<d1a36904>]    psr: 80000093
    [   60.646201] sp : d6d21f08  ip : ee81dffc  fp : d6d21f24
    [   60.657725] r10: d6d009c8  r9 : 00000008  r8 : eec44440
    [   60.662970] r7 : 00000100  r6 : 00000200  r5 : d1a3690c  r4 : d1a36900
    [   60.669522] r3 : 00000000  r2 : fffffffc  r1 : a0000013  r0 : a0000013
    [   60.676075] Flags: Nzcv  IRQs off  FIQs on  Mode SVC_32  ISA ARM  Segment none
    [   60.683327] Control: 10c5387d  Table: 96d3806a  DAC: 00000051
    [   60.689096] Process avm_qt_app (pid: 1767, stack limit = 0xd6d20210)
    [   60.695475] Stack: (0xd6d21f08 to 0xd6d22000)
    [   60.699851] 1f00:                   d6d009c0 ee9b3a30 00000000 ef0c6510 d6d21f5c d6d21f28
    [   60.708065] 1f20: c01219bc c0413ce4 00000000 00000000 d6d21f54 ee7c5e60 c098c7a8 00000000
    [   60.716279] 1f40: ee7c5a00 c000fe24 d6d20000 00000000 d6d21f6c d6d21f60 c0121b64 c0121940
    [   60.724493] 1f60: d6d21f8c d6d21f70 c004fb18 c0121b60 d6d20000 c000fe24 d6d21fb0 00000006
    [   60.732706] 1f80: d6d21fac d6d21f90 c00136f0 c004fa8c addb64ac 0017ce58 addb64ac 00000006
    [   60.740920] 1fa0: 00000000 d6d21fb0 c000fcb4 c0013640 00000000 00000002 b27d6084 00000000
    [   60.749132] 1fc0: addb64ac 0017ce58 addb64ac 00000006 001a3608 00000001 b6f22000 00000000
    [   60.757345] 1fe0: 00000000 bebf3b70 00000000 b4804d22 80000030 0000000a 00000000 00000000
    [   60.765553] Backtrace: 
    [   60.768020] [<c0413cd8>] (vmemexp_release) from [<c01219bc>] (__fput+0x88/0x1d0)
    [   60.775445]  r7:ef0c6510 r6:00000000 r5:ee9b3a30 r4:d6d009c0
    [   60.781162] [<c0121934>] (__fput) from [<c0121b64>] (____fput+0x10/0x14)
    [   60.787889]  r10:00000000 r9:d6d20000 r8:c000fe24 r7:ee7c5a00 r6:00000000 r5:c098c7a8
    [   60.795791]  r4:ee7c5e60
    [   60.798345] [<c0121b54>] (____fput) from [<c004fb18>] (task_work_run+0x98/0xcc)
    [   60.805690] [<c004fa80>] (task_work_run) from [<c00136f0>] (do_work_pending+0xbc/0xc0)
    [   60.813637]  r7:00000006 r6:d6d21fb0 r5:c000fe24 r4:d6d20000
    [   60.819355] [<c0013634>] (do_work_pending) from [<c000fcb4>] (slow_work_pending+0xc/0x20)
    [   60.827565]  r7:00000006 r6:addb64ac r5:0017ce58 r4:addb64ac
    [   60.833279] Code: e3a07c01 e3a06c02 e59ce008 e1540002 (e583e004) 
    [   60.839398] ---[ end trace 4ab3edbdb4b98d28 ]---
    [   60.844040] CPU0: stopping
    [   60.846759] CPU: 0 PID: 1767 Comm: avm_qt_app Tainted: G      D    O    4.4.84 #6
    [   60.854270] Hardware name: Generic DRA74X (Flattened Device Tree)
    [   60.860386] Backtrace: 
    [   60.862854] [<c0013b1c>] (dump_backtrace) from [<c0013d18>] (show_stack+0x18/0x1c)
    [   60.870453]  r7:d6d21c68 r6:20000193 r5:00000000 r4:c0959590
    [   60.876175] [<c0013d00>] (show_stack) from [<c02b39a8>] (dump_stack+0x8c/0xa0)
    [   60.883431] [<c02b391c>] (dump_stack) from [<c0016e64>] (handle_IPI+0x184/0x198)
    [   60.890854]  r7:d6d21c68 r6:00000000 r5:00000000 r4:c093640c
    [   60.896569] [<c0016ce0>] (handle_IPI) from [<c0009528>] (gic_handle_irq+0x78/0x7c)
    [   60.904167]  r7:fa212000 r6:d6d21c68 r5:fa21200c r4:c093c8e4
    [   60.909882] [<c00094b0>] (gic_handle_irq) from [<c0014854>] (__irq_svc+0x54/0x90)
    [   60.917395] Exception stack(0xd6d21c68 to 0xd6d21cb0)
    [   60.922468] 1c60:                   ee70d4c4 00000000 00000002 0000030a ee7c5a00 00000000
    [   60.930683] 1c80: 00000504 c0413d24 00000001 c0413d22 c081f384 d6d21cc4 d6d21cc8 d6d21cb8
    [   60.938894] 1ca0: c0042f30 c068be68 60000113 ffffffff
    [   60.943963]  r9:c0413d22 r8:00000001 r7:d6d21c9c r6:ffffffff r5:60000113 r4:c068be68
    [   60.951788] [<c068be40>] (_raw_spin_unlock_irq) from [<c0042f30>] (exit_signals+0xb4/0x148)
    [   60.960176] [<c0042e7c>] (exit_signals) from [<c0038240>] (do_exit+0xa8/0x9b8)
    [   60.967425]  r6:0000000b r5:0000000b r4:ee7c5a00
    [   60.972085] [<c0038198>] (do_exit) from [<c0013f68>] (die+0x24c/0x45c)
    [   60.978638]  r7:c0413d24
    [   60.981191] [<c0013d1c>] (die) from [<c002222c>] (__do_kernel_fault.part.0+0x6c/0x1ec)
    [   60.989139]  r10:d6d009c8 r9:00000008 r8:00000004 r7:ee5eb340 r6:00000817 r5:d6d21eb8
    [   60.997039]  r4:00000004
    [   60.999593] [<c00221c0>] (__do_kernel_fault.part.0) from [<c001d88c>] (do_page_fault+0x34c/0x358)
    [   61.008501]  r7:00000817 r4:d6d21eb8
    [   61.012106] [<c001d540>] (do_page_fault) from [<c00092f4>] (do_DataAbort+0x40/0xc0)
    [   61.019792]  r10:d6d009c8 r9:00000008 r8:d6d21eb8 r7:00000004 r6:c001d540 r5:00000817
    [   61.027694]  r4:c0940ec4
    [   61.030245] [<c00092b4>] (do_DataAbort) from [<c00147e0>] (__dabt_svc+0x40/0x60)
    [   61.037669] Exception stack(0xd6d21eb8 to 0xd6d21f00)
    [   61.042742] 1ea0:                                                       a0000013 a0000013
    [   61.050956] 1ec0: fffffffc 00000000 d1a36900 d1a3690c 00000200 00000100 eec44440 00000008
    [   61.059169] 1ee0: d6d009c8 d6d21f24 ee81dffc d6d21f08 d1a36904 c0413d20 80000093 ffffffff
    [   61.067378]  r8:eec44440 r7:d6d21eec r6:ffffffff r5:80000093 r4:c0413d20
    [   61.074148] [<c0413cd8>] (vmemexp_release) from [<c01219bc>] (__fput+0x88/0x1d0)
    [   61.081572]  r7:ef0c6510 r6:00000000 r5:ee9b3a30 r4:d6d009c0
    [   61.087268] SMP: failed to stop secondary CPUs
    [[     6 161..009911774411]]  ------[[ en de nKd erKneler npeanl ic -p anniotc  -s ynnocitn gsy:n cFaitnga:l  Feaxtcealp tieoxcn eiptn iionnt iern interrupt
    [   61.105532]  r10:00000000 r9:d6d20000 r8:c000fe24 r7:ee7c5a00 r6:00000000 r5:c098c7a8
    [   61.113432]  r4:ee7c5e60
    [   61.115984] [<c0121b54>] (____fput) from [<c004fb18>] (task_work_run+0x98/0xcc)
    [   61.123327] [<c004fa80>] (task_work_run) from [<c00136f0>] (do_work_pending+0xbc/0xc0)
    [   61.131274]  r7:00000006 r6:d6d21fb0 r5:c000fe24 r4:d6d20000
    [   61.136994] [<c0013634>] (do_work_pending) from [<c000fcb4>] (slow_work_pending+0xc/0x20)
    [   61.145202]  r7:00000006 r6:addb64ac r5:0017ce58 r4:addb64ac

  • Hi Ramprasad,

    I attached my simple test case below which is copy from gbm_allocator_get_native_buffer() . It still memory leak, and leak size is equal to "size = 10 * 1024 * 1024;".

    int main() {
        while(1){
            int devBufFD = open("/dev/vmemexp", O_RDWR | O_CLOEXEC);
            if (devBufFD < 0)
            {
                return -1;
            }
            struct dmabuf_vmem_export exp;
            size_t size = 10 * 1024 * 1024;
            unsigned long *vAddr = (unsigned long *)malloc(size);
            if (vAddr <= 0)
            {
                return -1;
            }
    
            exp.vaddr = (unsigned long)vAddr;
            exp.size = size;
    
            printf("before ioctl\n");
            getc(stdin);
            int ret = ioctl(devBufFD, DBUFIOC_EXPORT_VIRTMEM, &exp);
            if (ret == 0)
            {
                // close(exp.fd); will crash
            }
            else
            {
                printf(" exportDmaBuf failed retVal=%d errno %s  addr %x size %d \n", ret, strerror(errno), vAddr, exp.size);
            }
    
            printf("after ioctl\n");
            close(devBufFD);
            close(exp.fd);
            free(vAddr);
        }
    }

    I changed exp.fd and devBufFD close sequence because it will crash if exp.fd close before devBufFD, no matter if we changed vmem-exp.c or not. The crash log please refer to previouse said. And I found it because of "kfree(buf)" in "vmem_exp_dmabuf_ops_release"  is same as "list_del(&buf->node);" in "vmemexp_release".

    So, would you please tell us what we missed?

    Thanks!

     

     

    Ramprasad:

  • Hi:

      if not comment out as following, it will not free memory, and also require us to close devfd first then close expfd, anyway it will crash

    while (--i >= 0) {
    			//if (buf->dma_dir == DMA_FROM_DEVICE) {
    				 printk(KERN_ALERT "vmem_exp_dmabuf_ops_release DMA_FROM_DEVICE pages %d  %d \n",DMA_FROM_DEVICE,i);
    				set_page_dirty_lock(buf->pages[i]);
    				__free_page(buf->pages[i]);
    			//}
    		}

  • Hi ,

    This conditional freeing pages looks bug.

    dma_dir used during export is DMA_BIDIRECTIONAL but while freeing , it is being done only if dma_dir=DMA_FROM_DEVICE.

    Thanks for identifying this.

    i will get back to you on this after discussing with the vmem export driver author,

    Thanks

    Ram

  • Thanks Ram!

    But this bug block our stable test for our customer, hope you could provide us fix patch soon.

    Thanks!

  • Hi Ram:

      Any update?

      thanks