Message ID | 20221116075736.1909690-3-vishal.l.verma@intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp13054wru; Wed, 16 Nov 2022 00:00:22 -0800 (PST) X-Google-Smtp-Source: AA0mqf4LZOjtgfYoyCG9q5jcJ5jwT7o4RcSv7XT0gPZ+N95l8l+uYbKr6TXHkvFHS7APRr6bt1Vy X-Received: by 2002:a17:902:9f97:b0:186:de87:7ffd with SMTP id g23-20020a1709029f9700b00186de877ffdmr7592772plq.94.1668585621850; Wed, 16 Nov 2022 00:00:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668585621; cv=none; d=google.com; s=arc-20160816; b=CbVB54TMqWdQXuWvdcvUVJUNQfF72xFGoRq/L/MNBcLgrfiJ4PE7m4mShOEgc6qgFc picp6k4xGepDCiGnRSIzTIAIVcPn4jE1/LjzeBVN20vRiBgAoo3fzIbaPOiLWQeSxmRK OzWg0fHVNv2y5IrQnbyTP5tvxnvPokua9He/rONo211bE/rOfgwV/d2zUxKR6zMrmunH uqEVnjsk1u2/sGFXbYN3eSwdOKKZImHKci1IiGVwhB71AtSQKyJ1qvvi+JxacTjN5BwG iReVj/s/X/m+NG9V6jrKkESL/favrauavlUbPFJpvRlxmoaIIWPhdroc0fYJixMna+q8 +v0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=C0sd6wRU45F9xX0jSwoktycCHQUBaFh/jGapD9gBDNA=; b=B0bg5DhFidpbX+2dNMzEkCc6y8pZel7RKe0HUJxEEcYgYeYw3iaI8WqPjEUmI4Ejbj 0s7zEyVWxU0wY7vFMTRet+TlQWsB6+x1saHVzUceeWizcuNUATlXcuAD55hN0JtyO+Fn lxkb0OQH39te18Vh/Gb2C+A0auIAVlRzOBEuWiFjJ8Z4eRNaf0Tsy2xHWmCtXLF2gez2 QWzlSt0wZWpMfmK6oqre11nL9xXg+zg8Hu/1JBmoQeJNM6uUSXs5Clb1TY1IDJQ0jpmD wpwJbrbp/GAIn1V1i3xEmvfcxZYqMh9RFpPsF0tgoRsRsKI/AayGGxMt7SuWH/XxPIji 98kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ktiYYRaV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g24-20020a633758000000b00476980fbc85si6118644pgn.105.2022.11.16.00.00.08; Wed, 16 Nov 2022 00:00:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ktiYYRaV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232934AbiKPH6F (ORCPT <rfc822;maxim.cournoyer@gmail.com> + 99 others); Wed, 16 Nov 2022 02:58:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232793AbiKPH5u (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 16 Nov 2022 02:57:50 -0500 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DB5123154; Tue, 15 Nov 2022 23:57:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668585470; x=1700121470; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=verj7hVUBInaUTF3sejWeZjrgjgv2y6v3Lf9mbwz5Qg=; b=ktiYYRaVPz2+PliAKTwVkG3LO+dbbsgvG4mS+EWHYgtczXej+6FLOe6x nA4gyqwT5Z8+sHjvI4mZalfPbu+GzQUpU/Zf9sU19/W9UtfhAjHtoRuAe hKFRtiu95z7BKsLCIkJArAC1zPtX8Pd5p8L+whwy3HgAbrCerdif6YPGJ XUylVolqsURspS+4z4SSVNIAmBuHtP6v/K/2LKn8knwwUwqSSb0xKsFLr TlLRBsT0+DmnBLbhwMfbc41uj5+NMLuY2lwYEXhfklSQfW9C7FwINn3e9 uGEgw55HJpF7uoY9YsBxHQzmTl5mZ7mB3/NUmGqVFL4R/o+7l0BLzU1QR Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10532"; a="398767160" X-IronPort-AV: E=Sophos;i="5.96,167,1665471600"; d="scan'208";a="398767160" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Nov 2022 23:57:49 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10532"; a="702769368" X-IronPort-AV: E=Sophos;i="5.96,167,1665471600"; d="scan'208";a="702769368" Received: from ake-mobl.amr.corp.intel.com (HELO vverma7-desk1.intel.com) ([10.209.189.231]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Nov 2022 23:57:48 -0800 From: Vishal Verma <vishal.l.verma@intel.com> To: <linux-acpi@vger.kernel.org> Cc: <linux-kernel@vger.kernel.org>, <nvdimm@lists.linux.dev>, "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>, Dan Williams <dan.j.williams@intel.com>, liushixin2@huawei.com, Vishal Verma <vishal.l.verma@intel.com>, Chris Piper <chris.d.piper@intel.com>, stable@vger.kernel.org, "Rafael J . Wysocki" <rafael@kernel.org> Subject: [PATCH 2/2] ACPI: HMAT: Fix initiator registration for single-initiator systems Date: Wed, 16 Nov 2022 00:57:36 -0700 Message-Id: <20221116075736.1909690-3-vishal.l.verma@intel.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221116075736.1909690-1-vishal.l.verma@intel.com> References: <20221116075736.1909690-1-vishal.l.verma@intel.com> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3279; h=from:subject; bh=verj7hVUBInaUTF3sejWeZjrgjgv2y6v3Lf9mbwz5Qg=; b=owGbwMvMwCXGf25diOft7jLG02pJDMkl0z9svJ/buO2c3Rtu9enxRRNuzgtbEmQ67VaDm8jbhSIb 5/RP7ShlYRDjYpAVU2T5u+cj4zG57fk8gQmOMHNYmUCGMHBxCsBECqIY/vs7MtucytbScuKRXbFYMr ro6v09R37KLFjgFX8/0Z2j8AnDH47sSynStb89puWtldx+bNK/fQLWPxZavtp/xEj2bdZzRjYA X-Developer-Key: i=vishal.l.verma@intel.com; a=openpgp; fpr=F8682BE134C67A12332A2ED07AFA61BEA3B84DFF Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749638837093431925?= X-GMAIL-MSGID: =?utf-8?q?1749638837093431925?= |
Series |
ACPI: HMAT: fix single-initiator target registrations
|
|
Commit Message
Verma, Vishal L
Nov. 16, 2022, 7:57 a.m. UTC
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(-)
Comments
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.
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().
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.
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)