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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 89F44C4828F for ; Thu, 8 Feb 2024 06:29:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=zIwrvI+uK2uWHC5cCcsp/9TRgRT0aFMVqK2bMsbJtqs=; b=I2RiPB8ymMSHY6 4eYZGojx7IE1JV+xjRIxijTk67bzN8KJoZOVIncWRGfBdoBKj0b7kStoNEAAv3v8XV0vImEW7fL4D EaXQBWAn+JUWhMRcLdz7WoreZJkt4OhZppKTGRqqBbRHbRuoZtc71Gpp+LRPJShDLBO+b9KwQtn6K NosutcO4iPXoDLpsADeiJQUhF5BY6jHyOTb62kc6qRu4lLvyyhR2skAEc4hzS9q97sPduZeQuXRg8 IVj6dQtgXbYWR03sXMsoUOMwyIrjSRugMaGK8Yxpov2n3xznNxvQO+QLyIKpVnVS/GLnPDLc3GGCy uAB+F2LsfCyZpvAteQyQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXxux-0000000Cog7-02R5; Thu, 08 Feb 2024 06:29:51 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXxut-0000000Coev-0b3q; Thu, 08 Feb 2024 06:29:48 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 8BB1E61B29; Thu, 8 Feb 2024 06:29:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3E21FC433F1; Thu, 8 Feb 2024 06:29:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707373786; bh=x4GCLa2xzNhu7jlHpC2LrDTqBpAccwVcIjWuUAdJzgc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Phoix+90khL4IEhQ6gpSoCEIa7eKrFuowZSgj42G9vOi8dSlpe1gQK0YyWgYKp+4r sPLY9+CUFb9aZvZlJVuQqwKhWZ+pa+B4zWmW6ij44vrjGh7IL5UzkD3sKKzoxbKYee QNwaU30tJ0UF6MuasMfjEGa+A4FY8V6otf3jfYDzeJPTIubtszyNvCkdBsoVBCTCKZ +W8z7CCvQhm6qI593PxMf1LOB8FDsoWbQ3LesFfp+jH1tSwZzvF1v7s5703XCDTQvu YYI3y/4CVWlLjbUJLn8zUCRy2xy0Roln1eAOTnw74B+sWgLw7OSbGWrqA5wjWVRClH ouB/3F6aDobjA== Date: Thu, 8 Feb 2024 08:29:21 +0200 From: Mike Rapoport To: David Hildenbrand Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Matthew Wilcox , Ryan Roberts , Russell King , Catalin Marinas , Will Deacon , Dinh Nguyen , Michael Ellerman , Nicholas Piggin , Christophe Leroy , "Aneesh Kumar K.V" , "Naveen N. Rao" , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexander Gordeev , Gerald Schaefer , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Sven Schnelle , "David S. Miller" , linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org Subject: Re: [PATCH v3 11/15] mm/memory: factor out copying the actual PTE in copy_present_pte() Message-ID: References: <20240129124649.189745-1-david@redhat.com> <20240129124649.189745-12-david@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240129124649.189745-12-david@redhat.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240207_222947_278720_12EBF78E X-CRM114-Status: GOOD ( 26.15 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org On Mon, Jan 29, 2024 at 01:46:45PM +0100, David Hildenbrand wrote: > Let's prepare for further changes. > > Reviewed-by: Ryan Roberts > Signed-off-by: David Hildenbrand Reviewed-by: Mike Rapoport (IBM) > --- > mm/memory.c | 63 ++++++++++++++++++++++++++++------------------------- > 1 file changed, 33 insertions(+), 30 deletions(-) > > diff --git a/mm/memory.c b/mm/memory.c > index 8d14ba440929..a3bdb25f4c8d 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -930,6 +930,29 @@ copy_present_page(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma > return 0; > } > > +static inline void __copy_present_pte(struct vm_area_struct *dst_vma, > + struct vm_area_struct *src_vma, pte_t *dst_pte, pte_t *src_pte, > + pte_t pte, unsigned long addr) > +{ > + struct mm_struct *src_mm = src_vma->vm_mm; > + > + /* If it's a COW mapping, write protect it both processes. */ > + if (is_cow_mapping(src_vma->vm_flags) && pte_write(pte)) { > + ptep_set_wrprotect(src_mm, addr, src_pte); > + pte = pte_wrprotect(pte); > + } > + > + /* If it's a shared mapping, mark it clean in the child. */ > + if (src_vma->vm_flags & VM_SHARED) > + pte = pte_mkclean(pte); > + pte = pte_mkold(pte); > + > + if (!userfaultfd_wp(dst_vma)) > + pte = pte_clear_uffd_wp(pte); > + > + set_pte_at(dst_vma->vm_mm, addr, dst_pte, pte); > +} > + > /* > * Copy one pte. Returns 0 if succeeded, or -EAGAIN if one preallocated page > * is required to copy this pte. > @@ -939,23 +962,23 @@ copy_present_pte(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma, > pte_t *dst_pte, pte_t *src_pte, unsigned long addr, int *rss, > struct folio **prealloc) > { > - struct mm_struct *src_mm = src_vma->vm_mm; > - unsigned long vm_flags = src_vma->vm_flags; > pte_t pte = ptep_get(src_pte); > struct page *page; > struct folio *folio; > > page = vm_normal_page(src_vma, addr, pte); > - if (page) > - folio = page_folio(page); > - if (page && folio_test_anon(folio)) { > + if (unlikely(!page)) > + goto copy_pte; > + > + folio = page_folio(page); > + folio_get(folio); > + if (folio_test_anon(folio)) { > /* > * 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. > */ > - folio_get(folio); > if (unlikely(folio_try_dup_anon_rmap_pte(folio, page, src_vma))) { > /* Page may be pinned, we have to copy. */ > folio_put(folio); > @@ -963,34 +986,14 @@ copy_present_pte(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma, > addr, rss, prealloc, page); > } > rss[MM_ANONPAGES]++; > - } else if (page) { > - folio_get(folio); > + VM_WARN_ON_FOLIO(PageAnonExclusive(page), folio); > + } else { > folio_dup_file_rmap_pte(folio, page); > rss[mm_counter_file(folio)]++; > } > > - /* > - * If it's a COW mapping, write protect it both > - * in the parent and the child > - */ > - if (is_cow_mapping(vm_flags) && pte_write(pte)) { > - ptep_set_wrprotect(src_mm, addr, src_pte); > - pte = pte_wrprotect(pte); > - } > - VM_BUG_ON(page && folio_test_anon(folio) && PageAnonExclusive(page)); > - > - /* > - * If it's a shared mapping, mark it clean in > - * the child > - */ > - if (vm_flags & VM_SHARED) > - pte = pte_mkclean(pte); > - pte = pte_mkold(pte); > - > - if (!userfaultfd_wp(dst_vma)) > - pte = pte_clear_uffd_wp(pte); > - > - set_pte_at(dst_vma->vm_mm, addr, dst_pte, pte); > +copy_pte: > + __copy_present_pte(dst_vma, src_vma, dst_pte, src_pte, pte, addr); > return 0; > } > > -- > 2.43.0 > > -- Sincerely yours, Mike. _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A954067E67; Thu, 8 Feb 2024 06:29:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707373786; cv=none; b=XwxXYush4ctiQsT/Mzb0zEldr1DYYNkcLd1W8cVfvCDlNWsJq4THKh+JtWaAmEQYNi7g/ZllPdqKLcJUdvvAJFQKRbvUF+2eiFbmPVDcCLBO09ycwzwoRy9eGdqbuScjpfBK9tPF01gQI3iTbhgCIgG24/lfvK7u7BwVsYIZEP4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707373786; c=relaxed/simple; bh=x4GCLa2xzNhu7jlHpC2LrDTqBpAccwVcIjWuUAdJzgc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=nK6LUx6DTXCDoxGb8Yo0Q6e0fGFzSbyEgFGyloC7SZvX9phPLJ1GVp+GJIj1fg0SRnh0157QclJQpRM/SJv+cumnE3SgtkQJARYUJIY3RWP6KmytQkeOlruoPBwcODMjk4HCuDlVrMWa8XdszFjTyz4YKIUsABx3iP29CtCDP9w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Phoix+90; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Phoix+90" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3E21FC433F1; Thu, 8 Feb 2024 06:29:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707373786; bh=x4GCLa2xzNhu7jlHpC2LrDTqBpAccwVcIjWuUAdJzgc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Phoix+90khL4IEhQ6gpSoCEIa7eKrFuowZSgj42G9vOi8dSlpe1gQK0YyWgYKp+4r sPLY9+CUFb9aZvZlJVuQqwKhWZ+pa+B4zWmW6ij44vrjGh7IL5UzkD3sKKzoxbKYee QNwaU30tJ0UF6MuasMfjEGa+A4FY8V6otf3jfYDzeJPTIubtszyNvCkdBsoVBCTCKZ +W8z7CCvQhm6qI593PxMf1LOB8FDsoWbQ3LesFfp+jH1tSwZzvF1v7s5703XCDTQvu YYI3y/4CVWlLjbUJLn8zUCRy2xy0Roln1eAOTnw74B+sWgLw7OSbGWrqA5wjWVRClH ouB/3F6aDobjA== Date: Thu, 8 Feb 2024 08:29:21 +0200 From: Mike Rapoport To: David Hildenbrand Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Matthew Wilcox , Ryan Roberts , Russell King , Catalin Marinas , Will Deacon , Dinh Nguyen , Michael Ellerman , Nicholas Piggin , Christophe Leroy , "Aneesh Kumar K.V" , "Naveen N. Rao" , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexander Gordeev , Gerald Schaefer , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Sven Schnelle , "David S. Miller" , linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org Subject: Re: [PATCH v3 11/15] mm/memory: factor out copying the actual PTE in copy_present_pte() Message-ID: References: <20240129124649.189745-1-david@redhat.com> <20240129124649.189745-12-david@redhat.com> Precedence: bulk X-Mailing-List: linux-s390@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240129124649.189745-12-david@redhat.com> On Mon, Jan 29, 2024 at 01:46:45PM +0100, David Hildenbrand wrote: > Let's prepare for further changes. > > Reviewed-by: Ryan Roberts > Signed-off-by: David Hildenbrand Reviewed-by: Mike Rapoport (IBM) > --- > mm/memory.c | 63 ++++++++++++++++++++++++++++------------------------- > 1 file changed, 33 insertions(+), 30 deletions(-) > > diff --git a/mm/memory.c b/mm/memory.c > index 8d14ba440929..a3bdb25f4c8d 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -930,6 +930,29 @@ copy_present_page(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma > return 0; > } > > +static inline void __copy_present_pte(struct vm_area_struct *dst_vma, > + struct vm_area_struct *src_vma, pte_t *dst_pte, pte_t *src_pte, > + pte_t pte, unsigned long addr) > +{ > + struct mm_struct *src_mm = src_vma->vm_mm; > + > + /* If it's a COW mapping, write protect it both processes. */ > + if (is_cow_mapping(src_vma->vm_flags) && pte_write(pte)) { > + ptep_set_wrprotect(src_mm, addr, src_pte); > + pte = pte_wrprotect(pte); > + } > + > + /* If it's a shared mapping, mark it clean in the child. */ > + if (src_vma->vm_flags & VM_SHARED) > + pte = pte_mkclean(pte); > + pte = pte_mkold(pte); > + > + if (!userfaultfd_wp(dst_vma)) > + pte = pte_clear_uffd_wp(pte); > + > + set_pte_at(dst_vma->vm_mm, addr, dst_pte, pte); > +} > + > /* > * Copy one pte. Returns 0 if succeeded, or -EAGAIN if one preallocated page > * is required to copy this pte. > @@ -939,23 +962,23 @@ copy_present_pte(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma, > pte_t *dst_pte, pte_t *src_pte, unsigned long addr, int *rss, > struct folio **prealloc) > { > - struct mm_struct *src_mm = src_vma->vm_mm; > - unsigned long vm_flags = src_vma->vm_flags; > pte_t pte = ptep_get(src_pte); > struct page *page; > struct folio *folio; > > page = vm_normal_page(src_vma, addr, pte); > - if (page) > - folio = page_folio(page); > - if (page && folio_test_anon(folio)) { > + if (unlikely(!page)) > + goto copy_pte; > + > + folio = page_folio(page); > + folio_get(folio); > + if (folio_test_anon(folio)) { > /* > * 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. > */ > - folio_get(folio); > if (unlikely(folio_try_dup_anon_rmap_pte(folio, page, src_vma))) { > /* Page may be pinned, we have to copy. */ > folio_put(folio); > @@ -963,34 +986,14 @@ copy_present_pte(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma, > addr, rss, prealloc, page); > } > rss[MM_ANONPAGES]++; > - } else if (page) { > - folio_get(folio); > + VM_WARN_ON_FOLIO(PageAnonExclusive(page), folio); > + } else { > folio_dup_file_rmap_pte(folio, page); > rss[mm_counter_file(folio)]++; > } > > - /* > - * If it's a COW mapping, write protect it both > - * in the parent and the child > - */ > - if (is_cow_mapping(vm_flags) && pte_write(pte)) { > - ptep_set_wrprotect(src_mm, addr, src_pte); > - pte = pte_wrprotect(pte); > - } > - VM_BUG_ON(page && folio_test_anon(folio) && PageAnonExclusive(page)); > - > - /* > - * If it's a shared mapping, mark it clean in > - * the child > - */ > - if (vm_flags & VM_SHARED) > - pte = pte_mkclean(pte); > - pte = pte_mkold(pte); > - > - if (!userfaultfd_wp(dst_vma)) > - pte = pte_clear_uffd_wp(pte); > - > - set_pte_at(dst_vma->vm_mm, addr, dst_pte, pte); > +copy_pte: > + __copy_present_pte(dst_vma, src_vma, dst_pte, src_pte, pte, addr); > return 0; > } > > -- > 2.43.0 > > -- Sincerely yours, Mike. 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 lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D1EC7C48260 for ; Thu, 8 Feb 2024 06:30:31 +0000 (UTC) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=Phoix+90; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4TVnD63gQDz3cRY for ; Thu, 8 Feb 2024 17:30:30 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=Phoix+90; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=kernel.org (client-ip=2604:1380:4641:c500::1; helo=dfw.source.kernel.org; envelope-from=rppt@kernel.org; receiver=lists.ozlabs.org) Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4TVnCJ3yhWz2xFk for ; Thu, 8 Feb 2024 17:29:48 +1100 (AEDT) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 8BB1E61B29; Thu, 8 Feb 2024 06:29:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3E21FC433F1; Thu, 8 Feb 2024 06:29:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707373786; bh=x4GCLa2xzNhu7jlHpC2LrDTqBpAccwVcIjWuUAdJzgc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Phoix+90khL4IEhQ6gpSoCEIa7eKrFuowZSgj42G9vOi8dSlpe1gQK0YyWgYKp+4r sPLY9+CUFb9aZvZlJVuQqwKhWZ+pa+B4zWmW6ij44vrjGh7IL5UzkD3sKKzoxbKYee QNwaU30tJ0UF6MuasMfjEGa+A4FY8V6otf3jfYDzeJPTIubtszyNvCkdBsoVBCTCKZ +W8z7CCvQhm6qI593PxMf1LOB8FDsoWbQ3LesFfp+jH1tSwZzvF1v7s5703XCDTQvu YYI3y/4CVWlLjbUJLn8zUCRy2xy0Roln1eAOTnw74B+sWgLw7OSbGWrqA5wjWVRClH ouB/3F6aDobjA== Date: Thu, 8 Feb 2024 08:29:21 +0200 From: Mike Rapoport To: David Hildenbrand Subject: Re: [PATCH v3 11/15] mm/memory: factor out copying the actual PTE in copy_present_pte() Message-ID: References: <20240129124649.189745-1-david@redhat.com> <20240129124649.189745-12-david@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240129124649.189745-12-david@redhat.com> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Catalin Marinas , linux-mm@kvack.org, sparclinux@vger.kernel.org, Alexander Gordeev , Will Deacon , linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, Russell King , Matthew Wilcox , "Aneesh Kumar K.V" , "Naveen N. Rao" , Gerald Schaefer , Christian Borntraeger , Albert Ou , Ryan Roberts , Vasily Gorbik , Heiko Carstens , Nicholas Piggin , Paul Walmsley , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Dinh Nguyen , Palmer Dabbelt , Sven Schnelle , Andrew Morton , linuxppc-dev@lists.ozlabs.org, "David S. Miller" Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On Mon, Jan 29, 2024 at 01:46:45PM +0100, David Hildenbrand wrote: > Let's prepare for further changes. > > Reviewed-by: Ryan Roberts > Signed-off-by: David Hildenbrand Reviewed-by: Mike Rapoport (IBM) > --- > mm/memory.c | 63 ++++++++++++++++++++++++++++------------------------- > 1 file changed, 33 insertions(+), 30 deletions(-) > > diff --git a/mm/memory.c b/mm/memory.c > index 8d14ba440929..a3bdb25f4c8d 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -930,6 +930,29 @@ copy_present_page(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma > return 0; > } > > +static inline void __copy_present_pte(struct vm_area_struct *dst_vma, > + struct vm_area_struct *src_vma, pte_t *dst_pte, pte_t *src_pte, > + pte_t pte, unsigned long addr) > +{ > + struct mm_struct *src_mm = src_vma->vm_mm; > + > + /* If it's a COW mapping, write protect it both processes. */ > + if (is_cow_mapping(src_vma->vm_flags) && pte_write(pte)) { > + ptep_set_wrprotect(src_mm, addr, src_pte); > + pte = pte_wrprotect(pte); > + } > + > + /* If it's a shared mapping, mark it clean in the child. */ > + if (src_vma->vm_flags & VM_SHARED) > + pte = pte_mkclean(pte); > + pte = pte_mkold(pte); > + > + if (!userfaultfd_wp(dst_vma)) > + pte = pte_clear_uffd_wp(pte); > + > + set_pte_at(dst_vma->vm_mm, addr, dst_pte, pte); > +} > + > /* > * Copy one pte. Returns 0 if succeeded, or -EAGAIN if one preallocated page > * is required to copy this pte. > @@ -939,23 +962,23 @@ copy_present_pte(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma, > pte_t *dst_pte, pte_t *src_pte, unsigned long addr, int *rss, > struct folio **prealloc) > { > - struct mm_struct *src_mm = src_vma->vm_mm; > - unsigned long vm_flags = src_vma->vm_flags; > pte_t pte = ptep_get(src_pte); > struct page *page; > struct folio *folio; > > page = vm_normal_page(src_vma, addr, pte); > - if (page) > - folio = page_folio(page); > - if (page && folio_test_anon(folio)) { > + if (unlikely(!page)) > + goto copy_pte; > + > + folio = page_folio(page); > + folio_get(folio); > + if (folio_test_anon(folio)) { > /* > * 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. > */ > - folio_get(folio); > if (unlikely(folio_try_dup_anon_rmap_pte(folio, page, src_vma))) { > /* Page may be pinned, we have to copy. */ > folio_put(folio); > @@ -963,34 +986,14 @@ copy_present_pte(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma, > addr, rss, prealloc, page); > } > rss[MM_ANONPAGES]++; > - } else if (page) { > - folio_get(folio); > + VM_WARN_ON_FOLIO(PageAnonExclusive(page), folio); > + } else { > folio_dup_file_rmap_pte(folio, page); > rss[mm_counter_file(folio)]++; > } > > - /* > - * If it's a COW mapping, write protect it both > - * in the parent and the child > - */ > - if (is_cow_mapping(vm_flags) && pte_write(pte)) { > - ptep_set_wrprotect(src_mm, addr, src_pte); > - pte = pte_wrprotect(pte); > - } > - VM_BUG_ON(page && folio_test_anon(folio) && PageAnonExclusive(page)); > - > - /* > - * If it's a shared mapping, mark it clean in > - * the child > - */ > - if (vm_flags & VM_SHARED) > - pte = pte_mkclean(pte); > - pte = pte_mkold(pte); > - > - if (!userfaultfd_wp(dst_vma)) > - pte = pte_clear_uffd_wp(pte); > - > - set_pte_at(dst_vma->vm_mm, addr, dst_pte, pte); > +copy_pte: > + __copy_present_pte(dst_vma, src_vma, dst_pte, src_pte, pte, addr); > return 0; > } > > -- > 2.43.0 > > -- Sincerely yours, Mike. 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7A84AC4828F for ; Thu, 8 Feb 2024 06:29:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=BTpjMTH/b5AwoL2WHIoWbkYDb1AqBtjuT3CvTfPG4Jg=; b=TZTtTba/HJlTkp 6rESQt9PAUyXcKxJEwgPo3qMSfpu9/NhZOMFLXhcc9zGSMab7IFuxuMd+YYn9L6LIsNicBSutc20H CPxi0UhwXWY1bVE1sNIMshLOgoEy5N4gyAA42chYyhJciUL6Pg1JHYpdwzLWVJyCq5ZRIjj+9Bgqb fGcvs+kfTeotj61vZxE8lcakSsB0AsTNo2fGDBGSTkDC+5HCMhuUd2/um8e0cnzWYHXWNHUGZciyp ABf91bWRHb6Ov1xuYyC30z0umEbbMVYNaG8YDc5jGZFW+RrI84zvkGd7cQFFYcRWogiL1AtW0sTOM E/uYdw8pXMb26QCivOHw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXxuw-0000000Cofj-1EzF; Thu, 08 Feb 2024 06:29:50 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXxut-0000000Coev-0b3q; Thu, 08 Feb 2024 06:29:48 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 8BB1E61B29; Thu, 8 Feb 2024 06:29:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3E21FC433F1; Thu, 8 Feb 2024 06:29:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707373786; bh=x4GCLa2xzNhu7jlHpC2LrDTqBpAccwVcIjWuUAdJzgc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Phoix+90khL4IEhQ6gpSoCEIa7eKrFuowZSgj42G9vOi8dSlpe1gQK0YyWgYKp+4r sPLY9+CUFb9aZvZlJVuQqwKhWZ+pa+B4zWmW6ij44vrjGh7IL5UzkD3sKKzoxbKYee QNwaU30tJ0UF6MuasMfjEGa+A4FY8V6otf3jfYDzeJPTIubtszyNvCkdBsoVBCTCKZ +W8z7CCvQhm6qI593PxMf1LOB8FDsoWbQ3LesFfp+jH1tSwZzvF1v7s5703XCDTQvu YYI3y/4CVWlLjbUJLn8zUCRy2xy0Roln1eAOTnw74B+sWgLw7OSbGWrqA5wjWVRClH ouB/3F6aDobjA== Date: Thu, 8 Feb 2024 08:29:21 +0200 From: Mike Rapoport To: David Hildenbrand Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Matthew Wilcox , Ryan Roberts , Russell King , Catalin Marinas , Will Deacon , Dinh Nguyen , Michael Ellerman , Nicholas Piggin , Christophe Leroy , "Aneesh Kumar K.V" , "Naveen N. Rao" , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexander Gordeev , Gerald Schaefer , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Sven Schnelle , "David S. Miller" , linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org Subject: Re: [PATCH v3 11/15] mm/memory: factor out copying the actual PTE in copy_present_pte() Message-ID: References: <20240129124649.189745-1-david@redhat.com> <20240129124649.189745-12-david@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240129124649.189745-12-david@redhat.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240207_222947_278720_12EBF78E X-CRM114-Status: GOOD ( 26.15 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Jan 29, 2024 at 01:46:45PM +0100, David Hildenbrand wrote: > Let's prepare for further changes. > > Reviewed-by: Ryan Roberts > Signed-off-by: David Hildenbrand Reviewed-by: Mike Rapoport (IBM) > --- > mm/memory.c | 63 ++++++++++++++++++++++++++++------------------------- > 1 file changed, 33 insertions(+), 30 deletions(-) > > diff --git a/mm/memory.c b/mm/memory.c > index 8d14ba440929..a3bdb25f4c8d 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -930,6 +930,29 @@ copy_present_page(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma > return 0; > } > > +static inline void __copy_present_pte(struct vm_area_struct *dst_vma, > + struct vm_area_struct *src_vma, pte_t *dst_pte, pte_t *src_pte, > + pte_t pte, unsigned long addr) > +{ > + struct mm_struct *src_mm = src_vma->vm_mm; > + > + /* If it's a COW mapping, write protect it both processes. */ > + if (is_cow_mapping(src_vma->vm_flags) && pte_write(pte)) { > + ptep_set_wrprotect(src_mm, addr, src_pte); > + pte = pte_wrprotect(pte); > + } > + > + /* If it's a shared mapping, mark it clean in the child. */ > + if (src_vma->vm_flags & VM_SHARED) > + pte = pte_mkclean(pte); > + pte = pte_mkold(pte); > + > + if (!userfaultfd_wp(dst_vma)) > + pte = pte_clear_uffd_wp(pte); > + > + set_pte_at(dst_vma->vm_mm, addr, dst_pte, pte); > +} > + > /* > * Copy one pte. Returns 0 if succeeded, or -EAGAIN if one preallocated page > * is required to copy this pte. > @@ -939,23 +962,23 @@ copy_present_pte(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma, > pte_t *dst_pte, pte_t *src_pte, unsigned long addr, int *rss, > struct folio **prealloc) > { > - struct mm_struct *src_mm = src_vma->vm_mm; > - unsigned long vm_flags = src_vma->vm_flags; > pte_t pte = ptep_get(src_pte); > struct page *page; > struct folio *folio; > > page = vm_normal_page(src_vma, addr, pte); > - if (page) > - folio = page_folio(page); > - if (page && folio_test_anon(folio)) { > + if (unlikely(!page)) > + goto copy_pte; > + > + folio = page_folio(page); > + folio_get(folio); > + if (folio_test_anon(folio)) { > /* > * 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. > */ > - folio_get(folio); > if (unlikely(folio_try_dup_anon_rmap_pte(folio, page, src_vma))) { > /* Page may be pinned, we have to copy. */ > folio_put(folio); > @@ -963,34 +986,14 @@ copy_present_pte(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma, > addr, rss, prealloc, page); > } > rss[MM_ANONPAGES]++; > - } else if (page) { > - folio_get(folio); > + VM_WARN_ON_FOLIO(PageAnonExclusive(page), folio); > + } else { > folio_dup_file_rmap_pte(folio, page); > rss[mm_counter_file(folio)]++; > } > > - /* > - * If it's a COW mapping, write protect it both > - * in the parent and the child > - */ > - if (is_cow_mapping(vm_flags) && pte_write(pte)) { > - ptep_set_wrprotect(src_mm, addr, src_pte); > - pte = pte_wrprotect(pte); > - } > - VM_BUG_ON(page && folio_test_anon(folio) && PageAnonExclusive(page)); > - > - /* > - * If it's a shared mapping, mark it clean in > - * the child > - */ > - if (vm_flags & VM_SHARED) > - pte = pte_mkclean(pte); > - pte = pte_mkold(pte); > - > - if (!userfaultfd_wp(dst_vma)) > - pte = pte_clear_uffd_wp(pte); > - > - set_pte_at(dst_vma->vm_mm, addr, dst_pte, pte); > +copy_pte: > + __copy_present_pte(dst_vma, src_vma, dst_pte, src_pte, pte, addr); > return 0; > } > > -- > 2.43.0 > > -- Sincerely yours, Mike. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel