From: Kairui Song <kasong@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: Dave Young <dyoung@redhat.com>, Baoquan He <bhe@redhat.com>,
Vivek Goyal <vgoyal@redhat.com>,
Alexey Dobriyan <adobriyan@gmail.com>,
Eric Biederman <ebiederm@xmission.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
kexec@lists.infradead.org, Kairui Song <kasong@redhat.com>
Subject: [RFC PATCH 3/3] x86_64: implement copy_to_oldmem_page
Date: Wed, 9 Sep 2020 15:50:16 +0800 [thread overview]
Message-ID: <20200909075016.104407-4-kasong@redhat.com> (raw)
In-Reply-To: <20200909075016.104407-1-kasong@redhat.com>
Previous commit introduced writing support for vmcore, it requires
per-architecture implementation for the writing function.
Signed-off-by: Kairui Song <kasong@redhat.com>
---
arch/x86/kernel/crash_dump_64.c | 49 +++++++++++++++++++++++++++------
1 file changed, 40 insertions(+), 9 deletions(-)
diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
index 045e82e8945b..ec80da75b287 100644
--- a/arch/x86/kernel/crash_dump_64.c
+++ b/arch/x86/kernel/crash_dump_64.c
@@ -13,7 +13,7 @@
static ssize_t __copy_oldmem_page(unsigned long pfn, char *buf, size_t csize,
unsigned long offset, int userbuf,
- bool encrypted)
+ bool encrypted, bool is_write)
{
void *vaddr;
@@ -28,13 +28,25 @@ static ssize_t __copy_oldmem_page(unsigned long pfn, char *buf, size_t csize,
if (!vaddr)
return -ENOMEM;
- if (userbuf) {
- if (copy_to_user((void __user *)buf, vaddr + offset, csize)) {
- iounmap((void __iomem *)vaddr);
- return -EFAULT;
+ if (is_write) {
+ if (userbuf) {
+ if (copy_from_user(vaddr + offset, (void __user *)buf, csize)) {
+ iounmap((void __iomem *)vaddr);
+ return -EFAULT;
+ }
+ } else {
+ memcpy(vaddr + offset, buf, csize);
}
- } else
- memcpy(buf, vaddr + offset, csize);
+ } else {
+ if (userbuf) {
+ if (copy_to_user((void __user *)buf, vaddr + offset, csize)) {
+ iounmap((void __iomem *)vaddr);
+ return -EFAULT;
+ }
+ } else {
+ memcpy(buf, vaddr + offset, csize);
+ }
+ }
set_iounmap_nonlazy();
iounmap((void __iomem *)vaddr);
@@ -57,7 +69,7 @@ static ssize_t __copy_oldmem_page(unsigned long pfn, char *buf, size_t csize,
ssize_t copy_oldmem_page(unsigned long pfn, char *buf, size_t csize,
unsigned long offset, int userbuf)
{
- return __copy_oldmem_page(pfn, buf, csize, offset, userbuf, false);
+ return __copy_oldmem_page(pfn, buf, csize, offset, userbuf, false, false);
}
/**
@@ -68,7 +80,26 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf, size_t csize,
ssize_t copy_oldmem_page_encrypted(unsigned long pfn, char *buf, size_t csize,
unsigned long offset, int userbuf)
{
- return __copy_oldmem_page(pfn, buf, csize, offset, userbuf, true);
+ return __copy_oldmem_page(pfn, buf, csize, offset, userbuf, true, false);
+}
+
+/**
+ * copy_to_oldmem_page - similar to copy_oldmem_page but in opposite direction.
+ */
+ssize_t copy_to_oldmem_page(unsigned long pfn, char *src, size_t csize,
+ unsigned long offset, int userbuf)
+{
+ return __copy_oldmem_page(pfn, src, csize, offset, userbuf, false, true);
+}
+
+/**
+ * copy_to_oldmem_page_encrypted - similar to copy_oldmem_page_encrypted but
+ * in opposite direction.
+ */
+ssize_t copy_to_oldmem_page_encrypted(unsigned long pfn, char *src, size_t csize,
+ unsigned long offset, int userbuf)
+{
+ return __copy_oldmem_page(pfn, src, csize, offset, userbuf, true, true);
}
ssize_t elfcorehdr_read(char *buf, size_t count, u64 *ppos)
--
2.26.2
next prev parent reply other threads:[~2020-09-09 7:51 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-09 7:50 [RFC PATCH 0/3] Add writing support to vmcore for reusing oldmem Kairui Song
2020-09-09 7:50 ` [RFC PATCH 1/3] vmcore: simplify read_from_olemem Kairui Song
2020-09-09 7:50 ` [RFC PATCH 2/3] vmcore: Add interface to write to old mem Kairui Song
2020-09-09 7:50 ` Kairui Song [this message]
2020-09-09 14:04 ` [RFC PATCH 0/3] Add writing support to vmcore for reusing oldmem Eric W. Biederman
2020-09-09 16:43 ` Kairui Song
2020-09-21 7:17 ` Kairui Song
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=20200909075016.104407-4-kasong@redhat.com \
--to=kasong@redhat.com \
--cc=adobriyan@gmail.com \
--cc=bhe@redhat.com \
--cc=bp@alien8.de \
--cc=dyoung@redhat.com \
--cc=ebiederm@xmission.com \
--cc=kexec@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=vgoyal@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).