Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp119561iob; Tue, 17 May 2022 20:52:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxVbYnseXmHG4qbGxbLhnFNRB6ZThY0dGBRJQF4tEhV0NK4FwyMmv7egbNMcVSry6ipCzl+ X-Received: by 2002:a63:c4e:0:b0:3db:6074:117a with SMTP id 14-20020a630c4e000000b003db6074117amr22547669pgm.87.1652845941813; Tue, 17 May 2022 20:52:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652845941; cv=none; d=google.com; s=arc-20160816; b=aEAQnr+DlTlrQg08D+fqWYX0iJ44XpOAVHrWRRg0g3PR4Epks0btvLq0Wi7BkNgC2b MjezO5G14xIFDtB94no0H1w+lsNAqDyAJQoxj4yGqmuLytl9HQ2TJeCPRULQdF68ApnB Wl1HhP27h25flAlk/HmInTO3SLRLeW3e26FtOcNoycT8K5PsatH5a4dndT/MBR0j6h0u IP/F/Ei2kwoVii82aHMEPkrt23OXElNQEtxZdW4da1ivi7QLy3Tg78rlIDLaOl9K2F3B /eUE4NYcgTm75zCANNT4Qbgxr//lt6vANLBwrVJAWYWu9BlmRk/F+ArnjNBiaB280Ya2 LFOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=avGBDf+YcfUQWpS9rfKzkw3jWC131FHQWzTg8qKPFqw=; b=r2jouh/4xZJF8Dvr3sqQt/9pK0gKLxvSU/ZkyAsE++tLgHQzU3hjEql/i2wW5h896J ByAzGHYnVFV+hnKGzkauYsixTzBAOmFjPwUYQPOvc6Ce8SoYAey0/TGMfvQgvMprN5YZ iF/3i/UL7H3xJOp+3q8UwjwNfrwPJuyiib29C/TFIVCjbAiMUY5zckGCV5yy9O3OMjVt rk4KM0y6v+lHynKDdrktDJ0WUIJJk6PoQoTSlr0u6LVSWZDNH537z4TvPzv48q3N1jYz cM3Wx+Lpc//qaoAEIWlt2eIKk+ndXpaT0aYrAXUeBz8rKIjwiOQ94JF717HrbUwzRZQ/ xv1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jRb7dfs8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id x10-20020a170902ec8a00b0015cdfb5dc6asi1543324plg.84.2022.05.17.20.52.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 20:52:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jRb7dfs8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2651791579; Tue, 17 May 2022 20:34:09 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347890AbiEQNyt (ORCPT + 99 others); Tue, 17 May 2022 09:54:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348077AbiEQNyp (ORCPT ); Tue, 17 May 2022 09:54:45 -0400 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A63C54BB99 for ; Tue, 17 May 2022 06:54:40 -0700 (PDT) Received: by mail-lf1-x131.google.com with SMTP id u23so31485272lfc.1 for ; Tue, 17 May 2022 06:54:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=avGBDf+YcfUQWpS9rfKzkw3jWC131FHQWzTg8qKPFqw=; b=jRb7dfs8lGxQ3YOhE9jtyLR9OjOQn6Ob3LXeKcIGOjMV5oj1YP+SHcx/bDYZxbJAkm T84cjlHn7tqU2KIRDGjIGqypUYocG/p7wA9Fy6aua7syaeSSMV1ZXpdiq9NLm0GAcX6p grmMFZfqklB2XqQxUrnIZimU//BqI/XLTXCRDkMLELC3O4cGKx9cGY7WMwVXHOmdYiPx xgeqSBFAJfeZbsGo5EjSxJ3v2cKHOGRS7kE0mO7+k5GpSxPDb0SpYxyXO4F4kEVhQVZV BXMNG/BjO36xrWM/u3hPEFXOtZ4vi9poI13rZD3yIKD1bNZKts48/KucltHBNaxDoDEi nDhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=avGBDf+YcfUQWpS9rfKzkw3jWC131FHQWzTg8qKPFqw=; b=2pm5aEhIHhXJSu8zeSidO2G35vsF5hKoC+/46dsdCFV2xGGBrov8rZQZ9hhHthFSV2 3hqRe0+XKXKGGs0uSAHZN+WR1awq3GkE5lHl03zXqwTKQnv8tOkPXZKbKpyLN+XbRR4b YMRA0jkIY5bDQ4fbv1A/63NkKXXhaBcmH1dCDav8LNFJIebJ//0SAY0mB5NcO9OxLAmn Sf9qtl1jSLwUXzLMn8wv2j+D4P+cPXx64nPm5ch55RSh30KEYyC2sQCkJTuxSfpVGAOK IsHwJLDEHG6S+as8koscwaQYazDLzkZ02GnLKABBIsF8rYbfXLQQzyuHWKY4wzWY+SZd Vm/Q== X-Gm-Message-State: AOAM533mh5HQ9EzaUML65IA2NiyKnzaGdXVzMKoglmsJte3tEll3qulS X0UjYzmsE7BLOSM+wXqHvr/ITA== X-Received: by 2002:a05:6512:3d89:b0:473:9e0e:8c4c with SMTP id k9-20020a0565123d8900b004739e0e8c4cmr17248132lfv.160.1652795678409; Tue, 17 May 2022 06:54:38 -0700 (PDT) Received: from mutt (c-7303e555.07-21-73746f28.bbcust.telenor.se. [85.229.3.115]) by smtp.gmail.com with ESMTPSA id a16-20020a19f810000000b0047255d21109sm1600301lff.56.2022.05.17.06.54.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 06:54:37 -0700 (PDT) Date: Tue, 17 May 2022 15:54:35 +0200 From: Anders Roxell To: Tong Tiangen Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Pasha Tatashin , Anshuman Khandual , Andrew Morton , Catalin Marinas , Will Deacon , Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-riscv@lists.infradead.org, Kefeng Wang , Guohanjun Subject: Re: [PATCH -next v7 5/6] arm64/mm: Enable ARCH_SUPPORTS_PAGE_TABLE_CHECK Message-ID: <20220517135435.GA553@mutt> References: <20220507110114.4128854-1-tongtiangen@huawei.com> <20220507110114.4128854-6-tongtiangen@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20220507110114.4128854-6-tongtiangen@huawei.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2022-05-07 11:01, Tong Tiangen wrote: > From: Kefeng Wang > > As commit d283d422c6c4 ("x86: mm: add x86_64 support for page table check") > , enable ARCH_SUPPORTS_PAGE_TABLE_CHECK on arm64. > > Add additional page table check stubs for page table helpers, these stubs > can be used to check the existing page table entries. > > Signed-off-by: Kefeng Wang > Signed-off-by: Tong Tiangen > Reviewed-by: Pasha Tatashin When building and booting an arm64 allmodconfig kernel on the next tree, branch next-20220516, see the following kernel oops when booting in QEMU [1]: T35] ------------[ cut here ]------------ [ 578.695796][ T35] kernel BUG at mm/page_table_check.c:82! [ 578.697292][ T35] Internal error: Oops - BUG: 0 [#1] PREEMPT SMP [ 578.704318][ T35] Modules linked in: [ 578.705907][ T35] CPU: 0 PID: 35 Comm: khugepaged Tainted: G T 5.18.0-rc6-next-20220513 #1 893498a5d8159d9fb26e12492a93c07e83dd4b7f [ 578.711170][ T35] Hardware name: linux,dummy-virt (DT) [ 578.713315][ T35] pstate: 60400005 (nZCv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--) [ 578.716398][ T35] pc : page_table_check_clear.constprop.0+0x1f4/0x280 [ 578.719107][ T35] lr : page_table_check_clear.constprop.0+0x1cc/0x280 [ 578.721781][ T35] sp : ffff80000f3778b0 [ 578.723446][ T35] x29: ffff80000f3778b0 x28: ffff80000b891218 x27: ffff000012dd55f0 [ 578.726667][ T35] x26: 0000000000000008 x25: ffff80000c38cd80 x24: 0000000000000000 [ 578.729870][ T35] x23: ffff80000c38c9c0 x22: 0000000000000000 x21: 0000000000000200 [ 578.733079][ T35] x20: ffff000007bae000 x19: ffff000007bae008 x18: 0000000000000000 [ 578.736299][ T35] x17: 0000000000000000 x16: 0000000000000000 x15: 0000000000000000 [ 578.739505][ T35] x14: 0000000000000000 x13: 0000000000000000 x12: 0000000000000000 [ 578.742735][ T35] x11: 0000000000000000 x10: 0000000000000000 x9 : 0000000000000000 [ 578.745925][ T35] x8 : 0000000000000000 x7 : 0000000000000000 x6 : 0000000000000000 [ 578.749145][ T35] x5 : 0000000000000000 x4 : 0000000000000000 x3 : ffff000007bae00c [ 578.752348][ T35] x2 : 0000000000000000 x1 : 0000000000000001 x0 : 00000000ffffffff [ 578.755556][ T35] Call trace: [ 578.756877][ T35] page_table_check_clear.constprop.0+0x1f4/0x280 [ 578.759446][ T35] __page_table_check_pmd_clear+0xc4/0x140 [ 578.761757][ T35] pmdp_collapse_flush+0xa4/0x1c0 [ 578.763771][ T35] collapse_huge_page+0x4e4/0xb00 [ 578.765778][ T35] khugepaged_scan_pmd+0xc18/0xd00 [ 578.767840][ T35] khugepaged_scan_mm_slot+0x580/0x780 [ 578.770018][ T35] khugepaged+0x2dc/0x400 [ 578.771786][ T35] kthread+0x164/0x180 [ 578.773430][ T35] ret_from_fork+0x10/0x20 [ 578.775253][ T35] Code: 52800021 91001263 14000388 36f80040 (d4210000) [ 578.777990][ T35] ---[ end trace 0000000000000000 ]--- [ 578.778021][ T35] Kernel panic - not syncing: Oops - BUG: Fatal exception [ 578.782934][ T35] Kernel Offset: disabled [ 578.784642][ T35] CPU features: 0x000,00100010,00001086 [ 578.786848][ T35] Memory Limit: none [ 578.788433][ T35] ---[ end Kernel panic - not syncing: Oops - BUG: Fatal exception ]--- Bisected down to this patch, see the bisect log [2]. When I revert this patch I don't see the issue anymore. Cheers, Anders [1] https://people.linaro.org/~anders.roxell/output-next-20220513.log [2] http://ix.io/3XZB > --- > arch/arm64/Kconfig | 1 + > arch/arm64/include/asm/pgtable.h | 61 ++++++++++++++++++++++++++++---- > 2 files changed, 56 insertions(+), 6 deletions(-) > > diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig > index 272c75af9302..3055fb5b3fb4 100644 > --- a/arch/arm64/Kconfig > +++ b/arch/arm64/Kconfig > @@ -92,6 +92,7 @@ config ARM64 > select ARCH_SUPPORTS_ATOMIC_RMW > select ARCH_SUPPORTS_INT128 if CC_HAS_INT128 > select ARCH_SUPPORTS_NUMA_BALANCING > + select ARCH_SUPPORTS_PAGE_TABLE_CHECK > select ARCH_WANT_COMPAT_IPC_PARSE_VERSION if COMPAT > select ARCH_WANT_DEFAULT_BPF_JIT > select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT > diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h > index 8ebf1cec5d90..4e61cde27f9f 100644 > --- a/arch/arm64/include/asm/pgtable.h > +++ b/arch/arm64/include/asm/pgtable.h > @@ -33,6 +33,7 @@ > #include > #include > #include > +#include > > #ifdef CONFIG_TRANSPARENT_HUGEPAGE > #define __HAVE_ARCH_FLUSH_PMD_TLB_RANGE > @@ -96,6 +97,7 @@ static inline pteval_t __phys_to_pte_val(phys_addr_t phys) > #define pte_young(pte) (!!(pte_val(pte) & PTE_AF)) > #define pte_special(pte) (!!(pte_val(pte) & PTE_SPECIAL)) > #define pte_write(pte) (!!(pte_val(pte) & PTE_WRITE)) > +#define pte_user(pte) (!!(pte_val(pte) & PTE_USER)) > #define pte_user_exec(pte) (!(pte_val(pte) & PTE_UXN)) > #define pte_cont(pte) (!!(pte_val(pte) & PTE_CONT)) > #define pte_devmap(pte) (!!(pte_val(pte) & PTE_DEVMAP)) > @@ -312,8 +314,8 @@ static inline void __check_racy_pte_update(struct mm_struct *mm, pte_t *ptep, > __func__, pte_val(old_pte), pte_val(pte)); > } > > -static inline void set_pte_at(struct mm_struct *mm, unsigned long addr, > - pte_t *ptep, pte_t pte) > +static inline void __set_pte_at(struct mm_struct *mm, unsigned long addr, > + pte_t *ptep, pte_t pte) > { > if (pte_present(pte) && pte_user_exec(pte) && !pte_special(pte)) > __sync_icache_dcache(pte); > @@ -343,6 +345,13 @@ static inline void set_pte_at(struct mm_struct *mm, unsigned long addr, > set_pte(ptep, pte); > } > > +static inline void set_pte_at(struct mm_struct *mm, unsigned long addr, > + pte_t *ptep, pte_t pte) > +{ > + page_table_check_pte_set(mm, addr, ptep, pte); > + return __set_pte_at(mm, addr, ptep, pte); > +} > + > /* > * Huge pte definitions. > */ > @@ -454,6 +463,8 @@ static inline int pmd_trans_huge(pmd_t pmd) > #define pmd_dirty(pmd) pte_dirty(pmd_pte(pmd)) > #define pmd_young(pmd) pte_young(pmd_pte(pmd)) > #define pmd_valid(pmd) pte_valid(pmd_pte(pmd)) > +#define pmd_user(pmd) pte_user(pmd_pte(pmd)) > +#define pmd_user_exec(pmd) pte_user_exec(pmd_pte(pmd)) > #define pmd_cont(pmd) pte_cont(pmd_pte(pmd)) > #define pmd_wrprotect(pmd) pte_pmd(pte_wrprotect(pmd_pte(pmd))) > #define pmd_mkold(pmd) pte_pmd(pte_mkold(pmd_pte(pmd))) > @@ -501,8 +512,19 @@ static inline pmd_t pmd_mkdevmap(pmd_t pmd) > #define pud_pfn(pud) ((__pud_to_phys(pud) & PUD_MASK) >> PAGE_SHIFT) > #define pfn_pud(pfn,prot) __pud(__phys_to_pud_val((phys_addr_t)(pfn) << PAGE_SHIFT) | pgprot_val(prot)) > > -#define set_pmd_at(mm, addr, pmdp, pmd) set_pte_at(mm, addr, (pte_t *)pmdp, pmd_pte(pmd)) > -#define set_pud_at(mm, addr, pudp, pud) set_pte_at(mm, addr, (pte_t *)pudp, pud_pte(pud)) > +static inline void set_pmd_at(struct mm_struct *mm, unsigned long addr, > + pmd_t *pmdp, pmd_t pmd) > +{ > + page_table_check_pmd_set(mm, addr, pmdp, pmd); > + return __set_pte_at(mm, addr, (pte_t *)pmdp, pmd_pte(pmd)); > +} > + > +static inline void set_pud_at(struct mm_struct *mm, unsigned long addr, > + pud_t *pudp, pud_t pud) > +{ > + page_table_check_pud_set(mm, addr, pudp, pud); > + return __set_pte_at(mm, addr, (pte_t *)pudp, pud_pte(pud)); > +} > > #define __p4d_to_phys(p4d) __pte_to_phys(p4d_pte(p4d)) > #define __phys_to_p4d_val(phys) __phys_to_pte_val(phys) > @@ -643,6 +665,24 @@ static inline unsigned long pmd_page_vaddr(pmd_t pmd) > #define pud_present(pud) pte_present(pud_pte(pud)) > #define pud_leaf(pud) (pud_present(pud) && !pud_table(pud)) > #define pud_valid(pud) pte_valid(pud_pte(pud)) > +#define pud_user(pud) pte_user(pud_pte(pud)) > + > +#ifdef CONFIG_PAGE_TABLE_CHECK > +static inline bool pte_user_accessible_page(pte_t pte) > +{ > + return pte_present(pte) && (pte_user(pte) || pte_user_exec(pte)); > +} > + > +static inline bool pmd_user_accessible_page(pmd_t pmd) > +{ > + return pmd_present(pmd) && (pmd_user(pmd) || pmd_user_exec(pmd)); > +} > + > +static inline bool pud_user_accessible_page(pud_t pud) > +{ > + return pud_present(pud) && pud_user(pud); > +} > +#endif > > static inline void set_pud(pud_t *pudp, pud_t pud) > { > @@ -876,7 +916,11 @@ static inline int pmdp_test_and_clear_young(struct vm_area_struct *vma, > static inline pte_t ptep_get_and_clear(struct mm_struct *mm, > unsigned long address, pte_t *ptep) > { > - return __pte(xchg_relaxed(&pte_val(*ptep), 0)); > + pte_t pte = __pte(xchg_relaxed(&pte_val(*ptep), 0)); > + > + page_table_check_pte_clear(mm, address, pte); > + > + return pte; > } > > #ifdef CONFIG_TRANSPARENT_HUGEPAGE > @@ -884,7 +928,11 @@ static inline pte_t ptep_get_and_clear(struct mm_struct *mm, > static inline pmd_t pmdp_huge_get_and_clear(struct mm_struct *mm, > unsigned long address, pmd_t *pmdp) > { > - return pte_pmd(ptep_get_and_clear(mm, address, (pte_t *)pmdp)); > + pmd_t pmd = __pmd(xchg_relaxed(&pmd_val(*pmdp), 0)); > + > + page_table_check_pmd_clear(mm, address, pmd); > + > + return pmd; > } > #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ > > @@ -918,6 +966,7 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm, > static inline pmd_t pmdp_establish(struct vm_area_struct *vma, > unsigned long address, pmd_t *pmdp, pmd_t pmd) > { > + page_table_check_pmd_set(vma->vm_mm, address, pmdp, pmd); > return __pmd(xchg_relaxed(&pmd_val(*pmdp), pmd_val(pmd))); > } > #endif > -- > 2.25.1 > -- Anders Roxell anders.roxell@linaro.org M: +46 708 22 71 05 | IRC: roxell