Skip to content

Commit 53d9f7e

Browse files
linuswthangqn-ampere
authored andcommitted
RDMA/siw: Pass a pointer to virt_to_page()
[ Upstream commit 0d1b756 ] Functions that work on a pointer to virtual memory such as virt_to_pfn() and users of that function such as virt_to_page() are supposed to pass a pointer to virtual memory, ideally a (void *) or other pointer. However since many architectures implement virt_to_pfn() as a macro, this function becomes polymorphic and accepts both a (unsigned long) and a (void *). If we instead implement a proper virt_to_pfn(void *addr) function the following happens (occurred on arch/arm): drivers/infiniband/sw/siw/siw_qp_tx.c:32:23: warning: incompatible integer to pointer conversion passing 'dma_addr_t' (aka 'unsigned int') to parameter of type 'const void *' [-Wint-conversion] drivers/infiniband/sw/siw/siw_qp_tx.c:32:37: warning: passing argument 1 of 'virt_to_pfn' makes pointer from integer without a cast [-Wint-conversion] drivers/infiniband/sw/siw/siw_qp_tx.c:538:36: warning: incompatible integer to pointer conversion passing 'unsigned long long' to parameter of type 'const void *' [-Wint-conversion] Fix this with an explicit cast. In one case where the SIW SGE uses an unaligned u64 we need a double cast modifying the virtual address (va) to a platform-specific uintptr_t before casting to a (void *). Fixes: b9be6f1 ("rdma/siw: transmit path") Cc: [email protected] Signed-off-by: Linus Walleij <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Leon Romanovsky <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent cd0d704 commit 53d9f7e

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

drivers/infiniband/sw/siw/siw_qp_tx.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static struct page *siw_get_pblpage(struct siw_mem *mem, u64 addr, int *idx)
2929
dma_addr_t paddr = siw_pbl_get_buffer(pbl, offset, NULL, idx);
3030

3131
if (paddr)
32-
return virt_to_page(paddr);
32+
return virt_to_page((void *)paddr);
3333

3434
return NULL;
3535
}
@@ -533,13 +533,23 @@ static int siw_tx_hdt(struct siw_iwarp_tx *c_tx, struct socket *s)
533533
kunmap_local(kaddr);
534534
}
535535
} else {
536-
u64 va = sge->laddr + sge_off;
536+
/*
537+
* Cast to an uintptr_t to preserve all 64 bits
538+
* in sge->laddr.
539+
*/
540+
uintptr_t va = (uintptr_t)(sge->laddr + sge_off);
537541

538-
page_array[seg] = virt_to_page(va & PAGE_MASK);
542+
/*
543+
* virt_to_page() takes a (void *) pointer
544+
* so cast to a (void *) meaning it will be 64
545+
* bits on a 64 bit platform and 32 bits on a
546+
* 32 bit platform.
547+
*/
548+
page_array[seg] = virt_to_page((void *)(va & PAGE_MASK));
539549
if (do_crc)
540550
crypto_shash_update(
541551
c_tx->mpa_crc_hd,
542-
(void *)(uintptr_t)va,
552+
(void *)va,
543553
plen);
544554
}
545555

0 commit comments

Comments
 (0)