linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Reinette Chatre <reinette.chatre@intel.com>
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 <reinette.chatre@intel.com>
Subject: [PATCH 2/2] x86/intel_rdt: Fix cleanup of plr structure on error
Date: Sat, 30 Jun 2018 22:03:03 -0700	[thread overview]
Message-ID: <49b4782f6d204d122cee3499e642b2772a98d2b4.1530421026.git.reinette.chatre@intel.com> (raw)
In-Reply-To: <cover.1530421026.git.reinette.chatre@intel.com>
In-Reply-To: <cover.1530421026.git.reinette.chatre@intel.com>

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 <reinette.chatre@intel.com>
---
 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


  parent reply	other threads:[~2018-07-01  5:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-01  5:03 [PATCH 0/2] x86/intel_rdt: Fix cache pseudo-locking error path cleanup Reinette Chatre
2018-07-01  5:03 ` [PATCH 1/2] x86/intel_rdt: Move pseudo_lock_region_clear Reinette Chatre
2018-07-03  6:42   ` [tip:x86/cache] x86/intel_rdt: Move pseudo_lock_region_clear() tip-bot for Reinette Chatre
2018-07-01  5:03 ` Reinette Chatre [this message]
2018-07-03  6:43   ` [tip:x86/cache] x86/intel_rdt: Fix cleanup of plr structure on error tip-bot for Reinette Chatre

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=49b4782f6d204d122cee3499e642b2772a98d2b4.1530421026.git.reinette.chatre@intel.com \
    --to=reinette.chatre@intel.com \
    --cc=dave.hansen@intel.com \
    --cc=fenghua.yu@intel.com \
    --cc=gavin.hindman@intel.com \
    --cc=hpa@zytor.com \
    --cc=jithu.joseph@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=tony.luck@intel.com \
    --cc=vikas.shivappa@linux.intel.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).