LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [RFC][PATCH 2/2 -mm] kexec based hibernation: kexec restore
@ 2007-08-27 1:14 Huang, Ying
2007-08-27 21:31 ` Pavel Machek
0 siblings, 1 reply; 4+ messages in thread
From: Huang, Ying @ 2007-08-27 1:14 UTC (permalink / raw)
To: Eric W. Biederman, Pavel Machek, nigel, Andrew Morton,
Jeremy Maitin-Shepard
Cc: linux-kernel, linux-pm, Kexec Mailing List
This patch adds writing support for /dev/oldmem. This is used to
restore the memory contents of hibernated system.
Signed-off-by: Huang Ying <ying.huang@intel.com>
---
arch/i386/kernel/crash_dump.c | 27 +++++++++++++++++++++++++++
drivers/char/mem.c | 32 ++++++++++++++++++++++++++++++++
include/linux/crash_dump.h | 2 ++
3 files changed, 61 insertions(+)
Index: linux-2.6.23-rc3/arch/i386/kernel/crash_dump.c
===================================================================
--- linux-2.6.23-rc3.orig/arch/i386/kernel/crash_dump.c 2007-08-25 21:56:52.000000000 +0800
+++ linux-2.6.23-rc3/arch/i386/kernel/crash_dump.c 2007-08-25 21:57:11.000000000 +0800
@@ -58,6 +58,33 @@
return csize;
}
+ssize_t write_oldmem_page(unsigned long pfn, const char *buf,
+ size_t csize, unsigned long offset, int userbuf)
+{
+ void *vaddr;
+
+ if (!csize)
+ return 0;
+
+ if (!userbuf) {
+ vaddr = kmap_atomic_pfn(pfn, KM_PTE0);
+ memcpy(vaddr + offset, buf, csize);
+ } else {
+ if (!kdump_buf_page) {
+ printk(KERN_WARNING "Kdump: Kdump buffer page not"
+ " allocated\n");
+ return -EFAULT;
+ }
+ if (copy_from_user(kdump_buf_page, buf, csize))
+ return -EFAULT;
+ vaddr = kmap_atomic_pfn(pfn, KM_PTE0);
+ memcpy(vaddr + offset, kdump_buf_page, csize);
+ }
+ kunmap_atomic(vaddr, KM_PTE0);
+
+ return csize;
+}
+
static int __init kdump_buf_page_init(void)
{
int ret = 0;
Index: linux-2.6.23-rc3/include/linux/crash_dump.h
===================================================================
--- linux-2.6.23-rc3.orig/include/linux/crash_dump.h 2007-08-25 21:56:52.000000000 +0800
+++ linux-2.6.23-rc3/include/linux/crash_dump.h 2007-08-25 21:57:11.000000000 +0800
@@ -11,6 +11,8 @@
extern unsigned long long elfcorehdr_addr;
extern ssize_t copy_oldmem_page(unsigned long, char *, size_t,
unsigned long, int);
+extern ssize_t write_oldmem_page(unsigned long, const char *, size_t,
+ unsigned long, int);
extern const struct file_operations proc_vmcore_operations;
extern struct proc_dir_entry *proc_vmcore;
Index: linux-2.6.23-rc3/drivers/char/mem.c
===================================================================
--- linux-2.6.23-rc3.orig/drivers/char/mem.c 2007-08-25 21:56:52.000000000 +0800
+++ linux-2.6.23-rc3/drivers/char/mem.c 2007-08-25 21:57:11.000000000 +0800
@@ -348,6 +348,37 @@
}
return read;
}
+
+/*
+ * Write memory corresponding to the old kernel.
+ */
+static ssize_t write_oldmem(struct file *file, const char __user *buf,
+ size_t count, loff_t *ppos)
+{
+ unsigned long pfn, offset;
+ size_t write = 0, csize;
+ int rc = 0;
+
+ while (count) {
+ pfn = *ppos / PAGE_SIZE;
+ if (pfn > saved_max_pfn)
+ return write;
+
+ offset = (unsigned long)(*ppos % PAGE_SIZE);
+ if (count > PAGE_SIZE - offset)
+ csize = PAGE_SIZE - offset;
+ else
+ csize = count;
+ rc = write_oldmem_page(pfn, buf, csize, offset, 1);
+ if (rc < 0)
+ return rc;
+ buf += csize;
+ *ppos += csize;
+ write += csize;
+ count -= csize;
+ }
+ return write;
+}
#endif
extern long vread(char *buf, char *addr, unsigned long count);
@@ -783,6 +814,7 @@
#ifdef CONFIG_CRASH_DUMP
static const struct file_operations oldmem_fops = {
.read = read_oldmem,
+ .write = write_oldmem,
.open = open_oldmem,
};
#endif
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFC][PATCH 2/2 -mm] kexec based hibernation: kexec restore
2007-08-27 1:14 [RFC][PATCH 2/2 -mm] kexec based hibernation: kexec restore Huang, Ying
@ 2007-08-27 21:31 ` Pavel Machek
2007-08-28 1:14 ` Huang, Ying
0 siblings, 1 reply; 4+ messages in thread
From: Pavel Machek @ 2007-08-27 21:31 UTC (permalink / raw)
To: Huang, Ying
Cc: Eric W. Biederman, nigel, Andrew Morton, Jeremy Maitin-Shepard,
linux-kernel, linux-pm, Kexec Mailing List
Hi!
> This patch adds writing support for /dev/oldmem. This is used to
> restore the memory contents of hibernated system.
>
> Signed-off-by: Huang Ying <ying.huang@intel.com>
> +ssize_t write_oldmem_page(unsigned long pfn, const char *buf,
> + size_t csize, unsigned long offset, int userbuf)
Hmm, int userbuf is only ever set to one... Does it make sense to have
write_oldmem_page in the separate file? The onl user is mem.c, perhaps
it should go there?
> +
> +/*
> + * Write memory corresponding to the old kernel.
> + */
> +static ssize_t write_oldmem(struct file *file, const char __user *buf,
> + size_t count, loff_t *ppos)
> +{
> + unsigned long pfn, offset;
> + size_t write = 0, csize;
> + int rc = 0;
> +
> + while (count) {
> + pfn = *ppos / PAGE_SIZE;
> + if (pfn > saved_max_pfn)
> + return write;
> +
> + offset = (unsigned long)(*ppos % PAGE_SIZE);
> + if (count > PAGE_SIZE - offset)
> + csize = PAGE_SIZE - offset;
> + else
> + csize = count;
> + rc = write_oldmem_page(pfn, buf, csize, offset, 1);
> + if (rc < 0)
> + return rc;
> + buf += csize;
> + *ppos += csize;
> + write += csize;
> + count -= csize;
> + }
> + return write;
> +}
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFC][PATCH 2/2 -mm] kexec based hibernation: kexec restore
2007-08-27 21:31 ` Pavel Machek
@ 2007-08-28 1:14 ` Huang, Ying
2007-08-29 15:15 ` Pavel Machek
0 siblings, 1 reply; 4+ messages in thread
From: Huang, Ying @ 2007-08-28 1:14 UTC (permalink / raw)
To: Pavel Machek
Cc: Eric W. Biederman, nigel, Andrew Morton, Jeremy Maitin-Shepard,
linux-kernel, linux-pm, Kexec Mailing List
On Mon, 2007-08-27 at 23:31 +0200, Pavel Machek wrote:
> Hi!
>
> > This patch adds writing support for /dev/oldmem. This is used to
> > restore the memory contents of hibernated system.
> >
> > Signed-off-by: Huang Ying <ying.huang@intel.com>
>
> > +ssize_t write_oldmem_page(unsigned long pfn, const char *buf,
> > + size_t csize, unsigned long offset, int userbuf)
>
> Hmm, int userbuf is only ever set to one... Does it make sense to have
> write_oldmem_page in the separate file? The onl user is mem.c, perhaps
> it should go there?
>
write_oldmem_page is kept to be consistent with copy_oldmem_page as much
as possible. The userbuf is used by copy_oldmem_page too, and
write_oldmem_page is in the same file as copy_oldmem_page. I think the
consistence between them is reasonable.
And the copy_oldmem_page/write_oldmem_page is considered to be
architecture dependent. Now, there are different implementations for
copy_oldmem_page on different architectures. So I think the
copy_oldmem_page/write_oldmem_page should be kept in separate file
instead of go mem.c.
Best Regards,
Huang Ying
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFC][PATCH 2/2 -mm] kexec based hibernation: kexec restore
2007-08-28 1:14 ` Huang, Ying
@ 2007-08-29 15:15 ` Pavel Machek
0 siblings, 0 replies; 4+ messages in thread
From: Pavel Machek @ 2007-08-29 15:15 UTC (permalink / raw)
To: Huang, Ying
Cc: Eric W. Biederman, nigel, Andrew Morton, Jeremy Maitin-Shepard,
linux-kernel, linux-pm, Kexec Mailing List
> On Mon, 2007-08-27 at 23:31 +0200, Pavel Machek wrote:
> > Hi!
> >
> > > This patch adds writing support for /dev/oldmem. This is used to
> > > restore the memory contents of hibernated system.
> > >
> > > Signed-off-by: Huang Ying <ying.huang@intel.com>
> >
> > > +ssize_t write_oldmem_page(unsigned long pfn, const char *buf,
> > > + size_t csize, unsigned long offset, int userbuf)
> >
> > Hmm, int userbuf is only ever set to one... Does it make sense to have
> > write_oldmem_page in the separate file? The onl user is mem.c, perhaps
> > it should go there?
> >
>
> write_oldmem_page is kept to be consistent with copy_oldmem_page as much
> as possible. The userbuf is used by copy_oldmem_page too, and
> write_oldmem_page is in the same file as copy_oldmem_page. I think the
> consistence between them is reasonable.
>
> And the copy_oldmem_page/write_oldmem_page is considered to be
> architecture dependent. Now, there are different implementations for
> copy_oldmem_page on different architectures. So I think the
> copy_oldmem_page/write_oldmem_page should be kept in separate file
> instead of go mem.c.
I thought it may have something to do with consistency. ACK on that
one. Perhaps it should be pushed to akpm?
Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-08-29 15:15 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-27 1:14 [RFC][PATCH 2/2 -mm] kexec based hibernation: kexec restore Huang, Ying
2007-08-27 21:31 ` Pavel Machek
2007-08-28 1:14 ` Huang, Ying
2007-08-29 15:15 ` Pavel Machek
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).