Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp798435pxb; Fri, 22 Apr 2022 11:22:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzajI7R9oWTMyy0Q5oDSypA+uICwDGYsTg+lYd825WU09v8z0E6lxy0iGdwA8wH9B7lFoEB X-Received: by 2002:a05:6a00:8d6:b0:505:b41a:13a0 with SMTP id s22-20020a056a0008d600b00505b41a13a0mr6349090pfu.67.1650651729559; Fri, 22 Apr 2022 11:22:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650651729; cv=none; d=google.com; s=arc-20160816; b=T6Gnn3ZmSPsrr5tGR66XfUap7YIGCBqDmpHYbFW6GDgP3Bxiu6qJCWCAAHrgKstbxh AJpudAcRBCGWVhESLdYU5tEmzoU0iVwMEuS35AFLXtWno4uNfyiVSP27cczyUKEdruOR kL1+bFofsmq+VH8lQiQdxqwU9QrR87juITZW/1EEsL2pgzuNdZ4KhqOwLtQtIDp1bsyy kue63P4U8+AEZ1U58VeN2PlvZwuihU/5mrF4VFIROzOrIjrbZxr0I8dXiCPxrSGbj/PN X25qfjKrk3QAxbdKPpKUhwEJwSp1CVsg8NqVs1xqi5yONJgbdNPCBwavp9GgqWbVa7rj Ie9w== 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:content-language:subject:user-agent:mime-version :date:message-id; bh=ihGJy/Mckw2/m4pGnHkk8Vt/Fw9vA4NgF1UKxZBu6DY=; b=A9tsIbX3wWSHdyjfZegeAgXUZ2npNh75SdxgHP09zXRLl1co7sZfJrhqqcFtljmWBa eyk2M7DVYYrypma/B36uW1Tralu6Tx0oyynnnPMIUMaab5f6qaicQSID6HBl4m9xGt6n 7ItpCCiNZGOy/a56NO74JAvxoentr6F0glDMPUiwqEAEeRwvNZ+WhUxV34WeQ9KW7Fw6 k6ZG4XM3ROWtQilno6IlY3/QU9qZYMPAkEz3ECBAXmYMfSpFGrL7fTrHOxYDlG/0DVfM jvhfneft0j/eSJauVhGNx0n4sx235EPD/jsK5rzGoiXK8Z5/WqDTZjBLBNtaR3d+FNrr jLpw== 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=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id t185-20020a635fc2000000b00398580600aasi8752997pgb.433.2022.04.22.11.22.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 11:22:09 -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=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8241F1418E4; Fri, 22 Apr 2022 10:52:39 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442946AbiDVGHl (ORCPT + 99 others); Fri, 22 Apr 2022 02:07:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1444223AbiDVGH3 (ORCPT ); Fri, 22 Apr 2022 02:07:29 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3BE5B5005C for ; Thu, 21 Apr 2022 23:04:37 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C4B1D1576; Thu, 21 Apr 2022 23:04:36 -0700 (PDT) Received: from [10.163.40.48] (unknown [10.163.40.48]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 595F83F5A1; Thu, 21 Apr 2022 23:04:27 -0700 (PDT) Message-ID: <7fc56f41-a3c2-76be-7a20-dda392f3c4fc@arm.com> Date: Fri, 22 Apr 2022 11:35:13 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH -next v5 3/5] mm: page_table_check: add hooks to public helpers Content-Language: en-US To: Tong Tiangen , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Pasha Tatashin , Andrew Morton , Catalin Marinas , Will Deacon , Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-riscv@lists.infradead.org, Kefeng Wang , Guohanjun References: <20220421082042.1167967-1-tongtiangen@huawei.com> <20220421082042.1167967-4-tongtiangen@huawei.com> From: Anshuman Khandual In-Reply-To: <20220421082042.1167967-4-tongtiangen@huawei.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, RDNS_NONE,SPF_HELO_NONE autolearn=unavailable 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 On 4/21/22 13:50, 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. Could instrumenting generic page table helpers (fallback instances when its corresponding __HAVE_ARCH_XXX is not defined on the platform), might add all the page table check hooks into paths on platforms which have not subscribed ARCH_SUPPORTS_PAGE_TABLE_CHECK in the first place ? Although these looks have !CONFIG_PAGE_TABLE_CHECK fallback stubs in the header, hence a build problem gets avoided. > > Signed-off-by: Tong Tiangen > Acked-by: Pasha Tatashin > --- > arch/x86/include/asm/pgtable.h | 10 ---------- > include/linux/pgtable.h | 26 ++++++++++++++++++-------- > 2 files changed, 18 insertions(+), 18 deletions(-) > > diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h > index 564abe42b0f7..51cd39858f81 100644 > --- a/arch/x86/include/asm/pgtable.h > +++ b/arch/x86/include/asm/pgtable.h > @@ -1073,16 +1073,6 @@ static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm, > return pte; > } > > -#define __HAVE_ARCH_PTEP_CLEAR AFICS X86 is the only platform subscribing __HAVE_ARCH_PTEP_CLEAR. Hence if this is getting dropped for generic ptep_clear(), then no need to add back #ifnded __HAVE_ARCH_PTEP_CLEAR construct. Generic ptep_clear() is the only definition for all platforms ? Also if this patch is trying to drop off __HAVE_ARCH_PTEP_CLEAR along with other page table check related changes, it needs to be done via a separate patch instead. > -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 49ab8ee2d6d7..10d2d91edf20 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 > @@ -272,14 +273,6 @@ static inline bool arch_has_hw_pte_young(void) > } > #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, > @@ -287,10 +280,22 @@ 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) > +{ > + if (IS_ENABLED(CONFIG_PAGE_TABLE_CHECK)) > + ptep_get_and_clear(mm, addr, ptep); > + else > + pte_clear(mm, addr, ptep); Could not this be reworked to avoid IS_ENABLED() ? This is confusing. If the page table hooks can be added to all potential page table paths via generic helpers, irrespective of CONFIG_PAGE_TABLE_CHECK option, there is no rationale for doing a IS_ENABLED() check here. > +} > +#endif > + > #ifndef __HAVE_ARCH_PTEP_GET > static inline pte_t ptep_get(pte_t *ptep) > { > @@ -360,7 +365,10 @@ static inline pmd_t pmdp_huge_get_and_clear(struct mm_struct *mm, > pmd_t *pmdp) > { > pmd_t pmd = *pmdp; > + > pmd_clear(pmdp); > + page_table_check_pmd_clear(mm, address, pmd); > + > return pmd; > } > #endif /* __HAVE_ARCH_PMDP_HUGE_GET_AND_CLEAR */ > @@ -372,6 +380,8 @@ static inline pud_t pudp_huge_get_and_clear(struct mm_struct *mm, > pud_t pud = *pudp; > > pud_clear(pudp); > + page_table_check_pud_clear(mm, address, pud); > + > return pud; > } > #endif /* __HAVE_ARCH_PUDP_HUGE_GET_AND_CLEAR */