All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] x86/intel_rdt: Fix cache pseudo-locking error path cleanup
@ 2018-07-01  5:03 Reinette Chatre
  2018-07-01  5:03 ` [PATCH 1/2] x86/intel_rdt: Move pseudo_lock_region_clear Reinette Chatre
  2018-07-01  5:03 ` [PATCH 2/2] x86/intel_rdt: Fix cleanup of plr structure on error Reinette Chatre
  0 siblings, 2 replies; 5+ messages in thread
From: Reinette Chatre @ 2018-07-01  5:03 UTC (permalink / raw)
  To: tglx, fenghua.yu, tony.luck, vikas.shivappa
  Cc: gavin.hindman, jithu.joseph, dave.hansen, mingo, hpa, x86,
	linux-kernel, Reinette Chatre

Dear Maintainers,

A bug exists in the error handling code during pseudo-lock region creation.
When an error occurs early during pseudo-lock region creation the
pseudo_lock_region struct is not cleaned up properly but remains associated
with the resource group (since it remains in pseudo-locksetup mode).
This partially initialized struct causes problems when other areas
need to obtain resource group data - when partially initialized the
resource group is treated as a pseudo-locked region.

Following is an example of the error being encountered. First a
pseudo-locked region of larger than 4MB is attempted. This fails early
because of lack for support. Since this is not cleaned up properly,
a subsequent attempt fails because it is (incorrectly) believed that
a pseudo-locked region already exists, also the bit_usage file
reports incorrect data.

# mount -t resctrl resctrl /sys/fs/resctrl
# cd /sys/fs/resctrl/
# mkdir p1
# echo 'L3:1=0xffff0' > schemata
# echo pseudo-locksetup > p1/mode
# echo 'L3:1=0xf' > p1/schemata
-bash: echo: write error: Argument list too long
# cat info/last_cmd_status
requested region exceeds maximum size
# echo 'L3:1=0x1' > p1/schemata
-bash: echo: write error: Invalid argument
# cat info/last_cmd_status
pseudo-locked region in hierarchy
# cat info/L3/bit_usage
0=XXSSSSSSSSSSSSSSSSSS;1=XXSSSSSSSSSSSSSSPPPP

After the fixes in this series have been applied:
# mount -t resctrl resctrl /sys/fs/resctrl/
# cd /sys/fs/resctrl/
# mkdir p1
# echo pseudo-locksetup > p1/mode
# echo 'L3:1=0xffff0' > schemata
# echo 'L3:1=0xf' > p1/schemata
-bash: echo: write error: Argument list too long
# cat info/last_cmd_status
requested region exceeds maximum size
# cat info/L3/bit_usage
0=XXSSSSSSSSSSSSSSSSSS;1=XXSSSSSSSSSSSSSS0000
# echo 'L3:1=0x1' > p1/schemata
# cat info/L3/bit_usage
0=XXSSSSSSSSSSSSSSSSSS;1=XXSSSSSSSSSSSSSS000P


Reinette Chatre (2):
  x86/intel_rdt: Move pseudo_lock_region_clear
  x86/intel_rdt: Fix cleanup of plr structure on error

 arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c | 68 ++++++++++++---------
 1 file changed, 40 insertions(+), 28 deletions(-)

-- 
2.17.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] x86/intel_rdt: Move pseudo_lock_region_clear
  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 ` 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 ` [PATCH 2/2] x86/intel_rdt: Fix cleanup of plr structure on error Reinette Chatre
  1 sibling, 1 reply; 5+ messages in thread
From: Reinette Chatre @ 2018-07-01  5:03 UTC (permalink / raw)
  To: tglx, fenghua.yu, tony.luck, vikas.shivappa
  Cc: gavin.hindman, jithu.joseph, dave.hansen, mingo, hpa, x86,
	linux-kernel, Reinette Chatre

The pseudo_lock_region_clear() function is moved to earlier in the
file in preparation for its use in functions that currently appear
before it. No functional change.

Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
---
 arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c | 46 ++++++++++-----------
 1 file changed, 23 insertions(+), 23 deletions(-)

diff --git a/arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c b/arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c
index 6e83f61552a5..1860ec10302d 100644
--- a/arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c
+++ b/arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c
@@ -246,6 +246,29 @@ static int pseudo_lock_cstates_constrain(struct pseudo_lock_region *plr)
 	return ret;
 }
 
+/**
+ * pseudo_lock_region_clear - Reset pseudo-lock region data
+ * @plr: pseudo-lock region
+ *
+ * All content of the pseudo-locked region is reset - any memory allocated
+ * freed.
+ *
+ * Return: void
+ */
+static void pseudo_lock_region_clear(struct pseudo_lock_region *plr)
+{
+	plr->size = 0;
+	plr->line_size = 0;
+	kfree(plr->kmem);
+	plr->kmem = NULL;
+	plr->r = NULL;
+	if (plr->d)
+		plr->d->plr = NULL;
+	plr->d = NULL;
+	plr->cbm = 0;
+	plr->debugfs_dir = NULL;
+}
+
 /**
  * pseudo_lock_region_init - Initialize pseudo-lock region information
  * @plr: pseudo-lock region
@@ -318,29 +341,6 @@ static int pseudo_lock_init(struct rdtgroup *rdtgrp)
 	return 0;
 }
 
-/**
- * pseudo_lock_region_clear - Reset pseudo-lock region data
- * @plr: pseudo-lock region
- *
- * All content of the pseudo-locked region is reset - any memory allocated
- * freed.
- *
- * Return: void
- */
-static void pseudo_lock_region_clear(struct pseudo_lock_region *plr)
-{
-	plr->size = 0;
-	plr->line_size = 0;
-	kfree(plr->kmem);
-	plr->kmem = NULL;
-	plr->r = NULL;
-	if (plr->d)
-		plr->d->plr = NULL;
-	plr->d = NULL;
-	plr->cbm = 0;
-	plr->debugfs_dir = NULL;
-}
-
 /**
  * pseudo_lock_region_alloc - Allocate kernel memory that will be pseudo-locked
  * @plr: pseudo-lock region
-- 
2.17.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] x86/intel_rdt: Fix cleanup of plr structure on error
  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-01  5:03 ` Reinette Chatre
  2018-07-03  6:43   ` [tip:x86/cache] " tip-bot for Reinette Chatre
  1 sibling, 1 reply; 5+ messages in thread
From: Reinette Chatre @ 2018-07-01  5:03 UTC (permalink / raw)
  To: tglx, fenghua.yu, tony.luck, vikas.shivappa
  Cc: gavin.hindman, jithu.joseph, dave.hansen, mingo, hpa, x86,
	linux-kernel, Reinette Chatre

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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [tip:x86/cache] x86/intel_rdt: Move pseudo_lock_region_clear()
  2018-07-01  5:03 ` [PATCH 1/2] x86/intel_rdt: Move pseudo_lock_region_clear Reinette Chatre
@ 2018-07-03  6:42   ` tip-bot for Reinette Chatre
  0 siblings, 0 replies; 5+ messages in thread
From: tip-bot for Reinette Chatre @ 2018-07-03  6:42 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, hpa, tglx, mingo, reinette.chatre

Commit-ID:  ce730f1cc1255be152c879a2bc5f295d341d8036
Gitweb:     https://git.kernel.org/tip/ce730f1cc1255be152c879a2bc5f295d341d8036
Author:     Reinette Chatre <reinette.chatre@intel.com>
AuthorDate: Sat, 30 Jun 2018 22:03:02 -0700
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Tue, 3 Jul 2018 08:38:39 +0200

x86/intel_rdt: Move pseudo_lock_region_clear()

The pseudo_lock_region_clear() function is moved to earlier in the file in
preparation for its use in functions that currently appear before it. No
functional change.

Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: fenghua.yu@intel.com
Cc: tony.luck@intel.com
Cc: vikas.shivappa@linux.intel.com
Cc: gavin.hindman@intel.com
Cc: jithu.joseph@intel.com
Cc: dave.hansen@intel.com
Cc: hpa@zytor.com
Link: https://lkml.kernel.org/r/ef098ec2a45501e23792289bff80ae3152141e2f.1530421026.git.reinette.chatre@intel.com

---
 arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c | 46 ++++++++++++++---------------
 1 file changed, 23 insertions(+), 23 deletions(-)

diff --git a/arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c b/arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c
index 6e83f61552a5..1860ec10302d 100644
--- a/arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c
+++ b/arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c
@@ -246,6 +246,29 @@ out_err:
 	return ret;
 }
 
+/**
+ * pseudo_lock_region_clear - Reset pseudo-lock region data
+ * @plr: pseudo-lock region
+ *
+ * All content of the pseudo-locked region is reset - any memory allocated
+ * freed.
+ *
+ * Return: void
+ */
+static void pseudo_lock_region_clear(struct pseudo_lock_region *plr)
+{
+	plr->size = 0;
+	plr->line_size = 0;
+	kfree(plr->kmem);
+	plr->kmem = NULL;
+	plr->r = NULL;
+	if (plr->d)
+		plr->d->plr = NULL;
+	plr->d = NULL;
+	plr->cbm = 0;
+	plr->debugfs_dir = NULL;
+}
+
 /**
  * pseudo_lock_region_init - Initialize pseudo-lock region information
  * @plr: pseudo-lock region
@@ -318,29 +341,6 @@ static int pseudo_lock_init(struct rdtgroup *rdtgrp)
 	return 0;
 }
 
-/**
- * pseudo_lock_region_clear - Reset pseudo-lock region data
- * @plr: pseudo-lock region
- *
- * All content of the pseudo-locked region is reset - any memory allocated
- * freed.
- *
- * Return: void
- */
-static void pseudo_lock_region_clear(struct pseudo_lock_region *plr)
-{
-	plr->size = 0;
-	plr->line_size = 0;
-	kfree(plr->kmem);
-	plr->kmem = NULL;
-	plr->r = NULL;
-	if (plr->d)
-		plr->d->plr = NULL;
-	plr->d = NULL;
-	plr->cbm = 0;
-	plr->debugfs_dir = NULL;
-}
-
 /**
  * pseudo_lock_region_alloc - Allocate kernel memory that will be pseudo-locked
  * @plr: pseudo-lock region

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [tip:x86/cache] x86/intel_rdt: Fix cleanup of plr structure on error
  2018-07-01  5:03 ` [PATCH 2/2] x86/intel_rdt: Fix cleanup of plr structure on error Reinette Chatre
@ 2018-07-03  6:43   ` tip-bot for Reinette Chatre
  0 siblings, 0 replies; 5+ messages in thread
From: tip-bot for Reinette Chatre @ 2018-07-03  6:43 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: tglx, mingo, reinette.chatre, linux-kernel, hpa

Commit-ID:  546d3c74277398a3d76d059bd2db47186bb47fc8
Gitweb:     https://git.kernel.org/tip/546d3c74277398a3d76d059bd2db47186bb47fc8
Author:     Reinette Chatre <reinette.chatre@intel.com>
AuthorDate: Sat, 30 Jun 2018 22:03:03 -0700
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Tue, 3 Jul 2018 08:38:39 +0200

x86/intel_rdt: Fix cleanup of plr structure on error

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.

Fixes: 018961ae5579 ("x86/intel_rdt: Pseudo-lock region creation/removal core")
Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: fenghua.yu@intel.com
Cc: tony.luck@intel.com
Cc: vikas.shivappa@linux.intel.com
Cc: gavin.hindman@intel.com
Cc: jithu.joseph@intel.com
Cc: dave.hansen@intel.com
Cc: hpa@zytor.com
Link: https://lkml.kernel.org/r/49b4782f6d204d122cee3499e642b2772a98d2b4.1530421026.git.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;
 }
 
 /**

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-07-03  6:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 2/2] x86/intel_rdt: Fix cleanup of plr structure on error Reinette Chatre
2018-07-03  6:43   ` [tip:x86/cache] " tip-bot for Reinette Chatre

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.