Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3452504imm; Tue, 29 May 2018 07:30:55 -0700 (PDT) X-Google-Smtp-Source: AB8JxZo6Zj9dPyvn9DuJG/EGZOZT126X28En40jQW+pSIsQgJ0Ozuy39+bSQJEE1mXySszSGf2r5 X-Received: by 2002:a17:902:581:: with SMTP id f1-v6mr17976931plf.48.1527604254966; Tue, 29 May 2018 07:30:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527604254; cv=none; d=google.com; s=arc-20160816; b=bMAtvn5Vfyib2ETnecnxDnCk+o7Fe5kibZHbfl/j0Eb1SZowl48eumdLdfrq33AdQJ x+PxQ9zRWUExvvFEVDd6qpg43u5Ax/doQ4u0uZHdXJUu42Ju9B3b6FhVGgBRdxp1dTyP qi0+m3GNOTeL0YH6qpPeT3Y7UflYA0DcHxoUIsIXduCPg0jcdciKTBNEk9CplllvL9K9 3IRmJZ/TbmGLWHgVgj+ocJrPcBgZIK26BeUfODvwluE2P1JxTiST4Mbfgqc6hReBCw/V AiWQwOP+HhBDTLu9/ffpEdKoaro/0pCWdAu2tJgfx8yzE6d+u2zFqYypFi2VoKDFXj31 31HA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=maLHTQgXyoMV7ilEqF5mhztiHxnL3UFgm5lV906Mdn4=; b=ZQ+p5DZe8QHxb6a8JMrc97ke6+PZwosJBpnFV5HWDMrEglAO9LFiqo1PKvL9ImNfRf wX/YhhjQ4tss4U+kPKwPFSENpT/tTzi2gVqzmr1uURXbWVcV3F8kw7tKjhb+3eURsoVo ZiiYTa3BNEGx25/hbUWLjBn441OOXTK1p6X2q2MSbUMy8nfINyejqxdsj1Hy9yb/z2Eq fA93byIyDEwQX6RjAadrh22skJSpoSV7VRW1qjsV5MdJjQlJT58H8QT6GhVDZjeNv9S8 muX7ettaAXaBiRiDIb4WI2M5DAY/4SH/PPWTaPoE+4jyb7qomOD5d/LlOoN6Zq2nDGq3 dzyQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 67-v6si10409276pge.373.2018.05.29.07.30.40; Tue, 29 May 2018 07:30:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935011AbeE2O2c (ORCPT + 99 others); Tue, 29 May 2018 10:28:32 -0400 Received: from smtp4.ccs.ornl.gov ([160.91.203.40]:38208 "EHLO smtp4.ccs.ornl.gov" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935086AbeE2OWO (ORCPT ); Tue, 29 May 2018 10:22:14 -0400 Received: from star.ccs.ornl.gov (star.ccs.ornl.gov [160.91.202.134]) by smtp4.ccs.ornl.gov (Postfix) with ESMTP id CA91A100527E; Tue, 29 May 2018 10:22:06 -0400 (EDT) Received: by star.ccs.ornl.gov (Postfix, from userid 2004) id C7A602C1; Tue, 29 May 2018 10:22:06 -0400 (EDT) From: James Simmons To: Greg Kroah-Hartman , devel@driverdev.osuosl.org, Andreas Dilger , Oleg Drokin , NeilBrown Cc: Linux Kernel Mailing List , Lustre Development List , James Simmons , James Simmons Subject: [PATCH v2 04/25] staging: lustre: libcfs: properly handle failure cases in SMP code Date: Tue, 29 May 2018 10:21:44 -0400 Message-Id: <1527603725-30560-5-git-send-email-jsimmons@infradead.org> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1527603725-30560-1-git-send-email-jsimmons@infradead.org> References: <1527603725-30560-1-git-send-email-jsimmons@infradead.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org While pushing the SMP work some bugs were pointed out by Dan Carpenter in the code. Due to single err label in cfs_cpu_init() and cfs_cpt_table_alloc() a few items were being cleaned up that were never initialized. This can lead to crashed and other problems. In those initialization function introduce individual labels to jump to only the thing initialized get freed on failure. Signed-off-by: James Simmons Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-10932 Reviewed-on: https://review.whamcloud.com/32085 Reviewed-by: Dmitry Eremin Reviewed-by: Andreas Dilger Signed-off-by: James Simmons --- Changelog: v1) New patch to make libcfs SMP code handle failure paths correctly. drivers/staging/lustre/lnet/libcfs/libcfs_cpu.c | 72 ++++++++++++++++++------- 1 file changed, 52 insertions(+), 20 deletions(-) diff --git a/drivers/staging/lustre/lnet/libcfs/libcfs_cpu.c b/drivers/staging/lustre/lnet/libcfs/libcfs_cpu.c index 34df7ed..b67a60c 100644 --- a/drivers/staging/lustre/lnet/libcfs/libcfs_cpu.c +++ b/drivers/staging/lustre/lnet/libcfs/libcfs_cpu.c @@ -81,17 +81,19 @@ struct cfs_cpt_table * cptab->ctb_nparts = ncpt; + if (!zalloc_cpumask_var(&cptab->ctb_cpumask, GFP_NOFS)) + goto failed_alloc_cpumask; + cptab->ctb_nodemask = kzalloc(sizeof(*cptab->ctb_nodemask), GFP_NOFS); - if (!zalloc_cpumask_var(&cptab->ctb_cpumask, GFP_NOFS) || - !cptab->ctb_nodemask) - goto failed; + if (!cptab->ctb_nodemask) + goto failed_alloc_nodemask; cptab->ctb_cpu2cpt = kvmalloc_array(num_possible_cpus(), sizeof(cptab->ctb_cpu2cpt[0]), GFP_KERNEL); if (!cptab->ctb_cpu2cpt) - goto failed; + goto failed_alloc_cpu2cpt; memset(cptab->ctb_cpu2cpt, -1, num_possible_cpus() * sizeof(cptab->ctb_cpu2cpt[0])); @@ -99,22 +101,41 @@ struct cfs_cpt_table * cptab->ctb_parts = kvmalloc_array(ncpt, sizeof(cptab->ctb_parts[0]), GFP_KERNEL); if (!cptab->ctb_parts) - goto failed; + goto failed_alloc_ctb_parts; + + memset(cptab->ctb_parts, -1, ncpt * sizeof(cptab->ctb_parts[0])); for (i = 0; i < ncpt; i++) { struct cfs_cpu_partition *part = &cptab->ctb_parts[i]; + if (!zalloc_cpumask_var(&part->cpt_cpumask, GFP_NOFS)) + goto failed_setting_ctb_parts; + part->cpt_nodemask = kzalloc(sizeof(*part->cpt_nodemask), GFP_NOFS); - if (!zalloc_cpumask_var(&part->cpt_cpumask, GFP_NOFS) || - !part->cpt_nodemask) - goto failed; + if (!part->cpt_nodemask) + goto failed_setting_ctb_parts; } return cptab; - failed: - cfs_cpt_table_free(cptab); +failed_setting_ctb_parts: + while (i-- >= 0) { + struct cfs_cpu_partition *part = &cptab->ctb_parts[i]; + + kfree(part->cpt_nodemask); + free_cpumask_var(part->cpt_cpumask); + } + + kvfree(cptab->ctb_parts); +failed_alloc_ctb_parts: + kvfree(cptab->ctb_cpu2cpt); +failed_alloc_cpu2cpt: + kfree(cptab->ctb_nodemask); +failed_alloc_nodemask: + free_cpumask_var(cptab->ctb_cpumask); +failed_alloc_cpumask: + kfree(cptab); return NULL; } EXPORT_SYMBOL(cfs_cpt_table_alloc); @@ -940,7 +961,7 @@ static int cfs_cpu_dead(unsigned int cpu) int cfs_cpu_init(void) { - int ret = 0; + int ret; LASSERT(!cfs_cpt_tab); @@ -949,23 +970,23 @@ static int cfs_cpu_dead(unsigned int cpu) "staging/lustre/cfe:dead", NULL, cfs_cpu_dead); if (ret < 0) - goto failed; + goto failed_cpu_dead; + ret = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, "staging/lustre/cfe:online", cfs_cpu_online, NULL); if (ret < 0) - goto failed; + goto failed_cpu_online; + lustre_cpu_online = ret; #endif - ret = -EINVAL; - get_online_cpus(); if (*cpu_pattern) { char *cpu_pattern_dup = kstrdup(cpu_pattern, GFP_KERNEL); if (!cpu_pattern_dup) { CERROR("Failed to duplicate cpu_pattern\n"); - goto failed; + goto failed_alloc_table; } cfs_cpt_tab = cfs_cpt_table_create_pattern(cpu_pattern_dup); @@ -973,7 +994,7 @@ static int cfs_cpu_dead(unsigned int cpu) if (!cfs_cpt_tab) { CERROR("Failed to create cptab from pattern %s\n", cpu_pattern); - goto failed; + goto failed_alloc_table; } } else { @@ -981,7 +1002,7 @@ static int cfs_cpu_dead(unsigned int cpu) if (!cfs_cpt_tab) { CERROR("Failed to create ptable with npartitions %d\n", cpu_npartitions); - goto failed; + goto failed_alloc_table; } } @@ -992,8 +1013,19 @@ static int cfs_cpu_dead(unsigned int cpu) cfs_cpt_number(cfs_cpt_tab)); return 0; - failed: +failed_alloc_table: put_online_cpus(); - cfs_cpu_fini(); + + if (cfs_cpt_tab) + cfs_cpt_table_free(cfs_cpt_tab); + + ret = -EINVAL; +#ifdef CONFIG_HOTPLUG_CPU + if (lustre_cpu_online > 0) + cpuhp_remove_state_nocalls(lustre_cpu_online); +failed_cpu_online: + cpuhp_remove_state_nocalls(CPUHP_LUSTRE_CFS_DEAD); +failed_cpu_dead: +#endif return ret; } -- 1.8.3.1