Skip to content

Commit 4ba6609

Browse files
Dasaratharaman Chandramoulidledford
authored andcommitted
IB/core: Check for global flag when using ah_attr
Read/write grh fields of the ah_attr only if the ah_flags field has the IB_AH_GRH bit enabled Reviewed-by: Ira Weiny <ira.weiny@intel.com> Reviewed-by: Don Hiatt <don.hiatt@intel.com> Reviewed-by: Sean Hefty <sean.hefty@intel.com> Signed-off-by: Dasaratharaman Chandramouli <dasaratharaman.chandramouli@intel.com> Signed-off-by: Doug Ledford <dledford@redhat.com>
1 parent cf0b939 commit 4ba6609

2 files changed

Lines changed: 57 additions & 35 deletions

File tree

‎drivers/infiniband/core/uverbs_cmd.c‎

Lines changed: 50 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,28 +1847,33 @@ ssize_t ib_uverbs_query_qp(struct ib_uverbs_file *file,
18471847
resp.alt_port_num = attr->alt_port_num;
18481848
resp.alt_timeout = attr->alt_timeout;
18491849

1850-
memcpy(resp.dest.dgid, attr->ah_attr.grh.dgid.raw, 16);
1851-
resp.dest.flow_label = attr->ah_attr.grh.flow_label;
1852-
resp.dest.sgid_index = attr->ah_attr.grh.sgid_index;
1853-
resp.dest.hop_limit = attr->ah_attr.grh.hop_limit;
1854-
resp.dest.traffic_class = attr->ah_attr.grh.traffic_class;
18551850
resp.dest.dlid = attr->ah_attr.dlid;
18561851
resp.dest.sl = attr->ah_attr.sl;
18571852
resp.dest.src_path_bits = attr->ah_attr.src_path_bits;
18581853
resp.dest.static_rate = attr->ah_attr.static_rate;
18591854
resp.dest.is_global = !!(attr->ah_attr.ah_flags & IB_AH_GRH);
1855+
if (resp.dest.is_global) {
1856+
memcpy(resp.dest.dgid, attr->ah_attr.grh.dgid.raw, 16);
1857+
resp.dest.flow_label = attr->ah_attr.grh.flow_label;
1858+
resp.dest.sgid_index = attr->ah_attr.grh.sgid_index;
1859+
resp.dest.hop_limit = attr->ah_attr.grh.hop_limit;
1860+
resp.dest.traffic_class = attr->ah_attr.grh.traffic_class;
1861+
}
18601862
resp.dest.port_num = attr->ah_attr.port_num;
18611863

1862-
memcpy(resp.alt_dest.dgid, attr->alt_ah_attr.grh.dgid.raw, 16);
1863-
resp.alt_dest.flow_label = attr->alt_ah_attr.grh.flow_label;
1864-
resp.alt_dest.sgid_index = attr->alt_ah_attr.grh.sgid_index;
1865-
resp.alt_dest.hop_limit = attr->alt_ah_attr.grh.hop_limit;
1866-
resp.alt_dest.traffic_class = attr->alt_ah_attr.grh.traffic_class;
18671864
resp.alt_dest.dlid = attr->alt_ah_attr.dlid;
18681865
resp.alt_dest.sl = attr->alt_ah_attr.sl;
18691866
resp.alt_dest.src_path_bits = attr->alt_ah_attr.src_path_bits;
18701867
resp.alt_dest.static_rate = attr->alt_ah_attr.static_rate;
18711868
resp.alt_dest.is_global = !!(attr->alt_ah_attr.ah_flags & IB_AH_GRH);
1869+
if (resp.alt_dest.is_global) {
1870+
memcpy(resp.alt_dest.dgid, attr->alt_ah_attr.grh.dgid.raw, 16);
1871+
resp.alt_dest.flow_label = attr->alt_ah_attr.grh.flow_label;
1872+
resp.alt_dest.sgid_index = attr->alt_ah_attr.grh.sgid_index;
1873+
resp.alt_dest.hop_limit = attr->alt_ah_attr.grh.hop_limit;
1874+
resp.alt_dest.traffic_class =
1875+
attr->alt_ah_attr.grh.traffic_class;
1876+
}
18721877
resp.alt_dest.port_num = attr->alt_ah_attr.port_num;
18731878

18741879
resp.max_send_wr = init_attr->cap.max_send_wr;
@@ -1943,30 +1948,41 @@ static int modify_qp(struct ib_uverbs_file *file,
19431948
attr->alt_timeout = cmd->base.alt_timeout;
19441949
attr->rate_limit = cmd->rate_limit;
19451950

1946-
memcpy(attr->ah_attr.grh.dgid.raw, cmd->base.dest.dgid, 16);
1947-
attr->ah_attr.grh.flow_label = cmd->base.dest.flow_label;
1948-
attr->ah_attr.grh.sgid_index = cmd->base.dest.sgid_index;
1949-
attr->ah_attr.grh.hop_limit = cmd->base.dest.hop_limit;
1950-
attr->ah_attr.grh.traffic_class = cmd->base.dest.traffic_class;
1951+
if (cmd->base.dest.is_global) {
1952+
memcpy(attr->ah_attr.grh.dgid.raw, cmd->base.dest.dgid, 16);
1953+
attr->ah_attr.grh.flow_label = cmd->base.dest.flow_label;
1954+
attr->ah_attr.grh.sgid_index = cmd->base.dest.sgid_index;
1955+
attr->ah_attr.grh.hop_limit = cmd->base.dest.hop_limit;
1956+
attr->ah_attr.grh.traffic_class = cmd->base.dest.traffic_class;
1957+
attr->ah_attr.ah_flags = IB_AH_GRH;
1958+
} else {
1959+
attr->ah_attr.ah_flags = 0;
1960+
}
19511961
attr->ah_attr.dlid = cmd->base.dest.dlid;
19521962
attr->ah_attr.sl = cmd->base.dest.sl;
19531963
attr->ah_attr.src_path_bits = cmd->base.dest.src_path_bits;
19541964
attr->ah_attr.static_rate = cmd->base.dest.static_rate;
1955-
attr->ah_attr.ah_flags = cmd->base.dest.is_global ?
1956-
IB_AH_GRH : 0;
19571965
attr->ah_attr.port_num = cmd->base.dest.port_num;
19581966

1959-
memcpy(attr->alt_ah_attr.grh.dgid.raw, cmd->base.alt_dest.dgid, 16);
1960-
attr->alt_ah_attr.grh.flow_label = cmd->base.alt_dest.flow_label;
1961-
attr->alt_ah_attr.grh.sgid_index = cmd->base.alt_dest.sgid_index;
1962-
attr->alt_ah_attr.grh.hop_limit = cmd->base.alt_dest.hop_limit;
1963-
attr->alt_ah_attr.grh.traffic_class = cmd->base.alt_dest.traffic_class;
1967+
if (cmd->base.alt_dest.is_global) {
1968+
memcpy(attr->alt_ah_attr.grh.dgid.raw,
1969+
cmd->base.alt_dest.dgid, 16);
1970+
attr->alt_ah_attr.grh.flow_label =
1971+
cmd->base.alt_dest.flow_label;
1972+
attr->alt_ah_attr.grh.sgid_index =
1973+
cmd->base.alt_dest.sgid_index;
1974+
attr->alt_ah_attr.grh.hop_limit =
1975+
cmd->base.alt_dest.hop_limit;
1976+
attr->alt_ah_attr.grh.traffic_class =
1977+
cmd->base.alt_dest.traffic_class;
1978+
attr->alt_ah_attr.ah_flags = IB_AH_GRH;
1979+
} else {
1980+
attr->alt_ah_attr.ah_flags = 0;
1981+
}
19641982
attr->alt_ah_attr.dlid = cmd->base.alt_dest.dlid;
19651983
attr->alt_ah_attr.sl = cmd->base.alt_dest.sl;
19661984
attr->alt_ah_attr.src_path_bits = cmd->base.alt_dest.src_path_bits;
19671985
attr->alt_ah_attr.static_rate = cmd->base.alt_dest.static_rate;
1968-
attr->alt_ah_attr.ah_flags = cmd->base.alt_dest.is_global ?
1969-
IB_AH_GRH : 0;
19701986
attr->alt_ah_attr.port_num = cmd->base.alt_dest.port_num;
19711987

19721988
if (qp->real_qp == qp) {
@@ -2531,14 +2547,18 @@ ssize_t ib_uverbs_create_ah(struct ib_uverbs_file *file,
25312547
attr.sl = cmd.attr.sl;
25322548
attr.src_path_bits = cmd.attr.src_path_bits;
25332549
attr.static_rate = cmd.attr.static_rate;
2534-
attr.ah_flags = cmd.attr.is_global ? IB_AH_GRH : 0;
25352550
attr.port_num = cmd.attr.port_num;
2536-
attr.grh.flow_label = cmd.attr.grh.flow_label;
2537-
attr.grh.sgid_index = cmd.attr.grh.sgid_index;
2538-
attr.grh.hop_limit = cmd.attr.grh.hop_limit;
2539-
attr.grh.traffic_class = cmd.attr.grh.traffic_class;
25402551
memset(&attr.dmac, 0, sizeof(attr.dmac));
2541-
memcpy(attr.grh.dgid.raw, cmd.attr.grh.dgid, 16);
2552+
if (cmd.attr.is_global) {
2553+
attr.ah_flags = IB_AH_GRH;
2554+
attr.grh.flow_label = cmd.attr.grh.flow_label;
2555+
attr.grh.sgid_index = cmd.attr.grh.sgid_index;
2556+
attr.grh.hop_limit = cmd.attr.grh.hop_limit;
2557+
attr.grh.traffic_class = cmd.attr.grh.traffic_class;
2558+
memcpy(attr.grh.dgid.raw, cmd.attr.grh.dgid, 16);
2559+
} else {
2560+
attr.ah_flags = 0;
2561+
}
25422562

25432563
ah = pd->device->create_ah(pd, &attr, &udata);
25442564

‎drivers/infiniband/core/uverbs_marshall.c‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,19 @@
3636
void ib_copy_ah_attr_to_user(struct ib_uverbs_ah_attr *dst,
3737
struct ib_ah_attr *src)
3838
{
39-
memcpy(dst->grh.dgid, src->grh.dgid.raw, sizeof(src->grh.dgid));
40-
dst->grh.flow_label = src->grh.flow_label;
41-
dst->grh.sgid_index = src->grh.sgid_index;
42-
dst->grh.hop_limit = src->grh.hop_limit;
43-
dst->grh.traffic_class = src->grh.traffic_class;
4439
memset(&dst->grh.reserved, 0, sizeof(dst->grh.reserved));
4540
dst->dlid = src->dlid;
4641
dst->sl = src->sl;
4742
dst->src_path_bits = src->src_path_bits;
4843
dst->static_rate = src->static_rate;
4944
dst->is_global = src->ah_flags & IB_AH_GRH ? 1 : 0;
45+
if (dst->is_global) {
46+
memcpy(dst->grh.dgid, src->grh.dgid.raw, sizeof(src->grh.dgid));
47+
dst->grh.flow_label = src->grh.flow_label;
48+
dst->grh.sgid_index = src->grh.sgid_index;
49+
dst->grh.hop_limit = src->grh.hop_limit;
50+
dst->grh.traffic_class = src->grh.traffic_class;
51+
}
5052
dst->port_num = src->port_num;
5153
dst->reserved = 0;
5254
}

0 commit comments

Comments
 (0)