From nobody Tue Jan 04 18:03:29 2022 X-Original-To: dev-commits-src-branches@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 CEAA11923B8F; Tue, 4 Jan 2022 18:03:30 +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 4JT0pn6BlPz4tYW; Tue, 4 Jan 2022 18:03:29 +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 788E31D5EC; Tue, 4 Jan 2022 18:03:29 +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 204I3THc025649; Tue, 4 Jan 2022 18:03:29 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 204I3T3Y025648; Tue, 4 Jan 2022 18:03:29 GMT (envelope-from git) Date: Tue, 4 Jan 2022 18:03:29 GMT Message-Id: <202201041803.204I3T3Y025648@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Alexander Motin Subject: git: a77188ffd34f - stable/13 - acpi_cpu: Fix panic if some CPU devices are disabled. List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org 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/stable/13 X-Git-Reftype: branch X-Git-Commit: a77188ffd34f5f6ba1209caa25f227362339f23f Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1641319409; 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=yjhuDRPCiblixU2bHXGLR3uJH50Gf8woq8pEtOr8BcI=; b=ojcmq9S2p90/z1jOA9eGJEDOLgh/V1DyOAVQV5z+BVWbdKDDlD7zKVB/X1L8HqHsb6yc7i pP5J3VvP1bGGhsusj2B8i7xsHIj0PUvpIk/YN05gNSZP3R61LIOWTm5jrjKxsvE+zuBSs5 RVjTRCB+MDmAOqhcWn2noaFpEeaMGoG4srGHGHGyKgwjaXEi89Zw/NK2Ja8f9Gn/zbckNA ZRW/UQdA4G/vOZymWQfsL5s1xKxEZSQGYeptuRTl311UVVEw18+S+6+A3fOWCJePMoacle VdnJSbF+j2SZ0ZeQeMx8NCvaneib7XABKvR1soGJkpj2utT6MQy1qbDKyhU2Aw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1641319409; a=rsa-sha256; cv=none; b=Iq114KyuA7GRWMd4J/U+VGbZoutq/WRCKBYSSXEo3SP6BO0qrONbQwLTuELjHLlQB/EFsu e1mGdrzg6iyV5DIFRyoLU4tW3JoNYagodh5WRmLiILRJL3Qc6m77iAgK9Eaech2EO0cM+0 HfrUvoBuMPsNazk3FNfH2bpbaQ4daC3YZA8UPdR8qO0o/5Lw/NYOM9+KqfKpoRgTU6laHA D6rR3sld9GCfOQJmWrlCYyQcLwv5J5Ruh4tyBVqZ1ufxsWblmyiRNnID1fGiAJYI46VhFK u0r8+ak8tK7c3etxao/gpNCarM973UVZoCudz0Qk6WnnNvM2Fu3PpKkf6eK05Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by mav: URL: https://cgit.FreeBSD.org/src/commit/?id=a77188ffd34f5f6ba1209caa25f227362339f23f commit a77188ffd34f5f6ba1209caa25f227362339f23f Author: Alexander Motin AuthorDate: 2021-09-25 20:54:28 +0000 Commit: Alexander Motin CommitDate: 2022-01-04 17:21:46 +0000 acpi_cpu: Fix panic if some CPU devices are disabled. While there, remove couple unneeded global variables. (cherry picked from commit 695323ae88c71776e131940ed7dedd25365e932f) --- 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); }