Received: by 2002:ab2:4a89:0:b0:1f4:a8b6:6e69 with SMTP id w9csp242901lqj; Wed, 10 Apr 2024 09:09:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUiuR53Y6IbFMRjjfD1ZSWmLvS4lVm23p6N9pxCqGtW02yXKCbEpvZYUf3FUWKLde+1QzwDgqOcEwdAQ2/K0YB/Eil9cMPp9J5mxrwhwQ== X-Google-Smtp-Source: AGHT+IGm0e1v5wnaUk2A8ioJcczWl+/CiH8ywC5ZLRS8lzXg6cn9I8Aga+e57wqseXSQtuc04Nxu X-Received: by 2002:a05:6a20:12c6:b0:1a9:6c78:6892 with SMTP id v6-20020a056a2012c600b001a96c786892mr1229318pzg.45.1712765376272; Wed, 10 Apr 2024 09:09:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712765376; cv=pass; d=google.com; s=arc-20160816; b=dFUddoYC4RtpfdMLJlx//yo2QfEw8rkmcHCwrBOaWTMzJfEzbYIvOKzBSm8VuclZtP N6yvqw8xFEuWyEnZDFbICUty0FOxbh7ASb6bqYf9p8+EeJPzmvDcs3QDVIuQVm/v79dm g3kMNYxtJxaO/Gk5xbq/QzutjHP27eLTvrl33/Q7d9gstB+sOF7awg/pDKoCX6yqN196 Uvfa8R8e39DwT+hiRaWOzhkESUKH+s9yLEZn3cRwsuHuUNehlnWkKaaNqXF4RXmUxpI3 LmKxooF8AfKJ6iMoU6GQitTCMWUmSXubDjuTUSxMAMvXDfnUrw451fADnNVjYwOrQyvT 3kRQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:organization:references :in-reply-to:message-id:subject:cc:to:from:date; bh=tyLs7DNrQ5Vq3JAkoJkUajeF1UkBFCwkESZfmZj7dd4=; fh=dBQLiBGtDR5OUTfKtTSVB92ax4OdmfUvjJr/HDYImzU=; b=H2Okcgl57gvPbtDCYAwrCCwjtlt9jq6ZhqRB+YCj1tg7ZPBecC2XKTiVKbuIEe7KHi uWDAUjQ2m0TqT/oMoCnQXKpb1hy049D8/xP/uVd1QEkRJg0ABBV4JkMQQPop13Gu3Q/3 T+2ie/GvBuxXAP/Y2lqInzdgK9NP91g1WxpZAy4X1TUG1LPpGdBxAFVWrFMEyfs6AWBt QhWDyPznnLlA6TK+LKcaSEmeR8a39WNQgxYErzIpP2Hkkavxp240HLUXa6A0amiN5lHn NOBZNe0R0ReWZgEjGavibYEmXfU1b9zOJsbXewck9Bs+EonuoiVw0jAZIUSpOr3PrNrA 849g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-138944-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-138944-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id h16-20020a635310000000b005f0a54e50e2si10663689pgb.889.2024.04.10.09.09.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 09:09:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-138944-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-138944-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-138944-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.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 545D628B4A1 for ; Wed, 10 Apr 2024 16:00:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 98D10174ED7; Wed, 10 Apr 2024 15:59:08 +0000 (UTC) Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C1FC215DBA9; Wed, 10 Apr 2024 15:59:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.176.79.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712764747; cv=none; b=Yn6aMDK1J9NepSyYZAeEf8exfWwta5r1Tts3ipsgPn9/XIL5rBqZ83m/suYEgO/lkEHrY0seDzlShK8wTnu594rZXXrgAEn9YzN3DojoSBwFkUFqAp6Etx266eYdeYqO/ENSX0JSoK4R35rP/UFMoHyRsVNYPJ+hs58EFZ/Ek10= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712764747; c=relaxed/simple; bh=xfuJ3ry5n91qJc92j6kBa5Z9W5YhchcmI5daF8Z4UqY=; h=Date:From:To:CC:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=C3CudGzcCa84BvuYwipZaYA0DCgyK0O8kow+kyKvYUgCHxfWtbtynoyPuBk7mHSEAtvgymIYYy9BBSxiTrFyRznUwEF0VXVv6ZRnm+7b7hCBXk+FfgXVCcvIn7dlEfmPEz+GOporlrqwHAidBaMfufRPo0is8NSPMojr2vmCB7A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=185.176.79.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.18.186.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4VF6sR73psz6J9yF; Wed, 10 Apr 2024 23:57:15 +0800 (CST) Received: from lhrpeml500005.china.huawei.com (unknown [7.191.163.240]) by mail.maildlp.com (Postfix) with ESMTPS id 32165140DD4; Wed, 10 Apr 2024 23:58:56 +0800 (CST) Received: from localhost (10.122.247.231) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Wed, 10 Apr 2024 16:58:55 +0100 Date: Wed, 10 Apr 2024 16:58:54 +0100 From: Jonathan Cameron To: "Rafael J. Wysocki" CC: Russell King , , , , , , , , , , , , , , , Salil Mehta , Jean-Philippe Brucker , , , James Morse , Miguel Luis Subject: Re: [PATCH RFC v4 02/15] ACPI: processor: Register all CPUs from acpi_processor_get_info() Message-ID: <20240410165854.00002973@huawei.com> In-Reply-To: References: <20240322185327.00002416@Huawei.com> <20240410134318.0000193c@huawei.com> <20240410145005.00003050@Huawei.com> Organization: Huawei Technologies R&D (UK) Ltd. X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.29; x86_64-w64-mingw32) 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="UTF-8" Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: lhrpeml100006.china.huawei.com (7.191.160.224) To lhrpeml500005.china.huawei.com (7.191.163.240) On Wed, 10 Apr 2024 16:19:50 +0200 "Rafael J. Wysocki" wrote: > On Wed, Apr 10, 2024 at 3:50=E2=80=AFPM Jonathan Cameron > wrote: > > > > On Wed, 10 Apr 2024 15:28:18 +0200 > > "Rafael J. Wysocki" wrote: > > =20 > > > On Wed, Apr 10, 2024 at 2:43=E2=80=AFPM Jonathan Cameron > > > wrote: =20 > > > > =20 > > > > > > =20 > > > > > > > diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c > > > > > > > index 47de0f140ba6..13d052bf13f4 100644 > > > > > > > --- a/drivers/base/cpu.c > > > > > > > +++ b/drivers/base/cpu.c > > > > > > > @@ -553,7 +553,11 @@ static void __init cpu_dev_register_gene= ric(void) > > > > > > > { > > > > > > > int i, ret; > > > > > > > > > > > > > > - if (!IS_ENABLED(CONFIG_GENERIC_CPU_DEVICES)) > > > > > > > + /* > > > > > > > + * When ACPI is enabled, CPUs are registered via > > > > > > > + * acpi_processor_get_info(). > > > > > > > + */ > > > > > > > + if (!IS_ENABLED(CONFIG_GENERIC_CPU_DEVICES) || !acpi_= disabled) > > > > > > > return; =20 > > > > > > > > > > > > Honestly, this looks like a quick hack to me and it absolutely > > > > > > requires an ACK from the x86 maintainers to go anywhere. =20 > > > > > Will address this separately. > > > > > =20 > > > > > > > > So do people prefer this hack, or something along lines of the foll= owing? > > > > > > > > static int __init cpu_dev_register_generic(void) > > > > { > > > > int i, ret =3D 0; > > > > > > > > for_each_online_cpu(i) { > > > > if (!get_cpu_device(i)) { > > > > ret =3D arch_register_cpu(i); > > > > if (ret) > > > > pr_warn("register_cpu %d failed (%d= )\n", i, ret); > > > > } > > > > } > > > > //Probably just eat the error. > > > > return 0; > > > > } > > > > subsys_initcall_sync(cpu_dev_register_generic); =20 > > > > > > I would prefer something like the above. > > > > > > I actually thought that arch_register_cpu() might return something > > > like -EPROBE_DEFER when it cannot determine whether or not the CPU is > > > really available. =20 > > > > Ok. That would end up looking much more like the original code I think. > > So we wouldn't have this late registration at all, or keep it for DT > > on arm64? I'm not sure that's a clean solution though leaves > > the x86 path alone. =20 >=20 > I'm not sure why DT on arm64 would need to do late registration. This was me falsely thinking better to do it close together for DT and ACPI. It definitely doesn't need to (or it wouldn't work today!) >=20 > There is this chain of calls in the mainline today: >=20 > driver_init() > cpu_dev_init() > cpu_dev_register_generic() >=20 > the last of which registers CPUs on arm64/DT systems IIUC. I don't see > a need to change this behavior. >=20 > On arm64/ACPI, though, arch_register_cpu() cannot make progress until > it can look into the ACPI Namespace, so I would just make it return > -EPROBE_DEFER or equivalent then and the ACPI enumeration will find > the CPU and basically treat it as one that has just appeared. Ok so giving this a go... Arm 64 version of arch_register_cpu() ended up as the following (obviously needs cleaning up, bikeshedding of naming etc) int arch_register_cpu(int cpu) { struct cpu *c =3D &per_cpu(cpu_devices, cpu); acpi_handle acpi_handle =3D ACPI_HANDLE(&c->dev); int ret; printk("!!!!! INTO arch_register_cpu() %px\n", ACPI_HANDLE(&c->dev)); if (!acpi_disabled && !acpi_handle) return -EPROBE_DEFER; if (acpi_handle) { ret =3D acpi_sta_enabled(acpi_handle); if (ret) { printk("Have handle, not enabled\n"); /* Not enabled */ return ret; } } printk("!!!!! onwards arch_register_cpu()\n"); c->hotpluggable =3D arch_cpu_is_hotpluggable(cpu); return register_cpu(c, cpu); } with new utility function in drivers/acpi/utils.c int acpi_sta_enabled(acpi_handle handle) { unsigned long long sta; bool present, enabled; acpi_status status; if (acpi_has_method(handle, "_STA")) { status =3D acpi_evaluate_integer(handle, "_STA", NULL, &sta); if (ACPI_FAILURE(status)) return -ENODEV; present =3D sta & ACPI_STA_DEVICE_PRESENT; enabled =3D sta & ACPI_STA_DEVICE_ENABLED; if (!present || !enabled) { return -EPROBE_DEFER; } return 0; } return 0; /* No _STA means always on! */ } struct cpu *c =3D &per_cpu(cpu_devices, pr->id);=09 ACPI_COMPANION_SET(&c->dev, device); in acpi_processor_get_info() and that calls static int acpi_processor_make_enabled(struct acpi_processor *pr) { int ret; if (invalid_phys_cpuid(pr->phys_id)) return -ENODEV; cpus_write_lock(); ret =3D arch_register_cpu(pr->id); cpus_write_unlock(); return ret; } I think setting the ACPI handle should be harmless on other architectures. It seems like the obvious one to set it to for cpu->dev. Brief tests on same set of DT and ACPI on x86 and arm64 seem fine. >=20 > > If we get rid of this catch all, solution would be to move the > > !acpi_disabled check into the arm64 version of arch_cpu_register() > > because we would only want the delayed registration path to be > > used on ACPI cases where the question of CPU availability can't > > yet be resolved. =20 >=20 > Exactly. >=20 > This is similar (if not equivalent even) to a CPU becoming available > between the cpu_dev_register_generic() call and the ACPI enumeration. >=20 > > > > > > Then, the ACPI processor enumeration path may take care of registering > > > CPU that have not been registered so far and in the more-or-less the > > > same way regardless of the architecture (modulo some arch-specific > > > stuff). =20 > > > > If I understand correctly, in acpi_processor_get_info() we'd end up > > with a similar check on whether it was already registered (the x86 path) > > or had be deferred (arm64 / acpi). > > =20 > > > > > > In the end, it should be possible to avoid changing the behavior of > > > x86 and loongarch in this series. =20 > > > > Possible, yes, but result if I understand correctly is we end up with > > very different flows and replication of functionality between the > > early registration and the late one. I'm fine with that if you prefer i= t! =20 >=20 > But that's what is there today, isn't it? Agreed - but I was previously thinking we could move everything late. I'm fine with just keeping the two flows separate. >=20 > I think this can be changed to reduce the duplication, but I'd prefer > to do that later, when the requisite functionality is in place and we > just do the consolidation. In that case, if anything goes wrong, we > can take a step back and reconsider without deferring the arm64 CPU > hotplug support. Great. That plan certainly works for me :) Thanks for quick replies and help getting this headed in right direction. +CC Miguel who is also looking at some of this series. Sorry Miguel, was assuming you were on the thread and never checked :( Jonathan