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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 973FCC38A2D for ; Wed, 26 Oct 2022 16:45:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A43648E0002; Wed, 26 Oct 2022 12:45:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9F3708E0001; Wed, 26 Oct 2022 12:45:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8BCE88E0002; Wed, 26 Oct 2022 12:45:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 7874D8E0001 for ; Wed, 26 Oct 2022 12:45:55 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 1B183141145 for ; Wed, 26 Oct 2022 16:45:55 +0000 (UTC) X-FDA: 80063677470.17.FF0A57C Received: from mail-io1-f50.google.com (mail-io1-f50.google.com [209.85.166.50]) by imf04.hostedemail.com (Postfix) with ESMTP id 7143740002 for ; Wed, 26 Oct 2022 16:45:53 +0000 (UTC) Received: by mail-io1-f50.google.com with SMTP id z3so1726784iof.3 for ; Wed, 26 Oct 2022 09:45:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=fxTHlIfpvK2/XOz3/tL/wS4RrUbx2mvunQ/ZFXzMWeQ=; b=WT+esLeg58MgeuQ+1rmpS52RKHc5+4Args2zNgvxdjA0+krh/MK3yUijxvyu6gkQXE vWSlt76ZWSYNm/M2CYc075MKBRC/d0nRnGK3XsmuJKy+CQFPtJ7OFAk576MrZwKFLgKl IYri2G8+xpHd+RgZilll4KLD6r2u16OWjVzm5TE4Adyw3bQMFHQ2hBFPvW66z1r9WWSM SWX4Tig38kHiPWZuIIiNm6zhirvDtVQLQi3ElVsi0qK36h8T5EPR/BUuhvbD5bmAsWh1 CJ90qsFb08pjPdxpHIKWAP0mF11M2uXMWv44EgU9uaWv26am7egYWSvs+JF/jDJNxugI Gjig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=fxTHlIfpvK2/XOz3/tL/wS4RrUbx2mvunQ/ZFXzMWeQ=; b=ZvWE1IYv/vIu85wpbYHan/Egqhwtk8OYvHBYk253xGGSv4uXE/drBHtpZkIBTosvml PzC0fnXPfQD0fXv9mdma9cBV9mNNadED/rtfnq/H3FkBnfZASFH8lj9X+5O7qUdnTx85 eFkysmIBrklQ7wMWJCo+TINAvJmoeUCpRUQqCXY2OLat4BA29jvLmaPe4k/MosE/ktYZ wLbUn1ae2ER9urPUCsR1m7o/6xJp9EB6VEg/xP0qxaqm/ne5Vlw6mSBERy8pUzuPQrmF Qz38fSz9M+z6MDXaXmO/lXEL0ITZLlC8i35m5GorYFES/CVbBWXTHj4t3zqke8vvDMBm EEUQ== X-Gm-Message-State: ACrzQf1ig8xQ+H6eH1+ls/R/mDx2wSdcl/cbHxKGHZ1dhLNZ1Cjv++8v C++Ld5SAG/MJU0671sY8OeIYZhruTcMNHj0qA7hbUA== X-Google-Smtp-Source: AMsMyM7gFelwmQ3nX67YX6RCo4WlbOCwBT9+vJfELkygPZtXcuQ7UzJe7QJqQ9/cl5mZZ+hZtMjqWTSFGSI3Y/Lx8tg= X-Received: by 2002:a05:6602:1588:b0:6bc:d49a:61cc with SMTP id e8-20020a056602158800b006bcd49a61ccmr26832467iow.154.1666802752567; Wed, 26 Oct 2022 09:45:52 -0700 (PDT) MIME-Version: 1.0 References: <20221022111403.531902164@infradead.org> <20221022114424.515572025@infradead.org> <2c800ed1-d17a-def4-39e1-09281ee78d05@nvidia.com> In-Reply-To: From: Jann Horn Date: Wed, 26 Oct 2022 18:45:16 +0200 Message-ID: Subject: Re: [PATCH 01/13] mm: Update ptep_get_lockless()s comment To: Peter Zijlstra Cc: John Hubbard , x86@kernel.org, willy@infradead.org, torvalds@linux-foundation.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, aarcange@redhat.com, kirill.shutemov@linux.intel.com, jroedel@suse.de, ubizjak@gmail.com Content-Type: text/plain; charset="UTF-8" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666802753; a=rsa-sha256; cv=none; b=ya9T98Ehyov/X2GsKoxd+CiIkDIauMjVcHZJxk+gzQy2VprjSLvOgY+etAYsLUm2U2m9QB rzvQ04kDRTLqTPxxviVpyp8SKVbMx93098nRrTAhnSHQVrE56L1uqbD/fEJljOVGX33TNm +5T2eHiYe2XM937mIEAxZenfouCtu3k= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=WT+esLeg; spf=pass (imf04.hostedemail.com: domain of jannh@google.com designates 209.85.166.50 as permitted sender) smtp.mailfrom=jannh@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666802753; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=fxTHlIfpvK2/XOz3/tL/wS4RrUbx2mvunQ/ZFXzMWeQ=; b=fN/uHXRune7bhjt0rdZs8DK5AhIFtCBxFCtwOTWKgHhJMsGuWbFSPvR9ClJpmw2Qlg78eZ xlQhFUdgqUBmqMqf5CZ0B2/NYPWCQDsN1k62/cUGo6CmiC/u/A66kcg2sqUNxoebo2WUXc yw0lghBfPVy7xXVotGKPwUxraNFivys= X-Rspam-User: X-Rspamd-Queue-Id: 7143740002 Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=WT+esLeg; spf=pass (imf04.hostedemail.com: domain of jannh@google.com designates 209.85.166.50 as permitted sender) smtp.mailfrom=jannh@google.com; dmarc=pass (policy=reject) header.from=google.com X-Stat-Signature: xdzp6xc5o1oc17gwxwd3pubz65pc8a9w X-Rspamd-Server: rspam03 X-HE-Tag: 1666802753-506874 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 Tue, Oct 25, 2022 at 5:06 PM Peter Zijlstra wrote: > On Tue, Oct 25, 2022 at 04:18:20PM +0200, Jann Horn wrote: > > On Tue, Oct 25, 2022 at 4:02 PM Peter Zijlstra wrote: > > > On Mon, Oct 24, 2022 at 09:58:07PM +0200, Jann Horn wrote: > > > > > > > Unless I'm completely misunderstanding what's going on here, the whole > > > > "remove_table" thing only happens when you "remove a table", meaning > > > > you free an entire *pagetable*. Just zapping PTEs doesn't trigger that > > > > logic. > > > > > > Aah; yes true. OTOH even it that were not so, I think it would still be > > > broken because the current code relies on the TLB flush to have > > > completed, whereas the RCU scheme is effectively async and can be > > > considered pending until the callback runs. > > > > > > Hurmph... easiest fix is probably to dis-allow kvm_flush_tlb_multi() > > > for i386-pae builds. > > > > > > Something like so... nobody in his right mind should care about i386-pae > > > virt performance much. > > > > I think Xen and HyperV have similar codepaths. > > hyperv_flush_tlb_multi() looks like it uses remote flush hypercalls, > > xen_flush_tlb_multi() too. > > Sure (not updated). > > > On top of that, I think that theoretically, Linux doesn't even ensure > > that you have a TLB flush in between tearing down one PTE and > > installing another PTE (see > > https://lore.kernel.org/all/CAG48ez1Oz4tT-N2Y=Zs6jumu=zOp7SQRZ=V2c+b5bT9P4retJA@mail.gmail.com/), > > but I haven't tested that, and if it is true, I'm also not entirely > > sure if it's correct (in the sense that it only creates incoherent-TLB > > states when userspace is doing something stupid like racing > > MADV_DONTNEED and page faults on the same region). > > > > I think the more clearly correct fix would be to get rid of the split > > loads and use CMPXCHG16B instead (probably destroying the performance > > of GUP-fast completely), but that's complicated because some of the > > architectures that use the split loads path don't have cmpxchg_double > > (or at least don't have it wired up). > > cmpxchg8b; but no, I think we want to fix MADV_DONTNEED, incoherent TLB > states are a pain nobody needs. > > Something like so should force TLB flushes before dropping pte_lock (not > looked at the various pmd level things yet). [...] > #endif /* _LINUX_MM_H */ > diff --git a/mm/memory.c b/mm/memory.c > index f88c351aecd4..9bb63b3fbee1 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -1440,6 +1440,11 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, > tlb_remove_tlb_entry(tlb, pte, addr); > zap_install_uffd_wp_if_needed(vma, addr, pte, details, > ptent); > + > + if (!force_flush && !tlb->fullmm && details && > + details->zap_flags & ZAP_FLAG_FORCE_FLUSH) > + force_flush = 1; > + Hmm... I guess that might work, assuming that there is no other codepath we might race with that first turns the present PTE into a non-present PTE but keeps the flush queued for later. At least codepaths that use the tlb_batched infrastructure are unproblematic...