Re: Re: [PATCH] RDMA/siw: Fix compiler warnings on 32-bit due to u64/pointer abuse

Bernard Metzler
2019-08-19T13:36:19Z

-----"Jason Gunthorpe" <jgg@ziepe.ca> wrote: -----

>To: "Geert Uytterhoeven" <geert@linux-m68k.org>
>From: "Jason Gunthorpe" <jgg@ziepe.ca>
>Date: 08/19/2019 02:25PM
>Cc: "Bernard Metzler" <bmt@zurich.ibm.com>, "Doug Ledford"
><dledford@redhat.com>, linux-rdma@vger.kernel.org,
>linux-kernel@vger.kernel.org
>Subject: [EXTERNAL] Re: [PATCH] RDMA/siw: Fix compiler warnings on
>32-bit due to u64/pointer abuse
>
>On Mon, Aug 19, 2019 at 12:05:26PM +0200, Geert Uytterhoeven wrote:
>> When compiling on 32-bit:
>>
>> drivers/infiniband/sw/siw/siw_cq.c:76:20: warning: cast to
>pointer from integer of different size [-Wint-to-pointer-cast]
>> drivers/infiniband/sw/siw/siw_qp.c:952:28: warning: cast from
>pointer to integer of different size [-Wpointer-to-int-cast]
>> drivers/infiniband/sw/siw/siw_qp_tx.c:53:10: warning: cast to
>pointer from integer of different size [-Wint-to-pointer-cast]
>> drivers/infiniband/sw/siw/siw_qp_tx.c:59:11: warning: cast to
>pointer from integer of different size [-Wint-to-pointer-cast]
>> drivers/infiniband/sw/siw/siw_qp_tx.c:59:26: warning: cast to
>pointer from integer of different size [-Wint-to-pointer-cast]
>> drivers/infiniband/sw/siw/siw_qp_tx.c:61:23: warning: cast to
>pointer from integer of different size [-Wint-to-pointer-cast]
>> drivers/infiniband/sw/siw/siw_qp_tx.c:62:9: warning: cast to
>pointer from integer of different size [-Wint-to-pointer-cast]
>> drivers/infiniband/sw/siw/siw_qp_tx.c:82:12: warning: cast to
>pointer from integer of different size [-Wint-to-pointer-cast]
>> drivers/infiniband/sw/siw/siw_qp_tx.c:87:12: warning: cast to
>pointer from integer of different size [-Wint-to-pointer-cast]
>> drivers/infiniband/sw/siw/siw_qp_tx.c:101:12: warning: cast to
>pointer from integer of different size [-Wint-to-pointer-cast]
>> drivers/infiniband/sw/siw/siw_qp_tx.c:169:29: warning: cast
>from pointer to integer of different size [-Wpointer-to-int-cast]
>> drivers/infiniband/sw/siw/siw_qp_tx.c:192:29: warning: cast
>from pointer to integer of different size [-Wpointer-to-int-cast]
>> drivers/infiniband/sw/siw/siw_qp_tx.c:204:29: warning: cast
>from pointer to integer of different size [-Wpointer-to-int-cast]
>> drivers/infiniband/sw/siw/siw_qp_tx.c:219:29: warning: cast
>from pointer to integer of different size [-Wpointer-to-int-cast]
>> drivers/infiniband/sw/siw/siw_qp_tx.c:476:24: warning: cast to
>pointer from integer of different size [-Wint-to-pointer-cast]
>> drivers/infiniband/sw/siw/siw_qp_tx.c:535:7: warning: cast to
>pointer from integer of different size [-Wint-to-pointer-cast]
>> drivers/infiniband/sw/siw/siw_qp_tx.c:832:29: warning: cast
>from pointer to integer of different size [-Wpointer-to-int-cast]
>> drivers/infiniband/sw/siw/siw_qp_tx.c:927:26: warning: cast to
>pointer from integer of different size [-Wint-to-pointer-cast]
>> drivers/infiniband/sw/siw/siw_qp_rx.c:43:5: warning: cast to
>pointer from integer of different size [-Wint-to-pointer-cast]
>> drivers/infiniband/sw/siw/siw_qp_rx.c:43:24: warning: cast to
>pointer from integer of different size [-Wint-to-pointer-cast]
>> drivers/infiniband/sw/siw/siw_qp_rx.c:141:23: warning: cast to
>pointer from integer of different size [-Wint-to-pointer-cast]
>> drivers/infiniband/sw/siw/siw_qp_rx.c:488:6: warning: cast to
>pointer from integer of different size [-Wint-to-pointer-cast]
>> drivers/infiniband/sw/siw/siw_qp_rx.c:601:5: warning: cast to
>pointer from integer of different size [-Wint-to-pointer-cast]
>> drivers/infiniband/sw/siw/siw_qp_rx.c:844:24: warning: cast to
>pointer from integer of different size [-Wint-to-pointer-cast]
>> drivers/infiniband/sw/siw/siw_verbs.c:665:22: warning: cast
>from pointer to integer of different size [-Wpointer-to-int-cast]
>> drivers/infiniband/sw/siw/siw_verbs.c:828:19: warning: cast
>from pointer to integer of different size [-Wpointer-to-int-cast]
>> drivers/infiniband/sw/siw/siw_verbs.c:846:32: warning: cast to
>pointer from integer of different size [-Wint-to-pointer-cast]
>>
>> Fix this by applying the following rules:
>> 1. When printing a u64, the %llx format specififer should be
>used,
>> instead of casting to a pointer, and printing the latter.
>> 2. When assigning a pointer to a u64, the pointer should be cast
>to
>> uintptr_t, not u64,
>> 3. When casting from u64 to pointer, an intermediate cast to
>uintptr_t
>> should be added,
>>
>> Fixes: 2c8ccb37b08fe364 ("RDMA/siw: Change CQ flags from 64->32
>bits")
>> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
>> The issues predate the commit mentioned above, but didn't become
>visible
>> before.
>>
>> The Right Thing(TM) would be to get rid of all this casting, and
>use
>> proper types instead.
>> This would involve teaching the siw people that a kernel virtual
>address
>> is not called a physical address, and should not use u64.
>> drivers/infiniband/sw/siw/siw_cq.c | 5 ++--
>> drivers/infiniband/sw/siw/siw_qp.c | 2 +-
>> drivers/infiniband/sw/siw/siw_qp_rx.c | 16 +++++++------
>> drivers/infiniband/sw/siw/siw_qp_tx.c | 34
>++++++++++++++-------------
>> drivers/infiniband/sw/siw/siw_verbs.c | 8 +++----
>> 5 files changed, 35 insertions(+), 30 deletions(-)
>>
>> diff --git a/drivers/infiniband/sw/siw/siw_cq.c
>b/drivers/infiniband/sw/siw/siw_cq.c
>> index e381ae9b7d62498e..f4ec26eeb9df62bf 100644
>> +++ b/drivers/infiniband/sw/siw/siw_cq.c
>> @@ -71,9 +71,10 @@ int siw_reap_cqe(struct siw_cq *cq, struct ib_wc
>*wc)
>> wc->wc_flags = IB_WC_WITH_INVALIDATE;
>> }
>> wc->qp = cqe->base_qp;
>> - siw_dbg_cq(cq, "idx %u, type %d, flags %2x, id 0x%p\n",
>> + siw_dbg_cq(cq,
>> + "idx %u, type %d, flags %2x, id 0x%llx\n",
>> cq->cq_get % cq->num_cqe, cqe->opcode,
>> - cqe->flags, (void *)cqe->id);
>> + cqe->flags, cqe->id);
>
>If the value is really a kernel pointer, then it ought to be printed
>with %p. We have been getting demanding on this point lately in RDMA
>to enforce the ability to keep kernel pointers secret.
>
>> - wqe->sqe.sge[0].laddr = (u64)&wqe->sqe.sge[1];
>> + wqe->sqe.sge[0].laddr = (uintptr_t)&wqe->sqe.sge[1];
>
>[..]
>
>> rv = siw_rx_kva(srx,
>> - (void *)(sge->laddr + frx->sge_off),
>> + (void *)(uintptr_t)(sge->laddr + frx->sge_off),
>> sge_bytes);
>
>Bernard, this is nonsense, what is going on here with sge->laddr that
>it can't be a void *?
>
siw_sge is defined in siw-abi.h. We make the address u64 to keep the ABI
arch independent.

Thanks and best regards,
Bernard.