Index | Thread | Search

From:
Stefan Hahne <Stefan.Hahne@gmx.de>
Subject:
ACPI: Check the loop in acpicpu_getcst
To:
tech@openbsd.org
Date:
Sun, 15 Nov 2026 17:25:06 +0100

Download raw body.

Thread
  • Stefan Hahne:

    ACPI: Check the loop in acpicpu_getcst

Hi,

i am currently looking into the idle behavior of OpenBSD. In a first 
step i added several measurement variables inside the kernel and looked 
into idle related code path. I am quite new to these OpenBSD kernel 
related topics so i could be wrong with the following assessment.

When i instrumented the code inside 'acpi/acpicpu_x86.c' i looked at the 
function 'acpicpu_getcst' and the state loop looks like it is missing an 
element.

I am talking about the following (please ignore the diff before the 
mentioned function):

diff --git sys/dev/acpi/acpicpu_x86.c sys/dev/acpi/acpicpu_x86.c
index 16a0549dcca..5f35ab9a02e 100644
--- sys/dev/acpi/acpicpu_x86.c
+++ sys/dev/acpi/acpicpu_x86.c
@@ -45,10 +45,10 @@ int    acpicpu_notify(struct aml_node *, int, void *);
  void    acpicpu_setperf(int);
  void    acpicpu_setperf_ppc_change(struct acpicpu_pss *, int);

-#define ACPI_STATE_C0        0x00
  #define ACPI_STATE_C1        0x01
  #define ACPI_STATE_C2        0x02
  #define ACPI_STATE_C3        0x03
+#define CSTATE_MAX          ACPI_STATE_C3

  #define ACPI_PDC_REVID        0x1
  #define ACPI_PDC_SMP        0xa
@@ -382,7 +382,7 @@ acpicpu_add_cstatepkg(struct aml_value *val, void *arg)

      /* range and sanity checks */
      state = val->v_package[1]->v_integer;
-    if (state < 0 || state > 4)
+    if (state < ACPI_STATE_C1 || state > CSTATE_MAX)
          return;
      if (val->v_package[0]->type != AML_OBJTYPE_BUFFER) {
          printf(": C%d (unexpected ACPI object type %d)",
@@ -537,14 +537,15 @@ acpicpu_getcst(struct acpicpu_softc *sc)
       * Also keep track if all the states we'll use use mwait.
       */
      use_nonmwait = 0;
-    while ((next_cx = SLIST_NEXT(cx, link)) != NULL) {
+    do {
          if (cx->state > 1 &&
              (sc->sc_ci->ci_feature_tpmflags & TPM_ARAT) == 0)
              cx->flags |= CST_FLAG_SKIP;
          else if (cx->method != CST_METH_MWAIT)
              use_nonmwait = 1;
+        next_cx = SLIST_NEXT(cx, link);
          cx = next_cx;
-    }
+    } while (next_cx != NULL);
      if (use_nonmwait)
          sc->sc_flags &= ~FLAGS_MWAIT_ONLY;
      else


Kind regards,

Stefan