Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp1804169ybg; Sat, 19 Oct 2019 02:52:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqzn3o8lpUdhf0octLObZyu9gYU0hPOj2QVErEbf12bPBmch7zu5ekfEoXqx/acfDCO015Ct X-Received: by 2002:a05:6402:751:: with SMTP id p17mr14307818edy.161.1571478755134; Sat, 19 Oct 2019 02:52:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571478755; cv=none; d=google.com; s=arc-20160816; b=b/Bgu8OHxTK3rYKbki++bkV49aw7qAgefRoZt3xRjPh8N3qpZRHc9li97rchYSlNJc 0/d6KkAO8lPkLNUDebtnUTTuA5U39u3rgplek618jhnDOnNZfIYbeipVFZKD68k7JW6a Wr9Thuy5fbGBrXbgmSForxfM4TDloG9nrM+zkGwEUady9XNg17FgXvANHNCfHLDLYzXI eiKz2QzQvNFZ9KS3HMj8TMdAHiXnjZRhtOH8Slntf/I4ZNw0JGoKJ3izaWzU6FilILvT mDASJ2PDaoK7E9kDiGWyFg5I8THkoQRIqiepFcn+gh2rE082AlkzuYgZbUqhXmki7Thu iYHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject:dkim-signature; bh=2+uRH+ZKfyt86cxDF8FPbZk+BAT5hdpRwMdmmfN7ogM=; b=feu0PV3s/FPUErz07/BvivWfP1YTRZC1MTpqpdZZGkU2Nlllwguwm32B9mIUCf/pxg utmM2qWqDtHuEVushp3gxCKkGgcbdm76oL7sRhr0zDOv6Gi1CFc96YVfsgAphn7V5HnI DV8Qo55ZYNmWZ9qNn7CFayV9xSRy7jNPumdCNxuiOc6me/6kCfhIPshrsJ+lgU6TpmNN 85hdZxmK1VKBJpDnw9ApHZLEjFkGTrbxFrZeBKDlM2ihPXVokfasK1NUAhxFX7Kq1feB NwxHX1PAPl6k16Fx3hLTrAqxMkBipVxy82MS+MZyeC7j0O7wCkJz6OCijgXOIYALZZCG 20FA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=I1HV2wIY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e21si5953053edb.164.2019.10.19.02.52.11; Sat, 19 Oct 2019 02:52:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=I1HV2wIY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1727140AbfJSC7n (ORCPT + 99 others); Fri, 18 Oct 2019 22:59:43 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:38338 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726924AbfJSC7m (ORCPT ); Fri, 18 Oct 2019 22:59:42 -0400 Received: by mail-pg1-f193.google.com with SMTP id w3so4355353pgt.5 for ; Fri, 18 Oct 2019 19:59:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=2+uRH+ZKfyt86cxDF8FPbZk+BAT5hdpRwMdmmfN7ogM=; b=I1HV2wIYlB/eRmfzqyirQiy5WOxMTDsX6O64/uCAnuoS5yCXBnyTNJe3QDZ7DlNCyT RzG/6iJSDKWZip6da9We9PVBS86OX602nr0C8kjWoKGAAylamEerSrFVg8kHVF7lMXwA 2Duum+VhYbpqCx2DWQeERJBqSFPNtIyU3cM/s2m9Bz+Bzi8QE2kpXQTftSeXOeJdH3Tj YrZ/FzLZCdLeoEkKnF92uJE7SXSQzCukP0CX0meQk5Z7QwhYrU3kKUXCOvNp+aMLYVBj VOz8+nQpKhd2gYCcjghdM1Le5t26IZH7s8yqaVi39yesYZGgBI1Z/TB2wTY7j90tbF7C xorA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=2+uRH+ZKfyt86cxDF8FPbZk+BAT5hdpRwMdmmfN7ogM=; b=BlNBP75Lo8jNVHCu/N29ILkIwhg5WHiXohzVjigHhFvLGgbx5QJfSp6UmT7trtPBqz sywFZ5mLAlkPFj82wbqBHuLEAhiw9edJg+rzXh1wFJ5rFQW5ZID3LljeuLP1ZGxX75Bb evd6jjfWmvKoAX2jYQuStqIUz/bArRxJfugnjBWuLctODu/uFNVMex7ZCyn/yMyM+iZW sWF+jkjqBmo1tE6QvVTUYAgac5pByeTMwFVSHcffeAjYTxUNzzvWYPsSYmtMxzJf7GcF V9m+J2Z1+PjEE8omnKc59B/VirSZCpIt9Pfhsw7FosbcNdkJSl692h+r/eGVyUynJhgw /EIw== X-Gm-Message-State: APjAAAVbYDi4WhmgsRW8/hrcZ0k1IBeApg+VlkEzhafZ8WIs0hFDWyZE NSR8bkWHR6n5F+RPt00Fas4= X-Received: by 2002:a17:90a:17c4:: with SMTP id q62mr14310962pja.83.1571453980149; Fri, 18 Oct 2019 19:59:40 -0700 (PDT) Received: from [0.0.0.0] (104.129.187.94.16clouds.com. [104.129.187.94]) by smtp.gmail.com with ESMTPSA id q30sm7759691pja.18.2019.10.18.19.59.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Oct 2019 19:59:39 -0700 (PDT) Subject: Re: [PATCH v10 3/3] mm: fix double page fault on arm64 if PTE_AF is cleared To: Palmer Dabbelt , will@kernel.org Cc: Justin.He@arm.com, Catalin.Marinas@arm.com, Mark.Rutland@arm.com, James.Morse@arm.com, maz@kernel.org, willy@infradead.org, kirill.shutemov@linux.intel.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, punitagrawal@gmail.com, tglx@linutronix.de, akpm@linux-foundation.org, Kaly.Xin@arm.com, nd@arm.com References: From: Jia He Message-ID: Date: Sat, 19 Oct 2019 10:59:22 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Palmer On 2019/10/19 4:38, Palmer Dabbelt wrote: > On Wed, 16 Oct 2019 16:46:08 PDT (-0700), will@kernel.org wrote: >> Hey Palmer, >> >> On Wed, Oct 16, 2019 at 04:21:59PM -0700, Palmer Dabbelt wrote: >>> On Tue, 08 Oct 2019 05:39:44 PDT (-0700), will@kernel.org wrote: >>> > On Tue, Oct 08, 2019 at 02:19:05AM +0000, Justin He (Arm Technology >>> China) wrote: >>> > > > On Mon, Sep 30, 2019 at 09:57:40AM +0800, Jia He wrote: >>> > > > > diff --git a/mm/memory.c b/mm/memory.c >>> > > > > index b1ca51a079f2..1f56b0118ef5 100644 >>> > > > > --- a/mm/memory.c >>> > > > > +++ b/mm/memory.c >>> > > > > @@ -118,6 +118,13 @@ int randomize_va_space __read_mostly = >>> > > > >                      2; >>> > > > >  #endif >>> > > > > >>> > > > > +#ifndef arch_faults_on_old_pte >>> > > > > +static inline bool arch_faults_on_old_pte(void) >>> > > > > +{ >>> > > > > +    return false; >>> > > > > +} >>> > > > > +#endif >>> > > > >>> > > > Kirill has acked this, so I'm happy to take the patch as-is, however >>> isn't >>> > > > it the case that /most/ architectures will want to return true for >>> > > > arch_faults_on_old_pte()? In which case, wouldn't it make more sense for >>> > > > that to be the default, and have x86 and arm64 provide an override? For >>> > > > example, aren't most architectures still going to hit the double fault >>> > > > scenario even with your patch applied? >>> > > >>> > > No, after applying my patch series, only those architectures which >>> don't provide >>> > > setting access flag by hardware AND don't implement their >>> arch_faults_on_old_pte >>> > > will hit the double page fault. >>> > > >>> > > The meaning of true for arch_faults_on_old_pte() is "this arch doesn't >>> have the hardware >>> > > setting access flag way, it might cause page fault on an old pte" >>> > > I don't want to change other architectures' default behavior here. So >>> by default, >>> > > arch_faults_on_old_pte() is false. >>> > >>> > ...and my complaint is that this is the majority of supported architectures, >>> > so you're fixing something for arm64 which also affects arm, powerpc, >>> > alpha, mips, riscv, ... >>> > >>> > Chances are, they won't even realise they need to implement >>> > arch_faults_on_old_pte() until somebody runs into the double fault and >>> > wastes lots of time debugging it before they spot your patch. >>> >>> If I understand the semantics correctly, we should have this set to true.  I >>> don't have any context here, but we've got >>> >>>                /* >>>                 * The kernel assumes that TLBs don't cache invalid >>>                 * entries, but in RISC-V, SFENCE.VMA specifies an >>>                 * ordering constraint, not a cache flush; it is >>>                 * necessary even after writing invalid entries. >>>                 */ >>>                local_flush_tlb_page(addr); >>> >>> in do_page_fault(). >> >> Ok, although I think this is really about whether or not your hardware can >> make a pte young when accessed, or whether you take a fault and do it >> by updating the pte explicitly. >> >> v12 of the patches did change the default, so you should be "safe" with >> those either way: >> >> http://lists.infradead.org/pipermail/linux-arm-kernel/2019-October/686030.html > > OK, that fence is because we allow invalid translations to be cached, which > is a completely different issue. > > RISC-V implementations are allowed to have software managed accessed/dirty > bits.  For some reason I thought we were relying on the firmware to handle > this, but I can't actually find the code so I might be crazy.  Wherever it's > done, there's no spec enforcing it so we should leave this true on RISC-V. > Thanks for the confirmation. So we can keep the default arch_faults_on_old_pte (return true) on RISC-V. Thanks. --- Cheers, Justin (Jia He)