From patchwork Tue Jul 5 18:37:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tamas Lengyel X-Patchwork-Id: 9215081 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 2832260752 for ; Tue, 5 Jul 2016 18:40:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1C3F928119 for ; Tue, 5 Jul 2016 18:40:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 10C6A28179; Tue, 5 Jul 2016 18:40: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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,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 4894928119 for ; Tue, 5 Jul 2016 18:40:25 +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 1bKVEO-000176-RV; Tue, 05 Jul 2016 18:38:00 +0000 Received: from mail6.bemta6.messagelabs.com ([85.158.143.247]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bKVEN-00015g-OI for xen-devel@lists.xenproject.org; Tue, 05 Jul 2016 18:37:59 +0000 Received: from [85.158.143.35] by server-3.bemta-6.messagelabs.com id 22/F3-22092-78EFB775; Tue, 05 Jul 2016 18:37:59 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrLIsWRWlGSWpSXmKPExsVyMfT+Id22f9X hBl+fWVp83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBktU04yFdy2rviwuJm5gfGQfhcjF4eQwExG iTffnjOBOCwCzawSb1YfZAZxJAT6WSUmfXvJ3sXICeTESNxe+ZkZwq6R6P/+gRHEFhLQlDi44 QwzxKhJTBJPG7ezgCTYBIwkrl7tYQOxRQSUJO6tmgy2glmghVFi/4eLYFOFBfQl3v+fD2azCK hK/NvWBdbAK+Ap8WvOfKjNchKXpz8Ai3MKeEkcWf+LDWKzp8SdbfeZJzAKLGBkWMWoXpxaVJZ apGuol1SUmZ5RkpuYmaNraGCml5taXJyYnpqTmFSsl5yfu4kRGFwMQLCDcedzp0OMkhxMSqK8 LN+qw4X4kvJTKjMSizPii0pzUosPMcpwcChJ8P74A5QTLEpNT61Iy8wBhjlMWoKDR0mEV/wvU Jq3uCAxtzgzHSJ1itGSY8vva2uZOI7NvQEkt029t5ZJiCUvPy9VSpx3Asg8AZCGjNI8uHGwWL zEKCslzMsIdKAQT0FqUW5mCar8K0ZxDkYlYV5tkLU8mXklcFtfAR3EBHTQTxewg0oSEVJSDYw euvOkjl+VqJJWCNhy+OYe1+ysEy15PUJXBd6VnY/8kq3ScWvJbzXutiuT7s/qsfDMUi52tvKq 99TbnsAoqiyxZOvSosXfH77xuZf6bpm4TM09BTE9rhkeu68b/2r8vcHhUPqkuj2mU7uCAqYcX PtR1Pz0WdbD1hcjbJvLsnUNBPyv5imVqiuxFGckGmoxFxUnAgBgI+UNwAIAAA== X-Env-Sender: tamas.lengyel@zentific.com X-Msg-Ref: server-8.tower-21.messagelabs.com!1467743877!22388396!1 X-Originating-IP: [209.85.223.194] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.46; banners=-,-,- X-VirusChecked: Checked Received: (qmail 7813 invoked from network); 5 Jul 2016 18:37:58 -0000 Received: from mail-io0-f194.google.com (HELO mail-io0-f194.google.com) (209.85.223.194) by server-8.tower-21.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 5 Jul 2016 18:37:58 -0000 Received: by mail-io0-f194.google.com with SMTP id u25so21561634iou.2 for ; Tue, 05 Jul 2016 11:37:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zentific-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=LXBr3I6fDcdeE0tA8iNz51gWKCt2dW0UNsQHhxA8W+Y=; b=qFCC1cmcIURRelCSWrYe+8wXpJX/sVUItTbw9rXgAOSkYlT6a4V50Hat4+ZUFwju8p bebeJR5NDI/Vcvg6ToLp0BZwdLho7cfK2nCO6bZ2qXr1xqDsC71iqH2mZQ/xzxHcBiFP 2rHbRpM91+TLMmHE6J14Kwy937Yy2bCPOKfeSK+zt18m9YBonBWk8JfslJAFD5lyqq41 AMRkc5TdK+E/xLMJeAV7DrXydFWaTs2He6ux0SowgDFEIEwUaUE2PTaRPzDkDP5dtroX KLlpLCPkkDO/g/94vgzJ/3qD20BqFwqoIWS0Z2Stl1NEhq8uvN/ybcNMrxEPeI3CKoS3 Ct7g== 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=LXBr3I6fDcdeE0tA8iNz51gWKCt2dW0UNsQHhxA8W+Y=; b=GplyMybJuB7b3J39F+KSnsG/gkPM70WpidgHQh1J71CDCNXvIgE3TxZX2ut0C5ubc1 tqxDoXakOhcdgBbywFqvqxxy56ks8eUcV7WTW9tFRm3D1ELPtduXjEqI/9JjoVQJo+f2 iNGz57dqNn0U3yf5PvDzzCe4i67wuai0mxBf/PiLUfom+BHK/TsYT2sQk15DKq/vjHzM H8QTt18Kx77Qi+LZflAy6uAld3HOPHcfGlQAn061ev5TfPuaTy56Er+knTrOZcVRCV94 yhAabhAe9j0kWTq4yQBICOr8JHQ6z295WkAP1x6M2u5bljhubKCvmGVE8l2c/lSh2Rmx 3mkw== X-Gm-Message-State: ALyK8tISNo/SWa0iEVn+sx1SwzmRg1yOit13R3JRUeKbP0Tlwx0NVGZKxvjVhJN2t84+gw== X-Received: by 10.107.48.193 with SMTP id w184mr17420556iow.140.1467743877106; Tue, 05 Jul 2016 11:37:57 -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 o133sm2083760ioo.10.2016.07.05.11.37.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Jul 2016 11:37:56 -0700 (PDT) From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Tue, 5 Jul 2016 12:37:48 -0600 Message-Id: <1467743871-9644-3-git-send-email-tamas.lengyel@zentific.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1467743871-9644-1-git-send-email-tamas.lengyel@zentific.com> References: <1467743871-9644-1-git-send-email-tamas.lengyel@zentific.com> Cc: Tamas K Lengyel , Julien Grall , Stefano Stabellini Subject: [Xen-devel] [PATCH v8 3/6] monitor: 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-Virus-Scanned: ClamAV using ClamSMTP Add support for monitoring ARM SMC events. This patch only adds the required bits to enable/disable monitoring and forwarding the event through vm_event. Signed-off-by: Tamas K Lengyel Acked-by: Razvan Cojocaru --- Cc: Stefano Stabellini Cc: Julien Grall --- xen/arch/arm/Makefile | 1 + xen/arch/arm/monitor.c | 82 +++++++++++++++++++++++++++++++++++++++++++ xen/arch/arm/traps.c | 9 ++++- xen/include/asm-arm/domain.h | 5 +++ xen/include/asm-arm/monitor.h | 22 +++--------- xen/include/public/domctl.h | 1 + xen/include/public/vm_event.h | 10 ++++++ 7 files changed, 112 insertions(+), 18 deletions(-) create mode 100644 xen/arch/arm/monitor.c diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile index 9e38da3..ffb0e96 100644 --- a/xen/arch/arm/Makefile +++ b/xen/arch/arm/Makefile @@ -41,6 +41,7 @@ obj-y += decode.o obj-y += processor.o obj-y += smc.o obj-$(CONFIG_LIVEPATCH) += livepatch.o +obj-y += monitor.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..d609f4f --- /dev/null +++ b/xen/arch/arm/monitor.c @@ -0,0 +1,82 @@ +/* + * arch/arm/monitor.c + * + * Arch-specific monitor_op domctl handler. + * + * Copyright (c) 2016 Tamas K Lengyel (tamas.lengyel@zentific.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 + +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() +{ + struct vcpu *curr = current; + + if ( curr->domain->arch.monitor.privileged_call_enabled ) + { + vm_event_request_t req = { 0 }; + + req.reason = VM_EVENT_REASON_PRIVILEGED_CALL; + req.vcpu_id = curr->vcpu_id; + req.u.privcall.type = PRIVCALL_SMC; + + return monitor_traps(curr, 1, &req); + } + + return 0; +} + +/* + * 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 627e8c9..846ba26 100644 --- a/xen/arch/arm/traps.c +++ b/xen/arch/arm/traps.c @@ -42,6 +42,7 @@ #include #include #include +#include #include "decode.h" #include "vtimer.h" @@ -2509,13 +2510,19 @@ bad_data_abort: static void do_trap_smc(struct cpu_user_regs *regs, const union hsr hsr) { + int rc; + if ( !check_conditional_instr(regs, hsr) ) { advance_pc(regs, hsr); return; } - inject_undef_exception(regs, hsr); + rc = monitor_smc(); + if ( rc < 0 ) + domain_crash_synchronous(); + if ( !rc ) + inject_undef_exception(regs, hsr); } static void enter_hypervisor_head(struct cpu_user_regs *regs) diff --git a/xen/include/asm-arm/domain.h b/xen/include/asm-arm/domain.h index 979f7de..a97bee7 100644 --- a/xen/include/asm-arm/domain.h +++ b/xen/include/asm-arm/domain.h @@ -127,6 +127,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 4af707a..dcb0c5d 100644 --- a/xen/include/asm-arm/monitor.h +++ b/xen/include/asm-arm/monitor.h @@ -32,19 +32,8 @@ 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 int arch_monitor_init_domain(struct domain *d) @@ -61,11 +50,10 @@ void arch_monitor_cleanup_domain(struct domain *d) static inline uint32_t arch_monitor_get_capabilities(struct domain *d) { - uint32_t capabilities = 0; - - capabilities = (1U << XEN_DOMCTL_MONITOR_EVENT_GUEST_REQUEST); - - return capabilities; + return (1U << XEN_DOMCTL_MONITOR_EVENT_GUEST_REQUEST) | + (1U << XEN_DOMCTL_MONITOR_EVENT_PRIVILEGED_CALL); } +int monitor_smc(void); + #endif /* __ASM_ARM_MONITOR_H__ */ diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index 30020ba..8503291 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -1081,6 +1081,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_domctl_psr_cmt_op_t); #define XEN_DOMCTL_MONITOR_EVENT_SOFTWARE_BREAKPOINT 3 #define XEN_DOMCTL_MONITOR_EVENT_GUEST_REQUEST 4 #define XEN_DOMCTL_MONITOR_EVENT_DEBUG_EXCEPTION 5 +#define XEN_DOMCTL_MONITOR_EVENT_PRIVILEGED_CALL 6 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 7bfe6cc..66e27b7 100644 --- a/xen/include/public/vm_event.h +++ b/xen/include/public/vm_event.h @@ -122,6 +122,8 @@ #define VM_EVENT_REASON_GUEST_REQUEST 8 /* A debug exception was caught */ #define VM_EVENT_REASON_DEBUG_EXCEPTION 9 +/* Privileged call executed (e.g. SMC) */ +#define VM_EVENT_REASON_PRIVILEGED_CALL 10 /* Supported values for the vm_event_write_ctrlreg index. */ #define VM_EVENT_X86_CR0 0 @@ -222,6 +224,13 @@ struct vm_event_mov_to_msr { uint64_t value; }; +#define PRIVCALL_SMC 0 + +struct vm_event_privcall { + uint32_t type; /* PRIVCALL_* */ + uint32_t _pad; +}; + #define MEM_PAGING_DROP_PAGE (1 << 0) #define MEM_PAGING_EVICT_FAIL (1 << 1) @@ -260,6 +269,7 @@ typedef struct vm_event_st { struct vm_event_singlestep singlestep; struct vm_event_debug software_breakpoint; struct vm_event_debug debug_exception; + struct vm_event_privcall privcall; } u; union {