From patchwork Fri Feb 11 22:12:06 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 550931 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 p1BMCAtN012622 for ; Fri, 11 Feb 2011 22:12:10 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758267Ab1BKWMJ (ORCPT ); Fri, 11 Feb 2011 17:12:09 -0500 Received: from quartz.orcorp.ca ([139.142.54.143]:52513 "EHLO quartz.orcorp.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758116Ab1BKWMI (ORCPT ); Fri, 11 Feb 2011 17:12:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=obsidianresearch.com; s=rsa1; h=Content-Type:MIME-Version:Message-ID:Subject:To:From:Date; bh=SzisETDBXUlc1ngyfkm3ylRZjomuB7ZlaGhcmQv+q10=; b=Da9CD7xOnFgr+DcOseEGH2euLIutgiNadNAUttG4fgb3Ndp5LRdKBd6Za90mSGlW0DWG5VCoar+GACc6GMI2kCdy1OUuopZ5kq8P6CfHCeBdQ3Rs6aqIrcJ+yOrVLUR0sHoGJON+YHfZnsEAz4v+n9EghoOn8wkXVM6bf6yG6YI=; Received: from [10.0.0.11] (helo=jggl.edm.orcorp.ca) by quartz.orcorp.ca with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.72) (envelope-from ) id 1Po1Di-0005y4-JL; Fri, 11 Feb 2011 15:12:06 -0700 Received: from jgg by jggl.edm.orcorp.ca with local (Exim 4.72) (envelope-from ) id 1Po1Di-0002EQ-5R; Fri, 11 Feb 2011 15:12:06 -0700 Date: Fri, 11 Feb 2011 15:12:06 -0700 From: Jason Gunthorpe To: linux-rdma , Alex Netes Subject: [PATCH/opensm] Decode the SAPKeyTableRecord block number properly, and don't segv Message-ID: <20110211221206.GA8532@obsidianresearch.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-Broken-Reverse-DNS: no host name found for IP address 10.0.0.11 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]); Fri, 11 Feb 2011 22:12:10 +0000 (UTC) diff --git a/opensm/include/iba/ib_types.h b/opensm/include/iba/ib_types.h index e1bc102..24f5662 100644 --- a/opensm/include/iba/ib_types.h +++ b/opensm/include/iba/ib_types.h @@ -6724,7 +6724,7 @@ typedef struct _ib_pkey_table { #include typedef struct _ib_pkey_table_record { ib_net16_t lid; // for CA: lid of port, for switch lid of port 0 - uint16_t block_num; + ib_net16_t block_num; uint8_t port_num; // for switch: port number, for CA: reserved uint8_t reserved1; uint16_t reserved2; diff --git a/opensm/opensm/osm_sa_pkey_record.c b/opensm/opensm/osm_sa_pkey_record.c index e4930d0..cf50430 100644 --- a/opensm/opensm/osm_sa_pkey_record.c +++ b/opensm/opensm/osm_sa_pkey_record.c @@ -71,6 +71,7 @@ static void sa_pkey_create(IN osm_sa_t * sa, IN osm_physp_t * p_physp, osm_pkey_item_t *p_rec_item; uint16_t lid; ib_api_status_t status = IB_SUCCESS; + ib_pkey_table_t *tbl; OSM_LOG_ENTER(sa->p_log); @@ -98,8 +99,15 @@ static void sa_pkey_create(IN osm_sa_t * sa, IN osm_physp_t * p_physp, p_rec_item->rec.lid = lid; p_rec_item->rec.block_num = block; p_rec_item->rec.port_num = osm_physp_get_port_num(p_physp); - p_rec_item->rec.pkey_tbl = - *(osm_pkey_tbl_block_get(osm_physp_get_pkey_tbl(p_physp), block)); + /* FIXME: There are ninf.PartitionCap or swinf.PartitionEnforcementCap + pkey entries so everything in that range is a valid block number + even if opensm is not using it. Return 0. However things outside + that range should return no entries.. Not sure how to figure that + here? The range of pkey_tbl can be less than the cap, so + this falsely triggers. */ + tbl = osm_pkey_tbl_block_get(osm_physp_get_pkey_tbl(p_physp), block); + if (tbl) + p_rec_item->rec.pkey_tbl = *tbl; cl_qlist_insert_tail(p_ctxt->p_list, &p_rec_item->list_item); @@ -269,14 +277,14 @@ void osm_pkey_rec_rcv_process(IN void *ctx, IN void *data) context.p_list = &rec_list; context.comp_mask = p_rcvd_mad->comp_mask; context.sa = sa; - context.block_num = p_rcvd_rec->block_num; + context.block_num = cl_ntoh16(p_rcvd_rec->block_num); context.p_req_physp = p_req_physp; OSM_LOG(sa->p_log, OSM_LOG_DEBUG, "Got Query Lid:%u(%02X), Block:0x%02X(%02X), Port:0x%02X(%02X)\n", cl_ntoh16(p_rcvd_rec->lid), (comp_mask & IB_PKEY_COMPMASK_LID) != 0, p_rcvd_rec->port_num, - (comp_mask & IB_PKEY_COMPMASK_PORT) != 0, p_rcvd_rec->block_num, + (comp_mask & IB_PKEY_COMPMASK_PORT) != 0, context.block_num, (comp_mask & IB_PKEY_COMPMASK_BLOCK) != 0); cl_plock_acquire(sa->p_lock);