From patchwork Wed May 3 09:10:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Razvan Cojocaru X-Patchwork-Id: 9709041 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 DE3BC60351 for ; Wed, 3 May 2017 09:12:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D94082841E for ; Wed, 3 May 2017 09:12:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CE1E8284D5; Wed, 3 May 2017 09:12:16 +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 D59782841E for ; Wed, 3 May 2017 09:12:15 +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 1d5qIx-0005Dz-FX; Wed, 03 May 2017 09:10:39 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d5qIw-0005Cv-IT for xen-devel@lists.xen.org; Wed, 03 May 2017 09:10:38 +0000 Received: from [85.158.137.68] by server-11.bemta-3.messagelabs.com id 41/71-01744-D8E99095; Wed, 03 May 2017 09:10:37 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrDIsWRWlGSWpSXmKPExsUSfTxjoW7PPM5 Ig/7FZhZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8b+td/YC446V5yYvpWpgXGTcRcjJ4eQgJvE siXP2bsYuYDsNYwS225OYIZwrjFKHDqxmBGiylViyozpUFX7GCXu3nvFDJJgEzCUWL2xhQ3EF hGQlrj2+TJYA7NAqcSlif1gtrCAncTkszPZQWwWAVWJDY+ngPXyCnhI/Fj2FiwuISAncfLYZF YQm1PAU2Lbw81AcQ6gZR4SF6/GQZTkSDw80coGEpYQkJL436oEco6EwAYWiTM7lzND1MhIPJp 4k20Co9ACRoZVjOrFqUVlqUW6JnpJRZnpGSW5iZk5uoYGxnq5qcXFiempOYlJxXrJ+bmbGIFh yAAEOxgbvzgdYpTkYFIS5VV/xR4pxJeUn1KZkVicEV9UmpNafIhRhoNDSYJ3xRzOSCHBotT01 Iq0zBxgRMCkJTh4lER4J4OkeYsLEnOLM9MhUqcYjTneLf3wnonjSuvH90xCLHn5ealS4rwRc4 FKBUBKM0rz4AbBIvUSo6yUMC8j0GlCPAWpRbmZJajyrxjFORiVhHkVQabwZOaVwO17BXQKE9A pzbIcIKeUJCKkpBoYi25KCAb1V7I+qA6a1SN9j2H2/y7ZbR2tLz11pjS4XX6lY7hlSb3LkqiL FW0MpXlcBmbCK5nu7E+4aGfXsOWemOLqph3M6/ZYqWsc/SW3984bZaWwZXY8x/+tZ3RmWi/4M T2CbZ3lzxkGoQKL/sz6H/BT5OGVk7xP9jgfftSbqF/bwLaq7VmZEktxRqKhFnNRcSIAo1bScs 8CAAA= X-Env-Sender: rcojocaru@bitdefender.com X-Msg-Ref: server-10.tower-31.messagelabs.com!1493802635!97811833!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 39157 invoked from network); 3 May 2017 09:10:36 -0000 Received: from mx01.bbu.dsd.mx.bitdefender.com (HELO mx01.bbu.dsd.mx.bitdefender.com) (91.199.104.161) by server-10.tower-31.messagelabs.com with DHE-RSA-AES128-GCM-SHA256 encrypted SMTP; 3 May 2017 09:10:36 -0000 Received: (qmail 8385 invoked from network); 3 May 2017 12:10: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; 3 May 2017 12:10: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 BCC2C7FBFD for ; Wed, 3 May 2017 12:10:34 +0300 (EEST) Received: (qmail 438 invoked from network); 3 May 2017 12:10: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; 3 May 2017 12:10:34 +0300 From: Razvan Cojocaru To: xen-devel@lists.xen.org Date: Wed, 3 May 2017 12:10:02 +0300 Message-Id: <1493802603-4978-2-git-send-email-rcojocaru@bitdefender.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1493802603-4978-1-git-send-email-rcojocaru@bitdefender.com> References: <1493802603-4978-1-git-send-email-rcojocaru@bitdefender.com> X-BitDefender-Scanner: Clean, Agent: BitDefender qmail 3.1.6 on smtp02.buh.bitdefender.net, sigver: 7.71200 X-BitDefender-Spam: No (0) X-BitDefender-SpamStamp: Build: [Engines: 2.15.8.1074, Dats: 447993, Stamp: 3], Multi: [Enabled, t: (0.000017, 0.021744)], BW: [Enabled, t: (0.000011)], RBL DNSBL: [Disabled], APM: [Enabled, Score: 500, t: (0.006593), 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.013942, 0.000355)], URL: [Enabled, t: (0.000015, 0.000001)], RTDA: [Enabled, t: (0.245832), Hit: No, Details: v2.4.8; Id: 11.5eu788.1bf4fimic.kai9], 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 V2 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 --- MAINTAINERS | 2 + xen/arch/x86/hvm/Makefile | 1 + xen/arch/x86/hvm/hvm.c | 64 +---------------------- xen/arch/x86/hvm/vm_event.c | 101 +++++++++++++++++++++++++++++++++++++ xen/include/asm-x86/hvm/vm_event.h | 34 +++++++++++++ 5 files changed, 140 insertions(+), 62 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..f010394 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 @@ -483,67 +483,7 @@ void hvm_do_resume(struct vcpu *v) if ( !handle_hvm_io_completion(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..b35ee12 --- /dev/null +++ b/xen/arch/x86/hvm/vm_event.c @@ -0,0 +1,101 @@ +/* + * arch/x86/hvm/vm_event.c + * + * HVM vm_event handling routines + * + * Copyright (c) 2017 Razvan Cojocaru (rcojocaru@bitdefender.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 . + */ + +#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 ( 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; + } + + 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; + } +} + +/* + * 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..515fa85 --- /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_MONITOR_H__ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */