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 CD143C433F5 for ; Mon, 11 Apr 2022 18:18:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 262A26B0072; Mon, 11 Apr 2022 14:18:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 212506B0073; Mon, 11 Apr 2022 14:18:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 08C966B0074; Mon, 11 Apr 2022 14:18:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0030.hostedemail.com [216.40.44.30]) by kanga.kvack.org (Postfix) with ESMTP id EDDEA6B0072 for ; Mon, 11 Apr 2022 14:18:32 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id B18B3A5BC6 for ; Mon, 11 Apr 2022 18:18:32 +0000 (UTC) X-FDA: 79345408464.21.CE62F9A Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf02.hostedemail.com (Postfix) with ESMTP id F27A880009 for ; Mon, 11 Apr 2022 18:18:31 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 64B181F864; Mon, 11 Apr 2022 18:18:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1649701110; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9rwmjqY/Hr1f5h6HYYWQymxcjH9AvmzShmJ/szJdFG8=; b=rQDz49TQRDKjiHrsPtwvnSQfXrC45tSOp7KKgS2VJwBzntHE740J3ICE2oq0q1KK1PsP6n Rsgy6K9oBChXkkDQrqX7BdYQENTWjTcZQ3tMTq288ju4q8IkhHnVedqDZzNnCvUXfTyMcc I7eCrTyFazpcwQ62nauksU2lYEY0m5I= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1649701110; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9rwmjqY/Hr1f5h6HYYWQymxcjH9AvmzShmJ/szJdFG8=; b=90vftVHB04f2xIV5eUZzqqFGsIDsAVhzcm+ncL7/U060hmQJpHXZ0zdh7p/6gw4Mr8YJJx pDhKisIL4ZC4OjCg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id E5E6A13A93; Mon, 11 Apr 2022 18:18:29 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id g+NuN/VwVGIXIQAAMHmgww (envelope-from ); Mon, 11 Apr 2022 18:18:29 +0000 Message-ID: Date: Mon, 11 Apr 2022 20:18:29 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Content-Language: en-US To: David Hildenbrand , linux-kernel@vger.kernel.org Cc: Andrew Morton , Hugh Dickins , Linus Torvalds , David Rientjes , Shakeel Butt , John Hubbard , Jason Gunthorpe , Mike Kravetz , Mike Rapoport , Yang Shi , "Kirill A . Shutemov" , Matthew Wilcox , Jann Horn , Michal Hocko , Nadav Amit , Rik van Riel , Roman Gushchin , Andrea Arcangeli , Peter Xu , Donald Dutile , Christoph Hellwig , Oleg Nesterov , Jan Kara , Liang Zhang , Pedro Gomes , Oded Gabbay , linux-mm@kvack.org References: <20220329160440.193848-1-david@redhat.com> <20220329160440.193848-5-david@redhat.com> From: Vlastimil Babka Subject: Re: [PATCH v3 04/16] mm/rmap: split page_dup_rmap() into page_dup_file_rmap() and page_try_dup_anon_rmap() In-Reply-To: <20220329160440.193848-5-david@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Stat-Signature: 5n3fwz57dxjrcbbsniwxpw9ra573taqo Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=rQDz49TQ; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=90vftVHB; dmarc=none; spf=pass (imf02.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz X-Rspam-User: X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: F27A880009 X-HE-Tag: 1649701111-440410 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 3/29/22 18:04, David Hildenbrand wrote: > ... and move the special check for pinned pages into > page_try_dup_anon_rmap() to prepare for tracking exclusive anonymous > pages via a new pageflag, clearing it only after making sure that there > are no GUP pins on the anonymous page. > > We really only care about pins on anonymous pages, because they are > prone to getting replaced in the COW handler once mapped R/O. For !anon > pages in cow-mappings (!VM_SHARED && VM_MAYWRITE) we shouldn't really > care about that, at least not that I could come up with an example. > > Let's drop the is_cow_mapping() check from page_needs_cow_for_dma(), as we > know we're dealing with anonymous pages. Also, drop the handling of > pinned pages from copy_huge_pud() and add a comment if ever supporting > anonymous pages on the PUD level. > > This is a preparation for tracking exclusivity of anonymous pages in > the rmap code, and disallowing marking a page shared (-> failing to > duplicate) if there are GUP pins on a page. > > Signed-off-by: David Hildenbrand Acked-by: Vlastimil Babka Nit: > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -825,7 +825,8 @@ copy_nonpresent_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm, > */ > get_page(page); > rss[mm_counter(page)]++; > - page_dup_rmap(page, false); > + /* Cannot fail as these pages cannot get pinned. */ > + BUG_ON(page_try_dup_anon_rmap(page, false, src_vma)); Should we just call __page_dup_rmap() here? This is block for the condition is_device_private_entry(), and page_try_dup_anon_rmap() can't return -EBUSY for is_device_private_page(). > > /* > * We do not preserve soft-dirty information, because so > @@ -921,18 +922,24 @@ copy_present_pte(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma, > struct page *page; > > page = vm_normal_page(src_vma, addr, pte); > - if (page && unlikely(page_needs_cow_for_dma(src_vma, page))) { > + if (page && PageAnon(page)) { > /* > * If this page may have been pinned by the parent process, > * copy the page immediately for the child so that we'll always > * guarantee the pinned page won't be randomly replaced in the > * future. > */ > - return copy_present_page(dst_vma, src_vma, dst_pte, src_pte, > - addr, rss, prealloc, page); > + get_page(page); > + if (unlikely(page_try_dup_anon_rmap(page, false, src_vma))) { > + /* Page maybe pinned, we have to copy. */ > + put_page(page); > + return copy_present_page(dst_vma, src_vma, dst_pte, src_pte, > + addr, rss, prealloc, page); > + } > + rss[mm_counter(page)]++; > } else if (page) { > get_page(page); > - page_dup_rmap(page, false); > + page_dup_file_rmap(page, false); > rss[mm_counter(page)]++; > } > > diff --git a/mm/migrate.c b/mm/migrate.c > index 3d60823afd2d..97de2fc17f34 100644 > --- a/mm/migrate.c > +++ b/mm/migrate.c > @@ -234,7 +234,7 @@ static bool remove_migration_pte(struct folio *folio, > if (folio_test_anon(folio)) > hugepage_add_anon_rmap(new, vma, pvmw.address); > else > - page_dup_rmap(new, true); > + page_dup_file_rmap(new, true); > set_huge_pte_at(vma->vm_mm, pvmw.address, pvmw.pte, pte); > } else > #endif