From nobody Fri Jan 10 19:18:31 2025 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4YVBJm2HfZz5kNsl; Fri, 10 Jan 2025 19:18:32 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YVBJm1KBDz4Mgw; Fri, 10 Jan 2025 19:18:32 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1736536712; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=kUht3pIm0N6irH6IapjcSfonGFnl5V1dgNcsG1GrXDE=; b=JXBomqYsJb5yY8ErFZaEBHe6CGLdiy0S4k+AcNSNOJJLvMuoxvHVcptEwmzPYHysWvCpIM dkkmDyhQlLIuc3+vLg+Ikr0eHEdXB+kFuxm1z0i7WVtegJ/m5L10C4X1KYX8Q4uP5LxZUZ eBpQ6IljSFrdGjiaFTWz7iARK7K00A+9hC5vEBrlR875tciUSHB3nKZlNps8U+3CLzKFx6 +HzwPo/uhor/wDe8ZPOAAOiVXogsUSsPPQE4Nwz/ngZxOLFmRxb6GTBAFPiLYtkVZnd1hU /ImuoPAbn4k87ngJvIImQtVnJUb0UxiyeCI1XU6xTtdHb1AO/sz67tPU+HtRkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1736536712; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=kUht3pIm0N6irH6IapjcSfonGFnl5V1dgNcsG1GrXDE=; b=obM8OCJOxJ1j8VPWBClVfE2WWeCgROQENuIgV51gxM1p70y/QMxUJFsn9BbfNFpfF8Nj1h 5+rtXE9L+U3wGEYu3BiTlUJgQ5URRZzMgw4Pv011M+odHdEGrrBM/qoQ9j6uBIFC2MDhj+ qr1JFavTXPRgpcSNvZadzAaVO8ecQ8pkC4qsdxPqdI+VYG7qzdE4S0iYQ0Tcm2/G6NnmXH pbCaT/3IrI+ILRIBWnFO8cua9jVcLtCTGoHRbxiCxpPCcmCuxIhF13TfHagVkynUbFn7LA h0OYIj4zWjRNmK3hARSHNQ3+jbxhbj3k65iJaJyXF0JbtWYWK1rSbZCELKPYVg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1736536712; a=rsa-sha256; cv=none; b=FAsG/1Av82ET4iV6tyFS6kcDS+6xMr3iWBpGmKfiR8h4ls3Q9JdYEhlcZWaW6/TDle7OFn aV2ETZKN5QOc431KK6ObWxNSy63Nfq33MbdEa98wFf+0SfoF1re5IlLoubXNz4BCfe2aDG JZmlBtYtFIzInkTuDV3f3xEABPdkk6QdSkQdESHjFysLKMkuWKZPyQbAhN3P+CVB8xqywZ vrZ5kgrMkgp+290FVUL/Bvb+P0YGpW4hpTMWAUBIIP3vCyFYQdCkbuUsa0Ef0C1mnZqLhP A8G5dmyI2otkmbvzMx+8MH37h0k/IGLrp7bt4NvFrr9l7hKO66tWmncLPhe69g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4YVBJm0fscz90F; Fri, 10 Jan 2025 19:18:32 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 50AJIVb0026528; Fri, 10 Jan 2025 19:18:31 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 50AJIVqL026525; Fri, 10 Jan 2025 19:18:31 GMT (envelope-from git) Date: Fri, 10 Jan 2025 19:18:31 GMT Message-Id: <202501101918.50AJIVqL026525@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mitchell Horne Subject: git: ac9de183f370 - main - ofw_cpu: check for "disabled" status during probe List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: ac9de183f37006fc2089757779d6d5065a530d5b Auto-Submitted: auto-generated The branch main has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=ac9de183f37006fc2089757779d6d5065a530d5b commit ac9de183f37006fc2089757779d6d5065a530d5b Author: Mitchell Horne AuthorDate: 2025-01-10 18:46:56 +0000 Commit: Mitchell Horne CommitDate: 2025-01-10 18:59:08 +0000 ofw_cpu: check for "disabled" status during probe Some RISC-V CPUs contain a "monitor core" with limited functionality (no MMU). These cores appear in some device trees, but we don't run the kernel on them; in early CPU start-up code we skip them, and they have no impact on mp_ncpu. It seems the new trend is to mark these monitor cores with a 'status' property of 'disabled'. However, we still instantiate an ofw_cpu pseudo device for the disabled core. This is generally harmless, but there is an impact when attempting to attach the cpufreq_dt driver. It counts more OFW CPU devices (unit number) than logical CPUs (mp_ncpus), and therefore fails to attach for the last logical CPU. The solution is to check the status property in ofw_cpu_probe(), and fail if the core is marked "disabled". This is subject to the same exception already in ofw_cpu_early_foreach(); that is, if a disabled CPU has an 'enable-method' property, it can be used by the kernel. Reviewed by: andrew, jrtc27 MFC after: 1 month Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D48123 --- sys/dev/ofw/ofw_cpu.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/sys/dev/ofw/ofw_cpu.c b/sys/dev/ofw/ofw_cpu.c index 339716a946ff..888af0440746 100644 --- a/sys/dev/ofw/ofw_cpu.c +++ b/sys/dev/ofw/ofw_cpu.c @@ -182,6 +182,24 @@ static driver_t ofw_cpu_driver = { DRIVER_MODULE(ofw_cpu, cpulist, ofw_cpu_driver, 0, 0); +static bool +ofw_cpu_is_runnable(phandle_t node) +{ + /* + * Per the DeviceTree Specification, a cpu node (under /cpus) that + * has 'status = disabled' indicates that "the CPU is in a quiescent + * state." + * + * A quiescent CPU that specifies an "enable-method", such as + * "spin-table", can still be used by the kernel. + * + * Lacking this, any CPU marked "disabled" or other non-okay status + * should be excluded from the kernel's view. + */ + return (ofw_bus_node_status_okay(node) || + OF_hasprop(node, "enable-method")); +} + static int ofw_cpu_probe(device_t dev) { @@ -190,6 +208,9 @@ ofw_cpu_probe(device_t dev) if (type == NULL || strcmp(type, "cpu") != 0) return (ENXIO); + if (!ofw_cpu_is_runnable(ofw_bus_get_node(dev))) + return (ENXIO); + device_set_desc(dev, "Open Firmware CPU"); if (!bootverbose && device_get_unit(dev) != 0) { device_quiet(dev); @@ -352,7 +373,6 @@ ofw_cpu_early_foreach(ofw_cpu_foreach_cb callback, bool only_runnable) { phandle_t node, child; pcell_t addr_cells, reg[2]; - char status[16]; char device_type[16]; u_int id, next_id; int count, rv; @@ -389,14 +409,8 @@ ofw_cpu_early_foreach(ofw_cpu_foreach_cb callback, bool only_runnable) * those that have been enabled, or do provide a method * to enable them. */ - if (only_runnable) { - status[0] = '\0'; - OF_getprop(child, "status", status, sizeof(status)); - if (status[0] != '\0' && strcmp(status, "okay") != 0 && - strcmp(status, "ok") != 0 && - !OF_hasprop(child, "enable-method")) - continue; - } + if (only_runnable && !ofw_cpu_is_runnable(child)) + continue; /* * Check we have a register to identify the cpu