From patchwork Sat Jul 9 04:17:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corneliu ZUZU X-Patchwork-Id: 9221983 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 6239360467 for ; Sat, 9 Jul 2016 04:20:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 536B2285CD for ; Sat, 9 Jul 2016 04:20:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 47C1828615; Sat, 9 Jul 2016 04:20:49 +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 99282285CD for ; Sat, 9 Jul 2016 04:20:48 +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 1bLjir-00023h-Rp; Sat, 09 Jul 2016 04:18:33 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bLjir-00023Q-2P for xen-devel@lists.xen.org; Sat, 09 Jul 2016 04:18:33 +0000 Received: from [85.158.137.68] by server-3.bemta-3.messagelabs.com id AE/1D-31810-81B70875; Sat, 09 Jul 2016 04:18:32 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrGIsWRWlGSWpSXmKPExsUSfTxjoa54dUO 4wbuT6hZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8b2dcsZC65bV8y+NpO9gfGDbhcjJ4eQgLvE jbVrWbsYuYDsNYwSp09/YYNwTjJKtHWvAMpwADluEvvOMELE1zFKbJ24mRmkm01AW+LcoXtMI LaIgLTEtc+XwYqYBX4ySqz9OB2sSFggVeLQs9tgNouAqsSet0sZQWxeAReJvpc9LCALJATkJB ZcSAcJcwq4Spx7+5oV4joXiRv7JoHNlxDIkVj5bBY7RLmUxP9WJZBVEgLLWCR+LXzGBlEjI/F o4k22CYxCCxgZVjGqF6cWlaUW6ZrrJRVlpmeU5CZm5ugaGhjr5aYWFyemp+YkJhXrJefnbmIE hiEDEOxgbPzudIhRkoNJSZT3gm1DuBBfUn5KZUZicUZ8UWlOavEhRhkODiUJXvEqoJxgUWp6a kVaZg4wImDSEhw8SiK8miBp3uKCxNzizHSI1ClGXY5jc2+sZRJiycvPS5US5+UEKRIAKcoozY MbAYvOS4yyUsK8jEBHCfEUpBblZpagyr9iFOdgVBLmzQKZwpOZVwK36RXQEUxARxgE1IMcUZK IkJJqYKx7xf9qYjK7Tmd0hIATq/w1bc8T5elHN88zfPvnhL7VNNnc99t0T6a8jZD6X+huyJP+ c9/dG2+Z3R5fcw+/a1NUw2i7PTX3JEPyz/sT63ZfL+NKeGG4vVdXIdSPWWrOxJ1LZ9mIsb04k hJxerHKy1pdq/ebTtbeYPN8N9ntrZRn0Dwrm+LvAUosxRmJhlrMRcWJAG26a8HJAgAA X-Env-Sender: czuzu@bitdefender.com X-Msg-Ref: server-3.tower-31.messagelabs.com!1468037911!49609043!1 X-Originating-IP: [91.199.104.161] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.46; banners=-,-,- X-VirusChecked: Checked Received: (qmail 63983 invoked from network); 9 Jul 2016 04:18:31 -0000 Received: from mx01.bbu.dsd.mx.bitdefender.com (HELO mx01.bbu.dsd.mx.bitdefender.com) (91.199.104.161) by server-3.tower-31.messagelabs.com with DHE-RSA-AES128-GCM-SHA256 encrypted SMTP; 9 Jul 2016 04:18:31 -0000 Received: (qmail 12002 invoked from network); 9 Jul 2016 07:18:31 +0300 Received: from unknown (HELO mx-sr.buh.bitdefender.com) (10.17.80.103) by mx01.bbu.dsd.mx.bitdefender.com with AES256-GCM-SHA384 encrypted SMTP; 9 Jul 2016 07:18:31 +0300 Received: from smtp03.buh.bitdefender.org (unknown [10.17.80.77]) by mx-sr.buh.bitdefender.com (Postfix) with ESMTP id A6A387FC00 for ; Sat, 9 Jul 2016 07:18:29 +0300 (EEST) Received: (qmail 4476 invoked from network); 9 Jul 2016 07:18:29 +0300 Received: from 188-24-34-246.rdsnet.ro (HELO localhost.localdomain) (czuzu@bitdefender.com@188.24.34.246) by smtp03.buh.bitdefender.org with SMTP; 9 Jul 2016 07:18:29 +0300 From: Corneliu ZUZU To: xen-devel@lists.xen.org Date: Sat, 9 Jul 2016 07:17:31 +0300 Message-Id: <1468037851-6801-1-git-send-email-czuzu@bitdefender.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1468037509-6428-1-git-send-email-czuzu@bitdefender.com> References: <1468037509-6428-1-git-send-email-czuzu@bitdefender.com> X-BitDefender-Scanner: Clean, Agent: BitDefender qmail 3.1.6 on smtp03.buh.bitdefender.org, sigver: 7.66242 X-BitDefender-Spam: No (0) X-BitDefender-SpamStamp: Build: [Engines: 2.15.6.911, Dats: 425852, Stamp: 3], Multi: [Enabled, t: (0.000010, 0.007199)], BW: [Enabled, t: (0.000007,0.000001)], RBL DNSBL: [Disabled], APM: [Enabled, Score: 500, t: (0.005362), Flags: 85D2ED72; NN_TP_TAG_HTTP; NN_NO_CONTENT_TYPE; NN_LEGIT_SUMM_400_WORDS; NN_LEGIT_BITDEFENDER; NN_LEGIT_S_SQARE_BRACKETS; NN_LEGIT_MAILING_LIST_TO], SGN: [Enabled, t: (0.011702)], URL: [Enabled, t: (0.000019)], RTDA: [Enabled, t: (0.033633), Hit: No, Details: v2.3.10; Id: 2m1ghmj.1amgkr0nl.111pr], total: 0(775) X-BitDefender-CF-Stamp: none Cc: Tamas K Lengyel , Razvan Cojocaru , Andrew Cooper , Julien Grall , Stefano Stabellini , Jan Beulich Subject: [Xen-devel] [PATCH 08/16] x86/vm-event: call monitor init & cleanup funcs from respective vm_event funcs 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 For clarity: do init/cleanup of the vm-events subsystems (e.g. functions monitor_init,cleanup_domain()) from the vm-event_init,cleanup_domain() functions. Done by passing-on the ved param from vm_event_enable,disable() functions down to the vm_event_init,cleanup_domain() functions. This makes it easier to follow the init/cleanup sequences for all vm-events subsystems. In the process, we also replace the vec param of vm_event_enable() with a port param, since the op/mode fields of vec are already handled before the function is called. This was also done because conceptually it was strange relying on the ved param in vm_event_init,cleanup_domain() to determine the target vm-event subsystem when we already had vec->mode in vm_event_enable(). Signed-off-by: Corneliu ZUZU --- xen/arch/x86/monitor.c | 5 +++++ xen/arch/x86/vm_event.c | 15 ++++++++++++--- xen/common/vm_event.c | 18 +++++++----------- xen/include/asm-arm/vm_event.h | 15 ++++++++++++--- xen/include/asm-x86/vm_event.h | 4 ++-- 5 files changed, 38 insertions(+), 19 deletions(-) diff --git a/xen/arch/x86/monitor.c b/xen/arch/x86/monitor.c index 8f41f21..aeee435 100644 --- a/xen/arch/x86/monitor.c +++ b/xen/arch/x86/monitor.c @@ -52,6 +52,7 @@ static inline void monitor_ctrlreg_disable_traps(struct domain *d) } } +/* Implicitly serialized by the domctl lock. */ int monitor_init_domain(struct domain *d) { if ( likely(!d->arch.monitor.msr_bitmap) ) @@ -64,6 +65,10 @@ int monitor_init_domain(struct domain *d) return 0; } +/* + * Implicitly serialized by the domctl lock, + * or on domain cleanup paths only. + */ void monitor_cleanup_domain(struct domain *d) { xfree(d->arch.monitor.msr_bitmap); diff --git a/xen/arch/x86/vm_event.c b/xen/arch/x86/vm_event.c index 22c63ea..e795e5e 100644 --- a/xen/arch/x86/vm_event.c +++ b/xen/arch/x86/vm_event.c @@ -18,10 +18,11 @@ * License along with this program; If not, see . */ +#include #include /* Implicitly serialized by the domctl lock. */ -int vm_event_init_domain(struct domain *d) +int vm_event_init_domain(struct domain *d, struct vm_event_domain *ved) { int rc = 0; struct vcpu *v; @@ -40,10 +41,14 @@ int vm_event_init_domain(struct domain *d) } } + /* Initialize specified subsystem. */ + if ( &d->vm_event->monitor == ved ) + rc = monitor_init_domain(d); + err: if ( unlikely(rc) ) /* On fail cleanup whatever resources have been partially allocated. */ - vm_event_cleanup_domain(d); + vm_event_cleanup_domain(d, ved); return rc; } @@ -52,10 +57,14 @@ err: * Implicitly serialized by the domctl lock, * or on domain cleanup paths only. */ -void vm_event_cleanup_domain(struct domain *d) +void vm_event_cleanup_domain(struct domain *d, struct vm_event_domain *ved) { struct vcpu *v; + /* Uninitialize specified subsystem. */ + if ( &d->vm_event->monitor == ved ) + monitor_cleanup_domain(d); + /* Per-vcpu uninitializations. */ for_each_vcpu ( d, v ) { diff --git a/xen/common/vm_event.c b/xen/common/vm_event.c index e60e1f2..dafe7bf 100644 --- a/xen/common/vm_event.c +++ b/xen/common/vm_event.c @@ -41,8 +41,8 @@ static int vm_event_enable( struct domain *d, - xen_domctl_vm_event_op_t *vec, struct vm_event_domain *ved, + unsigned long xen_port, int pause_flag, int param, xen_event_channel_notification_t notification_fn) @@ -64,7 +64,7 @@ static int vm_event_enable( vm_event_ring_lock_init(ved); vm_event_ring_lock(ved); - rc = vm_event_init_domain(d); + rc = vm_event_init_domain(d, ved); if ( rc < 0 ) goto err; @@ -83,7 +83,7 @@ static int vm_event_enable( if ( rc < 0 ) goto err; - ved->xen_port = vec->port = rc; + ved->xen_port = xen_port = rc; /* Prepare ring buffer */ FRONT_RING_INIT(&ved->front_ring, @@ -232,7 +232,7 @@ static int vm_event_disable(struct domain *d, struct vm_event_domain *ved) destroy_ring_for_helper(&ved->ring_page, ved->ring_pg_struct); - vm_event_cleanup_domain(d); + vm_event_cleanup_domain(d, ved); vm_event_ring_unlock(ved); } @@ -630,7 +630,7 @@ int vm_event_domctl(struct domain *d, xen_domctl_vm_event_op_t *vec, break; /* domain_pause() not required here, see XSA-99 */ - rc = vm_event_enable(d, vec, ved, _VPF_mem_paging, + rc = vm_event_enable(d, ved, vec->port, _VPF_mem_paging, HVM_PARAM_PAGING_RING_PFN, mem_paging_notification); } @@ -669,10 +669,7 @@ int vm_event_domctl(struct domain *d, xen_domctl_vm_event_op_t *vec, { case XEN_VM_EVENT_ENABLE: /* domain_pause() not required here, see XSA-99 */ - rc = monitor_init_domain(d); - if ( rc ) - break; - rc = vm_event_enable(d, vec, ved, _VPF_mem_access, + rc = vm_event_enable(d, ved, vec->port, _VPF_mem_access, HVM_PARAM_MONITOR_RING_PFN, monitor_notification); break; @@ -682,7 +679,6 @@ int vm_event_domctl(struct domain *d, xen_domctl_vm_event_op_t *vec, { domain_pause(d); rc = vm_event_disable(d, ved); - monitor_cleanup_domain(d); domain_unpause(d); } break; @@ -721,7 +717,7 @@ int vm_event_domctl(struct domain *d, xen_domctl_vm_event_op_t *vec, break; /* domain_pause() not required here, see XSA-99 */ - rc = vm_event_enable(d, vec, ved, _VPF_mem_sharing, + rc = vm_event_enable(d, ved, vec->port, _VPF_mem_sharing, HVM_PARAM_SHARING_RING_PFN, mem_sharing_notification); break; diff --git a/xen/include/asm-arm/vm_event.h b/xen/include/asm-arm/vm_event.h index 0129b04..93fc4db 100644 --- a/xen/include/asm-arm/vm_event.h +++ b/xen/include/asm-arm/vm_event.h @@ -23,14 +23,23 @@ #include #include -static inline int vm_event_init_domain(struct domain *d) +static inline +int vm_event_init_domain(struct domain *d, struct vm_event_domain *ved) { - /* Nothing to do. */ + /* Initialize specified subsystem. */ + if ( &d->vm_event->monitor == ved ) + return monitor_init_domain(d); + return 0; } -static inline void vm_event_cleanup_domain(struct domain *d) +static inline +void vm_event_cleanup_domain(struct domain *d, struct vm_event_domain *ved) { + /* Uninitialize specified subsystem. */ + if ( &d->vm_event->monitor == ved ) + monitor_cleanup_domain(d); + memset(&d->monitor, 0, sizeof(d->monitor)); } diff --git a/xen/include/asm-x86/vm_event.h b/xen/include/asm-x86/vm_event.h index c53effb..934f385 100644 --- a/xen/include/asm-x86/vm_event.h +++ b/xen/include/asm-x86/vm_event.h @@ -31,9 +31,9 @@ struct arch_vm_event { struct monitor_write_data write_data; }; -int vm_event_init_domain(struct domain *d); +int vm_event_init_domain(struct domain *d, struct vm_event_domain *ved); -void vm_event_cleanup_domain(struct domain *d); +void vm_event_cleanup_domain(struct domain *d, struct vm_event_domain *ved); void vm_event_toggle_singlestep(struct domain *d, struct vcpu *v);