Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1546145pxp; Thu, 17 Mar 2022 11:13:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzwztL7aJ6RD+TjulPhpT8aNyBOEMKVNfwxEK7BRAhxWaRRD8fLLhetGlC9g4zkomrYuHot X-Received: by 2002:a05:6a00:1254:b0:4fa:3aec:7ec4 with SMTP id u20-20020a056a00125400b004fa3aec7ec4mr4770703pfi.83.1647540825906; Thu, 17 Mar 2022 11:13:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647540825; cv=none; d=google.com; s=arc-20160816; b=AHzMMFTLuT0lVdgejF6Lu4TSiSetNQhgP2Zvg+NZv+DAJQiISS/mC90MrIVQ23I1nN HcHoPdO+RPc5THdwi1qXIeTQP6qA0xJA3CSK8mZX5NmCNq8vVauadv1DW65arOC+4A9p DFskFfRtD8rTcuYMKek5/djvCLeh47othQoja8TJXiJJsDSyiKShUaxOZOnQWRQLw813 HHiUCUtd2QAx7QJMSShe3pFfjP0p58aJtoWviiLkhXKOttfOdHKU8qzFtSnI4m5b0QUw sCPqzW2vhtNYFbuwBaLOU4F6IZbfHqDyV/6ev7svrHjaM0Y0St20XQ0+wSagjh/HdyIy TXpQ== 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=sHKOHmId80GqxaEw8yxvydxi7Y2k/ZTvjRgA+VBotTcP4pB9rlGUabFTvbsZ0JRcvX +tii5Cp+OyBk0/P/Pm0TFY42RkMmfhuOdb/nX8FaRl5JwNc4yJeM5JXxx0adV7Oc5th5 bMrP0y/aF+3bnsSbB3jzxZv/sKsmW67ZJef6/8PiObD22mNW6p06IVU+vz9TCZ4dWjjD 4kaDk3qz0lPijJDE262Ii/ZjI5k9vc389ORroqa7hEXAYW0sYkcORfvUPRhZ2dIL5ucV qZqhYn2FgOiOivcSYxUMaaTe/FX8Oro1iMJLgdyRFHYp/WgRZbXaNrkFB4TTgpY0WuIX Of0w== 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 p3-20020a63e643000000b003816043eee1si2783421pgj.214.2022.03.17.11.13.29; Thu, 17 Mar 2022 11:13:45 -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 S234731AbiCQNyz (ORCPT + 99 others); Thu, 17 Mar 2022 09:54:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234710AbiCQNys (ORCPT ); Thu, 17 Mar 2022 09:54:48 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EEF97ECD99 for ; Thu, 17 Mar 2022 06:53:30 -0700 (PDT) Received: from kwepemi100013.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4KK7mf63gZz9sYl; Thu, 17 Mar 2022 21:49:38 +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; Thu, 17 Mar 2022 21:53:28 +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; Thu, 17 Mar 2022 21:53:27 +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 , Palmer Dabbelt , Albert Ou CC: , , , , Tong Tiangen Subject: [PATCH -next 2/4] mm: page_table_check: add hooks to public helpers Date: Thu, 17 Mar 2022 14:12:01 +0000 Message-ID: <20220317141203.3646253-3-tongtiangen@huawei.com> X-Mailer: git-send-email 2.18.0.huawei.25 In-Reply-To: <20220317141203.3646253-1-tongtiangen@huawei.com> References: <20220317141203.3646253-1-tongtiangen@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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