public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Yuntao Wang <ytcoode@gmail.com>
To: linux-kernel@vger.kernel.org, kexec@lists.infradead.org, x86@kernel.org
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Jonathan Corbet <corbet@lwn.net>,
	Eric Biederman <ebiederm@xmission.com>,
	Yuntao Wang <ytcoode@gmail.com>
Subject: [PATCH 2/3] kexec_file: fix incorrect temp_start value in locate_mem_hole_top_down()
Date: Fri, 15 Dec 2023 16:09:09 +0800	[thread overview]
Message-ID: <20231215080910.173338-3-ytcoode@gmail.com> (raw)
In-Reply-To: <20231215080910.173338-1-ytcoode@gmail.com>

temp_end represents the address of the last available byte. Therefore, the
starting address of the memory segment with temp_end as its last available
byte and a size of `kbuf->memsz`, that is, the value of temp_start, should
be `temp_end - kbuf->memsz + 1` instead of `temp_end - kbuf->memsz`.

Additionally, use the ALIGN_DOWN macro instead of open-coding it directly
in locate_mem_hole_top_down() to improve code readability.

Signed-off-by: Yuntao Wang <ytcoode@gmail.com>
---
 kernel/kexec_file.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c
index 26be070d3bdd..c3bf52a9a8ad 100644
--- a/kernel/kexec_file.c
+++ b/kernel/kexec_file.c
@@ -426,11 +426,11 @@ static int locate_mem_hole_top_down(unsigned long start, unsigned long end,
 	unsigned long temp_start, temp_end;
 
 	temp_end = min(end, kbuf->buf_max);
-	temp_start = temp_end - kbuf->memsz;
+	temp_start = temp_end - kbuf->memsz + 1;
 
 	do {
 		/* align down start */
-		temp_start = temp_start & (~(kbuf->buf_align - 1));
+		temp_start = ALIGN_DOWN(temp_start, kbuf->buf_align);
 
 		if (temp_start < start || temp_start < kbuf->buf_min)
 			return 0;
-- 
2.43.0


  parent reply	other threads:[~2023-12-15  8:10 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-15  8:09 [PATCH 0/3] Some bug fixes and cleanups related to kexec Yuntao Wang
2023-12-15  8:09 ` [PATCH 1/3] kexec_file: fix incorrect end value passed to kimage_is_destination_range() Yuntao Wang
2023-12-15 17:46   ` Eric W. Biederman
2023-12-16  2:21     ` Baoquan He
2023-12-16  4:18       ` [PATCH 1/3 v2] kexec: modify the meaning of the end parameter in kimage_is_destination_range() Yuntao Wang
2023-12-16  9:29         ` Baoquan He
2023-12-16 11:23           ` [PATCH 1/3 v3] " Yuntao Wang
2023-12-16 12:05           ` [PATCH 1/3 v4] " Yuntao Wang
2023-12-17  1:02             ` Baoquan He
2023-12-15  8:09 ` Yuntao Wang [this message]
2023-12-15  8:09 ` [PATCH 3/3] x86/kexec: use pr_err() instead of pr_debug() when an error occurs Yuntao Wang

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=20231215080910.173338-3-ytcoode@gmail.com \
    --to=ytcoode@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=bp@alien8.de \
    --cc=corbet@lwn.net \
    --cc=dave.hansen@linux.intel.com \
    --cc=ebiederm@xmission.com \
    --cc=hpa@zytor.com \
    --cc=kexec@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=x86@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