From patchwork Thu Jan 28 11:17:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corneliu ZUZU X-Patchwork-Id: 8149501 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 899749F440 for ; Thu, 28 Jan 2016 11:20:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3DE922024F for ; Thu, 28 Jan 2016 11:20:57 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id ED22B20211 for ; Thu, 28 Jan 2016 11:20:53 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aOkaR-00007C-2V; Thu, 28 Jan 2016 11:18:03 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aOkaP-000077-Ok for xen-devel@lists.xen.org; Thu, 28 Jan 2016 11:18:01 +0000 Received: from [85.158.137.68] by server-16.bemta-3.messagelabs.com id 6B/F2-07451-8E8F9A65; Thu, 28 Jan 2016 11:18:00 +0000 X-Env-Sender: czuzu@bitdefender.com X-Msg-Ref: server-2.tower-31.messagelabs.com!1453979879!18734794!1 X-Originating-IP: [91.199.104.161] X-SpamReason: No, hits=0.5 required=7.0 tests=BODY_RANDOM_LONG X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 51442 invoked from network); 28 Jan 2016 11:18:00 -0000 Received: from mx01.buh.bitdefender.com (HELO mx01.buh.bitdefender.com) (91.199.104.161) by server-2.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 28 Jan 2016 11:18:00 -0000 Comment: DomainKeys? See http://domainkeys.sourceforge.net/ DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=bitdefender.com; b=SfodR0cbw77VuE93h+mCmWYm1IbrJ5Uqjf3WmKoPsuPzEO65bpO48E3FpST8pw6zWj0pm4P/zSMypNkJ5xBoSWvivxfNE4LogjSPWjraNhmIMfICnBVxBFO4T/TE34AAlPIT+oRayOqnkXX05GnLjIPh/VKkd2LF9I/SQT+rLrbeqarR9CMCimDd1wAzzTDnpp7RjjUan9zBrC655C2xgTg/jE17uKvRgBTdS68YpnxkZCjmAlL/spoW6h8OJ3F8+gruWgcDBczWY2r7P2yUWg7sqUIWN34sdSzlBVAKiitpaSmdOVvQROQIf2AoFcmv3RpqZ35vL/5VPa1In8zE7w==; h=Received:Received:Received:Received:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer:X-BitDefender-Scanner:X-BitDefender-Spam:X-BitDefender-SpamStamp:X-BitDefender-CF-Stamp; DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=bitdefender.com; h=from:to :cc:subject:date:message-id; s=default; bh=h1IjSaqHS04bhDYl6Z/vF ENAsWo=; b=IUnryw7HMtmaVMisq60JAjniJxKarjsxesumBCj9ogX24/JV1wOFg 8o/c94RK6kB/Rfnt1OW9Yz7kKCxSpWYrgqNIfnuTOe/FAiM/U1+1LVdjM6ZCRHfJ txcKiixzQ7yi/toc6xt/j8rJrv5wuxqCcOKdozGvoXMV9dtHCV0RNERU9fIWDfbq veemcUpsHjPxAW7Z6kiQgnogRofqpb713ubYHbxfu+vLEvzo/Gz/R6q+DbguRuzD T6gtpfnS/2WGJBTsZ5GgL6/Ouzf4TtldYBD5Q8pZOtsdSRO+/kAOboXmqR4sklbw IPgKVpPfmfNUZ6CODmjezw807j9GsQK0g== Received: (qmail 852 invoked from network); 28 Jan 2016 13:17:59 +0200 Received: from unknown (HELO mx-sr.buh.bitdefender.com) (10.17.80.103) by mx01.buh.bitdefender.com with AES256-GCM-SHA384 encrypted SMTP; 28 Jan 2016 13:17:59 +0200 Received: from smtp01.buh.bitdefender.com (unknown [10.17.80.75]) by mx-sr.buh.bitdefender.com (Postfix) with ESMTP id D4D81803B5 for ; Thu, 28 Jan 2016 13:17:58 +0200 (EET) Received: (qmail 4533 invoked from network); 28 Jan 2016 13:17:58 +0200 Received: from unknown (HELO czuzu-dev-vm.clj.bitdefender.biz) (czuzu@bitdefender.com@172.21.6.207) by smtp01.buh.bitdefender.com with AES128-SHA256 encrypted SMTP; 28 Jan 2016 13:17:58 +0200 From: Corneliu ZUZU To: xen-devel@lists.xen.org Date: Thu, 28 Jan 2016 13:17:54 +0200 Message-Id: <1453979874-20037-1-git-send-email-czuzu@bitdefender.com> X-Mailer: git-send-email 2.5.0 X-BitDefender-Scanner: Clean, Agent: BitDefender qmail 3.1.4 on smtp01.buh.bitdefender.com, sigver: 7.64319 X-BitDefender-Spam: No (0) X-BitDefender-SpamStamp: Build: [Engines: 2.15.6.743, Dats: 413411, Stamp: 3], Multi: [Enabled, t: (0.000011, 0.008818)], BW: [Enabled, t: (0.000007,0.000001)], RBL DNSBL: [Disabled], APM: [Enabled, Score: 500, t: (0.006434), Flags: 2A917CE3; NN_TP_TAG_HTTP; NN_NO_CONTENT_TYPE; NN_LEGIT_SUMM_400_WORDS; NN_LEGIT_BITDEFENDER; NN_LEGIT_S_SQARE_BRACKETS; NN_LEGIT_MAILING_LIST_TO], SGN: [Enabled, t: (0.012469)], URL: [Enabled, t: (0.000029)], RTDA: [Enabled, t: (0.096616), Hit: No, Details: v2.3.2; Id: 2m1gj0i.1a9kniubi.5la52], total: 0(775) X-BitDefender-CF-Stamp: none Cc: Stefano Stabellini , Ian Campbell Subject: [Xen-devel] [PATCH] ARM: Support for guest-request vm-events X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch implements ARM support for guest-request vm-events. The code has been ported from x86 side w/ minor adjustments. Signed-off-by: Corneliu ZUZU --- xen/arch/arm/Makefile | 2 + xen/arch/arm/event.c | 86 ++++++++++++++++++++++++++++ xen/arch/arm/hvm.c | 9 ++- xen/arch/arm/monitor.c | 123 ++++++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/domain.h | 8 +++ xen/include/asm-arm/hvm/event.h | 36 ++++++++++++ xen/include/asm-arm/monitor.h | 8 +-- xen/include/asm-arm/vm_event.h | 4 +- 8 files changed, 267 insertions(+), 9 deletions(-) create mode 100644 xen/arch/arm/event.c create mode 100644 xen/arch/arm/monitor.c create mode 100644 xen/include/asm-arm/hvm/event.h diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile index 2f050f5..d3d8d7b 100644 --- a/xen/arch/arm/Makefile +++ b/xen/arch/arm/Makefile @@ -31,6 +31,8 @@ obj-y += smpboot.o obj-y += smp.o obj-y += shutdown.o obj-y += traps.o +obj-y += event.o +obj-y += monitor.o obj-y += vgic.o vgic-v2.o obj-$(CONFIG_ARM_64) += vgic-v3.o obj-y += vtimer.o diff --git a/xen/arch/arm/event.c b/xen/arch/arm/event.c new file mode 100644 index 0000000..e4bc25a --- /dev/null +++ b/xen/arch/arm/event.c @@ -0,0 +1,86 @@ +/* +* arch/arm/event.c +* +* Common hardware virtual machine event abstractions. +* Copy-pasted & adjusted from x86 counterpart. +* +* Copyright (c) 2004, Intel Corporation. +* Copyright (c) 2005, International Business Machines Corporation. +* Copyright (c) 2008, Citrix Systems, Inc. +* Copyright (c) 2016, Bitdefender S.R.L. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License along with +* this program; If not, see . +*/ + +#include +#include +#include +#include + +static int hvm_event_traps(uint8_t sync, vm_event_request_t *req) +{ + int rc; + struct vcpu *curr = current; + struct domain *currd = curr->domain; + + rc = vm_event_claim_slot(currd, &currd->vm_event->monitor); + switch ( rc ) + { + case 0: + break; + case -ENOSYS: + /* + * If there was no ring to handle the event, then + * simply continue executing normally. + */ + return 1; + default: + return rc; + }; + + if ( sync ) + { + req->flags |= VM_EVENT_FLAG_VCPU_PAUSED; + vm_event_vcpu_pause(curr); + } + + vm_event_put_request(currd, &currd->vm_event->monitor, req); + + return 1; +} + +void hvm_event_guest_request(void) +{ + struct vcpu *curr = current; + struct arch_domain *currad = &curr->domain->arch; + + if ( currad->monitor.guest_request_enabled ) + { + vm_event_request_t req = { + .reason = VM_EVENT_REASON_GUEST_REQUEST, + .vcpu_id = curr->vcpu_id, + }; + + hvm_event_traps(currad->monitor.guest_request_sync, &req); + } +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/arm/hvm.c b/xen/arch/arm/hvm.c index 5fd0753..f314bd7 100644 --- a/xen/arch/arm/hvm.c +++ b/xen/arch/arm/hvm.c @@ -11,10 +11,10 @@ #include #include +#include #include long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) - { long rc = 0; @@ -55,6 +55,13 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) break; } + case HVMOP_guest_request_vm_event: + if ( guest_handle_is_null(arg) ) + hvm_event_guest_request(); + else + rc = -EINVAL; + break; + default: { gdprintk(XENLOG_DEBUG, "HVMOP op=%lu: not implemented\n", op); diff --git a/xen/arch/arm/monitor.c b/xen/arch/arm/monitor.c new file mode 100644 index 0000000..22455f7 --- /dev/null +++ b/xen/arch/arm/monitor.c @@ -0,0 +1,123 @@ +/* + * arch/arm/monitor.c + * + * Architecture-specific monitor_op domctl handler. + * Copy-pasted & adjusted from x86 counterpart. + * + * Copyright (c) 2015 Tamas K Lengyel (tamas@tklengyel.com) + * Copyright (c) 2016 Bitdefender S.R.L. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License v2 as published by the Free Software Foundation. + * + * 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 021110-1307, USA. + */ + +#include +#include +#include +#include +#include + +/* + * Sanity check whether option is already enabled/disabled + */ +static inline +int status_check(struct xen_domctl_monitor_op *mop, bool_t old_status) +{ + bool_t requested_status = (mop->op == XEN_DOMCTL_MONITOR_OP_ENABLE); + + if ( old_status == requested_status ) + return -EEXIST; + + return 0; +} + +static inline uint32_t get_capabilities(struct domain *d) +{ + uint32_t capabilities = 0; + + capabilities = (1 << XEN_DOMCTL_MONITOR_EVENT_GUEST_REQUEST); + + return capabilities; +} + +int monitor_domctl(struct domain *d, struct xen_domctl_monitor_op *mop) +{ + int rc; + struct arch_domain *ad = &d->arch; + uint32_t capabilities = get_capabilities(d); + + rc = xsm_vm_event_control(XSM_PRIV, d, mop->op, mop->event); + if ( rc ) + return rc; + + if ( mop->op == XEN_DOMCTL_MONITOR_OP_GET_CAPABILITIES ) + { + mop->event = capabilities; + return 0; + } + + /* + * Sanity check + */ + if ( mop->op != XEN_DOMCTL_MONITOR_OP_ENABLE && + mop->op != XEN_DOMCTL_MONITOR_OP_DISABLE ) + return -EOPNOTSUPP; + + /* Check if event type is available. */ + if ( !(capabilities & (1 << mop->event)) ) + return -EOPNOTSUPP; + + switch ( mop->event ) + { + case XEN_DOMCTL_MONITOR_EVENT_GUEST_REQUEST: + { + bool_t old_status = ad->monitor.guest_request_enabled; + + rc = status_check(mop, old_status); + if ( rc ) + return rc; + + ad->monitor.guest_request_sync = mop->u.guest_request.sync; + + domain_pause(d); + ad->monitor.guest_request_enabled = !old_status; + domain_unpause(d); + break; + } + + default: + /* + * Should not be reached unless get_capabilities() is not properly + * implemented. In that case, since reaching this point does not + * really break anything, don't crash the hypervisor, issue a + * warning instead of BUG(). + */ + printk(XENLOG_WARNING + "WARNING, BUG: get_capabilities() not properly" + "implemented.\n"); + + return -EOPNOTSUPP; + }; + + return 0; +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/include/asm-arm/domain.h b/xen/include/asm-arm/domain.h index aa7f283..cd5d285 100644 --- a/xen/include/asm-arm/domain.h +++ b/xen/include/asm-arm/domain.h @@ -124,6 +124,14 @@ struct arch_domain } vuart; unsigned int evtchn_irq; + + /* Monitor options */ + struct { + uint8_t guest_request_enabled : 1; + uint8_t guest_request_sync : 1; + uint8_t : 6; + } monitor; + } __cacheline_aligned; struct arch_vcpu diff --git a/xen/include/asm-arm/hvm/event.h b/xen/include/asm-arm/hvm/event.h new file mode 100644 index 0000000..246dfb8 --- /dev/null +++ b/xen/include/asm-arm/hvm/event.h @@ -0,0 +1,36 @@ +/* + * include/asm-arm/hvm/event.h: + * + * Copy-pasted & adjusted from x86 counterpart. + * + * Copyright (c) 2016, Bitdefender S.R.L. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; If not, see . + */ + +#ifndef __ASM_ARM_HVM_EVENT_H__ +#define __ASM_ARM_HVM_EVENT_H__ + +void hvm_event_guest_request(void); + +#endif /* __ASM_ARM_HVM_EVENT_H__ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/include/asm-arm/monitor.h b/xen/include/asm-arm/monitor.h index a3a9703..9d1a530 100644 --- a/xen/include/asm-arm/monitor.h +++ b/xen/include/asm-arm/monitor.h @@ -24,10 +24,6 @@ #include #include -static inline -int monitor_domctl(struct domain *d, struct xen_domctl_monitor_op *op) -{ - return -ENOSYS; -} +int monitor_domctl(struct domain *d, struct xen_domctl_monitor_op *op); -#endif /* __ASM_X86_MONITOR_H__ */ +#endif /* __ASM_ARM_MONITOR_H__ */ diff --git a/xen/include/asm-arm/vm_event.h b/xen/include/asm-arm/vm_event.h index 4d0fbf7..b468b89 100644 --- a/xen/include/asm-arm/vm_event.h +++ b/xen/include/asm-arm/vm_event.h @@ -25,14 +25,14 @@ static inline int vm_event_init_domain(struct domain *d) { - /* Not supported on ARM. */ + /* Nothing to do */ return 0; } static inline void vm_event_cleanup_domain(struct domain *d) { - /* Not supported on ARM. */ + memset(&d->arch.monitor, 0, sizeof(d->arch.monitor)); } static inline