From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E36E7C3064D for ; Fri, 28 Jun 2024 07:24:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 57D5A6B008C; Fri, 28 Jun 2024 03:24:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 52D3D6B0098; Fri, 28 Jun 2024 03:24:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3F5486B009A; Fri, 28 Jun 2024 03:24:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 203FD6B008C for ; Fri, 28 Jun 2024 03:24:28 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 9588F1A0405 for ; Fri, 28 Jun 2024 07:24:27 +0000 (UTC) X-FDA: 82279459374.22.34923A4 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by imf22.hostedemail.com (Postfix) with ESMTP id 6735EC000D for ; Fri, 28 Jun 2024 07:24:25 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=yoseli.org header.s=gm1 header.b=b7FTYbtQ; spf=none (imf22.hostedemail.com: domain of jeanmichel.hautbois@yoseli.org has no SPF policy when checking 217.70.183.197) smtp.mailfrom=jeanmichel.hautbois@yoseli.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719559452; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=VbQoS/OcvJlXrl5R2AyCpMc/YyKW0c2dWjj15GxiM8A=; b=eeTOZokE/C3jRoP6KATRWaemCBPASn6KSEnhn0lLzORXQhsTTbCKOWQa9tStg91fshJSER +4geW+vAfOiRbitKzLH/+Fq/WFnwZLMvEzwRKKHcyW574sJF729ADyz0SShNOsAjnV+umN fw4IIpDBB6/VZVAu52ixRQbU15Lc77w= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=yoseli.org header.s=gm1 header.b=b7FTYbtQ; spf=none (imf22.hostedemail.com: domain of jeanmichel.hautbois@yoseli.org has no SPF policy when checking 217.70.183.197) smtp.mailfrom=jeanmichel.hautbois@yoseli.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719559452; a=rsa-sha256; cv=none; b=eP0eDpj2BbRtgqYHDVbTOCNRD+j/dfJo8YUwhcmBovxX6cRcckcBuNYG13ifNAT138H9f1 A7Ue2H3ZEAtBYcTjn4yl/XjEtMaAE4y0csH4wK5X8AIppY78SHTI3T8LJMRRvPHEVqGCP/ CHaq7wFjnXCmg7wTzY8N76VHKzCR3nI= Received: by mail.gandi.net (Postfix) with ESMTPSA id 9E2E31C0004; Fri, 28 Jun 2024 07:24:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yoseli.org; s=gm1; t=1719559463; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VbQoS/OcvJlXrl5R2AyCpMc/YyKW0c2dWjj15GxiM8A=; b=b7FTYbtQb/lZGAPoCFSkYLDT06YA4dKtIPv9ILZ0saB/FtAA9ka0Xee56Vw85OvOUO8QNA otMNSq7lta/n8Z05tRP75SvCxbyYvCEM16PsXk5VzsWIy830iGMGdKzKQ1hUVWabV+fPF1 08nKct7UdGNO7eGUG4uFfBB/976J2Z9UNCI/TBlarEv3aahmU2wQQ/U6cpLgpqza9B9Mog Ruq8QpsMJTo6CKafr99P7nMqrlnQICUqIMjuenStZS2I2SU6cL0UOtkWW/b/4RJ3QkP01u b0M3mlJtBVAc2Didjjp2yzxCA17FxdLRM2zuOOD2l1TUBHaONimcbSzyEPwgSA== Message-ID: Date: Fri, 28 Jun 2024 09:24:22 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: m68k 54418 fails to execute user space To: Michael Schmitz , linux-m68k@lists.linux-m68k.org, linux-mm@kvack.org, linux-mtd@lists.infradead.org Cc: Greg Ungerer , Geert Uytterhoeven , Christoph Hellwig , wbx@openadk.org References: <735e19b6-3747-417f-ba5b-1a7da137a3a3@yoseli.org> <7fb2988d-ab89-405f-8cf1-edcdd2196376@gmail.com> <57879ac8-eaf5-48f1-b4ef-6619d9108440@yoseli.org> Content-Language: en-US From: Jean-Michel Hautbois In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-GND-Sasl: jeanmichel.hautbois@yoseli.org X-Stat-Signature: w7oudc3ziaapydq55nzjx1d5xefxwgrg X-Rspam-User: X-Rspamd-Queue-Id: 6735EC000D X-Rspamd-Server: rspam02 X-HE-Tag: 1719559465-471630 X-HE-Meta: U2FsdGVkX1+Nr4CaMul8vUYYuc9oCu2Bk3Uuw/GHqkDzq7gKmd5Ais51mO79MzrcANhd4T+iKXyj0O/sntWCtCBOGepZsP2bqWfhvZEUOi84dQp8ryapMA+8DR3eCCcvRPcubJrghJK5AM3YfxrYJqJGq1HBgx0K9ideslaagJTwxu2Nbb5XO+Npt+pbgqiAs2KXtzifXhqpw2PlO+wFrNx+PeO2aKUc41arklj8LVHOyNqWAhaFUXn0H0nNnn0IfOssnXs2jLlYEAD5fkVdFaDAk8Ovk8jvTGHYKGr2H7RjMd5PRANbe4P/e3ct53cn6RA/yYodxfCL04YZbF8n/0VBeTsciXW9eAdEVCixNo9uoACJS/enIHKdrLhpEQSeOaVT153JSG6iMP9FWRzUQEjy4jDditdWpRxDkwm1UERyb+hVMO9ZP+Vgu/yfjuNFRhXI18y+iXBpYpvuEZotOdEuncEHYQq8FzHqgFYcJKVkN0ffzbh1F6yzen8fXX0d1SytEzhU8CroJShxp1rjYAUBHoNu0oXD28EPFGSSnhKrhbYNA/UIqgWpj0Qqb/1eOJpxmUJ8Odn56+sx3NCV+15IbwJPdqpLNRU4rvLGNZo6dTyW6JrSewJRSqPK042S4TmzSQJ7yLqqzgEEP24GlL5zZo6VqgsiUjJNlZFc8PLcuWjP/WXm3N2RbSjK0vZBUFWrKY/9dqtGV78AMGB2+lF0Cjj3Ee/yiXRNGXJALTE5TD9ZH+It56yixHxMcS75VDGBVx2Q3Q+JUsfjeepOwaxSwC/STUdQuz0oRaN+xQscgz4C/+yoAGM8zKbKVdrY1ONdGrsJdGfWO/9XRHIKaK1r+P/FIJjHHupO7RclMrxSFdIufYfX9BDBBoDIxl+ASLGYDCsCWb0rtZcax/t9HMIGWMvFvi7zFIl9hSJfrqxWvCj//ZS0LQiRdtO3h1H82D91IGBcE9j12za+Q0K iy3CG6Jg 2KIlTXNoizl6jL1AmwnZcbQgHrJ3Q+WJRUS+zKE/Vdu61gCPH+WB6GWxRytk93W4mFd/Ao9s6xrN3H5Y9RWkCaPG8idBmJ/OYzi4yxFb+XCZagHzOS0AVbRZPpzPhsfgG8CqUj/ROArE41gEnNPOxO/+VuKhn/Tg2MPE7 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Hi Michael, On 28/06/2024 01:58, Michael Schmitz wrote: > Jean-Michel, > > Am 28.06.2024 um 00:36 schrieb Jean-Michel Hautbois: >>>>  ./scripts/decode_stacktrace.sh vmlinux < /tmp/trace.log >>>> [    3.857000] Run /bin/bash as init process >>>> [    3.858000]   with arguments: >>>> [    3.861000]     /bin/bash >>>> [    3.862000]   with environment: >>>> [    3.863000]     HOME=/ >>>> [    3.864000]     TERM=linux >>>> [    4.242000] do page fault: >>>> [    4.242000] regs->sr=0x2000, regs->pc=0x41366924, >>>> address=0x700b3364, 2, 41fb0000 >>>> [    4.242000] Kernel panic - not syncing: page fault error >>>> [    4.242000] CPU: 0 PID: 1 Comm: bash Not tainted >>>> 6.10.0-rc5-g927da6cf01fe-dirty #25 >>>> [    4.242000] Stack from 4186dda8: >>>> [    4.242000]         4186dda8 41423aa4 41423aa4 700b3300 00000001 >>>> 00000000 4136ee10 41423aa4 >>>> [    4.242000]         41366d7a 700b3364 700b3364 00000000 0000000d >>>> 4186de60 41fb0000 41d51a60 >>>> [    4.242000]         41005696 41416a90 41416a4d 00002000 41366924 >>>> 700b3364 00000002 41fb0000 >>>> [    4.242000]         0000000a 700b3364 00000000 0000000d 00000012 >>>> 41d51a00 4186de60 41d51a60 >>>> [    4.242000]         41fb81c0 41d51a60 410052fe 4100529a 4186de60 >>>> 700b3364 00000002 00000000 >>>> [    4.242000]         700bc414 00000003 00008000 700ac000 41003660 >>>> 4186de60 00000000 00000000 >>>> [    4.242000] Call Trace: dump_stack (lib/dump_stack.c:124) >>>> [    4.242000] panic (kernel/panic.c:266 kernel/panic.c:368) >>>> [    4.242000] do_page_fault (arch/m68k/mm/fault.c:88 (discriminator >>>> 1)) >>>> [    4.242000] __clear_user (arch/m68k/lib/uaccess.c:108) >>>> [    4.242000] buserr_c (arch/m68k/kernel/traps.c:725 >>>> arch/m68k/kernel/traps.c:775) >>>> [    4.242000] buserr_c (arch/m68k/kernel/traps.c:748 >>>> arch/m68k/kernel/traps.c:775) >>>> [    4.242000] buserr (arch/m68k/kernel/entry.S:116) >>>> [    4.242000] ma_slots (lib/maple_tree.c:759) >>>> [    4.242000] __clear_user (arch/m68k/lib/uaccess.c:108) >>>> [    4.242000] elf_load (fs/binfmt_elf.c:125 (discriminator 1) >>>> fs/binfmt_elf.c:421 (discriminator 1)) >>>> [    4.242000] load_elf_binary (fs/binfmt_elf.c:1132) >>>> [    4.242000] memset (arch/m68k/lib/memset.c:11) >>>> [    4.242000] load_misc_binary (fs/binfmt_misc.c:97 >>>> fs/binfmt_misc.c:146 fs/binfmt_misc.c:213) >>>> [    4.242000] memset (arch/m68k/lib/memset.c:11) >>>> [    4.242000] bprm_execve (fs/exec.c:1797 fs/exec.c:1839 >>>> fs/exec.c:1891 fs/exec.c:1867) >>>> [    4.242000] copy_strings_kernel (fs/exec.c:669) >>>> [    4.242000] count_strings_kernel (fs/exec.c:473) >>>> [    4.242000] kernel_execve (fs/exec.c:2058) >>>> [    4.242000] __dynamic_pr_debug (lib/dynamic_debug.c:865) >>>> [    4.242000] run_init_process (init/main.c:1389) >>>> [    4.242000] _printk (kernel/printk/printk.c:2365) >>>> [    4.242000] kernel_init (init/main.c:1508) >>>> [    4.242000] kernel_init (init/main.c:1459) >>>> [    4.242000] ret_from_kernel_thread (arch/m68k/kernel/entry.S:142) >>>> [    4.242000] >>>> [    4.242000] ---[ end Kernel panic - not syncing: page fault error >>>> ]--- >>>> >>>> Looks like a memory mapping failure, but why ? >>>> My JTAG at this point dumps a list of 0s at 0x41fb0000 and my SDRAM >>>> starts at 0x40000000 and ends at 0x50000000 (256MB). >>> 0x41fb0000 seems to be init's page directory. The fault address is in >>> the range where I'd expect dynamic libraries to reside. >>>> >>>> It looks like a TLB write miss which is obscure to me :-). >>>> >>>> I tried to use the /proc but as expected it is not alive after >>>> mounting it. >>> >>> The memory map ought to be accessible through sysrq - an alternative >>> would be to modify the ELF binfmt handler and dump the map once ld.so >>> has finished with relocations. >> >> I added a dump in the binfmt_elf file: >> diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c >> index a43897b03ce9..395f556f3a90 100644 >> --- a/fs/binfmt_elf.c >> +++ b/fs/binfmt_elf.c >> @@ -816,6 +816,63 @@ static int parse_elf_properties(struct file *f, >> const struct elf_phdr *phdr, >>         return ret == -ENOENT ? 0 : ret; >>  } >> >> +static int dump_memory_map(struct task_struct *task) >> +{ >> +    struct mm_struct *mm = task->mm; >> +    struct vm_area_struct *vma; >> +       MA_STATE(mas, &mm->mm_mt, 0, -1); >> +    struct file *file; >> +    struct path *path; >> +    char *buf; >> +    char *pathname; >> + >> +    // Acquire the read lock for mmap_lock >> +    down_read(&mm->mmap_lock); >> +       mas_lock(&mas); >> +    for (vma = mas_find(&mas, ULONG_MAX); vma; vma = mas_find(&mas, >> ULONG_MAX)) { >> +        if (vma->vm_file) { >> +            buf = (char *)__get_free_page(GFP_KERNEL); >> +            if (!buf) { >> +                continue; // Handle memory allocation failure >> +            } >> + >> +            file = vma->vm_file; >> +            path = &file->f_path; >> +            pathname = d_path(path, buf, PAGE_SIZE); >> +            if (IS_ERR(pathname)) { >> +                pathname = NULL; >> +            } >> + >> +            pr_info("%lx-%lx %c%c%c%c %08lx %02x:%02x %lu %s\n", >> +                vma->vm_start, vma->vm_end, >> +                vma->vm_flags & VM_READ ? 'r' : '-', >> +                vma->vm_flags & VM_WRITE ? 'w' : '-', >> +                vma->vm_flags & VM_EXEC ? 'x' : '-', >> +                vma->vm_flags & VM_MAYSHARE ? 's' : 'p', >> +                vma->vm_pgoff << PAGE_SHIFT, >> +                MAJOR(file->f_inode->i_rdev), >> +                MINOR(file->f_inode->i_rdev), >> +                file->f_inode->i_ino, >> +                pathname ? pathname : ""); >> + >> +            free_page((unsigned long)buf); >> +        } else { >> +            pr_info("%lx-%lx %c%c%c%c %08lx 00:00 0\n", >> +                vma->vm_start, vma->vm_end, >> +                vma->vm_flags & VM_READ ? 'r' : '-', >> +                vma->vm_flags & VM_WRITE ? 'w' : '-', >> +                vma->vm_flags & VM_EXEC ? 'x' : '-', >> +                vma->vm_flags & VM_MAYSHARE ? 's' : 'p', >> +                vma->vm_pgoff << PAGE_SHIFT); >> +        } >> +    } >> +       mas_unlock(&mas); >> +    // Release the read lock for mmap_lock >> +    up_read(&mm->mmap_lock); >> + >> +    return 0; >> +} >> + >>  static int load_elf_binary(struct linux_binprm *bprm) >>  { >>         struct file *interpreter = NULL; /* to shut gcc up */ >> @@ -1299,6 +1356,9 @@ static int load_elf_binary(struct linux_binprm >> *bprm) >> >>         finalize_exec(bprm); >>         START_THREAD(elf_ex, regs, elf_entry, bprm->p); >> +       if (current->pid == 1) {  // Check if this is the init process >> +            dump_memory_map(current); >> +    } >>         retval = 0; >>  out: >>         return retval; >> >> I think it is quick and dirty, but seems to do the trick. >> I then get in my console: >> [    4.265000] 60000000-6001e000 r-xp 00000000 00:00 178 /lib/ld.so.1 >> [    4.266000] 6001e000-60022000 rw-p 0001c000 00:00 178 /lib/ld.so.1 >> [    4.267000] 70000000-700ac000 r-xp 00000000 00:00 27 /bin/bash >> [    4.268000] 700ac000-700b4000 rw-p 000ac000 00:00 27 /bin/bash >> [    4.269000] 700b4000-700be000 rwxp 700b4000 00:00 0 >> [    4.270000] bfe7a000-bfe9c000 rw-p bffde000 00:00 0 >> >> But nothing rings a bell at this level for me... > > You are again using bash as init process, so the process of interest > (/bin/ls) is a child of init and does not get logged here. > > But we are getting some mapping information at last. No shared libraries > mapped as yet, but that's the same in Greg's dump. > > Comparing with what I get from cat /proc/1/maps on a 030 system., the > rwxp section at 0x700b4000 is the process heap, and the rwp section at > 0xbfe7a000 is the process stack. > > I forgot to take into account that libraries are loaded only the binary > starts executing. Can you print the same map dump in the exit syscall > code path? That ought to show all loaded libraries at that point. Thanks for your suggestion ! I changed it a bit, and I added a call in do_exit() as suggested. When executing ls I get: bash-5.2# ls -l load_elf_binary: Dump memory for ls (31): mmap: 60000000-6001e000 r-xp 00000000 00:00 178 /lib/ld.so.1 mmap: 6001e000-60022000 rw-p 0001c000 00:00 178 /lib/ld.so.1 mmap: 70000000-700c2000 r-xp 00000000 00:00 28 /bin/busybox mmap: 700c2000-700ca000 rw-p 000c0000 00:00 28 /bin/busybox mmap: bfc1e000-bfc40000 rw-p bffde000 00:00 0 [stack] do_exit: Dump memory for ls (31): mmap: 60000000-6001e000 r-xp 00000000 00:00 178 /lib/ld.so.1 mmap: 6001e000-60020000 r--p 0001c000 00:00 178 /lib/ld.so.1 mmap: 60020000-60022000 rw-p 0001e000 00:00 178 /lib/ld.so.1 mmap: 60022000-6002c000 r-xp 00000000 00:00 193 /lib/libresolv.so.2 mmap: 6002c000-6002e000 r--p 00008000 00:00 193 /lib/libresolv.so.2 mmap: 6002e000-60030000 rw-p 0000a000 00:00 193 /lib/libresolv.so.2 mmap: 60030000-60032000 rw-p 60030000 00:00 0 mmap: 60032000-6015a000 r-xp 00000000 00:00 185 /lib/libc.so.6 mmap: 6015a000-6015c000 r--p 00126000 00:00 185 /lib/libc.so.6 mmap: 6015c000-60160000 rw-p 00128000 00:00 185 /lib/libc.so.6 mmap: 60160000-6016e000 rw-p 60160000 00:00 0 mmap: 70000000-700c2000 r-xp 00000000 00:00 28 /bin/busybox mmap: 700c2000-700c4000 r--p 000c0000 00:00 28 /bin/busybox mmap: 700c4000-700ca000 rw-p 000c2000 00:00 28 /bin/busybox mmap: 700ca000-700ec000 rwxp 700ca000 00:00 0 [heap] mmap: bfc1e000-bfc40000 rw-p bffde000 00:00 0 [stack] When I call it a second time, I get: bash-5.2# ls -l load_elf_binary: Dump memory for ls (33): mmap: 60000000-6001e000 r-xp 00000000 00:00 178 /lib/ld.so.1 mmap: 6001e000-60022000 rw-p 0001c000 00:00 178 /lib/ld.so.1 mmap: 70000000-700c2000 r-xp 00000000 00:00 28 /bin/busybox mmap: 700c2000-700ca000 rw-p 000c0000 00:00 28 /bin/busybox mmap: bfb5a000-bfb7c000 rw-p bffde000 00:00 0 [stack] do_exit: Dump memory for ls (33): mmap: 60000000-6001e000 r-xp 00000000 00:00 178 /lib/ld.so.1 mmap: 6001e000-60020000 r--p 0001c000 00:00 178 /lib/ld.so.1 mmap: 60020000-60022000 rw-p 0001e000 00:00 178 /lib/ld.so.1 mmap: 60022000-6002c000 r-xp 00000000 00:00 193 /lib/libresolv.so.2 mmap: 6002c000-6002e000 r--p 00008000 00:00 193 /lib/libresolv.so.2 mmap: 6002e000-60030000 rw-p 0000a000 00:00 193 /lib/libresolv.so.2 mmap: 60030000-60032000 rw-p 60030000 00:00 0 mmap: 60032000-6015a000 r-xp 00000000 00:00 185 /lib/libc.so.6 mmap: 6015a000-6015c000 r--p 00126000 00:00 185 /lib/libc.so.6 mmap: 6015c000-60160000 rw-p 00128000 00:00 185 /lib/libc.so.6 mmap: 60160000-6016e000 rw-p 60160000 00:00 0 mmap: 70000000-700c2000 r-xp 00000000 00:00 28 /bin/busybox mmap: 700c2000-700c4000 r--p 000c0000 00:00 28 /bin/busybox mmap: 700c4000-700ca000 rw-p 000c2000 00:00 28 /bin/busybox mmap: bfb5a000-bfb7c000 rw-p bffde000 00:00 0 [stack] The first call generates the "ls" output, not the second one. The helper looks like: diff --git a/mm/mmap.c b/mm/mmap.c index 83b4682ec85c..14d861e9cba2 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -76,6 +76,87 @@ int mmap_rnd_compat_bits __read_mostly = CONFIG_ARCH_MMAP_RND_COMPAT_BITS; static bool ignore_rlimit_data; core_param(ignore_rlimit_data, ignore_rlimit_data, bool, 0644); +int dump_memory_map(struct task_struct *task) +{ + struct mm_struct *mm = task->mm; + struct vm_area_struct *vma; + struct file *file; + struct path *path; + char *buf; + char *pathname; + + if (!mm) { + return -ENOMEM; + } + + MA_STATE(mas, &mm->mm_mt, 0, -1); + // Acquire the read lock for mmap_lock + down_read(&mm->mmap_lock); + mas_lock(&mas); + for (vma = mas_find(&mas, ULONG_MAX); vma; vma = mas_find(&mas, ULONG_MAX)) { + char perms[5] = "---p"; // Default permissions + // Set permissions based on vm_flags + if (vma->vm_flags & VM_READ) perms[0] = 'r'; + if (vma->vm_flags & VM_WRITE) perms[1] = 'w'; + if (vma->vm_flags & VM_EXEC) perms[2] = 'x'; + if (vma->vm_flags & VM_MAYSHARE) perms[3] = 's'; + + if (vma->vm_file) { // If there's an associated file + buf = (char *)__get_free_page(GFP_KERNEL); + if (!buf) { + continue; // Handle memory allocation failure + } + + file = vma->vm_file; + path = &file->f_path; + pathname = d_path(path, buf, PAGE_SIZE); + if (IS_ERR(pathname)) { + pathname = NULL; + } + + // Print memory area information with file path + pr_info("%08lx-%08lx %s %08lx %02x:%02x %lu %s\n", + vma->vm_start, vma->vm_end, + perms, + vma->vm_pgoff << PAGE_SHIFT, + MAJOR(file_inode(file)->i_rdev), + MINOR(file_inode(file)->i_rdev), + file_inode(file)->i_ino, + pathname ? pathname : ""); + + free_page((unsigned long)buf); + } else { + char *special_area_name = NULL; + + // Check for heap + if (vma->vm_end > mm->start_brk && vma->vm_start < mm->brk) { + special_area_name = "[heap]"; + } + // Check for stack + else if (vma->vm_start <= mm->start_stack && vma->vm_end >= mm->start_stack) { + special_area_name = "[stack]"; + } + // Check for vdso + else if (vma->vm_flags & VM_EXEC && vma->vm_flags & VM_READ && !vma->vm_file) { + special_area_name = "[vdso]"; + } + + // Print memory area information without file path + pr_info("%08lx-%08lx %s %08lx 00:00 0 %s\n", + vma->vm_start, vma->vm_end, + perms, + vma->vm_pgoff << PAGE_SHIFT, + special_area_name ? special_area_name : " "); + } + } + mas_unlock(&mas); + // Release the read lock for mmap_lock + up_read(&mm->mmap_lock); + + return 0; +} +EXPORT_SYMBOL(dump_memory_map); Thanks, JM