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;
}
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) ?
there is a possibility for the semi-common case of vmap-ing only one
page. but i'm not familiar enough with the mm code to figure that
case out.
-mike
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majo...@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Oops, sorry.
> 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, 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.
> 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.
--
David Woodhouse Open Source Technology Centre
David.W...@intel.com Intel Corporation
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
diff --git a/mm/nommu.c b/mm/nommu.c
index 8687973..d28ab94 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -360,14 +360,26 @@ EXPORT_SYMBOL(vmalloc_32_user);
void *vmap(struct page **pages, unsigned int count, unsigned long flags, pgprot_t prot)
{
- BUG();
- return NULL;
+ 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;
}
EXPORT_SYMBOL(vmap);
void vunmap(const void *addr)
{
- BUG();
+ kfree(addr);
}
EXPORT_SYMBOL(vunmap);
--
1.6.5.4
blah, didnt realize i still had this crap. drop the changelog and add:
Signed-off-by: Mike Frysinger <vap...@gentoo.org>
-mike
It could be done more efficiently if vunmap() was given the page count given
to vmap().
David
mm/nommu.c | 18 +++++++++++++++---
1 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/mm/nommu.c b/mm/nommu.c
index b9b5cce..61a68d5 100644
1.7.0.2
Instead, why not just override vmap() in firmware_class.c for the one instance
where we know we're happy with this behaviour?
David
---
From: David Howells <dhow...@redhat.com>
Subject: [PATCH] NOMMU: Work around the lack of vmap()/vunmap() in firmware_loading_store()
Work around the lack of vmap()/vunmap() in firmware_loading_store() when
operating in NOMMU mode. vmap() cannot be implemented as there's no virtual
mapping available.
Instead, in NOMMU mode, coalesce the data into one big buffer and store as the
address vmap() would've returned.
Signed-off-by: David Howells <dhow...@redhat.com>
---
drivers/base/firmware_class.c | 27 +++++++++++++++++++++++++++
1 files changed, 27 insertions(+), 0 deletions(-)
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index 18518ba..e33c2cb 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -59,6 +59,33 @@ static struct builtin_fw *__start_builtin_fw;
static struct builtin_fw *__end_builtin_fw;
#endif
+/*
+ * NOMMU mode can't provide vmap() as there's no MMU to do the virtual mapping.
+ * Coalesce the data into a big buffer instead.
+ */
+#ifndef CONFIG_MMU
+static void *__pretend_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;
+}
+
+#define vmap(pg, c, f, pr) __pretend_vmap(pg, c, f, pr)
+#endif /* !CONFIG_MMU */
+
static void
fw_load_abort(struct firmware_priv *fw_priv)
{
how about putting this implementation into like vmap_nommu() and only
rewriting vmap() to vmap_nommu() when we know it's safe ? such as this
firmware case ?
-mike
> how about putting this implementation into like vmap_nommu() and only
> rewriting vmap() to vmap_nommu() when we know it's safe ? such as this
> firmware case ?
Well, I'd argue it's _not_ vmap(), so it doesn't really make sense to call it
such. Perhaps some better name? Perhaps vcopy()?
David
> > how about putting this implementation into like vmap_nommu() and only
> > rewriting vmap() to vmap_nommu() when we know it's safe ? such as this
> > firmware case ?
>
> Well, I'd argue it's _not_ vmap(), so it doesn't really make sense to call it
> such. Perhaps some better name? Perhaps vcopy()?
How about vcoalesce()?
fair point
> How about vcoalesce()?
WFM, as does something like vmerge() ...
-mike