lib: don't fall back to /dev/mem for ACPI tables exposed via sysfs#308
Open
rucoder wants to merge 1 commit into
Open
lib: don't fall back to /dev/mem for ACPI tables exposed via sysfs#308rucoder wants to merge 1 commit into
rucoder wants to merge 1 commit into
Conversation
45ebfc4 to
d2130b8
Compare
There was a problem hiding this comment.
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, returnNULLinstead of scanning physical memory via/dev/mem. - Preserve the legacy
/dev/memfallback 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.
Contributor
|
HI @rucoder , |
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>
d2130b8 to
9fbbbc3
Compare
Contributor
Author
|
@rkanagar addressed the review comments in 9fbbbc3: reworded the comment and debug message in |
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; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Closes #307.
On kernels built with
CONFIG_STRICT_DEVMEM=y, initializing libpqos (or running thepqosCLI) emits:acpi_get_sig()first looks for a table under/sys/firmware/acpi/tables/, and if it is not there falls back toacpi_get_mmap(), which opens/dev/memand maps/reads physical memory (RSDP/BIOS region).CONFIG_STRICT_DEVMEM=yrestricts/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.cwalksacpi_gbl_root_table_listwith no signature filtering). Therefore:/dev/memneeded./dev/memeither — 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, returnNULLinstead of scanning/dev/mem. The memory fallback is preserved for kernels that do not expose that directory.Test
make -C libbuilds clean (no new warnings;acpi_get_mmapis still referenced for the legacy path).CONFIG_STRICT_DEVMEM=yhost where/sys/firmware/acpi/tables/exists without anERDTentry, init no longer touches/dev/memand the errors above are gone.