Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp101950pxb; Mon, 25 Oct 2021 04:46:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx/ytD3dqpyY87DF/pi7dMgQOaxzCWqVJUf/GchidCMU/ehBmYjphRuoLlrAdAVMQmOvomz X-Received: by 2002:a17:906:5d11:: with SMTP id g17mr5330490ejt.175.1635162376559; Mon, 25 Oct 2021 04:46:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635162376; cv=none; d=google.com; s=arc-20160816; b=lU47qZlQIi1oo9muYPWEKTyqzL7x8bw2JU3h+wtnQBNGlv7A8VB0gcucHvg9iBnmWi t3ybYjYDSJc6MEHct28E23e56OMLa+Lz6riH4EkiG+jcCxF0PvN6d95ZvpuXwxfgRkkE z/juVSpWHbt8jQd2N7HHp1JtRKvdo256DIX6+BEcQV79lmefvSnWJqTugZbbMVHT6/jm upiWJr4E+VQsjb7+4OwSHsagxhqeaEea5V5A0g2kNl4CuB/4dIrIN+cXoTrR9DcmYlfT sSzrstCdQTiNlvVMnu3BV0pUu1x5tcxt6S/bh9+Yh5dW0xer9ZbMzDCLxpD40mtaOlD8 URCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=fWNxGT5LtHzA26MweR5leugLZdnvfvBUGjVtTUT0oqA=; b=aT46Pxpxflv5chWxzaGSEfdLl8mGzLir49l6FSKtP4an/QXPrZ9xD0P1GL1MAW8s1L zGkhaIB7IiKEyZF3iR/BTVNBPNjF8p5MgHBIuDwVVjrFFDJrrH8x269Q361SDX3giYSO QkAJgQJUqSFjBUIph630xurf8dXBOXq7s6RX8jzidNHnueobVsxNbq6xBc7iH1q6My1U GSjObkuC2hmNhnyJMPs4IiH5/CS2Hg7K4lYyKudHVqoPU+PacaEg+kupIwwJ3wNAdqyq rLG/uQmIt6prgeSwKfdSW/85yhTrQnGOixIijqTp3qZ1zGQVVfJzMqbHJ6qyL2vX44OX t/tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b="JmO3/plr"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b15si27858758ede.144.2021.10.25.04.45.13; Mon, 25 Oct 2021 04:46:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b="JmO3/plr"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231358AbhJYLPC (ORCPT + 99 others); Mon, 25 Oct 2021 07:15:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233016AbhJYLO7 (ORCPT ); Mon, 25 Oct 2021 07:14:59 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0450AC061767 for ; Mon, 25 Oct 2021 04:12:38 -0700 (PDT) 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> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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?