From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C23F4C433FE for ; Fri, 21 Jan 2022 11:41:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D180D6B0085; Fri, 21 Jan 2022 06:41:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CC7436B0087; Fri, 21 Jan 2022 06:41:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BDCF96B0089; Fri, 21 Jan 2022 06:41:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0135.hostedemail.com [216.40.44.135]) by kanga.kvack.org (Postfix) with ESMTP id AF42F6B0085 for ; Fri, 21 Jan 2022 06:41:17 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 702C318194D77 for ; Fri, 21 Jan 2022 11:41:17 +0000 (UTC) X-FDA: 79054103394.24.BAC6E0A Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf12.hostedemail.com (Postfix) with ESMTP id 77F2E40005 for ; Fri, 21 Jan 2022 11:41:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=xWZDmg9dD+bIX1jVVA1AvE8Malvggiw/J3x4iYuMuz0=; b=HsAX+SqW2L76NBQvWu1PrqWimf lTviSMT5+R6d+xAfx10tH3WdylZdHX7ZkzpwAifrznjJgJpkGCBEQ8HfUZe2IuVyU0IoEzWnlJNSd Rjwsq3ujrhV650oRKW7DNK1Ze9woD5gBYFVZTHkH8wgB6aeVD9/kLlKAAXa1zm7dZDeyJg4VkITVk pzUXwU+8lLpJwkwrvHoXl6rMj4zlKsJsuYAW5r2d149PJW5qyFTlIshhjzzXgSKoeWvkXl1v8wtZl tOMtFLtlm9gywyy1pnJ9jw72BWJEiF72kwEuyPUfvpDxXELDLx8C+0uWwRV/fhfh2Szv954w6P6DC 7zOF4wTw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=worktop.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1nAsHt-00FYqS-Sx; Fri, 21 Jan 2022 11:41:02 +0000 Received: by worktop.programming.kicks-ass.net (Postfix, from userid 1000) id C4D369853F1; Fri, 21 Jan 2022 12:40:58 +0100 (CET) Date: Fri, 21 Jan 2022 12:40:58 +0100 From: Peter Zijlstra To: David Hildenbrand Cc: mingo@redhat.com, tglx@linutronix.de, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-api@vger.kernel.org, x86@kernel.org, pjt@google.com, posk@google.com, avagin@google.com, jannh@google.com, tdelisle@uwaterloo.ca, mark.rutland@arm.com, posk@posk.io Subject: Re: [RFC][PATCH v2 1/5] mm: Avoid unmapping pinned pages Message-ID: <20220121114058.GE20638@worktop.programming.kicks-ass.net> References: <20220120155517.066795336@infradead.org> <20220120160822.666778608@infradead.org> <20220121075157.GA20638@worktop.programming.kicks-ass.net> <20220121085917.GA22849@worktop.programming.kicks-ass.net> <10d6cc13-b96b-e1b6-8751-1b245b242738@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <10d6cc13-b96b-e1b6-8751-1b245b242738@redhat.com> X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 77F2E40005 X-Stat-Signature: khyf4g6883ynbw8cqtq7x5c5e3rw91ny Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=HsAX+SqW; dmarc=none; spf=none (imf12.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org X-HE-Tag: 1642765276-311584 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Fri, Jan 21, 2022 at 10:04:45AM +0100, David Hildenbrand wrote: > On 21.01.22 09:59, Peter Zijlstra wrote: > > However, I'm not quite sure what fork() does with pages that have a pin. > > We COW the anon pages always, and we protect against concurrent GUP > using the > * mmap_lock in exclusive mode for ordinary GUP > * mm->write_protect_seq for GUP-fast Right, but neither the mmap_sem nor the write_protect_seq help anything at all vs already extant page pins. But I just found copy_present_page()'s page_needs_cow_for_dma(), which I think deals with exactly that case, it avoids doing CoW on pinned pages and instead feeds the child a full copy while keeping the pinned page in the original process. > > Naively, a page that has async DMA activity should not be CoW'ed, or if > > it is, care must be taken to ensure the original pages stays in the > > original process, but I realize that's somewhat hard. > > That's precisely what I'm working on fixing ... and yes, it's hard. > > Let me know if you need any other information, I've spent way too much > time on this than I ever panned. So let me try and get this right: - GUP post-fork breaks CoW for FOLL_WRITE/FOLL_PIN, without either there's a problem where one task might observe changes by another. - GUP pre-fork prevents CoW and does a full copy. And that all mostly works, except for a fair amount of 'fun' cases?