From patchwork Tue Jul 6 06:17:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 12359815 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C7FCC07E96 for ; Tue, 6 Jul 2021 06:18:13 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EA4F26128E for ; Tue, 6 Jul 2021 06:18:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EA4F26128E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id BBB726B006C; Tue, 6 Jul 2021 02:18:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B91B66B0070; Tue, 6 Jul 2021 02:18:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A0B786B0071; Tue, 6 Jul 2021 02:18:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0189.hostedemail.com [216.40.44.189]) by kanga.kvack.org (Postfix) with ESMTP id 7E36A6B006C for ; Tue, 6 Jul 2021 02:18:12 -0400 (EDT) Received: from smtpin38.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 001541857D for ; Tue, 6 Jul 2021 06:18:11 +0000 (UTC) X-FDA: 78331158024.38.B3DFF72 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf21.hostedemail.com (Postfix) with ESMTP id 50437D0008A0 for ; Tue, 6 Jul 2021 06:18:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625552290; h=from:from:reply-to:subject:subject: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=hpwSgpFLoDsdkUovQ9z2uwcbJjcZlIAZZdxuaSnsMUg=; b=byZKcKmEpf0pQ9iXKwU7QcfwhNf1SXTtKrW7tty7Zc7rjOwVSwahTw5qV8LuPRLc3euD9p 81y5vNJ+RAIU9k4rOxqKQHPSPPc/39S14+jMB9uyH0k42xGOFZ5t1vIdNjCFdfqxf8AGQD m40f5i2VAo793KsTJ3qnW+hA0PAfsj8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-100-DwZIVDjnPJOxW-kURgutTA-1; Tue, 06 Jul 2021 02:18:07 -0400 X-MC-Unique: DwZIVDjnPJOxW-kURgutTA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 747C11800D41; Tue, 6 Jul 2021 06:18:06 +0000 (UTC) Received: from gshan.redhat.com (vpn2-54-119.bne.redhat.com [10.64.54.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id EA77C60583; Tue, 6 Jul 2021 06:18:00 +0000 (UTC) From: Gavin Shan To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, anshuman.khandual@arm.com, catalin.marinas@arm.com, will@kernel.org, akpm@linux-foundation.org, shan.gavin@gmail.com, chuhu@redhat.com Subject: [PATCH 01/12] mm/debug_vm_pgtable: Introduce struct vm_pgtable_debug Date: Tue, 6 Jul 2021 14:17:37 +0800 Message-Id: <20210706061748.161258-2-gshan@redhat.com> In-Reply-To: <20210706061748.161258-1-gshan@redhat.com> References: <20210706061748.161258-1-gshan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 50437D0008A0 X-Stat-Signature: 9317z4kcz8fzq7yspftsu9b3j1pppkiq Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=byZKcKmE; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf21.hostedemail.com: domain of gshan@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=gshan@redhat.com X-HE-Tag: 1625552291-258886 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: 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 functions for various test cases need is the struct, to simplify the code. It makes the code easier to be maintained. Besides, set_pte_at() could access the data on the corresponding pages. So the test cases using set_pte_at() should have the pages allocated from buddy. Otherwise, we're acceessing pages that aren't owned by us. This causes issues like page flag corruption. So we need the allocated pages for these tests where set_pte_at() is used. The struct is introduced so that the old and new implementation can coexist so that the patches can be organized in a easy way. This introduces "struct vm_pgtable_debug" for above purposes. The struct is initialized and destroyed, but the information in the struct isn't used yet. They will be used in subsequent patches. Signed-off-by: Gavin Shan --- mm/debug_vm_pgtable.c | 210 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 209 insertions(+), 1 deletion(-) diff --git a/mm/debug_vm_pgtable.c b/mm/debug_vm_pgtable.c index 1c922691aa61..225e2ea4d72f 100644 --- a/mm/debug_vm_pgtable.c +++ b/mm/debug_vm_pgtable.c @@ -58,6 +58,36 @@ #define RANDOM_ORVALUE (GENMASK(BITS_PER_LONG - 1, 0) & ~ARCH_SKIP_MASK) #define RANDOM_NZVALUE GENMASK(7, 0) +struct vm_pgtable_debug { + 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; + + 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 +985,180 @@ static unsigned long __init get_random_vaddr(void) return random_vaddr; } +static void __init free_mem(struct vm_pgtable_debug *debug) +{ + struct page *page = NULL; + int order = 0; + + /* Free (huge) page */ +#ifdef CONFIG_TRANSPARENT_HUGEPAGE +#ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD + if (has_transparent_hugepage() && + debug->pud_pfn != ULONG_MAX) { + page = pfn_to_page(debug->pud_pfn); + order = HPAGE_PUD_SHIFT - PAGE_SHIFT; + } +#endif + + if (has_transparent_hugepage() && + debug->pmd_pfn != ULONG_MAX && !page) { + page = pfn_to_page(debug->pmd_pfn); + order = HPAGE_PMD_ORDER; + } +#endif + + if (debug->pte_pfn != ULONG_MAX && !page) { + page = pfn_to_page(debug->pte_pfn); + order = 0; + } + + if (page) + __free_pages(page, order); + + /* Free page table */ + if (debug->start_ptep) { + pte_free(debug->mm, debug->start_ptep); + mm_dec_nr_ptes(debug->mm); + } + + if (debug->start_pmdp) { + pmd_free(debug->mm, debug->start_pmdp); + mm_dec_nr_pmds(debug->mm); + } + + if (debug->start_pudp) { + pud_free(debug->mm, debug->start_pudp); + mm_dec_nr_puds(debug->mm); + } + + if (debug->start_p4dp) + p4d_free(debug->mm, debug->p4dp); + + /* Free vma and mm struct */ + if (debug->vma) + vm_area_free(debug->vma); + if (debug->mm) + mmdrop(debug->mm); +} + +static int __init alloc_mem(struct vm_pgtable_debug *debug) +{ + struct page *page = NULL; + phys_addr_t phys; + int ret = 0; + + /* Initialize the debugging data */ + debug->mm = NULL; + debug->vma = NULL; + debug->pgdp = NULL; + debug->p4dp = NULL; + debug->pudp = NULL; + debug->pmdp = NULL; + debug->ptep = NULL; + debug->start_p4dp = NULL; + debug->start_pudp = NULL; + debug->start_pmdp = NULL; + debug->start_ptep = NULL; + debug->vaddr = 0UL; + debug->page_prot = vm_get_page_prot(VM_READ | VM_WRITE | VM_EXEC); + debug->page_prot_none = __P000; + debug->pud_pfn = ULONG_MAX; + debug->pmd_pfn = ULONG_MAX; + debug->pte_pfn = ULONG_MAX; + debug->fixed_pgd_pfn = ULONG_MAX; + debug->fixed_p4d_pfn = ULONG_MAX; + debug->fixed_pud_pfn = ULONG_MAX; + debug->fixed_pmd_pfn = ULONG_MAX; + debug->fixed_pte_pfn = ULONG_MAX; + + /* Allocate mm and vma */ + debug->mm = mm_alloc(); + if (!debug->mm) { + pr_warn("Failed to allocate mm struct\n"); + ret = -ENOMEM; + goto error; + } + + debug->vma = vm_area_alloc(debug->mm); + if (!debug->vma) { + pr_warn("Failed to allocate vma\n"); + ret = -ENOMEM; + goto error; + } + + /* Figure out the virtual address and allocate page table entries */ + debug->vaddr = get_random_vaddr(); + debug->pgdp = pgd_offset(debug->mm, debug->vaddr); + debug->p4dp = p4d_alloc(debug->mm, debug->pgdp, debug->vaddr); + debug->pudp = debug->p4dp ? + pud_alloc(debug->mm, debug->p4dp, debug->vaddr) : NULL; + debug->pmdp = debug->pudp ? + pmd_alloc(debug->mm, debug->pudp, debug->vaddr) : NULL; + debug->ptep = debug->pmdp ? + pte_alloc_map(debug->mm, debug->pmdp, debug->vaddr) : NULL; + if (!debug->ptep) { + pr_warn("Failed to allocate page table\n"); + ret = -ENOMEM; + goto error; + } + + /* + * The above page table entries will be modified. Lets save the + * page table entries so that they can be released when the tests + * are completed. + */ + debug->start_p4dp = p4d_offset(debug->pgdp, 0UL); + debug->start_pudp = pud_offset(debug->p4dp, 0UL); + debug->start_pmdp = pmd_offset(debug->pudp, 0UL); + debug->start_ptep = pmd_pgtable(*(debug->pmdp)); + + /* + * Figure out the fixed addresses, which are all around the kernel + * symbol (@start_kernel). The corresponding PFNs might be invalid, + * but it's fine as the following tests won't access the pages. + */ + phys = __pa_symbol(&start_kernel); + debug->fixed_pgd_pfn = __phys_to_pfn(phys & PGDIR_MASK); + debug->fixed_p4d_pfn = __phys_to_pfn(phys & P4D_MASK); + debug->fixed_pud_pfn = __phys_to_pfn(phys & PUD_MASK); + debug->fixed_pmd_pfn = __phys_to_pfn(phys & PMD_MASK); + debug->fixed_pte_pfn = __phys_to_pfn(phys & PAGE_MASK); + + /* + * Allocate (huge) pages because some of the tests need to access + * the data in the pages. The corresponding tests will be skipped + * if we fail to allocate (huge) pages. + */ +#ifdef CONFIG_TRANSPARENT_HUGEPAGE +#ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD + if (has_transparent_hugepage()) { + page = alloc_pages(GFP_KERNEL, HPAGE_PUD_SHIFT - PAGE_SHIFT); + if (page) + debug->pud_pfn = page_to_pfn(page); + } +#endif + + if (has_transparent_hugepage()) { + page = page ? page : alloc_pages(GFP_KERNEL, HPAGE_PMD_ORDER); + if (page) + debug->pmd_pfn = page_to_pfn(page); + } +#endif + + page = page ? page : alloc_pages(GFP_KERNEL, 0); + if (page) + debug->pte_pfn = page_to_pfn(page); + + return 0; + +error: + free_mem(debug); + return ret; +} + static int __init debug_vm_pgtable(void) { + struct vm_pgtable_debug debug; struct vm_area_struct *vma; struct mm_struct *mm; pgd_t *pgdp; @@ -970,9 +1172,13 @@ static int __init debug_vm_pgtable(void) unsigned long vaddr, pte_aligned, pmd_aligned; unsigned long pud_aligned, p4d_aligned, pgd_aligned; spinlock_t *ptl = NULL; - int idx; + int idx, ret; pr_info("Validating architecture page table helpers\n"); + ret = alloc_mem(&debug); + if (ret) + return ret; + prot = vm_get_page_prot(VMFLAGS); vaddr = get_random_vaddr(); mm = mm_alloc(); @@ -1127,6 +1333,8 @@ static int __init debug_vm_pgtable(void) mm_dec_nr_pmds(mm); mm_dec_nr_ptes(mm); mmdrop(mm); + + free_mem(&debug); return 0; } late_initcall(debug_vm_pgtable); From patchwork Tue Jul 6 06:17:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 12359817 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EB16FC07E96 for ; Tue, 6 Jul 2021 06:18:18 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9CB736128E for ; Tue, 6 Jul 2021 06:18:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9CB736128E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 74EA26B0071; Tue, 6 Jul 2021 02:18:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 725936B0072; Tue, 6 Jul 2021 02:18:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5C67A6B0073; Tue, 6 Jul 2021 02:18:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0234.hostedemail.com [216.40.44.234]) by kanga.kvack.org (Postfix) with ESMTP id 3ACA46B0071 for ; Tue, 6 Jul 2021 02:18:18 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id B154918064A51 for ; Tue, 6 Jul 2021 06:18:17 +0000 (UTC) X-FDA: 78331158234.16.D9C6FB5 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf05.hostedemail.com (Postfix) with ESMTP id 5B0CE500377E for ; Tue, 6 Jul 2021 06:18:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625552296; h=from:from:reply-to:subject:subject: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=SxpKf50j3O10GJyNjIQZVgEWk6Jo+0mI+zNXP97fMs8=; b=govQaD7HeYr1u163IzOuSyZN1Oz6m3myKlsloX0+jOMTOdufthQTk64Wrf3B4XILXYnH7H 4M0DQfA09kmbgb4dvoGsmZG2OaDcFCwEYBNoEdsmKNZe7DGvJG55xum5GFrF7rQrOn2a1E Hk6OeAUtYw7eBzGP4bPrgNSIzOYzQEg= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-220-ljQffE8xNmaRCPxNR6JMuA-1; Tue, 06 Jul 2021 02:18:13 -0400 X-MC-Unique: ljQffE8xNmaRCPxNR6JMuA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5B42710C1ADC; Tue, 6 Jul 2021 06:18:12 +0000 (UTC) Received: from gshan.redhat.com (vpn2-54-119.bne.redhat.com [10.64.54.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id 26AD22C00F; Tue, 6 Jul 2021 06:18:06 +0000 (UTC) From: Gavin Shan To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, anshuman.khandual@arm.com, catalin.marinas@arm.com, will@kernel.org, akpm@linux-foundation.org, shan.gavin@gmail.com, chuhu@redhat.com Subject: [PATCH 02/12] mm/debug_vm_pgtable: Use struct vm_pgtable_debug in basic tests Date: Tue, 6 Jul 2021 14:17:38 +0800 Message-Id: <20210706061748.161258-3-gshan@redhat.com> In-Reply-To: <20210706061748.161258-1-gshan@redhat.com> References: <20210706061748.161258-1-gshan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=govQaD7H; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf05.hostedemail.com: domain of gshan@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=gshan@redhat.com X-Rspamd-Server: rspam02 X-Stat-Signature: t7ohn6re1bgcedr63tn4t5b1iwumth1o X-Rspamd-Queue-Id: 5B0CE500377E X-HE-Tag: 1625552297-139025 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: This uses struct vm_pgtable_debug in the basic test functions. There are more cleanups applied: * Move hugetlb_basic_tests() so that the basic tests are treated as a bundle. * Drop parameters to {pgd, p4d}_basic_tests() as they're never used. Signed-off-by: Gavin Shan --- mm/debug_vm_pgtable.c | 47 +++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/mm/debug_vm_pgtable.c b/mm/debug_vm_pgtable.c index 225e2ea4d72f..759f27e1046e 100644 --- a/mm/debug_vm_pgtable.c +++ b/mm/debug_vm_pgtable.c @@ -88,10 +88,10 @@ struct vm_pgtable_debug { unsigned long fixed_pte_pfn; }; -static void __init pte_basic_tests(unsigned long pfn, int idx) +static void __init pte_basic_tests(struct vm_pgtable_debug *debug, int idx) { pgprot_t prot = protection_map[idx]; - pte_t pte = pfn_pte(pfn, prot); + pte_t pte = pfn_pte(debug->fixed_pte_pfn, prot); unsigned long val = idx, *ptr = &val; pr_debug("Validating PTE basic (%pGv)\n", ptr); @@ -173,7 +173,7 @@ static void __init pte_savedwrite_tests(unsigned long pfn, pgprot_t prot) } #ifdef CONFIG_TRANSPARENT_HUGEPAGE -static void __init pmd_basic_tests(unsigned long pfn, int idx) +static void __init pmd_basic_tests(struct vm_pgtable_debug *debug, int idx) { pgprot_t prot = protection_map[idx]; unsigned long val = idx, *ptr = &val; @@ -183,7 +183,7 @@ static void __init pmd_basic_tests(unsigned long pfn, int idx) return; pr_debug("Validating PMD basic (%pGv)\n", ptr); - pmd = pfn_pmd(pfn, prot); + pmd = pfn_pmd(debug->fixed_pmd_pfn, prot); /* * This test needs to be executed after the given page table entry @@ -295,7 +295,7 @@ static void __init pmd_savedwrite_tests(unsigned long pfn, pgprot_t prot) } #ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD -static void __init pud_basic_tests(struct mm_struct *mm, unsigned long pfn, int idx) +static void __init pud_basic_tests(struct vm_pgtable_debug *debug, int idx) { pgprot_t prot = protection_map[idx]; unsigned long val = idx, *ptr = &val; @@ -305,7 +305,7 @@ static void __init pud_basic_tests(struct mm_struct *mm, unsigned long pfn, int return; pr_debug("Validating PUD basic (%pGv)\n", ptr); - pud = pfn_pud(pfn, prot); + pud = pfn_pud(debug->fixed_pud_pfn, prot); /* * This test needs to be executed after the given page table entry @@ -326,7 +326,7 @@ static void __init pud_basic_tests(struct mm_struct *mm, unsigned long pfn, int WARN_ON(pud_dirty(pud_wrprotect(pud_mkclean(pud)))); WARN_ON(!pud_dirty(pud_wrprotect(pud_mkdirty(pud)))); - if (mm_pmd_folded(mm)) + if (mm_pmd_folded(debug->mm)) return; /* @@ -403,7 +403,7 @@ static void __init pud_leaf_tests(unsigned long pfn, pgprot_t prot) WARN_ON(!pud_leaf(pud)); } #else /* !CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */ -static void __init pud_basic_tests(struct mm_struct *mm, unsigned long pfn, int idx) { } +static void __init pud_basic_tests(struct vm_pgtable_debug *debug, int idx) { } static void __init pud_advanced_tests(struct mm_struct *mm, struct vm_area_struct *vma, pud_t *pudp, unsigned long pfn, unsigned long vaddr, @@ -413,8 +413,8 @@ static void __init pud_advanced_tests(struct mm_struct *mm, static void __init pud_leaf_tests(unsigned long pfn, pgprot_t prot) { } #endif /* CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */ #else /* !CONFIG_TRANSPARENT_HUGEPAGE */ -static void __init pmd_basic_tests(unsigned long pfn, int idx) { } -static void __init pud_basic_tests(struct mm_struct *mm, unsigned long pfn, int idx) { } +static void __init pmd_basic_tests(struct vm_pgtable_debug *debug, int idx) { } +static void __init pud_basic_tests(struct vm_pgtable_debug *debug, int idx) { } static void __init pmd_advanced_tests(struct mm_struct *mm, struct vm_area_struct *vma, pmd_t *pmdp, unsigned long pfn, unsigned long vaddr, @@ -475,7 +475,7 @@ static void __init pmd_huge_tests(pmd_t *pmdp, unsigned long pfn, pgprot_t prot) static void __init pud_huge_tests(pud_t *pudp, unsigned long pfn, pgprot_t prot) { } #endif /* CONFIG_HAVE_ARCH_HUGE_VMAP */ -static void __init p4d_basic_tests(unsigned long pfn, pgprot_t prot) +static void __init p4d_basic_tests(void) { p4d_t p4d; @@ -484,7 +484,7 @@ static void __init p4d_basic_tests(unsigned long pfn, pgprot_t prot) WARN_ON(!p4d_same(p4d, p4d)); } -static void __init pgd_basic_tests(unsigned long pfn, pgprot_t prot) +static void __init pgd_basic_tests(void) { pgd_t pgd; @@ -889,7 +889,7 @@ static void __init swap_migration_tests(void) } #ifdef CONFIG_HUGETLB_PAGE -static void __init hugetlb_basic_tests(unsigned long pfn, pgprot_t prot) +static void __init hugetlb_basic_tests(struct vm_pgtable_debug *debug) { struct page *page; pte_t pte; @@ -899,21 +899,21 @@ static void __init hugetlb_basic_tests(unsigned long pfn, pgprot_t prot) * Accessing the page associated with the pfn is safe here, * as it was previously derived from a real kernel symbol. */ - page = pfn_to_page(pfn); - pte = mk_huge_pte(page, prot); + page = pfn_to_page(debug->fixed_pmd_pfn); + pte = mk_huge_pte(page, debug->page_prot); WARN_ON(!huge_pte_dirty(huge_pte_mkdirty(pte))); WARN_ON(!huge_pte_write(huge_pte_mkwrite(huge_pte_wrprotect(pte)))); WARN_ON(huge_pte_write(huge_pte_wrprotect(huge_pte_mkwrite(pte)))); #ifdef CONFIG_ARCH_WANT_GENERAL_HUGETLB - pte = pfn_pte(pfn, prot); + pte = pfn_pte(debug->fixed_pmd_pfn, debug->page_prot); WARN_ON(!pte_huge(pte_mkhuge(pte))); #endif /* CONFIG_ARCH_WANT_GENERAL_HUGETLB */ } #else /* !CONFIG_HUGETLB_PAGE */ -static void __init hugetlb_basic_tests(unsigned long pfn, pgprot_t prot) { } +static void __init hugetlb_basic_tests(struct vm_pgtable_debug *debug) { } #endif /* CONFIG_HUGETLB_PAGE */ #ifdef CONFIG_TRANSPARENT_HUGEPAGE @@ -1248,9 +1248,9 @@ static int __init debug_vm_pgtable(void) * given page table entry. */ for (idx = 0; idx < ARRAY_SIZE(protection_map); idx++) { - pte_basic_tests(pte_aligned, idx); - pmd_basic_tests(pmd_aligned, idx); - pud_basic_tests(mm, pud_aligned, idx); + pte_basic_tests(&debug, idx); + pmd_basic_tests(&debug, idx); + pud_basic_tests(&debug, idx); } /* @@ -1260,8 +1260,9 @@ static int __init debug_vm_pgtable(void) * the above iteration for now to save some test execution * time. */ - p4d_basic_tests(p4d_aligned, prot); - pgd_basic_tests(pgd_aligned, prot); + p4d_basic_tests(); + pgd_basic_tests(); + hugetlb_basic_tests(&debug); pmd_leaf_tests(pmd_aligned, prot); pud_leaf_tests(pud_aligned, prot); @@ -1290,8 +1291,6 @@ static int __init debug_vm_pgtable(void) pmd_thp_tests(pmd_aligned, prot); pud_thp_tests(pud_aligned, prot); - hugetlb_basic_tests(pte_aligned, prot); - /* * Page table modifying tests. They need to hold * proper page table lock. From patchwork Tue Jul 6 06:17:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 12359819 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AE1E0C07E96 for ; Tue, 6 Jul 2021 06:18:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5BCB961988 for ; Tue, 6 Jul 2021 06:18:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5BCB961988 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 357726B0072; Tue, 6 Jul 2021 02:18:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 32CFF6B0073; Tue, 6 Jul 2021 02:18:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1CE806B0074; Tue, 6 Jul 2021 02:18:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0208.hostedemail.com [216.40.44.208]) by kanga.kvack.org (Postfix) with ESMTP id F06C76B0072 for ; Tue, 6 Jul 2021 02:18:21 -0400 (EDT) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 73053824999B for ; Tue, 6 Jul 2021 06:18:21 +0000 (UTC) X-FDA: 78331158402.10.65548BE Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf02.hostedemail.com (Postfix) with ESMTP id EFC817001A06 for ; Tue, 6 Jul 2021 06:18:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625552300; h=from:from:reply-to:subject:subject: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=yqWqc3qJ5Z1i9z5/ocO7SPqVFa7kPAf7B1uDwOvhDPQ=; b=PTjuVmDHPv+0DRejGZSCYIYlUAI0DlGkT8umbgj2zrd983hIajHjcbcUesEmeSk/dakKBN mrCCDdtejVNYTo8p1OS1vGlnLXqZpzMwzATlSCZlO+c0ARPgRHAjC7OIzs/7LDb16PTOKX kMOQz3DgpGInrWr4J7ilYZsi9nMoVEs= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-175-WKmQyO3uMbSZPhKBR1qALQ-1; Tue, 06 Jul 2021 02:18:17 -0400 X-MC-Unique: WKmQyO3uMbSZPhKBR1qALQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B6A781800D41; Tue, 6 Jul 2021 06:18:15 +0000 (UTC) Received: from gshan.redhat.com (vpn2-54-119.bne.redhat.com [10.64.54.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id D746560583; Tue, 6 Jul 2021 06:18:12 +0000 (UTC) From: Gavin Shan To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, anshuman.khandual@arm.com, catalin.marinas@arm.com, will@kernel.org, akpm@linux-foundation.org, shan.gavin@gmail.com, chuhu@redhat.com Subject: [PATCH 03/12] mm/debug_vm_pgtable: Use struct vm_pgtable_debug in leaf and savewrite tests Date: Tue, 6 Jul 2021 14:17:39 +0800 Message-Id: <20210706061748.161258-4-gshan@redhat.com> In-Reply-To: <20210706061748.161258-1-gshan@redhat.com> References: <20210706061748.161258-1-gshan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: EFC817001A06 X-Stat-Signature: guj1egrzij31h5ndef6uk7495nir94e9 Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=PTjuVmDH; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf02.hostedemail.com: domain of gshan@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=gshan@redhat.com X-HE-Tag: 1625552300-930347 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: This uses struct vm_pgtable_debug in the leaf and savewrite test functions. Signed-off-by: Gavin Shan --- mm/debug_vm_pgtable.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/mm/debug_vm_pgtable.c b/mm/debug_vm_pgtable.c index 759f27e1046e..00ddce30c6ca 100644 --- a/mm/debug_vm_pgtable.c +++ b/mm/debug_vm_pgtable.c @@ -160,9 +160,9 @@ static void __init pte_advanced_tests(struct mm_struct *mm, WARN_ON(pte_young(pte)); } -static void __init pte_savedwrite_tests(unsigned long pfn, pgprot_t prot) +static void __init pte_savedwrite_tests(struct vm_pgtable_debug *debug) { - pte_t pte = pfn_pte(pfn, prot); + pte_t pte = pfn_pte(debug->fixed_pte_pfn, debug->page_prot_none); if (!IS_ENABLED(CONFIG_NUMA_BALANCING)) return; @@ -261,7 +261,7 @@ static void __init pmd_advanced_tests(struct mm_struct *mm, pgtable = pgtable_trans_huge_withdraw(mm, pmdp); } -static void __init pmd_leaf_tests(unsigned long pfn, pgprot_t prot) +static void __init pmd_leaf_tests(struct vm_pgtable_debug *debug) { pmd_t pmd; @@ -269,7 +269,7 @@ static void __init pmd_leaf_tests(unsigned long pfn, pgprot_t prot) return; pr_debug("Validating PMD leaf\n"); - pmd = pfn_pmd(pfn, prot); + pmd = pfn_pmd(debug->fixed_pmd_pfn, debug->page_prot); /* * PMD based THP is a leaf entry. @@ -278,7 +278,7 @@ static void __init pmd_leaf_tests(unsigned long pfn, pgprot_t prot) WARN_ON(!pmd_leaf(pmd)); } -static void __init pmd_savedwrite_tests(unsigned long pfn, pgprot_t prot) +static void __init pmd_savedwrite_tests(struct vm_pgtable_debug *debug) { pmd_t pmd; @@ -289,7 +289,7 @@ static void __init pmd_savedwrite_tests(unsigned long pfn, pgprot_t prot) return; pr_debug("Validating PMD saved write\n"); - pmd = pfn_pmd(pfn, prot); + pmd = pfn_pmd(debug->fixed_pmd_pfn, debug->page_prot_none); WARN_ON(!pmd_savedwrite(pmd_mk_savedwrite(pmd_clear_savedwrite(pmd)))); WARN_ON(pmd_savedwrite(pmd_clear_savedwrite(pmd_mk_savedwrite(pmd)))); } @@ -387,7 +387,7 @@ static void __init pud_advanced_tests(struct mm_struct *mm, pudp_huge_get_and_clear(mm, vaddr, pudp); } -static void __init pud_leaf_tests(unsigned long pfn, pgprot_t prot) +static void __init pud_leaf_tests(struct vm_pgtable_debug *debug) { pud_t pud; @@ -395,7 +395,7 @@ static void __init pud_leaf_tests(unsigned long pfn, pgprot_t prot) return; pr_debug("Validating PUD leaf\n"); - pud = pfn_pud(pfn, prot); + pud = pfn_pud(debug->fixed_pud_pfn, debug->page_prot); /* * PUD based THP is a leaf entry. */ @@ -410,7 +410,7 @@ static void __init pud_advanced_tests(struct mm_struct *mm, pgprot_t prot) { } -static void __init pud_leaf_tests(unsigned long pfn, pgprot_t prot) { } +static void __init pud_leaf_tests(struct vm_pgtable_debug *debug) { } #endif /* CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */ #else /* !CONFIG_TRANSPARENT_HUGEPAGE */ static void __init pmd_basic_tests(struct vm_pgtable_debug *debug, int idx) { } @@ -427,9 +427,9 @@ static void __init pud_advanced_tests(struct mm_struct *mm, pgprot_t prot) { } -static void __init pmd_leaf_tests(unsigned long pfn, pgprot_t prot) { } -static void __init pud_leaf_tests(unsigned long pfn, pgprot_t prot) { } -static void __init pmd_savedwrite_tests(unsigned long pfn, pgprot_t prot) { } +static void __init pmd_leaf_tests(struct vm_pgtable_debug *debug) { } +static void __init pud_leaf_tests(struct vm_pgtable_debug *debug) { } +static void __init pmd_savedwrite_tests(struct vm_pgtable_debug *debug) { } #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ #ifdef CONFIG_HAVE_ARCH_HUGE_VMAP @@ -1264,11 +1264,11 @@ static int __init debug_vm_pgtable(void) pgd_basic_tests(); hugetlb_basic_tests(&debug); - pmd_leaf_tests(pmd_aligned, prot); - pud_leaf_tests(pud_aligned, prot); + pmd_leaf_tests(&debug); + pud_leaf_tests(&debug); - pte_savedwrite_tests(pte_aligned, protnone); - pmd_savedwrite_tests(pmd_aligned, protnone); + pte_savedwrite_tests(&debug); + pmd_savedwrite_tests(&debug); pte_special_tests(pte_aligned, prot); pte_protnone_tests(pte_aligned, protnone); From patchwork Tue Jul 6 06:17:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 12359821 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93E3EC07E9C for ; Tue, 6 Jul 2021 06:18:24 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2B3D66128E for ; Tue, 6 Jul 2021 06:18:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2B3D66128E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id EF0386B0073; Tue, 6 Jul 2021 02:18:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EA24F6B0074; Tue, 6 Jul 2021 02:18:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D1AEF6B0075; Tue, 6 Jul 2021 02:18:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0050.hostedemail.com [216.40.44.50]) by kanga.kvack.org (Postfix) with ESMTP id ABC446B0073 for ; Tue, 6 Jul 2021 02:18:23 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 22E6C18ED7 for ; Tue, 6 Jul 2021 06:18:23 +0000 (UTC) X-FDA: 78331158486.24.4BE4C1D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf30.hostedemail.com (Postfix) with ESMTP id 86833E0016BB for ; Tue, 6 Jul 2021 06:18:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625552302; h=from:from:reply-to:subject:subject: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=/2fHwz8f+R11Ghnan8DHffCQMDEr89Mbu17MGhyW0ZQ=; b=K7sM7/1erhp5med425NMlKIzhyTfpow8XYhXnxuhekcj67aQze2lDRU1Pn0db07MTkAkUG TOHEOLOuXI0YmMnMtzferfRxCisd7ZTf+07bL6Y2riQO7TkbcSgKTBxnSIJ6ZUYD2oM6Ft tebsV25PtPS6LEZCj2TtpPqMudndKWM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-314-nLFyZ7y_PlKbdhtAOMivIw-1; Tue, 06 Jul 2021 02:18:20 -0400 X-MC-Unique: nLFyZ7y_PlKbdhtAOMivIw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 71D95804302; Tue, 6 Jul 2021 06:18:19 +0000 (UTC) Received: from gshan.redhat.com (vpn2-54-119.bne.redhat.com [10.64.54.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6C5E560583; Tue, 6 Jul 2021 06:18:15 +0000 (UTC) From: Gavin Shan To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, anshuman.khandual@arm.com, catalin.marinas@arm.com, will@kernel.org, akpm@linux-foundation.org, shan.gavin@gmail.com, chuhu@redhat.com Subject: [PATCH 04/12] mm/debug_vm_pgtable: Use struct vm_pgtable_debug in protnone and devmap tests Date: Tue, 6 Jul 2021 14:17:40 +0800 Message-Id: <20210706061748.161258-5-gshan@redhat.com> In-Reply-To: <20210706061748.161258-1-gshan@redhat.com> References: <20210706061748.161258-1-gshan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="K7sM7/1e"; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf30.hostedemail.com: domain of gshan@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=gshan@redhat.com X-Stat-Signature: i3ucff6krfds1ku73rggenuixoh6ejr1 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 86833E0016BB X-HE-Tag: 1625552302-833482 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: This uses struct vm_pgtable_debug in protnone and devmap test functions. Signed-off-by: Gavin Shan --- mm/debug_vm_pgtable.c | 50 +++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/mm/debug_vm_pgtable.c b/mm/debug_vm_pgtable.c index 00ddce30c6ca..cfb3dfb0447e 100644 --- a/mm/debug_vm_pgtable.c +++ b/mm/debug_vm_pgtable.c @@ -661,9 +661,9 @@ static void __init pmd_populate_tests(struct mm_struct *mm, pmd_t *pmdp, WARN_ON(pmd_bad(pmd)); } -static void __init pte_special_tests(unsigned long pfn, pgprot_t prot) +static void __init pte_special_tests(struct vm_pgtable_debug *debug) { - pte_t pte = pfn_pte(pfn, prot); + pte_t pte = pfn_pte(debug->fixed_pte_pfn, debug->page_prot); if (!IS_ENABLED(CONFIG_ARCH_HAS_PTE_SPECIAL)) return; @@ -672,9 +672,9 @@ static void __init pte_special_tests(unsigned long pfn, pgprot_t prot) WARN_ON(!pte_special(pte_mkspecial(pte))); } -static void __init pte_protnone_tests(unsigned long pfn, pgprot_t prot) +static void __init pte_protnone_tests(struct vm_pgtable_debug *debug) { - pte_t pte = pfn_pte(pfn, prot); + pte_t pte = pfn_pte(debug->fixed_pte_pfn, debug->page_prot_none); if (!IS_ENABLED(CONFIG_NUMA_BALANCING)) return; @@ -685,7 +685,7 @@ static void __init pte_protnone_tests(unsigned long pfn, pgprot_t prot) } #ifdef CONFIG_TRANSPARENT_HUGEPAGE -static void __init pmd_protnone_tests(unsigned long pfn, pgprot_t prot) +static void __init pmd_protnone_tests(struct vm_pgtable_debug *debug) { pmd_t pmd; @@ -696,25 +696,25 @@ static void __init pmd_protnone_tests(unsigned long pfn, pgprot_t prot) return; pr_debug("Validating PMD protnone\n"); - pmd = pmd_mkhuge(pfn_pmd(pfn, prot)); + pmd = pmd_mkhuge(pfn_pmd(debug->fixed_pmd_pfn, debug->page_prot_none)); WARN_ON(!pmd_protnone(pmd)); WARN_ON(!pmd_present(pmd)); } #else /* !CONFIG_TRANSPARENT_HUGEPAGE */ -static void __init pmd_protnone_tests(unsigned long pfn, pgprot_t prot) { } +static void __init pmd_protnone_tests(struct vm_pgtable_debug *debug) { } #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ #ifdef CONFIG_ARCH_HAS_PTE_DEVMAP -static void __init pte_devmap_tests(unsigned long pfn, pgprot_t prot) +static void __init pte_devmap_tests(struct vm_pgtable_debug *debug) { - pte_t pte = pfn_pte(pfn, prot); + pte_t pte = pfn_pte(debug->fixed_pte_pfn, debug->page_prot); pr_debug("Validating PTE devmap\n"); WARN_ON(!pte_devmap(pte_mkdevmap(pte))); } #ifdef CONFIG_TRANSPARENT_HUGEPAGE -static void __init pmd_devmap_tests(unsigned long pfn, pgprot_t prot) +static void __init pmd_devmap_tests(struct vm_pgtable_debug *debug) { pmd_t pmd; @@ -722,12 +722,12 @@ static void __init pmd_devmap_tests(unsigned long pfn, pgprot_t prot) return; pr_debug("Validating PMD devmap\n"); - pmd = pfn_pmd(pfn, prot); + pmd = pfn_pmd(debug->fixed_pmd_pfn, debug->page_prot); WARN_ON(!pmd_devmap(pmd_mkdevmap(pmd))); } #ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD -static void __init pud_devmap_tests(unsigned long pfn, pgprot_t prot) +static void __init pud_devmap_tests(struct vm_pgtable_debug *debug) { pud_t pud; @@ -735,20 +735,20 @@ static void __init pud_devmap_tests(unsigned long pfn, pgprot_t prot) return; pr_debug("Validating PUD devmap\n"); - pud = pfn_pud(pfn, prot); + pud = pfn_pud(debug->fixed_pud_pfn, debug->page_prot); WARN_ON(!pud_devmap(pud_mkdevmap(pud))); } #else /* !CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */ -static void __init pud_devmap_tests(unsigned long pfn, pgprot_t prot) { } +static void __init pud_devmap_tests(struct vm_pgtable_debug *debug) { } #endif /* CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */ #else /* CONFIG_TRANSPARENT_HUGEPAGE */ -static void __init pmd_devmap_tests(unsigned long pfn, pgprot_t prot) { } -static void __init pud_devmap_tests(unsigned long pfn, pgprot_t prot) { } +static void __init pmd_devmap_tests(struct vm_pgtable_debug *debug) { } +static void __init pud_devmap_tests(struct vm_pgtable_debug *debug) { } #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ #else -static void __init pte_devmap_tests(unsigned long pfn, pgprot_t prot) { } -static void __init pmd_devmap_tests(unsigned long pfn, pgprot_t prot) { } -static void __init pud_devmap_tests(unsigned long pfn, pgprot_t prot) { } +static void __init pte_devmap_tests(struct vm_pgtable_debug *debug) { } +static void __init pmd_devmap_tests(struct vm_pgtable_debug *debug) { } +static void __init pud_devmap_tests(struct vm_pgtable_debug *debug) { } #endif /* CONFIG_ARCH_HAS_PTE_DEVMAP */ static void __init pte_soft_dirty_tests(unsigned long pfn, pgprot_t prot) @@ -1270,13 +1270,13 @@ static int __init debug_vm_pgtable(void) pte_savedwrite_tests(&debug); pmd_savedwrite_tests(&debug); - pte_special_tests(pte_aligned, prot); - pte_protnone_tests(pte_aligned, protnone); - pmd_protnone_tests(pmd_aligned, protnone); + pte_special_tests(&debug); + pte_protnone_tests(&debug); + pmd_protnone_tests(&debug); - pte_devmap_tests(pte_aligned, prot); - pmd_devmap_tests(pmd_aligned, prot); - pud_devmap_tests(pud_aligned, prot); + pte_devmap_tests(&debug); + pmd_devmap_tests(&debug); + pud_devmap_tests(&debug); pte_soft_dirty_tests(pte_aligned, prot); pmd_soft_dirty_tests(pmd_aligned, prot); From patchwork Tue Jul 6 06:17:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 12359823 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4842CC07E9C for ; Tue, 6 Jul 2021 06:18:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8990F6198D for ; Tue, 6 Jul 2021 06:18:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8990F6198D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5A1896B0074; Tue, 6 Jul 2021 02:18:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 576EC6B0075; Tue, 6 Jul 2021 02:18:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 440A56B0078; Tue, 6 Jul 2021 02:18:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 22B1E6B0074 for ; Tue, 6 Jul 2021 02:18:28 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id A5C8B18021856 for ; Tue, 6 Jul 2021 06:18:27 +0000 (UTC) X-FDA: 78331158654.30.40B213B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf28.hostedemail.com (Postfix) with ESMTP id 572B090000A3 for ; Tue, 6 Jul 2021 06:18:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625552306; h=from:from:reply-to:subject:subject: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=fCFBqkpZgP/Z0/ZzWRbd+xN5AltcaGMWwLkPEJqMw/8=; b=JQqXeA7uIqt1a/2gB00pWD/BIHQWijbvAOttrKhCiOZwLksUUClgcgZGIhHjSlOQvnXMpL Mo2fxCaMuBzCINrkk7X/AZkOSJvQXNdz3CQyxiZAz03Vd7YZIaktyltDhTze3PulDLMnsA Son1YL2AIwn66ejoWfxKmlCbIzaZHg4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-594-1EuPmPaHOQCEGyRXK4qKzw-1; Tue, 06 Jul 2021 02:18:23 -0400 X-MC-Unique: 1EuPmPaHOQCEGyRXK4qKzw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 15B22800D62; Tue, 6 Jul 2021 06:18:22 +0000 (UTC) Received: from gshan.redhat.com (vpn2-54-119.bne.redhat.com [10.64.54.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0B56A60583; Tue, 6 Jul 2021 06:18:19 +0000 (UTC) From: Gavin Shan To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, anshuman.khandual@arm.com, catalin.marinas@arm.com, will@kernel.org, akpm@linux-foundation.org, shan.gavin@gmail.com, chuhu@redhat.com Subject: [PATCH 05/12] mm/vm_debug_pgtable: Use struct vm_pgtable_debug in soft_dirty and swap tests Date: Tue, 6 Jul 2021 14:17:41 +0800 Message-Id: <20210706061748.161258-6-gshan@redhat.com> In-Reply-To: <20210706061748.161258-1-gshan@redhat.com> References: <20210706061748.161258-1-gshan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JQqXeA7u; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf28.hostedemail.com: domain of gshan@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=gshan@redhat.com X-Rspamd-Server: rspam02 X-Stat-Signature: xjtjmpx63qokhczk6eie4rremxwq3ap6 X-Rspamd-Queue-Id: 572B090000A3 X-HE-Tag: 1625552307-583505 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: This uses struct vm_pgtable_debug in the soft_dirty and swap test functions. Signed-off-by: Gavin Shan --- mm/debug_vm_pgtable.c | 48 +++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/mm/debug_vm_pgtable.c b/mm/debug_vm_pgtable.c index cfb3dfb0447e..eb0a836a73ad 100644 --- a/mm/debug_vm_pgtable.c +++ b/mm/debug_vm_pgtable.c @@ -751,9 +751,9 @@ static void __init pmd_devmap_tests(struct vm_pgtable_debug *debug) { } static void __init pud_devmap_tests(struct vm_pgtable_debug *debug) { } #endif /* CONFIG_ARCH_HAS_PTE_DEVMAP */ -static void __init pte_soft_dirty_tests(unsigned long pfn, pgprot_t prot) +static void __init pte_soft_dirty_tests(struct vm_pgtable_debug *debug) { - pte_t pte = pfn_pte(pfn, prot); + pte_t pte = pfn_pte(debug->fixed_pte_pfn, debug->page_prot); if (!IS_ENABLED(CONFIG_MEM_SOFT_DIRTY)) return; @@ -763,9 +763,9 @@ static void __init pte_soft_dirty_tests(unsigned long pfn, pgprot_t prot) WARN_ON(pte_soft_dirty(pte_clear_soft_dirty(pte))); } -static void __init pte_swap_soft_dirty_tests(unsigned long pfn, pgprot_t prot) +static void __init pte_swap_soft_dirty_tests(struct vm_pgtable_debug *debug) { - pte_t pte = pfn_pte(pfn, prot); + pte_t pte = pfn_pte(debug->fixed_pte_pfn, debug->page_prot); if (!IS_ENABLED(CONFIG_MEM_SOFT_DIRTY)) return; @@ -776,7 +776,7 @@ static void __init pte_swap_soft_dirty_tests(unsigned long pfn, pgprot_t prot) } #ifdef CONFIG_TRANSPARENT_HUGEPAGE -static void __init pmd_soft_dirty_tests(unsigned long pfn, pgprot_t prot) +static void __init pmd_soft_dirty_tests(struct vm_pgtable_debug *debug) { pmd_t pmd; @@ -787,12 +787,12 @@ static void __init pmd_soft_dirty_tests(unsigned long pfn, pgprot_t prot) return; pr_debug("Validating PMD soft dirty\n"); - pmd = pfn_pmd(pfn, prot); + pmd = pfn_pmd(debug->fixed_pmd_pfn, debug->page_prot); WARN_ON(!pmd_soft_dirty(pmd_mksoft_dirty(pmd))); WARN_ON(pmd_soft_dirty(pmd_clear_soft_dirty(pmd))); } -static void __init pmd_swap_soft_dirty_tests(unsigned long pfn, pgprot_t prot) +static void __init pmd_swap_soft_dirty_tests(struct vm_pgtable_debug *debug) { pmd_t pmd; @@ -804,31 +804,29 @@ static void __init pmd_swap_soft_dirty_tests(unsigned long pfn, pgprot_t prot) return; pr_debug("Validating PMD swap soft dirty\n"); - pmd = pfn_pmd(pfn, prot); + pmd = pfn_pmd(debug->fixed_pmd_pfn, debug->page_prot); WARN_ON(!pmd_swp_soft_dirty(pmd_swp_mksoft_dirty(pmd))); WARN_ON(pmd_swp_soft_dirty(pmd_swp_clear_soft_dirty(pmd))); } #else /* !CONFIG_TRANSPARENT_HUGEPAGE */ -static void __init pmd_soft_dirty_tests(unsigned long pfn, pgprot_t prot) { } -static void __init pmd_swap_soft_dirty_tests(unsigned long pfn, pgprot_t prot) -{ -} +static void __init pmd_soft_dirty_tests(struct vm_pgtable_debug *debug) { } +static void __init pmd_swap_soft_dirty_tests(struct vm_pgtable_debug *debug) { } #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ -static void __init pte_swap_tests(unsigned long pfn, pgprot_t prot) +static void __init pte_swap_tests(struct vm_pgtable_debug *debug) { swp_entry_t swp; pte_t pte; pr_debug("Validating PTE swap\n"); - pte = pfn_pte(pfn, prot); + pte = pfn_pte(debug->fixed_pte_pfn, debug->page_prot); swp = __pte_to_swp_entry(pte); pte = __swp_entry_to_pte(swp); - WARN_ON(pfn != pte_pfn(pte)); + WARN_ON(debug->fixed_pte_pfn != pte_pfn(pte)); } #ifdef CONFIG_ARCH_ENABLE_THP_MIGRATION -static void __init pmd_swap_tests(unsigned long pfn, pgprot_t prot) +static void __init pmd_swap_tests(struct vm_pgtable_debug *debug) { swp_entry_t swp; pmd_t pmd; @@ -837,13 +835,13 @@ static void __init pmd_swap_tests(unsigned long pfn, pgprot_t prot) return; pr_debug("Validating PMD swap\n"); - pmd = pfn_pmd(pfn, prot); + pmd = pfn_pmd(debug->fixed_pmd_pfn, debug->page_prot); swp = __pmd_to_swp_entry(pmd); pmd = __swp_entry_to_pmd(swp); - WARN_ON(pfn != pmd_pfn(pmd)); + WARN_ON(debug->fixed_pmd_pfn != pmd_pfn(pmd)); } #else /* !CONFIG_ARCH_ENABLE_THP_MIGRATION */ -static void __init pmd_swap_tests(unsigned long pfn, pgprot_t prot) { } +static void __init pmd_swap_tests(struct vm_pgtable_debug *debug) { } #endif /* CONFIG_ARCH_ENABLE_THP_MIGRATION */ static void __init swap_migration_tests(void) @@ -1278,13 +1276,13 @@ static int __init debug_vm_pgtable(void) pmd_devmap_tests(&debug); pud_devmap_tests(&debug); - pte_soft_dirty_tests(pte_aligned, prot); - pmd_soft_dirty_tests(pmd_aligned, prot); - pte_swap_soft_dirty_tests(pte_aligned, prot); - pmd_swap_soft_dirty_tests(pmd_aligned, prot); + pte_soft_dirty_tests(&debug); + pmd_soft_dirty_tests(&debug); + pte_swap_soft_dirty_tests(&debug); + pmd_swap_soft_dirty_tests(&debug); - pte_swap_tests(pte_aligned, prot); - pmd_swap_tests(pmd_aligned, prot); + pte_swap_tests(&debug); + pmd_swap_tests(&debug); swap_migration_tests(); From patchwork Tue Jul 6 06:17:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 12359825 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F36C4C07E96 for ; Tue, 6 Jul 2021 06:18:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AE3E06128E for ; Tue, 6 Jul 2021 06:18:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AE3E06128E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id F3F556B0075; Tue, 6 Jul 2021 02:18:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F11646B0078; Tue, 6 Jul 2021 02:18:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CCAD66B007B; Tue, 6 Jul 2021 02:18:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0235.hostedemail.com [216.40.44.235]) by kanga.kvack.org (Postfix) with ESMTP id AA6B86B0075 for ; Tue, 6 Jul 2021 02:18:28 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 242A018021856 for ; Tue, 6 Jul 2021 06:18:28 +0000 (UTC) X-FDA: 78331158696.19.046068C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf22.hostedemail.com (Postfix) with ESMTP id CB4E71985 for ; Tue, 6 Jul 2021 06:18:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625552307; h=from:from:reply-to:subject:subject: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=0ityYjh9siN+cqt37lMH9iM8Kf6RLNgbJQFwFFwEp1c=; b=bkDkH2tSP+U9vvsci5Roiiz1Sq75LYDU86AsQZstWu9eYHIvTkwNRbOVgDt0psn9F3qpzQ 9LK/gCf8OGZ0uryAi3WMMwQbr1aLOJfALnCQb22Z9jSwdsMhpOy34xjvAjvwfiO7ErSig6 TYjVJ27hMm9JyOZM3JgVarJVc9rZsPU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-333-ZUYQh8yQMBeQUgTYI9qmEQ-1; Tue, 06 Jul 2021 02:18:26 -0400 X-MC-Unique: ZUYQh8yQMBeQUgTYI9qmEQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 815EC1800D41; Tue, 6 Jul 2021 06:18:24 +0000 (UTC) Received: from gshan.redhat.com (vpn2-54-119.bne.redhat.com [10.64.54.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7A19260583; Tue, 6 Jul 2021 06:18:22 +0000 (UTC) From: Gavin Shan To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, anshuman.khandual@arm.com, catalin.marinas@arm.com, will@kernel.org, akpm@linux-foundation.org, shan.gavin@gmail.com, chuhu@redhat.com Subject: [PATCH 06/12] mm/debug_vm_pgtable: Use struct vm_pgtable_debug in migration and thp tests Date: Tue, 6 Jul 2021 14:17:42 +0800 Message-Id: <20210706061748.161258-7-gshan@redhat.com> In-Reply-To: <20210706061748.161258-1-gshan@redhat.com> References: <20210706061748.161258-1-gshan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bkDkH2tS; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf22.hostedemail.com: domain of gshan@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=gshan@redhat.com X-Rspamd-Server: rspam02 X-Stat-Signature: xzst6rzuf57sc6ox9inptorzbbdc6aah X-Rspamd-Queue-Id: CB4E71985 X-HE-Tag: 1625552307-84649 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: This uses struct vm_pgtable_debug in the migration and thp test functions. It's notable that the pre-allocated page is used in swap_migration_tests() as set_pte_at() is used there. Signed-off-by: Gavin Shan --- mm/debug_vm_pgtable.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/mm/debug_vm_pgtable.c b/mm/debug_vm_pgtable.c index eb0a836a73ad..757d2d9c4e93 100644 --- a/mm/debug_vm_pgtable.c +++ b/mm/debug_vm_pgtable.c @@ -844,7 +844,7 @@ static void __init pmd_swap_tests(struct vm_pgtable_debug *debug) static void __init pmd_swap_tests(struct vm_pgtable_debug *debug) { } #endif /* CONFIG_ARCH_ENABLE_THP_MIGRATION */ -static void __init swap_migration_tests(void) +static void __init swap_migration_tests(struct vm_pgtable_debug *debug) { struct page *page; swp_entry_t swp; @@ -860,9 +860,10 @@ static void __init swap_migration_tests(void) * problematic. Lets allocate a dedicated page explicitly for this * purpose that will be freed subsequently. */ - page = alloc_page(GFP_KERNEL); + page = (debug->pte_pfn != ULONG_MAX) ? + pfn_to_page(debug->pte_pfn) : NULL; if (!page) { - pr_err("page allocation failed\n"); + pr_err("no page available\n"); return; } @@ -883,7 +884,6 @@ static void __init swap_migration_tests(void) WARN_ON(!is_migration_entry(swp)); WARN_ON(is_writable_migration_entry(swp)); __ClearPageLocked(page); - __free_page(page); } #ifdef CONFIG_HUGETLB_PAGE @@ -915,7 +915,7 @@ static void __init hugetlb_basic_tests(struct vm_pgtable_debug *debug) { } #endif /* CONFIG_HUGETLB_PAGE */ #ifdef CONFIG_TRANSPARENT_HUGEPAGE -static void __init pmd_thp_tests(unsigned long pfn, pgprot_t prot) +static void __init pmd_thp_tests(struct vm_pgtable_debug *debug) { pmd_t pmd; @@ -934,7 +934,7 @@ static void __init pmd_thp_tests(unsigned long pfn, pgprot_t prot) * needs to return true. pmd_present() should be true whenever * pmd_trans_huge() returns true. */ - pmd = pfn_pmd(pfn, prot); + pmd = pfn_pmd(debug->fixed_pmd_pfn, debug->page_prot); WARN_ON(!pmd_trans_huge(pmd_mkhuge(pmd))); #ifndef __HAVE_ARCH_PMDP_INVALIDATE @@ -944,7 +944,7 @@ static void __init pmd_thp_tests(unsigned long pfn, pgprot_t prot) } #ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD -static void __init pud_thp_tests(unsigned long pfn, pgprot_t prot) +static void __init pud_thp_tests(struct vm_pgtable_debug *debug) { pud_t pud; @@ -952,7 +952,7 @@ static void __init pud_thp_tests(unsigned long pfn, pgprot_t prot) return; pr_debug("Validating PUD based THP\n"); - pud = pfn_pud(pfn, prot); + pud = pfn_pud(debug->fixed_pud_pfn, debug->page_prot); WARN_ON(!pud_trans_huge(pud_mkhuge(pud))); /* @@ -964,11 +964,11 @@ static void __init pud_thp_tests(unsigned long pfn, pgprot_t prot) */ } #else /* !CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */ -static void __init pud_thp_tests(unsigned long pfn, pgprot_t prot) { } +static void __init pud_thp_tests(struct vm_pgtable_debug *debug) { } #endif /* CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */ #else /* !CONFIG_TRANSPARENT_HUGEPAGE */ -static void __init pmd_thp_tests(unsigned long pfn, pgprot_t prot) { } -static void __init pud_thp_tests(unsigned long pfn, pgprot_t prot) { } +static void __init pmd_thp_tests(struct vm_pgtable_debug *debug) { } +static void __init pud_thp_tests(struct vm_pgtable_debug *debug) { } #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ static unsigned long __init get_random_vaddr(void) @@ -1284,10 +1284,10 @@ static int __init debug_vm_pgtable(void) pte_swap_tests(&debug); pmd_swap_tests(&debug); - swap_migration_tests(); + swap_migration_tests(&debug); - pmd_thp_tests(pmd_aligned, prot); - pud_thp_tests(pud_aligned, prot); + pmd_thp_tests(&debug); + pud_thp_tests(&debug); /* * Page table modifying tests. They need to hold From patchwork Tue Jul 6 06:17:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 12359827 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75B48C07E96 for ; Tue, 6 Jul 2021 06:18:33 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 27F946128E for ; Tue, 6 Jul 2021 06:18:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 27F946128E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id F16356B0078; Tue, 6 Jul 2021 02:18:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EED876B007B; Tue, 6 Jul 2021 02:18:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D8DEF6B007D; Tue, 6 Jul 2021 02:18:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0144.hostedemail.com [216.40.44.144]) by kanga.kvack.org (Postfix) with ESMTP id B8C386B0078 for ; Tue, 6 Jul 2021 02:18:32 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 441FB1944E for ; Tue, 6 Jul 2021 06:18:32 +0000 (UTC) X-FDA: 78331158864.09.EAE3223 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf06.hostedemail.com (Postfix) with ESMTP id EE089801AF30 for ; Tue, 6 Jul 2021 06:18:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625552311; h=from:from:reply-to:subject:subject: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=o1RqI6/k+gLG4IBAoruYRzV3DbWVpzskLQJDvjLcGQg=; b=PhS5ytQWduEs20zHoJot5Egpa8w+amF8BtuRmDr4+wCAL3K9aQOGyVlS1sgItf7K3C4nTn ESE/IamIX/qivOqvKkZ1S7Hex+o6LXt7RZAv4eGhgjBaLTz+kQ9E5Y0xlsHPZtkvKlut6H kTUWPKpy6VfD8JjB1eNhd0ZU+KdL7yk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-467-XhIQ4N8fPpacsNAEXHbrPg-1; Tue, 06 Jul 2021 02:18:29 -0400 X-MC-Unique: XhIQ4N8fPpacsNAEXHbrPg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2C441100CEC1; Tue, 6 Jul 2021 06:18:28 +0000 (UTC) Received: from gshan.redhat.com (vpn2-54-119.bne.redhat.com [10.64.54.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id F250560583; Tue, 6 Jul 2021 06:18:24 +0000 (UTC) From: Gavin Shan To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, anshuman.khandual@arm.com, catalin.marinas@arm.com, will@kernel.org, akpm@linux-foundation.org, shan.gavin@gmail.com, chuhu@redhat.com Subject: [PATCH 07/12] mm/debug_vm_pgtable: Use struct vm_pgtable_debug in PTE modifying tests Date: Tue, 6 Jul 2021 14:17:43 +0800 Message-Id: <20210706061748.161258-8-gshan@redhat.com> In-Reply-To: <20210706061748.161258-1-gshan@redhat.com> References: <20210706061748.161258-1-gshan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=PhS5ytQW; spf=none (imf06.hostedemail.com: domain of gshan@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=gshan@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Stat-Signature: 8scc7i85cxi9kwu3oh17tt941s8qgup9 X-Rspamd-Queue-Id: EE089801AF30 X-Rspamd-Server: rspam06 X-HE-Tag: 1625552311-567841 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: This uses struct vm_pgtable_debug in PTE modifying tests. The allocated page is used as set_pte_at() is used there. The tests are skipped if the allocated page doesn't exist. Signed-off-by: Gavin Shan --- mm/debug_vm_pgtable.c | 71 +++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/mm/debug_vm_pgtable.c b/mm/debug_vm_pgtable.c index 757d2d9c4e93..2b4f0738f266 100644 --- a/mm/debug_vm_pgtable.c +++ b/mm/debug_vm_pgtable.c @@ -116,10 +116,7 @@ static void __init pte_basic_tests(struct vm_pgtable_debug *debug, int idx) WARN_ON(!pte_dirty(pte_wrprotect(pte_mkdirty(pte)))); } -static void __init pte_advanced_tests(struct mm_struct *mm, - struct vm_area_struct *vma, pte_t *ptep, - unsigned long pfn, unsigned long vaddr, - pgprot_t prot) +static void __init pte_advanced_tests(struct vm_pgtable_debug *debug) { pte_t pte; @@ -130,33 +127,38 @@ static void __init pte_advanced_tests(struct mm_struct *mm, */ pr_debug("Validating PTE advanced\n"); - pte = pfn_pte(pfn, prot); - set_pte_at(mm, vaddr, ptep, pte); - ptep_set_wrprotect(mm, vaddr, ptep); - pte = ptep_get(ptep); + if (debug->pte_pfn == ULONG_MAX) { + pr_debug("%s: Skipped\n", __func__); + return; + } + + pte = pfn_pte(debug->pte_pfn, debug->page_prot); + set_pte_at(debug->mm, debug->vaddr, debug->ptep, pte); + ptep_set_wrprotect(debug->mm, debug->vaddr, debug->ptep); + pte = ptep_get(debug->ptep); WARN_ON(pte_write(pte)); - ptep_get_and_clear(mm, vaddr, ptep); - pte = ptep_get(ptep); + ptep_get_and_clear(debug->mm, debug->vaddr, debug->ptep); + pte = ptep_get(debug->ptep); WARN_ON(!pte_none(pte)); - pte = pfn_pte(pfn, prot); + pte = pfn_pte(debug->pte_pfn, debug->page_prot); pte = pte_wrprotect(pte); pte = pte_mkclean(pte); - set_pte_at(mm, vaddr, ptep, pte); + set_pte_at(debug->mm, debug->vaddr, debug->ptep, pte); pte = pte_mkwrite(pte); pte = pte_mkdirty(pte); - ptep_set_access_flags(vma, vaddr, ptep, pte, 1); - pte = ptep_get(ptep); + ptep_set_access_flags(debug->vma, debug->vaddr, debug->ptep, pte, 1); + pte = ptep_get(debug->ptep); WARN_ON(!(pte_write(pte) && pte_dirty(pte))); - ptep_get_and_clear_full(mm, vaddr, ptep, 1); - pte = ptep_get(ptep); + ptep_get_and_clear_full(debug->mm, debug->vaddr, debug->ptep, 1); + pte = ptep_get(debug->ptep); WARN_ON(!pte_none(pte)); - pte = pfn_pte(pfn, prot); + pte = pfn_pte(debug->pte_pfn, debug->page_prot); pte = pte_mkyoung(pte); - set_pte_at(mm, vaddr, ptep, pte); - ptep_test_and_clear_young(vma, vaddr, ptep); - pte = ptep_get(ptep); + set_pte_at(debug->mm, debug->vaddr, debug->ptep, pte); + ptep_test_and_clear_young(debug->vma, debug->vaddr, debug->ptep); + pte = ptep_get(debug->ptep); WARN_ON(pte_young(pte)); } @@ -617,20 +619,24 @@ static void __init pgd_populate_tests(struct mm_struct *mm, pgd_t *pgdp, } #endif /* PAGETABLE_P4D_FOLDED */ -static void __init pte_clear_tests(struct mm_struct *mm, pte_t *ptep, - unsigned long pfn, unsigned long vaddr, - pgprot_t prot) +static void __init pte_clear_tests(struct vm_pgtable_debug *debug) { - pte_t pte = pfn_pte(pfn, prot); + pte_t pte; pr_debug("Validating PTE clear\n"); + if (debug->pte_pfn == ULONG_MAX) { + pr_debug("%s: Skipped\n", __func__); + return; + } + + pte = pfn_pte(debug->pte_pfn, debug->page_prot); #ifndef CONFIG_RISCV pte = __pte(pte_val(pte) | RANDOM_ORVALUE); #endif - set_pte_at(mm, vaddr, ptep, pte); + set_pte_at(debug->mm, debug->vaddr, debug->ptep, pte); barrier(); - pte_clear(mm, vaddr, ptep); - pte = ptep_get(ptep); + pte_clear(debug->mm, debug->vaddr, debug->ptep); + pte = ptep_get(debug->ptep); WARN_ON(!pte_none(pte)); } @@ -1163,7 +1169,6 @@ static int __init debug_vm_pgtable(void) p4d_t *p4dp, *saved_p4dp; pud_t *pudp, *saved_pudp; pmd_t *pmdp, *saved_pmdp, pmd; - pte_t *ptep; pgtable_t saved_ptep; pgprot_t prot, protnone; phys_addr_t paddr; @@ -1293,11 +1298,11 @@ static int __init debug_vm_pgtable(void) * Page table modifying tests. They need to hold * proper page table lock. */ - - ptep = pte_offset_map_lock(mm, pmdp, vaddr, &ptl); - pte_clear_tests(mm, ptep, pte_aligned, vaddr, prot); - pte_advanced_tests(mm, vma, ptep, pte_aligned, vaddr, prot); - pte_unmap_unlock(ptep, ptl); + ptl = pte_lockptr(debug.mm, debug.pmdp); + spin_lock(ptl); + pte_clear_tests(&debug); + pte_advanced_tests(&debug); + spin_unlock(ptl); ptl = pmd_lock(mm, pmdp); pmd_clear_tests(mm, pmdp); From patchwork Tue Jul 6 06:17:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 12359829 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73288C07E9C for ; Tue, 6 Jul 2021 06:18:35 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 24C1A6198D for ; Tue, 6 Jul 2021 06:18:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 24C1A6198D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E79826B007B; Tue, 6 Jul 2021 02:18:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E2A2C6B007D; Tue, 6 Jul 2021 02:18:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CF1496B0080; Tue, 6 Jul 2021 02:18:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0157.hostedemail.com [216.40.44.157]) by kanga.kvack.org (Postfix) with ESMTP id A4B856B007B for ; Tue, 6 Jul 2021 02:18:34 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 1B6C71E4DA for ; Tue, 6 Jul 2021 06:18:34 +0000 (UTC) X-FDA: 78331158948.09.A8D9998 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf05.hostedemail.com (Postfix) with ESMTP id BC061500377D for ; Tue, 6 Jul 2021 06:18:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625552313; h=from:from:reply-to:subject:subject: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=gdLRMVXjWmvY7VZHVXP3ortBI+YRImx3WOefvtaILtw=; b=eqXxpbg6Z7hqn4/N7dAOrJ2v6DXbKESn8/5rSF4tmk1II+o15Sgwh9p3XQlbwFQDZ/WayX 40vVhRyeoe0VxCDI6XtHe2ykwVzig9yNGqkRQfRjLBx/A44M30AK2VMwF8uoAIirskz2UV q0IFDPDktpNq2JRZrS1odPqSACveGlg= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-530-p5FZRNcqOOKPRu8GmlZnAQ-1; Tue, 06 Jul 2021 02:18:32 -0400 X-MC-Unique: p5FZRNcqOOKPRu8GmlZnAQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EA563100CCC2; Tue, 6 Jul 2021 06:18:30 +0000 (UTC) Received: from gshan.redhat.com (vpn2-54-119.bne.redhat.com [10.64.54.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8DD7260583; Tue, 6 Jul 2021 06:18:28 +0000 (UTC) From: Gavin Shan To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, anshuman.khandual@arm.com, catalin.marinas@arm.com, will@kernel.org, akpm@linux-foundation.org, shan.gavin@gmail.com, chuhu@redhat.com Subject: [PATCH 08/12] mm/debug_vm_pgtable: Use struct vm_pgtable_debug in PMD modifying tests Date: Tue, 6 Jul 2021 14:17:44 +0800 Message-Id: <20210706061748.161258-9-gshan@redhat.com> In-Reply-To: <20210706061748.161258-1-gshan@redhat.com> References: <20210706061748.161258-1-gshan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: BC061500377D X-Stat-Signature: ewgt4zjroqhfqhd7a8so7b6q1jwjxkrb Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=eqXxpbg6; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf05.hostedemail.com: domain of gshan@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=gshan@redhat.com X-HE-Tag: 1625552313-984272 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: This uses struct vm_pgtable_debug in PMD modifying tests. The allocated huge page is used when set_pmd_at() is used. The corresponding tests are skipped if the huge page doesn't exist. Signed-off-by: Gavin Shan --- mm/debug_vm_pgtable.c | 99 ++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 52 deletions(-) diff --git a/mm/debug_vm_pgtable.c b/mm/debug_vm_pgtable.c index 2b4f0738f266..c554b6c42281 100644 --- a/mm/debug_vm_pgtable.c +++ b/mm/debug_vm_pgtable.c @@ -213,54 +213,54 @@ static void __init pmd_basic_tests(struct vm_pgtable_debug *debug, int idx) WARN_ON(!pmd_bad(pmd_mkhuge(pmd))); } -static void __init pmd_advanced_tests(struct mm_struct *mm, - struct vm_area_struct *vma, pmd_t *pmdp, - unsigned long pfn, unsigned long vaddr, - pgprot_t prot, pgtable_t pgtable) +static void __init pmd_advanced_tests(struct vm_pgtable_debug *debug) { pmd_t pmd; + unsigned long vaddr = (debug->vaddr & HPAGE_PMD_MASK); if (!has_transparent_hugepage()) return; pr_debug("Validating PMD advanced\n"); - /* Align the address wrt HPAGE_PMD_SIZE */ - vaddr &= HPAGE_PMD_MASK; + if (debug->pmd_pfn == ULONG_MAX) { + pr_debug("%s: Skipped\n", __func__); + return; + } - pgtable_trans_huge_deposit(mm, pmdp, pgtable); + pgtable_trans_huge_deposit(debug->mm, debug->pmdp, debug->start_ptep); - pmd = pfn_pmd(pfn, prot); - set_pmd_at(mm, vaddr, pmdp, pmd); - pmdp_set_wrprotect(mm, vaddr, pmdp); - pmd = READ_ONCE(*pmdp); + pmd = pfn_pmd(debug->pmd_pfn, debug->page_prot); + set_pmd_at(debug->mm, vaddr, debug->pmdp, pmd); + pmdp_set_wrprotect(debug->mm, vaddr, debug->pmdp); + pmd = READ_ONCE(*(debug->pmdp)); WARN_ON(pmd_write(pmd)); - pmdp_huge_get_and_clear(mm, vaddr, pmdp); - pmd = READ_ONCE(*pmdp); + pmdp_huge_get_and_clear(debug->mm, vaddr, debug->pmdp); + pmd = READ_ONCE(*(debug->pmdp)); WARN_ON(!pmd_none(pmd)); - pmd = pfn_pmd(pfn, prot); + pmd = pfn_pmd(debug->pmd_pfn, debug->page_prot); pmd = pmd_wrprotect(pmd); pmd = pmd_mkclean(pmd); - set_pmd_at(mm, vaddr, pmdp, pmd); + set_pmd_at(debug->mm, vaddr, debug->pmdp, pmd); pmd = pmd_mkwrite(pmd); pmd = pmd_mkdirty(pmd); - pmdp_set_access_flags(vma, vaddr, pmdp, pmd, 1); - pmd = READ_ONCE(*pmdp); + pmdp_set_access_flags(debug->vma, vaddr, debug->pmdp, pmd, 1); + pmd = READ_ONCE(*(debug->pmdp)); WARN_ON(!(pmd_write(pmd) && pmd_dirty(pmd))); - pmdp_huge_get_and_clear_full(vma, vaddr, pmdp, 1); - pmd = READ_ONCE(*pmdp); + pmdp_huge_get_and_clear_full(debug->vma, vaddr, debug->pmdp, 1); + pmd = READ_ONCE(*(debug->pmdp)); WARN_ON(!pmd_none(pmd)); - pmd = pmd_mkhuge(pfn_pmd(pfn, prot)); + pmd = pmd_mkhuge(pfn_pmd(debug->pmd_pfn, debug->page_prot)); pmd = pmd_mkyoung(pmd); - set_pmd_at(mm, vaddr, pmdp, pmd); - pmdp_test_and_clear_young(vma, vaddr, pmdp); - pmd = READ_ONCE(*pmdp); + set_pmd_at(debug->mm, vaddr, debug->pmdp, pmd); + pmdp_test_and_clear_young(debug->vma, vaddr, debug->pmdp); + pmd = READ_ONCE(*(debug->pmdp)); WARN_ON(pmd_young(pmd)); /* Clear the pte entries */ - pmdp_huge_get_and_clear(mm, vaddr, pmdp); - pgtable = pgtable_trans_huge_withdraw(mm, pmdp); + pmdp_huge_get_and_clear(debug->mm, vaddr, debug->pmdp); + pgtable_trans_huge_withdraw(debug->mm, debug->pmdp); } static void __init pmd_leaf_tests(struct vm_pgtable_debug *debug) @@ -417,12 +417,7 @@ static void __init pud_leaf_tests(struct vm_pgtable_debug *debug) { } #else /* !CONFIG_TRANSPARENT_HUGEPAGE */ static void __init pmd_basic_tests(struct vm_pgtable_debug *debug, int idx) { } static void __init pud_basic_tests(struct vm_pgtable_debug *debug, int idx) { } -static void __init pmd_advanced_tests(struct mm_struct *mm, - struct vm_area_struct *vma, pmd_t *pmdp, - unsigned long pfn, unsigned long vaddr, - pgprot_t prot, pgtable_t pgtable) -{ -} +static void __init pmd_advanced_tests(struct vm_pgtable_debug *debug) { } static void __init pud_advanced_tests(struct mm_struct *mm, struct vm_area_struct *vma, pud_t *pudp, unsigned long pfn, unsigned long vaddr, @@ -435,11 +430,11 @@ static void __init pmd_savedwrite_tests(struct vm_pgtable_debug *debug) { } #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ #ifdef CONFIG_HAVE_ARCH_HUGE_VMAP -static void __init pmd_huge_tests(pmd_t *pmdp, unsigned long pfn, pgprot_t prot) +static void __init pmd_huge_tests(struct vm_pgtable_debug *debug) { pmd_t pmd; - if (!arch_vmap_pmd_supported(prot)) + if (!arch_vmap_pmd_supported(debug->page_prot)) return; pr_debug("Validating PMD huge\n"); @@ -447,10 +442,11 @@ static void __init pmd_huge_tests(pmd_t *pmdp, unsigned long pfn, pgprot_t prot) * X86 defined pmd_set_huge() verifies that the given * PMD is not a populated non-leaf entry. */ - WRITE_ONCE(*pmdp, __pmd(0)); - WARN_ON(!pmd_set_huge(pmdp, __pfn_to_phys(pfn), prot)); - WARN_ON(!pmd_clear_huge(pmdp)); - pmd = READ_ONCE(*pmdp); + WRITE_ONCE(*(debug->pmdp), __pmd(0)); + WARN_ON(!pmd_set_huge(debug->pmdp, __pfn_to_phys(debug->fixed_pmd_pfn), + debug->page_prot)); + WARN_ON(!pmd_clear_huge(debug->pmdp)); + pmd = READ_ONCE(*(debug->pmdp)); WARN_ON(!pmd_none(pmd)); } @@ -473,7 +469,7 @@ static void __init pud_huge_tests(pud_t *pudp, unsigned long pfn, pgprot_t prot) WARN_ON(!pud_none(pud)); } #else /* !CONFIG_HAVE_ARCH_HUGE_VMAP */ -static void __init pmd_huge_tests(pmd_t *pmdp, unsigned long pfn, pgprot_t prot) { } +static void __init pmd_huge_tests(struct vm_pgtable_debug *debug) { } static void __init pud_huge_tests(pud_t *pudp, unsigned long pfn, pgprot_t prot) { } #endif /* CONFIG_HAVE_ARCH_HUGE_VMAP */ @@ -640,20 +636,19 @@ static void __init pte_clear_tests(struct vm_pgtable_debug *debug) WARN_ON(!pte_none(pte)); } -static void __init pmd_clear_tests(struct mm_struct *mm, pmd_t *pmdp) +static void __init pmd_clear_tests(struct vm_pgtable_debug *debug) { - pmd_t pmd = READ_ONCE(*pmdp); + pmd_t pmd = READ_ONCE(*(debug->pmdp)); pr_debug("Validating PMD clear\n"); pmd = __pmd(pmd_val(pmd) | RANDOM_ORVALUE); - WRITE_ONCE(*pmdp, pmd); - pmd_clear(pmdp); - pmd = READ_ONCE(*pmdp); + WRITE_ONCE(*(debug->pmdp), pmd); + pmd_clear(debug->pmdp); + pmd = READ_ONCE(*(debug->pmdp)); WARN_ON(!pmd_none(pmd)); } -static void __init pmd_populate_tests(struct mm_struct *mm, pmd_t *pmdp, - pgtable_t pgtable) +static void __init pmd_populate_tests(struct vm_pgtable_debug *debug) { pmd_t pmd; @@ -662,8 +657,8 @@ static void __init pmd_populate_tests(struct mm_struct *mm, pmd_t *pmdp, * This entry points to next level page table page. * Hence this must not qualify as pmd_bad(). */ - pmd_populate(mm, pmdp, pgtable); - pmd = READ_ONCE(*pmdp); + pmd_populate(debug->mm, debug->pmdp, debug->start_ptep); + pmd = READ_ONCE(*(debug->pmdp)); WARN_ON(pmd_bad(pmd)); } @@ -1304,11 +1299,11 @@ static int __init debug_vm_pgtable(void) pte_advanced_tests(&debug); spin_unlock(ptl); - ptl = pmd_lock(mm, pmdp); - pmd_clear_tests(mm, pmdp); - pmd_advanced_tests(mm, vma, pmdp, pmd_aligned, vaddr, prot, saved_ptep); - pmd_huge_tests(pmdp, pmd_aligned, prot); - pmd_populate_tests(mm, pmdp, saved_ptep); + ptl = pmd_lock(debug.mm, debug.pmdp); + pmd_clear_tests(&debug); + pmd_advanced_tests(&debug); + pmd_huge_tests(&debug); + pmd_populate_tests(&debug); spin_unlock(ptl); ptl = pud_lock(mm, pudp); From patchwork Tue Jul 6 06:17:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 12359831 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ECA44C07E9C for ; Tue, 6 Jul 2021 06:18:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9B5566128E for ; Tue, 6 Jul 2021 06:18:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9B5566128E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 6D88F6B007D; Tue, 6 Jul 2021 02:18:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6B0026B0080; Tue, 6 Jul 2021 02:18:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 550456B0081; Tue, 6 Jul 2021 02:18:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0250.hostedemail.com [216.40.44.250]) by kanga.kvack.org (Postfix) with ESMTP id 346526B007D for ; Tue, 6 Jul 2021 02:18:39 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 07222824999B for ; Tue, 6 Jul 2021 06:18:38 +0000 (UTC) X-FDA: 78331159116.17.5EF408F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf11.hostedemail.com (Postfix) with ESMTP id A057EF0000B6 for ; Tue, 6 Jul 2021 06:18:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625552316; h=from:from:reply-to:subject:subject: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=JBk1oz7ojY+fvkBs8xNxVAkbEhj914dQYyR+sCAdK5U=; b=SoVWYlzCWBu0QID9Z609B55uEM/Bsln7yPFA5gRsMsnM8viy63cvJet800WfQ7g5CGoQbS 2Um7QH1/ZJ5EGDs8rjxeUClvgGq5TI8JHztOyeXaLN0ibIUtUO+2UwZOwaa6z5PZ01ms/x B5nzcGsrS3nOUYzRYdYSe1rDv7+FvYI= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-257-D1d1i8S3OT2xryhkLkOxWA-1; Tue, 06 Jul 2021 02:18:35 -0400 X-MC-Unique: D1d1i8S3OT2xryhkLkOxWA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 47E47800D62; Tue, 6 Jul 2021 06:18:34 +0000 (UTC) Received: from gshan.redhat.com (vpn2-54-119.bne.redhat.com [10.64.54.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6CB6769CB4; Tue, 6 Jul 2021 06:18:31 +0000 (UTC) From: Gavin Shan To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, anshuman.khandual@arm.com, catalin.marinas@arm.com, will@kernel.org, akpm@linux-foundation.org, shan.gavin@gmail.com, chuhu@redhat.com Subject: [PATCH 09/12] mm/vm_debug_pgtable: Use struct vm_pgtable_debug in PUD modifying tests Date: Tue, 6 Jul 2021 14:17:45 +0800 Message-Id: <20210706061748.161258-10-gshan@redhat.com> In-Reply-To: <20210706061748.161258-1-gshan@redhat.com> References: <20210706061748.161258-1-gshan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=SoVWYlzC; spf=none (imf11.hostedemail.com: domain of gshan@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=gshan@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Stat-Signature: 5ojg6d9ojg6erf8higkqq6xna5muwgcd X-Rspamd-Queue-Id: A057EF0000B6 X-Rspamd-Server: rspam06 X-HE-Tag: 1625552317-705121 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: This uses struct vm_pgtable_debug in PUD modifying tests. The allocated huge page is used when set_pud_at() is used. The corresponding tests are skipped if the huge page doesn't exist. Signed-off-by: Gavin Shan --- mm/debug_vm_pgtable.c | 113 +++++++++++++++++++----------------------- 1 file changed, 50 insertions(+), 63 deletions(-) diff --git a/mm/debug_vm_pgtable.c b/mm/debug_vm_pgtable.c index c554b6c42281..59fd9440ab12 100644 --- a/mm/debug_vm_pgtable.c +++ b/mm/debug_vm_pgtable.c @@ -338,55 +338,55 @@ static void __init pud_basic_tests(struct vm_pgtable_debug *debug, int idx) WARN_ON(!pud_bad(pud_mkhuge(pud))); } -static void __init pud_advanced_tests(struct mm_struct *mm, - struct vm_area_struct *vma, pud_t *pudp, - unsigned long pfn, unsigned long vaddr, - pgprot_t prot) +static void __init pud_advanced_tests(struct vm_pgtable_debug *debug) { + unsigned long vaddr = (debug->vaddr & HPAGE_PUD_MASK); pud_t pud; if (!has_transparent_hugepage()) return; pr_debug("Validating PUD advanced\n"); - /* Align the address wrt HPAGE_PUD_SIZE */ - vaddr &= HPAGE_PUD_MASK; + if (debug->pud_pfn == ULONG_MAX) { + pr_debug("%s: Skipped\n", __func__); + return; + } - pud = pfn_pud(pfn, prot); - set_pud_at(mm, vaddr, pudp, pud); - pudp_set_wrprotect(mm, vaddr, pudp); - pud = READ_ONCE(*pudp); + pud = pfn_pud(debug->pud_pfn, debug->page_prot); + set_pud_at(debug->mm, vaddr, debug->pudp, pud); + pudp_set_wrprotect(debug->mm, vaddr, debug->pudp); + pud = READ_ONCE(*(debug->pudp)); WARN_ON(pud_write(pud)); #ifndef __PAGETABLE_PMD_FOLDED - pudp_huge_get_and_clear(mm, vaddr, pudp); - pud = READ_ONCE(*pudp); + pudp_huge_get_and_clear(debug->mm, vaddr, debug->pudp); + pud = READ_ONCE(*(debug->pudp)); WARN_ON(!pud_none(pud)); #endif /* __PAGETABLE_PMD_FOLDED */ - pud = pfn_pud(pfn, prot); + pud = pfn_pud(debug->pud_pfn, debug->page_prot); pud = pud_wrprotect(pud); pud = pud_mkclean(pud); - set_pud_at(mm, vaddr, pudp, pud); + set_pud_at(debug->mm, vaddr, debug->pudp, pud); pud = pud_mkwrite(pud); pud = pud_mkdirty(pud); - pudp_set_access_flags(vma, vaddr, pudp, pud, 1); - pud = READ_ONCE(*pudp); + pudp_set_access_flags(debug->vma, vaddr, debug->pudp, pud, 1); + pud = READ_ONCE(*(debug->pudp)); WARN_ON(!(pud_write(pud) && pud_dirty(pud))); #ifndef __PAGETABLE_PMD_FOLDED - pudp_huge_get_and_clear_full(mm, vaddr, pudp, 1); - pud = READ_ONCE(*pudp); + pudp_huge_get_and_clear_full(debug->mm, vaddr, debug->pudp, 1); + pud = READ_ONCE(*(debug->pudp)); WARN_ON(!pud_none(pud)); #endif /* __PAGETABLE_PMD_FOLDED */ - pud = pfn_pud(pfn, prot); + pud = pfn_pud(debug->pud_pfn, debug->page_prot); pud = pud_mkyoung(pud); - set_pud_at(mm, vaddr, pudp, pud); - pudp_test_and_clear_young(vma, vaddr, pudp); - pud = READ_ONCE(*pudp); + set_pud_at(debug->mm, vaddr, debug->pudp, pud); + pudp_test_and_clear_young(debug->vma, vaddr, debug->pudp); + pud = READ_ONCE(*(debug->pudp)); WARN_ON(pud_young(pud)); - pudp_huge_get_and_clear(mm, vaddr, pudp); + pudp_huge_get_and_clear(debug->mm, vaddr, debug->pudp); } static void __init pud_leaf_tests(struct vm_pgtable_debug *debug) @@ -406,24 +406,14 @@ static void __init pud_leaf_tests(struct vm_pgtable_debug *debug) } #else /* !CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */ static void __init pud_basic_tests(struct vm_pgtable_debug *debug, int idx) { } -static void __init pud_advanced_tests(struct mm_struct *mm, - struct vm_area_struct *vma, pud_t *pudp, - unsigned long pfn, unsigned long vaddr, - pgprot_t prot) -{ -} +static void __init pud_advanced_tests(struct vm_pgtable_debug *debug) { } static void __init pud_leaf_tests(struct vm_pgtable_debug *debug) { } #endif /* CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */ #else /* !CONFIG_TRANSPARENT_HUGEPAGE */ static void __init pmd_basic_tests(struct vm_pgtable_debug *debug, int idx) { } static void __init pud_basic_tests(struct vm_pgtable_debug *debug, int idx) { } static void __init pmd_advanced_tests(struct vm_pgtable_debug *debug) { } -static void __init pud_advanced_tests(struct mm_struct *mm, - struct vm_area_struct *vma, pud_t *pudp, - unsigned long pfn, unsigned long vaddr, - pgprot_t prot) -{ -} +static void __init pud_advanced_tests(struct vm_pgtable_debug *debug) { } static void __init pmd_leaf_tests(struct vm_pgtable_debug *debug) { } static void __init pud_leaf_tests(struct vm_pgtable_debug *debug) { } static void __init pmd_savedwrite_tests(struct vm_pgtable_debug *debug) { } @@ -450,11 +440,11 @@ static void __init pmd_huge_tests(struct vm_pgtable_debug *debug) WARN_ON(!pmd_none(pmd)); } -static void __init pud_huge_tests(pud_t *pudp, unsigned long pfn, pgprot_t prot) +static void __init pud_huge_tests(struct vm_pgtable_debug *debug) { pud_t pud; - if (!arch_vmap_pud_supported(prot)) + if (!arch_vmap_pud_supported(debug->page_prot)) return; pr_debug("Validating PUD huge\n"); @@ -462,15 +452,16 @@ static void __init pud_huge_tests(pud_t *pudp, unsigned long pfn, pgprot_t prot) * X86 defined pud_set_huge() verifies that the given * PUD is not a populated non-leaf entry. */ - WRITE_ONCE(*pudp, __pud(0)); - WARN_ON(!pud_set_huge(pudp, __pfn_to_phys(pfn), prot)); - WARN_ON(!pud_clear_huge(pudp)); - pud = READ_ONCE(*pudp); + WRITE_ONCE(*(debug->pudp), __pud(0)); + WARN_ON(!pud_set_huge(debug->pudp, __pfn_to_phys(debug->fixed_pud_pfn), + debug->page_prot)); + WARN_ON(!pud_clear_huge(debug->pudp)); + pud = READ_ONCE(*(debug->pudp)); WARN_ON(!pud_none(pud)); } #else /* !CONFIG_HAVE_ARCH_HUGE_VMAP */ static void __init pmd_huge_tests(struct vm_pgtable_debug *debug) { } -static void __init pud_huge_tests(pud_t *pudp, unsigned long pfn, pgprot_t prot) { } +static void __init pud_huge_tests(struct vm_pgtable_debug *debug) { } #endif /* CONFIG_HAVE_ARCH_HUGE_VMAP */ static void __init p4d_basic_tests(void) @@ -492,27 +483,26 @@ static void __init pgd_basic_tests(void) } #ifndef __PAGETABLE_PUD_FOLDED -static void __init pud_clear_tests(struct mm_struct *mm, pud_t *pudp) +static void __init pud_clear_tests(struct vm_pgtable_debug *debug) { - pud_t pud = READ_ONCE(*pudp); + pud_t pud = READ_ONCE(*(debug->pudp)); - if (mm_pmd_folded(mm)) + if (mm_pmd_folded(debug->mm)) return; pr_debug("Validating PUD clear\n"); pud = __pud(pud_val(pud) | RANDOM_ORVALUE); - WRITE_ONCE(*pudp, pud); - pud_clear(pudp); - pud = READ_ONCE(*pudp); + WRITE_ONCE(*(debug->pudp), pud); + pud_clear(debug->pudp); + pud = READ_ONCE(*(debug->pudp)); WARN_ON(!pud_none(pud)); } -static void __init pud_populate_tests(struct mm_struct *mm, pud_t *pudp, - pmd_t *pmdp) +static void __init pud_populate_tests(struct vm_pgtable_debug *debug) { pud_t pud; - if (mm_pmd_folded(mm)) + if (mm_pmd_folded(debug->mm)) return; pr_debug("Validating PUD populate\n"); @@ -520,16 +510,13 @@ static void __init pud_populate_tests(struct mm_struct *mm, pud_t *pudp, * This entry points to next level page table page. * Hence this must not qualify as pud_bad(). */ - pud_populate(mm, pudp, pmdp); - pud = READ_ONCE(*pudp); + pud_populate(debug->mm, debug->pudp, debug->start_pmdp); + pud = READ_ONCE(*(debug->pudp)); WARN_ON(pud_bad(pud)); } #else /* !__PAGETABLE_PUD_FOLDED */ -static void __init pud_clear_tests(struct mm_struct *mm, pud_t *pudp) { } -static void __init pud_populate_tests(struct mm_struct *mm, pud_t *pudp, - pmd_t *pmdp) -{ -} +static void __init pud_clear_tests(struct vm_pgtable_debug *debug) { } +static void __init pud_populate_tests(struct vm_pgtable_debug *debug) { } #endif /* PAGETABLE_PUD_FOLDED */ #ifndef __PAGETABLE_P4D_FOLDED @@ -1306,11 +1293,11 @@ static int __init debug_vm_pgtable(void) pmd_populate_tests(&debug); spin_unlock(ptl); - ptl = pud_lock(mm, pudp); - pud_clear_tests(mm, pudp); - pud_advanced_tests(mm, vma, pudp, pud_aligned, vaddr, prot); - pud_huge_tests(pudp, pud_aligned, prot); - pud_populate_tests(mm, pudp, saved_pmdp); + ptl = pud_lock(debug.mm, debug.pudp); + pud_clear_tests(&debug); + pud_advanced_tests(&debug); + pud_huge_tests(&debug); + pud_populate_tests(&debug); spin_unlock(ptl); spin_lock(&mm->page_table_lock); From patchwork Tue Jul 6 06:17:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 12359833 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97289C07E9C for ; Tue, 6 Jul 2021 06:18:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4EDAC61992 for ; Tue, 6 Jul 2021 06:18:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4EDAC61992 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 1A87E6B0080; Tue, 6 Jul 2021 02:18:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 180B26B0081; Tue, 6 Jul 2021 02:18:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 01FC76B0082; Tue, 6 Jul 2021 02:18:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0137.hostedemail.com [216.40.44.137]) by kanga.kvack.org (Postfix) with ESMTP id D63166B0080 for ; Tue, 6 Jul 2021 02:18:43 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 50920202F1 for ; Tue, 6 Jul 2021 06:18:43 +0000 (UTC) X-FDA: 78331159326.24.D2DABEE Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf19.hostedemail.com (Postfix) with ESMTP id F0493B000189 for ; Tue, 6 Jul 2021 06:18:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625552322; h=from:from:reply-to:subject:subject: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=jiK7WbmZHUKFR/bsDbzja/cvbEFXN86BsWzUPyPwIkM=; b=cQXfxAm0tmgn0B9XVoDWFT2dxCb8w9d8zJGl95MOo2h9ecLN5IwS8d6/om9PsV1M7zb33h YlC5SoQMyMIOCWyIW5sA2XBeR3aC5PBg1+owrXjRfcbGE7P7eIArkTgphGOvdQL4wE3rF4 8CFa7xByhIwvY269MULoqF/Yaw5dy6k= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-484-w--MKDzAOdODqUO_ItzE6w-1; Tue, 06 Jul 2021 02:18:39 -0400 X-MC-Unique: w--MKDzAOdODqUO_ItzE6w-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 12C6E8015C6; Tue, 6 Jul 2021 06:18:38 +0000 (UTC) Received: from gshan.redhat.com (vpn2-54-119.bne.redhat.com [10.64.54.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id B07F360583; Tue, 6 Jul 2021 06:18:34 +0000 (UTC) From: Gavin Shan To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, anshuman.khandual@arm.com, catalin.marinas@arm.com, will@kernel.org, akpm@linux-foundation.org, shan.gavin@gmail.com, chuhu@redhat.com Subject: [PATCH 10/12] mm/debug_vm_pgtable: Use struct vm_pgtable_debug in PGD and P4D modifying tests Date: Tue, 6 Jul 2021 14:17:46 +0800 Message-Id: <20210706061748.161258-11-gshan@redhat.com> In-Reply-To: <20210706061748.161258-1-gshan@redhat.com> References: <20210706061748.161258-1-gshan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cQXfxAm0; spf=none (imf19.hostedemail.com: domain of gshan@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=gshan@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: F0493B000189 X-Stat-Signature: phdx9hhkyfwog8gyj5kjn794tpb74c4e X-HE-Tag: 1625552322-452780 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: This uses struct vm_pgtable_debug in PGD/P4D modifying tests. No allocated huge page is used in these tests. Signed-off-by: Gavin Shan --- mm/debug_vm_pgtable.c | 76 +++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 42 deletions(-) diff --git a/mm/debug_vm_pgtable.c b/mm/debug_vm_pgtable.c index 59fd9440ab12..7bc26808033c 100644 --- a/mm/debug_vm_pgtable.c +++ b/mm/debug_vm_pgtable.c @@ -520,27 +520,26 @@ static void __init pud_populate_tests(struct vm_pgtable_debug *debug) { } #endif /* PAGETABLE_PUD_FOLDED */ #ifndef __PAGETABLE_P4D_FOLDED -static void __init p4d_clear_tests(struct mm_struct *mm, p4d_t *p4dp) +static void __init p4d_clear_tests(struct vm_pgtable_debug *debug) { - p4d_t p4d = READ_ONCE(*p4dp); + p4d_t p4d = READ_ONCE(*(debug->p4dp)); - if (mm_pud_folded(mm)) + if (mm_pud_folded(debug->mm)) return; pr_debug("Validating P4D clear\n"); p4d = __p4d(p4d_val(p4d) | RANDOM_ORVALUE); - WRITE_ONCE(*p4dp, p4d); - p4d_clear(p4dp); - p4d = READ_ONCE(*p4dp); + WRITE_ONCE(*(debug->p4dp), p4d); + p4d_clear(debug->p4dp); + p4d = READ_ONCE(*(debug->p4dp)); WARN_ON(!p4d_none(p4d)); } -static void __init p4d_populate_tests(struct mm_struct *mm, p4d_t *p4dp, - pud_t *pudp) +static void __init p4d_populate_tests(struct vm_pgtable_debug *debug) { p4d_t p4d; - if (mm_pud_folded(mm)) + if (mm_pud_folded(debug->mm)) return; pr_debug("Validating P4D populate\n"); @@ -548,34 +547,33 @@ static void __init p4d_populate_tests(struct mm_struct *mm, p4d_t *p4dp, * This entry points to next level page table page. * Hence this must not qualify as p4d_bad(). */ - pud_clear(pudp); - p4d_clear(p4dp); - p4d_populate(mm, p4dp, pudp); - p4d = READ_ONCE(*p4dp); + pud_clear(debug->pudp); + p4d_clear(debug->p4dp); + p4d_populate(debug->mm, debug->p4dp, debug->start_pudp); + p4d = READ_ONCE(*(debug->p4dp)); WARN_ON(p4d_bad(p4d)); } -static void __init pgd_clear_tests(struct mm_struct *mm, pgd_t *pgdp) +static void __init pgd_clear_tests(struct vm_pgtable_debug *debug) { - pgd_t pgd = READ_ONCE(*pgdp); + pgd_t pgd = READ_ONCE(*(debug->pgdp)); - if (mm_p4d_folded(mm)) + if (mm_p4d_folded(debug->mm)) return; pr_debug("Validating PGD clear\n"); pgd = __pgd(pgd_val(pgd) | RANDOM_ORVALUE); - WRITE_ONCE(*pgdp, pgd); - pgd_clear(pgdp); - pgd = READ_ONCE(*pgdp); + WRITE_ONCE(*(debug->pgdp), pgd); + pgd_clear(debug->pgdp); + pgd = READ_ONCE(*(debug->pgdp)); WARN_ON(!pgd_none(pgd)); } -static void __init pgd_populate_tests(struct mm_struct *mm, pgd_t *pgdp, - p4d_t *p4dp) +static void __init pgd_populate_tests(struct vm_pgtable_debug *debug) { pgd_t pgd; - if (mm_p4d_folded(mm)) + if (mm_p4d_folded(debug->mm)) return; pr_debug("Validating PGD populate\n"); @@ -583,23 +581,17 @@ static void __init pgd_populate_tests(struct mm_struct *mm, pgd_t *pgdp, * This entry points to next level page table page. * Hence this must not qualify as pgd_bad(). */ - p4d_clear(p4dp); - pgd_clear(pgdp); - pgd_populate(mm, pgdp, p4dp); - pgd = READ_ONCE(*pgdp); + p4d_clear(debug->p4dp); + pgd_clear(debug->pgdp); + pgd_populate(debug->mm, debug->pgdp, debug->start_p4dp); + pgd = READ_ONCE(*(debug->pgdp)); WARN_ON(pgd_bad(pgd)); } #else /* !__PAGETABLE_P4D_FOLDED */ -static void __init p4d_clear_tests(struct mm_struct *mm, p4d_t *p4dp) { } -static void __init pgd_clear_tests(struct mm_struct *mm, pgd_t *pgdp) { } -static void __init p4d_populate_tests(struct mm_struct *mm, p4d_t *p4dp, - pud_t *pudp) -{ -} -static void __init pgd_populate_tests(struct mm_struct *mm, pgd_t *pgdp, - p4d_t *p4dp) -{ -} +static void __init p4d_clear_tests(struct vm_pgtable_debug *debug) { } +static void __init pgd_clear_tests(struct vm_pgtable_debug *debug) { } +static void __init p4d_populate_tests(struct vm_pgtable_debug *debug) { } +static void __init pgd_populate_tests(struct vm_pgtable_debug *debug) { } #endif /* PAGETABLE_P4D_FOLDED */ static void __init pte_clear_tests(struct vm_pgtable_debug *debug) @@ -1300,12 +1292,12 @@ static int __init debug_vm_pgtable(void) pud_populate_tests(&debug); spin_unlock(ptl); - spin_lock(&mm->page_table_lock); - p4d_clear_tests(mm, p4dp); - pgd_clear_tests(mm, pgdp); - p4d_populate_tests(mm, p4dp, saved_pudp); - pgd_populate_tests(mm, pgdp, saved_p4dp); - spin_unlock(&mm->page_table_lock); + spin_lock(&(debug.mm->page_table_lock)); + p4d_clear_tests(&debug); + pgd_clear_tests(&debug); + p4d_populate_tests(&debug); + pgd_populate_tests(&debug); + spin_unlock(&(debug.mm->page_table_lock)); p4d_free(mm, saved_p4dp); pud_free(mm, saved_pudp); From patchwork Tue Jul 6 06:17:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 12359835 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D2AEAC11F66 for ; Tue, 6 Jul 2021 06:18:45 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8343C61988 for ; Tue, 6 Jul 2021 06:18:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8343C61988 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 579246B0081; Tue, 6 Jul 2021 02:18:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 52AB46B0082; Tue, 6 Jul 2021 02:18:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 32E216B0083; Tue, 6 Jul 2021 02:18:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0059.hostedemail.com [216.40.44.59]) by kanga.kvack.org (Postfix) with ESMTP id 11F816B0081 for ; Tue, 6 Jul 2021 02:18:45 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 8505D202F1 for ; Tue, 6 Jul 2021 06:18:44 +0000 (UTC) X-FDA: 78331159368.24.DDF6B33 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf22.hostedemail.com (Postfix) with ESMTP id 40D0A1981 for ; Tue, 6 Jul 2021 06:18:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625552323; h=from:from:reply-to:subject:subject: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=mweAYxCEdF4Jkl2O4UzKsGw6+VTXjzI6QarLmf2D4cQ=; b=VgXneh8OJTy3+tCaO2fF4WEBK0CUdwuG4G04cdyRZYoUu3OLRHBJ+M9zYHcRnlMe+4nPAu 4lOEzd+qVISfJk4oWN7qU+dcB4l+56z0Q1ufSqCGgpWQpDd7+gjECc3SsBmWeqrN1W+Ld3 7VYjbvbyFnRBQOQMm7iRq0fFLorT0Sk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-541--V6AXFTSPsah_cUp3ox1cw-1; Tue, 06 Jul 2021 02:18:42 -0400 X-MC-Unique: -V6AXFTSPsah_cUp3ox1cw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F0713801B2E; Tue, 6 Jul 2021 06:18:40 +0000 (UTC) Received: from gshan.redhat.com (vpn2-54-119.bne.redhat.com [10.64.54.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7C79D60583; Tue, 6 Jul 2021 06:18:38 +0000 (UTC) From: Gavin Shan To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, anshuman.khandual@arm.com, catalin.marinas@arm.com, will@kernel.org, akpm@linux-foundation.org, shan.gavin@gmail.com, chuhu@redhat.com Subject: [PATCH 11/12] mm/debug_vm_pgtable: Remove unused code Date: Tue, 6 Jul 2021 14:17:47 +0800 Message-Id: <20210706061748.161258-12-gshan@redhat.com> In-Reply-To: <20210706061748.161258-1-gshan@redhat.com> References: <20210706061748.161258-1-gshan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=VgXneh8O; spf=none (imf22.hostedemail.com: domain of gshan@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=gshan@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Stat-Signature: p7u1q68e8aearka31saanbpqfhdncd6k X-Rspamd-Queue-Id: 40D0A1981 X-Rspamd-Server: rspam06 X-HE-Tag: 1625552324-672487 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: The variables used by old implementation isn't needed as we switched to "struct vm_pgtable_debug". Lets just remove them. Signed-off-by: Gavin Shan --- mm/debug_vm_pgtable.c | 99 +++---------------------------------------- 1 file changed, 6 insertions(+), 93 deletions(-) diff --git a/mm/debug_vm_pgtable.c b/mm/debug_vm_pgtable.c index 7bc26808033c..1fd6d73d2152 100644 --- a/mm/debug_vm_pgtable.c +++ b/mm/debug_vm_pgtable.c @@ -32,14 +32,6 @@ #include #include -/* - * Please refer Documentation/vm/arch_pgtable_helpers.rst for the semantics - * expectations that are being validated here. All future changes in here - * or the documentation need to be in sync. - */ - -#define VMFLAGS (VM_READ|VM_WRITE|VM_EXEC) - /* * On s390 platform, the lower 4 bits are used to identify given page table * entry type. But these bits might affect the ability to clear entries with @@ -1025,7 +1017,12 @@ static int __init alloc_mem(struct vm_pgtable_debug *debug) phys_addr_t phys; int ret = 0; - /* Initialize the debugging data */ + /* + * Initialize the debugging data. For @page_prot, please refer + * Documentation/vm/arch_pgtable_helpers.rst for the semantics + * expectations that are being validated here. All future changes + * in here or the documentation need to be in sync. + */ debug->mm = NULL; debug->vma = NULL; debug->pgdp = NULL; @@ -1137,17 +1134,6 @@ static int __init alloc_mem(struct vm_pgtable_debug *debug) static int __init debug_vm_pgtable(void) { struct vm_pgtable_debug debug; - struct vm_area_struct *vma; - struct mm_struct *mm; - pgd_t *pgdp; - p4d_t *p4dp, *saved_p4dp; - pud_t *pudp, *saved_pudp; - pmd_t *pmdp, *saved_pmdp, pmd; - pgtable_t saved_ptep; - pgprot_t prot, protnone; - phys_addr_t paddr; - unsigned long vaddr, pte_aligned, pmd_aligned; - unsigned long pud_aligned, p4d_aligned, pgd_aligned; spinlock_t *ptl = NULL; int idx, ret; @@ -1156,68 +1142,6 @@ static int __init debug_vm_pgtable(void) if (ret) return ret; - prot = vm_get_page_prot(VMFLAGS); - vaddr = get_random_vaddr(); - mm = mm_alloc(); - if (!mm) { - pr_err("mm_struct allocation failed\n"); - return 1; - } - - /* - * __P000 (or even __S000) will help create page table entries with - * PROT_NONE permission as required for pxx_protnone_tests(). - */ - protnone = __P000; - - vma = vm_area_alloc(mm); - if (!vma) { - pr_err("vma allocation failed\n"); - return 1; - } - - /* - * PFN for mapping at PTE level is determined from a standard kernel - * text symbol. But pfns for higher page table levels are derived by - * masking lower bits of this real pfn. These derived pfns might not - * exist on the platform but that does not really matter as pfn_pxx() - * helpers will still create appropriate entries for the test. This - * helps avoid large memory block allocations to be used for mapping - * at higher page table levels. - */ - paddr = __pa_symbol(&start_kernel); - - pte_aligned = (paddr & PAGE_MASK) >> PAGE_SHIFT; - pmd_aligned = (paddr & PMD_MASK) >> PAGE_SHIFT; - pud_aligned = (paddr & PUD_MASK) >> PAGE_SHIFT; - p4d_aligned = (paddr & P4D_MASK) >> PAGE_SHIFT; - pgd_aligned = (paddr & PGDIR_MASK) >> PAGE_SHIFT; - WARN_ON(!pfn_valid(pte_aligned)); - - pgdp = pgd_offset(mm, vaddr); - p4dp = p4d_alloc(mm, pgdp, vaddr); - pudp = pud_alloc(mm, p4dp, vaddr); - pmdp = pmd_alloc(mm, pudp, vaddr); - /* - * Allocate pgtable_t - */ - if (pte_alloc(mm, pmdp)) { - pr_err("pgtable allocation failed\n"); - return 1; - } - - /* - * Save all the page table page addresses as the page table - * entries will be used for testing with random or garbage - * values. These saved addresses will be used for freeing - * page table pages. - */ - pmd = READ_ONCE(*pmdp); - saved_p4dp = p4d_offset(pgdp, 0UL); - saved_pudp = pud_offset(p4dp, 0UL); - saved_pmdp = pmd_offset(pudp, 0UL); - saved_ptep = pmd_pgtable(pmd); - /* * Iterate over the protection_map[] to make sure that all * the basic page table transformation validations just hold @@ -1299,17 +1223,6 @@ static int __init debug_vm_pgtable(void) pgd_populate_tests(&debug); spin_unlock(&(debug.mm->page_table_lock)); - p4d_free(mm, saved_p4dp); - pud_free(mm, saved_pudp); - pmd_free(mm, saved_pmdp); - pte_free(mm, saved_ptep); - - vm_area_free(vma); - mm_dec_nr_puds(mm); - mm_dec_nr_pmds(mm); - mm_dec_nr_ptes(mm); - mmdrop(mm); - free_mem(&debug); return 0; } From patchwork Tue Jul 6 06:17:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 12359837 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC1FDC07E9B for ; Tue, 6 Jul 2021 06:18:50 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9216661988 for ; Tue, 6 Jul 2021 06:18:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9216661988 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 6B15C6B0083; Tue, 6 Jul 2021 02:18:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 687BB6B0087; Tue, 6 Jul 2021 02:18:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5293B6B0088; Tue, 6 Jul 2021 02:18:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0130.hostedemail.com [216.40.44.130]) by kanga.kvack.org (Postfix) with ESMTP id 2CB6C6B0083 for ; Tue, 6 Jul 2021 02:18:50 -0400 (EDT) Received: from smtpin38.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id AD5A71801BD8B for ; Tue, 6 Jul 2021 06:18:49 +0000 (UTC) X-FDA: 78331159578.38.E466DB2 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf30.hostedemail.com (Postfix) with ESMTP id 4E5D7E0016BB for ; Tue, 6 Jul 2021 06:18:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625552328; h=from:from:reply-to:subject:subject: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=qHjYf26nDQF8IxrBuohCHfhS/U3Bnml2w07ftwA7X+w=; b=PvHi2ocuGOGKd4ZSKiQKnxZGYs9W5Cx1C2ss0JFVxtgGr9D5PzJf0cExepl+36tUTAxf8n PfqGdHD6NCQ7FA9G4tmmAQOxWdYTib5NUDDbp66uoYStAZ4dKG+YFKDeWiYYz41ICApGQN YN3uu1kZsc6KOPxsGJhYNUwOwYy7yM8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-20-Eo_T1f37OX6II2fr5ElcwA-1; Tue, 06 Jul 2021 02:18:45 -0400 X-MC-Unique: Eo_T1f37OX6II2fr5ElcwA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 73ECD100CEC0; Tue, 6 Jul 2021 06:18:44 +0000 (UTC) Received: from gshan.redhat.com (vpn2-54-119.bne.redhat.com [10.64.54.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7399060583; Tue, 6 Jul 2021 06:18:41 +0000 (UTC) From: Gavin Shan To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, anshuman.khandual@arm.com, catalin.marinas@arm.com, will@kernel.org, akpm@linux-foundation.org, shan.gavin@gmail.com, chuhu@redhat.com Subject: [PATCH 12/12] mm/debug_vm_pgtable: Fix corrupted page flag Date: Tue, 6 Jul 2021 14:17:48 +0800 Message-Id: <20210706061748.161258-13-gshan@redhat.com> In-Reply-To: <20210706061748.161258-1-gshan@redhat.com> References: <20210706061748.161258-1-gshan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=PvHi2ocu; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf30.hostedemail.com: domain of gshan@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=gshan@redhat.com X-Stat-Signature: unnrz1qpm4nsus4z4wnuemmfmaj6ejij X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 4E5D7E0016BB X-HE-Tag: 1625552329-886183 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: In page table entry modifying tests, set_{pud, pmd, pte}_at() are used to populate the page table entries. On ARM64, PG_arch_1 is set to the target page flag if execution permission is given. The page flag is kept when the page is free'd to buddy's free area list. However, it will trigger page checking failure when it's pulled from the buddy's free area list, as the following warning messages indicate. BUG: Bad page state in process memhog pfn:08000 page:0000000015c0a628 refcount:0 mapcount:0 \ mapping:0000000000000000 index:0x1 pfn:0x8000 flags: 0x7ffff8000000800(arch_1|node=0|zone=0|lastcpupid=0xfffff) raw: 07ffff8000000800 dead000000000100 dead000000000122 0000000000000000 raw: 0000000000000001 0000000000000000 00000000ffffffff 0000000000000000 page dumped because: PAGE_FLAGS_CHECK_AT_PREP flag(s) set This fixes the issue by clearing PG_arch_1 through flush_dcache_page(), right after set_{pud, pmd, pte}_at() is called. Signed-off-by: Gavin Shan --- mm/debug_vm_pgtable.c | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/mm/debug_vm_pgtable.c b/mm/debug_vm_pgtable.c index 1fd6d73d2152..de6f99382b4b 100644 --- a/mm/debug_vm_pgtable.c +++ b/mm/debug_vm_pgtable.c @@ -29,6 +29,8 @@ #include #include #include + +#include #include #include @@ -110,6 +112,7 @@ static void __init pte_basic_tests(struct vm_pgtable_debug *debug, int idx) static void __init pte_advanced_tests(struct vm_pgtable_debug *debug) { + struct page *page; pte_t pte; /* @@ -119,13 +122,17 @@ static void __init pte_advanced_tests(struct vm_pgtable_debug *debug) */ pr_debug("Validating PTE advanced\n"); - if (debug->pte_pfn == ULONG_MAX) { + + page = (debug->pte_pfn != ULONG_MAX) ? + pfn_to_page(debug->pte_pfn) : NULL; + if (!page) { pr_debug("%s: Skipped\n", __func__); return; } pte = pfn_pte(debug->pte_pfn, debug->page_prot); set_pte_at(debug->mm, debug->vaddr, debug->ptep, pte); + flush_dcache_page(page); ptep_set_wrprotect(debug->mm, debug->vaddr, debug->ptep); pte = ptep_get(debug->ptep); WARN_ON(pte_write(pte)); @@ -137,6 +144,7 @@ static void __init pte_advanced_tests(struct vm_pgtable_debug *debug) pte = pte_wrprotect(pte); pte = pte_mkclean(pte); set_pte_at(debug->mm, debug->vaddr, debug->ptep, pte); + flush_dcache_page(page); pte = pte_mkwrite(pte); pte = pte_mkdirty(pte); ptep_set_access_flags(debug->vma, debug->vaddr, debug->ptep, pte, 1); @@ -149,6 +157,7 @@ static void __init pte_advanced_tests(struct vm_pgtable_debug *debug) pte = pfn_pte(debug->pte_pfn, debug->page_prot); pte = pte_mkyoung(pte); set_pte_at(debug->mm, debug->vaddr, debug->ptep, pte); + flush_dcache_page(page); ptep_test_and_clear_young(debug->vma, debug->vaddr, debug->ptep); pte = ptep_get(debug->ptep); WARN_ON(pte_young(pte)); @@ -207,6 +216,7 @@ static void __init pmd_basic_tests(struct vm_pgtable_debug *debug, int idx) static void __init pmd_advanced_tests(struct vm_pgtable_debug *debug) { + struct page *page; pmd_t pmd; unsigned long vaddr = (debug->vaddr & HPAGE_PMD_MASK); @@ -214,7 +224,10 @@ static void __init pmd_advanced_tests(struct vm_pgtable_debug *debug) return; pr_debug("Validating PMD advanced\n"); - if (debug->pmd_pfn == ULONG_MAX) { + + page = (debug->pmd_pfn != ULONG_MAX) ? + pfn_to_page(debug->pmd_pfn) : NULL; + if (!page) { pr_debug("%s: Skipped\n", __func__); return; } @@ -223,6 +236,7 @@ static void __init pmd_advanced_tests(struct vm_pgtable_debug *debug) pmd = pfn_pmd(debug->pmd_pfn, debug->page_prot); set_pmd_at(debug->mm, vaddr, debug->pmdp, pmd); + flush_dcache_page(page); pmdp_set_wrprotect(debug->mm, vaddr, debug->pmdp); pmd = READ_ONCE(*(debug->pmdp)); WARN_ON(pmd_write(pmd)); @@ -234,6 +248,7 @@ static void __init pmd_advanced_tests(struct vm_pgtable_debug *debug) pmd = pmd_wrprotect(pmd); pmd = pmd_mkclean(pmd); set_pmd_at(debug->mm, vaddr, debug->pmdp, pmd); + flush_dcache_page(page); pmd = pmd_mkwrite(pmd); pmd = pmd_mkdirty(pmd); pmdp_set_access_flags(debug->vma, vaddr, debug->pmdp, pmd, 1); @@ -246,6 +261,7 @@ static void __init pmd_advanced_tests(struct vm_pgtable_debug *debug) pmd = pmd_mkhuge(pfn_pmd(debug->pmd_pfn, debug->page_prot)); pmd = pmd_mkyoung(pmd); set_pmd_at(debug->mm, vaddr, debug->pmdp, pmd); + flush_dcache_page(page); pmdp_test_and_clear_young(debug->vma, vaddr, debug->pmdp); pmd = READ_ONCE(*(debug->pmdp)); WARN_ON(pmd_young(pmd)); @@ -332,6 +348,7 @@ static void __init pud_basic_tests(struct vm_pgtable_debug *debug, int idx) static void __init pud_advanced_tests(struct vm_pgtable_debug *debug) { + struct page *page; unsigned long vaddr = (debug->vaddr & HPAGE_PUD_MASK); pud_t pud; @@ -339,13 +356,17 @@ static void __init pud_advanced_tests(struct vm_pgtable_debug *debug) return; pr_debug("Validating PUD advanced\n"); - if (debug->pud_pfn == ULONG_MAX) { + + page = (debug->pud_pfn != ULONG_MAX) ? + pfn_to_page(debug->pud_pfn) : NULL; + if (!page) { pr_debug("%s: Skipped\n", __func__); return; } pud = pfn_pud(debug->pud_pfn, debug->page_prot); set_pud_at(debug->mm, vaddr, debug->pudp, pud); + flush_dcache_page(page); pudp_set_wrprotect(debug->mm, vaddr, debug->pudp); pud = READ_ONCE(*(debug->pudp)); WARN_ON(pud_write(pud)); @@ -359,6 +380,7 @@ static void __init pud_advanced_tests(struct vm_pgtable_debug *debug) pud = pud_wrprotect(pud); pud = pud_mkclean(pud); set_pud_at(debug->mm, vaddr, debug->pudp, pud); + flush_dcache_page(page); pud = pud_mkwrite(pud); pud = pud_mkdirty(pud); pudp_set_access_flags(debug->vma, vaddr, debug->pudp, pud, 1); @@ -374,6 +396,7 @@ static void __init pud_advanced_tests(struct vm_pgtable_debug *debug) pud = pfn_pud(debug->pud_pfn, debug->page_prot); pud = pud_mkyoung(pud); set_pud_at(debug->mm, vaddr, debug->pudp, pud); + flush_dcache_page(page); pudp_test_and_clear_young(debug->vma, vaddr, debug->pudp); pud = READ_ONCE(*(debug->pudp)); WARN_ON(pud_young(pud)); @@ -588,10 +611,14 @@ static void __init pgd_populate_tests(struct vm_pgtable_debug *debug) { } static void __init pte_clear_tests(struct vm_pgtable_debug *debug) { + struct page *page; pte_t pte; pr_debug("Validating PTE clear\n"); - if (debug->pte_pfn == ULONG_MAX) { + + page = (debug->pte_pfn != ULONG_MAX) ? + pfn_to_page(debug->pte_pfn) : NULL; + if (!page) { pr_debug("%s: Skipped\n", __func__); return; } @@ -601,6 +628,7 @@ static void __init pte_clear_tests(struct vm_pgtable_debug *debug) pte = __pte(pte_val(pte) | RANDOM_ORVALUE); #endif set_pte_at(debug->mm, debug->vaddr, debug->ptep, pte); + flush_dcache_page(page); barrier(); pte_clear(debug->mm, debug->vaddr, debug->ptep); pte = ptep_get(debug->ptep);