From: Jinjie Ruan <ruanjinjie@huawei.com>
To: Mike Rapoport <rppt@kernel.org>
Cc: <linux@armlinux.org.uk>, <paul.walmsley@sifive.com>,
<palmer@dabbelt.com>, <aou@eecs.berkeley.edu>,
<tglx@linutronix.de>, <mingo@redhat.com>, <bp@alien8.de>,
<dave.hansen@linux.intel.com>, <hpa@zytor.com>, <arnd@arndb.de>,
<gregkh@linuxfoundation.org>, <deller@gmx.de>,
<javierm@redhat.com>, <bhe@redhat.com>, <robh@kernel.org>,
<alexghiti@rivosinc.com>, <bjorn@rivosinc.com>,
<akpm@linux-foundation.org>, <namcao@linutronix.de>,
<dawei.li@shingroup.cn>, <chenjiahao16@huawei.com>,
<julian.stecklina@cyberus-technology.de>,
<rafael.j.wysocki@intel.com>,
<linux-arm-kernel@lists.infradead.org>,
<linux-riscv@lists.infradead.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v4 3/3] riscv: kdump: Fix crash memory reserve exceed system memory bug
Date: Mon, 22 Jul 2024 15:08:29 +0800 [thread overview]
Message-ID: <5816d4d5-e038-c90b-5ac2-1a3b3a8b9e46@huawei.com> (raw)
In-Reply-To: <Zp3-dZHhN7LbMggc@kernel.org>
On 2024/7/22 14:38, Mike Rapoport wrote:
> Hi,
>
> On Mon, Jul 22, 2024 at 11:57:01AM +0800, Jinjie Ruan wrote:
>> Similar with x86_32, on Riscv32 Qemu "virt" machine with 1GB memory, the
>> crash kernel "crashkernel=4G" is ok as below:
>> crashkernel reserved: 0x00000000bf400000 - 0x00000001bf400000 (4096 MB)
>>
>> The cause is that the crash_size is parsed and printed with "unsigned long
>> long" data type which is 8 bytes but allocated used with "phys_addr_t"
>> which is 4 bytes in memblock_phys_alloc_range().
>>
>> Fix it by checking if the crash_size is greater than system RAM size and
>> warn out as parse_crashkernel_mem() do it if so.
>>
>> After this patch, it fails and there is no above confusing reserve
>> success info.
>>
>> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
>> ---
>> arch/riscv/mm/init.c | 5 +++++
>> 1 file changed, 5 insertions(+)
>>
>> diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
>> index bfa2dea95354..5d66a4937fcd 100644
>> --- a/arch/riscv/mm/init.c
>> +++ b/arch/riscv/mm/init.c
>> @@ -1381,6 +1381,11 @@ static void __init arch_reserve_crashkernel(void)
>> if (ret)
>> return;
>>
>> + if (crash_size >= memblock_phys_mem_size()) {
>> + pr_warn("Crashkernel: invalid size.");
>> + return;
>> + }
>> +
>
> What the point of adding three identical checks right after the call to
> parse_crashkernel()?
>
> This check should be there and parse_crashkernel() should return error in
> this case.
Hi, Mike
How about the folling rough patch?
--- a/kernel/crash_reserve.c
+++ b/kernel/crash_reserve.c
@@ -313,7 +313,7 @@ int __init parse_crashkernel(char *cmdline,
if (high && ret == -ENOENT) {
ret = __parse_crashkernel(cmdline, 0, crash_size,
crash_base, suffix_tbl[SUFFIX_HIGH]);
- if (ret || !*crash_size)
+ if (ret || !*crash_size || crash_size >= system_ram)
return -EINVAL;
/*
@@ -332,7 +332,7 @@ int __init parse_crashkernel(char *cmdline,
*high = true;
}
#endif
- if (!*crash_size)
+ if (!*crash_size || crash_size >= system_ram)
ret = -EINVAL;
>
>> reserve_crashkernel_generic(cmdline, crash_size, crash_base,
>> low_size, high);
>> }
>> --
>> 2.34.1
>>
>
next prev parent reply other threads:[~2024-07-22 7:08 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-22 3:56 [PATCH v4 0/3] crash: " Jinjie Ruan
2024-07-22 3:56 ` [PATCH v4 1/3] x86/kexec: " Jinjie Ruan
2024-07-22 3:57 ` [PATCH v4 2/3] ARM: " Jinjie Ruan
2024-07-29 11:14 ` Russell King (Oracle)
2024-07-22 3:57 ` [PATCH v4 3/3] riscv: kdump: " Jinjie Ruan
2024-07-22 6:38 ` Mike Rapoport
2024-07-22 7:04 ` Jinjie Ruan
2024-07-22 7:08 ` Jinjie Ruan [this message]
2024-07-22 7:23 ` Mike Rapoport
2024-07-22 7:49 ` Jinjie Ruan
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=5816d4d5-e038-c90b-5ac2-1a3b3a8b9e46@huawei.com \
--to=ruanjinjie@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=alexghiti@rivosinc.com \
--cc=aou@eecs.berkeley.edu \
--cc=arnd@arndb.de \
--cc=bhe@redhat.com \
--cc=bjorn@rivosinc.com \
--cc=bp@alien8.de \
--cc=chenjiahao16@huawei.com \
--cc=dave.hansen@linux.intel.com \
--cc=dawei.li@shingroup.cn \
--cc=deller@gmx.de \
--cc=gregkh@linuxfoundation.org \
--cc=hpa@zytor.com \
--cc=javierm@redhat.com \
--cc=julian.stecklina@cyberus-technology.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=linux@armlinux.org.uk \
--cc=mingo@redhat.com \
--cc=namcao@linutronix.de \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=rafael.j.wysocki@intel.com \
--cc=robh@kernel.org \
--cc=rppt@kernel.org \
--cc=tglx@linutronix.de \
/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
all inboxes | Powered by JetHome®