Re: [PATCH v21 08/26] x86/mm: Introduce _PAGE_COW

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Mar 02, 2021 at 03:46:31PM -0800, Yu, Yu-cheng wrote:
> There is a problem of doing that: pmd_write() is defined after this
> function.  Maybe we can declare it first, or leave this as-is?

Or a third option: you lift those two functions in a prepatch and then
in this patch use them directly.

Combined diff ontop:

---
diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
index 1a6c0784af0a..b7e4d031ce22 100644
--- a/arch/x86/include/asm/pgtable.h
+++ b/arch/x86/include/asm/pgtable.h
@@ -209,6 +209,18 @@ static inline int pte_write(pte_t pte)
 	return (pte_flags(pte) & _PAGE_RW) || pte_shstk(pte);
 }
 
+#define pmd_write pmd_write
+static inline int pmd_write(pmd_t pmd)
+{
+	return (pmd_flags(pmd) & _PAGE_RW) || pmd_shstk(pmd);
+}
+
+#define pud_write pud_write
+static inline int pud_write(pud_t pud)
+{
+	return pud_flags(pud) & _PAGE_RW;
+}
+
 static inline int pte_huge(pte_t pte)
 {
 	return pte_flags(pte) & _PAGE_PSE;
@@ -540,7 +552,7 @@ static inline pmd_t pmd_mkdirty(pmd_t pmd)
 	pmdval_t dirty = _PAGE_DIRTY;
 
 	/* Avoid creating (HW)Dirty=1, Write=0 PMDs */
-	if (cpu_feature_enabled(X86_FEATURE_SHSTK) && !(pmd_flags(pmd) & _PAGE_RW))
+	if (cpu_feature_enabled(X86_FEATURE_SHSTK) && !pmd_write(pmd))
 		dirty = _PAGE_COW;
 
 	return pmd_set_flags(pmd, dirty | _PAGE_SOFT_DIRTY);
@@ -636,7 +648,7 @@ static inline pud_t pud_mkdirty(pud_t pud)
 	pudval_t dirty = _PAGE_DIRTY;
 
 	/* Avoid creating (HW)Dirty=1, Write=0 PUDs */
-	if (cpu_feature_enabled(X86_FEATURE_SHSTK) && !(pud_flags(pud) & _PAGE_RW))
+	if (cpu_feature_enabled(X86_FEATURE_SHSTK) && !pud_write(pud))
 		dirty = _PAGE_COW;
 
 	return pud_set_flags(pud, dirty | _PAGE_SOFT_DIRTY);
@@ -1273,12 +1285,6 @@ extern int pmdp_clear_flush_young(struct vm_area_struct *vma,
 				  unsigned long address, pmd_t *pmdp);
 
 
-#define pmd_write pmd_write
-static inline int pmd_write(pmd_t pmd)
-{
-	return (pmd_flags(pmd) & _PAGE_RW) || pmd_shstk(pmd);
-}
-
 #define __HAVE_ARCH_PMDP_HUGE_GET_AND_CLEAR
 static inline pmd_t pmdp_huge_get_and_clear(struct mm_struct *mm, unsigned long addr,
 				       pmd_t *pmdp)
@@ -1300,12 +1306,6 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
 	clear_bit(_PAGE_BIT_RW, (unsigned long *)pmdp);
 }
 
-#define pud_write pud_write
-static inline int pud_write(pud_t pud)
-{
-	return pud_flags(pud) & _PAGE_RW;
-}
-
 #ifndef pmdp_establish
 #define pmdp_establish pmdp_establish
 static inline pmd_t pmdp_establish(struct vm_area_struct *vma,

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette



[Index of Archives]     [Linux Kernel]     [Kernel Newbies]     [x86 Platform Driver]     [Netdev]     [Linux Wireless]     [Netfilter]     [Bugtraq]     [Linux Filesystems]     [Yosemite Discussion]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]

  Powered by Linux