Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp4335116pxb; Wed, 20 Apr 2022 00:28:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxrmrIDZxOENIe4/BRgimURftdXNPvssh+gJuNi+73pZwIycvfpUEH3CUBjo4wSXvknUoCJ X-Received: by 2002:a17:90b:4f92:b0:1cd:3a73:3a46 with SMTP id qe18-20020a17090b4f9200b001cd3a733a46mr2958421pjb.66.1650439696447; Wed, 20 Apr 2022 00:28:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650439696; cv=none; d=google.com; s=arc-20160816; b=oYXFImS+vV6JLSMOztF9IQdfXJtztTWRj9Z8Usk239CIwU67UfMmukvonyz+hhVTdw sWU5BnY0NlpEKG1LEwAfpMShqPX49cmX0ApQ28qlLe2hYiH6LfOvM3ZovH4phUjF4JUL Ej6Yw6RmQHGGgkNZC8qM/uKL4B2tAM2yHxPaK7CN93aFzVMweh/UreXNPwioMQFPRqKP FeeOFeypcb5f+xugw3cibdP5qD/Fm/hqu4KJ28X/BH5vhuqzawmrl8kzJLpkBtbmjHZE +b969gr0W6eldw02hppfmB2DC1gVdvhgolX9XULauGPgmCYm8cPdvMWUQYB5PZY4+Myr AP3A== 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=CDiGDwQnnU2EFpBvXmCY23P7+TXnJPf8wKh3bLZrXPA=; b=E4OzeONb1tL5UVojmSTngvPBfmg2Z4/zoBl7zKjCY11xnwn7hcQz4rszuzZ6MBqgxO eeu4hpaF5ixDRdsYxxr9TmYPI6vBomy+5Q0ki3beCu9phJQmkvUh2LzD2gdGXtkqhLT0 9AsHVrXFqd+1KHcJvr4R1kvTLwVvKpqDbjtWxLrlT0vHTBN2fURBCkqNDzzca8pO/DMA Ga7xAk8KOa2z1nvnW4jrYIJPzzuVjcB4oPlFlY7bDPul5We8dt18lLZmaloh+JUEKiZy N+9v83xRaAfOi1Qu1wgWV6whPOcrNMOBp/X7MjfG5Vpo8Wn206P75DLj0P2jTUF5qdL4 qFuA== 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 y62-20020a638a41000000b003aa7696a827si56194pgd.784.2022.04.20.00.28.02; Wed, 20 Apr 2022 00:28:16 -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 S236021AbiDRD2w (ORCPT + 99 others); Sun, 17 Apr 2022 23:28:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236031AbiDRD2q (ORCPT ); Sun, 17 Apr 2022 23:28:46 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C692517ABA for ; Sun, 17 Apr 2022 20:26:08 -0700 (PDT) Received: from kwepemi100004.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4KhXPc28kfz1J9jy; Mon, 18 Apr 2022 11:25:24 +0800 (CST) Received: from kwepemm600017.china.huawei.com (7.193.23.234) by kwepemi100004.china.huawei.com (7.221.188.70) 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 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:04 +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 1/4] mm: page_table_check: move pxx_user_accessible_page into x86 Date: Mon, 18 Apr 2022 03:44:41 +0000 Message-ID: <20220418034444.520928-2-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 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 b7464f13e416..564abe42b0f7 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -1447,6 +1447,25 @@ static inline bool arch_has_hw_pte_young(void) return true; } +#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.25.1