From patchwork Thu Oct 12 09:10:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Stefan ISAILA X-Patchwork-Id: 10001271 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 BCE5F602BF for ; Thu, 12 Oct 2017 09:13:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AED5728D2D for ; Thu, 12 Oct 2017 09:13:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A390A28D37; Thu, 12 Oct 2017 09:13:01 +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 13BD128D2D for ; Thu, 12 Oct 2017 09:13:00 +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 1e2ZVv-0004qm-0D; Thu, 12 Oct 2017 09:10:47 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e2ZVt-0004qf-MB for xen-devel@lists.xen.org; Thu, 12 Oct 2017 09:10:45 +0000 Received: from [85.158.139.211] by server-12.bemta-5.messagelabs.com id CE/B9-06262-4913FD95; Thu, 12 Oct 2017 09:10:44 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupgkeJIrShJLcpLzFFi42KJPp7RqjvF8H6 kwY/LTBZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8bdqe1sBd89Kq7sXs3awHjUsouRk4NZwFqi 918zYxcjFweLQDOLxKQd69ggnJ/MEgvX9bF3MXJwCAl4SOzZGQQSFxJYwChx6f80VpBukPi+v 1uZIexljBIX1ieD2GwCBhKvvn5jBLFFBKQlrn2+DLaBWWABk0Tv4g9MIAlhAT2JKU83gdksAq oSnSdfgw3lFXCTWDb1OlhcQkBO4ua5TuYJjHwLGBlWMWoUpxaVpRbpGprqJRVlpmeU5CZm5ug aGpjq5aYWFyemp+YkJhXrJefnbmIEhgoDEOxgbNjueYhRkoNJSZT32r17kUJ8SfkplRmJxRnx RaU5qcWHGGU4OJQkeK/p348UEixKTU+tSMvMAQYtTFqCg0dJhLfBACjNW1yQmFucmQ6ROsWoy 9Fx8+4fJiGWvPy8VClx3jcgMwRAijJK8+BGwCLoEqOslDAvI9BRQjwFqUW5mSWo8q8YxTkYlY R5pUFW8WTmlcBtegV0BBPQEaJpd0COKElESEk1MDZyLJnA8qzj/BP/lt/B686H8Z5c4Bq94A1 3o1V6sMItd/MJjCt+TQx//3LBLv7Tj3lXL27ifrV2nrfW/OO/dV6eSYgUmPdu2VfBhJhPOqtr n7695bX79Jygfckyqd9EG+fWnxCyMNyYYWGzWOhq/zPeD7Okkgql0vaH/1o+ibn5859bvL0Xe EKVWIozEg21mIuKEwHAT9TZmwIAAA== X-Env-Sender: aisaila@bitdefender.com X-Msg-Ref: server-5.tower-206.messagelabs.com!1507799443!105004602!1 X-Originating-IP: [91.199.104.133] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 17922 invoked from network); 12 Oct 2017 09:10:43 -0000 Received: from mx02.bbu.dsd.mx.bitdefender.com (HELO mx02.buh.bitdefender.com) (91.199.104.133) by server-5.tower-206.messagelabs.com with DHE-RSA-AES128-GCM-SHA256 encrypted SMTP; 12 Oct 2017 09:10:43 -0000 Comment: DomainKeys? See http://domainkeys.sourceforge.net/ DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=bitdefender.com; b=pknvrWC4fhCfMQ2qHzXdGPMdJW/a65auP+pTuqRnemFXiAgq0fFHtBKl8AXrbUqvNBNyLQyipFcEr1Tw+7VwdWH00beleV4d/ijx9K7KCfDdD9KcYB/vGwhWXc28DVN6GzMRyB44NAHO7kwxow5swWE3c//4HqXDVBsKpgPkcgJWDBke5OlUqZdxWfedmA9Ep8RjeanPqpx15Gj8ur579LZnP8Id/6ITxlSYv+UJTArSsXgP9vLygeDLgU8UYJfOOP2wafKDzHi9CXBEzeB6bLDc7Qf1RCkLEJQKq6TBs0Sq/nIUGqhDZtiuy7Hf4k21qt3Fimh823qOhdSlsuMmuA==; h=Received:Received:Received:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer; DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=bitdefender.com; h=from:to :cc:subject:date:message-id; s=default; bh=xSXrjLkd1AjZtJ+5co3jm hA93pw=; b=glWe1GVo1VcSMS9OkTjLV2DlYKyU5gvRdsYbsfTAdPp62IoNPgri9 biU77jqFi0X63XNPH7JKgqevfphWF6WkKyq+mnniT3zAsyDwPCLXj7HmBBHo9RFd hnkh6FnlgjfhID/09qMTJSBPoIgIyjic1x38jzmepA++AQZ9HeR1xYIMp8OnjbM6 0hhxdCgW4QV69uUBgVsxXKmi7O342duJ1C5HTp0xLiZHKwDkc3XlDajeOP94t9ck +jDYcCPk8tTZGThYtTO36rosRpu6N4mCzpg5uh0Q7Z3lVFXlT63rd5uaDN1SesEr BN10aOHVOklo9n4g3BmFEbF84L0Ob/+nA== Received: (qmail 28388 invoked from network); 12 Oct 2017 12:10:41 +0300 Received: from mx01robo.bbu.dsd.mx.bitdefender.com (10.17.80.60) by mx02.buh.bitdefender.com with AES128-GCM-SHA256 encrypted SMTP; 12 Oct 2017 12:10:41 +0300 Received: (qmail 13472 invoked from network); 12 Oct 2017 12:10:40 +0300 Received: from unknown (HELO aisaila-Latitude-E5570.dsd.bitdefender.biz) (10.10.195.54) by mx01robo.bbu.dsd.mx.bitdefender.com with SMTP; 12 Oct 2017 12:10:40 +0300 From: Alexandru Isaila To: xen-devel@lists.xen.org Date: Thu, 12 Oct 2017 12:10:25 +0300 Message-Id: <1507799425-3286-1-git-send-email-aisaila@bitdefender.com> X-Mailer: git-send-email 2.7.4 Cc: sstabellini@kernel.org, wei.liu2@citrix.com, rcojocaru@bitdefender.com, konrad.wilk@oracle.com, George.Dunlap@eu.citrix.com, andrew.cooper3@citrix.com, ian.jackson@eu.citrix.com, tim@xen.org, tamas@tklengyel.com, jbeulich@suse.com, Alexandru Isaila Subject: [Xen-devel] [PATCH v1] x86/hvm: Add MSR old value 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 This patch adds the old value param and the onchangeonly option to the VM_EVENT_REASON_MOV_TO_MSR event. The param was added to the vm_event_mov_to_msr struct and to the hvm_monitor_msr function. Finally I've changed the bool_t param to a bool for the hvm_msr_write_intercept function. Signed-off-by: Alexandru Isaila Acked-by: Tamas K Lengyel Acked-by: Wei Liu --- tools/libxc/include/xenctrl.h | 2 +- tools/libxc/xc_monitor.c | 3 ++- xen/arch/x86/hvm/hvm.c | 10 ++++++++-- xen/arch/x86/hvm/monitor.c | 9 ++++++--- xen/arch/x86/monitor.c | 26 +++++++++++++++++++++++--- xen/include/asm-x86/hvm/monitor.h | 2 +- xen/include/asm-x86/hvm/support.h | 2 +- xen/include/asm-x86/monitor.h | 2 ++ xen/include/public/domctl.h | 2 ++ xen/include/public/vm_event.h | 5 +++-- 10 files changed, 49 insertions(+), 14 deletions(-) diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index 3bcab3c..b99d6eb 100644 --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -2048,7 +2048,7 @@ int xc_monitor_write_ctrlreg(xc_interface *xch, domid_t domain_id, * non-architectural indices. */ int xc_monitor_mov_to_msr(xc_interface *xch, domid_t domain_id, uint32_t msr, - bool enable); + bool enable, bool onchangeonly); int xc_monitor_singlestep(xc_interface *xch, domid_t domain_id, bool enable); int xc_monitor_software_breakpoint(xc_interface *xch, domid_t domain_id, bool enable); diff --git a/tools/libxc/xc_monitor.c b/tools/libxc/xc_monitor.c index 6046680..09d04be 100644 --- a/tools/libxc/xc_monitor.c +++ b/tools/libxc/xc_monitor.c @@ -90,7 +90,7 @@ int xc_monitor_write_ctrlreg(xc_interface *xch, domid_t domain_id, } int xc_monitor_mov_to_msr(xc_interface *xch, domid_t domain_id, uint32_t msr, - bool enable) + bool enable, bool onchangeonly) { DECLARE_DOMCTL; @@ -100,6 +100,7 @@ int xc_monitor_mov_to_msr(xc_interface *xch, domid_t domain_id, uint32_t msr, : XEN_DOMCTL_MONITOR_OP_DISABLE; domctl.u.monitor_op.event = XEN_DOMCTL_MONITOR_EVENT_MOV_TO_MSR; domctl.u.monitor_op.u.mov_to_msr.msr = msr; + domctl.u.monitor_op.u.mov_to_msr.onchangeonly = onchangeonly; return do_domctl(xch, &domctl); } diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 205b4cb..0238787 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -3489,7 +3489,7 @@ int hvm_msr_read_intercept(unsigned int msr, uint64_t *msr_content) } int hvm_msr_write_intercept(unsigned int msr, uint64_t msr_content, - bool_t may_defer) + bool may_defer) { struct vcpu *v = current; struct domain *d = v->domain; @@ -3500,6 +3500,12 @@ int hvm_msr_write_intercept(unsigned int msr, uint64_t msr_content, if ( may_defer && unlikely(monitored_msr(v->domain, msr)) ) { + uint64_t msr_old_content; + + ret = hvm_msr_read_intercept(msr, &msr_old_content); + if ( ret != X86EMUL_OKAY ) + return ret; + ASSERT(v->arch.vm_event); /* The actual write will occur in hvm_do_resume() (if permitted). */ @@ -3507,7 +3513,7 @@ int hvm_msr_write_intercept(unsigned int msr, uint64_t msr_content, v->arch.vm_event->write_data.msr = msr; v->arch.vm_event->write_data.value = msr_content; - hvm_monitor_msr(msr, msr_content); + hvm_monitor_msr(msr, msr_content, msr_old_content); return X86EMUL_OKAY; } diff --git a/xen/arch/x86/hvm/monitor.c b/xen/arch/x86/hvm/monitor.c index 4ce778c..74f83b4 100644 --- a/xen/arch/x86/hvm/monitor.c +++ b/xen/arch/x86/hvm/monitor.c @@ -74,16 +74,19 @@ bool hvm_monitor_emul_unimplemented(void) monitor_traps(curr, true, &req) == 1; } -void hvm_monitor_msr(unsigned int msr, uint64_t value) +void hvm_monitor_msr(unsigned int msr, uint64_t new_value, uint64_t old_value) { struct vcpu *curr = current; - if ( monitored_msr(curr->domain, msr) ) + if ( monitored_msr(curr->domain, msr) && + ( !monitored_msr_onchangeonly(curr->domain, msr) || + new_value != old_value ) ) { vm_event_request_t req = { .reason = VM_EVENT_REASON_MOV_TO_MSR, .u.mov_to_msr.msr = msr, - .u.mov_to_msr.value = value, + .u.mov_to_msr.new_value = new_value, + .u.mov_to_msr.old_value = old_value }; monitor_traps(curr, 1, &req); diff --git a/xen/arch/x86/monitor.c b/xen/arch/x86/monitor.c index e59f1f5..a3046c6 100644 --- a/xen/arch/x86/monitor.c +++ b/xen/arch/x86/monitor.c @@ -25,7 +25,7 @@ int arch_monitor_init_domain(struct domain *d) { if ( !d->arch.monitor.msr_bitmap ) - d->arch.monitor.msr_bitmap = xzalloc(struct monitor_msr_bitmap); + d->arch.monitor.msr_bitmap = xzalloc_array(struct monitor_msr_bitmap, 2); if ( !d->arch.monitor.msr_bitmap ) return -ENOMEM; @@ -67,7 +67,7 @@ static unsigned long *monitor_bitmap_for_msr(const struct domain *d, u32 *msr) } } -static int monitor_enable_msr(struct domain *d, u32 msr) +static int monitor_enable_msr(struct domain *d, u32 msr, bool onchangeonly) { unsigned long *bitmap; u32 index = msr; @@ -84,6 +84,11 @@ static int monitor_enable_msr(struct domain *d, u32 msr) hvm_enable_msr_interception(d, msr); + if( onchangeonly ) + __set_bit(index + sizeof(struct monitor_msr_bitmap), bitmap); + else + __clear_bit(index + sizeof(struct monitor_msr_bitmap), bitmap); + return 0; } @@ -119,6 +124,21 @@ bool monitored_msr(const struct domain *d, u32 msr) return test_bit(msr, bitmap); } +bool monitored_msr_onchangeonly(const struct domain *d, u32 msr) +{ + const unsigned long *bitmap; + + if ( !d->arch.monitor.msr_bitmap ) + return false; + + bitmap = monitor_bitmap_for_msr(d, &msr); + + if ( !bitmap ) + return false; + + return test_bit(msr + sizeof(struct monitor_msr_bitmap), bitmap); +} + int arch_monitor_domctl_event(struct domain *d, struct xen_domctl_monitor_op *mop) { @@ -198,7 +218,7 @@ int arch_monitor_domctl_event(struct domain *d, } if ( requested_status ) - rc = monitor_enable_msr(d, msr); + rc = monitor_enable_msr(d, msr, mop->u.mov_to_msr.onchangeonly); else rc = monitor_disable_msr(d, msr); diff --git a/xen/include/asm-x86/hvm/monitor.h b/xen/include/asm-x86/hvm/monitor.h index 6e22091..260d7b0 100644 --- a/xen/include/asm-x86/hvm/monitor.h +++ b/xen/include/asm-x86/hvm/monitor.h @@ -37,7 +37,7 @@ bool hvm_monitor_cr(unsigned int index, unsigned long value, unsigned long old); #define hvm_monitor_crX(cr, new, old) \ hvm_monitor_cr(VM_EVENT_X86_##cr, new, old) -void hvm_monitor_msr(unsigned int msr, uint64_t value); +void hvm_monitor_msr(unsigned int msr, uint64_t new_value, uint64_t old_value); void hvm_monitor_descriptor_access(uint64_t exit_info, uint64_t vmx_exit_qualification, uint8_t descriptor, bool is_write); diff --git a/xen/include/asm-x86/hvm/support.h b/xen/include/asm-x86/hvm/support.h index d784fc1..ac33eea 100644 --- a/xen/include/asm-x86/hvm/support.h +++ b/xen/include/asm-x86/hvm/support.h @@ -154,7 +154,7 @@ void hvm_ud_intercept(struct cpu_user_regs *); int __must_check hvm_msr_read_intercept( unsigned int msr, uint64_t *msr_content); int __must_check hvm_msr_write_intercept( - unsigned int msr, uint64_t msr_content, bool_t may_defer); + unsigned int msr, uint64_t msr_content, bool may_defer); #endif /* __ASM_X86_HVM_SUPPORT_H__ */ diff --git a/xen/include/asm-x86/monitor.h b/xen/include/asm-x86/monitor.h index 0ada970..575b3c6 100644 --- a/xen/include/asm-x86/monitor.h +++ b/xen/include/asm-x86/monitor.h @@ -105,4 +105,6 @@ void arch_monitor_cleanup_domain(struct domain *d); bool monitored_msr(const struct domain *d, u32 msr); +bool monitored_msr_onchangeonly(const struct domain *d, u32 msr); + #endif /* __ASM_X86_MONITOR_H__ */ diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index 8853445..3dfadae 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -1046,6 +1046,8 @@ struct xen_domctl_monitor_op { struct { uint32_t msr; + /* Send event only on a change of value */ + uint8_t onchangeonly; } mov_to_msr; struct { diff --git a/xen/include/public/vm_event.h b/xen/include/public/vm_event.h index b531f71..36e3f46 100644 --- a/xen/include/public/vm_event.h +++ b/xen/include/public/vm_event.h @@ -29,7 +29,7 @@ #include "xen.h" -#define VM_EVENT_INTERFACE_VERSION 0x00000002 +#define VM_EVENT_INTERFACE_VERSION 0x00000003 #if defined(__XEN__) || defined(__XEN_TOOLS__) @@ -260,7 +260,8 @@ struct vm_event_debug { struct vm_event_mov_to_msr { uint64_t msr; - uint64_t value; + uint64_t new_value; + uint64_t old_value; }; #define VM_EVENT_DESC_IDTR 1