linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dou Liyang <douly.fnst@cn.fujitsu.com>
To: <cl@linux.com>, <tj@kernel.org>, <mika.j.penttila@gmail.com>,
	<mingo@redhat.com>, <akpm@linux-foundation.org>,
	<rjw@rjwysocki.net>, <hpa@zytor.com>, <yasu.isimatu@gmail.com>,
	<isimatu.yasuaki@jp.fujitsu.com>,
	<kamezawa.hiroyu@jp.fujitsu.com>, <izumi.taku@jp.fujitsu.com>,
	<gongzhaogang@inspur.com>, <len.brown@intel.com>,
	<lenb@kernel.org>, <tglx@linutronix.de>, <chen.tang@easystack.cn>,
	<rafael@kernel.org>
Cc: <x86@kernel.org>, <linux-acpi@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <linux-mm@kvack.org>,
	Dou Liyang <douly.fnst@cn.fujitsu.com>
Subject: [PATCH v12 6/7] acpi: Provide the mechanism to validate processors in the ACPI tables
Date: Thu, 25 Aug 2016 16:35:19 +0800	[thread overview]
Message-ID: <1472114120-3281-7-git-send-email-douly.fnst@cn.fujitsu.com> (raw)
In-Reply-To: <1472114120-3281-1-git-send-email-douly.fnst@cn.fujitsu.com>

[Problem]

When we set cpuid <-> nodeid mapping to be persistent, it will use the DSDT
As we know, the ACPI tables are just like user's input in that respect, and
we don't crash if user's input is unreasonable.

Such as, the mapping of the proc_id and pxm in some machine's ACPI table is
like this:

proc_id   |    pxm
--------------------
0       <->     0
1       <->     0
2       <->     1
3       <->     1
89      <->     0
89      <->     0
89      <->     0
89      <->     1
89      <->     1
89      <->     2
89      <->     3
.....

We can't be sure which one is correct to the proc_id 89. We may map a wrong
node to a cpu. When pages are allocated, this may cause a kernal panic.

So, we should provide mechanisms to validate the ACPI tables, just like we
do validation to check user's input in web project.

The mechanism is that the processor objects which have the duplicate IDs
are not valid.

[Solution]

We add a validation function, like this:

foreach Processor in DSDT
	proc_id= get_ACPI_Processor_number(Processor)
	if(the proc_id has alreadly existed )
		mark both of them as being unreasonable;

The function will record the unique or duplicate processor IDs.

The duplicate processor IDs such as 89 are regarded as the unreasonable IDs
which mean that the processor objects in question are not valid.

Signed-off-by: Dou Liyang <douly.fnst@cn.fujitsu.com>
---
 drivers/acpi/acpi_processor.c | 79 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 79 insertions(+)

diff --git a/drivers/acpi/acpi_processor.c b/drivers/acpi/acpi_processor.c
index 0c15828..346fbfc 100644
--- a/drivers/acpi/acpi_processor.c
+++ b/drivers/acpi/acpi_processor.c
@@ -581,8 +581,87 @@ static struct acpi_scan_handler processor_container_handler = {
 	.attach = acpi_processor_container_attach,
 };
 
+/* The number of the unique processor IDs */
+static int nr_unique_ids;
+
+/* The number of the duplicate processor IDs */
+static int nr_duplicate_ids;
+
+/* Used to store the unique processor IDs */
+static int unique_processor_ids[] = {
+	[0 ... NR_CPUS - 1] = -1,
+};
+
+/* Used to store the duplicate processor IDs */
+static int duplicate_processor_ids[] = {
+	[0 ... NR_CPUS - 1] = -1,
+};
+
+static void processor_validated_ids_update(int proc_id)
+{
+	int i;
+
+	if (nr_unique_ids == NR_CPUS||nr_duplicate_ids == NR_CPUS)
+		return;
+
+	/*
+	 * Firstly, compare the proc_id with duplicate IDs, if the proc_id is
+	 * already in the IDs, do nothing.
+	 */
+	for (i = 0; i < nr_duplicate_ids; i++) {
+		if (duplicate_processor_ids[i] == proc_id)
+			return;
+	}
+
+	/*
+	 * Secondly, compare the proc_id with unique IDs, if the proc_id is in
+	 * the IDs, put it in the duplicate IDs.
+	 */
+	for (i = 0; i < nr_unique_ids; i++) {
+		if (unique_processor_ids[i] == proc_id) {
+			duplicate_processor_ids[nr_duplicate_ids] = proc_id;
+			nr_duplicate_ids++;
+			return;
+		}
+	}
+
+	/*
+	 * Lastly, the proc_id is a unique ID, put it in the unique IDs.
+	 */
+	unique_processor_ids[nr_unique_ids] = proc_id;
+	nr_unique_ids++;
+}
+
+static acpi_status acpi_processor_ids_walk(acpi_handle handle,
+						u32 lvl,
+						void *context,
+						void **rv)
+{
+	acpi_status status;
+	union acpi_object object = { 0 };
+	struct acpi_buffer buffer = { sizeof(union acpi_object), &object };
+
+	status = acpi_evaluate_object(handle, NULL, NULL, &buffer);
+	if (ACPI_FAILURE(status))
+		acpi_handle_info(handle, "Not get the processor object\n");
+	else
+		processor_validated_ids_update(object.processor.proc_id);
+
+	return AE_OK;
+}
+
+static void acpi_processor_duplication_valiate(void)
+{
+	/* Search all processor nodes in ACPI namespace */
+	acpi_walk_namespace(ACPI_TYPE_PROCESSOR, ACPI_ROOT_OBJECT,
+						ACPI_UINT32_MAX,
+						acpi_processor_ids_walk,
+						NULL, NULL, NULL);
+}
+
 void __init acpi_processor_init(void)
 {
+	acpi_processor_duplication_valiate();
 	acpi_scan_add_handler_with_hotplug(&processor_handler, "processor");
 	acpi_scan_add_handler(&processor_container_handler);
 }
-- 
2.5.5

  parent reply	other threads:[~2016-08-25  8:43 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-25  8:35 [PATCH v12 0/7] Make cpuid <-> nodeid mapping persistent Dou Liyang
2016-08-25  8:35 ` [PATCH v12 1/7] x86, memhp, numa: Online memory-less nodes at boot time Dou Liyang
2016-09-22 19:09   ` [tip:x86/apic] x86/numa: " tip-bot for Tang Chen
2016-08-25  8:35 ` [PATCH v12 2/7] x86, acpi, cpu-hotplug: Enable acpi to register all possible cpus " Dou Liyang
2016-08-25  8:57   ` Dou Liyang
2016-09-22 19:10   ` [tip:x86/apic] x86/acpi: " tip-bot for Gu Zheng
2016-08-25  8:35 ` [PATCH v12 3/7] x86, acpi, cpu-hotplug: Introduce cpuid_to_apicid[] array to store persistent cpuid <-> apicid mapping Dou Liyang
2016-09-22 19:10   ` [tip:x86/apic] x86/acpi: Introduce persistent storage for " tip-bot for Gu Zheng
2016-10-04  6:02     ` Yinghai Lu
2016-10-05 14:04       ` Thomas Gleixner
2016-10-06  4:53         ` Yinghai Lu
2016-10-06  8:06           ` Dou Liyang
2016-10-06 21:20             ` Yinghai Lu
2016-10-07  4:35               ` Dou Liyang
2016-10-07 12:50                 ` Thomas Gleixner
2016-10-07 13:00                   ` Thomas Gleixner
2016-10-07 18:55                     ` Yinghai Lu
2016-10-08  5:22                     ` Dou Liyang
2016-10-07 11:02               ` Thomas Gleixner
2016-10-07 11:04               ` Thomas Gleixner
2016-10-07 13:07             ` Thomas Gleixner
2016-10-08  4:14               ` Dou Liyang
2016-08-25  8:35 ` [PATCH v12 4/7] x86, acpi, cpu-hotplug: Enable MADT APIs to return disabled apicid Dou Liyang
2016-09-22 19:11   ` [tip:x86/apic] x86/acpi: Enable MADT APIs to return disabled apicids tip-bot for Gu Zheng
2016-08-25  8:35 ` [PATCH v12 5/7] x86, acpi, cpu-hotplug: Set persistent cpuid <-> nodeid mapping when booting Dou Liyang
2016-09-22 19:11   ` [tip:x86/apic] x86/acpi: " tip-bot for Gu Zheng
2016-08-25  8:35 ` Dou Liyang [this message]
2016-09-22 19:12   ` [tip:x86/apic] acpi: Provide mechanism to validate processors in the ACPI tables tip-bot for Dou Liyang
2016-08-25  8:35 ` [PATCH v12 7/7] acpi: Provide the interface to validate the proc_id Dou Liyang
2016-09-22 19:12   ` [tip:x86/apic] acpi: Validate processor id when mapping the processor tip-bot for Dou Liyang
2016-08-25  9:08 ` [PATCH v12 0/7] Make cpuid <-> nodeid mapping persistent Dou Liyang
2016-09-02  6:57 ` Dou Liyang
2016-09-13 11:33   ` Dou Liyang

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=1472114120-3281-7-git-send-email-douly.fnst@cn.fujitsu.com \
    --to=douly.fnst@cn.fujitsu.com \
    --cc=akpm@linux-foundation.org \
    --cc=chen.tang@easystack.cn \
    --cc=cl@linux.com \
    --cc=gongzhaogang@inspur.com \
    --cc=hpa@zytor.com \
    --cc=isimatu.yasuaki@jp.fujitsu.com \
    --cc=izumi.taku@jp.fujitsu.com \
    --cc=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=len.brown@intel.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mika.j.penttila@gmail.com \
    --cc=mingo@redhat.com \
    --cc=rafael@kernel.org \
    --cc=rjw@rjwysocki.net \
    --cc=tglx@linutronix.de \
    --cc=tj@kernel.org \
    --cc=x86@kernel.org \
    --cc=yasu.isimatu@gmail.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).