Skip to content

utilities: Add bounded bitmap accessors - #377

Open
bentheredonethat wants to merge 4 commits into
OpenAMP:mainfrom
bentheredonethat:bitmap-bounded-accessors
Open

bentheredonethat wants to merge 4 commits into
OpenAMP:mainfrom
bentheredonethat:bitmap-bounded-accessors

Conversation

@bentheredonethat

Copy link
Copy Markdown
Contributor

The existing bitmap accessors accept signed bit IDs without a bitmap size, so invalid IDs can access storage outside the bitmap. OpenAMP's remoteproc notification bitmap needs bounded operations for allocation and rollback.

Add metal_bitmap_set(), metal_bitmap_clear(), metal_bitmap_is_set(), and metal_bitmap_is_clear() with unsigned bit IDs and an explicit size in bits. Reject out-of-range IDs with -EINVAL before accessing storage. Set and clear return zero on success; queries return one or zero for valid IDs.

Deprecate the four unbounded accessors while preserving their signatures and behavior. Migrate bitmap searches and Linux IRQ callers to the bounded accessors without changing search semantics or circular allocation behavior.

Add cross-platform tests for word boundaries, partial-word bitmap sizes, out-of-range IDs, unchanged storage on failure, and zero-size access.

Note that is per OpenAMP/open-amp#707 this is created

Comment thread lib/utilities.h Resolved
Comment thread test/bitmap.c Resolved
Comment thread test/bitmap.c Resolved
Comment thread lib/utilities.h Resolved
@bentheredonethat

Copy link
Copy Markdown
Contributor Author

@arnopo updated per your review

Comment thread lib/system/linux/irq.c Resolved
Comment thread lib/system/linux/irq.c Resolved
@bentheredonethat

Copy link
Copy Markdown
Contributor Author

@arnopo
Updated the series to address both comments. Both bitmap set and clear return values are now checked; on failure, the IRQ lock is released, the error is logged, and the function returns before notifying the IRQ thread.

The Linux IRQ migration is now in a separate commit from the bounded accessor definitions, ahead of the deprecation commit. The build and bitmap tests pass for both static and shared libraries.

@arnopo arnopo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

one minor update requested else looks good to me

Comment thread lib/system/linux/irq.c Resolved
Comment thread lib/utilities.h Outdated
#ifndef __METAL_UTILITIES__H__
#define __METAL_UTILITIES__H__

#include <errno.h>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should be <metal/errno.h>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@iuliana-prodan updated - thank you!

Add bitmap operations with unsigned bit indices and an explicit size.
Set and clear return -EINVAL for invalid indices; boolean queries
return false without accessing storage when out of range.

Migrate bitmap searches to bounded operations while preserving search
and allocation behavior.

Assisted-by: Codex:GPT-6
Signed-off-by: Ben Levinsky <ben.levinsky@amd.com>
Migrate Linux IRQ callers to the bounded bitmap operations. Check set
and clear return values, release the IRQ lock, and log and return on
failure before notifying the IRQ thread.

Assisted-by: Codex:GPT-6
Signed-off-by: Ben Levinsky <ben.levinsky@amd.com>
Mark the four legacy accessors deprecated and document their bounded
replacements. Preserve signatures and behavior, and avoid calling a
deprecated accessor from the legacy clear query.

Assisted-by: Codex:GPT-6
Signed-off-by: Ben Levinsky <ben.levinsky@amd.com>
Cover word boundaries, partial-word sizes, invalid indices, unchanged
storage, and zero-size access. Expect false for invalid boolean
queries and -EINVAL for invalid mutation operations.

Report each failing operation with its bit index, bitmap size,
expected result, and actual result. Restore logging settings after the
test.

Assisted-by: Codex:GPT-6
Signed-off-by: Ben Levinsky <ben.levinsky@amd.com>
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.

3 participants