History

Merge tag 'ntb-4.6' of git://github.com/jonmason/ntb

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

Linus Torvalds committed 10 years ago

Commit b4cec5f2 parents 895a106 4f1b50c4 files · +79 −70Browse files

Unified · Split

4 files
  1. drivers/ntb/hw/amd/ntb_hw_amd.c +0 −30
  2. drivers/ntb/ntb_transport.c +24 −7
  3. drivers/ntb/test/ntb_perf.c +47 −31
  4. include/linux/ntb.h +8 −2
drivers/ntb/hw/amd/ntb_hw_amd.c+0−30
@@ -357,20 +357,6 @@ static int amd_ntb_db_clear_mask(struct ntb_dev *ntb, u64 db_bits) · 356 unmodified lines
357 return 0;357 return 0;
358}358}
359 359
360static 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
374static int amd_ntb_peer_db_set(struct ntb_dev *ntb, u64 db_bits)360static int amd_ntb_peer_db_set(struct ntb_dev *ntb, u64 db_bits)
375{361{
376 struct amd_ntb_dev *ndev = ntb_ndev(ntb);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 return 0;401 return 0;
416}402}
417 403
418static 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
432static u32 amd_ntb_peer_spad_read(struct ntb_dev *ntb, int idx)404static u32 amd_ntb_peer_spad_read(struct ntb_dev *ntb, int idx)
433{405{
434 struct amd_ntb_dev *ndev = ntb_ndev(ntb);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 .db_clear = amd_ntb_db_clear,444 .db_clear = amd_ntb_db_clear,
473 .db_set_mask = amd_ntb_db_set_mask,445 .db_set_mask = amd_ntb_db_set_mask,
474 .db_clear_mask = amd_ntb_db_clear_mask,446 .db_clear_mask = amd_ntb_db_clear_mask,
475 .peer_db_addr = amd_ntb_peer_db_addr,
476 .peer_db_set = amd_ntb_peer_db_set,447 .peer_db_set = amd_ntb_peer_db_set,
477 .spad_count = amd_ntb_spad_count,448 .spad_count = amd_ntb_spad_count,
478 .spad_read = amd_ntb_spad_read,449 .spad_read = amd_ntb_spad_read,
479 .spad_write = amd_ntb_spad_write,450 .spad_write = amd_ntb_spad_write,
480 .peer_spad_addr = amd_ntb_peer_spad_addr,
481 .peer_spad_read = amd_ntb_peer_spad_read,451 .peer_spad_read = amd_ntb_peer_spad_read,
482 .peer_spad_write = amd_ntb_peer_spad_write,452 .peer_spad_write = amd_ntb_peer_spad_write,
483};453};
drivers/ntb/ntb_transport.c+24−7
@@ -124,6 +124,7 @@ struct ntb_transport_qp { · 123 unmodified lines
124 124
125 bool client_ready;125 bool client_ready;
126 bool link_is_up;126 bool link_is_up;
127 bool active;
127 128
128 u8 qp_num; /* Only 64 QP's are allowed. 0-63 */129 u8 qp_num; /* Only 64 QP's are allowed. 0-63 */
129 u64 qp_bit;130 u64 qp_bit;
@@ -719,6 +720,7 @@ static int ntb_set_mw(struct ntb_transport_ctx *nt, int num_mw, · 589 unmodified lines
719static void ntb_qp_link_down_reset(struct ntb_transport_qp *qp)720static void ntb_qp_link_down_reset(struct ntb_transport_qp *qp)
720{721{
721 qp->link_is_up = false;722 qp->link_is_up = false;
723 qp->active = false;
722 724
723 qp->tx_index = 0;725 qp->tx_index = 0;
724 qp->rx_index = 0;726 qp->rx_index = 0;
@@ -827,7 +829,7 @@ static void ntb_transport_link_work(struct work_struct *work) · 102 unmodified lines
827 struct pci_dev *pdev = ndev->pdev;829 struct pci_dev *pdev = ndev->pdev;
828 resource_size_t size;830 resource_size_t size;
829 u32 val;831 u32 val;
830 int rc, i, spad;832 int rc = 0, i, spad;
831 833
832 /* send the local info, in the opposite order of the way we read it */834 /* send the local info, in the opposite order of the way we read it */
833 for (i = 0; i < nt->mw_count; i++) {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
897out1:899out1:
898 for (i = 0; i < nt->mw_count; i++)900 for (i = 0; i < nt->mw_count; i++)
899 ntb_free_mw(nt, i);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
900out:909out:
901 if (ntb_link_is_up(ndev, NULL, NULL) == 1)910 if (ntb_link_is_up(ndev, NULL, NULL) == 1)
902 schedule_delayed_work(&nt->link_work,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 if (val & BIT(qp->qp_num)) {935 if (val & BIT(qp->qp_num)) {
927 dev_info(&pdev->dev, "qp %d: Link Up\n", qp->qp_num);936 dev_info(&pdev->dev, "qp %d: Link Up\n", qp->qp_num);
928 qp->link_is_up = true;937 qp->link_is_up = true;
938 qp->active = true;
929 939
930 if (qp->event_handler)940 if (qp->event_handler)
931 qp->event_handler(qp->cb_data, qp->link_is_up);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 } else if (nt->link_is_up)945 } else if (nt->link_is_up)
935 schedule_delayed_work(&qp->link_work,946 schedule_delayed_work(&qp->link_work,
936 msecs_to_jiffies(NTB_LINK_DOWN_TIMEOUT));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 if (i == qp->rx_max_entry) {1423 if (i == qp->rx_max_entry) {
1413 /* there is more work to do */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 } else if (ntb_db_read(qp->ndev) & BIT_ULL(qp->qp_num)) {1427 } else if (ntb_db_read(qp->ndev) & BIT_ULL(qp->qp_num)) {
1416 /* the doorbell bit is set: clear it */1428 /* the doorbell bit is set: clear it */
1417 ntb_db_clear(qp->ndev, BIT_ULL(qp->qp_num));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 * ntb_process_rxc and clearing the doorbell bit:1434 * ntb_process_rxc and clearing the doorbell bit:
1423 * there might be some more work to do.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 pdev = qp->ndev->pdev;1774 pdev = qp->ndev->pdev;
1762 1775
1776 qp->active = false;
1777
1763 if (qp->tx_dma_chan) {1778 if (qp->tx_dma_chan) {
1764 struct dma_chan *chan = qp->tx_dma_chan;1779 struct dma_chan *chan = qp->tx_dma_chan;
1765 /* Putting the dma_chan to NULL will force any new traffic to be1780 /* 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 qp_bit = BIT_ULL(qp->qp_num);1808 qp_bit = BIT_ULL(qp->qp_num);
1794 1809
1795 ntb_db_set_mask(qp->ndev, qp_bit);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 cancel_delayed_work_sync(&qp->link_work);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 ntb_list_add(&qp->ntb_rx_q_lock, &entry->entry, &qp->rx_pend_q);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 return 0;1907 return 0;
1892}1908}
@@ -2069,7 +2085,8 @@ static void ntb_transport_doorbell_callback(void *data, int vector) · 176 unmodified lines
2069 qp_num = __ffs(db_bits);2085 qp_num = __ffs(db_bits);
2070 qp = &nt->qp_vec[qp_num];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 db_bits &= ~BIT_ULL(qp_num);2091 db_bits &= ~BIT_ULL(qp_num);
2075 }2092 }
drivers/ntb/test/ntb_perf.c+47−31
@@ -178,7 +178,7 @@ static void perf_copy_callback(void *data) · 177 unmodified lines
178 atomic_dec(&pctx->dma_sync);178 atomic_dec(&pctx->dma_sync);
179}179}
180 180
181static ssize_t perf_copy(struct pthr_ctx *pctx, char *dst,181static ssize_t perf_copy(struct pthr_ctx *pctx, char __iomem *dst,
182 char *src, size_t size)182 char *src, size_t size)
183{183{
184 struct perf_ctx *perf = pctx->perf;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 dma_cookie_t cookie;189 dma_cookie_t cookie;
190 size_t src_off, dst_off;190 size_t src_off, dst_off;
191 struct perf_mw *mw = &perf->mw;191 struct perf_mw *mw = &perf->mw;
192 u64 vbase, dst_vaddr;192 void __iomem *vbase;
193 void __iomem *dst_vaddr;
193 dma_addr_t dst_phys;194 dma_addr_t dst_phys;
194 int retries = 0;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 device = chan->device;207 device = chan->device;
207 src_off = (size_t)src & ~PAGE_MASK;208 src_off = (uintptr_t)src & ~PAGE_MASK;
208 dst_off = (size_t)dst & ~PAGE_MASK;209 dst_off = (uintptr_t __force)dst & ~PAGE_MASK;
209 210
210 if (!is_dma_copy_aligned(device, src_off, dst_off, size))211 if (!is_dma_copy_aligned(device, src_off, dst_off, size))
211 return -ENODEV;212 return -ENODEV;
212 213
213 vbase = (u64)(u64 *)mw->vbase;214 vbase = mw->vbase;
214 dst_vaddr = (u64)(u64 *)dst;215 dst_vaddr = dst;
215 dst_phys = mw->phys_addr + (dst_vaddr - vbase);216 dst_phys = mw->phys_addr + (dst_vaddr - vbase);
216 217
217 unmap = dmaengine_get_unmap_data(device->dev, 1, GFP_NOWAIT);218 unmap = dmaengine_get_unmap_data(device->dev, 1, GFP_NOWAIT);
@@ -261,13 +262,13 @@ err_get_unmap: · 43 unmodified lines
261 return 0;262 return 0;
262}263}
263 264
264static int perf_move_data(struct pthr_ctx *pctx, char *dst, char *src,265static int perf_move_data(struct pthr_ctx *pctx, char __iomem *dst, char *src,
265 u64 buf_size, u64 win_size, u64 total)266 u64 buf_size, u64 win_size, u64 total)
266{267{
267 int chunks, total_chunks, i;268 int chunks, total_chunks, i;
268 int copied_chunks = 0;269 int copied_chunks = 0;
269 u64 copied = 0, result;270 u64 copied = 0, result;
270 char *tmp = dst;271 char __iomem *tmp = dst;
271 u64 perf, diff_us;272 u64 perf, diff_us;
272 ktime_t kstart, kstop, kdiff;273 ktime_t kstart, kstop, kdiff;
273 274
@@ -324,7 +325,7 @@ static int ntb_perf_thread(void *data) · 50 unmodified lines
324 struct perf_ctx *perf = pctx->perf;325 struct perf_ctx *perf = pctx->perf;
325 struct pci_dev *pdev = perf->ntb->pdev;326 struct pci_dev *pdev = perf->ntb->pdev;
326 struct perf_mw *mw = &perf->mw;327 struct perf_mw *mw = &perf->mw;
327 char *dst;328 char __iomem *dst;
328 u64 win_size, buf_size, total;329 u64 win_size, buf_size, total;
329 void *src;330 void *src;
330 int rc, node, i;331 int rc, node, i;
@@ -364,7 +365,7 @@ static int ntb_perf_thread(void *data) · 33 unmodified lines
364 if (buf_size > MAX_TEST_SIZE)365 if (buf_size > MAX_TEST_SIZE)
365 buf_size = MAX_TEST_SIZE;366 buf_size = MAX_TEST_SIZE;
366 367
367 dst = (char *)mw->vbase;368 dst = (char __iomem *)mw->vbase;
368 369
369 atomic_inc(&perf->tsync);370 atomic_inc(&perf->tsync);
370 while (atomic_read(&perf->tsync) != perf->perf_threads)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 struct perf_mw *mw = &perf->mw;426 struct perf_mw *mw = &perf->mw;
426 size_t xlat_size, buf_size;427 size_t xlat_size, buf_size;
428 int rc;
427 429
428 if (!size)430 if (!size)
429 return -EINVAL;431 return -EINVAL;
@@ -447,6 +449,13 @@ static int perf_set_mw(struct perf_ctx *perf, resource_size_t size) · 17 unmodified lines
447 mw->buf_size = 0;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 return 0;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 return 0;550 return 0;
542 551
543 buf = kmalloc(64, GFP_KERNEL);552 buf = kmalloc(64, GFP_KERNEL);
553 if (!buf)
554 return -ENOMEM;
544 out_offset = snprintf(buf, 64, "%d\n", perf->run);555 out_offset = snprintf(buf, 64, "%d\n", perf->run);
545 ret = simple_read_from_buffer(ubuf, count, offp, buf, out_offset);556 ret = simple_read_from_buffer(ubuf, count, offp, buf, out_offset);
546 kfree(buf);557 kfree(buf);
@@ -548,6 +559,21 @@ static ssize_t debugfs_run_read(struct file *filp, char __user *ubuf, · 1 unmodified line
548 return ret;559 return ret;
549}560}
550 561
562static 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
551static ssize_t debugfs_run_write(struct file *filp, const char __user *ubuf,577static ssize_t debugfs_run_write(struct file *filp, const char __user *ubuf,
552 size_t count, loff_t *offp)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 if (atomic_read(&perf->tsync) == 0)589 if (atomic_read(&perf->tsync) == 0)
564 perf->run = false;590 perf->run = false;
565 591
566 if (perf->run) {592 if (perf->run)
567 /* lets stop the threads */593 threads_cleanup(perf);
568 perf->run = false;594 else {
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 {
577 perf->run = true;595 perf->run = true;
578 596
579 if (perf->perf_threads > MAX_THREADS) {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 kthread_create_on_node(ntb_perf_thread,622 kthread_create_on_node(ntb_perf_thread,
605 (void *)pctx,623 (void *)pctx,
606 node, "ntb_perf %d", i);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 wake_up_process(pctx->thread);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 if (perf->run == false)631 if (perf->run == false)
620 return -ENXIO;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 return count;637 return count;
638
639err:
640 threads_cleanup(perf);
641 return -ENXIO;
626}642}
627 643
628static const struct file_operations ntb_perf_debugfs_run = {644static const struct file_operations ntb_perf_debugfs_run = {
include/linux/ntb.h+8−2
@@ -284,7 +284,7 @@ static inline int ntb_dev_ops_is_valid(const struct ntb_dev_ops *ops) · 283 unmodified lines
284 /* ops->db_read_mask && */284 /* ops->db_read_mask && */
285 ops->db_set_mask &&285 ops->db_set_mask &&
286 ops->db_clear_mask &&286 ops->db_clear_mask &&
287 ops->peer_db_addr &&287 /* ops->peer_db_addr && */
288 /* ops->peer_db_read && */288 /* ops->peer_db_read && */
289 ops->peer_db_set &&289 ops->peer_db_set &&
290 /* ops->peer_db_clear && */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 ops->spad_count &&295 ops->spad_count &&
296 ops->spad_read &&296 ops->spad_read &&
297 ops->spad_write &&297 ops->spad_write &&
298 ops->peer_spad_addr &&298 /* ops->peer_spad_addr && */
299 /* ops->peer_spad_read && */299 /* ops->peer_spad_read && */
300 ops->peer_spad_write &&300 ops->peer_spad_write &&
301 1;301 1;
@@ -757,6 +757,9 @@ static inline int ntb_peer_db_addr(struct ntb_dev *ntb, · 455 unmodified lines
757 phys_addr_t *db_addr,757 phys_addr_t *db_addr,
758 resource_size_t *db_size)758 resource_size_t *db_size)
759{759{
760 if (!ntb->ops->peer_db_addr)
761 return -EINVAL;
762
760 return ntb->ops->peer_db_addr(ntb, db_addr, db_size);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
948static inline int ntb_peer_spad_addr(struct ntb_dev *ntb, int idx,951static inline int ntb_peer_spad_addr(struct ntb_dev *ntb, int idx,
949 phys_addr_t *spad_addr)952 phys_addr_t *spad_addr)
950{953{
954 if (!ntb->ops->peer_spad_addr)
955 return -EINVAL;
956
951 return ntb->ops->peer_spad_addr(ntb, idx, spad_addr);957 return ntb->ops->peer_spad_addr(ntb, idx, spad_addr);
952}958}
953 959

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