From patchwork Mon Jan 7 08:45:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Haakon Bugge X-Patchwork-Id: 10750149 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 36A3913BF for ; Mon, 7 Jan 2019 08:45:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 245C328A31 for ; Mon, 7 Jan 2019 08:45:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 18A5928A2E; Mon, 7 Jan 2019 08:45:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B46A828A32 for ; Mon, 7 Jan 2019 08:45:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726554AbfAGIp0 (ORCPT ); Mon, 7 Jan 2019 03:45:26 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:44464 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726511AbfAGIp0 (ORCPT ); Mon, 7 Jan 2019 03:45:26 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id x078hdb0179101; Mon, 7 Jan 2019 08:45:18 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=dl3yJ16QtfwTddPYkQMA/VpQrFrhs9WNolMSG++6OUw=; b=4AYavYvqYoI+nWMRzjLPUYMaVCVsJdOAruUbM5N9Mq66pr/abKCQxtbyypIfKttqjzXc z7/uBl69rD1D4XmWc0plBisHFG7udtoafmF/Er/o0uMC+ZQerR/v92umEZYUiN1bcKqx f2wDzqQ+uWBE8RVCqkHZV5YAV7SOsok9cEY6ldJEMP2CJUEHnOSdWVQmkHVeYcaGRHIq sBpycxmRxuXdD6R4ATNyUA04z4cXl6yhtRNmkAz3QF4Hna0xMw6SdgY/KvyipOJ//l0L yrlAwBsoCnQrJQjI/HbJYVbA9r7m6OVZHm6qLUVQbo803xACxgUd9XADh73vIKnm8HTj VQ== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp2130.oracle.com with ESMTP id 2ptj3dmnh6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 07 Jan 2019 08:45:18 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x078jH2o010922 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 7 Jan 2019 08:45:17 GMT Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x078jHb2026231; Mon, 7 Jan 2019 08:45:17 GMT Received: from lab02.no.oracle.com (/10.172.144.56) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 07 Jan 2019 00:45:16 -0800 From: =?utf-8?q?H=C3=A5kon_Bugge?= To: sean.hefty@intel.com, hal@dev.mellanox.co.il, dledford@redhat.com Cc: leon@kernel.org, jgg@mellanox.com, mark.haywood@oracle.com, aron.silverton@oracle.com, linux-rdma@vger.kernel.org Subject: [PATCH ibacm v2 1/2] ibacm: Remove trailing blanks in acm.h Date: Mon, 7 Jan 2019 09:45:02 +0100 Message-Id: <04978e1117b11b2478c64108bf283c2f56c9e591.1546850468.git.haakon.bugge@oracle.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9128 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1901070079 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Håkon Bugge Signed-off-by: Håkon Bugge --- ibacm/include/infiniband/acm.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ibacm/include/infiniband/acm.h b/ibacm/include/infiniband/acm.h index 0f846999..f6efee18 100644 --- a/ibacm/include/infiniband/acm.h +++ b/ibacm/include/infiniband/acm.h @@ -130,7 +130,7 @@ struct acm_perf_msg { }; /* - * Endpoint query messages are sent/received in network byte order. + * Endpoint query messages are sent/received in network byte order. */ struct acm_ep_config_data { uint64_t dev_guid; From patchwork Mon Jan 7 08:45:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Haakon Bugge X-Patchwork-Id: 10750151 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1816F746 for ; Mon, 7 Jan 2019 08:45:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0756128A27 for ; Mon, 7 Jan 2019 08:45:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EF89028A31; Mon, 7 Jan 2019 08:45:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 398D628A2E for ; Mon, 7 Jan 2019 08:45:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726511AbfAGIp3 (ORCPT ); Mon, 7 Jan 2019 03:45:29 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:44506 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726404AbfAGIp2 (ORCPT ); Mon, 7 Jan 2019 03:45:28 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id x078hgTr179114; Mon, 7 Jan 2019 08:45:19 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=NV+6ek8ML23ELnuZuIgdV/VaY+QQbGhrg0QhK1yPbs0=; b=f+KkH6JHyFqnvWxM2aDY2dLkGFkp6Chu30FQRtzha60aTdUSGMS1qVaBXOns/O6H1AgJ f7b8jcWos7tL316vtwsUcrVnCRQbchqTYDC1qCI+C5lgLBZDPesONpLLU7GhSux9M4oB 1aIHftE5TCFoVylfjVPY1xZ8mF5yuVPMZXWxo9f/RG3DO67Yka+ZPwmdBXJmpPDEVovg NZslhXHTmFJziQ6H8ykdkWapOtR+pehl8SCLazO3Bc22t0YyABlg0vB5u08thOlYXE7V APOaYnyayKgVun9R8koO3u13hxzBlTrlpwYIBpLqBOboiWupkJUlnevAnN1pO6F821v7 gQ== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp2130.oracle.com with ESMTP id 2ptj3dmnhe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 07 Jan 2019 08:45:19 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x078jJei004986 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 7 Jan 2019 08:45:19 GMT Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x078jIip011083; Mon, 7 Jan 2019 08:45:18 GMT Received: from lab02.no.oracle.com (/10.172.144.56) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 07 Jan 2019 00:45:18 -0800 From: =?utf-8?q?H=C3=A5kon_Bugge?= To: sean.hefty@intel.com, hal@dev.mellanox.co.il, dledford@redhat.com Cc: leon@kernel.org, jgg@mellanox.com, mark.haywood@oracle.com, aron.silverton@oracle.com, linux-rdma@vger.kernel.org Subject: [PATCH ibacm v2 2/2] ibacm: acme supports only one port Date: Mon, 7 Jan 2019 09:45:03 +0100 Message-Id: <3c979b69a5f654b6ae2c43b90a87e70bb16c92ea.1546850468.git.haakon.bugge@oracle.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9128 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1901070079 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP acme can display end-point information. This is implemented in acm by iterating through all end-points and their ports, until the end-point indexes match. This implies, considering a multi-ported device, that the address information associated with the first port is the only one displayed. Before this commit: # ibstat | grep ports Number of ports: 2 # ib_acme -e svc,guid,port,pkey,ep_index,prov,addr_0,addresses ibacm-unix.sock,0x0021280001a17c96,1,0xffff,1,ibacmp,lab36,lab36-1,192.168.2.2 Fixed by adding port_num to the equation, and the above command will yield: # ib_acme -e svc,guid,port,pkey,ep_index,prov,addr_0,addresses ibacm-unix.sock,0x0021280001a17c96,1,0xffff,1,ibacmp,192.168.2.2,lab36,lab36-1 ibacm-unix.sock,0x0021280001a17c96,2,0xffff,1,ibacmp,192.168.2.3,lab36-2 Signed-off-by: Håkon Bugge --- v1 -> v2: * Incorporated review comments from Doug * Fixed a memory leak in enumerate_ep() introduced by v1 * Hardened enumerate_ep() related to the first EP being unavailable --- ibacm/include/infiniband/acm.h | 6 ++-- ibacm/src/acm.c | 11 +++++-- ibacm/src/acme.c | 36 ++++++++++++++--------- ibacm/src/libacm.c | 53 +++++++++++++++++++++++----------- ibacm/src/libacm.h | 2 +- 5 files changed, 71 insertions(+), 37 deletions(-) diff --git a/ibacm/include/infiniband/acm.h b/ibacm/include/infiniband/acm.h index f6efee18..90f3d431 100644 --- a/ibacm/include/infiniband/acm.h +++ b/ibacm/include/infiniband/acm.h @@ -73,7 +73,8 @@ struct acm_hdr { uint8_t version; uint8_t opcode; uint8_t status; - uint8_t data[3]; + uint8_t port_num; + uint8_t data[2]; uint16_t length; uint64_t tid; }; @@ -135,7 +136,8 @@ struct acm_perf_msg { struct acm_ep_config_data { uint64_t dev_guid; uint8_t port_num; - uint8_t rsvd[3]; + uint8_t phys_port_cnt; + uint8_t rsvd[2]; uint16_t pkey; uint16_t addr_cnt; uint8_t prov_name[ACM_MAX_PROV_NAME]; diff --git a/ibacm/src/acm.c b/ibacm/src/acm.c index 6453c5f0..8f25f34b 100644 --- a/ibacm/src/acm.c +++ b/ibacm/src/acm.c @@ -876,7 +876,9 @@ static struct acmc_addr *acm_get_ep_address(struct acm_ep_addr_data *data) return NULL; } -static struct acmc_ep *acm_get_ep(int index) +/* If port_num is zero, iterate through all ports, otherwise consider + * only the specific port_num */ +static struct acmc_ep *acm_get_ep(int index, uint8_t port_num) { struct acmc_device *dev; struct acmc_ep *ep; @@ -885,6 +887,8 @@ static struct acmc_ep *acm_get_ep(int index) acm_log(2, "ep index %d\n", index); list_for_each(&dev_list, dev, entry) { for (i = 0; i < dev->port_cnt; i++) { + if (port_num && port_num != (i + 1)) + continue; if (dev->port[i].state != IBV_PORT_ACTIVE) continue; list_for_each(&dev->port[i].ep_list, ep, entry) { @@ -1156,7 +1160,7 @@ static int acm_svr_perf_query(struct acmc_client *client, struct acm_msg *msg) len = ACM_MSG_HDR_LENGTH + (ACM_MAX_COUNTER * sizeof(uint64_t)); } else { if (index >= 1) { - ep = acm_get_ep(index - 1); + ep = acm_get_ep(index - 1, msg->hdr.port_num); } else { addr = acm_get_ep_address(&msg->resolve_data[0]); if (addr) @@ -1193,11 +1197,12 @@ static int acm_svr_ep_query(struct acmc_client *client, struct acm_msg *msg) acm_log(2, "client %d\n", client->index); index = msg->hdr.data[0]; - ep = acm_get_ep(index - 1); + ep = acm_get_ep(index - 1, msg->hdr.port_num); if (ep) { msg->hdr.status = ACM_STATUS_SUCCESS; msg->ep_data[0].dev_guid = ep->port->dev->device.dev_guid; msg->ep_data[0].port_num = ep->port->port.port_num; + msg->ep_data[0].phys_port_cnt = ep->port->dev->port_cnt; msg->ep_data[0].pkey = htobe16(ep->endpoint.pkey); strncpy((char *)msg->ep_data[0].prov_name, ep->port->prov->name, ACM_MAX_PROV_NAME - 1); diff --git a/ibacm/src/acme.c b/ibacm/src/acme.c index b592b977..1289fa36 100644 --- a/ibacm/src/acme.c +++ b/ibacm/src/acme.c @@ -926,24 +926,32 @@ static int enumerate_ep(char *svc, int index) static int labels; int ret, i; struct acm_ep_config_data *ep_data; + int phys_port_cnt = 255; + int found = 0; + int port; - ret = ib_acm_enum_ep(index, &ep_data); - if (ret) - return ret; + for (port = 1; port <= phys_port_cnt; ++port) { + ret = ib_acm_enum_ep(index, &ep_data, port); + if (ret) + continue; - if (!labels) { - printf("svc,guid,port,pkey,ep_index,prov,addr_0,addresses\n"); - labels = 1; - } + found = 1; - printf("%s,0x%016" PRIx64 ",%d,0x%04x,%d,%s", svc, ep_data->dev_guid, - ep_data->port_num, ep_data->pkey, index, ep_data->prov_name); - for (i = 0; i < ep_data->addr_cnt; i++) - printf(",%s", ep_data->addrs[i].name); - printf("\n"); - ib_acm_free_ep_data(ep_data); + if (!labels) { + printf("svc,guid,port,pkey,ep_index,prov,addr_0,addresses\n"); + labels = 1; + } - return 0; + printf("%s,0x%016" PRIx64 ",%d,0x%04x,%d,%s", svc, ep_data->dev_guid, + ep_data->port_num, ep_data->pkey, index, ep_data->prov_name); + for (i = 0; i < ep_data->addr_cnt; i++) + printf(",%s", ep_data->addrs[i].name); + printf("\n"); + phys_port_cnt = ep_data->phys_port_cnt; + ib_acm_free_ep_data(ep_data); + } + + return !found; } static void enumerate_eps(char *svc) diff --git a/ibacm/src/libacm.c b/ibacm/src/libacm.c index 1d9d7145..92f5baf9 100644 --- a/ibacm/src/libacm.c +++ b/ibacm/src/libacm.c @@ -382,18 +382,21 @@ out: return ret; } -int ib_acm_enum_ep(int index, struct acm_ep_config_data **data) +int ib_acm_enum_ep(int index, struct acm_ep_config_data **data, uint8_t port) { + struct acm_ep_config_data *netw_edata = NULL; + struct acm_ep_config_data *host_edata = NULL; + struct acm_hdr hdr; struct acm_msg msg; int ret; int len; - int cnt; - struct acm_ep_config_data *edata; + int i; pthread_mutex_lock(&acm_lock); memset(&msg, 0, sizeof msg); msg.hdr.version = ACM_VERSION; msg.hdr.opcode = ACM_OP_EP_QUERY; + msg.hdr.port_num = port; msg.hdr.data[0] = index; msg.hdr.length = htobe16(ACM_MSG_HDR_LENGTH); @@ -401,33 +404,49 @@ int ib_acm_enum_ep(int index, struct acm_ep_config_data **data) if (ret != ACM_MSG_HDR_LENGTH) goto out; - ret = recv(sock, (char *) &msg, sizeof msg, 0); - if (ret < ACM_MSG_HDR_LENGTH || ret != be16toh(msg.hdr.length)) { + ret = recv(sock, (char *) &hdr, sizeof(hdr), 0); + if (ret != sizeof(hdr)) { ret = ACM_STATUS_EINVAL; goto out; } - if (msg.hdr.status) { - ret = acm_error(msg.hdr.status); + if (hdr.status) { + ret = acm_error(hdr.status); goto out; } - cnt = be16toh(msg.ep_data[0].addr_cnt); - len = sizeof(struct acm_ep_config_data) + - ACM_MAX_ADDRESS * cnt; - edata = malloc(len); - if (!edata) { + len = be16toh(hdr.length) - sizeof(hdr); + netw_edata = (struct acm_ep_config_data *)malloc(len); + host_edata = (struct acm_ep_config_data *)malloc(len); + if (!netw_edata || !host_edata) { ret = ACM_STATUS_ENOMEM; goto out; } - memcpy(edata, &msg.ep_data[0], len); - edata->dev_guid = be64toh(msg.ep_data[0].dev_guid); - edata->pkey = be16toh(msg.ep_data[0].pkey); - edata->addr_cnt = cnt; - *data = edata; + ret = recv(sock, (char *)netw_edata, len, 0); + if (ret != len) { + ret = ACM_STATUS_EINVAL; + goto out; + } + + host_edata->dev_guid = be64toh(netw_edata->dev_guid); + host_edata->port_num = netw_edata->port_num; + host_edata->phys_port_cnt = netw_edata->phys_port_cnt; + host_edata->pkey = be16toh(netw_edata->pkey); + host_edata->addr_cnt = be16toh(netw_edata->addr_cnt); + + memcpy(host_edata->prov_name, netw_edata->prov_name, + sizeof(host_edata->prov_name)); + + for (i = 0; i < host_edata->addr_cnt; ++i) + host_edata->addrs[i] = netw_edata->addrs[i]; + + *data = host_edata; ret = 0; out: + free(netw_edata); + if (ret) + free(host_edata); pthread_mutex_unlock(&acm_lock); return ret; } diff --git a/ibacm/src/libacm.h b/ibacm/src/libacm.h index bf8cb79b..fb81b417 100644 --- a/ibacm/src/libacm.h +++ b/ibacm/src/libacm.h @@ -54,7 +54,7 @@ int ib_acm_query_perf_ep_addr(uint8_t *src, uint8_t type, const char *ib_acm_cntr_name(int index); -int ib_acm_enum_ep(int index, struct acm_ep_config_data **data); +int ib_acm_enum_ep(int index, struct acm_ep_config_data **data, uint8_t port); #define ib_acm_free_ep_data(data) free(data) #endif /* LIBACM_H */