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: <20150205213939.GA3364@wil.cx>
Date:	Thu, 5 Feb 2015 16:39:39 -0500
From:	Matthew Wilcox <willy@...ux.intel.com>
To:	Yigal Korman <yigal@...xistor.com>
Cc:	Matthew Wilcox <matthew.r.wilcox@...el.com>,
	linux-fsdevel@...r.kernel.org,
	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
	"linux-mm@...ck.org" <linux-mm@...ck.org>, willy@...ux.intel.com,
	Andrew Morton <akpm@...ux-foundation.org>
Subject: Re: [PATCH v12 04/20] mm: Allow page fault handlers to perform the
 COW

On Thu, Feb 05, 2015 at 11:16:53AM +0200, Yigal Korman wrote:
> I have a question on a related issue (I think).
> I've noticed that for pfn-only mappings (VM_FAULT_NOPAGE)
> do_shared_fault only maps the pfn with r/o permissions.
> So if I use DAX to write the mmap()-ed pfn I get two faults - first
> handled by do_shared_fault and then again for making it r/w in
> do_wp_page.
> Is this simply a missing optimization like was done here with the
> cow_page? or am I missing something?

I have also noticed this behaviour.  I tracked down why it's happening:

DAX calls:
        error = vm_insert_mixed(vma, vaddr, pfn);
which calls:
        return insert_pfn(vma, addr, pfn, vma->vm_page_prot);

If you insert some debugging, you'll notice here that vm_page_prot does
not include PROT_WRITE.

That got cleared during mmap_region() where it does:

        if (vma_wants_writenotify(vma)) {
                pgprot_t pprot = vma->vm_page_prot;
...
                vma->vm_page_prot = vm_get_page_prot(vm_flags & ~VM_SHARED);


And why do we want writenotify (according to the VM)?  Because we have:

        /* The backer wishes to know when pages are first written to? */
        if (vma->vm_ops && vma->vm_ops->page_mkwrite)
                return 1;

We don't really want to be notified on a first write; we want the page to be
inserted write-enabled.  But in the case where we've covered a hole with a
read-only zero page, we need to be notified so we can allocate a page of
storage.

So, how to fix?  We could adjust vm_page_prot to include PROT_WRITE.
I think that should work, since we'll only insert zeroed pages for read
faults, and so the maybe_mkwrite() won't be called in do_set_pte().
I'm just not entirely sure where to set it.  Perhaps a MM person could
make a helpful suggestion?
--
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