Skip to content

Commit 48d4180

Browse files
stellarhopperdjbw
authored andcommitted
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 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: <[email protected]> Cc: Rafael J. Wysocki <[email protected]> Cc: Liu Shixin <[email protected]> Cc: Dan Williams <[email protected]> Cc: Kirill A. Shutemov <[email protected]> Reported-by: Chris Piper <[email protected]> Signed-off-by: Vishal Verma <[email protected]> Acked-by: Rafael J. Wysocki <[email protected]> Acked-by: Kirill A. Shutemov <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dan Williams <[email protected]>
1 parent 14f16d4 commit 48d4180

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

drivers/acpi/numa/hmat.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -562,17 +562,26 @@ static int initiator_cmp(void *priv, const struct list_head *a,
562562
{
563563
struct memory_initiator *ia;
564564
struct memory_initiator *ib;
565-
unsigned long *p_nodes = priv;
566565

567566
ia = list_entry(a, struct memory_initiator, node);
568567
ib = list_entry(b, struct memory_initiator, node);
569568

570-
set_bit(ia->processor_pxm, p_nodes);
571-
set_bit(ib->processor_pxm, p_nodes);
572-
573569
return ia->processor_pxm - ib->processor_pxm;
574570
}
575571

572+
static int initiators_to_nodemask(unsigned long *p_nodes)
573+
{
574+
struct memory_initiator *initiator;
575+
576+
if (list_empty(&initiators))
577+
return -ENXIO;
578+
579+
list_for_each_entry(initiator, &initiators, node)
580+
set_bit(initiator->processor_pxm, p_nodes);
581+
582+
return 0;
583+
}
584+
576585
static void hmat_register_target_initiators(struct memory_target *target)
577586
{
578587
static DECLARE_BITMAP(p_nodes, MAX_NUMNODES);
@@ -609,7 +618,10 @@ static void hmat_register_target_initiators(struct memory_target *target)
609618
* initiators.
610619
*/
611620
bitmap_zero(p_nodes, MAX_NUMNODES);
612-
list_sort(p_nodes, &initiators, initiator_cmp);
621+
list_sort(NULL, &initiators, initiator_cmp);
622+
if (initiators_to_nodemask(p_nodes) < 0)
623+
return;
624+
613625
if (!access0done) {
614626
for (i = WRITE_LATENCY; i <= READ_BANDWIDTH; i++) {
615627
loc = localities_types[i];
@@ -643,7 +655,9 @@ static void hmat_register_target_initiators(struct memory_target *target)
643655

644656
/* Access 1 ignores Generic Initiators */
645657
bitmap_zero(p_nodes, MAX_NUMNODES);
646-
list_sort(p_nodes, &initiators, initiator_cmp);
658+
if (initiators_to_nodemask(p_nodes) < 0)
659+
return;
660+
647661
for (i = WRITE_LATENCY; i <= READ_BANDWIDTH; i++) {
648662
loc = localities_types[i];
649663
if (!loc)

0 commit comments

Comments
 (0)