From patchwork Mon Apr 11 19:39:43 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hal Rosenstock X-Patchwork-Id: 698691 X-Patchwork-Delegate: alexne@voltaire.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p3BJdi1J023091 for ; Mon, 11 Apr 2011 19:39:49 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754795Ab1DKTjs (ORCPT ); Mon, 11 Apr 2011 15:39:48 -0400 Received: from mail-bw0-f46.google.com ([209.85.214.46]:58364 "EHLO mail-bw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753756Ab1DKTjs (ORCPT ); Mon, 11 Apr 2011 15:39:48 -0400 Received: by mail-bw0-f46.google.com with SMTP id 15so4779653bwz.19 for ; Mon, 11 Apr 2011 12:39:47 -0700 (PDT) Received: by 10.204.19.3 with SMTP id y3mr647439bka.180.1302550787564; Mon, 11 Apr 2011 12:39:47 -0700 (PDT) Received: from [192.168.1.103] (c-75-69-247-31.hsd1.ma.comcast.net [75.69.247.31]) by mx.google.com with ESMTPS id w3sm3405478bkt.5.2011.04.11.12.39.45 (version=SSLv3 cipher=OTHER); Mon, 11 Apr 2011 12:39:46 -0700 (PDT) Message-ID: <4DA358FF.3060200@dev.mellanox.co.il> Date: Mon, 11 Apr 2011 15:39:43 -0400 From: Hal Rosenstock User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 MIME-Version: 1.0 To: Alex Netes CC: "linux-rdma@vger.kernel.org" Subject: [PATCH 2/2] opensm/osm_pkey_mgr.c: Handle osm_pkey_tbl_new_block_get returning NULL Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Mon, 11 Apr 2011 19:39:49 +0000 (UTC) Fixes seg fault when ib_pkey_is_invalid called in last_used_pkey_index Introduced by commit aebd9f9d9cdd1c60c2b3784c0c03cfe8f4014019 for better last block handling Signed-off-by: Hal Rosenstock --- -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/opensm/osm_pkey_mgr.c b/opensm/osm_pkey_mgr.c index 06d9b1e..a2021e9 100644 --- a/opensm/osm_pkey_mgr.c +++ b/opensm/osm_pkey_mgr.c @@ -375,14 +375,19 @@ static int pkey_mgr_update_port(osm_log_t * p_log, osm_sm_t * sm, return ret; } -static uint16_t last_used_pkey_index(const osm_port_t * const p_port, - const osm_pkey_tbl_t * p_pkey_tbl) +static int last_used_pkey_index(const osm_port_t * const p_port, + const osm_pkey_tbl_t * p_pkey_tbl, + uint16_t * p_last_index) { ib_pkey_table_t *last_block; uint16_t index, last_index = 0; + CL_ASSERT(p_last_index); + last_block = osm_pkey_tbl_new_block_get(p_pkey_tbl, p_pkey_tbl->used_blocks - 1); + if (!last_block) + return 1; if (p_pkey_tbl->used_blocks == p_pkey_tbl->max_blocks) last_index = cl_ntoh16(p_port->p_node->node_info.partition_cap) % IB_NUM_PKEY_ELEMENTS_IN_BLOCK; @@ -395,7 +400,8 @@ static uint16_t last_used_pkey_index(const osm_port_t * const p_port, break; } while (index != 0); - return index; + *p_last_index = index; + return 0; } static int update_peer_block(osm_log_t * p_log, osm_sm_t * sm, @@ -510,20 +516,21 @@ static int pkey_mgr_update_peer_port(osm_log_t * p_log, osm_sm_t * sm, p_peer_pkey_tbl->used_blocks = peer_block_idx + 1; if (p_peer_pkey_tbl->used_blocks == peer_max_blocks) { /* Is last used pkey index beyond switch peer port capacity ? */ - last_index = peer_block_idx * IB_NUM_PKEY_ELEMENTS_IN_BLOCK + - last_used_pkey_index(p_port, - p_peer_pkey_tbl); - if (cl_ntoh16(p_node->sw->switch_info.enforce_cap) <= last_index) { - OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 0507: " - "Not enough pkey entries (%u <= %u) on switch 0x%016" - PRIx64 " port %u (%s). Clearing Enforcement bit\n", - cl_ntoh16(p_node->sw->switch_info.enforce_cap), - last_index, - cl_ntoh64(osm_node_get_node_guid(p_node)), - osm_physp_get_port_num(peer), - p_node->print_desc); - enforce = FALSE; - ret = -1; + if (!last_used_pkey_index(p_port, p_peer_pkey_tbl, + &last_index)) { + last_index += peer_block_idx * IB_NUM_PKEY_ELEMENTS_IN_BLOCK; + if (cl_ntoh16(p_node->sw->switch_info.enforce_cap) <= last_index) { + OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 0507: " + "Not enough pkey entries (%u <= %u) on switch 0x%016" + PRIx64 " port %u (%s). Clearing Enforcement bit\n", + cl_ntoh16(p_node->sw->switch_info.enforce_cap), + last_index, + cl_ntoh64(osm_node_get_node_guid(p_node)), + osm_physp_get_port_num(peer), + p_node->print_desc); + enforce = FALSE; + ret = -1; + } } } } else {