All of lore.kernel.org
 help / color / mirror / Atom feed
From: "chenjiahao (C)" <chenjiahao16@huawei.com>
To: Baoquan He <bhe@redhat.com>
Cc: <linux-kernel@vger.kernel.org>, <linux-riscv@lists.infradead.org>,
	<kexec@lists.infradead.org>, <linux-doc@vger.kernel.org>,
	<paul.walmsley@sifive.com>, <palmer@dabbelt.com>,
	<conor.dooley@microchip.com>, <guoren@kernel.org>,
	<heiko@sntech.de>, <bjorn@rivosinc.com>, <alex@ghiti.fr>,
	<akpm@linux-foundation.org>, <atishp@rivosinc.com>,
	<thunder.leizhen@huawei.com>, <horms@kernel.org>
Subject: Re: [PATCH -next v5 1/2] riscv: kdump: Implement crashkernel=X,[high,low]
Date: Sat, 1 Jul 2023 17:51:26 +0800	[thread overview]
Message-ID: <5c80666c-e6e2-8fa6-50b6-89536315925e@huawei.com> (raw)
In-Reply-To: <852b8777-3c6e-f76b-0413-1c66629f33cd@huawei.com>


On 2023/6/15 17:49, chenjiahao (C) wrote:
>
> On 2023/6/4 11:50, Baoquan He wrote:
>> Hi Jiahao,
>>
>> On 05/11/23 at 04:51pm, Chen Jiahao wrote:
>> ......
>>> @@ -1300,14 +1325,34 @@ static void __init reserve_crashkernel(void)
>>>           return;
>>>       }
>>>   -    ret = parse_crashkernel(boot_command_line, 
>>> memblock_phys_mem_size(),
>>> +    ret = parse_crashkernel(cmdline, memblock_phys_mem_size(),
>>>                   &crash_size, &crash_base);
>>> -    if (ret || !crash_size)
>>> +    if (ret == -ENOENT) {
>>> +        /* Fallback to crashkernel=X,[high,low] */
>>> +        ret = parse_crashkernel_high(cmdline, 0, &crash_size, 
>>> &crash_base);
>>> +        if (ret || !crash_size)
>>> +            return;
>>> +
>>> +        /*
>>> +         * crashkernel=Y,low is valid only when crashkernel=X,high
>>> +         * is passed.
>>> +         */
>>> +        ret = parse_crashkernel_low(cmdline, 0, &crash_low_size, 
>>> &crash_base);
>>> +        if (ret == -ENOENT)
>>> +            crash_low_size = DEFAULT_CRASH_KERNEL_LOW_SIZE;
>>> +        else if (ret)
>>> +            return;
>>> +
>>> +        search_end = memblock_end_of_DRAM();
>>> +    } else if (ret || !crash_size) {
>>> +        /* Invalid argument value specified */
>>>           return;
>>> +    }
>> The parsing part looks great, while you didn't mark if it's specified
>> high reservation, please see later comment why it's needed.
>>
>>>         crash_size = PAGE_ALIGN(crash_size);
>>>         if (crash_base) {
>>> +        fixed_base = true;
>>>           search_start = crash_base;
>>>           search_end = crash_base + crash_size;
>>>       }
>>> @@ -1320,17 +1365,31 @@ static void __init reserve_crashkernel(void)
>>>        * swiotlb can work on the crash kernel.
>>>        */
>>>       crash_base = memblock_phys_alloc_range(crash_size, PMD_SIZE,
>>> -                           search_start,
>>> -                           min(search_end, (unsigned long) SZ_4G));
>>> +                           search_start, search_end);
>> If it's a specified high reservation, you have
>> search_start = memblock_start_of_DRAM();
>> search_end = memblock_end_of_DRAM();
>>
>> Then it attempts to search top down first time here.
>>
>>>       if (crash_base == 0) {
>>> -        /* Try again without restricting region to 32bit 
>>> addressible memory */
>>> +        if (fixed_base) {
>>> +            pr_warn("crashkernel: allocating failed with given 
>>> size@offset\n");
>>> +            return;
>>> +        }
>>> +        search_end = memblock_end_of_DRAM();
>>> +
>>> +        /* Try again above the region of 32bit addressible memory */
>>>           crash_base = memblock_phys_alloc_range(crash_size, PMD_SIZE,
>>> -                        search_start, search_end);
>>> +                               search_start, search_end);
>> If crashkernel=,high case, the first attempt failed, here it assigns
>> search_end with memblock_end_of_DRAM(). It's the exactly the same
>> attempt, why is that needed? Why don't you use a local variable 'high'
>> to mark the crashkernel=,hig, then judge when deciding how to adjsut the
>> reservation range.
>>
>> Do I misunderstand the code?
>>
>> Thanks
>> Baoquan
>
> You are right. Here I use search_end = memblock_end_of_DRAM() for the
> first attempt on "crashkernel=,high" case, but it will not distinct from
> other cases if the first attempt fails.
>
> I have read your latest refactor on Arm64, introducing the "high" flag
> is a good choice, the logic gets more straightforward when handling
> crashkernel=,high case and retrying.
>
> Following that logic, here introducing and set "high" flag when parsing
> cmdline, when the first attempt failed:
>
> if fixed_base:
>     failed and return;
>
> if set high:
>     search_start = memblock_start_of_DRAM();
>     search_end = (unsigned long)dma32_phys_limit;
> else:
>     search_start = (unsigned long)dma32_phys_limit;
>     search_end = memblock_end_of_DRAM();
>
> second attempt with new {search_start, search_end}
> ...
>
> This should handle "crashkernel=,high" case correctly and avoid cross
> 4G reservation.
>
> Is that logic correct, or is any other problem missed?
>
> Thanks,
> Jiahao

I have sent v6 patches, implementing the logic above. That fixes the 
retrying

logic and should be aligned with Arm64 code.


Please let me know if there is any problem remains.


Thanks,

Jiahao


>
>>
>>>           if (crash_base == 0) {
>>>               pr_warn("crashkernel: couldn't allocate %lldKB\n",
>>>                   crash_size >> 10);
>>>               return;
>>>           }
>>> +
>>> +        if (!crash_low_size)
>>> +            crash_low_size = DEFAULT_CRASH_KERNEL_LOW_SIZE;
>>> +    }
>>> +
>>> +    if ((crash_base > dma32_phys_limit - crash_low_size) &&
>>> +        crash_low_size && reserve_crashkernel_low(crash_low_size)) {
>>> +        memblock_phys_free(crash_base, crash_size);
>>> +        return;
>>>       }
>>>         pr_info("crashkernel: reserved 0x%016llx - 0x%016llx (%lld 
>>> MB)\n",
>>> -- 
>>> 2.31.1
>>>
>
> _______________________________________________
> kexec mailing list
> kexec@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/kexec

WARNING: multiple messages have this Message-ID (diff)
From: "chenjiahao (C)" <chenjiahao16@huawei.com>
To: Baoquan He <bhe@redhat.com>
Cc: <linux-kernel@vger.kernel.org>, <linux-riscv@lists.infradead.org>,
	<kexec@lists.infradead.org>, <linux-doc@vger.kernel.org>,
	<paul.walmsley@sifive.com>, <palmer@dabbelt.com>,
	<conor.dooley@microchip.com>, <guoren@kernel.org>,
	<heiko@sntech.de>, <bjorn@rivosinc.com>, <alex@ghiti.fr>,
	<akpm@linux-foundation.org>, <atishp@rivosinc.com>,
	<thunder.leizhen@huawei.com>, <horms@kernel.org>
Subject: Re: [PATCH -next v5 1/2] riscv: kdump: Implement crashkernel=X,[high,low]
Date: Sat, 1 Jul 2023 17:51:26 +0800	[thread overview]
Message-ID: <5c80666c-e6e2-8fa6-50b6-89536315925e@huawei.com> (raw)
In-Reply-To: <852b8777-3c6e-f76b-0413-1c66629f33cd@huawei.com>


On 2023/6/15 17:49, chenjiahao (C) wrote:
>
> On 2023/6/4 11:50, Baoquan He wrote:
>> Hi Jiahao,
>>
>> On 05/11/23 at 04:51pm, Chen Jiahao wrote:
>> ......
>>> @@ -1300,14 +1325,34 @@ static void __init reserve_crashkernel(void)
>>>           return;
>>>       }
>>>   -    ret = parse_crashkernel(boot_command_line, 
>>> memblock_phys_mem_size(),
>>> +    ret = parse_crashkernel(cmdline, memblock_phys_mem_size(),
>>>                   &crash_size, &crash_base);
>>> -    if (ret || !crash_size)
>>> +    if (ret == -ENOENT) {
>>> +        /* Fallback to crashkernel=X,[high,low] */
>>> +        ret = parse_crashkernel_high(cmdline, 0, &crash_size, 
>>> &crash_base);
>>> +        if (ret || !crash_size)
>>> +            return;
>>> +
>>> +        /*
>>> +         * crashkernel=Y,low is valid only when crashkernel=X,high
>>> +         * is passed.
>>> +         */
>>> +        ret = parse_crashkernel_low(cmdline, 0, &crash_low_size, 
>>> &crash_base);
>>> +        if (ret == -ENOENT)
>>> +            crash_low_size = DEFAULT_CRASH_KERNEL_LOW_SIZE;
>>> +        else if (ret)
>>> +            return;
>>> +
>>> +        search_end = memblock_end_of_DRAM();
>>> +    } else if (ret || !crash_size) {
>>> +        /* Invalid argument value specified */
>>>           return;
>>> +    }
>> The parsing part looks great, while you didn't mark if it's specified
>> high reservation, please see later comment why it's needed.
>>
>>>         crash_size = PAGE_ALIGN(crash_size);
>>>         if (crash_base) {
>>> +        fixed_base = true;
>>>           search_start = crash_base;
>>>           search_end = crash_base + crash_size;
>>>       }
>>> @@ -1320,17 +1365,31 @@ static void __init reserve_crashkernel(void)
>>>        * swiotlb can work on the crash kernel.
>>>        */
>>>       crash_base = memblock_phys_alloc_range(crash_size, PMD_SIZE,
>>> -                           search_start,
>>> -                           min(search_end, (unsigned long) SZ_4G));
>>> +                           search_start, search_end);
>> If it's a specified high reservation, you have
>> search_start = memblock_start_of_DRAM();
>> search_end = memblock_end_of_DRAM();
>>
>> Then it attempts to search top down first time here.
>>
>>>       if (crash_base == 0) {
>>> -        /* Try again without restricting region to 32bit 
>>> addressible memory */
>>> +        if (fixed_base) {
>>> +            pr_warn("crashkernel: allocating failed with given 
>>> size@offset\n");
>>> +            return;
>>> +        }
>>> +        search_end = memblock_end_of_DRAM();
>>> +
>>> +        /* Try again above the region of 32bit addressible memory */
>>>           crash_base = memblock_phys_alloc_range(crash_size, PMD_SIZE,
>>> -                        search_start, search_end);
>>> +                               search_start, search_end);
>> If crashkernel=,high case, the first attempt failed, here it assigns
>> search_end with memblock_end_of_DRAM(). It's the exactly the same
>> attempt, why is that needed? Why don't you use a local variable 'high'
>> to mark the crashkernel=,hig, then judge when deciding how to adjsut the
>> reservation range.
>>
>> Do I misunderstand the code?
>>
>> Thanks
>> Baoquan
>
> You are right. Here I use search_end = memblock_end_of_DRAM() for the
> first attempt on "crashkernel=,high" case, but it will not distinct from
> other cases if the first attempt fails.
>
> I have read your latest refactor on Arm64, introducing the "high" flag
> is a good choice, the logic gets more straightforward when handling
> crashkernel=,high case and retrying.
>
> Following that logic, here introducing and set "high" flag when parsing
> cmdline, when the first attempt failed:
>
> if fixed_base:
>     failed and return;
>
> if set high:
>     search_start = memblock_start_of_DRAM();
>     search_end = (unsigned long)dma32_phys_limit;
> else:
>     search_start = (unsigned long)dma32_phys_limit;
>     search_end = memblock_end_of_DRAM();
>
> second attempt with new {search_start, search_end}
> ...
>
> This should handle "crashkernel=,high" case correctly and avoid cross
> 4G reservation.
>
> Is that logic correct, or is any other problem missed?
>
> Thanks,
> Jiahao

I have sent v6 patches, implementing the logic above. That fixes the 
retrying

logic and should be aligned with Arm64 code.


Please let me know if there is any problem remains.


Thanks,

Jiahao


>
>>
>>>           if (crash_base == 0) {
>>>               pr_warn("crashkernel: couldn't allocate %lldKB\n",
>>>                   crash_size >> 10);
>>>               return;
>>>           }
>>> +
>>> +        if (!crash_low_size)
>>> +            crash_low_size = DEFAULT_CRASH_KERNEL_LOW_SIZE;
>>> +    }
>>> +
>>> +    if ((crash_base > dma32_phys_limit - crash_low_size) &&
>>> +        crash_low_size && reserve_crashkernel_low(crash_low_size)) {
>>> +        memblock_phys_free(crash_base, crash_size);
>>> +        return;
>>>       }
>>>         pr_info("crashkernel: reserved 0x%016llx - 0x%016llx (%lld 
>>> MB)\n",
>>> -- 
>>> 2.31.1
>>>
>
> _______________________________________________
> kexec mailing list
> kexec@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/kexec

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

WARNING: multiple messages have this Message-ID (diff)
From: "chenjiahao (C)" <chenjiahao16@huawei.com>
To: Baoquan He <bhe@redhat.com>
Cc: <linux-kernel@vger.kernel.org>, <linux-riscv@lists.infradead.org>,
	<kexec@lists.infradead.org>, <linux-doc@vger.kernel.org>,
	<paul.walmsley@sifive.com>, <palmer@dabbelt.com>,
	<conor.dooley@microchip.com>, <guoren@kernel.org>,
	<heiko@sntech.de>, <bjorn@rivosinc.com>, <alex@ghiti.fr>,
	<akpm@linux-foundation.org>, <atishp@rivosinc.com>,
	<thunder.leizhen@huawei.com>, <horms@kernel.org>
Subject: Re: [PATCH -next v5 1/2] riscv: kdump: Implement crashkernel=X,[high,low]
Date: Sat, 1 Jul 2023 17:51:26 +0800	[thread overview]
Message-ID: <5c80666c-e6e2-8fa6-50b6-89536315925e@huawei.com> (raw)
In-Reply-To: <852b8777-3c6e-f76b-0413-1c66629f33cd@huawei.com>


On 2023/6/15 17:49, chenjiahao (C) wrote:
>
> On 2023/6/4 11:50, Baoquan He wrote:
>> Hi Jiahao,
>>
>> On 05/11/23 at 04:51pm, Chen Jiahao wrote:
>> ......
>>> @@ -1300,14 +1325,34 @@ static void __init reserve_crashkernel(void)
>>>           return;
>>>       }
>>>   -    ret = parse_crashkernel(boot_command_line, 
>>> memblock_phys_mem_size(),
>>> +    ret = parse_crashkernel(cmdline, memblock_phys_mem_size(),
>>>                   &crash_size, &crash_base);
>>> -    if (ret || !crash_size)
>>> +    if (ret == -ENOENT) {
>>> +        /* Fallback to crashkernel=X,[high,low] */
>>> +        ret = parse_crashkernel_high(cmdline, 0, &crash_size, 
>>> &crash_base);
>>> +        if (ret || !crash_size)
>>> +            return;
>>> +
>>> +        /*
>>> +         * crashkernel=Y,low is valid only when crashkernel=X,high
>>> +         * is passed.
>>> +         */
>>> +        ret = parse_crashkernel_low(cmdline, 0, &crash_low_size, 
>>> &crash_base);
>>> +        if (ret == -ENOENT)
>>> +            crash_low_size = DEFAULT_CRASH_KERNEL_LOW_SIZE;
>>> +        else if (ret)
>>> +            return;
>>> +
>>> +        search_end = memblock_end_of_DRAM();
>>> +    } else if (ret || !crash_size) {
>>> +        /* Invalid argument value specified */
>>>           return;
>>> +    }
>> The parsing part looks great, while you didn't mark if it's specified
>> high reservation, please see later comment why it's needed.
>>
>>>         crash_size = PAGE_ALIGN(crash_size);
>>>         if (crash_base) {
>>> +        fixed_base = true;
>>>           search_start = crash_base;
>>>           search_end = crash_base + crash_size;
>>>       }
>>> @@ -1320,17 +1365,31 @@ static void __init reserve_crashkernel(void)
>>>        * swiotlb can work on the crash kernel.
>>>        */
>>>       crash_base = memblock_phys_alloc_range(crash_size, PMD_SIZE,
>>> -                           search_start,
>>> -                           min(search_end, (unsigned long) SZ_4G));
>>> +                           search_start, search_end);
>> If it's a specified high reservation, you have
>> search_start = memblock_start_of_DRAM();
>> search_end = memblock_end_of_DRAM();
>>
>> Then it attempts to search top down first time here.
>>
>>>       if (crash_base == 0) {
>>> -        /* Try again without restricting region to 32bit 
>>> addressible memory */
>>> +        if (fixed_base) {
>>> +            pr_warn("crashkernel: allocating failed with given 
>>> size@offset\n");
>>> +            return;
>>> +        }
>>> +        search_end = memblock_end_of_DRAM();
>>> +
>>> +        /* Try again above the region of 32bit addressible memory */
>>>           crash_base = memblock_phys_alloc_range(crash_size, PMD_SIZE,
>>> -                        search_start, search_end);
>>> +                               search_start, search_end);
>> If crashkernel=,high case, the first attempt failed, here it assigns
>> search_end with memblock_end_of_DRAM(). It's the exactly the same
>> attempt, why is that needed? Why don't you use a local variable 'high'
>> to mark the crashkernel=,hig, then judge when deciding how to adjsut the
>> reservation range.
>>
>> Do I misunderstand the code?
>>
>> Thanks
>> Baoquan
>
> You are right. Here I use search_end = memblock_end_of_DRAM() for the
> first attempt on "crashkernel=,high" case, but it will not distinct from
> other cases if the first attempt fails.
>
> I have read your latest refactor on Arm64, introducing the "high" flag
> is a good choice, the logic gets more straightforward when handling
> crashkernel=,high case and retrying.
>
> Following that logic, here introducing and set "high" flag when parsing
> cmdline, when the first attempt failed:
>
> if fixed_base:
>     failed and return;
>
> if set high:
>     search_start = memblock_start_of_DRAM();
>     search_end = (unsigned long)dma32_phys_limit;
> else:
>     search_start = (unsigned long)dma32_phys_limit;
>     search_end = memblock_end_of_DRAM();
>
> second attempt with new {search_start, search_end}
> ...
>
> This should handle "crashkernel=,high" case correctly and avoid cross
> 4G reservation.
>
> Is that logic correct, or is any other problem missed?
>
> Thanks,
> Jiahao

I have sent v6 patches, implementing the logic above. That fixes the 
retrying

logic and should be aligned with Arm64 code.


Please let me know if there is any problem remains.


Thanks,

Jiahao


>
>>
>>>           if (crash_base == 0) {
>>>               pr_warn("crashkernel: couldn't allocate %lldKB\n",
>>>                   crash_size >> 10);
>>>               return;
>>>           }
>>> +
>>> +        if (!crash_low_size)
>>> +            crash_low_size = DEFAULT_CRASH_KERNEL_LOW_SIZE;
>>> +    }
>>> +
>>> +    if ((crash_base > dma32_phys_limit - crash_low_size) &&
>>> +        crash_low_size && reserve_crashkernel_low(crash_low_size)) {
>>> +        memblock_phys_free(crash_base, crash_size);
>>> +        return;
>>>       }
>>>         pr_info("crashkernel: reserved 0x%016llx - 0x%016llx (%lld 
>>> MB)\n",
>>> -- 
>>> 2.31.1
>>>
>
> _______________________________________________
> kexec mailing list
> kexec@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/kexec

_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

  reply	other threads:[~2023-07-01  9:51 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-11  8:51 [PATCH -next v5 0/2] support allocating crashkernel above 4G explicitly on riscv Chen Jiahao
2023-05-11  8:51 ` Chen Jiahao
2023-05-11  8:51 ` Chen Jiahao
2023-05-11  8:51 ` [PATCH -next v5 1/2] riscv: kdump: Implement crashkernel=X,[high,low] Chen Jiahao
2023-05-11  8:51   ` Chen Jiahao
2023-05-11  8:51   ` Chen Jiahao
2023-06-04  3:50   ` Baoquan He
2023-06-04  3:50     ` Baoquan He
2023-06-04  3:50     ` Baoquan He
2023-06-15  9:49     ` chenjiahao (C)
2023-06-15  9:49       ` chenjiahao (C)
2023-06-15  9:49       ` chenjiahao (C)
2023-07-01  9:51       ` chenjiahao (C) [this message]
2023-07-01  9:51         ` chenjiahao (C)
2023-07-01  9:51         ` chenjiahao (C)
2023-07-02  4:06         ` Baoquan He
2023-07-02  4:06           ` Baoquan He
2023-07-02  4:06           ` Baoquan He
2023-07-04  3:51           ` chenjiahao (C)
2023-07-04  3:51             ` chenjiahao (C)
2023-07-04  3:51             ` chenjiahao (C)
2023-05-11  8:51 ` [PATCH -next v5 2/2] docs: kdump: Update the crashkernel description for riscv Chen Jiahao
2023-05-11  8:51   ` Chen Jiahao
2023-05-11  8:51   ` Chen Jiahao

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=5c80666c-e6e2-8fa6-50b6-89536315925e@huawei.com \
    --to=chenjiahao16@huawei.com \
    --cc=akpm@linux-foundation.org \
    --cc=alex@ghiti.fr \
    --cc=atishp@rivosinc.com \
    --cc=bhe@redhat.com \
    --cc=bjorn@rivosinc.com \
    --cc=conor.dooley@microchip.com \
    --cc=guoren@kernel.org \
    --cc=heiko@sntech.de \
    --cc=horms@kernel.org \
    --cc=kexec@lists.infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=palmer@dabbelt.com \
    --cc=paul.walmsley@sifive.com \
    --cc=thunder.leizhen@huawei.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.