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 ECAF2C04A95 for ; Tue, 25 Oct 2022 14:18:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5C2898E0002; Tue, 25 Oct 2022 10:18:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5735E8E0001; Tue, 25 Oct 2022 10:18:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 461F68E0002; Tue, 25 Oct 2022 10:18:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 36C788E0001 for ; Tue, 25 Oct 2022 10:18:58 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id CBE4F1A048D for ; Tue, 25 Oct 2022 14:18:57 +0000 (UTC) X-FDA: 80059678314.17.F6F5FA2 Received: from mail-io1-f47.google.com (mail-io1-f47.google.com [209.85.166.47]) by imf29.hostedemail.com (Postfix) with ESMTP id 75718120045 for ; Tue, 25 Oct 2022 14:18:57 +0000 (UTC) Received: by mail-io1-f47.google.com with SMTP id l127so10386104iof.12 for ; Tue, 25 Oct 2022 07:18:57 -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=tYduAKOaNAny9MQJ4fO8rjwMRKFCq+OYJTarNsbUmcc=; b=b9nMU8xuokJYf96EjprqccecIqVi4LtY3NFELQACDNkjVNyYV5P7dus7/1w2YDJwgK ffsiW3uQSUh69VSxmzuUBqiEKAqZ922NLo4YDQsIN5UVsgRKFvNffrkjhK1Y0lYXP84H jg9uBRwVgmb6fpFxQV7l1maCPUEy+bliJmEeRE7BJgrXGF9+sJwNsL8BKrafOFyXptA2 65j6ZKttleyPBv02B1gf7tuDyQQcBJsBqNWzQTr/WU2tEv2wHNTODsMQaujRGUhbb6DD X6spe92iE48FoTkqnAvohe4EBX7WyUeIl9CiG/5wmbV22hNWSJEK3Ddx7Bxhf5YiWGTC QRcA== 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=tYduAKOaNAny9MQJ4fO8rjwMRKFCq+OYJTarNsbUmcc=; b=n2N1ZIRgBL3VRFjOcjDHrCbfPA8fWpXM8AC7LejngeeK4ExPeppKtBe50TiYBxjwmZ 8tmO/UgrGBXYd9hFDBqgo6oloha2zGWIgCo8kXRpC4Ng4LXTG1kzTVb6A2W584gDNP1k ZoYso0HV2BUM/HH4s/7L7cIOAeAUDI9FsI5c0m/BByVT1dfmKayvDLXkyQ0hdk0phciC flWQjkgK9g+J8irhJ/Kq8R2myfZerxSyu+OfbCAA34/jeMVyMtBHoPkFpexWYKqNCgKx YPHvcfkY6yiqHAWtiHprosnPqimfQYjnWWMra7eeV6yVr2lCzpKhmO1y/LTGsoB44WEw W4LA== X-Gm-Message-State: ACrzQf0qPacFaNyJcpkuBZHoQakCtS7uAijTjwz28ROEsbt2ltUcqgmu P8VsUnjgqojlTAvT3+AriAAeEkxXTGdFRPckknDNBQ== X-Google-Smtp-Source: AMsMyM7kgc8WOeDtEkSpzZEDfe3c6j9gRL+T2Jhn7Z9EiLOLURzVvAcjowE4b4X9Dv6gjSpOsHeaOGc+YH0eodTP438= X-Received: by 2002:a6b:690b:0:b0:6bc:4d2a:e60a with SMTP id e11-20020a6b690b000000b006bc4d2ae60amr22450717ioc.56.1666707536652; Tue, 25 Oct 2022 07:18:56 -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: Tue, 25 Oct 2022 16:18:20 +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=1666707537; a=rsa-sha256; cv=none; b=k6QZ9ulhs05dRIEr9d9SO7mcKl49XJWaqZ48RVsVtyTwWFwxiVTIgabGvEqKCW7qfKWnwn ZyuKXVusfltduMdG70ezNU7COpwcBCxDXDwXshl/WiriXK/Vvn8IWJoZtAw/Fuh4RgyIvx UiqppuLp8oZiZ39sTFshNAmfJj5wxTc= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=b9nMU8xu; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf29.hostedemail.com: domain of jannh@google.com designates 209.85.166.47 as permitted sender) smtp.mailfrom=jannh@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666707537; 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=tYduAKOaNAny9MQJ4fO8rjwMRKFCq+OYJTarNsbUmcc=; b=FHSyodkA/Q5GB1f5WG7oJ0vcak2hOm2dNflJT26YXQOE0HUpm/S+HBIKA9tL1FjOhgQjWu OtRKL2yPGHuCo9uq6iY3dHftOwZub+DNFEkRePkn74FuC7rg2u+4OXaCWzoo0BxNpY670X rtgMM0I8cuzBslTqB3uxPVItbuHx3Tg= X-Rspamd-Queue-Id: 75718120045 Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=b9nMU8xu; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf29.hostedemail.com: domain of jannh@google.com designates 209.85.166.47 as permitted sender) smtp.mailfrom=jannh@google.com X-Rspamd-Server: rspam12 X-Rspam-User: X-Stat-Signature: 5ua9wo1aexdhzfjgr8kwrwnskzonp5s4 X-HE-Tag: 1666707537-350024 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 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. 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).