kernel - Fix int/long truncation problem in rman_reserve_resource() master
authorMatthew Dillon <dillon@apollo.backplane.com>
Tue, 21 Oct 2014 06:08:50 +0000 (23:08 -0700)
committerMatthew Dillon <dillon@apollo.backplane.com>
Tue, 21 Oct 2014 06:08:50 +0000 (23:08 -0700)
* 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.

sys/kern/subr_rman.c
sys/platform/pc64/x86_64/nexus.c

index 7570544..386b654 100644 (file)
@@ -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);
index 39626b3..058959d 100644 (file)
@@ -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);