Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp89409pxa; Fri, 21 Aug 2020 01:51:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy9lwFZmZy7aulJEYuphhk9s/ugX8ojYuBVbADhJbDKLwRuE84Dkw/3hfq9TTw7t7vfWfGK X-Received: by 2002:a17:906:a8f:: with SMTP id y15mr1866985ejf.140.1597999912560; Fri, 21 Aug 2020 01:51:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597999912; cv=none; d=google.com; s=arc-20160816; b=kWN3tBDiZorCbts8tuPKuATFvkwK290jJmRFLHH0C43QQACrGqLd94uIJU9hDowuJg kii8cLaUsINMe2CcHS5mbScRad2AkW782erjDMKQVbbrxykWXIQwFGO7Wl3AssbdbCCr iLhzP/QK5J2DH037Sh+RTYJ3bEAj/D6Z+YE0aKh2kgM/93aUEmlI57xu3p5niIocUKNC eqX8bViRFkQYzF4KTnmShPmJgbE2XQGIxGrRBHmbyg3deGmugNNg7kXhtQ4EHX0mI4Dw 4e7PDN1+Gmefi/KDX926MbAwdnFmr337sufLVkhQRpoWwpE2AAbBrtYV5/xIZpJGVRzB 9tWQ== 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:date:subject:cc:to:from; bh=rWj6sG7swYbaLRV38FkOqio2Srrz7EQlTc9vexptXMM=; b=Qvl/NWBIXveNV3pDEYc41x6S9bPQYtoyfpEwXXvnytqfmO6GP75N2rjGqaNeERRbH+ T1NvzaJn38+h9TTIBVVsrVDk4PhrRNvK/GWd83oUCy301TVDopcmRU4I4i9fUiWZ+zRN BHD+PxDpC+AIlkISwl9BgyY4SRggmzv52zoU7CNXUfxTAP6dtcmacbDVNQmwm5kCCJL4 UjL9djU75XhBfRvSABO/q6oVGsfgbJo5l7AQ2V9u6q/F1vPR/Cj/ExQydmo9tf766989 qFWQJjmU9RAyXAP3q0aEguZPrdZQtPVB+adCkpHlM9FgeP4sM8jcLvsJ1M5Kt+BPgOuo nzzg== 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 n5si718991eju.119.2020.08.21.01.51.28; Fri, 21 Aug 2020 01:51: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 S1728148AbgHUIuT (ORCPT + 99 others); Fri, 21 Aug 2020 04:50:19 -0400 Received: from mail.fireflyinternet.com ([77.68.26.236]:55722 "EHLO fireflyinternet.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1727868AbgHUIuT (ORCPT ); Fri, 21 Aug 2020 04:50:19 -0400 X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.65.138; Received: from build.alporthouse.com (unverified [78.156.65.138]) by fireflyinternet.com (Firefly Internet (M1)) with ESMTP id 22195097-1500050 for multiple; Fri, 21 Aug 2020 09:50:14 +0100 From: Chris Wilson To: linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org Cc: linux-mm@kvack.org, Chris Wilson , Pavel Machek , Andrew Morton , Joerg Roedel , Linus Torvalds , Dave Airlie , Joonas Lahtinen , Rodrigo Vivi , David Vrabel , stable@vger.kernel.org Subject: [PATCH 1/4] mm: Export flush_vm_area() to sync the PTEs upon construction Date: Fri, 21 Aug 2020 09:50:08 +0100 Message-Id: <20200821085011.28878-1-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); + + flush_cache_vmap(addr, area->size); +} +EXPORT_SYMBOL_GPL(flush_vm_area); + void free_vm_area(struct vm_struct *area) { struct vm_struct *ret; -- 2.20.1