From: Nadav Amit <nadav.amit@gmail.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Linux-MM <linux-mm@kvack.org>,
LKML <linux-kernel@vger.kernel.org>,
Andrea Arcangeli <aarcange@redhat.com>,
Andrew Morton <akpm@linux-foundation.org>,
Andy Lutomirski <luto@kernel.org>,
Dave Hansen <dave.hansen@linux.intel.com>,
Peter Xu <peterx@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
Will Deacon <will@kernel.org>, Yu Zhao <yuzhao@google.com>,
Nick Piggin <npiggin@gmail.com>,
x86@kernel.org
Subject: Re: [PATCH v2 5/5] mm/mprotect: do not flush on permission promotion
Date: Mon, 25 Oct 2021 09:27:08 -0700 [thread overview]
Message-ID: <94412B55-0E16-4BC1-982F-37C082A0BABD@gmail.com> (raw)
In-Reply-To: <YXaRHE0IrJD2lXeg@hirez.programming.kicks-ass.net>
> On Oct 25, 2021, at 4:12 AM, Peter Zijlstra <peterz@infradead.org> wrote:
>
> On Thu, Oct 21, 2021 at 05:21:12AM -0700, Nadav Amit wrote:
>> +/*
>> + * pte_may_need_flush() checks whether permissions were demoted and require a
>> + * flush. It should only be used for userspace PTEs.
>> + */
>> +static inline bool pte_may_need_flush(pte_t oldpte, pte_t newpte)
>> +{
>> + /* new is non-present: need only if old is present */
>> + if (!pte_present(newpte))
>> + return pte_present(oldpte);
>> +
>> + /* old is not present: no need for flush */
>> + if (!pte_present(oldpte))
>> + return false;
>
> Would it not be clearer to write the above like:
>
> /* !PRESENT -> * ; no need for flush */
> if (!pte_present(oldpte))
> return false;
>
> /* PRESENT -> !PRESENT ; needs flush */
> if (!pte_present(newpte))
> return true;
>
> ?
I will change the comment to yours. Thanks.
>
>
>> diff --git a/mm/mprotect.c b/mm/mprotect.c
>> index 0f5c87af5c60..6179c82ea72d 100644
>> --- a/mm/mprotect.c
>> +++ b/mm/mprotect.c
>> @@ -141,7 +141,8 @@ static unsigned long change_pte_range(struct mmu_gather *tlb,
>> ptent = pte_mkwrite(ptent);
>> }
>> ptep_modify_prot_commit(vma, addr, pte, oldpte, ptent);
>> - tlb_flush_pte_range(tlb, addr, PAGE_SIZE);
>> + if (pte_may_need_flush(oldpte, ptent))
>> + tlb_flush_pte_range(tlb, addr, PAGE_SIZE);
>> pages++;
>> } else if (is_swap_pte(oldpte)) {
>> swp_entry_t entry = pte_to_swp_entry(oldpte);
>
> One question on naming, "may_need" sounds a bit washy to me, either it
> does or it does not. I suppose you're trying to convey the fact that we
> ought to err towards too many TLBi rather than too few, but that's
> always true.
>
> That is, would "needs" not be a better name?
The “may” is indeed intended to be clear that the function can error
towards too many TLB flushes (of any kind). For instance, in a change
from (!dirty|write)->(!write), no flush is needed in theory. I was too
chicken to add it, at least for now.
I can change the name and indicate in the comment instead though.
next prev parent reply other threads:[~2021-10-25 16:27 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-21 12:21 [PATCH v2 0/5] mm/mprotect: avoid unnecessary TLB flushes Nadav Amit
2021-10-21 12:21 ` [PATCH v2 1/5] x86: Detection of Knights Landing A/D leak Nadav Amit
2021-10-26 15:54 ` Dave Hansen
2021-10-26 15:57 ` Nadav Amit
2021-10-21 12:21 ` [PATCH v2 2/5] mm: avoid unnecessary flush on change_huge_pmd() Nadav Amit
2021-10-25 10:52 ` Peter Zijlstra
2021-10-25 16:29 ` Nadav Amit
2021-10-26 16:06 ` Dave Hansen
2021-10-26 16:47 ` Nadav Amit
2021-10-26 16:53 ` Nadav Amit
2021-10-26 17:44 ` Nadav Amit
2021-10-26 18:44 ` Dave Hansen
2021-10-26 19:06 ` Nadav Amit
2021-10-26 19:40 ` Dave Hansen
2021-10-26 20:07 ` Nadav Amit
2021-10-26 20:47 ` Dave Hansen
2021-10-21 12:21 ` [PATCH v2 3/5] x86/mm: check exec permissions on fault Nadav Amit
2021-10-25 10:59 ` Peter Zijlstra
2021-10-25 11:13 ` Andrew Cooper
2021-10-25 14:23 ` Dave Hansen
2021-10-25 14:20 ` Dave Hansen
2021-10-25 16:19 ` Nadav Amit
2021-10-25 17:45 ` Dave Hansen
2021-10-25 17:51 ` Nadav Amit
2021-10-25 18:00 ` Dave Hansen
2021-10-21 12:21 ` [PATCH v2 4/5] mm/mprotect: use mmu_gather Nadav Amit
2021-10-21 12:21 ` [PATCH v2 5/5] mm/mprotect: do not flush on permission promotion Nadav Amit
2021-10-25 11:12 ` Peter Zijlstra
2021-10-25 16:27 ` Nadav Amit [this message]
2021-10-22 3:04 ` [PATCH v2 0/5] mm/mprotect: avoid unnecessary TLB flushes Andrew Morton
2021-10-22 21:58 ` Nadav Amit
2021-10-26 16:09 ` Dave Hansen
2021-10-25 10:50 ` Peter Zijlstra
2021-10-25 16:42 ` Nadav Amit
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=94412B55-0E16-4BC1-982F-37C082A0BABD@gmail.com \
--to=nadav.amit@gmail.com \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=dave.hansen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=luto@kernel.org \
--cc=npiggin@gmail.com \
--cc=peterx@redhat.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=will@kernel.org \
--cc=x86@kernel.org \
--cc=yuzhao@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox