xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] hvm/svm: Implement CPUID events
@ 2018-02-23  9:46 Alexandru Isaila
  2018-02-23 14:50 ` Boris Ostrovsky
  2018-02-23 22:27 ` Tamas K Lengyel
  0 siblings, 2 replies; 3+ messages in thread
From: Alexandru Isaila @ 2018-02-23  9:46 UTC (permalink / raw)
  To: xen-devel
  Cc: tamas, suravee.suthikulpanit, rcojocaru, andrew.cooper3, jbeulich,
	Alexandru Isaila, boris.ostrovsky

At this moment the CPUID events for the AMD architecture are not
forwarded to the monitor layer.

This patch adds the CPUID event to the common capabilities and then
forwards the event to the monitor layer.

---
    Changes since V2:
	- Pass the inst_len to svm_vmexit_do_cpuid()

Signed-off-by: Alexandru Isaila <aisaila@bitdefender.com>
---
 xen/arch/x86/hvm/svm/svm.c    | 27 ++++++++++++++++++---------
 xen/include/asm-x86/monitor.h |  2 +-
 2 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c
index e36ad05..8ae2ae5 100644
--- a/xen/arch/x86/hvm/svm/svm.c
+++ b/xen/arch/x86/hvm/svm/svm.c
@@ -1799,19 +1799,15 @@ static void svm_fpu_dirty_intercept(void)
         vmcb_set_cr0(vmcb, vmcb_get_cr0(vmcb) & ~X86_CR0_TS);
 }
 
-static void svm_vmexit_do_cpuid(struct cpu_user_regs *regs)
+static int svm_vmexit_do_cpuid(struct cpu_user_regs *regs, unsigned int inst_len)
 {
     struct vcpu *curr = current;
-    unsigned int inst_len;
     struct cpuid_leaf res;
 
-    if ( (inst_len = __get_instruction_length(curr, INSTR_CPUID)) == 0 )
-        return;
-
     if ( hvm_check_cpuid_faulting(curr) )
     {
         hvm_inject_hw_exception(TRAP_gp_fault, 0);
-        return;
+        return 1; /* Don't advance the guest IP! */
     }
 
     guest_cpuid(curr, regs->eax, regs->ecx, &res);
@@ -1822,7 +1818,7 @@ static void svm_vmexit_do_cpuid(struct cpu_user_regs *regs)
     regs->rcx = res.c;
     regs->rdx = res.d;
 
-    __update_guest_eip(regs, inst_len);
+    return hvm_monitor_cpuid(inst_len, regs->eax, regs->ecx);
 }
 
 static void svm_vmexit_do_cr_access(
@@ -2768,9 +2764,22 @@ void svm_vmexit_handler(struct cpu_user_regs *regs)
     }
 
     case VMEXIT_CPUID:
-        svm_vmexit_do_cpuid(regs);
-        break;
+    {
+        unsigned int inst_len = __get_instruction_length(v, INSTR_CPUID);
+        int rc = 0;
 
+        if ( inst_len == 0 )
+            break;
+
+        rc = svm_vmexit_do_cpuid(regs, inst_len);
+
+        if ( rc < 0 )
+            goto unexpected_exit_type;
+        if ( !rc )
+            __update_guest_eip(regs, inst_len); /* Safe: CPUID */
+
+        break;
+    }
     case VMEXIT_HLT:
         svm_vmexit_do_hlt(vmcb, regs);
         break;
diff --git a/xen/include/asm-x86/monitor.h b/xen/include/asm-x86/monitor.h
index 7a9e1e8..99ed4b87 100644
--- a/xen/include/asm-x86/monitor.h
+++ b/xen/include/asm-x86/monitor.h
@@ -81,12 +81,12 @@ static inline uint32_t arch_monitor_get_capabilities(struct domain *d)
                     (1U << XEN_DOMCTL_MONITOR_EVENT_SOFTWARE_BREAKPOINT) |
                     (1U << XEN_DOMCTL_MONITOR_EVENT_MOV_TO_MSR) |
                     (1U << XEN_DOMCTL_MONITOR_EVENT_INTERRUPT) |
+                    (1U << XEN_DOMCTL_MONITOR_EVENT_CPUID) |
                     (1U << XEN_DOMCTL_MONITOR_EVENT_WRITE_CTRLREG));
 
     if ( cpu_has_vmx )
     {
         capabilities |= ((1U << XEN_DOMCTL_MONITOR_EVENT_DEBUG_EXCEPTION) |
-                         (1U << XEN_DOMCTL_MONITOR_EVENT_CPUID) |
                          (1U << XEN_DOMCTL_MONITOR_EVENT_EMUL_UNIMPLEMENTED));
 
         /* Since we know this is on VMX, we can just call the hvm func */
-- 
2.7.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] hvm/svm: Implement CPUID events
  2018-02-23  9:46 [PATCH v3] hvm/svm: Implement CPUID events Alexandru Isaila
@ 2018-02-23 14:50 ` Boris Ostrovsky
  2018-02-23 22:27 ` Tamas K Lengyel
  1 sibling, 0 replies; 3+ messages in thread
From: Boris Ostrovsky @ 2018-02-23 14:50 UTC (permalink / raw)
  To: Alexandru Isaila, xen-devel
  Cc: andrew.cooper3, tamas, jbeulich, suravee.suthikulpanit, rcojocaru

On 02/23/2018 04:46 AM, Alexandru Isaila wrote:
> At this moment the CPUID events for the AMD architecture are not
> forwarded to the monitor layer.
>
> This patch adds the CPUID event to the common capabilities and then
> forwards the event to the monitor layer.
>
> ---
>     Changes since V2:
> 	- Pass the inst_len to svm_vmexit_do_cpuid()
>
> Signed-off-by: Alexandru Isaila <aisaila@bitdefender.com>

Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] hvm/svm: Implement CPUID events
  2018-02-23  9:46 [PATCH v3] hvm/svm: Implement CPUID events Alexandru Isaila
  2018-02-23 14:50 ` Boris Ostrovsky
@ 2018-02-23 22:27 ` Tamas K Lengyel
  1 sibling, 0 replies; 3+ messages in thread
From: Tamas K Lengyel @ 2018-02-23 22:27 UTC (permalink / raw)
  To: Alexandru Isaila
  Cc: Suravee Suthikulpanit, Razvan Cojocaru, Andrew Cooper, Xen-devel,
	Jan Beulich, Boris Ostrovsky

On Fri, Feb 23, 2018 at 2:46 AM, Alexandru Isaila
<aisaila@bitdefender.com> wrote:
> At this moment the CPUID events for the AMD architecture are not
> forwarded to the monitor layer.
>
> This patch adds the CPUID event to the common capabilities and then
> forwards the event to the monitor layer.
>
> ---
>     Changes since V2:
>         - Pass the inst_len to svm_vmexit_do_cpuid()
>
> Signed-off-by: Alexandru Isaila <aisaila@bitdefender.com>

Acked-by: Tamas K Lengyel <tamas@tklengyel.com>

> ---
>  xen/arch/x86/hvm/svm/svm.c    | 27 ++++++++++++++++++---------
>  xen/include/asm-x86/monitor.h |  2 +-
>  2 files changed, 19 insertions(+), 10 deletions(-)
>
> diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c
> index e36ad05..8ae2ae5 100644
> --- a/xen/arch/x86/hvm/svm/svm.c
> +++ b/xen/arch/x86/hvm/svm/svm.c
> @@ -1799,19 +1799,15 @@ static void svm_fpu_dirty_intercept(void)
>          vmcb_set_cr0(vmcb, vmcb_get_cr0(vmcb) & ~X86_CR0_TS);
>  }
>
> -static void svm_vmexit_do_cpuid(struct cpu_user_regs *regs)
> +static int svm_vmexit_do_cpuid(struct cpu_user_regs *regs, unsigned int inst_len)
>  {
>      struct vcpu *curr = current;
> -    unsigned int inst_len;
>      struct cpuid_leaf res;
>
> -    if ( (inst_len = __get_instruction_length(curr, INSTR_CPUID)) == 0 )
> -        return;
> -
>      if ( hvm_check_cpuid_faulting(curr) )
>      {
>          hvm_inject_hw_exception(TRAP_gp_fault, 0);
> -        return;
> +        return 1; /* Don't advance the guest IP! */
>      }
>
>      guest_cpuid(curr, regs->eax, regs->ecx, &res);
> @@ -1822,7 +1818,7 @@ static void svm_vmexit_do_cpuid(struct cpu_user_regs *regs)
>      regs->rcx = res.c;
>      regs->rdx = res.d;
>
> -    __update_guest_eip(regs, inst_len);
> +    return hvm_monitor_cpuid(inst_len, regs->eax, regs->ecx);
>  }
>
>  static void svm_vmexit_do_cr_access(
> @@ -2768,9 +2764,22 @@ void svm_vmexit_handler(struct cpu_user_regs *regs)
>      }
>
>      case VMEXIT_CPUID:
> -        svm_vmexit_do_cpuid(regs);
> -        break;
> +    {
> +        unsigned int inst_len = __get_instruction_length(v, INSTR_CPUID);
> +        int rc = 0;
>
> +        if ( inst_len == 0 )
> +            break;
> +
> +        rc = svm_vmexit_do_cpuid(regs, inst_len);
> +
> +        if ( rc < 0 )
> +            goto unexpected_exit_type;
> +        if ( !rc )
> +            __update_guest_eip(regs, inst_len); /* Safe: CPUID */
> +
> +        break;
> +    }
>      case VMEXIT_HLT:
>          svm_vmexit_do_hlt(vmcb, regs);
>          break;
> diff --git a/xen/include/asm-x86/monitor.h b/xen/include/asm-x86/monitor.h
> index 7a9e1e8..99ed4b87 100644
> --- a/xen/include/asm-x86/monitor.h
> +++ b/xen/include/asm-x86/monitor.h
> @@ -81,12 +81,12 @@ static inline uint32_t arch_monitor_get_capabilities(struct domain *d)
>                      (1U << XEN_DOMCTL_MONITOR_EVENT_SOFTWARE_BREAKPOINT) |
>                      (1U << XEN_DOMCTL_MONITOR_EVENT_MOV_TO_MSR) |
>                      (1U << XEN_DOMCTL_MONITOR_EVENT_INTERRUPT) |
> +                    (1U << XEN_DOMCTL_MONITOR_EVENT_CPUID) |
>                      (1U << XEN_DOMCTL_MONITOR_EVENT_WRITE_CTRLREG));
>
>      if ( cpu_has_vmx )
>      {
>          capabilities |= ((1U << XEN_DOMCTL_MONITOR_EVENT_DEBUG_EXCEPTION) |
> -                         (1U << XEN_DOMCTL_MONITOR_EVENT_CPUID) |
>                           (1U << XEN_DOMCTL_MONITOR_EVENT_EMUL_UNIMPLEMENTED));
>
>          /* Since we know this is on VMX, we can just call the hvm func */
> --
> 2.7.4

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-02-23 22:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-23  9:46 [PATCH v3] hvm/svm: Implement CPUID events Alexandru Isaila
2018-02-23 14:50 ` Boris Ostrovsky
2018-02-23 22:27 ` Tamas K Lengyel

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).