Commit 5a4e6dccbc0cd1b726820b782daebf887dcb95e9

Authored by Roland Dreier
1 parent 22db37ec5f

IB/mthca: Use IRQ safe locks to protect allocation bitmaps

It is supposed to be OK to call mthca_create_ah() and mthca_destroy_ah()
from any context.  However, for mem-full HCAs, these functions use the
mthca_alloc() and mthca_free() bitmap helpers, and those helpers use
non-IRQ-safe spin_lock() internally.  Lockdep correctly warns that
this could lead to a deadlock.  Fix this by changing mthca_alloc() and
mthca_free() to use spin_lock_irqsave().

Signed-off-by: Roland Dreier <rolandd@cisco.com>

Showing 1 changed file with 11 additions and 4 deletions Side-by-side Diff

drivers/infiniband/hw/mthca/mthca_allocator.c
... ... @@ -41,9 +41,11 @@
41 41 /* Trivial bitmap-based allocator */
42 42 u32 mthca_alloc(struct mthca_alloc *alloc)
43 43 {
  44 + unsigned long flags;
44 45 u32 obj;
45 46  
46   - spin_lock(&alloc->lock);
  47 + spin_lock_irqsave(&alloc->lock, flags);
  48 +
47 49 obj = find_next_zero_bit(alloc->table, alloc->max, alloc->last);
48 50 if (obj >= alloc->max) {
49 51 alloc->top = (alloc->top + alloc->max) & alloc->mask;
50 52  
51 53  
52 54  
... ... @@ -56,19 +58,24 @@
56 58 } else
57 59 obj = -1;
58 60  
59   - spin_unlock(&alloc->lock);
  61 + spin_unlock_irqrestore(&alloc->lock, flags);
60 62  
61 63 return obj;
62 64 }
63 65  
64 66 void mthca_free(struct mthca_alloc *alloc, u32 obj)
65 67 {
  68 + unsigned long flags;
  69 +
66 70 obj &= alloc->max - 1;
67   - spin_lock(&alloc->lock);
  71 +
  72 + spin_lock_irqsave(&alloc->lock, flags);
  73 +
68 74 clear_bit(obj, alloc->table);
69 75 alloc->last = min(alloc->last, obj);
70 76 alloc->top = (alloc->top + alloc->max) & alloc->mask;
71   - spin_unlock(&alloc->lock);
  77 +
  78 + spin_unlock_irqrestore(&alloc->lock, flags);
72 79 }
73 80  
74 81 int mthca_alloc_init(struct mthca_alloc *alloc, u32 num, u32 mask,