lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20130612111303.3323f24f@holzheu>
Date:	Wed, 12 Jun 2013 11:13:03 +0200
From:	Michael Holzheu <holzheu@...ux.vnet.ibm.com>
To:	HATAYAMA Daisuke <d.hatayama@...il.com>
Cc:	Vivek Goyal <vgoyal@...hat.com>, Jan Willeke <willeke@...ibm.com>,
	Martin Schwidefsky <schwidefsky@...ibm.com>,
	Heiko Carstens <heiko.carstens@...ibm.com>,
	linux-kernel@...r.kernel.org, kexec@...ts.infradead.org
Subject: Re: [PATCH v5 3/5] vmcore: Introduce remap_oldmem_pfn_range()

On Tue, 11 Jun 2013 21:42:15 +0900
HATAYAMA Daisuke <d.hatayama@...il.com> wrote:

> 2013/6/11 Michael Holzheu <holzheu@...ux.vnet.ibm.com>:
> > On Mon, 10 Jun 2013 22:40:24 +0900
> > HATAYAMA Daisuke <d.hatayama@...il.com> wrote:
> >
> >> 2013/6/8 Michael Holzheu <holzheu@...ux.vnet.ibm.com>:
> >> <cut>
> >> > @@ -225,6 +251,56 @@ static ssize_t read_vmcore(struct file *file, char __user *buffer,
> >> >         return acc;
> >> >  }
> >> >
> >> > +static ssize_t read_vmcore(struct file *file, char __user *buffer,
> >> > +                          size_t buflen, loff_t *fpos)
> >> > +{
> >> > +       return __read_vmcore(buffer, buflen, fpos, 1);
> >> > +}
> >> > +
> >> > +/*
> >> > + * The vmcore fault handler uses the page cache and fills data using the
> >> > + * standard __vmcore_read() function.
> >> > + */
> >> > +static int mmap_vmcore_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
> >> > +{
> >> > +       struct address_space *mapping = vma->vm_private_data;
> >> > +       pgoff_t index = vmf->pgoff;
> >> > +       struct page *page;
> >> > +       loff_t src;
> >> > +       char *buf;
> >> > +       int rc;
> >> > +
> >> > +find_page:
> >> > +       page = find_lock_page(mapping, index);
> >> > +       if (page) {
> >> > +               unlock_page(page);
> >> > +               rc = VM_FAULT_MINOR;
> >> > +       } else {
> >> > +               page = page_cache_alloc_cold(mapping);
> >> > +               if (!page)
> >> > +                       return VM_FAULT_OOM;
> >> > +               rc = add_to_page_cache_lru(page, mapping, index, GFP_KERNEL);
> >> > +               if (rc) {
> >> > +                       page_cache_release(page);
> >> > +                       if (rc == -EEXIST)
> >> > +                               goto find_page;
> >> > +                       /* Probably ENOMEM for radix tree node */
> >> > +                       return VM_FAULT_OOM;
> >> > +               }
> >> > +               buf = (void *) (page_to_pfn(page) << PAGE_SHIFT);
> >> > +               src = index << PAGE_CACHE_SHIFT;
> >> > +               __read_vmcore(buf, PAGE_SIZE, &src, 0);
> >> > +               unlock_page(page);
> >> > +               rc = VM_FAULT_MAJOR;
> >> > +       }
> >> > +       vmf->page = page;
> >> > +       return rc;
> >> > +}
> >>
> >> How about reusing find_or_create_page()?
> >
> > The function would then look like the following:
> >
> > static int mmap_vmcore_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
> > {
> >         struct address_space *mapping = vma->vm_private_data;
> >         pgoff_t index = vmf->pgoff;
> >         struct page *page;
> >         loff_t src;
> >         char *buf;
> >
> >         page = find_or_create_page(mapping, index, GFP_KERNEL);
> >         if (!page)
> >                 return VM_FAULT_OOM;
> >         src = index << PAGE_CACHE_SHIFT;
> >         buf = (void *) (page_to_pfn(page) << PAGE_SHIFT);
> >         __read_vmcore(buf, PAGE_SIZE, &src, 0);
> >         unlock_page(page);
> >         vmf->page = page;
> >         return 0;
> > }
> >
> > I agree that this makes the function simpler but we have to copy
> > the page also if it has already been filled, correct?
> >
> 
> You can use for the purpose PG_uptodate flag.

Thanks for that hint! So together with your other comment regarding
error checking for __read_vmcore() the function would look like the
following:

static int mmap_vmcore_fault(struct vm_area_struct *vma, struct'vm_fault *vmf)
{
        struct address_space *mapping = vma->vm_private_data;
        pgoff_t index = vmf->pgoff;
        struct page *page;
        loff_t src;
        char *buf;

        page = find_or_create_page(mapping, index, GFP_KERNEL);
        if (!page)
                return VM_FAULT_OOM;
        if (!PageUptodate(page)) {
                src = index << PAGE_CACHE_SHIFT;
                buf = (void *) (page_to_pfn(page) << PAGE_SHIFT);
                if (__read_vmcore(buf, PAGE_SIZE, &src, 0) < 0) {
                        unlock_page(page);
                        return VM_FAULT_SIGBUS;
                }
                SetPageUptodate(page);
        }
        unlock_page(page);
        vmf->page = page;
        return 0;
}

Perhaps one open issue remains:

Can we remove the page from the page cache if __read_vmcore() fails?

Thanks!
Michael

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ