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);