From: Arnd Bergmann <arnd@arndb.de>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Clemens Ladisch <clemens@ladisch.de>,
Takashi Iwai <tiwai@suse.de>,
Mauro Carvalho Chehab <mchehab@redhat.com>
Subject: Re: Device driver memory 'mmap()' function helper cleanup
Date: Wed, 17 Apr 2013 23:28:00 +0200 [thread overview]
Message-ID: <201304172328.01071.arnd@arndb.de> (raw)
In-Reply-To: <CA+55aFxuLZ5Y2qLtn5=MXNF7oiuTK3ZuQhAjWPPb1wrd6D7sZw@mail.gmail.com>
On Wednesday 17 April 2013, Linus Torvalds wrote:
> Not the way things are now.
>
> vm_iomap_memory() actually allows non-page-aligned things to be
> mapped, with the assumption that the user will then know about the
> internal offsets.
>
> The reason for that is questionable, but that's how pretty much
> every single user I've seen has worked, throwing the low bits of the
> physical away (after adding them to the length of the area).
There is a separate check for the physical address that gets
mapped in hpet_mmap:
if (addr & (PAGE_SIZE - 1))
return -ENOSYS;
We cannot remove that without changing the semantics of this function,
but the check that I mentioned:
if (((vma->vm_end - vma->vm_start) != PAGE_SIZE) || vma->vm_pgoff)
return -EINVAL;
is for the virtual address. All of vm_start, vm_end and vm_pgoff
are guaranteed to be page-aligned through previous checks or
shifts, and we have also checked that the size is non-zero.
Since we pass a hardcoded len=PAGE_SIZE into vm_iomap_memory, that will
return -EINVAL for any non-zero vma->vm_pgoff. Testing ((vma->vm_end -
vma->vm_start) != PAGE_SIZE) is redundant as well, because we know it
is a positive multiple of PAGE_SIZE because of the call chain leading
up to this function, and vm_iomap_memory() ensures that it can not
be more than len, which leaves PAGE_SIZE as the only possible value
not resulting in -EINVAL without the extra check.
> It may be that I should have done things differently: make the normal
> helper function verify page alignment, and warn if it's missing. Then,
> we could have a "vm_unaligned_iomap_memory()" that would just do the
> "extend to aligned pages" that people could convert any odd users for.
> That would probably be a good thing to do, but it would be separate
> "phase two" from the "let's start using the sane helper".
Makes sense, but I think this is independent of the observation I made
regarding the checks for the vma.
Arnd
next prev parent reply other threads:[~2013-04-17 21:28 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-17 3:12 Device driver memory 'mmap()' function helper cleanup Linus Torvalds
2013-04-17 7:20 ` Takashi Iwai
2013-04-17 9:15 ` Arnd Bergmann
2013-04-17 9:45 ` Clemens Ladisch
2013-04-17 17:58 ` Linus Torvalds
2013-04-17 21:28 ` Arnd Bergmann [this message]
2013-04-17 21:31 ` Linus Torvalds
2013-04-17 10:43 ` Mauro Carvalho Chehab
2013-04-17 12:22 ` [PATCH 1/2] [media] videobuf-dma-contig: remove support for cached mem Mauro Carvalho Chehab
2013-04-17 12:22 ` [PATCH 2/2] [media] videobuf-dma-contig: use vm_iomap_memory() Mauro Carvalho Chehab
2013-04-17 12:56 ` Mauro Carvalho Chehab
2013-04-17 12:49 ` [PATCH 1/2] [media] videobuf-dma-contig: remove support for cached mem Hans Verkuil
2013-05-12 21:52 ` Device driver memory 'mmap()' function helper cleanup Sakari Ailus
2013-04-17 11:34 ` Tomi Valkeinen
2013-04-17 14:44 ` Linus Torvalds
2013-04-17 17:11 ` David Miller
2013-04-17 17:20 ` Linus Torvalds
2013-04-17 17:27 ` David Miller
2013-04-17 17:48 ` Linus Torvalds
2013-04-19 15:43 ` Michel Lespinasse
2013-04-19 23:07 ` Linus Torvalds
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=201304172328.01071.arnd@arndb.de \
--to=arnd@arndb.de \
--cc=clemens@ladisch.de \
--cc=linux-kernel@vger.kernel.org \
--cc=mchehab@redhat.com \
--cc=tiwai@suse.de \
--cc=torvalds@linux-foundation.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