All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anshuman Khandual <anshuman.khandual@arm.com>
To: Gavin Shan <gshan@redhat.com>, linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org, gerald.schaefer@linux.ibm.com,
	aneesh.kumar@linux.ibm.com, christophe.leroy@csgroup.eu,
	cai@lca.pw, catalin.marinas@arm.com, will@kernel.org,
	akpm@linux-foundation.org, chuhu@redhat.com,
	shan.gavin@gmail.com
Subject: Re: [PATCH v4 01/12] mm/debug_vm_pgtable: Introduce struct pgtable_debug_args
Date: Wed, 28 Jul 2021 13:02:36 +0530	[thread overview]
Message-ID: <9977fea4-ff36-390a-3a5a-58f088dab111@arm.com> (raw)
In-Reply-To: <20210727061401.592616-2-gshan@redhat.com>



On 7/27/21 11:43 AM, Gavin Shan wrote:
> In debug_vm_pgtable(), there are many local variables introduced to
> track the needed information and they are passed to the functions for
> various test cases. It'd better to introduce a struct as place holder
> for these information. With it, what the tests functions need is the
> struct. In this way, the code is simplified and easier to be maintained.
> 
> Besides, set_xxx_at() could access the data on the corresponding pages
> in the page table modifying tests. So the accessed pages in the tests
> should have been allocated from buddy. Otherwise, we're accessing pages
> that aren't owned by us. This causes issues like page flag corruption
> or kernel crash on accessing unmapped page when CONFIG_DEBUG_PAGEALLOC
> is enabled.
> 
> This introduces "struct pgtable_debug_args". The struct is initialized
> and destroyed, but the information in the struct isn't used yet. It will
> be used in subsequent patches.
> 
> Signed-off-by: Gavin Shan <gshan@redhat.com>
> ---
>  mm/debug_vm_pgtable.c | 280 +++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 279 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/debug_vm_pgtable.c b/mm/debug_vm_pgtable.c
> index 1c922691aa61..8c7361643166 100644
> --- a/mm/debug_vm_pgtable.c
> +++ b/mm/debug_vm_pgtable.c
> @@ -58,6 +58,37 @@
>  #define RANDOM_ORVALUE (GENMASK(BITS_PER_LONG - 1, 0) & ~ARCH_SKIP_MASK)
>  #define RANDOM_NZVALUE	GENMASK(7, 0)
>  
> +struct pgtable_debug_args {
> +	struct mm_struct	*mm;
> +	struct vm_area_struct	*vma;
> +
> +	pgd_t			*pgdp;
> +	p4d_t			*p4dp;
> +	pud_t			*pudp;
> +	pmd_t			*pmdp;
> +	pte_t			*ptep;
> +
> +	p4d_t			*start_p4dp;
> +	pud_t			*start_pudp;
> +	pmd_t			*start_pmdp;
> +	pgtable_t		start_ptep;
> +
> +	unsigned long		vaddr;
> +	pgprot_t		page_prot;
> +	pgprot_t		page_prot_none;
> +
> +	bool			is_contiguous_page;
> +	unsigned long		pud_pfn;
> +	unsigned long		pmd_pfn;
> +	unsigned long		pte_pfn;
> +
> +	unsigned long		fixed_pgd_pfn;
> +	unsigned long		fixed_p4d_pfn;
> +	unsigned long		fixed_pud_pfn;
> +	unsigned long		fixed_pmd_pfn;
> +	unsigned long		fixed_pte_pfn;
> +};
> +
>  static void __init pte_basic_tests(unsigned long pfn, int idx)
>  {
>  	pgprot_t prot = protection_map[idx];
> @@ -955,8 +986,249 @@ static unsigned long __init get_random_vaddr(void)
>  	return random_vaddr;
>  }
>  
> +static void __init destroy_args(struct pgtable_debug_args *args)
> +{
> +	struct page *page = NULL;
> +
> +	/* Free (huge) page */
> +	if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) &&
> +	    IS_ENABLED(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD) &&
> +	    has_transparent_hugepage() &&
> +	    args->pud_pfn != ULONG_MAX) {
> +		if (args->is_contiguous_page) {
> +			free_contig_range(args->pud_pfn,
> +					  (1 << (HPAGE_PUD_SHIFT - PAGE_SHIFT)));
> +		} else {
> +			page = pfn_to_page(args->pud_pfn);
> +			__free_pages(page, HPAGE_PUD_SHIFT - PAGE_SHIFT);
> +		}
> +
> +		args->pud_pfn = ULONG_MAX;
> +		args->pmd_pfn = ULONG_MAX;
> +		args->pte_pfn = ULONG_MAX;
> +	}
> +
> +	if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) &&
> +	    has_transparent_hugepage() &&
> +	    args->pmd_pfn != ULONG_MAX) {
> +		if (args->is_contiguous_page) {
> +			free_contig_range(args->pmd_pfn, (1 << HPAGE_PMD_ORDER));
> +		} else {
> +			page = pfn_to_page(args->pmd_pfn);
> +			__free_pages(page, HPAGE_PMD_ORDER);
> +		}
> +
> +		args->pmd_pfn = ULONG_MAX;
> +		args->pte_pfn = ULONG_MAX;
> +	}
> +
> +	if (args->pte_pfn != ULONG_MAX) {
> +		page = pfn_to_page(args->pte_pfn);
> +		__free_pages(page, 0);
> +	}
> +
> +	/* Free page table entries */
> +	if (args->start_ptep) {
> +		pte_free(args->mm, args->start_ptep);
> +		mm_dec_nr_ptes(args->mm);
> +	}
> +
> +	if (args->start_pmdp) {
> +		pmd_free(args->mm, args->start_pmdp);
> +		mm_dec_nr_pmds(args->mm);
> +	}
> +
> +	if (args->start_pudp) {
> +		pud_free(args->mm, args->start_pudp);
> +		mm_dec_nr_puds(args->mm);
> +	}
> +
> +	if (args->start_p4dp)
> +		p4d_free(args->mm, args->p4dp);

				     ^^^^ s/args->p4dp/args->start_p4dp ?

  reply	other threads:[~2021-07-28  7:31 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-27  6:13 [PATCH v4 00/12] mm/debug_vm_pgtable: Enhancements Gavin Shan
2021-07-27  6:13 ` [PATCH v4 01/12] mm/debug_vm_pgtable: Introduce struct pgtable_debug_args Gavin Shan
2021-07-28  7:32   ` Anshuman Khandual [this message]
2021-07-28  7:38     ` Gavin Shan
2021-07-29  4:45   ` Anshuman Khandual
2021-07-29  9:40     ` Gavin Shan
2021-07-27  6:13 ` [PATCH v4 02/12] mm/debug_vm_pgtable: Use struct pgtable_debug_args in basic tests Gavin Shan
2021-07-29  4:53   ` Anshuman Khandual
2021-07-27  6:13 ` [PATCH v4 03/12] mm/debug_vm_pgtable: Use struct pgtable_debug_args in leaf and savewrite tests Gavin Shan
2021-07-29  5:00   ` Anshuman Khandual
2021-07-27  6:13 ` [PATCH v4 04/12] mm/debug_vm_pgtable: Use struct pgtable_debug_args in protnone and devmap tests Gavin Shan
2021-07-29  5:02   ` Anshuman Khandual
2021-07-27  6:13 ` [PATCH v4 05/12] mm/debug_vm_pgtable: Use struct pgtable_debug_args in soft_dirty and swap tests Gavin Shan
2021-07-29  5:07   ` Anshuman Khandual
2021-07-27  6:13 ` [PATCH v4 06/12] mm/debug_vm_pgtable: Use struct pgtable_debug_args in migration and thp tests Gavin Shan
2021-07-28 11:08   ` Anshuman Khandual
2021-07-28 23:54     ` Gavin Shan
2021-07-27  6:13 ` [PATCH v4 07/12] mm/debug_vm_pgtable: Use struct pgtable_debug_args in PTE modifying tests Gavin Shan
2021-07-29  5:16   ` Anshuman Khandual
2021-07-27  6:13 ` [PATCH v4 08/12] mm/debug_vm_pgtable: Use struct pgtable_debug_args in PMD " Gavin Shan
2021-07-29  5:30   ` Anshuman Khandual
2021-07-27  6:13 ` [PATCH v4 09/12] mm/debug_vm_pgtable: Use struct pgtable_debug_args in PUD " Gavin Shan
2021-07-29  5:44   ` Anshuman Khandual
2021-07-27  6:13 ` [PATCH v4 10/12] mm/debug_vm_pgtable: Use struct pgtable_debug_args in PGD and P4D " Gavin Shan
2021-07-29  5:51   ` Anshuman Khandual
2021-07-27  6:14 ` [PATCH v4 11/12] mm/debug_vm_pgtable: Remove unused code Gavin Shan
2021-07-29  5:59   ` Anshuman Khandual
2021-07-27  6:14 ` [PATCH v4 12/12] mm/debug_vm_pgtable: Fix corrupted page flag Gavin Shan
2021-07-28  7:53   ` Christophe Leroy
2021-07-28 10:05     ` Anshuman Khandual
2021-07-29  0:00       ` Gavin Shan
2021-07-29  6:05   ` Anshuman Khandual
2021-07-29  7:14 ` [PATCH v4 00/12] mm/debug_vm_pgtable: Enhancements Anshuman Khandual
2021-08-02  0:09   ` Gavin Shan
2021-08-02  4:53     ` Anshuman Khandual

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=9977fea4-ff36-390a-3a5a-58f088dab111@arm.com \
    --to=anshuman.khandual@arm.com \
    --cc=akpm@linux-foundation.org \
    --cc=aneesh.kumar@linux.ibm.com \
    --cc=cai@lca.pw \
    --cc=catalin.marinas@arm.com \
    --cc=christophe.leroy@csgroup.eu \
    --cc=chuhu@redhat.com \
    --cc=gerald.schaefer@linux.ibm.com \
    --cc=gshan@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=shan.gavin@gmail.com \
    --cc=will@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.