Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp869527rwd; Thu, 15 Jun 2023 03:17:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ42nT/NNYl/COt5D3b/pHJhBJQaSEfW+MNOiJ5jF8JxpZb+YFKYW97vYiHTWng4qP2lukHA X-Received: by 2002:a17:907:3d88:b0:982:91a0:2353 with SMTP id he8-20020a1709073d8800b0098291a02353mr2335599ejc.35.1686824254945; Thu, 15 Jun 2023 03:17:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686824254; cv=none; d=google.com; s=arc-20160816; b=MpXqEqK1V7km3D+hTSkBZfRYhmlLJQXTX1LMrYT9Vu4mBHxMBnZvdLeaJ0kzkhuFj6 pwDPSFxlSSJYvHNJ7c3nMm8wuuQKFk6iyg8V0lmyTbR14qzWi5wBJoveHPc9Fu6mIugk B/4Y6tThpVb97yXQYsmjo5ya6KnP78Ck9tctk9qVYsYvhDWpR4FC6oeUHo5axR9NhBUD A9u8CJOlVDHXHlhciB+SOhqWiNRvtRWh6m9zeWCQ/NS2P3qmteNj+2CUzao6pjLEtWeW a/TxdU7gTEkC5fn98A1weaUokDtzh2PQ4GXmqCj4o6p8jaSvzx94vZ6Su3P/BCcTR3+j uBvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id; bh=vvqvHLz13jX/WJyiaQ0pA/7BwSAi14/NuTWH+7pE1MU=; b=Z+jKDaz8VaCmQl/n382hsjvGqjHWCWON7MMXtEgEK554eu5eX/egU1BN4dvWVlYrK3 l+3XAVRemh9W/mqEVBEY6uSfW9APHdVPs8w4FN0MXEJMGyM2Mm+zTAsjd2jTIBNLMp0N LnKYjGa9Clznh1CrIuPLDXhhJIvj/gZdizQ82eStlmA6o+Sx0bwpvReDXT5CBZAhliMd K5IPeDrMl5Eu4mRlJEF3ngRbg09UUahrDiUGyJUCqdISioxMe8dBNPp3DlgoZP3vf5I9 gXPaqP6eMfMiNkr8a6CqnIi1yH8RB+QpERBOFWPYkGt0cUL1cMExhotl9HlLE+DKLmHs uBtA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f9-20020aa7d849000000b00518f3db77b4si1630516eds.91.2023.06.15.03.17.10; Thu, 15 Jun 2023 03:17:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244999AbjFOJtR (ORCPT + 99 others); Thu, 15 Jun 2023 05:49:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238910AbjFOJtQ (ORCPT ); Thu, 15 Jun 2023 05:49:16 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12EE51A3; Thu, 15 Jun 2023 02:49:14 -0700 (PDT) Received: from dggpemm500016.china.huawei.com (unknown [172.30.72.54]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4Qhcs36BWrzLmp5; Thu, 15 Jun 2023 17:47:19 +0800 (CST) Received: from [10.67.108.26] (10.67.108.26) by dggpemm500016.china.huawei.com (7.185.36.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Thu, 15 Jun 2023 17:49:10 +0800 Message-ID: <852b8777-3c6e-f76b-0413-1c66629f33cd@huawei.com> Date: Thu, 15 Jun 2023 17:49:10 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Subject: Re: [PATCH -next v5 1/2] riscv: kdump: Implement crashkernel=X,[high,low] To: Baoquan He CC: , , , , , , , , , , , , , , References: <20230511085139.1039088-1-chenjiahao16@huawei.com> <20230511085139.1039088-2-chenjiahao16@huawei.com> Content-Language: en-US From: "chenjiahao (C)" In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.108.26] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm500016.china.huawei.com (7.185.36.25) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > >> 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 >>