Skip to contentSkip to conversation

Skip holes in GID tables

PATCH In review Leon Romanovsky 3 participants 9 messages Nov 22, 2021 – Dec 9, 2021 InfiniBand

lore
Share & tools
lore
#0 lore raw

cover Skip holes in GID tables

From: Leon Romanovsky <[email protected]>

Hi,

This short series extends rdma_query_gid() callers to skip holes in GID tables.

Avihai Horon (3):
RDMA/core: Modify rdma_query_gid() to return accurate error codes RDMA/core: Let ib_find_gid() continue search even after empty entry RDMA/cma: Let cma_resolve_ib_dev() continue search even after empty
entry

 drivers/infiniband/core/cache.c  |  8 ++++++--
 drivers/infiniband/core/cma.c    | 14 +++++++++++---
 drivers/infiniband/core/device.c |  3 +++
 3 files changed, 20 insertions(+), 5 deletions(-)
Signature · 1 line
2.33.1
#1 lore raw

PATCH 1/3 RDMA/core: Modify rdma_query_gid() to return accurate error codes

From: Avihai Horon <[email protected]>

Modify rdma_query_gid() to return -ENOENT for empty entries. This will make error reporting more accurate and will be used in next patches.

---
 drivers/infiniband/core/cache.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/infiniband/core/cache.c +6 -2
index 0c98dd3dee67..dd66f1a6e792 100644
@@ -963,9 +963,13 @@ int rdma_query_gid(struct ib_device *device, u32 port_num,
 	table = rdma_gid_table(device, port_num);
 	read_lock_irqsave(&table->rwlock, flags);
 
-	if (index < 0 || index >= table->sz ||
-	    !is_gid_entry_valid(table->data_vec[index]))
+	if (index < 0 || index >= table->sz)
+		goto done;
+
+	if (!is_gid_entry_valid(table->data_vec[index])) {
+		res = -ENOENT;
 		goto done;
+	}
 
 	memcpy(gid, &table->data_vec[index]->attr.gid, sizeof(*gid));
 	res = 0;
Signature · 1 line
2.33.1
maintainer
#2 lore raw

Re: [PATCH rdma-next 1/3] RDMA/core: Modify rdma_query_gid() to return accurate error codes

Quoted 17 lines · Leon Romanovsky

From: Avihai Horon <[email protected]>

Modify rdma_query_gid() to return -ENOENT for empty entries. This will make error reporting more accurate and will be used in next patches.

 drivers/infiniband/core/cache.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/infiniband/core/cache.c +1 -0
index 0c98dd3dee67..dd66f1a6e792 100644
+++ b/drivers/infiniband/core/cache.c
@@ -963,9 +963,13 @@ int rdma_query_gid(struct ib_device *device, u32 port_num,
 	table = rdma_gid_table(device, port_num);
 	read_lock_irqsave(&table->rwlock, flags);

drivers/infiniband/core/cache.c int rdma_query_gid(struct ib_device *device, u32 port_num, · line 972

Quoted 10 lines
drivers/infiniband/core/cache.c +6 -2
 
-	if (index < 0 || index >= table->sz ||
-	    !is_gid_entry_valid(table->data_vec[index]))
+	if (index < 0 || index >= table->sz)
+		goto done;
+
+	if (!is_gid_entry_valid(table->data_vec[index])) {
+		res = -ENOENT;
 		goto done;
+	}

Please get rid of the default assignment to res so this code is all consistent

@@ -955,7 +955,7 @@ int rdma_query_gid(struct ib_device *device, u32 port_num,

 {
        struct ib_gid_table *table;
        unsigned long flags;

- int res = -EINVAL;
+ int res;

if (!rdma_is_port_valid(device, port_num))
return -EINVAL;
@@ -963,9 +963,15 @@ int rdma_query_gid(struct ib_device *device, u32 port_num,

        table = rdma_gid_table(device, port_num);
        read_lock_irqsave(&table->rwlock, flags);

- if (index < 0 || index >= table->sz ||
- !is_gid_entry_valid(table->data_vec[index]))
+ if (index < 0 || index >= table->sz) {

+               res = -EINVAL;
                goto done;

+ }
+
+ if (!is_gid_entry_valid(table->data_vec[index])) {
+ res = -ENOENT;
+ goto done;
+ }

Jason

#3 lore raw

PATCH 2/3 RDMA/core: Let ib_find_gid() continue search even after empty entry

In reply to Leon Romanovsky

From: Avihai Horon <[email protected]>

Currently, ib_find_gid() will stop searching after encountering the first empty GID table entry. This behavior is wrong since neither IB nor RoCE spec enforce tightly packed GID tables.

For example, when a valid GID entry exists at index N, and if a GID entry is empty at index N-1, ib_find_gid() will fail to find the valid entry.

Fix it by making ib_find_gid() continue searching even after encountering missing entries.

Fixes 5eb620c81ce3 ("IB/core: Add helpers for uncached GID and P_Key searches")
---
 drivers/infiniband/core/device.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/infiniband/core/device.c +3 -0
index 22a4adda7981..b5d8443030d4 100644
@@ -2460,8 +2460,11 @@ int ib_find_gid(struct ib_device *device, union ib_gid *gid,
 		for (i = 0; i < device->port_data[port].immutable.gid_tbl_len;
 		     ++i) {
 			ret = rdma_query_gid(device, port, i, &tmp_gid);
+			if (ret == -ENOENT)
+				continue;
 			if (ret)
 				return ret;
+
 			if (!memcmp(&tmp_gid, gid, sizeof *gid)) {
 				*port_num = port;
 				if (index)
Signature · 1 line
2.33.1
maintainer
#4 lore raw

Re: [PATCH rdma-next 2/3] RDMA/core: Let ib_find_gid() continue search even after empty entry

Quoted 24 lines · Leon Romanovsky

From: Avihai Horon <[email protected]>

Currently, ib_find_gid() will stop searching after encountering the first empty GID table entry. This behavior is wrong since neither IB nor RoCE spec enforce tightly packed GID tables.

For example, when a valid GID entry exists at index N, and if a GID entry is empty at index N-1, ib_find_gid() will fail to find the valid entry.

Fix it by making ib_find_gid() continue searching even after encountering missing entries.

Fixes 5eb620c81ce3 ("IB/core: Add helpers for uncached GID and P_Key searches")
 drivers/infiniband/core/device.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/infiniband/core/device.c +1 -0
index 22a4adda7981..b5d8443030d4 100644
+++ b/drivers/infiniband/core/device.c

drivers/infiniband/core/device.c int ib_find_gid(struct ib_device *device, union ib_gid *gid, · line 2466

Quoted 7 lines
drivers/infiniband/core/device.c +2 -0
@@ -2460,8 +2460,11 @@ int ib_find_gid(struct ib_device *device, union ib_gid *gid,
 		for (i = 0; i < device->port_data[port].immutable.gid_tbl_len;
 		     ++i) {
 			ret = rdma_query_gid(device, port, i, &tmp_gid);
+			if (ret == -ENOENT)
+				continue;
 			if (ret)
 				return ret;

There is no return code from rdma_query_gid that means stop searching, so just write

if (ret)
continue

Jason

#5 lore raw

Re: [PATCH rdma-next 2/3] RDMA/core: Let ib_find_gid() continue search even after empty entry

Quoted 21 lines · Jason Gunthorpe
Quoted 20 lines · Leon Romanovsky

From: Avihai Horon <[email protected]>

Currently, ib_find_gid() will stop searching after encountering the first empty GID table entry. This behavior is wrong since neither IB nor RoCE spec enforce tightly packed GID tables.

For example, when a valid GID entry exists at index N, and if a GID entry is empty at index N-1, ib_find_gid() will fail to find the valid entry.

Fix it by making ib_find_gid() continue searching even after encountering missing entries.

Fixes 5eb620c81ce3 ("IB/core: Add helpers for uncached GID and P_Key searches")
 drivers/infiniband/core/device.c | 3 +++
 1 file changed, 3 insertions(+)
Quoted 13 lines

drivers/infiniband/core/device.c int ib_find_gid(struct ib_device *device, union ib_gid *gid, · line 2466

Quoted 11 lines
drivers/infiniband/core/device.c +3 -0
index 22a4adda7981..b5d8443030d4 100644
+++ b/drivers/infiniband/core/device.c
@@ -2460,8 +2460,11 @@ int ib_find_gid(struct ib_device *device, union ib_gid *gid,
 		for (i = 0; i < device->port_data[port].immutable.gid_tbl_len;
 		     ++i) {
 			ret = rdma_query_gid(device, port, i, &tmp_gid);
+			if (ret == -ENOENT)
+				continue;
 			if (ret)
 				return ret;

There is no return code from rdma_query_gid that means stop searching,

In rdma_query_gid() any error stopped searching, and here we continue same behaviour as before. You can argue that this function can't really get illegal parameters and it never returns -EINVAL, but someone needs to check all callers that this is true.

Quoted 4 lines

so just write

if (ret)
continue

As long as we don't delete input validity checks, it is not correct.

Thanks

Quoted 2 lines

Jason

#6 lore raw

Re: [PATCH rdma-next 2/3] RDMA/core: Let ib_find_gid() continue search even after empty entry

Quoted 41 lines · Leon Romanovsky
Quoted 21 lines · Jason Gunthorpe
Quoted 20 lines · Leon Romanovsky

From: Avihai Horon <[email protected]>

Currently, ib_find_gid() will stop searching after encountering the first empty GID table entry. This behavior is wrong since neither IB nor RoCE spec enforce tightly packed GID tables.

For example, when a valid GID entry exists at index N, and if a GID entry is empty at index N-1, ib_find_gid() will fail to find the valid entry.

Fix it by making ib_find_gid() continue searching even after encountering missing entries.

Fixes 5eb620c81ce3 ("IB/core: Add helpers for uncached GID and P_Key searches")
 drivers/infiniband/core/device.c | 3 +++
 1 file changed, 3 insertions(+)
Quoted 13 lines

drivers/infiniband/core/device.c int ib_find_gid(struct ib_device *device, union ib_gid *gid, · line 2466

Quoted 11 lines
drivers/infiniband/core/device.c +3 -0
index 22a4adda7981..b5d8443030d4 100644
+++ b/drivers/infiniband/core/device.c
@@ -2460,8 +2460,11 @@ int ib_find_gid(struct ib_device *device, union ib_gid *gid,
 		for (i = 0; i < device->port_data[port].immutable.gid_tbl_len;
 		     ++i) {
 			ret = rdma_query_gid(device, port, i, &tmp_gid);
+			if (ret == -ENOENT)
+				continue;
 			if (ret)
 				return ret;

There is no return code from rdma_query_gid that means stop searching,

In rdma_query_gid() any error stopped searching, and here we continue same behaviour as before. You can argue that this function can't really get illegal parameters and it never returns -EINVAL, but someone needs to check all callers that this is true.

Quoted 6 lines
Quoted 4 lines

so just write

if (ret)
continue

As long as we don't delete input validity checks, it is not correct.

It is fine, there is no return condition that means stop searching, and even if we fail the validity checks that is a WARN_ON and keep going, not a stop searching event here.

So just do continue, no need for complications.

Jason

#7 lore raw

PATCH 3/3 RDMA/cma: Let cma_resolve_ib_dev() continue search even after empty entry

In reply to Leon Romanovsky

From: Avihai Horon <[email protected]>

Currently, when cma_resolve_ib_dev() searches for a matching GID it will stop searching after encountering the first empty GID table entry. This behavior is wrong since neither IB nor RoCE spec enforce tightly packed GID tables.

For example, when the matching valid GID entry exists at index N, and if a GID entry is empty at index N-1, cma_resolve_ib_dev() will fail to find the matching valid entry.

Fix it by making cma_resolve_ib_dev() continue searching even after encountering missing entries.

Fixes f17df3b0dede ("RDMA/cma: Add support for AF_IB to rdma_resolve_addr()")
---
 drivers/infiniband/core/cma.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/infiniband/core/cma.c +11 -3
index 835ac54d4a24..b669002c9255 100644
@@ -766,6 +766,7 @@ static int cma_resolve_ib_dev(struct rdma_id_private *id_priv)
 	unsigned int p;
 	u16 pkey, index;
 	enum ib_port_state port_state;
+	int ret;
 	int i;
 
 	cma_dev = NULL;
@@ -784,9 +785,16 @@ static int cma_resolve_ib_dev(struct rdma_id_private *id_priv)
 
 			if (ib_get_cached_port_state(cur_dev->device, p, &port_state))
 				continue;
-			for (i = 0; !rdma_query_gid(cur_dev->device,
-						    p, i, &gid);
-			     i++) {
+
+			for (i = 0; i < cur_dev->device->port_data[p].immutable.gid_tbl_len;
+			     ++i) {
+				ret = rdma_query_gid(cur_dev->device, p, i,
+						     &gid);
+				if (ret == -ENOENT)
+					continue;
+				if (ret)
+					break;
+
 				if (!memcmp(&gid, dgid, sizeof(gid))) {
 					cma_dev = cur_dev;
 					sgid = gid;
Signature · 1 line
2.33.1
maintainer
#8 lore raw

Re: [PATCH rdma-next 3/3] RDMA/cma: Let cma_resolve_ib_dev() continue search even after empty entry

Quoted 38 lines · Leon Romanovsky

From: Avihai Horon <[email protected]>

Currently, when cma_resolve_ib_dev() searches for a matching GID it will stop searching after encountering the first empty GID table entry. This behavior is wrong since neither IB nor RoCE spec enforce tightly packed GID tables.

For example, when the matching valid GID entry exists at index N, and if a GID entry is empty at index N-1, cma_resolve_ib_dev() will fail to find the matching valid entry.

Fix it by making cma_resolve_ib_dev() continue searching even after encountering missing entries.

Fixes f17df3b0dede ("RDMA/cma: Add support for AF_IB to rdma_resolve_addr()")
 drivers/infiniband/core/cma.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/infiniband/core/cma.c +2 -2
index 835ac54d4a24..b669002c9255 100644
+++ b/drivers/infiniband/core/cma.c
@@ -766,6 +766,7 @@ static int cma_resolve_ib_dev(struct rdma_id_private *id_priv)
 	unsigned int p;
 	u16 pkey, index;
 	enum ib_port_state port_state;
+	int ret;
 	int i;
 
 	cma_dev = NULL;
@@ -784,9 +785,16 @@ static int cma_resolve_ib_dev(struct rdma_id_private *id_priv)
 
 			if (ib_get_cached_port_state(cur_dev->device, p, &port_state))
 				continue;
-			for (i = 0; !rdma_query_gid(cur_dev->device,
-						    p, i, &gid);

drivers/infiniband/core/cma.c static int cma_resolve_ib_dev(struct rdma_id_private *id_priv) · line 796

Quoted 10 lines
drivers/infiniband/core/cma.c +9 -1
-			     i++) {
+
+			for (i = 0; i < cur_dev->device->port_data[p].immutable.gid_tbl_len;
+			     ++i) {
+				ret = rdma_query_gid(cur_dev->device, p, i,
+						     &gid);
+				if (ret == -ENOENT)
+					continue;
+				if (ret)
+					break;

Same here, just always continue

Jason