Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Dasaratharaman Chandramouli and committed by
Doug Ledford
4ba66093 cf0b9395

+57 -35
+50 -30
drivers/infiniband/core/uverbs_cmd.c
··· 1847 1847 resp.alt_port_num = attr->alt_port_num; 1848 1848 resp.alt_timeout = attr->alt_timeout; 1849 1849 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; 1855 1850 resp.dest.dlid = attr->ah_attr.dlid; 1856 1851 resp.dest.sl = attr->ah_attr.sl; 1857 1852 resp.dest.src_path_bits = attr->ah_attr.src_path_bits; 1858 1853 resp.dest.static_rate = attr->ah_attr.static_rate; 1859 1854 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 + } 1860 1862 resp.dest.port_num = attr->ah_attr.port_num; 1861 1863 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; 1867 1864 resp.alt_dest.dlid = attr->alt_ah_attr.dlid; 1868 1865 resp.alt_dest.sl = attr->alt_ah_attr.sl; 1869 1866 resp.alt_dest.src_path_bits = attr->alt_ah_attr.src_path_bits; 1870 1867 resp.alt_dest.static_rate = attr->alt_ah_attr.static_rate; 1871 1868 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 + } 1872 1877 resp.alt_dest.port_num = attr->alt_ah_attr.port_num; 1873 1878 1874 1879 resp.max_send_wr = init_attr->cap.max_send_wr; ··· 1948 1943 attr->alt_timeout = cmd->base.alt_timeout; 1949 1944 attr->rate_limit = cmd->rate_limit; 1950 1945 1951 - memcpy(attr->ah_attr.grh.dgid.raw, cmd->base.dest.dgid, 16); 1952 - attr->ah_attr.grh.flow_label = cmd->base.dest.flow_label; 1953 - attr->ah_attr.grh.sgid_index = cmd->base.dest.sgid_index; 1954 - attr->ah_attr.grh.hop_limit = cmd->base.dest.hop_limit; 1955 - attr->ah_attr.grh.traffic_class = cmd->base.dest.traffic_class; 1946 + if (cmd->base.dest.is_global) { 1947 + memcpy(attr->ah_attr.grh.dgid.raw, cmd->base.dest.dgid, 16); 1948 + attr->ah_attr.grh.flow_label = cmd->base.dest.flow_label; 1949 + attr->ah_attr.grh.sgid_index = cmd->base.dest.sgid_index; 1950 + attr->ah_attr.grh.hop_limit = cmd->base.dest.hop_limit; 1951 + attr->ah_attr.grh.traffic_class = cmd->base.dest.traffic_class; 1952 + attr->ah_attr.ah_flags = IB_AH_GRH; 1953 + } else { 1954 + attr->ah_attr.ah_flags = 0; 1955 + } 1956 1956 attr->ah_attr.dlid = cmd->base.dest.dlid; 1957 1957 attr->ah_attr.sl = cmd->base.dest.sl; 1958 1958 attr->ah_attr.src_path_bits = cmd->base.dest.src_path_bits; 1959 1959 attr->ah_attr.static_rate = cmd->base.dest.static_rate; 1960 - attr->ah_attr.ah_flags = cmd->base.dest.is_global ? 1961 - IB_AH_GRH : 0; 1962 1960 attr->ah_attr.port_num = cmd->base.dest.port_num; 1963 1961 1964 - memcpy(attr->alt_ah_attr.grh.dgid.raw, cmd->base.alt_dest.dgid, 16); 1965 - attr->alt_ah_attr.grh.flow_label = cmd->base.alt_dest.flow_label; 1966 - attr->alt_ah_attr.grh.sgid_index = cmd->base.alt_dest.sgid_index; 1967 - attr->alt_ah_attr.grh.hop_limit = cmd->base.alt_dest.hop_limit; 1968 - attr->alt_ah_attr.grh.traffic_class = cmd->base.alt_dest.traffic_class; 1962 + if (cmd->base.alt_dest.is_global) { 1963 + memcpy(attr->alt_ah_attr.grh.dgid.raw, 1964 + cmd->base.alt_dest.dgid, 16); 1965 + attr->alt_ah_attr.grh.flow_label = 1966 + cmd->base.alt_dest.flow_label; 1967 + attr->alt_ah_attr.grh.sgid_index = 1968 + cmd->base.alt_dest.sgid_index; 1969 + attr->alt_ah_attr.grh.hop_limit = 1970 + cmd->base.alt_dest.hop_limit; 1971 + attr->alt_ah_attr.grh.traffic_class = 1972 + cmd->base.alt_dest.traffic_class; 1973 + attr->alt_ah_attr.ah_flags = IB_AH_GRH; 1974 + } else { 1975 + attr->alt_ah_attr.ah_flags = 0; 1976 + } 1969 1977 attr->alt_ah_attr.dlid = cmd->base.alt_dest.dlid; 1970 1978 attr->alt_ah_attr.sl = cmd->base.alt_dest.sl; 1971 1979 attr->alt_ah_attr.src_path_bits = cmd->base.alt_dest.src_path_bits; 1972 1980 attr->alt_ah_attr.static_rate = cmd->base.alt_dest.static_rate; 1973 - attr->alt_ah_attr.ah_flags = cmd->base.alt_dest.is_global ? 1974 - IB_AH_GRH : 0; 1975 1981 attr->alt_ah_attr.port_num = cmd->base.alt_dest.port_num; 1976 1982 1977 1983 if (qp->real_qp == qp) { ··· 2547 2531 attr.sl = cmd.attr.sl; 2548 2532 attr.src_path_bits = cmd.attr.src_path_bits; 2549 2533 attr.static_rate = cmd.attr.static_rate; 2550 - attr.ah_flags = cmd.attr.is_global ? IB_AH_GRH : 0; 2551 2534 attr.port_num = cmd.attr.port_num; 2552 - attr.grh.flow_label = cmd.attr.grh.flow_label; 2553 - attr.grh.sgid_index = cmd.attr.grh.sgid_index; 2554 - attr.grh.hop_limit = cmd.attr.grh.hop_limit; 2555 - attr.grh.traffic_class = cmd.attr.grh.traffic_class; 2556 2535 memset(&attr.dmac, 0, sizeof(attr.dmac)); 2557 - memcpy(attr.grh.dgid.raw, cmd.attr.grh.dgid, 16); 2536 + if (cmd.attr.is_global) { 2537 + attr.ah_flags = IB_AH_GRH; 2538 + attr.grh.flow_label = cmd.attr.grh.flow_label; 2539 + attr.grh.sgid_index = cmd.attr.grh.sgid_index; 2540 + attr.grh.hop_limit = cmd.attr.grh.hop_limit; 2541 + attr.grh.traffic_class = cmd.attr.grh.traffic_class; 2542 + memcpy(attr.grh.dgid.raw, cmd.attr.grh.dgid, 16); 2543 + } else { 2544 + attr.ah_flags = 0; 2545 + } 2558 2546 2559 2547 ah = pd->device->create_ah(pd, &attr, &udata); 2560 2548
+7 -5
drivers/infiniband/core/uverbs_marshall.c
··· 36 36 void ib_copy_ah_attr_to_user(struct ib_uverbs_ah_attr *dst, 37 37 struct ib_ah_attr *src) 38 38 { 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; 44 39 memset(&dst->grh.reserved, 0, sizeof(dst->grh.reserved)); 45 40 dst->dlid = src->dlid; 46 41 dst->sl = src->sl; 47 42 dst->src_path_bits = src->src_path_bits; 48 43 dst->static_rate = src->static_rate; 49 44 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 + } 50 52 dst->port_num = src->port_num; 51 53 dst->reserved = 0; 52 54 }