diff mbox series

[5/7] spapr/xics: Configure number of servers in KVM

Message ID 157010410405.246126.5846482955650460662.stgit@bahia.lan
State New
Headers show
Series spapr: Use less XIVE HW resources in KVM | expand

Commit Message

Greg Kurz Oct. 3, 2019, 12:01 p.m. UTC
The XICS-on-XIVE KVM devices now has an attribute to configure the number
of interrupt servers. This allows to greatly optimize the usage of the VP
space in the XIVE HW, and thus to start a lot more VMs.

Only set this attribute if available in order to support older POWER9 KVM
and pre-POWER9 XICS KVM devices.

The XICS-on-XIVE KVM device now reports the exhaustion of VPs upon the
connection of the first VCPU. Check that in order to have a chance to
provide an hint to the user.

Signed-off-by: Greg Kurz <groug@kaod.org>
---
 hw/intc/xics_kvm.c |   24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

Comments

Cédric Le Goater Oct. 3, 2019, 12:29 p.m. UTC | #1
On 03/10/2019 14:01, Greg Kurz wrote:
> The XICS-on-XIVE KVM devices now has an attribute to configure the number
> of interrupt servers. This allows to greatly optimize the usage of the VP
> space in the XIVE HW, and thus to start a lot more VMs.
> 
> Only set this attribute if available in order to support older POWER9 KVM
> and pre-POWER9 XICS KVM devices.
> 
> The XICS-on-XIVE KVM device now reports the exhaustion of VPs upon the
> connection of the first VCPU. Check that in order to have a chance to
> provide an hint to the user.

That part would have been better in its own patch. Simpler to review.
 
> Signed-off-by: Greg Kurz <groug@kaod.org>

Anyhow, if you split or not :

Reviewed-by: Cédric Le Goater <clg@kaod.org>

> ---
>  hw/intc/xics_kvm.c |   24 ++++++++++++++++++++++--
>  1 file changed, 22 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/intc/xics_kvm.c b/hw/intc/xics_kvm.c
> index ba90d6dc966c..12d9524cc432 100644
> --- a/hw/intc/xics_kvm.c
> +++ b/hw/intc/xics_kvm.c
> @@ -165,8 +165,15 @@ void icp_kvm_realize(DeviceState *dev, Error **errp)
>  
>      ret = kvm_vcpu_enable_cap(cs, KVM_CAP_IRQ_XICS, 0, kernel_xics_fd, vcpu_id);
>      if (ret < 0) {
> -        error_setg(errp, "Unable to connect CPU%ld to kernel XICS: %s", vcpu_id,
> -                   strerror(errno));
> +        Error *local_err = NULL;
> +
> +        error_setg(&local_err, "Unable to connect CPU%ld to kernel XICS: %s",
> +                   vcpu_id, strerror(errno));
> +        if (errno == ENOSPC) {
> +            error_append_hint(&local_err, "Try -smp maxcpus=N with N < %u\n",
> +                              MACHINE(qdev_get_machine())->smp.max_cpus);
> +        }
> +        error_propagate(errp, local_err);
>          return;
>      }
>      enabled_icp = g_malloc(sizeof(*enabled_icp));
> @@ -344,6 +351,7 @@ void ics_kvm_set_irq(ICSState *ics, int srcno, int val)
>  
>  int xics_kvm_connect(SpaprMachineState *spapr, Error **errp)
>  {
> +    ICSState *ics = spapr->ics;
>      int rc;
>      CPUState *cs;
>      Error *local_err = NULL;
> @@ -397,6 +405,18 @@ int xics_kvm_connect(SpaprMachineState *spapr, Error **errp)
>          goto fail;
>      }
>  
> +    /* Tell KVM about the # of VCPUs we may have (POWER9 and newer only) */
> +    if (kvm_device_check_attr(rc, KVM_DEV_XICS_GRP_CTRL,
> +                              KVM_DEV_XICS_NR_SERVERS)) {
> +        uint32_t nr_servers = xics_nr_servers(ics->xics);
> +
> +        if (kvm_device_access(rc, KVM_DEV_XICS_GRP_CTRL,
> +                              KVM_DEV_XICS_NR_SERVERS, &nr_servers, true,
> +                              &local_err)) {
> +            goto fail;
> +        }
> +    }
> +
>      kernel_xics_fd = rc;
>      kvm_kernel_irqchip = true;
>      kvm_msi_via_irqfd_allowed = true;
>
Greg Kurz Oct. 3, 2019, 12:55 p.m. UTC | #2
On Thu, 3 Oct 2019 14:29:46 +0200
Cédric Le Goater <clg@kaod.org> wrote:

> On 03/10/2019 14:01, Greg Kurz wrote:
> > The XICS-on-XIVE KVM devices now has an attribute to configure the number
> > of interrupt servers. This allows to greatly optimize the usage of the VP
> > space in the XIVE HW, and thus to start a lot more VMs.
> > 
> > Only set this attribute if available in order to support older POWER9 KVM
> > and pre-POWER9 XICS KVM devices.
> > 
> > The XICS-on-XIVE KVM device now reports the exhaustion of VPs upon the
> > connection of the first VCPU. Check that in order to have a chance to
> > provide an hint to the user.
> 
> That part would have been better in its own patch. Simpler to review.
>  

Yeah, possibly... on the other hand, it's only two fairly simple
hunks. :)

> > Signed-off-by: Greg Kurz <groug@kaod.org>
> 
> Anyhow, if you split or not :
> 
> Reviewed-by: Cédric Le Goater <clg@kaod.org>
> 
> > ---
> >  hw/intc/xics_kvm.c |   24 ++++++++++++++++++++++--
> >  1 file changed, 22 insertions(+), 2 deletions(-)
> > 
> > diff --git a/hw/intc/xics_kvm.c b/hw/intc/xics_kvm.c
> > index ba90d6dc966c..12d9524cc432 100644
> > --- a/hw/intc/xics_kvm.c
> > +++ b/hw/intc/xics_kvm.c
> > @@ -165,8 +165,15 @@ void icp_kvm_realize(DeviceState *dev, Error **errp)
> >  
> >      ret = kvm_vcpu_enable_cap(cs, KVM_CAP_IRQ_XICS, 0, kernel_xics_fd, vcpu_id);
> >      if (ret < 0) {
> > -        error_setg(errp, "Unable to connect CPU%ld to kernel XICS: %s", vcpu_id,
> > -                   strerror(errno));
> > +        Error *local_err = NULL;
> > +
> > +        error_setg(&local_err, "Unable to connect CPU%ld to kernel XICS: %s",
> > +                   vcpu_id, strerror(errno));
> > +        if (errno == ENOSPC) {
> > +            error_append_hint(&local_err, "Try -smp maxcpus=N with N < %u\n",
> > +                              MACHINE(qdev_get_machine())->smp.max_cpus);
> > +        }
> > +        error_propagate(errp, local_err);
> >          return;
> >      }
> >      enabled_icp = g_malloc(sizeof(*enabled_icp));
> > @@ -344,6 +351,7 @@ void ics_kvm_set_irq(ICSState *ics, int srcno, int val)
> >  
> >  int xics_kvm_connect(SpaprMachineState *spapr, Error **errp)
> >  {
> > +    ICSState *ics = spapr->ics;
> >      int rc;
> >      CPUState *cs;
> >      Error *local_err = NULL;
> > @@ -397,6 +405,18 @@ int xics_kvm_connect(SpaprMachineState *spapr, Error **errp)
> >          goto fail;
> >      }
> >  
> > +    /* Tell KVM about the # of VCPUs we may have (POWER9 and newer only) */
> > +    if (kvm_device_check_attr(rc, KVM_DEV_XICS_GRP_CTRL,
> > +                              KVM_DEV_XICS_NR_SERVERS)) {
> > +        uint32_t nr_servers = xics_nr_servers(ics->xics);
> > +
> > +        if (kvm_device_access(rc, KVM_DEV_XICS_GRP_CTRL,
> > +                              KVM_DEV_XICS_NR_SERVERS, &nr_servers, true,
> > +                              &local_err)) {
> > +            goto fail;
> > +        }
> > +    }
> > +
> >      kernel_xics_fd = rc;
> >      kvm_kernel_irqchip = true;
> >      kvm_msi_via_irqfd_allowed = true;
> > 
>
diff mbox series

Patch

diff --git a/hw/intc/xics_kvm.c b/hw/intc/xics_kvm.c
index ba90d6dc966c..12d9524cc432 100644
--- a/hw/intc/xics_kvm.c
+++ b/hw/intc/xics_kvm.c
@@ -165,8 +165,15 @@  void icp_kvm_realize(DeviceState *dev, Error **errp)
 
     ret = kvm_vcpu_enable_cap(cs, KVM_CAP_IRQ_XICS, 0, kernel_xics_fd, vcpu_id);
     if (ret < 0) {
-        error_setg(errp, "Unable to connect CPU%ld to kernel XICS: %s", vcpu_id,
-                   strerror(errno));
+        Error *local_err = NULL;
+
+        error_setg(&local_err, "Unable to connect CPU%ld to kernel XICS: %s",
+                   vcpu_id, strerror(errno));
+        if (errno == ENOSPC) {
+            error_append_hint(&local_err, "Try -smp maxcpus=N with N < %u\n",
+                              MACHINE(qdev_get_machine())->smp.max_cpus);
+        }
+        error_propagate(errp, local_err);
         return;
     }
     enabled_icp = g_malloc(sizeof(*enabled_icp));
@@ -344,6 +351,7 @@  void ics_kvm_set_irq(ICSState *ics, int srcno, int val)
 
 int xics_kvm_connect(SpaprMachineState *spapr, Error **errp)
 {
+    ICSState *ics = spapr->ics;
     int rc;
     CPUState *cs;
     Error *local_err = NULL;
@@ -397,6 +405,18 @@  int xics_kvm_connect(SpaprMachineState *spapr, Error **errp)
         goto fail;
     }
 
+    /* Tell KVM about the # of VCPUs we may have (POWER9 and newer only) */
+    if (kvm_device_check_attr(rc, KVM_DEV_XICS_GRP_CTRL,
+                              KVM_DEV_XICS_NR_SERVERS)) {
+        uint32_t nr_servers = xics_nr_servers(ics->xics);
+
+        if (kvm_device_access(rc, KVM_DEV_XICS_GRP_CTRL,
+                              KVM_DEV_XICS_NR_SERVERS, &nr_servers, true,
+                              &local_err)) {
+            goto fail;
+        }
+    }
+
     kernel_xics_fd = rc;
     kvm_kernel_irqchip = true;
     kvm_msi_via_irqfd_allowed = true;