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