RFC: /proc/kcore

Russell King (rmk@arm.linux.org.uk)
Mon, 11 Mar 2002 20:00:41 +0000


A short while ago, I cooked up the following for the ARM architecture
to allow /proc/kcore to work. I suspect it needs to be extended to all
architectures however; comments from all other architecture maintainers
are welcome.

In the ELF headers, we supply the following information for the kernels
memory space:

phdr->p_type = PT_LOAD;
phdr->p_flags = PF_R|PF_W|PF_X;
phdr->p_offset = dataoff;
phdr->p_vaddr = PAGE_OFFSET;
phdr->p_paddr = __pa(PAGE_OFFSET);
phdr->p_filesz = phdr->p_memsz = ((unsigned long)high_memory - PAGE_OFFSET);
phdr->p_align = PAGE_SIZE;

So, when we access file offset 'dataoff' we expect the bytes starting
at virtual memory address 'PAGE_OFFSET' (or physical address
__pa(PAGE_OFFSET)).

'dataoff' comes from get_kcore_size, and is the same as the elf_buflen
you see in the patch below, and is the first byte of non-header
information.

With a file offset of 'elf_buflen', the original code does:

start = __va(0)

and the only way this will return the byte at PAGE_OFFSET is if __va
is defined as (PAGE_OFFSET + (x)). However, a machine where the RAM
does not start at physical address zero, this will not be the case.

I therefore expect that the code I have below for ARM should be used
for all architectures.

I'd like other people to confirm. If I don't hear anything, I'll
generate such a patch, and forward it to Linus, Marcelo and LKML for
inclusion in the next kernel releases.

--- orig/fs/proc/kcore.c Mon Oct 1 23:11:24 2001
+++ linux/fs/proc/kcore.c Tue Jan 29 20:57:03 2002
@@ -382,7 +382,17 @@
}
#endif
/* fill the remainder of the buffer from kernel VM space */
+#ifndef __arm__
start = (unsigned long)__va(*fpos - elf_buflen);
+#else
+ /*
+ * this would appear to be more correct than the above.
+ * We said in the ELF header that the data which starts
+ * at 'elf_buflen' is virtual address PAGE_OFFSET. This
+ * is not what the above does.
+ */
+ start = PAGE_OFFSET + (*fpos - elf_buflen);
+#endif
if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
tsz = buflen;

-- 
Russell King (rmk@arm.linux.org.uk)                The developer of ARM Linux
             http://www.arm.linux.org.uk/personal/aboutme.html

- 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/