* + kexec-copy-only-happens-before-uchunk-goes-to-zero.patch added to mm-nonmm-unstable branch
@ 2024-03-01 17:43 Andrew Morton
[not found] ` <d5dcc228289d48109a558d8fafdc3590@hexintek.com>
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2024-03-01 17:43 UTC (permalink / raw)
To: mm-commits, bhe, yang.zhang, akpm
The patch titled
Subject: kexec: copy only happens before uchunk goes to zero
has been added to the -mm mm-nonmm-unstable branch. Its filename is
kexec-copy-only-happens-before-uchunk-goes-to-zero.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/kexec-copy-only-happens-before-uchunk-goes-to-zero.patch
This patch will later appear in the mm-nonmm-unstable branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via the mm-everything
branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there every 2-3 working days
------------------------------------------------------
From: "yang.zhang" <yang.zhang@hexintek.com>
Subject: kexec: copy only happens before uchunk goes to zero
Date: Thu, 22 Feb 2024 17:21:19 +0800
When loading segments, ubytes is <= mbytes. When ubytes is exhausted,
there could be remaining mbytes. Then in the while loop, the buf pointer
advancing with mchunk will causing meaningless reading even though it
doesn't harm.
So let's change to make sure that all of the copying and the rest only
happens before uchunk goes to zero.
Link: https://lkml.kernel.org/r/20240222092119.5602-1-gaoshanliukou@163.com
Signed-off-by: yang.zhang <yang.zhang@hexintek.com>
Acked-by: Baoquan He <bhe@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
kernel/kexec_core.c | 44 ++++++++++++++++++++++--------------------
1 file changed, 24 insertions(+), 20 deletions(-)
--- a/kernel/kexec_core.c~kexec-copy-only-happens-before-uchunk-goes-to-zero
+++ a/kernel/kexec_core.c
@@ -750,22 +750,24 @@ static int kimage_load_normal_segment(st
PAGE_SIZE - (maddr & ~PAGE_MASK));
uchunk = min(ubytes, mchunk);
- /* For file based kexec, source pages are in kernel memory */
- if (image->file_mode)
- memcpy(ptr, kbuf, uchunk);
- else
- result = copy_from_user(ptr, buf, uchunk);
+ if (uchunk) {
+ /* For file based kexec, source pages are in kernel memory */
+ if (image->file_mode)
+ memcpy(ptr, kbuf, uchunk);
+ else
+ result = copy_from_user(ptr, buf, uchunk);
+ ubytes -= uchunk;
+ if (image->file_mode)
+ kbuf += uchunk;
+ else
+ buf += uchunk;
+ }
kunmap_local(ptr);
if (result) {
result = -EFAULT;
goto out;
}
- ubytes -= uchunk;
maddr += mchunk;
- if (image->file_mode)
- kbuf += mchunk;
- else
- buf += mchunk;
mbytes -= mchunk;
cond_resched();
@@ -817,11 +819,18 @@ static int kimage_load_crash_segment(str
memset(ptr + uchunk, 0, mchunk - uchunk);
}
- /* For file based kexec, source pages are in kernel memory */
- if (image->file_mode)
- memcpy(ptr, kbuf, uchunk);
- else
- result = copy_from_user(ptr, buf, uchunk);
+ if (uchunk) {
+ /* For file based kexec, source pages are in kernel memory */
+ if (image->file_mode)
+ memcpy(ptr, kbuf, uchunk);
+ else
+ result = copy_from_user(ptr, buf, uchunk);
+ ubytes -= uchunk;
+ if (image->file_mode)
+ kbuf += uchunk;
+ else
+ buf += uchunk;
+ }
kexec_flush_icache_page(page);
kunmap_local(ptr);
arch_kexec_pre_free_pages(page_address(page), 1);
@@ -829,12 +838,7 @@ static int kimage_load_crash_segment(str
result = -EFAULT;
goto out;
}
- ubytes -= uchunk;
maddr += mchunk;
- if (image->file_mode)
- kbuf += mchunk;
- else
- buf += mchunk;
mbytes -= mchunk;
cond_resched();
_
Patches currently in -mm which might be from yang.zhang@hexintek.com are
kexec-copy-only-happens-before-uchunk-goes-to-zero.patch
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-03-05 6:06 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-01 17:43 + kexec-copy-only-happens-before-uchunk-goes-to-zero.patch added to mm-nonmm-unstable branch Andrew Morton
[not found] ` <d5dcc228289d48109a558d8fafdc3590@hexintek.com>
2024-03-05 5:19 ` 答复: " bhe
2024-03-05 6:06 ` 答复: " 张洋
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.