Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp178214rwd; Tue, 30 May 2023 18:20:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6idwFtwufr5fz2Miarozyk8DiH5BZcQKKAsOAVQfae/KThcGptpVAu6zszdTo6H7wX40v9 X-Received: by 2002:a05:6a20:12cc:b0:10b:aeff:aa00 with SMTP id v12-20020a056a2012cc00b0010baeffaa00mr4289316pzg.28.1685496020559; Tue, 30 May 2023 18:20:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685496020; cv=none; d=google.com; s=arc-20160816; b=jGEuwLHXA9u8f4G+CyHvHVexfByPOfAmwbP11Aca4FroL437flIrT0MXglrsp2RoHV 66GQ7MaYG3iI8VkcD5iqCaOVyk78r7K07xXJJ+lhj8YEItTdH5zI1PiFG34+tqaati8N /gzTTwWkCtx0kdcLgcR0ROODZUnAJ+kFdicZm5QztQ+soIIh/hIIPzRXZlN1reHFD6YB LjkfgUgrvP/s6NYzVoH8hOx9IwyF+Ww+B/BFOchm7NtU4UgAcauVPt/x1Utz2GGf/0B2 Q0JAQsuS07MJ7+2cT6TPh5N4WfuYssmQKk4Bs37NJtXT3PWVJA7bpxj8JHBoT79O0RnA WuOA== 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=zj/BIM+VdA0vKXtuUZT47umYLWTNiMUvzwP/+p9FM8I=; b=ip+0174obVz1EWxhpkyDQkj0kjIHlM9r6trECA0qNvParicnb/kAgEYKXXnyAlA5X3 bSMusu6piKZJszqhsiwyMgErFWKMgjUMk57MMdSiyb5JrJhsHoO7drYeBYHkYBNjEjQg 6k/EGkYZ1qyhAjJm48d4nc+xoquUb/rArBAbsYpIvkDoTlUVOPQtr/fE29lJonZccI9R diLGae3vCaCAk7RyHVX4hw1hZuhJpZGqbn2CtKP2UJ5eXAULCqk+XbQltXppua1Lox6V 7JpelXi39OkNrfUSlNZemsgTyFgKFa4BxrGTS3Xr2+SCl0M2hWOPyq4stkuwwpKLJgZP 17hw== 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 y14-20020aa79e0e000000b0063b7e907032si2612185pfq.271.2023.05.30.18.20.06; Tue, 30 May 2023 18:20:20 -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 S233957AbjEaBQ3 (ORCPT + 99 others); Tue, 30 May 2023 21:16:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231545AbjEaBQ2 (ORCPT ); Tue, 30 May 2023 21:16:28 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E80FCF3 for ; Tue, 30 May 2023 18:16:25 -0700 (PDT) Received: from dggpemm500006.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4QWB746xqwzqTYs; Wed, 31 May 2023 09:11:44 +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 09:16:23 +0800 Subject: Re: [PATCH 1/6] kexec: fix a memory leak in crash_shrink_memory() To: Baoquan He CC: Eric Biederman , , , Michael Holzheu , Andrew Morton References: <20230527123439.772-1-thunder.leizhen@huawei.com> <20230527123439.772-2-thunder.leizhen@huawei.com> From: "Leizhen (ThunderTown)" Message-ID: <5232350c-7529-eece-c9cb-8a8bbc83a81a@huawei.com> Date: Wed, 31 May 2023 09:16:22 +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: dggems704-chm.china.huawei.com (10.3.19.181) 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 8:13, Baoquan He wrote: > On 05/27/23 at 08:34pm, Zhen Lei wrote: >> If the value of parameter 'new_size' is in the semi-open and semi-closed >> interval (crashk_res.end - KEXEC_CRASH_MEM_ALIGN + 1, crashk_res.end], the >> calculation result of ram_res is: >> ram_res->start = crashk_res.end + 1 >> ram_res->end = crashk_res.end > > If the new_size is smaller than KEXEC_CRASH_MEM_ALIGN, does it make > any sense except of testing purpose? Do we need to fail this kind of > shrinking, or just shrink all the left crash memory? We can't give a fixed value, that is, how much crash memory is reserved to ensure that the capture kernel runs. The size of KEXEC_CRASH_MEM_ALIGN is only one page on non-s390 platforms. So, it's better to keep the code simple, and let the user(administrator) shrink the crash memory reasonably. include/linux/kexec.h #define KEXEC_CRASH_MEM_ALIGN PAGE_SIZE > >> The operation of function insert_resource() fails, and ram_res is not >> added to iomem_resource. As a result, the memory of the control block >> ram_res is leaked. >> >> In fact, on all architectures, the start address and size of crashk_res >> are already aligned by KEXEC_CRASH_MEM_ALIGN. Therefore, we do not need to >> round up crashk_res.start again. Instead, we should round up 'new_size' >> in advance. >> >> Fixes: 6480e5a09237 ("kdump: add missing RAM resource in crash_shrink_memory()") >> Fixes: 06a7f711246b ("kexec: premit reduction of the reserved memory size") >> Signed-off-by: Zhen Lei >> --- >> kernel/kexec_core.c | 5 ++--- >> 1 file changed, 2 insertions(+), 3 deletions(-) >> >> diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c >> index 3d578c6fefee385..22acee18195a591 100644 >> --- a/kernel/kexec_core.c >> +++ b/kernel/kexec_core.c >> @@ -1122,6 +1122,7 @@ int crash_shrink_memory(unsigned long new_size) >> start = crashk_res.start; >> end = crashk_res.end; >> old_size = (end == 0) ? 0 : end - start + 1; >> + new_size = roundup(new_size, KEXEC_CRASH_MEM_ALIGN); >> if (new_size >= old_size) { >> ret = (new_size == old_size) ? 0 : -EINVAL; >> goto unlock; >> @@ -1133,9 +1134,7 @@ int crash_shrink_memory(unsigned long new_size) >> goto unlock; >> } >> >> - start = roundup(start, KEXEC_CRASH_MEM_ALIGN); >> - end = roundup(start + new_size, KEXEC_CRASH_MEM_ALIGN); >> - >> + end = start + new_size; >> crash_free_reserved_phys_range(end, crashk_res.end); >> >> if ((start == end) && (crashk_res.parent != NULL)) >> -- >> 2.25.1 >> > > . > -- Regards, Zhen Lei