All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Egger <Christoph.Egger@amd.com>
To: xen-devel@lists.xensource.com
Cc: Ian Campbell <ian.campbell@citrix.com>
Subject: Re: [PATCH 01 of 25] libxc: some xc_gnttab_* functions are not Linux specific
Date: Wed, 22 Dec 2010 15:34:13 +0100	[thread overview]
Message-ID: <201012221534.16652.Christoph.Egger@amd.com> (raw)
In-Reply-To: <7c6e87f167d47b2c0b85.1291370225@localhost.localdomain>


Successfully tested with NetBSD.
Acked-by: Christoph Egger <Christoph.Egger@amd.com>

On Friday 03 December 2010 10:57:05 Ian Campbell wrote:
> # HG changeset patch
> # User Ian Campbell <ian.campbell@citrix.com>
> # Date 1291369006 0
> # Node ID 7c6e87f167d47b2c0b850806d0e9fa298018ebd4
> # Parent  9a40ab7a4347e4c49785d079a598a1bc22477739
> libxc: some xc_gnttab_* functions are not Linux specific
>
> They simply make hypercalls and perform other operations via the
> abstract interface. Create xc_gnttab.c and move those functions there.
>
> Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
>
> diff -r 9a40ab7a4347 -r 7c6e87f167d4 tools/libxc/Makefile
> --- a/tools/libxc/Makefile      Fri Dec 03 09:36:46 2010 +0000
> +++ b/tools/libxc/Makefile      Fri Dec 03 09:36:46 2010 +0000
> @@ -11,6 +11,7 @@ CTRL_SRCS-y       += xc_cpupool.c
>  CTRL_SRCS-y       += xc_cpupool.c
>  CTRL_SRCS-y       += xc_domain.c
>  CTRL_SRCS-y       += xc_evtchn.c
> +CTRL_SRCS-y       += xc_gnttab.c
>  CTRL_SRCS-y       += xc_misc.c
>  CTRL_SRCS-y       += xc_acm.c
>  CTRL_SRCS-y       += xc_flask.c
> diff -r 9a40ab7a4347 -r 7c6e87f167d4 tools/libxc/xc_gnttab.c
> --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
> +++ b/tools/libxc/xc_gnttab.c   Fri Dec 03 09:36:46 2010 +0000
> @@ -0,0 +1,147 @@
> +/*************************************************************************
>***** + *
> + * Copyright (c) 2007-2008, D G Murray <Derek.Murray@cl.cam.ac.uk>
> + *
> + * 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 "xc_private.h"
> +
> +int xc_gnttab_op(xc_interface *xch, int cmd, void * op, int op_size, int
> count) +{
> +    int ret = 0;
> +    DECLARE_HYPERCALL;
> +    DECLARE_HYPERCALL_BOUNCE(op, count * op_size,
> XC_HYPERCALL_BUFFER_BOUNCE_BOTH); +
> +    if ( xc_hypercall_bounce_pre(xch, op) )
> +    {
> +        PERROR("Could not bounce buffer for grant table op hypercall");
> +        goto out1;
> +    }
> +
> +    hypercall.op = __HYPERVISOR_grant_table_op;
> +    hypercall.arg[0] = cmd;
> +    hypercall.arg[1] = HYPERCALL_BUFFER_AS_ARG(op);
> +    hypercall.arg[2] = count;
> +
> +    ret = do_xen_hypercall(xch, &hypercall);
> +
> +    xc_hypercall_bounce_post(xch, op);
> +
> + out1:
> +    return ret;
> +}
> +
> +int xc_gnttab_get_version(xc_interface *xch, int domid)
> +{
> +    struct gnttab_get_version query;
> +    int rc;
> +
> +    query.dom = domid;
> +    rc = xc_gnttab_op(xch, GNTTABOP_get_version, &query, sizeof(query),
> +                      1);
> +    if ( rc < 0 )
> +        return rc;
> +    else
> +        return query.version;
> +}
> +
> +static void *_gnttab_map_table(xc_interface *xch, int domid, int *gnt_num)
> +{
> +    int rc, i;
> +    struct gnttab_query_size query;
> +    struct gnttab_setup_table setup;
> +    DECLARE_HYPERCALL_BUFFER(unsigned long, frame_list);
> +    xen_pfn_t *pfn_list = NULL;
> +    grant_entry_v1_t *gnt = NULL;
> +
> +    if ( !gnt_num )
> +        return NULL;
> +
> +    query.dom = domid;
> +    rc = xc_gnttab_op(xch, GNTTABOP_query_size, &query, sizeof(query), 1);
> +
> +    if ( rc || (query.status != GNTST_okay) )
> +    {
> +        ERROR("Could not query dom's grant size\n", domid);
> +        return NULL;
> +    }
> +
> +    *gnt_num = query.nr_frames * (PAGE_SIZE / sizeof(grant_entry_v1_t) );
> +
> +    frame_list = xc_hypercall_buffer_alloc(xch, frame_list,
> query.nr_frames * sizeof(unsigned long)); +    if ( !frame_list )
> +    {
> +        ERROR("Could not allocate frame_list in xc_gnttab_map_table\n");
> +        return NULL;
> +    }
> +
> +    pfn_list = malloc(query.nr_frames * sizeof(xen_pfn_t));
> +    if ( !pfn_list )
> +    {
> +        ERROR("Could not allocate pfn_list in xc_gnttab_map_table\n");
> +        goto err;
> +    }
> +
> +    setup.dom = domid;
> +    setup.nr_frames = query.nr_frames;
> +    set_xen_guest_handle(setup.frame_list, frame_list);
> +
> +    /* XXX Any race with other setup_table hypercall? */
> +    rc = xc_gnttab_op(xch, GNTTABOP_setup_table, &setup, sizeof(setup),
> +                      1);
> +
> +    if ( rc || (setup.status != GNTST_okay) )
> +    {
> +        ERROR("Could not get grant table frame list\n");
> +        goto err;
> +    }
> +
> +    for ( i = 0; i < setup.nr_frames; i++ )
> +        pfn_list[i] = frame_list[i];
> +
> +    gnt = xc_map_foreign_pages(xch, domid, PROT_READ, pfn_list,
> +                               setup.nr_frames);
> +    if ( !gnt )
> +    {
> +        ERROR("Could not map grant table\n");
> +        goto err;
> +    }
> +
> +err:
> +    if ( frame_list )
> +        xc_hypercall_buffer_free(xch, frame_list);
> +    if ( pfn_list )
> +        free(pfn_list);
> +
> +    return gnt;
> +}
> +
> +grant_entry_v1_t *xc_gnttab_map_table_v1(xc_interface *xch, int domid,
> +                                         int *gnt_num)
> +{
> +    if (xc_gnttab_get_version(xch, domid) == 2)
> +        return NULL;
> +    return _gnttab_map_table(xch, domid, gnt_num);
> +}
> +
> +grant_entry_v2_t *xc_gnttab_map_table_v2(xc_interface *xch, int domid,
> +                                         int *gnt_num)
> +{
> +    if (xc_gnttab_get_version(xch, domid) != 2)
> +        return NULL;
> +    return _gnttab_map_table(xch, domid, gnt_num);
> +}
> +
> diff -r 9a40ab7a4347 -r 7c6e87f167d4 tools/libxc/xc_linux.c
> --- a/tools/libxc/xc_linux.c    Fri Dec 03 09:36:46 2010 +0000
> +++ b/tools/libxc/xc_linux.c    Fri Dec 03 09:36:46 2010 +0000
> @@ -608,132 +608,6 @@ int xc_gnttab_set_max_grants(xc_interfac
>      return 0;
>  }
>
> -int xc_gnttab_op(xc_interface *xch, int cmd, void * op, int op_size, int
> count) -{
> -    int ret = 0;
> -    DECLARE_HYPERCALL;
> -    DECLARE_HYPERCALL_BOUNCE(op, count * op_size,
> XC_HYPERCALL_BUFFER_BOUNCE_BOTH); -
> -    if ( xc_hypercall_bounce_pre(xch, op) )
> -    {
> -        PERROR("Could not bounce buffer for grant table op hypercall");
> -        goto out1;
> -    }
> -
> -    hypercall.op = __HYPERVISOR_grant_table_op;
> -    hypercall.arg[0] = cmd;
> -    hypercall.arg[1] = HYPERCALL_BUFFER_AS_ARG(op);
> -    hypercall.arg[2] = count;
> -
> -    ret = do_xen_hypercall(xch, &hypercall);
> -
> -    xc_hypercall_bounce_post(xch, op);
> -
> - out1:
> -    return ret;
> -}
> -
> -int xc_gnttab_get_version(xc_interface *xch, int domid)
> -{
> -    struct gnttab_get_version query;
> -    int rc;
> -
> -    query.dom = domid;
> -    rc = xc_gnttab_op(xch, GNTTABOP_get_version, &query, sizeof(query),
> -                      1);
> -    if ( rc < 0 )
> -        return rc;
> -    else
> -        return query.version;
> -}
> -
> -static void *_gnttab_map_table(xc_interface *xch, int domid, int *gnt_num)
> -{
> -    int rc, i;
> -    struct gnttab_query_size query;
> -    struct gnttab_setup_table setup;
> -    DECLARE_HYPERCALL_BUFFER(unsigned long, frame_list);
> -    xen_pfn_t *pfn_list = NULL;
> -    grant_entry_v1_t *gnt = NULL;
> -
> -    if ( !gnt_num )
> -        return NULL;
> -
> -    query.dom = domid;
> -    rc = xc_gnttab_op(xch, GNTTABOP_query_size, &query, sizeof(query), 1);
> -
> -    if ( rc || (query.status != GNTST_okay) )
> -    {
> -        ERROR("Could not query dom's grant size\n", domid);
> -        return NULL;
> -    }
> -
> -    *gnt_num = query.nr_frames * (PAGE_SIZE / sizeof(grant_entry_v1_t) );
> -
> -    frame_list = xc_hypercall_buffer_alloc(xch, frame_list,
> query.nr_frames * sizeof(unsigned long)); -    if ( !frame_list )
> -    {
> -        ERROR("Could not allocate frame_list in xc_gnttab_map_table\n");
> -        return NULL;
> -    }
> -
> -    pfn_list = malloc(query.nr_frames * sizeof(xen_pfn_t));
> -    if ( !pfn_list )
> -    {
> -        ERROR("Could not allocate pfn_list in xc_gnttab_map_table\n");
> -        goto err;
> -    }
> -
> -    setup.dom = domid;
> -    setup.nr_frames = query.nr_frames;
> -    set_xen_guest_handle(setup.frame_list, frame_list);
> -
> -    /* XXX Any race with other setup_table hypercall? */
> -    rc = xc_gnttab_op(xch, GNTTABOP_setup_table, &setup, sizeof(setup),
> -                      1);
> -
> -    if ( rc || (setup.status != GNTST_okay) )
> -    {
> -        ERROR("Could not get grant table frame list\n");
> -        goto err;
> -    }
> -
> -    for ( i = 0; i < setup.nr_frames; i++ )
> -        pfn_list[i] = frame_list[i];
> -
> -    gnt = xc_map_foreign_pages(xch, domid, PROT_READ, pfn_list,
> -                               setup.nr_frames);
> -    if ( !gnt )
> -    {
> -        ERROR("Could not map grant table\n");
> -        goto err;
> -    }
> -
> -err:
> -    if ( frame_list )
> -        xc_hypercall_buffer_free(xch, frame_list);
> -    if ( pfn_list )
> -        free(pfn_list);
> -
> -    return gnt;
> -}
> -
> -grant_entry_v1_t *xc_gnttab_map_table_v1(xc_interface *xch, int domid,
> -                                         int *gnt_num)
> -{
> -    if (xc_gnttab_get_version(xch, domid) == 2)
> -        return NULL;
> -    return _gnttab_map_table(xch, domid, gnt_num);
> -}
> -
> -grant_entry_v2_t *xc_gnttab_map_table_v2(xc_interface *xch, int domid,
> -                                         int *gnt_num)
> -{
> -    if (xc_gnttab_get_version(xch, domid) != 2)
> -        return NULL;
> -    return _gnttab_map_table(xch, domid, gnt_num);
> -}
> -
>  /*
>   * Local variables:
>   * mode: C
> diff -r 9a40ab7a4347 -r 7c6e87f167d4 tools/libxc/xc_minios.c
> --- a/tools/libxc/xc_minios.c   Fri Dec 03 09:36:46 2010 +0000
> +++ b/tools/libxc/xc_minios.c   Fri Dec 03 09:36:46 2010 +0000
> @@ -457,18 +457,6 @@ int xc_gnttab_set_max_grants(xc_interfac
>      return ret;
>  }
>
> -grant_entry_v1_t *xc_gnttab_map_table_v1(
> -    xc_interface *xch, int domid, int *gnt_num)
> -{
> -    return NULL;
> -}
> -
> -grant_entry_v2_t *xc_gnttab_map_table_v2(
> -    xc_interface *xch, int domid, int *gnt_num)
> -{
> -    return NULL;
> -}
> -
>  /*
>   * Local variables:
>   * mode: C
> diff -r 9a40ab7a4347 -r 7c6e87f167d4 tools/libxc/xc_netbsd.c
> --- a/tools/libxc/xc_netbsd.c   Fri Dec 03 09:36:46 2010 +0000
> +++ b/tools/libxc/xc_netbsd.c   Fri Dec 03 09:36:46 2010 +0000
> @@ -287,18 +287,6 @@ void discard_file_cache(xc_interface *xc
>      }
>  }
>
> -grant_entry_v1_t *xc_gnttab_map_table_v1(
> -    xc_interface *xch, int domid, int *gnt_num)
> -{
> -    return NULL;
> -}
> -
> -grant_entry_v2_t *xc_gnttab_map_table_v2(
> -    xc_interface *xch, int domid, int *gnt_num)
> -{
> -    return NULL;
> -}
> -
>  /*
>   * Local variables:
>   * mode: C
> diff -r 9a40ab7a4347 -r 7c6e87f167d4 tools/libxc/xc_solaris.c
> --- a/tools/libxc/xc_solaris.c  Fri Dec 03 09:36:46 2010 +0000
> +++ b/tools/libxc/xc_solaris.c  Fri Dec 03 09:36:46 2010 +0000
> @@ -261,15 +261,3 @@ void discard_file_cache(xc_interface *xc
>  {
>      // TODO: Implement for Solaris!
>  }
> -
> -grant_entry_v1_t *xc_gnttab_map_table_v1(
> -    xc_interface *xch, int domid, int *gnt_num)
> -{
> -    return NULL;
> -}
> -
> -grant_entry_v2_t *xc_gnttab_map_table_v2(
> -    xc_interface *xch, int domid, int *gnt_num)
> -{
> -    return NULL;
> -}
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xensource.com
> http://lists.xensource.com/xen-devel



-- 
---to satisfy European Law for business letters:
Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach b. Muenchen
Geschaeftsfuehrer: Alberto Bozzo, Andrew Bowd
Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632

  reply	other threads:[~2010-12-22 14:34 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-03  9:57 [PATCH 00 of 25] libxc: dom0 OS integration cleanup+abstraction Ian Campbell
2010-12-03  9:57 ` [PATCH 01 of 25] libxc: some xc_gnttab_* functions are not Linux specific Ian Campbell
2010-12-22 14:34   ` Christoph Egger [this message]
2010-12-23 15:51     ` Ian Jackson
2010-12-03  9:57 ` [PATCH 02 of 25] libxc: convert evtchn interfaces to use an opaque handle type Ian Campbell
2010-12-03  9:57 ` [PATCH 03 of 25] libxc: convert gnttab " Ian Campbell
2010-12-03  9:57 ` [PATCH 04 of 25] libxc: osdep: add framework for abstracting access to dom0 OS hypervisor interfaces Ian Campbell
2010-12-03  9:57 ` [PATCH 05 of 25] libxc: osdep: convert do_xen_hypercall() Ian Campbell
2010-12-03  9:57 ` [PATCH 06 of 25] libxc: osdep: convert xc_map_foreign_{batch, bulk} Ian Campbell
2010-12-03  9:57 ` [PATCH 07 of 25] libxc: osdep: convert xc_map_foreign_range() Ian Campbell
2010-12-03  9:57 ` [PATCH 08 of 25] libxc: osdep: convert xc_map_foreign_ranges() Ian Campbell
2010-12-03  9:57 ` [PATCH 09 of 25] libxc: osdep: convert xc_evtchn_fd() Ian Campbell
2010-12-03  9:57 ` [PATCH 10 of 25] libxc: osdep: convert xc_evtchn_notify() Ian Campbell
2010-12-03  9:57 ` [PATCH 11 of 25] libxc: osdep: convert xc_evtchn_bind_unbound_port() Ian Campbell
2010-12-03  9:57 ` [PATCH 12 of 25] libxc: osdep: convert xc_evtchn_bind_interdomain() Ian Campbell
2010-12-03  9:57 ` [PATCH 13 of 25] libxc: osdep: convert xc_evtchn_bind_virq() Ian Campbell
2010-12-03  9:57 ` [PATCH 14 of 25] libxc: osdep: convert xc_evtchn_unbind() Ian Campbell
2010-12-03  9:57 ` [PATCH 15 of 25] libxc: osdep: convert xc_evtchn_{pending, unmask}() Ian Campbell
2010-12-03  9:57 ` [PATCH 16 of 25] libxc: osdep: convert xc_gnttab_map_{grant_ref, grant_refs, domain_grant_refs}() Ian Campbell
2010-12-03  9:57 ` [PATCH 17 of 25] libxc: osdep: convert xc_gnttab_munmap() Ian Campbell
2010-12-03  9:57 ` [PATCH 18 of 25] libxc: osdep: convert xc_gnttab_set_max_grants() Ian Campbell
2010-12-03  9:57 ` [PATCH 19 of 25] libxc: add ability to query OS interface for "fakeness" Ian Campbell
2010-12-03  9:57 ` [PATCH 20 of 25] libxc: drop fd from xc_interface Ian Campbell
2010-12-03  9:57 ` [PATCH 21 of 25] libxc: allow osdep backends to log via the xc infrastructure Ian Campbell
2010-12-03  9:57 ` [PATCH 22 of 25] libxc: osdep: Use XC_PAGE_{SHIFT, MASK} Ian Campbell
2010-12-03  9:57 ` [PATCH 23 of 25] libxc: add abitility to dynamically load osdep Ian Campbell
2010-12-03  9:57 ` [PATCH 24 of 25] libxc: move foreign memory functions to xc_foreign_memory.c Ian Campbell
2010-12-03  9:57 ` [PATCH 25 of 25] libxc: refactor Linux OS interface into a separate file Ian Campbell
2010-12-03  9:57 ` [PATCH] qemu-xen: update for libxc evtchn interface change Ian Campbell
2010-12-03  9:57 ` [PATCH] qemu-xen: update for libxc gnttab " Ian Campbell

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=201012221534.16652.Christoph.Egger@amd.com \
    --to=christoph.egger@amd.com \
    --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.