From: Corneliu ZUZU <czuzu@bitdefender.com>
To: xen-devel@lists.xen.org
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
Tamas K Lengyel <tamas@tklengyel.com>,
Razvan Cojocaru <rcojocaru@bitdefender.com>,
Jan Beulich <jbeulich@suse.com>
Subject: [PATCH 5/7] x86: replace monitor_write_data.do_write with enum
Date: Thu, 16 Jun 2016 17:10:55 +0300 [thread overview]
Message-ID: <1466086255-7661-1-git-send-email-czuzu@bitdefender.com> (raw)
In-Reply-To: <1466085888-7428-1-git-send-email-czuzu@bitdefender.com>
After trapping a control-register write vm-event and -until- deciding if that
write is to be permitted or not (VM_EVENT_FLAG_DENY) and doing the actual write,
there cannot and should not be another trapped control-register write event.
That is: currently -only one- of the fields of monitor_write_data.do_write can
be true at any given moment and therefore it would be more appropriate to
replace those fields with an enum value.
Signed-off-by: Corneliu ZUZU <czuzu@bitdefender.com>
---
xen/arch/x86/hvm/hvm.c | 18 ++++++++-----
xen/arch/x86/vm_event.c | 63 ++++++++++++++------------------------------
xen/include/asm-x86/domain.h | 20 +++++++-------
3 files changed, 41 insertions(+), 60 deletions(-)
diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index 2f48846..4596662 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -2156,8 +2156,9 @@ int hvm_set_cr0(unsigned long value, bool_t may_defer)
/* The actual write will occur in vcpu_enter_write_data(), if
* permitted.
*/
- v->arch.vm_event->write_data.do_write.cr0 = 1;
- v->arch.vm_event->write_data.cr0 = value;
+ ASSERT(MWS_NOWRITE == v->arch.vm_event->write_data.status);
+ v->arch.vm_event->write_data.status = MWS_CR0;
+ v->arch.vm_event->write_data.value = value;
return X86EMUL_OKAY;
}
@@ -2260,8 +2261,9 @@ int hvm_set_cr3(unsigned long value, bool_t may_defer)
/* The actual write will occur in vcpu_enter_write_data(), if
* permitted.
*/
- v->arch.vm_event->write_data.do_write.cr3 = 1;
- v->arch.vm_event->write_data.cr3 = value;
+ ASSERT(MWS_NOWRITE == v->arch.vm_event->write_data.status);
+ v->arch.vm_event->write_data.status = MWS_CR3;
+ v->arch.vm_event->write_data.value = value;
return X86EMUL_OKAY;
}
@@ -2342,8 +2344,9 @@ int hvm_set_cr4(unsigned long value, bool_t may_defer)
/* The actual write will occur in vcpu_enter_write_data(), if
* permitted.
*/
- v->arch.vm_event->write_data.do_write.cr4 = 1;
- v->arch.vm_event->write_data.cr4 = value;
+ ASSERT(MWS_NOWRITE == v->arch.vm_event->write_data.status);
+ v->arch.vm_event->write_data.status = MWS_CR4;
+ v->arch.vm_event->write_data.value = value;
return X86EMUL_OKAY;
}
@@ -3724,7 +3727,8 @@ int hvm_msr_write_intercept(unsigned int msr, uint64_t msr_content,
/* The actual write will occur in vcpu_enter_write_data(), if
* permitted.
*/
- v->arch.vm_event->write_data.do_write.msr = 1;
+ ASSERT(MWS_NOWRITE == v->arch.vm_event->write_data.status);
+ v->arch.vm_event->write_data.status = MWS_MSR;
v->arch.vm_event->write_data.msr = msr;
v->arch.vm_event->write_data.value = msr_content;
diff --git a/xen/arch/x86/vm_event.c b/xen/arch/x86/vm_event.c
index 94b50fc..94342d5 100644
--- a/xen/arch/x86/vm_event.c
+++ b/xen/arch/x86/vm_event.c
@@ -74,30 +74,8 @@ void vm_event_register_write_resume(struct vcpu *v, vm_event_response_t *rsp)
if ( (rsp->flags & VM_EVENT_FLAG_DENY) &&
(rsp->flags & VM_EVENT_FLAG_VCPU_PAUSED) )
{
- struct monitor_write_data *w = &v->arch.vm_event->write_data;
-
- ASSERT(w);
-
- switch ( rsp->reason )
- {
- case VM_EVENT_REASON_MOV_TO_MSR:
- w->do_write.msr = 0;
- break;
- case VM_EVENT_REASON_WRITE_CTRLREG:
- switch ( rsp->u.write_ctrlreg.index )
- {
- case VM_EVENT_X86_CR0:
- w->do_write.cr0 = 0;
- break;
- case VM_EVENT_X86_CR3:
- w->do_write.cr3 = 0;
- break;
- case VM_EVENT_X86_CR4:
- w->do_write.cr4 = 0;
- break;
- }
- break;
- }
+ ASSERT(v->arch.vm_event);
+ v->arch.vm_event->write_data.status = MWS_NOWRITE;
}
}
@@ -208,29 +186,28 @@ static inline void vcpu_enter_write_data(struct vcpu *v)
v->arch.vm_event->emulate_flags = 0;
}
- if ( w->do_write.msr )
- {
- hvm_msr_write_intercept(w->msr, w->value, 0);
- w->do_write.msr = 0;
- }
-
- if ( w->do_write.cr0 )
- {
- hvm_set_cr0(w->cr0, 0);
- w->do_write.cr0 = 0;
- }
+ if ( likely(MWS_NOWRITE == w->status) )
+ return;
- if ( w->do_write.cr4 )
+ switch ( w->status )
{
- hvm_set_cr4(w->cr4, 0);
- w->do_write.cr4 = 0;
+ case MWS_MSR:
+ hvm_msr_write_intercept(w->msr, w->value, 0);
+ break;
+ case MWS_CR0:
+ hvm_set_cr0(w->value, 0);
+ break;
+ case MWS_CR3:
+ hvm_set_cr3(w->value, 0);
+ break;
+ case MWS_CR4:
+ hvm_set_cr4(w->value, 0);
+ break;
+ default:
+ break;
}
- if ( w->do_write.cr3 )
- {
- hvm_set_cr3(w->cr3, 0);
- w->do_write.cr3 = 0;
- }
+ w->status = MWS_NOWRITE;
}
static inline void vcpu_enter_adjust_traps(struct vcpu *v)
diff --git a/xen/include/asm-x86/domain.h b/xen/include/asm-x86/domain.h
index 783fa4f..0ed2761 100644
--- a/xen/include/asm-x86/domain.h
+++ b/xen/include/asm-x86/domain.h
@@ -259,19 +259,19 @@ struct pv_domain
struct cpuidmasks *cpuidmasks;
};
-struct monitor_write_data {
- struct {
- unsigned int msr : 1;
- unsigned int cr0 : 1;
- unsigned int cr3 : 1;
- unsigned int cr4 : 1;
- } do_write;
+enum monitor_write_status
+{
+ MWS_NOWRITE = 0,
+ MWS_MSR,
+ MWS_CR0,
+ MWS_CR3,
+ MWS_CR4,
+};
+struct monitor_write_data {
+ enum monitor_write_status status;
uint32_t msr;
uint64_t value;
- uint64_t cr0;
- uint64_t cr3;
- uint64_t cr4;
};
struct arch_domain
--
2.5.0
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
next prev parent reply other threads:[~2016-06-16 14:10 UTC|newest]
Thread overview: 73+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-16 14:04 [PATCH 0/7] vm-event: Implement ARM support for control-register writes Corneliu ZUZU
2016-06-16 14:06 ` [PATCH 1/7] minor (formatting) fixes Corneliu ZUZU
2016-06-16 14:24 ` Jan Beulich
2016-06-16 19:19 ` Corneliu ZUZU
2016-06-17 7:06 ` Jan Beulich
2016-06-17 10:46 ` Corneliu ZUZU
2016-06-16 16:02 ` Tamas K Lengyel
2016-06-17 8:33 ` Corneliu ZUZU
2016-06-17 8:36 ` Razvan Cojocaru
2016-06-17 9:29 ` Andrew Cooper
2016-06-17 9:35 ` Jan Beulich
2016-06-17 9:33 ` Jan Beulich
2016-06-17 9:36 ` Razvan Cojocaru
2016-06-17 9:40 ` Jan Beulich
2016-06-17 9:42 ` Razvan Cojocaru
2016-06-17 19:05 ` Tamas K Lengyel
2016-06-16 14:07 ` [PATCH 2/7] vm-event: VM_EVENT_FLAG_DENY requires VM_EVENT_FLAG_VCPU_PAUSED Corneliu ZUZU
2016-06-16 16:11 ` Tamas K Lengyel
2016-06-17 8:43 ` Corneliu ZUZU
2016-06-21 11:26 ` Corneliu ZUZU
2016-06-21 15:09 ` Tamas K Lengyel
2016-06-22 8:34 ` Corneliu ZUZU
2016-06-16 14:08 ` [PATCH 3/7] vm-event: introduce vm_event_vcpu_enter Corneliu ZUZU
2016-06-16 14:51 ` Jan Beulich
2016-06-16 20:10 ` Corneliu ZUZU
2016-06-16 20:33 ` Razvan Cojocaru
2016-06-17 10:41 ` Corneliu ZUZU
2016-06-17 7:17 ` Jan Beulich
2016-06-17 11:13 ` Corneliu ZUZU
2016-06-17 11:27 ` Jan Beulich
2016-06-17 12:13 ` Corneliu ZUZU
2016-06-16 16:17 ` Tamas K Lengyel
2016-06-17 9:19 ` Corneliu ZUZU
2016-06-17 8:55 ` Julien Grall
2016-06-17 11:40 ` Corneliu ZUZU
2016-06-17 13:22 ` Julien Grall
2016-06-16 14:09 ` [PATCH 4/7] vm-event/x86: use vm_event_vcpu_enter properly Corneliu ZUZU
2016-06-16 15:00 ` Jan Beulich
2016-06-16 20:20 ` Corneliu ZUZU
2016-06-17 7:20 ` Jan Beulich
2016-06-17 11:23 ` Corneliu ZUZU
2016-06-16 16:27 ` Tamas K Lengyel
2016-06-17 9:24 ` Corneliu ZUZU
2016-06-16 14:10 ` Corneliu ZUZU [this message]
2016-06-16 14:12 ` [PATCH 6/7] vm-event/arm: move hvm_event_cr->common vm_event_monitor_cr Corneliu ZUZU
2016-06-16 15:16 ` Jan Beulich
2016-06-17 8:25 ` Corneliu ZUZU
2016-06-17 8:38 ` Jan Beulich
2016-06-17 11:31 ` Corneliu ZUZU
2016-06-21 7:08 ` Corneliu ZUZU
2016-06-21 7:20 ` Jan Beulich
2016-06-21 15:22 ` Tamas K Lengyel
2016-06-22 6:33 ` Jan Beulich
2016-06-16 16:55 ` Tamas K Lengyel
2016-06-17 10:37 ` Corneliu ZUZU
2016-06-16 14:13 ` [PATCH 7/7] vm-event/arm: implement support for control-register write vm-events Corneliu ZUZU
2016-06-16 14:26 ` Julien Grall
2016-06-16 19:24 ` Corneliu ZUZU
2016-06-16 21:28 ` Julien Grall
2016-06-17 11:46 ` Corneliu ZUZU
2016-06-16 16:49 ` Julien Grall
2016-06-17 10:36 ` Corneliu ZUZU
2016-06-17 13:18 ` Julien Grall
2016-06-22 16:35 ` Corneliu ZUZU
2016-06-22 17:17 ` Julien Grall
2016-06-22 18:39 ` Corneliu ZUZU
2016-06-22 19:37 ` Corneliu ZUZU
2016-06-22 19:41 ` Julien Grall
2016-06-23 5:31 ` Corneliu ZUZU
2016-06-23 5:49 ` Corneliu ZUZU
2016-06-23 11:11 ` Julien Grall
2016-06-24 9:32 ` Corneliu ZUZU
2016-06-23 11:00 ` Julien Grall
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=1466086255-7661-1-git-send-email-czuzu@bitdefender.com \
--to=czuzu@bitdefender.com \
--cc=andrew.cooper3@citrix.com \
--cc=jbeulich@suse.com \
--cc=rcojocaru@bitdefender.com \
--cc=tamas@tklengyel.com \
--cc=xen-devel@lists.xen.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).