mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hugh Dickins <hugh@veritas.com>
To: Roland Dreier <rdreier@cisco.com>
Cc: Andrew Morton <akpm@osdl.org>,
	"Bryan O'Sullivan" <bos@pathscale.com>,
	Alan Cox <alan@lxorguk.ukuu.org.uk>,
	torvalds@osdl.org, hch@infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: Remapping pages mapped to userspace (was: [PATCH 10 of 20] ipath - support for userspace apps using core driver)
Date: Fri, 17 Mar 2006 17:13:16 +0000 (GMT)	[thread overview]
Message-ID: <Pine.LNX.4.61.0603171631240.32660@goblin.wat.veritas.com> (raw)
In-Reply-To: <adad5gmne20.fsf_-_@cisco.com>

On Thu, 16 Mar 2006, Roland Dreier wrote:

> Anyway, I'd like to hijack this thread slightly, since we are close to
> a subject that I've been thinking about lately, and I'd like to take
> advantage of the expert's attention...

I look over my shoulder, ah yes, you're speaking to Alan, who's given
you a good reply.  But he's looking at it from a bus/driver perspective,
which I can't comment on, so I'll return to your original mail.

> My mthca driver (drivers/infiniband/hw/mthca) supports mapping some
> MMIO registers into userspace via io_remap_pfn_range() in a .mmap
> method.  I think I have that pretty well under control.
> 
> However, on a hot unplug event, when the underlying PCI device is
> going away, I would like to replace that mapping with a mapping (with
> a mapping to the zero page?), so that userspace accesses after the
> device is gone don't explode.  What's the "right" way to do that?

Nobody has asked for that before (so far as I know; or maybe I'm just
not looking at your question from the right angle), so I don't have
any canned right answer.

Sounds a reasonable thing to ask for, especially from the hotplug world.
But it's not how we've proceeded until now: things stay open until the
last user goes away, only then can the driver go away.

Thus a file remains open, and its filesystem busily mounted, until
the last user unmaps or closes it.

You seem to be asking to "revoke" an mmap: not unreasonable, but
we've never provided a revoke method before, and I fear there
might be gotchas.  Perhaps there's a different, more familiar
model I can feel more comfortable with...

Shall we look at it, instead, as like truncating a file?  You could
use vmtruncate, but you'll have nothing cached, so maybe just use
unmap_mapping_range (see mm/memory.c for args), which is also exported.
Only one caller on the inode(mapping) at once, please (on a regular
file, inode->i_sem is held; but that won't quite work with a device).

So far as I can see, that should work nicely (even, fortuitously,
despite Linus' special adjustment of vm_pgoff on VM_PFNMAP areas).
Though it looks like subsequent userspace accesses will then go to
do_anonymous_page, giving ZERO_PAGE to read faults or a fresh anon
page to write faults: I think I'd prefer it if pte_none accesses in
a VM_PFNMAP area gave SIGBUS, but unsure if we can change that now.

> Presumably it would be something like zeromap_page_range(), but that's
> not exported to modules.  Exporting that would be one option, but in a
> way that's overkill for me: I only have a single page to deal with, so
> I could also do something like
> 
> 	vm_insert_page(vma, addr, ZERO_PAGE(addr));
> 
> But do I have to do anything to kill the old mapping coming from
> remap_pfn_range()?  What's the exported API to do that?

vm_insert_page will fail with -EBUSY if there's something there
already; and though it looks as if it'll do the right thing with
ZERO_PAGE(addr) if the mapping was read-only, it'll very nastily
give write access to it if the mapping was read-write.

But I see no point in inserting pages there anyway: the important
part is removing the old ptes, which unmap_mapping_range should do.

> I can keep a list of vmas that have registers mapped to userspace and
> iterate through it on hot unplug.  The only question is what to do
> with those vmas.

unmap_mapping_range will work its own way through the prio_tree of
all vmas mapping your device: so I think it'll spare you some effort.

But it hasn't been used in this way before: I may be missing things.

Hugh

  parent reply	other threads:[~2006-03-17 17:12 UTC|newest]

Thread overview: 76+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <71644dd19420ddb07a75.1141922823@localhost.localdomain>
2006-03-09 23:28 ` [PATCH 10 of 20] ipath - support for userspace apps using core driver Roland Dreier
2006-03-09 23:55   ` Bryan O'Sullivan
2006-03-10  0:01     ` Roland Dreier
2006-03-10  0:07       ` Bryan O'Sullivan
2006-03-10  0:32         ` Roland Dreier
2006-03-10  0:36           ` Bryan O'Sullivan
2006-03-10  0:37         ` Andrew Morton
2006-03-10  0:50           ` Bryan O'Sullivan
2006-03-16  0:56           ` Bryan O'Sullivan
2006-03-16  1:51             ` Roland Dreier
2006-03-16  2:11               ` Bryan O'Sullivan
2006-03-16  2:37                 ` Roland Dreier
2006-03-16  2:52                   ` Bryan O'Sullivan
2006-03-16  2:56                     ` Bryan O'Sullivan
2006-03-16  3:28                     ` Andrew Morton
2006-03-16  4:58                       ` Bryan O'Sullivan
2006-03-16  5:38                         ` Andrew Morton
2006-03-16  5:54                           ` Roland Dreier
2006-03-16  6:17                             ` Andrew Morton
2006-03-16  6:44                               ` Nick Piggin
2006-03-16  9:39                                 ` Andrew Morton
2006-03-16 10:00                                   ` Nick Piggin
2006-03-16  7:25                               ` Roland Dreier
2006-03-16 16:46                                 ` Linus Torvalds
2006-03-16 14:57                               ` Hugh Dickins
2006-03-16  6:31                             ` Nick Piggin
2006-03-16 14:34                               ` Hugh Dickins
2006-03-17  0:37                                 ` Nick Piggin
2006-03-17  1:09                                   ` Roland Dreier
2006-03-17 15:27                                   ` Hugh Dickins
2006-03-17 22:21                                     ` Nick Piggin
2006-03-17 16:11                                   ` Bryan O'Sullivan
2006-03-17 16:28                                     ` Linus Torvalds
2006-03-17 16:40                                       ` Bryan O'Sullivan
2006-03-17 22:28                                         ` Nick Piggin
2006-03-17 22:14                                     ` Nick Piggin
2006-03-16 15:12                             ` Bryan O'Sullivan
2006-03-16 17:08                               ` Linus Torvalds
2006-03-16 17:46                               ` Hugh Dickins
2006-03-16 17:53                                 ` Bryan O'Sullivan
2006-03-16 14:24                           ` Hugh Dickins
2006-03-16 15:33                             ` Bryan O'Sullivan
2006-03-16 17:23                               ` Hugh Dickins
2006-03-16 17:40                                 ` Bryan O'Sullivan
2006-03-16 19:52                                 ` Bryan O'Sullivan
2006-03-16 20:10                                   ` Hugh Dickins
2006-03-16 20:35                                     ` Linus Torvalds
2006-03-16 20:43                                       ` Bryan O'Sullivan
2006-03-21 20:52                                     ` Bryan O'Sullivan
2006-03-21 23:20                                       ` Hugh Dickins
2006-03-22 15:58                                         ` Bryan O'Sullivan
2006-03-22 16:19                                           ` Linus Torvalds
2006-03-22 16:43                                             ` Bryan O'Sullivan
2006-03-22 17:46                                           ` Hugh Dickins
2006-03-22 17:53                                             ` Bryan O'Sullivan
2006-03-16 23:37                             ` Roland Dreier
2006-03-16 23:51                             ` Remapping pages mapped to userspace (was: [PATCH 10 of 20] ipath - support for userspace apps using core driver) Roland Dreier
2006-03-16 23:56                               ` Bryan O'Sullivan
2006-03-17  1:10                                 ` Remapping pages mapped to userspace Roland Dreier
2006-03-17  1:12                                 ` Roland Dreier
2006-03-17  1:28                                   ` Alan Cox
2006-03-17  2:16                                     ` Roland Dreier
2006-03-17 17:13                               ` Hugh Dickins [this message]
2006-03-17 17:17                                 ` Remapping pages mapped to userspace (was: [PATCH 10 of 20] ipath - support for userspace apps using core driver) Bryan O'Sullivan
2006-03-17 17:30                                   ` Linus Torvalds
2006-03-17 18:20                                     ` Hugh Dickins
2006-03-17 22:58                                     ` Remapping pages mapped to userspace Roland Dreier
2006-03-16 15:08                           ` [PATCH 10 of 20] ipath - support for userspace apps using core driver Bryan O'Sullivan
2006-03-16 17:27                             ` Hugh Dickins
2006-03-16 17:44                               ` Bryan O'Sullivan
2006-03-16 16:52                           ` Bryan O'Sullivan
2006-03-16  3:58                     ` Linus Torvalds
2006-03-16  4:53                     ` Roland Dreier
2006-03-16  2:28             ` Linus Torvalds
2006-03-09 23:33 ` Roland Dreier
2006-03-09 23:56   ` Bryan O'Sullivan

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=Pine.LNX.4.61.0603171631240.32660@goblin.wat.veritas.com \
    --to=hugh@veritas.com \
    --cc=akpm@osdl.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=bos@pathscale.com \
    --cc=hch@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rdreier@cisco.com \
    --cc=torvalds@osdl.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

all inboxes | Powered by JetHome®