From patchwork Sun May 10 10:26:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haggai Eran X-Patchwork-Id: 6371521 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 0C73FBEEE1 for ; Sun, 10 May 2015 10:28:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 216542010F for ; Sun, 10 May 2015 10:28:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1F92920389 for ; Sun, 10 May 2015 10:28:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752605AbbEJK17 (ORCPT ); Sun, 10 May 2015 06:27:59 -0400 Received: from ns1327.ztomy.com ([193.47.165.129]:49410 "EHLO mellanox.co.il" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752593AbbEJK1r (ORCPT ); Sun, 10 May 2015 06:27:47 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from haggaie@mellanox.com) with ESMTPS (AES256-SHA encrypted); 10 May 2015 13:26:39 +0300 Received: from gen-l-vrt-034.mtl.labs.mlnx (gen-l-vrt-034.mtl.labs.mlnx [10.137.34.1]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id t4AAQjho005986; Sun, 10 May 2015 13:26:46 +0300 From: Haggai Eran To: Doug Ledford Cc: linux-rdma@vger.kernel.org, netdev@vger.kernel.org, Liran Liss , Guy Shapiro , Shachar Raindel , Yotam Kenneth , Haggai Eran Subject: [PATCH v3 for-next 09/13] IB/cma: Add compare_data checks to the RDMA CM module Date: Sun, 10 May 2015 13:26:40 +0300 Message-Id: <1431253604-9214-10-git-send-email-haggaie@mellanox.com> X-Mailer: git-send-email 1.7.11.2 In-Reply-To: <1431253604-9214-1-git-send-email-haggaie@mellanox.com> References: <1431253604-9214-1-git-send-email-haggaie@mellanox.com> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Previously RDMA CM relied on the CM module to check the incoming requests against "compare data" struct to dispatch events for different RDMA CM IDs based on the request parameters (IP address, address family, etc.). With namespace support, multiple namespaces in RDMA CM will need to share a single CM ID. Such an ID cannot be associated with a specific compare data, because that could create conflicts with other namespaces. The patch adds checks to verify that incoming requests match their RDMA CM ID destination inside the RDMA CM module itself. Signed-off-by: Haggai Eran --- drivers/infiniband/core/cm.c | 5 +++-- drivers/infiniband/core/cma.c | 12 +++++++++--- include/rdma/ib_cm.h | 3 +++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c index fc33fb215e55..d023639a9f75 100644 --- a/drivers/infiniband/core/cm.c +++ b/drivers/infiniband/core/cm.c @@ -459,8 +459,8 @@ static int cm_compare_data(struct ib_cm_compare_data *src_data, return memcmp(src, dst, sizeof(src)); } -static int cm_compare_private_data(u32 *private_data, - struct ib_cm_compare_data *dst_data) +int cm_compare_private_data(u32 *private_data, + struct ib_cm_compare_data *dst_data) { u32 src[IB_CM_COMPARE_SIZE]; @@ -470,6 +470,7 @@ static int cm_compare_private_data(u32 *private_data, cm_mask_copy(src, private_data, dst_data->mask); return memcmp(src, dst_data->data, sizeof(src)); } +EXPORT_SYMBOL(cm_compare_private_data); /* * Trivial helpers to strip endian annotation and compare; the diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c index b5d3321e613e..1f591458b4de 100644 --- a/drivers/infiniband/core/cma.c +++ b/drivers/infiniband/core/cma.c @@ -146,6 +146,7 @@ struct rdma_id_private { u8 tos; u8 reuseaddr; u8 afonly; + struct ib_cm_compare_data compare_data; }; struct cma_multicast { @@ -1319,6 +1320,10 @@ static int cma_req_handler(struct ib_cm_id *cm_id, struct ib_cm_event *ib_event) int offset, ret; listen_id = cm_id->context; + if (cm_compare_private_data(ib_event->private_data, + &listen_id->compare_data)) + return -EINVAL; + if (!cma_check_req_qp_type(&listen_id->id, ib_event)) return -EINVAL; @@ -1586,7 +1591,6 @@ out: static int cma_ib_listen(struct rdma_id_private *id_priv) { - struct ib_cm_compare_data compare_data; struct sockaddr *addr; struct ib_cm_id *id; __be64 svc_id; @@ -1603,8 +1607,10 @@ static int cma_ib_listen(struct rdma_id_private *id_priv) if (cma_any_addr(addr) && !id_priv->afonly) ret = ib_cm_listen(id_priv->cm_id.ib, svc_id, 0, NULL); else { - cma_set_compare_data(id_priv->id.ps, addr, &compare_data); - ret = ib_cm_listen(id_priv->cm_id.ib, svc_id, 0, &compare_data); + cma_set_compare_data(id_priv->id.ps, addr, + &id_priv->compare_data); + ret = ib_cm_listen(id_priv->cm_id.ib, svc_id, 0, + &id_priv->compare_data); } if (ret) { diff --git a/include/rdma/ib_cm.h b/include/rdma/ib_cm.h index 17e072d1677c..4c767b5daf50 100644 --- a/include/rdma/ib_cm.h +++ b/include/rdma/ib_cm.h @@ -347,6 +347,9 @@ struct ib_cm_compare_data { u32 mask[IB_CM_COMPARE_SIZE]; }; +int cm_compare_private_data(u32 *private_data, + struct ib_cm_compare_data *dst_data); + /** * ib_cm_listen - Initiates listening on the specified service ID for * connection and service ID resolution requests.