From patchwork Tue Jul 31 16:04:47 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Netes X-Patchwork-Id: 1260981 X-Patchwork-Delegate: alexne@voltaire.com Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id EDF23DF26F for ; Tue, 31 Jul 2012 16:09:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755454Ab2GaQJV (ORCPT ); Tue, 31 Jul 2012 12:09:21 -0400 Received: from mail-vb0-f46.google.com ([209.85.212.46]:54893 "EHLO mail-vb0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755441Ab2GaQJU (ORCPT ); Tue, 31 Jul 2012 12:09:20 -0400 Received: by mail-vb0-f46.google.com with SMTP id ff1so5920363vbb.19 for ; Tue, 31 Jul 2012 09:09:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=2sPGdmL0dCXLvAzAGzSBlT9B5E5qJnzZCU0iCePbiGo=; b=n1KUXqUHhUs151eQYwAkL3txqOb0zAhGudcYWkNBP2Bzlh91YPTKwtU3gxheR3b1x1 y5aDWdEb7CetBl+5WZ+Z7r/wA87RuNzgHWAleS4Tkn0huV/+gwYBUyQT/cIKk4cNJrZi b4hoWC/Puq1HcPdz/CjE9RSLiLmld7YpNnWwioJKYMnBplnnI3wijNRvvlCMzbWQpdGj ii06Enl2CwoW1cxlTDbCwb/RMEGkzjO2knWmbdbe8b8SZtlt5Jjf+J8WlBfWzOQbq8wP 2ma2YosOY9aPbydj0B4AXVJFdFSMiUpucBzCDZBMXpCfEXcIa+apvQjjwaXa/xnsMJsm H2qg== Received: by 10.52.70.242 with SMTP id p18mr12654952vdu.97.1343750960028; Tue, 31 Jul 2012 09:09:20 -0700 (PDT) Received: from localhost ([193.47.165.251]) by mx.google.com with ESMTPS id i13sm431350vdj.4.2012.07.31.09.09.18 (version=SSLv3 cipher=OTHER); Tue, 31 Jul 2012 09:09:19 -0700 (PDT) From: Alex Netes To: linux-rdma@vger.kernel.org Cc: Alex Netes , Hal Rosenstock , Vladimir Koushnir Subject: [PATCH 19/27] Fix crash in ucast cache when ucast cache invalidates after updating one of the switches Date: Tue, 31 Jul 2012 19:04:47 +0300 Message-Id: <1343750695-28063-19-git-send-email-alexne@mellanox.com> X-Mailer: git-send-email 1.7.11.2 In-Reply-To: <1343750695-28063-1-git-send-email-alexne@mellanox.com> References: <1343750695-28063-1-git-send-email-alexne@mellanox.com> X-Gm-Message-State: ALoCoQkJX9QSCPSEPzsYQ+noM9T2W1DsosI81vH9bK1lEcmsE8Lt7UlPLnGrYtPlL/sDepB10fFg Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Signed-off-by: Alex Netes Signed-off-by: Hal Rosenstock Signed-off-by: Vladimir Koushnir --- Changes since v2: Sets p_sw->lft_size = 0 in osm_ucast_cache_add_node() Changes since v1: Sets p_sw->lft_size only after successful malloc() --- opensm/osm_ucast_cache.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/opensm/osm_ucast_cache.c b/opensm/osm_ucast_cache.c index 701b8a8..fc28be7 100644 --- a/opensm/osm_ucast_cache.c +++ b/opensm/osm_ucast_cache.c @@ -318,8 +318,6 @@ cache_restore_ucast_info(osm_ucast_mgr_t * p_mgr, free(p_sw->new_lft); p_sw->new_lft = p_cache_sw->lft; p_cache_sw->lft = NULL; - p_sw->lft_size = (p_sw->max_lid_ho / IB_SMP_DATA_SIZE + 1) - * IB_SMP_DATA_SIZE; p_sw->num_hops = p_cache_sw->num_hops; p_cache_sw->num_hops = 0; @@ -978,6 +976,7 @@ void osm_ucast_cache_add_node(osm_ucast_mgr_t * p_mgr, osm_node_t * p_node) /* no LFT buffer, so we use the switch's LFT */ p_cache_sw->lft = p_node->sw->lft; p_node->sw->lft = NULL; + p_node->sw->lft_size = 0; } p_cache_sw->max_lid_ho = p_node->sw->max_lid_ho; } else { @@ -1007,6 +1006,7 @@ int osm_ucast_cache_process(osm_ucast_mgr_t * p_mgr) cl_qmap_t *tbl = &p_mgr->p_subn->sw_guid_tbl; cl_map_item_t *item; osm_switch_t *p_sw; + uint16_t lft_size; if (!p_mgr->p_subn->opt.use_ucast_cache) return 1; @@ -1028,10 +1028,12 @@ int osm_ucast_cache_process(osm_ucast_mgr_t * p_mgr) switch, but the LFT needs to be updated anyway */ p_sw->new_lft = p_sw->lft; - - p_sw->lft = malloc(p_sw->lft_size); + lft_size = (p_sw->max_lid_ho / IB_SMP_DATA_SIZE + 1) + * IB_SMP_DATA_SIZE; + p_sw->lft = malloc(lft_size); if (!p_sw->lft) return IB_INSUFFICIENT_MEMORY; + p_sw->lft_size = lft_size; memset(p_sw->lft, OSM_NO_PATH, p_sw->lft_size); }