From: "HAGIO KAZUHITO(萩尾 一仁)" <k-hagio-ab@nec.com>
To: Song Shuai <suagrfillet@gmail.com>
Cc: "linux-riscv@lists.infradead.org"
<linux-riscv@lists.infradead.org>,
"kexec@lists.infradead.org" <kexec@lists.infradead.org>,
"crash-utility@redhat.com" <crash-utility@redhat.com>,
"xianting.tian@linux.alibaba.com"
<xianting.tian@linux.alibaba.com>,
"mick@ics.forth.gr" <mick@ics.forth.gr>,
"heinrich.schuchardt@canonical.com"
<heinrich.schuchardt@canonical.com>,
"guoren@kernel.org" <guoren@kernel.org>,
"yixun.lan@gmail.com" <yixun.lan@gmail.com>,
"lijiang@redhat.com" <lijiang@redhat.com>
Subject: Re: [Crash-utility] RISCV64: Use va_kernel_pa_offset in VTOP()
Date: Fri, 4 Aug 2023 04:42:35 +0000 [thread overview]
Message-ID: <378ea919-5149-fb1a-02ec-3c0b41ebecc3@nec.com> (raw)
In-Reply-To: <20230724040649.220279-1-suagrfillet@gmail.com>
On 2023/07/24 13:06, Song Shuai wrote:
> Since RISC-V Linux v6.4, the commit 3335068f8721 ("riscv: Use
> PUD/P4D/PGD pages for the linear mapping") changes the
> phys_ram_base from the kernel_map.phys_addr to the start of DRAM.
>
> The Crash's VTOP() still uses phys_ram_base and kernel_map.virt_addr
> to translate kernel virtual address, that made Crash boot failed with
> Linux v6.4 and later version.
>
> Let Linux export kernel_map.va_kernel_pa_offset in v6.5 and Crash can
> use "va_kernel_pa_offset" to translate the kernel virtual address in
> VTOP() correctly.
>
> Signed-off-by: Song Shuai <suagrfillet@gmail.com>
> ---
> You can check/test the Linux changes from this link:
> https://github.com/sugarfillet/linux/commits/6.5-rc3-crash
>
> And I'll send the Linux changes to riscv/for-next If you're ok with this patch.
> ---
> defs.h | 4 ++--
> riscv64.c | 22 ++++++++++++++++++++++
> 2 files changed, 24 insertions(+), 2 deletions(-)
>
> diff --git a/defs.h b/defs.h
> index 358f365..46b9857 100644
> --- a/defs.h
> +++ b/defs.h
> @@ -3662,8 +3662,7 @@ typedef signed int s32;
> ulong _X = X; \
> (THIS_KERNEL_VERSION >= LINUX(5,13,0) && \
> (_X) >= machdep->machspec->kernel_link_addr) ? \
> - (((unsigned long)(_X)-(machdep->machspec->kernel_link_addr)) + \
> - machdep->machspec->phys_base): \
> + ((unsigned long)(_X)-(machdep->machspec->va_kernel_pa_offset)): \
> (((unsigned long)(_X)-(machdep->kvbase)) + \
> machdep->machspec->phys_base); \
> })
> @@ -7021,6 +7020,7 @@ struct machine_specific {
> ulong modules_vaddr;
> ulong modules_end;
> ulong kernel_link_addr;
> + ulong va_kernel_pa_offset;
>
> ulong _page_present;
> ulong _page_read;
> diff --git a/riscv64.c b/riscv64.c
> index 6b9a688..b9e50b4 100644
> --- a/riscv64.c
> +++ b/riscv64.c
> @@ -418,6 +418,27 @@ error:
> error(FATAL, "cannot get vm layout\n");
> }
>
> +static void
> +riscv64_get_va_kernel_pa_offset(struct machine_specific *ms)
> +{
> + unsigned long kernel_version = riscv64_get_kernel_version();
> +
> + /*
> + * va_kernel_pa_offset is defined in Linux kernel since 6.5.
> + */
> + if (kernel_version >= LINUX(6,5,0)) {
The kernel patches look accepted, so for the crash patch detail,
I think this first version check is not necessary, we can just use the
vmcoreinfo entry if available. With it, backporting the kernel patches
to e.g. 6.4.0 will also be supported.
Thanks,
Kazu
> + char *string;
> + if ((string = pc->read_vmcoreinfo("NUMBER(va_kernel_pa_offset)"))) {
> + ms->va_kernel_pa_offset = htol(string, QUIET, NULL);
> + free(string);
> + } else
> + error(FATAL, "cannot read va_kernel_pa_offset\n");
> + } else if (kernel_version >= LINUX(6,4,0))
> + error(FATAL, "cannot determine va_kernel_pa_offset since Linux 6.4\n");
> + else
> + ms->va_kernel_pa_offset = ms->kernel_link_addr - ms->phys_base;
> +}
> +
> static int
> riscv64_is_kvaddr(ulong vaddr)
> {
> @@ -1352,6 +1373,7 @@ riscv64_init(int when)
> riscv64_get_struct_page_size(machdep->machspec);
> riscv64_get_va_bits(machdep->machspec);
> riscv64_get_va_range(machdep->machspec);
> + riscv64_get_va_kernel_pa_offset(machdep->machspec);
>
> pt_level_alloc(&machdep->pgd, "cannot malloc pgd space.");
> pt_level_alloc(&machdep->machspec->p4d, "cannot malloc p4d space.");
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
next prev parent reply other threads:[~2023-08-04 4:43 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-24 4:06 [Crash-utility] RISCV64: Use va_kernel_pa_offset in VTOP() Song Shuai
2023-07-24 7:41 ` Conor Dooley
2023-07-24 8:44 ` Song Shuai
2023-07-24 9:22 ` HAGIO KAZUHITO(萩尾 一仁)
2023-07-24 8:13 ` Alexandre Ghiti
2023-07-24 8:48 ` Song Shuai
2023-08-04 4:42 ` HAGIO KAZUHITO(萩尾 一仁) [this message]
2023-08-04 9:20 ` Song Shuai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=378ea919-5149-fb1a-02ec-3c0b41ebecc3@nec.com \
--to=k-hagio-ab@nec.com \
--cc=crash-utility@redhat.com \
--cc=guoren@kernel.org \
--cc=heinrich.schuchardt@canonical.com \
--cc=kexec@lists.infradead.org \
--cc=lijiang@redhat.com \
--cc=linux-riscv@lists.infradead.org \
--cc=mick@ics.forth.gr \
--cc=suagrfillet@gmail.com \
--cc=xianting.tian@linux.alibaba.com \
--cc=yixun.lan@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox