From: Matthew Wilcox <willy@infradead.org>
To: Christoph Hellwig <hch@lst.de>
Cc: Amit Daniel Kachhap <amit.kachhap@arm.com>,
linux-kernel@vger.kernel.org,
Vincenzo Frascino <Vincenzo.Frascino@arm.com>,
Kevin Brodsky <kevin.brodsky@arm.com>,
linux-fsdevel <linux-fsdevel@vger.kernel.org>,
kexec <kexec@lists.infradead.org>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Young <dyoung@redhat.com>, Baoquan He <bhe@redhat.com>,
Vivek Goyal <vgoyal@redhat.com>, x86 <x86@kernel.org>
Subject: Re: [RFC PATCH 01/14] fs/proc/vmcore: Update read_from_oldmem() for user pointer
Date: Mon, 6 Dec 2021 14:17:24 +0000 [thread overview]
Message-ID: <Ya4bdB0UBJCZhUSo@casper.infradead.org> (raw)
In-Reply-To: <20211206140451.GA4936@lst.de>
On Mon, Dec 06, 2021 at 03:04:51PM +0100, Christoph Hellwig wrote:
> This looks like a huge mess. What speak against using an iov_iter
> here?
I coincidentally made a start on this last night. Happy to stop.
What do you think to adding a generic copy_pfn_to_iter()? Not sure
which APIs to use to implement it ... some architectures have weird
requirements about which APIs can be used for what kinds of PFNs.
diff --git a/arch/arm/kernel/crash_dump.c b/arch/arm/kernel/crash_dump.c
index 53cb92435392..ed0d806a4d14 100644
--- a/arch/arm/kernel/crash_dump.c
+++ b/arch/arm/kernel/crash_dump.c
@@ -16,39 +16,28 @@
#include <linux/io.h>
/**
- * copy_oldmem_page() - copy one page from old kernel memory
- * @pfn: page frame number to be copied
- * @buf: buffer where the copied page is placed
- * @csize: number of bytes to copy
- * @offset: offset in bytes into the page
- * @userbuf: if set, @buf is int he user address space
+ * copy_pfn_to_iter() - copy one page from old kernel memory.
+ * @iter: Where to copy the page to.
+ * @pfn: Page frame number to be copied.
+ * @offset: Offset in bytes into the page.
+ * @len: Number of bytes to copy.
*
- * This function copies one page from old kernel memory into buffer pointed by
- * @buf. If @buf is in userspace, set @userbuf to %1. Returns number of bytes
- * copied or negative error in case of failure.
+ * This function copies (part of) one page from old kernel memory into
+ * memory described by @iter.
+ *
+ * Return: Number of bytes copied or negative error in case of failure.
*/
-ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
- size_t csize, unsigned long offset,
- int userbuf)
+ssize_t copy_pfn_to_iter(struct iov_iter *iter, unsigned long pfn,
+ size_t offset, size_t len)
{
void *vaddr;
- if (!csize)
- return 0;
-
vaddr = ioremap(__pfn_to_phys(pfn), PAGE_SIZE);
if (!vaddr)
return -ENOMEM;
- if (userbuf) {
- if (copy_to_user(buf, vaddr + offset, csize)) {
- iounmap(vaddr);
- return -EFAULT;
- }
- } else {
- memcpy(buf, vaddr + offset, csize);
- }
+ len = copy_to_iter(vadd + offset, len, iter);
iounmap(vaddr);
- return csize;
+ return len;
}
diff --git a/include/linux/crash_dump.h b/include/linux/crash_dump.h
index 620821549b23..2dd3a692bcb7 100644
--- a/include/linux/crash_dump.h
+++ b/include/linux/crash_dump.h
@@ -24,8 +24,8 @@ extern int remap_oldmem_pfn_range(struct vm_area_struct *vma,
unsigned long from, unsigned long pfn,
unsigned long size, pgprot_t prot);
-extern ssize_t copy_oldmem_page(unsigned long, char *, size_t,
- unsigned long, int);
+ssize_t copy_pfn_to_iter(struct iov_iter *i, unsigned long pfn, size_t offset,
+ size_t len);
extern ssize_t copy_oldmem_page_encrypted(unsigned long pfn, char *buf,
size_t csize, unsigned long offset,
int userbuf);
next prev parent reply other threads:[~2021-12-06 14:17 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-03 10:42 [RFC PATCH 00/14] fs/proc/vmcore: Remove unnecessary user pointer conversions Amit Daniel Kachhap
2021-12-03 10:42 ` [RFC PATCH 01/14] fs/proc/vmcore: Update read_from_oldmem() for user pointer Amit Daniel Kachhap
2021-12-06 14:04 ` Christoph Hellwig
2021-12-06 14:17 ` Matthew Wilcox [this message]
2021-12-06 14:54 ` Christoph Hellwig
2021-12-06 15:07 ` Matthew Wilcox
2021-12-07 11:15 ` Christoph Hellwig
2021-12-07 7:11 ` Amit Kachhap
2021-12-03 10:42 ` [RFC PATCH 02/14] fs/proc/vmcore: Update copy_oldmem_page_encrypted() for user buffer Amit Daniel Kachhap
2021-12-03 10:42 ` [RFC PATCH 03/14] fs/proc/vmcore: Update copy_oldmem_page() " Amit Daniel Kachhap
2021-12-03 10:42 ` [RFC PATCH 04/14] x86/crash_dump_64: Use the new interface copy_oldmem_page_buf Amit Daniel Kachhap
2021-12-03 10:42 ` [RFC PATCH 05/14] x86/crash_dump_32: " Amit Daniel Kachhap
2021-12-03 10:42 ` [RFC PATCH 06/14] arm64/crash_dump: " Amit Daniel Kachhap
2021-12-03 10:42 ` [RFC PATCH 07/14] arm/crash_dump: " Amit Daniel Kachhap
2021-12-03 10:42 ` [RFC PATCH 08/14] mips/crash_dump: " Amit Daniel Kachhap
2021-12-03 10:42 ` [RFC PATCH 09/14] sh/crash_dump: " Amit Daniel Kachhap
2021-12-03 10:42 ` [RFC PATCH 10/14] riscv/crash_dump: " Amit Daniel Kachhap
2021-12-03 10:42 ` [RFC PATCH 11/14] powerpc/crash_dump: " Amit Daniel Kachhap
2021-12-03 10:42 ` [RFC PATCH 12/14] ia64/crash_dump: " Amit Daniel Kachhap
2021-12-03 10:42 ` [RFC PATCH 13/14] s390/crash_dump: " Amit Daniel Kachhap
2021-12-03 10:42 ` [RFC PATCH 14/14] fs/proc/vmcore: Remove the unused old interface copy_oldmem_page Amit Daniel Kachhap
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=Ya4bdB0UBJCZhUSo@casper.infradead.org \
--to=willy@infradead.org \
--cc=Vincenzo.Frascino@arm.com \
--cc=amit.kachhap@arm.com \
--cc=bhe@redhat.com \
--cc=bp@alien8.de \
--cc=dyoung@redhat.com \
--cc=hch@lst.de \
--cc=kevin.brodsky@arm.com \
--cc=kexec@lists.infradead.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=vgoyal@redhat.com \
--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;
as well as URLs for NNTP newsgroup(s).