xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Dongxiao Xu <dongxiao.xu@intel.com>
To: xen-devel@lists.xen.org
Cc: keir@xen.org, Ian.Campbell@citrix.com,
	stefano.stabellini@eu.citrix.com, George.Dunlap@eu.citrix.com,
	andrew.cooper3@citrix.com, Ian.Jackson@eu.citrix.com,
	JBeulich@suse.com, dgdegra@tycho.nsa.gov
Subject: [PATCH v13 03/10] tools: provide interface for generic resource access
Date: Mon,  4 Aug 2014 10:16:59 +0800	[thread overview]
Message-ID: <1407118626-76843-4-git-send-email-dongxiao.xu@intel.com> (raw)
In-Reply-To: <1407118626-76843-1-git-send-email-dongxiao.xu@intel.com>

Xen added a new platform_op hypercall for generic MSR access, and this
is the the tool side change to wrapper the hypercall into xc APIs.

Signed-off-by: Dongxiao Xu <dongxiao.xu@intel.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
---
 tools/libxc/Makefile      |  1 +
 tools/libxc/xc_private.h  | 31 +++++++++++++++++++++++++++
 tools/libxc/xc_resource.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++
 tools/libxc/xenctrl.h     |  5 +++++
 4 files changed, 90 insertions(+)
 create mode 100644 tools/libxc/xc_resource.c

diff --git a/tools/libxc/Makefile b/tools/libxc/Makefile
index 22eef8e..92ac227 100644
--- a/tools/libxc/Makefile
+++ b/tools/libxc/Makefile
@@ -34,6 +34,7 @@ CTRL_SRCS-y       += xc_foreign_memory.c
 CTRL_SRCS-y       += xc_kexec.c
 CTRL_SRCS-y       += xtl_core.c
 CTRL_SRCS-y       += xtl_logger_stdio.c
+CTRL_SRCS-y       += xc_resource.c
 CTRL_SRCS-$(CONFIG_X86) += xc_pagetab.c
 CTRL_SRCS-$(CONFIG_Linux) += xc_linux.c xc_linux_osdep.c
 CTRL_SRCS-$(CONFIG_FreeBSD) += xc_freebsd.c xc_freebsd_osdep.c
diff --git a/tools/libxc/xc_private.h b/tools/libxc/xc_private.h
index c50a7c9..716affd 100644
--- a/tools/libxc/xc_private.h
+++ b/tools/libxc/xc_private.h
@@ -46,6 +46,7 @@
 #define DECLARE_SYSCTL struct xen_sysctl sysctl
 #define DECLARE_PHYSDEV_OP struct physdev_op physdev_op
 #define DECLARE_FLASK_OP struct xen_flask_op op
+#define DECLARE_PLATFORM_OP struct xen_platform_op platform_op
 
 #undef PAGE_SHIFT
 #undef PAGE_SIZE
@@ -310,6 +311,36 @@ static inline int do_sysctl(xc_interface *xch, struct xen_sysctl *sysctl)
     return ret;
 }
 
+static inline int do_platform_op(xc_interface *xch,
+                                 struct xen_platform_op *platform_op)
+{
+    int ret = -1;
+    DECLARE_HYPERCALL;
+    DECLARE_HYPERCALL_BOUNCE(platform_op, sizeof(*platform_op),
+                             XC_HYPERCALL_BUFFER_BOUNCE_BOTH);
+
+    platform_op->interface_version = XENPF_INTERFACE_VERSION;
+
+    if ( xc_hypercall_bounce_pre(xch, platform_op) )
+    {
+        PERROR("Could not bounce buffer for platform_op hypercall");
+        goto out1;
+    }
+
+    hypercall.op     = __HYPERVISOR_platform_op;
+    hypercall.arg[0] = HYPERCALL_BUFFER_AS_ARG(platform_op);
+    if ( (ret = do_xen_hypercall(xch, &hypercall)) < 0 )
+    {
+        if ( errno == EACCES )
+            DPRINTF("platform operation failed -- need to"
+                    " rebuild the user-space tool set?\n");
+    }
+
+    xc_hypercall_bounce_post(xch, platform_op);
+ out1:
+    return ret;
+}
+
 int do_memory_op(xc_interface *xch, int cmd, void *arg, size_t len);
 
 void *xc_map_foreign_ranges(xc_interface *xch, uint32_t dom,
diff --git a/tools/libxc/xc_resource.c b/tools/libxc/xc_resource.c
new file mode 100644
index 0000000..bfecfdd
--- /dev/null
+++ b/tools/libxc/xc_resource.c
@@ -0,0 +1,53 @@
+/*
+ * xc_resource.c
+ *
+ * Generic resource access API
+ *
+ * Copyright (C) 2014      Intel Corporation
+ * Author Dongxiao Xu <dongxiao.xu@intel.com>
+ *
+ * This program 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 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program 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.
+ */
+
+#include "xc_private.h"
+
+int xc_resource_op(xc_interface *xch, uint32_t nr, uint32_t type,
+                   xc_resource_data_t *data)
+{
+    int rc;
+    DECLARE_PLATFORM_OP;
+    DECLARE_HYPERCALL_BOUNCE(data, nr * sizeof(*data),
+                             XC_HYPERCALL_BUFFER_BOUNCE_BOTH);
+
+    if ( xc_hypercall_bounce_pre(xch, data) )
+        return -1;
+
+    platform_op.cmd = XENPF_resource_op;
+    platform_op.u.resource_op.nr = nr;
+    platform_op.u.resource_op.type = type;
+    set_xen_guest_handle(platform_op.u.resource_op.data, data);
+
+    rc = do_platform_op(xch, &platform_op);
+
+    xc_hypercall_bounce_post(xch, data);
+
+    return rc;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/tools/libxc/xenctrl.h b/tools/libxc/xenctrl.h
index 5beb846..cb3ac70 100644
--- a/tools/libxc/xenctrl.h
+++ b/tools/libxc/xenctrl.h
@@ -47,6 +47,7 @@
 #include <xen/xsm/flask_op.h>
 #include <xen/tmem.h>
 #include <xen/kexec.h>
+#include <xen/platform.h>
 
 #include "xentoollog.h"
 
@@ -2643,6 +2644,10 @@ int xc_kexec_load(xc_interface *xch, uint8_t type, uint16_t arch,
  */
 int xc_kexec_unload(xc_interface *xch, int type);
 
+typedef xenpf_resource_data_t xc_resource_data_t;
+int xc_resource_op(xc_interface *xch, uint32_t nr,
+    uint32_t type, xc_resource_data_t *data);
+
 #endif /* XENCTRL_H */
 
 /*
-- 
1.8.1.5

  parent reply	other threads:[~2014-08-04  2:16 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-04  2:16 [PATCH v13 00/10] enable Cache QoS Monitoring (CQM) feature Dongxiao Xu
2014-08-04  2:16 ` [PATCH v13 01/10] x86: add generic resource (e.g. MSR) access hypercall Dongxiao Xu
2014-08-04 11:07   ` Jan Beulich
2014-08-04  2:16 ` [PATCH v13 02/10] xsm: add resource operation related xsm policy Dongxiao Xu
2014-08-04  2:16 ` Dongxiao Xu [this message]
2014-08-04  2:17 ` [PATCH v13 04/10] x86: detect and initialize Platform QoS Monitoring feature Dongxiao Xu
2014-08-04 11:19   ` Jan Beulich
2014-08-04  2:17 ` [PATCH v13 05/10] x86: dynamically attach/detach QoS monitoring service for a guest Dongxiao Xu
2014-08-04  9:38   ` Andrew Cooper
2014-08-04 11:23   ` Jan Beulich
2014-08-04  2:17 ` [PATCH v13 06/10] x86: collect global QoS monitoring information Dongxiao Xu
2014-08-04 11:31   ` Jan Beulich
2014-08-04 11:34   ` Jan Beulich
2014-08-04  2:17 ` [PATCH v13 07/10] x86: enable QoS monitoring for each domain RMID Dongxiao Xu
2014-08-04  9:44   ` Andrew Cooper
2014-08-04 11:33   ` Jan Beulich
2014-08-04  2:17 ` [PATCH v13 08/10] x86: add QoS monitoring related MSRs in allowed list Dongxiao Xu
2014-08-04  2:17 ` [PATCH v13 09/10] xsm: add platform QoS related xsm policies Dongxiao Xu
2014-08-04  2:17 ` [PATCH v13 10/10] tools: CMDs and APIs for Platform QoS Monitoring Dongxiao Xu
2014-08-04 10:29 ` [PATCH v13 00/10] enable Cache QoS Monitoring (CQM) feature Jan Beulich

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=1407118626-76843-4-git-send-email-dongxiao.xu@intel.com \
    --to=dongxiao.xu@intel.com \
    --cc=George.Dunlap@eu.citrix.com \
    --cc=Ian.Campbell@citrix.com \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=JBeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=dgdegra@tycho.nsa.gov \
    --cc=keir@xen.org \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=xen-devel@lists.xen.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;
as well as URLs for NNTP newsgroup(s).