@@ -98,18 +98,19 @@ extern unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)];
9898#define pte_valid (pte ) (!!(pte_val(pte) & PTE_VALID))
9999#define pte_valid_not_user (pte ) \
100100 ((pte_val(pte) & (PTE_VALID | PTE_USER)) == PTE_VALID)
101- #define pte_valid_young (pte ) \
102- ((pte_val(pte) & (PTE_VALID | PTE_AF)) == (PTE_VALID | PTE_AF))
103101#define pte_valid_user (pte ) \
104102 ((pte_val(pte) & (PTE_VALID | PTE_USER)) == (PTE_VALID | PTE_USER))
105103
106104/*
107105 * Could the pte be present in the TLB? We must check mm_tlb_flush_pending
108106 * so that we don't erroneously return false for pages that have been
109107 * remapped as PROT_NONE but are yet to be flushed from the TLB.
108+ * Note that we can't make any assumptions based on the state of the access
109+ * flag, since ptep_clear_flush_young() elides a DSB when invalidating the
110+ * TLB.
110111 */
111112#define pte_accessible (mm , pte ) \
112- (mm_tlb_flush_pending(mm) ? pte_present(pte) : pte_valid_young (pte))
113+ (mm_tlb_flush_pending(mm) ? pte_present(pte) : pte_valid (pte))
113114
114115/*
115116 * p??_access_permitted() is true for valid user mappings (subject to the
@@ -135,13 +136,6 @@ static inline pte_t set_pte_bit(pte_t pte, pgprot_t prot)
135136 return pte ;
136137}
137138
138- static inline pte_t pte_wrprotect (pte_t pte )
139- {
140- pte = clear_pte_bit (pte , __pgprot (PTE_WRITE ));
141- pte = set_pte_bit (pte , __pgprot (PTE_RDONLY ));
142- return pte ;
143- }
144-
145139static inline pte_t pte_mkwrite (pte_t pte )
146140{
147141 pte = set_pte_bit (pte , __pgprot (PTE_WRITE ));
@@ -167,6 +161,20 @@ static inline pte_t pte_mkdirty(pte_t pte)
167161 return pte ;
168162}
169163
164+ static inline pte_t pte_wrprotect (pte_t pte )
165+ {
166+ /*
167+ * If hardware-dirty (PTE_WRITE/DBM bit set and PTE_RDONLY
168+ * clear), set the PTE_DIRTY bit.
169+ */
170+ if (pte_hw_dirty (pte ))
171+ pte = pte_mkdirty (pte );
172+
173+ pte = clear_pte_bit (pte , __pgprot (PTE_WRITE ));
174+ pte = set_pte_bit (pte , __pgprot (PTE_RDONLY ));
175+ return pte ;
176+ }
177+
170178static inline pte_t pte_mkold (pte_t pte )
171179{
172180 return clear_pte_bit (pte , __pgprot (PTE_AF ));
@@ -782,12 +790,6 @@ static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addres
782790 pte = READ_ONCE (* ptep );
783791 do {
784792 old_pte = pte ;
785- /*
786- * If hardware-dirty (PTE_WRITE/DBM bit set and PTE_RDONLY
787- * clear), set the PTE_DIRTY bit.
788- */
789- if (pte_hw_dirty (pte ))
790- pte = pte_mkdirty (pte );
791793 pte = pte_wrprotect (pte );
792794 pte_val (pte ) = cmpxchg_relaxed (& pte_val (* ptep ),
793795 pte_val (old_pte ), pte_val (pte ));
0 commit comments