Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp292076rwi; Thu, 27 Oct 2022 01:00:29 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5XxGoFZmETYSTORv9yTs/G7S5l2w3Ee067jN9qYOpk4ODBITVUuU8e3q+jMr/EiAll6yAg X-Received: by 2002:a05:6402:2706:b0:461:b93c:cbd8 with SMTP id y6-20020a056402270600b00461b93ccbd8mr19928086edd.254.1666857628366; Thu, 27 Oct 2022 01:00:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666857628; cv=none; d=google.com; s=arc-20160816; b=m6N0hnbZEgdeC8WSnl+ghpIU68NM7SAx4Xlfsf35XEferWTuISG3948kVyJ3hIJ2+L X8w1gPUzwjQjARw4x2eoJ4zFS55vxnak10JP0A5Vz/V2XnV5E3itJxKfwG+hDh5DBv6s L+khYf5o0ztkFVtYJ25zv16U8qX53RMdi4oL0fI2K8lCAvSEsXjoCns/bKasIq4+4LtS BmXMjgYQygikVhsj4CtRppCtve1KQ1dWqjyg4S5udAz/QYoWNLiS/imsL41Vc16Ick49 dcaIPmctRr3NHvuUYgyWugZyZ9a0v0OLidOXCPtFb/6pRl8tu/AFsZR1CRQw8N+abPT9 c5QQ== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=jIdXoveHpdJhxsDFwLhwCoDvMUr3LOjoTAAeFN1VZDQ=; b=FnZlGS8bDODaSL87B/vGkXD/KuwNDfDqdRpVnqFy8qIcQBgjAr1znQzDwwu+zSZggl OTXVNfc57Ic/UZOjFuAcqW+BzS0rJf6sb3yZNEhfEgj9D9VTpi4sD2aTj8NDYMXa7AJo frE38aiHLkCG70EsG6FWe0WynIl9CXnmt6JmykYsYOhpLKuGxMxJmW+xLYUDpWoUf9Zk Ahn2EqQSWudVN+ZTmnOQrr/BXh4PeSY688AAtjqtxtpbEI6pxe9aDf0E2d7Lm+vC+FrZ eq5EHIoRMbyvmq1dRbgZaPqyMXLhhbBP1uwGl7+UJnGxYCoj3z9l0uuKiN+8r7GQWMEM RMiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=g65dTzP5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nd33-20020a17090762a100b0078dc7f7d0ebsi984738ejc.822.2022.10.27.01.00.01; Thu, 27 Oct 2022 01:00:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=g65dTzP5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234220AbiJ0H2A (ORCPT + 99 others); Thu, 27 Oct 2022 03:28:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229938AbiJ0H17 (ORCPT ); Thu, 27 Oct 2022 03:27:59 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0A76AA341 for ; Thu, 27 Oct 2022 00:27:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=jIdXoveHpdJhxsDFwLhwCoDvMUr3LOjoTAAeFN1VZDQ=; b=g65dTzP5bb0fhavL07nyRH67sL JxPUwHx33jCezjgWMyZ/zIRcKV747ZUDgHTkXrrstMI3mR4lR+UnZ52hRh6EIX6CPKUMlEzYtEcZf ENNDp2T908EBfh0CapbhhRzQAaRii980WW83/tj0rno7AGTb6mAHOtI8dlestPf5eTzLYVIhq6zlS 3/OSWHsnT0BcatXfMGrcBq/n/r6KUuFxE4Zk+T5RYoYPQx40ydg7WLYbUC8F/Ks6NSt30Pv0ulsXM YZPImpEsJerxzOqjdaLjzzxyelWx+ZyGdUJZD/MnGPuLDZdYQ+qQFYZ2DyTXZmzW7/8zWVax3OyNo CZ+tbLOg==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1onxIs-0000zr-3v; Thu, 27 Oct 2022 07:27:50 +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 (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id E350730029C; Thu, 27 Oct 2022 09:27:43 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id C96D22012B90F; Thu, 27 Oct 2022 09:27:43 +0200 (CEST) Date: Thu, 27 Oct 2022 09:27:43 +0200 From: Peter Zijlstra To: Nadav Amit Cc: Jann Horn , John Hubbard , X86 ML , Matthew Wilcox , Linus Torvalds , Andrew Morton , kernel list , Linux-MM , Andrea Arcangeli , "Kirill A . Shutemov" , jroedel@suse.de, ubizjak@gmail.com Subject: Re: [PATCH 01/13] mm: Update ptep_get_lockless()s comment Message-ID: References: <20221022111403.531902164@infradead.org> <20221022114424.515572025@infradead.org> <2c800ed1-d17a-def4-39e1-09281ee78d05@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 26, 2022 at 10:43:21PM +0300, Nadav Amit wrote: > On Oct 25, 2022, at 6:06 PM, Peter Zijlstra wrote: > > > if (!force_flush && !tlb->fullmm && details && > > + details->zap_flags & ZAP_FLAG_FORCE_FLUSH) > > + force_flush = 1; > > Isn’t it too big of a hammer? It is the obvious hammer :-) TLB invalidate under pte_lock when clearing. > At the same time, the whole reasoning about TLB flushes is not getting any > simpler. We had cases in which MADV_DONTNEED and another concurrent > operation that effectively zapped PTEs (e.g., another MADV_DONTNEED) caused > the zap_pte_range() to skip entries since pte_none() was true. To resolve > these cases we relied on tlb_finish_mmu() to flush the range when needed > (i.e., flush the whole range when mm_tlb_flush_nested()). Yeah, whoever thought that allowing concurrency there was a great idea :/ And I must admit to hating the pending thing with a passion. And that mm_tlb_flush_nested() thing in tlb_finish_mmu() is a giant hack at the best of times. Also; I feel it's part of the problem here; it violates the basic rules we've had for a very long time. > Now, I do not have a specific broken scenario in mind following this change, > but it is all sounds to me a bit dangerous and at same time can potentially > introduce new overheads. I'll take correctness over being fast. As you say, this whole TLB thing is getting out of hand. > One alternative may be using mm_tlb_flush_pending() when setting a new PTE > to check for pending flushes and flushing the TLB if that is the case. This > is somewhat similar to what ptep_clear_flush() does. Anyhow, I guess this > might induce some overheads. As noted before, it is possible to track > pending TLB flushes in VMA/page-table granularity, with different tradeoffs > of overheads. Right; I just don't believe in VMAs for this, they're *waaay* to big.