From patchwork Mon Apr 3 09:44:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bhupinder Thakur X-Patchwork-Id: 9659163 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 90FEF60353 for ; Mon, 3 Apr 2017 09:47:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 79D2E26E39 for ; Mon, 3 Apr 2017 09:47:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6C7C327EED; Mon, 3 Apr 2017 09:47:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RCVD_IN_SORBS_SPAM,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0A2A520572 for ; Mon, 3 Apr 2017 09:47:26 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cuyXt-0001UQ-SG; Mon, 03 Apr 2017 09:45:09 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cuyXs-0001Td-Ju for xen-devel@lists.xenproject.org; Mon, 03 Apr 2017 09:45:08 +0000 Received: from [85.158.143.35] by server-2.bemta-6.messagelabs.com id 15/9A-19731-3A912E85; Mon, 03 Apr 2017 09:45:07 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprDIsWRWlGSWpSXmKPExsXiVRtsqLtY8lG Ewdl+IYvvWyYzOTB6HP5whSWAMYo1My8pvyKBNWPPpRb2gj8qFbN2tLM3MB6Q6mLk4hASmMEo 8ezkfKYuRk4OFoF5zBLrH0uC2BIC/awS++ZnQNgxEg1r3rJB2BUSd443MILYQgJaEkdPzWaFG NTKJLHjwBMgh4ODTcBEYlaHBEiNiICSxL1Vk5lAapgF5jNK7O05C1YjLBAosfhIOIjJIqAq8W uhOEg5r4C3xPnfN1ggVslJ3DzXyQxSwingI3HrVQLEVm+JV/ensU1gFFjAyLCKUaM4tagstUj X0EwvqSgzPaMkNzEzR9fQwEwvN7W4ODE9NScxqVgvOT93EyMwpBiAYAfj/Y0BhxglOZiURHnf 3HkYIcSXlJ9SmZFYnBFfVJqTWnyIUYaDQ0mC97n4owghwaLU9NSKtMwcYHDDpCU4eJREeB+Cp HmLCxJzizPTIVKnGHU5PvQffsMkxJKXn5cqJc4bKQFUJABSlFGaBzcCFmmXGGWlhHkZgY4S4i lILcrNLEGVf8UozsGoJMz7EmQVT2ZeCdymV0BHMAEd8QTkft7ikkSElFQDI4NxY0ly7Dd7Pfa tqgtSjedcuxZjNMGrPWBzRqjZjmDjZ30Z7Xr1LdGaTx8qrxJwOPFocqPIn1MxrhNVOdQ+xjPr FPlfeirM/yHhG3vij/6V1tUlMX9Xy19zrJ3zUWAHX7TaUZ8dHeZi8YGcvlrs7K9+eAtwPtiXs funlkps0umTapNUFxorsRRnJBpqMRcVJwIAOhSRR68CAAA= X-Env-Sender: bhupinder.thakur@linaro.org X-Msg-Ref: server-2.tower-21.messagelabs.com!1491212706!47821646!1 X-Originating-IP: [74.125.83.49] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 31793 invoked from network); 3 Apr 2017 09:45:07 -0000 Received: from mail-pg0-f49.google.com (HELO mail-pg0-f49.google.com) (74.125.83.49) by server-2.tower-21.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 3 Apr 2017 09:45:07 -0000 Received: by mail-pg0-f49.google.com with SMTP id 21so115428117pgg.1 for ; Mon, 03 Apr 2017 02:45:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=E9PvMy+Ii+Irs6yieWYOybtvMHOHqK0uBIdU4BXqEUg=; b=R91TvyBIIvWkZaSDkpvP1a1v9Q4y8JGUPw9vmMYOsBKcOtvCrlCaGQazdxhRK4lShE 9FHOUfTw2owf+uxjMGfc64SihXFQWJy5quFprhjniEByI39e6qj99VvG/MVhwiV0SqSa CSREDwU/JwkVg4UGRVrPhwkdxji4pq5o5sazY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=E9PvMy+Ii+Irs6yieWYOybtvMHOHqK0uBIdU4BXqEUg=; b=a3WWtRWXSJ/IBj3bSlzHonjz0EuThwhCoxvBH4QUojc/H5XLINHIIha6rgUZNpVxeN dJCTTvIpn9Eu4DwVWPmwtOEe5Gl+xnvkRmoRY0Dz7zClX+EjaMUR2gtPdregKTg51xri I/c3PBuwZMEzIaPbkwvB+m3FJfS6gCij5+xbVTIjbJ50651POovlbAloSg8AugN5Smzq 8+13u04HJGChMsX9X0PMhqoMML5XYQmN6gS3ICn4ycFmAR/YHuBCvjwNKaaP30K5/++G jgmDNHfkx+9+3URI5vPvBLtMjCSwemF26w9zRWSTDG0R/TOpLbDRm54grdonJzU6DS56 FRkA== X-Gm-Message-State: AFeK/H14quQjCbz9OxEmcLba0zuchPeHimnLDPXxjlLO0LByzF8yC55uzq12zYz1FRLT0+Fm X-Received: by 10.99.247.69 with SMTP id f5mr17295464pgk.63.1491212690629; Mon, 03 Apr 2017 02:44:50 -0700 (PDT) Received: from blr-ubuntu-linaro.wlan.qualcomm.com ([202.46.23.54]) by smtp.gmail.com with ESMTPSA id y7sm24751844pfk.93.2017.04.03.02.44.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 03 Apr 2017 02:44:50 -0700 (PDT) From: Bhupinder Thakur To: xen-devel@lists.xenproject.org Date: Mon, 3 Apr 2017 15:14:25 +0530 Message-Id: <1491212673-13476-3-git-send-email-bhupinder.thakur@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1491212673-13476-1-git-send-email-bhupinder.thakur@linaro.org> References: <1491212673-13476-1-git-send-email-bhupinder.thakur@linaro.org> Cc: Wei Liu , Julien Grall , Stefano Stabellini , Ian Jackson Subject: [Xen-devel] [PATCH 02/10] xen/arm: vpl011: Add new virtual console hvm params in Xen X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 #include #include +#include +#include #include @@ -31,6 +33,80 @@ #include #include +#include + +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