@@ -108,18 +108,19 @@ extern unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)];
108108#define pte_valid (pte ) (!!(pte_val(pte) & PTE_VALID))
109109#define pte_valid_not_user (pte ) \
110110 ((pte_val(pte) & (PTE_VALID | PTE_USER)) == PTE_VALID)
111- #define pte_valid_young (pte ) \
112- ((pte_val(pte) & (PTE_VALID | PTE_AF)) == (PTE_VALID | PTE_AF))
113111#define pte_valid_user (pte ) \
114112 ((pte_val(pte) & (PTE_VALID | PTE_USER)) == (PTE_VALID | PTE_USER))
115113
116114/*
117115 * Could the pte be present in the TLB? We must check mm_tlb_flush_pending
118116 * so that we don't erroneously return false for pages that have been
119117 * remapped as PROT_NONE but are yet to be flushed from the TLB.
118+ * Note that we can't make any assumptions based on the state of the access
119+ * flag, since ptep_clear_flush_young() elides a DSB when invalidating the
120+ * TLB.
120121 */
121122#define pte_accessible (mm , pte ) \
122- (mm_tlb_flush_pending(mm) ? pte_present(pte) : pte_valid_young (pte))
123+ (mm_tlb_flush_pending(mm) ? pte_present(pte) : pte_valid (pte))
123124
124125/*
125126 * p??_access_permitted() is true for valid user mappings (subject to the
@@ -145,13 +146,6 @@ static inline pte_t set_pte_bit(pte_t pte, pgprot_t prot)
145146 return pte ;
146147}
147148
148- static inline pte_t pte_wrprotect (pte_t pte )
149- {
150- pte = clear_pte_bit (pte , __pgprot (PTE_WRITE ));
151- pte = set_pte_bit (pte , __pgprot (PTE_RDONLY ));
152- return pte ;
153- }
154-
155149static inline pte_t pte_mkwrite (pte_t pte )
156150{
157151 pte = set_pte_bit (pte , __pgprot (PTE_WRITE ));
@@ -177,6 +171,20 @@ static inline pte_t pte_mkdirty(pte_t pte)
177171 return pte ;
178172}
179173
174+ static inline pte_t pte_wrprotect (pte_t pte )
175+ {
176+ /*
177+ * If hardware-dirty (PTE_WRITE/DBM bit set and PTE_RDONLY
178+ * clear), set the PTE_DIRTY bit.
179+ */
180+ if (pte_hw_dirty (pte ))
181+ pte = pte_mkdirty (pte );
182+
183+ pte = clear_pte_bit (pte , __pgprot (PTE_WRITE ));
184+ pte = set_pte_bit (pte , __pgprot (PTE_RDONLY ));
185+ return pte ;
186+ }
187+
180188static inline pte_t pte_mkold (pte_t pte )
181189{
182190 return clear_pte_bit (pte , __pgprot (PTE_AF ));
@@ -798,12 +806,6 @@ static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addres
798806 pte = READ_ONCE (* ptep );
799807 do {
800808 old_pte = pte ;
801- /*
802- * If hardware-dirty (PTE_WRITE/DBM bit set and PTE_RDONLY
803- * clear), set the PTE_DIRTY bit.
804- */
805- if (pte_hw_dirty (pte ))
806- pte = pte_mkdirty (pte );
807809 pte = pte_wrprotect (pte );
808810 pte_val (pte ) = cmpxchg_relaxed (& pte_val (* ptep ),
809811 pte_val (old_pte ), pte_val (pte ));
0 commit comments