[RFC PATCH v0 2/2] ppc,spapr: Handle KVM_EXIT_ESN

Bharata B Rao posted 2 patches 4 years, 6 months ago
Maintainers: Greg Kurz <groug@kaod.org>, "Michael S. Tsirkin" <mst@redhat.com>, Cornelia Huck <cohuck@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, David Gibson <david@gibson.dropbear.id.au>
[RFC PATCH v0 2/2] ppc,spapr: Handle KVM_EXIT_ESN
Posted by Bharata B Rao 4 years, 6 months ago
Handle KVM_EXIT_ESN exit by issuing subvention notification
interrupt to the guest. Guests supporting async-pf feature
will need this interrupt to wake up tasks that are waiting
for the expropriated pages to be available.

Note: Updates to linux-headers/linux/kvm.h are temporary
pending headers update.

Signed-off-by: Bharata B Rao <bharata@linux.ibm.com>
---
 linux-headers/linux/kvm.h |  1 +
 target/ppc/kvm.c          | 16 ++++++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h
index a76945fcbc..105c8b069a 100644
--- a/linux-headers/linux/kvm.h
+++ b/linux-headers/linux/kvm.h
@@ -269,6 +269,7 @@ struct kvm_xen_exit {
 #define KVM_EXIT_AP_RESET_HOLD    32
 #define KVM_EXIT_X86_BUS_LOCK     33
 #define KVM_EXIT_XEN              34
+#define KVM_EXIT_ESN              35
 
 /* For KVM_EXIT_INTERNAL_ERROR */
 /* Emulate instruction failed. */
diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
index 330985c8a0..6bf3f06b88 100644
--- a/target/ppc/kvm.c
+++ b/target/ppc/kvm.c
@@ -38,6 +38,7 @@
 #include "hw/ppc/spapr_cpu_core.h"
 #include "hw/hw.h"
 #include "hw/ppc/ppc.h"
+#include "hw/irq.h"
 #include "migration/qemu-file-types.h"
 #include "sysemu/watchdog.h"
 #include "trace.h"
@@ -1657,6 +1658,16 @@ static int kvm_handle_debug(PowerPCCPU *cpu, struct kvm_run *run)
     return DEBUG_RETURN_GUEST;
 }
 
+#if defined(TARGET_PPC64)
+static void kvmppc_handle_esn(PowerPCCPU *cpu)
+{
+    SpaprMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
+
+    fprintf(stderr, "%s: ESN exit\n", __func__);
+    qemu_irq_pulse(spapr_qirq(spapr, SPAPR_IRQ_SNS));
+}
+#endif
+
 int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
 {
     PowerPCCPU *cpu = POWERPC_CPU(cs);
@@ -1687,6 +1698,11 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
                                               run->papr_hcall.args);
         ret = 0;
         break;
+
+    case KVM_EXIT_ESN:
+        kvmppc_handle_esn(cpu);
+        ret = 0;
+        break;
 #endif
     case KVM_EXIT_EPR:
         trace_kvm_handle_epr();
-- 
2.31.1


Re: [RFC PATCH v0 2/2] ppc,spapr: Handle KVM_EXIT_ESN
Posted by Laurent Vivier 4 years, 6 months ago
On 05/08/2021 09:32, Bharata B Rao wrote:
> Handle KVM_EXIT_ESN exit by issuing subvention notification
> interrupt to the guest. Guests supporting async-pf feature
> will need this interrupt to wake up tasks that are waiting
> for the expropriated pages to be available.
> 
> Note: Updates to linux-headers/linux/kvm.h are temporary
> pending headers update.
> 
> Signed-off-by: Bharata B Rao <bharata@linux.ibm.com>
> ---
>  linux-headers/linux/kvm.h |  1 +
>  target/ppc/kvm.c          | 16 ++++++++++++++++
>  2 files changed, 17 insertions(+)
...
> diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
> index 330985c8a0..6bf3f06b88 100644
> --- a/target/ppc/kvm.c
> +++ b/target/ppc/kvm.c
...
> @@ -1657,6 +1658,16 @@ static int kvm_handle_debug(PowerPCCPU *cpu, struct kvm_run *run)
>      return DEBUG_RETURN_GUEST;
>  }
>  
> +#if defined(TARGET_PPC64)
> +static void kvmppc_handle_esn(PowerPCCPU *cpu)
> +{
> +    SpaprMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
> +
> +    fprintf(stderr, "%s: ESN exit\n", __func__);

Do you keep this fprintf() on purpose?
You should use trace framework to add debugging traces.

Thanks,
Laurent


Re: [RFC PATCH v0 2/2] ppc,spapr: Handle KVM_EXIT_ESN
Posted by Bharata B Rao 4 years, 6 months ago
On Thu, Aug 05, 2021 at 09:48:04AM +0200, Laurent Vivier wrote:
> On 05/08/2021 09:32, Bharata B Rao wrote:
> > Handle KVM_EXIT_ESN exit by issuing subvention notification
> > interrupt to the guest. Guests supporting async-pf feature
> > will need this interrupt to wake up tasks that are waiting
> > for the expropriated pages to be available.
> > 
> > Note: Updates to linux-headers/linux/kvm.h are temporary
> > pending headers update.
> > 
> > Signed-off-by: Bharata B Rao <bharata@linux.ibm.com>
> > ---
> >  linux-headers/linux/kvm.h |  1 +
> >  target/ppc/kvm.c          | 16 ++++++++++++++++
> >  2 files changed, 17 insertions(+)
> ...
> > diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
> > index 330985c8a0..6bf3f06b88 100644
> > --- a/target/ppc/kvm.c
> > +++ b/target/ppc/kvm.c
> ...
> > @@ -1657,6 +1658,16 @@ static int kvm_handle_debug(PowerPCCPU *cpu, struct kvm_run *run)
> >      return DEBUG_RETURN_GUEST;
> >  }
> >  
> > +#if defined(TARGET_PPC64)
> > +static void kvmppc_handle_esn(PowerPCCPU *cpu)
> > +{
> > +    SpaprMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
> > +
> > +    fprintf(stderr, "%s: ESN exit\n", __func__);
> 
> Do you keep this fprintf() on purpose?

Not really, just that it survived the pre-post cleanup :-(

Regards,
Bharata.