Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libsel4vka: Fix size bits in vka_untyped_retype for seL4_CapTableObject #91

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

astevins
Copy link

The size bits for a untyped retype to seL4_CapTableObject are calculated incorrectly when using vka_untyped_retype

The result is that seL4_SlotBits is added twice, causing the UntypedRetype operation to fail with "Insufficient memory" for this simple test:

int test_retype_cap_table_object(env_t env)
{
    int error;
    size_t cspace_size_bits = 17;

    vka_object_t untyped;
    error = vka_alloc_untyped(&env->vka, cspace_size_bits + seL4_SlotBits, &untyped);
    test_error_eq(error, 0);

    cspacepath_t cnode_dest;
    error = vka_cspace_alloc_path(&env->vka, &cnode_dest);
    test_error_eq(error, 0);

    error = vka_untyped_retype(&untyped, seL4_CapTableObject, cspace_size_bits, 1, &cnode_dest);
    test_error_eq(error, 0);
}

A simple solution is to subtract seL4_SlotBits before calling seL4_Untyped_Retype.

@astevins astevins force-pushed the retype_cap_table branch 2 times, most recently from b29e137 to 23c060c Compare July 22, 2024 19:56
Signed-off-by: Arya Stevinson <arya.stevinson@gmail.com>
@astevins
Copy link
Author

Force pushed to adhere to gitlint's commit title length requirement

@lsf37
Copy link
Member

lsf37 commented Jul 22, 2024

I think the question here is more one of what the expected behaviour of this function is -- it currently exports the meaning of size_bits from the seL4 API, which is the size of the object in terms of its native size. I.e. bytes for Untypeds and number of slots for CNodes.

@kent-mcleod do you know what the intention was for this one? For allocators it would make sense to take the size in bytes and translate to object size, but I would assume that there is plenty of other code that assumes the current behaviour (might also be relevant for number of SchedulingContext refills, I guess).

@astevins
Copy link
Author

astevins commented Jul 22, 2024

Potentially replacing the vka_get_object_size call with something like get_sel4_object_size is a better approach

static inline size_t get_sel4_object_size(seL4_Word type, size_t size_bits) {

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.

2 participants