From: NIIBE Yutaka <gniibe@fsij.org>
To: James Bottomley <James.Bottomley@HansenPartnership.com>
Cc: John David Anglin <dave@hiauly1.hia.nrc.ca>,
linux-parisc@vger.kernel.org,
pkg-gauche-devel@lists.alioth.debian.org, 561203@bugs.debian.org
Subject: Re: threads and fork on machine with VIPT-WB cache
Date: Tue, 06 Apr 2010 13:57:07 +0900 [thread overview]
Message-ID: <4BBABF23.1030405@fsij.org> (raw)
In-Reply-To: <1270484318.2790.38.camel@mulgrave.site>
John David Anglin wrote:
> It is interesting that in the case of the Debian bug that
> a thread of the parent process causes the COW break and thereby corrupts
> its own memory. As far as I can tell, the fork'd child never writes
> to the memory that causes the fault.
Thanks for writing and testing a patch.
The case of #561203 is second scenario. I think that this case is
relevant to VIVT-WB machine too (provided kernel does copy by kernel
address).
James Bottomley wrote:
> So this is going to be a hard sell because of the arch churn. There are,
> however, three ways to do it with the original signature.
Currently, I think that signature change would be inevitable for
ptep_set_wrprotect.
> 1. implement copy_user_highpage ... this allows us to copy through
> the child's page cache (which is coherent with the parent's
> before the cow) and thus pick up any cache changes without a
> flush
Let me think about this way.
Well, this would improve both cases of the first scenario of mine and
the second scenario.
But... I think that even if we would have copy_user_highpage which
does copy by user address, we need to flush at ptep_set_wrprotect. I
think that we need to keep the condition: no dirty cache for COW page.
Think about third scenario of threads and fork:
(1) In process A, there are multiple threads, and a thread A-1 invokes
fork. We have process B, with a different space identifier color.
(2) Another thread A-2 in process A runs while A-1 copies memory by
dup_mmap. A-2 writes to the address <x> in a page. Let's call
this page <oldpage>.
(3) We have dirty cache for <x> by A-2 at the time of
ptep_set_wrprotect of thread A-1. Suppose that we don't flush
here.
(4) A-1 finishes copy, and sleeps.
(5) Child process B is waken up and sees old value at <x> in <oldpage>,
through different cache line. B sleeps.
(6) A-2 is waken up. A-2 touches the memory again, breaks COW. A-2
copies data on <oldpage> to <newpage>. OK, <newpage> is
consistent with copy_user_highpage by user address.
Note that during this copy, the cache line of <x> by A-2 is
flushed out to <oldpage>. It invokes another memory fault and COW
break. (I think that this memory fault is unhealthy.)
Then, new value goes to <x> on <oldpage> (when it's physically
tagged cache).
A-2 sleeps.
(7) Child process B is waken up. When it accesses at <x>, it sees new
value suddenly.
If we flush cache to <oldpage> at ptep_set_wrprotect, this couldn't
occur.
* * *
I know that we should not do "threads and fork". It is difficult to
define clean semantics. Because another thread may touch memory while
a thread which does memory copy for fork, the memory what the child
process will see may be inconsistent. For the child, a page might be
new, while another page might be old.
For VIVT-WB cache machine, I am considering a possibility for the
child process to have inconsistent memory even within a single page
(when we have no flush at ptep_set_wrprotect).
It will be needed for me to talk to linux-arch soon or later.
--
next prev parent reply other threads:[~2010-04-06 4:57 UTC|newest]
Thread overview: 74+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <4BA43CE5.4020807@fsij.org>
[not found] ` <87hbo4ek8l.fsf@thialfi.karme.de>
[not found] ` <4BB18B46.2070203@fsij.org>
[not found] ` <4BB53D26.60601@fsij.org>
2010-04-02 2:41 ` threads and fork on machine with VIPT-WB cache NIIBE Yutaka
2010-04-02 3:30 ` James Bottomley
2010-04-02 3:48 ` NIIBE Yutaka
2010-04-02 8:05 ` NIIBE Yutaka
2010-04-02 19:35 ` John David Anglin
2010-04-08 21:11 ` Helge Deller
2010-04-08 21:54 ` John David Anglin
2010-04-08 22:44 ` John David Anglin
2010-04-09 14:14 ` Carlos O'Donell
2010-04-09 15:13 ` John David Anglin
2010-04-09 15:48 ` James Bottomley
2010-04-09 16:22 ` John David Anglin
2010-04-09 16:31 ` James Bottomley
2010-04-10 20:46 ` Helge Deller
2010-04-10 21:56 ` John David Anglin
2010-04-10 22:53 ` John David Anglin
2010-04-11 18:50 ` Helge Deller
2010-04-11 22:25 ` John David Anglin
2010-04-12 21:02 ` Helge Deller
2010-04-12 21:41 ` John David Anglin
2010-04-13 11:55 ` Helge Deller
2010-04-13 14:03 ` John David Anglin
2010-04-15 22:35 ` John David Anglin
2010-04-19 16:26 ` John David Anglin
2010-04-20 17:59 ` Helge Deller
2010-04-20 18:52 ` John David Anglin
2010-05-09 12:43 ` John David Anglin
2010-05-09 14:14 ` Carlos O'Donell
2010-05-10 9:56 ` Helge Deller
2010-05-10 14:56 ` John David Anglin
2010-05-10 19:20 ` Helge Deller
2010-05-10 21:07 ` John David Anglin
2010-05-11 16:37 ` John David Anglin
2010-05-11 21:39 ` John David Anglin
2010-05-11 20:44 ` Helge Deller
2010-05-11 20:41 ` Helge Deller
2010-05-11 21:26 ` John David Anglin
2010-05-11 21:41 ` Helge Deller
2010-05-15 21:02 ` John David Anglin
2010-05-16 20:22 ` Helge Deller
2010-05-16 21:38 ` John David Anglin
2010-05-22 17:25 ` John David Anglin
2010-05-23 13:11 ` Carlos O'Donell
2010-05-23 14:43 ` John David Anglin
2010-05-01 18:34 ` Thibaut VARENE
2010-05-01 20:17 ` John David Anglin
2010-05-02 10:53 ` Thibaut VARÈNE
2010-04-11 16:36 ` [PATCH] Call pagefault_disable/pagefault_enable in kmap_atomic/kunmap_atomic John David Anglin
2010-04-11 17:03 ` [PATCH] Remove unnecessary macros from entry.S John David Anglin
2010-04-11 17:08 ` [PATCH] Delete unnecessary nop's in entry.S John David Anglin
2010-04-11 17:12 ` [PATCH] Avoid interruption in critical region " John David Anglin
2010-04-11 18:24 ` James Bottomley
2010-04-11 18:45 ` John David Anglin
2010-04-11 18:53 ` James Bottomley
2010-04-11 17:26 ` [PATCH] LWS fixes for syscall.S John David Anglin
2010-06-02 15:33 ` Bug#561203: threads and fork on machine with VIPT-WB cache Modestas Vainius
2010-06-02 17:16 ` John David Anglin
2010-06-02 17:56 ` Bug#561203: " dann frazier
2010-06-03 8:50 ` Modestas Vainius
2010-06-04 1:03 ` NIIBE Yutaka
2010-06-04 5:21 ` dann frazier
2010-06-04 10:44 ` Thibaut VARENE
2010-06-07 17:11 ` dann frazier
2010-06-07 18:27 ` Thibaut VARÈNE
2010-06-07 23:33 ` dann frazier
2010-06-06 1:01 ` Modestas Vainius
2010-04-02 12:22 ` James Bottomley
2010-04-05 0:39 ` NIIBE Yutaka
2010-04-05 2:51 ` John David Anglin
2010-04-05 2:58 ` John David Anglin
2010-04-05 16:18 ` James Bottomley
2010-04-06 4:57 ` NIIBE Yutaka [this message]
2010-04-06 13:37 ` James Bottomley
2010-04-06 13:44 ` James Bottomley
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4BBABF23.1030405@fsij.org \
--to=gniibe@fsij.org \
--cc=561203@bugs.debian.org \
--cc=James.Bottomley@HansenPartnership.com \
--cc=dave@hiauly1.hia.nrc.ca \
--cc=linux-parisc@vger.kernel.org \
--cc=pkg-gauche-devel@lists.alioth.debian.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.