Commit 60fa1571 authored by Anton Ivanov's avatar Anton Ivanov Committed by Stefan Bader

um: Avoid marking pages with "changed protection"

BugLink: https://bugs.launchpad.net/bugs/1818813

[ Upstream commit 8892d854 ]

Changing protection is a very high cost operation in UML
because in addition to an extra syscall it also interrupts
mmap merge sequences generated by the tlb.

While the condition is not particularly common it is worth
avoiding.
Signed-off-by: default avatarAnton Ivanov <anton.ivanov@cambridgegreys.com>
Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarJuerg Haefliger <juergh@canonical.com>
Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
parent fc434a53
...@@ -197,12 +197,17 @@ static inline pte_t pte_mkold(pte_t pte) ...@@ -197,12 +197,17 @@ static inline pte_t pte_mkold(pte_t pte)
static inline pte_t pte_wrprotect(pte_t pte) static inline pte_t pte_wrprotect(pte_t pte)
{ {
pte_clear_bits(pte, _PAGE_RW); if (likely(pte_get_bits(pte, _PAGE_RW)))
pte_clear_bits(pte, _PAGE_RW);
else
return pte;
return(pte_mknewprot(pte)); return(pte_mknewprot(pte));
} }
static inline pte_t pte_mkread(pte_t pte) static inline pte_t pte_mkread(pte_t pte)
{ {
if (unlikely(pte_get_bits(pte, _PAGE_USER)))
return pte;
pte_set_bits(pte, _PAGE_USER); pte_set_bits(pte, _PAGE_USER);
return(pte_mknewprot(pte)); return(pte_mknewprot(pte));
} }
...@@ -221,6 +226,8 @@ static inline pte_t pte_mkyoung(pte_t pte) ...@@ -221,6 +226,8 @@ static inline pte_t pte_mkyoung(pte_t pte)
static inline pte_t pte_mkwrite(pte_t pte) static inline pte_t pte_mkwrite(pte_t pte)
{ {
if (unlikely(pte_get_bits(pte, _PAGE_RW)))
return pte;
pte_set_bits(pte, _PAGE_RW); pte_set_bits(pte, _PAGE_RW);
return(pte_mknewprot(pte)); return(pte_mknewprot(pte));
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment