LinuxPPC-Dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Bringmann <mwb@linux.vnet.ibm.com>
To: linuxppc-dev@lists.ozlabs.org
Cc: Michael Bringmann <mwb@linux.vnet.ibm.com>, nfont@linux.vnet.ibm.com
Subject: [PATCH] powerpc/hotplug/drcinfo: Fixes bug with hot-add of CPUs
Date: Thu, 1 Feb 2018 15:59:02 -0600	[thread overview]
Message-ID: <bd7f8d6d-3a60-9833-87f9-e7acccbf9354@linux.vnet.ibm.com> (raw)

This patch fixes a bug matching drc-indexes of CPUs that are
being hot-added to a system either individually or by count.
This patch inserts a couple of missing checks and parsing code
for the new representation of device-tree information provided
by the property "ibm,drc-info".

Signed-off-by: Michael Bringmann <mwb@linux.vnet.ibm.com>
Fixes: 3f38000eda48 ("powerpc/firmware: Add definitions for new drc-info firmwar
e feature" -- end of patch series applied to powerpc next)
---
 arch/powerpc/platforms/pseries/hotplug-cpu.c |  117 +++++++++++++++++++++-----
 1 file changed, 96 insertions(+), 21 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/hotplug-cpu.c b/arch/powerpc/platforms/pseries/hotplug-cpu.c
index a7d14aa7..4cc6b70 100644
--- a/arch/powerpc/platforms/pseries/hotplug-cpu.c
+++ b/arch/powerpc/platforms/pseries/hotplug-cpu.c
@@ -413,19 +413,52 @@ static bool valid_cpu_drc_index(struct device_node *parent, u32 drc_index)
 	bool found = false;
 	int rc, index;
 
-	index = 0;
-	while (!found) {
-		u32 drc;
+	if (firmware_has_feature(FW_FEATURE_DRC_INFO)) {
+		struct property *info = NULL;
+		struct of_drc_info drc;
+		int j;
+		u32 num_set_entries;
+		const __be32 *value;
+
+		info = of_find_property(parent, "ibm,drc-info", NULL);
+		if (info == NULL)
+			goto end_out;
+
+		value = of_prop_next_u32(info, NULL, &num_set_entries);
+		if (!value)
+			goto end_out;
+		value++;
+
+		for (j = 0; j < num_set_entries; j++) {
+
+			of_read_drc_info_cell(&info, &value, &drc);
+			if (strncmp(drc.drc_type, "CPU", 3))
+				goto end_out;
+
+			if ((drc.drc_index_start <= drc_index) &&
+				(drc_index <= drc.last_drc_index)) {
+				found = true;
+				break;
+			}
+		}
 
-		rc = of_property_read_u32_index(parent, "ibm,drc-indexes",
+	} else {
+		index = 0;
+		while (!found) {
+			u32 drc;
+
+			rc = of_property_read_u32_index(parent,
+						"ibm,drc-indexes",
 						index++, &drc);
-		if (rc)
-			break;
+			if (rc)
+				break;
 
-		if (drc == drc_index)
-			found = true;
+			if (drc == drc_index)
+				found = true;
+		}
 	}
 
+end_out:
 	return found;
 }
 
@@ -731,26 +764,68 @@ static int find_dlpar_cpus_to_add(u32 *cpu_drcs, u32 cpus_to_add)
 		return -1;
 	}
 
-	/* Search the ibm,drc-indexes array for possible CPU drcs to
-	 * add. Note that the format of the ibm,drc-indexes array is
-	 * the number of entries in the array followed by the array
-	 * of drc values so we start looking at index = 1.
+	/* Search the ibm,drc-indexes or ibm,drc-info array for
+	 * possible CPU drcs to add. Note that the format of the
+	 * ibm,drc-indexes array is the number of entries in the
+	 * array followed by the array of drc values so we start
+	 * looking at index = 1.  The ibm,drc-info array is a more
+	 * compact format for large numbers of CPUs, and the format
+	 * is correspondingly more complex.
 	 */
-	index = 1;
-	while (cpus_found < cpus_to_add) {
-		u32 drc;
+	if (firmware_has_feature(FW_FEATURE_DRC_INFO)) {
+		struct property *info = NULL;
+		struct of_drc_info drc;
+		int j;
+		u32 num_set_entries;
+		const __be32 *value;
+
+		info = of_find_property(parent, "ibm,drc-info", NULL);
+		if (info == NULL)
+			goto err_out;
+
+		value = of_prop_next_u32(info, NULL, &num_set_entries);
+		if (!value)
+			goto err_out;
+		value++;
+
+		for (j = 0; j < num_set_entries; j++) {
+			int k;
+
+			of_read_drc_info_cell(&info, &value, &drc);
+			if (strncmp(drc.drc_type, "CPU", 3))
+				goto err_out;
+
+			for (k = 0; (k < drc.num_sequential_elems) &&
+					(cpus_found < cpus_to_add); k++) {
+				u32 idrc = drc.drc_index_start +
+					(k * drc.sequential_inc);
+
+				if (dlpar_cpu_exists(parent, idrc))
+					continue;
+
+				cpu_drcs[cpus_found++] = idrc;
+			}
+		}
+
+	} else {
+		index = 1;
+		while (cpus_found < cpus_to_add) {
+			u32 drc;
 
-		rc = of_property_read_u32_index(parent, "ibm,drc-indexes",
+			rc = of_property_read_u32_index(parent,
+						"ibm,drc-indexes",
 						index++, &drc);
-		if (rc)
-			break;
+			if (rc)
+				break;
 
-		if (dlpar_cpu_exists(parent, drc))
-			continue;
+			if (dlpar_cpu_exists(parent, drc))
+				continue;
 
-		cpu_drcs[cpus_found++] = drc;
+			cpu_drcs[cpus_found++] = drc;
+		}
 	}
 
+err_out:
 	of_node_put(parent);
 	return cpus_found;
 }

                 reply	other threads:[~2018-02-01 21:59 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=bd7f8d6d-3a60-9833-87f9-e7acccbf9354@linux.vnet.ibm.com \
    --to=mwb@linux.vnet.ibm.com \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=nfont@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