[PATCH 1/3] lib: Add a generic copy_oldmem_page()

Arnd Bergmann arnd at arndb.de
Mon Jul 13 09:39:17 EDT 2020


On Mon, Jul 13, 2020 at 3:07 PM Christoph Hellwig <hch at infradead.org> wrote:
> On Fri, Jul 10, 2020 at 08:55:42PM -0700, Palmer Dabbelt wrote:
> > +ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
> > +                      size_t csize, unsigned long offset,
> > +                      int userbuf)
> > +{
> > +     void *vaddr;
> > +
> > +     if (!csize)
> > +             return 0;
> > +
> > +     vaddr = memremap(__pfn_to_phys(pfn), PAGE_SIZE, MEMREMAP_WB);
> > +     if (!vaddr)
> > +             return -ENOMEM;
>
> Doing a memremap for every page is very inefficient.  Also I don't see
> why you'd want to even do that.  All memory is in the direct mapping
> for RISC-V.  For other architecture that support highmem kmap_atomic_pfn
> would do the job, which is what I'd use in a generic version.

I would expect the 'oldmem' data to not have a 'struct page', which would
be a problem at least for the generic implementation of kmap_atomic_pfn()

include/linux/highmem.h:#define kmap_atomic_pfn(pfn)
kmap_atomic(pfn_to_page(pfn))

kmap_atomic() might still work with a bogus page pointer if it
only transforms it back into a pfn, but some implementations just
have this one that cannot work:
static inline void *page_address(const struct page *page)
{
        return page->virtual;
}

I have not checked how the crash dump code works though, maybe
it does work after all.

       Arnd



More information about the linux-arm-kernel mailing list