tree:   https://git.kernel.org/pub/scm/linux/kernel/git/leon/linux-rdma.git 
rdma-next
head:   e52681bff63423dffd7aeaca15ebdd7c1438f1f9
commit: c5e72baddd5a8870d30bcaed21b0ed2f0b44d365 [34/82] IB/mlx5: Add flow 
counters binding support

New smatch warnings:
drivers/infiniband/hw/mlx5/main.c:3378 _create_flow_rule() error: potential 
null dereference 'handler'.  (kzalloc returns null)
drivers/infiniband/hw/mlx5/main.c:3378 _create_flow_rule() error: we previously 
assumed 'handler' could be null (see line 3282)

Old smatch warnings:
drivers/infiniband/hw/mlx5/main.c:434 mlx5_query_port_roce() error: 
uninitialized symbol 'qkey_viol_cntr'.
drivers/infiniband/hw/mlx5/main.c:509 set_roce_addr() error: we previously 
assumed 'gid' could be null (see line 482)
drivers/infiniband/hw/mlx5/main.c:3688 mlx5_ib_create_flow_action_esp() error: 
uninitialized symbol 'action_flags'.

# 
https://git.kernel.org/pub/scm/linux/kernel/git/leon/linux-rdma.git/commit/?id=c5e72baddd5a8870d30bcaed21b0ed2f0b44d365
git remote add leon-rdma 
https://git.kernel.org/pub/scm/linux/kernel/git/leon/linux-rdma.git
git remote update leon-rdma
git checkout c5e72baddd5a8870d30bcaed21b0ed2f0b44d365
vim +3199 drivers/infiniband/hw/mlx5/main.c

c5e72badd Raed Salem       2018-01-08  3183  
c5e72badd Raed Salem       2018-01-08  3184  #define MAX_COUNTERS_NUM 
(USHRT_MAX / (sizeof(u32) * 2))
c5e72badd Raed Salem       2018-01-08  3185  static int 
flow_counters_set_data(struct ib_counters *ibcounters,
c5e72badd Raed Salem       2018-01-08  3186                               
struct mlx5_ib_create_flow *ucmd)
c5e72badd Raed Salem       2018-01-08  3187  {
c5e72badd Raed Salem       2018-01-08  3188     struct mlx5_ib_mcounters 
*mcounters = to_mcounters(ibcounters);
c5e72badd Raed Salem       2018-01-08  3189     struct 
mlx5_ib_flow_counters_data *cntrs_data = NULL;
c5e72badd Raed Salem       2018-01-08  3190     u32 *desc_data = NULL;
c5e72badd Raed Salem       2018-01-08  3191     bool hw_hndl = false;
c5e72badd Raed Salem       2018-01-08  3192     int ret = 0;
c5e72badd Raed Salem       2018-01-08  3193  
c5e72badd Raed Salem       2018-01-08  3194     if (ucmd && 
ucmd->ncounters_data != 0) {
c5e72badd Raed Salem       2018-01-08  3195             cntrs_data = ucmd->data;
c5e72badd Raed Salem       2018-01-08  3196             if 
(cntrs_data->ncounters  > MAX_COUNTERS_NUM)

Extra space char befreo >

c5e72badd Raed Salem       2018-01-08  3197                     return -EINVAL;
c5e72badd Raed Salem       2018-01-08  3198  
c5e72badd Raed Salem       2018-01-08  3199             desc_data = 
kcalloc(cntrs_data->ncounters,
c5e72badd Raed Salem       2018-01-08  3200                                 
sizeof(u32) * 2,
c5e72badd Raed Salem       2018-01-08  3201                                 
GFP_KERNEL);
c5e72badd Raed Salem       2018-01-08  3202             if (!desc_data)
c5e72badd Raed Salem       2018-01-08  3203                     return  -ENOMEM;
c5e72badd Raed Salem       2018-01-08  3204  
c5e72badd Raed Salem       2018-01-08  3205             if 
(copy_from_user(desc_data,
c5e72badd Raed Salem       2018-01-08  3206                                
u64_to_user_ptr(cntrs_data->counters_data),
c5e72badd Raed Salem       2018-01-08  3207                                
sizeof(u32) * 2 * cntrs_data->ncounters)) {
c5e72badd Raed Salem       2018-01-08  3208                             ret = 
-EFAULT;
c5e72badd Raed Salem       2018-01-08  3209                             goto 
free;
c5e72badd Raed Salem       2018-01-08  3210             }
c5e72badd Raed Salem       2018-01-08  3211     }
c5e72badd Raed Salem       2018-01-08  3212  
c5e72badd Raed Salem       2018-01-08  3213     if (!mcounters->hw_cntrs_hndl) {
c5e72badd Raed Salem       2018-01-08  3214             
mcounters->hw_cntrs_hndl =
c5e72badd Raed Salem       2018-01-08  3215                     (void 
*)mlx5_fc_create(to_mdev(ibcounters->device)->mdev,
c5e72badd Raed Salem       2018-01-08  3216                                     
       false);

No need to cast void pointers.

c5e72badd Raed Salem       2018-01-08  3217             if 
(!mcounters->hw_cntrs_hndl) {
c5e72badd Raed Salem       2018-01-08  3218                     ret = -ENOMEM;
c5e72badd Raed Salem       2018-01-08  3219                     goto free;
c5e72badd Raed Salem       2018-01-08  3220             }
c5e72badd Raed Salem       2018-01-08  3221             hw_hndl = true;
c5e72badd Raed Salem       2018-01-08  3222     }
c5e72badd Raed Salem       2018-01-08  3223  
c5e72badd Raed Salem       2018-01-08  3224     if (desc_data) {
c5e72badd Raed Salem       2018-01-08  3225             /* counters already 
bound to at least one flow */
c5e72badd Raed Salem       2018-01-08  3226             if 
(mcounters->cntrs_max_index) {

I looked at the code and can't figure out what ->cntrs_max_index does.
There is a an integer overflow from the user when we set it:

                cntrs_max_index = desc_data[i + 1] + 1;

desc_data[i + 1] can be UINT_MAX.  I'm not able to publish my static
checker warning for this because these are too common and often
harmless...

c5e72badd Raed Salem       2018-01-08  3227                     ret = -EINVAL;
c5e72badd Raed Salem       2018-01-08  3228                     goto free_hndl;
c5e72badd Raed Salem       2018-01-08  3229             }
c5e72badd Raed Salem       2018-01-08  3230  
c5e72badd Raed Salem       2018-01-08  3231             ret = 
counters_set_description(ibcounters,
c5e72badd Raed Salem       2018-01-08  3232                                     
       MLX5_IB_COUNTERS_FLOW,
c5e72badd Raed Salem       2018-01-08  3233                                     
       desc_data,
c5e72badd Raed Salem       2018-01-08  3234                                     
       cntrs_data->ncounters);
c5e72badd Raed Salem       2018-01-08  3235             if (ret)
c5e72badd Raed Salem       2018-01-08  3236                     goto free_hndl;
c5e72badd Raed Salem       2018-01-08  3237  
c5e72badd Raed Salem       2018-01-08  3238     } else if 
(!mcounters->cntrs_max_index) {
c5e72badd Raed Salem       2018-01-08  3239             /* counters not bound 
yet, must have udata passed */
c5e72badd Raed Salem       2018-01-08  3240                     ret = -EINVAL;
c5e72badd Raed Salem       2018-01-08  3241                     goto free_hndl;

Indented too far.

c5e72badd Raed Salem       2018-01-08  3242     }
c5e72badd Raed Salem       2018-01-08  3243  
c5e72badd Raed Salem       2018-01-08  3244     return 0;
c5e72badd Raed Salem       2018-01-08  3245  
c5e72badd Raed Salem       2018-01-08  3246  free_hndl:
c5e72badd Raed Salem       2018-01-08  3247     if (hw_hndl) {
c5e72badd Raed Salem       2018-01-08  3248             
mlx5_fc_destroy(to_mdev(ibcounters->device)->mdev,
c5e72badd Raed Salem       2018-01-08  3249                             (struct 
mlx5_fc *)mcounters->hw_cntrs_hndl);
c5e72badd Raed Salem       2018-01-08  3250             
mcounters->hw_cntrs_hndl = NULL;
c5e72badd Raed Salem       2018-01-08  3251     }
c5e72badd Raed Salem       2018-01-08  3252  free:
c5e72badd Raed Salem       2018-01-08  3253     kfree(desc_data);
c5e72badd Raed Salem       2018-01-08  3254     return ret;
c5e72badd Raed Salem       2018-01-08  3255  }
c5e72badd Raed Salem       2018-01-08  3256  
a550ddfc5 Yishai Hadas     2017-08-17  3257  static struct mlx5_ib_flow_handler 
*_create_flow_rule(struct mlx5_ib_dev *dev,
038d2ef87 Maor Gottlieb    2016-01-11  3258                                     
              struct mlx5_ib_flow_prio *ft_prio,
dd063d0e6 Maor Gottlieb    2016-08-28  3259                                     
              const struct ib_flow_attr *flow_attr,
a550ddfc5 Yishai Hadas     2017-08-17  3260                                     
              struct mlx5_flow_destination *dst,
c5e72badd Raed Salem       2018-01-08  3261                                     
              u32 underlay_qpn,
c5e72badd Raed Salem       2018-01-08  3262                                     
              struct mlx5_ib_create_flow *ucmd)
038d2ef87 Maor Gottlieb    2016-01-11  3263  {
038d2ef87 Maor Gottlieb    2016-01-11  3264     struct mlx5_flow_table  *ft = 
ft_prio->flow_table;
038d2ef87 Maor Gottlieb    2016-01-11  3265     struct mlx5_ib_flow_handler 
*handler;
075572d4b Boris Pismenny   2017-08-16  3266     struct mlx5_flow_act flow_act = 
{.flow_tag = MLX5_FS_DEFAULT_FLOW_TAG};
c5bb17302 Maor Gottlieb    2016-07-04  3267     struct mlx5_flow_spec *spec;
c5e72badd Raed Salem       2018-01-08  3268     struct mlx5_flow_destination 
dest_arr[2] = {};
c5e72badd Raed Salem       2018-01-08  3269     struct mlx5_flow_destination 
*rule_dst = dest_arr;
dd063d0e6 Maor Gottlieb    2016-08-28  3270     const void *ib_flow = (const 
void *)flow_attr + sizeof(*flow_attr);
038d2ef87 Maor Gottlieb    2016-01-11  3271     unsigned int spec_index;
71c6e8638 Ariel Levkovich  2018-05-13  3272     u32 prev_type = 0;
038d2ef87 Maor Gottlieb    2016-01-11  3273     int err = 0;
c5e72badd Raed Salem       2018-01-08  3274     int dest_num = 0;
802c21256 Aviad Yehezkel   2018-03-28  3275     bool is_egress = 
flow_attr->flags & IB_FLOW_ATTR_FLAGS_EGRESS;
038d2ef87 Maor Gottlieb    2016-01-11  3276  
19cc75249 Ariel Levkovich  2017-04-03  3277     if (!is_valid_attr(dev->mdev, 
flow_attr))
038d2ef87 Maor Gottlieb    2016-01-11  3278             return ERR_PTR(-EINVAL);
038d2ef87 Maor Gottlieb    2016-01-11  3279  
1b9a07ee2 Leon Romanovsky  2017-05-10  3280     spec = kvzalloc(sizeof(*spec), 
GFP_KERNEL);
038d2ef87 Maor Gottlieb    2016-01-11  3281     handler = 
kzalloc(sizeof(*handler), GFP_KERNEL);
c5bb17302 Maor Gottlieb    2016-07-04 @3282     if (!handler || !spec) {
038d2ef87 Maor Gottlieb    2016-01-11  3283             err = -ENOMEM;
038d2ef87 Maor Gottlieb    2016-01-11  3284             goto free;
038d2ef87 Maor Gottlieb    2016-01-11  3285     }
038d2ef87 Maor Gottlieb    2016-01-11  3286  
038d2ef87 Maor Gottlieb    2016-01-11  3287     INIT_LIST_HEAD(&handler->list);
c5e72badd Raed Salem       2018-01-08  3288     if (dst) {
c5e72badd Raed Salem       2018-01-08  3289             memcpy(&dest_arr[0], 
dst, sizeof(*dst));
c5e72badd Raed Salem       2018-01-08  3290             dest_num++;
c5e72badd Raed Salem       2018-01-08  3291     }
038d2ef87 Maor Gottlieb    2016-01-11  3292  
038d2ef87 Maor Gottlieb    2016-01-11  3293     for (spec_index = 0; spec_index 
< flow_attr->num_of_specs; spec_index++) {
19cc75249 Ariel Levkovich  2017-04-03  3294             err = 
parse_flow_attr(dev->mdev, spec->match_criteria,
a22ed86cf Slava Shwartsman 2017-04-03  3295                                   
spec->match_value,
71c6e8638 Ariel Levkovich  2018-05-13  3296                                   
ib_flow, flow_attr, &flow_act,
71c6e8638 Ariel Levkovich  2018-05-13  3297                                   
prev_type);
038d2ef87 Maor Gottlieb    2016-01-11  3298             if (err < 0)
038d2ef87 Maor Gottlieb    2016-01-11  3299                     goto free;
038d2ef87 Maor Gottlieb    2016-01-11  3300  
71c6e8638 Ariel Levkovich  2018-05-13  3301             prev_type = ((union 
ib_flow_spec *)ib_flow)->type;
038d2ef87 Maor Gottlieb    2016-01-11  3302             ib_flow += ((union 
ib_flow_spec *)ib_flow)->size;
038d2ef87 Maor Gottlieb    2016-01-11  3303     }
038d2ef87 Maor Gottlieb    2016-01-11  3304  
a550ddfc5 Yishai Hadas     2017-08-17  3305     if 
(!flow_is_multicast_only(flow_attr))
a550ddfc5 Yishai Hadas     2017-08-17  3306             set_underlay_qp(dev, 
spec, underlay_qpn);
a550ddfc5 Yishai Hadas     2017-08-17  3307  
018a94eec Mark Bloch       2018-01-16  3308     if (dev->rep) {
018a94eec Mark Bloch       2018-01-16  3309             void *misc;
018a94eec Mark Bloch       2018-01-16  3310  
018a94eec Mark Bloch       2018-01-16  3311             misc = 
MLX5_ADDR_OF(fte_match_param, spec->match_value,
018a94eec Mark Bloch       2018-01-16  3312                                 
misc_parameters);
018a94eec Mark Bloch       2018-01-16  3313             
MLX5_SET(fte_match_set_misc, misc, source_port,
018a94eec Mark Bloch       2018-01-16  3314                      
dev->rep->vport);
018a94eec Mark Bloch       2018-01-16  3315             misc = 
MLX5_ADDR_OF(fte_match_param, spec->match_criteria,
018a94eec Mark Bloch       2018-01-16  3316                                 
misc_parameters);
018a94eec Mark Bloch       2018-01-16  3317             
MLX5_SET_TO_ONES(fte_match_set_misc, misc, source_port);
018a94eec Mark Bloch       2018-01-16  3318     }
018a94eec Mark Bloch       2018-01-16  3319  
466fa6d2e Maor Gottlieb    2016-08-30  3320     spec->match_criteria_enable = 
get_match_criteria_enable(spec->match_criteria);
802c21256 Aviad Yehezkel   2018-03-28  3321  
802c21256 Aviad Yehezkel   2018-03-28  3322     if (is_egress &&
802c21256 Aviad Yehezkel   2018-03-28  3323         !is_valid_spec(dev->mdev, 
spec, &flow_act, is_egress)) {
802c21256 Aviad Yehezkel   2018-03-28  3324             err = -EINVAL;
802c21256 Aviad Yehezkel   2018-03-28  3325             goto free;
802c21256 Aviad Yehezkel   2018-03-28  3326     }
802c21256 Aviad Yehezkel   2018-03-28  3327  
c5e72badd Raed Salem       2018-01-08  3328     if (flow_act.action & 
MLX5_FLOW_CONTEXT_ACTION_COUNT) {
c5e72badd Raed Salem       2018-01-08  3329             err = 
flow_counters_set_data(flow_act.counters, ucmd);
c5e72badd Raed Salem       2018-01-08  3330             if (err)
c5e72badd Raed Salem       2018-01-08  3331                     goto free;
c5e72badd Raed Salem       2018-01-08  3332  
c5e72badd Raed Salem       2018-01-08  3333             handler->ibcounters = 
flow_act.counters;
c5e72badd Raed Salem       2018-01-08  3334             dest_arr[dest_num].type 
=
c5e72badd Raed Salem       2018-01-08  3335                     
MLX5_FLOW_DESTINATION_TYPE_COUNTER;
c5e72badd Raed Salem       2018-01-08  3336             
dest_arr[dest_num].counter =
c5e72badd Raed Salem       2018-01-08  3337                     (struct mlx5_fc 
*)(to_mcounters(flow_act.counters)->hw_cntrs_hndl);
c5e72badd Raed Salem       2018-01-08  3338             dest_num++;
c5e72badd Raed Salem       2018-01-08  3339     }
c5e72badd Raed Salem       2018-01-08  3340  
075572d4b Boris Pismenny   2017-08-16  3341     if (flow_act.action & 
MLX5_FLOW_CONTEXT_ACTION_DROP) {
c5e72badd Raed Salem       2018-01-08  3342             if (!(flow_act.action & 
MLX5_FLOW_CONTEXT_ACTION_COUNT)) {
a22ed86cf Slava Shwartsman 2017-04-03  3343                     rule_dst = NULL;
a22ed86cf Slava Shwartsman 2017-04-03  3344                     dest_num = 0;
c5e72badd Raed Salem       2018-01-08  3345             }
a22ed86cf Slava Shwartsman 2017-04-03  3346     } else {
802c21256 Aviad Yehezkel   2018-03-28  3347             if (is_egress)
802c21256 Aviad Yehezkel   2018-03-28  3348                     flow_act.action 
|= MLX5_FLOW_CONTEXT_ACTION_ALLOW;
802c21256 Aviad Yehezkel   2018-03-28  3349             else
802c21256 Aviad Yehezkel   2018-03-28  3350                     flow_act.action 
|=
c5e72badd Raed Salem       2018-01-08  3351                             
dest_num ?  MLX5_FLOW_CONTEXT_ACTION_FWD_DEST :
35d190113 Maor Gottlieb    2016-03-07  3352                                     
MLX5_FLOW_CONTEXT_ACTION_FWD_NEXT_PRIO;
a22ed86cf Slava Shwartsman 2017-04-03  3353     }
2ac693f99 Moses Reuben     2017-01-18  3354  
a9db0ecf1 Matan Barak      2017-08-16  3355     if (flow_act.has_flow_tag &&
2ac693f99 Moses Reuben     2017-01-18  3356         (flow_attr->type == 
IB_FLOW_ATTR_ALL_DEFAULT ||
2ac693f99 Moses Reuben     2017-01-18  3357          flow_attr->type == 
IB_FLOW_ATTR_MC_DEFAULT)) {
2ac693f99 Moses Reuben     2017-01-18  3358             mlx5_ib_warn(dev, "Flow 
tag %u and attribute type %x isn't allowed in leftovers\n",
075572d4b Boris Pismenny   2017-08-16  3359                          
flow_act.flow_tag, flow_attr->type);
2ac693f99 Moses Reuben     2017-01-18  3360             err = -EINVAL;
2ac693f99 Moses Reuben     2017-01-18  3361             goto free;
2ac693f99 Moses Reuben     2017-01-18  3362     }
74491de93 Mark Bloch       2016-08-31  3363     handler->rule = 
mlx5_add_flow_rules(ft, spec,
66958ed90 Hadar Hen Zion   2016-11-07  3364                                     
    &flow_act,
a22ed86cf Slava Shwartsman 2017-04-03  3365                                     
    rule_dst, dest_num);
038d2ef87 Maor Gottlieb    2016-01-11  3366  
038d2ef87 Maor Gottlieb    2016-01-11  3367     if (IS_ERR(handler->rule)) {
038d2ef87 Maor Gottlieb    2016-01-11  3368             err = 
PTR_ERR(handler->rule);
038d2ef87 Maor Gottlieb    2016-01-11  3369             goto free;
038d2ef87 Maor Gottlieb    2016-01-11  3370     }
038d2ef87 Maor Gottlieb    2016-01-11  3371  
d9d4980af Maor Gottlieb    2016-08-28  3372     ft_prio->refcount++;
5497adc63 Maor Gottlieb    2016-08-28  3373     handler->prio = ft_prio;
038d2ef87 Maor Gottlieb    2016-01-11  3374  
038d2ef87 Maor Gottlieb    2016-01-11  3375     ft_prio->flow_table = ft;
038d2ef87 Maor Gottlieb    2016-01-11  3376  free:
c5e72badd Raed Salem       2018-01-08  3377     if (err) {
c5e72badd Raed Salem       2018-01-08 @3378             if (handler->ibcounters 
&&
c5e72badd Raed Salem       2018-01-08  3379                 
atomic_read(&handler->ibcounters->usecnt) == 1)
c5e72badd Raed Salem       2018-01-08  3380                     
counters_clear_description(handler->ibcounters);
038d2ef87 Maor Gottlieb    2016-01-11  3381             kfree(handler);
c5e72badd Raed Salem       2018-01-08  3382     }
c5bb17302 Maor Gottlieb    2016-07-04  3383     kvfree(spec);
038d2ef87 Maor Gottlieb    2016-01-11  3384     return err ? ERR_PTR(err) : 
handler;
038d2ef87 Maor Gottlieb    2016-01-11  3385  }
038d2ef87 Maor Gottlieb    2016-01-11  3386  

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
_______________________________________________
kbuild mailing list
kbuild@lists.01.org
https://lists.01.org/mailman/listinfo/kbuild

Reply via email to