From mboxrd@z Thu Jan 1 00:00:00 1970 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 0B5D6C5B572 for ; Sun, 16 Aug 2026 11:00:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=pVPiYTx5xsmZOnMUcbrtteXSXwIvJir7dW3VRw6OI/o=; b=X6RWE7z7R5sNwzMPRLjKeFCSpS ngtO5YuZeifk1f0t8DgHAclIK9tkPJ0DqKMmdrhKOPPl153F/TxumriKXhTVegO3QHya1V8/W7H5L RiWOaPynvkcjLSv3LYO3s7Dki7gTMsrcfO12HjSPLj3fdb5FviPR3hYN44vEDitBB0YPecDsAF4gP Q5wDmlWRAQfgdXGABMjz5MMw+CALeojUGyHpNlrIGBMJXwquUTZRnfK9tnvSVgYoDY2huoAAHRXLT YdVWvMEpv2CdJ6bMPr4XRYftkmpHwVZI0do6k2l9qAB2Q0+I8/xdPsy6YPitkvt5Z8sIfTLa22W+V kjtvg5WQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wvYbF-00000004fu8-0UPb; Sun, 16 Aug 2026 11:00:21 +0000 Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wvYbA-00000004frp-3yLi; Sun, 16 Aug 2026 11:00:17 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 571CD40461; Sun, 16 Aug 2026 11:00:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC81B1F000E9; Sun, 16 Aug 2026 11:00:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1786878016; bh=pVPiYTx5xsmZOnMUcbrtteXSXwIvJir7dW3VRw6OI/o=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=Wn2tZkv2GmmvVvChb74RK7g+ieOJXoK9nRUtAwcKG1NxkbRbiQnwxuFtGfZc934GF ojnGXmG2CmOzyYd4WRDvKp74bLte24Nxofl5tovKCDjJt8Klp3pt15WXlZF0xsKWd/ VAZrWr9rmwXSRxftpWSw5h1IkcUwmiJS2YwRKrOxgPSde0/kgHE18LZwznsC9zVKob RkLvq8BCC+Cb38ljwdvLoIU5DXXQkdqpAZkhq6nlU183ZRgqoCY/nK3PbTrZgcsh+x gKDjsg7+EFabNEvmBTKl2HgmFZfhiaPb85PFS+49KLaXDpFuB/mB1UDggWiTDWKvSb sgZxxI00zoBMg== From: "Mike Rapoport (Microsoft)" Date: Sun, 16 Aug 2026 13:59:27 +0300 Subject: [PATCH 4/6] mm/vmalloc: make set_area_direct_map HUGE_VMAP friendly MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260816-execmem-set-vm-perms-v0-2-v1-4-90944a3ad43f@kernel.org> References: <20260816-execmem-set-vm-perms-v0-2-v1-0-90944a3ad43f@kernel.org> In-Reply-To: <20260816-execmem-set-vm-perms-v0-2-v1-0-90944a3ad43f@kernel.org> To: Andrew Morton Cc: =?utf-8?q?Adrian_Barna=C5=9B?= , Albert Ou , Alexander Gordeev , Alexandre Ghiti , Andy Lutomirski , Borislav Petkov , Brendan Jackman , Catalin Marinas , Christian Borntraeger , Dave Hansen , David Hildenbrand , Gerald Schaefer , Heiko Carstens , Huacai Chen , Ingo Molnar , Len Brown , Mike Rapoport , Palmer Dabbelt , Paul Walmsley , Pavel Machek , Peter Zijlstra , "H. Peter Anvin" , "Rafael J. Wysocki" , Ryan Roberts , Sven Schnelle , Thomas Gleixner , Uladzislau Rezki , Vasily Gorbik , WANG Xuerui , Will Deacon , x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-pm@vger.kernel.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, loongarch@lists.linux.dev X-Mailer: b4 0.17-dev 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 set_area_direct_map() always updates direct map alias permissions in single page increments. For HUGE_VMAP areas it's suboptimal. Not only the loop in set_area_direct_map() needlessly has more iterations (e.g times 512 on x86), but it also causes fragmentation of the direct map that could be avoided for the HUGE_VMAP areas populated with large pages. All pages in an area are always of the same order: either same-order large pages when VM_ALLOW_HUGE_VMAP is set and all huge pages were successfully allocated, or order-0 page when VM_ALLOW_HUGE_VMAP is cleared or when huge pages allocation fails and fallback path is taken. Instead of updating the direct map permissions for every order-0 page in an area, use the area's page_order as the loop increment and update the large pages in one call to set_direct_map_{invalid,default}_noflush(). Signed-off-by: Mike Rapoport (Microsoft) --- mm/vmalloc.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index fc7993db4152..11170d1ee5be 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -3361,12 +3361,15 @@ static inline void set_area_direct_map(const struct vm_struct *area, int (*set_direct_map)(struct page *page, unsigned int nr)) { - unsigned long i; + unsigned int nr = (1U << vm_area_page_order(area)); + + for (unsigned long i = 0; i < area->nr_pages; i += nr) { + if (page_address(area->pages[i])) { + int err = set_direct_map(area->pages[i], nr); - /* HUGE_VMALLOC passes small pages to set_direct_map */ - for (i = 0; i < area->nr_pages; i++) - if (page_address(area->pages[i])) - set_direct_map(area->pages[i], 1); + WARN_ON_ONCE(err); + } + } } /* -- 2.53.0