Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1194642rwb; Wed, 16 Nov 2022 13:38:07 -0800 (PST) X-Google-Smtp-Source: AA0mqf4yzvihj/gcvxU3Q/pcBjJ+IFnZHZnVeZF1z4PrezLqyUelKR8/RpEG5lpkmvih8hHpt7Uz X-Received: by 2002:aa7:d38b:0:b0:467:71de:fe10 with SMTP id x11-20020aa7d38b000000b0046771defe10mr19453607edq.63.1668634687250; Wed, 16 Nov 2022 13:38:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668634687; cv=none; d=google.com; s=arc-20160816; b=NI0toO57fJdXzmp2Ne58noHwBSe91P0bd/bBJ6jj31HaOAZkxdUK7OcTt2GXqiUVTY Smvu3e6iisKRmEaL+ooOipEY0sTysYTuMl4aFK6Ro7zHvg0XbOgzdu+sxgrlE3LpnI6q RcrzN4IZ3CNNTtqLFqMR/dFMhzda4zNxzeMyHYM5VJO3Znergn2c8bPBMo9+3nm1l4iR sYegREj7xu7yzEoG9UhiBw8R7qndjXGLu2idCjaJVUezCl9uIOnvvee4Ydg/BpIP6aRR b5R+KnKmNM/vAB8wRE6/YU5lkyXq6Tk0W0xluUS6hVHJxZXZInQ3AYHj75EstutmdurO wUWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:feedback-id:dkim-signature:dkim-signature; bh=YOfiesPEOAuUBSKKpRAQrX3e3W+dT8d3FBCanuP8ktQ=; b=hjwhHm+7/5rBrXsaNOWYGOWv1mbJLmje7GVbujS1I705Ja43mfl4oY2qekKg23WnMJ yQ7fnDVlqGN/GYKCYTpttHhgQ6/4zDWAQGHd44Nzhr5MgAuszYw8TOhJPOUPHQ4qMV9J HeJh5q50va+qpEoP3+ptrpXK87WE8XGpjEYGMTHeqsO+9aONj61X2d4fpNfvs3Ev5nbW dgW51Q560F+0fho7iyzaSF6bfayxnsSByWbct3DxHTAAJmZXXpibh5PsqYAQR9PTP6vK mY8PRbzq8kJ/nucwd+S1BlKgMKTunVwuZM8mQdRfUsE+Y8FCjkcEUA+U91ugq4gqMdVP PCXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov.name header.s=fm2 header.b=N08txJlU; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=irvJFQAL; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gb17-20020a170907961100b0078d1faeb619si16944119ejc.777.2022.11.16.13.37.44; Wed, 16 Nov 2022 13:38:07 -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=@shutemov.name header.s=fm2 header.b=N08txJlU; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=irvJFQAL; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233466AbiKPUpC (ORCPT + 90 others); Wed, 16 Nov 2022 15:45:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231221AbiKPUpA (ORCPT ); Wed, 16 Nov 2022 15:45:00 -0500 Received: from wout3-smtp.messagingengine.com (wout3-smtp.messagingengine.com [64.147.123.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1300E40448; Wed, 16 Nov 2022 12:44:58 -0800 (PST) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 13E02320096B; Wed, 16 Nov 2022 15:44:56 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Wed, 16 Nov 2022 15:44:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov.name; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm2; t=1668631495; x= 1668717895; bh=YOfiesPEOAuUBSKKpRAQrX3e3W+dT8d3FBCanuP8ktQ=; b=N 08txJlUzUDG1GQF4uRqGt7udIYP7fS7l3NRcYysByYbhCMbq9e4xqDHSxNBTV2Km iofRM+eUOJUo5KznvBAdG1FV9cnpjnSKGEBomqIK0CsXtW5COSjS5juZ/Z3h82Ox h2ZGcaZPeYmlCwxeWieupmAMQoHy6E0e14aerd6V9MUqBb29y3/QQaLmp4Iuh2ES evJczTWPL5xpf2mrDLvmBRdgulCX9Vv0VdLiSzjMF8oXJt6KIJ6kwEBAK6qUsld/ EXvgkk4G4BZXUocLVYa4LYh+GyZMcZy9iooNv7EXPcmRQ29ssGGHaY45J07lb9cY 2b/3xJcdaMFFDqkgEUIEQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1668631495; x= 1668717895; bh=YOfiesPEOAuUBSKKpRAQrX3e3W+dT8d3FBCanuP8ktQ=; b=i rvJFQALqk2m9ETraqa9ybGitP5C4ZLZOREAwq/aM/bBoX3Olp2w6i4x8qommR4te 8rFDrvzIMHx7lbqzFGiHVH705dNMhp2Z5zrmeQFBDQqDFgHBzKVD1vA+o1PyDQTU eCLPr++CCOYVUuVHCDF+k5g2e4s8pt48qUC49WUQjq7doSgZ544WPwpC5KpKOJnQ qd9Q+tOyUR3zaXfVIcaRZkGRswv697bU13T85ZDVK8PNceJ0obtpcZmG8fa+ZQ7s riqbnzN03UFJLupeOoPqEpvXOtI1LpmHkIeP2WXIO/NUdy3ZA3HZCvbMezN1fSYx bChB5SkSSvIvOnxikL+2A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvgedrgeeigddufeelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggugfgjsehtkedttddttddunecuhfhrohhmpedfkhhi rhhilhhlsehshhhuthgvmhhovhdrnhgrmhgvfdcuoehkihhrihhllhesshhhuhhtvghmoh hvrdhnrghmvgeqnecuggftrfgrthhtvghrnhepleehvefgieeukeekvddvudevieeikeeu gfeghfejjedvfeeivdfhtddtueetgfejnecuvehluhhsthgvrhfuihiivgeptdenucfrrg hrrghmpehmrghilhhfrhhomhepkhhirhhilhhlsehshhhuthgvmhhovhdrnhgrmhgv X-ME-Proxy: Feedback-ID: ie3994620:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 16 Nov 2022 15:44:54 -0500 (EST) Received: by box.shutemov.name (Postfix, from userid 1000) id 1BEF1109702; Wed, 16 Nov 2022 23:44:51 +0300 (+03) Date: Wed, 16 Nov 2022 23:44:51 +0300 From: "kirill@shutemov.name" 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" Subject: Re: [PATCH 2/2] ACPI: HMAT: Fix initiator registration for single-initiator systems Message-ID: <20221116204451.rmh6lq7vilajg7ss@box.shutemov.name> References: <20221116075736.1909690-1-vishal.l.verma@intel.com> <20221116075736.1909690-3-vishal.l.verma@intel.com> <20221116124634.nlvnsirdnlafdfeh@box.shutemov.name> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_PASS 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: X-Mailing-List: linux-kernel@vger.kernel.org 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 > > > Cc: > > > Cc: Rafael J. Wysocki > > > Cc: Liu Shixin > > > Cc: Dan Williams > > > Signed-off-by: Vishal Verma > > > --- > > > ?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