From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A800C433EF for ; Mon, 25 Oct 2021 11:12:35 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9122360238 for ; Mon, 25 Oct 2021 11:12:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9122360238 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 2A34E940008; Mon, 25 Oct 2021 07:12:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2519E940007; Mon, 25 Oct 2021 07:12:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 140D5940008; Mon, 25 Oct 2021 07:12:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0247.hostedemail.com [216.40.44.247]) by kanga.kvack.org (Postfix) with ESMTP id 03F7A940007 for ; Mon, 25 Oct 2021 07:12:34 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id B7ABC1801E8CD for ; Mon, 25 Oct 2021 11:12:33 +0000 (UTC) X-FDA: 78734696586.17.AD913B3 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf02.hostedemail.com (Postfix) with ESMTP id 2A01B7001A24 for ; Mon, 25 Oct 2021 11:12:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=fWNxGT5LtHzA26MweR5leugLZdnvfvBUGjVtTUT0oqA=; b=JmO3/plrRLhiuyjpPJ1R/qg2up RAavhob5okv+8vNs79EfBR0iAkR8EvUaNfaeRXPMKijRHV2/FxTL4HhIInWqsYv61GD6Bw3lb4t5o 1NAbqU6iwRLcFREv//JAZPYsZ3CisfvORjZ2ryKk/kCPvnhyrFE54mnh+yPdGun7UkKYyWcsF/F+R 5Z1Q4FXp50qyVsCnAHovDJYi0l4/bN2BKnfHk20kMbSlAf3N5VtSJ23/X0xLGohQeG+EqQ+41R5Xn g9xKhO3H1PaxXVkEb8CnROrnKODaxo8EkfC9ELXZkRwvQcOE4Q/pronaCVZoFx5nztcloXylWZxmU kSVT7ZfA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mexu1-00C8IH-A3; Mon, 25 Oct 2021 11:12:29 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id CC66D300230; Mon, 25 Oct 2021 13:12:28 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id AE47320C6C147; Mon, 25 Oct 2021 13:12:28 +0200 (CEST) Date: Mon, 25 Oct 2021 13:12:28 +0200 From: Peter Zijlstra To: Nadav Amit Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Nadav Amit , Andrea Arcangeli , Andrew Morton , Andy Lutomirski , Dave Hansen , Peter Xu , Thomas Gleixner , Will Deacon , Yu Zhao , Nick Piggin , x86@kernel.org Subject: Re: [PATCH v2 5/5] mm/mprotect: do not flush on permission promotion Message-ID: References: <20211021122112.592634-1-namit@vmware.com> <20211021122112.592634-6-namit@vmware.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211021122112.592634-6-namit@vmware.com> X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 2A01B7001A24 X-Stat-Signature: hn5j1b9gpribsc4di8xoya9waoa7e9n7 Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b="JmO3/plr"; dmarc=none; spf=none (imf02.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.92.199) smtp.mailfrom=peterz@infradead.org X-HE-Tag: 1635160350-974411 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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; ? > 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?