Patch 1 is an obvious cleanup found while fixing this problem.
Patch 2 Fixes a bug with initiator registration for single-initiator systems. More details on this in its commit message.
Rafael - I didn't retain your ack for patch 2 since it seemed like a nontrivial change.
Cc: Rafael J. Wysocki rafael@kernel.org Cc: Liu Shixin liushixin2@huawei.com Cc: Dan Williams dan.j.williams@intel.com Cc: linux-acpi@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: stable@vger.kernel.org Cc: Chris Piper chris.d.piper@intel.com Cc: Kirill A. Shutemov kirill.shutemov@linux.intel.com Signed-off-by: Vishal Verma vishal.l.verma@intel.com
--- Changes in v2: - Collect Acks for patch 1. - Separate out the bitmask generation from the comparision helper to make it more explicit and easier to follow (Kirill) - Link to v1: https://lore.kernel.org/r/20221116075736.1909690-1-vishal.l.verma@intel.com
--- Vishal Verma (2): ACPI: HMAT: remove unnecessary variable initialization ACPI: HMAT: Fix initiator registration for single-initiator systems
drivers/acpi/numa/hmat.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) --- base-commit: 9abf2313adc1ca1b6180c508c25f22f9395cc780 change-id: 20221116-acpi_hmat_fix-7acf4bca37c0
Best regards,
In hmat_register_target_initiators(), the variable 'best' gets initialized in the outer per-locality-type for loop. The initialization just before setting up 'Access 1' targets was unnecessary. Remove it.
Cc: Rafael J. Wysocki rafael@kernel.org Cc: Liu Shixin liushixin2@huawei.com Cc: Dan Williams dan.j.williams@intel.com Acked-by: Kirill A. Shutemov kirill.shutemov@linux.intel.com Acked-by: Rafael J. Wysocki rafael.j.wysocki@intel.com Signed-off-by: Vishal Verma vishal.l.verma@intel.com --- drivers/acpi/numa/hmat.c | 1 - 1 file changed, 1 deletion(-)
diff --git a/drivers/acpi/numa/hmat.c b/drivers/acpi/numa/hmat.c index 23f49a2f4d14..144a84f429ed 100644 --- a/drivers/acpi/numa/hmat.c +++ b/drivers/acpi/numa/hmat.c @@ -644,7 +644,6 @@ 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); - best = 0; for (i = WRITE_LATENCY; i <= READ_BANDWIDTH; i++) { loc = localities_types[i]; if (!loc)
Hi,
Thanks for your patch.
FYI: kernel test robot notices the stable kernel rule is not satisfied.
Rule: 'Cc: stable@vger.kernel.org' or 'commit <sha1> upstream.' Subject: [PATCH v2 1/2] ACPI: HMAT: remove unnecessary variable initialization Link: https://lore.kernel.org/stable/20221116-acpi_hmat_fix-v2-1-3712569be691%40in...
The check is based on https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
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 consume the sorted initiator list, and generate the nodemask, decoupling it from the overloaded initiator_cmp() comparision callback. This prevents the singular list corner case naturally, and makes the code easier to follow as well.
Cc: stable@vger.kernel.org Cc: Rafael J. Wysocki rafael@kernel.org Cc: Liu Shixin liushixin2@huawei.com Cc: Dan Williams dan.j.williams@intel.com Cc: Kirill A. Shutemov kirill.shutemov@linux.intel.com Reported-by: Chris Piper chris.d.piper@intel.com Signed-off-by: Vishal Verma vishal.l.verma@intel.com --- drivers/acpi/numa/hmat.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-)
diff --git a/drivers/acpi/numa/hmat.c b/drivers/acpi/numa/hmat.c index 144a84f429ed..6cceca64a6bc 100644 --- a/drivers/acpi/numa/hmat.c +++ b/drivers/acpi/numa/hmat.c @@ -562,17 +562,26 @@ static int initiator_cmp(void *priv, const struct list_head *a, { struct memory_initiator *ia; struct memory_initiator *ib; - unsigned long *p_nodes = priv;
ia = list_entry(a, struct memory_initiator, node); ib = list_entry(b, struct memory_initiator, node);
- set_bit(ia->processor_pxm, p_nodes); - set_bit(ib->processor_pxm, p_nodes); - return ia->processor_pxm - ib->processor_pxm; }
+static int initiators_to_nodemask(unsigned long *p_nodes) +{ + struct memory_initiator *initiator; + + if (list_empty(&initiators)) + return -ENXIO; + + list_for_each_entry(initiator, &initiators, node) + set_bit(initiator->processor_pxm, p_nodes); + + return 0; +} + static void hmat_register_target_initiators(struct memory_target *target) { static DECLARE_BITMAP(p_nodes, MAX_NUMNODES); @@ -609,7 +618,10 @@ static void hmat_register_target_initiators(struct memory_target *target) * initiators. */ bitmap_zero(p_nodes, MAX_NUMNODES); - list_sort(p_nodes, &initiators, initiator_cmp); + list_sort(NULL, &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 +655,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)
On Wed, Nov 16, 2022 at 04:37:37PM -0700, Vishal Verma wrote:
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 consume the sorted initiator list, and generate the nodemask, decoupling it from the overloaded initiator_cmp() comparision callback. This prevents the singular list corner case naturally, and makes the code easier to follow as well.
Cc: stable@vger.kernel.org Cc: Rafael J. Wysocki rafael@kernel.org Cc: Liu Shixin liushixin2@huawei.com Cc: Dan Williams dan.j.williams@intel.com Cc: Kirill A. Shutemov kirill.shutemov@linux.intel.com Reported-by: Chris Piper chris.d.piper@intel.com Signed-off-by: Vishal Verma vishal.l.verma@intel.com
Acked-by: Kirill A. Shutemov kirill.shutemov@linux.intel.com
On 11/17/2022 12:37 AM, Vishal Verma wrote:
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 consume the sorted initiator list, and generate the nodemask, decoupling it from the overloaded initiator_cmp() comparision callback. This prevents the singular list corner case naturally, and makes the code easier to follow as well.
Cc: stable@vger.kernel.org Cc: Rafael J. Wysocki rafael@kernel.org Cc: Liu Shixin liushixin2@huawei.com Cc: Dan Williams dan.j.williams@intel.com Cc: Kirill A. Shutemov kirill.shutemov@linux.intel.com Reported-by: Chris Piper chris.d.piper@intel.com Signed-off-by: Vishal Verma vishal.l.verma@intel.com
Acked-by: Rafael J. Wysocki rafael.j.wysocki@intel.com
drivers/acpi/numa/hmat.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-)
diff --git a/drivers/acpi/numa/hmat.c b/drivers/acpi/numa/hmat.c index 144a84f429ed..6cceca64a6bc 100644 --- a/drivers/acpi/numa/hmat.c +++ b/drivers/acpi/numa/hmat.c @@ -562,17 +562,26 @@ static int initiator_cmp(void *priv, const struct list_head *a, { struct memory_initiator *ia; struct memory_initiator *ib;
- unsigned long *p_nodes = priv;
ia = list_entry(a, struct memory_initiator, node); ib = list_entry(b, struct memory_initiator, node);
- set_bit(ia->processor_pxm, p_nodes);
- set_bit(ib->processor_pxm, p_nodes);
- return ia->processor_pxm - ib->processor_pxm; }
+static int initiators_to_nodemask(unsigned long *p_nodes) +{
- struct memory_initiator *initiator;
- if (list_empty(&initiators))
return -ENXIO;
- list_for_each_entry(initiator, &initiators, node)
set_bit(initiator->processor_pxm, p_nodes);
- return 0;
+}
- static void hmat_register_target_initiators(struct memory_target *target) { static DECLARE_BITMAP(p_nodes, MAX_NUMNODES);
@@ -609,7 +618,10 @@ static void hmat_register_target_initiators(struct memory_target *target) * initiators. */ bitmap_zero(p_nodes, MAX_NUMNODES);
- list_sort(p_nodes, &initiators, initiator_cmp);
- list_sort(NULL, &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 +655,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)
linux-stable-mirror@lists.linaro.org