Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp8319816ybn; Tue, 1 Oct 2019 06:33:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqyqo7CGkgAda9onaEZgiXjy6zmGAjcpwxMRkDnbaEYp8w9O7lbzlFBdjQ/C7gIkVs/oyLAz X-Received: by 2002:a50:8933:: with SMTP id e48mr25207476ede.51.1569936801650; Tue, 01 Oct 2019 06:33:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569936801; cv=none; d=google.com; s=arc-20160816; b=VN1bEphwoHhr2xw7NbLAnKKH1oF3BNmjy1EoLOqFyGgpCuJjmCjnmKdN1ng1GilQ/D xj61ijuC2wA//llT3pUoyRv3osjUFxgd0utI1jfjTp5zELv4ul6ZX+sohe5tmpUj8ft8 m8NCISJ5AWrnTJnk82PZpH3koAO1q/GoyK+5nRyniHCJkYqhiDSu+qLj0uXJTorYRFYj Eqbuw6jw8Xo+p9PzPj3t+AZxkVY9aSrxnJNhUmJbUGvlK7k8+vB0xQOrI9+Gep2sN7ws BPlrJNSBhs9YGRdNyx1xfIXavoN/MlBkCz7YLLs/HM8RXmAwbOl10MzRs6n9dNuQ5w9D iGJQ== 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 :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=GvCUP3hFt7s8m6oQv44AahwMQGx0suQUUdeh7iLJBTI=; b=GQXDArVSg6j2vxwI7iidPuNwEEd61U7qx5Ve6ddh7Z6P+1LCsjYqV/fW33zrdFrc/w 3c8s/OCJiGPJtP0VoTjMk86SHZMEdU0DpMoaecwEm+Fq4Qr0tDmHSJYtxHSW5A7xcl+C hCM/Eq6CuPs+SIOIa5lsQ8p7VueCYu8NBHefkpBUcmZylcANVtH3/upSnzA8BQ0vfFjw 3aUY8bKms8PjuNgZQw+8uXSnHO5KLQsQB22Ey67ouAxTqiI+EcZHI2V7LuDfjlRAZTZ7 os3hzK9IJyL5URfYhkV78R9Q/fRLsMMlFWj/H+cpao2h8UdpgpuSaut58ekJVtWSnH6K alyw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b15si9149811edm.395.2019.10.01.06.32.50; Tue, 01 Oct 2019 06:33:21 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388504AbfJANc1 (ORCPT + 99 others); Tue, 1 Oct 2019 09:32:27 -0400 Received: from inca-roads.misterjones.org ([213.251.177.50]:46743 "EHLO inca-roads.misterjones.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388466AbfJANc1 (ORCPT ); Tue, 1 Oct 2019 09:32:27 -0400 Received: from 78.163-31-62.static.virginmediabusiness.co.uk ([62.31.163.78] helo=why) by cheepnis.misterjones.org with esmtpsa (TLSv1.2:AES256-GCM-SHA384:256) (Exim 4.80) (envelope-from ) id 1iFIGL-00060M-7n; Tue, 01 Oct 2019 15:32:21 +0200 Date: Tue, 1 Oct 2019 14:32:19 +0100 From: Marc Zyngier To: Will Deacon Cc: Jia He , Catalin Marinas , Mark Rutland , James Morse , Matthew Wilcox , "Kirill A. Shutemov" , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Punit Agrawal , Thomas Gleixner , Andrew Morton , hejianet@gmail.com, Kaly Xin Subject: Re: [PATCH v10 2/3] arm64: mm: implement arch_faults_on_old_pte() on arm64 Message-ID: <20191001143219.018281be@why> In-Reply-To: <20191001125031.7ddm5dlwss6m3dth@willie-the-truck> References: <20190930015740.84362-1-justin.he@arm.com> <20190930015740.84362-3-justin.he@arm.com> <20191001125031.7ddm5dlwss6m3dth@willie-the-truck> Organization: Approximate X-Mailer: Claws Mail 3.17.4 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-SA-Exim-Connect-IP: 62.31.163.78 X-SA-Exim-Rcpt-To: will@kernel.org, justin.he@arm.com, catalin.marinas@arm.com, mark.rutland@arm.com, james.morse@arm.com, 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 X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on cheepnis.misterjones.org); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 1 Oct 2019 13:50:32 +0100 Will Deacon wrote: > On Mon, Sep 30, 2019 at 09:57:39AM +0800, Jia He wrote: > > On arm64 without hardware Access Flag, copying fromuser will fail because > > the pte is old and cannot be marked young. So we always end up with zeroed > > page after fork() + CoW for pfn mappings. we don't always have a > > hardware-managed access flag on arm64. > > > > Hence implement arch_faults_on_old_pte on arm64 to indicate that it might > > cause page fault when accessing old pte. > > > > Signed-off-by: Jia He > > Reviewed-by: Catalin Marinas > > --- > > arch/arm64/include/asm/pgtable.h | 14 ++++++++++++++ > > 1 file changed, 14 insertions(+) > > > > diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h > > index 7576df00eb50..e96fb82f62de 100644 > > --- a/arch/arm64/include/asm/pgtable.h > > +++ b/arch/arm64/include/asm/pgtable.h > > @@ -885,6 +885,20 @@ static inline void update_mmu_cache(struct vm_area_struct *vma, > > #define phys_to_ttbr(addr) (addr) > > #endif > > > > +/* > > + * On arm64 without hardware Access Flag, copying from user will fail because > > + * the pte is old and cannot be marked young. So we always end up with zeroed > > + * page after fork() + CoW for pfn mappings. We don't always have a > > + * hardware-managed access flag on arm64. > > + */ > > +static inline bool arch_faults_on_old_pte(void) > > +{ > > + WARN_ON(preemptible()); > > + > > + return !cpu_has_hw_af(); > > +} > > Does this work correctly in a KVM guest? (i.e. is the MMFR sanitised in that > case, despite not being the case on the host?) Yup, all the 64bit MMFRs are trapped (HCR_EL2.TID3 is set for an AArch64 guest), and we return the sanitised version. But that's an interesting remark: we're now trading an extra fault on CPUs that do not support HWAFDBS for a guaranteed trap for each and every guest under the sun that will hit the COW path... My gut feeling is that this is going to be pretty visible. Jia, do you have any numbers for this kind of behaviour? Thanks, M. -- Without deviation from the norm, progress is not possible.