@@ -271,8 +271,9 @@ static inline enum pte_flush_type pte_flags_flush_type(unsigned long oldflags,
* dirty/access bit if needed without a fault.
*/
const pteval_t flush_on_clear = _PAGE_DIRTY | _PAGE_PRESENT |
- _PAGE_ACCESSED | _PAGE_RW;
+ _PAGE_ACCESSED;
const pteval_t flush_on_set = _PAGE_NX;
+ const pteval_t flush_on_special = _PAGE_RW;
const pteval_t flush_on_set_relaxed = _PAGE_RW;
const pteval_t flush_on_clear_relaxed = _PAGE_NX;
const pteval_t software_flags = _PAGE_SOFTW1 | _PAGE_SOFTW2 |
@@ -302,6 +303,17 @@ static inline enum pte_flush_type pte_flags_flush_type(unsigned long oldflags,
if (diff & oldflags & flush_on_clear)
return PTE_FLUSH_STRICT;
+ /*
+ * Did any of the 'flush_on_set' flags was set between 'oldflags' and
+ * 'newflags'?
+ */
+ if (diff & newflags & flush_on_set)
+ return PTE_FLUSH_STRICT;
+
+ /* On RW->RO, a flush is needed if the old entry is dirty */
+ if ((diff & oldflags & _PAGE_RW) && (oldflags & _PAGE_DIRTY))
+ return PTE_FLUSH_STRICT;
+
/* Flush on modified flags. */
if (diff & flush_on_change)
return PTE_FLUSH_STRICT;
@@ -314,7 +326,7 @@ static inline enum pte_flush_type pte_flags_flush_type(unsigned long oldflags,
/* Ensure there are no flags that were left behind */
if (IS_ENABLED(CONFIG_DEBUG_VM) &&
- (diff & ~(flush_on_clear | flush_on_set |
+ (diff & ~(flush_on_clear | flush_on_set | flush_on_special |
software_flags | flush_on_change))) {
VM_WARN_ON_ONCE(1);
return PTE_FLUSH_STRICT;