Skip to contentSkip to conversation

RDMA/rtrs-srv: suppress warnings passing zero to 'PTR_ERR'

PATCH In review Jack Wang 2 participants 5 messages Feb 16, 2021

Subsystems (2)
lore
Share & tools
lore

Jack Wang

author
#0 lore raw

PATCH 1/1 RDMA/rtrs-srv: suppress warnings passing zero to 'PTR_ERR'

smatch warnings:
drivers/infiniband/ulp/rtrs/rtrs-srv.c:1805 rtrs_rdma_connect() warn: passing zero to 'PTR_ERR'

Smatch seems confused by the refcount_read condition, so just treat it seperately.

Fixes f0751419d3a1 ("RDMA/rtrs: Only allow addition of path to an already established session")
---
 drivers/infiniband/ulp/rtrs/rtrs-srv.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/infiniband/ulp/rtrs/rtrs-srv.c +6 -2
index eb17c3a08810..2f6d665bea90 100644
@@ -1799,12 +1799,16 @@ static int rtrs_rdma_connect(struct rdma_cm_id *cm_id,
 	}
 	recon_cnt = le16_to_cpu(msg->recon_cnt);
 	srv = get_or_create_srv(ctx, &msg->paths_uuid, msg->first_conn);
+	if (IS_ERR(srv)) {
+		err = PTR_ERR(srv);
+		goto reject_w_err;
+	}
 	/*
 	 * "refcount == 0" happens if a previous thread calls get_or_create_srv
 	 * allocate srv, but chunks of srv are not allocated yet.
 	 */
-	if (IS_ERR(srv) || refcount_read(&srv->refcount) == 0) {
-		err = PTR_ERR(srv);
+	if (refcount_read(&srv->refcount) == 0) {
+		err = -EBUSY;
 		goto reject_w_err;
 	}
 	mutex_lock(&srv->paths_mutex);
Signature · 1 line
2.25.1
#1 lore raw
Quoted 23 lines · Jack Wang

smatch warnings:
drivers/infiniband/ulp/rtrs/rtrs-srv.c:1805 rtrs_rdma_connect() warn: passing zero to 'PTR_ERR'

Smatch seems confused by the refcount_read condition, so just treat it seperately.

Fixes f0751419d3a1 ("RDMA/rtrs: Only allow addition of path to an already established session")
---
 drivers/infiniband/ulp/rtrs/rtrs-srv.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/infiniband/ulp/rtrs/rtrs-srv.c +1 -0
index eb17c3a08810..2f6d665bea90 100644
@@ -1799,12 +1799,16 @@ static int rtrs_rdma_connect(struct rdma_cm_id *cm_id,
 	}
 	recon_cnt = le16_to_cpu(msg->recon_cnt);
 	srv = get_or_create_srv(ctx, &msg->paths_uuid, msg->first_conn);
+	if (IS_ERR(srv)) {

drivers/infiniband/ulp/rtrs/rtrs-srv.c static int rtrs_rdma_connect(struct rdma_cm_id *cm_id, · line 1810

Quoted 10 lines
drivers/infiniband/ulp/rtrs/rtrs-srv.c +4 -2
+		err = PTR_ERR(srv);
+		goto reject_w_err;
+	}
 	/*
 	 * "refcount == 0" happens if a previous thread calls get_or_create_srv
 	 * allocate srv, but chunks of srv are not allocated yet.
 	 */
-	if (IS_ERR(srv) || refcount_read(&srv->refcount) == 0) {
-		err = PTR_ERR(srv);
+	if (refcount_read(&srv->refcount) == 0) {

I would say that "list_add(&srv->ctx_list, &ctx->srv_list);" line in the get_or_create_srv() is performed too early, relying on zero in the refcount doesn't look great.

Thanks

author
#2 lore raw

Hi Leon,

Quoted 30 lines · Leon Romanovsky
Quoted 28 lines · Jack Wang

smatch warnings:
drivers/infiniband/ulp/rtrs/rtrs-srv.c:1805 rtrs_rdma_connect() warn: passing zero to 'PTR_ERR'

Smatch seems confused by the refcount_read condition, so just treat it seperately.

Fixes f0751419d3a1 ("RDMA/rtrs: Only allow addition of path to an already established session")
---
 drivers/infiniband/ulp/rtrs/rtrs-srv.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/infiniband/ulp/rtrs/rtrs-srv.c +4 -0
index eb17c3a08810..2f6d665bea90 100644
@@ -1799,12 +1799,16 @@ static int rtrs_rdma_connect(struct rdma_cm_id *cm_id,
      }
      recon_cnt = le16_to_cpu(msg->recon_cnt);
      srv = get_or_create_srv(ctx, &msg->paths_uuid, msg->first_conn);
+     if (IS_ERR(srv)) {
+             err = PTR_ERR(srv);
+             goto reject_w_err;
+     }
      /*
       * "refcount == 0" happens if a previous thread calls get_or_create_srv
Quoted 8 lines

drivers/infiniband/ulp/rtrs/rtrs-srv.c static int rtrs_rdma_connect(struct rdma_cm_id *cm_id, · line 1810

Quoted 5 lines
drivers/infiniband/ulp/rtrs/rtrs-srv.c +1 -2
       * allocate srv, but chunks of srv are not allocated yet.
       */
-     if (IS_ERR(srv) || refcount_read(&srv->refcount) == 0) {
-             err = PTR_ERR(srv);
+     if (refcount_read(&srv->refcount) == 0) {

I would say that "list_add(&srv->ctx_list, &ctx->srv_list);" line in the get_or_create_srv() is performed too early,

Moving list_add down to the end was the initial code, but we noticed the memory allocation could take quite
some time when system under memory pressure, hence we changed it in d715ff8acbd5 ("RDMA/rtrs-srv: Don't guard the whole __alloc_srv with srv_mutex")

Thanks for the comment.

#3 lore raw
Quoted 40 lines · Jinpu Wang

Hi Leon,

Quoted 30 lines · Leon Romanovsky
Quoted 28 lines · Jack Wang

smatch warnings:
drivers/infiniband/ulp/rtrs/rtrs-srv.c:1805 rtrs_rdma_connect() warn: passing zero to 'PTR_ERR'

Smatch seems confused by the refcount_read condition, so just treat it seperately.

Fixes f0751419d3a1 ("RDMA/rtrs: Only allow addition of path to an already established session")
---
 drivers/infiniband/ulp/rtrs/rtrs-srv.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/infiniband/ulp/rtrs/rtrs-srv.c +4 -0
index eb17c3a08810..2f6d665bea90 100644
@@ -1799,12 +1799,16 @@ static int rtrs_rdma_connect(struct rdma_cm_id *cm_id,
      }
      recon_cnt = le16_to_cpu(msg->recon_cnt);
      srv = get_or_create_srv(ctx, &msg->paths_uuid, msg->first_conn);
+     if (IS_ERR(srv)) {
+             err = PTR_ERR(srv);
+             goto reject_w_err;
+     }
      /*
       * "refcount == 0" happens if a previous thread calls get_or_create_srv
Quoted 8 lines

drivers/infiniband/ulp/rtrs/rtrs-srv.c static int rtrs_rdma_connect(struct rdma_cm_id *cm_id, · line 1810

Quoted 5 lines
drivers/infiniband/ulp/rtrs/rtrs-srv.c +1 -2
       * allocate srv, but chunks of srv are not allocated yet.
       */
-     if (IS_ERR(srv) || refcount_read(&srv->refcount) == 0) {
-             err = PTR_ERR(srv);
+     if (refcount_read(&srv->refcount) == 0) {

I would say that "list_add(&srv->ctx_list, &ctx->srv_list);" line in the get_or_create_srv() is performed too early,

Quoted 5 lines

Moving list_add down to the end was the initial code, but we noticed the memory allocation could take quite
some time when system under memory pressure, hence we changed it in d715ff8acbd5 ("RDMA/rtrs-srv: Don't guard the whole __alloc_srv with srv_mutex")

You don't need to hold lock during allocation, only during search in the list.

Thanks

Quoted 2 lines

Thanks for the comment.

author
#4 lore raw
Quoted 42 lines · Leon Romanovsky
Quoted 40 lines · Jinpu Wang

Hi Leon,

Quoted 38 lines · Leon Romanovsky
Quoted 23 lines · Jack Wang

smatch warnings:
drivers/infiniband/ulp/rtrs/rtrs-srv.c:1805 rtrs_rdma_connect() warn: passing zero to 'PTR_ERR'

Smatch seems confused by the refcount_read condition, so just treat it seperately.

Fixes f0751419d3a1 ("RDMA/rtrs: Only allow addition of path to an already established session")
---
 drivers/infiniband/ulp/rtrs/rtrs-srv.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/infiniband/ulp/rtrs/rtrs-srv.c +1 -0
index eb17c3a08810..2f6d665bea90 100644
@@ -1799,12 +1799,16 @@ static int rtrs_rdma_connect(struct rdma_cm_id *cm_id,
      }
      recon_cnt = le16_to_cpu(msg->recon_cnt);
      srv = get_or_create_srv(ctx, &msg->paths_uuid, msg->first_conn);
+     if (IS_ERR(srv)) {

drivers/infiniband/ulp/rtrs/rtrs-srv.c static int rtrs_rdma_connect(struct rdma_cm_id *cm_id, · line 1810

Quoted 10 lines
drivers/infiniband/ulp/rtrs/rtrs-srv.c +4 -2
+             err = PTR_ERR(srv);
+             goto reject_w_err;
+     }
      /*
       * "refcount == 0" happens if a previous thread calls get_or_create_srv
       * allocate srv, but chunks of srv are not allocated yet.
       */
-     if (IS_ERR(srv) || refcount_read(&srv->refcount) == 0) {
-             err = PTR_ERR(srv);
+     if (refcount_read(&srv->refcount) == 0) {

I would say that "list_add(&srv->ctx_list, &ctx->srv_list);" line in the get_or_create_srv() is performed too early,

Quoted 7 lines
Quoted 5 lines

Moving list_add down to the end was the initial code, but we noticed the memory allocation could take quite
some time when system under memory pressure, hence we changed it in d715ff8acbd5 ("RDMA/rtrs-srv: Don't guard the whole __alloc_srv with srv_mutex")

You don't need to hold lock during allocation, only during search in the list.

Thanks, I will try and test.

Quoted 5 lines

Thanks

Quoted 2 lines

Thanks for the comment.