Changeset 69146b93 in mainline for kernel/generic/src/mm


Ignore:
Timestamp:
2012-11-26T19:02:45Z (13 years ago)
Author:
Adam Hraska <adam.hraska+hos@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
04552324
Parents:
5d230a30 (diff), 7462674 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merged mainline,1723.

Location:
kernel/generic/src/mm
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/mm/as.c

    r5d230a30 r69146b93  
    7979#include <syscall/copy.h>
    8080#include <arch/interrupt.h>
     81#include <interrupt.h>
    8182
    8283/**
     
    426427        /*
    427428         * So far, the area does not conflict with other areas.
    428          * Check if it doesn't conflict with kernel address space.
     429         * Check if it is contained in the user address space.
    429430         */
    430431        if (!KERNEL_ADDRESS_SPACE_SHADOWED) {
    431                 return !overlaps(addr, P2SZ(count), KERNEL_ADDRESS_SPACE_START,
    432                     KERNEL_ADDRESS_SPACE_END - KERNEL_ADDRESS_SPACE_START);
     432                return iswithin(USER_ADDRESS_SPACE_START,
     433                    (USER_ADDRESS_SPACE_END - USER_ADDRESS_SPACE_START) + 1,
     434                    addr, P2SZ(count));
    433435        }
    434436       
     
    696698                return ENOENT;
    697699        }
    698        
    699         if (area->backend == &phys_backend) {
    700                 /*
    701                  * Remapping of address space areas associated
    702                  * with memory mapped devices is not supported.
     700
     701        if (!area->backend->is_resizable(area)) {
     702                /*
     703                 * The backend does not support resizing for this area.
    703704                 */
    704705                mutex_unlock(&area->lock);
     
    10571058        }
    10581059       
    1059         if ((!src_area->backend) || (!src_area->backend->share)) {
    1060                 /*
    1061                  * There is no backend or the backend does not
    1062                  * know how to share the area.
     1060        if (!src_area->backend->is_shareable(src_area)) {
     1061                /*
     1062                 * The backend does not permit sharing of this area.
    10631063                 */
    10641064                mutex_unlock(&src_area->lock);
     
    13631363int as_page_fault(uintptr_t page, pf_access_t access, istate_t *istate)
    13641364{
     1365        int rc = AS_PF_FAULT;
     1366
    13651367        if (!THREAD)
    1366                 return AS_PF_FAULT;
     1368                goto page_fault;
    13671369       
    13681370        if (!AS)
    1369                 return AS_PF_FAULT;
     1371                goto page_fault;
    13701372       
    13711373        mutex_lock(&AS->lock);
     
    14231425         * Resort to the backend page fault handler.
    14241426         */
    1425         if (area->backend->page_fault(area, page, access) != AS_PF_OK) {
     1427        rc = area->backend->page_fault(area, page, access);
     1428        if (rc != AS_PF_OK) {
    14261429                page_table_unlock(AS, false);
    14271430                mutex_unlock(&area->lock);
     
    14441447                istate_set_retaddr(istate,
    14451448                    (uintptr_t) &memcpy_to_uspace_failover_address);
     1449        } else if (rc == AS_PF_SILENT) {
     1450                printf("Killing task %" PRIu64 " due to a "
     1451                    "failed late reservation request.\n", TASK->taskid);
     1452                task_kill_self(true);
    14461453        } else {
    1447                 return AS_PF_FAULT;
     1454                fault_if_from_uspace(istate, "Page fault: %p.", (void *) page);
     1455                panic_memtrap(istate, access, page, NULL);
    14481456        }
    14491457       
     
    21322140{
    21332141        uintptr_t virt = base;
    2134         as_area_t *area = as_area_create(AS, flags | AS_AREA_CACHEABLE, size,
     2142        as_area_t *area = as_area_create(AS, flags, size,
    21352143            AS_AREA_ATTR_NONE, &anon_backend, NULL, &virt, bound);
    21362144        if (area == NULL)
  • kernel/generic/src/mm/backend_anon.c

    r5d230a30 r69146b93  
    5959static void anon_destroy(as_area_t *);
    6060
     61static bool anon_is_resizable(as_area_t *);
     62static bool anon_is_shareable(as_area_t *);
     63
    6164static int anon_page_fault(as_area_t *, uintptr_t, pf_access_t);
    6265static void anon_frame_free(as_area_t *, uintptr_t, uintptr_t);
     
    6871        .destroy = anon_destroy,
    6972
     73        .is_resizable = anon_is_resizable,
     74        .is_shareable = anon_is_shareable,
     75
    7076        .page_fault = anon_page_fault,
    7177        .frame_free = anon_frame_free,
     
    7480bool anon_create(as_area_t *area)
    7581{
     82        if (area->flags & AS_AREA_LATE_RESERVE)
     83                return true;
     84
    7685        return reserve_try_alloc(area->pages);
    7786}
     
    7988bool anon_resize(as_area_t *area, size_t new_pages)
    8089{
     90        if (area->flags & AS_AREA_LATE_RESERVE)
     91                return true;
     92
    8193        if (new_pages > area->pages)
    8294                return reserve_try_alloc(new_pages - area->pages);
     
    100112        ASSERT(mutex_locked(&area->as->lock));
    101113        ASSERT(mutex_locked(&area->lock));
     114        ASSERT(!(area->flags & AS_AREA_LATE_RESERVE));
    102115
    103116        /*
     
    139152void anon_destroy(as_area_t *area)
    140153{
     154        if (area->flags & AS_AREA_LATE_RESERVE)
     155                return;
     156
    141157        reserve_free(area->pages);
    142158}
    143159
     160bool anon_is_resizable(as_area_t *area)
     161{
     162        return true;
     163}
     164
     165bool anon_is_shareable(as_area_t *area)
     166{
     167        return !(area->flags & AS_AREA_LATE_RESERVE);
     168}
    144169
    145170/** Service a page fault in the anonymous memory address space area.
     
    225250                 *   the different causes
    226251                 */
     252
     253                if (area->flags & AS_AREA_LATE_RESERVE) {
     254                        /*
     255                         * Reserve the memory for this page now.
     256                         */
     257                        if (!reserve_try_alloc(1))
     258                                return AS_PF_SILENT;
     259                }
     260
    227261                kpage = km_temporary_page_get(&frame, FRAME_NO_RESERVE);
    228262                memsetb((void *) kpage, PAGE_SIZE, 0);
     
    255289        ASSERT(mutex_locked(&area->lock));
    256290
    257         frame_free_noreserve(frame);
     291        if (area->flags & AS_AREA_LATE_RESERVE) {
     292                /*
     293                 * In case of the late reserve areas, physical memory will not
     294                 * be unreserved when the area is destroyed so we need to use
     295                 * the normal unreserving frame_free().
     296                 */
     297                frame_free(frame);
     298        } else {
     299                /*
     300                 * The reserve will be given back when the area is destroyed or
     301                 * resized, so use the frame_free_noreserve() which does not
     302                 * manipulate the reserve or it would be given back twice.
     303                 */
     304                frame_free_noreserve(frame);
     305        }
    258306}
    259307
  • kernel/generic/src/mm/backend_elf.c

    r5d230a30 r69146b93  
    5858static void elf_destroy(as_area_t *);
    5959
     60static bool elf_is_resizable(as_area_t *);
     61static bool elf_is_shareable(as_area_t *);
     62
    6063static int elf_page_fault(as_area_t *, uintptr_t, pf_access_t);
    6164static void elf_frame_free(as_area_t *, uintptr_t, uintptr_t);
     
    6669        .share = elf_share,
    6770        .destroy = elf_destroy,
     71
     72        .is_resizable = elf_is_resizable,
     73        .is_shareable = elf_is_shareable,
    6874
    6975        .page_fault = elf_page_fault,
     
    213219}
    214220
     221bool elf_is_resizable(as_area_t *area)
     222{
     223        return true;
     224}
     225
     226bool elf_is_shareable(as_area_t *area)
     227{
     228        return true;
     229}
     230
     231
    215232/** Service a page fault in the ELF backend address space area.
    216233 *
  • kernel/generic/src/mm/backend_phys.c

    r5d230a30 r69146b93  
    5252static void phys_destroy(as_area_t *);
    5353
     54static bool phys_is_resizable(as_area_t *);
     55static bool phys_is_shareable(as_area_t *);
     56
     57
    5458static int phys_page_fault(as_area_t *, uintptr_t, pf_access_t);
    5559
     
    5963        .share = phys_share,
    6064        .destroy = phys_destroy,
     65
     66        .is_resizable = phys_is_resizable,
     67        .is_shareable = phys_is_shareable,
    6168
    6269        .page_fault = phys_page_fault,
     
    8794        /* Nothing to do. */
    8895}
     96
     97bool phys_is_resizable(as_area_t *area)
     98{
     99        return false;
     100}
     101
     102bool phys_is_shareable(as_area_t *area)
     103{
     104        return true;
     105}
     106
    89107
    90108/** Service a page fault in the address space area backed by physical memory.
  • kernel/generic/src/mm/km.c

    r5d230a30 r69146b93  
    234234 * @param[inout] framep Pointer to a variable which will receive the physical
    235235 *                      address of the allocated frame.
    236  * @param[in] flags     Frame allocation flags. FRAME_NONE or FRAME_NO_RESERVE.
     236 * @param[in] flags     Frame allocation flags. FRAME_NONE, FRAME_NO_RESERVE
     237 *                      and FRAME_ATOMIC bits are allowed.
    237238 * @return              Virtual address of the allocated frame.
    238239 */
     
    244245        ASSERT(THREAD);
    245246        ASSERT(framep);
    246         ASSERT(!(flags & ~FRAME_NO_RESERVE));
     247        ASSERT(!(flags & ~(FRAME_NO_RESERVE | FRAME_ATOMIC)));
    247248
    248249        /*
     
    256257                ASSERT(page);   // FIXME
    257258        } else {
    258                 frame = (uintptr_t) frame_alloc_noreserve(ONE_FRAME,
    259                     FRAME_LOWMEM);
     259                frame = (uintptr_t) frame_alloc(ONE_FRAME,
     260                    FRAME_LOWMEM | flags);
     261                if (!frame)
     262                        return (uintptr_t) NULL;
    260263                page = PA2KA(frame);
    261264        }
Note: See TracChangeset for help on using the changeset viewer.