From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_2 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 041D5C10F14 for ; Tue, 8 Oct 2019 07:46:17 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B97372067B for ; Tue, 8 Oct 2019 07:46:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B97372067B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 676E68E0005; Tue, 8 Oct 2019 03:46:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5FFAC8E0003; Tue, 8 Oct 2019 03:46:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 49FD98E0005; Tue, 8 Oct 2019 03:46:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0099.hostedemail.com [216.40.44.99]) by kanga.kvack.org (Postfix) with ESMTP id 200638E0003 for ; Tue, 8 Oct 2019 03:46:16 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with SMTP id 9B32E180AD803 for ; Tue, 8 Oct 2019 07:46:15 +0000 (UTC) X-FDA: 76019834310.07.screw59_70c86f1e10132 X-HE-Tag: screw59_70c86f1e10132 X-Filterd-Recvd-Size: 7273 Received: from inca-roads.misterjones.org (inca-roads.misterjones.org [213.251.177.50]) by imf17.hostedemail.com (Postfix) with ESMTP for ; Tue, 8 Oct 2019 07:46:14 +0000 (UTC) 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 1iHkC5-0001oY-Va; Tue, 08 Oct 2019 09:46:06 +0200 Date: Tue, 8 Oct 2019 08:46:04 +0100 From: Marc Zyngier To: "Justin He (Arm Technology China)" Cc: Will Deacon , 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 (Arm Technology China)" , nd Subject: Re: [PATCH v10 2/3] arm64: mm: implement arch_faults_on_old_pte() on arm64 Message-ID: <20191008084604.7db2a123@why> In-Reply-To: References: <20190930015740.84362-1-justin.he@arm.com> <20190930015740.84362-3-justin.he@arm.com> <20191001125031.7ddm5dlwss6m3dth@willie-the-truck> <20191001143219.018281be@why> 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=UTF-8 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 62.31.163.78 X-SA-Exim-Rcpt-To: Justin.He@arm.com, will@kernel.org, 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, nd@arm.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on cheepnis.misterjones.org); SAEximRunCond expanded to false X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, 8 Oct 2019 01:55:04 +0000 "Justin He (Arm Technology China)" wrote: > Hi Will and Marc >=20 > > -----Original Message----- > > From: Marc Zyngier > > Sent: 2019=E5=B9=B410=E6=9C=881=E6=97=A5 21:32 > > To: Will Deacon > > Cc: Justin He (Arm Technology China) ; 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 (Arm Technology China) > > Subject: Re: [PATCH v10 2/3] arm64: mm: implement > > arch_faults_on_old_pte() on arm64 > >=20 > > On Tue, 1 Oct 2019 13:50:32 +0100 > > Will Deacon wrote: > > =20 > > > On Mon, Sep 30, 2019 at 09:57:39AM +0800, Jia He wrote: =20 > > > > On arm64 without hardware Access Flag, copying fromuser will fail = =20 > > because =20 > > > > the pte is old and cannot be marked young. So we always end up with= =20 > > zeroed =20 > > > > 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= =20 > > might =20 > > > > 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 =20 > > b/arch/arm64/include/asm/pgtable.h =20 > > > > 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 =20 > > vm_area_struct *vma, =20 > > > > #define phys_to_ttbr(addr) (addr) > > > > #endif > > > > > > > > +/* > > > > + * On arm64 without hardware Access Flag, copying from user will f= ail =20 > > because =20 > > > > + * the pte is old and cannot be marked young. So we always end up = =20 > > with zeroed =20 > > > > + * 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(); > > > > +} =20 > > > > > > Does this work correctly in a KVM guest? (i.e. is the MMFR sanitised = in =20 > > that =20 > > > case, despite not being the case on the host?) =20 > >=20 > > Yup, all the 64bit MMFRs are trapped (HCR_EL2.TID3 is set for an > > AArch64 guest), and we return the sanitised version. =20 > Thanks for Marc's explanation. I verified the patch series on a kvm guest= (-M virt) > with simulated nvdimm device created by qemu. The host is ThunderX2 aarch= 64. >=20 > >=20 > > 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... > >=20 > > My gut feeling is that this is going to be pretty visible. Jia, do you > > have any numbers for this kind of behaviour? =20 > It is not a common COW path, but a COW for PFN mapping pages only. > I add a g_counter before pte_mkyoung in force_mkyoung{} when testing=20 > vmmalloc_fork at [1]. >=20 > In this test case, it will start M fork processes and N pthreads. The def= ault is > M=3D2,N=3D4. the g_counter is about 241, that is it will hit my patch ser= ies for 241 > times. > If I set M=3D20 and N=3D40 for TEST3, the g_counter is about 1492. I must confess I'm not so much interested in random microbenchmarks, but more in actual applications that could potentially be impacted by this. The numbers you're quoting here seem pretty small, which would indicate a low overhead, but that's not indicative of what would happen in real life. I guess that we can leave it at that for now, and turn it into a CPU feature (with the associated static key) if this shows anywhere. Thanks, M. > =20 > [1] https://github.com/pmem/pmdk/tree/master/src/test/vmmalloc_fork >=20 >=20 > -- > Cheers, > Justin (Jia He) >=20 --=20 Jazz is not dead. It just smells funny...