Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1269636rdb; Wed, 24 Jan 2024 09:41:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IHdIdk7AXQtFRyl7bHYCYiDOV7MP1ml8xOFW01E5RqiAbw6cUufbKBU8lNcany/lhs2Lfz1 X-Received: by 2002:a05:6a00:84:b0:6d0:8b0d:b8c1 with SMTP id c4-20020a056a00008400b006d08b0db8c1mr7993144pfj.35.1706118095766; Wed, 24 Jan 2024 09:41:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706118095; cv=pass; d=google.com; s=arc-20160816; b=k5cURjkGUuLI6Ah2qCeYgdWR5OWBOHJRmDajpWeKFds3dIt/pGiRtpH1yyrPMpnFEr e0QoDLSB3ad2pwMxqbbvUM1VsDt2xUMkKZm+7g5+EY19Los9ZBH+GrwHxGxf9nGGLGEZ kjlfjoZi2UiuLuzvOaZb8wiSpwU0sxZPnIpbUq97XLvEZMyyRR7imCFi2J7ZVsrAkO8U +tgirPHj+WEBA9gM8g4BQtLxkhW2snOo7UQuj+50iR8zrT9zFHFVPXUXWXjgCs6WLR8o t701PEz4jcXOpQhzHUrMIesOQPJfBMBzlqj7UzQgNtotg8IHzPEl5Tbj3FfSiyTffVMX Z4Hw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=HrKSWjAPLury0l0O07YwABLahdqYSfqu/vkyFWYooQ8=; fh=Ru3N0omC7MFqUR4cInxfXuPYgF2VaXRcKcrOgsv8nyw=; b=OCTQ+jEA3kVDE+QC35HIjb7Ts+EF7bGyObOEZFTZSYc1mgrRtyJ/X2u4DyfqqxZozm kTzy8xLOdNYievFBRFbor5xc8a80LDn7N75mJkgrYg+E1SLbg0KyaTXOX6vJtnPHj+6z F2VG6P//wa0ljQRssweDLX5DB+0u8XPOxSiF9vKfVu4U4V/cUp4rPrcBXXyTpwwt/ZlM vKlhlQnLtI6ZVGhr2ztlguxka1hIHvA2TgWYUeZE/1wfCP0e+Uf8dgdR9l1EXpD8K0BQ VKuUUYUqvYR+0uAIFBXtMozylqmZ0ROao+ZTHtJ4ipYvxvqq7iqpfNtWUjez3uCtDQKW Rg5w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=G5EdBFOr; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-37451-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37451-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id a8-20020a637048000000b005cddfe1270asi11729960pgn.827.2024.01.24.09.41.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 09:41:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-37451-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=G5EdBFOr; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-37451-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37451-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 651FC28223A for ; Wed, 24 Jan 2024 17:41:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 12C1181AA5; Wed, 24 Jan 2024 17:41:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="G5EdBFOr" Received: from mail-yw1-f180.google.com (mail-yw1-f180.google.com [209.85.128.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CFE067F7F2; Wed, 24 Jan 2024 17:41:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706118082; cv=none; b=Uk7OIwcgdGmO6fcVgsHAPrEFoAjCmkQioAqvH+93o7Fh6JsWrkeeOrZOIMbS5Pe/5dwf4PgOnobB7r/kO5anncA4FjL0ODIGRczFEHrY7C9imejCrW7MihtZKHYm2QA9wEszYT7RRC6KKZBBhZfdDeL9mM5IUlxN/WeBrwZ/03k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706118082; c=relaxed/simple; bh=tw/ivyCBJnZU8g06Ui6BqgkgwG6NCYQYJWdwrEbM3kk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=cSjtuzbZNbogPLgKRE0GjDpMZXi+bVag+INxfIeLFayqGzsE15FV5xX9LgonPjhxKBvHg24z9n9e1HNIj8PLfep8QUnT9ABJL3+NNYQkg3eoZQDvV7OrSAey113JwLzMFwhVm6jtEjb7DOTWWHhasgpuKjTyGYTc5OeFI8XEAWM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=G5EdBFOr; arc=none smtp.client-ip=209.85.128.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-yw1-f180.google.com with SMTP id 00721157ae682-5ff84214fc7so56504587b3.0; Wed, 24 Jan 2024 09:41:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706118080; x=1706722880; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=HrKSWjAPLury0l0O07YwABLahdqYSfqu/vkyFWYooQ8=; b=G5EdBFOrAMr19wXn2q14X3LktuaZwjb1JaH9G+/9xLGwXHmGz3H/Bg/o9H/g+d5zTd MB7isfnGoAtjLDqpLhEPl48t1p0VST3rziSB78N+5rZfq915mUvuC3e2Z0cHLw8EkLe6 7CmdbkRX9Ximcvf6CuJZLPPjugNw5kzYzMV1VUNRFXR7euEYBl9dIojpDZVjijgPXXer b2peL5QCepqqnrHucuRUg9L8FTjSx03nSx3g8WQjBpHFosE9urZenIJ2MXfU/LvijYvQ fFp+LtHhW0/Mn8aVc+YlF+exhgK2fQCH0NIh+lOJgSaP4ZP1aN3DqsexWp9RDkyAGgY5 /0LA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706118080; x=1706722880; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=HrKSWjAPLury0l0O07YwABLahdqYSfqu/vkyFWYooQ8=; b=MDhAxeb3LoGADwktNboej6gHeMACe96qXGog3FeumAwMpNzKxNEQpV2i4D4SuXerNW As6CYk484OsGwejYoQVcU99DPlxhkSGoLAi99WiNGyQr1fuKE9KcS6mPNRfhxlkiohph eV9Priu+YLfX39cRcaguUaXKT0G7kIFA2NM1v+UG32LebNIMSjAWqZG86dQoOxVW0Bzq SdCS5PgY7BONS01CpME/hq5XuHHvjW3HUvNoNuZJf6rDp2fF7xul7ZA+2VHojw+oG9Kk +kcYksoXY5WHHnjaZYtdq67wtDRvK5hgew/M1wckILDiupu8DH5dinQ7tkvIoj9BrGCx AQMg== X-Gm-Message-State: AOJu0YyHdTSImhU/F5BF606d1InoH42aedxQTHfmFSJC3q+Sf/oYyrTB YfsAmX6VbBTgkIWCNjW7azF3Nm7jCuAaJIwDMwEJ3BuuIajmUg7t X-Received: by 2002:a0d:d70b:0:b0:5ff:9f2c:1299 with SMTP id z11-20020a0dd70b000000b005ff9f2c1299mr1077412ywd.65.1706118079707; Wed, 24 Jan 2024 09:41:19 -0800 (PST) Received: from localhost ([2601:344:8301:57f0:abdb:7236:6977:9ab5]) by smtp.gmail.com with ESMTPSA id t140-20020a0dea92000000b005ffb2815960sm77564ywe.45.2024.01.24.09.41.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 09:41:19 -0800 (PST) Date: Wed, 24 Jan 2024 09:41:18 -0800 From: Yury Norov To: "Lameter, Christopher" Cc: Huang Shijie , gregkh@linuxfoundation.org, patches@amperecomputing.com, rafael@kernel.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, kuba@kernel.org, vschneid@redhat.com, mingo@kernel.org, akpm@linux-foundation.org, vbabka@suse.cz, rppt@kernel.org, tglx@linutronix.de, jpoimboe@kernel.org, ndesaulniers@google.com, mikelley@microsoft.com, mhiramat@kernel.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, catalin.marinas@arm.com, will@kernel.org, mark.rutland@arm.com, mpe@ellerman.id.au, linuxppc-dev@lists.ozlabs.org, chenhuacai@kernel.org, jiaxun.yang@flygoat.com, linux-mips@vger.kernel.org Subject: Re: [PATCH v2] NUMA: Early use of cpu_to_node() returns 0 instead of the correct node id Message-ID: References: <20240123045843.75969-1-shijie@os.amperecomputing.com> <4a13353c-cf4b-a388-5776-389c61c63ec0@os.amperecomputing.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4a13353c-cf4b-a388-5776-389c61c63ec0@os.amperecomputing.com> On Wed, Jan 24, 2024 at 09:19:00AM -0800, Lameter, Christopher wrote: > On Tue, 23 Jan 2024, Huang Shijie wrote: > > > During the kernel booting, the generic cpu_to_node() is called too early in > > arm64, powerpc and riscv when CONFIG_NUMA is enabled. > > > > For arm64/powerpc/riscv, there are at least four places in the common code > > where the generic cpu_to_node() is called before it is initialized: > > 1.) early_trace_init() in kernel/trace/trace.c > > 2.) sched_init() in kernel/sched/core.c > > 3.) init_sched_fair_class() in kernel/sched/fair.c > > 4.) workqueue_init_early() in kernel/workqueue.c > > > > In order to fix the bug, the patch changes generic cpu_to_node to > > function pointer, and export it for kernel modules. > > Introduce smp_prepare_boot_cpu_start() to wrap the original > > smp_prepare_boot_cpu(), and set cpu_to_node with early_cpu_to_node. > > Introduce smp_prepare_cpus_done() to wrap the original smp_prepare_cpus(), > > and set the cpu_to_node to formal _cpu_to_node(). > > Would you please fix this cleanly without a function pointer? > > What I think needs to be done is a patch series. > > 1. Instrument cpu_to_node so that some warning is issued if it is used too > early. Preloading the array with NUMA_NO_NODE would allow us to do that. By preloading do you mean compile-time initialization? > 2. Implement early_cpu_to_node on platforms that currently do not have it. > > 3. A series of patches that fix each place where cpu_to_node is used too > early. Agree. This is the right way to go. And pretty well all of it was discussed in v1, isn't? Thanks, Yury