lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20221116075736.1909690-3-vishal.l.verma@intel.com>
Date:   Wed, 16 Nov 2022 00:57:36 -0700
From:   Vishal Verma <vishal.l.verma@...el.com>
To:     <linux-acpi@...r.kernel.org>
Cc:     <linux-kernel@...r.kernel.org>, <nvdimm@...ts.linux.dev>,
        "Rafael J. Wysocki" <rafael.j.wysocki@...el.com>,
        Dan Williams <dan.j.williams@...el.com>, liushixin2@...wei.com,
        Vishal Verma <vishal.l.verma@...el.com>,
        Chris Piper <chris.d.piper@...el.com>, stable@...r.kernel.org,
        "Rafael J . Wysocki" <rafael@...nel.org>
Subject: [PATCH 2/2] ACPI: HMAT: Fix initiator registration for single-initiator systems

In a system with a single initiator node, and one or more memory-only
'target' nodes, the memory-only node(s) would fail to register their
initiator node correctly. i.e. in sysfs:

  # ls /sys/devices/system/node/node0/access0/targets/
  node0

Where as the correct behavior should be:

  # ls /sys/devices/system/node/node0/access0/targets/
  node0 node1

This happened because hmat_register_target_initiators() uses list_sort()
to sort the initiator list, but the sort comparision function
(initiator_cmp()) is overloaded to also set the node mask's bits.

In a system with a single initiator, the list is singular, and list_sort
elides the comparision helper call. Thus the node mask never gets set,
and the subsequent search for the best initiator comes up empty.

Add a new helper to sort the initiator list, and handle the singular
list corner case by setting the node mask for that explicitly.

Reported-by: Chris Piper <chris.d.piper@...el.com>
Cc: <stable@...r.kernel.org>
Cc: Rafael J. Wysocki <rafael@...nel.org>
Cc: Liu Shixin <liushixin2@...wei.com>
Cc: Dan Williams <dan.j.williams@...el.com>
Signed-off-by: Vishal Verma <vishal.l.verma@...el.com>
---
 drivers/acpi/numa/hmat.c | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/drivers/acpi/numa/hmat.c b/drivers/acpi/numa/hmat.c
index 144a84f429ed..cd20b0e9cdfa 100644
--- a/drivers/acpi/numa/hmat.c
+++ b/drivers/acpi/numa/hmat.c
@@ -573,6 +573,30 @@ static int initiator_cmp(void *priv, const struct list_head *a,
 	return ia->processor_pxm - ib->processor_pxm;
 }
 
+static int initiators_to_nodemask(unsigned long *p_nodes)
+{
+	/*
+	 * list_sort doesn't call @cmp (initiator_cmp) for 0 or 1 sized lists.
+	 * For a single-initiator system with other memory-only nodes, this
+	 * means an empty p_nodes mask, since that is set by initiator_cmp().
+	 * Special case the singular list, and make sure the node mask gets set
+	 * appropriately.
+	 */
+	if (list_empty(&initiators))
+		return -ENXIO;
+
+	if (list_is_singular(&initiators)) {
+		struct memory_initiator *initiator = list_first_entry(
+			&initiators, struct memory_initiator, node);
+
+		set_bit(initiator->processor_pxm, p_nodes);
+		return 0;
+	}
+
+	list_sort(p_nodes, &initiators, initiator_cmp);
+	return 0;
+}
+
 static void hmat_register_target_initiators(struct memory_target *target)
 {
 	static DECLARE_BITMAP(p_nodes, MAX_NUMNODES);
@@ -609,7 +633,9 @@ static void hmat_register_target_initiators(struct memory_target *target)
 	 * initiators.
 	 */
 	bitmap_zero(p_nodes, MAX_NUMNODES);
-	list_sort(p_nodes, &initiators, initiator_cmp);
+	if (initiators_to_nodemask(p_nodes) < 0)
+		return;
+
 	if (!access0done) {
 		for (i = WRITE_LATENCY; i <= READ_BANDWIDTH; i++) {
 			loc = localities_types[i];
@@ -643,7 +669,9 @@ static void hmat_register_target_initiators(struct memory_target *target)
 
 	/* Access 1 ignores Generic Initiators */
 	bitmap_zero(p_nodes, MAX_NUMNODES);
-	list_sort(p_nodes, &initiators, initiator_cmp);
+	if (initiators_to_nodemask(p_nodes) < 0)
+		return;
+
 	for (i = WRITE_LATENCY; i <= READ_BANDWIDTH; i++) {
 		loc = localities_types[i];
 		if (!loc)
-- 
2.38.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ