From: Tamas K Lengyel <tamas.lengyel@zentific.com>
To: xen-devel@lists.xenproject.org
Cc: Tamas K Lengyel <tamas.lengyel@zentific.com>,
Julien Grall <julien.grall@arm.com>,
Stefano Stabellini <sstabellini@kernel.org>
Subject: [PATCH v8 3/6] monitor: ARM SMC events
Date: Tue, 5 Jul 2016 12:37:48 -0600 [thread overview]
Message-ID: <1467743871-9644-3-git-send-email-tamas.lengyel@zentific.com> (raw)
In-Reply-To: <1467743871-9644-1-git-send-email-tamas.lengyel@zentific.com>
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 <tamas.lengyel@zentific.com>
Acked-by: Razvan Cojocaru <rcojocaru@bitdefender.com>
---
Cc: Stefano Stabellini <sstabellini@kernel.org>
Cc: Julien Grall <julien.grall@arm.com>
---
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 <http://www.gnu.org/licenses/>.
+ */
+
+#include <asm/monitor.h>
+#include <xen/monitor.h>
+
+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 <asm/mmio.h>
#include <asm/cpufeature.h>
#include <asm/flushtlb.h>
+#include <asm/monitor.h>
#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 {
--
2.8.1
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2016-07-05 18:37 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-05 18:37 [PATCH v8 1/6] monitor: rename and relocate vm_event_monitor_traps Tamas K Lengyel
2016-07-05 18:37 ` [PATCH v8 2/6] arm: filter SMC exceptions with failed condition checks Tamas K Lengyel
2016-07-06 17:31 ` Julien Grall
2016-07-06 18:52 ` Tamas K Lengyel
2016-07-05 18:37 ` Tamas K Lengyel [this message]
2016-07-05 18:37 ` [PATCH v8 4/6] arm/vm_event: get/set registers Tamas K Lengyel
2016-07-06 7:43 ` Jan Beulich
2016-07-06 7:59 ` Razvan Cojocaru
2016-07-06 17:39 ` Julien Grall
2016-07-06 19:23 ` Tamas K Lengyel
2016-07-06 21:12 ` Julien Grall
2016-07-06 22:01 ` Tamas K Lengyel
2016-07-06 18:04 ` Julien Grall
2016-07-06 19:12 ` Tamas K Lengyel
2016-07-07 8:23 ` Jan Beulich
2016-07-07 9:46 ` Julien Grall
2016-07-07 9:57 ` Jan Beulich
2016-07-07 10:09 ` Julien Grall
2016-07-07 15:53 ` Tamas K Lengyel
2016-07-05 18:37 ` [PATCH v8 5/6] tools/libxc: add xc_monitor_privileged_call Tamas K Lengyel
2016-07-05 18:37 ` [PATCH v8 6/6] tools/xen-access: add test-case for ARM SMC Tamas K Lengyel
2016-07-07 10:05 ` Julien Grall
2016-07-07 15:54 ` Tamas K Lengyel
2016-07-05 19:15 ` [PATCH v8 1/6] monitor: rename and relocate vm_event_monitor_traps Razvan Cojocaru
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1467743871-9644-3-git-send-email-tamas.lengyel@zentific.com \
--to=tamas.lengyel@zentific.com \
--cc=julien.grall@arm.com \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).