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=-9.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS 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 CB217C433DF for ; Fri, 21 Aug 2020 09:54:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 67BAA20732 for ; Fri, 21 Aug 2020 09:54:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 67BAA20732 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=chris-wilson.co.uk Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E63246B0087; Fri, 21 Aug 2020 05:54:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E13DB8D0006; Fri, 21 Aug 2020 05:54:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D29046B0089; Fri, 21 Aug 2020 05:54:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0101.hostedemail.com [216.40.44.101]) by kanga.kvack.org (Postfix) with ESMTP id BD42E6B0087 for ; Fri, 21 Aug 2020 05:54:52 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 86327A8D4 for ; Fri, 21 Aug 2020 09:54:52 +0000 (UTC) X-FDA: 77174116824.23.pies47_4610a1027038 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin23.hostedemail.com (Postfix) with ESMTP id 4A03037606 for ; Fri, 21 Aug 2020 09:54:52 +0000 (UTC) X-HE-Tag: pies47_4610a1027038 X-Filterd-Recvd-Size: 4633 Received: from fireflyinternet.com (unknown [77.68.26.236]) by imf19.hostedemail.com (Postfix) with ESMTP for ; Fri, 21 Aug 2020 09:54:51 +0000 (UTC) X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.65.138; Received: from localhost (unverified [78.156.65.138]) by fireflyinternet.com (Firefly Internet (M1)) with ESMTP (TLS) id 22195973-1500050 for multiple; Fri, 21 Aug 2020 10:54:23 +0100 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable In-Reply-To: <20200821095129.GF3354@suse.de> References: <20200821085011.28878-1-chris@chris-wilson.co.uk> <20200821095129.GF3354@suse.de> Subject: Re: [PATCH 1/4] mm: Export flush_vm_area() to sync the PTEs upon construction From: Chris Wilson Cc: linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org, linux-mm@kvack.org, Pavel Machek , Andrew Morton , Linus Torvalds , Dave Airlie , Joonas Lahtinen , Rodrigo Vivi , David Vrabel , stable@vger.kernel.org To: Joerg Roedel Date: Fri, 21 Aug 2020 10:54:22 +0100 Message-ID: <159800366215.29194.8455636122843151159@build.alporthouse.com> User-Agent: alot/0.9 X-Rspamd-Queue-Id: 4A03037606 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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: Quoting Joerg Roedel (2020-08-21 10:51:29) > On Fri, Aug 21, 2020 at 09:50:08AM +0100, Chris Wilson wrote: > > The alloc_vm_area() is another method for drivers to > > vmap/map_kernel_range that uses apply_to_page_range() rather than the > > direct vmalloc walkers. This is missing the page table modification > > tracking, and the ability to synchronize the PTE updates afterwards. > > Provide flush_vm_area() for the users of alloc_vm_area() that assumes > > the worst and ensures that the page directories are correctly flushed > > upon construction. > >=20 > > The impact is most pronounced on x86_32 due to the delayed set_pmd(). > >=20 > > Reported-by: Pavel Machek > > References: 2ba3e6947aed ("mm/vmalloc: track which page-table levels we= re modified") > > References: 86cf69f1d893 ("x86/mm/32: implement arch_sync_kernel_mappin= gs()") > > Signed-off-by: Chris Wilson > > Cc: Andrew Morton > > Cc: Joerg Roedel > > Cc: Linus Torvalds > > Cc: Dave Airlie > > Cc: Joonas Lahtinen > > Cc: Rodrigo Vivi > > Cc: Pavel Machek > > Cc: David Vrabel > > Cc: # v5.8+ > > --- > > include/linux/vmalloc.h | 1 + > > mm/vmalloc.c | 16 ++++++++++++++++ > > 2 files changed, 17 insertions(+) > >=20 > > diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h > > index 0221f852a7e1..a253b27df0ac 100644 > > --- a/include/linux/vmalloc.h > > +++ b/include/linux/vmalloc.h > > @@ -204,6 +204,7 @@ static inline void set_vm_flush_reset_perms(void *a= ddr) > > =20 > > /* Allocate/destroy a 'vmalloc' VM area. */ > > extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes); > > +extern void flush_vm_area(struct vm_struct *area); > > extern void free_vm_area(struct vm_struct *area); > > =20 > > /* for /dev/kmem */ > > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > > index b482d240f9a2..c41934486031 100644 > > --- a/mm/vmalloc.c > > +++ b/mm/vmalloc.c > > @@ -3078,6 +3078,22 @@ struct vm_struct *alloc_vm_area(size_t size, pte= _t **ptes) > > } > > EXPORT_SYMBOL_GPL(alloc_vm_area); > > =20 > > +void flush_vm_area(struct vm_struct *area) > > +{ > > + unsigned long addr =3D (unsigned long)area->addr; > > + > > + /* apply_to_page_range() doesn't track the damage, assume the wor= st */ > > + if (ARCH_PAGE_TABLE_SYNC_MASK & (PGTBL_PTE_MODIFIED | > > + PGTBL_PMD_MODIFIED | > > + PGTBL_PUD_MODIFIED | > > + PGTBL_P4D_MODIFIED | > > + PGTBL_PGD_MODIFIED)) > > + arch_sync_kernel_mappings(addr, addr + area->size); >=20 > This should happen in __apply_to_page_range() directly and look like > this: Ok. I thought it had to be after assigning the *ptep. If we apply the sync first, do not have to worry about PGTBL_PTE_MODIFIED from the *ptep? -Chris