From owner-dev-commits-src-main@freebsd.org Sat Sep 25 21:01:32 2021 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id DEFB1668A91; Sat, 25 Sep 2021 21:01: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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HH1Xr5rx9z3j07; Sat, 25 Sep 2021 21:01:32 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 A92291164B; Sat, 25 Sep 2021 21:01:32 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 18PL1WW7003366; Sat, 25 Sep 2021 21:01:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 18PL1W4I003365; Sat, 25 Sep 2021 21:01:32 GMT (envelope-from git) Date: Sat, 25 Sep 2021 21:01:32 GMT Message-Id: <202109252101.18PL1W4I003365@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Alexander Motin Subject: git: 695323ae88c7 - main - acpi_cpu: Fix panic if some CPU devices are disabled. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mav X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 695323ae88c71776e131940ed7dedd25365e932f Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 25 Sep 2021 21:01:32 -0000 The branch main has been updated by mav: URL: https://cgit.FreeBSD.org/src/commit/?id=695323ae88c71776e131940ed7dedd25365e932f commit 695323ae88c71776e131940ed7dedd25365e932f Author: Alexander Motin AuthorDate: 2021-09-25 20:54:28 +0000 Commit: Alexander Motin CommitDate: 2021-09-25 21:01:28 +0000 acpi_cpu: Fix panic if some CPU devices are disabled. While there, remove couple unneeded global variables. --- sys/dev/acpica/acpi_cpu.c | 66 +++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 37 deletions(-) diff --git a/sys/dev/acpica/acpi_cpu.c b/sys/dev/acpica/acpi_cpu.c index ab4ffda7a02e..0577b6eac8b7 100644 --- a/sys/dev/acpica/acpi_cpu.c +++ b/sys/dev/acpica/acpi_cpu.c @@ -154,8 +154,6 @@ static struct sysctl_oid *cpu_sysctl_tree; static int cpu_cx_generic; static int cpu_cx_lowest_lim; -static device_t *cpu_devices; -static int cpu_ndevices; static struct acpi_cpu_softc **cpu_softc; ACPI_SERIAL_DECL(cpu, "ACPI CPU"); @@ -443,26 +441,21 @@ acpi_cpu_attach(device_t dev) static void acpi_cpu_postattach(void *unused __unused) { - device_t *devices; - int err; - int i, n; - int attached; - - err = devclass_get_devices(acpi_cpu_devclass, &devices, &n); - if (err != 0) { - printf("devclass_get_devices(acpi_cpu_devclass) failed\n"); - return; + struct acpi_cpu_softc *sc; + int attached = 0, i; + + mtx_lock(&Giant); + CPU_FOREACH(i) { + if ((sc = cpu_softc[i]) != NULL) + bus_generic_probe(sc->cpu_dev); + } + CPU_FOREACH(i) { + if ((sc = cpu_softc[i]) != NULL) { + bus_generic_attach(sc->cpu_dev); + attached = 1; + } } - attached = 0; - for (i = 0; i < n; i++) - if (device_is_attached(devices[i]) && - device_get_driver(devices[i]) == &acpi_cpu_driver) - attached = 1; - for (i = 0; i < n; i++) - bus_generic_probe(devices[i]); - for (i = 0; i < n; i++) - bus_generic_attach(devices[i]); - free(devices, M_TEMP); + mtx_unlock(&Giant); if (attached) { #ifdef EARLY_AP_STARTUP @@ -937,9 +930,6 @@ acpi_cpu_startup(void *arg) struct acpi_cpu_softc *sc; int i; - /* Get set of CPU devices */ - devclass_get_devices(acpi_cpu_devclass, &cpu_devices, &cpu_ndevices); - /* * Setup any quirks that might necessary now that we have probed * all the CPUs @@ -951,9 +941,9 @@ acpi_cpu_startup(void *arg) * We are using generic Cx mode, probe for available Cx states * for all processors. */ - for (i = 0; i < cpu_ndevices; i++) { - sc = device_get_softc(cpu_devices[i]); - acpi_cpu_generic_cx_probe(sc); + CPU_FOREACH(i) { + if ((sc = cpu_softc[i]) != NULL) + acpi_cpu_generic_cx_probe(sc); } } else { /* @@ -961,8 +951,9 @@ acpi_cpu_startup(void *arg) * As we now know for sure that we will be using _CST mode * install our notify handler. */ - for (i = 0; i < cpu_ndevices; i++) { - sc = device_get_softc(cpu_devices[i]); + CPU_FOREACH(i) { + if ((sc = cpu_softc[i]) == NULL) + continue; if (cpu_quirks & CPU_QUIRK_NO_C3) { sc->cpu_cx_count = min(sc->cpu_cx_count, sc->cpu_non_c3 + 1); } @@ -972,9 +963,9 @@ acpi_cpu_startup(void *arg) } /* Perform Cx final initialization. */ - for (i = 0; i < cpu_ndevices; i++) { - sc = device_get_softc(cpu_devices[i]); - acpi_cpu_startup_cx(sc); + CPU_FOREACH(i) { + if ((sc = cpu_softc[i]) != NULL) + acpi_cpu_startup_cx(sc); } /* Add a sysctl handler to handle global Cx lowest setting */ @@ -985,9 +976,9 @@ acpi_cpu_startup(void *arg) /* Take over idling from cpu_idle_default(). */ cpu_cx_lowest_lim = 0; - for (i = 0; i < cpu_ndevices; i++) { - sc = device_get_softc(cpu_devices[i]); - enable_idle(sc); + CPU_FOREACH(i) { + if ((sc = cpu_softc[i]) != NULL) + enable_idle(sc); } #if defined(__i386__) || defined(__amd64__) cpu_idle_hook = acpi_cpu_idle; @@ -1517,8 +1508,9 @@ acpi_cpu_global_cx_lowest_sysctl(SYSCTL_HANDLER_ARGS) /* Update the new lowest useable Cx state for all CPUs. */ ACPI_SERIAL_BEGIN(cpu); cpu_cx_lowest_lim = val - 1; - for (i = 0; i < cpu_ndevices; i++) { - sc = device_get_softc(cpu_devices[i]); + CPU_FOREACH(i) { + if ((sc = cpu_softc[i]) == NULL) + continue; sc->cpu_cx_lowest_lim = cpu_cx_lowest_lim; acpi_cpu_set_cx_lowest(sc); }