From patchwork Mon Feb 22 14:29:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tamas K Lengyel X-Patchwork-Id: 8377741 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 8C5559F314 for ; Mon, 22 Feb 2016 14:33:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 53207204D1 for ; Mon, 22 Feb 2016 14:33:34 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F363620452 for ; Mon, 22 Feb 2016 14:33:32 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aXrVu-0007Ul-6d; Mon, 22 Feb 2016 14:31:02 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aXrVs-0007UY-PD for xen-devel@lists.xenproject.org; Mon, 22 Feb 2016 14:31:01 +0000 Received: from [193.109.254.147] by server-7.bemta-14.messagelabs.com id 37/9E-29985-4AB1BC65; Mon, 22 Feb 2016 14:31:00 +0000 X-Env-Sender: tlengyel@novetta.com X-Msg-Ref: server-2.tower-27.messagelabs.com!1456151458!23763470!1 X-Originating-IP: [209.85.213.53] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 3189 invoked from network); 22 Feb 2016 14:30:59 -0000 Received: from mail-vk0-f53.google.com (HELO mail-vk0-f53.google.com) (209.85.213.53) by server-2.tower-27.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 22 Feb 2016 14:30:59 -0000 Received: by mail-vk0-f53.google.com with SMTP id k196so131872182vka.0 for ; Mon, 22 Feb 2016 06:30:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=novetta-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=3zUflqBsRxQQadzHDkikZJFIpJd4lRzRgaerz8uEcaw=; b=TmEsL8Y/ZnhmMQOaJWEKsjV3MUdMoK6KRD+xD85fVKgPtMKT6ph+cL6YJrFKHLJiGu HSUSR+8NapFPbEg/bHzHgh5X1l95fB8z+wHsWSnbKKBe/frmlXZ6yG9x6jsSrbU+58Ed 3+uz+julcQssBBbfS2cos11TJqb27JWVHSIqLl8S3kLSybI3t3vHI7Sbw9og9ubaKYO7 S0MqQGogjc4gRV0WnfuHJX61cMb94Yo/QW9WxZgctODvzMLq75rhtEbQpfX/v19uCTvM iV4gLgkjVtncw/OCgrv4nK9DFLI4LHKaShl8nBrqNY8J8A+X8YZ/V2IZsbk1mChV3wnX 1RSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=3zUflqBsRxQQadzHDkikZJFIpJd4lRzRgaerz8uEcaw=; b=PKhUKIKZAtox78ROFzMPI7a6xcRgabalFMHHICaVdb2loi6EDdP2dL3BXttROtt0oU u8hnCvetnNttt4tGxhHgUpoz0YQ22LzwPk9nwE3lP1dTCHLjfYYoYMNERBrA605eu9A0 ZZKTYRZ4f4nccyleg6A86iLzAc4szjLJb8bwFidZ7OhrrDBIDkPi12g4q/1uoenL720X pAT+cK9TMwPy/mhu9KjwXeC3cKXR2ziFca172Pe5ZyOhoDpuYQ6nTzfJ9oqF/DuhoFK6 bddFrSYvVklu8DQn9Y61mTCj7bOF7zvr/nyAHbu3H/byLQkjlz6XEfAGUWuZ7qH7Ap3r 77vQ== X-Gm-Message-State: AG10YORk5RdQicgfrf1yDT9kQNWQlWQIkSI9/JNS6+04sUTTQ+D6hmMX2op9YWkQ9yaMzqrz X-Received: by 10.31.148.215 with SMTP id w206mr20443152vkd.65.1456151457895; Mon, 22 Feb 2016 06:30:57 -0800 (PST) Received: from l1.hil-mclmhhh.dca.wayport.net (ip-64-134-242-23.public.wayport.net. [64.134.242.23]) by smtp.gmail.com with ESMTPSA id t72sm2994926vke.28.2016.02.22.06.30.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 22 Feb 2016 06:30:57 -0800 (PST) From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Mon, 22 Feb 2016 09:29:49 -0500 Message-Id: <1456151389-7857-1-git-send-email-tlengyel@novetta.com> X-Mailer: git-send-email 2.1.4 Cc: Keir Fraser , Razvan Cojocaru , George Dunlap , Andrew Cooper , Jan Beulich , Tamas K Lengyel Subject: [Xen-devel] [PATCH v3] vm_event: consolidate hvm_event_fill_regs and p2m_vm_event_fill_regs X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently the registers saved in the request depend on which type of event is filling in the registers. In this patch we consolidate the two versions of register filling function as to return a fix set of registers irrespective of the underlying event. Signed-off-by: Tamas K Lengyel Acked-by: George Dunlap Acked-by: Razvan Cojocaru --- Cc: Razvan Cojocaru Cc: Keir Fraser Cc: Jan Beulich Cc: Andrew Cooper Cc: George Dunlap v4: remove dr7 fix which can be done in a separate patch v3: add ASSERT check for hvm vcpu v2: get dr7 from hvm context --- xen/arch/x86/hvm/event.c | 35 ++------------------------ xen/arch/x86/mm/p2m.c | 57 +----------------------------------------- xen/arch/x86/vm_event.c | 57 ++++++++++++++++++++++++++++++++++++++++++ xen/include/asm-x86/vm_event.h | 2 ++ 4 files changed, 62 insertions(+), 89 deletions(-) diff --git a/xen/arch/x86/hvm/event.c b/xen/arch/x86/hvm/event.c index 874a36c..7958bef 100644 --- a/xen/arch/x86/hvm/event.c +++ b/xen/arch/x86/hvm/event.c @@ -25,40 +25,9 @@ #include #include #include +#include #include -static void hvm_event_fill_regs(vm_event_request_t *req) -{ - const struct cpu_user_regs *regs = guest_cpu_user_regs(); - const struct vcpu *curr = current; - - req->data.regs.x86.rax = regs->eax; - req->data.regs.x86.rcx = regs->ecx; - req->data.regs.x86.rdx = regs->edx; - req->data.regs.x86.rbx = regs->ebx; - req->data.regs.x86.rsp = regs->esp; - req->data.regs.x86.rbp = regs->ebp; - req->data.regs.x86.rsi = regs->esi; - req->data.regs.x86.rdi = regs->edi; - - req->data.regs.x86.r8 = regs->r8; - req->data.regs.x86.r9 = regs->r9; - req->data.regs.x86.r10 = regs->r10; - req->data.regs.x86.r11 = regs->r11; - req->data.regs.x86.r12 = regs->r12; - req->data.regs.x86.r13 = regs->r13; - req->data.regs.x86.r14 = regs->r14; - req->data.regs.x86.r15 = regs->r15; - - req->data.regs.x86.rflags = regs->eflags; - req->data.regs.x86.rip = regs->eip; - - req->data.regs.x86.msr_efer = curr->arch.hvm_vcpu.guest_efer; - req->data.regs.x86.cr0 = curr->arch.hvm_vcpu.guest_cr[0]; - req->data.regs.x86.cr3 = curr->arch.hvm_vcpu.guest_cr[3]; - req->data.regs.x86.cr4 = curr->arch.hvm_vcpu.guest_cr[4]; -} - static int hvm_event_traps(uint8_t sync, vm_event_request_t *req) { int rc; @@ -92,7 +61,7 @@ static int hvm_event_traps(uint8_t sync, vm_event_request_t *req) req->altp2m_idx = vcpu_altp2m(curr).p2midx; } - hvm_event_fill_regs(req); + vm_event_fill_regs(req); vm_event_put_request(currd, &currd->vm_event->monitor, req); return 1; diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index a25b18b..b3fce1b 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -1541,61 +1541,6 @@ void p2m_mem_paging_resume(struct domain *d, vm_event_response_t *rsp) } } -static void p2m_vm_event_fill_regs(vm_event_request_t *req) -{ - const struct cpu_user_regs *regs = guest_cpu_user_regs(); - struct segment_register seg; - struct hvm_hw_cpu ctxt; - struct vcpu *curr = current; - - /* Architecture-specific vmcs/vmcb bits */ - hvm_funcs.save_cpu_ctxt(curr, &ctxt); - - req->data.regs.x86.rax = regs->eax; - req->data.regs.x86.rcx = regs->ecx; - req->data.regs.x86.rdx = regs->edx; - req->data.regs.x86.rbx = regs->ebx; - req->data.regs.x86.rsp = regs->esp; - req->data.regs.x86.rbp = regs->ebp; - req->data.regs.x86.rsi = regs->esi; - req->data.regs.x86.rdi = regs->edi; - - req->data.regs.x86.r8 = regs->r8; - req->data.regs.x86.r9 = regs->r9; - req->data.regs.x86.r10 = regs->r10; - req->data.regs.x86.r11 = regs->r11; - req->data.regs.x86.r12 = regs->r12; - req->data.regs.x86.r13 = regs->r13; - req->data.regs.x86.r14 = regs->r14; - req->data.regs.x86.r15 = regs->r15; - - req->data.regs.x86.rflags = regs->eflags; - req->data.regs.x86.rip = regs->eip; - - req->data.regs.x86.dr7 = curr->arch.debugreg[7]; - req->data.regs.x86.cr0 = ctxt.cr0; - req->data.regs.x86.cr2 = ctxt.cr2; - req->data.regs.x86.cr3 = ctxt.cr3; - req->data.regs.x86.cr4 = ctxt.cr4; - - req->data.regs.x86.sysenter_cs = ctxt.sysenter_cs; - req->data.regs.x86.sysenter_esp = ctxt.sysenter_esp; - req->data.regs.x86.sysenter_eip = ctxt.sysenter_eip; - - req->data.regs.x86.msr_efer = ctxt.msr_efer; - req->data.regs.x86.msr_star = ctxt.msr_star; - req->data.regs.x86.msr_lstar = ctxt.msr_lstar; - - hvm_get_segment_register(curr, x86_seg_fs, &seg); - req->data.regs.x86.fs_base = seg.base; - - hvm_get_segment_register(curr, x86_seg_gs, &seg); - req->data.regs.x86.gs_base = seg.base; - - hvm_get_segment_register(curr, x86_seg_cs, &seg); - req->data.regs.x86.cs_arbytes = seg.attr.bytes; -} - void p2m_mem_access_emulate_check(struct vcpu *v, const vm_event_response_t *rsp) { @@ -1760,7 +1705,7 @@ bool_t p2m_mem_access_check(paddr_t gpa, unsigned long gla, req->u.mem_access.flags |= npfec.insn_fetch ? MEM_ACCESS_X : 0; req->vcpu_id = v->vcpu_id; - p2m_vm_event_fill_regs(req); + vm_event_fill_regs(req); if ( altp2m_active(v->domain) ) { diff --git a/xen/arch/x86/vm_event.c b/xen/arch/x86/vm_event.c index 08d678a..2a2abd7 100644 --- a/xen/arch/x86/vm_event.c +++ b/xen/arch/x86/vm_event.c @@ -122,6 +122,63 @@ void vm_event_set_registers(struct vcpu *v, vm_event_response_t *rsp) v->arch.user_regs.eip = rsp->data.regs.x86.rip; } +void vm_event_fill_regs(vm_event_request_t *req) +{ + const struct cpu_user_regs *regs = guest_cpu_user_regs(); + struct segment_register seg; + struct hvm_hw_cpu ctxt; + struct vcpu *curr = current; + + ASSERT(is_hvm_vcpu(curr)); + + /* Architecture-specific vmcs/vmcb bits */ + hvm_funcs.save_cpu_ctxt(curr, &ctxt); + + req->data.regs.x86.rax = regs->eax; + req->data.regs.x86.rcx = regs->ecx; + req->data.regs.x86.rdx = regs->edx; + req->data.regs.x86.rbx = regs->ebx; + req->data.regs.x86.rsp = regs->esp; + req->data.regs.x86.rbp = regs->ebp; + req->data.regs.x86.rsi = regs->esi; + req->data.regs.x86.rdi = regs->edi; + + req->data.regs.x86.r8 = regs->r8; + req->data.regs.x86.r9 = regs->r9; + req->data.regs.x86.r10 = regs->r10; + req->data.regs.x86.r11 = regs->r11; + req->data.regs.x86.r12 = regs->r12; + req->data.regs.x86.r13 = regs->r13; + req->data.regs.x86.r14 = regs->r14; + req->data.regs.x86.r15 = regs->r15; + + req->data.regs.x86.rflags = regs->eflags; + req->data.regs.x86.rip = regs->eip; + + req->data.regs.x86.dr7 = curr->arch.debugreg[7]; + req->data.regs.x86.cr0 = ctxt.cr0; + req->data.regs.x86.cr2 = ctxt.cr2; + req->data.regs.x86.cr3 = ctxt.cr3; + req->data.regs.x86.cr4 = ctxt.cr4; + + req->data.regs.x86.sysenter_cs = ctxt.sysenter_cs; + req->data.regs.x86.sysenter_esp = ctxt.sysenter_esp; + req->data.regs.x86.sysenter_eip = ctxt.sysenter_eip; + + req->data.regs.x86.msr_efer = ctxt.msr_efer; + req->data.regs.x86.msr_star = ctxt.msr_star; + req->data.regs.x86.msr_lstar = ctxt.msr_lstar; + + hvm_get_segment_register(curr, x86_seg_fs, &seg); + req->data.regs.x86.fs_base = seg.base; + + hvm_get_segment_register(curr, x86_seg_gs, &seg); + req->data.regs.x86.gs_base = seg.base; + + hvm_get_segment_register(curr, x86_seg_cs, &seg); + req->data.regs.x86.cs_arbytes = seg.attr.bytes; +} + /* * Local variables: * mode: C diff --git a/xen/include/asm-x86/vm_event.h b/xen/include/asm-x86/vm_event.h index fff8326..026f42e 100644 --- a/xen/include/asm-x86/vm_event.h +++ b/xen/include/asm-x86/vm_event.h @@ -42,4 +42,6 @@ void vm_event_register_write_resume(struct vcpu *v, vm_event_response_t *rsp); void vm_event_set_registers(struct vcpu *v, vm_event_response_t *rsp); +void vm_event_fill_regs(vm_event_request_t *req); + #endif /* __ASM_X86_VM_EVENT_H__ */