From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by mx.groups.io with SMTP id smtpd.web08.4946.1662534420897077982 for ; Wed, 07 Sep 2022 00:07:01 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AME25nLW; spf=pass (domain: kernel.org, ip: 145.40.68.75, mailfrom: ardb@kernel.org) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id A06CBB819D5 for ; Wed, 7 Sep 2022 07:06:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DF368C433D6 for ; Wed, 7 Sep 2022 07:06:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1662534417; bh=z7Gx/8xsb5UltcIibOIV8itB0CBst9NWOVnx8w3enpI=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=AME25nLW13d2sFxefyjaxW906ztb0NmwdKsltwy0IUSXbJThaTXKEKUqetN9Tk0ws Imiu2vlkKJ6X/g9OaK7sQgcziui5i+Cja+XxGiUTPae9Z3fXtqXgAivGp7dzP6qAt0 +gY1W64LEEKdAMYO+4Jr+6PIc/1S2A9RuQmN7HsurGGoJi4ltIfpYqq04XFDX550St zL73q+ozBVqMhvWNaz+AQg67mLrbAkhm/vtdMgGEn7RUnP2lCuKvuBwWAr9vWBX7JA k+wgOjgUATg/cB7b7CNMs1t1Zm5nO00YZ4aBkSwE33fnWyehbpLTUJ6YJPoVTpFZOT mvxFxdAxgySWw== Received: by mail-lf1-f41.google.com with SMTP id x14so5617577lfu.10 for ; Wed, 07 Sep 2022 00:06:57 -0700 (PDT) X-Gm-Message-State: ACgBeo0j4MhpWCRG3j6VKswQg7U+JPt7CxcE90AYK0n92FqWqD52MSOI 4uOQmTs+1rgkZYn2Y0CuO9D9eo91zQZCA3HY3rE= X-Google-Smtp-Source: AA6agR4vljLBo6wgzmjXnVAFoD0KUn+CWVA5d8Z8QhPIGYapsD1ykwvtM8ocZ2sXbLl+IQW9rsPcv1yhh9Qzllb0K7k= X-Received: by 2002:a05:6512:150e:b0:492:d9fd:9bdf with SMTP id bq14-20020a056512150e00b00492d9fd9bdfmr614893lfb.583.1662534415913; Wed, 07 Sep 2022 00:06:55 -0700 (PDT) MIME-Version: 1.0 References: <20220705065503.29583-1-mark-pk.tsai@mediatek.com> In-Reply-To: <20220705065503.29583-1-mark-pk.tsai@mediatek.com> From: "Ard Biesheuvel" Date: Wed, 7 Sep 2022 09:06:44 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] ArmVirtPkg: Fix boot fail on numa system. To: Mark-PK Tsai Cc: ardb+tianocore@kernel.org, quic_llindhol@quicinc.com, sami.mujawar@arm.com, kraxel@redhat.com, julien@xen.org, devel@edk2.groups.io, yj.chiang@mediatek.com, YJ Chiang Content-Type: text/plain; charset="UTF-8" On Tue, 5 Jul 2022 at 08:55, Mark-PK Tsai wrote: > > If "numa-node-id" is specified in a memory node, > take node 0 as system memory instead of taking > the first memory node. > > Cc: YJ Chiang Typo in email address > Signed-off-by: Mark-PK Tsai > --- > ArmVirtPkg/PrePi/FdtParser.c | 32 ++++++++++++++++++++++++++++---- > 1 file changed, 28 insertions(+), 4 deletions(-) > > diff --git a/ArmVirtPkg/PrePi/FdtParser.c b/ArmVirtPkg/PrePi/FdtParser.c > index 5a91f7e62d..5c7de3bc31 100644 > --- a/ArmVirtPkg/PrePi/FdtParser.c > +++ b/ArmVirtPkg/PrePi/FdtParser.c > @@ -19,19 +19,43 @@ FindMemnode ( > INT32 SizeCells; > INT32 Length; > CONST INT32 *Prop; > + INT32 NumaId; > + INT32 Node, Prev; > + CONST CHAR8 *Type; > > if (fdt_check_header (DeviceTreeBlob) != 0) { > return FALSE; > } > > // > - // Look for a node called "memory" at the lowest level of the tree > + // Look for the lowest memory node. > + // On Numa system, use node 0 as system memory. There could be other reasons there are multiple memory nodes, right? So wouldn't it be better if we cross reference the memory node with some other information, for instance, where the firmware image itself was loaded in memory? > // > - MemoryNode = fdt_path_offset (DeviceTreeBlob, "/memory"); > - if (MemoryNode <= 0) { > - return FALSE; > + MemoryNode = -1; > + NumaId = -1; > + > + for (Prev = 0; ; Prev = Node) { > + Node = fdt_next_node (DeviceTreeBlob, Prev, NULL); > + if (Node < 0) > + break; > + > + Type = fdt_getprop (DeviceTreeBlob, Node, "device_type", &Length); > + if (Type && (AsciiStrnCmp (Type, "memory", Length) == 0)) { > + Prop = fdt_getprop (DeviceTreeBlob, Node, "numa-node-id", &Length); > + if (Prop && Length == 4) { > + NumaId = fdt32_to_cpu (*Prop); > + } > + > + if (!Prop || (Prop && NumaId == 0)) { > + MemoryNode = Node; > + break; > + } > + } > } > > + if (MemoryNode < 0) > + return FALSE; > + > // > // Retrieve the #address-cells and #size-cells properties > // from the root node, or use the default if not provided. > -- > 2.32.0 >