From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.54 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796202789; b=ddh0+SsJ9rgT0ckbs8grlqDV1HUkIFXyMZzbdvfsvShHFceOP0Qvb2UgyAGbRM8u6LYD /r1J7IYKfR4PWTUM1vLpWjvTrgu7qwxaL1J5/HEZVg49NTFOwU8cduJU3pLjS88EDGcGr aoYlOXQLZj+vvbkaP1Fiesy2UmZQu7Bh377qSNbjoLnhUd9QFRRSJPfKhbFRHZNoCJoRI 2zr2DLbVGe9b+hnZtWxq44jyumnIPHX5lWAYrBp06PEcr1guIccmSw2NqhXoGP3l/GsCi VTilVmM5i8E5s1Z9wIgZKqJfjVk0Ux/L/ZNOhytfxnpdrnGgerZbtNX/HrroTdzuLeg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796202789; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=s1j68ZDl9icq4D4Zj7VsWlR4J4avZgt3U9RzjuyIwWo=; b=u5MYeeHyNJ2q0wkO05X15JE+lacapyhfoMHC+5yGmtRXag7iqXMWzXGiVYCjR0xXi0ao C+ndYa/HjY2A3Wj0PYajddAQUnlsWWExmzgKBJzutbZVtNl1gBGsL2XlSHx37Vq/PoIL9 lztyI3DhnQRBUWX+Hwb0J1JULhO+CtrHVhE2tOj44DykJA+UCGfVCCrEmFISAhyMszxea cj+2CguRp0Ok4cZdHccrTasIR3Nzcwb/blRNwa3Ue9BFvEUniKnPLOqRKjVhI42GVSavx 8pQhmv9YB/8U7LMRoO/MH6iEho274i1/CIOA3XZRYEQlLDDlMitGq/qdX/qvYgkK4hw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="j6eo/ygN"; arc=none smtp.remote-ip=209.85.216.54 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D7085606A323 for ; Wed, 2 Dec 2026 09:13:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D7085606A323 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.a=rsa-sha256 header.s=20260707 header.b=j6eo/ygN Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-3b413997581so8742881a91.2 for ; Wed, 02 Dec 2026 01:13:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796202788; x=1796807588; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=s1j68ZDl9icq4D4Zj7VsWlR4J4avZgt3U9RzjuyIwWo=; b=j6eo/ygNnvX2WN6L4rvLpSzJDAGzLD/uA55e1dTMzbX0Ky/PiFcL3gSpLOF8KTSSAf jWgCwly+nnfLiNzyuvUCnqLQiiHkJMPnoo1o+C/3UHNXI6HcjNVGBsuaDrRuLYXNaXE3 Z6iVnoQvWcb/va/LIOeTzUwbNU+k2fMT+EPtc11oAB7cBznpFgFIYWhp7rxV6Uvr9WtG PFt74bCv8KgbFyP54JMz07besmlLBpyZW7IoKw1SXUMElJ7goS1eFhW0o1TkyRPIyKy6 iJCIfoX8/HbLJWoovcxW413cqk6iB5/7GzVG78wuQLuSvQvfDbmfJYBFZiJH79ULGIdn 3Bvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796202788; x=1796807588; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=s1j68ZDl9icq4D4Zj7VsWlR4J4avZgt3U9RzjuyIwWo=; b=Vjg/p+AttbzUQ8rBq0ZO3ukm26dHU/hpwTcAj8uDIu7Si9ATCP0+ps+ZxEhj1sKk7x dGI9NtOpPZVP+YPHnBXEofnpGszSF8OU6LW6SLk4qjk7cD30r7wII8664imq6j5m97PD 0ygyrm5IeXyi9gcvrIAR4TqvF8Ruaa/RtxDp0Wj07TPwy8pDsOgg6W+xjvAPEzgLD9mo /ALItty+dfJhzCfk96zrZWEmBSTprjWpLOrbVgZRCnbaZ2mDVsfFdIiNoHEos/VAt+Y0 tcPkJ37zaDHyUNFKcxpGo4145dsjkYZtq2cU3srN5Iw70G910U3TETEXVED7105+4P3P lbYw== X-Forwarded-Encrypted: i=1; AL+hErHEn+lAbmS25lLDP/PabbXLI6f/X9uneJ2gl2msBh++Wsoh5rP+tSBXHpLrTQ7Ut7okrrNHWtAu0VxNr2U=@vger.kernel.org X-Gm-Message-State: APuU4Z/HhszTsz05/RlrCFaykZjgnUJ1s3wMhwpc26FW07WE5SQyLiFi AShFRQ78tckLesz00t9GvwOeusMJY5Q3t+u/cZO9ams3y7ZhJUCJvCKZ X-Gm-Gg: AZFdTZdmyMR8uS4Lgdc+v4scgTuS4qC8u2vAMi1tnYHAZDiggyiiCbBAjDtLpKALhMu wRKWFDV8aUP2ze+DBOOD49J9/swoGu2NzYP4yFYZh6D5aJj/QCGs47O1NNVzy5R15goRInu3F+i 7aCQNWdGnVAibAWsLimoELIbhTLHvu9gbqrLTJfjuVTVdFFYqr6KTi1Mxc72P9tXFP/nx1kj/2s o1fNinmv2CbAdgcRTdTZLGH/uVxllXhlWrH9ovxcgIyP6PEqOWCQul6AbgnUECSSGzlwLkP9oMy FqgOdnID7BNhzFHYCOUITxYsr67B+VB+fxWyanaNEjQ4IgmIeiMsNuxKdj2crzI+Ksxe8Imth/A wUF2vmAo6seEsId+VfZB+2EysibvaFnF4tPecwtXfyfwJ3a19W4aWKIeK8V74RJ93UTrTnnKTWR b9GNhx10VjeZPe1BTpR0q+AclZabp/ONC3N5YKeIzWPcFF6Ka21HOzDOMe3tUuRsV52hgamE92h ZfE/pLf7bwivDq0h4PXjRZonKA9iRlcT1HMy+iCtHEsvBWRypeD+YyWbHH7KFkdgifcfYDEIH1s o9IeZglH/uKp7WLjKU4RUebmanmMiWX1wnYrmeU3n8+emYhNbJdB0bnzncDW3IWddyrEF6cbQAu clGI= X-Received: by 2002:a17:90b:2f8f:b0:3b0:ad59:7199 with SMTP id 98e67ed59e1d1-3b41c942629mr36193228a91.32.1796202787786; Wed, 02 Dec 2026 01:13:07 -0800 (PST) Received: from mi-OptiPlex-7060.mioffice.cn ([43.224.245.234]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b41adcafe0sm65347467a91.16.2026.12.02.01.13.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 01:13:07 -0800 (PST) From: Wen Jiang To: Andrew Morton , Uladzislau Rezki , linux-mm@kvack.org Cc: Barry Song , Ryan Roberts , Dev Jain , Anshuman Khandual , David Hildenbrand , Catalin Marinas , Will Deacon , Leo Yan , Xueyuan Chen , Mike Rapoport , Pasha Tatashin , Pratyush Yadav , Alexander Graf , kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Wen Jiang Subject: [RFC PATCH 2/4] mm/vmalloc: add VM_HAS_HUGE_VMAP Date: Wed, 2 Dec 2026 17:12:10 +0800 Message-Id: <20261202091212.363755-3-jiangwenxiaomi@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261202091212.363755-1-jiangwenxiaomi@gmail.com> References: <20261202091212.363755-1-jiangwenxiaomi@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Wen Jiang vrealloc() frees the tail pages of a shrinking area unless its page_order is non-zero, as partial freeing would require splitting a huge mapping, and is_vm_area_hugepages() reports huge mappings from page_order as well. Both rely on a huge vmalloc area being mapped either entirely with blocks of 1 << page_order pages or entirely with base pages. A follow-up change lets a huge vmalloc area fall back to smaller block sizes for part of the area. page_order then has to be the smallest order used, so that the page array can still be walked in steps of 1 << page_order. It can be 0 for an area that still contains PMD or contiguous PTE mappings. Add an internal VM_HAS_HUGE_VMAP flag, set when at least part of an area is mapped with entries larger than PAGE_SIZE, and use it in vrealloc() and is_vm_area_hugepages() instead of page_order. Together with page_order it describes the layout: !VM_HAS_HUGE_VMAP base pages only VM_HAS_HUGE_VMAP, page_order == 0 huge mappings plus base pages VM_HAS_HUGE_VMAP, page_order > 0 huge mappings only For vrealloc() and the powerpc set_memory_*() guard, any huge mapping is reason enough to back off. alloc_large_system_hash() only uses the result for its boot message. set_vm_area_page_order() sets the flag for a non-zero order, so for now the flag is set exactly when page_order is non-zero and there is no functional change. Like page_order, the flag is only set by the vmalloc allocation path. Huge mappings created by vmap() or ioremap() are tracked by neither. Let kho_preserve_vmalloc() accept the new flag, as it rejects any flag it does not know about. Suggested-by: Barry Song Assisted-by: LLM Signed-off-by: Wen Jiang --- include/linux/vmalloc.h | 7 ++++--- kernel/liveupdate/kexec_handover.c | 3 ++- mm/vmalloc.c | 9 ++++++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h index 034a693777ca0..31be61ad88550 100644 --- a/include/linux/vmalloc.h +++ b/include/linux/vmalloc.h @@ -40,6 +40,7 @@ struct iov_iter; /* in uio.h */ #endif #define VM_SPARSE 0x00001000 /* sparse vm_area. not all pages are present. */ #define VM_REQUIRE_HUGE_VMAP 0x00002000 /* huge page mapping or nothing */ +#define VM_HAS_HUGE_VMAP 0x00004000 /* part of the area has huge mappings */ /* bits [20..32] reserved for arch specific ioremap internals */ @@ -265,13 +266,13 @@ static inline bool is_vm_area_hugepages(const void *addr) * This may not 100% tell if the area is mapped with > PAGE_SIZE * page table entries, if for some reason the architecture indicates * larger sizes are available but decides not to use them, nothing - * prevents that. This only indicates the size of the physical page - * allocated in the vmalloc layer. + * prevents that. This only indicates that the vmalloc layer mapped + * at least part of the area with such entries. */ #ifdef CONFIG_HAVE_ARCH_HUGE_VMALLOC struct vm_struct *area = find_vm_area(addr); - return area && area->page_order > 0; + return area && (area->flags & VM_HAS_HUGE_VMAP); #else return false; #endif diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_handover.c index 42c6609a1766a..c2d5823b498a3 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -1288,7 +1288,8 @@ void kho_unpreserve_pages(struct page *page, unsigned long nr_pages) EXPORT_SYMBOL_GPL(kho_unpreserve_pages); /* vmalloc flags KHO supports */ -#define KHO_VMALLOC_SUPPORTED_FLAGS (VM_ALLOC | VM_ALLOW_HUGE_VMAP) +#define KHO_VMALLOC_SUPPORTED_FLAGS (VM_ALLOC | VM_ALLOW_HUGE_VMAP | \ + VM_HAS_HUGE_VMAP) /* KHO internal flags for vmalloc preservations */ #define KHO_VMALLOC_ALLOC 0x0001 diff --git a/mm/vmalloc.c b/mm/vmalloc.c index eb28dbd29c2e1..595b07a6cc3d1 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -3222,6 +3222,8 @@ static inline void set_vm_area_page_order(struct vm_struct *vm, unsigned int ord { #ifdef CONFIG_HAVE_ARCH_HUGE_VMALLOC vm->page_order = order; + if (order) + vm->flags |= VM_HAS_HUGE_VMAP; #else BUG_ON(order != 0); #endif @@ -4613,7 +4615,7 @@ void *vrealloc_node_align_noprof(const void *p, size_t size, unsigned long align /* * Free tail pages when shrink crosses a page boundary. * - * Skip huge page allocations (page_order > 0) as partial + * Skip areas with huge mappings (VM_HAS_HUGE_VMAP) as partial * freeing would require splitting. * * Skip VM_FLUSH_RESET_PERMS, as direct-map permissions must @@ -4629,8 +4631,9 @@ void *vrealloc_node_align_noprof(const void *p, size_t size, unsigned long align * GFP_KERNEL, which could trigger a recursive deadlock * if we are under filesystem or I/O reclaim. */ - if (new_nr_pages < vm->nr_pages && !vm_area_page_order(vm) && - !(vm->flags & (VM_FLUSH_RESET_PERMS | VM_USERMAP)) && + if (new_nr_pages < vm->nr_pages && + !(vm->flags & (VM_HAS_HUGE_VMAP | VM_FLUSH_RESET_PERMS | + VM_USERMAP)) && gfp_has_io_fs(flags)) { unsigned long addr = (unsigned long)kasan_reset_tag(p); unsigned long old_nr_pages = vm->nr_pages; -- 2.34.1