Re: userspace firmware loader, vmap, and nommu

From: Mike Frysinger
Date: Tue Oct 06 2009 - 01:04:50 EST


On Tue, Oct 6, 2009 at 00:38, David Woodhouse wrote:
> On Tue, 2009-10-06 at 00:25 -0400, Mike Frysinger wrote:
>> Âthe firmware loader used to work before this
>> change because it would handle the realloc steps itself (allocate
>> larger contiguous memory, copy over older data, release older memory)
>> and vmalloc() on nommu is simply kmalloc().
>>
>> this could be handled transparently on nommu systems by moving this
>> scatter gathering of pages into vmap:
>> void *vmap(struct page **pages, unsigned int count, unsigned long
>> flags, pgprot_t prot)
>> {
>> Â Â unsigned int i;
>> Â Â void *new_map, *page_data;
>>
>> Â Â new_map = kmalloc(count << PAGE_SHIFT, GFP_KERNEL);
>> Â Â if (!new_map)
>> Â Â Â Â return NULL;
>>
>> Â Â for (i = 0; i < count; ++i) {
>> Â Â Â Â page_data = kmap(pages[i]);
>> Â Â Â Â memcpy(new_map + (i << PAGE_SHIFT), page_data, PAGE_SIZE);
>> Â Â Â Â kunmap(page_data);
>> Â Â }
>>
>> Â Â return new_map;
>
> I wouldn't necessarily want to do that for _all_ vmap() calls,

there arent any vmap() callers currently on nommu systems since the
functions currently BUG(). looking at lxr for 2.6.31 indicates that
there are very few relevant vmap() callers in general.

> but doing
> it just for the firmware loader might make some sense. It does mean you
> have to have _twice_ as much memory available as the size of the
> firmware in question. And you have to have a contiguous chunk even
> _after_ allocating it once piecemeal.

yes, but this is how it worked before and no one complained ;).
firmware files after all tend to be on the "small" side, so getting a
small physically contiguous mapping isnt that hard.

>> void vunmap(const void *addr)
>> {
>> Â Â kfree(addr);
>> }
>>
>> or we could add nommu-specific code to the firmware loader to not use
>> vmap(). Âhow would you like to go David (Howells) ?
>
> Or we could add _generic_ code not to use vmap(). Just teach the users
> that you don't get a virtually contiguous blob back from
> request_firmware(); you get an array of pages instead.

wouldnt that non-trivially increase the code work for callers of the
firmware functions ? seems like a hefty penalty for a minority
(nommu) to impose on the majority (mmu).
-mike
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/