Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2195947pxb; Fri, 25 Mar 2022 12:50:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwCsfA3UHRmJOG0WdQhVMUBMEXLdml2qiHKAwqG+dVm0saOUOe/HzBu9dXbLs4ikvUCSLc4 X-Received: by 2002:a05:6a00:21c8:b0:4c4:4bd:dc17 with SMTP id t8-20020a056a0021c800b004c404bddc17mr11345716pfj.57.1648237799845; Fri, 25 Mar 2022 12:49:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648237799; cv=none; d=google.com; s=arc-20160816; b=Xz+twmhcEFkatWX1EEBf6aU4dh6uv3iaqqvZgXEV8rqYSS8Y4RU3aX2nqEGyYU1K7R QBlyeIEXq/08aBJxCPzgODLSTLcPLmoM9v7qKwwa6iC4CH4oBBFVGEvmPhX9f3zHMwAb wl/qqCNtYYXDxKkij85gofuzLRFEMva+Uev6n/G/EI2f5XOEUuG0s3Rf7gbYPyeTz52x 8G67+1aeh9j7iRAf7e7aHc8yes1NzNJ6GCc+A6vuPdhw6LglYVftUfCeAzVjiGRgmlA2 z2PAiMOOPmlDCYPBnfNDZtdPSap0PvEAmc3K4xfzH+eXQ0JdRu5vdQtJEOCJ9GTpEdHy x5Ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id; bh=P7TUGD+nSHbg1XagqPzV6ojH27KcZgL8HVojAA7GA4E=; b=e196jp7acDLQ8bHOAW/cXSXgrrpk7fiuYvth8rGnjaYEq8oFy/pR0b5O3yblxo7961 v/rV8mpFz4pej0J3bbJ5Z0L18bp18yYzBEzAu8eqmPNL5wudzA+5IhfMhu5Glb5bCz9I zM6xNfpXNjv6QznahPjlJJYMhPT7jHHUE4N0LIO/98VdTN7psepLs3fIwBcH6XYnTJeE 8rLiQiCZBSmH3I3FMXGpmUYzYhXhYhv488dP7sPFU7Ji/fT1760ope45FpSV5I/wm9TY 0cwmQXSmY3e9t1OePNCC7j2rvlC6z9bDhyrVFuQlfoxmaQTOFqlf/o4W5O1Yidj7cVo2 bjnw== 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:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id 4-20020a170902ee4400b00153b2d1645esi2986790plo.102.2022.03.25.12.49.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 12:49:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 681A92C5EF0; Fri, 25 Mar 2022 11:39:34 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242232AbiCXCJs (ORCPT + 99 others); Wed, 23 Mar 2022 22:09:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348652AbiCXCJZ (ORCPT ); Wed, 23 Mar 2022 22:09:25 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E161617A for ; Wed, 23 Mar 2022 19:07:54 -0700 (PDT) Received: from kwepemi500008.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4KP7qD2mtszCqsq; Thu, 24 Mar 2022 10:05:44 +0800 (CST) Received: from kwepemm600017.china.huawei.com (7.193.23.234) by kwepemi500008.china.huawei.com (7.221.188.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Thu, 24 Mar 2022 10:07:51 +0800 Received: from [10.174.179.234] (10.174.179.234) 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, 24 Mar 2022 10:07:50 +0800 Message-ID: <0c95c24d-b980-a8b3-9c68-e10d16e05e10@huawei.com> Date: Thu, 24 Mar 2022 10:07:49 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Subject: Re: [PATCH -next v2 2/4] mm: page_table_check: add hooks to public helpers To: Pasha Tatashin CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , "H. Peter Anvin" , Andrew Morton , "Catalin Marinas" , Will Deacon , "Paul Walmsley" , Palmer Dabbelt , Albert Ou , LKML , linux-mm , Linux ARM , References: <20220322144447.3563146-1-tongtiangen@huawei.com> <20220322144447.3563146-3-tongtiangen@huawei.com> From: Tong Tiangen In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.179.234] 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=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 在 2022/3/24 1:42, Pasha Tatashin 写道: > On Tue, Mar 22, 2022 at 10:25 AM Tong Tiangen wrote: >> >> 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 > > I have a preference to use if (IS_ENABLED(CONFIG_PAGE_TABLE_CHECK)) > instead of #ifdef. The end result is the same. Otherwise it looks > good. > > Thanks, > Pasha > . I have a little hesitation when making this change , in theory, add if here may affect the performance a little in some scenarios. However, the impact on the whole call path should be small. I will send v3 using if (IS_ENABLED(CONFIG_PAGE_TABLE_CHECK)). Thanks. Tong .