Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp532033rwd; Wed, 31 May 2023 01:38:44 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4iG4i4l8/cridkoqapjgb0BbjyfwAUnA1XTRT00CtJEmTER+lCF4Rz0rV2f/2Z25aQl7Uu X-Received: by 2002:a05:6e02:803:b0:338:9bf3:467e with SMTP id u3-20020a056e02080300b003389bf3467emr2157502ilm.22.1685522324372; Wed, 31 May 2023 01:38:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685522324; cv=none; d=google.com; s=arc-20160816; b=Oh2eN5MNqoZ2Dhh+Qg4mNgAGusKbtkhkmoHpfJQQ5wJTzJINpqfmcDeVR3v+O9ceoV 3X43E8B0HzPdeEVdlSkoMFCikRo1c/cEUXP5vRIl26zDpSfTset/cQsFj2avBWVE9auv 15XzavWb30GjukC2WlAMLKTbV3z5sV9tyllidhe1K5UTP1/4R2Ik9UbgBxREaqkVtopS Z+xf9HqtPDrtf1yr6E2WhKhI0bEwXCRKR+Aqr9hHtrjtzxuhLnXaZae5iA7xuFATerzo toozlWwWOB/S8AMtJtGmVf8zFlLymYgZBB3ZucuzI3DS8VKwb0qldVomWQtCyu+xiKzn /Grg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=yeraDz9q9gOZPrNC11kDcNaCNBaiIHa0uwrxu0NvbBg=; b=tWRO+Wr+W6ZStjCLVotq8prE7zkuS49QiyuwLtcv25Xi1rLg98BfhMmtqSNPv115vL nkHRVNMxR34k6ISEDeg/GaIIissRVAQEHiNgtVYh5Z7OUbDSI+HjIOEPxpqmLpVPZH2R 4nsS/SD8DBqTbei4yTcCB9l1VbUzkZjrm3182IikKFCtadcWj/6hyEbsF/X97R8iQmyg Yeth3rTsQt4AsSdJSXUbazvOLGBO1eFYJG8CQNugsFeBiy8iUJwEGrZhpu2OylpPsDDF tLD/WYznfEt2M1e9UHPEYH/J+aGp95mfu56nUxd5d73HSbKzkX6tmW8+in6TuBgl0X0Z Qo2A== 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 a3-20020a1709027d8300b001afc602cd5esi541083plm.90.2023.05.31.01.38.32; Wed, 31 May 2023 01:38:44 -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 S234765AbjEaI1F (ORCPT + 99 others); Wed, 31 May 2023 04:27:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232156AbjEaI1A (ORCPT ); Wed, 31 May 2023 04:27:00 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49508C5 for ; Wed, 31 May 2023 01:26:58 -0700 (PDT) Received: from dggpemm500006.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4QWMgq6QC8zqTfn; Wed, 31 May 2023 16:22:15 +0800 (CST) Received: from [10.174.178.55] (10.174.178.55) by dggpemm500006.china.huawei.com (7.185.36.236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Wed, 31 May 2023 16:26:54 +0800 Subject: Re: [PATCH 2/6] kexec: delete a useless check in crash_shrink_memory() To: Baoquan He CC: Eric Biederman , , , Michael Holzheu , Andrew Morton References: <20230527123439.772-1-thunder.leizhen@huawei.com> <20230527123439.772-3-thunder.leizhen@huawei.com> <5beb1883-5391-1b75-d8cd-2152478b9e72@huawei.com> From: "Leizhen (ThunderTown)" Message-ID: Date: Wed, 31 May 2023 16:26:54 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.178.55] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500006.china.huawei.com (7.185.36.236) 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/5/31 15:41, Baoquan He wrote: > On 05/31/23 at 10:19am, Leizhen (ThunderTown) wrote: >> >> >> On 2023/5/31 8:17, Baoquan He wrote: >>> On 05/27/23 at 08:34pm, Zhen Lei wrote: >>>> The check '(crashk_res.parent != NULL)' is added by >>>> commit e05bd3367bd3 ("kexec: fix Oops in crash_shrink_memory()"), but it's >>>> stale now. Because if 'crashk_res' is not reserved, it will be zero in >>>> size and will be intercepted by the above 'if (new_size >= old_size)'. >>>> >>>> Ago: >>>> if (new_size >= end - start + 1) >>>> >>>> Now: >>>> old_size = (end == 0) ? 0 : end - start + 1; >>>> if (new_size >= old_size) >>> >>> Hmm, I would strongly suggest we keep that check. Even though the >>> current code like above can do the acutal checking, but its actual usage >>> is not obvious for checking of crashk_res existence. In the future, >>> someone may change above calculation and don't notice the hidden >>> functionality at all behind the calculation. The cost of the check is >>> almost zero, right? >> >> The cost of the check is negligible. The only downside is that it's hard to >> understand why it's added, and I only found out why by looking at the history >> log. In my opinion, the above 'Now:' is the right fix. > > It checks if the resource exists before releasing, just a normal > checking? If resource_size(&crashk_res) is zero, it means that crashk_res has not been added(insert_resource) or has been deleted(release_resource). I've tested it. It's okay. >> >>> >>>> >>>> Signed-off-by: Zhen Lei >>>> --- >>>> kernel/kexec_core.c | 2 +- >>>> 1 file changed, 1 insertion(+), 1 deletion(-) >>>> >>>> diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c >>>> index 22acee18195a591..d1ab139dd49035e 100644 >>>> --- a/kernel/kexec_core.c >>>> +++ b/kernel/kexec_core.c >>>> @@ -1137,7 +1137,7 @@ int crash_shrink_memory(unsigned long new_size) >>>> end = start + new_size; >>>> crash_free_reserved_phys_range(end, crashk_res.end); >>>> >>>> - if ((start == end) && (crashk_res.parent != NULL)) >>>> + if (start == end) >>>> release_resource(&crashk_res); >>>> >>>> ram_res->start = end; >>>> -- >>>> 2.25.1 >>>> >>> >>> . >>> >> >> -- >> Regards, >> Zhen Lei >> > > > . > -- Regards, Zhen Lei