linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Jack Miller <millerjo@us.ibm.com>
To: linuxppc-dev@lists.ozlabs.org
Cc: preeti@linux.vnet.ibm.com, shreyas@linux.vnet.ibm.com, jk@ozlabs.org
Subject: [PATCH] powerpc/powernv: Fix idle state allocation corruption
Date: Wed, 20 May 2015 12:13:04 -0500	[thread overview]
Message-ID: <1432141984-5804-1-git-send-email-millerjo@us.ibm.com> (raw)

pnv_alloc_idle_core_states is iterating over PACAs based on the
configured maximum number of CPUs (NR_CPUS), but PACAs are only
initialized up to nr_cpu_ids, so rein in loops to keep from overwriting
adjacent memory.

Signed-off-by: Jack Miller <millerjo@us.ibm.com>
---
 arch/powerpc/platforms/powernv/setup.c | 26 +++++++++++---------------
 1 file changed, 11 insertions(+), 15 deletions(-)

diff --git a/arch/powerpc/platforms/powernv/setup.c b/arch/powerpc/platforms/powernv/setup.c
index ad0e32e..8e794b6 100644
--- a/arch/powerpc/platforms/powernv/setup.c
+++ b/arch/powerpc/platforms/powernv/setup.c
@@ -356,9 +356,8 @@ int pnv_save_sprs_for_winkle(void)
 
 static void pnv_alloc_idle_core_states(void)
 {
-	int i, j;
-	int nr_cores = cpu_nr_cores();
-	u32 *core_idle_state;
+	u32 *core_idle_state = NULL;
+	int i, thread;
 
 	/*
 	 * core_idle_state - First 8 bits track the idle state of each thread
@@ -371,20 +370,17 @@ static void pnv_alloc_idle_core_states(void)
 	 * b. While the last thread in the core is saving the core state, it
 	 * prevents a different thread from waking up.
 	 */
-	for (i = 0; i < nr_cores; i++) {
-		int first_cpu = i * threads_per_core;
-		int node = cpu_to_node(first_cpu);
+	for (i = 0; i < nr_cpu_ids; i++) {
+		thread = i % threads_per_core;
 
-		core_idle_state = kmalloc_node(sizeof(u32), GFP_KERNEL, node);
-		*core_idle_state = PNV_CORE_IDLE_THREAD_BITS;
-
-		for (j = 0; j < threads_per_core; j++) {
-			int cpu = first_cpu + j;
-
-			paca[cpu].core_idle_state_ptr = core_idle_state;
-			paca[cpu].thread_idle_state = PNV_THREAD_RUNNING;
-			paca[cpu].thread_mask = 1 << j;
+		if (thread == 0) {
+			core_idle_state = kmalloc_node(sizeof(u32), GFP_KERNEL, cpu_to_node(i));
+			*core_idle_state = PNV_CORE_IDLE_THREAD_BITS;
 		}
+
+		paca[i].core_idle_state_ptr = core_idle_state;
+		paca[i].thread_idle_state = PNV_THREAD_RUNNING;
+		paca[i].thread_mask = 1 << thread;
 	}
 
 	update_subcore_sibling_mask();
-- 
2.4.1

             reply	other threads:[~2015-05-20 17:13 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-20 17:13 Jack Miller [this message]
2015-05-20 17:28 ` [PATCH] powerpc/powernv: Fix idle state allocation corruption Shreyas B Prabhu
2015-05-20 19:02   ` Jack Miller

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=1432141984-5804-1-git-send-email-millerjo@us.ibm.com \
    --to=millerjo@us.ibm.com \
    --cc=jk@ozlabs.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=preeti@linux.vnet.ibm.com \
    --cc=shreyas@linux.vnet.ibm.com \
    /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).