Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1273036rwi; Thu, 27 Oct 2022 13:36:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4NT/x2mK/ryljdXh7T1DcY20M3FZmzf+iPd0R3Is0paPho6PBNSRp0P1m+vJmNYDzLVRKs X-Received: by 2002:a63:4243:0:b0:439:2031:be87 with SMTP id p64-20020a634243000000b004392031be87mr43950846pga.592.1666902984428; Thu, 27 Oct 2022 13:36:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666902984; cv=none; d=google.com; s=arc-20160816; b=efSM5riDZiyyRgh0h1nhP9ZAyl8dddywjJwddYaTS4vuufrcafm+kWMQH1wToVR/QL 0j0uP4DwTDL6gj9U26XzSFR6CkPlLqRtVFfJq/un+ChdBgrCpXP4SbLsly55sLySX/ZZ fww6CAl3XTNCa1OUqSdAeSH8onw4wAvrre3cNRYYSoLhhsT0lMuuw0b4JrVXSBdnYatx +6WjjvdVi0aPMM1w0mArQnTVi6pyGk1y7FDkMw2yLB6DE9+KRErKD2yCOYjYlFoXTYpm DrYnYBcYS4Gwb3yUYdgHJLn2JQYZ494KjKzmCnF2/pFZXZJnaI50CXqC4ATX2C7zXwDi PiyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature; bh=A7LaqFW6corIRO3XUNY2tm6XyzywliIkqOeicYcLPwU=; b=yTLeKHY7JS3O6InjXiBu0QzK2kutMopj9LcW5ImdMyD04ao9ARGwEjz9bjSEObTqNK n7Ev0iHnb1PlWyZIdUQU4FO1ySkB+6WWR6cA2gfMjPL1Jg8TgQN+1F5Jr+8WhCjrj/Kx vsSRnnPOlKY2TDkuznXNGJE1hbRRmQdfsQoNS3lZ1Uhl9ncJ6bblZJMPKBleKuB0VXUy sNl8PzvArBEuSMJsjLbXHhvyT3/aXcXHuXdq6CcnVSFKQPf6W0Vk+RffmEPw/Fy0CWvF ITtCE2U9sFECwBr7ypwxb4r3ugTfiO5iYX2KBN4XJp5sw7QpkLmCbdyIufDAezphGiHV MQng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=EtGLqAsr; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id pv10-20020a17090b3c8a00b0020befc1a93asi2419628pjb.100.2022.10.27.13.36.12; Thu, 27 Oct 2022 13:36:24 -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=@gmail.com header.s=20210112 header.b=EtGLqAsr; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236081AbiJ0UPh (ORCPT + 99 others); Thu, 27 Oct 2022 16:15:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236007AbiJ0UPZ (ORCPT ); Thu, 27 Oct 2022 16:15:25 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACEBC58170 for ; Thu, 27 Oct 2022 13:15:24 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id b29so2751581pfp.13 for ; Thu, 27 Oct 2022 13:15:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=A7LaqFW6corIRO3XUNY2tm6XyzywliIkqOeicYcLPwU=; b=EtGLqAsrZBujejbp7Q++OuP58NpeNYIWlM3H+9eLJhYSS9IAXx5rtZGoA7RUdQY+Bs amndNceTD08Uql5/ps1yOAjVZA1MiHZlXVGAOZ5iTIpdwWnUrRbh5BmjM9At8WnMHqJM 6Bk8ghKciKOWW40SUonD2lnOWdW56oJUrOE3oEL0alwqa22h8gW/+qKWEv0flfLF9+hN m6MEsWhjPrDv5LpnCz8s2phwqGgkMtlM+DxdIXP5E9XWopvDKtxBZ2AZeRwnh5VJyktv AMFFUG884QlAoRm/uAVfRtjXHfQ5ZngonXWVDVMwmZC9Ez+F7Lu3WnxudT2o2WxI8U4w eqhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=A7LaqFW6corIRO3XUNY2tm6XyzywliIkqOeicYcLPwU=; b=3GSIedFDzTnU1BjWbXh928wxXkWPMEG1jCO5rq3VQ1knVbxKA6xJ7Ndkqlci0P2I1c Q3sSC/LcgS1ekgil5XEJUdV5hKoqjpzeufw2sfJh4PtiYeN5thn/oSO0Q1cLtqwXfiie +rEclSM3C4BppLEtc1xsAJ2pOkdoduomy+qLHvpojM3dloY4k0vyFhdk5O68t0L6EqSG /EwW9V/GiYFt2UsJYDO1xJRI2O4kESxnsW9xDhRrMaAqW9VHvu0Imbtn2Xi0sPQ+6+56 SMbZIzE6p8u7zCsrrFMeTEPjsNqN5txuUNZqHgIcrO5NR8mU2NMpcjXXTCxsUqlIYVPa szfQ== X-Gm-Message-State: ACrzQf2lKgKhGs63Zfdh5uAEcMCIABBCX0Jvq/mswEEFpdArQly9G/0X mE4sOgC4hR2AostZDw4tbyEOUH5hAWwceK0l X-Received: by 2002:a63:2253:0:b0:43c:c924:e56a with SMTP id t19-20020a632253000000b0043cc924e56amr42160495pgm.122.1666901723974; Thu, 27 Oct 2022 13:15:23 -0700 (PDT) Received: from smtpclient.apple ([66.170.99.95]) by smtp.gmail.com with ESMTPSA id x15-20020aa79a4f000000b0056bc67f9da8sm1547358pfj.63.2022.10.27.13.15.22 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Oct 2022 13:15:23 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Subject: Re: [PATCH 01/13] mm: Update ptep_get_lockless()s comment From: Nadav Amit In-Reply-To: Date: Thu, 27 Oct 2022 13:15:22 -0700 Cc: Peter Zijlstra , Jann Horn , John Hubbard , x86@kernel.org, willy@infradead.org, Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrea Arcangeli , kirill.shutemov@linux.intel.com, jroedel@suse.de, ubizjak@gmail.com Content-Transfer-Encoding: quoted-printable Message-Id: <6C548A9A-3AF3-4EC1-B1E5-47A7FFBEB761@gmail.com> References: <20221022111403.531902164@infradead.org> <20221022114424.515572025@infradead.org> <2c800ed1-d17a-def4-39e1-09281ee78d05@nvidia.com> To: Linus Torvalds X-Mailer: Apple Mail (2.3696.120.41.1.1) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 Oct 27, 2022, at 11:13 AM, Linus Torvalds = wrote: > Anybody willing to try to write up the rules (and have each rule > document *why* it's a rule - not just "by fiat", but an actual "these > are the rules and this is *why* they are the rules"). >=20 > Because right now I think all of our rules are almost entirely just > encoded in the code, with a couple of comments, and a few people who > just remember why we do what we do. I think it might be easier to come up with new rules instead of phrasing = the existing ones. The approach I suggested before [1] is something like: 1. Turn x86=E2=80=99s TLB-generation mechanism to be generic. Turn the TLB-generation into =E2=80=9Cpending TLB-generation=E2=80=9D. 2. For each mm track =E2=80=9Ccompleted TLB-generation=E2=80=9D, = whenever an actual flush takes place. 3. When you defer a TLB-flush, while holding the PTL: a. Increase the TLB-generation. b. Save the updated =E2=80=9Ctable generation" in a new field in the page-table=E2=80=99s page-struct. 4. When you are about to rely on a PTE value that is read from a = page-table, first check if a TLB flush is needed. The check is performed by = comparing the =E2=80=9Ctable generation=E2=80=9D with the =E2=80=9Ccompleted = generation=E2=80=9D. If the =E2=80=9Ctable generation=E2=80=9D is behind, a TLB flush is needed. [ You rely on the PTE value when you install new PTEs or change them = ] That=E2=80=99s about it. I might have not covered some issues with = fast-GUP. But in general I think it is a simple scheme. The thing I like about this = scheme the most is that it avoids relying on almost all the OS data-structures (e.g., PageAnon()), making it much easier to grasp. I can revive the patch-set if the overall approach is agreeable. [1] = https://lore.kernel.org/lkml/20210131001132.3368247-1-namit@vmware.com/=