Re: [Xen-devel] [PATCH v3 34/39] ARM: new VGIC: vgic-init: register VGIC

2018-03-27 Thread Stefano Stabellini
On Thu, 22 Mar 2018, Julien Grall wrote:
> Hi Andre,
> 
> On 03/21/2018 04:32 PM, Andre Przywara wrote:
> > This patch implements the function which is called by Xen when it wants
> > to register the virtual GIC.
> > This also implements vgic_max_vcpus() for the new VGIC, which reports
> > back the maximum number of VCPUs a certain GIC model supports. Similar
> > to the counterpart in the "old" VGIC, we return some maximum value if
> > the VGIC has not been initialised yet.
> > 
> > Signed-off-by: Andre Przywara 
> 
> Thank you for the update. We will have to remove the GIC_INVALID case once
> Andrew's series is merged. If his series is merged before yours, it would not
> be an issue as that case should never be hit.
> 
> So:
> 
> Reviewed-by: Julien Grall 

Acked-by: Stefano Stabellini 


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

Re: [Xen-devel] [PATCH v3 34/39] ARM: new VGIC: vgic-init: register VGIC

2018-03-22 Thread Andre Przywara
Hi,

On 22/03/18 08:00, Julien Grall wrote:
> Hi Andre,
> 
> On 03/21/2018 04:32 PM, Andre Przywara wrote:
>> This patch implements the function which is called by Xen when it wants
>> to register the virtual GIC.
>> This also implements vgic_max_vcpus() for the new VGIC, which reports
>> back the maximum number of VCPUs a certain GIC model supports. Similar
>> to the counterpart in the "old" VGIC, we return some maximum value if
>> the VGIC has not been initialised yet.
>>
>> Signed-off-by: Andre Przywara 
> 
> Thank you for the update. We will have to remove the GIC_INVALID case
> once Andrew's series is merged. If his series is merged before yours, it
> would not be an issue as that case should never be hit.

Yes, for my first reply I didn't originally see that his patch was a 20/20.

So I changed my mind and decided to not rely on this series ;-)
We can indeed fix this up later.

> Reviewed-by: Julien Grall 

Thanks!

Andre.

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

Re: [Xen-devel] [PATCH v3 34/39] ARM: new VGIC: vgic-init: register VGIC

2018-03-22 Thread Julien Grall

Hi Andre,

On 03/21/2018 04:32 PM, Andre Przywara wrote:

This patch implements the function which is called by Xen when it wants
to register the virtual GIC.
This also implements vgic_max_vcpus() for the new VGIC, which reports
back the maximum number of VCPUs a certain GIC model supports. Similar
to the counterpart in the "old" VGIC, we return some maximum value if
the VGIC has not been initialised yet.

Signed-off-by: Andre Przywara 


Thank you for the update. We will have to remove the GIC_INVALID case 
once Andrew's series is merged. If his series is merged before yours, it 
would not be an issue as that case should never be hit.


So:

Reviewed-by: Julien Grall 

Cheers,

--
Julien Grall

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

[Xen-devel] [PATCH v3 34/39] ARM: new VGIC: vgic-init: register VGIC

2018-03-21 Thread Andre Przywara
This patch implements the function which is called by Xen when it wants
to register the virtual GIC.
This also implements vgic_max_vcpus() for the new VGIC, which reports
back the maximum number of VCPUs a certain GIC model supports. Similar
to the counterpart in the "old" VGIC, we return some maximum value if
the VGIC has not been initialised yet.

Signed-off-by: Andre Przywara 
---
Changelog v2 ... v3:
- drop premature #ifdef CONFIG_HAS_GICV3
- use new GIC_INVALID to detect uninitialised VGIC

 xen/arch/arm/vgic/vgic-init.c | 60 +++
 xen/arch/arm/vgic/vgic.c  | 25 ++
 xen/arch/arm/vgic/vgic.h  |  3 +++
 3 files changed, 88 insertions(+)
 create mode 100644 xen/arch/arm/vgic/vgic-init.c

diff --git a/xen/arch/arm/vgic/vgic-init.c b/xen/arch/arm/vgic/vgic-init.c
new file mode 100644
index 00..d091c92ed0
--- /dev/null
+++ b/xen/arch/arm/vgic/vgic-init.c
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2015, 2016 ARM Ltd.
+ * Imported from Linux ("new" KVM VGIC) and heavily adapted to Xen.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#include 
+#include 
+
+#include "vgic.h"
+
+/* CREATION */
+
+/**
+ * domain_vgic_register: create a virtual GIC
+ * @d: domain pointer
+ * @mmio_count: pointer to add number of required MMIO regions
+ *
+ * was: kvm_vgic_create
+ */
+int domain_vgic_register(struct domain *d, int *mmio_count)
+{
+switch ( d->arch.vgic.version )
+{
+case GIC_V2:
+*mmio_count = 1;
+break;
+default:
+BUG();
+}
+
+if ( d->max_vcpus > domain_max_vcpus(d) )
+return -E2BIG;
+
+d->arch.vgic.vgic_dist_base = VGIC_ADDR_UNDEF;
+d->arch.vgic.vgic_cpu_base = VGIC_ADDR_UNDEF;
+d->arch.vgic.vgic_redist_base = VGIC_ADDR_UNDEF;
+
+return 0;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/xen/arch/arm/vgic/vgic.c b/xen/arch/arm/vgic/vgic.c
index b70fdaaecb..131358a5a1 100644
--- a/xen/arch/arm/vgic/vgic.c
+++ b/xen/arch/arm/vgic/vgic.c
@@ -956,6 +956,31 @@ void vgic_sync_hardware_irq(struct domain *d,
 spin_unlock_irqrestore(>lock, flags);
 }
 
+unsigned int vgic_max_vcpus(const struct domain *d)
+{
+unsigned int vgic_vcpu_limit;
+
+switch ( d->arch.vgic.version )
+{
+case GIC_INVALID:
+/*
+ * Since evtchn_init would call domain_max_vcpus for poll_mask
+ * allocation before the VGIC has been initialised, we need to
+ * return some safe value in this case. As this is for allocation
+ * purposes, go with the maximum value.
+ */
+vgic_vcpu_limit = MAX_VIRT_CPUS;
+break;
+case GIC_V2:
+vgic_vcpu_limit = VGIC_V2_MAX_CPUS;
+break;
+default:
+BUG();
+}
+
+return min_t(unsigned int, MAX_VIRT_CPUS, vgic_vcpu_limit);
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/xen/arch/arm/vgic/vgic.h b/xen/arch/arm/vgic/vgic.h
index c7eeaf7a38..a3fcd4d965 100644
--- a/xen/arch/arm/vgic/vgic.h
+++ b/xen/arch/arm/vgic/vgic.h
@@ -25,6 +25,9 @@
 #define VARIANT_ID_XEN  0x01
 #define IMPLEMENTER_ARM 0x43b
 
+#define VGIC_ADDR_UNDEF INVALID_PADDR
+#define IS_VGIC_ADDR_UNDEF(_x)  ((_x) == VGIC_ADDR_UNDEF)
+
 #define VGIC_PRI_BITS   5
 
 #define vgic_irq_is_sgi(intid) ((intid) < VGIC_NR_SGIS)
-- 
2.14.1


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