From patchwork Fri May 19 12:02:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 13248267 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CFB67C77B7F for ; Fri, 19 May 2023 12:02:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=puG4JId6DwWFfljfZyBvcuUF+WPfos9FjGkNMxX42zg=; b=JmbYdGk8PilvNV J9NEMftzQxPoxk6WD5iNAHjfSeA1yHV9uZrT8wU+iITb9nHGjtrM6CHxoqyqZjCWyznuOdjpU3tUG MiA3Qtrtug/E+CIlTllhvz1PkvN+8ZTKxp+kGyQDqf+XQ5dQMC/CrNcLj2qClU11eTbstjROatckI dWDtgCllh1xK2oB4qAacSjRuwWJD7FJg3rSUAsdMV0IJ2d7Wdka5RFRNYMpbWXIXUgPlAqwOlHxvE rQP7sgVBue7ULkSxF658WnLwqs1VvTTZ5Md6hUykrKZ4aB5JfZ4Pp6PDggFUPkoFDZE6ucf8KpLf0 LeE98zU+yaDW+3mIi8kw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzyoR-00GBBF-0A; Fri, 19 May 2023 12:02:23 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzyoN-00GB9y-2C for linux-arm-kernel@lists.infradead.org; Fri, 19 May 2023 12:02:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684497738; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=cwIaLMT16E5qj8r3voiOM19WTdKFjWSp1/HW3YYU9XQ=; b=gJ/E6MLuVu2EmXNG7Jfnt/BZmOSXrtS0gRK3fzrA54aArVII2QpT4L5fvQjmyN3yF4ci9d 2GfiQt+zo9nnJ435JNMIw+kZ8E3OpTL+uovFHiaUrp4tijkkmxiUVJwPfE+0ykzVkEarut W5wBjNwSzjwRzkTmRWE8jLS051g4BpY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-618-C3i_wYVyMvq9E-ledI_xKw-1; Fri, 19 May 2023 08:02:15 -0400 X-MC-Unique: C3i_wYVyMvq9E-ledI_xKw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D2DC985A5BF; Fri, 19 May 2023 12:02:14 +0000 (UTC) Received: from localhost (ovpn-12-79.pek2.redhat.com [10.72.12.79]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 05C7840CFD46; Fri, 19 May 2023 12:02:13 +0000 (UTC) Date: Fri, 19 May 2023 20:02:10 +0800 From: Baoquan He To: Thomas Gleixner Cc: "Russell King (Oracle)" , Andrew Morton , linux-mm@kvack.org, Christoph Hellwig , Uladzislau Rezki , Lorenzo Stoakes , Peter Zijlstra , John Ogness , linux-arm-kernel@lists.infradead.org, Mark Rutland , Marc Zyngier , x86@kernel.org Subject: [RFC PATCH 2/3] mm/vmalloc.c: Only flush VM_FLUSH_RESET_PERMS area immediately Message-ID: References: <87zg658fla.ffs@tglx> <87r0rg93z5.ffs@tglx> <87ilcs8zab.ffs@tglx> <87fs7w8z6y.ffs@tglx> <874joc8x7d.ffs@tglx> <87r0rg73wp.ffs@tglx> <87edng6qu8.ffs@tglx> MIME-Version: 1.0 In-Reply-To: <87edng6qu8.ffs@tglx> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230519_050219_792628_6FF40ACB X-CRM114-Status: GOOD ( 20.81 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org When freeing vmalloc range mapping, only unmapping the page tables is done, TLB flush is lazily deferred to a late stage until lazy_max_pages() is met or vmalloc() can't find available virtual memory region. However, to free VM_FLUSH_RESET_PERMS memory of vmalloc, TLB flushing need be done immediately before freeing pages, and the direct map needs resetting permissions and TLB flushing. Please see commit 868b104d7379 ("mm/vmalloc: Add flag for freeing of special permsissions") for more details. In the current code, when freeing VM_FLUSH_RESET_PERMS memory, lazy purge is also done to try to save a TLB flush later. When doing that, it merges the direct map range with the percpu vbq dirty range and all purge ranges by calculating flush range of [min:max]. That will add the huge gap between direct map range and vmalloc range into the final TLB flush range. So here, only flush VM_FLUSH_RESET_PERMS area immediately, and leave the lazy flush to the normal points, e.g when allocating a new vmap_area, or lazy_max_pages() is met. Signed-off-by: Baoquan He --- mm/vmalloc.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 31e8d9e93650..87134dd8abc3 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -2690,9 +2690,10 @@ static inline void set_area_direct_map(const struct vm_struct *area, */ static void vm_reset_perms(struct vm_struct *area) { - unsigned long start = ULONG_MAX, end = 0; + unsigned long start = ULONG_MAX, end = 0, pages = 0; unsigned int page_order = vm_area_page_order(area); - int flush_dmap = 0; + struct list_head local_flush_list; + struct vmap_area alias_va, va; int i; /* @@ -2708,17 +2709,33 @@ static void vm_reset_perms(struct vm_struct *area) page_size = PAGE_SIZE << page_order; start = min(addr, start); end = max(addr + page_size, end); - flush_dmap = 1; } } + va.va_start = (unsigned long)area->addr; + va.va_end = (unsigned long)(area->addr + area->size); /* * Set direct map to something invalid so that it won't be cached if * there are any accesses after the TLB flush, then flush the TLB and * reset the direct map permissions to the default. */ set_area_direct_map(area, set_direct_map_invalid_noflush); - _vm_unmap_aliases(start, end, flush_dmap); + if (IS_ENABLED(CONFIG_HAVE_FLUSH_TLB_KERNEL_VAS)) { + if (end > start) { + pages = (end - start) >> PAGE_SHIFT; + alias_va.va_start = (unsigned long)start; + alias_va.va_end = (unsigned long)end; + list_add(&alias_va.list, &local_flush_list); + } + + pages += area->size >> PAGE_SHIFT; + list_add(&va.list, &local_flush_list); + + flush_tlb_kernel_vas(&local_flush_list, pages); + } else { + flush_tlb_kernel_range(start, end); + flush_tlb_kernel_range(va.va_start, va.va_end); + } set_area_direct_map(area, set_direct_map_default_noflush); }