Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp118852pxa; Fri, 21 Aug 2020 02:52:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzQNxXJb33z1JKufZ5a2Y//VJZsvTB6wja5SGm+Fk29vJg/57f3H3+YRyCJ6RsyAfyN3JrN X-Received: by 2002:a17:906:dbd8:: with SMTP id yc24mr2037944ejb.176.1598003572119; Fri, 21 Aug 2020 02:52:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598003572; cv=none; d=google.com; s=arc-20160816; b=GXaEGYYq0qLRT9UN9YvBhdS9y05owjAY1GUjgadHvFzqC+jEz8vUxcg6N0Vog6FfO/ 23g5Av78IEV20JYP8pCjrpCRYGccsyNrQZ8YYiOMs4HBKEvZ/npELPqriF3D60WJhto1 TjwDn0TqnvIgiS/ZF3RBeL+eLb+z47g2xgAtv78mF6z7NsLRGqun225knSAylFIzOFHl tm+PYC8/oMPPFVx4Zat4jQ05dHp2/zOkCYak6bkAQ5eEx4Bnn04RBhPBPF3Zvhyy4FQ1 hJWkPuhOjtfjF6Xuts0Naj0VqSxHn7rcgaCwiR9yhkz6eVgwv7JhuaIQr6Vm/btMwwcs 0+9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=kUgWaMne9brpAzM1hNWNLuM+0NHxojmY34VOS7vZ3K8=; b=jbvmQbX1oEuhA/i75rprh3O2oH5if0MSiQiS3T9CdKLv/Hi2wbFOtt30w69pypN/G5 KIFJvmPqFS94Oim0SiKGg0/1VcGUmjFwDqrCJGkK/OIGdLP0Y81vikry2lxo4tq+JIz7 L9fg5oNCDJvrPc1WVSx+A0+SlYxujU1nVQm79+o7ykLvPu7K5JuL600rx0/k7Up4cfjB QTBk67e57654RGcpSlH0yjo7eWzSJmy5NWWMwMH+yKo9pmxc1Mn3lRSl6FuBjFv7CfDH P71febWcTnzKGYO/DK77Log8DBspZuN2XGmMWODSduPLzMD4yNaGfEMWkvwqXF5eYmfF j9vg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r26si928172ejb.209.2020.08.21.02.52.28; Fri, 21 Aug 2020 02:52:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728004AbgHUJve (ORCPT + 99 others); Fri, 21 Aug 2020 05:51:34 -0400 Received: from mx2.suse.de ([195.135.220.15]:34666 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725855AbgHUJvd (ORCPT ); Fri, 21 Aug 2020 05:51:33 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id A0C2CAB9F; Fri, 21 Aug 2020 09:51:59 +0000 (UTC) Date: Fri, 21 Aug 2020 11:51:29 +0200 From: Joerg Roedel To: 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 Subject: Re: [PATCH 1/4] mm: Export flush_vm_area() to sync the PTEs upon construction Message-ID: <20200821095129.GF3354@suse.de> References: <20200821085011.28878-1-chris@chris-wilson.co.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200821085011.28878-1-chris@chris-wilson.co.uk> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > > The impact is most pronounced on x86_32 due to the delayed set_pmd(). > > Reported-by: Pavel Machek > References: 2ba3e6947aed ("mm/vmalloc: track which page-table levels were modified") > References: 86cf69f1d893 ("x86/mm/32: implement arch_sync_kernel_mappings()") > 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(+) > > 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 *addr) > > /* 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); > > /* 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); > > +void flush_vm_area(struct vm_struct *area) > +{ > + unsigned long addr = (unsigned long)area->addr; > + > + /* apply_to_page_range() doesn't track the damage, assume the worst */ > + 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); This should happen in __apply_to_page_range() directly and look like this: if (ARCH_PAGE_TABLE_SYNC_MASK && create) arch_sync_kernel_mappings(addr, addr + size); Or even better, track whether something had to be allocated in the __apply_to_page_range() path and check for: if (ARCH_PAGE_TABLE_SYNC_MASK & mask)