linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH rdma-next v1 0/3] Skip holes in GID table
@ 2021-12-09 13:16 Leon Romanovsky
  2021-12-09 13:16 ` [PATCH rdma-next v1 1/3] RDMA/core: Modify rdma_query_gid() to return accurate error codes Leon Romanovsky
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Leon Romanovsky @ 2021-12-09 13:16 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: Leon Romanovsky, Avihai Horon, linux-kernel, linux-rdma, Mark Zhang

From: Leon Romanovsky <leonro@nvidia.com>

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/cover.1637581778.git.leonro@nvidia.com

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

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(-)

-- 
2.33.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH rdma-next v1 1/3] RDMA/core: Modify rdma_query_gid() to return accurate error codes
  2021-12-09 13:16 [PATCH rdma-next v1 0/3] Skip holes in GID table Leon Romanovsky
@ 2021-12-09 13:16 ` Leon Romanovsky
  2021-12-09 18:17   ` Leon Romanovsky
  2021-12-09 13:16 ` [PATCH rdma-next v1 2/3] RDMA/core: Let ib_find_gid() continue search even after empty entry Leon Romanovsky
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 6+ messages in thread
From: Leon Romanovsky @ 2021-12-09 13:16 UTC (permalink / raw)
  To: Jason Gunthorpe; +Cc: Avihai Horon, linux-kernel, linux-rdma, Mark Zhang

From: Avihai Horon <avihaih@nvidia.com>

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

Signed-off-by: Avihai Horon <avihaih@nvidia.com>
Reviewed-by: Mark Zhang <markzhang@nvidia.com>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
---
 drivers/infiniband/core/cache.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/infiniband/core/cache.c b/drivers/infiniband/core/cache.c
index 0c98dd3dee67..edddcca62ece 100644
--- a/drivers/infiniband/core/cache.c
+++ b/drivers/infiniband/core/cache.c
@@ -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;
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH rdma-next v1 2/3] RDMA/core: Let ib_find_gid() continue search even after empty entry
  2021-12-09 13:16 [PATCH rdma-next v1 0/3] Skip holes in GID table Leon Romanovsky
  2021-12-09 13:16 ` [PATCH rdma-next v1 1/3] RDMA/core: Modify rdma_query_gid() to return accurate error codes Leon Romanovsky
@ 2021-12-09 13:16 ` Leon Romanovsky
  2021-12-09 13:16 ` [PATCH rdma-next v1 3/3] RDMA/cma: Let cma_resolve_ib_dev() " Leon Romanovsky
  2021-12-15  0:12 ` [PATCH rdma-next v1 0/3] Skip holes in GID table Jason Gunthorpe
  3 siblings, 0 replies; 6+ messages in thread
From: Leon Romanovsky @ 2021-12-09 13:16 UTC (permalink / raw)
  To: Jason Gunthorpe; +Cc: Avihai Horon, linux-kernel, linux-rdma, Mark Zhang

From: Avihai Horon <avihaih@nvidia.com>

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")
Signed-off-by: Avihai Horon <avihaih@nvidia.com>
Reviewed-by: Mark Zhang <markzhang@nvidia.com>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
---
 drivers/infiniband/core/device.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c
index 22a4adda7981..a311df07b1bd 100644
--- a/drivers/infiniband/core/device.c
+++ b/drivers/infiniband/core/device.c
@@ -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)
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH rdma-next v1 3/3] RDMA/cma: Let cma_resolve_ib_dev() continue search even after empty entry
  2021-12-09 13:16 [PATCH rdma-next v1 0/3] Skip holes in GID table Leon Romanovsky
  2021-12-09 13:16 ` [PATCH rdma-next v1 1/3] RDMA/core: Modify rdma_query_gid() to return accurate error codes Leon Romanovsky
  2021-12-09 13:16 ` [PATCH rdma-next v1 2/3] RDMA/core: Let ib_find_gid() continue search even after empty entry Leon Romanovsky
@ 2021-12-09 13:16 ` Leon Romanovsky
  2021-12-15  0:12 ` [PATCH rdma-next v1 0/3] Skip holes in GID table Jason Gunthorpe
  3 siblings, 0 replies; 6+ messages in thread
From: Leon Romanovsky @ 2021-12-09 13:16 UTC (permalink / raw)
  To: Jason Gunthorpe; +Cc: Avihai Horon, linux-kernel, linux-rdma, Mark Zhang

From: Avihai Horon <avihaih@nvidia.com>

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()")
Signed-off-by: Avihai Horon <avihaih@nvidia.com>
Reviewed-by: Mark Zhang <markzhang@nvidia.com>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
---
 drivers/infiniband/core/cma.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
index 8a98aa90956f..27a00ce2e101 100644
--- a/drivers/infiniband/core/cma.c
+++ 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,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;
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH rdma-next v1 1/3] RDMA/core: Modify rdma_query_gid() to return accurate error codes
  2021-12-09 13:16 ` [PATCH rdma-next v1 1/3] RDMA/core: Modify rdma_query_gid() to return accurate error codes Leon Romanovsky
@ 2021-12-09 18:17   ` Leon Romanovsky
  0 siblings, 0 replies; 6+ messages in thread
From: Leon Romanovsky @ 2021-12-09 18:17 UTC (permalink / raw)
  To: Jason Gunthorpe; +Cc: Avihai Horon, linux-kernel, linux-rdma, Mark Zhang

On Thu, Dec 09, 2021 at 03:16:05PM +0200, Leon Romanovsky wrote:
> From: Avihai Horon <avihaih@nvidia.com>
> 
> Modify rdma_query_gid() to return -ENOENT for empty entries. This will
> make error reporting more accurate and will be used in next patches.
> 
> Signed-off-by: Avihai Horon <avihaih@nvidia.com>
> Reviewed-by: Mark Zhang <markzhang@nvidia.com>
> Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
> ---
>  drivers/infiniband/core/cache.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/infiniband/core/cache.c b/drivers/infiniband/core/cache.c
> index 0c98dd3dee67..edddcca62ece 100644
> --- a/drivers/infiniband/core/cache.c
> +++ b/drivers/infiniband/core/cache.c
> @@ -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

Jason,

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

Thanks

>  		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;
> -- 
> 2.33.1
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH rdma-next v1 0/3] Skip holes in GID table
  2021-12-09 13:16 [PATCH rdma-next v1 0/3] Skip holes in GID table Leon Romanovsky
                   ` (2 preceding siblings ...)
  2021-12-09 13:16 ` [PATCH rdma-next v1 3/3] RDMA/cma: Let cma_resolve_ib_dev() " Leon Romanovsky
@ 2021-12-15  0:12 ` Jason Gunthorpe
  3 siblings, 0 replies; 6+ messages in thread
From: Jason Gunthorpe @ 2021-12-15  0:12 UTC (permalink / raw)
  To: Leon Romanovsky
  Cc: Leon Romanovsky, Avihai Horon, linux-kernel, linux-rdma, Mark Zhang

On Thu, Dec 09, 2021 at 03:16:04PM +0200, Leon Romanovsky wrote:
> From: Leon Romanovsky <leonro@nvidia.com>
> 
> 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/cover.1637581778.git.leonro@nvidia.com
> 
> ---------------------------------------------------------------------
> 
> 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

Applied to for-next, thanks

Jason

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-12-15  0:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-09 13:16 [PATCH rdma-next v1 0/3] Skip holes in GID table Leon Romanovsky
2021-12-09 13:16 ` [PATCH rdma-next v1 1/3] RDMA/core: Modify rdma_query_gid() to return accurate error codes Leon Romanovsky
2021-12-09 18:17   ` Leon Romanovsky
2021-12-09 13:16 ` [PATCH rdma-next v1 2/3] RDMA/core: Let ib_find_gid() continue search even after empty entry Leon Romanovsky
2021-12-09 13:16 ` [PATCH rdma-next v1 3/3] RDMA/cma: Let cma_resolve_ib_dev() " Leon Romanovsky
2021-12-15  0:12 ` [PATCH rdma-next v1 0/3] Skip holes in GID table Jason Gunthorpe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).