From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 908F9C433F5 for ; Thu, 24 Mar 2022 02:44:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CF62C6B0072; Wed, 23 Mar 2022 22:44:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CA5D96B0073; Wed, 23 Mar 2022 22:44:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B47716B0074; Wed, 23 Mar 2022 22:44:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.27]) by kanga.kvack.org (Postfix) with ESMTP id A195F6B0072 for ; Wed, 23 Mar 2022 22:44:32 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id DFACE20583 for ; Thu, 24 Mar 2022 02:44:31 +0000 (UTC) X-FDA: 79277736342.12.55387D2 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf15.hostedemail.com (Postfix) with ESMTP id 99666A002D for ; Thu, 24 Mar 2022 02:44:30 +0000 (UTC) Received: from kwepemi100013.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4KP8f53mB4zfZCQ; Thu, 24 Mar 2022 10:42:53 +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; Thu, 24 Mar 2022 10:44:27 +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:44:25 +0800 Message-ID: Date: Thu, 24 Mar 2022 10:44:25 +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> <0c95c24d-b980-a8b3-9c68-e10d16e05e10@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: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemm600017.china.huawei.com (7.193.23.234) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 99666A002D X-Stat-Signature: x4yaoesddfmftxu1dcjwfgd35nxagbg5 X-Rspam-User: Authentication-Results: imf15.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf15.hostedemail.com: domain of tongtiangen@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=tongtiangen@huawei.com X-HE-Tag: 1648089870-839014 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 在 2022/3/24 10:12, Pasha Tatashin 写道: > On Wed, Mar 23, 2022 at 10:07 PM Tong Tiangen wrote: >> >> >> >> 在 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 do not think so, the compiler should optimize out IS_ENABLED() when > not enabled, no? > You are right. https://www.kernel.org/doc/Documentation/process/coding-style.rst The compiler will constant-fold the conditional away, and include or exclude the block of code just as with an #ifdef, so this will **not add any runtime overhead**. Thanks :) >> >> I will send v3 using if (IS_ENABLED(CONFIG_PAGE_TABLE_CHECK)). >> >> Thanks. >> Tong >> . > .