Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp4866735pxb; Mon, 28 Mar 2022 04:50:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyHmF+KZAQymj3e584cs3kiC2t3BYRooDyT/bAvLuUyADIMa03bMeCO6B/mKi+uZruXQAU0 X-Received: by 2002:a02:b783:0:b0:323:66ed:8266 with SMTP id f3-20020a02b783000000b0032366ed8266mr3121860jam.297.1648468222566; Mon, 28 Mar 2022 04:50:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648468222; cv=none; d=google.com; s=arc-20160816; b=fIhbLR678Zmd2V0x7lhsvAykayvgb0Ozm6YP66ApSZFSGl+KZXyb1o7t0ETghTdwCN XJCoHvvx1buw/Yw/Tz/4PBJjjQm4pjFkdWLtJEHdDM2d0ONZidgTQK4YRMQcYT6YAB6x UYgH1lShUz9/oiipDgdMtGLc7WMkfKwDjv4PFCm+V5Tj4Otz+Orq65XFqYv7zIc/VEW8 6F3epkgRJaIsgJcGObLxeQ8HML0KW9v1jo57q6fFedyS+sskN4AhahkXkAs3tDIsZ8BT fLzUBYmlYDl1Rd1S5xi7MPvQKZ/i516Bwq4oonfMHNxzLMT2JWyi+tlkXIU0/UaOqV2q xTxw== 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=/fGQKEerRxBP58WYGCaXg/v644rqdvym52uUVJyuKBw=; b=yo2rqWIWAMyASqOAhG2Ke8hGyGXn7rsDP7GEkmCZn29uPZVmvepO1RtTrLDEt624LZ N7hzQgG9rUGItnRF99RPUK7CQqQ0gpUbQT8/A0VHHda2k2dqmAY1kWwWgm26jc12Q1Px kPgJ9qoV5NyFr4ErvAYn4CgT4GEpv4jbR78i0iS7SMnvYShYL1PGDBG2+ePSVxucaqbd VuriKWKneXmR42tqHg+wunsvl5GwLUUnuUwMTSOuri7kwOndKID6FyD2O4HhFPWU+9dW zWgclVccf8j9didyLk1gRTLorzNth73uMV9s04PvoYgSgG3TK4GWTfTjTDRzsZLTEjWn oazg== 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 t16-20020a922c10000000b002c9ca96a0e9si308696ile.153.2022.03.28.04.50.10; Mon, 28 Mar 2022 04:50:22 -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 S236736AbiC1Bfp (ORCPT + 99 others); Sun, 27 Mar 2022 21:35:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229867AbiC1Bfm (ORCPT ); Sun, 27 Mar 2022 21:35:42 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4B8D220D8 for ; Sun, 27 Mar 2022 18:34:02 -0700 (PDT) Received: from kwepemi100013.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4KRZwT5XMcz1GCx0; Mon, 28 Mar 2022 09:33:45 +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; Mon, 28 Mar 2022 09:33:59 +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; Mon, 28 Mar 2022 09:33:58 +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 v3 1/4] mm: page_table_check: move pxx_user_accessible_page into x86 Date: Mon, 28 Mar 2022 01:52:39 +0000 Message-ID: <20220328015242.1136836-2-tongtiangen@huawei.com> X-Mailer: git-send-email 2.18.0.huawei.25 In-Reply-To: <20220328015242.1136836-1-tongtiangen@huawei.com> References: <20220328015242.1136836-1-tongtiangen@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) 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 From: Kefeng Wang The pxx_user_accessible_page() check the PTE bit, it's architecture-specific code, move them into x86's pgtable.h, also add default PMD/PUD_PAGE_SIZE definition, it's prepare for support page table check feature on new architecture. Signed-off-by: Kefeng Wang Acked-by: Pasha Tatashin --- arch/x86/include/asm/pgtable.h | 19 +++++++++++++++++++ mm/page_table_check.c | 25 ++++++++----------------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index 62ab07e24aef..8cd6514e3052 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -1430,6 +1430,25 @@ static inline bool arch_faults_on_old_pte(void) return false; } +#ifdef CONFIG_PAGE_TABLE_CHECK +static inline bool pte_user_accessible_page(pte_t pte) +{ + return (pte_val(pte) & _PAGE_PRESENT) && (pte_val(pte) & _PAGE_USER); +} + +static inline bool pmd_user_accessible_page(pmd_t pmd) +{ + return pmd_leaf(pmd) && (pmd_val(pmd) & _PAGE_PRESENT) && + (pmd_val(pmd) & _PAGE_USER); +} + +static inline bool pud_user_accessible_page(pud_t pud) +{ + return pud_leaf(pud) && (pud_val(pud) & _PAGE_PRESENT) && + (pud_val(pud) & _PAGE_USER); +} +#endif + #endif /* __ASSEMBLY__ */ #endif /* _ASM_X86_PGTABLE_H */ diff --git a/mm/page_table_check.c b/mm/page_table_check.c index 2458281bff89..145f059d1c4d 100644 --- a/mm/page_table_check.c +++ b/mm/page_table_check.c @@ -10,6 +10,14 @@ #undef pr_fmt #define pr_fmt(fmt) "page_table_check: " fmt +#ifndef PMD_PAGE_SIZE +#define PMD_PAGE_SIZE PMD_SIZE +#endif + +#ifndef PUD_PAGE_SIZE +#define PUD_PAGE_SIZE PUD_SIZE +#endif + struct page_table_check { atomic_t anon_map_count; atomic_t file_map_count; @@ -52,23 +60,6 @@ static struct page_table_check *get_page_table_check(struct page_ext *page_ext) return (void *)(page_ext) + page_table_check_ops.offset; } -static inline bool pte_user_accessible_page(pte_t pte) -{ - return (pte_val(pte) & _PAGE_PRESENT) && (pte_val(pte) & _PAGE_USER); -} - -static inline bool pmd_user_accessible_page(pmd_t pmd) -{ - return pmd_leaf(pmd) && (pmd_val(pmd) & _PAGE_PRESENT) && - (pmd_val(pmd) & _PAGE_USER); -} - -static inline bool pud_user_accessible_page(pud_t pud) -{ - return pud_leaf(pud) && (pud_val(pud) & _PAGE_PRESENT) && - (pud_val(pud) & _PAGE_USER); -} - /* * An enty is removed from the page table, decrement the counters for that page * verify that it is of correct type and counters do not become negative. -- 2.18.0.huawei.25