All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bhupinder Thakur <bhupinder.thakur@linaro.org>
To: xen-devel@lists.xenproject.org
Cc: Wei Liu <wei.liu2@citrix.com>,
	Julien Grall <julien.grall@arm.com>,
	Stefano Stabellini <sstabellini@kernel.org>,
	Ian Jackson <ian.jackson@eu.citrix.com>
Subject: [PATCH 02/10] xen/arm: vpl011: Add new virtual console hvm params in Xen
Date: Mon,  3 Apr 2017 15:14:25 +0530	[thread overview]
Message-ID: <1491212673-13476-3-git-send-email-bhupinder.thakur@linaro.org> (raw)
In-Reply-To: <1491212673-13476-1-git-send-email-bhupinder.thakur@linaro.org>

1. Add two new HVM param handlers for:
    - Allocate a new event channel for sending/receiving events to/from Xen.
    - Map the PFN allocted by the toolstack to be used as IN/OUT ring buffers.

2. Add validation to disallow get/set of these HVM params from guest
domain.

Xen will communicate with xenconsole over the ring buffer and the event
channel to transmit and receive pl011 data on guest domain's behalf.

Signed-off-by: Bhupinder Thakur <bhupinder.thakur@linaro.org>
---
 xen/arch/arm/hvm.c              | 112 ++++++++++++++++++++++++++++++++++++++++
 xen/include/public/hvm/params.h |  10 ++++
 2 files changed, 122 insertions(+)

diff --git a/xen/arch/arm/hvm.c b/xen/arch/arm/hvm.c
index d999bde..c1fed45 100644
--- a/xen/arch/arm/hvm.c
+++ b/xen/arch/arm/hvm.c
@@ -23,6 +23,8 @@
 #include <xen/guest_access.h>
 #include <xen/sched.h>
 #include <xen/monitor.h>
+#include <xen/event.h>
+#include <xen/vmap.h>
 
 #include <xsm/xsm.h>
 
@@ -31,6 +33,80 @@
 #include <public/hvm/hvm_op.h>
 
 #include <asm/hypercall.h>
+#include <xen/vpl011.h>
+
+static bool vpl011_built(void)
+{
+#ifdef CONFIG_VPL011_CONSOLE
+	return true;
+#else
+	return false;
+#endif
+}
+
+static int hvm_allow_set_param(struct domain *d,
+                               const struct xen_hvm_param *a)
+{
+    uint64_t value = d->arch.hvm_domain.params[a->index];
+    int rc;
+
+    rc = xsm_hvm_param(XSM_TARGET, d, HVMOP_set_param);
+    if ( rc )
+        return rc;
+
+    switch ( a->index )
+    {
+    /* The following parameters should not be set by the guest. */
+    case HVM_PARAM_VCONSOLE_PFN:
+    case HVM_PARAM_VCONSOLE_EVTCHN:
+        if ( d == current->domain )
+            rc = -EPERM;
+        break;
+    default:
+        break;
+    }
+
+    if ( rc )
+        return rc;
+
+    switch ( a->index )
+    {
+    /* The following parameters should only be changed once. */
+    case HVM_PARAM_VCONSOLE_PFN:
+    case HVM_PARAM_VCONSOLE_EVTCHN:
+        if ( value != 0 && a->value != value )
+            rc = -EEXIST;
+        break;
+    default:
+        break;
+    }
+
+    return rc;
+}
+
+static int hvm_allow_get_param(struct domain *d,
+                               const struct xen_hvm_param *a)
+{
+    int rc;
+
+    rc = xsm_hvm_param(XSM_TARGET, d, HVMOP_get_param);
+    if ( rc )
+        return rc;
+
+    switch ( a->index )
+    {
+    /* The remaining parameters should not be read by the guest. */
+    case HVM_PARAM_VCONSOLE_PFN:
+    case HVM_PARAM_VCONSOLE_EVTCHN:
+        if ( d == current->domain )
+            rc = -EPERM;
+        break;
+    default:
+        break;
+    }
+
+    return rc;
+}
 
 long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg)
 {
@@ -61,9 +137,45 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg)
         if ( op == HVMOP_set_param )
         {
             d->arch.hvm_domain.params[a.index] = a.value;
+
+            if ( a.index == HVM_PARAM_VCONSOLE_PFN ||
+                 a.index == HVM_PARAM_VCONSOLE_EVTCHN )
+            {
+				if ( vpl011_built() )
+				{
+                    rc = hvm_allow_set_param(d, &a);
+                    if ( rc )
+                        goto param_fail;
+
+					if ( a.index == HVM_PARAM_VCONSOLE_PFN )
+					{
+						rc = vpl011_map_guest_page(d);
+						if ( rc )
+							goto param_fail;
+					}
+				}
+				else
+				{
+					rc = -1;
+					goto param_fail;
+				}
+            }
         }
         else
         {
+            if ( a.index == HVM_PARAM_VCONSOLE_PFN ||
+                 a.index == HVM_PARAM_VCONSOLE_EVTCHN )
+            {
+				if ( !vpl011_built() )
+				{
+					rc = -1;
+					goto param_fail;
+				}
+            }
+            rc = hvm_allow_get_param(d, &a);
+            if ( rc )
+                goto param_fail;
+
             a.value = d->arch.hvm_domain.params[a.index];
             rc = copy_to_guest(arg, &a, 1) ? -EFAULT : 0;
         }
diff --git a/xen/include/public/hvm/params.h b/xen/include/public/hvm/params.h
index 3f54a49..15d37e5 100644
--- a/xen/include/public/hvm/params.h
+++ b/xen/include/public/hvm/params.h
@@ -203,10 +203,20 @@
  */
 #define HVM_PARAM_ACPI_IOPORTS_LOCATION 19
 
+#if defined(__arm__) || defined(__aarch64__)
+/* Virtual console (VC) shared memory ring and event channel. */
+#define HVM_PARAM_VCONSOLE_PFN    20
+#define HVM_PARAM_VCONSOLE_EVTCHN 21
+#else
 /* Deprecated */
 #define HVM_PARAM_MEMORY_EVENT_CR0          20
 #define HVM_PARAM_MEMORY_EVENT_CR3          21
+#endif
+
+/* Deprecated */
 #define HVM_PARAM_MEMORY_EVENT_CR4          22
+
+/* Deprecated */
 #define HVM_PARAM_MEMORY_EVENT_INT3         23
 #define HVM_PARAM_MEMORY_EVENT_SINGLE_STEP  25
 #define HVM_PARAM_MEMORY_EVENT_MSR          30
-- 
2.7.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  parent reply	other threads:[~2017-04-03  9:45 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-03  9:44 [PATCH 00/10] pl011 emulation support in Xen Bhupinder Thakur
2017-04-03  9:44 ` [PATCH 01/10] xen/arm: vpl011: Add pl011 uart emulation " Bhupinder Thakur
2017-04-12 16:32   ` Wei Liu
2017-04-19  0:15   ` Stefano Stabellini
2017-04-19  7:28     ` Bhupinder Thakur
2017-04-19  8:36       ` Julien Grall
2017-04-19 18:40       ` Stefano Stabellini
2017-04-25  7:31         ` Bhupinder Thakur
2017-04-25 17:56           ` Stefano Stabellini
2017-04-26  7:49             ` Bhupinder Thakur
2017-04-26  8:13               ` Julien Grall
2017-04-26 17:03                 ` Stefano Stabellini
2017-04-03  9:44 ` Bhupinder Thakur [this message]
2017-04-19  0:22   ` [PATCH 02/10] xen/arm: vpl011: Add new virtual console hvm params " Stefano Stabellini
2017-04-19  8:48     ` Bhupinder Thakur
2017-04-03  9:44 ` [PATCH 03/10] xen/arm: vpl011: Enable pl011 emulation for a guest domain " Bhupinder Thakur
2017-04-19  0:27   ` Stefano Stabellini
2017-04-03  9:44 ` [PATCH 04/10] xen/arm: vpl011: Provide a knob in libxl to enable/disable pl011 emulation Bhupinder Thakur
2017-04-12 16:32   ` Wei Liu
2017-04-13  8:19     ` Bhupinder Thakur
2017-04-13  8:37       ` Wei Liu
2017-04-19  0:29         ` Stefano Stabellini
2017-04-19  9:17           ` Bhupinder Thakur
2017-04-19 10:25             ` Wei Liu
2017-04-19 11:06               ` Julien Grall
2017-04-03  9:44 ` [PATCH 05/10] xen/arm: vpl011: Allocate a new PFN in the toolstack for the virtual console Bhupinder Thakur
2017-04-12 16:33   ` Wei Liu
2017-04-13  8:37     ` Bhupinder Thakur
2017-04-13  8:53       ` Wei Liu
2017-04-19  0:36         ` Stefano Stabellini
2017-04-19 10:28           ` Wei Liu
2017-04-19 11:01             ` Julien Grall
2017-04-19 13:05               ` Bhupinder Thakur
2017-04-19 13:35                 ` Julien Grall
2017-04-03  9:44 ` [PATCH 06/10] xen/arm: vpl011: Add new parameters to xenstore " Bhupinder Thakur
2017-04-12 16:32   ` Wei Liu
2017-04-25 10:18     ` Bhupinder Thakur
2017-04-25 11:55       ` Wei Liu
2017-04-19 18:58   ` Stefano Stabellini
2017-04-03  9:44 ` [PATCH 07/10] xen/arm: vpl011: Add a new console type to domain structure in xenconsole Bhupinder Thakur
2017-04-12 16:33   ` Wei Liu
2017-04-13  9:49     ` Bhupinder Thakur
2017-04-19 19:09   ` Stefano Stabellini
2017-04-03  9:44 ` [PATCH 08/10] xen/arm: vpl011: Modify the APIs in xenconsole to acces both PV and VCON consoles Bhupinder Thakur
2017-04-12 16:33   ` Wei Liu
2017-04-24 14:52     ` Bhupinder Thakur
2017-04-03  9:44 ` [PATCH 09/10] xen/arm: vpl011: Add new virtual console to xenconsole client Bhupinder Thakur
2017-04-19 18:55   ` Stefano Stabellini
2017-04-03  9:44 ` [PATCH 10/10] xen/arm: vpl011: Add a pl011 uart DT node in the guest device tree Bhupinder Thakur
2017-04-19 18:53   ` Stefano Stabellini
2017-04-20 12:47 ` [PATCH 00/10] pl011 emulation support in Xen Julien Grall
2017-04-26 15:21   ` Bhupinder Thakur
2017-04-26 17:09     ` Stefano Stabellini

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=1491212673-13476-3-git-send-email-bhupinder.thakur@linaro.org \
    --to=bhupinder.thakur@linaro.org \
    --cc=ian.jackson@eu.citrix.com \
    --cc=julien.grall@arm.com \
    --cc=sstabellini@kernel.org \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xenproject.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 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.