All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeremy Fitzhardinge <jeremy@goop.org>
To: Ian Campbell <ian.campbell@citrix.com>
Cc: xen-devel@lists.xensource.com
Subject: Re: [PATCH 10 of 24] libxc: infrastructure for hypercall safe data buffers
Date: Tue, 07 Sep 2010 18:44:37 +1000	[thread overview]
Message-ID: <4C85FB75.9070905@goop.org> (raw)
In-Reply-To: <bf7fb64762eb7decea9a.1283780310@localhost.localdomain>

 On 09/06/2010 11:38 PM, Ian Campbell wrote:
> # HG changeset patch
> # User Ian Campbell <ian.campbell@citrix.com>
> # Date 1283779691 -3600
> # Node ID bf7fb64762eb7decea9a6804460f0f966496ba07
> # Parent  7b45202f78cd82d320fb32fea67c0a618697baec
> libxc: infrastructure for hypercall safe data buffers.
>
> Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
>
> diff -r 7b45202f78cd -r bf7fb64762eb tools/libxc/Makefile
> --- a/tools/libxc/Makefile	Mon Sep 06 14:28:11 2010 +0100
> +++ b/tools/libxc/Makefile	Mon Sep 06 14:28:11 2010 +0100
> @@ -27,6 +27,7 @@ CTRL_SRCS-y       += xc_mem_event.c
>  CTRL_SRCS-y       += xc_mem_event.c
>  CTRL_SRCS-y       += xc_mem_paging.c
>  CTRL_SRCS-y       += xc_memshr.c
> +CTRL_SRCS-y       += xc_hcall_buf.c
>  CTRL_SRCS-y       += xtl_core.c
>  CTRL_SRCS-y       += xtl_logger_stdio.c
>  CTRL_SRCS-$(CONFIG_X86) += xc_pagetab.c
> diff -r 7b45202f78cd -r bf7fb64762eb tools/libxc/xc_hcall_buf.c
> --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
> +++ b/tools/libxc/xc_hcall_buf.c	Mon Sep 06 14:28:11 2010 +0100
> @@ -0,0 +1,147 @@
> +/*
> + * Copyright (c) 2010, Citrix Systems, Inc.
> + *
> + * This library is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation;
> + * version 2.1 of the License.
> + *
> + * This library is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with this library; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
> + */
> +
> +#include <inttypes.h>
> +#include "xc_private.h"
> +#include "xg_private.h"
> +
> +DECLARE_NAMED_HYPERCALL_BUFFER(HYPERCALL_BUFFER_NULL);
> +
> +void *xc__hypercall_buffer_alloc_pages(xc_interface *xch, xc_hypercall_buffer_t *b, int nr_pages)
> +{
> +    size_t size = nr_pages * PAGE_SIZE;
> +    void *p;
> +#if defined(_POSIX_C_SOURCE) && !defined(__sun__)
> +    int ret;
> +    ret = posix_memalign(&p, PAGE_SIZE, size);
> +    if (ret != 0)
> +        return NULL;
> +#elif defined(__NetBSD__) || defined(__OpenBSD__)
> +    p = valloc(size);
> +#else
> +    p = memalign(PAGE_SIZE, size);
> +#endif
> +
> +    if (!p)
> +        return NULL;
> +
> +#ifndef __sun__
> +    if ( mlock(p, size) < 0 )
> +    {
> +        free(p);
> +        return NULL;
> +    }
> +#endif
> +
> +    b->hbuf = p;
> +
> +    memset(p, 0, size);
> +    return b->hbuf;
> +}
> +
> +void xc__hypercall_buffer_free_pages(xc_interface *xch, xc_hypercall_buffer_t *b, int nr_pages)
> +{
> +    if ( b->hbuf == NULL )
> +        return;
> +
> +#ifndef __sun__
> +    (void) munlock(b->hbuf, nr_pages * PAGE_SIZE);
> +#endif
> +
> +    free(b->hbuf);
> +}

How does this end up making the memory suitable for passing to Xen? 
Where does it get locked down in the non-__sun__ case?  And why just
__sun__ here?

Is there any way to make memory hypercall-safe with existing syscalls,
or does/will it end up copying from this memory into the kernel before
issuing the hypercall?  Or adding some other mechanism for pinning down
the pages?

    J

  reply	other threads:[~2010-09-07  8:44 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 [this message]
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
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=4C85FB75.9070905@goop.org \
    --to=jeremy@goop.org \
    --cc=ian.campbell@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.