Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5016330pxv; Wed, 28 Jul 2021 00:39:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzoEUtpoFLcTA7KDPyi6EEspokDVB8pF6jVXHDu6gZSOyDk+6nqRMT+o2hT9QG2MltcMP77 X-Received: by 2002:a17:906:55cd:: with SMTP id z13mr24271410ejp.99.1627457982235; Wed, 28 Jul 2021 00:39:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627457982; cv=none; d=google.com; s=arc-20160816; b=lmd4vD+qirKLKJmrdOUmWsDvKmA3dX0iHShTAiQEjrITLlpBY1N5rVePleQzPc0DLE rgC293iuNmL+7ZmMud2rCjK+uEHNzQF8SbTJcl3ITch3DnCDqAPXN+NfODY2wJpk9alt WKYzvC1S9SjN5OQ89Ro1Is052h70JCycoAuy80Jc9lY3JkmsFB2SBKwZqMHex+4sU/vR AFU6HMXgU8ivXbG7z0+OKdTQgQ/IVnHDi6p+jEUMZa4SU7AMkRDkbTeRn9egzOCeTt1w asxakya2OIc1PIdKGAyTB+18wSjI6+IESB2Ieso9pc0XqbHm29dhZk0OUjiM47dv3mF5 slag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:reply-to:dkim-signature; bh=65Z8ZWIRBkX0VRMC+qLtByPlgxjiVH76+vN5XvSW6MQ=; b=ZXx8DOwQGY4aysx7PwDuQB0441cOsR9/1jsEEZFdZHjooRpiZeOG0p7edZlx33S1az Z2r/ni8EvWIGvIntzxh6gHm18KhtJNnznAkxZm+DZ7Hss5J9d0YnKw3vaIUG+RLHrY4a mIMIWsJ7BDOzHcbCvWB6ioRMLtQ/+AC5xdRnQUJUIv6jPnCTyRECBeR4d9EpUfQRSTgy lMO5MOW8Xofdn214fiQY/LZNkzSB9fMTBrslQ/eV4ruj2849Lz4wm4OiW4c6GInyHPWn q7DoBKTbq8EiPAWFd5Z3Isg+UvmNf2qbYJdjRm1HsfCk50CfIlNCA5OhlS4wSRW+4TVe YVng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=NHZ1DnHe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dd21si5477738edb.514.2021.07.28.00.39.19; Wed, 28 Jul 2021 00:39:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=NHZ1DnHe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233937AbhG1HiA (ORCPT + 99 others); Wed, 28 Jul 2021 03:38:00 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:30407 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232691AbhG1HiA (ORCPT ); Wed, 28 Jul 2021 03:38:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1627457878; h=from:from:reply-to: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=65Z8ZWIRBkX0VRMC+qLtByPlgxjiVH76+vN5XvSW6MQ=; b=NHZ1DnHeLX24npvJUJlLKOWBtaE4+M2gJAuFtuANaUOESDu0CPkkg5qZlzCvRsNmCFq6hj vuOYSHxciVHGHUqa78TYdOWon8qj7cphzO2UzJpVX7SHdVkGKS/vmg9+Q3U3d8IBjXeteF kgK0eq4AM19KjMMh/JSALJmxi1eOI9k= 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-37-2UQmif5RMlKfIAAn1RswgA-1; Wed, 28 Jul 2021 03:37:55 -0400 X-MC-Unique: 2UQmif5RMlKfIAAn1RswgA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 26C9C107ACF5; Wed, 28 Jul 2021 07:37:53 +0000 (UTC) Received: from [10.64.54.184] (vpn2-54-184.bne.redhat.com [10.64.54.184]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B34EB60862; Wed, 28 Jul 2021 07:37:48 +0000 (UTC) Reply-To: Gavin Shan Subject: Re: [PATCH v4 01/12] mm/debug_vm_pgtable: Introduce struct pgtable_debug_args To: Anshuman Khandual , linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, gerald.schaefer@linux.ibm.com, aneesh.kumar@linux.ibm.com, christophe.leroy@csgroup.eu, cai@lca.pw, catalin.marinas@arm.com, will@kernel.org, akpm@linux-foundation.org, chuhu@redhat.com, shan.gavin@gmail.com References: <20210727061401.592616-1-gshan@redhat.com> <20210727061401.592616-2-gshan@redhat.com> <9977fea4-ff36-390a-3a5a-58f088dab111@arm.com> From: Gavin Shan Message-ID: Date: Wed, 28 Jul 2021 17:38:01 +1000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.0 MIME-Version: 1.0 In-Reply-To: <9977fea4-ff36-390a-3a5a-58f088dab111@arm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Anshuman, On 7/28/21 5:32 PM, Anshuman Khandual wrote: > On 7/27/21 11:43 AM, Gavin Shan wrote: >> In debug_vm_pgtable(), there are many local variables introduced to >> track the needed information and they are passed to the functions for >> various test cases. It'd better to introduce a struct as place holder >> for these information. With it, what the tests functions need is the >> struct. In this way, the code is simplified and easier to be maintained. >> >> Besides, set_xxx_at() could access the data on the corresponding pages >> in the page table modifying tests. So the accessed pages in the tests >> should have been allocated from buddy. Otherwise, we're accessing pages >> that aren't owned by us. This causes issues like page flag corruption >> or kernel crash on accessing unmapped page when CONFIG_DEBUG_PAGEALLOC >> is enabled. >> >> This introduces "struct pgtable_debug_args". The struct is initialized >> and destroyed, but the information in the struct isn't used yet. It will >> be used in subsequent patches. >> >> Signed-off-by: Gavin Shan >> --- >> mm/debug_vm_pgtable.c | 280 +++++++++++++++++++++++++++++++++++++++++- >> 1 file changed, 279 insertions(+), 1 deletion(-) >> >> diff --git a/mm/debug_vm_pgtable.c b/mm/debug_vm_pgtable.c >> index 1c922691aa61..8c7361643166 100644 >> --- a/mm/debug_vm_pgtable.c >> +++ b/mm/debug_vm_pgtable.c >> @@ -58,6 +58,37 @@ >> #define RANDOM_ORVALUE (GENMASK(BITS_PER_LONG - 1, 0) & ~ARCH_SKIP_MASK) >> #define RANDOM_NZVALUE GENMASK(7, 0) >> >> +struct pgtable_debug_args { >> + struct mm_struct *mm; >> + struct vm_area_struct *vma; >> + >> + pgd_t *pgdp; >> + p4d_t *p4dp; >> + pud_t *pudp; >> + pmd_t *pmdp; >> + pte_t *ptep; >> + >> + p4d_t *start_p4dp; >> + pud_t *start_pudp; >> + pmd_t *start_pmdp; >> + pgtable_t start_ptep; >> + >> + unsigned long vaddr; >> + pgprot_t page_prot; >> + pgprot_t page_prot_none; >> + >> + bool is_contiguous_page; >> + unsigned long pud_pfn; >> + unsigned long pmd_pfn; >> + unsigned long pte_pfn; >> + >> + unsigned long fixed_pgd_pfn; >> + unsigned long fixed_p4d_pfn; >> + unsigned long fixed_pud_pfn; >> + unsigned long fixed_pmd_pfn; >> + unsigned long fixed_pte_pfn; >> +}; >> + >> static void __init pte_basic_tests(unsigned long pfn, int idx) >> { >> pgprot_t prot = protection_map[idx]; >> @@ -955,8 +986,249 @@ static unsigned long __init get_random_vaddr(void) >> return random_vaddr; >> } >> >> +static void __init destroy_args(struct pgtable_debug_args *args) >> +{ >> + struct page *page = NULL; >> + >> + /* Free (huge) page */ >> + if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && >> + IS_ENABLED(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD) && >> + has_transparent_hugepage() && >> + args->pud_pfn != ULONG_MAX) { >> + if (args->is_contiguous_page) { >> + free_contig_range(args->pud_pfn, >> + (1 << (HPAGE_PUD_SHIFT - PAGE_SHIFT))); >> + } else { >> + page = pfn_to_page(args->pud_pfn); >> + __free_pages(page, HPAGE_PUD_SHIFT - PAGE_SHIFT); >> + } >> + >> + args->pud_pfn = ULONG_MAX; >> + args->pmd_pfn = ULONG_MAX; >> + args->pte_pfn = ULONG_MAX; >> + } >> + >> + if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && >> + has_transparent_hugepage() && >> + args->pmd_pfn != ULONG_MAX) { >> + if (args->is_contiguous_page) { >> + free_contig_range(args->pmd_pfn, (1 << HPAGE_PMD_ORDER)); >> + } else { >> + page = pfn_to_page(args->pmd_pfn); >> + __free_pages(page, HPAGE_PMD_ORDER); >> + } >> + >> + args->pmd_pfn = ULONG_MAX; >> + args->pte_pfn = ULONG_MAX; >> + } >> + >> + if (args->pte_pfn != ULONG_MAX) { >> + page = pfn_to_page(args->pte_pfn); >> + __free_pages(page, 0); >> + } >> + >> + /* Free page table entries */ >> + if (args->start_ptep) { >> + pte_free(args->mm, args->start_ptep); >> + mm_dec_nr_ptes(args->mm); >> + } >> + >> + if (args->start_pmdp) { >> + pmd_free(args->mm, args->start_pmdp); >> + mm_dec_nr_pmds(args->mm); >> + } >> + >> + if (args->start_pudp) { >> + pud_free(args->mm, args->start_pudp); >> + mm_dec_nr_puds(args->mm); >> + } >> + >> + if (args->start_p4dp) >> + p4d_free(args->mm, args->p4dp); > > ^^^^ s/args->p4dp/args->start_p4dp ? > Yes, It should be "args->start_p4dp" here. I will correct it in v5 after you finish review on v4. Thanks, Gavin