public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] random: fix inconsistent spinlock usage
@ 2019-02-15 22:03 Sultan Alsawaf
  2019-02-16 17:59 ` Theodore Y. Ts'o
  0 siblings, 1 reply; 2+ messages in thread
From: Sultan Alsawaf @ 2019-02-15 22:03 UTC (permalink / raw)
  To: tytso; +Cc: linux-kernel

All users of the struct entropy_store spinlock use the irqsave spinlock variant.
Spinlock users of the same lock should use be consistent in their use of a
certain spinlock primitive, which makes add_interrupt_randomness()'s spinlock
usage incorrect.

Fix the inconsistency by converting add_interrupt_randomness()'s spinlocks to
use the irqsave primitive.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
---
 drivers/char/random.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/char/random.c b/drivers/char/random.c
index 38c6d1af6..1365017a7 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1239,6 +1239,7 @@ void add_interrupt_randomness(int irq, int irq_flags)
  __u64 ip;
  unsigned long seed;
  int credit = 0;
+ unsigned long flags;

  if (cycles == 0)
  cycles = get_reg(fast_pool, regs);
@@ -1269,7 +1270,7 @@ void add_interrupt_randomness(int irq, int irq_flags)
  return;

  r = &input_pool;
- if (!spin_trylock(&r->lock))
+ if (!spin_trylock_irqsave(&r->lock, flags))
  return;

  fast_pool->last = now;
@@ -1285,7 +1286,7 @@ void add_interrupt_randomness(int irq, int irq_flags)
  __mix_pool_bytes(r, &seed, sizeof(seed));
  credit = 1;
  }
- spin_unlock(&r->lock);
+ spin_unlock_irqrestore(&r->lock, flags);

  fast_pool->count = 0;

-- 
2.20.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-02-16 18:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-02-15 22:03 [PATCH] random: fix inconsistent spinlock usage Sultan Alsawaf
2019-02-16 17:59 ` Theodore Y. Ts'o

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox