* [PATCH 0/2] ACPI: HMAT: fix single-initiator target registrations
@ 2022-11-16 7:57 Vishal Verma
2022-11-16 7:57 ` [PATCH 1/2] ACPI: HMAT: remove unnecessary variable initialization Vishal Verma
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Vishal Verma @ 2022-11-16 7:57 UTC (permalink / raw)
To: linux-acpi
Cc: linux-kernel, nvdimm, Rafael J. Wysocki, Dan Williams, liushixin2,
Vishal Verma
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.
Vishal Verma (2):
ACPI: HMAT: remove unnecessary variable initialization
ACPI: HMAT: Fix initiator registration for single-initiator systems
drivers/acpi/numa/hmat.c | 33 ++++++++++++++++++++++++++++++---
1 file changed, 30 insertions(+), 3 deletions(-)
base-commit: 9abf2313adc1ca1b6180c508c25f22f9395cc780
--
2.38.1
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH 1/2] ACPI: HMAT: remove unnecessary variable initialization 2022-11-16 7:57 [PATCH 0/2] ACPI: HMAT: fix single-initiator target registrations Vishal Verma @ 2022-11-16 7:57 ` Vishal Verma 2022-11-16 12:41 ` Kirill A. Shutemov 2022-11-16 7:57 ` [PATCH 2/2] ACPI: HMAT: Fix initiator registration for single-initiator systems Vishal Verma 2022-11-16 12:04 ` [PATCH 0/2] ACPI: HMAT: fix single-initiator target registrations Rafael J. Wysocki 2 siblings, 1 reply; 8+ messages in thread From: Vishal Verma @ 2022-11-16 7:57 UTC (permalink / raw) To: linux-acpi Cc: linux-kernel, nvdimm, Rafael J. Wysocki, Dan Williams, liushixin2, Vishal Verma, Rafael J . Wysocki 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> 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) -- 2.38.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] ACPI: HMAT: remove unnecessary variable initialization 2022-11-16 7:57 ` [PATCH 1/2] ACPI: HMAT: remove unnecessary variable initialization Vishal Verma @ 2022-11-16 12:41 ` Kirill A. Shutemov 0 siblings, 0 replies; 8+ messages in thread From: Kirill A. Shutemov @ 2022-11-16 12:41 UTC (permalink / raw) To: Vishal Verma Cc: linux-acpi, linux-kernel, nvdimm, Rafael J. Wysocki, Dan Williams, liushixin2, Rafael J . Wysocki On Wed, Nov 16, 2022 at 12:57:35AM -0700, Vishal Verma wrote: > 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> > Signed-off-by: Vishal Verma <vishal.l.verma@intel.com> Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> -- Kiryl Shutsemau / Kirill A. Shutemov ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 2/2] ACPI: HMAT: Fix initiator registration for single-initiator systems 2022-11-16 7:57 [PATCH 0/2] ACPI: HMAT: fix single-initiator target registrations Vishal Verma 2022-11-16 7:57 ` [PATCH 1/2] ACPI: HMAT: remove unnecessary variable initialization Vishal Verma @ 2022-11-16 7:57 ` Vishal Verma 2022-11-16 12:46 ` Kirill A. Shutemov 2022-11-16 12:04 ` [PATCH 0/2] ACPI: HMAT: fix single-initiator target registrations Rafael J. Wysocki 2 siblings, 1 reply; 8+ messages in thread From: Vishal Verma @ 2022-11-16 7:57 UTC (permalink / raw) To: linux-acpi Cc: linux-kernel, nvdimm, Rafael J. Wysocki, Dan Williams, liushixin2, Vishal Verma, Chris Piper, stable, Rafael J . Wysocki 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@intel.com> 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> Signed-off-by: Vishal Verma <vishal.l.verma@intel.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 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] ACPI: HMAT: Fix initiator registration for single-initiator systems 2022-11-16 7:57 ` [PATCH 2/2] ACPI: HMAT: Fix initiator registration for single-initiator systems Vishal Verma @ 2022-11-16 12:46 ` Kirill A. Shutemov 2022-11-16 18:02 ` Verma, Vishal L 0 siblings, 1 reply; 8+ messages in thread From: Kirill A. Shutemov @ 2022-11-16 12:46 UTC (permalink / raw) To: Vishal Verma Cc: linux-acpi, linux-kernel, nvdimm, Rafael J. Wysocki, Dan Williams, liushixin2, Chris Piper, stable, Rafael J . Wysocki On Wed, Nov 16, 2022 at 12:57:36AM -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 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@intel.com> > 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> > Signed-off-by: Vishal Verma <vishal.l.verma@intel.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; > +} > + Hm. I think it indicates that these set_bit()s do not belong to initiator_cmp(). Maybe remove both set_bit() from the compare helper and walk the list separately to initialize the node mask? I think it will be easier to follow. -- Kiryl Shutsemau / Kirill A. Shutemov ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] ACPI: HMAT: Fix initiator registration for single-initiator systems 2022-11-16 12:46 ` Kirill A. Shutemov @ 2022-11-16 18:02 ` Verma, Vishal L 2022-11-16 20:44 ` kirill 0 siblings, 1 reply; 8+ messages in thread From: Verma, Vishal L @ 2022-11-16 18:02 UTC (permalink / raw) To: kirill@shutemov.name Cc: Piper, Chris D, rafael@kernel.org, linux-kernel@vger.kernel.org, Williams, Dan J, Wysocki, Rafael J, linux-acpi@vger.kernel.org, stable@vger.kernel.org, nvdimm@lists.linux.dev, liushixin2@huawei.com On Wed, 2022-11-16 at 15:46 +0300, Kirill A. Shutemov wrote: > On Wed, Nov 16, 2022 at 12:57:36AM -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 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@intel.com> > > 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> > > Signed-off-by: Vishal Verma <vishal.l.verma@intel.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; > > +} > > + > > Hm. I think it indicates that these set_bit()s do not belong to > initiator_cmp(). > > Maybe remove both set_bit() from the compare helper and walk the list > separately to initialize the node mask? I think it will be easier to > follow. Yes - I thuoght about this, but went with the seemingly less intrusive change. I can send a v2 which separates out the set_bit()s. I agree that's cleaner and easier to follow than overloading initiator_cmp(). ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] ACPI: HMAT: Fix initiator registration for single-initiator systems 2022-11-16 18:02 ` Verma, Vishal L @ 2022-11-16 20:44 ` kirill 0 siblings, 0 replies; 8+ messages in thread From: kirill @ 2022-11-16 20:44 UTC (permalink / raw) To: Verma, Vishal L Cc: Piper, Chris D, rafael@kernel.org, linux-kernel@vger.kernel.org, Williams, Dan J, Wysocki, Rafael J, linux-acpi@vger.kernel.org, stable@vger.kernel.org, nvdimm@lists.linux.dev, liushixin2@huawei.com On Wed, Nov 16, 2022 at 06:02:32PM +0000, Verma, Vishal L wrote: > On Wed, 2022-11-16 at 15:46 +0300, Kirill A. Shutemov wrote: > > On Wed, Nov 16, 2022 at 12:57:36AM -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 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@intel.com> > > > 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> > > > Signed-off-by: Vishal Verma <vishal.l.verma@intel.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; > > > +} > > > + > > > > Hm. I think it indicates that these set_bit()s do not belong to > > initiator_cmp(). > > > > Maybe remove both set_bit() from the compare helper and walk the list > > separately to initialize the node mask? I think it will be easier to > > follow. > > > Yes - I thuoght about this, but went with the seemingly less intrusive > change. I can send a v2 which separates out the set_bit()s. I agree > that's cleaner and easier to follow than overloading initiator_cmp(). Yes, please make v2. With current implementation set_bit() can be called multiple times on the same initiator, depending on placement of the initiator in the list. It is totally wrong place. -- Kiryl Shutsemau / Kirill A. Shutemov ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 0/2] ACPI: HMAT: fix single-initiator target registrations 2022-11-16 7:57 [PATCH 0/2] ACPI: HMAT: fix single-initiator target registrations Vishal Verma 2022-11-16 7:57 ` [PATCH 1/2] ACPI: HMAT: remove unnecessary variable initialization Vishal Verma 2022-11-16 7:57 ` [PATCH 2/2] ACPI: HMAT: Fix initiator registration for single-initiator systems Vishal Verma @ 2022-11-16 12:04 ` Rafael J. Wysocki 2 siblings, 0 replies; 8+ messages in thread From: Rafael J. Wysocki @ 2022-11-16 12:04 UTC (permalink / raw) To: Vishal Verma Cc: linux-acpi, linux-kernel, nvdimm, Rafael J. Wysocki, Dan Williams, liushixin2 On Wed, Nov 16, 2022 at 8:57 AM Vishal Verma <vishal.l.verma@intel.com> wrote: > > 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. > > > Vishal Verma (2): > ACPI: HMAT: remove unnecessary variable initialization > ACPI: HMAT: Fix initiator registration for single-initiator systems Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> for both and please feel free to ask Dan to take them. Alternatively, if you want me to apply them, please let me know. > drivers/acpi/numa/hmat.c | 33 ++++++++++++++++++++++++++++++--- > 1 file changed, 30 insertions(+), 3 deletions(-) > > > base-commit: 9abf2313adc1ca1b6180c508c25f22f9395cc780 > -- ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2022-11-16 20:45 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2022-11-16 7:57 [PATCH 0/2] ACPI: HMAT: fix single-initiator target registrations Vishal Verma 2022-11-16 7:57 ` [PATCH 1/2] ACPI: HMAT: remove unnecessary variable initialization Vishal Verma 2022-11-16 12:41 ` Kirill A. Shutemov 2022-11-16 7:57 ` [PATCH 2/2] ACPI: HMAT: Fix initiator registration for single-initiator systems Vishal Verma 2022-11-16 12:46 ` Kirill A. Shutemov 2022-11-16 18:02 ` Verma, Vishal L 2022-11-16 20:44 ` kirill 2022-11-16 12:04 ` [PATCH 0/2] ACPI: HMAT: fix single-initiator target registrations Rafael J. Wysocki
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox