ia64/xen-unstable

changeset 15995:9c567284436e

x86: If e820 map overflows, leak memory in a safe manner.
Signed-off-by: Keir Fraser <keir@xensource.com>
author Keir Fraser <keir@xensource.com>
date Thu Sep 27 16:50:52 2007 +0100 (2007-09-27)
parents 04cc0e22a20a
children 3a799196ff69
files xen/arch/x86/e820.c
line diff
     1.1 --- a/xen/arch/x86/e820.c	Thu Sep 27 16:36:23 2007 +0100
     1.2 +++ b/xen/arch/x86/e820.c	Thu Sep 27 16:50:52 2007 +0100
     1.3 @@ -416,11 +416,9 @@ int __init reserve_e820_ram(struct e820m
     1.4          /* Truncate end. */
     1.5          e820->map[i].size -= e - s;
     1.6      }
     1.7 -    else
     1.8 +    else if ( e820->nr_map < ARRAY_SIZE(e820->map) )
     1.9      {
    1.10          /* Split in two. */
    1.11 -        if ( e820->nr_map >= ARRAY_SIZE(e820->map) )
    1.12 -            return 0;
    1.13          memmove(&e820->map[i+1], &e820->map[i],
    1.14                  (e820->nr_map-i) * sizeof(e820->map[0]));
    1.15          e820->nr_map++;
    1.16 @@ -429,6 +427,21 @@ int __init reserve_e820_ram(struct e820m
    1.17          e820->map[i].addr = e;
    1.18          e820->map[i].size = re - e;
    1.19      }
    1.20 +    else
    1.21 +    {
    1.22 +        /* e820map is at maximum size. We have to leak some space. */
    1.23 +        if ( (s - rs) > (re - e) )
    1.24 +        {
    1.25 +            printk("e820 overflow: leaking RAM %"PRIx64"-%"PRIx64"\n", e, re);
    1.26 +            e820->map[i].size = s - rs;
    1.27 +        }
    1.28 +        else
    1.29 +        {
    1.30 +            printk("e820 overflow: leaking RAM %"PRIx64"-%"PRIx64"\n", rs, s);
    1.31 +            e820->map[i].addr = e;
    1.32 +            e820->map[i].size = re - e;
    1.33 +        }
    1.34 +    }
    1.35  
    1.36      return 1;
    1.37  }