From e956a1ec841f76873b0d4264392a95705f127888 Mon Sep 17 00:00:00 2001 From: nwhitehorn Date: Wed, 8 Sep 2010 16:58:06 +0000 Subject: Fix a typo in the original import of this code from NetBSD that caused the wrong element of the VSID bitmap array to be examined after a collision, leading to reallocation of in-use VSIDs under some circumstances, with attendant memory corruption. Also add an assert to check for this kind of problem in the future. MFC after: 4 days --- sys/powerpc/aim/mmu_oea.c | 2 +- sys/powerpc/aim/mmu_oea64.c | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'sys') diff --git a/sys/powerpc/aim/mmu_oea.c b/sys/powerpc/aim/mmu_oea.c index d3a2459..2ade00f 100644 --- a/sys/powerpc/aim/mmu_oea.c +++ b/sys/powerpc/aim/mmu_oea.c @@ -1618,7 +1618,7 @@ moea_pinit(mmu_t mmu, pmap_t pmap) entropy = (moea_vsidcontext >> 20); continue; } - i = ffs(~moea_vsid_bitmap[i]) - 1; + i = ffs(~moea_vsid_bitmap[n]) - 1; mask = 1 << i; hash &= 0xfffff & ~(VSID_NBPW - 1); hash |= i; diff --git a/sys/powerpc/aim/mmu_oea64.c b/sys/powerpc/aim/mmu_oea64.c index c1b6f2c..8cf8349 100644 --- a/sys/powerpc/aim/mmu_oea64.c +++ b/sys/powerpc/aim/mmu_oea64.c @@ -2080,11 +2080,13 @@ moea64_get_unique_vsid(void) { entropy = (moea64_vsidcontext >> 20); continue; } - i = ffs(~moea64_vsid_bitmap[i]) - 1; + i = ffs(~moea64_vsid_bitmap[n]) - 1; mask = 1 << i; hash &= VSID_HASHMASK & ~(VSID_NBPW - 1); hash |= i; } + KASSERT(!(moea64_vsid_bitmap[n] & mask), + ("Allocating in-use VSID %#x\n", hash)); moea64_vsid_bitmap[n] |= mask; mtx_unlock(&moea64_slb_mutex); return (hash); -- cgit v1.1