From patchwork Fri Apr 29 18:07:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tamas K Lengyel X-Patchwork-Id: 8984521 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 4C59C9F1D3 for ; Fri, 29 Apr 2016 18:10:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5E04E201E4 for ; Fri, 29 Apr 2016 18:10:09 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 5F55D20212 for ; Fri, 29 Apr 2016 18:10:06 +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 1awCpO-0005MS-2i; Fri, 29 Apr 2016 18:07:46 +0000 Received: from mail6.bemta6.messagelabs.com ([85.158.143.247]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1awCpL-0005MG-ST for xen-devel@lists.xenproject.org; Fri, 29 Apr 2016 18:07:44 +0000 Received: from [85.158.143.35] by server-2.bemta-6.messagelabs.com id FD/4E-09532-FE2A3275; Fri, 29 Apr 2016 18:07:43 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrAIsWRWlGSWpSXmKPExsVyMfTqOt13i5T DDa708lp83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBmPt09mL3i+jrHi9J/5bA2Mu9oYuxi5OIQE ZjJKnH74g7WLkZNDQqCfVWLzbV8IO0biac8aZgi7UqLh1VIWEFtIQEPi9s1GdojmSUwSd859A WtmE9CWaHu9C8wWEVCSuLdqMhOIzSzwikni8WUfEFtYwEri0M3PbCA2i4CqxJVzR8GG8go4S/ yZdZkRYpmcxOXpD8BqOAVcJE58XA212Fli797bTBMY+RcwMqxiVC9OLSpLLdI11EsqykzPKMl NzMzRNTQw08tNLS5OTE/NSUwq1kvOz93ECAwhBiDYwbjzudMhRkkOJiVR3qu6yuFCfEn5KZUZ icUZ8UWlOanFhxhlODiUJHjnLATKCRalpqdWpGXmAIMZJi3BwaMkwntiAVCat7ggMbc4Mx0id YrRkmPL72trmTiOzb0BJLdNvbeWSYglLz8vVUqcNw9kngBIQ0ZpHtw4WMRdYpSVEuZlBDpQiK cgtSg3swRV/hWjOAejkjDvNZApPJl5JXBbXwEdxAR0kMAmRZCDShIRUlINjPaqVvuSNjM29H7 9qTNBRLDMJ7SXSW3TNY6JbwUiNyizq8jK7Zx3+Mtxw1+sDbefJ3Nv3z35fvSqhn+zeC28nbyq 995d1vWx9LTaqkPtQj9yjF49cnruavD6o0KQ0aNnr4/nrZdN0v7b/mPL8klz+L4rH3m2cfWF5 0fD3/0LcXDxzN1aIWcde1uJpTgj0VCLuag4EQB8wVyqswIAAA== X-Env-Sender: tamas.k.lengyel@gmail.com X-Msg-Ref: server-2.tower-21.messagelabs.com!1461953260!2213949!1 X-Originating-IP: [209.85.213.174] X-SpamReason: No, hits=0.5 required=7.0 tests=BODY_RANDOM_LONG X-StarScan-Received: X-StarScan-Version: 8.34; banners=-,-,- X-VirusChecked: Checked Received: (qmail 46436 invoked from network); 29 Apr 2016 18:07:41 -0000 Received: from mail-ig0-f174.google.com (HELO mail-ig0-f174.google.com) (209.85.213.174) by server-2.tower-21.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 29 Apr 2016 18:07:41 -0000 Received: by mail-ig0-f174.google.com with SMTP id bi2so30291215igb.0 for ; Fri, 29 Apr 2016 11:07:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=8+qp4SZD8TTavqC04hbAahNLk9TebHu5IT6zcL7rOKQ=; b=NgTuzjIB6wrKMBFDxMDDvToNJNaoIPOkFzn1eqoucJiHLMuhj+AAQj9x4z8Rau/Y0A kBMnAm2EG5HuC9gzkQKssMyh1qvyfWFIp25FeB8ozU5uP5ytfVGiZAXJx54HCmbfbx/Y sJ2/cDqsjCk4FKMmpk6IASIIc4fGUEjaXKJi0D2FZopCTDmkaHIuyQ1APO2gp1Ml8nTG fW/oK4fdQEF9y06UQXAw4FwmSHYK/luaho4QPgo+LGKxdJdpUWwuW/8JZSLSGBc658/I eT6/jkqBXiBC2F76Nj//7G8309eK2Ar8o4AcPrk86LQqMtqL2Ajf19TDi++piDVWJS0C jwxg== X-Gm-Message-State: AOPr4FXR9Yhx4wYwSgzRWn9lQHDzngbSZLl6KFB6EnSJavOzaO7DvJv2jtioMgIX2u5KFQ== X-Received: by 10.50.230.17 with SMTP id su17mr5908463igc.80.1461953260498; Fri, 29 Apr 2016 11:07:40 -0700 (PDT) Received: from l1.lan (c-73-14-35-59.hsd1.co.comcast.net. [73.14.35.59]) by smtp.gmail.com with ESMTPSA id k33sm10721589iod.44.2016.04.29.11.07.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 Apr 2016 11:07:39 -0700 (PDT) From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Fri, 29 Apr 2016 12:07:30 -0600 Message-Id: <1461953253-32043-2-git-send-email-tamas@tklengyel.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1461953253-32043-1-git-send-email-tamas@tklengyel.com> References: <1461953253-32043-1-git-send-email-tamas@tklengyel.com> Cc: Tamas K Lengyel , Wei Liu , Razvan Cojocaru , Stefano Stabellini , Andrew Cooper , Ian Jackson , Julien Grall , Jan Beulich , Keir Fraser Subject: [Xen-devel] [PATCH v2 2/5] vm_event: Implement ARM SMC events 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-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 The ARM SMC instructions are already configured to trap to Xen by default. In this patch we allow a user-space process in a privileged domain to receive notification of when such event happens through the vm_event subsystem by introducing the PRIVILEGED_CALL type. Signed-off-by: Tamas K Lengyel Acked-by: Wei Liu --- Cc: Razvan Cojocaru Cc: Ian Jackson Cc: Stefano Stabellini Cc: Wei Liu Cc: Julien Grall Cc: Keir Fraser Cc: Jan Beulich Cc: Andrew Cooper v2: introduce VM_EVENT_REASON_PRIVELEGED_CALL aarch64 support --- MAINTAINERS | 6 +- tools/libxc/include/xenctrl.h | 2 + tools/libxc/xc_monitor.c | 26 +++++++- tools/tests/xen-access/xen-access.c | 31 ++++++++- xen/arch/arm/Makefile | 2 + xen/arch/arm/monitor.c | 80 +++++++++++++++++++++++ xen/arch/arm/traps.c | 20 +++++- xen/arch/arm/vm_event.c | 127 ++++++++++++++++++++++++++++++++++++ xen/arch/x86/hvm/event.c | 2 + xen/common/vm_event.c | 1 - xen/include/asm-arm/domain.h | 5 ++ xen/include/asm-arm/monitor.h | 20 ++---- xen/include/asm-arm/vm_event.h | 16 ++--- xen/include/public/domctl.h | 1 + xen/include/public/vm_event.h | 27 ++++++++ 15 files changed, 333 insertions(+), 33 deletions(-) create mode 100644 xen/arch/arm/monitor.c create mode 100644 xen/arch/arm/vm_event.c diff --git a/MAINTAINERS b/MAINTAINERS index 5af7a0c..36d8591 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -355,12 +355,10 @@ VM EVENT AND MEM ACCESS M: Razvan Cojocaru M: Tamas K Lengyel S: Supported -F: xen/common/vm_event.c +F: xen/*/vm_event.c +F: xen/*/monitor.c F: xen/common/mem_access.c -F: xen/common/monitor.c F: xen/arch/x86/hvm/event.c -F: xen/arch/x86/monitor.c -F: xen/arch/*/vm_event.c F: tools/tests/xen-access VTPM diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index 42f201b..4b75ae4 100644 --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -2160,6 +2160,8 @@ int xc_monitor_software_breakpoint(xc_interface *xch, domid_t domain_id, bool enable); int xc_monitor_guest_request(xc_interface *xch, domid_t domain_id, bool enable, bool sync); +int xc_monitor_privileged_call(xc_interface *xch, domid_t domain_id, + bool enable); /** * This function enables / disables emulation for each REP for a diff --git a/tools/libxc/xc_monitor.c b/tools/libxc/xc_monitor.c index b1705dd..072df70 100644 --- a/tools/libxc/xc_monitor.c +++ b/tools/libxc/xc_monitor.c @@ -4,7 +4,7 @@ * * Interface to VM event monitor * - * Copyright (c) 2015 Tamas K Lengyel (tamas@tklengyel.com) + * Copyright (c) 2015-2016 Tamas K Lengyel (tamas@tklengyel.com) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -156,3 +156,27 @@ int xc_monitor_emulate_each_rep(xc_interface *xch, domid_t domain_id, return do_domctl(xch, &domctl); } + +int xc_monitor_privileged_call(xc_interface *xch, domid_t domain_id, + bool enable) +{ + DECLARE_DOMCTL; + + domctl.cmd = XEN_DOMCTL_monitor_op; + domctl.domain = domain_id; + domctl.u.monitor_op.op = enable ? XEN_DOMCTL_MONITOR_OP_ENABLE + : XEN_DOMCTL_MONITOR_OP_DISABLE; + domctl.u.monitor_op.event = XEN_DOMCTL_MONITOR_EVENT_PRIVILEGED_CALL; + + return do_domctl(xch, &domctl); +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/tools/tests/xen-access/xen-access.c b/tools/tests/xen-access/xen-access.c index f26e723..33e8044 100644 --- a/tools/tests/xen-access/xen-access.c +++ b/tools/tests/xen-access/xen-access.c @@ -334,6 +334,8 @@ void usage(char* progname) fprintf(stderr, "Usage: %s [-m] write|exec", progname); #if defined(__i386__) || defined(__x86_64__) fprintf(stderr, "|breakpoint|altp2m_write|altp2m_exec"); +#elif defined(__arm__) || defined(__aarch64__) + fprintf(stderr, "|privcall"); #endif fprintf(stderr, "\n" @@ -357,6 +359,7 @@ int main(int argc, char *argv[]) int required = 0; int breakpoint = 0; int shutting_down = 0; + int privcall = 0; int altp2m = 0; uint16_t altp2m_view_id = 0; @@ -412,6 +415,11 @@ int main(int argc, char *argv[]) default_access = XENMEM_access_rw; altp2m = 1; } +#elif defined(__arm__) || defined(__aarch64__) + else if ( !strcmp(argv[0], "privcall") ) + { + privcall = 1; + } #endif else { @@ -524,6 +532,16 @@ int main(int argc, char *argv[]) } } + if ( privcall ) + { + rc = xc_monitor_privileged_call(xch, domain_id, 1); + if ( rc < 0 ) + { + ERROR("Error %d setting privileged call trapping with vm_event\n", rc); + goto exit; + } + } + /* Wait for access */ for (;;) { @@ -535,6 +553,9 @@ int main(int argc, char *argv[]) if ( breakpoint ) rc = xc_monitor_software_breakpoint(xch, domain_id, 0); + if ( privcall ) + rc = xc_monitor_privileged_call(xch, domain_id, 0); + if ( altp2m ) { rc = xc_altp2m_switch_to_view( xch, domain_id, 0 ); @@ -635,7 +656,7 @@ int main(int argc, char *argv[]) rsp.u.mem_access = req.u.mem_access; break; case VM_EVENT_REASON_SOFTWARE_BREAKPOINT: - printf("Breakpoint: rip=%016"PRIx64", gfn=%"PRIx64" (vcpu %d)\n", + printf("Breakpoint: rip=%"PRIx64" gfn=%"PRIx64" (vcpu %d)\n", req.data.regs.x86.rip, req.u.software_breakpoint.gfn, req.vcpu_id); @@ -650,7 +671,15 @@ int main(int argc, char *argv[]) interrupted = -1; continue; } + break; + case VM_EVENT_REASON_PRIVILEGED_CALL: + printf("Privileged call: pc=%"PRIx64" (vcpu %d)\n", + req.data.regs.arm.pc, + req.vcpu_id); + rsp.data.regs.arm = req.data.regs.arm; + rsp.data.regs.arm.pc += 4; + rsp.flags |= VM_EVENT_FLAG_SET_REGISTERS; break; case VM_EVENT_REASON_SINGLESTEP: printf("Singlestep: rip=%016"PRIx64", vcpu %d, altp2m %u\n", diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile index 0328b50..118be99 100644 --- a/xen/arch/arm/Makefile +++ b/xen/arch/arm/Makefile @@ -40,6 +40,8 @@ obj-y += device.o obj-y += decode.o obj-y += processor.o obj-y += smc.o +obj-y += monitor.o +obj-y += vm_event.o #obj-bin-y += ....o diff --git a/xen/arch/arm/monitor.c b/xen/arch/arm/monitor.c new file mode 100644 index 0000000..e845f28 --- /dev/null +++ b/xen/arch/arm/monitor.c @@ -0,0 +1,80 @@ +/* + * arch/arm/monitor.c + * + * Arch-specific monitor_op domctl handler. + * + * Copyright (c) 2015-2016 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, see . + */ + +#include +#include + +int arch_monitor_domctl_event(struct domain *d, + struct xen_domctl_monitor_op *mop) +{ + struct arch_domain *ad = &d->arch; + bool_t requested_status = (XEN_DOMCTL_MONITOR_OP_ENABLE == mop->op); + + switch ( mop->event ) + { + case XEN_DOMCTL_MONITOR_EVENT_PRIVILEGED_CALL: + { + bool_t old_status = ad->monitor.privileged_call_enabled; + + if ( unlikely(old_status == requested_status) ) + return -EEXIST; + + domain_pause(d); + ad->monitor.privileged_call_enabled = requested_status; + domain_unpause(d); + break; + } + + default: + /* + * Should not be reached unless arch_monitor_get_capabilities() is + * not properly implemented. + */ + ASSERT_UNREACHABLE(); + return -EOPNOTSUPP; + } + + return 0; +} + +int monitor_smc(const struct cpu_user_regs *regs) { + struct vcpu *curr = current; + vm_event_request_t req = { 0 }; + + if ( !curr->domain->arch.monitor.privileged_call_enabled ) + return 0; + + req.reason = VM_EVENT_REASON_PRIVILEGED_CALL; + req.vcpu_id = curr->vcpu_id; + + vm_event_fill_regs(&req, regs, curr->domain); + + return vm_event_monitor_traps(curr, 1, &req); +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c index 9abfc3c..9c8d395 100644 --- a/xen/arch/arm/traps.c +++ b/xen/arch/arm/traps.c @@ -41,6 +41,7 @@ #include #include #include +#include #include "decode.h" #include "vtimer.h" @@ -2491,6 +2492,21 @@ bad_data_abort: inject_dabt_exception(regs, info.gva, hsr.len); } +static void do_trap_smc(struct cpu_user_regs *regs, const union hsr hsr) +{ + int rc = 0; + if ( current->domain->arch.monitor.privileged_call_enabled ) + { + rc = monitor_smc(regs); + } + + if ( rc != 1 ) + { + GUEST_BUG_ON(!psr_mode_is_32bit(regs->cpsr)); + inject_undef_exception(regs, hsr); + } +} + static void enter_hypervisor_head(struct cpu_user_regs *regs) { if ( guest_mode(regs) ) @@ -2566,7 +2582,7 @@ asmlinkage void do_trap_hypervisor(struct cpu_user_regs *regs) */ GUEST_BUG_ON(!psr_mode_is_32bit(regs->cpsr)); perfc_incr(trap_smc32); - inject_undef32_exception(regs); + do_trap_smc(regs, hsr); break; case HSR_EC_HVC32: GUEST_BUG_ON(!psr_mode_is_32bit(regs->cpsr)); @@ -2599,7 +2615,7 @@ asmlinkage void do_trap_hypervisor(struct cpu_user_regs *regs) */ GUEST_BUG_ON(psr_mode_is_32bit(regs->cpsr)); perfc_incr(trap_smc64); - inject_undef64_exception(regs, hsr.len); + do_trap_smc(regs, hsr); break; case HSR_EC_SYSREG: GUEST_BUG_ON(psr_mode_is_32bit(regs->cpsr)); diff --git a/xen/arch/arm/vm_event.c b/xen/arch/arm/vm_event.c new file mode 100644 index 0000000..3369a96 --- /dev/null +++ b/xen/arch/arm/vm_event.c @@ -0,0 +1,127 @@ +/* + * arch/arm/vm_event.c + * + * Architecture-specific vm_event handling routines + * + * Copyright (c) 2016 Tamas K Lengyel (tamas@tklengyel.com) + * + * 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, see . + */ + +#include +#include + +void vm_event_fill_regs(vm_event_request_t *req, + const struct cpu_user_regs *regs, + struct domain *d) +{ + if ( is_32bit_domain(d) ) + { + req->data.regs.arm.x0 = regs->r0; + req->data.regs.arm.x1 = regs->r1; + req->data.regs.arm.x2 = regs->r2; + req->data.regs.arm.x3 = regs->r3; + req->data.regs.arm.x4 = regs->r4; + req->data.regs.arm.x5 = regs->r5; + req->data.regs.arm.x6 = regs->r6; + req->data.regs.arm.x7 = regs->r7; + req->data.regs.arm.x8 = regs->r8; + req->data.regs.arm.x9 = regs->r9; + req->data.regs.arm.x10 = regs->r10; + req->data.regs.arm.pc = regs->pc32; + req->data.regs.arm.sp_el0 = regs->sp_usr; + req->data.regs.arm.sp_el1 = regs->sp_svc; + } +#ifdef CONFIG_ARM_64 + else + { + req->data.regs.arm.x0 = regs->x0; + req->data.regs.arm.x1 = regs->x1; + req->data.regs.arm.x2 = regs->x2; + req->data.regs.arm.x3 = regs->x3; + req->data.regs.arm.x4 = regs->x4; + req->data.regs.arm.x5 = regs->x5; + req->data.regs.arm.x6 = regs->x6; + req->data.regs.arm.x7 = regs->x7; + req->data.regs.arm.x8 = regs->x8; + req->data.regs.arm.x9 = regs->x9; + req->data.regs.arm.x10 = regs->x10; + req->data.regs.arm.pc = regs->pc; + req->data.regs.arm.sp_el0 = regs->sp_el0; + req->data.regs.arm.sp_el1 = regs->sp_el1; + } +#endif + req->data.regs.arm.fp = regs->fp; + req->data.regs.arm.lr = regs->lr; + req->data.regs.arm.cpsr = regs->cpsr; + req->data.regs.arm.spsr_el1 = regs->spsr_svc; + req->data.regs.arm.ttbr0 = READ_SYSREG64(TTBR0_EL1); + req->data.regs.arm.ttbr1 = READ_SYSREG64(TTBR1_EL1); +} + +void vm_event_set_registers(struct vcpu *v, vm_event_response_t *rsp) +{ + struct cpu_user_regs *regs = &v->arch.cpu_info->guest_cpu_user_regs; + + if ( is_32bit_domain(v->domain) ) + { + regs->r0 = rsp->data.regs.arm.x0; + regs->r1 = rsp->data.regs.arm.x1; + regs->r2 = rsp->data.regs.arm.x2; + regs->r3 = rsp->data.regs.arm.x3; + regs->r4 = rsp->data.regs.arm.x4; + regs->r5 = rsp->data.regs.arm.x5; + regs->r6 = rsp->data.regs.arm.x6; + regs->r7 = rsp->data.regs.arm.x7; + regs->r8 = rsp->data.regs.arm.x8; + regs->r9 = rsp->data.regs.arm.x9; + regs->r10 = rsp->data.regs.arm.x10; + regs->pc32 = rsp->data.regs.arm.pc; + regs->sp_usr = rsp->data.regs.arm.sp_el0; + regs->sp_svc = rsp->data.regs.arm.sp_el1; + } +#ifdef CONFIG_ARM_64 + else + { + regs->x0 = rsp->data.regs.arm.x0; + regs->x1 = rsp->data.regs.arm.x1; + regs->x2 = rsp->data.regs.arm.x2; + regs->x3 = rsp->data.regs.arm.x3; + regs->x4 = rsp->data.regs.arm.x4; + regs->x5 = rsp->data.regs.arm.x5; + regs->x6 = rsp->data.regs.arm.x6; + regs->x7 = rsp->data.regs.arm.x7; + regs->x8 = rsp->data.regs.arm.x8; + regs->x9 = rsp->data.regs.arm.x9; + regs->x10 = rsp->data.regs.arm.x10; + regs->pc = rsp->data.regs.arm.pc; + regs->sp_el0 = rsp->data.regs.arm.sp_el0; + regs->sp_el1 = rsp->data.regs.arm.sp_el1; + } +#endif + + regs->fp = rsp->data.regs.arm.fp; + regs->lr = rsp->data.regs.arm.lr; + regs->cpsr = rsp->data.regs.arm.cpsr; + v->arch.ttbr0 = rsp->data.regs.arm.ttbr0; + v->arch.ttbr1 = rsp->data.regs.arm.ttbr1; +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/x86/hvm/event.c b/xen/arch/x86/hvm/event.c index 56c5514..f7d1418 100644 --- a/xen/arch/x86/hvm/event.c +++ b/xen/arch/x86/hvm/event.c @@ -47,6 +47,7 @@ bool_t hvm_event_cr(unsigned int index, unsigned long value, unsigned long old) .u.write_ctrlreg.old_value = old }; + vm_event_fill_regs(&req); vm_event_monitor_traps(curr, sync, &req); return 1; } @@ -115,6 +116,7 @@ int hvm_event_breakpoint(unsigned long rip, } req.vcpu_id = curr->vcpu_id; + vm_event_fill_regs(&req); return vm_event_monitor_traps(curr, 1, &req); } diff --git a/xen/common/vm_event.c b/xen/common/vm_event.c index 2906407..a29bda8 100644 --- a/xen/common/vm_event.c +++ b/xen/common/vm_event.c @@ -818,7 +818,6 @@ int vm_event_monitor_traps(struct vcpu *v, uint8_t sync, req->altp2m_idx = altp2m_vcpu_idx(v); } - vm_event_fill_regs(req); vm_event_put_request(d, &d->vm_event->monitor, req); return 1; diff --git a/xen/include/asm-arm/domain.h b/xen/include/asm-arm/domain.h index c35ed40..87c7d7d 100644 --- a/xen/include/asm-arm/domain.h +++ b/xen/include/asm-arm/domain.h @@ -129,6 +129,11 @@ struct arch_domain paddr_t efi_acpi_gpa; paddr_t efi_acpi_len; #endif + + /* Monitor options */ + struct { + uint8_t privileged_call_enabled : 1; + } monitor; } __cacheline_aligned; struct arch_vcpu diff --git a/xen/include/asm-arm/monitor.h b/xen/include/asm-arm/monitor.h index 3fd3c9d..114237a 100644 --- a/xen/include/asm-arm/monitor.h +++ b/xen/include/asm-arm/monitor.h @@ -3,7 +3,7 @@ * * Arch-specific monitor_op domctl handler. * - * Copyright (c) 2015 Tamas K Lengyel (tamas@tklengyel.com) + * Copyright (c) 2015-2016 Tamas K Lengyel (tamas@tklengyel.com) * Copyright (c) 2016, Bitdefender S.R.L. * * This program is free software; you can redistribute it and/or @@ -32,27 +32,19 @@ int arch_monitor_domctl_op(struct domain *d, struct xen_domctl_monitor_op *mop) return -EOPNOTSUPP; } -static inline int arch_monitor_domctl_event(struct domain *d, - struct xen_domctl_monitor_op *mop) -{ - /* - * No arch-specific monitor vm-events on ARM. - * - * Should not be reached unless arch_monitor_get_capabilities() is not - * properly implemented. - */ - ASSERT_UNREACHABLE(); - return -EOPNOTSUPP; -} + struct xen_domctl_monitor_op *mop); static inline uint32_t arch_monitor_get_capabilities(struct domain *d) { uint32_t capabilities = 0; - capabilities = (1U << XEN_DOMCTL_MONITOR_EVENT_GUEST_REQUEST); + capabilities = (1U << XEN_DOMCTL_MONITOR_EVENT_GUEST_REQUEST) | + (1U << XEN_DOMCTL_MONITOR_EVENT_PRIVILEGED_CALL); return capabilities; } +int monitor_smc(const struct cpu_user_regs *regs); + #endif /* __ASM_ARM_MONITOR_H__ */ diff --git a/xen/include/asm-arm/vm_event.h b/xen/include/asm-arm/vm_event.h index a3fc4ce..432a790 100644 --- a/xen/include/asm-arm/vm_event.h +++ b/xen/include/asm-arm/vm_event.h @@ -1,7 +1,7 @@ /* * vm_event.h: architecture specific vm_event handling routines * - * Copyright (c) 2015 Tamas K Lengyel (tamas@tklengyel.com) + * Copyright (c) 2015-2016 Tamas K Lengyel (tamas@tklengyel.com) * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -19,6 +19,7 @@ #ifndef __ASM_ARM_VM_EVENT_H__ #define __ASM_ARM_VM_EVENT_H__ +#include #include #include #include @@ -48,15 +49,10 @@ void vm_event_register_write_resume(struct vcpu *v, vm_event_response_t *rsp) /* Not supported on ARM. */ } -static inline -void vm_event_set_registers(struct vcpu *v, vm_event_response_t *rsp) -{ - /* Not supported on ARM. */ -} +void vm_event_fill_regs(vm_event_request_t *req, + const struct cpu_user_regs *regs, + struct domain *d); -static inline void vm_event_fill_regs(vm_event_request_t *req) -{ - /* Not supported on ARM. */ -} +void vm_event_set_registers(struct vcpu *v, vm_event_response_t *rsp); #endif /* __ASM_ARM_VM_EVENT_H__ */ diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index 2457698..35adce2 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -1080,6 +1080,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_domctl_psr_cmt_op_t); #define XEN_DOMCTL_MONITOR_EVENT_SINGLESTEP 2 #define XEN_DOMCTL_MONITOR_EVENT_SOFTWARE_BREAKPOINT 3 #define XEN_DOMCTL_MONITOR_EVENT_GUEST_REQUEST 4 +#define XEN_DOMCTL_MONITOR_EVENT_PRIVILEGED_CALL 5 struct xen_domctl_monitor_op { uint32_t op; /* XEN_DOMCTL_MONITOR_OP_* */ diff --git a/xen/include/public/vm_event.h b/xen/include/public/vm_event.h index 9270d52..f039207 100644 --- a/xen/include/public/vm_event.h +++ b/xen/include/public/vm_event.h @@ -119,6 +119,8 @@ #define VM_EVENT_REASON_SINGLESTEP 7 /* An event has been requested via HVMOP_guest_request_vm_event. */ #define VM_EVENT_REASON_GUEST_REQUEST 8 +/* Privileged call executed (e.g. SMC) */ +#define VM_EVENT_REASON_PRIVILEGED_CALL 9 /* Supported values for the vm_event_write_ctrlreg index. */ #define VM_EVENT_X86_CR0 0 @@ -166,6 +168,30 @@ struct vm_event_regs_x86 { uint32_t _pad; }; +struct vm_event_regs_arm { + /* Aarch64 Aarch32 */ + uint64_t x0; /* r0_usr */ + uint64_t x1; /* r1_usr */ + uint64_t x2; /* r2_usr */ + uint64_t x3; /* r3_usr */ + uint64_t x4; /* r4_usr */ + uint64_t x5; /* r5_usr */ + uint64_t x6; /* r6_usr */ + uint64_t x7; /* r7_usr */ + uint64_t x8; /* r8_usr */ + uint64_t x9; /* r9_usr */ + uint64_t x10; /* r10_usr */ + uint64_t lr; /* lr_usr */ + uint64_t sp_el0; /* sp_usr */ + uint64_t sp_el1; /* sp_svc */ + uint32_t spsr_el1; /* spsr_svc */ + uint64_t fp; + uint64_t pc; + uint32_t cpsr; + uint64_t ttbr0; + uint64_t ttbr1; +}; + /* * mem_access flag definitions * @@ -254,6 +280,7 @@ typedef struct vm_event_st { union { union { struct vm_event_regs_x86 x86; + struct vm_event_regs_arm arm; } regs; struct vm_event_emul_read_data emul_read_data;