From patchwork Wed Aug 31 23:52:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tamas Lengyel X-Patchwork-Id: 9308037 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 0075F60487 for ; Wed, 31 Aug 2016 23:55:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D6C4220265 for ; Wed, 31 Aug 2016 23:55:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C985629012; Wed, 31 Aug 2016 23:55:12 +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=-3.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RCVD_IN_SORBS_SPAM,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 F092D20265 for ; Wed, 31 Aug 2016 23:55:11 +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 1bfFIq-0007b6-Ty; Wed, 31 Aug 2016 23:52:20 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bfFIp-0007b0-By for xen-devel@lists.xenproject.org; Wed, 31 Aug 2016 23:52:19 +0000 Received: from [193.109.254.147] by server-4.bemta-6.messagelabs.com id 58/64-29421-1BD67C75; Wed, 31 Aug 2016 23:52:17 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupnkeJIrShJLcpLzFFi42K5GHrNSXdD7vF wg+NvDCy+b5nM5MDocfjDFZYAxijWzLyk/IoE1ox9rUtYCjaoVVzruMnewLhErouRi0NIYAaj ROumR+wgDovAGxaJaaeegzkSAu9YJFZ37mLuYuQEcmIkNt6byQhhV0n8WX2PBcQWEtCUOLjhD DOEPYFJ4u4PWxCbTcBI4urVHjYQW0RASeLeqslMIEOZBQ4xSZxrfsoOkhAWcJXYevky2FAWAV WJI9+/gjXwCthJfOh/BrVYTuLSti/MExj5FjAyrGLUKE4tKkst0jWy0EsqykzPKMlNzMzRNTQ w08tNLS5OTE/NSUwq1kvOz93ECAwWBiDYwXh+beAhRkkOJiVRXrW44+FCfEn5KZUZicUZ8UWl OanFhxhlODiUJHif5QDlBItS01Mr0jJzgGELk5bg4FES4X0EkuYtLkjMLc5Mh0idYjTm2PL72 lomjm1T761lEmLJy89LlRLnnQVSKgBSmlGaBzcIFk+XGGWlhHkZgU4T4ilILcrNLEGVf8Uozs GoJMz7HGQKT2ZeCdy+V0CnMAGdUnDnMMgpJYkIKakGRofVKcaCgSd3lVSvmZIlaRzzRemgS8o Clp2llj07j6qmGRgv/6b7/NXDlzsZVm95NDNkToTX3Utz72Y89lGu+y9ltCV0zaFV3YY/rNau ZlnedTfB+HT3oSUi75gL2AWOlr+NL6zcXtudwNyQoto56ZVFWuCZl/M/Be2pargl8krofYjWk d6ztkosxRmJhlrMRcWJAPr5PVGiAgAA X-Env-Sender: tamas.lengyel@zentific.com X-Msg-Ref: server-8.tower-27.messagelabs.com!1472687535!46521412!1 X-Originating-IP: [209.85.214.66] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 1441 invoked from network); 31 Aug 2016 23:52:16 -0000 Received: from mail-it0-f66.google.com (HELO mail-it0-f66.google.com) (209.85.214.66) by server-8.tower-27.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 31 Aug 2016 23:52:16 -0000 Received: by mail-it0-f66.google.com with SMTP id g185so2009027ith.0 for ; Wed, 31 Aug 2016 16:52:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zentific-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=vdxgkHVfVB2eCyV5MbeIPgkqMM7d0jl3LoTI/8h63BM=; b=fnHIT/sFVgv0sNZkro3DxSkVnb6hiMykya46PldVPAjNzniJHv36st6jbfUmIMdwc1 Ffc41YhIbNNJ5tpMInGCYONVvBOARoJ/HhUGumeIAWcVqc6kIXGFRfCjx5YsERfyTkDj w+NDKIp69wl5hCOeTomwKsLN4015ULNcyBll8VXcRYvrTyGvFNwqW4YTWA7jewQGLRE/ wJp5r+W4LEvFHYogT+PKp4oAjUQuHGY4GcfUkHgpX+88ysSg1P298F10kIaT/Hl+Er5g K9vPQxFaqVu/imevxIBYkHV/m4hq+/s8vlMFrkPAJvbSuDI3S+L7iUCe5lTWLL34R0nm K1uA== 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=vdxgkHVfVB2eCyV5MbeIPgkqMM7d0jl3LoTI/8h63BM=; b=dY/YIPrXFJ6Z2zvCAZfy42tp3spSVb44KLn9VN/9FoaLGaoiCp3GUrw7d84j0WY/JK W9Yo3Fva55zbu7R2/2yZC9f4yOQAeWlQl7mVc73Ykros8pTkHNuaiu21AhUCDR9PFgLK rd1y+UC6fsw/cyDQIzsjdPUTFFKE9UAMzIEVYKxd5rXhfVoB+/tA75l3uWobxMDNe4Mh aZstIffIo+302Lc/d27cWv4glWfADcfUhVj0XxbXuJRlJFyO3l5z9JbRMvztI4VzQvSU qjcqIG4w7XQXCY6/UWduNbcwcn5xIAff3n32/SQYlLXaIoOe4QVro1Y7e921d7iFHrWV MVDw== X-Gm-Message-State: AE9vXwOER/Iasd1B4vnXSsJPFXeVbxTwUYkLFPnVtZ5q4suSfuEiuwZw2w6CRduaWgnqIw== X-Received: by 10.36.34.213 with SMTP id o204mr35735394ito.13.1472687535407; Wed, 31 Aug 2016 16:52:15 -0700 (PDT) Received: from l1.lan (c-73-14-35-59.hsd1.co.comcast.net. [73.14.35.59]) by smtp.gmail.com with ESMTPSA id e8sm6411004itc.15.2016.08.31.16.52.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 31 Aug 2016 16:52:14 -0700 (PDT) From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Wed, 31 Aug 2016 17:52:10 -0600 Message-Id: <20160831235210.1976-1-tamas.lengyel@zentific.com> X-Mailer: git-send-email 2.9.3 Cc: Kevin Tian , Wei Liu , Jun Nakajima , Razvan Cojocaru , Tamas K Lengyel , Ian Jackson , Jan Beulich , Andrew Cooper Subject: [Xen-devel] [PATCH] x86/monitor: Include EAX/ECX in CPUID monitor events 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 Extend the CPUID monitor event to include EAX and ECX values that were used when CPUID was executed. This is useful in identifying which leaf was queried. We also adjust the xen-access output format to more closely resemble the output of the Linux cpuid tool's raw format. Signed-off-by: Tamas K Lengyel --- Cc: Razvan Cojocaru Cc: Ian Jackson Cc: Wei Liu Cc: Jan Beulich Cc: Andrew Cooper Cc: Jun Nakajima Cc: Kevin Tian --- tools/tests/xen-access/xen-access.c | 4 +++- xen/arch/x86/hvm/monitor.c | 5 ++++- xen/arch/x86/hvm/vmx/vmx.c | 7 ++++++- xen/include/asm-x86/hvm/monitor.h | 3 ++- xen/include/public/vm_event.h | 7 +++++++ 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/tools/tests/xen-access/xen-access.c b/tools/tests/xen-access/xen-access.c index ebb63b1..b51b62c 100644 --- a/tools/tests/xen-access/xen-access.c +++ b/tools/tests/xen-access/xen-access.c @@ -735,10 +735,12 @@ int main(int argc, char *argv[]) break; case VM_EVENT_REASON_CPUID: printf("CPUID executed: rip=%016"PRIx64", vcpu %d. Insn length: %"PRIu32" " \ - "EAX: 0x%"PRIx64" EBX: 0x%"PRIx64" ECX: 0x%"PRIx64" EDX: 0x%"PRIx64"\n", + "0x%"PRIx32" 0x%"PRIx32": EAX=0x%"PRIx64" EBX=0x%"PRIx64" ECX=0x%"PRIx64" EDX=0x%"PRIx64"\n", req.data.regs.x86.rip, req.vcpu_id, req.u.cpuid.insn_length, + req.u.cpuid.eax, + req.u.cpuid.ecx, req.data.regs.x86.rax, req.data.regs.x86.rbx, req.data.regs.x86.rcx, diff --git a/xen/arch/x86/hvm/monitor.c b/xen/arch/x86/hvm/monitor.c index 7277c12..6540e2b 100644 --- a/xen/arch/x86/hvm/monitor.c +++ b/xen/arch/x86/hvm/monitor.c @@ -136,7 +136,8 @@ int hvm_monitor_debug(unsigned long rip, enum hvm_monitor_debug_type type, return monitor_traps(curr, sync, &req); } -int hvm_monitor_cpuid(unsigned long insn_length) +int hvm_monitor_cpuid(unsigned long insn_length, unsigned int eax, + unsigned int ecx) { struct vcpu *curr = current; struct arch_domain *ad = &curr->domain->arch; @@ -148,6 +149,8 @@ int hvm_monitor_cpuid(unsigned long insn_length) req.reason = VM_EVENT_REASON_CPUID; req.vcpu_id = curr->vcpu_id; req.u.cpuid.insn_length = insn_length; + req.u.cpuid.eax = eax; + req.u.cpuid.ecx = ecx; return monitor_traps(curr, 1, &req); } diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index 3d330b6..6df7612 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -2402,12 +2402,17 @@ static void vmx_cpuid_intercept( static int vmx_do_cpuid(struct cpu_user_regs *regs) { unsigned int eax, ebx, ecx, edx; + unsigned int _eax, _ecx; eax = regs->eax; ebx = regs->ebx; ecx = regs->ecx; edx = regs->edx; + /* The CPUID monitor needs both the old and new values of EAX and ECX */ + _eax = regs->eax; + _ecx = regs->ecx; + vmx_cpuid_intercept(&eax, &ebx, &ecx, &edx); regs->eax = eax; @@ -2415,7 +2420,7 @@ static int vmx_do_cpuid(struct cpu_user_regs *regs) regs->ecx = ecx; regs->edx = edx; - return hvm_monitor_cpuid(get_instruction_length()); + return hvm_monitor_cpuid(get_instruction_length(), _eax, _ecx);; } static void vmx_dr_access(unsigned long exit_qualification, diff --git a/xen/include/asm-x86/hvm/monitor.h b/xen/include/asm-x86/hvm/monitor.h index a92f3fc..cdcbeca 100644 --- a/xen/include/asm-x86/hvm/monitor.h +++ b/xen/include/asm-x86/hvm/monitor.h @@ -40,7 +40,8 @@ bool_t hvm_monitor_cr(unsigned int index, unsigned long value, void hvm_monitor_msr(unsigned int msr, uint64_t value); int hvm_monitor_debug(unsigned long rip, enum hvm_monitor_debug_type type, unsigned long trap_type, unsigned long insn_length); -int hvm_monitor_cpuid(unsigned long insn_length); +int hvm_monitor_cpuid(unsigned long insn_length, unsigned int eax, + unsigned int ecx); #endif /* __ASM_X86_HVM_MONITOR_H__ */ diff --git a/xen/include/public/vm_event.h b/xen/include/public/vm_event.h index 64e6857..e0fee23 100644 --- a/xen/include/public/vm_event.h +++ b/xen/include/public/vm_event.h @@ -226,6 +226,13 @@ struct vm_event_mov_to_msr { struct vm_event_cpuid { uint32_t insn_length; + /* + * Value of EAX and ECX when CPUID was executed. + * Note that the resulting register values are accessible in + * vm_event_regs_x86. + */ + uint32_t eax; + uint32_t ecx; uint32_t _pad; };