From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 781194AEEF; Sun, 23 Aug 2026 11:46:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787485607; cv=none; b=bW2iAg6MwR6nkujuhggSgUcr9lVy6aia81F9BqDCy0Mo1VSunch0fDEG8U5QJL5L8pxBOwx70DgviKiqkZK/dNb0Vm33Ic8byo6lNFgwYy0DIkZd7eFmJDOyGPmtuU24A8TkD+CTgIOZD+5u8FtFcK9EdPB2y3G2yuICacuDlwo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787485607; c=relaxed/simple; bh=YedKgqqYw3L3v5xJ0EbP4LlOeGvqsy+4IAQkezqL70Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eWEQKnjn0jg4hgBEPlmYORy1jY2rzUW5RRvjm/OfgRLUQ5clJ4afHcUptacRVDgdCivVZVR1hYl3rMlNJ3feJ540UMNDQFR+oVn2B9BG4JQEzd+fxbsbUyibiya3dw+Lcp/vVrGx84bgiGN+K/+Bczt1763sHA7STh8k6zl1kJk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VyWudsJG; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VyWudsJG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B30B91F000E9; Sun, 23 Aug 2026 11:46:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787485606; bh=YH6xHkx4+EyCoseoSiUf2zwvyC6OW03ddFXTuW/vMMg=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=VyWudsJGZZyn98IpDn33fiJpcRQMtFjwf269UCpmwdtR/WVag6vsK83RuHax2TL3s TTyVaOEq5dByB4DENbbp14bUpoLk16SOg+s5gq+Yo3DpAT9OVRlgf7oUH/IMx9Tl4B gBh1M7+s2LbOLsQMlvBF49yV5I89L6IAiDhC9+MGX14RBk1HvhY4FgKXygUbjXtSV9 WgBhXsUFyhGVNDe1SfV1s1oULI1r/gwIibyPFizfUTqYWrr6IwUdQIps1dr/8NfM/O QszJm+j6PVZH6tLf6zN/NcQGt0UL5noV+oU2bZ6dJA1SZEfZucZIu9HdqTF0dbp/8E VshKjRX91/aIg== From: "Mike Rapoport (Microsoft)" Date: Sun, 23 Aug 2026 14:46:13 +0300 Subject: [PATCH v2 2/6] mm/vmalloc: set area's page_order after allocation succeeds Precedence: bulk X-Mailing-List: linux-s390@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260823-execmem-set-vm-perms-v0-2-v2-2-b013a37d84b3@kernel.org> References: <20260823-execmem-set-vm-perms-v0-2-v2-0-b013a37d84b3@kernel.org> In-Reply-To: <20260823-execmem-set-vm-perms-v0-2-v2-0-b013a37d84b3@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 __vmalloc_area_node() calls set_vm_area_page_order() to set area's page_order before actually allocating pages to populate the area. If allocation of large pages in HUGE_VMAP case fails midway, this leaves the area with elevated page_order throughout the cleanup path. There is no actual issue with this because the only place that currently relies on area->page_order on the cleanup path is the loop calculating the direct map alias range in vm_reset_perms() and it anyway skips unpopulated pages. But having set_vm_area_page_order() in the middle of __vmalloc_area_node() makes things very obscure, hard to reason about and error prone against future changes of the cleanup path. Move the call to set_vm_area_page_order() just before the successful return from __vmalloc_area_node() where page order is guaranteed. While on it, initialize local page_order variable with its declaration. Reviewed-by: Uladzislau Rezki (Sony) Signed-off-by: Mike Rapoport (Microsoft) --- mm/vmalloc.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 22566e0b6e38..9bd94e2f2895 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -3873,7 +3873,7 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask, unsigned long size = get_vm_area_size(area); unsigned long array_size; unsigned long nr_small_pages = size >> PAGE_SHIFT; - unsigned int page_order; + unsigned int page_order = page_shift - PAGE_SHIFT; unsigned int flags; int ret; @@ -3901,9 +3901,6 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask, goto fail; } - set_vm_area_page_order(area, page_shift - PAGE_SHIFT); - page_order = vm_area_page_order(area); - /* * High-order nofail allocations are really expensive and * potentially dangerous (pre-mature OOM, disruptive reclaim @@ -3958,6 +3955,7 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask, goto fail; } + set_vm_area_page_order(area, page_order); return area->addr; fail: -- 2.53.0