Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp1776530ybg; Sat, 19 Oct 2019 02:16:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqwdSqVDVOqJZsHJF9Uu64n+LOHACkiQRAZH3e7VIadtpR9GCvIHE7Q0lVCz+CcySwCveb6E X-Received: by 2002:a05:6402:2028:: with SMTP id ay8mr14018930edb.273.1571476584267; Sat, 19 Oct 2019 02:16:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571476584; cv=none; d=google.com; s=arc-20160816; b=q0yoR4ds9oXO3dVGXb2O6X0tvf2zkCPQcjr3zlT38osJysrNT7mB/GUK/p5oO6wZhH yz/trf6nc/RTZoalDMolszFFSjX2IpD6JR/z1jQAT8SjQa/+nbAVLr005tpNbYL/jasy N4srGXdjgJqZ9Jlj3wpVifW3BqDzHdBnWtJAgAyTz0T0ELyOVE8EvNXiiirMsf5I2S63 SwqeGEjUF4oiyaG2EX5dWq9wS7iLjNkPyqnZ1ER5yaA3TcNzfKbc930NUIJwAqHNeDnX EerFwSXYptJE71+/FAV/UG0AMajncOz9Mli46uhpJKJQcImXR8bLrVnDpuWuVazMhNaE MY8A== 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:mime-version :message-id:to:from:cc:in-reply-to:subject:date:dkim-signature; bh=Js8UyXKzcNoEJJmDg2fB7ETZw1UXZrdaUdx46TnSzV4=; b=lzRxLnpLvPAzk3Csjjf92bodXXqI+QJhPtxOM5r6EJACY42DugCYZJzBzoQlGqDzcV pmzEbrrOsIThtjDH0D3YkvJz6FfIR4eVQGF40PHyq8q+JB2V7Liqc5K9C4wDDv7sboYa 0/wRu1iDfxueBtFwgV76c/W8AdZzvGEXmllZEgss7XpmznkK6CsxVYdwiGfN0JXSk9T+ 4npbxq4BiAheChuP1zzfeXHX0oITVKIuSVJD0gJ5V/pnAVBE6gKTPgwGaXVf1hhDC1Yq qvXzmD+x6GFgYEsDEGN6BwG59WJkZbvTNl1hSdeaMOoMpYGL/niDzbAoSB6saW+qpc5o DUOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=PmFQYioV; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id va9si4998405ejb.126.2019.10.19.02.16.00; Sat, 19 Oct 2019 02:16:24 -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=@sifive.com header.s=google header.b=PmFQYioV; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2502973AbfJRUiL (ORCPT + 99 others); Fri, 18 Oct 2019 16:38:11 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:38131 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731326AbfJRUiK (ORCPT ); Fri, 18 Oct 2019 16:38:10 -0400 Received: by mail-pl1-f195.google.com with SMTP id w8so3395957plq.5 for ; Fri, 18 Oct 2019 13:38:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=date:subject:in-reply-to:cc:from:to:message-id:mime-version :content-transfer-encoding; bh=Js8UyXKzcNoEJJmDg2fB7ETZw1UXZrdaUdx46TnSzV4=; b=PmFQYioVvRr2wRTUyHxpUOWHMVdu2thIjey8wW+t1W0rNA8gV8xD+qzVNMJgwsoJ+s 0vY1RJJoS5FGWiyKZ0yzgg4GvAK997c+qFIJ7rda8sls+g72uwDctwaE9TgXDCSGCNRB 673GKj5l/F5sgl/YxgqJD3cG2/ziJBAzhM7pJFcqjOlGlgykC+mTzeLDbc/ZsX63X4NR JvARjArPuTkFdVl7WNt3JU/En33mF6//9NP6rkGcJ6wsBWuPfYWYI2NQxniixZcLot4g a7vvRgCmgXXN77Sacj+NOQVObFJHbEaZIxAqegMjy8bGOiid9UwyAJuG3Rqb3PllEgJn RMRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:subject:in-reply-to:cc:from:to:message-id :mime-version:content-transfer-encoding; bh=Js8UyXKzcNoEJJmDg2fB7ETZw1UXZrdaUdx46TnSzV4=; b=AUD0ylbuVpjny6EVvLAVY2d6DFmCH34UVa8nak1zPn5QuX1FQb80FFFTwMEZVUUUMJ tGIt3cFl6YmNquni1jQcfQdYONGUPzmomCGRQyQR8P4VMw7LPaUkbWyFGIucc70zxWml gGPtJG4Ea4Q4afFY0gwULGBXAuS+B8Ee8C0I3YOBpSOQT4KuR++Vp6XtEZ7LQ4O4Gifm XhcMK/ZYT/s3EDFLbw/omiXUYHZwFWQVPYzEQ70pm6mpyuByWA9z1EJIgoLYAyv4YQuH sjsLrteuikhfOaJm/cp5v15XS3Ge/kW+8sVCZG+UIw0zDCnqhmEzR9WCXEDu3ZZOdOvx qErQ== X-Gm-Message-State: APjAAAUY9kYtXgiXF02ebJT9ztXRIc0af7TMyxkQRg1mnagI8JdLXqbI pVtaYQ2FpovfGSXJvhUNWYziPg== X-Received: by 2002:a17:902:fe04:: with SMTP id g4mr4203122plj.58.1571431089200; Fri, 18 Oct 2019 13:38:09 -0700 (PDT) Received: from localhost ([152.179.112.46]) by smtp.gmail.com with ESMTPSA id bb15sm6704697pjb.2.2019.10.18.13.38.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2019 13:38:08 -0700 (PDT) Date: Fri, 18 Oct 2019 13:38:08 -0700 (PDT) X-Google-Original-Date: Fri, 18 Oct 2019 13:36:06 PDT (-0700) Subject: Re: [PATCH v10 3/3] mm: fix double page fault on arm64 if PTE_AF is cleared In-Reply-To: <20191016234607.626nzv5kf5fgz25x@willie-the-truck> 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, hejianet@gmail.com, Kaly.Xin@arm.com, nd@arm.com From: Palmer Dabbelt To: will@kernel.org Message-ID: Mime-Version: 1.0 (MHng) 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 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! > Will