Changeset 482f968 in mainline


Ignore:
Timestamp:
2018-10-31T16:48:51Z (6 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
91a8f83, bab75df6
Parents:
37781819
Message:

Make FRAME_HIGHMEM fall back to low memory on failure.

Which is what existing users of it are doing, and there is no reason
not to as far as I can see.

Also make sure calls to frame_alloc all have either FRAME_LOWMEM or
FRAME_HIGHMEM explicitly set, as appropriate.

Location:
kernel
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/amd64/src/vreg.c

    r37781819 r482f968  
    6262        frame = frame_alloc(1, FRAME_ATOMIC | FRAME_HIGHMEM, 0);
    6363        if (!frame)
    64                 frame = frame_alloc(1, FRAME_ATOMIC | FRAME_LOWMEM, 0);
    65         if (!frame)
    6664                panic("Cannot allocate VREG frame.");
    6765
  • kernel/arch/arm32/src/mm/page.c

    r37781819 r482f968  
    6969#ifdef HIGH_EXCEPTION_VECTORS
    7070        /* Create mapping for exception table at high offset */
    71         uintptr_t ev_frame = frame_alloc(1, FRAME_NONE, 0);
     71        uintptr_t ev_frame = frame_alloc(1, FRAME_HIGHMEM, 0);
    7272        page_mapping_insert(AS_KERNEL, EXC_BASE_ADDRESS, ev_frame, flags);
    7373#else
  • kernel/arch/arm32/src/ras.c

    r37781819 r482f968  
    5151void ras_init(void)
    5252{
    53         uintptr_t frame =
    54             frame_alloc(1, FRAME_ATOMIC | FRAME_HIGHMEM, 0);
    55         if (!frame)
    56                 frame = frame_alloc(1, FRAME_LOWMEM, 0);
     53        uintptr_t frame = frame_alloc(1, FRAME_HIGHMEM, 0);
    5754
    5855        ras_page = (uintptr_t *) km_map(frame, PAGE_SIZE, PAGE_SIZE,
  • kernel/arch/ia32/src/vreg.c

    r37781819 r482f968  
    6363        frame = frame_alloc(1, FRAME_ATOMIC | FRAME_HIGHMEM, 0);
    6464        if (!frame)
    65                 frame = frame_alloc(1, FRAME_ATOMIC | FRAME_LOWMEM, 0);
    66         if (!frame)
    6765                panic("Cannot allocate VREG frame.");
    6866
  • kernel/arch/ia64/src/mm/vhpt.c

    r37781819 r482f968  
    4444{
    4545        uintptr_t vhpt_frame =
    46             frame_alloc(SIZE2FRAMES(VHPT_SIZE), FRAME_ATOMIC, 0);
     46            frame_alloc(SIZE2FRAMES(VHPT_SIZE), FRAME_LOWMEM | FRAME_ATOMIC, 0);
    4747        if (!vhpt_frame)
    4848                panic("Kernel configured with VHPT but no memory for table.");
  • kernel/arch/sparc64/src/mm/sun4u/as.c

    r37781819 r482f968  
    6363{
    6464#ifdef CONFIG_TSB
    65         uintptr_t tsb_base = frame_alloc(TSB_FRAMES, flags, TSB_SIZE - 1);
     65        uintptr_t tsb_base = frame_alloc(TSB_FRAMES, FRAME_LOWMEM | flags,
     66            TSB_SIZE - 1);
    6667        if (!tsb_base)
    6768                return ENOMEM;
  • kernel/arch/sparc64/src/mm/sun4v/as.c

    r37781819 r482f968  
    6666{
    6767#ifdef CONFIG_TSB
    68         uintptr_t tsb_base = frame_alloc(TSB_FRAMES, flags, TSB_SIZE - 1);
     68        uintptr_t tsb_base = frame_alloc(TSB_FRAMES, FRAME_LOWMEM | flags,
     69            TSB_SIZE - 1);
    6970        if (!tsb_base)
    7071                return ENOMEM;
  • kernel/generic/include/mm/frame.h

    r37781819 r482f968  
    5959/** Allocate a frame which can be identity-mapped. */
    6060#define FRAME_LOWMEM      0x08
    61 /** Allocate a frame which cannot be identity-mapped. */
     61/**
     62 * Allocate a frame outside the identity-mapped region if possible.
     63 * Fall back to low memory if that fails.
     64 */
    6265#define FRAME_HIGHMEM     0x10
     66
     67// NOTE: If neither FRAME_LOWMEM nor FRAME_HIGHMEM is set, FRAME_LOWMEM is
     68//       assumed as a safe default, and a runtime warning may be issued.
     69//       If both are set, FRAME_LOWMEM takes priority.
    6370
    6471typedef uint8_t zone_flags_t;
     
    7885/** Mask of zone bits that must be matched exactly. */
    7986#define ZONE_EF_MASK  0x07
    80 
    81 #define FRAME_TO_ZONE_FLAGS(ff) \
    82         ((((ff) & FRAME_LOWMEM) ? ZONE_LOWMEM : \
    83             (((ff) & FRAME_HIGHMEM) ? ZONE_HIGHMEM : \
    84             ZONE_LOWMEM /* | ZONE_HIGHMEM */)) | \
    85             ZONE_AVAILABLE)
    8687
    8788#define ZONE_FLAGS_MATCH(zf, f) \
  • kernel/generic/src/ddi/ddi.c

    r37781819 r482f968  
    385385                return EINVAL;
    386386
     387        // FIXME: probably need to ensure that the memory is suitable for DMA
    387388        *phys = frame_alloc(frames, FRAME_ATOMIC, constraint);
    388389        if (*phys == 0)
  • kernel/generic/src/mm/frame.c

    r37781819 r482f968  
    815815}
    816816
     817static size_t try_find_zone(size_t count, bool lowmem,
     818    pfn_t frame_constraint, size_t hint)
     819{
     820        if (!lowmem) {
     821                size_t znum = find_free_zone(count,
     822                    ZONE_HIGHMEM | ZONE_AVAILABLE, frame_constraint, hint);
     823                if (znum != (size_t) -1)
     824                        return znum;
     825        }
     826
     827        return find_free_zone(count, ZONE_LOWMEM | ZONE_AVAILABLE,
     828            frame_constraint, hint);
     829}
     830
    817831/** Allocate frames of physical memory.
    818832 *
     
    843857        irq_spinlock_lock(&zones.lock, true);
    844858
     859        // TODO: Print diagnostic if neither is explicitly specified.
     860        bool lowmem = (flags & FRAME_LOWMEM) || !(flags & FRAME_HIGHMEM);
     861
    845862        /*
    846863         * First, find suitable frame zone.
    847864         */
    848         size_t znum = find_free_zone(count, FRAME_TO_ZONE_FLAGS(flags),
    849             frame_constraint, hint);
     865        size_t znum = try_find_zone(count, lowmem, frame_constraint, hint);
    850866
    851867        /*
     
    859875
    860876                if (freed > 0)
    861                         znum = find_free_zone(count, FRAME_TO_ZONE_FLAGS(flags),
     877                        znum = try_find_zone(count, lowmem,
    862878                            frame_constraint, hint);
    863879
     
    868884
    869885                        if (freed > 0)
    870                                 znum = find_free_zone(count, FRAME_TO_ZONE_FLAGS(flags),
     886                                znum = try_find_zone(count, lowmem,
    871887                                    frame_constraint, hint);
    872888                }
  • kernel/generic/src/mm/km.c

    r37781819 r482f968  
    121121                return base;
    122122        else
    123                 return (uintptr_t) NULL;
     123                panic("Kernel ran out of virtual address space.");
    124124}
    125125
     
    256256        uintptr_t frame;
    257257
    258         frame = frame_alloc(1, FRAME_HIGHMEM | FRAME_ATOMIC | flags, 0);
    259         if (frame) {
     258        frame = frame_alloc(1, FRAME_HIGHMEM | flags, 0);
     259        if (frame >= config.identity_size) {
    260260                page = km_map(frame, PAGE_SIZE, PAGE_SIZE,
    261261                    PAGE_READ | PAGE_WRITE | PAGE_CACHEABLE);
    262                 if (!page) {
    263                         frame_free(frame, 1);
    264                         goto lowmem;
    265                 }
    266262        } else {
    267         lowmem:
    268                 frame = frame_alloc(1, FRAME_LOWMEM | flags, 0);
    269                 if (!frame)
    270                         return (uintptr_t) NULL;
    271 
    272263                page = PA2KA(frame);
    273264        }
  • kernel/generic/src/mm/slab.c

    r37781819 r482f968  
    188188
    189189        uintptr_t data_phys =
    190             frame_alloc_generic(cache->frames, flags, 0, &zone);
     190            frame_alloc_generic(cache->frames, FRAME_LOWMEM | flags, 0, &zone);
    191191        if (!data_phys)
    192192                return NULL;
  • kernel/generic/src/time/clock.c

    r37781819 r482f968  
    8181void clock_counter_init(void)
    8282{
    83         uintptr_t faddr = frame_alloc(1, FRAME_ATOMIC, 0);
     83        uintptr_t faddr = frame_alloc(1, FRAME_LOWMEM | FRAME_ATOMIC, 0);
    8484        if (faddr == 0)
    8585                panic("Cannot allocate page for clock.");
  • kernel/test/mm/mapping1.c

    r37781819 r482f968  
    4141const char *test_mapping1(void)
    4242{
    43         uintptr_t frame = frame_alloc(1, FRAME_NONE, 0);
     43        uintptr_t frame = frame_alloc(1, FRAME_HIGHMEM, 0);
    4444
    4545        uintptr_t page0 = km_map(frame, FRAME_SIZE, FRAME_SIZE,
Note: See TracChangeset for help on using the changeset viewer.