Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp2543312pxb; Mon, 18 Apr 2022 02:59:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwa2HGNr3gDM/Jh2eAieDSr5ENzlZzm8bl1YuJnU1o42n0Hw98yLMzGkEO78gk4UIA+EMse X-Received: by 2002:a17:90a:9416:b0:1ca:9cff:7877 with SMTP id r22-20020a17090a941600b001ca9cff7877mr17435285pjo.141.1650275955099; Mon, 18 Apr 2022 02:59:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650275955; cv=none; d=google.com; s=arc-20160816; b=sAgnyhFkKOce4Ld6PHNn33VoDypwPR1VBtbrw8YtaeugVgIxCySElRceNLxUNZpZXo 4oaxJeAjFOYZrQS0S2coPHaj1Jzu2KzZI2T7o91NdB+oaWRY3D1Z05WwkM0GguKz9QUu ruiUY0z2++iWbQBWN56P/T0aBgPBmmgJI6smUV55liZngQUpDHy93Z0vcg9+MUrX9RGS q5GjUx7WjA7JefuXbzpMK39vFLo5R7hvxuXpkJjo7Jb7nt9/xBiAq7FypCKaxISiEc27 XWFWEtTDdpRerHG6JNsdyrThUu0gXykMrrn7yuyIV/7UXAtfzHYHrjMp1iilWPQjoS1S J9Og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=olrT0E6oDemAzI8ARY8JXETqJmSFCMkOE0SfsxemN7M=; b=dvYKQqAr48O2cUgdhws8tRlBN/bT0JwgvFxSk+MPTJtmHrbVFhdmSxZ0T5bCb5g7Bq ydUFFilCTQAZ694z07lqlMlrumdOcHAaZwZA7sSSSRyy53DG1wOqEcPB2WBb173wyeKZ YrS1G/dwxcEEHJbMrGSqoRuxGte+9UehcF+fjfljRrmaevuXomno1t017oE/bLyyNtN6 g5jg3UAPTZZ2LNJO3CAbCUQibN94C50tiUAIxUF4BeaCj7V+4E/ksN8ut0m8HPagrs0Y ggfR5I2wo7kC9pgGKCT0t2OVJmRAeqt2ddfvOwezfvX693AZhqMSrVeB4xG4iaGDEMbl PGRQ== 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 w70-20020a638249000000b003a158337b8fsi8433222pgd.3.2022.04.18.02.58.59; Mon, 18 Apr 2022 02:59:15 -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 S236038AbiDRD25 (ORCPT + 99 others); Sun, 17 Apr 2022 23:28:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236033AbiDRD2s (ORCPT ); Sun, 17 Apr 2022 23:28:48 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CFA917E12 for ; Sun, 17 Apr 2022 20:26:11 -0700 (PDT) Received: from kwepemi100002.china.huawei.com (unknown [172.30.72.54]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4KhXKP69wVzCr70; Mon, 18 Apr 2022 11:21:45 +0800 (CST) Received: from kwepemm600017.china.huawei.com (7.193.23.234) by kwepemi100002.china.huawei.com (7.221.188.188) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 18 Apr 2022 11:26:08 +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.2375.24; Mon, 18 Apr 2022 11:26:06 +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 , Kefeng Wang , Guohanjun Subject: [PATCH -next v4 2/4] mm: page_table_check: add hooks to public helpers Date: Mon, 18 Apr 2022 03:44:42 +0000 Message-ID: <20220418034444.520928-3-tongtiangen@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220418034444.520928-1-tongtiangen@huawei.com> References: <20220418034444.520928-1-tongtiangen@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemm600017.china.huawei.com (7.193.23.234) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-5.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 Acked-by: Pasha Tatashin --- arch/x86/include/asm/pgtable.h | 10 ---------- include/linux/pgtable.h | 26 ++++++++++++++++++-------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index 564abe42b0f7..51cd39858f81 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -1073,16 +1073,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 49ab8ee2d6d7..10d2d91edf20 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 @@ -272,14 +273,6 @@ static inline bool arch_has_hw_pte_young(void) } #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, @@ -287,10 +280,22 @@ 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) +{ + if (IS_ENABLED(CONFIG_PAGE_TABLE_CHECK)) + ptep_get_and_clear(mm, addr, ptep); + else + pte_clear(mm, addr, ptep); +} +#endif + #ifndef __HAVE_ARCH_PTEP_GET static inline pte_t ptep_get(pte_t *ptep) { @@ -360,7 +365,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 */ @@ -372,6 +380,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.25.1