From patchwork Thu May 4 09:00:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Razvan Cojocaru X-Patchwork-Id: 9711027 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 BBAF860362 for ; Thu, 4 May 2017 09:03:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A386528693 for ; Thu, 4 May 2017 09:03:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9386C28694; Thu, 4 May 2017 09:03: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.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 86BEF2869C for ; Thu, 4 May 2017 09:03: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 1d6Ccs-0003dR-HY; Thu, 04 May 2017 09:00:42 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d6Ccq-0003co-Ns for xen-devel@lists.xen.org; Thu, 04 May 2017 09:00:40 +0000 Received: from [85.158.139.211] by server-9.bemta-5.messagelabs.com id A5/A4-01999-8BDEA095; Thu, 04 May 2017 09:00:40 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrDIsWRWlGSWpSXmKPExsUSfTxjoe6Wt1y RBrNWiVgs+biYxYHR4+ju30wBjFGsmXlJ+RUJrBl3b0xjLdjhVnF+6jO2BsZXpl2MnBxCAu4S j/cvZOli5AKy1zBKXFrXwwbhXGOUeH3gGytM1c3NXVBV+xgltjdOBEuwCRhKrN7YwgZiiwhIS 1z7fJkRxGYWKJW4NLEfzBYWsJNouPIEyObgYBFQlTh22R0kzCvgKbHn5DOwEgkBOYmTxyazgp RwCnhJHNluAbHWU+LN9Q52iJIciR2He5lASiQEpCT+tyqBXCMhsJxFYvu071A1MhKPJt5km8A otICRYRWjRnFqUVlqka6RiV5SUWZ6RkluYmaOrqGBqV5uanFxYnpqTmJSsV5yfu4mRmAY1jMw MO5gvDnZ7xCjJAeTkiiv+iv2SCG+pPyUyozE4oz4otKc1OJDjDIcHEoSvHvecEUKCRalpqdWp GXmACMCJi3BwaMkwhsEkuYtLkjMLc5Mh0idYjTmeLf0w3smjiutH98zCbHk5eelSonzLgUpFQ ApzSjNgxsEi9RLjLJSwryMDAwMQjwFqUW5mSWo8q8YxTkYlYR5k0Gm8GTmlcDtewV0ChPQKc2 yHCCnlCQipKQaGJe9yVnpWiaferxck0Hhapvxs+5SF6usCbuq+9LVQ+znLm6O+Cp8OFLteepk +V1MvRfzuM83ck6xmrB2ffW/D0YdX8LdXbOTF2+KFtYK7d7VXbkz0DVyb1DA3bLZVpenHuqZs 3zmM81vz3pFRFhKAsNmmeSabZjT0Pr+yseb4o5vD7UoCM1PUmIpzkg01GIuKk4EAE+8wEvPAg AA X-Env-Sender: rcojocaru@bitdefender.com X-Msg-Ref: server-8.tower-206.messagelabs.com!1493888435!96193009!1 X-Originating-IP: [91.199.104.161] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.12; banners=-,-,- X-VirusChecked: Checked Received: (qmail 31038 invoked from network); 4 May 2017 09:00:36 -0000 Received: from mx01.bbu.dsd.mx.bitdefender.com (HELO mx01.bbu.dsd.mx.bitdefender.com) (91.199.104.161) by server-8.tower-206.messagelabs.com with DHE-RSA-AES128-GCM-SHA256 encrypted SMTP; 4 May 2017 09:00:36 -0000 Received: (qmail 16145 invoked from network); 4 May 2017 12:00:34 +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; 4 May 2017 12:00:34 +0300 Received: from smtp02.buh.bitdefender.net (smtp.bitdefender.biz [10.17.80.76]) by mx-sr.buh.bitdefender.com (Postfix) with ESMTP id 60EC57FE54 for ; Thu, 4 May 2017 12:00:34 +0300 (EEST) Received: (qmail 32596 invoked from network); 4 May 2017 12:00:34 +0300 Received: from xen.dsd.ro (HELO xen.dsd.bitdefender.biz) (rcojocaru@bitdefender.com@10.10.14.109) by smtp02.buh.bitdefender.net with AES128-SHA256 encrypted SMTP; 4 May 2017 12:00:34 +0300 From: Razvan Cojocaru To: xen-devel@lists.xen.org Date: Thu, 4 May 2017 12:00:16 +0300 Message-Id: <1493888417-20803-2-git-send-email-rcojocaru@bitdefender.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1493888417-20803-1-git-send-email-rcojocaru@bitdefender.com> References: <1493888417-20803-1-git-send-email-rcojocaru@bitdefender.com> X-BitDefender-Scanner: Clean, Agent: BitDefender qmail 3.1.6 on smtp02.buh.bitdefender.net, sigver: 7.71216 X-BitDefender-Spam: No (0) X-BitDefender-SpamStamp: Build: [Engines: 2.15.8.1074, Dats: 448088, Stamp: 3], Multi: [Enabled, t: (0.000014, 0.023803)], BW: [Enabled, t: (0.000010)], RBL DNSBL: [Disabled], APM: [Enabled, Score: 500, t: (0.006943), 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.013454,0.000338)], URL: [Enabled, t: (0.000019)], RTDA: [Enabled, t: (0.160505), Hit: No, Details: v2.4.9; Id: 11.5eun85.1bf993f0g.1219], total: 0(775) X-BitDefender-CF-Stamp: none Cc: andrew.cooper3@citrix.com, tamas@tklengyel.com, Razvan Cojocaru , jbeulich@suse.com Subject: [Xen-devel] [PATCH V3 1/2] x86/vm_event: added hvm/vm_event.{h,c} 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 Created arch/x86/hvm/vm_event.c and include/asm-x86/hvm/vm_event.h, where HVM-specific vm_event-related code will live. This cleans up hvm_do_resume() and ensures that the vm_event maintainers are responsible for changes to that code. Signed-off-by: Razvan Cojocaru Acked-by: Tamas K Lengyel Acked-by: Jan Beulich --- Changes since V2: - Added if ( unlikely(v->arch.vm_event) ) before the hvm_do_resume() call. - Added unlikely()s in hvm_vm_event_do_resume() for the register write cases. - Moved the copyright lines over from hvm.c. --- MAINTAINERS | 2 + xen/arch/x86/hvm/Makefile | 1 + xen/arch/x86/hvm/hvm.c | 63 +---------------------- xen/arch/x86/hvm/vm_event.c | 103 +++++++++++++++++++++++++++++++++++++ xen/include/asm-x86/hvm/vm_event.h | 34 ++++++++++++ 5 files changed, 142 insertions(+), 61 deletions(-) create mode 100644 xen/arch/x86/hvm/vm_event.c create mode 100644 xen/include/asm-x86/hvm/vm_event.h diff --git a/MAINTAINERS b/MAINTAINERS index c345a50..10863bc 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -404,6 +404,7 @@ S: Supported F: tools/tests/xen-access F: xen/arch/*/monitor.c F: xen/arch/*/vm_event.c +F: xen/arch/*/hvm/vm_event.c F: xen/arch/arm/mem_access.c F: xen/arch/x86/mm/mem_access.c F: xen/arch/x86/hvm/monitor.c @@ -413,6 +414,7 @@ F: xen/common/vm_event.c F: xen/include/*/mem_access.h F: xen/include/*/monitor.h F: xen/include/*/vm_event.h +F: xen/include/*/hvm/vm_event.h F: xen/include/asm-x86/hvm/monitor.h VTPM diff --git a/xen/arch/x86/hvm/Makefile b/xen/arch/x86/hvm/Makefile index 0a3d0f4..02f0add 100644 --- a/xen/arch/x86/hvm/Makefile +++ b/xen/arch/x86/hvm/Makefile @@ -24,6 +24,7 @@ obj-y += stdvga.o obj-y += vioapic.o obj-y += viridian.o obj-y += vlapic.o +obj-y += vm_event.o obj-y += vmsi.o obj-y += vpic.o obj-y += vpt.o diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index a441955..81691e2 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -34,7 +34,6 @@ #include #include #include -#include #include #include #include @@ -61,6 +60,7 @@ #include #include #include +#include #include #include #include @@ -484,66 +484,7 @@ void hvm_do_resume(struct vcpu *v) return; if ( unlikely(v->arch.vm_event) ) - { - struct monitor_write_data *w = &v->arch.vm_event->write_data; - - if ( unlikely(v->arch.vm_event->emulate_flags) ) - { - enum emul_kind kind = EMUL_KIND_NORMAL; - - /* - * Please observ the order here to match the flag descriptions - * provided in public/vm_event.h - */ - if ( v->arch.vm_event->emulate_flags & - VM_EVENT_FLAG_SET_EMUL_READ_DATA ) - kind = EMUL_KIND_SET_CONTEXT_DATA; - else if ( v->arch.vm_event->emulate_flags & - VM_EVENT_FLAG_EMULATE_NOWRITE ) - kind = EMUL_KIND_NOWRITE; - else if ( v->arch.vm_event->emulate_flags & - VM_EVENT_FLAG_SET_EMUL_INSN_DATA ) - kind = EMUL_KIND_SET_CONTEXT_INSN; - - hvm_emulate_one_vm_event(kind, TRAP_invalid_op, - X86_EVENT_NO_EC); - - v->arch.vm_event->emulate_flags = 0; - } - - if ( w->do_write.msr ) - { - if ( hvm_msr_write_intercept(w->msr, w->value, 0) == - X86EMUL_EXCEPTION ) - hvm_inject_hw_exception(TRAP_gp_fault, 0); - - w->do_write.msr = 0; - } - - if ( w->do_write.cr0 ) - { - if ( hvm_set_cr0(w->cr0, 0) == X86EMUL_EXCEPTION ) - hvm_inject_hw_exception(TRAP_gp_fault, 0); - - w->do_write.cr0 = 0; - } - - if ( w->do_write.cr4 ) - { - if ( hvm_set_cr4(w->cr4, 0) == X86EMUL_EXCEPTION ) - hvm_inject_hw_exception(TRAP_gp_fault, 0); - - w->do_write.cr4 = 0; - } - - if ( w->do_write.cr3 ) - { - if ( hvm_set_cr3(w->cr3, 0) == X86EMUL_EXCEPTION ) - hvm_inject_hw_exception(TRAP_gp_fault, 0); - - w->do_write.cr3 = 0; - } - } + hvm_vm_event_do_resume(v); /* Inject pending hw/sw event */ if ( v->arch.hvm_vcpu.inject_event.vector >= 0 ) diff --git a/xen/arch/x86/hvm/vm_event.c b/xen/arch/x86/hvm/vm_event.c new file mode 100644 index 0000000..1934556 --- /dev/null +++ b/xen/arch/x86/hvm/vm_event.c @@ -0,0 +1,103 @@ +/* + * arch/x86/hvm/vm_event.c + * + * HVM vm_event handling routines + * + * Copyright (c) 2004, Intel Corporation. + * Copyright (c) 2005, International Business Machines Corporation. + * Copyright (c) 2008, Citrix Systems, Inc. + * + * 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 . + */ + +#include +#include +#include +#include + +void hvm_vm_event_do_resume(struct vcpu *v) +{ + struct monitor_write_data *w; + + if ( likely(!v->arch.vm_event) ) + return; + + w = &v->arch.vm_event->write_data; + + if ( unlikely(v->arch.vm_event->emulate_flags) ) + { + enum emul_kind kind = EMUL_KIND_NORMAL; + + /* + * Please observe the order here to match the flag descriptions + * provided in public/vm_event.h + */ + if ( v->arch.vm_event->emulate_flags & + VM_EVENT_FLAG_SET_EMUL_READ_DATA ) + kind = EMUL_KIND_SET_CONTEXT_DATA; + else if ( v->arch.vm_event->emulate_flags & + VM_EVENT_FLAG_EMULATE_NOWRITE ) + kind = EMUL_KIND_NOWRITE; + else if ( v->arch.vm_event->emulate_flags & + VM_EVENT_FLAG_SET_EMUL_INSN_DATA ) + kind = EMUL_KIND_SET_CONTEXT_INSN; + + hvm_emulate_one_vm_event(kind, TRAP_invalid_op, + X86_EVENT_NO_EC); + + v->arch.vm_event->emulate_flags = 0; + } + + if ( unlikely(w->do_write.cr0) ) + { + if ( hvm_set_cr0(w->cr0, 0) == X86EMUL_EXCEPTION ) + hvm_inject_hw_exception(TRAP_gp_fault, 0); + + w->do_write.cr0 = 0; + } + + if ( unlikely(w->do_write.cr4) ) + { + if ( hvm_set_cr4(w->cr4, 0) == X86EMUL_EXCEPTION ) + hvm_inject_hw_exception(TRAP_gp_fault, 0); + + w->do_write.cr4 = 0; + } + + if ( unlikely(w->do_write.cr3) ) + { + if ( hvm_set_cr3(w->cr3, 0) == X86EMUL_EXCEPTION ) + hvm_inject_hw_exception(TRAP_gp_fault, 0); + + w->do_write.cr3 = 0; + } + + if ( unlikely(w->do_write.msr) ) + { + if ( hvm_msr_write_intercept(w->msr, w->value, 0) == + X86EMUL_EXCEPTION ) + hvm_inject_hw_exception(TRAP_gp_fault, 0); + + w->do_write.msr = 0; + } +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/include/asm-x86/hvm/vm_event.h b/xen/include/asm-x86/hvm/vm_event.h new file mode 100644 index 0000000..28cb07c --- /dev/null +++ b/xen/include/asm-x86/hvm/vm_event.h @@ -0,0 +1,34 @@ +/* + * include/asm-x86/hvm/vm_event.h + * + * Hardware virtual machine vm_event abstractions. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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 . + */ + +#ifndef __ASM_X86_HVM_VM_EVENT_H__ +#define __ASM_X86_HVM_VM_EVENT_H__ + +void hvm_vm_event_do_resume(struct vcpu *v); + +#endif /* __ASM_X86_HVM_VM_EVENT_H__ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */