linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Mike Rapoport <rppt@kernel.org>
To: David Hildenbrand <david@redhat.com>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	Andrew Morton <akpm@linux-foundation.org>,
	Matthew Wilcox <willy@infradead.org>,
	Ryan Roberts <ryan.roberts@arm.com>,
	Russell King <linux@armlinux.org.uk>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>, Dinh Nguyen <dinguyen@kernel.org>,
	Michael Ellerman <mpe@ellerman.id.au>,
	Nicholas Piggin <npiggin@gmail.com>,
	Christophe Leroy <christophe.leroy@csgroup.eu>,
	"Aneesh Kumar K.V" <aneesh.kumar@kernel.org>,
	"Naveen N. Rao" <naveen.n.rao@linux.ibm.com>,
	Paul Walmsley <paul.walmsley@sifive.com>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Albert Ou <aou@eecs.berkeley.edu>,
	Alexander Gordeev <agordeev@linux.ibm.com>,
	Gerald Schaefer <gerald.schaefer@linux.ibm.com>,
	Heiko Carstens <hca@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	Sven Schnelle <svens@linux.ibm.com>,
	"David S. Miller" <davem@davemloft.net>,
	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 01/15] arm64/mm: Make set_ptes() robust when OAs cross 48-bit boundary
Date: Thu, 8 Feb 2024 08:10:59 +0200	[thread overview]
Message-ID: <ZcRwc2mEDHIXxgGa@kernel.org> (raw)
In-Reply-To: <20240129124649.189745-2-david@redhat.com>

On Mon, Jan 29, 2024 at 01:46:35PM +0100, David Hildenbrand wrote:
> From: Ryan Roberts <ryan.roberts@arm.com>
> 
> Since the high bits [51:48] of an OA are not stored contiguously in the
> PTE, there is a theoretical bug in set_ptes(), which just adds PAGE_SIZE
> to the pte to get the pte with the next pfn. This works until the pfn
> crosses the 48-bit boundary, at which point we overflow into the upper
> attributes.
> 
> Of course one could argue (and Matthew Wilcox has :) that we will never
> see a folio cross this boundary because we only allow naturally aligned
> power-of-2 allocation, so this would require a half-petabyte folio. So
> its only a theoretical bug. But its better that the code is robust
> regardless.
> 
> I've implemented pte_next_pfn() as part of the fix, which is an opt-in
> core-mm interface. So that is now available to the core-mm, which will
> be needed shortly to support forthcoming fork()-batching optimizations.
> 
> Link: https://lkml.kernel.org/r/20240125173534.1659317-1-ryan.roberts@arm.com
> Fixes: 4a169d61c2ed ("arm64: implement the new page table range API")
> Closes: https://lore.kernel.org/linux-mm/fdaeb9a5-d890-499a-92c8-d171df43ad01@arm.com/
> Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
> Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
> Reviewed-by: David Hildenbrand <david@redhat.com>
> Signed-off-by: David Hildenbrand <david@redhat.com>

Reviewed-by: Mike Rapoport (IBM) <rppt@kernel.org>

> ---
>  arch/arm64/include/asm/pgtable.h | 28 +++++++++++++++++-----------
>  1 file changed, 17 insertions(+), 11 deletions(-)
> 
> diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
> index b50270107e2f..9428801c1040 100644
> --- a/arch/arm64/include/asm/pgtable.h
> +++ b/arch/arm64/include/asm/pgtable.h
> @@ -341,6 +341,22 @@ static inline void __sync_cache_and_tags(pte_t pte, unsigned int nr_pages)
>  		mte_sync_tags(pte, nr_pages);
>  }
>  
> +/*
> + * Select all bits except the pfn
> + */
> +static inline pgprot_t pte_pgprot(pte_t pte)
> +{
> +	unsigned long pfn = pte_pfn(pte);
> +
> +	return __pgprot(pte_val(pfn_pte(pfn, __pgprot(0))) ^ pte_val(pte));
> +}
> +
> +#define pte_next_pfn pte_next_pfn
> +static inline pte_t pte_next_pfn(pte_t pte)
> +{
> +	return pfn_pte(pte_pfn(pte) + 1, pte_pgprot(pte));
> +}
> +
>  static inline void set_ptes(struct mm_struct *mm,
>  			    unsigned long __always_unused addr,
>  			    pte_t *ptep, pte_t pte, unsigned int nr)
> @@ -354,7 +370,7 @@ static inline void set_ptes(struct mm_struct *mm,
>  		if (--nr == 0)
>  			break;
>  		ptep++;
> -		pte_val(pte) += PAGE_SIZE;
> +		pte = pte_next_pfn(pte);
>  	}
>  }
>  #define set_ptes set_ptes
> @@ -433,16 +449,6 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte)
>  	return clear_pte_bit(pte, __pgprot(PTE_SWP_EXCLUSIVE));
>  }
>  
> -/*
> - * Select all bits except the pfn
> - */
> -static inline pgprot_t pte_pgprot(pte_t pte)
> -{
> -	unsigned long pfn = pte_pfn(pte);
> -
> -	return __pgprot(pte_val(pfn_pte(pfn, __pgprot(0))) ^ pte_val(pte));
> -}
> -
>  #ifdef CONFIG_NUMA_BALANCING
>  /*
>   * See the comment in include/linux/pgtable.h
> -- 
> 2.43.0
> 
> 

-- 
Sincerely yours,
Mike.


  reply	other threads:[~2024-02-08  6:11 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-29 12:46 [PATCH v3 00/15] mm/memory: optimize fork() with PTE-mapped THP David Hildenbrand
2024-01-29 12:46 ` [PATCH v3 01/15] arm64/mm: Make set_ptes() robust when OAs cross 48-bit boundary David Hildenbrand
2024-02-08  6:10   ` Mike Rapoport [this message]
2024-02-09 22:36     ` David Hildenbrand
2024-01-29 12:46 ` [PATCH v3 02/15] arm/pgtable: define PFN_PTE_SHIFT David Hildenbrand
2024-02-08  6:11   ` Mike Rapoport
2024-01-29 12:46 ` [PATCH v3 03/15] nios2/pgtable: " David Hildenbrand
2024-02-08  6:12   ` Mike Rapoport
2024-01-29 12:46 ` [PATCH v3 04/15] powerpc/pgtable: " David Hildenbrand
2024-02-08  6:13   ` Mike Rapoport
2024-01-29 12:46 ` [PATCH v3 05/15] riscv/pgtable: " David Hildenbrand
2024-02-08  6:14   ` Mike Rapoport
2024-01-29 12:46 ` [PATCH v3 06/15] s390/pgtable: " David Hildenbrand
2024-02-08  6:15   ` Mike Rapoport
2024-01-29 12:46 ` [PATCH v3 07/15] sparc/pgtable: " David Hildenbrand
2024-02-08  6:18   ` Mike Rapoport
2024-01-29 12:46 ` [PATCH v3 08/15] mm/pgtable: make pte_next_pfn() independent of set_ptes() David Hildenbrand
2024-02-08  6:19   ` Mike Rapoport
2024-01-29 12:46 ` [PATCH v3 09/15] arm/mm: use pte_next_pfn() in set_ptes() David Hildenbrand
2024-02-08  6:20   ` Mike Rapoport
2024-01-29 12:46 ` [PATCH v3 10/15] powerpc/mm: " David Hildenbrand
2024-02-08  6:20   ` Mike Rapoport
2024-01-29 12:46 ` [PATCH v3 11/15] mm/memory: factor out copying the actual PTE in copy_present_pte() David Hildenbrand
2024-02-08  6:29   ` Mike Rapoport
2024-01-29 12:46 ` [PATCH v3 12/15] mm/memory: pass PTE to copy_present_pte() David Hildenbrand
2024-02-08  6:27   ` Mike Rapoport
2024-02-14 22:40   ` David Hildenbrand
2024-01-29 12:46 ` [PATCH v3 13/15] mm/memory: optimize fork() with PTE-mapped THP David Hildenbrand
2024-02-08  6:41   ` Mike Rapoport
2024-01-29 12:46 ` [PATCH v3 14/15] mm/memory: ignore dirty/accessed/soft-dirty bits in folio_pte_batch() David Hildenbrand
2024-01-29 12:46 ` [PATCH v3 15/15] mm/memory: ignore writable bit " David Hildenbrand
2024-01-31 10:43 ` [PATCH v3 00/15] mm/memory: optimize fork() with PTE-mapped THP Ryan Roberts
2024-01-31 11:06   ` David Hildenbrand
2024-01-31 11:16     ` Ryan Roberts
2024-01-31 11:28       ` David Hildenbrand
2024-01-31 11:49         ` Ryan Roberts
2024-01-31 12:37           ` Ryan Roberts
2024-01-31 12:56             ` David Hildenbrand
2024-01-31 13:16               ` Ryan Roberts
2024-01-31 13:38                 ` David Hildenbrand
2024-01-31 13:58                   ` Ryan Roberts
2024-01-31 14:29                     ` David Hildenbrand
2024-01-31 15:02                       ` Ryan Roberts
2024-01-31 15:05                         ` David Hildenbrand
2024-01-31 15:08                           ` Ryan Roberts
2024-01-31 15:11                             ` David Hildenbrand
2024-01-31 12:59           ` David Hildenbrand
2024-03-25  4:42 ` patchwork-bot+linux-riscv

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=ZcRwc2mEDHIXxgGa@kernel.org \
    --to=rppt@kernel.org \
    --cc=agordeev@linux.ibm.com \
    --cc=akpm@linux-foundation.org \
    --cc=aneesh.kumar@kernel.org \
    --cc=aou@eecs.berkeley.edu \
    --cc=borntraeger@linux.ibm.com \
    --cc=catalin.marinas@arm.com \
    --cc=christophe.leroy@csgroup.eu \
    --cc=davem@davemloft.net \
    --cc=david@redhat.com \
    --cc=dinguyen@kernel.org \
    --cc=gerald.schaefer@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mpe@ellerman.id.au \
    --cc=naveen.n.rao@linux.ibm.com \
    --cc=npiggin@gmail.com \
    --cc=palmer@dabbelt.com \
    --cc=paul.walmsley@sifive.com \
    --cc=ryan.roberts@arm.com \
    --cc=sparclinux@vger.kernel.org \
    --cc=svens@linux.ibm.com \
    --cc=will@kernel.org \
    --cc=willy@infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).