From patchwork Thu Dec 9 13:16:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leon Romanovsky X-Patchwork-Id: 12666541 X-Patchwork-Delegate: jgg@ziepe.ca Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 51C6CC433EF for ; Thu, 9 Dec 2021 13:16:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234132AbhLINTz (ORCPT ); Thu, 9 Dec 2021 08:19:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237687AbhLINTz (ORCPT ); Thu, 9 Dec 2021 08:19:55 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7ADA1C061746; Thu, 9 Dec 2021 05:16:21 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id C3C06CE24D7; Thu, 9 Dec 2021 13:16:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 30E88C004DD; Thu, 9 Dec 2021 13:16:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1639055778; bh=wU55ICo+Pqb82iww6DK1SKuU+eZ932CsbqoXkSR0ClQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cLutSu9crIT7azrYqENKFi5z8ip8ci6YnG5yrdPbpi2RFNu88XYT3fsCrMkeJ4pO5 tZJ6o7xMkPBxjwPkgvnZvMA9ayRDuRQIu+2VKLAbY5vlIAgGh+gq5AVbG7ok9970lo IteuZ6/F0lOxMfc0aTkMExydCA7UNZoLcFUY0yHGUXBXge5ouRvM65TIdxDJnrP+Fd wTknTzgbHSD731819fPCMih56PtTHvUXZHGYsVR7X9rqQi8+xmEr6R3gB5GaFOljW0 UdBvqKzoqzhMtvRWNc66MXsfhNMrJ6Qc1hUf53157nJ2XRT7TnnGvTPlzz746wXpZP g2R+rZebczmrw== From: Leon Romanovsky To: Jason Gunthorpe Cc: Avihai Horon , linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, Mark Zhang Subject: [PATCH rdma-next v1 1/3] RDMA/core: Modify rdma_query_gid() to return accurate error codes Date: Thu, 9 Dec 2021 15:16:05 +0200 Message-Id: <1f2b65dfb4d995e74b621e3e21e7c7445d187956.1639055490.git.leonro@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org From: Avihai Horon 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 Reviewed-by: Mark Zhang Signed-off-by: Leon Romanovsky --- 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; From patchwork Thu Dec 9 13:16:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leon Romanovsky X-Patchwork-Id: 12666543 X-Patchwork-Delegate: jgg@ziepe.ca Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8184CC433F5 for ; Thu, 9 Dec 2021 13:16:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237687AbhLINUA (ORCPT ); Thu, 9 Dec 2021 08:20:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237698AbhLINT7 (ORCPT ); Thu, 9 Dec 2021 08:19:59 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3706BC061353; Thu, 9 Dec 2021 05:16:26 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 060AECE25C0; Thu, 9 Dec 2021 13:16:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 60937C004DD; Thu, 9 Dec 2021 13:16:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1639055782; bh=KOc8BLRYSBi58zVClsB+iA6Q32lJlqn/y4JFjjNo/k8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ah/s36ihTb2pYmOxYdPsDIo1IztQbwi5FiRcdgMafFzleYb1SQuIfXWwyFV0SFVBs mG2AlRRJh4T6q4eMbVJswSshewGwhOTcUgKnh7iTlJmcAD9tZ2JbFt4+XnZjpnUp8U ydPUeUxgwsC0Co+vx3oze1mnHfWsT/IqccRYUqksf139VZIyPMhQa2wXyV8B9ndRiy RZO+F/wjDWFlGGxoPUfDqAqF+eulYKhb+k9a/GSQMAwHZeoGS5GtTpu89T6SGEedDp md2P16VITWl1mlkwti2eBHOiSbEqCEcQxRqZ5pWOwIURVDOjrl8oF0ceK88YoWdf+E of2qdGu+LuWXA== From: Leon Romanovsky To: Jason Gunthorpe Cc: Avihai Horon , linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, Mark Zhang Subject: [PATCH rdma-next v1 2/3] RDMA/core: Let ib_find_gid() continue search even after empty entry Date: Thu, 9 Dec 2021 15:16:06 +0200 Message-Id: X-Mailer: git-send-email 2.33.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org From: Avihai Horon 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 Reviewed-by: Mark Zhang Signed-off-by: Leon Romanovsky --- 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) From patchwork Thu Dec 9 13:16:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leon Romanovsky X-Patchwork-Id: 12666545 X-Patchwork-Delegate: jgg@ziepe.ca Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B5C6C433F5 for ; Thu, 9 Dec 2021 13:16:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237698AbhLINUE (ORCPT ); Thu, 9 Dec 2021 08:20:04 -0500 Received: from sin.source.kernel.org ([145.40.73.55]:43060 "EHLO sin.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237724AbhLINUD (ORCPT ); Thu, 9 Dec 2021 08:20:03 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 369F3CE25B2; Thu, 9 Dec 2021 13:16:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 94451C004DD; Thu, 9 Dec 2021 13:16:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1639055786; bh=F3m5fBX84JidvrgmrY/pV9dmlTEPpKnxeK6GPMGoKrg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=saSMYIv8cEjCLq+tS77bmSzDxE3ooJ+uFgb16Oa79OmL+yowGpmnzxm1ZBITjP9RX o8XqhtGkc7GXUZs58hnWzWVUm9n8FL0/cRdvcJDbnWZ2IYgqEX6SvHR37EN2UcXJAq AZitj/fSumCHv2hDs1+4WdZHAXSmhaNPErYele7QqsgVvRj/EqFY2l4n59IXvy2RzU LNJSPhi2j3Mv03Xbyl0iWbjjQsb4My7DGcFRcs5Se3v4auThQvFPZe+kRH6Xut1r1R MuZwwbAAUbLbbKO+WyGUnVlIQB0MRohMTvprGYqXcTOZtKmJ1Bfb6cD2Ezt8kSA7bk Fc0pUPTvpOtow== From: Leon Romanovsky To: Jason Gunthorpe Cc: Avihai Horon , linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, Mark Zhang Subject: [PATCH rdma-next v1 3/3] RDMA/cma: Let cma_resolve_ib_dev() continue search even after empty entry Date: Thu, 9 Dec 2021 15:16:07 +0200 Message-Id: X-Mailer: git-send-email 2.33.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org From: Avihai Horon 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 Reviewed-by: Mark Zhang Signed-off-by: Leon Romanovsky --- 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;