Re: Re: [PATCH] RDMA/siw: Fix compiler warnings on 32-bit due to u64/pointer abuse
From: Bernard Metzler
Date: Mon Aug 19 2019 - 13:27:05 EST
Bernard Metzler, PhD
Tech. Leader High Performance I/O, Principal Research Staff
IBM Zurich Research Laboratory
CH-8803 Rueschlikon, Switzerland
+41 44 724 8605
-----"Geert Uytterhoeven" <geert@xxxxxxxxxxxxxx> wrote: -----
>To: "Joe Perches" <joe@xxxxxxxxxxx>
>From: "Geert Uytterhoeven" <geert@xxxxxxxxxxxxxx>
>Date: 08/19/2019 07:15PM
>Cc: "Bernard Metzler" <bmt@xxxxxxxxxxxxxx>, "Doug Ledford"
><dledford@xxxxxxxxxx>, "Jason Gunthorpe" <jgg@xxxxxxxx>, "linux-rdma"
><linux-rdma@xxxxxxxxxxxxxxx>, "Linux Kernel Mailing List"
>Subject: [EXTERNAL] Re: [PATCH] RDMA/siw: Fix compiler warnings on
>32-bit due to u64/pointer abuse
>On Mon, Aug 19, 2019 at 6:56 PM Joe Perches <joe@xxxxxxxxxxx> wrote:
>> On Mon, 2019-08-19 at 12:05 +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]
>> > Fix this by applying the following rules:
>> > 1. When printing a u64, the %llx format specififer should be
>> > instead of casting to a pointer, and printing the latter.
>> > 2. When assigning a pointer to a u64, the pointer should be
>> > uintptr_t, not u64,
>> > 3. When casting from u64 to pointer, an intermediate cast to
>> > should be added,
>> I think a cast to unsigned long is rather more common.
>> uintptr_t is used ~1300 times in the kernel.
>> I believe a cast to unsigned long is much more common.
>That is true, as uintptr_t was introduced in C99.
>Similarly, unsigned long was used before size_t became common.
>However, nowadays size_t and uintptr_t are preferred.
>> It might be useful to add something to the Documentation
>> for this style. Documentation/process/coding-style.rst
>> And trivia:
>> > > diff --git a/drivers/infiniband/sw/siw/siw_verbs.c
>> > @@ -842,8 +842,8 @@ int siw_post_send(struct ib_qp *base_qp,
>const struct ib_send_wr *wr,
>> > rv = -EINVAL;
>> > break;
>> > }
>> > - siw_dbg_qp(qp, "opcode %d, flags 0x%x, wr_id
>> > - sqe->opcode, sqe->flags, (void
>> > + siw_dbg_qp(qp, "opcode %d, flags 0x%x, wr_id
>> > + sqe->opcode, sqe->flags, sqe->id);
>> Printing possible pointers as %llx is generally not a good idea
>> given the desire for %p obfuscation.
>Are they pointers? Difficult to know with all the casting...
You are right. This one is not a pointer. It is an application
assigned unsigned 64bit. Just something (typically a pointer or
array index) assigned by the application to match work completions
with original work requests. So %llx would more correct here,
and the cast is not needed then.
Only problem that a kernel application typically puts a pointer
into here (a pointer to a local context etc.). With the aim
to support obfuscating the pointer for printout, we would be
back to the cast plus %p formatting....?
>Geert Uytterhoeven -- There's lots of Linux beyond ia32 --
>In personal conversations with technical people, I call myself a
>when I'm talking to journalists I just say "programmer" or something
> -- Linus Torvalds