From patchwork Wed May 4 14:51:14 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: 9015501 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 E705F9F30C for ; Wed, 4 May 2016 14:53:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E6144203A1 for ; Wed, 4 May 2016 14:53:41 +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 DBD7F203A0 for ; Wed, 4 May 2016 14:53:40 +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 1axy9G-00038V-4p; Wed, 04 May 2016 14:51:34 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1axy9F-00038E-6a for xen-devel@lists.xenproject.org; Wed, 04 May 2016 14:51:33 +0000 Received: from [85.158.139.211] by server-1.bemta-5.messagelabs.com id 6B/0A-32266-47C0A275; Wed, 04 May 2016 14:51:32 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprBIsWRWlGSWpSXmKPExsVyMfT+Nt1iHq1 wg8uHTS2+b5nM5MDocfjDFZYAxijWzLyk/IoE1oyP2+8yFUwxq1g65xZzA+NO7S5GLg4hgZmM Ev+eLmftYuTkkBDoZ5V4sJIJwo6RWHltJ1S8UuLKjIVgtpCAhsTtm43sEM0TmSSm9V1hBkmwC WhLtL3eBVYkIqAkcW/VZCaQImaB1YwSm1/tYexi5OAQFtCX+PwjHaSGRUBVouHkc7B6XgFniY aDz6GWyUlcnv6ADcTmFHCRaDrQzAax2Fli19wnzBMY+RcwMqxiVC9OLSpLLdI11UsqykzPKMl NzMzRNTQw1ctNLS5OTE/NSUwq1kvOz93ECAwfBiDYwfil3/kQoyQHk5Io76ovmuFCfEn5KZUZ icUZ8UWlOanFhxhlODiUJHgjuLXChQSLUtNTK9Iyc4CBDJOW4OBREuHlBknzFhck5hZnpkOkT jEac2z5fW0tE8e2qffWMgmx5OXnpUqJ8xqDlAqAlGaU5sENgkXYJUZZKWFeRqDThHgKUotyM0 tQ5V8xinMwKgnzKoBM4cnMK4Hb9wroFCagU97P1QQ5pSQRISXVwMh48+e3mNc7K8w1BDLWtWz h2nTOWu73Ye7AuKAnf5b4Fubu3/n/I9vBkn/nlty+P1uDv6LUTZj701/2X9vsoi0vPyuQq524 0nfSvetvbxxan/b5+/6fvlEJlxQvBnnrqvcfPacyN86Yf45K5cqXXJ/+lahP/PVuUp9i5dHD8 0tPHjBg26jdc3SFEktxRqKhFnNRcSIAxwOrSqsCAAA= X-Env-Sender: tamas.k.lengyel@gmail.com X-Msg-Ref: server-9.tower-206.messagelabs.com!1462373489!38017685!1 X-Originating-IP: [209.85.223.182] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.34; banners=-,-,- X-VirusChecked: Checked Received: (qmail 460 invoked from network); 4 May 2016 14:51:30 -0000 Received: from mail-io0-f182.google.com (HELO mail-io0-f182.google.com) (209.85.223.182) by server-9.tower-206.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 4 May 2016 14:51:30 -0000 Received: by mail-io0-f182.google.com with SMTP id 190so56419949iow.1 for ; Wed, 04 May 2016 07:51:30 -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=OmdQ37IpRwUmpnSYavmmqFlYR7eNSWQkk3h6WeKuSx4=; b=U0YxVnhWyf/pCJjfW7Ix44F3sD2uRl/OOZF4Nnj5PmrS2WsoPkOBKE5Zw8FYWM1hIA ThaghKqErFArRDuzx9rGncRd9G+tV0FZxTKiJF4s4FV8EGCwMj0oa+kXPcBxKKohLhbg W7XBoP7lg8bpKh480ymE7rNEjARaStAKHDHw2grQ0jFockNIBpSi2NZLaqAzXiEkAYVn HElGcPU0de09LWnDvrUGTPPcHJW8AkbiOno4zXPF2aafYpVkeq5sRPDq9XeshxJepjym ADEY4n/KYcwH6qIh2pV33HBE267DsH4f+PACiWBDhW6tJmWyOtxh3EpD6NadGJJp25QE ML2A== X-Gm-Message-State: AOPr4FWwiyX33H9W9A5GopbbEGvTerSE8KC94H71Vc1WLPFiiU32AHuGrVqLWd+aZUMeeQ== X-Received: by 10.107.188.71 with SMTP id m68mr11735272iof.1.1462373489523; Wed, 04 May 2016 07:51:29 -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 u187sm1563597iod.3.2016.05.04.07.51.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 May 2016 07:51:28 -0700 (PDT) From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Wed, 4 May 2016 08:51:14 -0600 Message-Id: <1462373480-20206-3-git-send-email-tamas@tklengyel.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1462373480-20206-1-git-send-email-tamas@tklengyel.com> References: <1462373480-20206-1-git-send-email-tamas@tklengyel.com> Cc: Julien Grall , Tamas K Lengyel , Stefano Stabellini , Razvan Cojocaru Subject: [Xen-devel] [PATCH v3 3/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-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 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 Cc: Razvan Cojocaru v3: Split parts off as separate patches Union for arm32/64 register structs in vm_event Cosmetic fixes --- xen/arch/arm/monitor.c | 49 +++++++++++++++++++++++++++++++++++++++++++ xen/arch/arm/traps.c | 16 ++++++++++++-- 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 | 2 ++ 6 files changed, 77 insertions(+), 20 deletions(-) diff --git a/xen/arch/arm/monitor.c b/xen/arch/arm/monitor.c index f957257..9c481ac 100644 --- a/xen/arch/arm/monitor.c +++ b/xen/arch/arm/monitor.c @@ -22,6 +22,55 @@ #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(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; + + if ( vm_event_monitor_traps(curr, 1, &req) <= 0 ) + return 0; + else + return 1; +} + void monitor_guest_request(void) { struct vcpu *curr = current; diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c index 9abfc3c..f26e12e 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,17 @@ 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 = 0; + + if ( current->domain->arch.monitor.privileged_call_enabled ) + handled = monitor_smc(regs); + + if ( handled != 1 ) + inject_undef_exception(regs, hsr); +} + static void enter_hypervisor_head(struct cpu_user_regs *regs) { if ( guest_mode(regs) ) @@ -2566,7 +2578,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 +2611,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 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..9a10d1f 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(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..3acf217 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