Changeset fbcdeb8 in mainline for uspace/srv


Ignore:
Timestamp:
2011-12-19T17:30:39Z (14 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
58f6229
Parents:
24cf31f1
Message:

Remove the two-phase way of creating virtual memory areas (first asking for a mappable address and then mapping it) which was prone to race conditions when two or more calls to as_get_mappable_page() and as_area_create() were interleaved. This for example caused the e1k driver to randomly fail.

The memory area related syscalls and IPC calls have all been altered to accept a special value (void *) -1, representing a demand to atomically search for a mappable address space "hole" and map to it.

Individual changes:

  • IPC_M_SHARE_OUT: the destination address space area is supplied by the kernel, the callee only specifies the lower bound

(the address is returned to the callee via a pointer in an IPC reply argument)

  • IPC_M_SHARE_IN: the destination address space ares is supplied by the kernel, the callee only specifies the lower bound

(the address is returned to the caller as usual via an IPC argument)

  • SYS_AS_GET_UNMAPPED_AREA was removed
  • dummy implementations of SYS_PHYSMEM_UNMAP and SYS_IOSPACE_DISABLE were added for the sake of symmetry (they do nothing yet)
  • SYS_PHYSMEM_MAP and SYS_DMAMEM_MAP were altered to accept (void *) -1 as address space area base and a lower bound
  • kernel as_area_create() and as_area_share() were altered to accept (void *) -1 as address space area base and a lower bound
  • uspace libraries and programs were altered to reflect the new API
Location:
uspace/srv
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/bd/ata_bd/ata_bd.c

    r24cf31f1 rfbcdeb8  
    309309        }
    310310
    311         fs_va = as_get_mappable_page(comm_size);
    312         if (fs_va == NULL) {
     311        (void) async_share_out_finalize(callid, &fs_va);
     312        if (fs_va == (void *) -1) {
    313313                async_answer_0(callid, EHANGUP);
    314314                return;
    315315        }
    316 
    317         (void) async_share_out_finalize(callid, fs_va);
    318316
    319317        while (true) {
  • uspace/srv/bd/file_bd/file_bd.c

    r24cf31f1 rfbcdeb8  
    190190        }
    191191
    192         fs_va = as_get_mappable_page(comm_size);
    193         if (fs_va == NULL) {
     192        (void) async_share_out_finalize(callid, &fs_va);
     193        if (fs_va == (void *) -1) {
    194194                async_answer_0(callid, EHANGUP);
    195195                return;
    196196        }
    197 
    198         (void) async_share_out_finalize(callid, fs_va);
    199197
    200198        while (true) {
  • uspace/srv/bd/gxe_bd/gxe_bd.c

    r24cf31f1 rfbcdeb8  
    193193        }
    194194
    195         fs_va = as_get_mappable_page(comm_size);
    196         if (fs_va == NULL) {
     195        (void) async_share_out_finalize(callid, &fs_va);
     196        if (fs_va == (void *) -1) {
    197197                async_answer_0(callid, EHANGUP);
    198198                return;
    199199        }
    200 
    201         (void) async_share_out_finalize(callid, fs_va);
    202200
    203201        while (true) {
  • uspace/srv/bd/part/guid_part/guid_part.c

    r24cf31f1 rfbcdeb8  
    348348        }
    349349
    350         fs_va = as_get_mappable_page(comm_size);
    351         if (fs_va == NULL) {
     350        (void) async_share_out_finalize(callid, &fs_va);
     351        if (fs_va == (void *) -1) {
    352352                async_answer_0(callid, EHANGUP);
    353353                return;
    354354        }
    355 
    356         (void) async_share_out_finalize(callid, fs_va);
    357355
    358356        while (true) {
  • uspace/srv/bd/part/mbr_part/mbr_part.c

    r24cf31f1 rfbcdeb8  
    425425        }
    426426
    427         fs_va = as_get_mappable_page(comm_size);
    428         if (fs_va == NULL) {
     427        (void) async_share_out_finalize(callid, &fs_va);
     428        if (fs_va == (void *) -1) {
    429429                async_answer_0(callid, EHANGUP);
    430430                return;
    431431        }
    432 
    433         (void) async_share_out_finalize(callid, fs_va);
    434432
    435433        while (1) {
  • uspace/srv/bd/rd/rd.c

    r24cf31f1 rfbcdeb8  
    105105        unsigned int flags;
    106106        if (async_share_out_receive(&callid, &comm_size, &flags)) {
    107                 fs_va = as_get_mappable_page(comm_size);
    108                 if (fs_va) {
    109                         (void) async_share_out_finalize(callid, fs_va);
    110                 } else {
     107                (void) async_share_out_finalize(callid, &fs_va);
     108                if (fs_va == (void *) -1) {
    111109                        async_answer_0(callid, EHANGUP);
    112110                        return;
     
    224222       
    225223        rd_size = ALIGN_UP(size, block_size);
    226         rd_addr = as_get_mappable_page(rd_size);
    227        
    228224        unsigned int flags =
    229225            AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE;
    230         ret = physmem_map((void *) addr_phys, rd_addr,
    231             ALIGN_UP(rd_size, PAGE_SIZE) >> PAGE_WIDTH, flags);
    232         if (ret < 0) {
     226       
     227        ret = physmem_map((void *) addr_phys,
     228            ALIGN_UP(rd_size, PAGE_SIZE) >> PAGE_WIDTH, flags, &rd_addr);
     229        if (ret != EOK) {
    233230                printf("%s: Error mapping RAM disk\n", NAME);
    234231                return false;
  • uspace/srv/hid/fb/fb.c

    r24cf31f1 rfbcdeb8  
    304304        }
    305305       
    306         frontbuf->data = as_get_mappable_page(frontbuf->size);
    307         int rc = async_answer_1(callid, EOK, (sysarg_t) frontbuf->data);
    308         if (rc != EOK) {
     306        int rc = async_share_out_finalize(callid, &frontbuf->data);
     307        if ((rc != EOK) || (frontbuf->data == (void *) -1)) {
    309308                free(frontbuf);
    310309                async_answer_0(iid, ENOMEM);
     
    348347        }
    349348       
    350         imagemap->data = as_get_mappable_page(imagemap->size);
    351         int rc = async_answer_1(callid, EOK, (sysarg_t) imagemap->data);
    352         if (rc != EOK) {
     349        int rc = async_share_out_finalize(callid, &imagemap->data);
     350        if ((rc != EOK) || (imagemap->data == (void *) -1)) {
    353351                free(imagemap);
    354352                async_answer_0(iid, ENOMEM);
  • uspace/srv/hid/fb/port/ega.c

    r24cf31f1 rfbcdeb8  
    280280       
    281281        ega.size = (width * height) << 1;
    282         ega.addr = as_get_mappable_page(ega.size);
    283         if (ega.addr == NULL)
    284                 return ENOMEM;
    285        
    286         rc = physmem_map((void *) paddr, ega.addr,
    287             ALIGN_UP(ega.size, PAGE_SIZE) >> PAGE_WIDTH, AS_AREA_READ | AS_AREA_WRITE);
     282       
     283        rc = physmem_map((void *) paddr,
     284            ALIGN_UP(ega.size, PAGE_SIZE) >> PAGE_WIDTH,
     285            AS_AREA_READ | AS_AREA_WRITE, (void *) &ega.addr);
    288286        if (rc != EOK)
    289287                return rc;
  • uspace/srv/hid/fb/port/kchar.c

    r24cf31f1 rfbcdeb8  
    8383                return rc;
    8484       
    85         kchar.addr = as_get_mappable_page(1);
    86         if (kchar.addr == NULL)
    87                 return ENOMEM;
    88        
    89         rc = physmem_map((void *) paddr, kchar.addr,
    90             ALIGN_UP(1, PAGE_SIZE) >> PAGE_WIDTH, AS_AREA_READ | AS_AREA_WRITE);
     85        rc = physmem_map((void *) paddr,
     86            ALIGN_UP(1, PAGE_SIZE) >> PAGE_WIDTH,
     87            AS_AREA_READ | AS_AREA_WRITE, (void *) &kchar.addr);
    9188        if (rc != EOK)
    9289                return rc;
  • uspace/srv/hid/fb/port/kfb.c

    r24cf31f1 rfbcdeb8  
    756756       
    757757        kfb.size = scanline * height;
    758         kfb.addr = as_get_mappable_page(kfb.size);
    759         if (kfb.addr == NULL) {
    760                 free(kfb.glyphs);
    761                 return ENOMEM;
    762         }
    763        
    764         rc = physmem_map((void *) paddr + offset, kfb.addr,
    765             ALIGN_UP(kfb.size, PAGE_SIZE) >> PAGE_WIDTH, AS_AREA_READ | AS_AREA_WRITE);
     758       
     759        rc = physmem_map((void *) paddr + offset,
     760            ALIGN_UP(kfb.size, PAGE_SIZE) >> PAGE_WIDTH,
     761            AS_AREA_READ | AS_AREA_WRITE, (void *) &kfb.addr);
    766762        if (rc != EOK) {
    767763                free(kfb.glyphs);
  • uspace/srv/hid/fb/port/niagara.c

    r24cf31f1 rfbcdeb8  
    103103                return rc;
    104104       
    105         niagara.fifo =
    106             (output_fifo_t *) as_get_mappable_page(sizeof(output_fifo_t));
    107         if (niagara.fifo == NULL)
    108                 return ENOMEM;
    109        
    110         rc = physmem_map((void *) paddr, (void *) niagara.fifo, 1,
    111             AS_AREA_READ | AS_AREA_WRITE);
     105        rc = physmem_map((void *) paddr, 1,
     106            AS_AREA_READ | AS_AREA_WRITE, (void *) &niagara.fifo);
    112107        if (rc != EOK)
    113108                return rc;
  • uspace/srv/hid/input/port/niagara.c

    r24cf31f1 rfbcdeb8  
    6363#define POLL_INTERVAL  10000
    6464
    65 /**
    66  * Virtual address mapped to the buffer shared with the kernel counterpart.
    67  */
    68 static uintptr_t input_buffer_addr;
    69 
    7065/*
    7166 * Kernel counterpart of the driver pushes characters (it has read) here.
     
    10297                return -1;
    10398       
    104         input_buffer_addr = (uintptr_t) as_get_mappable_page(PAGE_SIZE);
    105         int rc = physmem_map((void *) paddr, (void *) input_buffer_addr,
    106             1, AS_AREA_READ | AS_AREA_WRITE);
    107        
     99        int rc = physmem_map((void *) paddr, 1,
     100            AS_AREA_READ | AS_AREA_WRITE, (void *) &input_buffer);
    108101        if (rc != 0) {
    109102                printf("Niagara: uspace driver couldn't map physical memory: %d\n",
     
    111104                return rc;
    112105        }
    113        
    114         input_buffer = (input_buffer_t) input_buffer_addr;
    115106       
    116107        thread_id_t tid;
  • uspace/srv/hw/irc/obio/obio.c

    r24cf31f1 rfbcdeb8  
    124124       
    125125        base_phys = (void *) paddr;
    126         base_virt = as_get_mappable_page(OBIO_SIZE);
    127126       
    128127        int flags = AS_AREA_READ | AS_AREA_WRITE;
    129         int retval = physmem_map(base_phys, (void *) base_virt,
    130             ALIGN_UP(OBIO_SIZE, PAGE_SIZE) >> PAGE_WIDTH, flags);
     128        int retval = physmem_map(base_phys,
     129            ALIGN_UP(OBIO_SIZE, PAGE_SIZE) >> PAGE_WIDTH, flags, &base_virt);
    131130       
    132131        if (retval < 0) {
  • uspace/srv/vfs/vfs.c

    r24cf31f1 rfbcdeb8  
    172172         * Allocate and initialize the Path Lookup Buffer.
    173173         */
    174         plb = as_get_mappable_page(PLB_SIZE);
    175         if (!plb) {
    176                 printf(NAME ": Cannot allocate a mappable piece of address space\n");
    177                 return ENOMEM;
    178         }
    179        
    180         if (as_area_create(plb, PLB_SIZE, AS_AREA_READ | AS_AREA_WRITE |
    181             AS_AREA_CACHEABLE) != plb) {
     174        plb = as_area_create((void *) -1, PLB_SIZE,
     175            AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE);
     176        if (plb == (void *) -1) {
    182177                printf(NAME ": Cannot create address space area\n");
    183178                return ENOMEM;
Note: See TracChangeset for help on using the changeset viewer.