* A question aboout virtual mapping of kernel and module pages
@ 2013-12-19 20:25 Matvejchikov Ilya
2013-12-20 2:41 ` Vladimir Murzin
0 siblings, 1 reply; 3+ messages in thread
From: Matvejchikov Ilya @ 2013-12-19 20:25 UTC (permalink / raw)
To: linux-mm; +Cc: Ilya Matveychikov
[-- Attachment #1: Type: text/plain, Size: 2278 bytes --]
I'm using VMAP function to create memory writable mapping as it suggested
in ksplice project. Here is the implementation of map_writable function:
/*
* map_writable creates a shadow page mapping of the range
* [addr, addr + len) so that we can write to code mapped read-only.
*
* It is similar to a generalized version of x86's text_poke. But
* because one cannot use vmalloc/vfree() inside stop_machine, we use
* map_writable to map the pages before stop_machine, then use the
* mapping inside stop_machine, and unmap the pages afterwards.
*/
static void *map_writable(void *addr, size_t len)
{
void *vaddr;
int nr_pages = DIV_ROUND_UP(offset_in_page(addr) + len, PAGE_SIZE);
struct page **pages = kmalloc(nr_pages * sizeof(*pages),
GFP_KERNEL);
void *page_addr = (void *)((unsigned long)addr & PAGE_MASK);
int i;
if (pages == NULL)
return NULL;
for (i = 0; i < nr_pages; i++) {
if (__module_address((unsigned long)page_addr) == NULL) {
pages[i] = virt_to_page(page_addr);
WARN_ON(!PageReserved(pages[i]));
} else {
pages[i] = vmalloc_to_page(page_addr);
}
if (pages[i] == NULL) {
kfree(pages);
return NULL;
}
page_addr += PAGE_SIZE;
}
vaddr = vmap(pages, nr_pages, VM_MAP, PAGE_KERNEL);
kfree(pages);
if (vaddr == NULL)
return NULL;
return vaddr + offset_in_page(addr);
}
This function works well when I used it to map kernel's text addresses. All
fine and I can rewrite read-only data well via the mapping.
Now, I need to modify kernel module's text. Given the symbol address inside
the module, I use the same method. The mapping I've got seems to be valid.
But all my changes visible only in that mapping and not in the module!
I suppose that in case of module mapping I get something like copy-on-write
but I can't prove it.
Can anyone explain me what's happend and why I can use it for mapping
kernel and can't for modules?
http://stackoverflow.com/questions/20658357/virtual-mapping-of-kernel-and-module-pages
[-- Attachment #2: Type: text/html, Size: 2630 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: A question aboout virtual mapping of kernel and module pages
2013-12-19 20:25 A question aboout virtual mapping of kernel and module pages Matvejchikov Ilya
@ 2013-12-20 2:41 ` Vladimir Murzin
2013-12-20 8:25 ` Matvejchikov Ilya
0 siblings, 1 reply; 3+ messages in thread
From: Vladimir Murzin @ 2013-12-20 2:41 UTC (permalink / raw)
To: Matvejchikov Ilya; +Cc: linux-mm
Hi Ilya!
On Fri, Dec 20, 2013 at 12:25:13AM +0400, Matvejchikov Ilya wrote:
> I'm using VMAP function to create memory writable mapping as it suggested
> in ksplice project. Here is the implementation of map_writable function:
> ...
>
> This function works well when I used it to map kernel's text addresses. All
> fine and I can rewrite read-only data well via the mapping.
>
> Now, I need to modify kernel module's text. Given the symbol address inside
> the module, I use the same method. The mapping I've got seems to be valid.
> But all my changes visible only in that mapping and not in the module!
>
> I suppose that in case of module mapping I get something like copy-on-write
> but I can't prove it.
>
Looks like I-D cache aliasing... Have you flushed cashes after your
modifications were done?
Vladimir
> Can anyone explain me what's happend and why I can use it for mapping
> kernel and can't for modules?
>
> http://stackoverflow.com/questions/20658357/virtual-mapping-of-kernel-and-module-pages
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: A question aboout virtual mapping of kernel and module pages
2013-12-20 2:41 ` Vladimir Murzin
@ 2013-12-20 8:25 ` Matvejchikov Ilya
0 siblings, 0 replies; 3+ messages in thread
From: Matvejchikov Ilya @ 2013-12-20 8:25 UTC (permalink / raw)
To: Vladimir Murzin; +Cc: linux-mm
[-- Attachment #1: Type: text/plain, Size: 1377 bytes --]
Hi Vladimir,
Thanks for the suggestion, but the problem was not in mapping itself. I've
been mistaken
about
it
as
the problem I've had was related to bug in my code. Thanks for the idea to
check if I-D cache aliasing happens. It turns me to the
right
direction :)
2013/12/20 Vladimir Murzin <murzin.v@gmail.com>
> Hi Ilya!
>
> On Fri, Dec 20, 2013 at 12:25:13AM +0400, Matvejchikov Ilya wrote:
> > I'm using VMAP function to create memory writable mapping as it
suggested
> > in ksplice project. Here is the implementation of map_writable function:
> > ...
> >
> > This function works well when I used it to map kernel's text addresses.
All
> > fine and I can rewrite read-only data well via the mapping.
> >
> > Now, I need to modify kernel module's text. Given the symbol address
inside
> > the module, I use the same method. The mapping I've got seems to be
valid.
> > But all my changes visible only in that mapping and not in the module!
> >
> > I suppose that in case of module mapping I get something like
copy-on-write
> > but I can't prove it.
> >
>
> Looks like I-D cache aliasing... Have you flushed cashes after your
> modifications were done?
>
> Vladimir
>
> > Can anyone explain me what's happend and why I can use it for mapping
> > kernel and can't for modules?
> >
> >
http://stackoverflow.com/questions/20658357/virtual-mapping-of-kernel-and-module-pages
[-- Attachment #2: Type: text/html, Size: 2745 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-12-20 8:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-19 20:25 A question aboout virtual mapping of kernel and module pages Matvejchikov Ilya
2013-12-20 2:41 ` Vladimir Murzin
2013-12-20 8:25 ` Matvejchikov Ilya
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox