Kexec Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Zhen Lei <thunder.leizhen@huawei.com>
To: Eric Biederman <ebiederm@xmission.com>,
	Baoquan He <bhe@redhat.com>, <kexec@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>
Cc: Zhen Lei <thunder.leizhen@huawei.com>,
	Michael Holzheu <holzheu@linux.vnet.ibm.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Amerigo Wang <amwang@redhat.com>
Subject: [PATCH 3/6] kexec: clear crashk_res if all its memory has been released
Date: Sat, 27 May 2023 20:34:36 +0800	[thread overview]
Message-ID: <20230527123439.772-4-thunder.leizhen@huawei.com> (raw)
In-Reply-To: <20230527123439.772-1-thunder.leizhen@huawei.com>

If the resource of crashk_res has been released, it is better to clear
crashk_res.start and crashk_res.end. Because 'end = start - 1' is not
reasonable, and in some places the test is based on crashk_res.end, not
resource_size(&crashk_res).

Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
---
 kernel/kexec_core.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c
index d1ab139dd49035e..bcc86a250ab3bf9 100644
--- a/kernel/kexec_core.c
+++ b/kernel/kexec_core.c
@@ -1137,15 +1137,18 @@ int crash_shrink_memory(unsigned long new_size)
 	end = start + new_size;
 	crash_free_reserved_phys_range(end, crashk_res.end);
 
-	if (start == end)
-		release_resource(&crashk_res);
-
 	ram_res->start = end;
 	ram_res->end = crashk_res.end;
 	ram_res->flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM;
 	ram_res->name = "System RAM";
 
-	crashk_res.end = end - 1;
+	if (start == end) {
+		release_resource(&crashk_res);
+		crashk_res.start = 0;
+		crashk_res.end = 0;
+	} else {
+		crashk_res.end = end - 1;
+	}
 
 	insert_resource(&iomem_resource, ram_res);
 
-- 
2.25.1


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

  parent reply	other threads:[~2023-05-27 12:36 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-27 12:34 [PATCH 0/6] kexec: enable kexec_crash_size to support two crash kernel regions Zhen Lei
2023-05-27 12:34 ` [PATCH 1/6] kexec: fix a memory leak in crash_shrink_memory() Zhen Lei
2023-05-31  0:13   ` Baoquan He
2023-05-31  1:16     ` Leizhen (ThunderTown)
2023-05-31  7:31       ` Baoquan He
2023-05-27 12:34 ` [PATCH 2/6] kexec: delete a useless check " Zhen Lei
2023-05-31  0:17   ` Baoquan He
2023-05-31  2:19     ` Leizhen (ThunderTown)
2023-05-31  7:41       ` Baoquan He
2023-05-31  8:26         ` Leizhen (ThunderTown)
2023-05-27 12:34 ` Zhen Lei [this message]
2023-05-31  0:33   ` [PATCH 3/6] kexec: clear crashk_res if all its memory has been released Baoquan He
2023-05-27 12:34 ` [PATCH 4/6] kexec: improve the readability of crash_shrink_memory() Zhen Lei
2023-05-31  7:48   ` Baoquan He
2023-05-27 12:34 ` [PATCH 5/6] kexec: add helper __crash_shrink_memory() Zhen Lei
2023-05-28  0:08   ` kernel test robot
2023-05-29  0:37     ` Leizhen (ThunderTown)
2023-05-28  1:44   ` kernel test robot
2023-05-28  6:26   ` kernel test robot
2023-05-31  7:50   ` Baoquan He
2023-05-27 12:34 ` [PATCH 6/6] kexec: enable kexec_crash_size to support two crash kernel regions Zhen Lei
2023-05-31  9:53   ` Baoquan He
2023-05-31 14:25     ` Leizhen (ThunderTown)

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=20230527123439.772-4-thunder.leizhen@huawei.com \
    --to=thunder.leizhen@huawei.com \
    --cc=akpm@linux-foundation.org \
    --cc=amwang@redhat.com \
    --cc=bhe@redhat.com \
    --cc=ebiederm@xmission.com \
    --cc=holzheu@linux.vnet.ibm.com \
    --cc=kexec@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    /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