Re: [PATCH] ntb: perf test: fix address space confusion
From: Jiang, Dave
Date: Tue Jan 26 2016 - 13:20:21 EST
On Tue, 2016-01-26 at 10:31 +0100, Arnd Bergmann wrote:
> The ntb driver assigns between pointers an __iomem tokens, and
> also casts them to 64-bit integers, which results in compiler
> warnings on 32-bit systems:
>
> drivers/ntb/test/ntb_perf.c: In function 'perf_copy':
> drivers/ntb/test/ntb_perf.c:213:10: error: cast from pointer to
> integer of different size [-Werror=pointer-to-int-cast]
> Â vbase = (u64)(u64 *)mw->vbase;
> ÂÂÂÂÂÂÂÂÂÂ^
> drivers/ntb/test/ntb_perf.c:214:14: error: cast from pointer to
> integer of different size [-Werror=pointer-to-int-cast]
> Â dst_vaddr = (u64)(u64 *)dst;
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ^
>
> This adds __iomem annotations where needed and changes the temporary
> variables to iomem pointers to avoid casting them to u64. I did not
> see the problem in linux-next earlier, but it show showed up in
> 4.5-rc1.
>
> Signed-off-by: Arnd Bergmann <arnd@xxxxxxxx>
Acked-by: Dave Jiang <dave.jiang@xxxxxxxxx>
> Fixes: 8a7b6a778a85 ("ntb: ntb perf tool")
> ---
> Âdrivers/ntb/test/ntb_perf.c | 21 +++++++++++----------
> Â1 file changed, 11 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/ntb/test/ntb_perf.c
> b/drivers/ntb/test/ntb_perf.c
> index c8a37ba4b4f9..6bdc1e7b7503 100644
> --- a/drivers/ntb/test/ntb_perf.c
> +++ b/drivers/ntb/test/ntb_perf.c
> @@ -178,7 +178,7 @@ static void perf_copy_callback(void *data)
> Â atomic_dec(&pctx->dma_sync);
> Â}
> Â
> -static ssize_t perf_copy(struct pthr_ctx *pctx, char *dst,
> +static ssize_t perf_copy(struct pthr_ctx *pctx, char __iomem *dst,
> Â Âchar *src, size_t size)
> Â{
> Â struct perf_ctx *perf = pctx->perf;
> @@ -189,7 +189,8 @@ static ssize_t perf_copy(struct pthr_ctx *pctx,
> char *dst,
> Â dma_cookie_t cookie;
> Â size_t src_off, dst_off;
> Â struct perf_mw *mw = &perf->mw;
> - u64 vbase, dst_vaddr;
> + void __iomem *vbase;
> + void __iomem *dst_vaddr;
> Â dma_addr_t dst_phys;
> Â int retries = 0;
> Â
> @@ -204,14 +205,14 @@ static ssize_t perf_copy(struct pthr_ctx *pctx,
> char *dst,
> Â }
> Â
> Â device = chan->device;
> - src_off = (size_t)src & ~PAGE_MASK;
> - dst_off = (size_t)dst & ~PAGE_MASK;
> + src_off = (uintptr_t)src & ~PAGE_MASK;
> + dst_off = (uintptr_t __force)dst & ~PAGE_MASK;
> Â
> Â if (!is_dma_copy_aligned(device, src_off, dst_off, size))
> Â return -ENODEV;
> Â
> - vbase = (u64)(u64 *)mw->vbase;
> - dst_vaddr = (u64)(u64 *)dst;
> + vbase = mw->vbase;
> + dst_vaddr = dst;
> Â dst_phys = mw->phys_addr + (dst_vaddr - vbase);
> Â
> Â unmap = dmaengine_get_unmap_data(device->dev, 1,
> GFP_NOWAIT);
> @@ -261,13 +262,13 @@ err_get_unmap:
> Â return 0;
> Â}
> Â
> -static int perf_move_data(struct pthr_ctx *pctx, char *dst, char
> *src,
> +static int perf_move_data(struct pthr_ctx *pctx, char __iomem *dst,
> char *src,
> Â ÂÂu64 buf_size, u64 win_size, u64 total)
> Â{
> Â int chunks, total_chunks, i;
> Â int copied_chunks = 0;
> Â u64 copied = 0, result;
> - char *tmp = dst;
> + char __iomem *tmp = dst;
> Â u64 perf, diff_us;
> Â ktime_t kstart, kstop, kdiff;
> Â
> @@ -324,7 +325,7 @@ static int ntb_perf_thread(void *data)
> Â struct perf_ctx *perf = pctx->perf;
> Â struct pci_dev *pdev = perf->ntb->pdev;
> Â struct perf_mw *mw = &perf->mw;
> - char *dst;
> + char __iomem *dst;
> Â u64 win_size, buf_size, total;
> Â void *src;
> Â int rc, node, i;
> @@ -364,7 +365,7 @@ static int ntb_perf_thread(void *data)
> Â if (buf_size > MAX_TEST_SIZE)
> Â buf_size = MAX_TEST_SIZE;
> Â
> - dst = (char *)mw->vbase;
> + dst = (char __iomem *)mw->vbase;
> Â
> Â atomic_inc(&perf->tsync);
> Â while (atomic_read(&perf->tsync) != perf->perf_threads)