Changeset a35b458 in mainline for kernel/generic/src/mm


Ignore:
Timestamp:
2018-03-02T20:10:49Z (7 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:
f1380b7
Parents:
3061bc1
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
Message:

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

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

Legend:

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

    r3061bc1 ra35b458  
    114114{
    115115        as_t *as = (as_t *) obj;
    116        
     116
    117117        link_initialize(&as->inactive_as_with_asid_link);
    118118        mutex_initialize(&as->lock, MUTEX_PASSIVE);
    119        
     119
    120120        return as_constructor_arch(as, flags);
    121121}
     
    130130{
    131131        as_arch_init();
    132        
     132
    133133        as_cache = slab_cache_create("as_t", sizeof(as_t), 0,
    134134            as_constructor, as_destructor, SLAB_CACHE_MAGDEFERRED);
    135        
     135
    136136        AS_KERNEL = as_create(FLAG_AS_KERNEL);
    137137        if (!AS_KERNEL)
    138138                panic("Cannot create kernel address space.");
    139        
     139
    140140        /*
    141141         * Make sure the kernel address space
     
    155155        as_t *as = (as_t *) slab_alloc(as_cache, 0);
    156156        (void) as_create_arch(as, 0);
    157        
     157
    158158        btree_create(&as->as_area_btree);
    159        
     159
    160160        if (flags & FLAG_AS_KERNEL)
    161161                as->asid = ASID_KERNEL;
    162162        else
    163163                as->asid = ASID_INVALID;
    164        
     164
    165165        atomic_set(&as->refcount, 0);
    166166        as->cpu_refcount = 0;
    167        
     167
    168168#ifdef AS_PAGE_TABLE
    169169        as->genarch.page_table = page_table_create(flags);
     
    171171        page_table_create(flags);
    172172#endif
    173        
     173
    174174        return as;
    175175}
     
    188188{
    189189        DEADLOCK_PROBE_INIT(p_asidlock);
    190        
     190
    191191        assert(as != AS);
    192192        assert(atomic_get(&as->refcount) == 0);
    193        
     193
    194194        /*
    195195         * Since there is no reference to this address space, it is safe not to
    196196         * lock its mutex.
    197197         */
    198        
     198
    199199        /*
    200200         * We need to avoid deadlock between TLB shootdown and asidlock.
     
    206206        preemption_disable();
    207207        ipl_t ipl = interrupts_read();
    208        
     208
    209209retry:
    210210        interrupts_disable();
     
    214214                goto retry;
    215215        }
    216        
     216
    217217        /* Interrupts disabled, enable preemption */
    218218        preemption_enable();
    219        
     219
    220220        if ((as->asid != ASID_INVALID) && (as != AS_KERNEL)) {
    221221                if (as->cpu_refcount == 0)
    222222                        list_remove(&as->inactive_as_with_asid_link);
    223                
     223
    224224                asid_put(as->asid);
    225225        }
    226        
     226
    227227        spinlock_unlock(&asidlock);
    228228        interrupts_restore(ipl);
    229        
    230        
     229
     230
    231231        /*
    232232         * Destroy address space areas of the address space.
     
    237237        while (cond) {
    238238                assert(!list_empty(&as->as_area_btree.leaf_list));
    239                
     239
    240240                btree_node_t *node =
    241241                    list_get_instance(list_first(&as->as_area_btree.leaf_list),
    242242                    btree_node_t, leaf_link);
    243                
     243
    244244                if ((cond = node->keys))
    245245                        as_area_destroy(as, node->key[0]);
    246246        }
    247        
     247
    248248        btree_destroy(&as->as_area_btree);
    249        
     249
    250250#ifdef AS_PAGE_TABLE
    251251        page_table_destroy(as->genarch.page_table);
     
    253253        page_table_destroy(NULL);
    254254#endif
    255        
     255
    256256        slab_free(as_cache, as);
    257257}
     
    307307        if (overflows_into_positive(addr, P2SZ(count)))
    308308                return false;
    309        
     309
    310310        /*
    311311         * We don't want any area to have conflicts with NULL page.
     
    328328                        return false;
    329329        }
    330        
     330
    331331        /* First, check the two border cases. */
    332332        btree_node_t *node =
     
    334334        if (node) {
    335335                area = (as_area_t *) node->value[node->keys - 1];
    336                
     336
    337337                if (area != avoid) {
    338338                        mutex_lock(&area->lock);
     
    346346                        int const gp = (guarded ||
    347347                            (area->flags & AS_AREA_GUARD)) ? 1 : 0;
    348                        
     348
    349349                        /*
    350350                         * The area comes from the left neighbour node, which
     
    358358                                return false;
    359359                        }
    360                        
     360
    361361                        mutex_unlock(&area->lock);
    362362                }
    363363        }
    364        
     364
    365365        node = btree_leaf_node_right_neighbour(&as->as_area_btree, leaf);
    366366        if (node) {
    367367                area = (as_area_t *) node->value[0];
    368                
     368
    369369                if (area != avoid) {
    370370                        int gp;
     
    382382                                gp--;
    383383                        }
    384                        
     384
    385385                        if (overlaps(addr, P2SZ(count + gp), area->base,
    386386                            P2SZ(area->pages))) {
     
    388388                                return false;
    389389                        }
    390                        
     390
    391391                        mutex_unlock(&area->lock);
    392392                }
    393393        }
    394        
     394
    395395        /* Second, check the leaf node. */
    396396        btree_key_t i;
     
    399399                int agp;
    400400                int gp;
    401                
     401
    402402                if (area == avoid)
    403403                        continue;
    404                
     404
    405405                mutex_lock(&area->lock);
    406406
     
    421421                        return false;
    422422                }
    423                
     423
    424424                mutex_unlock(&area->lock);
    425425        }
    426        
     426
    427427        /*
    428428         * So far, the area does not conflict with other areas.
     
    434434                    addr, P2SZ(count));
    435435        }
    436        
     436
    437437        return true;
    438438}
     
    456456{
    457457        assert(mutex_locked(&as->lock));
    458        
     458
    459459        if (size == 0)
    460460                return (uintptr_t) -1;
    461        
     461
    462462        /*
    463463         * Make sure we allocate from page-aligned
     
    465465         * each step.
    466466         */
    467        
     467
    468468        size_t pages = SIZE2FRAMES(size);
    469        
     469
    470470        /*
    471471         * Find the lowest unmapped address aligned on the size
    472472         * boundary, not smaller than bound and of the required size.
    473473         */
    474        
     474
    475475        /* First check the bound address itself */
    476476        uintptr_t addr = ALIGN_UP(bound, PAGE_SIZE);
     
    486486                        return addr;
    487487        }
    488        
     488
    489489        /* Eventually check the addresses behind each area */
    490490        list_foreach(as->as_area_btree.leaf_list, leaf_link, btree_node_t, node) {
    491                
     491
    492492                for (btree_key_t i = 0; i < node->keys; i++) {
    493493                        as_area_t *area = (as_area_t *) node->value[i];
    494                        
     494
    495495                        mutex_lock(&area->lock);
    496                        
     496
    497497                        addr =
    498498                            ALIGN_UP(area->base + P2SZ(area->pages), PAGE_SIZE);
     
    508508                            ((addr >= bound) && (addr >= area->base) &&
    509509                            (check_area_conflicts(as, addr, pages, guarded, area)));
    510                        
     510
    511511                        mutex_unlock(&area->lock);
    512                        
     512
    513513                        if (avail)
    514514                                return addr;
    515515                }
    516516        }
    517        
     517
    518518        /* No suitable address space area found */
    519519        return (uintptr_t) -1;
     
    530530{
    531531        bool dealloc = false;
    532        
     532
    533533        mutex_lock(&sh_info->lock);
    534534        assert(sh_info->refcount);
    535        
     535
    536536        if (--sh_info->refcount == 0) {
    537537                dealloc = true;
    538                
     538
    539539                /*
    540540                 * Now walk carefully the pagemap B+tree and free/remove
     
    544544                    btree_node_t, node) {
    545545                        btree_key_t i;
    546                        
     546
    547547                        for (i = 0; i < node->keys; i++)
    548548                                frame_free((uintptr_t) node->value[i], 1);
    549549                }
    550                
     550
    551551        }
    552552        mutex_unlock(&sh_info->lock);
    553        
     553
    554554        if (dealloc) {
    555555                if (sh_info->backend && sh_info->backend->destroy_shared_data) {
     
    588588        if ((*base != (uintptr_t) AS_AREA_ANY) && !IS_ALIGNED(*base, PAGE_SIZE))
    589589                return NULL;
    590        
     590
    591591        if (size == 0)
    592592                return NULL;
    593593
    594594        size_t pages = SIZE2FRAMES(size);
    595        
     595
    596596        /* Writeable executable areas are not supported. */
    597597        if ((flags & AS_AREA_EXEC) && (flags & AS_AREA_WRITE))
     
    599599
    600600        bool const guarded = flags & AS_AREA_GUARD;
    601        
     601
    602602        mutex_lock(&as->lock);
    603        
     603
    604604        if (*base == (uintptr_t) AS_AREA_ANY) {
    605605                *base = as_get_unmapped_area(as, bound, size, guarded);
     
    619619                return NULL;
    620620        }
    621        
     621
    622622        as_area_t *area = (as_area_t *) malloc(sizeof(as_area_t), 0);
    623        
     623
    624624        mutex_initialize(&area->lock, MUTEX_PASSIVE);
    625        
     625
    626626        area->as = as;
    627627        area->flags = flags;
     
    632632        area->backend = backend;
    633633        area->sh_info = NULL;
    634        
     634
    635635        if (backend_data)
    636636                area->backend_data = *backend_data;
     
    655655
    656656                area->sh_info = si;
    657        
     657
    658658                if (area->backend && area->backend->create_shared_data) {
    659659                        if (!area->backend->create_shared_data(area)) {
     
    679679        btree_insert(&as->as_area_btree, *base, (void *) area,
    680680            NULL);
    681        
     681
    682682        mutex_unlock(&as->lock);
    683        
     683
    684684        return area;
    685685}
     
    697697{
    698698        assert(mutex_locked(&as->lock));
    699        
     699
    700700        btree_node_t *leaf;
    701701        as_area_t *area = (as_area_t *) btree_search(&as->as_area_btree, va,
     
    706706                return area;
    707707        }
    708        
     708
    709709        /*
    710710         * Search the leaf node and the rightmost record of its left neighbour
     
    712712         * space area found there.
    713713         */
    714        
     714
    715715        /* First, search the leaf node itself. */
    716716        btree_key_t i;
    717        
     717
    718718        for (i = 0; i < leaf->keys; i++) {
    719719                area = (as_area_t *) leaf->value[i];
    720                
     720
    721721                mutex_lock(&area->lock);
    722722
     
    724724                    (va <= area->base + (P2SZ(area->pages) - 1)))
    725725                        return area;
    726                
     726
    727727                mutex_unlock(&area->lock);
    728728        }
    729        
     729
    730730        /*
    731731         * Second, locate the left neighbour and test its last record.
     
    736736        if (lnode) {
    737737                area = (as_area_t *) lnode->value[lnode->keys - 1];
    738                
     738
    739739                mutex_lock(&area->lock);
    740                
     740
    741741                if (va <= area->base + (P2SZ(area->pages) - 1))
    742742                        return area;
    743                
     743
    744744                mutex_unlock(&area->lock);
    745745        }
    746        
     746
    747747        return NULL;
    748748}
     
    766766
    767767        mutex_lock(&as->lock);
    768        
     768
    769769        /*
    770770         * Locate the area.
     
    784784                return ENOTSUP;
    785785        }
    786        
     786
    787787        mutex_lock(&area->sh_info->lock);
    788788        if (area->sh_info->shared) {
     
    797797        }
    798798        mutex_unlock(&area->sh_info->lock);
    799        
     799
    800800        size_t pages = SIZE2FRAMES((address - area->base) + size);
    801801        if (!pages) {
     
    807807                return EPERM;
    808808        }
    809        
     809
    810810        if (pages < area->pages) {
    811811                uintptr_t start_free = area->base + P2SZ(pages);
    812                
     812
    813813                /*
    814814                 * Shrinking the area.
    815815                 * No need to check for overlaps.
    816816                 */
    817                
     817
    818818                page_table_lock(as, false);
    819                
     819
    820820                /*
    821821                 * Remove frames belonging to used space starting from
     
    828828                while (cond) {
    829829                        assert(!list_empty(&area->used_space.leaf_list));
    830                        
     830
    831831                        btree_node_t *node =
    832832                            list_get_instance(list_last(&area->used_space.leaf_list),
    833833                            btree_node_t, leaf_link);
    834                        
     834
    835835                        if ((cond = (node->keys != 0))) {
    836836                                uintptr_t ptr = node->key[node->keys - 1];
     
    838838                                    (size_t) node->value[node->keys - 1];
    839839                                size_t i = 0;
    840                                
     840
    841841                                if (overlaps(ptr, P2SZ(node_size), area->base,
    842842                                    P2SZ(pages))) {
    843                                        
     843
    844844                                        if (ptr + P2SZ(node_size) <= start_free) {
    845845                                                /*
     
    850850                                                break;
    851851                                        }
    852                                        
     852
    853853                                        /*
    854854                                         * Part of the interval corresponding
     
    856856                                         * address space area.
    857857                                         */
    858                                        
     858
    859859                                        /* We are almost done */
    860860                                        cond = false;
     
    871871                                                panic("Cannot remove used space.");
    872872                                }
    873                                
     873
    874874                                /*
    875875                                 * Start TLB shootdown sequence.
     
    887887                                    as->asid, area->base + P2SZ(pages),
    888888                                    area->pages - pages);
    889                
     889
    890890                                for (; i < node_size; i++) {
    891891                                        pte_t pte;
    892892                                        bool found = page_mapping_find(as,
    893893                                            ptr + P2SZ(i), false, &pte);
    894                                        
     894
    895895                                        assert(found);
    896896                                        assert(PTE_VALID(&pte));
    897897                                        assert(PTE_PRESENT(&pte));
    898                                        
     898
    899899                                        if ((area->backend) &&
    900900                                            (area->backend->frame_free)) {
     
    903903                                                    PTE_GET_FRAME(&pte));
    904904                                        }
    905                                        
     905
    906906                                        page_mapping_remove(as, ptr + P2SZ(i));
    907907                                }
    908                
     908
    909909                                /*
    910910                                 * Finish TLB shootdown sequence.
    911911                                 */
    912                
     912
    913913                                tlb_invalidate_pages(as->asid,
    914914                                    area->base + P2SZ(pages),
    915915                                    area->pages - pages);
    916                
     916
    917917                                /*
    918918                                 * Invalidate software translation caches
     
    944944                }
    945945        }
    946        
     946
    947947        if (area->backend && area->backend->resize) {
    948948                if (!area->backend->resize(area, pages)) {
     
    952952                }
    953953        }
    954        
     954
    955955        area->pages = pages;
    956        
     956
    957957        mutex_unlock(&area->lock);
    958958        mutex_unlock(&as->lock);
    959        
     959
    960960        return 0;
    961961}
     
    972972{
    973973        mutex_lock(&as->lock);
    974        
     974
    975975        as_area_t *area = find_area_and_lock(as, address);
    976976        if (!area) {
     
    981981        if (area->backend && area->backend->destroy)
    982982                area->backend->destroy(area);
    983        
     983
    984984        uintptr_t base = area->base;
    985        
     985
    986986        page_table_lock(as, false);
    987        
     987
    988988        /*
    989989         * Start TLB shootdown sequence.
     
    991991        ipl_t ipl = tlb_shootdown_start(TLB_INVL_PAGES, as->asid, area->base,
    992992            area->pages);
    993        
     993
    994994        /*
    995995         * Visit only the pages mapped by used_space B+tree.
     
    998998            node) {
    999999                btree_key_t i;
    1000                
     1000
    10011001                for (i = 0; i < node->keys; i++) {
    10021002                        uintptr_t ptr = node->key[i];
    10031003                        size_t size;
    1004                        
     1004
    10051005                        for (size = 0; size < (size_t) node->value[i]; size++) {
    10061006                                pte_t pte;
    10071007                                bool found = page_mapping_find(as,
    10081008                                     ptr + P2SZ(size), false, &pte);
    1009                                
     1009
    10101010                                assert(found);
    10111011                                assert(PTE_VALID(&pte));
    10121012                                assert(PTE_PRESENT(&pte));
    1013                                
     1013
    10141014                                if ((area->backend) &&
    10151015                                    (area->backend->frame_free)) {
     
    10181018                                            PTE_GET_FRAME(&pte));
    10191019                                }
    1020                                
     1020
    10211021                                page_mapping_remove(as, ptr + P2SZ(size));
    10221022                        }
    10231023                }
    10241024        }
    1025        
     1025
    10261026        /*
    10271027         * Finish TLB shootdown sequence.
    10281028         */
    1029        
     1029
    10301030        tlb_invalidate_pages(as->asid, area->base, area->pages);
    1031        
     1031
    10321032        /*
    10331033         * Invalidate potential software translation caches
     
    10361036        as_invalidate_translation_cache(as, area->base, area->pages);
    10371037        tlb_shootdown_finalize(ipl);
    1038        
     1038
    10391039        page_table_unlock(as, false);
    1040        
     1040
    10411041        btree_destroy(&area->used_space);
    1042        
     1042
    10431043        area->attributes |= AS_AREA_ATTR_PARTIAL;
    1044        
     1044
    10451045        sh_info_remove_reference(area->sh_info);
    1046        
     1046
    10471047        mutex_unlock(&area->lock);
    1048        
     1048
    10491049        /*
    10501050         * Remove the empty area from address space.
    10511051         */
    10521052        btree_remove(&as->as_area_btree, base, NULL);
    1053        
     1053
    10541054        free(area);
    1055        
     1055
    10561056        mutex_unlock(&as->lock);
    10571057        return 0;
     
    10981098                return ENOENT;
    10991099        }
    1100        
     1100
    11011101        if (!src_area->backend->is_shareable(src_area)) {
    11021102                /*
     
    11071107                return ENOTSUP;
    11081108        }
    1109        
     1109
    11101110        size_t src_size = P2SZ(src_area->pages);
    11111111        unsigned int src_flags = src_area->flags;
    11121112        mem_backend_t *src_backend = src_area->backend;
    11131113        mem_backend_data_t src_backend_data = src_area->backend_data;
    1114        
     1114
    11151115        /* Share the cacheable flag from the original mapping */
    11161116        if (src_flags & AS_AREA_CACHEABLE)
    11171117                dst_flags_mask |= AS_AREA_CACHEABLE;
    1118        
     1118
    11191119        if ((src_size != acc_size) ||
    11201120            ((src_flags & dst_flags_mask) != dst_flags_mask)) {
     
    11231123                return EPERM;
    11241124        }
    1125        
     1125
    11261126        /*
    11271127         * Now we are committed to sharing the area.
     
    11301130         */
    11311131        share_info_t *sh_info = src_area->sh_info;
    1132        
     1132
    11331133        mutex_lock(&sh_info->lock);
    11341134        sh_info->refcount++;
     
    11441144                src_area->backend->share(src_area);
    11451145        }
    1146        
     1146
    11471147        mutex_unlock(&src_area->lock);
    11481148        mutex_unlock(&src_as->lock);
    1149        
     1149
    11501150        /*
    11511151         * Create copy of the source address space area.
     
    11641164                 */
    11651165                sh_info_remove_reference(sh_info);
    1166                
     1166
    11671167                return ENOMEM;
    11681168        }
    1169        
     1169
    11701170        /*
    11711171         * Now the destination address space area has been
     
    11791179        mutex_unlock(&dst_area->lock);
    11801180        mutex_unlock(&dst_as->lock);
    1181        
     1181
    11821182        return 0;
    11831183}
     
    11951195{
    11961196        assert(mutex_locked(&area->lock));
    1197        
     1197
    11981198        int flagmap[] = {
    11991199                [PF_ACCESS_READ] = AS_AREA_READ,
     
    12011201                [PF_ACCESS_EXEC] = AS_AREA_EXEC
    12021202        };
    1203        
     1203
    12041204        if (!(area->flags & flagmap[access]))
    12051205                return false;
    1206        
     1206
    12071207        return true;
    12081208}
     
    12181218{
    12191219        unsigned int flags = PAGE_USER | PAGE_PRESENT;
    1220        
     1220
    12211221        if (aflags & AS_AREA_READ)
    12221222                flags |= PAGE_READ;
    1223                
     1223
    12241224        if (aflags & AS_AREA_WRITE)
    12251225                flags |= PAGE_WRITE;
    1226        
     1226
    12271227        if (aflags & AS_AREA_EXEC)
    12281228                flags |= PAGE_EXEC;
    1229        
     1229
    12301230        if (aflags & AS_AREA_CACHEABLE)
    12311231                flags |= PAGE_CACHEABLE;
    1232        
     1232
    12331233        return flags;
    12341234}
     
    12521252        /* Flags for the new memory mapping */
    12531253        unsigned int page_flags = area_flags_to_page_flags(flags);
    1254        
     1254
    12551255        mutex_lock(&as->lock);
    1256        
     1256
    12571257        as_area_t *area = find_area_and_lock(as, address);
    12581258        if (!area) {
     
    12601260                return ENOENT;
    12611261        }
    1262        
     1262
    12631263        if (area->backend != &anon_backend) {
    12641264                /* Copying non-anonymous memory not supported yet */
     
    12771277        }
    12781278        mutex_unlock(&area->sh_info->lock);
    1279        
     1279
    12801280        /*
    12811281         * Compute total number of used pages in the used_space B+tree
    12821282         */
    12831283        size_t used_pages = 0;
    1284        
     1284
    12851285        list_foreach(area->used_space.leaf_list, leaf_link, btree_node_t,
    12861286            node) {
    12871287                btree_key_t i;
    1288                
     1288
    12891289                for (i = 0; i < node->keys; i++)
    12901290                        used_pages += (size_t) node->value[i];
    12911291        }
    1292        
     1292
    12931293        /* An array for storing frame numbers */
    12941294        uintptr_t *old_frame = malloc(used_pages * sizeof(uintptr_t), 0);
    1295        
     1295
    12961296        page_table_lock(as, false);
    1297        
     1297
    12981298        /*
    12991299         * Start TLB shootdown sequence.
     
    13011301        ipl_t ipl = tlb_shootdown_start(TLB_INVL_PAGES, as->asid, area->base,
    13021302            area->pages);
    1303        
     1303
    13041304        /*
    13051305         * Remove used pages from page tables and remember their frame
     
    13071307         */
    13081308        size_t frame_idx = 0;
    1309        
     1309
    13101310        list_foreach(area->used_space.leaf_list, leaf_link, btree_node_t,
    13111311            node) {
    13121312                btree_key_t i;
    1313                
     1313
    13141314                for (i = 0; i < node->keys; i++) {
    13151315                        uintptr_t ptr = node->key[i];
    13161316                        size_t size;
    1317                        
     1317
    13181318                        for (size = 0; size < (size_t) node->value[i]; size++) {
    13191319                                pte_t pte;
    13201320                                bool found = page_mapping_find(as,
    13211321                                    ptr + P2SZ(size), false, &pte);
    1322                                
     1322
    13231323                                assert(found);
    13241324                                assert(PTE_VALID(&pte));
    13251325                                assert(PTE_PRESENT(&pte));
    1326                                
     1326
    13271327                                old_frame[frame_idx++] = PTE_GET_FRAME(&pte);
    1328                                
     1328
    13291329                                /* Remove old mapping */
    13301330                                page_mapping_remove(as, ptr + P2SZ(size));
     
    13321332                }
    13331333        }
    1334        
     1334
    13351335        /*
    13361336         * Finish TLB shootdown sequence.
    13371337         */
    1338        
     1338
    13391339        tlb_invalidate_pages(as->asid, area->base, area->pages);
    1340        
     1340
    13411341        /*
    13421342         * Invalidate potential software translation caches
     
    13451345        as_invalidate_translation_cache(as, area->base, area->pages);
    13461346        tlb_shootdown_finalize(ipl);
    1347        
     1347
    13481348        page_table_unlock(as, false);
    1349        
     1349
    13501350        /*
    13511351         * Set the new flags.
    13521352         */
    13531353        area->flags = flags;
    1354        
     1354
    13551355        /*
    13561356         * Map pages back in with new flags. This step is kept separate
     
    13591359         */
    13601360        frame_idx = 0;
    1361        
     1361
    13621362        list_foreach(area->used_space.leaf_list, leaf_link, btree_node_t,
    13631363            node) {
    13641364                btree_key_t i;
    1365                
     1365
    13661366                for (i = 0; i < node->keys; i++) {
    13671367                        uintptr_t ptr = node->key[i];
    13681368                        size_t size;
    1369                        
     1369
    13701370                        for (size = 0; size < (size_t) node->value[i]; size++) {
    13711371                                page_table_lock(as, false);
    1372                                
     1372
    13731373                                /* Insert the new mapping */
    13741374                                page_mapping_insert(as, ptr + P2SZ(size),
    13751375                                    old_frame[frame_idx++], page_flags);
    1376                                
     1376
    13771377                                page_table_unlock(as, false);
    13781378                        }
    13791379                }
    13801380        }
    1381        
     1381
    13821382        free(old_frame);
    1383        
     1383
    13841384        mutex_unlock(&area->lock);
    13851385        mutex_unlock(&as->lock);
    1386        
     1386
    13871387        return 0;
    13881388}
     
    14141414        if (!THREAD)
    14151415                goto page_fault;
    1416        
     1416
    14171417        if (!AS)
    14181418                goto page_fault;
    1419        
     1419
    14201420        mutex_lock(&AS->lock);
    14211421        as_area_t *area = find_area_and_lock(AS, page);
     
    14281428                goto page_fault;
    14291429        }
    1430        
     1430
    14311431        if (area->attributes & AS_AREA_ATTR_PARTIAL) {
    14321432                /*
     
    14381438                goto page_fault;
    14391439        }
    1440        
     1440
    14411441        if ((!area->backend) || (!area->backend->page_fault)) {
    14421442                /*
     
    14481448                goto page_fault;
    14491449        }
    1450        
     1450
    14511451        page_table_lock(AS, false);
    1452        
     1452
    14531453        /*
    14541454         * To avoid race condition between two page faults on the same address,
     
    14671467                }
    14681468        }
    1469        
     1469
    14701470        /*
    14711471         * Resort to the backend page fault handler.
     
    14781478                goto page_fault;
    14791479        }
    1480        
     1480
    14811481        page_table_unlock(AS, false);
    14821482        mutex_unlock(&area->lock);
    14831483        mutex_unlock(&AS->lock);
    14841484        return AS_PF_OK;
    1485        
     1485
    14861486page_fault:
    14871487        if (THREAD->in_copy_from_uspace) {
     
    15011501                panic_memtrap(istate, access, address, NULL);
    15021502        }
    1503        
     1503
    15041504        return AS_PF_DEFER;
    15051505}
     
    15211521        DEADLOCK_PROBE_INIT(p_asidlock);
    15221522        preemption_disable();
    1523        
     1523
    15241524retry:
    15251525        (void) interrupts_disable();
     
    15361536        }
    15371537        preemption_enable();
    1538        
     1538
    15391539        /*
    15401540         * First, take care of the old address space.
     
    15421542        if (old_as) {
    15431543                assert(old_as->cpu_refcount);
    1544                
     1544
    15451545                if ((--old_as->cpu_refcount == 0) && (old_as != AS_KERNEL)) {
    15461546                        /*
     
    15511551                         */
    15521552                        assert(old_as->asid != ASID_INVALID);
    1553                        
     1553
    15541554                        list_append(&old_as->inactive_as_with_asid_link,
    15551555                            &inactive_as_with_asid_list);
    15561556                }
    1557                
     1557
    15581558                /*
    15591559                 * Perform architecture-specific tasks when the address space
     
    15621562                as_deinstall_arch(old_as);
    15631563        }
    1564        
     1564
    15651565        /*
    15661566         * Second, prepare the new address space.
     
    15721572                        new_as->asid = asid_get();
    15731573        }
    1574        
     1574
    15751575#ifdef AS_PAGE_TABLE
    15761576        SET_PTL0_ADDRESS(new_as->genarch.page_table);
    15771577#endif
    1578        
     1578
    15791579        /*
    15801580         * Perform architecture-specific steps.
     
    15821582         */
    15831583        as_install_arch(new_as);
    1584        
     1584
    15851585        spinlock_unlock(&asidlock);
    1586        
     1586
    15871587        AS = new_as;
    15881588}
     
    15981598{
    15991599        assert(mutex_locked(&area->lock));
    1600        
     1600
    16011601        return area_flags_to_page_flags(area->flags);
    16021602}
     
    16171617        assert(as_operations);
    16181618        assert(as_operations->page_table_create);
    1619        
     1619
    16201620        return as_operations->page_table_create(flags);
    16211621}
     
    16321632        assert(as_operations);
    16331633        assert(as_operations->page_table_destroy);
    1634        
     1634
    16351635        as_operations->page_table_destroy(page_table);
    16361636}
     
    16531653        assert(as_operations);
    16541654        assert(as_operations->page_table_lock);
    1655        
     1655
    16561656        as_operations->page_table_lock(as, lock);
    16571657}
     
    16671667        assert(as_operations);
    16681668        assert(as_operations->page_table_unlock);
    1669        
     1669
    16701670        as_operations->page_table_unlock(as, unlock);
    16711671}
     
    16971697{
    16981698        size_t size;
    1699        
     1699
    17001700        page_table_lock(AS, true);
    17011701        as_area_t *src_area = find_area_and_lock(AS, base);
    1702        
     1702
    17031703        if (src_area) {
    17041704                size = P2SZ(src_area->pages);
     
    17061706        } else
    17071707                size = 0;
    1708        
     1708
    17091709        page_table_unlock(AS, true);
    17101710        return size;
     
    17271727        assert(IS_ALIGNED(page, PAGE_SIZE));
    17281728        assert(count);
    1729        
     1729
    17301730        btree_node_t *leaf = NULL;
    17311731        size_t pages = (size_t) btree_search(&area->used_space, page, &leaf);
     
    17381738
    17391739        assert(leaf != NULL);
    1740        
     1740
    17411741        if (!leaf->keys) {
    17421742                btree_insert(&area->used_space, page, (void *) count, leaf);
    17431743                goto success;
    17441744        }
    1745        
     1745
    17461746        btree_node_t *node = btree_leaf_node_left_neighbour(&area->used_space, leaf);
    17471747        if (node) {
     
    17501750                size_t left_cnt = (size_t) node->value[node->keys - 1];
    17511751                size_t right_cnt = (size_t) leaf->value[0];
    1752                
     1752
    17531753                /*
    17541754                 * Examine the possibility that the interval fits
     
    17561756                 * the left neigbour and the first interval of the leaf.
    17571757                 */
    1758                
     1758
    17591759                if (page >= right_pg) {
    17601760                        /* Do nothing. */
     
    18041804                uintptr_t right_pg = leaf->key[0];
    18051805                size_t right_cnt = (size_t) leaf->value[0];
    1806                
     1806
    18071807                /*
    18081808                 * Investigate the border case in which the left neighbour does
    18091809                 * not exist but the interval fits from the left.
    18101810                 */
    1811                
     1811
    18121812                if (overlaps(page, P2SZ(count), right_pg, P2SZ(right_cnt))) {
    18131813                        /* The interval intersects with the right interval. */
     
    18321832                }
    18331833        }
    1834        
     1834
    18351835        node = btree_leaf_node_right_neighbour(&area->used_space, leaf);
    18361836        if (node) {
     
    18391839                size_t left_cnt = (size_t) leaf->value[leaf->keys - 1];
    18401840                size_t right_cnt = (size_t) node->value[0];
    1841                
     1841
    18421842                /*
    18431843                 * Examine the possibility that the interval fits
     
    18451845                 * the right neigbour and the last interval of the leaf.
    18461846                 */
    1847                
     1847
    18481848                if (page < left_pg) {
    18491849                        /* Do nothing. */
     
    18931893                uintptr_t left_pg = leaf->key[leaf->keys - 1];
    18941894                size_t left_cnt = (size_t) leaf->value[leaf->keys - 1];
    1895                
     1895
    18961896                /*
    18971897                 * Investigate the border case in which the right neighbour
    18981898                 * does not exist but the interval fits from the right.
    18991899                 */
    1900                
     1900
    19011901                if (overlaps(page, P2SZ(count), left_pg, P2SZ(left_cnt))) {
    19021902                        /* The interval intersects with the left interval. */
     
    19191919                }
    19201920        }
    1921        
     1921
    19221922        /*
    19231923         * Note that if the algorithm made it thus far, the interval can fit
     
    19321932                        size_t left_cnt = (size_t) leaf->value[i - 1];
    19331933                        size_t right_cnt = (size_t) leaf->value[i];
    1934                        
     1934
    19351935                        /*
    19361936                         * The interval fits between left_pg and right_pg.
    19371937                         */
    1938                        
     1938
    19391939                        if (overlaps(page, P2SZ(count), left_pg,
    19401940                            P2SZ(left_cnt))) {
     
    19881988                }
    19891989        }
    1990        
     1990
    19911991        panic("Inconsistency detected while adding %zu pages of used "
    19921992            "space at %p.", count, (void *) page);
    1993        
     1993
    19941994success:
    19951995        area->resident += count;
     
    20132013        assert(IS_ALIGNED(page, PAGE_SIZE));
    20142014        assert(count);
    2015        
     2015
    20162016        btree_node_t *leaf;
    20172017        size_t pages = (size_t) btree_search(&area->used_space, page, &leaf);
     
    20382038                                }
    20392039                        }
    2040                        
     2040
    20412041                        goto error;
    20422042                }
    20432043        }
    2044        
     2044
    20452045        btree_node_t *node = btree_leaf_node_left_neighbour(&area->used_space,
    20462046            leaf);
     
    20482048                uintptr_t left_pg = node->key[node->keys - 1];
    20492049                size_t left_cnt = (size_t) node->value[node->keys - 1];
    2050                
     2050
    20512051                if (overlaps(left_pg, P2SZ(left_cnt), page, P2SZ(count))) {
    20522052                        if (page + P2SZ(count) == left_pg + P2SZ(left_cnt)) {
     
    20782078                        }
    20792079                }
    2080                
     2080
    20812081                return false;
    20822082        } else if (page < leaf->key[0])
    20832083                return false;
    2084        
     2084
    20852085        if (page > leaf->key[leaf->keys - 1]) {
    20862086                uintptr_t left_pg = leaf->key[leaf->keys - 1];
    20872087                size_t left_cnt = (size_t) leaf->value[leaf->keys - 1];
    2088                
     2088
    20892089                if (overlaps(left_pg, P2SZ(left_cnt), page, P2SZ(count))) {
    20902090                        if (page + P2SZ(count) == left_pg + P2SZ(left_cnt)) {
     
    21152115                        }
    21162116                }
    2117                
     2117
    21182118                return false;
    21192119        }
    2120        
     2120
    21212121        /*
    21222122         * The border cases have been already resolved.
     
    21282128                        uintptr_t left_pg = leaf->key[i - 1];
    21292129                        size_t left_cnt = (size_t) leaf->value[i - 1];
    2130                        
     2130
    21312131                        /*
    21322132                         * Now the interval is between intervals corresponding
     
    21662166                                }
    21672167                        }
    2168                        
     2168
    21692169                        return false;
    21702170                }
    21712171        }
    2172        
     2172
    21732173error:
    21742174        panic("Inconsistency detected while removing %zu pages of used "
    21752175            "space from %p.", count, (void *) page);
    2176        
     2176
    21772177success:
    21782178        area->resident -= count;
     
    22042204        if (area == NULL)
    22052205                return (sysarg_t) AS_MAP_FAILED;
    2206        
     2206
    22072207        return (sysarg_t) virt;
    22082208}
     
    22332233{
    22342234        mutex_lock(&as->lock);
    2235        
     2235
    22362236        /* First pass, count number of areas. */
    2237        
     2237
    22382238        size_t area_cnt = 0;
    2239        
     2239
    22402240        list_foreach(as->as_area_btree.leaf_list, leaf_link, btree_node_t,
    22412241            node) {
    22422242                area_cnt += node->keys;
    22432243        }
    2244        
     2244
    22452245        size_t isize = area_cnt * sizeof(as_area_info_t);
    22462246        as_area_info_t *info = malloc(isize, 0);
    2247        
     2247
    22482248        /* Second pass, record data. */
    2249        
     2249
    22502250        size_t area_idx = 0;
    2251        
     2251
    22522252        list_foreach(as->as_area_btree.leaf_list, leaf_link, btree_node_t,
    22532253            node) {
    22542254                btree_key_t i;
    2255                
     2255
    22562256                for (i = 0; i < node->keys; i++) {
    22572257                        as_area_t *area = node->value[i];
    2258                        
     2258
    22592259                        assert(area_idx < area_cnt);
    22602260                        mutex_lock(&area->lock);
    2261                        
     2261
    22622262                        info[area_idx].start_addr = area->base;
    22632263                        info[area_idx].size = P2SZ(area->pages);
    22642264                        info[area_idx].flags = area->flags;
    22652265                        ++area_idx;
    2266                        
     2266
    22672267                        mutex_unlock(&area->lock);
    22682268                }
    22692269        }
    2270        
     2270
    22712271        mutex_unlock(&as->lock);
    2272        
     2272
    22732273        *obuf = info;
    22742274        *osize = isize;
     
    22832283{
    22842284        mutex_lock(&as->lock);
    2285        
     2285
    22862286        /* Print out info about address space areas */
    22872287        list_foreach(as->as_area_btree.leaf_list, leaf_link, btree_node_t,
    22882288            node) {
    22892289                btree_key_t i;
    2290                
     2290
    22912291                for (i = 0; i < node->keys; i++) {
    22922292                        as_area_t *area = node->value[i];
    2293                        
     2293
    22942294                        mutex_lock(&area->lock);
    22952295                        printf("as_area: %p, base=%p, pages=%zu"
     
    23002300                }
    23012301        }
    2302        
     2302
    23032303        mutex_unlock(&as->lock);
    23042304}
  • kernel/generic/src/mm/backend_anon.c

    r3061bc1 ra35b458  
    125125            node) {
    126126                unsigned int i;
    127                
     127
    128128                for (i = 0; i < node->keys; i++) {
    129129                        uintptr_t base = node->key[i];
    130130                        size_t count = (size_t) node->value[i];
    131131                        unsigned int j;
    132                        
     132
    133133                        for (j = 0; j < count; j++) {
    134134                                pte_t pte;
    135135                                bool found;
    136                        
     136
    137137                                page_table_lock(area->as, false);
    138138                                found = page_mapping_find(area->as,
     
    201201        if (area->sh_info->shared) {
    202202                btree_node_t *leaf;
    203                
     203
    204204                /*
    205205                 * The area is shared, chances are that the mapping can be found
     
    214214                        bool allocate = true;
    215215                        unsigned int i;
    216                        
     216
    217217                        /*
    218218                         * Zero can be returned as a valid frame address.
     
    230230                                memsetb((void *) kpage, PAGE_SIZE, 0);
    231231                                km_temporary_page_put(kpage);
    232                                
     232
    233233                                /*
    234234                                 * Insert the address of the newly allocated
     
    272272        }
    273273        mutex_unlock(&area->sh_info->lock);
    274        
     274
    275275        /*
    276276         * Map 'upage' to 'frame'.
     
    281281        if (!used_space_insert(area, upage, 1))
    282282                panic("Cannot insert used space.");
    283                
     283
    284284        return AS_PF_OK;
    285285}
  • kernel/generic/src/mm/backend_elf.c

    r3061bc1 ra35b458  
    102102        if (area->pages <= nonanon_pages)
    103103                return true;
    104        
     104
    105105        return reserve_try_alloc(area->pages - nonanon_pages);
    106106}
     
    123123                        reserve_free(nonanon_pages - new_pages);
    124124        }
    125        
     125
    126126        return true;
    127127}
     
    166166            cur = cur->next) {
    167167                unsigned int i;
    168                
     168
    169169                node = list_get_instance(cur, btree_node_t, leaf_link);
    170                
     170
    171171                for (i = 0; i < node->keys; i++) {
    172172                        uintptr_t base = node->key[i];
    173173                        size_t count = (size_t) node->value[i];
    174174                        unsigned int j;
    175                        
     175
    176176                        /*
    177177                         * Skip read-only areas of used space that are backed
     
    182182                                    base + P2SZ(count) <= start_anon)
    183183                                        continue;
    184                        
     184
    185185                        for (j = 0; j < count; j++) {
    186186                                pte_t pte;
    187187                                bool found;
    188                        
     188
    189189                                /*
    190190                                 * Skip read-only pages that are backed by the
     
    195195                                            base + P2SZ(j + 1) <= start_anon)
    196196                                                continue;
    197                                
     197
    198198                                page_table_lock(area->as, false);
    199199                                found = page_mapping_find(area->as,
     
    212212                                frame_reference_add(pfn);
    213213                        }
    214                                
     214
    215215                }
    216216        }
     
    267267        if (!as_area_check_access(area, access))
    268268                return AS_PF_FAULT;
    269        
     269
    270270        if (upage < ALIGN_DOWN(entry->p_vaddr, PAGE_SIZE))
    271271                return AS_PF_FAULT;
    272        
     272
    273273        if (upage >= entry->p_vaddr + entry->p_memsz)
    274274                return AS_PF_FAULT;
    275        
     275
    276276        i = (upage - ALIGN_DOWN(entry->p_vaddr, PAGE_SIZE)) >> PAGE_WIDTH;
    277277        base = (uintptr_t)
     
    288288                 * The address space area is shared.
    289289                 */
    290                
     290
    291291                frame = (uintptr_t) btree_search(&area->sh_info->pagemap,
    292292                    upage - area->base, &leaf);
  • kernel/generic/src/mm/backend_phys.c

    r3061bc1 ra35b458  
    7575        .page_fault = phys_page_fault,
    7676        .frame_free = NULL,
    77        
     77
    7878        .create_shared_data = phys_create_shared_data,
    7979        .destroy_shared_data = phys_destroy_shared_data
     
    145145        page_mapping_insert(AS, upage, base + (upage - area->base),
    146146            as_area_get_flags(area));
    147        
     147
    148148        if (!used_space_insert(area, upage, 1))
    149149                panic("Cannot insert used space.");
  • kernel/generic/src/mm/backend_user.c

    r3061bc1 ra35b458  
    172172                /* Nothing to do */
    173173        }
    174                
     174
    175175}
    176176
  • kernel/generic/src/mm/frame.c

    r3061bc1 ra35b458  
    108108                return (size_t) -1;
    109109        }
    110        
     110
    111111        size_t i;
    112112        for (i = 0; i < zones.count; i++) {
     
    114114                if (overlaps(zones.info[i].base, zones.info[i].count,
    115115                    base, count)) {
    116                        
     116
    117117                        /*
    118118                         * If the overlaping zones are of the same type
     
    121121                         *
    122122                         */
    123                        
     123
    124124                        if ((zones.info[i].flags != flags) ||
    125125                            (!iswithin(zones.info[i].base, zones.info[i].count,
     
    132132                                    (void *) PFN2ADDR(zones.info[i].count));
    133133                        }
    134                        
     134
    135135                        return (size_t) -1;
    136136                }
     
    138138                        break;
    139139        }
    140        
     140
    141141        /* Move other zones up */
    142142        for (size_t j = zones.count; j > i; j--)
    143143                zones.info[j] = zones.info[j - 1];
    144        
     144
    145145        zones.count++;
    146        
     146
    147147        return i;
    148148}
     
    163163        for (i = 0; i < zones.count; i++)
    164164                total += zones.info[i].free_count;
    165        
     165
    166166        return total;
    167167}
     
    195195        if (hint >= zones.count)
    196196                hint = 0;
    197        
     197
    198198        size_t i = hint;
    199199        do {
     
    201201                    && (zones.info[i].base + zones.info[i].count >= frame + count))
    202202                        return i;
    203                
     203
    204204                i++;
    205205                if (i >= zones.count)
    206206                        i = 0;
    207                
     207
    208208        } while (i != hint);
    209        
     209
    210210        return (size_t) -1;
    211211}
     
    219219         * the bitmap if the last argument is NULL.
    220220         */
    221        
     221
    222222        return ((zone->flags & ZONE_AVAILABLE) &&
    223223            bitmap_allocate_range(&zone->bitmap, count, zone->base,
     
    245245        for (size_t pos = 0; pos < zones.count; pos++) {
    246246                size_t i = (pos + hint) % zones.count;
    247                
     247
    248248                /* Check whether the zone meets the search criteria. */
    249249                if (!ZONE_FLAGS_MATCH(zones.info[i].flags, flags))
    250250                        continue;
    251                
     251
    252252                /* Check if the zone can satisfy the allocation request. */
    253253                if (zone_can_alloc(&zones.info[i], count, constraint))
    254254                        return i;
    255255        }
    256        
     256
    257257        return (size_t) -1;
    258258}
     
    291291        for (size_t pos = 0; pos < zones.count; pos++) {
    292292                size_t i = (pos + hint) % zones.count;
    293                
     293
    294294                /* Skip zones containing only high-priority memory. */
    295295                if (is_high_priority(zones.info[i].base, zones.info[i].count))
    296296                        continue;
    297                
     297
    298298                /* Check whether the zone meets the search criteria. */
    299299                if (!ZONE_FLAGS_MATCH(zones.info[i].flags, flags))
    300300                        continue;
    301                
     301
    302302                /* Check if the zone can satisfy the allocation request. */
    303303                if (zone_can_alloc(&zones.info[i], count, constraint))
    304304                        return i;
    305305        }
    306        
     306
    307307        return (size_t) -1;
    308308}
     
    328328        if (hint >= zones.count)
    329329                hint = 0;
    330        
     330
    331331        /*
    332332         * Prefer zones with low-priority memory over
    333333         * zones with high-priority memory.
    334334         */
    335        
     335
    336336        size_t znum = find_free_zone_lowprio(count, flags, constraint, hint);
    337337        if (znum != (size_t) -1)
    338338                return znum;
    339        
     339
    340340        /* Take all zones into account */
    341341        return find_free_zone_all(count, flags, constraint, hint);
     
    350350{
    351351        assert(index < zone->count);
    352        
     352
    353353        return &zone->frames[index];
    354354}
     
    371371{
    372372        assert(zone->flags & ZONE_AVAILABLE);
    373        
     373
    374374        /* Allocate frames from zone */
    375375        size_t index = (size_t) -1;
    376376        int avail = bitmap_allocate_range(&zone->bitmap, count, zone->base,
    377377            FRAME_LOWPRIO, constraint, &index);
    378        
     378
    379379        assert(avail);
    380380        assert(index != (size_t) -1);
    381        
     381
    382382        /* Update frame reference count */
    383383        for (size_t i = 0; i < count; i++) {
    384384                frame_t *frame = zone_get_frame(zone, index + i);
    385                
     385
    386386                assert(frame->refcount == 0);
    387387                frame->refcount = 1;
    388388        }
    389        
     389
    390390        /* Update zone information. */
    391391        zone->free_count -= count;
    392392        zone->busy_count += count;
    393        
     393
    394394        return index;
    395395}
     
    408408{
    409409        assert(zone->flags & ZONE_AVAILABLE);
    410        
     410
    411411        frame_t *frame = zone_get_frame(zone, index);
    412        
     412
    413413        assert(frame->refcount > 0);
    414        
     414
    415415        if (!--frame->refcount) {
    416416                bitmap_set(&zone->bitmap, index, 0);
    417                
     417
    418418                /* Update zone information. */
    419419                zone->free_count++;
    420420                zone->busy_count--;
    421                
     421
    422422                return 1;
    423423        }
    424        
     424
    425425        return 0;
    426426}
     
    430430{
    431431        assert(zone->flags & ZONE_AVAILABLE);
    432        
     432
    433433        frame_t *frame = zone_get_frame(zone, index);
    434434        if (frame->refcount > 0)
    435435                return;
    436        
     436
    437437        frame->refcount = 1;
    438438        bitmap_set_range(&zone->bitmap, index, 1);
    439        
     439
    440440        zone->free_count--;
    441441        reserve_force_alloc(1);
     
    462462        assert(!overlaps(zones.info[z1].base, zones.info[z1].count,
    463463            zones.info[z2].base, zones.info[z2].count));
    464        
     464
    465465        /* Difference between zone bases */
    466466        pfn_t base_diff = zones.info[z2].base - zones.info[z1].base;
    467        
     467
    468468        zones.info[z1].count = base_diff + zones.info[z2].count;
    469469        zones.info[z1].free_count += zones.info[z2].free_count;
    470470        zones.info[z1].busy_count += zones.info[z2].busy_count;
    471        
     471
    472472        bitmap_initialize(&zones.info[z1].bitmap, zones.info[z1].count,
    473473            confdata + (sizeof(frame_t) * zones.info[z1].count));
    474474        bitmap_clear_range(&zones.info[z1].bitmap, 0, zones.info[z1].count);
    475        
     475
    476476        zones.info[z1].frames = (frame_t *) confdata;
    477        
     477
    478478        /*
    479479         * Copy frames and bits from both zones to preserve parents, etc.
    480480         */
    481        
     481
    482482        for (size_t i = 0; i < old_z1->count; i++) {
    483483                bitmap_set(&zones.info[z1].bitmap, i,
     
    485485                zones.info[z1].frames[i] = old_z1->frames[i];
    486486        }
    487        
     487
    488488        for (size_t i = 0; i < zones.info[z2].count; i++) {
    489489                bitmap_set(&zones.info[z1].bitmap, base_diff + i,
     
    510510{
    511511        assert(zones.info[znum].flags & ZONE_AVAILABLE);
    512        
     512
    513513        size_t cframes = SIZE2FRAMES(zone_conf_size(count));
    514        
     514
    515515        if ((pfn < zones.info[znum].base) ||
    516516            (pfn >= zones.info[znum].base + zones.info[znum].count))
    517517                return;
    518        
     518
    519519        for (size_t i = 0; i < cframes; i++)
    520520                (void) zone_frame_free(&zones.info[znum],
     
    536536{
    537537        irq_spinlock_lock(&zones.lock, true);
    538        
     538
    539539        bool ret = true;
    540        
     540
    541541        /*
    542542         * We can join only 2 zones with none existing inbetween,
     
    549549                goto errout;
    550550        }
    551        
     551
    552552        pfn_t cframes = SIZE2FRAMES(zone_conf_size(
    553553            zones.info[z2].base - zones.info[z1].base
    554554            + zones.info[z2].count));
    555        
     555
    556556        /* Allocate merged zone data inside one of the zones */
    557557        pfn_t pfn;
     
    566566                goto errout;
    567567        }
    568        
     568
    569569        /* Preserve original data from z1 */
    570570        zone_t old_z1 = zones.info[z1];
    571        
     571
    572572        /* Do zone merging */
    573573        zone_merge_internal(z1, z2, &old_z1, (void *) PA2KA(PFN2ADDR(pfn)));
    574        
     574
    575575        /* Subtract zone information from busy frames */
    576576        zones.info[z1].busy_count -= cframes;
    577        
     577
    578578        /* Free old zone information */
    579579        return_config_frames(z1,
     
    582582            ADDR2PFN(KA2PA((uintptr_t) zones.info[z2].frames)),
    583583            zones.info[z2].count);
    584        
     584
    585585        /* Move zones down */
    586586        for (size_t i = z2 + 1; i < zones.count; i++)
    587587                zones.info[i - 1] = zones.info[i];
    588        
     588
    589589        zones.count--;
    590        
     590
    591591errout:
    592592        irq_spinlock_unlock(&zones.lock, true);
    593        
     593
    594594        return ret;
    595595}
     
    605605{
    606606        size_t i = 1;
    607        
     607
    608608        while (i < zones.count) {
    609609                if (!zone_merge(i - 1, i))
     
    631631        zone->free_count = count;
    632632        zone->busy_count = 0;
    633        
     633
    634634        if (flags & ZONE_AVAILABLE) {
    635635                /*
     
    637637                 * frame_t structures in the configuration space).
    638638                 */
    639                
     639
    640640                bitmap_initialize(&zone->bitmap, count, confdata +
    641641                    (sizeof(frame_t) * count));
    642642                bitmap_clear_range(&zone->bitmap, 0, count);
    643                
     643
    644644                /*
    645645                 * Initialize the array of frame_t structures.
    646646                 */
    647                
     647
    648648                zone->frames = (frame_t *) confdata;
    649                
     649
    650650                for (size_t i = 0; i < count; i++)
    651651                        frame_initialize(&zone->frames[i]);
     
    672672{
    673673        size_t frames = SIZE2FRAMES(zone_conf_size(count));
    674        
     674
    675675        return ADDR2PFN((uintptr_t)
    676676            frame_alloc(frames, FRAME_LOWMEM | FRAME_ATOMIC, 0));
     
    697697{
    698698        irq_spinlock_lock(&zones.lock, true);
    699        
     699
    700700        if (flags & ZONE_AVAILABLE) {  /* Create available zone */
    701701                /*
     
    705705                 */
    706706                assert(confframe != ADDR2PFN((uintptr_t ) NULL));
    707                
     707
    708708                /* Update the known end of physical memory. */
    709709                config.physmem_end = max(config.physmem_end, PFN2ADDR(start + count));
    710                
     710
    711711                /*
    712712                 * If confframe is supposed to be inside our zone, then make sure
     
    714714                 */
    715715                size_t confcount = SIZE2FRAMES(zone_conf_size(count));
    716                
     716
    717717                if ((confframe >= start) && (confframe < start + count)) {
    718718                        for (; confframe < start + count; confframe++) {
     
    721721                                    KA2PA(config.base), config.kernel_size))
    722722                                        continue;
    723                                
     723
    724724                                if (overlaps(addr, PFN2ADDR(confcount),
    725725                                    KA2PA(config.stack_base), config.stack_size))
    726726                                        continue;
    727                                
     727
    728728                                bool overlap = false;
    729729                                for (size_t i = 0; i < init.cnt; i++) {
     
    735735                                        }
    736736                                }
    737                                
     737
    738738                                if (overlap)
    739739                                        continue;
    740                                
     740
    741741                                break;
    742742                        }
    743                        
     743
    744744                        if (confframe >= start + count)
    745745                                panic("Cannot find configuration data for zone.");
    746746                }
    747                
     747
    748748                size_t znum = zones_insert_zone(start, count, flags);
    749749                if (znum == (size_t) -1) {
     
    751751                        return (size_t) -1;
    752752                }
    753                
     753
    754754                void *confdata = (void *) PA2KA(PFN2ADDR(confframe));
    755755                zone_construct(&zones.info[znum], start, count, flags, confdata);
    756                
     756
    757757                /* If confdata in zone, mark as unavailable */
    758758                if ((confframe >= start) && (confframe < start + count)) {
     
    761761                                    i - zones.info[znum].base);
    762762                }
    763                
     763
    764764                irq_spinlock_unlock(&zones.lock, true);
    765                
     765
    766766                return znum;
    767767        }
    768        
     768
    769769        /* Non-available zone */
    770770        size_t znum = zones_insert_zone(start, count, flags);
     
    773773                return (size_t) -1;
    774774        }
    775        
     775
    776776        zone_construct(&zones.info[znum], start, count, flags, NULL);
    777        
     777
    778778        irq_spinlock_unlock(&zones.lock, true);
    779        
     779
    780780        return znum;
    781781}
     
    789789{
    790790        irq_spinlock_lock(&zones.lock, true);
    791        
     791
    792792        size_t znum = find_zone(pfn, 1, hint);
    793        
     793
    794794        assert(znum != (size_t) -1);
    795        
     795
    796796        zone_get_frame(&zones.info[znum],
    797797            pfn - zones.info[znum].base)->parent = data;
    798        
     798
    799799        irq_spinlock_unlock(&zones.lock, true);
    800800}
     
    803803{
    804804        irq_spinlock_lock(&zones.lock, true);
    805        
     805
    806806        size_t znum = find_zone(pfn, 1, hint);
    807        
     807
    808808        assert(znum != (size_t) -1);
    809        
     809
    810810        void *res = zone_get_frame(&zones.info[znum],
    811811            pfn - zones.info[znum].base)->parent;
    812        
     812
    813813        irq_spinlock_unlock(&zones.lock, true);
    814        
     814
    815815        return res;
    816816}
     
    831831{
    832832        assert(count > 0);
    833        
     833
    834834        size_t hint = pzone ? (*pzone) : 0;
    835835        pfn_t frame_constraint = ADDR2PFN(constraint);
    836        
     836
    837837        /*
    838838         * If not told otherwise, we must first reserve the memory.
     
    840840        if (!(flags & FRAME_NO_RESERVE))
    841841                reserve_force_alloc(count);
    842        
     842
    843843loop:
    844844        irq_spinlock_lock(&zones.lock, true);
    845        
     845
    846846        /*
    847847         * First, find suitable frame zone.
     
    849849        size_t znum = find_free_zone(count, FRAME_TO_ZONE_FLAGS(flags),
    850850            frame_constraint, hint);
    851        
     851
    852852        /*
    853853         * If no memory, reclaim some slab memory,
     
    858858                size_t freed = slab_reclaim(0);
    859859                irq_spinlock_lock(&zones.lock, true);
    860                
     860
    861861                if (freed > 0)
    862862                        znum = find_free_zone(count, FRAME_TO_ZONE_FLAGS(flags),
    863863                            frame_constraint, hint);
    864                
     864
    865865                if (znum == (size_t) -1) {
    866866                        irq_spinlock_unlock(&zones.lock, true);
    867867                        freed = slab_reclaim(SLAB_RECLAIM_ALL);
    868868                        irq_spinlock_lock(&zones.lock, true);
    869                        
     869
    870870                        if (freed > 0)
    871871                                znum = find_free_zone(count, FRAME_TO_ZONE_FLAGS(flags),
     
    873873                }
    874874        }
    875        
     875
    876876        if (znum == (size_t) -1) {
    877877                if (flags & FRAME_ATOMIC) {
    878878                        irq_spinlock_unlock(&zones.lock, true);
    879                        
     879
    880880                        if (!(flags & FRAME_NO_RESERVE))
    881881                                reserve_free(count);
    882                        
     882
    883883                        return 0;
    884884                }
    885                
     885
    886886                size_t avail = frame_total_free_get_internal();
    887                
     887
    888888                irq_spinlock_unlock(&zones.lock, true);
    889                
     889
    890890                if (!THREAD)
    891891                        panic("Cannot wait for %zu frames to become available "
    892892                            "(%zu available).", count, avail);
    893                
     893
    894894                /*
    895895                 * Sleep until some frames are available again.
    896896                 */
    897                
     897
    898898#ifdef CONFIG_DEBUG
    899899                log(LF_OTHER, LVL_DEBUG,
     
    901901                    "%zu available.", THREAD->tid, count, avail);
    902902#endif
    903                
     903
    904904                /*
    905905                 * Since the mem_avail_mtx is an active mutex, we need to
     
    908908                ipl_t ipl = interrupts_disable();
    909909                mutex_lock(&mem_avail_mtx);
    910                
     910
    911911                if (mem_avail_req > 0)
    912912                        mem_avail_req = min(mem_avail_req, count);
    913913                else
    914914                        mem_avail_req = count;
    915                
     915
    916916                size_t gen = mem_avail_gen;
    917                
     917
    918918                while (gen == mem_avail_gen)
    919919                        condvar_wait(&mem_avail_cv, &mem_avail_mtx);
    920                
     920
    921921                mutex_unlock(&mem_avail_mtx);
    922922                interrupts_restore(ipl);
    923                
     923
    924924#ifdef CONFIG_DEBUG
    925925                log(LF_OTHER, LVL_DEBUG, "Thread %" PRIu64 " woken up.",
    926926                    THREAD->tid);
    927927#endif
    928                
     928
    929929                goto loop;
    930930        }
    931        
     931
    932932        pfn_t pfn = zone_frame_alloc(&zones.info[znum], count,
    933933            frame_constraint) + zones.info[znum].base;
    934        
     934
    935935        irq_spinlock_unlock(&zones.lock, true);
    936        
     936
    937937        if (pzone)
    938938                *pzone = znum;
    939        
     939
    940940        return PFN2ADDR(pfn);
    941941}
     
    960960{
    961961        size_t freed = 0;
    962        
     962
    963963        irq_spinlock_lock(&zones.lock, true);
    964        
     964
    965965        for (size_t i = 0; i < count; i++) {
    966966                /*
     
    969969                pfn_t pfn = ADDR2PFN(start) + i;
    970970                size_t znum = find_zone(pfn, 1, 0);
    971                
     971
    972972                assert(znum != (size_t) -1);
    973                
     973
    974974                freed += zone_frame_free(&zones.info[znum],
    975975                    pfn - zones.info[znum].base);
    976976        }
    977        
     977
    978978        irq_spinlock_unlock(&zones.lock, true);
    979        
     979
    980980        /*
    981981         * Signal that some memory has been freed.
     
    984984         * with TLB shootdown.
    985985         */
    986        
     986
    987987        ipl_t ipl = interrupts_disable();
    988988        mutex_lock(&mem_avail_mtx);
    989        
     989
    990990        if (mem_avail_req > 0)
    991991                mem_avail_req -= min(mem_avail_req, freed);
    992        
     992
    993993        if (mem_avail_req == 0) {
    994994                mem_avail_gen++;
    995995                condvar_broadcast(&mem_avail_cv);
    996996        }
    997        
     997
    998998        mutex_unlock(&mem_avail_mtx);
    999999        interrupts_restore(ipl);
    1000        
     1000
    10011001        if (!(flags & FRAME_NO_RESERVE))
    10021002                reserve_free(freed);
     
    10241024{
    10251025        irq_spinlock_lock(&zones.lock, true);
    1026        
     1026
    10271027        /*
    10281028         * First, find host frame zone for addr.
    10291029         */
    10301030        size_t znum = find_zone(pfn, 1, 0);
    1031        
     1031
    10321032        assert(znum != (size_t) -1);
    1033        
     1033
    10341034        zones.info[znum].frames[pfn - zones.info[znum].base].refcount++;
    1035        
     1035
    10361036        irq_spinlock_unlock(&zones.lock, true);
    10371037}
     
    10431043{
    10441044        irq_spinlock_lock(&zones.lock, true);
    1045        
     1045
    10461046        for (size_t i = 0; i < count; i++) {
    10471047                size_t znum = find_zone(start + i, 1, 0);
    1048                
     1048
    10491049                if (znum == (size_t) -1)  /* PFN not found */
    10501050                        continue;
    1051                
     1051
    10521052                zone_mark_unavailable(&zones.info[znum],
    10531053                    start + i - zones.info[znum].base);
    10541054        }
    1055        
     1055
    10561056        irq_spinlock_unlock(&zones.lock, true);
    10571057}
     
    10681068                condvar_initialize(&mem_avail_cv);
    10691069        }
    1070        
     1070
    10711071        /* Tell the architecture to create some memory */
    10721072        frame_low_arch_init();
    1073        
     1073
    10741074        if (config.cpu_active == 1) {
    10751075                frame_mark_unavailable(ADDR2PFN(KA2PA(config.base)),
     
    10771077                frame_mark_unavailable(ADDR2PFN(KA2PA(config.stack_base)),
    10781078                    SIZE2FRAMES(config.stack_size));
    1079                
     1079
    10801080                for (size_t i = 0; i < init.cnt; i++)
    10811081                        frame_mark_unavailable(ADDR2PFN(init.tasks[i].paddr),
    10821082                            SIZE2FRAMES(init.tasks[i].size));
    1083                
     1083
    10841084                if (ballocs.size)
    10851085                        frame_mark_unavailable(ADDR2PFN(KA2PA(ballocs.base)),
    10861086                            SIZE2FRAMES(ballocs.size));
    1087                
     1087
    10881088                /*
    10891089                 * Blacklist first frame, as allocating NULL would
     
    10921092                frame_mark_unavailable(0, 1);
    10931093        }
    1094        
     1094
    10951095        frame_high_arch_init();
    10961096}
     
    11131113{
    11141114        uintptr_t limit = KA2PA(config.identity_base) + config.identity_size;
    1115        
     1115
    11161116        if (low) {
    11171117                if (*basep > limit)
    11181118                        return false;
    1119                
     1119
    11201120                if (*basep + *sizep > limit)
    11211121                        *sizep = limit - *basep;
     
    11231123                if (*basep + *sizep <= limit)
    11241124                        return false;
    1125                
     1125
    11261126                if (*basep <= limit) {
    11271127                        *sizep -= limit - *basep;
     
    11291129                }
    11301130        }
    1131        
     1131
    11321132        return true;
    11331133}
     
    11391139{
    11401140        irq_spinlock_lock(&zones.lock, true);
    1141        
     1141
    11421142        uint64_t total = 0;
    1143        
     1143
    11441144        for (size_t i = 0; i < zones.count; i++)
    11451145                total += (uint64_t) FRAMES2SIZE(zones.info[i].count);
    1146        
     1146
    11471147        irq_spinlock_unlock(&zones.lock, true);
    1148        
     1148
    11491149        return total;
    11501150}
     
    11571157        assert(busy != NULL);
    11581158        assert(free != NULL);
    1159        
     1159
    11601160        irq_spinlock_lock(&zones.lock, true);
    1161        
     1161
    11621162        *total = 0;
    11631163        *unavail = 0;
    11641164        *busy = 0;
    11651165        *free = 0;
    1166        
     1166
    11671167        for (size_t i = 0; i < zones.count; i++) {
    11681168                *total += (uint64_t) FRAMES2SIZE(zones.info[i].count);
    1169                
     1169
    11701170                if (zones.info[i].flags & ZONE_AVAILABLE) {
    11711171                        *busy += (uint64_t) FRAMES2SIZE(zones.info[i].busy_count);
     
    11741174                        *unavail += (uint64_t) FRAMES2SIZE(zones.info[i].count);
    11751175        }
    1176        
     1176
    11771177        irq_spinlock_unlock(&zones.lock, true);
    11781178}
     
    11901190        printf("[nr] [base address    ] [frames    ] [flags ] [free frames ] [busy frames ]\n");
    11911191#endif
    1192        
     1192
    11931193        /*
    11941194         * Because printing may require allocation of memory, we may not hold
     
    12011201         * the listing).
    12021202         */
    1203        
     1203
    12041204        size_t free_lowmem = 0;
    12051205        size_t free_highmem = 0;
    12061206        size_t free_highprio = 0;
    1207        
     1207
    12081208        for (size_t i = 0;; i++) {
    12091209                irq_spinlock_lock(&zones.lock, true);
    1210                
     1210
    12111211                if (i >= zones.count) {
    12121212                        irq_spinlock_unlock(&zones.lock, true);
    12131213                        break;
    12141214                }
    1215                
     1215
    12161216                pfn_t fbase = zones.info[i].base;
    12171217                uintptr_t base = PFN2ADDR(fbase);
     
    12201220                size_t free_count = zones.info[i].free_count;
    12211221                size_t busy_count = zones.info[i].busy_count;
    1222                
     1222
    12231223                bool available = ((flags & ZONE_AVAILABLE) != 0);
    12241224                bool lowmem = ((flags & ZONE_LOWMEM) != 0);
    12251225                bool highmem = ((flags & ZONE_HIGHMEM) != 0);
    12261226                bool highprio = is_high_priority(fbase, count);
    1227                
     1227
    12281228                if (available) {
    12291229                        if (lowmem)
    12301230                                free_lowmem += free_count;
    1231                        
     1231
    12321232                        if (highmem)
    12331233                                free_highmem += free_count;
    1234                        
     1234
    12351235                        if (highprio) {
    12361236                                free_highprio += free_count;
     
    12411241                                 * statistics.
    12421242                                 */
    1243                                
     1243
    12441244                                for (size_t index = 0; index < count; index++) {
    12451245                                        if (is_high_priority(fbase + index, 0)) {
     
    12511251                        }
    12521252                }
    1253                
     1253
    12541254                irq_spinlock_unlock(&zones.lock, true);
    1255                
     1255
    12561256                printf("%-4zu", i);
    1257                
     1257
    12581258#ifdef __32_BITS__
    12591259                printf("  %p", (void *) base);
    12601260#endif
    1261                
     1261
    12621262#ifdef __64_BITS__
    12631263                printf(" %p", (void *) base);
    12641264#endif
    1265                
     1265
    12661266                printf(" %12zu %c%c%c%c%c    ", count,
    12671267                    available ? 'A' : '-',
     
    12701270                    (flags & ZONE_LOWMEM) ? 'L' : '-',
    12711271                    (flags & ZONE_HIGHMEM) ? 'H' : '-');
    1272                
     1272
    12731273                if (available)
    12741274                        printf("%14zu %14zu",
    12751275                            free_count, busy_count);
    1276                
     1276
    12771277                printf("\n");
    12781278        }
    1279        
     1279
    12801280        printf("\n");
    1281        
     1281
    12821282        uint64_t size;
    12831283        const char *size_suffix;
    1284        
     1284
    12851285        bin_order_suffix(FRAMES2SIZE(free_lowmem), &size, &size_suffix,
    12861286            false);
    12871287        printf("Available low memory:    %zu frames (%" PRIu64 " %s)\n",
    12881288            free_lowmem, size, size_suffix);
    1289        
     1289
    12901290        bin_order_suffix(FRAMES2SIZE(free_highmem), &size, &size_suffix,
    12911291            false);
    12921292        printf("Available high memory:   %zu frames (%" PRIu64 " %s)\n",
    12931293            free_highmem, size, size_suffix);
    1294        
     1294
    12951295        bin_order_suffix(FRAMES2SIZE(free_highprio), &size, &size_suffix,
    12961296            false);
     
    13081308        irq_spinlock_lock(&zones.lock, true);
    13091309        size_t znum = (size_t) -1;
    1310        
     1310
    13111311        for (size_t i = 0; i < zones.count; i++) {
    13121312                if ((i == num) || (PFN2ADDR(zones.info[i].base) == num)) {
     
    13151315                }
    13161316        }
    1317        
     1317
    13181318        if (znum == (size_t) -1) {
    13191319                irq_spinlock_unlock(&zones.lock, true);
     
    13211321                return;
    13221322        }
    1323        
     1323
    13241324        size_t free_lowmem = 0;
    13251325        size_t free_highmem = 0;
    13261326        size_t free_highprio = 0;
    1327        
     1327
    13281328        pfn_t fbase = zones.info[znum].base;
    13291329        uintptr_t base = PFN2ADDR(fbase);
     
    13321332        size_t free_count = zones.info[znum].free_count;
    13331333        size_t busy_count = zones.info[znum].busy_count;
    1334        
     1334
    13351335        bool available = ((flags & ZONE_AVAILABLE) != 0);
    13361336        bool lowmem = ((flags & ZONE_LOWMEM) != 0);
    13371337        bool highmem = ((flags & ZONE_HIGHMEM) != 0);
    13381338        bool highprio = is_high_priority(fbase, count);
    1339        
     1339
    13401340        if (available) {
    13411341                if (lowmem)
    13421342                        free_lowmem = free_count;
    1343                
     1343
    13441344                if (highmem)
    13451345                        free_highmem = free_count;
    1346                
     1346
    13471347                if (highprio) {
    13481348                        free_highprio = free_count;
     
    13531353                         * statistics.
    13541354                         */
    1355                        
     1355
    13561356                        for (size_t index = 0; index < count; index++) {
    13571357                                if (is_high_priority(fbase + index, 0)) {
     
    13631363                }
    13641364        }
    1365        
     1365
    13661366        irq_spinlock_unlock(&zones.lock, true);
    1367        
     1367
    13681368        uint64_t size;
    13691369        const char *size_suffix;
    1370        
     1370
    13711371        bin_order_suffix(FRAMES2SIZE(count), &size, &size_suffix, false);
    1372        
     1372
    13731373        printf("Zone number:             %zu\n", znum);
    13741374        printf("Zone base address:       %p\n", (void *) base);
     
    13811381            (flags & ZONE_LOWMEM) ? 'L' : '-',
    13821382            (flags & ZONE_HIGHMEM) ? 'H' : '-');
    1383        
     1383
    13841384        if (available) {
    13851385                bin_order_suffix(FRAMES2SIZE(busy_count), &size, &size_suffix,
     
    13871387                printf("Allocated space:         %zu frames (%" PRIu64 " %s)\n",
    13881388                    busy_count, size, size_suffix);
    1389                
     1389
    13901390                bin_order_suffix(FRAMES2SIZE(free_count), &size, &size_suffix,
    13911391                    false);
    13921392                printf("Available space:         %zu frames (%" PRIu64 " %s)\n",
    13931393                    free_count, size, size_suffix);
    1394                
     1394
    13951395                bin_order_suffix(FRAMES2SIZE(free_lowmem), &size, &size_suffix,
    13961396                    false);
    13971397                printf("Available low memory:    %zu frames (%" PRIu64 " %s)\n",
    13981398                    free_lowmem, size, size_suffix);
    1399                
     1399
    14001400                bin_order_suffix(FRAMES2SIZE(free_highmem), &size, &size_suffix,
    14011401                    false);
    14021402                printf("Available high memory:   %zu frames (%" PRIu64 " %s)\n",
    14031403                    free_highmem, size, size_suffix);
    1404                
     1404
    14051405                bin_order_suffix(FRAMES2SIZE(free_highprio), &size, &size_suffix,
    14061406                    false);
  • kernel/generic/src/mm/km.c

    r3061bc1 ra35b458  
    149149        }
    150150        page_table_unlock(AS_KERNEL, true);
    151        
     151
    152152        return vaddr;
    153153}
     
    247247        assert(framep);
    248248        assert(!(flags & ~(FRAME_NO_RESERVE | FRAME_ATOMIC)));
    249        
     249
    250250        /*
    251251         * Allocate a frame, preferably from high memory.
     
    267267                if (!frame)
    268268                        return (uintptr_t) NULL;
    269                
     269
    270270                page = PA2KA(frame);
    271271        }
    272        
     272
    273273        *framep = frame;
    274274        return page;
  • kernel/generic/src/mm/page.c

    r3061bc1 ra35b458  
    9999{
    100100        assert(page_table_locked(as));
    101        
     101
    102102        assert(page_mapping_operations);
    103103        assert(page_mapping_operations->mapping_insert);
     
    105105        page_mapping_operations->mapping_insert(as, ALIGN_DOWN(page, PAGE_SIZE),
    106106            ALIGN_DOWN(frame, FRAME_SIZE), flags);
    107        
     107
    108108        /* Repel prefetched accesses to the old mapping. */
    109109        memory_barrier();
     
    123123{
    124124        assert(page_table_locked(as));
    125        
     125
    126126        assert(page_mapping_operations);
    127127        assert(page_mapping_operations->mapping_remove);
    128        
     128
    129129        page_mapping_operations->mapping_remove(as,
    130130            ALIGN_DOWN(page, PAGE_SIZE));
    131        
     131
    132132        /* Repel prefetched accesses to the old mapping. */
    133133        memory_barrier();
     
    148148{
    149149        assert(nolock || page_table_locked(as));
    150        
     150
    151151        assert(page_mapping_operations);
    152152        assert(page_mapping_operations->mapping_find);
    153        
     153
    154154        return page_mapping_operations->mapping_find(as,
    155155            ALIGN_DOWN(page, PAGE_SIZE), nolock, pte);
     
    169169{
    170170        assert(nolock || page_table_locked(as));
    171        
     171
    172172        assert(page_mapping_operations);
    173173        assert(page_mapping_operations->mapping_find);
    174        
     174
    175175        page_mapping_operations->mapping_update(as,
    176176            ALIGN_DOWN(page, PAGE_SIZE), nolock, pte);
     
    186186        assert(page_mapping_operations);
    187187        assert(page_mapping_operations->mapping_make_global);
    188        
     188
    189189        return page_mapping_operations->mapping_make_global(base, size);
    190190}
     
    193193{
    194194        page_table_lock(AS, true);
    195        
     195
    196196        pte_t pte;
    197197        bool found = page_mapping_find(AS, virt, false, &pte);
     
    200200                return ENOENT;
    201201        }
    202        
     202
    203203        *phys = PTE_GET_FRAME(&pte) +
    204204            (virt - ALIGN_DOWN(virt, PAGE_SIZE));
    205        
     205
    206206        page_table_unlock(AS, true);
    207        
     207
    208208        return EOK;
    209209}
     
    221221        if (rc != EOK)
    222222                return rc;
    223        
     223
    224224        rc = copy_to_uspace(phys_ptr, &phys, sizeof(phys));
    225225        return (sys_errno_t) rc;
  • kernel/generic/src/mm/slab.c

    r3061bc1 ra35b458  
    186186{
    187187        size_t zone = 0;
    188        
     188
    189189        uintptr_t data_phys =
    190190            frame_alloc_generic(cache->frames, flags, 0, &zone);
    191191        if (!data_phys)
    192192                return NULL;
    193        
     193
    194194        void *data = (void *) PA2KA(data_phys);
    195        
     195
    196196        slab_t *slab;
    197197        size_t fsize;
    198        
     198
    199199        if (!(cache->flags & SLAB_CACHE_SLINSIDE)) {
    200200                slab = slab_alloc(slab_extern_cache, flags);
     
    207207                slab = data + fsize - sizeof(*slab);
    208208        }
    209        
     209
    210210        /* Fill in slab structures */
    211211        size_t i;
    212212        for (i = 0; i < cache->frames; i++)
    213213                frame_set_parent(ADDR2PFN(KA2PA(data)) + i, slab, zone);
    214        
     214
    215215        slab->start = data;
    216216        slab->available = cache->objects;
    217217        slab->nextavail = 0;
    218218        slab->cache = cache;
    219        
     219
    220220        for (i = 0; i < cache->objects; i++)
    221221                *((size_t *) (slab->start + i * cache->size)) = i + 1;
    222        
     222
    223223        atomic_inc(&cache->allocated_slabs);
    224224        return slab;
     
    235235        if (!(cache->flags & SLAB_CACHE_SLINSIDE))
    236236                slab_free(slab_extern_cache, slab);
    237        
     237
    238238        atomic_dec(&cache->allocated_slabs);
    239        
     239
    240240        return cache->frames;
    241241}
     
    263263        if (!slab)
    264264                slab = obj2slab(obj);
    265        
     265
    266266        assert(slab->cache == cache);
    267        
     267
    268268        size_t freed = 0;
    269        
     269
    270270        if (cache->destructor)
    271271                freed = cache->destructor(obj);
    272        
     272
    273273        irq_spinlock_lock(&cache->slablock, true);
    274274        assert(slab->available < cache->objects);
    275        
     275
    276276        *((size_t *) obj) = slab->nextavail;
    277277        slab->nextavail = (obj - slab->start) / cache->size;
    278278        slab->available++;
    279        
     279
    280280        /* Move it to correct list */
    281281        if (slab->available == cache->objects) {
     
    283283                list_remove(&slab->link);
    284284                irq_spinlock_unlock(&cache->slablock, true);
    285                
     285
    286286                return freed + slab_space_free(cache, slab);
    287287        } else if (slab->available == 1) {
     
    290290                list_prepend(&slab->link, &cache->partial_slabs);
    291291        }
    292        
     292
    293293        irq_spinlock_unlock(&cache->slablock, true);
    294294        return freed;
     
    303303{
    304304        irq_spinlock_lock(&cache->slablock, true);
    305        
     305
    306306        slab_t *slab;
    307        
     307
    308308        if (list_empty(&cache->partial_slabs)) {
    309309                /*
     
    319319                if (!slab)
    320320                        return NULL;
    321                
     321
    322322                irq_spinlock_lock(&cache->slablock, true);
    323323        } else {
     
    326326                list_remove(&slab->link);
    327327        }
    328        
     328
    329329        void *obj = slab->start + slab->nextavail * cache->size;
    330330        slab->nextavail = *((size_t *) obj);
    331331        slab->available--;
    332        
     332
    333333        if (!slab->available)
    334334                list_prepend(&slab->link, &cache->full_slabs);
    335335        else
    336336                list_prepend(&slab->link, &cache->partial_slabs);
    337        
     337
    338338        irq_spinlock_unlock(&cache->slablock, true);
    339        
     339
    340340        if ((cache->constructor) && (cache->constructor(obj, flags) != EOK)) {
    341341                /* Bad, bad, construction failed */
     
    343343                return NULL;
    344344        }
    345        
     345
    346346        return obj;
    347347}
     
    361361        slab_magazine_t *mag = NULL;
    362362        link_t *cur;
    363        
     363
    364364        irq_spinlock_lock(&cache->maglock, true);
    365365        if (!list_empty(&cache->magazines)) {
     
    368368                else
    369369                        cur = list_last(&cache->magazines);
    370                
     370
    371371                mag = list_get_instance(cur, slab_magazine_t, link);
    372372                list_remove(&mag->link);
     
    385385{
    386386        irq_spinlock_lock(&cache->maglock, true);
    387        
     387
    388388        list_prepend(&mag->link, &cache->magazines);
    389389        atomic_inc(&cache->magazine_counter);
    390        
     390
    391391        irq_spinlock_unlock(&cache->maglock, true);
    392392}
     
    402402        size_t i;
    403403        size_t frames = 0;
    404        
     404
    405405        for (i = 0; i < mag->busy; i++) {
    406406                frames += slab_obj_destroy(cache, mag->objs[i], NULL);
    407407                atomic_dec(&cache->cached_objs);
    408408        }
    409        
     409
    410410        slab_free(&mag_cache, mag);
    411        
     411
    412412        return frames;
    413413}
     
    420420        slab_magazine_t *cmag = cache->mag_cache[CPU->id].current;
    421421        slab_magazine_t *lastmag = cache->mag_cache[CPU->id].last;
    422        
     422
    423423        assert(irq_spinlock_locked(&cache->mag_cache[CPU->id].lock));
    424        
     424
    425425        if (cmag) { /* First try local CPU magazines */
    426426                if (cmag->busy)
    427427                        return cmag;
    428                
     428
    429429                if ((lastmag) && (lastmag->busy)) {
    430430                        cache->mag_cache[CPU->id].current = lastmag;
     
    433433                }
    434434        }
    435        
     435
    436436        /* Local magazines are empty, import one from magazine list */
    437437        slab_magazine_t *newmag = get_mag_from_cache(cache, 1);
    438438        if (!newmag)
    439439                return NULL;
    440        
     440
    441441        if (lastmag)
    442442                magazine_destroy(cache, lastmag);
    443        
     443
    444444        cache->mag_cache[CPU->id].last = cmag;
    445445        cache->mag_cache[CPU->id].current = newmag;
    446        
     446
    447447        return newmag;
    448448}
     
    457457        if (!CPU)
    458458                return NULL;
    459        
     459
    460460        irq_spinlock_lock(&cache->mag_cache[CPU->id].lock, true);
    461        
     461
    462462        slab_magazine_t *mag = get_full_current_mag(cache);
    463463        if (!mag) {
     
    465465                return NULL;
    466466        }
    467        
     467
    468468        void *obj = mag->objs[--mag->busy];
    469469        irq_spinlock_unlock(&cache->mag_cache[CPU->id].lock, true);
    470        
     470
    471471        atomic_dec(&cache->cached_objs);
    472        
     472
    473473        return obj;
    474474}
     
    487487        slab_magazine_t *cmag = cache->mag_cache[CPU->id].current;
    488488        slab_magazine_t *lastmag = cache->mag_cache[CPU->id].last;
    489        
     489
    490490        assert(irq_spinlock_locked(&cache->mag_cache[CPU->id].lock));
    491        
     491
    492492        if (cmag) {
    493493                if (cmag->busy < cmag->size)
    494494                        return cmag;
    495                
     495
    496496                if ((lastmag) && (lastmag->busy < lastmag->size)) {
    497497                        cache->mag_cache[CPU->id].last = cmag;
     
    500500                }
    501501        }
    502        
     502
    503503        /* current | last are full | nonexistent, allocate new */
    504        
     504
    505505        /*
    506506         * We do not want to sleep just because of caching,
     
    513513        if (!newmag)
    514514                return NULL;
    515        
     515
    516516        newmag->size = SLAB_MAG_SIZE;
    517517        newmag->busy = 0;
    518        
     518
    519519        /* Flush last to magazine list */
    520520        if (lastmag)
    521521                put_mag_to_cache(cache, lastmag);
    522        
     522
    523523        /* Move current as last, save new as current */
    524524        cache->mag_cache[CPU->id].last = cmag;
    525525        cache->mag_cache[CPU->id].current = newmag;
    526        
     526
    527527        return newmag;
    528528}
     
    537537        if (!CPU)
    538538                return -1;
    539        
     539
    540540        irq_spinlock_lock(&cache->mag_cache[CPU->id].lock, true);
    541        
     541
    542542        slab_magazine_t *mag = make_empty_current_mag(cache);
    543543        if (!mag) {
     
    545545                return -1;
    546546        }
    547        
     547
    548548        mag->objs[mag->busy++] = obj;
    549        
     549
    550550        irq_spinlock_unlock(&cache->mag_cache[CPU->id].lock, true);
    551        
     551
    552552        atomic_inc(&cache->cached_objs);
    553        
     553
    554554        return 0;
    555555}
     
    578578        size_t objects = comp_objects(cache);
    579579        size_t ssize = FRAMES2SIZE(cache->frames);
    580        
     580
    581581        if (cache->flags & SLAB_CACHE_SLINSIDE)
    582582                ssize -= sizeof(slab_t);
    583        
     583
    584584        return ssize - objects * cache->size;
    585585}
     
    591591{
    592592        assert(_slab_initialized >= 2);
    593        
     593
    594594        cache->mag_cache = slab_alloc(&slab_mag_cache, FRAME_ATOMIC);
    595595        if (!cache->mag_cache)
    596596                return false;
    597        
     597
    598598        size_t i;
    599599        for (i = 0; i < config.cpu_count; i++) {
     
    602602                    "slab.cache.mag_cache[].lock");
    603603        }
    604        
     604
    605605        return true;
    606606}
     
    614614{
    615615        assert(size > 0);
    616        
     616
    617617        memsetb(cache, sizeof(*cache), 0);
    618618        cache->name = name;
    619        
     619
    620620        if (align < sizeof(sysarg_t))
    621621                align = sizeof(sysarg_t);
    622        
     622
    623623        size = ALIGN_UP(size, align);
    624        
     624
    625625        cache->size = size;
    626626        cache->constructor = constructor;
    627627        cache->destructor = destructor;
    628628        cache->flags = flags;
    629        
     629
    630630        list_initialize(&cache->full_slabs);
    631631        list_initialize(&cache->partial_slabs);
    632632        list_initialize(&cache->magazines);
    633        
     633
    634634        irq_spinlock_initialize(&cache->slablock, "slab.cache.slablock");
    635635        irq_spinlock_initialize(&cache->maglock, "slab.cache.maglock");
    636        
     636
    637637        if (!(cache->flags & SLAB_CACHE_NOMAGAZINE))
    638638                (void) make_magcache(cache);
    639        
     639
    640640        /* Compute slab sizes, object counts in slabs etc. */
    641641        if (cache->size < SLAB_INSIDE_SIZE)
    642642                cache->flags |= SLAB_CACHE_SLINSIDE;
    643        
     643
    644644        /* Minimum slab frames */
    645645        cache->frames = SIZE2FRAMES(cache->size);
    646        
     646
    647647        while (badness(cache) > SLAB_MAX_BADNESS(cache))
    648648                cache->frames <<= 1;
    649        
     649
    650650        cache->objects = comp_objects(cache);
    651        
     651
    652652        /* If info fits in, put it inside */
    653653        if (badness(cache) > sizeof(slab_t))
    654654                cache->flags |= SLAB_CACHE_SLINSIDE;
    655        
     655
    656656        /* Add cache to cache list */
    657657        irq_spinlock_lock(&slab_cache_lock, true);
     
    670670        _slab_cache_create(cache, name, size, align, constructor, destructor,
    671671            flags);
    672        
     672
    673673        return cache;
    674674}
     
    685685        if (cache->flags & SLAB_CACHE_NOMAGAZINE)
    686686                return 0; /* Nothing to do */
    687        
     687
    688688        /*
    689689         * We count up to original magazine count to avoid
     
    691691         */
    692692        atomic_count_t magcount = atomic_get(&cache->magazine_counter);
    693        
     693
    694694        slab_magazine_t *mag;
    695695        size_t frames = 0;
    696        
     696
    697697        while ((magcount--) && (mag = get_mag_from_cache(cache, 0))) {
    698698                frames += magazine_destroy(cache, mag);
     
    700700                        break;
    701701        }
    702        
     702
    703703        if (flags & SLAB_RECLAIM_ALL) {
    704704                /* Free cpu-bound magazines */
     
    707707                for (i = 0; i < config.cpu_count; i++) {
    708708                        irq_spinlock_lock(&cache->mag_cache[i].lock, true);
    709                        
     709
    710710                        mag = cache->mag_cache[i].current;
    711711                        if (mag)
    712712                                frames += magazine_destroy(cache, mag);
    713713                        cache->mag_cache[i].current = NULL;
    714                        
     714
    715715                        mag = cache->mag_cache[i].last;
    716716                        if (mag)
    717717                                frames += magazine_destroy(cache, mag);
    718718                        cache->mag_cache[i].last = NULL;
    719                        
     719
    720720                        irq_spinlock_unlock(&cache->mag_cache[i].lock, true);
    721721                }
    722722        }
    723        
     723
    724724        return frames;
    725725}
     
    731731{
    732732        ipl_t ipl = interrupts_disable();
    733        
     733
    734734        if ((cache->flags & SLAB_CACHE_NOMAGAZINE) ||
    735735            (magazine_obj_put(cache, obj)))
    736736                slab_obj_destroy(cache, obj, slab);
    737        
     737
    738738        interrupts_restore(ipl);
    739739        atomic_dec(&cache->allocated_objs);
     
    753753        list_remove(&cache->link);
    754754        irq_spinlock_unlock(&slab_cache_lock, true);
    755        
     755
    756756        /*
    757757         * Do not lock anything, we assume the software is correct and
     
    759759         *
    760760         */
    761        
     761
    762762        /* Destroy all magazines */
    763763        _slab_reclaim(cache, SLAB_RECLAIM_ALL);
    764        
     764
    765765        /* All slabs must be empty */
    766766        if ((!list_empty(&cache->full_slabs)) ||
    767767            (!list_empty(&cache->partial_slabs)))
    768768                panic("Destroying cache that is not empty.");
    769        
     769
    770770        if (!(cache->flags & SLAB_CACHE_NOMAGAZINE)) {
    771771                slab_t *mag_slab = obj2slab(cache->mag_cache);
    772772                _slab_free(mag_slab->cache, cache->mag_cache, mag_slab);
    773773        }
    774        
     774
    775775        slab_free(&slab_cache_cache, cache);
    776776}
     
    783783        /* Disable interrupts to avoid deadlocks with interrupt handlers */
    784784        ipl_t ipl = interrupts_disable();
    785        
     785
    786786        void *result = NULL;
    787        
     787
    788788        if (!(cache->flags & SLAB_CACHE_NOMAGAZINE))
    789789                result = magazine_obj_get(cache);
    790        
     790
    791791        if (!result)
    792792                result = slab_obj_create(cache, flags);
    793        
     793
    794794        interrupts_restore(ipl);
    795        
     795
    796796        if (result)
    797797                atomic_inc(&cache->allocated_objs);
    798        
     798
    799799        return result;
    800800}
     
    812812{
    813813        irq_spinlock_lock(&slab_cache_lock, true);
    814        
     814
    815815        size_t frames = 0;
    816816        list_foreach(slab_cache_list, link, slab_cache_t, cache) {
    817817                frames += _slab_reclaim(cache, flags);
    818818        }
    819        
     819
    820820        irq_spinlock_unlock(&slab_cache_lock, true);
    821        
     821
    822822        return frames;
    823823}
     
    828828        printf("[cache name      ] [size  ] [pages ] [obj/pg] [slabs ]"
    829829            " [cached] [alloc ] [ctl]\n");
    830        
     830
    831831        size_t skip = 0;
    832832        while (true) {
     
    853853                 * statistics.
    854854                 */
    855                
     855
    856856                irq_spinlock_lock(&slab_cache_lock, true);
    857                
     857
    858858                link_t *cur;
    859859                size_t i;
     
    861861                    (i < skip) && (cur != &slab_cache_list.head);
    862862                    i++, cur = cur->next);
    863                
     863
    864864                if (cur == &slab_cache_list.head) {
    865865                        irq_spinlock_unlock(&slab_cache_lock, true);
    866866                        break;
    867867                }
    868                
     868
    869869                skip++;
    870                
     870
    871871                slab_cache_t *cache = list_get_instance(cur, slab_cache_t, link);
    872                
     872
    873873                const char *name = cache->name;
    874874                size_t frames = cache->frames;
     
    879879                long allocated_objs = atomic_get(&cache->allocated_objs);
    880880                unsigned int flags = cache->flags;
    881                
     881
    882882                irq_spinlock_unlock(&slab_cache_lock, true);
    883                
     883
    884884                printf("%-18s %8zu %8zu %8zu %8ld %8ld %8ld %-5s\n",
    885885                    name, size, frames, objects, allocated_slabs,
     
    896896            sizeof(uintptr_t), NULL, NULL, SLAB_CACHE_NOMAGAZINE |
    897897            SLAB_CACHE_SLINSIDE);
    898        
     898
    899899        /* Initialize slab_cache cache */
    900900        _slab_cache_create(&slab_cache_cache, "slab_cache_cache",
    901901            sizeof(slab_cache_cache), sizeof(uintptr_t), NULL, NULL,
    902902            SLAB_CACHE_NOMAGAZINE | SLAB_CACHE_SLINSIDE);
    903        
     903
    904904        /* Initialize external slab cache */
    905905        slab_extern_cache = slab_cache_create("slab_t", sizeof(slab_t), 0,
    906906            NULL, NULL, SLAB_CACHE_SLINSIDE | SLAB_CACHE_MAGDEFERRED);
    907        
     907
    908908        /* Initialize structures for malloc */
    909909        size_t i;
    910910        size_t size;
    911        
     911
    912912        for (i = 0, size = (1 << SLAB_MIN_MALLOC_W);
    913913            i < (SLAB_MAX_MALLOC_W - SLAB_MIN_MALLOC_W + 1);
     
    916916                    NULL, NULL, SLAB_CACHE_MAGDEFERRED);
    917917        }
    918        
     918
    919919#ifdef CONFIG_DEBUG
    920920        _slab_initialized = 1;
     
    934934        _slab_initialized = 2;
    935935#endif
    936        
     936
    937937        _slab_cache_create(&slab_mag_cache, "slab_mag_cache",
    938938            sizeof(slab_mag_cache_t) * config.cpu_count, sizeof(uintptr_t),
    939939            NULL, NULL, SLAB_CACHE_NOMAGAZINE | SLAB_CACHE_SLINSIDE);
    940        
     940
    941941        irq_spinlock_lock(&slab_cache_lock, false);
    942        
     942
    943943        list_foreach(slab_cache_list, link, slab_cache_t, slab) {
    944944                if ((slab->flags & SLAB_CACHE_MAGDEFERRED) !=
    945945                    SLAB_CACHE_MAGDEFERRED)
    946946                        continue;
    947                
     947
    948948                (void) make_magcache(slab);
    949949                slab->flags &= ~SLAB_CACHE_MAGDEFERRED;
    950950        }
    951        
     951
    952952        irq_spinlock_unlock(&slab_cache_lock, false);
    953953}
     
    957957        assert(_slab_initialized);
    958958        assert(size <= (1 << SLAB_MAX_MALLOC_W));
    959        
     959
    960960        if (size < (1 << SLAB_MIN_MALLOC_W))
    961961                size = (1 << SLAB_MIN_MALLOC_W);
    962        
     962
    963963        uint8_t idx = fnzb(size - 1) - SLAB_MIN_MALLOC_W + 1;
    964        
     964
    965965        return slab_alloc(malloc_caches[idx], flags);
    966966}
     
    970970        assert(_slab_initialized);
    971971        assert(size <= (1 << SLAB_MAX_MALLOC_W));
    972        
     972
    973973        void *new_ptr;
    974        
     974
    975975        if (size > 0) {
    976976                if (size < (1 << SLAB_MIN_MALLOC_W))
    977977                        size = (1 << SLAB_MIN_MALLOC_W);
    978978                uint8_t idx = fnzb(size - 1) - SLAB_MIN_MALLOC_W + 1;
    979                
     979
    980980                new_ptr = slab_alloc(malloc_caches[idx], flags);
    981981        } else
    982982                new_ptr = NULL;
    983        
     983
    984984        if ((new_ptr != NULL) && (ptr != NULL)) {
    985985                slab_t *slab = obj2slab(ptr);
    986986                memcpy(new_ptr, ptr, min(size, slab->cache->size));
    987987        }
    988        
     988
    989989        if (ptr != NULL)
    990990                free(ptr);
    991        
     991
    992992        return new_ptr;
    993993}
     
    997997        if (!ptr)
    998998                return;
    999        
     999
    10001000        slab_t *slab = obj2slab(ptr);
    10011001        _slab_free(slab->cache, ptr, slab);
  • kernel/generic/src/mm/tlb.c

    r3061bc1 ra35b458  
    8787        CPU->tlb_active = false;
    8888        irq_spinlock_lock(&tlblock, false);
    89        
     89
    9090        size_t i;
    9191        for (i = 0; i < config.cpu_count; i++) {
    9292                if (i == CPU->id)
    9393                        continue;
    94                
     94
    9595                cpu_t *cpu = &cpus[i];
    96                
     96
    9797                irq_spinlock_lock(&cpu->lock, false);
    9898                if (cpu->tlb_messages_count == TLB_MESSAGE_QUEUE_LEN) {
     
    118118                irq_spinlock_unlock(&cpu->lock, false);
    119119        }
    120        
     120
    121121        tlb_shootdown_ipi_send();
    122        
     122
    123123busy_wait:
    124124        for (i = 0; i < config.cpu_count; i++) {
     
    126126                        goto busy_wait;
    127127        }
    128        
     128
    129129        return ipl;
    130130}
     
    153153{
    154154        assert(CPU);
    155        
     155
    156156        CPU->tlb_active = false;
    157157        irq_spinlock_lock(&tlblock, false);
    158158        irq_spinlock_unlock(&tlblock, false);
    159        
     159
    160160        irq_spinlock_lock(&CPU->lock, false);
    161161        assert(CPU->tlb_messages_count <= TLB_MESSAGE_QUEUE_LEN);
    162        
     162
    163163        size_t i;
    164164        for (i = 0; i < CPU->tlb_messages_count; i++) {
     
    167167                uintptr_t page = CPU->tlb_messages[i].page;
    168168                size_t count = CPU->tlb_messages[i].count;
    169                
     169
    170170                switch (type) {
    171171                case TLB_INVL_ALL:
     
    183183                        break;
    184184                }
    185                
     185
    186186                if (type == TLB_INVL_ALL)
    187187                        break;
    188188        }
    189        
     189
    190190        CPU->tlb_messages_count = 0;
    191191        irq_spinlock_unlock(&CPU->lock, false);
Note: See TracChangeset for help on using the changeset viewer.