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
120 u8 func_no)120 u8 func_no)
121{121{
122 const struct pci_epc_features *epc_features;122 const struct pci_epc_features *epc_features;
123 unsigned long flags;
124 123
125 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions)124 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions)
126 return NULL;125 return NULL;
@@ -128,9 +127,9 @@ const struct pci_epc_features *pci_epc_get_features(struct pci_epc *epc, · 1 unmodified line
128 if (!epc->ops->get_features)127 if (!epc->ops->get_features)
129 return NULL;128 return NULL;
130 129
131 spin_lock_irqsave(&epc->lock, flags);130 mutex_lock(&epc->lock);
132 epc_features = epc->ops->get_features(epc, func_no);131 epc_features = epc->ops->get_features(epc, func_no);
133 spin_unlock_irqrestore(&epc->lock, flags);132 mutex_unlock(&epc->lock);
134 133
135 return epc_features;134 return epc_features;
136}135}
@@ -144,14 +143,12 @@ EXPORT_SYMBOL_GPL(pci_epc_get_features); · 7 unmodified lines
144 */143 */
145void pci_epc_stop(struct pci_epc *epc)144void pci_epc_stop(struct pci_epc *epc)
146{145{
147 unsigned long flags;
148
149 if (IS_ERR(epc) || !epc->ops->stop)146 if (IS_ERR(epc) || !epc->ops->stop)
150 return;147 return;
151 148
152 spin_lock_irqsave(&epc->lock, flags);149 mutex_lock(&epc->lock);
153 epc->ops->stop(epc);150 epc->ops->stop(epc);
154 spin_unlock_irqrestore(&epc->lock, flags);151 mutex_unlock(&epc->lock);
155}152}
156EXPORT_SYMBOL_GPL(pci_epc_stop);153EXPORT_SYMBOL_GPL(pci_epc_stop);
157 154
@@ -164,7 +161,6 @@ EXPORT_SYMBOL_GPL(pci_epc_stop); · 6 unmodified lines
164int pci_epc_start(struct pci_epc *epc)161int pci_epc_start(struct pci_epc *epc)
165{162{
166 int ret;163 int ret;
167 unsigned long flags;
168 164
169 if (IS_ERR(epc))165 if (IS_ERR(epc))
170 return -EINVAL;166 return -EINVAL;
@@ -172,9 +168,9 @@ int pci_epc_start(struct pci_epc *epc) · 1 unmodified line
172 if (!epc->ops->start)168 if (!epc->ops->start)
173 return 0;169 return 0;
174 170
175 spin_lock_irqsave(&epc->lock, flags);171 mutex_lock(&epc->lock);
176 ret = epc->ops->start(epc);172 ret = epc->ops->start(epc);
177 spin_unlock_irqrestore(&epc->lock, flags);173 mutex_unlock(&epc->lock);
178 174
179 return ret;175 return ret;
180}176}
@@ -193,7 +189,6 @@ int pci_epc_raise_irq(struct pci_epc *epc, u8 func_no, · 12 unmodified lines
193 enum pci_epc_irq_type type, u16 interrupt_num)189 enum pci_epc_irq_type type, u16 interrupt_num)
194{190{
195 int ret;191 int ret;
196 unsigned long flags;
197 192
198 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions)193 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions)
199 return -EINVAL;194 return -EINVAL;
@@ -201,9 +196,9 @@ int pci_epc_raise_irq(struct pci_epc *epc, u8 func_no, · 1 unmodified line
201 if (!epc->ops->raise_irq)196 if (!epc->ops->raise_irq)
202 return 0;197 return 0;
203 198
204 spin_lock_irqsave(&epc->lock, flags);199 mutex_lock(&epc->lock);
205 ret = epc->ops->raise_irq(epc, func_no, type, interrupt_num);200 ret = epc->ops->raise_irq(epc, func_no, type, interrupt_num);
206 spin_unlock_irqrestore(&epc->lock, flags);201 mutex_unlock(&epc->lock);
207 202
208 return ret;203 return ret;
209}204}
@@ -219,7 +214,6 @@ EXPORT_SYMBOL_GPL(pci_epc_raise_irq); · 9 unmodified lines
219int pci_epc_get_msi(struct pci_epc *epc, u8 func_no)214int pci_epc_get_msi(struct pci_epc *epc, u8 func_no)
220{215{
221 int interrupt;216 int interrupt;
222 unsigned long flags;
223 217
224 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions)218 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions)
225 return 0;219 return 0;
@@ -227,9 +221,9 @@ int pci_epc_get_msi(struct pci_epc *epc, u8 func_no) · 1 unmodified line
227 if (!epc->ops->get_msi)221 if (!epc->ops->get_msi)
228 return 0;222 return 0;
229 223
230 spin_lock_irqsave(&epc->lock, flags);224 mutex_lock(&epc->lock);
231 interrupt = epc->ops->get_msi(epc, func_no);225 interrupt = epc->ops->get_msi(epc, func_no);
232 spin_unlock_irqrestore(&epc->lock, flags);226 mutex_unlock(&epc->lock);
233 227
234 if (interrupt < 0)228 if (interrupt < 0)
235 return 0;229 return 0;
@@ -252,7 +246,6 @@ int pci_epc_set_msi(struct pci_epc *epc, u8 func_no, u8 interrupts) · 16 unmodified lines
252{246{
253 int ret;247 int ret;
254 u8 encode_int;248 u8 encode_int;
255 unsigned long flags;
256 249
257 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions ||250 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions ||
258 interrupts > 32)251 interrupts > 32)
@@ -263,9 +256,9 @@ int pci_epc_set_msi(struct pci_epc *epc, u8 func_no, u8 interrupts) · 4 unmodified lines
263 256
264 encode_int = order_base_2(interrupts);257 encode_int = order_base_2(interrupts);
265 258
266 spin_lock_irqsave(&epc->lock, flags);259 mutex_lock(&epc->lock);
267 ret = epc->ops->set_msi(epc, func_no, encode_int);260 ret = epc->ops->set_msi(epc, func_no, encode_int);
268 spin_unlock_irqrestore(&epc->lock, flags);261 mutex_unlock(&epc->lock);
269 262
270 return ret;263 return ret;
271}264}
@@ -281,7 +274,6 @@ EXPORT_SYMBOL_GPL(pci_epc_set_msi); · 9 unmodified lines
281int pci_epc_get_msix(struct pci_epc *epc, u8 func_no)274int pci_epc_get_msix(struct pci_epc *epc, u8 func_no)
282{275{
283 int interrupt;276 int interrupt;
284 unsigned long flags;
285 277
286 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions)278 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions)
287 return 0;279 return 0;
@@ -289,9 +281,9 @@ int pci_epc_get_msix(struct pci_epc *epc, u8 func_no) · 1 unmodified line
289 if (!epc->ops->get_msix)281 if (!epc->ops->get_msix)
290 return 0;282 return 0;
291 283
292 spin_lock_irqsave(&epc->lock, flags);284 mutex_lock(&epc->lock);
293 interrupt = epc->ops->get_msix(epc, func_no);285 interrupt = epc->ops->get_msix(epc, func_no);
294 spin_unlock_irqrestore(&epc->lock, flags);286 mutex_unlock(&epc->lock);
295 287
296 if (interrupt < 0)288 if (interrupt < 0)
297 return 0;289 return 0;
@@ -311,7 +303,6 @@ EXPORT_SYMBOL_GPL(pci_epc_get_msix); · 13 unmodified lines
311int pci_epc_set_msix(struct pci_epc *epc, u8 func_no, u16 interrupts)303int pci_epc_set_msix(struct pci_epc *epc, u8 func_no, u16 interrupts)
312{304{
313 int ret;305 int ret;
314 unsigned long flags;
315 306
316 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions ||307 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions ||
317 interrupts < 1 || interrupts > 2048)308 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
320 if (!epc->ops->set_msix)311 if (!epc->ops->set_msix)
321 return 0;312 return 0;
322 313
323 spin_lock_irqsave(&epc->lock, flags);314 mutex_lock(&epc->lock);
324 ret = epc->ops->set_msix(epc, func_no, interrupts - 1);315 ret = epc->ops->set_msix(epc, func_no, interrupts - 1);
325 spin_unlock_irqrestore(&epc->lock, flags);316 mutex_unlock(&epc->lock);
326 317
327 return ret;318 return ret;
328}319}
@@ -339,17 +330,15 @@ EXPORT_SYMBOL_GPL(pci_epc_set_msix); · 10 unmodified lines
339void pci_epc_unmap_addr(struct pci_epc *epc, u8 func_no,330void pci_epc_unmap_addr(struct pci_epc *epc, u8 func_no,
340 phys_addr_t phys_addr)331 phys_addr_t phys_addr)
341{332{
342 unsigned long flags;
343
344 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions)333 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions)
345 return;334 return;
346 335
347 if (!epc->ops->unmap_addr)336 if (!epc->ops->unmap_addr)
348 return;337 return;
349 338
350 spin_lock_irqsave(&epc->lock, flags);339 mutex_lock(&epc->lock);
351 epc->ops->unmap_addr(epc, func_no, phys_addr);340 epc->ops->unmap_addr(epc, func_no, phys_addr);
352 spin_unlock_irqrestore(&epc->lock, flags);341 mutex_unlock(&epc->lock);
353}342}
354EXPORT_SYMBOL_GPL(pci_epc_unmap_addr);343EXPORT_SYMBOL_GPL(pci_epc_unmap_addr);
355 344
@@ -367,7 +356,6 @@ int pci_epc_map_addr(struct pci_epc *epc, u8 func_no, · 11 unmodified lines
367 phys_addr_t phys_addr, u64 pci_addr, size_t size)356 phys_addr_t phys_addr, u64 pci_addr, size_t size)
368{357{
369 int ret;358 int ret;
370 unsigned long flags;
371 359
372 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions)360 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions)
373 return -EINVAL;361 return -EINVAL;
@@ -375,9 +363,9 @@ int pci_epc_map_addr(struct pci_epc *epc, u8 func_no, · 1 unmodified line
375 if (!epc->ops->map_addr)363 if (!epc->ops->map_addr)
376 return 0;364 return 0;
377 365
378 spin_lock_irqsave(&epc->lock, flags);366 mutex_lock(&epc->lock);
379 ret = epc->ops->map_addr(epc, func_no, phys_addr, pci_addr, size);367 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);
381 369
382 return ret;370 return ret;
383}371}
@@ -394,8 +382,6 @@ EXPORT_SYMBOL_GPL(pci_epc_map_addr); · 10 unmodified lines
394void pci_epc_clear_bar(struct pci_epc *epc, u8 func_no,382void pci_epc_clear_bar(struct pci_epc *epc, u8 func_no,
395 struct pci_epf_bar *epf_bar)383 struct pci_epf_bar *epf_bar)
396{384{
397 unsigned long flags;
398
399 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions ||385 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions ||
400 (epf_bar->barno == BAR_5 &&386 (epf_bar->barno == BAR_5 &&
401 epf_bar->flags & PCI_BASE_ADDRESS_MEM_TYPE_64))387 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
404 if (!epc->ops->clear_bar)390 if (!epc->ops->clear_bar)
405 return;391 return;
406 392
407 spin_lock_irqsave(&epc->lock, flags);393 mutex_lock(&epc->lock);
408 epc->ops->clear_bar(epc, func_no, epf_bar);394 epc->ops->clear_bar(epc, func_no, epf_bar);
409 spin_unlock_irqrestore(&epc->lock, flags);395 mutex_unlock(&epc->lock);
410}396}
411EXPORT_SYMBOL_GPL(pci_epc_clear_bar);397EXPORT_SYMBOL_GPL(pci_epc_clear_bar);
412 398
@@ -422,7 +408,6 @@ int pci_epc_set_bar(struct pci_epc *epc, u8 func_no, · 9 unmodified lines
422 struct pci_epf_bar *epf_bar)408 struct pci_epf_bar *epf_bar)
423{409{
424 int ret;410 int ret;
425 unsigned long irq_flags;
426 int flags = epf_bar->flags;411 int flags = epf_bar->flags;
427 412
428 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions ||413 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
437 if (!epc->ops->set_bar)422 if (!epc->ops->set_bar)
438 return 0;423 return 0;
439 424
440 spin_lock_irqsave(&epc->lock, irq_flags);425 mutex_lock(&epc->lock);
441 ret = epc->ops->set_bar(epc, func_no, epf_bar);426 ret = epc->ops->set_bar(epc, func_no, epf_bar);
442 spin_unlock_irqrestore(&epc->lock, irq_flags);427 mutex_unlock(&epc->lock);
443 428
444 return ret;429 return ret;
445}430}
@@ -460,7 +445,6 @@ int pci_epc_write_header(struct pci_epc *epc, u8 func_no, · 14 unmodified lines
460 struct pci_epf_header *header)445 struct pci_epf_header *header)
461{446{
462 int ret;447 int ret;
463 unsigned long flags;
464 448
465 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions)449 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions)
466 return -EINVAL;450 return -EINVAL;
@@ -468,9 +452,9 @@ int pci_epc_write_header(struct pci_epc *epc, u8 func_no, · 1 unmodified line
468 if (!epc->ops->write_header)452 if (!epc->ops->write_header)
469 return 0;453 return 0;
470 454
471 spin_lock_irqsave(&epc->lock, flags);455 mutex_lock(&epc->lock);
472 ret = epc->ops->write_header(epc, func_no, header);456 ret = epc->ops->write_header(epc, func_no, header);
473 spin_unlock_irqrestore(&epc->lock, flags);457 mutex_unlock(&epc->lock);
474 458
475 return ret;459 return ret;
476}460}
@@ -487,8 +471,6 @@ EXPORT_SYMBOL_GPL(pci_epc_write_header); · 10 unmodified lines
487 */471 */
488int pci_epc_add_epf(struct pci_epc *epc, struct pci_epf *epf)472int pci_epc_add_epf(struct pci_epc *epc, struct pci_epf *epf)
489{473{
490 unsigned long flags;
491
492 if (epf->epc)474 if (epf->epc)
493 return -EBUSY;475 return -EBUSY;
494 476
@@ -500,9 +482,9 @@ int pci_epc_add_epf(struct pci_epc *epc, struct pci_epf *epf) · 5 unmodified lines
500 482
501 epf->epc = epc;483 epf->epc = epc;
502 484
503 spin_lock_irqsave(&epc->lock, flags);485 mutex_lock(&epc->lock);
504 list_add_tail(&epf->list, &epc->pci_epf);486 list_add_tail(&epf->list, &epc->pci_epf);
505 spin_unlock_irqrestore(&epc->lock, flags);487 mutex_unlock(&epc->lock);
506 488
507 return 0;489 return 0;
508}490}
@@ -517,15 +499,13 @@ EXPORT_SYMBOL_GPL(pci_epc_add_epf); · 8 unmodified lines
517 */499 */
518void pci_epc_remove_epf(struct pci_epc *epc, struct pci_epf *epf)500void pci_epc_remove_epf(struct pci_epc *epc, struct pci_epf *epf)
519{501{
520 unsigned long flags;
521
522 if (!epc || IS_ERR(epc) || !epf)502 if (!epc || IS_ERR(epc) || !epf)
523 return;503 return;
524 504
525 spin_lock_irqsave(&epc->lock, flags);505 mutex_lock(&epc->lock);
526 list_del(&epf->list);506 list_del(&epf->list);
527 epf->epc = NULL;507 epf->epc = NULL;
528 spin_unlock_irqrestore(&epc->lock, flags);508 mutex_unlock(&epc->lock);
529}509}
530EXPORT_SYMBOL_GPL(pci_epc_remove_epf);510EXPORT_SYMBOL_GPL(pci_epc_remove_epf);
531 511
@@ -604,7 +584,7 @@ __pci_epc_create(struct device *dev, const struct pci_epc_ops *ops, · 72 unmodified lines
604 goto err_ret;584 goto err_ret;
605 }585 }
606 586
607 spin_lock_init(&epc->lock);587 mutex_init(&epc->lock);
608 INIT_LIST_HEAD(&epc->pci_epf);588 INIT_LIST_HEAD(&epc->pci_epf);
609 ATOMIC_INIT_NOTIFIER_HEAD(&epc->notifier);589 ATOMIC_INIT_NOTIFIER_HEAD(&epc->notifier);
610 590
include/linux/pci-epc.h+3−3
@@ -88,7 +88,7 @@ struct pci_epc_mem { · 87 unmodified lines
88 * @mem: address space of the endpoint controller88 * @mem: address space of the endpoint controller
89 * @max_functions: max number of functions that can be configured in this EPC89 * @max_functions: max number of functions that can be configured in this EPC
90 * @group: configfs group representing the PCI EPC device90 * @group: configfs group representing the PCI EPC device
91 * @lock: spinlock to protect pci_epc ops91 * @lock: mutex to protect pci_epc ops
92 * @notifier: used to notify EPF of any EPC events (like linkup)92 * @notifier: used to notify EPF of any EPC events (like linkup)
93 */93 */
94struct pci_epc {94struct pci_epc {
@@ -98,8 +98,8 @@ struct pci_epc { · 3 unmodified lines
98 struct pci_epc_mem *mem;98 struct pci_epc_mem *mem;
99 u8 max_functions;99 u8 max_functions;
100 struct config_group *group;100 struct config_group *group;
101 /* spinlock to protect against concurrent access of EP controller */101 /* mutex to protect against concurrent access of EP controller */
102 spinlock_t lock;102 struct mutex lock;
103 struct atomic_notifier_head notifier;103 struct atomic_notifier_head notifier;
104};104};
105 105

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