All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeremy Fitzhardinge <jeremy@goop.org>
To: Ian Jackson <Ian.Jackson@eu.citrix.com>
Cc: Ian Campbell <Ian.Campbell@eu.citrix.com>,
	"xen-devel@lists.xensource.com" <xen-devel@lists.xensource.com>
Subject: Re: [PATCH 10 of 24] libxc: infrastructure for	hypercall safe data buffers
Date: Wed, 08 Sep 2010 09:31:58 +1000	[thread overview]
Message-ID: <4C86CB6E.2060605@goop.org> (raw)
In-Reply-To: <19590.29997.199583.59386@mariner.uk.xensource.com>

 On 09/08/2010 03:23 AM, Ian Jackson wrote:
> Ian and I discussed this extensively on IRC, during which conversation
> I became convinced that mlock() must do what we want.  Having read the
> code in the kernel I'm not not so sure.
>
> The ordinary userspace access functions are all written to cope with
> pagefaults and retry the access.  So userspace addresses are not in
> general valid in kernel mode even if you've called functions to try to
> test them.  It's not clear what mlock prevents; does it prevent NUMA
> page migration ?  If not then I think indeed the page could be made
> not present by one VCPU editing the page tables while another VCPU is
> entering the hypercall, so that the 2nd VCPU will get a spurious
> EFAULT.

As IanC said, the only thing mlock() guarantees is that accessing the
page won't cause a major fault - ie, need to go to disk to satisfy it. 
You can and will get minor faults on mlocked pages, as a result of the
pte being either non-present or RO.  It can be non-present as a result
of page migration (not necessarily NUMA migration, just defragging
kernel memory to make it possible to allocate higher-order pages), and
RO when doing page-dirtiness tracking.  And I think they can happen
concurrently on different vcpus, so you may end up with a hypercall
being able to start reading the memory, but then fail writing back the
results.

I think the only way to do this properly is to do ioctls out of kernel
memory rather than user process memory.  Perhaps the easiest way to do
this is add an mmap operation to privcmd which allocates a set of kernel
pages and maps them into the process memory, which it can then use as
its hypercall buffer.  The alternatives would be to copy the argument
memory into/out of kernel space around the call, or do some ad-hoc
pinning of pages around the call.  But if we can arrange for all
argument memory to come from a particular buffer, then its easier to
just make sure that buffer has the right properties.

> OTOH: there must be other things that work like Xen - what about user
> mode device drivers of various kinds ?  Do X servers not mlock memory
> and expect to be able to tell the video card to DMA to it ?  etc.
> I think if linux-kernel think that people haven't assumed that mlock()
> actually pins the page, they're mistaken - and it's likely to be not
> just us.

Not really - nothing much depends on keeping a page physically resident
and having a pte in a specific state.  DMA just cares about physical
residency, and you can't do usermode DMA without some way of also
getting the physical address of the page, which would mean you've
already got some kind of kernel driver.  And there would be no way to
make such DMA safe anyway (mlock wouldn't protect against a process
being killed, for example).

Trying to share memory via virtual addresses with an entity which is
entirely external to the kernel is just plain weird.

    J

  parent reply	other threads:[~2010-09-07 23:31 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-06 13:38 [PATCH 00 of 24] [RFC] libxc: hypercall buffers Ian Campbell
2010-09-06 13:38 ` [PATCH 01 of 24] xen: define raw version of set_xen_guest_handle Ian Campbell
2010-09-06 13:38 ` [PATCH 02 of 24] libxc: flask: use (un)lock pages rather than open coding m(un)lock Ian Campbell
2010-09-06 13:38 ` [PATCH 03 of 24] libxc: pass an xc_interface handle to page locking functions Ian Campbell
2010-09-06 13:38 ` [PATCH 04 of 24] libxc: Remove unnecessary double indirection from xc_readconsolering Ian Campbell
2010-09-06 13:38 ` [PATCH 05 of 24] libxc: use correct size of struct xen_mc Ian Campbell
2010-09-06 13:38 ` [PATCH 06 of 24] libxc: add to xc_domain_maximum_gpfn Ian Campbell
2010-09-06 13:38 ` [PATCH 07 of 24] libxc: replace open-coded use of XENMEM_decrease_reservation Ian Campbell
2010-09-06 13:38 ` [PATCH 08 of 24] libxc: simplify performance counters API Ian Campbell
2010-09-06 13:38 ` [PATCH 09 of 24] libxc: simplify lock profiling API Ian Campbell
2010-09-06 13:38 ` [PATCH 10 of 24] libxc: infrastructure for hypercall safe data buffers Ian Campbell
2010-09-07  8:44   ` Jeremy Fitzhardinge
2010-09-07  9:56     ` Ian Campbell
2010-09-07 17:23       ` Ian Jackson
2010-09-07 18:44         ` Ian Campbell
2010-09-07 23:31         ` Jeremy Fitzhardinge [this message]
2010-09-06 13:38 ` [PATCH 11 of 24] libxc: convert xc_version over to hypercall buffers Ian Campbell
2010-09-06 13:38 ` [PATCH 12 of 24] libxc: convert domctl interfaces " Ian Campbell
2010-09-06 13:38 ` [PATCH 13 of 24] libxc: convert shadow domctl interfaces and save/restore " Ian Campbell
2010-09-06 13:38 ` [PATCH 14 of 24] libxc: convert sysctl interfaces " Ian Campbell
2010-09-06 13:38 ` [PATCH 15 of 24] libxc: convert watchdog interface " Ian Campbell
2010-09-06 13:38 ` [PATCH 16 of 24] libxc: convert acm interfaces " Ian Campbell
2010-09-06 13:38 ` [PATCH 17 of 24] libxc: convert evtchn " Ian Campbell
2010-09-06 13:38 ` [PATCH 18 of 24] libxc: convert schedop " Ian Campbell
2010-09-06 13:38 ` [PATCH 19 of 24] libxc: convert physdevop interface " Ian Campbell
2010-09-06 13:38 ` [PATCH 20 of 24] libxc: convert flask interfaces " Ian Campbell
2010-09-06 13:38 ` [PATCH 21 of 24] libxc: convert hvmop " Ian Campbell
2010-09-06 13:38 ` [PATCH 22 of 24] libxc: convert mca interface " Ian Campbell
2010-09-06 13:38 ` [PATCH 23 of 24] libxc: convert tmem " Ian Campbell
2010-09-06 13:38 ` [PATCH 24 of 24] libxc: convert gnttab interfaces " Ian Campbell
2010-09-06 13:41 ` [PATCH 00 of 24] [RFC] libxc: " Ian Campbell
2010-09-07 16:35 ` Ian Jackson
2010-09-07 16:36   ` Ian Campbell
2010-09-07 17:28     ` Ian Jackson

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=4C86CB6E.2060605@goop.org \
    --to=jeremy@goop.org \
    --cc=Ian.Campbell@eu.citrix.com \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=xen-devel@lists.xensource.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.