From patchwork Thu Jun 2 22:52:22 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: 9151239 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 EFDC660751 for ; Thu, 2 Jun 2016 22:55:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E1C7026D19 for ; Thu, 2 Jun 2016 22:55:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D6A7528330; Thu, 2 Jun 2016 22:55:06 +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.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED 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 14FFF26D19 for ; Thu, 2 Jun 2016 22:55: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 1b8bTm-0008Uj-O9; Thu, 02 Jun 2016 22:52:42 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b8bTl-0008UJ-HC for xen-devel@lists.xenproject.org; Thu, 02 Jun 2016 22:52:41 +0000 Received: from [85.158.137.68] by server-8.bemta-3.messagelabs.com id F6/D7-06513-8B8B0575; Thu, 02 Jun 2016 22:52:40 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprLIsWRWlGSWpSXmKPExsVyMfT+Id0dOwL CDQ6d5bL4vmUykwOjx+EPV1gCGKNYM/OS8isSWDMm//vOVDDdtWLm5K3MDYyt5l2MXBxCAjMY Jd5MfMkC4kgI9LNKbO16y9TFyAnkxEh8X/2TrYuRA8iukHg4hwUkLCSgIXH7ZiM7RPNEJon/u /6D1bMJaEu0vd7FCmKLCChJ3Fs1GSzOLFArceLBJ7A5wgL6EtsXO4GEWQRUJRYt3wY2k1fAWe LjrY9sEGvlJC5PfwBmcwq4SNzvuMQKsddZYuHT64wTGPkXMDKsYlQvTi0qSy3SNdFLKspMzyj JTczM0TU0MNbLTS0uTkxPzUlMKtZLzs/dxAgMHgYg2MHY+MXpEKMkB5OSKC9jbEC4EF9Sfkpl RmJxRnxRaU5q8SFGGQ4OJQneNduAcoJFqempFWmZOcAwhklLcPAoifA2g6R5iwsSc4sz0yFSp xgtObb8vraWiePY3BtActvUe2uZhFjy8vNSpcR5z4I0CIA0ZJTmwY2DxdolRlkpYV5GoAOFeA pSi3IzS1DlXzGKczAqCfOKbAeawpOZVwK39RXQQUxABxU88gc5qCQRISXVwKgd9azrqGnLXf+ JrYfL2n/dvdKxsqpfQkr0WOZqX44qlbLMBRtXzbh1eMEcl5MrLTT4N0hskNgmrt//mN/u1w6d hX/efntW9GZpnkD+okNzuPf/uPajqaXm3mUesQbu5h0JE9Zpb9aSefxBt7N20e95JyJNJhpfC ZvGqHnpo03SGeUGXw6evhQlluKMREMt5qLiRAAT6UtGsAIAAA== X-Env-Sender: tamas.k.lengyel@gmail.com X-Msg-Ref: server-6.tower-31.messagelabs.com!1464907959!17243036!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 19485 invoked from network); 2 Jun 2016 22:52:39 -0000 Received: from mail-io0-f194.google.com (HELO mail-io0-f194.google.com) (209.85.223.194) by server-6.tower-31.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 2 Jun 2016 22:52:39 -0000 Received: by mail-io0-f194.google.com with SMTP id m17so8316186ioi.3 for ; Thu, 02 Jun 2016 15:52:39 -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=WecnWiy1o9JdWQN1FQXls2FALwVAP/v2Lqes1dpyJ6M=; b=IaPTbfxOBzT0lFgrK3NBLpd+UGpw1RqrWOVNXYgS0I80deD9YvxuDaw5XIrSbRFIPN IptMqXTWc1hVvDOV6MZ/ZEtJpfebTm5ei9j9/8ncX6dOcN8gqFNBut0q8kc1T293J58C //guQtfZovMb9SreAedISNvcgmtTe1huTA5pPvTz7+qGz4EaXufqnYI2dmm8PsKadETV yYaofsoWNmMX/Gz2TUWKcnC/HvNpoZS5CrO33qZWrbj2K0Inu0Pzkj1fF6RPElwC5qte lZLh0ESoFgNUhGwxbU8AlRH4MJiGSuECOXKL/GdmTnt0n5n2DoETnXhkN2mPKXLAPWcg 5sLw== X-Gm-Message-State: ALyK8tJmEp80SSZJy8YGLoVmEJ9oQdWurnzGpqHO5qbp+Rltiz4l6iaqngXDJP7SKK2+5w== X-Received: by 10.107.9.167 with SMTP id 39mr1368225ioj.139.1464907958595; Thu, 02 Jun 2016 15:52:38 -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 t91sm1484649ioi.26.2016.06.02.15.52.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Jun 2016 15:52:37 -0700 (PDT) From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Thu, 2 Jun 2016 16:52:22 -0600 Message-Id: <1464907946-19242-5-git-send-email-tamas@tklengyel.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1464907946-19242-1-git-send-email-tamas@tklengyel.com> References: <1464907946-19242-1-git-send-email-tamas@tklengyel.com> Cc: Julien Grall , Tamas K Lengyel , Stefano Stabellini Subject: [Xen-devel] [PATCH v5 5/9] 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 v5: Add struct vm_event_privcall to hold the SMM call# (ESR_EL2.iss) v4: Style fixes v3: Split parts off as separate patches Union for arm32/64 register structs in vm_event Cosmetic fixes --- xen/arch/arm/Makefile | 1 + xen/arch/arm/monitor.c | 84 +++++++++++++++++++++++++++++++++++++++++++ xen/arch/arm/traps.c | 13 +++++-- xen/include/asm-arm/domain.h | 5 +++ xen/include/asm-arm/monitor.h | 24 ++++--------- xen/include/public/domctl.h | 1 + xen/include/public/vm_event.h | 10 ++++++ 7 files changed, 118 insertions(+), 20 deletions(-) create mode 100644 xen/arch/arm/monitor.c diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile index ead0cc0..344d3ad 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_XSPLICE) += xsplice.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..90a13dd --- /dev/null +++ b/xen/arch/arm/monitor.c @@ -0,0 +1,84 @@ +/* + * arch/arm/monitor.c + * + * Arch-specific monitor_op domctl handler. + * + * 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 + +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; +} + +bool_t monitor_smc(unsigned long iss, const struct cpu_user_regs *regs) +{ + 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 = VM_EVENT_PRIVCALL_SMC; + req.u.privcall.vector = iss; + + if ( vm_event_monitor_traps(curr, 1, &req) > 0 ) + return 1; + } + + 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 aa3e3c2..965c151 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" @@ -2506,6 +2507,14 @@ 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) +{ + bool_t handled = monitor_smc(hsr.iss, regs); + + if ( !handled ) + inject_undef_exception(regs, hsr); +} + static void enter_hypervisor_head(struct cpu_user_regs *regs) { if ( guest_mode(regs) ) @@ -2581,7 +2590,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)); @@ -2614,7 +2623,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/include/asm-arm/domain.h b/xen/include/asm-arm/domain.h index 370cdeb..ed56fc9 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 3fd3c9d..0097be2 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,15 @@ 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); - - return capabilities; + return (1U << XEN_DOMCTL_MONITOR_EVENT_GUEST_REQUEST) | + (1U << XEN_DOMCTL_MONITOR_EVENT_PRIVILEGED_CALL); } +bool_t monitor_smc(unsigned long iss, const struct cpu_user_regs *regs); + #endif /* __ASM_ARM_MONITOR_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..7976080 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 @@ -212,6 +214,13 @@ struct vm_event_mov_to_msr { uint64_t value; }; +#define VM_EVENT_PRIVCALL_SMC 0 + +struct vm_event_privcall { + uint32_t type; + uint32_t vector; /* ESR_EL2.ISS for SMC calls */ +}; + #define MEM_PAGING_DROP_PAGE (1 << 0) #define MEM_PAGING_EVICT_FAIL (1 << 1) @@ -249,6 +258,7 @@ typedef struct vm_event_st { struct vm_event_mov_to_msr mov_to_msr; struct vm_event_debug software_breakpoint; struct vm_event_debug singlestep; + struct vm_event_privcall privcall; } u; union {