[Pdbg] [RFC] main: Implement 'dmesg' command
Balbir Singh
bsingharora at gmail.com
Fri May 25 14:21:09 AEST 2018
On Fri, 25 May 2018 12:53:04 +0930
Joel Stanley <joel at jms.id.au> wrote:
> This command fetches the linux kernel log from host RAM and displays it
> on stdout.
>
> Almost any powernv kernel will support this. However it requires a
> skiboot change in order to find the location of the kernel log buffer.
> On systems without that change this command will return a message saying
> it is unsupported.
>
> Signed-off-by: Joel Stanley <joel at jms.id.au>
> ---
> The guts of the log parsing comes from benh's kmsg_dump.c.
>
> The skiboot change has not been merged yet:
>
> http://patchwork.ozlabs.org/patch/919508/
>
> More importantly, this doesn't currently work, as we cannot read the
> memory region that log_buf points to. Jump to the end of this essay to
> see the error.
>
> __log_buf[] is a statically allocated buffer that the kernel uses for
> it's messages. However, we refer to it using the pointer log_buf, as the
> kernel may chose to reallocate the buffer.
>
> kernel/printk/printk.c:
>
> static char __log_buf[__LOG_BUF_LEN] __aligned(LOG_ALIGN);
> static char *log_buf = __log_buf;
> static u32 log_buf_len = __LOG_BUF_LEN;
>
> /* Return log buffer address */
> char *log_buf_addr_get(void)
> {
> return log_buf;
> }
>
> ...
>
> if (early) {
> new_log_buf =
> memblock_virt_alloc(new_log_buf_len, LOG_ALIGN);
> } else {
> new_log_buf = memblock_virt_alloc_nopanic(new_log_buf_len,
> LOG_ALIGN);
> }
>
> The value gets retrieved via log_buf_addr_get in the powernv platform
> code, and sent to skiboot via the opal_register_dump_region OPAL call.
>
> arch/powerpc/platforms/powernv/opal.c
>
> addr = log_buf_addr_get();
> if (addr == NULL)
> return;
> ...
>
> rc = opal_register_dump_region(OPAL_DUMP_REGION_LOG_BUF,
> __pa(addr), size);
>
> Skiboot sticks this in the debug descriptor:
>
> core/dump-region.c
>
> static int64_t bmc_opal_register_dump_region(uint32_t id,
> uint64_t addr, uint64_t size)
> {
> ...
> prlog(PR_INFO, "Registered log buf at 0x%016llx\n", addr);
> debug_descriptor.log_buf_phys = addr;
>
> Looking at the host's kallsyms, we can see where __log_buf starts. If we
> hardcode that as the address to read from in pdbg, we can get data out:
>
Let's not hardcode, please. Have you tried this with CONFIG_RELOCATABLE
and CONFIG_RELOCATABLE_TEST set?
Balbir Singh.
More information about the Pdbg
mailing list