Skip to content

Commit 511d63c

Browse files
horiagherbertx
authored andcommitted
crypto: talitos - properly lock access to global talitos registers
Access to global talitos registers must be protected for the case when affinities are configured such that primary and secondary talitos irqs run on different cpus. Signed-off-by: Horia Geanta <horia.geanta@freescale.com> Signed-off-by: Kim Phillips <kim.phillips@freescale.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 7525872 commit 511d63c

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

‎drivers/crypto/talitos.c‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ struct talitos_private {
124124
void __iomem *reg;
125125
int irq[2];
126126

127+
/* SEC global registers lock */
128+
spinlock_t reg_lock ____cacheline_aligned;
129+
127130
/* SEC version geometry (from device tree node) */
128131
unsigned int num_channels;
129132
unsigned int chfifo_len;
@@ -412,6 +415,7 @@ static void talitos_done_##name(unsigned long data) \
412415
{ \
413416
struct device *dev = (struct device *)data; \
414417
struct talitos_private *priv = dev_get_drvdata(dev); \
418+
unsigned long flags; \
415419
\
416420
if (ch_done_mask & 1) \
417421
flush_channel(dev, 0, 0, 0); \
@@ -427,8 +431,10 @@ static void talitos_done_##name(unsigned long data) \
427431
out: \
428432
/* At this point, all completed channels have been processed */ \
429433
/* Unmask done interrupts for channels completed later on. */ \
434+
spin_lock_irqsave(&priv->reg_lock, flags); \
430435
setbits32(priv->reg + TALITOS_IMR, ch_done_mask); \
431436
setbits32(priv->reg + TALITOS_IMR_LO, TALITOS_IMR_LO_INIT); \
437+
spin_unlock_irqrestore(&priv->reg_lock, flags); \
432438
}
433439
DEF_TALITOS_DONE(4ch, TALITOS_ISR_4CHDONE)
434440
DEF_TALITOS_DONE(ch0_2, TALITOS_ISR_CH_0_2_DONE)
@@ -619,22 +625,28 @@ static irqreturn_t talitos_interrupt_##name(int irq, void *data) \
619625
struct device *dev = data; \
620626
struct talitos_private *priv = dev_get_drvdata(dev); \
621627
u32 isr, isr_lo; \
628+
unsigned long flags; \
622629
\
630+
spin_lock_irqsave(&priv->reg_lock, flags); \
623631
isr = in_be32(priv->reg + TALITOS_ISR); \
624632
isr_lo = in_be32(priv->reg + TALITOS_ISR_LO); \
625633
/* Acknowledge interrupt */ \
626634
out_be32(priv->reg + TALITOS_ICR, isr & (ch_done_mask | ch_err_mask)); \
627635
out_be32(priv->reg + TALITOS_ICR_LO, isr_lo); \
628636
\
629-
if (unlikely((isr & ~TALITOS_ISR_4CHDONE) & ch_err_mask || isr_lo)) \
630-
talitos_error(dev, isr, isr_lo); \
631-
else \
637+
if (unlikely(isr & ch_err_mask || isr_lo)) { \
638+
spin_unlock_irqrestore(&priv->reg_lock, flags); \
639+
talitos_error(dev, isr & ch_err_mask, isr_lo); \
640+
} \
641+
else { \
632642
if (likely(isr & ch_done_mask)) { \
633643
/* mask further done interrupts. */ \
634644
clrbits32(priv->reg + TALITOS_IMR, ch_done_mask); \
635645
/* done_task will unmask done interrupts at exit */ \
636646
tasklet_schedule(&priv->done_task[tlet]); \
637647
} \
648+
spin_unlock_irqrestore(&priv->reg_lock, flags); \
649+
} \
638650
\
639651
return (isr & (ch_done_mask | ch_err_mask) || isr_lo) ? IRQ_HANDLED : \
640652
IRQ_NONE; \
@@ -2719,6 +2731,8 @@ static int talitos_probe(struct platform_device *ofdev)
27192731

27202732
priv->ofdev = ofdev;
27212733

2734+
spin_lock_init(&priv->reg_lock);
2735+
27222736
err = talitos_probe_irq(ofdev);
27232737
if (err)
27242738
goto err_out;

0 commit comments

Comments
 (0)