Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753057AbbBXVch (ORCPT ); Tue, 24 Feb 2015 16:32:37 -0500 Received: from mail-wg0-f49.google.com ([74.125.82.49]:40090 "EHLO mail-wg0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751721AbbBXVcf convert rfc822-to-8bit (ORCPT ); Tue, 24 Feb 2015 16:32:35 -0500 From: Michal Nazarewicz To: Stefan Strogin , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Stefan Strogin , Joonsoo Kim , Andrew Morton , Marek Szyprowski , aneesh.kumar@linux.vnet.ibm.com, Laurent Pinchart , Dmitry Safonov , Pintu Kumar , Weijie Yang , Laura Abbott , SeongJae Park , Hui Zhu , Minchan Kim , Dyasly Sergey , Vyacheslav Tyrtov , Aleksei Mateosian , gregory.0xf0@gmail.com, sasha.levin@oracle.com, gioh.kim@lge.com, pavel@ucw.cz, stefan.strogin@gmail.com Subject: Re: [PATCH v3 3/4] mm: cma: add list of currently allocated CMA buffers to debugfs In-Reply-To: <1fe64ae6f12eeda1c2aa59daea7f89e57e0e35a9.1424802755.git.s.strogin@partner.samsung.com> Organization: http://mina86.com/ References: <1fe64ae6f12eeda1c2aa59daea7f89e57e0e35a9.1424802755.git.s.strogin@partner.samsung.com> User-Agent: Notmuch/0.19+53~g2e63a09 (http://notmuchmail.org) Emacs/25.0.50.1 (x86_64-unknown-linux-gnu) X-Face: PbkBB1w#)bOqd`iCe"Ds{e+!C7`pkC9a|f)Qo^BMQvy\q5x3?vDQJeN(DS?|-^$uMti[3D*#^_Ts"pU$jBQLq~Ud6iNwAw_r_o_4]|JO?]}P_}Nc&"p#D(ZgUb4uCNPe7~a[DbPG0T~!&c.y$Ur,=N4RT>]dNpd;KFrfMCylc}gc??'U2j,!8%xdD Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAJFBMVEWbfGlUPDDHgE57V0jUupKjgIObY0PLrom9mH4dFRK4gmjPs41MxjOgAAACQElEQVQ4jW3TMWvbQBQHcBk1xE6WyALX1069oZBMlq+ouUwpEQQ6uRjttkWP4CmBgGM0BQLBdPFZYPsyFUo6uEtKDQ7oy/U96XR2Ux8ehH/89Z6enqxBcS7Lg81jmSuujrfCZcLI/TYYvbGj+jbgFpHJ/bqQAUISj8iLyu4LuFHJTosxsucO4jSDNE0Hq3hwK/ceQ5sx97b8LcUDsILfk+ovHkOIsMbBfg43VuQ5Ln9YAGCkUdKJoXR9EclFBhixy3EGVz1K6eEkhxCAkeMMnqoAhAKwhoUJkDrCqvbecaYINlFKSRS1i12VKH1XpUd4qxL876EkMcDvHj3s5RBajHHMlA5iK32e0C7VgG0RlzFPvoYHZLRmAC0BmNcBruhkE0KsMsbEc62ZwUJDxWUdMsMhVqovoT96i/DnX/ASvz/6hbCabELLk/6FF/8PNpPCGqcZTGFcBhhAaZZDbQPaAB3+KrWWy2XgbYDNIinkdWAFcCpraDE/knwe5DBqGmgzESl1p2E4MWAz0VUPgYYzmfWb9yS4vCvgsxJriNTHoIBz5YteBvg+VGISQWUqhMiByPIPpygeDBE6elD973xWwKkEiHZAHKjhuPsFnBuArrzxtakRcISv+XMIPl4aGBUJm8Emk7qBYU8IlgNEIpiJhk/No24jHwkKTFHDWfPniR4iw5vJaw2nzSjfq2zffcE/GDjRC2dn0J0XwPAbDL84TvaFCJEU4Oml9pRyEUhR3Cl2t01AoEjRbs0sYugp14/4X5n4pU4EHHnMAAAAAElFTkSuQmCC X-PGP: 50751FF4 X-PGP-FP: AC1F 5F5C D418 88F8 CC84 5858 2060 4012 5075 1FF4 X-Hashcash: 1:20:150224:stefan.strogin@gmail.com::cS3Xsj59NwqsTmu2:00000000000000000000000000000000000000CAD X-Hashcash: 1:20:150224:gioh.kim@lge.com::Xs4jzmeTANcOFr32:00GSj X-Hashcash: 1:20:150224:pintu.k@samsung.com::Ut+Dslf+TdLmP76s:00000000000000000000000000000000000000000007yO X-Hashcash: 1:20:150224:iamjoonsoo.kim@lge.com::eTlv3LBiLgU4FTy5:0000000000000000000000000000000000000000YrS X-Hashcash: 1:20:150224:linux-kernel@vger.kernel.org::jf6bEvPDLIE7U9eV:0000000000000000000000000000000000/HE X-Hashcash: 1:20:150224:pavel@ucw.cz::NWHD+1siViw65BiY:000001DtP X-Hashcash: 1:20:150224:v.tyrtov@samsung.com::G6J1fM8hhvBKRKGi:000000000000000000000000000000000000000000zkg X-Hashcash: 1:20:150224:laurent.pinchart@ideasonboard.com::AWD1+a2wNCWjMppZ:00000000000000000000000000001Qs6 X-Hashcash: 1:20:150224:akpm@linux-foundation.org::X706s1tBJNf1/H2V:0000000000000000000000000000000000001aoN X-Hashcash: 1:20:150224:gregory.0xf0@gmail.com::jWj9kUciJBzY7m6Z:0000000000000000000000000000000000000001Z6f X-Hashcash: 1:20:150224:a.mateosian@samsung.com::AaCO/5usxivmRXh0:000000000000000000000000000000000000001zO4 X-Hashcash: 1:20:150224:s.dyasly@samsung.com::ePxscZDfH2nl6Bzf:00000000000000000000000000000000000000000265w X-Hashcash: 1:20:150224:sj38.park@gmail.com::l7cwYPoUh0yK2E3c:0000000000000000000000000000000000000000002sVa X-Hashcash: 1:20:150224:d.safonov@partner.samsung.com::/cMG3qbqLBNsDDH4:000000000000000000000000000000002mJr X-Hashcash: 1:20:150224:s.strogin@partner.samsung.com::pcngxuPTcKIQlfRg:000000000000000000000000000000003b+r X-Hashcash: 1:20:150224:linux-mm@kvack.org::zLgEWOy01faZJaR7:00000000000000000000000000000000000000000004vzR X-Hashcash: 1:20:150224:weijie.yang@samsung.com::6jwfGgYeB8bbtVfZ:0000000000000000000000000000000000000041x1 X-Hashcash: 1:20:150224:m.szyprowski@samsung.com::BXN9vsSkFLgyg3ml:00000000000000000000000000000000000004Ve3 X-Hashcash: 1:20:150224:lauraa@codeaurora.org::4BOB0QVIDMXC2wNP:00000000000000000000000000000000000000005epx X-Hashcash: 1:20:150224:aneesh.kumar@linux.vnet.ibm.com::gTNIKKdt920fKRPl:0000000000000000000000000000006RHo X-Hashcash: 1:20:150224:sasha.levin@oracle.com::z4uDHGDHw8Z/fz+y:0000000000000000000000000000000000000006Fu1 X-Hashcash: 1:20:150224:minchan@kernel.org::YZBs973ncPI/VNSX:00000000000000000000000000000000000000000009+Rr X-Hashcash: 1:20:150224:zhuhui@xiaomi.com::PP5A8Wj8hHSseU5l:00000000000000000000000000000000000000000000E0az X-Hashcash: 1:20:150224:s.strogin@partner.samsung.com::NRZm+6SILE13BrW/:00000000000000000000000000000000Jxai Date: Tue, 24 Feb 2015 22:32:30 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4571 Lines: 135 On Tue, Feb 24 2015, Stefan Strogin wrote: > When CONFIG_CMA_BUFFER_LIST is configured a file is added to debugfs: > /sys/kernel/debug/cma/cma-/buffers contains a list of currently allocated > CMA buffers for each CMA region (N stands for number of CMA region). > > Format is: > - ( kB), allocated by () > > When CONFIG_CMA_ALLOC_STACKTRACE is configured then stack traces are saved when > the allocations are made. The stack traces are added to cma/cma-/buffers > for each buffer list entry. > > Example: > > root@debian:/sys/kernel/debug/cma# cat cma-0/buffers > 0x2f400000 - 0x2f417000 (92 kB), allocated by pid 1 (swapper/0) > [] cma_alloc+0x1bb/0x200 > [] dma_alloc_from_contiguous+0x3a/0x40 > [] dma_generic_alloc_coherent+0x89/0x160 > [] dmam_alloc_coherent+0xbe/0x100 > [] ahci_port_start+0xe2/0x210 > [] ata_host_start.part.28+0xc0/0x1a0 > [] ata_host_activate+0xd0/0x110 > [] ahci_host_activate+0x3f/0x170 > [] ahci_init_one+0x764/0xab0 > [] pci_device_probe+0x6f/0xd0 > [] driver_probe_device+0x68/0x210 > [] __driver_attach+0x79/0x80 > [] bus_for_each_dev+0x4f/0x80 > [] driver_attach+0x1e/0x20 > [] bus_add_driver+0x157/0x200 > [] driver_register+0x5d/0xf0 > <...> > > Signed-off-by: Stefan Strogin > --- a/mm/cma.h > +++ b/mm/cma.h > @@ -11,8 +13,32 @@ struct cma { > struct hlist_head mem_head; > spinlock_t mem_head_lock; > #endif > +#ifdef CONFIG_CMA_BUFFER_LIST > + struct list_head buffer_list; > + struct mutex list_lock; > +#endif > }; > > +#ifdef CONFIG_CMA_BUFFER_LIST > +struct cma_buffer { > + unsigned long pfn; > + unsigned long count; > + pid_t pid; > + char comm[TASK_COMM_LEN]; > +#ifdef CONFIG_CMA_ALLOC_STACKTRACE > + unsigned long trace_entries[16]; > + unsigned int nr_entries; > +#endif > + struct list_head list; > +}; This structure is only ever used in cma_debug.c so is there a reason to define it in the header file? > + > +extern int cma_buffer_list_add(struct cma *cma, unsigned long pfn, int count); > +extern void cma_buffer_list_del(struct cma *cma, unsigned long pfn, int count); > +#else > +#define cma_buffer_list_add(cma, pfn, count) { } > +#define cma_buffer_list_del(cma, pfn, count) { } > +#endif /* CONFIG_CMA_BUFFER_LIST */ > + > extern struct cma cma_areas[MAX_CMA_AREAS]; > extern unsigned cma_area_count; > +#ifdef CONFIG_CMA_BUFFER_LIST > +static ssize_t cma_buffer_list_read(struct file *file, char __user *userbuf, > + size_t count, loff_t *ppos) > +{ > + struct cma *cma = file->private_data; > + struct cma_buffer *cmabuf; > + char *buf; > + int ret, n = 0; > +#ifdef CONFIG_CMA_ALLOC_STACKTRACE > + struct stack_trace trace; > +#endif > + > + if (*ppos < 0 || !count) > + return -EINVAL; > + > + buf = vmalloc(count); > + if (!buf) > + return -ENOMEM; > + > + mutex_lock(&cma->list_lock); > + list_for_each_entry(cmabuf, &cma->buffer_list, list) { > + n += snprintf(buf + n, count - n, > + "0x%llx - 0x%llx (%lu kB), allocated by pid %u (%s)\n", > + (unsigned long long)PFN_PHYS(cmabuf->pfn), > + (unsigned long long)PFN_PHYS(cmabuf->pfn + > + cmabuf->count), > + (cmabuf->count * PAGE_SIZE) >> 10, cmabuf->pid, > + cmabuf->comm); > + > +#ifdef CONFIG_CMA_ALLOC_STACKTRACE > + trace.nr_entries = cmabuf->nr_entries; > + trace.entries = &cmabuf->trace_entries[0]; > + n += snprint_stack_trace(buf + n, count - n, &trace, 0); > + n += snprintf(buf + n, count - n, "\n"); > +#endif > + } > + mutex_unlock(&cma->list_lock); > + > + ret = simple_read_from_buffer(userbuf, count, ppos, buf, n); > + vfree(buf); > + > + return ret; > +} So in practice user space must allocate buffer big enough to read the whole file into memory. Calling read(2) with some count will never read anything past the first count bytes of the file. -- Best regards, _ _ .o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o ..o | Computer Science, Michał “mina86” Nazarewicz (o o) ooo +------ooO--(_)--Ooo-- -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/