From patchwork Sat Jan 21 07:10:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13111016 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 57D69C25B50 for ; Sat, 21 Jan 2023 07:11:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F19256B0072; Sat, 21 Jan 2023 02:11:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id ECA496B0080; Sat, 21 Jan 2023 02:11:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D1BF36B0081; Sat, 21 Jan 2023 02:11:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id C4D116B0072 for ; Sat, 21 Jan 2023 02:11:26 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id A25861A0F76 for ; Sat, 21 Jan 2023 07:11:26 +0000 (UTC) X-FDA: 80377935372.01.82165B0 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf12.hostedemail.com (Postfix) with ESMTP id 148E540006 for ; Sat, 21 Jan 2023 07:11:24 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=BxwUWG+8; spf=none (imf12.hostedemail.com: domain of BATV+1651c3ebed9361b307e7+7090+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+1651c3ebed9361b307e7+7090+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=1674285085; 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=MVFwvinoUqx5/lg5psoeJPHtHhWtA7mgRAAlRnZDces=; b=BAxBZQhd4MgM37EDyOm/DKPmz0y2IF/IE8CE6AxUI/XH081fTJw26cCyFvwSo+a/w2AkPf pDC6uj7Ivy/+jpuKbbcb9keZgS+FcymjuQA9c628p1uRuwjOCVwHQpk+RdjDKaejsZPe2A XbCo1L7+V7eC4Ptqs28Bj8ecrYfMjSc= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=BxwUWG+8; spf=none (imf12.hostedemail.com: domain of BATV+1651c3ebed9361b307e7+7090+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+1651c3ebed9361b307e7+7090+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674285085; a=rsa-sha256; cv=none; b=d0+zFjr5lo0boRZSVCmrVtKcD6kQCfpnxYoTQyALlAhM+58TlRbxa/AeudDXBo8zF1GRqb hBkKKhtxAv6rwzd15jkXgM+X7ZLQynbGw8L1+UiMqXXp7b76yKgX0FU5gaC73oDPnxy9nk rN7BuQ+ppEPGGAS/9Gg9ZMRM5rUvqIY= 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=MVFwvinoUqx5/lg5psoeJPHtHhWtA7mgRAAlRnZDces=; b=BxwUWG+8AyQ3rEml1EmfY53UY3 jW/EOiAn7IqlTNMKUXUHBDOwVMwHW+J1SEgJywBfXznR3TsUsK8VHIJlx/XP1Y2uFhfk5q4ch26MM 7y+8R3biifI9ZO4anC7jzQCQhsQz1ueVyMGEoZdLjBu3UFNnHrbYxLd7Ax/vygdZVrQxbimobqkgN MQq65HflqHD3HuYYp+tS8ILFI00CSdyk0cmGWRPkTw4brDSpV5D2nUoBIZMK5egKsomS4t/kwOMt4 m2O7SKRg094LUFjRiIdW1PtEuwWmbzUL5h7ZduAdeBXj2OnjV0vdvIyZOHo4Ve/gjPjZIeBaAPJva YhBnW1eg==; Received: from [2001:4bb8:19a:2039:6754:cc81:9ace:36fc] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pJ823-00DTtM-NY; Sat, 21 Jan 2023 07:11:20 +0000 From: Christoph Hellwig To: Andrew Morton , Uladzislau Rezki Cc: Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , kasan-dev@googlegroups.com, linux-mm@kvack.org Subject: [PATCH 10/10] mm: refactor va_remove_mappings Date: Sat, 21 Jan 2023 08:10:51 +0100 Message-Id: <20230121071051.1143058-11-hch@lst.de> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230121071051.1143058-1-hch@lst.de> References: <20230121071051.1143058-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-Stat-Signature: es9894if4fozbsrp5qkrn3akc5p8oncg X-Rspam-User: X-Rspamd-Queue-Id: 148E540006 X-Rspamd-Server: rspam06 X-HE-Tag: 1674285084-990436 X-HE-Meta: U2FsdGVkX18RDox2zcO9hQAySsSYpZeZ9HBMhu5uJ+gCOL0fXztKf2hF4uHiUWP4NfDHBYzywDQfLmkB8MMnV4h5Irk4GUeVDladycCfGm4EsnrEXs9oSWVNIRoKh2WuFwdc7f7za+xIhpt6Ia+l3aPr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5KLw0FBRWgM8vuiq/bKkMtrp5NUu9dYfphSjiuLlm0CRCFSlSBTyNsdF9u8Ki+UwSuDn8ha2q3OqeMnmapx2G6OZQwVwGvV8vml2oxExGa0tEbQ4a+Cpt0y1Jwo99NKzxINOjEAP9nzNL3ImSn/P7egAv00XrxGBGHM8FVEL8NC6qgorPjz8wG5R5HjjYisKYD1usdHivVtTIKm4+tOeYVlUqsnRRYQt4cFT/apfG2ynjsVqNEysfnwhHrwbjwEFrfPJ3RuKvnrh9kZ9G0mzJOhqvUDa8N5RnTv1eaAIruxWdduFnS+glGvCH0UrGp/52pmBD3h9reTBu/nT9sBZgU8cbU 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: 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) Reviewed-by: David Hildenbrand --- mm/vmalloc.c | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 6bd811e4b7561d..dfde5324e4803d 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 vm_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; } - vm_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];