From: Baoquan He <bhe@redhat.com>
To: Yuntao Wang <ytcoode@gmail.com>
Cc: akpm@linux-foundation.org, bp@alien8.de, corbet@lwn.net,
dave.hansen@linux.intel.com, ebiederm@xmission.com,
hpa@zytor.com, kexec@lists.infradead.org,
linux-kernel@vger.kernel.org, mingo@redhat.com,
tglx@linutronix.de, x86@kernel.org
Subject: Re: [PATCH 1/3 v2] kexec: modify the meaning of the end parameter in kimage_is_destination_range()
Date: Sat, 16 Dec 2023 17:29:35 +0800 [thread overview]
Message-ID: <ZX1t/4Reai6HdoJf@MiWiFi-R3L-srv> (raw)
In-Reply-To: <20231216041833.220466-1-ytcoode@gmail.com>
On 12/16/23 at 12:18pm, Yuntao Wang wrote:
> The end parameter received by kimage_is_destination_range() should be the
> last valid byte address of the target memory segment plus 1. However, in
> the locate_mem_hole_bottom_up() and locate_mem_hole_top_down() functions,
> the corresponding value passed to kimage_is_destination_range() is the last
> valid byte address of the target memory segment, which is 1 less.
>
> There are two ways to fix this bug. We can either correct the logic of the
> locate_mem_hole_bottom_up() and locate_mem_hole_top_down() functions, or we
> can fix kimage_is_destination_range() by making the end parameter represent
> the last valid byte address of the target memory segment. Here, we choose
> the second approach.
>
> Due to the modification to kimage_is_destination_range(), we also need to
> adjust its callers, such as kimage_alloc_normal_control_pages() and
> kimage_alloc_page().
>
> Signed-off-by: Yuntao Wang <ytcoode@gmail.com>
> ---
> v1->v2:
> Fix this issue using the approach suggested by Eric and Baoquan.
>
> As this patch is independent of the other patches in this series, I sent
> out the v2 patch separately. If it's inconvenient for anyone, I can
> resend the entire series again.
>
> kernel/kexec_core.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c
> index be5642a4ec49..5991b3ae072c 100644
> --- a/kernel/kexec_core.c
> +++ b/kernel/kexec_core.c
> @@ -276,8 +276,8 @@ int kimage_is_destination_range(struct kimage *image,
> unsigned long mstart, mend;
>
> mstart = image->segment[i].mem;
> - mend = mstart + image->segment[i].memsz;
> - if ((end > mstart) && (start < mend))
> + mend = mstart + image->segment[i].memsz - 1;
> + if ((end >= mstart) && (start <= mend))
> return 1;
> }
>
> @@ -372,7 +372,7 @@ static struct page *kimage_alloc_normal_control_pages(struct kimage *image,
> addr = pfn << PAGE_SHIFT;
> eaddr = epfn << PAGE_SHIFT;
eaddr = epfn << PAGE_SHIFT - 1;
The overall looks good to me, one tiny concern is I would like to
have 'eaddr' changed as above if a specific local variable has been
defined.
> if ((epfn >= (KEXEC_CONTROL_MEMORY_LIMIT >> PAGE_SHIFT)) ||
> - kimage_is_destination_range(image, addr, eaddr)) {
> + kimage_is_destination_range(image, addr, eaddr - 1)) {
Then we have:
+ kimage_is_destination_range(image, addr, eaddr)) {
> list_add(&pages->lru, &extra_pages);
> pages = NULL;
> }
> @@ -716,7 +716,7 @@ static struct page *kimage_alloc_page(struct kimage *image,
>
> /* If the page is not a destination page use it */
> if (!kimage_is_destination_range(image, addr,
> - addr + PAGE_SIZE))
> + addr + PAGE_SIZE - 1))
> break;
>
> /*
> --
> 2.43.0
>
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
WARNING: multiple messages have this Message-ID (diff)
From: Baoquan He <bhe@redhat.com>
To: Yuntao Wang <ytcoode@gmail.com>
Cc: akpm@linux-foundation.org, bp@alien8.de, corbet@lwn.net,
dave.hansen@linux.intel.com, ebiederm@xmission.com,
hpa@zytor.com, kexec@lists.infradead.org,
linux-kernel@vger.kernel.org, mingo@redhat.com,
tglx@linutronix.de, x86@kernel.org
Subject: Re: [PATCH 1/3 v2] kexec: modify the meaning of the end parameter in kimage_is_destination_range()
Date: Sat, 16 Dec 2023 17:29:35 +0800 [thread overview]
Message-ID: <ZX1t/4Reai6HdoJf@MiWiFi-R3L-srv> (raw)
In-Reply-To: <20231216041833.220466-1-ytcoode@gmail.com>
On 12/16/23 at 12:18pm, Yuntao Wang wrote:
> The end parameter received by kimage_is_destination_range() should be the
> last valid byte address of the target memory segment plus 1. However, in
> the locate_mem_hole_bottom_up() and locate_mem_hole_top_down() functions,
> the corresponding value passed to kimage_is_destination_range() is the last
> valid byte address of the target memory segment, which is 1 less.
>
> There are two ways to fix this bug. We can either correct the logic of the
> locate_mem_hole_bottom_up() and locate_mem_hole_top_down() functions, or we
> can fix kimage_is_destination_range() by making the end parameter represent
> the last valid byte address of the target memory segment. Here, we choose
> the second approach.
>
> Due to the modification to kimage_is_destination_range(), we also need to
> adjust its callers, such as kimage_alloc_normal_control_pages() and
> kimage_alloc_page().
>
> Signed-off-by: Yuntao Wang <ytcoode@gmail.com>
> ---
> v1->v2:
> Fix this issue using the approach suggested by Eric and Baoquan.
>
> As this patch is independent of the other patches in this series, I sent
> out the v2 patch separately. If it's inconvenient for anyone, I can
> resend the entire series again.
>
> kernel/kexec_core.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c
> index be5642a4ec49..5991b3ae072c 100644
> --- a/kernel/kexec_core.c
> +++ b/kernel/kexec_core.c
> @@ -276,8 +276,8 @@ int kimage_is_destination_range(struct kimage *image,
> unsigned long mstart, mend;
>
> mstart = image->segment[i].mem;
> - mend = mstart + image->segment[i].memsz;
> - if ((end > mstart) && (start < mend))
> + mend = mstart + image->segment[i].memsz - 1;
> + if ((end >= mstart) && (start <= mend))
> return 1;
> }
>
> @@ -372,7 +372,7 @@ static struct page *kimage_alloc_normal_control_pages(struct kimage *image,
> addr = pfn << PAGE_SHIFT;
> eaddr = epfn << PAGE_SHIFT;
eaddr = epfn << PAGE_SHIFT - 1;
The overall looks good to me, one tiny concern is I would like to
have 'eaddr' changed as above if a specific local variable has been
defined.
> if ((epfn >= (KEXEC_CONTROL_MEMORY_LIMIT >> PAGE_SHIFT)) ||
> - kimage_is_destination_range(image, addr, eaddr)) {
> + kimage_is_destination_range(image, addr, eaddr - 1)) {
Then we have:
+ kimage_is_destination_range(image, addr, eaddr)) {
> list_add(&pages->lru, &extra_pages);
> pages = NULL;
> }
> @@ -716,7 +716,7 @@ static struct page *kimage_alloc_page(struct kimage *image,
>
> /* If the page is not a destination page use it */
> if (!kimage_is_destination_range(image, addr,
> - addr + PAGE_SIZE))
> + addr + PAGE_SIZE - 1))
> break;
>
> /*
> --
> 2.43.0
>
next prev parent reply other threads:[~2023-12-16 9:29 UTC|newest]
Thread overview: 22+ 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 ` 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 8:09 ` Yuntao Wang
2023-12-15 17:46 ` Eric W. Biederman
2023-12-15 17:46 ` Eric W. Biederman
2023-12-16 2:21 ` Baoquan He
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 4:18 ` Yuntao Wang
2023-12-16 9:29 ` Baoquan He [this message]
2023-12-16 9:29 ` Baoquan He
2023-12-16 11:23 ` [PATCH 1/3 v3] " Yuntao Wang
2023-12-16 11:23 ` Yuntao Wang
2023-12-16 12:05 ` [PATCH 1/3 v4] " Yuntao Wang
2023-12-16 12:05 ` Yuntao Wang
2023-12-17 1:02 ` Baoquan He
2023-12-17 1:02 ` Baoquan He
2023-12-15 8:09 ` [PATCH 2/3] kexec_file: fix incorrect temp_start value in locate_mem_hole_top_down() Yuntao Wang
2023-12-15 8:09 ` Yuntao Wang
2023-12-15 8:09 ` [PATCH 3/3] x86/kexec: use pr_err() instead of pr_debug() when an error occurs Yuntao Wang
2023-12-15 8:09 ` 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=ZX1t/4Reai6HdoJf@MiWiFi-R3L-srv \
--to=bhe@redhat.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 \
--cc=ytcoode@gmail.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.