diff mbox series

[RFC,v2,21/22] i386/xen: implement HYPERVISOR_event_channel_op

Message ID 20221209095612.689243-22-dwmw2@infradead.org
State New
Headers show
Series Xen HVM support under KVM | expand

Commit Message

David Woodhouse Dec. 9, 2022, 9:56 a.m. UTC
From: Joao Martins <joao.m.martins@oracle.com>

Additionally set XEN_INTERFACE_VERSION to most recent in order to
exercise both event_channel_op and event_channel_op_compat.

Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
---
 target/i386/xen.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

Comments

Durrant, Paul Dec. 12, 2022, 4:23 p.m. UTC | #1
On 09/12/2022 09:56, David Woodhouse wrote:
> From: Joao Martins <joao.m.martins@oracle.com>
> 
> Additionally set XEN_INTERFACE_VERSION to most recent in order to
> exercise both event_channel_op and event_channel_op_compat.
> 
> Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
> Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
> ---
>   target/i386/xen.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 45 insertions(+)
> 
> diff --git a/target/i386/xen.c b/target/i386/xen.c
> index 1af336d9e5..f102c40f04 100644
> --- a/target/i386/xen.c
> +++ b/target/i386/xen.c
> @@ -18,11 +18,14 @@
>   #include "hw/i386/kvm/xen_overlay.h"
>   #include "hw/i386/kvm/xen_evtchn.h"
>   
> +#define __XEN_INTERFACE_VERSION__ 0x00040400
> +

Xen is actually at:

#define __XEN_LATEST_INTERFACE_VERSION__ 0x00040e00

now.

>   #include "standard-headers/xen/version.h"
>   #include "standard-headers/xen/memory.h"
>   #include "standard-headers/xen/hvm/hvm_op.h"
>   #include "standard-headers/xen/hvm/params.h"
>   #include "standard-headers/xen/vcpu.h"
> +#include "standard-headers/xen/event_channel.h"
>   
>   static bool kvm_gva_to_gpa(CPUState *cs, uint64_t gva, uint64_t *gpa,
>                              size_t *len, bool is_write)
> @@ -452,6 +455,42 @@ static bool kvm_xen_hcall_vcpu_op(struct kvm_xen_exit *exit, X86CPU *cpu,
>       return true;
>   }
>   
> +static bool kvm_xen_hcall_evtchn_op_compat(struct kvm_xen_exit *exit,
> +                                          X86CPU *cpu, uint64_t arg)
> +{
> +    struct evtchn_op op;
> +    int err = -EFAULT;
> +
> +    if (kvm_copy_from_gva(CPU(cpu), arg, &op, sizeof(op))) {
> +        goto err;
> +    }
> +
> +    switch (op.cmd) {
> +    default:
> +        return false;
> +    }
> +err:
> +    exit->u.hcall.result = err;
> +    return true;
> +}
> +
> +static bool kvm_xen_hcall_evtchn_op(struct kvm_xen_exit *exit,
> +                                    int cmd, uint64_t arg)
> +{
> +    int err = -ENOSYS;
> +
> +    switch (cmd) {
> +    case EVTCHNOP_init_control:
> +        err = -ENOSYS;

Why? It already has that value.

   Paul

> +        break;
> +    default:
> +        return false;
> +    }
> +
> +    exit->u.hcall.result = err;
> +    return true;
> +}
> +
diff mbox series

Patch

diff --git a/target/i386/xen.c b/target/i386/xen.c
index 1af336d9e5..f102c40f04 100644
--- a/target/i386/xen.c
+++ b/target/i386/xen.c
@@ -18,11 +18,14 @@ 
 #include "hw/i386/kvm/xen_overlay.h"
 #include "hw/i386/kvm/xen_evtchn.h"
 
+#define __XEN_INTERFACE_VERSION__ 0x00040400
+
 #include "standard-headers/xen/version.h"
 #include "standard-headers/xen/memory.h"
 #include "standard-headers/xen/hvm/hvm_op.h"
 #include "standard-headers/xen/hvm/params.h"
 #include "standard-headers/xen/vcpu.h"
+#include "standard-headers/xen/event_channel.h"
 
 static bool kvm_gva_to_gpa(CPUState *cs, uint64_t gva, uint64_t *gpa,
                            size_t *len, bool is_write)
@@ -452,6 +455,42 @@  static bool kvm_xen_hcall_vcpu_op(struct kvm_xen_exit *exit, X86CPU *cpu,
     return true;
 }
 
+static bool kvm_xen_hcall_evtchn_op_compat(struct kvm_xen_exit *exit,
+                                          X86CPU *cpu, uint64_t arg)
+{
+    struct evtchn_op op;
+    int err = -EFAULT;
+
+    if (kvm_copy_from_gva(CPU(cpu), arg, &op, sizeof(op))) {
+        goto err;
+    }
+
+    switch (op.cmd) {
+    default:
+        return false;
+    }
+err:
+    exit->u.hcall.result = err;
+    return true;
+}
+
+static bool kvm_xen_hcall_evtchn_op(struct kvm_xen_exit *exit,
+                                    int cmd, uint64_t arg)
+{
+    int err = -ENOSYS;
+
+    switch (cmd) {
+    case EVTCHNOP_init_control:
+        err = -ENOSYS;
+        break;
+    default:
+        return false;
+    }
+
+    exit->u.hcall.result = err;
+    return true;
+}
+
 static bool __kvm_xen_handle_exit(X86CPU *cpu, struct kvm_xen_exit *exit)
 {
     uint16_t code = exit->u.hcall.input;
@@ -462,6 +501,12 @@  static bool __kvm_xen_handle_exit(X86CPU *cpu, struct kvm_xen_exit *exit)
     }
 
     switch (code) {
+    case __HYPERVISOR_event_channel_op_compat:
+        return kvm_xen_hcall_evtchn_op_compat(exit, cpu,
+                                              exit->u.hcall.params[0]);
+    case __HYPERVISOR_event_channel_op:
+        return kvm_xen_hcall_evtchn_op(exit, exit->u.hcall.params[0],
+                                       exit->u.hcall.params[1]);
     case __HYPERVISOR_vcpu_op:
         return kvm_xen_hcall_vcpu_op(exit, cpu,
                                      exit->u.hcall.params[0],