From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 51DBF43B498 for ; Mon, 17 Aug 2026 17:31:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786987885; cv=none; b=VANXUh9EEjHg/jTWJdtTS4sGolou8LuhgtWMCz/UMsT7WThXvMnj8l98Ws2pkuyqGmSZJexh01VGqh94/09HUGmv0x+1FWa/d8egk26lftt3nOJdZ8t9Xr68tZ4KmnFREqqlulxtXPkgsCsHwKiQRNPjYfcCc12rJxZs7rlH9Fg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786987885; c=relaxed/simple; bh=XuQIGnNEgl05hW1Pt/SRDZrKnxVKWtgOYyJNVYljJJk=; h=From:Date:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=OiXP/t5rU9iOOe6z0/F+SJyHEQtqU3oPEtc6AU6PfBXv3j/Zd5cMMo166VYIycyYGfRJ6PQnR9k2HiJ5vb+e/F8BpvUdqM7iGFHxKWftLeIMZ0uAzo+ADM3tzdHaJ3m3mlBuRyDje9C88BeKpgs343Zl35F6oHOv+mrHoTy5BYQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=eTw2vNHr; arc=none smtp.client-ip=209.85.167.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eTw2vNHr" Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-5aeb59d54b1so3725004e87.1 for ; Mon, 17 Aug 2026 10:31:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786987880; x=1787592680; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:date:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=gdAST+PW7bd2DD1v0YjadB8+zi0iamo4AznH2c9tOUI=; b=eTw2vNHrPGyIV9SJRUFkqft+N4BJxLtAlV0iNfsuJt5IWSQfnFhP8uRxuMkrT9ZZsY 8o1MUhFKKYlyBvH+51JaxIK4APixLSZ3J7q8nE7YeatdCCWCdhZ7+ZPaN8Tvbls6Icaw Q6eKucOBcQ3Qkpz6PMIn1OXUTlDh3tjkT6hZK/2YJ29ODCxfUsIYma2jB8ZtBeeYNFZN ID4shGj2VzFEF2T+GvXDdCfcj3IOGVJjQgL16l2cyNicnipDO5jJy7xCi6rvaGruKrP/ f9mOusaNP7k/nQZ+x19zuyOFNxNwBzJRJOcx+v9BhX7dKYcf9VAT80GF4OQ3FfMezryH AWDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786987880; x=1787592680; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=gdAST+PW7bd2DD1v0YjadB8+zi0iamo4AznH2c9tOUI=; b=Tx97CPLkENbEyulvuo9lkW+7fPS4IXvZVA483FBGZZQVTlQU8m7OZrUJW9IUlfORei 15XRyIGhpXUyLZNpIntg8F24buevMZp8mUTkhjghthFjI+JgaLmDvIhirW1Am7RAgglP 8mqTghva0qI+RBKTqLJ3A6kS8InCRtL18PewPdm5M5593uZk7kv8An3z23D9VygbnvCI TigDFjpFhoNpQkSYNTImo5pAuIlOPWO3NY7D9yk4/R8a+rmhyG/YJB41kyjy6JFNEshJ nx2LLWJeRqhEsJRmeFP6V4mHARhVg5ehp2YChat90Y3qV5nPGQ4NuJC3uaATBZPTDzHJ MQ0w== X-Forwarded-Encrypted: i=1; AHgh+RoA/yD2H4kFq+/dwSXvQlT/6iAiaLhUBJgBzJcZ4Bcp3x8S755+Y2grMjsYIOrMx3P155Osej9w4DCV0wU=@vger.kernel.org X-Gm-Message-State: AOJu0Yx7tuC/GC7s3r5T4u64iM3VA+OCjF8uC+kfpOmwGvBI71V/vCHh 2nzwHNtWLGhooQ+WKnppQ4lVbeIHYxA+7BZtjaIvC//5iQVMK61B0v3d X-Gm-Gg: AR+sD124ME5lMFpytqkNZXAKNdOX1Hf4EVqhs5Midfmzehfqw8YOdAcA48flbx+7iKx q4BbY5fTu+s1TBTc/c4ABAAZXwLe0FEogiaoJzBj1zEH8pZGrFUgOSMkNKiDvPYY7jS+lf18etq +3vMr9xDOl4r9mOZmA7PQu6YqkUeY1iK7S4Py5V3s6h0pa8DcFROM830wFkaKXvDUnxIPFUCPeD dl2hua/7iJFqgNAG0bMNvk4fKQfCwwLIqASnmyb6Lld0y85T8cr7a/uD32WtRhXlvzSYHRQtVyV HojRO/tB/vnlw38xf8Yh66EeIUT+ujLxV+mC3S0z4QdyUZQGNvAN0ucsReAdzlXJe+2y27lTcx0 F54cjnwKtc4tQFJi4yP3SqVw7fOtLS1PWKdrDpA4i9YVqSrxuqMC+en70djGg2z3nhRPhjYgKhw MV1Z4cONR3CRmlH+5Nd4zYOrM+FA== X-Received: by 2002:a05:6512:1284:b0:5b2:9358:b854 with SMTP id 2adb3069b0e04-5b459142afbmr3869031e87.42.1786987880080; Mon, 17 Aug 2026 10:31:20 -0700 (PDT) Received: from milan ([2001:9b1:d5a0:a500::24b]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-3a16b1f1852sm5885691fa.38.2026.08.17.10.31.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Aug 2026 10:31:19 -0700 (PDT) From: Uladzislau Rezki X-Google-Original-From: Uladzislau Rezki Date: Mon, 17 Aug 2026 19:31:17 +0200 To: "Mike Rapoport (Microsoft)" Cc: Andrew Morton , Adrian =?utf-8?Q?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 , 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 Subject: Re: [PATCH 2/6] mm/vmalloc: set area's page_order after allocation succeeds Message-ID: References: <20260816-execmem-set-vm-perms-v0-2-v1-0-90944a3ad43f@kernel.org> <20260816-execmem-set-vm-perms-v0-2-v1-2-90944a3ad43f@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260816-execmem-set-vm-perms-v0-2-v1-2-90944a3ad43f@kernel.org> On Sun, Aug 16, 2026 at 01:59:25PM +0300, Mike Rapoport (Microsoft) wrote: > __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() after __vmalloc_area_node() > succeeded where page order is guaranteed. > > Signed-off-by: Mike Rapoport (Microsoft) > --- > mm/vmalloc.c | 11 +++++++++-- > 1 file changed, 9 insertions(+), 2 deletions(-) > > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > index 22566e0b6e38..6822f0fe9583 100644 > --- a/mm/vmalloc.c > +++ b/mm/vmalloc.c > @@ -3901,8 +3901,7 @@ 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); > + page_order = page_shift - PAGE_SHIFT; > > /* > * High-order nofail allocations are really expensive and > @@ -4106,6 +4105,14 @@ void *__vmalloc_node_range_noprof(unsigned long size, unsigned long align, > if (!ret) > goto fail; > > + /* > + * Set area->page_order once it's known exactly that the order of the > + * pages the area contains. > + * Even if we succeeded to partially populate the area with large pages, > + * still treat the area as populated with order-0 pages. > + */ > + set_vm_area_page_order(area, shift - PAGE_SHIFT); > + > /* > * Mark the pages as accessible, now that they are mapped. > * The condition for setting KASAN_VMALLOC_INIT should complement the > > -- > 2.53.0 > OK, can we just set it right after the: area->nr_pages = vm_area_alloc_pages( vmalloc_gfp_adjust(gfp_mask, page_order), node, page_order, nr_small_pages, area->pages); succeeds? I am not sure there is a good reason to move it out of the __vmalloc_area_node(). -- Uladzislau Rezki