Re: [PATCH RFC 06/39] mm/rmap: add hugetlb sanity checks

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 12/4/23 22:21, David Hildenbrand wrote:
> Let's make sure we end up with the right folios in the right functions.
> 
> Signed-off-by: David Hildenbrand <david@xxxxxxxxxx>

Reviewed-by: Yin Fengwei <fengwei.yin@xxxxxxxxx>

> ---
>  include/linux/rmap.h | 7 +++++++
>  mm/rmap.c            | 6 ++++++
>  2 files changed, 13 insertions(+)
> 
> diff --git a/include/linux/rmap.h b/include/linux/rmap.h
> index 3f38141b53b9d..77e336f86c72d 100644
> --- a/include/linux/rmap.h
> +++ b/include/linux/rmap.h
> @@ -212,6 +212,7 @@ void hugetlb_add_new_anon_rmap(struct folio *, struct vm_area_struct *,
>  static inline int hugetlb_try_dup_anon_rmap(struct folio *folio,
>  		struct vm_area_struct *vma)
>  {
> +	VM_WARN_ON_FOLIO(!folio_test_hugetlb(folio), folio);
>  	VM_WARN_ON_FOLIO(!folio_test_anon(folio), folio);
>  
>  	if (PageAnonExclusive(&folio->page)) {
> @@ -226,6 +227,7 @@ static inline int hugetlb_try_dup_anon_rmap(struct folio *folio,
>  /* See page_try_share_anon_rmap() */
>  static inline int hugetlb_try_share_anon_rmap(struct folio *folio)
>  {
> +	VM_WARN_ON_FOLIO(!folio_test_hugetlb(folio), folio);
>  	VM_WARN_ON_FOLIO(!folio_test_anon(folio), folio);
>  	VM_WARN_ON_FOLIO(!PageAnonExclusive(&folio->page), folio);
>  
> @@ -245,6 +247,7 @@ static inline int hugetlb_try_share_anon_rmap(struct folio *folio)
>  
>  static inline void hugetlb_add_file_rmap(struct folio *folio)
>  {
> +	VM_WARN_ON_FOLIO(!folio_test_hugetlb(folio), folio);
>  	VM_WARN_ON_FOLIO(folio_test_anon(folio), folio);
>  
>  	atomic_inc(&folio->_entire_mapcount);
> @@ -252,11 +255,15 @@ static inline void hugetlb_add_file_rmap(struct folio *folio)
>  
>  static inline void hugetlb_remove_rmap(struct folio *folio)
>  {
> +	VM_WARN_ON_FOLIO(!folio_test_hugetlb(folio), folio);
> +
>  	atomic_dec(&folio->_entire_mapcount);
>  }
>  
>  static inline void __page_dup_rmap(struct page *page, bool compound)
>  {
> +	VM_WARN_ON(folio_test_hugetlb(page_folio(page)));
> +
>  	if (compound) {
>  		struct folio *folio = (struct folio *)page;
>  
> diff --git a/mm/rmap.c b/mm/rmap.c
> index 2f1af3958e687..a735ecca47a81 100644
> --- a/mm/rmap.c
> +++ b/mm/rmap.c
> @@ -1313,6 +1313,7 @@ void folio_add_new_anon_rmap(struct folio *folio, struct vm_area_struct *vma,
>  {
>  	int nr;
>  
> +	VM_WARN_ON_FOLIO(folio_test_hugetlb(folio), folio);
>  	VM_BUG_ON_VMA(address < vma->vm_start || address >= vma->vm_end, vma);
>  	__folio_set_swapbacked(folio);
>  
> @@ -1353,6 +1354,7 @@ void folio_add_file_rmap_range(struct folio *folio, struct page *page,
>  	unsigned int nr_pmdmapped = 0, first;
>  	int nr = 0;
>  
> +	VM_WARN_ON_FOLIO(folio_test_hugetlb(folio), folio);
>  	VM_WARN_ON_FOLIO(compound && !folio_test_pmd_mappable(folio), folio);
>  
>  	/* Is page being mapped by PTE? Is this its first map to be added? */
> @@ -1438,6 +1440,7 @@ void page_remove_rmap(struct page *page, struct vm_area_struct *vma,
>  	bool last;
>  	enum node_stat_item idx;
>  
> +	VM_WARN_ON_FOLIO(folio_test_hugetlb(folio), folio);
>  	VM_BUG_ON_PAGE(compound && !PageHead(page), page);
>  
>  	/* Is page being unmapped by PTE? Is this its last map to be removed? */
> @@ -2590,6 +2593,7 @@ void rmap_walk_locked(struct folio *folio, struct rmap_walk_control *rwc)
>  void hugetlb_add_anon_rmap(struct folio *folio, struct vm_area_struct *vma,
>  		unsigned long address, rmap_t flags)
>  {
> +	VM_WARN_ON_FOLIO(!folio_test_hugetlb(folio), folio);
>  	VM_WARN_ON_FOLIO(!folio_test_anon(folio), folio);
>  
>  	atomic_inc(&folio->_entire_mapcount);
> @@ -2602,6 +2606,8 @@ void hugetlb_add_anon_rmap(struct folio *folio, struct vm_area_struct *vma,
>  void hugetlb_add_new_anon_rmap(struct folio *folio,
>  		struct vm_area_struct *vma, unsigned long address)
>  {
> +	VM_WARN_ON_FOLIO(!folio_test_hugetlb(folio), folio);
> +
>  	BUG_ON(address < vma->vm_start || address >= vma->vm_end);
>  	/* increment count (starts at -1) */
>  	atomic_set(&folio->_entire_mapcount, 0);




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux