Skip to content

Commit

Permalink
bitmap: use indices
Browse files Browse the repository at this point in the history
  • Loading branch information
asamy committed May 28, 2017
1 parent b895792 commit fa654b6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 4 additions & 4 deletions bitmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
#endif

#define BITMAP_BITS (sizeof(unsigned long) * CHAR_BIT)
#define BIT_MASK(nr) (1UL << ((nr - 1) % BITMAP_BITS))
#define BIT_WORD(nr) (((nr) - 1) / BITMAP_BITS)
#define BIT_MASK(nr) (1UL << ((nr) % BITMAP_BITS))
#define BIT_WORD(nr) ((nr) / BITMAP_BITS)
#define DECLARE_BITMAP(name, bits) \
unsigned long name[DIV_ROUND_UP(bits, BITMAP_BITS)]

Expand Down Expand Up @@ -74,7 +74,7 @@ static inline unsigned long __ffs(unsigned long x)
#ifdef _MSC_VER
unsigned long i;
_BitScanForward(&i, x);
return i + 1;
return i;
#else
return __builtin_ffs(x);
#endif
Expand All @@ -85,7 +85,7 @@ static inline unsigned long __ffz(unsigned long x)
#ifdef _MSC_VER
unsigned long i;
_BitScanForward(&i, ~x);
return i + 1;
return i;
#else
return __builtin_ffs(~x);
#endif
Expand Down
3 changes: 3 additions & 0 deletions vcpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ bool ept_create_ptr(struct ept *ept, int access, u16 *out)
if (eptp == EPT_MAX_EPTP_LIST)
return false;

/* find_first_zero_bit returns a number, not an index. */
eptp--;

pml4 = &EPT4(ept, eptp);
if (!(*pml4 = mm_alloc_page()))
return false;
Expand Down

0 comments on commit fa654b6

Please sign in to comment.