linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Vincent Donnefort <vdonnefort@google.com>
To: David Hildenbrand <david@redhat.com>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	Andrew Morton <akpm@linux-foundation.org>,
	Dan Williams <dan.j.williams@intel.com>,
	rostedt@goodmis.org
Subject: Re: [PATCH v1 1/2] mm/memory: cleanly support zeropage in vm_insert_page*(), vm_map_pages*() and vmf_insert_mixed()
Date: Tue, 21 May 2024 11:10:16 +0100	[thread overview]
Message-ID: <ZkxzCJBihAddyb4D@google.com> (raw)
In-Reply-To: <dde2f22d-c57f-44ac-9f2c-4a1790de084b@redhat.com>

On Tue, May 21, 2024 at 11:18:41AM +0200, David Hildenbrand wrote:
> On 21.05.24 11:06, Vincent Donnefort wrote:
> > On Tue, May 21, 2024 at 10:25:43AM +0200, David Hildenbrand wrote:
> > > On 17.05.24 17:07, Vincent Donnefort wrote:
> > > > Hi David,
> > > > 
> > > > [...]
> > > > 
> > > > > -static int validate_page_before_insert(struct page *page)
> > > > > +static bool vm_mixed_zeropage_allowed(struct vm_area_struct *vma)
> > > > > +{
> > > > > +	VM_WARN_ON_ONCE(vma->vm_flags & VM_PFNMAP);
> > > > > +	/*
> > > > > +	 * Whoever wants to forbid the zeropage after some zeropages
> > > > > +	 * might already have been mapped has to scan the page tables and
> > > > > +	 * bail out on any zeropages. Zeropages in COW mappings can
> > > > > +	 * be unshared using FAULT_FLAG_UNSHARE faults.
> > > > > +	 */
> > > > > +	if (mm_forbids_zeropage(vma->vm_mm))
> > > > > +		return false;
> > > > > +	/* zeropages in COW mappings are common and unproblematic. */
> > > > > +	if (is_cow_mapping(vma->vm_flags))
> > > > > +		return true;
> > > > > +	/* Mappings that do not allow for writable PTEs are unproblematic. */
> > > > > +	if (!(vma->vm_flags & (VM_WRITE | VM_MAYWRITE)))
> > > > > +		return false;
> > > > 
> > > > Shouldn't we return true here?
> > > 
> > > Indeed, thanks! I wish we would have user in the tree already that could
> > > exercise that code path.
> > 
> > I have a patch ready to use this path from the memory map tracing! I can either
> > send it once this one is picked-up or you can add it to your series?
> 
> Whatever works for you! To debug, it would be good if you could send me the
> patch and simple instructions on how to test it (do we have a selftest as
> well?).

Of course, I'll share something with you today! It includes an update to the
selftest to make sure we check the padding with the zero-page.

> 
> > 
> > > 
> > > [...]
> > > 
> > > > > @@ -2043,7 +2085,7 @@ static int insert_page_in_batch_locked(struct vm_area_struct *vma, pte_t *pte,
> > > > >    	if (!page_count(page))
> > > > >    		return -EINVAL;
> > > > 
> > > > This test here prevents inserting the zero-page.
> > > 
> > > You mean the existing page_count() check? or the (wrong) vma->vm_flags check
> > > in vm_mixed_zeropage_allowed() ?
> > 
> > I meant this page_count() here. As a quick test, I removed that check (also fixed
> > the vm_flags above) and the zero-page was properly mapped!
> 
> That's weird and might indicate another issue.
> 
> The refcount of the shared zeropage should be initialized to 1, just like
> for any other reserved pages
> (mm/mm_init.c:__init_single_page()->init_page_count())
> 
> Hm ...
> 
> -- 
> Cheers,
> 
> David / dhildenb
> 


  reply	other threads:[~2024-05-21 10:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-30 20:40 [PATCH v1 0/2] mm/memory: cleanly support zeropage in vm_insert_page*(), vm_map_pages*() and vmf_insert_mixed() David Hildenbrand
2024-04-30 20:40 ` [PATCH v1 1/2] " David Hildenbrand
2024-05-17 15:07   ` Vincent Donnefort
2024-05-21  8:25     ` David Hildenbrand
2024-05-21  9:06       ` Vincent Donnefort
2024-05-21  9:18         ` David Hildenbrand
2024-05-21 10:10           ` Vincent Donnefort [this message]
2024-04-30 20:40 ` [PATCH v1 2/2] mm/rmap: sanity check that zeropages are not passed to RMAP David Hildenbrand

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=ZkxzCJBihAddyb4D@google.com \
    --to=vdonnefort@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=dan.j.williams@intel.com \
    --cc=david@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=rostedt@goodmis.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).