Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3007298pxp; Tue, 22 Mar 2022 10:08:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzKqskrbAL1JJMmr6WwB9QsirOQg7SNK9DIK/ZVfnjEsmCCMOS7m2tgEvqkpc307TYryCIK X-Received: by 2002:a05:6402:34d6:b0:419:4dc2:91c5 with SMTP id w22-20020a05640234d600b004194dc291c5mr8495346edc.329.1647968910690; Tue, 22 Mar 2022 10:08:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647968910; cv=none; d=google.com; s=arc-20160816; b=YurZIgs+r77zLEZfr50TZP/ABpy92aHG4fdfMTWaq8+dyEFc2QGVANqNZcG78d9Tva 00mS+KkyJuS/1fpRRk1TKpPCYTG6o6EiBryLpJL302L04KeaFNRq58m8oqmSC8Ii2NB1 ZNwJTnfQ6YszcEbm0i3lQHRxexMCzSvkzKltIXXn2Q5RoljvkfptruYjm6lZFaASLCDy QIFbYGpLRtbrBbl5gy9qwKIYAjbeVsFOH+9aD5e1JsNME5SD8LrgDlFYIPhtxtQfnb0q uQA8unw6r+WYGCEHDNDaNj0ZEoaiOU89DIJMZF70eu9SWVgMIwpGwOqnCiJlfwjiU634 Jv8A== 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=5GgKO47TOAdaaZ1q/k+B5uhj39D6eJl3E5XK970yJ90=; b=KiesIXC7AYf4oXZxnaFbNB8YjDcC3NWB7X0Ia6dATHqRNyp8IWRIy8LBvPd/iAjhGO ty9i5IKHmjPNJYYIYXR4qrOZfge7GeQxfyYOuo1d47br9s9DGIHVJEY3bMsy9SMbj6Hs OTqTh1THTOgSN6jFzOkMrk0BIuh9zd0Zhyp8ajY87U1zW+qnvA45I05BTwyQg/8SGYUz 7fPhBjK3WBLRaRljtf8OkYsWQu3LRx2JfqneqD1DS4nTlv8JALeTpeWPDeWoFQbmj+U2 Q0Lcy8GvIyv5UA6bsobbbYfaSle5oONMSRIzDCi2FZF/VOvIXzQh268ejBJN98jwn5oR HgNA== 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 c8-20020a170906528800b006dfe7bc2fafsi7423307ejm.56.2022.03.22.10.07.59; Tue, 22 Mar 2022 10:08:30 -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 S236573AbiCVO2l (ORCPT + 99 others); Tue, 22 Mar 2022 10:28:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234404AbiCVO1c (ORCPT ); Tue, 22 Mar 2022 10:27:32 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E02492E6BD for ; Tue, 22 Mar 2022 07:25:54 -0700 (PDT) Received: from kwepemi500021.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4KNDJL6c4bzfZMV; Tue, 22 Mar 2022 22:24:18 +0800 (CST) Received: from kwepemm600017.china.huawei.com (7.193.23.234) by kwepemi500021.china.huawei.com (7.221.188.245) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 22 Mar 2022 22:25:51 +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:50 +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 1/4] mm: page_table_check: move pxx_user_accessible_page into x86 Date: Tue, 22 Mar 2022 14:44:44 +0000 Message-ID: <20220322144447.3563146-2-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 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 --- 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