Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp2487454imm; Sat, 30 Jun 2018 22:04:29 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcTA8swTfkK1txp5Zo05mck6RGj9brgDrV/NQhphH3oXmaAi7kYCn8Xtw7nVFvsVCRAeQA5 X-Received: by 2002:a62:930c:: with SMTP id b12-v6mr20469326pfe.193.1530421469089; Sat, 30 Jun 2018 22:04:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530421469; cv=none; d=google.com; s=arc-20160816; b=rdx3H5Vagtv0stM3/e7pULW5PJGSW8LjQ6c3xXw04f2hEgnTOv/bDY0XB5hDy29+VY n3MomW7InvoDKlW57e+7eTzSYM/art3EDQiDgxWoKs1Gk2K0kSMMzznYU5iTUXzQjaQ5 Li4GdqIf4qEmK83+58leBMdyV62v8rN0j61dYqUTnwevfMNH4Cf50Z+MSqeYxa0+e2Kb DScMaid9B59iDlV/0z8BNhG3Wxf/3SqlUPW0NLtXQNiK1+Cv7Q3oGFUK++9lfik/3wFe 2DEe4wMM51qgDnou644IUeO8twNRYLRcdfqBWiAY+xl+OL8eKIGWGLtmEgt5869WTIvJ CZjQ== 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:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=P1JHC/XR11PKtWFkliAn7HOieB5URHzqpx23/KFDWRg=; b=xvVi/copK+wdmv7Z5LDAv5MYV8GC0ABv252nf7WSH2Ugty3WQGvmCRUjOMHnuqFumn dVYOQHu5Bxg8XTzunRNtSwtGar089hw9j9ihJUpJjXi6Wm/yzjpfQQEeTxlcMJWWCrkd j43eD651Z8oUhPzhZkHMk9O7NIs6KFXLUAv3VknB/3Epv+BHugSAWMJjNkHh1bQbVMoJ 1YVBIoxBspFKWCNDLH7p109lf+Xrhcq0qqRdDw6QrelZ/C6GYm6vlxhlRHSHfvV4H7Kp aoTFu874IO6nCdaOjodORMs29rUzN1MZR2GSz53MSxwoQTc3+RgzTFWRh7u9KSY+z2nP lJwg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e6-v6si8639572pls.419.2018.06.30.22.04.15; Sat, 30 Jun 2018 22:04:29 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752036AbeGAFDa (ORCPT + 99 others); Sun, 1 Jul 2018 01:03:30 -0400 Received: from mga03.intel.com ([134.134.136.65]:48739 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751136AbeGAFDX (ORCPT ); Sun, 1 Jul 2018 01:03:23 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Jun 2018 22:03:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,293,1526367600"; d="scan'208";a="241698249" Received: from rchatre-s.jf.intel.com ([10.54.70.76]) by fmsmga005.fm.intel.com with ESMTP; 30 Jun 2018 22:03:21 -0700 From: Reinette Chatre To: tglx@linutronix.de, fenghua.yu@intel.com, tony.luck@intel.com, vikas.shivappa@linux.intel.com Cc: gavin.hindman@intel.com, jithu.joseph@intel.com, dave.hansen@intel.com, mingo@redhat.com, hpa@zytor.com, x86@kernel.org, linux-kernel@vger.kernel.org, Reinette Chatre Subject: [PATCH 2/2] x86/intel_rdt: Fix cleanup of plr structure on error Date: Sat, 30 Jun 2018 22:03:03 -0700 Message-Id: <49b4782f6d204d122cee3499e642b2772a98d2b4.1530421026.git.reinette.chatre@intel.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When a resource group enters pseudo-locksetup mode a pseudo_lock_region is associated with it. When the user writes to the resource group's schemata file the CBM of the requested pseudo-locked region is entered into the pseudo_lock_region struct. If any part of pseudo-lock region creation fails the resource group will remain in pseudo-locksetup mode with the pseudo_lock_region associated with it. In case of failure during pseudo-lock region creation care needs to be taken to ensure that the pseudo_lock_region struct associated with the resource group is cleared from any pseudo-locking data - especially the CBM. This is because the existence of a pseudo_lock_region struct with a CBM is significant in other areas of the code, for example, the display of bit_usage and initialization of a new resource group. Fix the error path of pseudo-lock region creation to ensure that the pseudo_lock_region struct is cleared at each error exit. Signed-off-by: Reinette Chatre --- arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c | 22 ++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c b/arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c index 1860ec10302d..8fd79c281ee6 100644 --- a/arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c +++ b/arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c @@ -290,6 +290,7 @@ static void pseudo_lock_region_clear(struct pseudo_lock_region *plr) static int pseudo_lock_region_init(struct pseudo_lock_region *plr) { struct cpu_cacheinfo *ci; + int ret; int i; /* Pick the first cpu we find that is associated with the cache. */ @@ -298,7 +299,8 @@ static int pseudo_lock_region_init(struct pseudo_lock_region *plr) if (!cpu_online(plr->cpu)) { rdt_last_cmd_printf("cpu %u associated with cache not online\n", plr->cpu); - return -ENODEV; + ret = -ENODEV; + goto out_region; } ci = get_cpu_cacheinfo(plr->cpu); @@ -312,8 +314,11 @@ static int pseudo_lock_region_init(struct pseudo_lock_region *plr) } } + ret = -1; rdt_last_cmd_puts("unable to determine cache line size\n"); - return -1; +out_region: + pseudo_lock_region_clear(plr); + return ret; } /** @@ -365,16 +370,23 @@ static int pseudo_lock_region_alloc(struct pseudo_lock_region *plr) */ if (plr->size > KMALLOC_MAX_SIZE) { rdt_last_cmd_puts("requested region exceeds maximum size\n"); - return -E2BIG; + ret = -E2BIG; + goto out_region; } plr->kmem = kzalloc(plr->size, GFP_KERNEL); if (!plr->kmem) { rdt_last_cmd_puts("unable to allocate memory\n"); - return -ENOMEM; + ret = -ENOMEM; + goto out_region; } - return 0; + ret = 0; + goto out; +out_region: + pseudo_lock_region_clear(plr); +out: + return ret; } /** -- 2.17.0