Skip to content

lib: don't fall back to /dev/mem for ACPI tables exposed via sysfs#308

Open
rucoder wants to merge 1 commit into
intel:masterfrom
rucoder:rucoder/acpi-strict-devmem
Open

lib: don't fall back to /dev/mem for ACPI tables exposed via sysfs#308
rucoder wants to merge 1 commit into
intel:masterfrom
rucoder:rucoder/acpi-strict-devmem

Conversation

@rucoder

@rucoder rucoder commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Problem

Closes #307.

On kernels built with CONFIG_STRICT_DEVMEM=y, initializing libpqos (or running the pqos CLI) emits:

ERROR: Memory map failed, address=... size=...
ERROR: Memory mapping failed!
ERROR: Failed to obtain RSDP table!
WARN: Could not obtain ERDT table

acpi_get_sig() first looks for a table under /sys/firmware/acpi/tables/, and if it is not there falls back to acpi_get_mmap(), which opens /dev/mem and maps/reads physical memory (RSDP/BIOS region). CONFIG_STRICT_DEVMEM=y restricts /dev/mem, so the mmap fails — or, for the low-BIOS scan region, the mmap can succeed and the subsequent read faults. For a library caller this is worse than log noise: a fault in this path takes down the process (e.g. a CGO host such as the Go bindings).

Why the memory fallback is unnecessary here

The kernel exposes every ACPI table advertised in the RSDT/XSDT under /sys/firmware/acpi/tables/, keyed by signature, regardless of whether the kernel has a driver for it (drivers/acpi/sysfs.c walks acpi_gbl_root_table_list with no signature filtering). Therefore:

  • If ERDT/MRRM/IRDT exist, firmware lists them in the XSDT and they are already present in sysfs — no /dev/mem needed.
  • If they are not in sysfs, they are not obtainable from /dev/mem either — the fallback finds nothing and only risks the strict-devmem fault.

The fallback is only meaningful on legacy kernels that do not expose /sys/firmware/acpi/tables/ at all.

Fix

In acpi_get_sig(), when /sys/firmware/acpi/tables/ exists but the requested table is not present there, return NULL instead of scanning /dev/mem. The memory fallback is preserved for kernels that do not expose that directory.

Test

  • make -C lib builds clean (no new warnings; acpi_get_mmap is still referenced for the legacy path).
  • On a CONFIG_STRICT_DEVMEM=y host where /sys/firmware/acpi/tables/ exists without an ERDT entry, init no longer touches /dev/mem and the errors above are gone.

@rucoder rucoder force-pushed the rucoder/acpi-strict-devmem branch 2 times, most recently from 45ebfc4 to d2130b8 Compare July 1, 2026 11:04
@rstorozh rstorozh requested a review from Copilot July 1, 2026 11:15
@rstorozh rstorozh self-assigned this Jul 1, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates libpqos ACPI table discovery to avoid falling back to /dev/mem when the kernel exposes ACPI tables via sysfs, preventing failures (and potential process faults) on CONFIG_STRICT_DEVMEM=y systems.

Changes:

  • In acpi_get_sig(), if /sys/firmware/acpi/tables/ exists but the requested table is not found there, return NULL instead of scanning physical memory via /dev/mem.
  • Preserve the legacy /dev/mem fallback only for kernels that do not expose the ACPI tables sysfs directory.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/acpi.c
Comment thread lib/acpi.c Outdated
@rkanagar

Copy link
Copy Markdown
Contributor

HI @rucoder ,
Please address the review comments. Thanks

On CONFIG_STRICT_DEVMEM=y kernels, acpi_get_sig() falling back to
acpi_get_mmap() maps and reads physical memory via /dev/mem, which the
kernel restricts. The mmap of the RSDP/BIOS region either fails or, worse,
succeeds and then faults on access, taking down a CGO host process such as
the Go bindings.

When the kernel exposes ACPI tables under /sys/firmware/acpi/tables but the
requested table is not present there, return NULL instead of scanning
/dev/mem. The memory fallback is still used on legacy kernels that do not
expose the sysfs ACPI tables directory at all.

Fixes: intel#307
Signed-off-by: Mikhail Malyshev <mike.malyshev@gmail.com>
@rucoder rucoder force-pushed the rucoder/acpi-strict-devmem branch from d2130b8 to 9fbbbc3 Compare July 10, 2026 07:11
@rucoder

rucoder commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

@rkanagar addressed the review comments in 9fbbbc3: reworded the comment and debug message in acpi_get_sig() to say the table is "not available via sysfs" (covering both the absent case and the present-but-unreadable/invalid case), since the early return also triggers when acpi_read_fs() fails. No behavior change. Thanks!

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread lib/acpi.c
Comment on lines +483 to +488
if (pqos_dir_exists(ACPI_TABLE_FS_PATH)) {
LOG_DEBUG("ACPI table %s not available via sysfs; "
"skipping memory scan\n",
sig);
return NULL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Access to /dev/mem doesn't allow using latest (13.02.26) libpqos on CONFIG_STRICT_DEVMEM=y systems

4 participants