RDMA/siw: Fix 64/32bit pointer inconsistency
Subsystems (2)
PATCH v3 1/1 RDMA/siw: Fix 64/32bit pointer inconsistency
Fixes improper casting between addresses and unsigned types. Changes siw_pbl_get_buffer() function to return appropriate dma_addr_t, and not u64.
Also fixes debug prints. Now any potentially kernel private pointers are printed formatted as '%pK', to allow keeping that information secret.
--- drivers/infiniband/sw/siw/siw.h | 8 +-- drivers/infiniband/sw/siw/siw_cm.c | 74 ++++++++++++--------------- drivers/infiniband/sw/siw/siw_cq.c | 5 +- drivers/infiniband/sw/siw/siw_mem.c | 14 ++--- drivers/infiniband/sw/siw/siw_mem.h | 2 +- drivers/infiniband/sw/siw/siw_qp.c | 2 +- drivers/infiniband/sw/siw/siw_qp_rx.c | 26 +++++----- drivers/infiniband/sw/siw/siw_qp_tx.c | 43 ++++++++-------- drivers/infiniband/sw/siw/siw_verbs.c | 40 +++++++-------- 9 files changed, 106 insertions(+), 108 deletions(-)
drivers/infiniband/sw/siw/siw.h +4 -4
@@ -138,9 +138,9 @@ struct siw_umem { };struct siw_pble { -u64 addr;/* Address of assigned user buffer */ -u64 size;/* Size of this entry */ -u64 pbl_off;/* Total offset from start of PBL */ +dma_addr_t addr;/* Address of assigned buffer */ +unsigned int size;/* Size of this entry */ +unsigned long pbl_off;/* Total offset from start of PBL */ };struct siw_pbl {
@@ -734,7 +734,7 @@ static inline void siw_crc_skb(struct siw_rx_stream *srx, unsigned int len) "MEM[0x%08x] %s: " fmt, mem->stag, __func__, ##__VA_ARGS__)#define siw_dbg_cep (cep, fmt, ...) \ - ibdev_dbg(&cep->sdev->base_dev, "CEP[0x%p] %s: " fmt, \ + ibdev_dbg(&cep->sdev->base_dev, "CEP[0x%pK] %s: " fmt, \ cep, __func__, ##__VA_ARGS__)void siw_cq_flush (struct siw_cq *cq);
drivers/infiniband/sw/siw/siw_cm.c +34 -40
225 lines not on this page · raw message
drivers/infiniband/sw/siw/siw_cq.c +3 -2
@@ -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%pK\n" , cq->cq_get % cq->num_cqe, cqe->opcode, - cqe->flags, (void *)cqe->id); + cqe->flags, (void *)(uintptr_t )cqe->id); }WRITE_ONCE (cqe->flags,0 ); cq->cq_get++;
drivers/infiniband/sw/siw/siw_mem.c +7 -7
@@ -197,12 +197,12 @@ int siw_check_mem(struct ib_pd *pd, struct siw_mem *mem, u64 addr,*/ if (addr < mem->va || addr + len > mem->va + mem->len) {siw_dbg_pd (pd,"MEM interval len %d\n" , len); -siw_dbg_pd (pd,"[0x%016llx, 0x%016llx] out of bounds\n" , - (unsigned long long )addr, - (unsigned long long )(addr + len)); -siw_dbg_pd (pd,"[0x%016llx, 0x%016llx] STag=0x%08x\n" , - (unsigned long long )mem->va, - (unsigned long long )(mem->va + mem->len), +siw_dbg_pd (pd,"[0x%pK, 0x%pK] out of bounds\n" , + (void *)(uintptr_t )addr, + (void *)(uintptr_t )(addr + len)); +siw_dbg_pd (pd,"[0x%pK, 0x%pK] STag=0x%08x\n" , + (void *)(uintptr_t )mem->va, + (void *)(uintptr_t )(mem->va + mem->len), mem->stag);return -E_BASE_BOUNDS ;
@@ -330,7 +330,7 @@ int siw_invalidate_stag(struct ib_pd *pd, u32 stag)* Optionally, provides remaining len within current element, and * current PBL index for later resume at same element. */ -u64 siw_pbl_get_buffer (struct siw_pbl *pbl,u64 off,int *len,int *idx) +dma_addr_t siw_pbl_get_buffer (struct siw_pbl *pbl,u64 off,int *len,int *idx) {int i = idx ? *idx :0 ;
drivers/infiniband/sw/siw/siw_mem.h +1 -1
@@ -9,7 +9,7 @@struct siw_umem *siw_umem_get (u64 start,u64 len,bool writable);void siw_umem_release (struct siw_umem *umem,bool dirty);struct siw_pbl *siw_pbl_alloc (u32 num_buf); -u64 siw_pbl_get_buffer (struct siw_pbl *pbl,u64 off,int *len,int *idx); +dma_addr_t siw_pbl_get_buffer (struct siw_pbl *pbl,u64 off,int *len,int *idx);struct siw_mem *siw_mem_id2obj (struct siw_device *sdev,int stag_index);int siw_mem_add (struct siw_device *sdev,struct siw_mem *m);int siw_invalidate_stag (struct ib_pd *pd,u32 stag);
drivers/infiniband/sw/siw/siw_qp.c +1 -1
@@ -949,7 +949,7 @@ int siw_activate_tx(struct siw_qp *qp) rv = -EINVAL ; goto out; } - wqe->sqe.sge[0 ].laddr = (u64)&wqe->sqe.sge[1 ]; + wqe->sqe.sge[0 ].laddr = (uintptr_t )&wqe->sqe.sge[1 ]; wqe->sqe.sge[0 ].lkey =0 ; wqe->sqe.num_sge =1 ; }
drivers/infiniband/sw/siw/siw_qp_rx.c +14 -12
@@ -38,9 +38,10 @@ static int siw_rx_umem(struct siw_rx_stream *srx, struct siw_umem *umem, p =siw_get_upage (umem, dest_addr);if (unlikely (!p)) { -pr_warn ("siw: %s: [QP %u]: bogus addr: %p, %p\n" , +pr_warn ("siw: %s: [QP %u]: bogus addr: %pK, %pK\n" , __func__,qp_id (rx_qp (srx)), - (void *)dest_addr, (void *)umem->fp_addr); + (void *)(uintptr_t )dest_addr, + (void *)(uintptr_t )umem->fp_addr);/* siw internal error */ srx->skb_copied += copied; srx->skb_new -= copied;
@@ -50,7 +51,7 @@ static int siw_rx_umem(struct siw_rx_stream *srx, struct siw_umem *umem, pg_off = dest_addr & ~PAGE_MASK ; bytes =min (len, (int )PAGE_SIZE - pg_off); -siw_dbg_qp (rx_qp (srx),"page %p, bytes=%u\n" , p, bytes); +siw_dbg_qp (rx_qp (srx),"page %pK, bytes=%u\n" , p, bytes); dest =kmap_atomic (p); rv = skb_copy_bits(srx->skb, srx->skb_offset, dest + pg_off,
@@ -104,11 +105,11 @@ static int siw_rx_kva(struct siw_rx_stream *srx, void *kva, int len) {int rv; -siw_dbg_qp (rx_qp (srx),"kva: 0x%p, len: %u\n" , kva, len); +siw_dbg_qp (rx_qp (srx),"kva: 0x%pK, len: %u\n" , kva, len); rv =skb_copy_bits (srx->skb, srx->skb_offset, kva, len);if (unlikely (rv)) { -pr_warn ("siw: [QP %u]: %s, len %d, kva 0x%p, rv %d\n" , +pr_warn ("siw: [QP %u]: %s, len %d, kva 0x%pK, rv %d\n" ,qp_id (rx_qp (srx)), __func__, len, kva, rv);return rv;
@@ -132,7 +133,7 @@ static int siw_rx_pbl(struct siw_rx_stream *srx, int *pbl_idx,while (len) {int bytes; -u64 buf_addr = +dma_addr_t buf_addr =siw_pbl_get_buffer (pbl, offset, &bytes, pbl_idx);if (!buf_addr)break ;
@@ -485,8 +486,8 @@ int siw_proc_send(struct siw_qp *qp) mem_p = *mem;if (mem_p->mem_obj ==NULL ) rv =siw_rx_kva (srx, - (void *)(sge->laddr + frx->sge_off), - sge_bytes); + (void *)(uintptr_t )(sge->laddr + frx->sge_off), + sge_bytes);else if (!mem_p->is_pbl) rv =siw_rx_umem (srx, mem_p->umem, sge->laddr + frx->sge_off, sge_bytes);
@@ -598,8 +599,8 @@ int siw_proc_write(struct siw_qp *qp)if (mem->mem_obj ==NULL ) rv =siw_rx_kva (srx, - (void *)(srx->ddp_to + srx->fpdu_part_rcvd), - bytes); + (void *)(uintptr_t )(srx->ddp_to + srx->fpdu_part_rcvd), + bytes);else if (!mem->is_pbl) rv =siw_rx_umem (srx, mem->umem, srx->ddp_to + srx->fpdu_part_rcvd, bytes);
@@ -841,8 +842,9 @@ int siw_proc_rresp(struct siw_qp *qp) bytes =min (srx->fpdu_part_rem, srx->skb_new);if (mem_p->mem_obj ==NULL ) - rv =siw_rx_kva (srx, (void *)(sge->laddr + wqe->processed), - bytes); + rv =siw_rx_kva (srx, + (void *)(uintptr_t )(sge->laddr + wqe->processed), + bytes);else if (!mem_p->is_pbl) rv =siw_rx_umem (srx, mem_p->umem, sge->laddr + wqe->processed, bytes);
drivers/infiniband/sw/siw/siw_qp_tx.c +22 -21
141 lines not on this page · raw message
drivers/infiniband/sw/siw/siw_verbs.c +20 -20
@@ -424,8 +424,7 @@ struct ib_qp *siw_create_qp(struct ib_pd *pd,*/ qp->srq =to_siw_srq (attrs->srq); qp->attrs.rq_size =0 ; -siw_dbg (base_dev,"QP [%u]: [SRQ 0x%p] attached\n" , - qp->qp_num, qp->srq); +siw_dbg (base_dev,"QP [%u]: SRQ attached\n" , qp->qp_num); }else if (num_rqe) {if (qp->kernel_verbs) qp->recvq =vzalloc (num_rqe *sizeof (struct siw_rqe ));
@@ -610,7 +609,7 @@ int siw_destroy_qp(struct ib_qp *base_qp, struct ib_udata *udata) base_ucontext);struct siw_qp_attrs qp_attrs; -siw_dbg_qp (qp,"state %d, cep 0x%p\n" , qp->attrs.state, qp->cep); +siw_dbg_qp (qp,"state %d\n" , qp->attrs.state);/* * Mark QP as in process of destruction to prevent from
@@ -662,7 +661,7 @@ static int siw_copy_inline_sgl(const struct ib_send_wr *core_wr,void *kbuf = &sqe->sge[1 ];int num_sge = core_wr->num_sge, bytes =0 ; - sqe->sge[0 ].laddr = (u64 )kbuf; + sqe->sge[0 ].laddr = (uintptr_t )kbuf; sqe->sge[0 ].lkey =0 ;while (num_sge--) {
@@ -825,7 +824,7 @@ int siw_post_send(struct ib_qp *base_qp, const struct ib_send_wr *wr,break ;case IB_WR_REG_MR : - sqe->base_mr = (uint64_t )reg_wr (wr)->mr; + sqe->base_mr = (uintptr_t )reg_wr (wr)->mr; sqe->rkey =reg_wr (wr)->key; sqe->access =reg_wr (wr)->access &IWARP_ACCESS_MASK ; sqe->opcode =SIW_OP_REG_MR ;
@@ -842,8 +841,9 @@ 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 0x%p\n" , - sqe->opcode, sqe->flags, (void *)sqe->id); +siw_dbg_qp (qp,"opcode %d, flags 0x%x, wr_id 0x%pK\n" , + sqe->opcode, sqe->flags, + (void *)(uintptr_t )sqe->id);if (unlikely (rv <0 ))break ;
@@ -1205,8 +1205,8 @@ struct ib_mr *siw_reg_user_mr(struct ib_pd *pd, u64 start, u64 len,unsigned long mem_limit =rlimit (RLIMIT_MEMLOCK );int rv; -siw_dbg_pd (pd,"start: 0x%016llx, va: 0x%016llx, len: %llu\n" , - (unsigned long long )start, (unsigned long long )rnic_va, +siw_dbg_pd (pd,"start: 0x%pK, va: 0x%pK, len: %llu\n" , + (void *)(uintptr_t )start, (void *)(uintptr_t )rnic_va, (unsigned long long )len);if (atomic_inc_return (&sdev->num_mr) >SIW_MAX_MR ) {
@@ -1363,7 +1363,7 @@ int siw_map_mr_sg(struct ib_mr *base_mr, struct scatterlist *sl, int num_sle,struct siw_mem *mem = mr->mem;struct siw_pbl *pbl = mem->pbl;struct siw_pble *pble; -u64 pbl_size; +unsigned long pbl_size;int i, rv;if (!pbl) {
@@ -1402,16 +1402,18 @@ int siw_map_mr_sg(struct ib_mr *base_mr, struct scatterlist *sl, int num_sle, pbl_size +=sg_dma_len (slp); }siw_dbg_mem (mem, -"sge[%d], size %llu, addr 0x%016llx, total %llu\n" , - i, pble->size, pble->addr, pbl_size); +"sge[%d], size %u, addr 0x%p, total %lu\n" , + i, pble->size, (void *)(uintptr_t )pble->addr, + pbl_size); } rv =ib_sg_to_pages (base_mr, sl, num_sle, sg_off, siw_set_pbl_page);if (rv >0 ) { mem->len = base_mr->length; mem->va = base_mr->iova;siw_dbg_mem (mem, -"%llu bytes, start 0x%016llx, %u SLE to %u entries\n" , - mem->len, mem->va, num_sle, pbl->num_buf); +"%llu bytes, start 0x%pK, %u SLE to %u entries\n" , + mem->len, (void *)(uintptr_t )mem->va, num_sle, + pbl->num_buf); }return rv; }
@@ -1529,7 +1531,7 @@ int siw_create_srq(struct ib_srq *base_srq, }spin_lock_init (&srq->lock); -siw_dbg_pd (base_srq->pd,"[SRQ 0x%p]: success\n" , srq); +siw_dbg_pd (base_srq->pd,"[SRQ]: success\n" );return 0 ;
@@ -1650,8 +1652,7 @@ int siw_post_srq_recv(struct ib_srq *base_srq, const struct ib_recv_wr *wr,if (unlikely (!srq->kernel_verbs)) {siw_dbg_pd (base_srq->pd, -"[SRQ 0x%p]: no kernel post_recv for mapped srq\n" , - srq); +"[SRQ]: no kernel post_recv for mapped srq\n" ); rv = -EINVAL ; goto out; }
@@ -1673,8 +1674,7 @@ int siw_post_srq_recv(struct ib_srq *base_srq, const struct ib_recv_wr *wr, }if (unlikely (wr->num_sge > srq->max_sge)) {siw_dbg_pd (base_srq->pd, -"[SRQ 0x%p]: too many sge's: %d\n" , srq, - wr->num_sge); +"[SRQ]: too many sge's: %d\n" , wr->num_sge); rv = -EINVAL ;break ; }
@@ -1693,7 +1693,7 @@ int siw_post_srq_recv(struct ib_srq *base_srq, const struct ib_recv_wr *wr,spin_unlock_irqrestore (&srq->lock, flags); out:if (unlikely (rv <0 )) { -siw_dbg_pd (base_srq->pd,"[SRQ 0x%p]: error %d\n" , srq, rv); +siw_dbg_pd (base_srq->pd,"[SRQ]: error %d\n" , rv); *bad_wr = wr; }return rv;
Signature · 1 line
2.17.2
Quoted 65 lines · Bernard Metzler
Fixes improper casting between addresses and unsigned types. Changes
siw_pbl_get_buffer()function to return appropriatedma_addr_t, and not u64.Also fixes debug prints. Now any potentially kernel private pointers are printed formatted as '%pK', to allow keeping that information secret.
Fixes d941bfe500be ("RDMA/siw: Change CQ flags from 64->32 bits")Fixes b0fff7317bb4 ("rdma/siw: completion queue methods")Fixes 8b6a361b8c48 ("rdma/siw: receive path")Fixes b9be6f18cf9e ("rdma/siw: transmit path")Fixes f29dd55b0236 ("rdma/siw: queue pair methods")Fixes 2251334dcac9 ("rdma/siw: application buffer management")Fixes 303ae1cdfdf7 ("rdma/siw: application interface")Fixes 6c52fdc244b5 ("rdma/siw: connection management")Fixes a531975279f3 ("rdma/siw: main include file")Reported-by Geert Uytterhoeven <[email protected]>Reported-by Jason Gunthorpe <[email protected]>Reported-by Leon Romanovsky <[email protected]>Signed-off-by Bernard Metzler <[email protected]>--- drivers/infiniband/sw/siw/siw.h | 8 +-- drivers/infiniband/sw/siw/siw_cm.c | 74 ++++++++++++--------------- drivers/infiniband/sw/siw/siw_cq.c | 5 +- drivers/infiniband/sw/siw/siw_mem.c | 14 ++--- drivers/infiniband/sw/siw/siw_mem.h | 2 +- drivers/infiniband/sw/siw/siw_qp.c | 2 +- drivers/infiniband/sw/siw/siw_qp_rx.c | 26 +++++----- drivers/infiniband/sw/siw/siw_qp_tx.c | 43 ++++++++-------- drivers/infiniband/sw/siw/siw_verbs.c | 40 +++++++-------- 9 files changed, 106 insertions(+), 108 deletions(-)drivers/infiniband/sw/siw/siw.h +4
-4@@ -138,9 +138,9 @@ struct siw_umem { };struct siw_pble { -u64 addr;/* Address of assigned user buffer */ -u64 size;/* Size of this entry */ -u64 pbl_off;/* Total offset from start of PBL */ +dma_addr_t addr;/* Address of assigned buffer */ +unsigned int size;/* Size of this entry */ +unsigned long pbl_off;/* Total offset from start of PBL */ };struct siw_pbl {@@ -734,7 +734,7 @@ static inline void siw_crc_skb(struct siw_rx_stream *srx, unsigned int len) "MEM[0x%08x] %s: " fmt, mem->stag, __func__, ##__VA_ARGS__)#define siw_dbg_cep (cep, fmt, ...) \ - ibdev_dbg(&cep->sdev->base_dev, "CEP[0x%p] %s: " fmt, \ + ibdev_dbg(&cep->sdev->base_dev, "CEP[0x%pK] %s: " fmt, \ cep, __func__, ##__VA_ARGS__)void siw_cq_flush (struct siw_cq *cq);drivers/infiniband/sw/siw/siw_cm.c +0
-0
drivers/infiniband/sw/siw/siw_cm.c static int siw_cm_upcall(struct siw_cep *cep, enum iw_cm_event_type reason, · line 359
Quoted 7 lines
drivers/infiniband/sw/siw/siw_cm.c +2
-2@@ -355,8 +355,8 @@ static int siw_cm_upcall(struct siw_cep *cep, enum iw_cm_event_type reason,getname_local (cep->sock, &event.local_addr);getname_peer (cep->sock, &event.remote_addr); } -siw_dbg_cep (cep,"[QP %u]: id 0x%p, reason=%d, status=%d\n" , - cep->qp ?qp_id (cep->qp) :-1 , id, reason, status); +siw_dbg_cep (cep,"[QP %u]: reason=%d, status=%d\n" , + cep->qp ?qp_id (cep->qp) :-1 , reason, status);
^^^^
There is a chance that such construction (attempt to print -1 with %u) will generate some sort of warning.
Thanks
Quoted 83 lines · Leon Romanovsky
Quoted 73 lines · Bernard Metzler
Fixes improper casting between addresses and unsigned types. Changes
siw_pbl_get_buffer()function to return appropriatedma_addr_t, and not u64.Also fixes debug prints. Now any potentially kernel private pointers are printed formatted as '%pK', to allow keeping that information secret.
Fixes d941bfe500be ("RDMA/siw: Change CQ flags from 64->32 bits")Fixes b0fff7317bb4 ("rdma/siw: completion queue methods")Fixes 8b6a361b8c48 ("rdma/siw: receive path")Fixes b9be6f18cf9e ("rdma/siw: transmit path")Fixes f29dd55b0236 ("rdma/siw: queue pair methods")Fixes 2251334dcac9 ("rdma/siw: application buffer management")Fixes 303ae1cdfdf7 ("rdma/siw: application interface")Fixes 6c52fdc244b5 ("rdma/siw: connection management")Fixes a531975279f3 ("rdma/siw: main include file")Reported-by Geert Uytterhoeven <[email protected]>Reported-by Jason Gunthorpe <[email protected]>Reported-by Leon Romanovsky <[email protected]>Signed-off-by Bernard Metzler <[email protected]>--- drivers/infiniband/sw/siw/siw.h | 8 +-- drivers/infiniband/sw/siw/siw_cm.c | 74 ++++++++++++---------- ----- drivers/infiniband/sw/siw/siw_cq.c | 5 +- drivers/infiniband/sw/siw/siw_mem.c | 14 ++--- drivers/infiniband/sw/siw/siw_mem.h | 2 +- drivers/infiniband/sw/siw/siw_qp.c | 2 +- drivers/infiniband/sw/siw/siw_qp_rx.c | 26 +++++----- drivers/infiniband/sw/siw/siw_qp_tx.c | 43 ++++++++-------- drivers/infiniband/sw/siw/siw_verbs.c | 40 +++++++-------- 9 files changed, 106 insertions(+), 108 deletions(-)drivers/infiniband/sw/siw/siw.h +3
-4@@ -138,9 +138,9 @@ struct siw_umem { };struct siw_pble { -u64 addr;/* Address of assigned user buffer */ -u64 size;/* Size of this entry */ -u64 pbl_off;/* Total offset from start of PBL */ +dma_addr_t addr;/* Address of assigned buffer */ +unsigned int size;/* Size of this entry */ +unsigned long pbl_off;/* Total offset from start of PBL */ };struct siw_pbl {@@ -734,7 +734,7 @@ static inline void siw_crc_skb(struct siw_rx_stream *srx, unsigned int len) "MEM[0x%08x] %s: " fmt, mem->stag, __func__, ##__VA_ARGS__)#define siw_dbg_cep (cep, fmt, ...) \ - ibdev_dbg(&cep->sdev->base_dev, "CEP[0x%p] %s: "fmt, \
drivers/infiniband/sw/siw/siw.h +1
-0+ ibdev_dbg(&cep->sdev->base_dev, "CEP[0x%pK] %s: "fmt, \
drivers/infiniband/sw/siw/siw.h +0
-0cep, __func__, ##__VA_ARGS__)void siw_cq_flush (struct siw_cq *cq);drivers/infiniband/sw/siw/siw_cm.c +0
-0drivers/infiniband/sw/siw/siw_cm.c static int siw_cm_upcall(struct siw_cep *cep, · line 360
Quoted 8 lines
drivers/infiniband/sw/siw/siw_cm.c +2
-2@@ -355,8 +355,8 @@ static int siw_cm_upcall(struct siw_cep *cep,enum iw_cm_event_type reason, getname_local(cep->sock, &event.local_addr);getname_peer (cep->sock, &event.remote_addr); } -siw_dbg_cep (cep,"[QP %u]: id 0x%p, reason=%d, status=%d\n" , - cep->qp ?qp_id (cep->qp) :-1 , id, reason, status); +siw_dbg_cep (cep,"[QP %u]: reason=%d, status=%d\n" , + cep->qp ?qp_id (cep->qp) :-1 , reason, status);^^^^
Quoted 4 lines
There is a chance that such construction (attempt to print -1 with %u) will generate some sort of warning.
Thanks
I didn't see any warnings when I built it. And %u->-1 would be the same error on 64bit or 32bit, so I think we're safe here.
Thanks Bernard, it's in my wip/dl-for-rc branch to get 0day testing.
Signature · 3 lines
Doug Ledford <[email protected]> GPG KeyID: B826A3330E572FDD Fingerprint = AE6B 1BDA 122B 23B4 265B 1274 B826 A333 0E57 2FDD
Quoted 87 lines · Doug Ledford
Quoted 86 lines · Leon Romanovsky
Quoted 73 lines · Bernard Metzler
Fixes improper casting between addresses and unsigned types. Changes
siw_pbl_get_buffer()function to return appropriatedma_addr_t, and not u64.Also fixes debug prints. Now any potentially kernel private pointers are printed formatted as '%pK', to allow keeping that information secret.
Fixes d941bfe500be ("RDMA/siw: Change CQ flags from 64->32 bits")Fixes b0fff7317bb4 ("rdma/siw: completion queue methods")Fixes 8b6a361b8c48 ("rdma/siw: receive path")Fixes b9be6f18cf9e ("rdma/siw: transmit path")Fixes f29dd55b0236 ("rdma/siw: queue pair methods")Fixes 2251334dcac9 ("rdma/siw: application buffer management")Fixes 303ae1cdfdf7 ("rdma/siw: application interface")Fixes 6c52fdc244b5 ("rdma/siw: connection management")Fixes a531975279f3 ("rdma/siw: main include file")Reported-by Geert Uytterhoeven <[email protected]>Reported-by Jason Gunthorpe <[email protected]>Reported-by Leon Romanovsky <[email protected]>Signed-off-by Bernard Metzler <[email protected]>--- drivers/infiniband/sw/siw/siw.h | 8 +-- drivers/infiniband/sw/siw/siw_cm.c | 74 ++++++++++++---------- ----- drivers/infiniband/sw/siw/siw_cq.c | 5 +- drivers/infiniband/sw/siw/siw_mem.c | 14 ++--- drivers/infiniband/sw/siw/siw_mem.h | 2 +- drivers/infiniband/sw/siw/siw_qp.c | 2 +- drivers/infiniband/sw/siw/siw_qp_rx.c | 26 +++++----- drivers/infiniband/sw/siw/siw_qp_tx.c | 43 ++++++++-------- drivers/infiniband/sw/siw/siw_verbs.c | 40 +++++++-------- 9 files changed, 106 insertions(+), 108 deletions(-)drivers/infiniband/sw/siw/siw.h +3
-4@@ -138,9 +138,9 @@ struct siw_umem { };struct siw_pble { -u64 addr;/* Address of assigned user buffer */ -u64 size;/* Size of this entry */ -u64 pbl_off;/* Total offset from start of PBL */ +dma_addr_t addr;/* Address of assigned buffer */ +unsigned int size;/* Size of this entry */ +unsigned long pbl_off;/* Total offset from start of PBL */ };struct siw_pbl {@@ -734,7 +734,7 @@ static inline void siw_crc_skb(struct siw_rx_stream *srx, unsigned int len) "MEM[0x%08x] %s: " fmt, mem->stag, __func__, ##__VA_ARGS__)#define siw_dbg_cep (cep, fmt, ...) \ - ibdev_dbg(&cep->sdev->base_dev, "CEP[0x%p] %s: "fmt, \
drivers/infiniband/sw/siw/siw.h +1
-0+ ibdev_dbg(&cep->sdev->base_dev, "CEP[0x%pK] %s: "fmt, \
drivers/infiniband/sw/siw/siw.h +0
-0cep, __func__, ##__VA_ARGS__)void siw_cq_flush (struct siw_cq *cq);drivers/infiniband/sw/siw/siw_cm.c +0
-0drivers/infiniband/sw/siw/siw_cm.c static int siw_cm_upcall(struct siw_cep *cep, · line 360
Quoted 8 lines
drivers/infiniband/sw/siw/siw_cm.c +2
-2@@ -355,8 +355,8 @@ static int siw_cm_upcall(struct siw_cep *cep,enum iw_cm_event_type reason, getname_local(cep->sock, &event.local_addr);getname_peer (cep->sock, &event.remote_addr); } -siw_dbg_cep (cep,"[QP %u]: id 0x%p, reason=%d, status=%d\n" , - cep->qp ?qp_id (cep->qp) :-1 , id, reason, status); +siw_dbg_cep (cep,"[QP %u]: reason=%d, status=%d\n" , + cep->qp ?qp_id (cep->qp) :-1 , reason, status);^^^^There is a chance that such construction (attempt to print -1 with %u) will generate some sort of warning.
Quoted 4 lines
Quoted 1 line
Thanks
I didn't see any warnings when I built it. And %u->-1 would be the same error on 64bit or 32bit, so I think we're safe here.
I tried -Wextra now with gcc version 9.1.1 and such code didn't produce any warnings, so you are right, it is safe.
Quoted 7 lines
Thanks Bernard, it's in my wip/dl-for-rc branch to get 0day testing.
--
Doug Ledford <[email protected]>GPG KeyID: B826A3330E572FDD Fingerprint = AE6B 1BDA 122B 23B4 265B 1274 B826 A333 0E57 2FDD
-----"Doug Ledford" <[email protected]> wrote: -----
Quoted 95 lines
To: "Leon Romanovsky" <[email protected]>, "Bernard Metzler" <[email protected]>
From: "Doug Ledford" <[email protected]>
Date: 08/22/2019 09:08PM
Cc: [email protected], [email protected], [email protected]
Subject: [EXTERNAL] Re: [PATCH v3] RDMA/siw: Fix 64/32bit pointer inconsistencyQuoted 10 lines · Leon Romanovsky
Quoted 9 lines · Bernard Metzler
Fixes improper casting between addresses and unsigned types. Changes
siw_pbl_get_buffer()function to return appropriatedma_addr_t, and not u64.Also fixes debug prints. Now any potentially kernel private pointers are printed formatted as '%pK', to allow keeping that information secret.
Fixes d941bfe500be ("RDMA/siw: Change CQ flags from 64->32bits")
Quoted 9 lines
Quoted 9 lines
Fixes b0fff7317bb4 ("rdma/siw: completion queue methods")Fixes 8b6a361b8c48 ("rdma/siw: receive path")Fixes b9be6f18cf9e ("rdma/siw: transmit path")Fixes f29dd55b0236 ("rdma/siw: queue pair methods")Fixes 2251334dcac9 ("rdma/siw: application buffer management")Fixes 303ae1cdfdf7 ("rdma/siw: application interface")Fixes 6c52fdc244b5 ("rdma/siw: connection management")Fixes a531975279f3 ("rdma/siw: main include file")Quoted 7 lines
Quoted 7 lines
Reported-by Geert Uytterhoeven <[email protected]>Reported-by Jason Gunthorpe <[email protected]>Reported-by Leon Romanovsky <[email protected]>Signed-off-by Bernard Metzler <[email protected]>--- drivers/infiniband/sw/siw/siw.h | 8 +-- drivers/infiniband/sw/siw/siw_cm.c | 74++++++++++++----------
Quoted 57 lines
Quoted 48 lines
-----
drivers/infiniband/sw/siw/siw_cq.c | 5 +- drivers/infiniband/sw/siw/siw_mem.c | 14 ++--- drivers/infiniband/sw/siw/siw_mem.h | 2 +- drivers/infiniband/sw/siw/siw_qp.c | 2 +- drivers/infiniband/sw/siw/siw_qp_rx.c | 26 +++++----- drivers/infiniband/sw/siw/siw_qp_tx.c | 43 ++++++++-------- drivers/infiniband/sw/siw/siw_verbs.c | 40 +++++++-------- 9 files changed, 106 insertions(+), 108 deletions(-)drivers/infiniband/sw/siw/siw.h +3
-4@@ -138,9 +138,9 @@ struct siw_umem { };struct siw_pble { -u64 addr;/* Address of assigned user buffer */ -u64 size;/* Size of this entry */ -u64 pbl_off;/* Total offset from start of PBL */ +dma_addr_t addr;/* Address of assigned buffer */ +unsigned int size;/* Size of this entry */ +unsigned long pbl_off;/* Total offset from start of PBL */ };struct siw_pbl {@@ -734,7 +734,7 @@ static inline void siw_crc_skb(struct siw_rx_stream *srx, unsigned int len) "MEM[0x%08x] %s: " fmt, mem->stag, __func__, ##__VA_ARGS__)#define siw_dbg_cep (cep, fmt, ...) \ - ibdev_dbg(&cep->sdev->base_dev, "CEP[0x%p] %s: "fmt, \
drivers/infiniband/sw/siw/siw.h +1
-0+ ibdev_dbg(&cep->sdev->base_dev, "CEP[0x%pK] %s: "fmt, \
drivers/infiniband/sw/siw/siw.h +0
-0cep, __func__, ##__VA_ARGS__)void siw_cq_flush (struct siw_cq *cq);drivers/infiniband/sw/siw/siw_cm.c +0
-0drivers/infiniband/sw/siw/siw_cm.c static int siw_cm_upcall(struct siw_cep *cep, · line 360
Quoted 8 lines
drivers/infiniband/sw/siw/siw_cm.c +2
-2@@ -355,8 +355,8 @@ static int siw_cm_upcall(struct siw_cep *cep,enum iw_cm_event_type reason, getname_local(cep->sock, &event.local_addr);getname_peer (cep->sock, &event.remote_addr); } -siw_dbg_cep (cep,"[QP %u]: id 0x%p, reason=%d, status=%d\n" , - cep->qp ?qp_id (cep->qp) :-1 , id, reason, status); +siw_dbg_cep (cep,"[QP %u]: reason=%d, status=%d\n" , + cep->qp ?qp_id (cep->qp) :-1 , reason, status);^^^^Quoted 1 line
There is a chance that such construction (attempt to print -1 with
Quoted 9 lines
%u)
Quoted 3 lines
will generate some sort of warning.
Thanks
I didn't see any warnings when I built it. And %u->-1 would be the same
error on 64bit or 32bit, so I think we're safe here.
Doug,
May I ask you to amend this patch in a way which would just stop this monument of programming stupidity from prolonging into the future, while of course recognizing the impossibility of erasing it from the past? Exchanging the %u with %d would help me regaining some self-confidence ;)
Thanks!
Bernard.
Quoted 7 lines
Thanks Bernard, it's in my wip/dl-for-rc branch to get 0day testing.
Signature · 3 lines
Doug Ledford <[email protected]> GPG KeyID: B826A3330E572FDD Fingerprint = AE6B 1BDA 122B 23B4 265B 1274 B826 A333 0E57 2FDD
[attachment "signature.asc" removed by Bernard Metzler/Zurich/IBM]
Quoted 25 lines · Bernard Metzler
Quoted 15 lines
Quoted 14 lines
drivers/infiniband/sw/siw/siw_cm.c static int siw_cm_upcall(struct siw_cep *cep, · line 360
Quoted 13 lines
drivers/infiniband/sw/siw/siw_cm.c +3
-2+++ b/drivers/infiniband/sw/siw/siw_cm.c@@ -355,8 +355,8 @@ static int siw_cm_upcall(struct siw_cep *cep,enum iw_cm_event_type reason, getname_local(cep->sock, &event.local_addr);getname_peer (cep->sock, &event.remote_addr); } -siw_dbg_cep (cep,"[QP %u]: id 0x%p, reason=%d, status=%d\n" , - cep->qp ?qp_id (cep->qp) :-1 , id, reason, status); +siw_dbg_cep (cep,"[QP %u]: reason=%d, status=%d\n" , + cep->qp ?qp_id (cep->qp) :-1 , reason, status);^^^^Quoted 1 line
There is a chance that such construction (attempt to print -1 with
Quoted 9 lines
%u)
Quoted 3 lines
will generate some sort of warning.
Thanks
I didn't see any warnings when I built it. And %u->-1 would be the same
error on 64bit or 32bit, so I think we're safe here.
Quoted 7 lines
Doug,
May I ask you to amend this patch in a way which would just stop this monument of programming stupidity from prolonging into the future, while of course recognizing the impossibility of erasing it from the past? Exchanging the %u with %d would help me regaining some self-confidence ;)
A
q?a:b
Expression has only a single type. There are some tricky rules on this, but since gcc does not complain on the %u it means 'q?(u32):(int)' is a (u32) and the -1 is implicitly casted.
The better thing to write would have been U32_MAX instead of -1
Jason
-----"Jason Gunthorpe" <[email protected]> wrote: -----
Quoted 45 lines
To: "Bernard Metzler" <[email protected]>
From: "Jason Gunthorpe" <[email protected]>
Date: 08/23/2019 04:42PM
Cc: "Doug Ledford" <[email protected]>, "Leon Romanovsky" <[email protected]>, [email protected], [email protected]
Subject: [EXTERNAL] Re: [PATCH v3] RDMA/siw: Fix 64/32bit pointer inconsistencyQuoted 5 lines · Bernard Metzler
Quoted 5 lines
Quoted 5 lines
drivers/infiniband/sw/siw/siw_cm.c static int siw_cm_upcall(struct siw_cep
Quoted 5 lines
drivers/infiniband/sw/siw/siw_cm.c +1
-0+++ b/drivers/infiniband/sw/siw/siw_cm.c@@ -355,8 +355,8 @@ static int siw_cm_upcall(struct siw_cep*cep,
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
drivers/infiniband/sw/siw/siw_cm.c static int siw_cm_upcall(struct siw_cep *cep, enum iw_cm_event_type reason, · line 359
Quoted 8 lines
drivers/infiniband/sw/siw/siw_cm.c +2
-2enum iw_cm_event_type reason, getname_local(cep->sock, &event.local_addr);getname_peer (cep->sock, &event.remote_addr); } -siw_dbg_cep (cep,"[QP %u]: id 0x%p, reason=%d, status=%d\n" , - cep->qp ?qp_id (cep->qp) :-1 , id, reason, status); +siw_dbg_cep (cep,"[QP %u]: reason=%d, status=%d\n" , + cep->qp ?qp_id (cep->qp) :-1 , reason, status);^^^^There is a chance that such construction (attempt to print -1
with
Quoted 6 lines
Quoted 6 lines
%u)
Quoted 3 lines
will generate some sort of warning.
Thanks
I didn't see any warnings when I built it. And %u->-1 would be
the
Quoted 11 lines
Quoted 3 lines
same
error on 64bit or 32bit, so I think we're safe here.Doug,
May I ask you to amend this patch in a way which would just stop this monument of programming stupidity from prolonging into the future, while of course recognizing the impossibility of erasing it from the past? Exchanging the %u with %d would help me regaining some self-confidence ;)
Quoted 9 lines
A
q?a:bExpression has only a single type. There are some tricky rules on this, but since gcc does not complain on the %u it means 'q?(u32):(int)' is a (u32) and the -1 is implicitly casted.
The better thing to write would have been
U32_MAXinstead of -1
What I wanted to have though is an easy to spot invalid number for the QP. This is why I wanted to have it a negative number on the screen, which is obviously not nicely achievable. So, yeah, U32_MAX is a better idea. It will not very often be a valid QP ID...
Thanks
Bernard.
Quoted 57 lines · Bernard Metzler
-----"Jason Gunthorpe" <[email protected]> wrote: -----
Quoted 55 lines
To: "Bernard Metzler" <[email protected]>
From: "Jason Gunthorpe" <[email protected]>
Date: 08/23/2019 04:42PM
Cc: "Doug Ledford" <[email protected]>, "Leon Romanovsky" <[email protected]>, [email protected], [email protected]
Subject: [EXTERNAL] Re: [PATCH v3] RDMA/siw: Fix 64/32bit pointer inconsistencyQuoted 5 lines · Bernard Metzler
Quoted 5 lines
Quoted 5 lines
drivers/infiniband/sw/siw/siw_cm.c static int siw_cm_upcall(struct siw_cep
Quoted 5 lines
drivers/infiniband/sw/siw/siw_cm.c +1
-0+++ b/drivers/infiniband/sw/siw/siw_cm.c@@ -355,8 +355,8 @@ static int siw_cm_upcall(struct siw_cep*cep,
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/infiniband/sw/siw/siw_cm.c +0
-1enum iw_cm_event_type reason, getname_local(cep->sock, &event.local_addr);getname_peer (cep->sock, &event.remote_addr); } - siw_dbg_cep(cep, "[QP %u]: id 0x%p, reason=%d,Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
drivers/infiniband/sw/siw/siw_cm.c +2
-1status=%d\n", - cep->qp ? qp_id(cep->qp) : -1, id, reason, status); + siw_dbg_cep(cep, "[QP %u]: reason=%d, status=%d\n", + cep->qp ? qp_id(cep->qp) : -1, reason,status);
^^^^There is a chance that such construction (attempt to print -1
with
Quoted 6 lines
Quoted 6 lines
%u)
Quoted 3 lines
will generate some sort of warning.
Thanks
I didn't see any warnings when I built it. And %u->-1 would be
the
Quoted 11 lines
Quoted 3 lines
same
error on 64bit or 32bit, so I think we're safe here.Doug,
May I ask you to amend this patch in a way which would just stop this monument of programming stupidity from prolonging into the future, while of course recognizing the impossibility of erasing it from the past? Exchanging the %u with %d would help me regaining some self-confidence ;)A
q?a:bExpression has only a single type. There are some tricky rules on this, but since gcc does not complain on the %u it means 'q?(u32):(int)' is a (u32) and the -1 is implicitly casted.
Quoted 8 lines
Quoted 2 lines
The better thing to write would have been
U32_MAXinstead of -1What I wanted to have though is an easy to spot invalid number for the QP. This is why I wanted to have it a negative number on the screen, which is obviously not nicely achievable. So, yeah,
U32_MAXis a better idea. It will not very often be a valid QP ID...
Given that this patch was still the top of my tree, I fixed this up. But, I think U32_MAX is wrong. It should be UINT_MAX (which is what I used). Otherwise it will give errors on s390 where an int is 31 bits (and anywhere else that might have a non-32 bit int).
Signature · 3 lines
Doug Ledford <[email protected]> GPG KeyID: B826A3330E572FDD Fingerprint = AE6B 1BDA 122B 23B4 265B 1274 B826 A333 0E57 2FDD
Quoted 25 lines · Doug Ledford
Quoted 15 lines · Bernard Metzler
Quoted 15 lines
Quoted 7 lines
Doug,
May I ask you to amend this patch in a way which would just stop this monument of programming stupidity from prolonging into the future, while of course recognizing the impossibility of erasing it from the past? Exchanging the %u with %d would help me regaining some self-confidence ;)A
q?a:bExpression has only a single type. There are some tricky rules on this, but since gcc does not complain on the %u it means 'q?(u32):(int)' is a (u32) and the -1 is implicitly casted.
Quoted 8 lines
Quoted 2 lines
The better thing to write would have been
U32_MAXinstead of -1What I wanted to have though is an easy to spot invalid number for the QP. This is why I wanted to have it a negative number on the screen, which is obviously not nicely achievable. So, yeah,
U32_MAXis a better idea. It will not very often be a valid QP ID...
Quoted 4 lines
Given that this patch was still the top of my tree, I fixed this up. But, I think
U32_MAXis wrong. It should beUINT_MAX(which is what I used). Otherwise it will give errors on s390 where an int is 31 bits (and anywhere else that might have a non-32 bit int).
qp_id returns u32 and the types of both sides of the : should be identical
A non-32 bit int does not exist in Linux, everything would break.
Jason
Quoted 35 lines · Jason Gunthorpe
Quoted 26 lines · Doug Ledford
Quoted 16 lines · Bernard Metzler
Quoted 16 lines
Quoted 7 lines
Doug,
May I ask you to amend this patch in a way which would just stop this monument of programming stupidity from prolonging into the future, while of course recognizing the impossibility of erasing it from the past? Exchanging the %u with %d would help me regaining some self-confidence ;)A
q?a:bExpression has only a single type. There are some tricky rules on
this, but since gcc does not complain on the %u it means 'q?(u32):(int)' is a (u32) and the -1 is implicitly casted.Quoted 8 lines
Quoted 2 lines
The better thing to write would have been
U32_MAXinstead of -1What I wanted to have though is an easy to spot invalid number for the QP. This is why I wanted to have it a negative number on the screen, which is obviously not nicely achievable. So, yeah,
U32_MAXis a better idea. It will not very often be a valid QP ID...Quoted 7 lines
Given that this patch was still the top of my tree, I fixed this up.
But, I thinkU32_MAXis wrong. It should beUINT_MAX(which is what I
used). Otherwise it will give errors on s390 where an int is 31 bits
(and anywhere else that might have a non-32 bit int).
Quoted 2 lines
qp_idreturns u32 and the types of both sides of the : should be identical
I disagree. I would rather the constant in a situation like this be consistent with the format specifier, which one can see right in the line of code, than with a type of an element of a struct, which one would have to go look up. And the format specifier is %u, unsigned int.
Quoted 1 line
A non-32 bit int does not exist in Linux, everything would break.
Well, s390 does have a 31 bit limit, but it's just the address space, not the int size of the registers, so you're right, I was conflating two different things.
Signature · 3 lines
Doug Ledford <[email protected]> GPG KeyID: B826A3330E572FDD Fingerprint = AE6B 1BDA 122B 23B4 265B 1274 B826 A333 0E57 2FDD