Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1540980 > unrolled thread

[PATCH] uprobes: allow for a cache flush after ixol breakpoint creation

Started byMarcin Nowakowski <marcin.nowakowski@imgtec.com>
First post2016-12-13 11:50 +0100
Last post2016-12-21 12:30 +0100
Articles 6 — 4 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] uprobes: allow for a cache flush after ixol breakpoint creation Marcin Nowakowski <marcin.nowakowski@imgtec.com> - 2016-12-13 11:50 +0100
    [tip:perf/urgent] uprobes: Fix uprobes on MIPS, allow for a cache  flush after ixol breakpoint creation tip-bot for Marcin Nowakowski <tipbot@zytor.com> - 2016-12-20 09:00 +0100
      Re: [tip:perf/urgent] uprobes: Fix uprobes on MIPS, allow for a  cache flush after ixol breakpoint creation Oleg Nesterov <oleg@redhat.com> - 2016-12-20 14:10 +0100
        Re: [tip:perf/urgent] uprobes: Fix uprobes on MIPS, allow for a cache  flush after ixol breakpoint creation Marcin Nowakowski <marcin.nowakowski@imgtec.com> - 2016-12-20 16:30 +0100
          Re: [tip:perf/urgent] uprobes: Fix uprobes on MIPS, allow for a         cache flush after ixol breakpoint creation Oleg Nesterov <oleg@redhat.com> - 2016-12-20 19:00 +0100
            Re: [tip:perf/urgent] uprobes: Fix uprobes on MIPS, allow for a  cache flush after ixol breakpoint creation Ralf Baechle <ralf@linux-mips.org> - 2016-12-21 12:30 +0100

#1540980 — [PATCH] uprobes: allow for a cache flush after ixol breakpoint creation

FromMarcin Nowakowski <marcin.nowakowski@imgtec.com>
Date2016-12-13 11:50 +0100
Subject[PATCH] uprobes: allow for a cache flush after ixol breakpoint creation
Message-ID<sNSOJ-7j-13@gated-at.bofh.it>
Commit 72e6ae285a1d ('ARM: 8043/1: uprobes need icache flush after xol
write' has introduced an arch-specific method to ensure all caches are
flushed appropriately after an instruction is written to an XOL page.

However, when the XOL area is created and the out-of-line breakpoint
instruction is copied, caches are not flushed at all and stale data may
be found in icache.

Replace a simple copy_to_page() with arch_uprobe_copy_ixol() to allow
the arch to ensure all caches are updated accordingly.

This change fixes uprobes on MIPS InterAptiv (tested on Creator Ci40).

Signed-off-by: Marcin Nowakowski <marcin.nowakowski@imgtec.com>
CC: Peter Zijlstra <peterz@infradead.org>
CC: Ingo Molnar <mingo@redhat.com>
CC: Arnaldo Carvalho de Melo <acme@kernel.org>
CC: Alexander Shishkin <alexander.shishkin@linux.intel.com>
CC: Victor Kamensky <victor.kamensky@linaro.org>

---
 kernel/events/uprobes.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index f9ec9ad..b5916b4 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -1194,7 +1194,7 @@ static struct xol_area *__create_xol_area(unsigned long vaddr)
 	/* Reserve the 1st slot for get_trampoline_vaddr() */
 	set_bit(0, area->bitmap);
 	atomic_set(&area->slot_count, 1);
-	copy_to_page(area->pages[0], 0, &insn, UPROBE_SWBP_INSN_SIZE);
+	arch_uprobe_copy_ixol(area->pages[0], 0, &insn, UPROBE_SWBP_INSN_SIZE);
 
 	if (!xol_add_vma(mm, area))
 		return area;
-- 
2.7.4

[toc] | [next] | [standalone]


#1544973 — [tip:perf/urgent] uprobes: Fix uprobes on MIPS, allow for a cache flush after ixol breakpoint creation

Fromtip-bot for Marcin Nowakowski <tipbot@zytor.com>
Date2016-12-20 09:00 +0100
Subject[tip:perf/urgent] uprobes: Fix uprobes on MIPS, allow for a cache flush after ixol breakpoint creation
Message-ID<sQnv4-2G0-21@gated-at.bofh.it>
In reply to#1540980
Commit-ID:  297e765e390a2ac996000b5f7228cbd84d995174
Gitweb:     http://git.kernel.org/tip/297e765e390a2ac996000b5f7228cbd84d995174
Author:     Marcin Nowakowski <marcin.nowakowski@imgtec.com>
AuthorDate: Tue, 13 Dec 2016 11:40:57 +0100
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Sun, 18 Dec 2016 09:42:11 +0100

uprobes: Fix uprobes on MIPS, allow for a cache flush after ixol breakpoint creation

Commit:

  72e6ae285a1d ('ARM: 8043/1: uprobes need icache flush after xol write'

... has introduced an arch-specific method to ensure all caches are
flushed appropriately after an instruction is written to an XOL page.

However, when the XOL area is created and the out-of-line breakpoint
instruction is copied, caches are not flushed at all and stale data may
be found in icache.

Replace a simple copy_to_page() with arch_uprobe_copy_ixol() to allow
the arch to ensure all caches are updated accordingly.

This change fixes uprobes on MIPS InterAptiv (tested on Creator Ci40).

Signed-off-by: Marcin Nowakowski <marcin.nowakowski@imgtec.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Victor Kamensky <victor.kamensky@linaro.org>
Cc: linux-mips@linux-mips.org
Link: http://lkml.kernel.org/r/1481625657-22850-1-git-send-email-marcin.nowakowski@imgtec.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 kernel/events/uprobes.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index f9ec9ad..b5916b4 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -1194,7 +1194,7 @@ static struct xol_area *__create_xol_area(unsigned long vaddr)
 	/* Reserve the 1st slot for get_trampoline_vaddr() */
 	set_bit(0, area->bitmap);
 	atomic_set(&area->slot_count, 1);
-	copy_to_page(area->pages[0], 0, &insn, UPROBE_SWBP_INSN_SIZE);
+	arch_uprobe_copy_ixol(area->pages[0], 0, &insn, UPROBE_SWBP_INSN_SIZE);
 
 	if (!xol_add_vma(mm, area))
 		return area;

[toc] | [prev] | [next] | [standalone]


#1545094 — Re: [tip:perf/urgent] uprobes: Fix uprobes on MIPS, allow for a cache flush after ixol breakpoint creation

FromOleg Nesterov <oleg@redhat.com>
Date2016-12-20 14:10 +0100
SubjectRe: [tip:perf/urgent] uprobes: Fix uprobes on MIPS, allow for a cache flush after ixol breakpoint creation
Message-ID<sQsl3-60s-13@gated-at.bofh.it>
In reply to#1544973
On 12/19, tip-bot for Marcin Nowakowski wrote:
>
> uprobes: Fix uprobes on MIPS, allow for a cache flush after ixol breakpoint creation
>
> Commit:
>
>   72e6ae285a1d ('ARM: 8043/1: uprobes need icache flush after xol write'
>
> ... has introduced an arch-specific method to ensure all caches are
> flushed appropriately after an instruction is written to an XOL page.

when this page is already mmaped,

> However, when the XOL area is created and the out-of-line breakpoint
> instruction is copied, caches are not flushed at all and stale data may
> be found in icache.

but in this case the page is not mmaped yet, the probed application will
take a page fault if it tries to execute this insn,

> Replace a simple copy_to_page() with arch_uprobe_copy_ixol() to allow
> the arch to ensure all caches are updated accordingly.
>
> This change fixes uprobes on MIPS InterAptiv (tested on Creator Ci40).

OK, I know nothing about MIPS, but could you help me understand this change?

See above. If we really need flush_icache_range() here then perhaps we should
modify install_special_mapping() and/or __do_fault/special_mapping_fault paths
instead?

Oleg.

[toc] | [prev] | [next] | [standalone]


#1545202 — Re: [tip:perf/urgent] uprobes: Fix uprobes on MIPS, allow for a cache flush after ixol breakpoint creation

FromMarcin Nowakowski <marcin.nowakowski@imgtec.com>
Date2016-12-20 16:30 +0100
SubjectRe: [tip:perf/urgent] uprobes: Fix uprobes on MIPS, allow for a cache flush after ixol breakpoint creation
Message-ID<sQuwy-7jd-35@gated-at.bofh.it>
In reply to#1545094
Hi Oleg,

On 20.12.2016 14:08, Oleg Nesterov wrote:
> On 12/19, tip-bot for Marcin Nowakowski wrote:
>>
>> uprobes: Fix uprobes on MIPS, allow for a cache flush after ixol breakpoint creation
>>
>> Commit:
>>
>>   72e6ae285a1d ('ARM: 8043/1: uprobes need icache flush after xol write'
>>
>> ... has introduced an arch-specific method to ensure all caches are
>> flushed appropriately after an instruction is written to an XOL page.
>
> when this page is already mmaped,
>
>> However, when the XOL area is created and the out-of-line breakpoint
>> instruction is copied, caches are not flushed at all and stale data may
>> be found in icache.
>
> but in this case the page is not mmaped yet, the probed application will
> take a page fault if it tries to execute this insn,

In case of MIPS (and AFAICT ARM as well, and these are the only 
architectures that implement arch_uprobe_copy_ixol), the cache flushing 
is done through the kernel addresses of that page, so the fact that it 
is not mapped yet is not an issue.

Do I understand correctly that your statement implies that after the 
page fault and mmapping the xol page, the page is guaranteed to be 
updated in the cache? As definitely that is not something that is 
happening at the moment.


>> Replace a simple copy_to_page() with arch_uprobe_copy_ixol() to allow
>> the arch to ensure all caches are updated accordingly.
>>
>> This change fixes uprobes on MIPS InterAptiv (tested on Creator Ci40).
>
> OK, I know nothing about MIPS, but could you help me understand this change?
>
> See above. If we really need flush_icache_range() here then perhaps we should
> modify install_special_mapping() and/or __do_fault/special_mapping_fault paths
> instead?

Are you suggesting that those should be updated to force a cache update?

Marcin

[toc] | [prev] | [next] | [standalone]


#1545324 — Re: [tip:perf/urgent] uprobes: Fix uprobes on MIPS, allow for a cache flush after ixol breakpoint creation

FromOleg Nesterov <oleg@redhat.com>
Date2016-12-20 19:00 +0100
SubjectRe: [tip:perf/urgent] uprobes: Fix uprobes on MIPS, allow for a cache flush after ixol breakpoint creation
Message-ID<sQwRH-fa-9@gated-at.bofh.it>
In reply to#1545202
On 12/20, Marcin Nowakowski wrote:
>
> Hi Oleg,
>
> On 20.12.2016 14:08, Oleg Nesterov wrote:
>> On 12/19, tip-bot for Marcin Nowakowski wrote:
>>>
>>> uprobes: Fix uprobes on MIPS, allow for a cache flush after ixol breakpoint creation
>>>
>>> Commit:
>>>
>>>   72e6ae285a1d ('ARM: 8043/1: uprobes need icache flush after xol write'
>>>
>>> ... has introduced an arch-specific method to ensure all caches are
>>> flushed appropriately after an instruction is written to an XOL page.
>>
>> when this page is already mmaped,
>>
>>> However, when the XOL area is created and the out-of-line breakpoint
>>> instruction is copied, caches are not flushed at all and stale data may
>>> be found in icache.
>>
>> but in this case the page is not mmaped yet, the probed application will
>> take a page fault if it tries to execute this insn,
>
> In case of MIPS (and AFAICT ARM as well, and these are the only  
> architectures that implement arch_uprobe_copy_ixol), the cache flushing  
> is done through the kernel addresses of that page, so the fact that it  
> is not mapped yet is not an issue.

OK, thanks,

> Do I understand correctly that your statement implies that after the  
> page fault and mmapping the xol page, the page is guaranteed to be  
> updated in the cache? As definitely that is not something that is  
> happening at the moment.

Well, I do not know. Let me repeat I don't understand this flush_.*cache
magic.

But. do_read_fault() does

	__do_fault(..., &fault_page, ...);

	alloc_set_pte(fault_page);

and alloc_set_pte() does flush_icache_page(vma, page)... Hmm, which is nop
on MIPS.

>> OK, I know nothing about MIPS, but could you help me understand this change?
>>
>> See above. If we really need flush_icache_range() here then perhaps we should
>> modify install_special_mapping() and/or __do_fault/special_mapping_fault paths
>> instead?
>
> Are you suggesting that those should be updated to force a cache update?

Again, I do not know. But perhaps it makes more sense to actually implement
flush_icache_page() ? Otherwise another user of install_special_mapping()
can hit the same problem?

Oleg.

[toc] | [prev] | [next] | [standalone]


#1545724 — Re: [tip:perf/urgent] uprobes: Fix uprobes on MIPS, allow for a cache flush after ixol breakpoint creation

FromRalf Baechle <ralf@linux-mips.org>
Date2016-12-21 12:30 +0100
SubjectRe: [tip:perf/urgent] uprobes: Fix uprobes on MIPS, allow for a cache flush after ixol breakpoint creation
Message-ID<sQNfQ-2Mj-15@gated-at.bofh.it>
In reply to#1545324
On Tue, Dec 20, 2016 at 06:50:05PM +0100, Oleg Nesterov wrote:

> >>> Commit:
> >>>
> >>>   72e6ae285a1d ('ARM: 8043/1: uprobes need icache flush after xol write'
> >>>
> >>> ... has introduced an arch-specific method to ensure all caches are
> >>> flushed appropriately after an instruction is written to an XOL page.
> >>
> >> when this page is already mmaped,
> >>
> >>> However, when the XOL area is created and the out-of-line breakpoint
> >>> instruction is copied, caches are not flushed at all and stale data may
> >>> be found in icache.
> >>
> >> but in this case the page is not mmaped yet, the probed application will
> >> take a page fault if it tries to execute this insn,
> >
> > In case of MIPS (and AFAICT ARM as well, and these are the only  
> > architectures that implement arch_uprobe_copy_ixol), the cache flushing  
> > is done through the kernel addresses of that page, so the fact that it  
> > is not mapped yet is not an issue.
> 
> OK, thanks,
> 
> > Do I understand correctly that your statement implies that after the  
> > page fault and mmapping the xol page, the page is guaranteed to be  
> > updated in the cache? As definitely that is not something that is  
> > happening at the moment.
> 
> Well, I do not know. Let me repeat I don't understand this flush_.*cache
> magic.
> 
> But. do_read_fault() does
> 
> 	__do_fault(..., &fault_page, ...);
> 
> 	alloc_set_pte(fault_page);
> 
> and alloc_set_pte() does flush_icache_page(vma, page)... Hmm, which is nop
> on MIPS.
> 
> >> OK, I know nothing about MIPS, but could you help me understand this change?
> >>
> >> See above. If we really need flush_icache_range() here then perhaps we should
> >> modify install_special_mapping() and/or __do_fault/special_mapping_fault paths
> >> instead?
> >
> > Are you suggesting that those should be updated to force a cache update?
> 
> Again, I do not know. But perhaps it makes more sense to actually implement
> flush_icache_page() ? Otherwise another user of install_special_mapping()
> can hit the same problem?

Documentation/cachetlb.txt says about flush_icache_page:

  void flush_icache_page(struct vm_area_struct *vma, struct page *page)
        All the functionality of flush_icache_page can be implemented in
        flush_dcache_page and update_mmu_cache. In the future, the hope
        is to remove this interface completely.

And that's exactly what MIPS already does, thus flush_icache_page() is a
no-op.  The new interfaces flush_dcache_page and update_mmu_cache
generally are much more efficient.

  Ralf

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web