linux-embedded.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Al Viro <viro@ZenIV.linux.org.uk>
To: Nicolas Pitre <nicolas.pitre@linaro.org>
Cc: linux-fsdevel@vger.kernel.org, linux-embedded@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Chris Brandt <Chris.Brandt@renesas.com>
Subject: Re: [PATCH v2 4/5] cramfs: add mmap support
Date: Mon, 28 Aug 2017 15:23:06 +0100	[thread overview]
Message-ID: <20170828142306.GJ5426@ZenIV.linux.org.uk> (raw)
In-Reply-To: <nycvar.YSQ.7.76.1708280914260.2606@knanqh.ubzr>

On Mon, Aug 28, 2017 at 09:29:58AM -0400, Nicolas Pitre wrote:
> > > +	/* Make sure the vma didn't change between the locks */
> > > +	vma = find_vma(mm, vmf->address);
> > > +	if (vma->vm_ops != &cramfs_vmasplit_ops) {
> > > +		/*
> > > +		 * Someone else raced with us and could have handled the fault.
> > > +		 * Let it go back to user space and fault again if necessary.
> > > +		 */
> > > +		downgrade_write(&mm->mmap_sem);
> > > +		return VM_FAULT_NOPAGE;
> > > +	}
> > > +
> > > +	/* Split the vma between the directly mapped area and the rest */
> > > +	ret = split_vma(mm, vma, split_addr, 0);
> > 
> > Egads...  Everything else aside, who said that your split_... will have
> > anything to do with the vma you get from find_vma()?
> 
> When vma->vm_ops == &cramfs_vmasplit_ops it is guaranteed that the vma 
> is not fully populated and that the unpopulated area starts at 
> split_addr. That split_addr was stored in vma->vm_private_data at the 
> same time as vma->vm_ops. Given that mm->mmap_sem is held all along 
> across find_vma(), split_vma() and the second find_vma() I hope that I 
> can trust that things will be related.

Huh?  You do realize that another thread might've been blocked on that ->mmap_sem
in mremap(), get it, have ours block on attempt to get ->mmap_sem exclusive,
exterminate the original vma and put there a vma that has also come from cramfs,
but other than that had not a damn thing in common with the original.  Different
memory area, etc.

Matching ->vm_ops is nowhere near enough.

While we are at it, what happens if you mmap 120Kb, then munmap() the middle
40Kb.  Leaving two 40Kb VMAs with 40Kb gap between them, that is.  Will your
->vm_private_data be correct for both?

  reply	other threads:[~2017-08-28 14:23 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-16 17:35 [PATCH v2 0/5] cramfs refresh for embedded usage Nicolas Pitre
2017-08-16 17:35 ` [PATCH v2 1/5] cramfs: direct memory access support Nicolas Pitre
2017-08-16 18:28   ` Chris Brandt
2017-08-16 19:44     ` Nicolas Pitre
2017-08-16 17:35 ` [PATCH v2 2/5] cramfs: make cramfs_physmem usable as root fs Nicolas Pitre
2017-08-16 17:35 ` [PATCH v2 3/5] cramfs: implement uncompressed and arbitrary data block positioning Nicolas Pitre
2017-08-16 18:28   ` Chris Brandt
2017-08-16 17:35 ` [PATCH v2 4/5] cramfs: add mmap support Nicolas Pitre
2017-08-16 18:28   ` Chris Brandt
2017-08-28  6:46   ` Al Viro
2017-08-28 13:29     ` Nicolas Pitre
2017-08-28 14:23       ` Al Viro [this message]
2017-08-28 19:17         ` Nicolas Pitre
2017-08-29 19:38           ` Chris Brandt
2017-08-29 20:00             ` Nicolas Pitre
2017-08-29 20:11               ` Chris Brandt
2017-08-31  2:29               ` Chris Brandt
2017-08-16 17:35 ` [PATCH v2 5/5] cramfs: rehabilitate it Nicolas Pitre
2017-08-31  2:30 ` [PATCH v2 0/5] cramfs refresh for embedded usage Chris Brandt
2017-08-31  3:03   ` Nicolas Pitre

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=20170828142306.GJ5426@ZenIV.linux.org.uk \
    --to=viro@zeniv.linux.org.uk \
    --cc=Chris.Brandt@renesas.com \
    --cc=linux-embedded@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nicolas.pitre@linaro.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).