Pull NTB bug fixes from Jon Mason: "NTB bug fixes for tasklet from spinning forever, link errors, translation window setup, NULL ptr dereference, and ntb-perf errors. Also, a modification to the driver API that makes _addr functions optional" * tag 'ntb-4.6' of git://github.com/jonmason/ntb: NTB: Remove _addr functions from ntb_hw_amd NTB: Make _addr functions optional in the API NTB: Fix incorrect clean up routine in ntb_perf NTB: Fix incorrect return check in ntb_perf ntb: fix possible NULL dereference ntb: add missing setup of translation window ntb: stop link work when we do not have memory ntb: stop tasklet from spinning forever during shutdown. ntb: perf test: fix address space confusion
Unified · Split
| @@ -357,20 +357,6 @@ static int amd_ntb_db_clear_mask(struct ntb_dev *ntb, u64 db_bits) · 356 unmodified lines | ||
| 357 | 357 | return 0; |
| 358 | 358 | } |
| 359 | 359 | |
| 360 | −static int amd_ntb_peer_db_addr(struct ntb_dev *ntb, | |
| 361 | − phys_addr_t *db_addr, | |
| 362 | − resource_size_t *db_size) | |
| 363 | −{ | |
| 364 | − struct amd_ntb_dev *ndev = ntb_ndev(ntb); | |
| 365 | − | |
| 366 | − if (db_addr) | |
| 367 | − *db_addr = (phys_addr_t)(ndev->peer_mmio + AMD_DBREQ_OFFSET); | |
| 368 | − if (db_size) | |
| 369 | − *db_size = sizeof(u32); | |
| 370 | − | |
| 371 | − return 0; | |
| 372 | −} | |
| 373 | − | |
| 374 | 360 | static int amd_ntb_peer_db_set(struct ntb_dev *ntb, u64 db_bits) |
| 375 | 361 | { |
| 376 | 362 | struct amd_ntb_dev *ndev = ntb_ndev(ntb); |
| @@ -415,20 +401,6 @@ static int amd_ntb_spad_write(struct ntb_dev *ntb, · 38 unmodified lines | ||
| 415 | 401 | return 0; |
| 416 | 402 | } |
| 417 | 403 | |
| 418 | −static int amd_ntb_peer_spad_addr(struct ntb_dev *ntb, int idx, | |
| 419 | − phys_addr_t *spad_addr) | |
| 420 | −{ | |
| 421 | − struct amd_ntb_dev *ndev = ntb_ndev(ntb); | |
| 422 | − | |
| 423 | − if (idx < 0 || idx >= ndev->spad_count) | |
| 424 | − return -EINVAL; | |
| 425 | − | |
| 426 | − if (spad_addr) | |
| 427 | − *spad_addr = (phys_addr_t)(ndev->self_mmio + AMD_SPAD_OFFSET + | |
| 428 | − ndev->peer_spad + (idx << 2)); | |
| 429 | − return 0; | |
| 430 | −} | |
| 431 | − | |
| 432 | 404 | static u32 amd_ntb_peer_spad_read(struct ntb_dev *ntb, int idx) |
| 433 | 405 | { |
| 434 | 406 | struct amd_ntb_dev *ndev = ntb_ndev(ntb); |
| @@ -472,12 +444,10 @@ static const struct ntb_dev_ops amd_ntb_ops = { · 37 unmodified lines | ||
| 472 | 444 | .db_clear = amd_ntb_db_clear, |
| 473 | 445 | .db_set_mask = amd_ntb_db_set_mask, |
| 474 | 446 | .db_clear_mask = amd_ntb_db_clear_mask, |
| 475 | − .peer_db_addr = amd_ntb_peer_db_addr, | |
| 476 | 447 | .peer_db_set = amd_ntb_peer_db_set, |
| 477 | 448 | .spad_count = amd_ntb_spad_count, |
| 478 | 449 | .spad_read = amd_ntb_spad_read, |
| 479 | 450 | .spad_write = amd_ntb_spad_write, |
| 480 | − .peer_spad_addr = amd_ntb_peer_spad_addr, | |
| 481 | 451 | .peer_spad_read = amd_ntb_peer_spad_read, |
| 482 | 452 | .peer_spad_write = amd_ntb_peer_spad_write, |
| 483 | 453 | }; |
| @@ -124,6 +124,7 @@ struct ntb_transport_qp { · 123 unmodified lines | ||
| 124 | 124 | |
| 125 | 125 | bool client_ready; |
| 126 | 126 | bool link_is_up; |
| 127 | + bool active; | |
| 127 | 128 | |
| 128 | 129 | u8 qp_num; /* Only 64 QP's are allowed. 0-63 */ |
| 129 | 130 | u64 qp_bit; |
| @@ -719,6 +720,7 @@ static int ntb_set_mw(struct ntb_transport_ctx *nt, int num_mw, · 589 unmodified lines | ||
| 719 | 720 | static void ntb_qp_link_down_reset(struct ntb_transport_qp *qp) |
| 720 | 721 | { |
| 721 | 722 | qp->link_is_up = false; |
| 723 | + qp->active = false; | |
| 722 | 724 | |
| 723 | 725 | qp->tx_index = 0; |
| 724 | 726 | qp->rx_index = 0; |
| @@ -827,7 +829,7 @@ static void ntb_transport_link_work(struct work_struct *work) · 102 unmodified lines | ||
| 827 | 829 | struct pci_dev *pdev = ndev->pdev; |
| 828 | 830 | resource_size_t size; |
| 829 | 831 | u32 val; |
| 830 | − int rc, i, spad; | |
| 832 | + int rc = 0, i, spad; | |
| 831 | 833 | |
| 832 | 834 | /* send the local info, in the opposite order of the way we read it */ |
| 833 | 835 | for (i = 0; i < nt->mw_count; i++) { |
| @@ -897,6 +899,13 @@ static void ntb_transport_link_work(struct work_struct *work) · 63 unmodified lines | ||
| 897 | 899 | out1: |
| 898 | 900 | for (i = 0; i < nt->mw_count; i++) |
| 899 | 901 | ntb_free_mw(nt, i); |
| 902 | + | |
| 903 | + /* if there's an actual failure, we should just bail */ | |
| 904 | + if (rc < 0) { | |
| 905 | + ntb_link_disable(ndev); | |
| 906 | + return; | |
| 907 | + } | |
| 908 | + | |
| 900 | 909 | out: |
| 901 | 910 | if (ntb_link_is_up(ndev, NULL, NULL) == 1) |
| 902 | 911 | schedule_delayed_work(&nt->link_work, |
| @@ -926,11 +935,13 @@ static void ntb_qp_link_work(struct work_struct *work) · 23 unmodified lines | ||
| 926 | 935 | if (val & BIT(qp->qp_num)) { |
| 927 | 936 | dev_info(&pdev->dev, "qp %d: Link Up\n", qp->qp_num); |
| 928 | 937 | qp->link_is_up = true; |
| 938 | + qp->active = true; | |
| 929 | 939 | |
| 930 | 940 | if (qp->event_handler) |
| 931 | 941 | qp->event_handler(qp->cb_data, qp->link_is_up); |
| 932 | 942 | |
| 933 | − tasklet_schedule(&qp->rxc_db_work); | |
| 943 | + if (qp->active) | |
| 944 | + tasklet_schedule(&qp->rxc_db_work); | |
| 934 | 945 | } else if (nt->link_is_up) |
| 935 | 946 | schedule_delayed_work(&qp->link_work, |
| 936 | 947 | msecs_to_jiffies(NTB_LINK_DOWN_TIMEOUT)); |
| @@ -1411,7 +1422,8 @@ static void ntb_transport_rxc_db(unsigned long data) · 474 unmodified lines | ||
| 1411 | 1422 | |
| 1412 | 1423 | if (i == qp->rx_max_entry) { |
| 1413 | 1424 | /* there is more work to do */ |
| 1414 | − tasklet_schedule(&qp->rxc_db_work); | |
| 1425 | + if (qp->active) | |
| 1426 | + tasklet_schedule(&qp->rxc_db_work); | |
| 1415 | 1427 | } else if (ntb_db_read(qp->ndev) & BIT_ULL(qp->qp_num)) { |
| 1416 | 1428 | /* the doorbell bit is set: clear it */ |
| 1417 | 1429 | ntb_db_clear(qp->ndev, BIT_ULL(qp->qp_num)); |
| @@ -1422,7 +1434,8 @@ static void ntb_transport_rxc_db(unsigned long data) · 4 unmodified lines | ||
| 1422 | 1434 | * ntb_process_rxc and clearing the doorbell bit: |
| 1423 | 1435 | * there might be some more work to do. |
| 1424 | 1436 | */ |
| 1425 | − tasklet_schedule(&qp->rxc_db_work); | |
| 1437 | + if (qp->active) | |
| 1438 | + tasklet_schedule(&qp->rxc_db_work); | |
| 1426 | 1439 | } |
| 1427 | 1440 | } |
| 1428 | 1441 | |
| @@ -1760,6 +1773,8 @@ void ntb_transport_free_queue(struct ntb_transport_qp *qp) · 331 unmodified lines | ||
| 1760 | 1773 | |
| 1761 | 1774 | pdev = qp->ndev->pdev; |
| 1762 | 1775 | |
| 1776 | + qp->active = false; | |
| 1777 | + | |
| 1763 | 1778 | if (qp->tx_dma_chan) { |
| 1764 | 1779 | struct dma_chan *chan = qp->tx_dma_chan; |
| 1765 | 1780 | /* Putting the dma_chan to NULL will force any new traffic to be |
| @@ -1793,7 +1808,7 @@ void ntb_transport_free_queue(struct ntb_transport_qp *qp) · 27 unmodified lines | ||
| 1793 | 1808 | qp_bit = BIT_ULL(qp->qp_num); |
| 1794 | 1809 | |
| 1795 | 1810 | ntb_db_set_mask(qp->ndev, qp_bit); |
| 1796 | − tasklet_disable(&qp->rxc_db_work); | |
| 1811 | + tasklet_kill(&qp->rxc_db_work); | |
| 1797 | 1812 | |
| 1798 | 1813 | cancel_delayed_work_sync(&qp->link_work); |
| 1799 | 1814 | |
| @@ -1886,7 +1901,8 @@ int ntb_transport_rx_enqueue(struct ntb_transport_qp *qp, void *cb, void *data, · 86 unmodified lines | ||
| 1886 | 1901 | |
| 1887 | 1902 | ntb_list_add(&qp->ntb_rx_q_lock, &entry->entry, &qp->rx_pend_q); |
| 1888 | 1903 | |
| 1889 | − tasklet_schedule(&qp->rxc_db_work); | |
| 1904 | + if (qp->active) | |
| 1905 | + tasklet_schedule(&qp->rxc_db_work); | |
| 1890 | 1906 | |
| 1891 | 1907 | return 0; |
| 1892 | 1908 | } |
| @@ -2069,7 +2085,8 @@ static void ntb_transport_doorbell_callback(void *data, int vector) · 176 unmodified lines | ||
| 2069 | 2085 | qp_num = __ffs(db_bits); |
| 2070 | 2086 | qp = &nt->qp_vec[qp_num]; |
| 2071 | 2087 | |
| 2072 | − tasklet_schedule(&qp->rxc_db_work); | |
| 2088 | + if (qp->active) | |
| 2089 | + tasklet_schedule(&qp->rxc_db_work); | |
| 2073 | 2090 | |
| 2074 | 2091 | db_bits &= ~BIT_ULL(qp_num); |
| 2075 | 2092 | } |
| @@ -178,7 +178,7 @@ static void perf_copy_callback(void *data) · 177 unmodified lines | ||
| 178 | 178 | atomic_dec(&pctx->dma_sync); |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | −static ssize_t perf_copy(struct pthr_ctx *pctx, char *dst, | |
| 181 | +static ssize_t perf_copy(struct pthr_ctx *pctx, char __iomem *dst, | |
| 182 | 182 | char *src, size_t size) |
| 183 | 183 | { |
| 184 | 184 | struct perf_ctx *perf = pctx->perf; |
| @@ -189,7 +189,8 @@ static ssize_t perf_copy(struct pthr_ctx *pctx, char *dst, · 4 unmodified lines | ||
| 189 | 189 | dma_cookie_t cookie; |
| 190 | 190 | size_t src_off, dst_off; |
| 191 | 191 | struct perf_mw *mw = &perf->mw; |
| 192 | − u64 vbase, dst_vaddr; | |
| 192 | + void __iomem *vbase; | |
| 193 | + void __iomem *dst_vaddr; | |
| 193 | 194 | dma_addr_t dst_phys; |
| 194 | 195 | int retries = 0; |
| 195 | 196 | |
| @@ -204,14 +205,14 @@ static ssize_t perf_copy(struct pthr_ctx *pctx, char *dst, · 8 unmodified lines | ||
| 204 | 205 | } |
| 205 | 206 | |
| 206 | 207 | device = chan->device; |
| 207 | − src_off = (size_t)src & ~PAGE_MASK; | |
| 208 | − dst_off = (size_t)dst & ~PAGE_MASK; | |
| 208 | + src_off = (uintptr_t)src & ~PAGE_MASK; | |
| 209 | + dst_off = (uintptr_t __force)dst & ~PAGE_MASK; | |
| 209 | 210 | |
| 210 | 211 | if (!is_dma_copy_aligned(device, src_off, dst_off, size)) |
| 211 | 212 | return -ENODEV; |
| 212 | 213 | |
| 213 | − vbase = (u64)(u64 *)mw->vbase; | |
| 214 | − dst_vaddr = (u64)(u64 *)dst; | |
| 214 | + vbase = mw->vbase; | |
| 215 | + dst_vaddr = dst; | |
| 215 | 216 | dst_phys = mw->phys_addr + (dst_vaddr - vbase); |
| 216 | 217 | |
| 217 | 218 | unmap = dmaengine_get_unmap_data(device->dev, 1, GFP_NOWAIT); |
| @@ -261,13 +262,13 @@ err_get_unmap: · 43 unmodified lines | ||
| 261 | 262 | return 0; |
| 262 | 263 | } |
| 263 | 264 | |
| 264 | −static int perf_move_data(struct pthr_ctx *pctx, char *dst, char *src, | |
| 265 | +static int perf_move_data(struct pthr_ctx *pctx, char __iomem *dst, char *src, | |
| 265 | 266 | u64 buf_size, u64 win_size, u64 total) |
| 266 | 267 | { |
| 267 | 268 | int chunks, total_chunks, i; |
| 268 | 269 | int copied_chunks = 0; |
| 269 | 270 | u64 copied = 0, result; |
| 270 | − char *tmp = dst; | |
| 271 | + char __iomem *tmp = dst; | |
| 271 | 272 | u64 perf, diff_us; |
| 272 | 273 | ktime_t kstart, kstop, kdiff; |
| 273 | 274 | |
| @@ -324,7 +325,7 @@ static int ntb_perf_thread(void *data) · 50 unmodified lines | ||
| 324 | 325 | struct perf_ctx *perf = pctx->perf; |
| 325 | 326 | struct pci_dev *pdev = perf->ntb->pdev; |
| 326 | 327 | struct perf_mw *mw = &perf->mw; |
| 327 | − char *dst; | |
| 328 | + char __iomem *dst; | |
| 328 | 329 | u64 win_size, buf_size, total; |
| 329 | 330 | void *src; |
| 330 | 331 | int rc, node, i; |
| @@ -364,7 +365,7 @@ static int ntb_perf_thread(void *data) · 33 unmodified lines | ||
| 364 | 365 | if (buf_size > MAX_TEST_SIZE) |
| 365 | 366 | buf_size = MAX_TEST_SIZE; |
| 366 | 367 | |
| 367 | − dst = (char *)mw->vbase; | |
| 368 | + dst = (char __iomem *)mw->vbase; | |
| 368 | 369 | |
| 369 | 370 | atomic_inc(&perf->tsync); |
| 370 | 371 | while (atomic_read(&perf->tsync) != perf->perf_threads) |
| @@ -424,6 +425,7 @@ static int perf_set_mw(struct perf_ctx *perf, resource_size_t size) · 53 unmodified lines | ||
| 424 | 425 | { |
| 425 | 426 | struct perf_mw *mw = &perf->mw; |
| 426 | 427 | size_t xlat_size, buf_size; |
| 428 | + int rc; | |
| 427 | 429 | |
| 428 | 430 | if (!size) |
| 429 | 431 | return -EINVAL; |
| @@ -447,6 +449,13 @@ static int perf_set_mw(struct perf_ctx *perf, resource_size_t size) · 17 unmodified lines | ||
| 447 | 449 | mw->buf_size = 0; |
| 448 | 450 | } |
| 449 | 451 | |
| 452 | + rc = ntb_mw_set_trans(perf->ntb, 0, mw->dma_addr, mw->xlat_size); | |
| 453 | + if (rc) { | |
| 454 | + dev_err(&perf->ntb->dev, "Unable to set mw0 translation\n"); | |
| 455 | + perf_free_mw(perf); | |
| 456 | + return -EIO; | |
| 457 | + } | |
| 458 | + | |
| 450 | 459 | return 0; |
| 451 | 460 | } |
| 452 | 461 | |
| @@ -541,6 +550,8 @@ static ssize_t debugfs_run_read(struct file *filp, char __user *ubuf, · 88 unmodified lines | ||
| 541 | 550 | return 0; |
| 542 | 551 | |
| 543 | 552 | buf = kmalloc(64, GFP_KERNEL); |
| 553 | + if (!buf) | |
| 554 | + return -ENOMEM; | |
| 544 | 555 | out_offset = snprintf(buf, 64, "%d\n", perf->run); |
| 545 | 556 | ret = simple_read_from_buffer(ubuf, count, offp, buf, out_offset); |
| 546 | 557 | kfree(buf); |
| @@ -548,6 +559,21 @@ static ssize_t debugfs_run_read(struct file *filp, char __user *ubuf, · 1 unmodified line | ||
| 548 | 559 | return ret; |
| 549 | 560 | } |
| 550 | 561 | |
| 562 | +static void threads_cleanup(struct perf_ctx *perf) | |
| 563 | +{ | |
| 564 | + struct pthr_ctx *pctx; | |
| 565 | + int i; | |
| 566 | + | |
| 567 | + perf->run = false; | |
| 568 | + for (i = 0; i < MAX_THREADS; i++) { | |
| 569 | + pctx = &perf->pthr_ctx[i]; | |
| 570 | + if (pctx->thread) { | |
| 571 | + kthread_stop(pctx->thread); | |
| 572 | + pctx->thread = NULL; | |
| 573 | + } | |
| 574 | + } | |
| 575 | +} | |
| 576 | + | |
| 551 | 577 | static ssize_t debugfs_run_write(struct file *filp, const char __user *ubuf, |
| 552 | 578 | size_t count, loff_t *offp) |
| 553 | 579 | { |
| @@ -563,17 +589,9 @@ static ssize_t debugfs_run_write(struct file *filp, const char __user *ubuf, · 9 unmodified lines | ||
| 563 | 589 | if (atomic_read(&perf->tsync) == 0) |
| 564 | 590 | perf->run = false; |
| 565 | 591 | |
| 566 | − if (perf->run) { | |
| 567 | − /* lets stop the threads */ | |
| 568 | − perf->run = false; | |
| 569 | − for (i = 0; i < MAX_THREADS; i++) { | |
| 570 | − if (perf->pthr_ctx[i].thread) { | |
| 571 | − kthread_stop(perf->pthr_ctx[i].thread); | |
| 572 | − perf->pthr_ctx[i].thread = NULL; | |
| 573 | − } else | |
| 574 | − break; | |
| 575 | − } | |
| 576 | − } else { | |
| 592 | + if (perf->run) | |
| 593 | + threads_cleanup(perf); | |
| 594 | + else { | |
| 577 | 595 | perf->run = true; |
| 578 | 596 | |
| 579 | 597 | if (perf->perf_threads > MAX_THREADS) { |
| @@ -604,17 +622,11 @@ static ssize_t debugfs_run_write(struct file *filp, const char __user *ubuf, · 24 unmodified lines | ||
| 604 | 622 | kthread_create_on_node(ntb_perf_thread, |
| 605 | 623 | (void *)pctx, |
| 606 | 624 | node, "ntb_perf %d", i); |
| 607 | − if (pctx->thread) | |
| 625 | + if (IS_ERR(pctx->thread)) { | |
| 626 | + pctx->thread = NULL; | |
| 627 | + goto err; | |
| 628 | + } else | |
| 608 | 629 | wake_up_process(pctx->thread); |
| 609 | − else { | |
| 610 | − perf->run = false; | |
| 611 | − for (i = 0; i < MAX_THREADS; i++) { | |
| 612 | − if (pctx->thread) { | |
| 613 | − kthread_stop(pctx->thread); | |
| 614 | − pctx->thread = NULL; | |
| 615 | − } | |
| 616 | − } | |
| 617 | − } | |
| 618 | 630 | |
| 619 | 631 | if (perf->run == false) |
| 620 | 632 | return -ENXIO; |
| @@ -623,6 +635,10 @@ static ssize_t debugfs_run_write(struct file *filp, const char __user *ubuf, · 2 unmodified lines | ||
| 623 | 635 | } |
| 624 | 636 | |
| 625 | 637 | return count; |
| 638 | + | |
| 639 | +err: | |
| 640 | + threads_cleanup(perf); | |
| 641 | + return -ENXIO; | |
| 626 | 642 | } |
| 627 | 643 | |
| 628 | 644 | static const struct file_operations ntb_perf_debugfs_run = { |
| @@ -284,7 +284,7 @@ static inline int ntb_dev_ops_is_valid(const struct ntb_dev_ops *ops) · 283 unmodified lines | ||
| 284 | 284 | /* ops->db_read_mask && */ |
| 285 | 285 | ops->db_set_mask && |
| 286 | 286 | ops->db_clear_mask && |
| 287 | − ops->peer_db_addr && | |
| 287 | + /* ops->peer_db_addr && */ | |
| 288 | 288 | /* ops->peer_db_read && */ |
| 289 | 289 | ops->peer_db_set && |
| 290 | 290 | /* ops->peer_db_clear && */ |
| @@ -295,7 +295,7 @@ static inline int ntb_dev_ops_is_valid(const struct ntb_dev_ops *ops) · 4 unmodified lines | ||
| 295 | 295 | ops->spad_count && |
| 296 | 296 | ops->spad_read && |
| 297 | 297 | ops->spad_write && |
| 298 | − ops->peer_spad_addr && | |
| 298 | + /* ops->peer_spad_addr && */ | |
| 299 | 299 | /* ops->peer_spad_read && */ |
| 300 | 300 | ops->peer_spad_write && |
| 301 | 301 | 1; |
| @@ -757,6 +757,9 @@ static inline int ntb_peer_db_addr(struct ntb_dev *ntb, · 455 unmodified lines | ||
| 757 | 757 | phys_addr_t *db_addr, |
| 758 | 758 | resource_size_t *db_size) |
| 759 | 759 | { |
| 760 | + if (!ntb->ops->peer_db_addr) | |
| 761 | + return -EINVAL; | |
| 762 | + | |
| 760 | 763 | return ntb->ops->peer_db_addr(ntb, db_addr, db_size); |
| 761 | 764 | } |
| 762 | 765 | |
| @@ -948,6 +951,9 @@ static inline int ntb_spad_write(struct ntb_dev *ntb, int idx, u32 val) · 185 unmodified lines | ||
| 948 | 951 | static inline int ntb_peer_spad_addr(struct ntb_dev *ntb, int idx, |
| 949 | 952 | phys_addr_t *spad_addr) |
| 950 | 953 | { |
| 954 | + if (!ntb->ops->peer_spad_addr) | |
| 955 | + return -EINVAL; | |
| 956 | + | |
| 951 | 957 | return ntb->ops->peer_spad_addr(ntb, idx, spad_addr); |
| 952 | 958 | } |
| 953 | 959 | |