Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp4088702pxp; Wed, 23 Mar 2022 11:02:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxhcGuPAasYc5c5wuciC35saXGcIIC4dZdqOkixSkLLwj+ujfJnqM4v0CmOnl28ZSyyd8h5 X-Received: by 2002:a05:6830:13cc:b0:5cb:56ff:811 with SMTP id e12-20020a05683013cc00b005cb56ff0811mr519780otq.280.1648058571015; Wed, 23 Mar 2022 11:02:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648058571; cv=none; d=google.com; s=arc-20160816; b=R1vkCTd+ZD1PMxHUikJqz0hNu5aRdCdFJ+13tkYJgCNJ16X9yBcsLxu9h/bCi6Ws9Z fFq4PzM59pNLl09+5mzySF3utbpwHG1vq2IzLohQsATDde3JzGJau6a0LADqIijKYNQa 7WfzjEZiPOQNzkeim+sCLfpJL/VzT7Tq5vzw1k7TWS9j9xfrRIFVnH+4zqTLkKDZ/T4D yEC8DcohdIXH9JSapq8Q93Al6/swBryL6jxb+0NM+M/x8A/wZMNrEJdlZwIbxYCr1+5f TboIvTrnQlx/2NLtqloFa7Sz1EFAahrCKa5kynEPeoFYEkaDwip2ixUGF7rTR7+gykuv lBIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=fy3DR+ZsMm4wO8pVkKQraIXakurLYWYeuyvi7wXT+0I=; b=1K2I6LlXtpnU8NfqKvEjUenuymWH2WmLsOZ17OufK/sJ12hHPQSs6q2AW64QQtxqSH WrGKKQWrD893RW8R+cbTg+lFrwKt7xp5nQXx0kCxkphuZ4O255WLBY9A1ghvC0NZVHuq 7VcyRtB38aK2m/q7zpcQLc6CFVdvh1cJ1KfxvHz+u+UXIYeIliC6hH2gibgaUO2kvSKI FzAjKgB7xIa7hQaRbsE9iUjjHxSOLtaUcb/2+Nbaksc2DU53exZ6syE2rMPKo/NNhwxV HouhxCGlA757HMLpjtt1EU3ChKEwdEhNSvQ94XFJTYXKopvefminDZ7c9D01h+o9xTHu 5Syw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h17-20020a9d7991000000b005cb55733f33si8644538otm.56.2022.03.23.11.02.37; Wed, 23 Mar 2022 11:02:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232775AbiCVO1m (ORCPT + 99 others); Tue, 22 Mar 2022 10:27:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233991AbiCVO1c (ORCPT ); Tue, 22 Mar 2022 10:27:32 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF26531342 for ; Tue, 22 Mar 2022 07:25:56 -0700 (PDT) Received: from kwepemi100013.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4KNDL26RV2z1GClx; Tue, 22 Mar 2022 22:25:46 +0800 (CST) Received: from kwepemm600017.china.huawei.com (7.193.23.234) by kwepemi100013.china.huawei.com (7.221.188.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Tue, 22 Mar 2022 22:25:54 +0800 Received: from localhost.localdomain (10.175.112.125) by kwepemm600017.china.huawei.com (7.193.23.234) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Tue, 22 Mar 2022 22:25:52 +0800 From: Tong Tiangen To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , , "H. Peter Anvin" , Pasha Tatashin , Andrew Morton , Catalin Marinas , Will Deacon , Paul Walmsley , Palmer Dabbelt , Albert Ou CC: , , , , Tong Tiangen Subject: [PATCH -next v2 2/4] mm: page_table_check: add hooks to public helpers Date: Tue, 22 Mar 2022 14:44:45 +0000 Message-ID: <20220322144447.3563146-3-tongtiangen@huawei.com> X-Mailer: git-send-email 2.18.0.huawei.25 In-Reply-To: <20220322144447.3563146-1-tongtiangen@huawei.com> References: <20220322144447.3563146-1-tongtiangen@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemm600017.china.huawei.com (7.193.23.234) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham 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 Move ptep_clear() to the include/linux/pgtable.h and add page table check relate hooks to some helpers, it's prepare for support page table check feature on new architecture. Signed-off-by: Tong Tiangen --- arch/x86/include/asm/pgtable.h | 10 ---------- include/linux/pgtable.h | 27 +++++++++++++++++++-------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index 8cd6514e3052..8c85f2eabbaa 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -1077,16 +1077,6 @@ static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm, return pte; } -#define __HAVE_ARCH_PTEP_CLEAR -static inline void ptep_clear(struct mm_struct *mm, unsigned long addr, - pte_t *ptep) -{ - if (IS_ENABLED(CONFIG_PAGE_TABLE_CHECK)) - ptep_get_and_clear(mm, addr, ptep); - else - pte_clear(mm, addr, ptep); -} - #define __HAVE_ARCH_PTEP_SET_WRPROTECT static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr, pte_t *ptep) diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index f4f4077b97aa..d27fd0ed84a9 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -12,6 +12,7 @@ #include #include #include +#include #if 5 - defined(__PAGETABLE_P4D_FOLDED) - defined(__PAGETABLE_PUD_FOLDED) - \ defined(__PAGETABLE_PMD_FOLDED) != CONFIG_PGTABLE_LEVELS @@ -259,14 +260,6 @@ static inline int pmdp_clear_flush_young(struct vm_area_struct *vma, #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ #endif -#ifndef __HAVE_ARCH_PTEP_CLEAR -static inline void ptep_clear(struct mm_struct *mm, unsigned long addr, - pte_t *ptep) -{ - pte_clear(mm, addr, ptep); -} -#endif - #ifndef __HAVE_ARCH_PTEP_GET_AND_CLEAR static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long address, @@ -274,10 +267,23 @@ static inline pte_t ptep_get_and_clear(struct mm_struct *mm, { pte_t pte = *ptep; pte_clear(mm, address, ptep); + page_table_check_pte_clear(mm, address, pte); return pte; } #endif +#ifndef __HAVE_ARCH_PTEP_CLEAR +static inline void ptep_clear(struct mm_struct *mm, unsigned long addr, + pte_t *ptep) +{ +#ifdef CONFIG_PAGE_TABLE_CHECK + ptep_get_and_clear(mm, addr, ptep); +#else + pte_clear(mm, addr, ptep); +#endif +} +#endif + #ifndef __HAVE_ARCH_PTEP_GET static inline pte_t ptep_get(pte_t *ptep) { @@ -347,7 +353,10 @@ static inline pmd_t pmdp_huge_get_and_clear(struct mm_struct *mm, pmd_t *pmdp) { pmd_t pmd = *pmdp; + pmd_clear(pmdp); + page_table_check_pmd_clear(mm, address, pmd); + return pmd; } #endif /* __HAVE_ARCH_PMDP_HUGE_GET_AND_CLEAR */ @@ -359,6 +368,8 @@ static inline pud_t pudp_huge_get_and_clear(struct mm_struct *mm, pud_t pud = *pudp; pud_clear(pudp); + page_table_check_pud_clear(mm, address, pud); + return pud; } #endif /* __HAVE_ARCH_PUDP_HUGE_GET_AND_CLEAR */ -- 2.18.0.huawei.25