From 3b5363c5335d9d155aa64366a06576d303da1781 Mon Sep 17 00:00:00 2001 From: Balazs Gerofi Date: Thu, 17 Aug 2017 14:07:59 +0900 Subject: [PATCH] HFI1: use original length calculation in sdma_send_pkts() Conflicts: kernel/include/hfi1/sdma.h --- kernel/include/hfi1/sdma.h | 24 +++++++++++++-- kernel/user_sdma.c | 60 ++++++++++---------------------------- 2 files changed, 37 insertions(+), 47 deletions(-) diff --git a/kernel/include/hfi1/sdma.h b/kernel/include/hfi1/sdma.h index 7dbe9f87..4fc54389 100644 --- a/kernel/include/hfi1/sdma.h +++ b/kernel/include/hfi1/sdma.h @@ -736,7 +736,6 @@ static inline int _sdma_txadd_daddr( return rval; } -#ifdef __HFI1_ORIG__ /** * sdma_txadd_page() - add a page to the sdma_txreq * @dd: the device to use for mapping @@ -756,12 +755,18 @@ static inline int _sdma_txadd_daddr( static inline int sdma_txadd_page( struct hfi1_devdata *dd, struct sdma_txreq *tx, +#ifdef __HFI1_ORIG__ struct page *page, unsigned long offset, +#else + void *virt, +#endif u16 len) { dma_addr_t addr; int rval; +#ifdef __HFI1_ORIG__ + /* TODO: check this coealesce thing */ hfi1_cdbg(AIOWRITE, "+"); if ((unlikely(tx->num_desc == tx->desc_limit))) { rval = ext_coal_sdma_tx_descs(dd, tx, SDMA_MAP_PAGE, @@ -783,10 +788,25 @@ static inline int sdma_txadd_page( } hfi1_cdbg(AIOWRITE, "-"); +#else + if (ihk_mc_pt_virt_to_phys( + cpu_local_var(current)->vm->address_space->page_table, + virt, &addr) < 0) { + /* TODO: shall we make this function fail? * + * Handle this error. */ + kprintf("%s: ERROR: virt_to_phys failed - virt = 0x%lx\n", + __FUNCTION__, virt); + return -EFAULT; + } +#endif + /* + * XXX: It seems that this is the place where the reference to + * the payload is added, but addr is kernel virtual here. + * TODO: verify this by printing it out in Linux. + */ return _sdma_txadd_daddr( dd, SDMA_MAP_PAGE, tx, addr, len); } -#endif /* __HFI1_ORIG__ */ /** * sdma_txadd_daddr() - add a dma address to the sdma_txreq diff --git a/kernel/user_sdma.c b/kernel/user_sdma.c index e456a029..aa82f7c3 100644 --- a/kernel/user_sdma.c +++ b/kernel/user_sdma.c @@ -1130,7 +1130,8 @@ static int user_sdma_send_pkts(struct user_sdma_request *req, unsigned maxpkts) while (npkts < maxpkts) { u32 datalen = 0, queued = 0, data_sent = 0; - //u64 iov_offset = 0; + unsigned long base_phys; + u64 iov_offset = 0; //TODO: enable test_bit #ifdef __HFI1_ORIG__ @@ -1275,76 +1276,47 @@ static int user_sdma_send_pkts(struct user_sdma_request *req, unsigned maxpkts) TP("+ If the request contains any data vectors, add up to fragsize bytes to the descriptor."); while (queued < datalen && (req->sent + data_sent) < req->data_len) { -#ifdef __HFI1_ORIG__ unsigned pageidx, len; unsigned long base, offset; + const void *virt; base = (unsigned long)iovec->iov.iov_base; offset = offset_in_page(base + iovec->offset + iov_offset); + virt = base + iovec->offset + iov_offset; pageidx = (((iovec->offset + iov_offset + base) - (base & PAGE_MASK)) >> PAGE_SHIFT); len = offset + req->info.fragsize > PAGE_SIZE ? PAGE_SIZE - offset : req->info.fragsize; len = min((datalen - queued), len); + SDMA_DBG("%s: dl: %d, qd: %d, len: %d\n", + __FUNCTION__, datalen, queued, len); ret = sdma_txadd_page(pq->dd, &tx->txreq, - iovec->pages[pageidx], - offset, len); +#ifdef __HFI1_ORIG__ + iovec->pages[pageidx], offset, #else - struct sdma_txreq *txreq = &tx->txreq; - if ((unlikely(txreq->num_desc == txreq->desc_limit))) { - kprintf("%s: ERROR: ext_coal_sdma_tx_descs() should have been called here\n", - __FUNCTION__); - } - unsigned long base; - const void *virt = (unsigned long)iovec->iov.iov_base + iovec->offset; - WARN_ON(iovec->iov.iov_len < iovec->offset); - unsigned len = (unsigned)iovec->iov.iov_len - iovec->offset; - len = min(((unsigned long)virt & PAGE_MASK) - + PAGE_SIZE - (unsigned long)virt, len); - len = min(req->info.fragsize, len); - len = min(txreq->tlen, len); - len = min((datalen - queued), len); - if (len) { - if (ihk_mc_pt_virt_to_phys(cpu_local_var(current)->vm->address_space->page_table, virt, &base) < 0) { - /* TODO: shall we make this function fail? * - * Handle this error. */ - kprintf("%s: ERROR: virt_to_phys failed - virt = 0x%lx, iovec->iov.iov_base = 0x%lx\n", - __FUNCTION__, virt, iovec->iov.iov_base); - return 0; - } - ret = _sdma_txadd_daddr(pq->dd, SDMA_MAP_PAGE, txreq, base, len); - if (ret) { - kprintf("%s: ERROR _sdma_txadd_daddr()", __FUNCTION__); - return 0; - } - else { - //kprintf("%s: txadd: base = 0x%lx, len = %d\n", __FUNCTION__, base, len); - } - } - TP("- custom sdma_txadd_page"); -#endif /* __HFI1_ORIG__ */ + virt, +#endif + len); if (ret) { SDMA_DBG(req, "SDMA txreq add page failed %d\n", ret); goto free_txreq; } -#ifdef __HFI1_ORIG__ iov_offset += len; -#else - iovec->offset += len; -#endif /* __HFI1_ORIG__ */ queued += len; data_sent += len; -#ifdef __HFI1_ORIG__ if (unlikely(queued < datalen && +#ifdef __HFI1_ORIG__ pageidx == iovec->npages && +#else + iov_offset == iovec->iov.iov_len && +#endif /* __HFI1_ORIG__ */ req->iov_idx < req->data_iovs - 1)) { iovec->offset += iov_offset; iovec = &req->iovs[++req->iov_idx]; iov_offset = 0; } -#endif /* __HFI1_ORIG__ */ } TP("- If the request contains any data vectors, add up to fragsize bytes to the descriptor."); /* @@ -1355,10 +1327,8 @@ static int user_sdma_send_pkts(struct user_sdma_request *req, unsigned maxpkts) if (req_opcode(req->info.ctrl) == EXPECTED) req->tidoffset += datalen; req->sent += data_sent; -#ifdef __HFI1_ORIG__ if (req->data_len) iovec->offset += iov_offset; -#endif /* __HFI1_ORIG__ */ list_add_tail(&tx->txreq.list, &req->txps); /* * It is important to increment this here as it is used to