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


Groups > linux.kernel > #1457173

Re: [PATCH] x86/mm: disable preemption during CR3 read+write

From Andy Lutomirski <luto@amacapital.net>
Newsgroups linux.kernel
Subject Re: [PATCH] x86/mm: disable preemption during CR3 read+write
Date 2016-08-05 17:50 +0200
Message-ID <s2PxL-YZ-5@gated-at.bofh.it> (permalink)
References <s2NvX-89z-13@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Fri, Aug 5, 2016 at 6:37 AM, Sebastian Andrzej Siewior
<bigeasy@linutronix.de> wrote:
> Usually current->mm (and therefore mm->pgd) stays the same during the
> lifetime of a task so it does not matter if a task gets preempted during
> the read and write of the CR3.
>
> But then, there is this scenario on x86-UP:
> TaskA is in do_exit() and exit_mm() sets current->mm = NULL followed by
> mmput() -> exit_mmap() -> tlb_finish_mmu() -> tlb_flush_mmu() ->
> tlb_flush_mmu_tlbonly() -> tlb_flush() -> flush_tlb_mm_range() ->
> __flush_tlb_up() -> __flush_tlb() ->  __native_flush_tlb().
>
> At this point current->mm is NULL but current->active_mm still points to
> the "old" mm.
> Let's preempt taskA _after_ native_read_cr3() by taskB. TaskB has its
> own mm so CR3 has changed.
> Now preempt back to taskA. TaskA has no ->mm set so it borrows taskB's
> mm and so CR3 remains unchanged. Once taskA gets active it continues
> where it was interrupted and that means it writes its old CR3 value
> back. Everything is fine because userland won't need its memory
> anymore.

This should affect kernel threads too, right?

Acked-by: Andy Lutomirski <luto@kernel.org>

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] x86/mm: disable preemption during CR3 read+write Sebastian Andrzej Siewior <bigeasy@linutronix.de> - 2016-08-05 15:40 +0200
  Re: [PATCH] x86/mm: disable preemption during CR3 read+write Peter Zijlstra <peterz@infradead.org> - 2016-08-05 16:00 +0200
  Re: [PATCH] x86/mm: disable preemption during CR3 read+write Rik van Riel <riel@redhat.com> - 2016-08-05 16:40 +0200
  Re: [PATCH] x86/mm: disable preemption during CR3 read+write Andy Lutomirski <luto@amacapital.net> - 2016-08-05 17:50 +0200
    Re: [PATCH] x86/mm: disable preemption during CR3 read+write Sebastian Andrzej Siewior <bigeasy@linutronix.de> - 2016-08-05 18:00 +0200
  [tip:x86/urgent] x86/mm: Disable preemption during CR3 read+write tip-bot for Sebastian Andrzej Siewior <tipbot@zytor.com> - 2016-08-10 23:00 +0200

csiph-web