linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Juergen Gross <jgross@suse.com>
To: Souptick Joarder <jrdr.linux@gmail.com>,
	marmarek@invisiblethingslab.com, sstabellini@kernel.org,
	boris.ostrovsky@oracle.com
Cc: linux@armlinux.org.uk, willy@infradead.org, linux-mm@kvack.org,
	akpm@linux-foundation.org, gregkh@linuxfoundation.org,
	xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH] xen/gntdev.c: Replace vm_map_pages() with vm_map_pages_zero()
Date: Wed, 31 Jul 2019 08:15:37 +0200	[thread overview]
Message-ID: <436440f5-0031-5ad5-4a22-2acf218ad727@suse.com> (raw)
In-Reply-To: <1564511696-4044-1-git-send-email-jrdr.linux@gmail.com>

On 30.07.19 20:34, Souptick Joarder wrote:
> 'commit df9bde015a72 ("xen/gntdev.c: convert to use vm_map_pages()")'
> breaks gntdev driver. If vma->vm_pgoff > 0, vm_map_pages()
> will:
>   - use map->pages starting at vma->vm_pgoff instead of 0
>   - verify map->count against vma_pages()+vma->vm_pgoff instead of just
>     vma_pages().
> 
> In practice, this breaks using a single gntdev FD for mapping multiple
> grants.
> 
> relevant strace output:
> [pid   857] ioctl(7, IOCTL_GNTDEV_MAP_GRANT_REF, 0x7ffd3407b6d0) = 0
> [pid   857] mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, 7, 0) =
> 0x777f1211b000
> [pid   857] ioctl(7, IOCTL_GNTDEV_SET_UNMAP_NOTIFY, 0x7ffd3407b710) = 0
> [pid   857] ioctl(7, IOCTL_GNTDEV_MAP_GRANT_REF, 0x7ffd3407b6d0) = 0
> [pid   857] mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, 7,
> 0x1000) = -1 ENXIO (No such device or address)
> 
> details here:
> https://github.com/QubesOS/qubes-issues/issues/5199
> 
> The reason is -> ( copying Marek's word from discussion)
> 
> vma->vm_pgoff is used as index passed to gntdev_find_map_index. It's
> basically using this parameter for "which grant reference to map".
> map struct returned by gntdev_find_map_index() describes just the pages
> to be mapped. Specifically map->pages[0] should be mapped at
> vma->vm_start, not vma->vm_start+vma->vm_pgoff*PAGE_SIZE.
> 
> When trying to map grant with index (aka vma->vm_pgoff) > 1,
> __vm_map_pages() will refuse to map it because it will expect map->count
> to be at least vma_pages(vma)+vma->vm_pgoff, while it is exactly
> vma_pages(vma).
> 
> Converting vm_map_pages() to use vm_map_pages_zero() will fix the
> problem.
> 
> Marek has tested and confirmed the same.
> 
> Reported-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
> Signed-off-by: Souptick Joarder <jrdr.linux@gmail.com>
> Tested-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>

Pushed to xen/tip.git for-linus-5.3a


Juergen


      parent reply	other threads:[~2019-07-31  6:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-30 18:34 [PATCH] xen/gntdev.c: Replace vm_map_pages() with vm_map_pages_zero() Souptick Joarder
2019-07-30 19:56 ` Boris Ostrovsky
2019-07-31  6:15 ` Juergen Gross [this message]

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=436440f5-0031-5ad5-4a22-2acf218ad727@suse.com \
    --to=jgross@suse.com \
    --cc=akpm@linux-foundation.org \
    --cc=boris.ostrovsky@oracle.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jrdr.linux@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux@armlinux.org.uk \
    --cc=marmarek@invisiblethingslab.com \
    --cc=sstabellini@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=willy@infradead.org \
    --cc=xen-devel@lists.xenproject.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).