diff mbox series

[RFC,13/21] i386/xen: implement HYPERVISOR_hvm_op

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

Commit Message

David Woodhouse Dec. 5, 2022, 5:31 p.m. UTC
From: Joao Martins <joao.m.martins@oracle.com>

This is when guest queries for support for HVMOP_pagetable_dying.

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

Comments

Philippe Mathieu-Daudé Dec. 5, 2022, 10:13 p.m. UTC | #1
On 5/12/22 18:31, David Woodhouse wrote:
> From: Joao Martins <joao.m.martins@oracle.com>
> 
> This is when guest queries for support for HVMOP_pagetable_dying.
> 
> Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
> Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
> ---
>   target/i386/xen.c | 18 ++++++++++++++++++
>   1 file changed, 18 insertions(+)
> 
> diff --git a/target/i386/xen.c b/target/i386/xen.c
> index 5d2d8a7e00..38d4cae3d0 100644
> --- a/target/i386/xen.c
> +++ b/target/i386/xen.c
> @@ -17,6 +17,7 @@
>   
>   #include "standard-headers/xen/version.h"
>   #include "standard-headers/xen/memory.h"
> +#include "standard-headers/xen/hvm/hvm_op.h"
>   
>   #define PAGE_OFFSET    0xffffffff80000000UL
>   #define PAGE_SHIFT     12
> @@ -181,6 +182,20 @@ static int kvm_xen_hcall_memory_op(struct kvm_xen_exit *exit,
>       return err ? HCALL_ERR : 0;
>   }
>   
> +static int kvm_xen_hcall_hvm_op(struct kvm_xen_exit *exit,
> +                                int cmd, uint64_t arg)
> +{
> +    switch (cmd) {
> +    case HVMOP_pagetable_dying: {
> +            exit->u.hcall.result = -ENOSYS;
> +            return 0;
> +        }
> +    }

Could it be helpful to have a trace event here, or log a GUEST_ERROR?

> +    exit->u.hcall.result = -ENOSYS;
> +    return HCALL_ERR;
> +}
David Woodhouse Dec. 6, 2022, 1:18 a.m. UTC | #2
On Mon, 2022-12-05 at 23:13 +0100, Philippe Mathieu-Daudé wrote:
> > +static int kvm_xen_hcall_hvm_op(struct kvm_xen_exit *exit,
> > +                                int cmd, uint64_t arg)
> > +{
> > +    switch (cmd) {
> > +    case HVMOP_pagetable_dying: {
> > +            exit->u.hcall.result = -ENOSYS;
> > +            return 0;
> > +        }
> > +    }
> 
> Could it be helpful to have a trace event here, or log a GUEST_ERROR?
> 
> > +    exit->u.hcall.result = -ENOSYS;
> > +    return HCALL_ERR;

We already have a trace event for hypercalls. So the unimplemented ones
look something like this (e.g. failing to set FIFO event channels, then
failing to get the CONSOLE_EVTCHN HVM param)...

[    0.151084] NR_IRQS: 524544, nr_irqs: 256, preallocated irqs: 16
kvm_xen_hypercall xen_hypercall: cpu 0 cpl 0 input 32 a0 0xb a1 0xffffffffbda03da0 a2 0xffff93cc3ec2e9a0 ret 0xffffffffffffffda
[    0.152018] xen:events: Using 2-level ABI
kvm_xen_hypercall xen_hypercall: cpu 0 cpl 0 input 34 a0 0x0 a1 0xffffffffbda03dd8 a2 0x7ff0 ret 0x0
[    0.152731] xen:events: Xen HVM callback vector for event delivery is enabled
[    0.154158] rcu: srcu_init: Setting srcu_struct sizes based on contention.
[    0.170239] Console: colour VGA+ 80x25
kvm_xen_hypercall xen_hypercall: cpu 0 cpl 0 input 34 a0 0x1 a1 0xffffffffbda03e60 a2 0x7ff0 ret 0xffffffffffffffda
[    0.170966] Cannot get hvm parameter CONSOLE_EVTCHN (18): -38!

(I just fixed a PRIu64 to PRIx64 in the trace event definition)
diff mbox series

Patch

diff --git a/target/i386/xen.c b/target/i386/xen.c
index 5d2d8a7e00..38d4cae3d0 100644
--- a/target/i386/xen.c
+++ b/target/i386/xen.c
@@ -17,6 +17,7 @@ 
 
 #include "standard-headers/xen/version.h"
 #include "standard-headers/xen/memory.h"
+#include "standard-headers/xen/hvm/hvm_op.h"
 
 #define PAGE_OFFSET    0xffffffff80000000UL
 #define PAGE_SHIFT     12
@@ -181,6 +182,20 @@  static int kvm_xen_hcall_memory_op(struct kvm_xen_exit *exit,
     return err ? HCALL_ERR : 0;
 }
 
+static int kvm_xen_hcall_hvm_op(struct kvm_xen_exit *exit,
+                                int cmd, uint64_t arg)
+{
+    switch (cmd) {
+    case HVMOP_pagetable_dying: {
+            exit->u.hcall.result = -ENOSYS;
+            return 0;
+        }
+    }
+
+    exit->u.hcall.result = -ENOSYS;
+    return HCALL_ERR;
+}
+
 static int __kvm_xen_handle_exit(X86CPU *cpu, struct kvm_xen_exit *exit)
 {
     uint16_t code = exit->u.hcall.input;
@@ -191,6 +206,9 @@  static int __kvm_xen_handle_exit(X86CPU *cpu, struct kvm_xen_exit *exit)
     }
 
     switch (code) {
+    case __HYPERVISOR_hvm_op:
+        return kvm_xen_hcall_hvm_op(exit, exit->u.hcall.params[0],
+                                    exit->u.hcall.params[1]);
     case __HYPERVISOR_memory_op:
         return kvm_xen_hcall_memory_op(exit, exit->u.hcall.params[0],
                                        exit->u.hcall.params[1], cpu);