Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp929484pxb; Thu, 24 Mar 2022 09:25:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyH1HtCR56NtkYg35qV/vRqZpxq5SO6EGjdrZY5r6XadpJ8MfAJea2AtAkaq9v+7SsiH88J X-Received: by 2002:a63:6c8a:0:b0:37c:62da:a647 with SMTP id h132-20020a636c8a000000b0037c62daa647mr4669262pgc.423.1648139112272; Thu, 24 Mar 2022 09:25:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648139112; cv=none; d=google.com; s=arc-20160816; b=GFmI7glB7fh5fBIc+mBa8uzrTCjPdFTPe3WPMLKDNRDSvxeyY4L/swHOP5AEfLYr26 n5XpzztEUH5a9/SZ24xa+j/qBEhAgcpaMahL3EFmItqPN7cooPTEWvoGeP2Jip+ypWUy cFHo8udUkJ2F7bGX3gBsuNwf0RER8H15fRxUFu4xmZqbCm9FVXcyPqGTMihAFdJ0o4Gz 3MYTUhr5z1PRnXpE5Y8kBMoHyA0pjlazUq9oBr3qGoh8zY3zcvPw+LSVLtSCwpIbK9aj vFHBc+Wwyz/1zaSpeFqknfWAIj9EsHJNC+8Zkh3vWJJmdLnOFYv1Y4EiJGgwnoBMCbK9 DPRQ== 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=TnkcATkTU8ZI+fid2mZj4wVp9KeNuQu9fpFtbErHEPg=; b=ldEjTW/pCmnjUKSMGpAQFFW95Cp6pyX0c95meXO+wC1b/B3IXfQVSCAtl/moMdU4bk 1O8xZdqu7jqJvQp3LyhYVtwDytzL62U1TCJZ+h5mL4vwwRWgHFMjTsYM37rxQD24arRa riH0uh0/3vnB+mgknj+YRR+EXewXCuE5XMFD4UaONBMK417BT29Dlf1bmUH7Ub0wZ6FZ hW3jA9JDRoLAEwJlfo30MpeQxkVjRjr7pJ+WsiiaUVyStJ/86k4T/5EANEgS3o976Vxa 0F4S8EZyCIdndxR7dt0tK+IYRBOde6JH1hl7S1Q2oesnW3j7npPiWVVM4JitOjuleZo2 itFg== 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 b129-20020a636787000000b003816043eea0si22186268pgc.149.2022.03.24.09.24.57; Thu, 24 Mar 2022 09:25:12 -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 S1346964AbiCXCqF (ORCPT + 99 others); Wed, 23 Mar 2022 22:46:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229863AbiCXCqC (ORCPT ); Wed, 23 Mar 2022 22:46:02 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFAE45D5D5 for ; Wed, 23 Mar 2022 19:44:29 -0700 (PDT) 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-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,NICE_REPLY_A, 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 在 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 >> . > .