Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3702629pxb; Mon, 24 Jan 2022 15:48:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJzK0hyHOwWG8+aFhrfNO4t2/sqTF9bSnf7yDqeXN7tjis/g68KfLKretHhurS68rtdpLXch X-Received: by 2002:a05:6a00:1a87:b0:4c4:ff65:749 with SMTP id e7-20020a056a001a8700b004c4ff650749mr15841508pfv.32.1643068132668; Mon, 24 Jan 2022 15:48:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643068132; cv=none; d=google.com; s=arc-20160816; b=eSCmxNG5igY58HX6r8QJhvJMWNqqd47blfMvKMqn/RjWl2Cj/iIHNb5rub6hMWBAzy BeeZFDmbJBtXbDw8lfebi0AAi+5rgOUIUuJBMJqFr0TyAMvmHd5Qv0FFkBD3PR2pBZZT jyNgLwE//WaUlnWnpZ5mh0hWq3voMuQElJXMJlrN/fY+UU59ThXUY5ADNIyaD0jesCTv TqK+TpDP8YJCGUJb8gDgZi3K4S9jBk1QrTn9yF9OR2tVsCm5w8TyYBWCjOGVYyn/r1DE T24unpTnvzJeTestzuxEzGs2BkM0K8yRqyBnsaVSdNsEQ3AfhZtiuD8/fdd29QLrik7u iNbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=oz6nH/SkFIodNqFrwsTPvHJGlaDU9A3ZqO5QhU2JXmU=; b=Yfdl3mGAbq4b/IjKcY9NKboFK/Bvfx6kkADWMS/Y1tuUaSHPvFdHihfU84aoUU+8d0 zV1yH0i7OdxPRl65GNIpTs2yyRfCksrohAabHO9yZXCAss9xWAs/kzcDZp+QmGl/wmFl chULTJPsbms5/K6JK5f1VpnzElod8WSw9gh0eeo9kO6BmELY7E9BdIFfJWJD1jsiV0RF 1ikoz82xFj+c115u++E7/cMXN4uQFiMlR9yVc3UAHKaFvGCtoF5qRyDiA8n7+50SbeBU Ad8wqy+7N1jUlHNuTN+Sm06deblB3S6Ue1SfAkzLH0poj4P6BnhAcKt3fhg3Wm1Okf1o NhYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=l67EzOip; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a15si13125894pls.47.2022.01.24.15.48.41; Mon, 24 Jan 2022 15:48:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=l67EzOip; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2362798AbiAXXmz (ORCPT + 99 others); Mon, 24 Jan 2022 18:42:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1844045AbiAXXHi (ORCPT ); Mon, 24 Jan 2022 18:07:38 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1EB50C06E03E; Mon, 24 Jan 2022 13:17:20 -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 dfw.source.kernel.org (Postfix) with ESMTPS id B36F1614A6; Mon, 24 Jan 2022 21:17:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85AEBC36AFB; Mon, 24 Jan 2022 21:17:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643059039; bh=tF0uGitjesxu8ManvGEcTbhnaW04Nx0vJWHp4smfh6s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l67EzOipAkcgLVusaMvAZGdCwX0ElCeAx64e5b8Iilw5j1s3OXMXUe+KfrxQ+TFSQ 8/IPLTmKo7kC6kSop28O4RHXrz6Gp3uuN5CZZZb3oDb9uNz9lVKPGik4yPXWGCkKx/ wKcL0Jzo5HNFN704R46ryBXsI1s9BVzfOpHCvNjk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Avihai Horon , Mark Zhang , Leon Romanovsky , Jason Gunthorpe , Sasha Levin Subject: [PATCH 5.16 0485/1039] RDMA/cma: Let cma_resolve_ib_dev() continue search even after empty entry Date: Mon, 24 Jan 2022 19:37:54 +0100 Message-Id: <20220124184141.573177206@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Avihai Horon [ Upstream commit 20679094a0161c94faf77e373fa3f7428a8e14bd ] 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()") Link: https://lore.kernel.org/r/b7346307e3bb396c43d67d924348c6c496493991.1639055490.git.leonro@nvidia.com Signed-off-by: Avihai Horon Reviewed-by: Mark Zhang Signed-off-by: Leon Romanovsky Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin --- 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 835ac54d4a24c..a3834ef691910 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.34.1