From f427d8ae5456f1bbff7b1a5a1c9aa02b9ba8c7d3 Mon Sep 17 00:00:00 2001 From: Shale Xiong Date: Fri, 16 Dec 2022 12:07:32 +0000 Subject: [PATCH] fix(runtime): incorrect bit manipulation for vmid. 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 --- runtime/core/vmid.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/runtime/core/vmid.c b/runtime/core/vmid.c index 64c30b32..e2116131 100644 --- a/runtime/core/vmid.c +++ b/runtime/core/vmid.c @@ -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); }