Skip to content

Commit 28b5b3a

Browse files
GustavoARSilvadledford
authored andcommitted
RDMA/core: Document confusing code
While looking into Coverity ID 1351047 I ran into the following piece of code at drivers/infiniband/core/verbs.c:496: ret = rdma_addr_find_l2_eth_by_grh(&dgid, &sgid,                                    ah_attr->dmac,                                    wc->wc_flags & IB_WC_WITH_VLAN ?                                    NULL : &vlan_id,                                    &if_index, &hoplimit); The issue here is that the position of arguments in the call to rdma_addr_find_l2_eth_by_grh() function do not match the order of the parameters: &dgid is passed to sgid &sgid is passed to dgid This is the function prototype: int rdma_addr_find_l2_eth_by_grh(const union ib_gid *sgid,  const union ib_gid *dgid,  u8 *dmac, u16 *vlan_id, int *if_index,  int *hoplimit) My question here is if this is intentional? Answer: Yes. ib_init_ah_from_wc() creates ah from the incoming packet. Incoming packet has dgid of the receiver node on which this code is getting executed and sgid contains the GID of the sender. When resolving mac address of destination, you use arrived dgid as sgid and use sgid as dgid because sgid contains destinations GID whom to respond to. Signed-off-by: Gustavo A. R. Silva <[email protected]> Signed-off-by: Doug Ledford <[email protected]>
1 parent 99975cd commit 28b5b3a

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

drivers/infiniband/core/verbs.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,19 @@ int ib_get_gids_from_rdma_hdr(const union rdma_network_hdr *hdr,
452452
}
453453
EXPORT_SYMBOL(ib_get_gids_from_rdma_hdr);
454454

455+
/*
456+
* This function creates ah from the incoming packet.
457+
* Incoming packet has dgid of the receiver node on which this code is
458+
* getting executed and, sgid contains the GID of the sender.
459+
*
460+
* When resolving mac address of destination, the arrived dgid is used
461+
* as sgid and, sgid is used as dgid because sgid contains destinations
462+
* GID whom to respond to.
463+
*
464+
* This is why when calling rdma_addr_find_l2_eth_by_grh() function, the
465+
* position of arguments dgid and sgid do not match the order of the
466+
* parameters.
467+
*/
455468
int ib_init_ah_from_wc(struct ib_device *device, u8 port_num,
456469
const struct ib_wc *wc, const struct ib_grh *grh,
457470
struct rdma_ah_attr *ah_attr)

0 commit comments

Comments
 (0)