irqchip updates for 5.0-rc6
Subsystems (2)
cover irqchip updates for 5.0-rc6
Hi Thomas,
This is the final set of 5.0 updates from the irqchip department. This time, an embarassingly large number of GICv3/GICv4 buglets (VLPI drop, MSI allocation race on device sharing the same DevID, LPI pool exhaustion and other cleanups), as well as a fix for PJ4-based systems that apparently never worked correctly until now.
Please pull,
M.
The following changes since commit 8208d1708b88b412ca97f50a6d951242c88cbbac:
irqchip/gic-v3-its: Align PCI Multi-MSI allocation on their size (2019-01-18 14:35:38 +0000)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.git tags/irqchip-5.0-3
for you to fetch changes up to 56841070ccc87b463ac037d2d1f2beb8e5e35f0c:
irqchip/gic-v3-its: Fix ITT_entry_size accessor (2019-01-31 12:51:33 +0000)
----------------------------------------------------------------
irqchip update for 5.0-rc6
- Another GICv3 ITS fix for devices sharing the same DevID
- Don't return invalid data on exhaustion of the GICv3 LPI pool
- Fix a GICv3 field decoding bug leading to memory over-allocation
- Init GICv4 at boot time instead of lazy init
- Fix interrupt masking on PJ4
----------------------------------------------------------------
Heyi Guo (1):
irqchip/gic-v4: Fix occasional VLPI drop
Lubomir Rintel (1):
irqchip/mmp: Only touch the PJ4 IRQ & FIQ bits on enable/disable
Marc Zyngier (2):
irqchip/gic-v3-its: Plug allocation race for devices sharing a DevID irqchip/gic-v3-its: Gracefully fail on LPI exhaustion
Zenghui Yu (1):
irqchip/gic-v3-its: Fix ITT_entry_size accessor
drivers/irqchip/irq-gic-v3-its.c | 101 +++++++++++++++++++++++++++++-------- drivers/irqchip/irq-mmp.c | 6 ++- include/linux/irqchip/arm-gic-v3.h | 2 +- 3 files changed, 85 insertions(+), 24 deletions(-)
PATCH 1/5 irqchip/gic-v4: Fix occasional VLPI drop
From: Heyi Guo <[email protected]>
1. In current implementation, every VLPI will temporarily be mapped to the first CPU in system (normally CPU0) and then moved to the real scheduled CPU later.
2. So there is a time window and a VLPI may be sent to CPU0 instead of the real scheduled vCPU, in a multi-CPU virtual machine.
3. However, CPU0 may have not been scheduled as a virtual CPU after system boots up, so the value of its GICR_VPROPBASER is unknown at that moment.
4. If the INTID of VLPI is larger than 2^(GICR_VPROPBASER.IDbits+1), while IDbits is also in unknown state, GIC will behave as if the VLPI is out of range and simply drop it, which results in interrupt missing in Guest.
As no code will clear GICR_VPROPBASER at runtime, we can safely initialize the IDbits field at boot time for each CPU to get rid of this issue.
We also clear Valid bit of GICR_VPENDBASER in case any ancient programming gets left in and causes memory corrupting. A new function its_clear_vpend_valid() is added to reuse the code in its_vpe_deschedule().
--- drivers/irqchip/irq-gic-v3-its.c | 66 ++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 17 deletions(-)
drivers/irqchip/irq-gic-v3-its.c +49 -17
@@ -2059,6 +2059,29 @@ static int __init allocate_lpi_tables(void)return 0 ; } +static u64 its_clear_vpend_valid (void __iomem *vlpi_base) +{ +u32 count =1000000 ;/* 1s! */ +bool clean; +u64 val; + + val =gits_read_vpendbaser (vlpi_base +GICR_VPENDBASER ); + val &= ~GICR_VPENDBASER_Valid; +gits_write_vpendbaser (val, vlpi_base +GICR_VPENDBASER ); + +do { + val =gits_read_vpendbaser (vlpi_base +GICR_VPENDBASER ); + clean = !(val & GICR_VPENDBASER_Dirty); +if (!clean) { + count--; +cpu_relax (); +udelay (1 ); + } + }while (!clean && count); + +return val; +} +static void its_cpu_init_lpis (void ) {void __iomem *rbase =gic_data_rdist_rd_base ();
@@ -2144,6 +2167,30 @@ static void its_cpu_init_lpis(void) val |=GICR_CTLR_ENABLE_LPIS ;writel_relaxed (val, rbase +GICR_CTLR ); +if (gic_rdists->has_vlpis) { +void __iomem *vlpi_base =gic_data_rdist_vlpi_base (); + +/* +* It's possible for CPU to receive VLPIs before it is +* sheduled as a vPE, especially for the first CPU, and the +* VLPI with INTID larger than 2^(IDbits+1) will be considered +* as out of range and dropped by GIC. +* So we initialize IDbits to known value to avoid VLPI drop. +*/ + val = (LPI_NRBITS -1 ) &GICR_VPROPBASER_IDBITS_MASK ; +pr_debug ("GICv4: CPU%d: Init IDbits to 0x%llx for GICR_VPROPBASER\n" , +smp_processor_id (), val); +gits_write_vpropbaser (val, vlpi_base +GICR_VPROPBASER ); + +/* +* Also clear Valid bit of GICR_VPENDBASER, in case some +* ancient programming gets left in and has possibility of +* corrupting memory. +*/ + val =its_clear_vpend_valid (vlpi_base); +WARN_ON (val & GICR_VPENDBASER_Dirty); + } +/* Make sure the GIC has seen the above */ dsb (sy); out:
@@ -2755,26 +2802,11 @@ static void its_vpe_schedule(struct its_vpe *vpe)static void its_vpe_deschedule (struct its_vpe *vpe) {void __iomem *vlpi_base =gic_data_rdist_vlpi_base (); -u32 count =1000000 ;/* 1s! */ -bool clean;u64 val; -/* We're being scheduled out */ - val =gits_read_vpendbaser (vlpi_base +GICR_VPENDBASER ); - val &= ~GICR_VPENDBASER_Valid; -gits_write_vpendbaser (val, vlpi_base +GICR_VPENDBASER ); - -do { - val =gits_read_vpendbaser (vlpi_base +GICR_VPENDBASER ); - clean = !(val & GICR_VPENDBASER_Dirty); -if (!clean) { - count--; -cpu_relax (); -udelay (1 ); - } - }while (!clean && count); + val =its_clear_vpend_valid (vlpi_base); -if (unlikely (!clean && !count)) { +if (unlikely (val & GICR_VPENDBASER_Dirty)) {pr_err_ratelimited ("ITS virtual pending table not cleaning\n" ); vpe->idai = false; vpe->pending_last = true;
Signature · 1 line
2.20.1
PATCH 2/5 irqchip/gic-v3-its: Plug allocation race for devices sharing a DevID
In reply to Marc ZyngierOn systems or VMs where multiple devices share a single DevID (because they sit behind a PCI bridge, or because the HW is broken in funky ways), we reuse the save its_device structure in order to reflect this.
It turns out that there is a distinct lack of locking when looking up the its_device, and two device being probed concurrently can result in double allocations. That's obviously not nice.
A solution for this is to have a per-ITS mutex that serializes device allocation.
A similar issue exists on the freeing side, which can run concurrently with the allocation. On top of now taking the appropriate lock, we also make sure that a shared device is never freed, as we have no way to currently track the life cycle of such object.
--- drivers/irqchip/irq-gic-v3-its.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-)
drivers/irqchip/irq-gic-v3-its.c +27 -5
@@ -97,9 +97,14 @@ struct its_device;* The ITS structure - contains most of the infrastructure, with the * top-level MSI domain, the command queue, the collections, and the * list of devices writing to it. +* +* dev_alloc_lock has to be taken for device allocations, while the +* spinlock must be taken to parse data structures such as the device +* list. */ struct its_node {raw_spinlock_t lock; +struct mutex dev_alloc_lock;struct list_head entry;void __iomem *base;phys_addr_t phys_base;
@@ -156,6 +161,7 @@ struct its_device {void *itt;u32 nr_ites;u32 device_id; +bool shared; }; static struct {
@@ -2469,6 +2475,7 @@ static int its_msi_prepare(struct irq_domain *domain, struct device *dev,struct its_device *its_dev;struct msi_domain_info *msi_info;u32 dev_id; +int err =0 ;/* * We ignore "dev" entierely, and rely on the dev_id that has
@@ -2491,6 +2498,7 @@ static int its_msi_prepare(struct irq_domain *domain, struct device *dev,return -EINVAL ; } +mutex_lock (&its->dev_alloc_lock); its_dev =its_find_device (its, dev_id);if (its_dev) {/*
@@ -2498,18 +2506,22 @@ static int its_msi_prepare(struct irq_domain *domain, struct device *dev,* another alias (PCI bridge of some sort). No need to * create the device. */ + its_dev->shared = true;pr_debug ("Reusing ITT for devID %x\n" , dev_id); goto out; } its_dev =its_create_device (its, dev_id, nvec, true); -if (!its_dev) -return -ENOMEM ; +if (!its_dev) { + err = -ENOMEM ; + goto out; + }pr_debug ("ITT %d entries, %d bits\n" , nvec,ilog2 (nvec)); out: +mutex_unlock (&its->dev_alloc_lock); info->scratchpad[0 ].ptr = its_dev; -return 0 ; +return err; }static struct msi_domain_ops its_msi_domain_ops = {
@@ -2613,6 +2625,7 @@ static void its_irq_domain_free(struct irq_domain *domain, unsigned int virq, {struct irq_data *d =irq_domain_get_irq_data (domain, virq);struct its_device *its_dev =irq_data_get_irq_chip_data (d); +struct its_node *its = its_dev->its;int i;for (i =0 ; i < nr_irqs; i++) {
@@ -2627,8 +2640,14 @@ static void its_irq_domain_free(struct irq_domain *domain, unsigned int virq,irq_domain_reset_irq_data (data); } -/* If all interrupts have been freed, start mopping the floor */ -if (bitmap_empty (its_dev->event_map.lpi_map, +mutex_lock (&its->dev_alloc_lock); + +/* +* If all interrupts have been freed, start mopping the +* floor. This is conditionned on the device not being shared. +*/ +if (!its_dev->shared && +bitmap_empty (its_dev->event_map.lpi_map, its_dev->event_map.nr_lpis)) { its_lpi_free(its_dev->event_map.lpi_map, its_dev->event_map.lpi_base,
@@ -2640,6 +2659,8 @@ static void its_irq_domain_free(struct irq_domain *domain, unsigned int virq,its_free_device (its_dev); } +mutex_unlock (&its->dev_alloc_lock); +irq_domain_free_irqs_parent (domain, virq, nr_irqs); }
@@ -3549,6 +3570,7 @@ static int __init its_probe_one(struct resource *res, }raw_spin_lock_init (&its->lock); +mutex_init (&its->dev_alloc_lock);INIT_LIST_HEAD (&its->entry);INIT_LIST_HEAD (&its->its_device_list); typer =gic_read_typer (its_base +GITS_TYPER );
Signature · 1 line
2.20.1
PATCH 3/5 irqchip/gic-v3-its: Gracefully fail on LPI exhaustion
In reply to Marc ZyngierIn the unlikely event that we cannot find any available LPI in the system, we should gracefully return an error instead of carrying on with no LPI allocated at all.
--- drivers/irqchip/irq-gic-v3-its.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/irqchip/irq-gic-v3-its.c +3 -0
@@ -1586,6 +1586,9 @@ static unsigned long *its_lpi_alloc(int nr_irqs, u32 *base, int *nr_ids) nr_irqs /=2 ; }while (nr_irqs >0 ); +if (!nr_irqs) + err = -ENOSPC ; +if (err) goto out;
Signature · 1 line
2.20.1
PATCH 4/5 irqchip/mmp: Only touch the PJ4 IRQ & FIQ bits on enable/disable
In reply to Marc ZyngierFrom: Lubomir Rintel <[email protected]>
Resetting bit 4 disables the interrupt delivery to the "secure processor" core. This breaks the keyboard on a OLPC XO 1.75 laptop, where the firmware running on the "secure processor" bit-bangs the PS/2 protocol over the GPIO lines.
It is not clear what the rest of the bits are and Marvell was unhelpful when asked for documentation. Aside from the SP bit, there are probably priority bits.
Leaving the unknown bits as the firmware set them up seems to be a wiser course of action compared to just turning them off.
--- drivers/irqchip/irq-mmp.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/irqchip/irq-mmp.c +5 -1
@@ -34,6 +34,9 @@#define SEL_INT_PENDING (1 << 6)#define SEL_INT_NUM_MASK 0x3f +#define MMP2_ICU_INT_ROUTE_PJ4_IRQ (1 << 5) +#define MMP2_ICU_INT_ROUTE_PJ4_FIQ (1 << 6) +struct icu_chip_data {int nr_irqs;unsigned int virq_base;
@@ -190,7 +193,8 @@ static const struct mmp_intc_conf mmp_conf = {static const struct mmp_intc_conf mmp2_conf = { .conf_enable =0x20 , .conf_disable =0x0 , - .conf_mask =0x7f , + .conf_mask =MMP2_ICU_INT_ROUTE_PJ4_IRQ | +MMP2_ICU_INT_ROUTE_PJ4_FIQ , }; static void __exception_irq_entry mmp_handle_irq(struct pt_regs *regs)
Signature · 1 line
2.20.1
PATCH 5/5 irqchip/gic-v3-its: Fix ITT_entry_size accessor
In reply to Marc ZyngierFrom: Zenghui Yu <[email protected]>
According to ARM IHI 0069C (ID070116), we should use GITS_TYPER's bits [7:4] as ITT_entry_size instead of [8:4]. Although this is pretty annoying, it only results in a potential over-allocation of memory, and nothing bad happens.
--- include/linux/irqchip/arm-gic-v3.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/irqchip/arm-gic-v3.h +1 -1
@@ -319,7 +319,7 @@#define GITS_TYPER_PLPIS (1UL << 0)#define GITS_TYPER_VLPIS (1UL << 1)#define GITS_TYPER_ITT_ENTRY_SIZE_SHIFT 4 -#define GITS_TYPER_ITT_ENTRY_SIZE (r) ((((r) >> GITS_TYPER_ITT_ENTRY_SIZE_SHIFT) & 0x1f) + 1) +#define GITS_TYPER_ITT_ENTRY_SIZE (r) ((((r) >> GITS_TYPER_ITT_ENTRY_SIZE_SHIFT) & 0xf) + 1)#define GITS_TYPER_IDBITS_SHIFT 8#define GITS_TYPER_DEVBITS_SHIFT 13#define GITS_TYPER_DEVBITS (r) ((((r) >> GITS_TYPER_DEVBITS_SHIFT) & 0x1f) + 1)
Signature · 1 line
2.20.1
Quoted 8 lines · Marc Zyngier
Hi Thomas,
This is the final set of 5.0 updates from the irqchip department. This time, an embarassingly large number of GICv3/GICv4 buglets (VLPI drop, MSI allocation race on device sharing the same DevID, LPI pool exhaustion and other cleanups), as well as a fix for PJ4-based systems that apparently never worked correctly until now.
Of course, the subject is slightly off, and it should say "GIT PULL". I swear I'll use the right script next time...
Thanks,
M.
Signature · 1 line
Jazz is not dead, it just smell funny.