Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1946476AbWJTULn (ORCPT ); Fri, 20 Oct 2006 16:11:43 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1946475AbWJTULn (ORCPT ); Fri, 20 Oct 2006 16:11:43 -0400 Received: from smtp.osdl.org ([65.172.181.4]:4822 "EHLO smtp.osdl.org") by vger.kernel.org with ESMTP id S1946457AbWJTULm (ORCPT ); Fri, 20 Oct 2006 16:11:42 -0400 Date: Fri, 20 Oct 2006 13:10:59 -0700 (PDT) From: Linus Torvalds To: David Miller cc: nickpiggin@yahoo.com.au, ralf@linux-mips.org, Andrew Morton , Linux Kernel Mailing List , anemo@mba.ocn.ne.jp, linux-arch@vger.kernel.org, Martin Schwidefsky Subject: Re: [PATCH 1/3] Fix COW D-cache aliasing on fork In-Reply-To: <20061020.125851.115909797.davem@davemloft.net> Message-ID: References: <20061020.123635.95058911.davem@davemloft.net> <20061020.125851.115909797.davem@davemloft.net> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1682 Lines: 53 On Fri, 20 Oct 2006, David Miller wrote: > > I did some more digging, here's what I think the hardware actually > does: Ok, this sounds sane. What should we do about this? How does this patch look to people? (Totally untested, and I'm not sure we should even do that whole "oldmm->mm_users" test, but I'm throwing it out here for discussion, in case it matters for performance. The second D$ flush should obviously be unnecessary for the common unthreaded case, which is why none of this has mattered historically, I think). Comments? We need ARM, MIPS, sparc and S390 at the very least to sign off on this, and somebody to write a nice explanation for the changelog (and preferably do this through -mm too). Linus --- diff --git a/kernel/fork.c b/kernel/fork.c index 29ebb30..14c6a1d 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -287,8 +287,18 @@ static inline int dup_mmap(struct mm_str } retval = 0; out: - up_write(&mm->mmap_sem); flush_tlb_mm(oldmm); + /* + * If we have other threads using the old mm, we need to + * flush the D$ again - the other threads might have dirtied + * it more before the TLB got flushed. + * + * After the flush, they can no longer dirty more pages, + * since they are now marked read-only, of course. + */ + if (atomic_read(&oldmm->mm_users) != 1) + flush_cache_mm(oldmm); + up_write(&mm->mmap_sem); up_write(&oldmm->mmap_sem); return retval; fail_nomem_policy: - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/