Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4435907pxu; Wed, 9 Dec 2020 17:47:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJwoLbNp9S1W0EFBA0/yQqM7Eh+v9k+NWK7t6eIDEVqnYTxZtaiUvlvHQdnKS8PmgOloFFcp X-Received: by 2002:a50:ee1a:: with SMTP id g26mr4655162eds.68.1607564845203; Wed, 09 Dec 2020 17:47:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607564845; cv=none; d=google.com; s=arc-20160816; b=Riz8Dh1QEKZocR/tUXXqTiiLjp/rPGKttvd/DOXY7HoV2hsB0JxdGk5Ac213vekfpp v83T9ceLR9rmOabCvq8zyz2pySo0o60DzIWd6p1H45UKet5B04FrECnciOFdQyhg5FWy 9F2hGhxWCmBR9vjktCdg3UM8mLO41pt4B63MplxVUUSFw00gknhPoCzd45lwdETltuFj UeRcXpjqMDP1DTWDLSOkidFbz5nhfxDI5FOtEV9jWtFdYnx5mdyS0V2JV0ZXn2t97nVE aN14i2iVut+utXFD1pMnH3Zkjecki1FVO0MCeSMOWZOjMEAgA7Skqt2c4yPVbmo4U6eF PE7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=uJaVhTpiMPaliRW1BsTVPR0HUZ5LPD9/lyKWp6voxZY=; b=EAf7WbsuMihbaVPflALJPAJz9G96QFQ/R7t352BzM0FsF7TVSjJScrQHw48rOOEuHZ JxpMSiH8qsuLkNzy7D2ePcW4ERxGaVN9iVe8lmSHsw7UXFC+6GBJDnt/cqX7FuDE/jrt /gvPTgz9+iu5gE/+z8saNIJ1RnnzlsUl7EIp+y6PcP/t51OzgucO4FdhWsNA2GCgLVkD CiiMyTIab3AFIxj9ZHeBGlCMghtwwlPn7k62PN0ICQ/VNTacq5QMHztMGThrDlYlztyX BSqoe7s0wNdx4cZTO/IseDHkyxtg/50c4UbPcbXzquNj2OfjM9/t6eAFg9H7/mV0+P9b vOfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=W3TAZiMx; 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 h17si1670652ejg.46.2020.12.09.17.47.01; Wed, 09 Dec 2020 17:47:25 -0800 (PST) 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=@linux-foundation.org header.s=google header.b=W3TAZiMx; 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 S1730626AbgLIR7T (ORCPT + 99 others); Wed, 9 Dec 2020 12:59:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727905AbgLIR7M (ORCPT ); Wed, 9 Dec 2020 12:59:12 -0500 Received: from mail-lf1-x141.google.com (mail-lf1-x141.google.com [IPv6:2a00:1450:4864:20::141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 780E6C0613D6 for ; Wed, 9 Dec 2020 09:58:32 -0800 (PST) Received: by mail-lf1-x141.google.com with SMTP id l11so4356453lfg.0 for ; Wed, 09 Dec 2020 09:58:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=uJaVhTpiMPaliRW1BsTVPR0HUZ5LPD9/lyKWp6voxZY=; b=W3TAZiMxgQtdmGJSBJFklYY9V2kwPDqdPrz6VB+jV0dmuZj2xY806aorny+f833fr0 b8e17lxLA8lqeWSjVicsm8ZauNAfVbS1JSChtiKvqoRliqknYvhRrkhxg/15OsDnB8Ae F7O6VFdwmN7mFS6k9yL922iGj3GMtLKU5aDW0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=uJaVhTpiMPaliRW1BsTVPR0HUZ5LPD9/lyKWp6voxZY=; b=MruqyttjjlYhAW/oiQ3qO8nTHBnpEIXaHbcMlOCSsrTyn2NHQxBVQ00XVJc96PUNox girE5mnLhi4fsdJH3fGqcNo8yHRp8oyv1z2Jj+Ce4WiGLzM57zaxmIYUBlp8OldCBH5p oMdEaLrQOmigREW+jGoggER1iX+tgDHXIS3Z5ba1PWy+E+1YLl29YrTHBZuUk5crjla0 EWVA5j6GZvKfe0+6Pbhm6CMk3UaYycBgOteV2RCb/Nt7nB24iJcS7j5NFWMa4jZould/ +EqRTyeRHiN0NqIXitbPEfFkpCBIe2Dui161fDX3JtYYKUNWbrWnRHg4ORNFCnoNT3XN gIHg== X-Gm-Message-State: AOAM533+QU+IIf9akZoguPM65QCN3h+/GTCyBw6BOLwynMI26B5vNhza 1kCuZZDJ6Afuf/OydPwN4bG8sdu834asvg== X-Received: by 2002:ac2:50d0:: with SMTP id h16mr1297886lfm.300.1607536710496; Wed, 09 Dec 2020 09:58:30 -0800 (PST) Received: from mail-lj1-f170.google.com (mail-lj1-f170.google.com. [209.85.208.170]) by smtp.gmail.com with ESMTPSA id w204sm242736lff.241.2020.12.09.09.58.29 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 09 Dec 2020 09:58:29 -0800 (PST) Received: by mail-lj1-f170.google.com with SMTP id y16so3473163ljk.1 for ; Wed, 09 Dec 2020 09:58:29 -0800 (PST) X-Received: by 2002:a2e:5750:: with SMTP id r16mr1446782ljd.61.1607536708800; Wed, 09 Dec 2020 09:58:28 -0800 (PST) MIME-Version: 1.0 References: <20201209163950.8494-1-will@kernel.org> <20201209163950.8494-2-will@kernel.org> In-Reply-To: <20201209163950.8494-2-will@kernel.org> From: Linus Torvalds Date: Wed, 9 Dec 2020 09:58:12 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/2] mm: Allow architectures to request 'old' entries when prefaulting To: Will Deacon Cc: Linux Kernel Mailing List , Linux-MM , Linux ARM , Catalin Marinas , Jan Kara , Minchan Kim , Andrew Morton , "Kirill A . Shutemov" , Vinayak Menon , Android Kernel Team Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Dec 9, 2020 at 8:40 AM Will Deacon wrote: > > @@ -3978,8 +3994,17 @@ static vm_fault_t do_fault_around(struct vm_fault *vmf) > > /* check if the page fault is solved */ > vmf->pte -= (vmf->address >> PAGE_SHIFT) - (address >> PAGE_SHIFT); > - if (!pte_none(*vmf->pte)) > - ret = VM_FAULT_NOPAGE; > + if (pte_none(*vmf->pte)) > + goto out_unlock; > + > + if (vmf->flags & FAULT_FLAG_PREFAULT_OLD) { > + pte_t pte = pte_mkyoung(*vmf->pte); > + if (ptep_set_access_flags(vmf->vma, address, vmf->pte, pte, 0)) > + update_mmu_cache(vmf->vma, address, vmf->pte); > + } Oh, please dear God no. First you incorrectly set it old, and then you conditionally make it young again and as a result force an atomic rwm update and another TLB flush for no good reason. Just make sure that the FAULT_FLAG_PREFAULT_OLD never sets the *actual* address to old. And yes, that probably means that you need to change "alloc_set_pte()" to actually pass in the real address, and leave "vmf->address" alone - so that it can know which ones are prefaulted and which one is real, but that sounds like a good idea anyway. Then you can just make alloc_set_pte() do the right thing in the first place, instead of doing this nasty "lets do it wrong and fix it up later" horror. Linus