From patchwork Thu Jan 19 10:02:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13107658 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE00AC00A5A for ; Thu, 19 Jan 2023 10:07:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 525CD6B0082; Thu, 19 Jan 2023 05:07:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4D6528E0002; Thu, 19 Jan 2023 05:07:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 39E7D6B0085; Thu, 19 Jan 2023 05:07:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 273326B0082 for ; Thu, 19 Jan 2023 05:07:14 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 06E35140CBE for ; Thu, 19 Jan 2023 10:07:14 +0000 (UTC) X-FDA: 80371120788.11.A373031 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf25.hostedemail.com (Postfix) with ESMTP id 840FEA0012 for ; Thu, 19 Jan 2023 10:07:12 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=fxi+I+rj; spf=none (imf25.hostedemail.com: domain of BATV+d6c99cb0ec1a2cfa7d20+7088+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+d6c99cb0ec1a2cfa7d20+7088+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674122832; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=N6RK7sD1bhTlPOZWkzdYEDixwksJjCe7JpWeHG+wfsg=; b=iQCi0jPAf8e1bXF0tsCDeecgrzV6mtlmDWsIgdD1xnRmh1G0G5oGDcZH9SR+XNEiY4MXrK AikLVjD6R1+koIiozKhQy7CvGQCzIGKl0kEW80/uxlEp8aYkgrUKwGS6A9qa0iY4hRCbFO kH/RuAwbkQnNl34jreaFgWSH1GozS08= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=fxi+I+rj; spf=none (imf25.hostedemail.com: domain of BATV+d6c99cb0ec1a2cfa7d20+7088+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+d6c99cb0ec1a2cfa7d20+7088+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674122832; a=rsa-sha256; cv=none; b=d/59aCzw3eKjOnQOPVVbPYKDqj4f9bnd26K7JjEPxd+BEBmrOvJSQ0CfGL8VzhwpHNAdLJ UDCWjHdULg9rP0SK70rK/FKHimwweq55MKxqAqY0OlNeV+BbqEQraMgRZgArYtA0TP4E9s 4OUual4VNyU9ue8hhs9J3FusfOigtPw= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=N6RK7sD1bhTlPOZWkzdYEDixwksJjCe7JpWeHG+wfsg=; b=fxi+I+rjMIPm9aq1Lf4AGHLq0t zcf0gfRREWv1msyE/Kw3jABqEm7S00/+4aO+QkP0aRRPcMXXJ6ej4FzlPTPGxp+0U32pn/wuuQfBA wLErfPOzU7w4Q1qRMu8K8sROZBxPkUxUi3UGIzFiZCJZCRY3ebIUAbcnSqFsr0DvTp9rJg9Fd4Imb T/6UXMEr70/mFXGG8QoLZKubBvkuoX/z0GdyjvJnyyadQqNFpRrV/N3sZS6U/UId3dhK+NTbES7Xn 2ZzmZ0OpRZl/VSM3Lj18r5aeuaxtpRkzGO8grTBNdPyzv94+FkQO4E8pWG3UYvCRar3LTjKcCIkgQ XJgzOylA==; Received: from 089144197172.atnat0006.highway.a1.net ([89.144.197.172] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pIRp6-004NMP-OP; Thu, 19 Jan 2023 10:07:09 +0000 From: Christoph Hellwig To: Andrew Morton , Uladzislau Rezki Cc: linux-mm@kvack.org Subject: [PATCH 10/10] mm: refactor va_remove_mappings Date: Thu, 19 Jan 2023 11:02:26 +0100 Message-Id: <20230119100226.789506-11-hch@lst.de> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230119100226.789506-1-hch@lst.de> References: <20230119100226.789506-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: 5wdztnan7j6a61r6thnzr7s49qp78r1q X-Rspamd-Queue-Id: 840FEA0012 X-HE-Tag: 1674122832-907066 X-HE-Meta: U2FsdGVkX18qcm1ou3V5PKHqMv3iThx1KMlECPKhh0mNts7yqDkabnu7vgrE1u7Ojj0Nr8D/K4KxR0gJP1AbHmBKQISFcUEOEQBBqmse9xvnmyuTgBqkF0F58GfMEaGgG4WpW/Sd8DmwmY0DVtsl0kJgczVy08IIUUdauCVYeoM6LrVBDSngJXCqzt4R/MQaAIGV+G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mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Move the VM_FLUSH_RESET_PERMS to the caller and rename the function to better describe what it is doing. Signed-off-by: Christoph Hellwig Reviewed-by: Uladzislau Rezki (Sony) --- mm/vmalloc.c | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 791d906d7e407c..f41be986b01e4e 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -2617,35 +2617,23 @@ static inline void set_area_direct_map(const struct vm_struct *area, set_direct_map(area->pages[i]); } -/* Handle removing and resetting vm mappings related to the vm_struct. */ -static void va_remove_mappings(struct vm_struct *area, int deallocate_pages) +/* + * Flush the vm mapping and reset the direct map. + */ +static void vm_reset_perms(struct vm_struct *area) { unsigned long start = ULONG_MAX, end = 0; unsigned int page_order = vm_area_page_order(area); - int flush_reset = area->flags & VM_FLUSH_RESET_PERMS; int flush_dmap = 0; int i; - /* If this is not VM_FLUSH_RESET_PERMS memory, no need for the below. */ - if (!flush_reset) - return; - - /* - * If not deallocating pages, just do the flush of the VM area and - * return. - */ - if (!deallocate_pages) { - vm_unmap_aliases(); - return; - } - /* - * If execution gets here, flush the vm mapping and reset the direct - * map. Find the start and end range of the direct mappings to make sure + * Find the start and end range of the direct mappings to make sure that * the vm_unmap_aliases() flush includes the direct map. */ for (i = 0; i < area->nr_pages; i += 1U << page_order) { unsigned long addr = (unsigned long)page_address(area->pages[i]); + if (addr) { unsigned long page_size; @@ -2740,7 +2728,8 @@ void vfree(const void *addr) return; } - va_remove_mappings(vm, true); + if (unlikely(vm->flags & VM_FLUSH_RESET_PERMS)) + vm_reset_perms(vm); for (i = 0; i < vm->nr_pages; i++) { struct page *page = vm->pages[i];