Skip to content

Commit

Permalink
fix(runtime): incorrect bit manipulation for vmid.
Browse files Browse the repository at this point in the history
Both `vmid_reserve` and `vmid_free` set the wrong bits in the vmids
array due to a missing modulo operation.

Change-Id: Id83419e04ac1891298bd119b28926c689124082b
Signed-off-by: Shale Xiong <[email protected]>
ShaleXIONG authored and soby-mathew committed Jan 4, 2023
1 parent e2eea7c commit f427d8a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion runtime/core/vmid.c
Original file line number Diff line number Diff line change
@@ -32,7 +32,8 @@ bool vmid_reserve(unsigned int vmid)
unsigned int vmid_count;

/* Number of supported VMID values */
vmid_count = is_feat_vmid16_present() ? VMID16_COUNT : VMID8_COUNT;
vmid_count = is_feat_vmid16_present() ? VMID16_COUNT : VMID8_COUNT;

/*
* The input from NS as part of RMI_REALM_CREATE is 'short int' type,
* so this check will not fail on systems with FEAT_VMID16 implemented.
@@ -42,6 +43,7 @@ bool vmid_reserve(unsigned int vmid)
}

offset = vmid / BITS_PER_UL;
vmid %= BITS_PER_UL;

return !atomic_bit_set_acquire_release_64(&vmids[offset], vmid);
}
@@ -60,6 +62,7 @@ void vmid_free(unsigned int vmid)
/* Check the number of supported VMID values */
assert(vmid < vmid_count);
offset = vmid / BITS_PER_UL;
vmid %= BITS_PER_UL;

atomic_bit_clear_release_64(&vmids[offset], vmid);
}

0 comments on commit f427d8a

Please sign in to comment.