Skip to content

Commit d185978

Browse files
malejo97DavidMCerdeira
authored andcommitted
fix(core): pCPU ID to vCPU ID translation
Signed-off-by: Manuel Rodríguez <manuel.cederog@gmail.com>
1 parent 02f612a commit d185978

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

src/core/inc/vm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ static inline cpuid_t vm_translate_to_pcpuid(struct vm* vm, vcpuid_t vcpuid)
150150
static inline vcpuid_t vm_translate_to_vcpuid(struct vm* vm, cpuid_t pcpuid)
151151
{
152152
if (vm->cpus & (1UL << pcpuid)) {
153-
return (cpuid_t)bit_count(vm->cpus & BIT_MASK(0, pcpuid));
153+
return (cpuid_t)bit_count(vm->cpus & ((1UL << pcpuid) - 1UL));
154154
} else {
155155
return INVALID_CPUID;
156156
}

src/lib/inc/bit.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
#include <bao.h>
1010

1111
/**
12+
* The bit mask macros support LEN within [1, BITS_PER_LONG]. LEN == 0 is not supported.
1213
* The extra shift is because both arm and riscv logical shift instructions support a maximum of
13-
* machine word length minus one bit shits. This covers the corner case of runtime full machine
14+
* machine word length minus one bit shifts. This covers the corner case of runtime full machine
1415
* word length masks with the cost of an extra shift instruction. For static masks, there should be
1516
* no extra costs.
1617
*/

0 commit comments

Comments
 (0)