History

PCI: endpoint: Replace spinlock with mutex

The pci_epc_ops is not intended to be invoked from interrupt context. Hence replace spin_lock_irqsave and spin_unlock_irqrestore with mutex_lock and mutex_unlock respectively.

Kishon Vijay Abraham I committed 6 years ago

Commit 3d3248d1 parent 5779dd02 files · +34 −54Browse files

Unified · Split

2 files
  1. drivers/pci/endpoint/pci-epc-core.c +31 −51
  2. include/linux/pci-epc.h +3 −3
drivers/pci/endpoint/pci-epc-core.c+31−51
@@ -120,7 +120,6 @@ const struct pci_epc_features *pci_epc_get_features(struct pci_epc *epc, · 119 unmodified lines
120120 u8 func_no)
121121 {
122122 const struct pci_epc_features *epc_features;
123− unsigned long flags;
124123
125124 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions)
126125 return NULL;
@@ -128,9 +127,9 @@ const struct pci_epc_features *pci_epc_get_features(struct pci_epc *epc, · 1 unmodified line
128127 if (!epc->ops->get_features)
129128 return NULL;
130129
131− spin_lock_irqsave(&epc->lock, flags);
130+ mutex_lock(&epc->lock);
132131 epc_features = epc->ops->get_features(epc, func_no);
133− spin_unlock_irqrestore(&epc->lock, flags);
132+ mutex_unlock(&epc->lock);
134133
135134 return epc_features;
136135 }
@@ -144,14 +143,12 @@ EXPORT_SYMBOL_GPL(pci_epc_get_features); · 7 unmodified lines
144143 */
145144 void pci_epc_stop(struct pci_epc *epc)
146145 {
147− unsigned long flags;
148−
149146 if (IS_ERR(epc) || !epc->ops->stop)
150147 return;
151148
152− spin_lock_irqsave(&epc->lock, flags);
149+ mutex_lock(&epc->lock);
153150 epc->ops->stop(epc);
154− spin_unlock_irqrestore(&epc->lock, flags);
151+ mutex_unlock(&epc->lock);
155152 }
156153 EXPORT_SYMBOL_GPL(pci_epc_stop);
157154
@@ -164,7 +161,6 @@ EXPORT_SYMBOL_GPL(pci_epc_stop); · 6 unmodified lines
164161 int pci_epc_start(struct pci_epc *epc)
165162 {
166163 int ret;
167− unsigned long flags;
168164
169165 if (IS_ERR(epc))
170166 return -EINVAL;
@@ -172,9 +168,9 @@ int pci_epc_start(struct pci_epc *epc) · 1 unmodified line
172168 if (!epc->ops->start)
173169 return 0;
174170
175− spin_lock_irqsave(&epc->lock, flags);
171+ mutex_lock(&epc->lock);
176172 ret = epc->ops->start(epc);
177− spin_unlock_irqrestore(&epc->lock, flags);
173+ mutex_unlock(&epc->lock);
178174
179175 return ret;
180176 }
@@ -193,7 +189,6 @@ int pci_epc_raise_irq(struct pci_epc *epc, u8 func_no, · 12 unmodified lines
193189 enum pci_epc_irq_type type, u16 interrupt_num)
194190 {
195191 int ret;
196− unsigned long flags;
197192
198193 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions)
199194 return -EINVAL;
@@ -201,9 +196,9 @@ int pci_epc_raise_irq(struct pci_epc *epc, u8 func_no, · 1 unmodified line
201196 if (!epc->ops->raise_irq)
202197 return 0;
203198
204− spin_lock_irqsave(&epc->lock, flags);
199+ mutex_lock(&epc->lock);
205200 ret = epc->ops->raise_irq(epc, func_no, type, interrupt_num);
206− spin_unlock_irqrestore(&epc->lock, flags);
201+ mutex_unlock(&epc->lock);
207202
208203 return ret;
209204 }
@@ -219,7 +214,6 @@ EXPORT_SYMBOL_GPL(pci_epc_raise_irq); · 9 unmodified lines
219214 int pci_epc_get_msi(struct pci_epc *epc, u8 func_no)
220215 {
221216 int interrupt;
222− unsigned long flags;
223217
224218 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions)
225219 return 0;
@@ -227,9 +221,9 @@ int pci_epc_get_msi(struct pci_epc *epc, u8 func_no) · 1 unmodified line
227221 if (!epc->ops->get_msi)
228222 return 0;
229223
230− spin_lock_irqsave(&epc->lock, flags);
224+ mutex_lock(&epc->lock);
231225 interrupt = epc->ops->get_msi(epc, func_no);
232− spin_unlock_irqrestore(&epc->lock, flags);
226+ mutex_unlock(&epc->lock);
233227
234228 if (interrupt < 0)
235229 return 0;
@@ -252,7 +246,6 @@ int pci_epc_set_msi(struct pci_epc *epc, u8 func_no, u8 interrupts) · 16 unmodified lines
252246 {
253247 int ret;
254248 u8 encode_int;
255− unsigned long flags;
256249
257250 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions ||
258251 interrupts > 32)
@@ -263,9 +256,9 @@ int pci_epc_set_msi(struct pci_epc *epc, u8 func_no, u8 interrupts) · 4 unmodified lines
263256
264257 encode_int = order_base_2(interrupts);
265258
266− spin_lock_irqsave(&epc->lock, flags);
259+ mutex_lock(&epc->lock);
267260 ret = epc->ops->set_msi(epc, func_no, encode_int);
268− spin_unlock_irqrestore(&epc->lock, flags);
261+ mutex_unlock(&epc->lock);
269262
270263 return ret;
271264 }
@@ -281,7 +274,6 @@ EXPORT_SYMBOL_GPL(pci_epc_set_msi); · 9 unmodified lines
281274 int pci_epc_get_msix(struct pci_epc *epc, u8 func_no)
282275 {
283276 int interrupt;
284− unsigned long flags;
285277
286278 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions)
287279 return 0;
@@ -289,9 +281,9 @@ int pci_epc_get_msix(struct pci_epc *epc, u8 func_no) · 1 unmodified line
289281 if (!epc->ops->get_msix)
290282 return 0;
291283
292− spin_lock_irqsave(&epc->lock, flags);
284+ mutex_lock(&epc->lock);
293285 interrupt = epc->ops->get_msix(epc, func_no);
294− spin_unlock_irqrestore(&epc->lock, flags);
286+ mutex_unlock(&epc->lock);
295287
296288 if (interrupt < 0)
297289 return 0;
@@ -311,7 +303,6 @@ EXPORT_SYMBOL_GPL(pci_epc_get_msix); · 13 unmodified lines
311303 int pci_epc_set_msix(struct pci_epc *epc, u8 func_no, u16 interrupts)
312304 {
313305 int ret;
314− unsigned long flags;
315306
316307 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions ||
317308 interrupts < 1 || interrupts > 2048)
@@ -320,9 +311,9 @@ int pci_epc_set_msix(struct pci_epc *epc, u8 func_no, u16 interrupts) · 2 unmodified lines
320311 if (!epc->ops->set_msix)
321312 return 0;
322313
323− spin_lock_irqsave(&epc->lock, flags);
314+ mutex_lock(&epc->lock);
324315 ret = epc->ops->set_msix(epc, func_no, interrupts - 1);
325− spin_unlock_irqrestore(&epc->lock, flags);
316+ mutex_unlock(&epc->lock);
326317
327318 return ret;
328319 }
@@ -339,17 +330,15 @@ EXPORT_SYMBOL_GPL(pci_epc_set_msix); · 10 unmodified lines
339330 void pci_epc_unmap_addr(struct pci_epc *epc, u8 func_no,
340331 phys_addr_t phys_addr)
341332 {
342− unsigned long flags;
343−
344333 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions)
345334 return;
346335
347336 if (!epc->ops->unmap_addr)
348337 return;
349338
350− spin_lock_irqsave(&epc->lock, flags);
339+ mutex_lock(&epc->lock);
351340 epc->ops->unmap_addr(epc, func_no, phys_addr);
352− spin_unlock_irqrestore(&epc->lock, flags);
341+ mutex_unlock(&epc->lock);
353342 }
354343 EXPORT_SYMBOL_GPL(pci_epc_unmap_addr);
355344
@@ -367,7 +356,6 @@ int pci_epc_map_addr(struct pci_epc *epc, u8 func_no, · 11 unmodified lines
367356 phys_addr_t phys_addr, u64 pci_addr, size_t size)
368357 {
369358 int ret;
370− unsigned long flags;
371359
372360 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions)
373361 return -EINVAL;
@@ -375,9 +363,9 @@ int pci_epc_map_addr(struct pci_epc *epc, u8 func_no, · 1 unmodified line
375363 if (!epc->ops->map_addr)
376364 return 0;
377365
378− spin_lock_irqsave(&epc->lock, flags);
366+ mutex_lock(&epc->lock);
379367 ret = epc->ops->map_addr(epc, func_no, phys_addr, pci_addr, size);
380− spin_unlock_irqrestore(&epc->lock, flags);
368+ mutex_unlock(&epc->lock);
381369
382370 return ret;
383371 }
@@ -394,8 +382,6 @@ EXPORT_SYMBOL_GPL(pci_epc_map_addr); · 10 unmodified lines
394382 void pci_epc_clear_bar(struct pci_epc *epc, u8 func_no,
395383 struct pci_epf_bar *epf_bar)
396384 {
397− unsigned long flags;
398−
399385 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions ||
400386 (epf_bar->barno == BAR_5 &&
401387 epf_bar->flags & PCI_BASE_ADDRESS_MEM_TYPE_64))
@@ -404,9 +390,9 @@ void pci_epc_clear_bar(struct pci_epc *epc, u8 func_no, · 2 unmodified lines
404390 if (!epc->ops->clear_bar)
405391 return;
406392
407− spin_lock_irqsave(&epc->lock, flags);
393+ mutex_lock(&epc->lock);
408394 epc->ops->clear_bar(epc, func_no, epf_bar);
409− spin_unlock_irqrestore(&epc->lock, flags);
395+ mutex_unlock(&epc->lock);
410396 }
411397 EXPORT_SYMBOL_GPL(pci_epc_clear_bar);
412398
@@ -422,7 +408,6 @@ int pci_epc_set_bar(struct pci_epc *epc, u8 func_no, · 9 unmodified lines
422408 struct pci_epf_bar *epf_bar)
423409 {
424410 int ret;
425− unsigned long irq_flags;
426411 int flags = epf_bar->flags;
427412
428413 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions ||
@@ -437,9 +422,9 @@ int pci_epc_set_bar(struct pci_epc *epc, u8 func_no, · 8 unmodified lines
437422 if (!epc->ops->set_bar)
438423 return 0;
439424
440− spin_lock_irqsave(&epc->lock, irq_flags);
425+ mutex_lock(&epc->lock);
441426 ret = epc->ops->set_bar(epc, func_no, epf_bar);
442− spin_unlock_irqrestore(&epc->lock, irq_flags);
427+ mutex_unlock(&epc->lock);
443428
444429 return ret;
445430 }
@@ -460,7 +445,6 @@ int pci_epc_write_header(struct pci_epc *epc, u8 func_no, · 14 unmodified lines
460445 struct pci_epf_header *header)
461446 {
462447 int ret;
463− unsigned long flags;
464448
465449 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions)
466450 return -EINVAL;
@@ -468,9 +452,9 @@ int pci_epc_write_header(struct pci_epc *epc, u8 func_no, · 1 unmodified line
468452 if (!epc->ops->write_header)
469453 return 0;
470454
471− spin_lock_irqsave(&epc->lock, flags);
455+ mutex_lock(&epc->lock);
472456 ret = epc->ops->write_header(epc, func_no, header);
473− spin_unlock_irqrestore(&epc->lock, flags);
457+ mutex_unlock(&epc->lock);
474458
475459 return ret;
476460 }
@@ -487,8 +471,6 @@ EXPORT_SYMBOL_GPL(pci_epc_write_header); · 10 unmodified lines
487471 */
488472 int pci_epc_add_epf(struct pci_epc *epc, struct pci_epf *epf)
489473 {
490− unsigned long flags;
491−
492474 if (epf->epc)
493475 return -EBUSY;
494476
@@ -500,9 +482,9 @@ int pci_epc_add_epf(struct pci_epc *epc, struct pci_epf *epf) · 5 unmodified lines
500482
501483 epf->epc = epc;
502484
503− spin_lock_irqsave(&epc->lock, flags);
485+ mutex_lock(&epc->lock);
504486 list_add_tail(&epf->list, &epc->pci_epf);
505− spin_unlock_irqrestore(&epc->lock, flags);
487+ mutex_unlock(&epc->lock);
506488
507489 return 0;
508490 }
@@ -517,15 +499,13 @@ EXPORT_SYMBOL_GPL(pci_epc_add_epf); · 8 unmodified lines
517499 */
518500 void pci_epc_remove_epf(struct pci_epc *epc, struct pci_epf *epf)
519501 {
520− unsigned long flags;
521−
522502 if (!epc || IS_ERR(epc) || !epf)
523503 return;
524504
525− spin_lock_irqsave(&epc->lock, flags);
505+ mutex_lock(&epc->lock);
526506 list_del(&epf->list);
527507 epf->epc = NULL;
528− spin_unlock_irqrestore(&epc->lock, flags);
508+ mutex_unlock(&epc->lock);
529509 }
530510 EXPORT_SYMBOL_GPL(pci_epc_remove_epf);
531511
@@ -604,7 +584,7 @@ __pci_epc_create(struct device *dev, const struct pci_epc_ops *ops, · 72 unmodified lines
604584 goto err_ret;
605585 }
606586
607− spin_lock_init(&epc->lock);
587+ mutex_init(&epc->lock);
608588 INIT_LIST_HEAD(&epc->pci_epf);
609589 ATOMIC_INIT_NOTIFIER_HEAD(&epc->notifier);
610590
include/linux/pci-epc.h+3−3
@@ -88,7 +88,7 @@ struct pci_epc_mem { · 87 unmodified lines
8888 * @mem: address space of the endpoint controller
8989 * @max_functions: max number of functions that can be configured in this EPC
9090 * @group: configfs group representing the PCI EPC device
91− * @lock: spinlock to protect pci_epc ops
91+ * @lock: mutex to protect pci_epc ops
9292 * @notifier: used to notify EPF of any EPC events (like linkup)
9393 */
9494 struct pci_epc {
@@ -98,8 +98,8 @@ struct pci_epc { · 3 unmodified lines
9898 struct pci_epc_mem *mem;
9999 u8 max_functions;
100100 struct config_group *group;
101− /* spinlock to protect against concurrent access of EP controller */
102− spinlock_t lock;
101+ /* mutex to protect against concurrent access of EP controller */
102+ struct mutex lock;
103103 struct atomic_notifier_head notifier;
104104 };
105105

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t