diff mbox series

[-next,v4,1/4] mm: page_table_check: move pxx_user_accessible_page into x86

Message ID 20220418034444.520928-2-tongtiangen@huawei.com (mailing list archive)
State New, archived
Headers show
Series mm: page_table_check: add support on arm64 and riscv | expand

Commit Message

Tong Tiangen April 18, 2022, 3:44 a.m. UTC
From: Kefeng Wang <wangkefeng.wang@huawei.com>

The pxx_user_accessible_page() check the PTE bit, it's
architecture-specific code, move them into x86's pgtable.h,
also add default PMD/PUD_PAGE_SIZE definition, it's prepare
for support page table check feature on new architecture.

Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Acked-by: Pasha Tatashin <pasha.tatashin@soleen.com>
---
 arch/x86/include/asm/pgtable.h | 19 +++++++++++++++++++
 mm/page_table_check.c          | 25 ++++++++-----------------
 2 files changed, 27 insertions(+), 17 deletions(-)

Comments

Anshuman Khandual April 19, 2022, 9:29 a.m. UTC | #1
On 4/18/22 09:14, Tong Tiangen wrote:
> --- a/mm/page_table_check.c
> +++ b/mm/page_table_check.c
> @@ -10,6 +10,14 @@
>  #undef pr_fmt
>  #define pr_fmt(fmt)	"page_table_check: " fmt
>  
> +#ifndef PMD_PAGE_SIZE
> +#define PMD_PAGE_SIZE	PMD_SIZE
> +#endif
> +
> +#ifndef PUD_PAGE_SIZE
> +#define PUD_PAGE_SIZE	PUD_SIZE
> +#endif

Why cannot PMD_SIZE/PUD_SIZE be used on every platform instead ? What is the
need for using PUD_PAGE_SIZE/PMD_PAGE_SIZE ? Are they different on x86 ?
Tong Tiangen April 20, 2022, 6:44 a.m. UTC | #2
在 2022/4/19 17:29, Anshuman Khandual 写道:
> 
> 
> On 4/18/22 09:14, Tong Tiangen wrote:
>> --- a/mm/page_table_check.c
>> +++ b/mm/page_table_check.c
>> @@ -10,6 +10,14 @@
>>   #undef pr_fmt
>>   #define pr_fmt(fmt)	"page_table_check: " fmt
>>   
>> +#ifndef PMD_PAGE_SIZE
>> +#define PMD_PAGE_SIZE	PMD_SIZE
>> +#endif
>> +
>> +#ifndef PUD_PAGE_SIZE
>> +#define PUD_PAGE_SIZE	PUD_SIZE
>> +#endif
> 
> Why cannot PMD_SIZE/PUD_SIZE be used on every platform instead ? What is the
> need for using PUD_PAGE_SIZE/PMD_PAGE_SIZE ? Are they different on x86 ?
> .

Hi, Pasha:
I checked the definitions of PMD_SIZE/PUD_SIZE and 
PUD_PAGE_SIZE/PMD_PAGE_SIZE in x86 architecture and their use outside 
the architecture(eg: in mm/, all used PMD_SIZE/PUD_SIZE), Would it be 
better to use a unified PMD_SIZE/PUD_SIZE here?

Thanks,
Tong.
Pasha Tatashin April 20, 2022, 4:44 p.m. UTC | #3
On Wed, Apr 20, 2022 at 2:45 AM Tong Tiangen <tongtiangen@huawei.com> wrote:
>
>
>
> 在 2022/4/19 17:29, Anshuman Khandual 写道:
> >
> >
> > On 4/18/22 09:14, Tong Tiangen wrote:
> >> --- a/mm/page_table_check.c
> >> +++ b/mm/page_table_check.c
> >> @@ -10,6 +10,14 @@
> >>   #undef pr_fmt
> >>   #define pr_fmt(fmt)        "page_table_check: " fmt
> >>
> >> +#ifndef PMD_PAGE_SIZE
> >> +#define PMD_PAGE_SIZE       PMD_SIZE
> >> +#endif
> >> +
> >> +#ifndef PUD_PAGE_SIZE
> >> +#define PUD_PAGE_SIZE       PUD_SIZE
> >> +#endif
> >
> > Why cannot PMD_SIZE/PUD_SIZE be used on every platform instead ? What is the
> > need for using PUD_PAGE_SIZE/PMD_PAGE_SIZE ? Are they different on x86 ?
> > .
>
> Hi, Pasha:
> I checked the definitions of PMD_SIZE/PUD_SIZE and
> PUD_PAGE_SIZE/PMD_PAGE_SIZE in x86 architecture and their use outside
> the architecture(eg: in mm/, all used PMD_SIZE/PUD_SIZE), Would it be
> better to use a unified PMD_SIZE/PUD_SIZE here?

Hi Tong,

Yes, it makes sense to use PMD_SIZE/PUD_SIZE instead of
PUD_PAGE_SIZE/PMD_PAGE_SIZE in page_table_check to be inline with the
rest of the mm/

Pasha

>
> Thanks,
> Tong.
Tong Tiangen April 21, 2022, 3:05 a.m. UTC | #4
在 2022/4/21 0:44, Pasha Tatashin 写道:
> On Wed, Apr 20, 2022 at 2:45 AM Tong Tiangen <tongtiangen@huawei.com> wrote:
>>
>>
>>
>> 在 2022/4/19 17:29, Anshuman Khandual 写道:
>>>
>>>
>>> On 4/18/22 09:14, Tong Tiangen wrote:
>>>> --- a/mm/page_table_check.c
>>>> +++ b/mm/page_table_check.c
>>>> @@ -10,6 +10,14 @@
>>>>    #undef pr_fmt
>>>>    #define pr_fmt(fmt)        "page_table_check: " fmt
>>>>
>>>> +#ifndef PMD_PAGE_SIZE
>>>> +#define PMD_PAGE_SIZE       PMD_SIZE
>>>> +#endif
>>>> +
>>>> +#ifndef PUD_PAGE_SIZE
>>>> +#define PUD_PAGE_SIZE       PUD_SIZE
>>>> +#endif
>>>
>>> Why cannot PMD_SIZE/PUD_SIZE be used on every platform instead ? What is the
>>> need for using PUD_PAGE_SIZE/PMD_PAGE_SIZE ? Are they different on x86 ?
>>> .
>>
>> Hi, Pasha:
>> I checked the definitions of PMD_SIZE/PUD_SIZE and
>> PUD_PAGE_SIZE/PMD_PAGE_SIZE in x86 architecture and their use outside
>> the architecture(eg: in mm/, all used PMD_SIZE/PUD_SIZE), Would it be
>> better to use a unified PMD_SIZE/PUD_SIZE here?
> 
> Hi Tong,
> 
> Yes, it makes sense to use PMD_SIZE/PUD_SIZE instead of
> PUD_PAGE_SIZE/PMD_PAGE_SIZE in page_table_check to be inline with the
> rest of the mm/
> 
> Pasha
> 
Hi Pasha and Anshuman:

OK, Functional correctness is not affected here, i plan to optimize this 
point after this patchset is merged.

Tong.

>>
>> Thanks,
>> Tong.
> .
Anshuman Khandual April 21, 2022, 3:44 a.m. UTC | #5
On 4/21/22 08:35, Tong Tiangen wrote:
> 
> 
> 在 2022/4/21 0:44, Pasha Tatashin 写道:
>> On Wed, Apr 20, 2022 at 2:45 AM Tong Tiangen <tongtiangen@huawei.com> wrote:
>>>
>>>
>>>
>>> 在 2022/4/19 17:29, Anshuman Khandual 写道:
>>>>
>>>>
>>>> On 4/18/22 09:14, Tong Tiangen wrote:
>>>>> --- a/mm/page_table_check.c
>>>>> +++ b/mm/page_table_check.c
>>>>> @@ -10,6 +10,14 @@
>>>>>    #undef pr_fmt
>>>>>    #define pr_fmt(fmt)        "page_table_check: " fmt
>>>>>
>>>>> +#ifndef PMD_PAGE_SIZE
>>>>> +#define PMD_PAGE_SIZE       PMD_SIZE
>>>>> +#endif
>>>>> +
>>>>> +#ifndef PUD_PAGE_SIZE
>>>>> +#define PUD_PAGE_SIZE       PUD_SIZE
>>>>> +#endif
>>>>
>>>> Why cannot PMD_SIZE/PUD_SIZE be used on every platform instead ? What is the
>>>> need for using PUD_PAGE_SIZE/PMD_PAGE_SIZE ? Are they different on x86 ?
>>>> .
>>>
>>> Hi, Pasha:
>>> I checked the definitions of PMD_SIZE/PUD_SIZE and
>>> PUD_PAGE_SIZE/PMD_PAGE_SIZE in x86 architecture and their use outside
>>> the architecture(eg: in mm/, all used PMD_SIZE/PUD_SIZE), Would it be
>>> better to use a unified PMD_SIZE/PUD_SIZE here?
>>
>> Hi Tong,
>>
>> Yes, it makes sense to use PMD_SIZE/PUD_SIZE instead of
>> PUD_PAGE_SIZE/PMD_PAGE_SIZE in page_table_check to be inline with the
>> rest of the mm/
>>
>> Pasha
>>
> Hi Pasha and Anshuman:
> 
> OK, Functional correctness is not affected here, i plan to optimize this point after this patchset is merged.

As page table check is now being proposed to be supported on multiple platforms i.e
arm64, riscv besides just x86, it should not have any architecture specific macros
or functions. Hence please do generalize these PMD/PUD sizes in this series itself.
Tong Tiangen April 21, 2022, 6:27 a.m. UTC | #6
在 2022/4/21 11:44, Anshuman Khandual 写道:
> 
> 
> On 4/21/22 08:35, Tong Tiangen wrote:
>>
>>
>> 在 2022/4/21 0:44, Pasha Tatashin 写道:
>>> On Wed, Apr 20, 2022 at 2:45 AM Tong Tiangen <tongtiangen@huawei.com> wrote:
>>>>
>>>>
>>>>
>>>> 在 2022/4/19 17:29, Anshuman Khandual 写道:
>>>>>
>>>>>
>>>>> On 4/18/22 09:14, Tong Tiangen wrote:
>>>>>> --- a/mm/page_table_check.c
>>>>>> +++ b/mm/page_table_check.c
>>>>>> @@ -10,6 +10,14 @@
>>>>>>     #undef pr_fmt
>>>>>>     #define pr_fmt(fmt)        "page_table_check: " fmt
>>>>>>
>>>>>> +#ifndef PMD_PAGE_SIZE
>>>>>> +#define PMD_PAGE_SIZE       PMD_SIZE
>>>>>> +#endif
>>>>>> +
>>>>>> +#ifndef PUD_PAGE_SIZE
>>>>>> +#define PUD_PAGE_SIZE       PUD_SIZE
>>>>>> +#endif
>>>>>
>>>>> Why cannot PMD_SIZE/PUD_SIZE be used on every platform instead ? What is the
>>>>> need for using PUD_PAGE_SIZE/PMD_PAGE_SIZE ? Are they different on x86 ?
>>>>> .
>>>>
>>>> Hi, Pasha:
>>>> I checked the definitions of PMD_SIZE/PUD_SIZE and
>>>> PUD_PAGE_SIZE/PMD_PAGE_SIZE in x86 architecture and their use outside
>>>> the architecture(eg: in mm/, all used PMD_SIZE/PUD_SIZE), Would it be
>>>> better to use a unified PMD_SIZE/PUD_SIZE here?
>>>
>>> Hi Tong,
>>>
>>> Yes, it makes sense to use PMD_SIZE/PUD_SIZE instead of
>>> PUD_PAGE_SIZE/PMD_PAGE_SIZE in page_table_check to be inline with the
>>> rest of the mm/
>>>
>>> Pasha
>>>
>> Hi Pasha and Anshuman:
>>
>> OK, Functional correctness is not affected here, i plan to optimize this point after this patchset is merged.
> 
> As page table check is now being proposed to be supported on multiple platforms i.e
> arm64, riscv besides just x86, it should not have any architecture specific macros
> or functions. Hence please do generalize these PMD/PUD sizes in this series itself.
> .

OK, will resend.

Thank you.
Tong.
diff mbox series

Patch

diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
index b7464f13e416..564abe42b0f7 100644
--- a/arch/x86/include/asm/pgtable.h
+++ b/arch/x86/include/asm/pgtable.h
@@ -1447,6 +1447,25 @@  static inline bool arch_has_hw_pte_young(void)
 	return true;
 }
 
+#ifdef CONFIG_PAGE_TABLE_CHECK
+static inline bool pte_user_accessible_page(pte_t pte)
+{
+	return (pte_val(pte) & _PAGE_PRESENT) && (pte_val(pte) & _PAGE_USER);
+}
+
+static inline bool pmd_user_accessible_page(pmd_t pmd)
+{
+	return pmd_leaf(pmd) && (pmd_val(pmd) & _PAGE_PRESENT) &&
+		(pmd_val(pmd) & _PAGE_USER);
+}
+
+static inline bool pud_user_accessible_page(pud_t pud)
+{
+	return pud_leaf(pud) && (pud_val(pud) & _PAGE_PRESENT) &&
+		(pud_val(pud) & _PAGE_USER);
+}
+#endif
+
 #endif	/* __ASSEMBLY__ */
 
 #endif /* _ASM_X86_PGTABLE_H */
diff --git a/mm/page_table_check.c b/mm/page_table_check.c
index 2458281bff89..145f059d1c4d 100644
--- a/mm/page_table_check.c
+++ b/mm/page_table_check.c
@@ -10,6 +10,14 @@ 
 #undef pr_fmt
 #define pr_fmt(fmt)	"page_table_check: " fmt
 
+#ifndef PMD_PAGE_SIZE
+#define PMD_PAGE_SIZE	PMD_SIZE
+#endif
+
+#ifndef PUD_PAGE_SIZE
+#define PUD_PAGE_SIZE	PUD_SIZE
+#endif
+
 struct page_table_check {
 	atomic_t anon_map_count;
 	atomic_t file_map_count;
@@ -52,23 +60,6 @@  static struct page_table_check *get_page_table_check(struct page_ext *page_ext)
 	return (void *)(page_ext) + page_table_check_ops.offset;
 }
 
-static inline bool pte_user_accessible_page(pte_t pte)
-{
-	return (pte_val(pte) & _PAGE_PRESENT) && (pte_val(pte) & _PAGE_USER);
-}
-
-static inline bool pmd_user_accessible_page(pmd_t pmd)
-{
-	return pmd_leaf(pmd) && (pmd_val(pmd) & _PAGE_PRESENT) &&
-		(pmd_val(pmd) & _PAGE_USER);
-}
-
-static inline bool pud_user_accessible_page(pud_t pud)
-{
-	return pud_leaf(pud) && (pud_val(pud) & _PAGE_PRESENT) &&
-		(pud_val(pud) & _PAGE_USER);
-}
-
 /*
  * An enty is removed from the page table, decrement the counters for that page
  * verify that it is of correct type and counters do not become negative.