Skip to contentSkip to conversation

Skip holes in GID table

PATCH Applied Leon Romanovsky 2 participants 6 messages Dec 9, 2021 – Dec 15, 2021 InfiniBand

lore
Share & tools
lore
#0 lore raw

cover Skip holes in GID table

From: Leon Romanovsky <[email protected]>

Changelog:
v1:
* Removed variable assignment in rdma_query_gid
* Changed special error code handling of return value from rdma_query_gid to continue search.
v0: https://lore.kernel.org/all/[email protected]

---------------------------------------------------------------------

Hi,

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

Thanks

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  | 12 +++++++++---
 drivers/infiniband/core/cma.c    | 12 +++++++++---
 drivers/infiniband/core/device.c |  3 ++-
 3 files changed, 20 insertions(+), 7 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 | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/infiniband/core/cache.c +9 -3
index 0c98dd3dee67..edddcca62ece 100644
@@ -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;
+	}
 
 	memcpy(gid, &table->data_vec[index]->attr.gid, sizeof(*gid));
 	res = 0;
Signature · 1 line
2.33.1
#2 lore raw

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

Quoted 26 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 | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/infiniband/core/cache.c +1 -1
index 0c98dd3dee67..edddcca62ece 100644
@@ -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;

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

Quoted 7 lines
drivers/infiniband/core/cache.c +2 -2
@@ -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

Jason,

I made stupid mistake here, and missed ";".
Can you fix it locally?

Thanks

Quoted 13 lines
drivers/infiniband/core/cache.c +6 -0
 		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
#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, 2 insertions(+), 1 deletion(-)
drivers/infiniband/core/device.c +2 -1
index 22a4adda7981..a311df07b1bd 100644
@@ -2461,7 +2461,8 @@ int ib_find_gid(struct ib_device *device, union ib_gid *gid,
 		     ++i) {
 			ret = rdma_query_gid(device, port, i, &tmp_gid);
 			if (ret)
-				return ret;
+				continue;
+
 			if (!memcmp(&tmp_gid, gid, sizeof *gid)) {
 				*port_num = port;
 				if (index)
Signature · 1 line
2.33.1
#4 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 | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/infiniband/core/cma.c +9 -3
index 8a98aa90956f..27a00ce2e101 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,14 @@ 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)
+					continue;
+
 				if (!memcmp(&gid, dgid, sizeof(gid))) {
 					cma_dev = cur_dev;
 					sgid = gid;
Signature · 1 line
2.33.1
maintainer Applied
#5 lore raw
In reply to Leon Romanovsky
Quoted 16 lines · Leon Romanovsky

From: Leon Romanovsky <[email protected]>

Changelog:
v1:
* Removed variable assignment in rdma_query_gid
* Changed special error code handling of return value from rdma_query_gid to continue search.
v0: https://lore.kernel.org/all/[email protected]

---------------------------------------------------------------------

Hi,

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

Quoted 7 lines

Thanks

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

Applied to for-next, thanks

Jason