From: Matthew Dillon Date: Tue, 21 Oct 2014 06:08:50 +0000 (-0700) Subject: kernel - Fix int/long truncation problem in rman_reserve_resource() X-Git-Tag: v4.1.0~29 X-Git-Url: https://gitweb.dragonflybsd.org/~tuxillo/dragonfly.git/commitdiff_plain/fc4394d140be3e7dba4315d0af40b2efa433164e kernel - Fix int/long truncation problem in rman_reserve_resource() * Use ulmin/ulmax instead of min/max in three places, fixing a 32-bit truncation problem when setting up memory resources that caused our 48-core opteron to panic. * An earlier commit adjusting count values to be more correct revealed the bug. * Fixes booting the kernel on our 48-core opteron w/128G of ram. --- diff --git a/sys/kern/subr_rman.c b/sys/kern/subr_rman.c index 75705440f7..386b654226 100644 --- a/sys/kern/subr_rman.c +++ b/sys/kern/subr_rman.c @@ -227,7 +227,7 @@ rman_reserve_resource(struct rman *rm, u_long start, u_long end, u_long count, rstart = ulmax(s->r_start, start); rstart = (rstart + ((1ul << RF_ALIGNMENT(flags))) - 1) & ~((1ul << RF_ALIGNMENT(flags)) - 1); - rend = min(s->r_end, max(start + count - 1, end)); + rend = ulmin(s->r_end, ulmax(start + count - 1, end)); DPRINTF(("truncated region: [%#lx, %#lx]; size %#lx (requested %#lx)\n", rstart, rend, (rend - rstart + 1), count)); @@ -326,8 +326,8 @@ rman_reserve_resource(struct rman *rm, u_long start, u_long end, u_long count, break; if ((s->r_flags & flags) != flags) continue; - rstart = max(s->r_start, start); - rend = min(s->r_end, max(start + count, end)); + rstart = ulmax(s->r_start, start); + rend = ulmin(s->r_end, ulmax(start + count, end)); if (s->r_start >= start && s->r_end <= end && (s->r_end - s->r_start + 1) == count) { rv = kmalloc(sizeof *rv, M_RMAN, M_NOWAIT | M_ZERO); diff --git a/sys/platform/pc64/x86_64/nexus.c b/sys/platform/pc64/x86_64/nexus.c index 39626b3244..058959db20 100644 --- a/sys/platform/pc64/x86_64/nexus.c +++ b/sys/platform/pc64/x86_64/nexus.c @@ -689,9 +689,13 @@ ram_attach(device_t dev) __func__, rid, error); res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, 0); - if (res == NULL) - panic("%s: resource %d failed to attach", - __func__, rid); + if (res == NULL) { + panic("%s: resource %d failed to " + "attach 0x%016jx/%jd", + __func__, rid, + (intmax_t)smap->base, + (intmax_t)smap->length); + } rid++; } return (0);