linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Anshuman Khandual <anshuman.khandual@arm.com>
To: Tong Tiangen <tongtiangen@huawei.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	Pasha Tatashin <pasha.tatashin@soleen.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>,
	Paul Walmsley <paul.walmsley@sifive.com>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Albert Ou <aou@eecs.berkeley.edu>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	linux-arm-kernel@lists.infradead.org,
	linux-riscv@lists.infradead.org,
	Kefeng Wang <wangkefeng.wang@huawei.com>,
	Guohanjun <guohanjun@huawei.com>
Subject: Re: [PATCH -next v5 3/5] mm: page_table_check: add hooks to public helpers
Date: Fri, 22 Apr 2022 11:35:13 +0530	[thread overview]
Message-ID: <7fc56f41-a3c2-76be-7a20-dda392f3c4fc@arm.com> (raw)
In-Reply-To: <20220421082042.1167967-4-tongtiangen@huawei.com>



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 <tongtiangen@huawei.com>
> Acked-by: Pasha Tatashin <pasha.tatashin@soleen.com>
> ---
>  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 <linux/bug.h>
>  #include <linux/errno.h>
>  #include <asm-generic/pgtable_uffd.h>
> +#include <linux/page_table_check.h>
>  
>  #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 */


  reply	other threads:[~2022-04-22  6:04 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-21  8:20 [PATCH -next v5 0/5]mm: page_table_check: add support on arm64 and riscv Tong Tiangen
2022-04-21  8:20 ` [PATCH -next v5 1/5] mm: page_table_check: using PxD_SIZE instead of PxD_PAGE_SIZE Tong Tiangen
2022-04-21 15:28   ` Pasha Tatashin
2022-04-21 18:40     ` Pasha Tatashin
2022-04-22  4:46       ` Anshuman Khandual
2022-04-22  4:41   ` Anshuman Khandual
2022-04-21  8:20 ` [PATCH -next v5 2/5] mm: page_table_check: move pxx_user_accessible_page into x86 Tong Tiangen
2022-04-22  5:11   ` Anshuman Khandual
2022-04-22  6:30     ` Tong Tiangen
2022-04-21  8:20 ` [PATCH -next v5 3/5] mm: page_table_check: add hooks to public helpers Tong Tiangen
2022-04-22  6:05   ` Anshuman Khandual [this message]
2022-04-24  4:10     ` Tong Tiangen
2022-04-25  5:52       ` Anshuman Khandual
2022-04-25 11:34         ` Tong Tiangen
2022-04-21  8:20 ` [PATCH -next v5 4/5] arm64: mm: add support for page table check Tong Tiangen
2022-04-22  6:45   ` Anshuman Khandual
2022-04-24  4:14     ` Tong Tiangen
2022-04-25  5:41       ` Anshuman Khandual
2022-04-25  7:34         ` Tong Tiangen
2022-04-21  8:20 ` [PATCH -next v5 5/5] riscv: " Tong Tiangen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7fc56f41-a3c2-76be-7a20-dda392f3c4fc@arm.com \
    --to=anshuman.khandual@arm.com \
    --cc=akpm@linux-foundation.org \
    --cc=aou@eecs.berkeley.edu \
    --cc=bp@alien8.de \
    --cc=catalin.marinas@arm.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=guohanjun@huawei.com \
    --cc=hpa@zytor.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=mingo@redhat.com \
    --cc=palmer@dabbelt.com \
    --cc=pasha.tatashin@soleen.com \
    --cc=paul.walmsley@sifive.com \
    --cc=tglx@linutronix.de \
    --cc=tongtiangen@huawei.com \
    --cc=wangkefeng.wang@huawei.com \
    --cc=will@kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox