From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.49]) (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 F1279313523 for ; Mon, 1 Sep 2025 09:19:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756718391; cv=none; b=W1TZNE+NEfYMnsNmJfRcVuTuscMaLAFCt6+vV0wSAFjtE9dj1XKKIA2PVQXC2ZCXCuEZy6mI+xWX6BmDNa8l1OX2kze00PfGjUq9KlTKt4rK0k4PiEgvtfTHlHbdIZuyq7gs1D1xJDiUeggIiNC5goXpJdSzoKjvlMwsNWsT6Wo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756718391; c=relaxed/simple; bh=keel1yn3FhEJPPOWeNQJAj3xmh/1LD+X02xJSdZzUVI=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=u0vOtadw90lfdgThg2ujQo9/Ad1LaDJJy0/8jn8nMjLlNvKWdF5/2LT7f+n89OnqR1v9EBjBv1RWfT71trJfubjmIAjfzbn2cCnYfRN/J7rLMDKnXVk4/2L7QLMeCJGcOa9pbFguLxkR7QvrmTHoKoOqOzxeFdOIX3z9BQmZC00= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=ionos.com; spf=pass smtp.mailfrom=ionos.com; dkim=pass (2048-bit key) header.d=ionos.com header.i=@ionos.com header.b=JW2okNwf; arc=none smtp.client-ip=209.85.218.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=ionos.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ionos.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ionos.com header.i=@ionos.com header.b="JW2okNwf" Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-b04163fe08dso202610066b.3 for ; Mon, 01 Sep 2025 02:19:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; t=1756718386; x=1757323186; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=u6Ls6t35aYYluwAFtTSG43pL4pzA4jbKsfNN9ofH+0I=; b=JW2okNwfJNFjfv/5BhnLFDP+XBM6PVBGnVlU9aSyVg6SWsa7L02fGvbyxKqX22qrQV VvD9s7YCXuwAlUbm4uTahpvYEL3ORrgtGnzge5703tr80mSti3fy+tMqW9FdPzdDJR1q e6jPcl+JnBu9OqRxioVDLtwfo6aKPwO6ypHN+SmheNP/COv4nOYZ//WOviKWfTs93hya utTcRGtFrHPyuxK0rypF/085815uUEjyeIMbMcTaztoTgp7LKVqyi6spNUSVk/8/crIS EIH8PWuvNGd+WShPqoY6iOCzhXvYpbZ998WgIF++IBic+PKq5DxOoJEQlmhyBfGUuJH4 6TTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756718386; x=1757323186; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=u6Ls6t35aYYluwAFtTSG43pL4pzA4jbKsfNN9ofH+0I=; b=taTSM6G3VGmJ9BcV1j3kuxs275grBHq9dj+lC3vKEFP2uPGyLSM1s4gybABFeCU7Zl HCaBHeUAqLPgn2qjoozUEvMBlle7Yt+YjspZet2b9vBHJIkJlycQPF4SBU1YhePCgKAa jfJjcaTRMQCtOzWNM+8FCcDN+lq+rKbwGP1djl2SepEcEKWibjRCkl0iO6G7yvc5PsGu miBH2UbPpZ2kzXxv9gzmek9i5E2n8mWDOoi5NYiy+cqwvJ5/t7glRNy8tWr9agNqsoab xANWy4nDWlmmsRdpdZXBxcykYWxCuNVkcF5u2zwnMJmhj45qmCgFAcFERS67tE62hGws 1s/Q== X-Forwarded-Encrypted: i=1; AJvYcCUbR3aDB0GpFKiFXBom8QCI5f91ZscA8EhLB7gIhEzrYOzn++paUn6/IqNz081/fYDkV3XkvK0HJDZxWNCI@vger.kernel.org X-Gm-Message-State: AOJu0YyE7VgqMjufkAx9K0dz04qX5KSReRWJmPtZdxX5ziLwylnNGUGa IVpavYPc8SEkdl7ihe4sP+IqjLwEFOu4zNyJjP9eQikooVc5tBC9dGrgIQ7cF0wEHJc= X-Gm-Gg: ASbGncsbJVesJ0H6I6ObuaKk14UbVjSIf2C6YGzFmQkDiRP9fU8YRLzaYbrV3QdiivX NDd7XUe4Y/4RhJbSjxGiBeMMm775raCA/1fMfG/qhfcGjSFFShqFtBYlEmo64iVxNldYjA+2Np8 mv8DCcr0ez5mEWKA/qjwOB+kOInBoOKXnNcWe05v20qrBDGqKDelMr8pVjnmtpxi0vJTHKn8hUJ RdgrR+MFY5EhXSLpwVk3iA9XCNgfDSmDJVu8EE57IXjWQAC+x1A/3QpBhcmPbzRrUbi5LHhFQaN 2Y+powHEjf+xuwnqp5uoBwwQ2ywnPIulr/8qr7KhsQmr2y4sez0OUCI9/oNcf9LNPTiKaIRUPvq NkJhWNLOwCX9J2fn031YzwUlh75sAbyVHmD+gT70ti/mTzr++RYDOHF5YmArpzNdlgcDO/O4TOr SUWK128gsCnot008iiwFvOaw== X-Google-Smtp-Source: AGHT+IEW+p/yFRXmmN9eW8x4AeaBg7N2/sFlQYebSPLD3vubNbtOgyDoyxrNrPhIPQlzogfakGVp6g== X-Received: by 2002:a17:907:94c9:b0:b04:2f81:5c35 with SMTP id a640c23a62f3a-b042f817f8cmr232585266b.34.1756718385988; Mon, 01 Sep 2025 02:19:45 -0700 (PDT) Received: from raven.intern.cm-ag (p200300dc6f1d0f00023064fffe740809.dip0.t-ipconnect.de. [2003:dc:6f1d:f00:230:64ff:fe74:809]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b01902d0e99sm541005766b.12.2025.09.01.02.19.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Sep 2025 02:19:45 -0700 (PDT) From: Max Kellermann To: akpm@linux-foundation.org, david@redhat.com, axelrasmussen@google.com, yuanchu@google.com, willy@infradead.org, hughd@google.com, mhocko@suse.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com, vbabka@suse.cz, rppt@kernel.org, surenb@google.com, vishal.moola@gmail.com, linux@armlinux.org.uk, James.Bottomley@HansenPartnership.com, deller@gmx.de, agordeev@linux.ibm.com, gerald.schaefer@linux.ibm.com, hca@linux.ibm.com, gor@linux.ibm.com, borntraeger@linux.ibm.com, svens@linux.ibm.com, davem@davemloft.net, andreas@gaisler.com, dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, hpa@zytor.com, chris@zankel.net, jcmvbkbc@gmail.com, viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz, weixugc@google.com, baolin.wang@linux.alibaba.com, rientjes@google.com, shakeel.butt@linux.dev, max.kellermann@ionos.com, thuth@redhat.com, broonie@kernel.org, osalvador@suse.de, jfalempe@redhat.com, mpe@ellerman.id.au, nysal@linux.ibm.com, linux-arm-kernel@lists.infradead.org, linux-parisc@vger.kernel.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v4 12/12] mm/highmem: add const to pointer parameters for improved const-correctness Date: Mon, 1 Sep 2025 11:19:15 +0200 Message-ID: <20250901091916.3002082-13-max.kellermann@ionos.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250901091916.3002082-1-max.kellermann@ionos.com> References: <20250901091916.3002082-1-max.kellermann@ionos.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The memory management (mm) subsystem is a fundamental low-level component of the Linux kernel. Establishing const-correctness at this foundational level enables higher-level subsystems, such as filesystems and drivers, to also adopt const-correctness in their interfaces. This patch lays the groundwork for broader const-correctness throughout the kernel by starting with the core mm subsystem. This patch adds const qualifiers to folio and page pointer parameters in highmem functions that do not modify the referenced memory, improving type safety and enabling compiler optimizations. Functions improved: - kmap_high_get() - arch_kmap_local_high_get() - get_pkmap_color() - __kmap_local_page_prot() - kunmap_high() - kunmap() - kmap_local_page() - kmap_local_page_try_from_panic() - kmap_local_folio() - kmap_local_page_prot() - kmap_atomic_prot() - kmap_atomic() Signed-off-by: Max Kellermann --- arch/arm/include/asm/highmem.h | 6 ++--- arch/xtensa/include/asm/highmem.h | 2 +- include/linux/highmem-internal.h | 38 +++++++++++++++++-------------- include/linux/highmem.h | 8 +++---- mm/highmem.c | 10 ++++---- 5 files changed, 34 insertions(+), 30 deletions(-) diff --git a/arch/arm/include/asm/highmem.h b/arch/arm/include/asm/highmem.h index b4b66220952d..023be74298f3 100644 --- a/arch/arm/include/asm/highmem.h +++ b/arch/arm/include/asm/highmem.h @@ -46,9 +46,9 @@ extern pte_t *pkmap_page_table; #endif #ifdef ARCH_NEEDS_KMAP_HIGH_GET -extern void *kmap_high_get(struct page *page); +extern void *kmap_high_get(const struct page *page); -static inline void *arch_kmap_local_high_get(struct page *page) +static inline void *arch_kmap_local_high_get(const struct page *page) { if (IS_ENABLED(CONFIG_DEBUG_HIGHMEM) && !cache_is_vivt()) return NULL; @@ -57,7 +57,7 @@ static inline void *arch_kmap_local_high_get(struct page *page) #define arch_kmap_local_high_get arch_kmap_local_high_get #else /* ARCH_NEEDS_KMAP_HIGH_GET */ -static inline void *kmap_high_get(struct page *page) +static inline void *kmap_high_get(const struct page *const page) { return NULL; } diff --git a/arch/xtensa/include/asm/highmem.h b/arch/xtensa/include/asm/highmem.h index 34b8b620e7f1..473b622b863b 100644 --- a/arch/xtensa/include/asm/highmem.h +++ b/arch/xtensa/include/asm/highmem.h @@ -29,7 +29,7 @@ #if DCACHE_WAY_SIZE > PAGE_SIZE #define get_pkmap_color get_pkmap_color -static inline int get_pkmap_color(struct page *page) +static inline int get_pkmap_color(const struct page *const page) { return DCACHE_ALIAS(page_to_phys(page)); } diff --git a/include/linux/highmem-internal.h b/include/linux/highmem-internal.h index 36053c3d6d64..ca2ba47c14e0 100644 --- a/include/linux/highmem-internal.h +++ b/include/linux/highmem-internal.h @@ -7,7 +7,7 @@ */ #ifdef CONFIG_KMAP_LOCAL void *__kmap_local_pfn_prot(unsigned long pfn, pgprot_t prot); -void *__kmap_local_page_prot(struct page *page, pgprot_t prot); +void *__kmap_local_page_prot(const struct page *page, pgprot_t prot); void kunmap_local_indexed(const void *vaddr); void kmap_local_fork(struct task_struct *tsk); void __kmap_local_sched_out(void); @@ -33,7 +33,7 @@ static inline void kmap_flush_tlb(unsigned long addr) { } #endif void *kmap_high(struct page *page); -void kunmap_high(struct page *page); +void kunmap_high(const struct page *page); void __kmap_flush_unused(void); struct page *__kmap_to_page(void *addr); @@ -50,7 +50,7 @@ static inline void *kmap(struct page *page) return addr; } -static inline void kunmap(struct page *page) +static inline void kunmap(const struct page *const page) { might_sleep(); if (!PageHighMem(page)) @@ -68,12 +68,12 @@ static inline void kmap_flush_unused(void) __kmap_flush_unused(); } -static inline void *kmap_local_page(struct page *page) +static inline void *kmap_local_page(const struct page *const page) { return __kmap_local_page_prot(page, kmap_prot); } -static inline void *kmap_local_page_try_from_panic(struct page *page) +static inline void *kmap_local_page_try_from_panic(const struct page *const page) { if (!PageHighMem(page)) return page_address(page); @@ -81,13 +81,15 @@ static inline void *kmap_local_page_try_from_panic(struct page *page) return NULL; } -static inline void *kmap_local_folio(struct folio *folio, size_t offset) +static inline void *kmap_local_folio(const struct folio *const folio, + const size_t offset) { - struct page *page = folio_page(folio, offset / PAGE_SIZE); + const struct page *page = folio_page(folio, offset / PAGE_SIZE); return __kmap_local_page_prot(page, kmap_prot) + offset % PAGE_SIZE; } -static inline void *kmap_local_page_prot(struct page *page, pgprot_t prot) +static inline void *kmap_local_page_prot(const struct page *const page, + const pgprot_t prot) { return __kmap_local_page_prot(page, prot); } @@ -102,7 +104,7 @@ static inline void __kunmap_local(const void *vaddr) kunmap_local_indexed(vaddr); } -static inline void *kmap_atomic_prot(struct page *page, pgprot_t prot) +static inline void *kmap_atomic_prot(const struct page *const page, const pgprot_t prot) { if (IS_ENABLED(CONFIG_PREEMPT_RT)) migrate_disable(); @@ -113,7 +115,7 @@ static inline void *kmap_atomic_prot(struct page *page, pgprot_t prot) return __kmap_local_page_prot(page, prot); } -static inline void *kmap_atomic(struct page *page) +static inline void *kmap_atomic(const struct page *const page) { return kmap_atomic_prot(page, kmap_prot); } @@ -173,17 +175,17 @@ static inline void *kmap(struct page *page) return page_address(page); } -static inline void kunmap_high(struct page *page) { } +static inline void kunmap_high(const struct page *const page) { } static inline void kmap_flush_unused(void) { } -static inline void kunmap(struct page *page) +static inline void kunmap(const struct page *const page) { #ifdef ARCH_HAS_FLUSH_ON_KUNMAP kunmap_flush_on_unmap(page_address(page)); #endif } -static inline void *kmap_local_page(struct page *page) +static inline void *kmap_local_page(const struct page *const page) { return page_address(page); } @@ -193,12 +195,14 @@ static inline void *kmap_local_page_try_from_panic(struct page *page) return page_address(page); } -static inline void *kmap_local_folio(struct folio *folio, size_t offset) +static inline void *kmap_local_folio(const struct folio *const folio, + const size_t offset) { return folio_address(folio) + offset; } -static inline void *kmap_local_page_prot(struct page *page, pgprot_t prot) +static inline void *kmap_local_page_prot(const struct page *const page, + const pgprot_t prot) { return kmap_local_page(page); } @@ -215,7 +219,7 @@ static inline void __kunmap_local(const void *addr) #endif } -static inline void *kmap_atomic(struct page *page) +static inline void *kmap_atomic(const struct page *const page) { if (IS_ENABLED(CONFIG_PREEMPT_RT)) migrate_disable(); @@ -225,7 +229,7 @@ static inline void *kmap_atomic(struct page *page) return page_address(page); } -static inline void *kmap_atomic_prot(struct page *page, pgprot_t prot) +static inline void *kmap_atomic_prot(const struct page *const page, const pgprot_t prot) { return kmap_atomic(page); } diff --git a/include/linux/highmem.h b/include/linux/highmem.h index 6234f316468c..105cc4c00cc3 100644 --- a/include/linux/highmem.h +++ b/include/linux/highmem.h @@ -43,7 +43,7 @@ static inline void *kmap(struct page *page); * Counterpart to kmap(). A NOOP for CONFIG_HIGHMEM=n and for mappings of * pages in the low memory area. */ -static inline void kunmap(struct page *page); +static inline void kunmap(const struct page *page); /** * kmap_to_page - Get the page for a kmap'ed address @@ -93,7 +93,7 @@ static inline void kmap_flush_unused(void); * disabling migration in order to keep the virtual address stable across * preemption. No caller of kmap_local_page() can rely on this side effect. */ -static inline void *kmap_local_page(struct page *page); +static inline void *kmap_local_page(const struct page *page); /** * kmap_local_folio - Map a page in this folio for temporary usage @@ -129,7 +129,7 @@ static inline void *kmap_local_page(struct page *page); * Context: Can be invoked from any context. * Return: The virtual address of @offset. */ -static inline void *kmap_local_folio(struct folio *folio, size_t offset); +static inline void *kmap_local_folio(const struct folio *folio, size_t offset); /** * kmap_atomic - Atomically map a page for temporary usage - Deprecated! @@ -176,7 +176,7 @@ static inline void *kmap_local_folio(struct folio *folio, size_t offset); * kunmap_atomic(vaddr2); * kunmap_atomic(vaddr1); */ -static inline void *kmap_atomic(struct page *page); +static inline void *kmap_atomic(const struct page *page); /* Highmem related interfaces for management code */ static inline unsigned long nr_free_highpages(void); diff --git a/mm/highmem.c b/mm/highmem.c index ef3189b36cad..93fa505fcb98 100644 --- a/mm/highmem.c +++ b/mm/highmem.c @@ -61,7 +61,7 @@ static inline int kmap_local_calc_idx(int idx) /* * Determine color of virtual address where the page should be mapped. */ -static inline unsigned int get_pkmap_color(struct page *page) +static inline unsigned int get_pkmap_color(const struct page *const page) { return 0; } @@ -334,7 +334,7 @@ EXPORT_SYMBOL(kmap_high); * * This can be called from any context. */ -void *kmap_high_get(struct page *page) +void *kmap_high_get(const struct page *const page) { unsigned long vaddr, flags; @@ -356,7 +356,7 @@ void *kmap_high_get(struct page *page) * If ARCH_NEEDS_KMAP_HIGH_GET is not defined then this may be called * only from user context. */ -void kunmap_high(struct page *page) +void kunmap_high(const struct page *const page) { unsigned long vaddr; unsigned long nr; @@ -508,7 +508,7 @@ static inline void kmap_local_idx_pop(void) #endif #ifndef arch_kmap_local_high_get -static inline void *arch_kmap_local_high_get(struct page *page) +static inline void *arch_kmap_local_high_get(const struct page *const page) { return NULL; } @@ -572,7 +572,7 @@ void *__kmap_local_pfn_prot(unsigned long pfn, pgprot_t prot) } EXPORT_SYMBOL_GPL(__kmap_local_pfn_prot); -void *__kmap_local_page_prot(struct page *page, pgprot_t prot) +void *__kmap_local_page_prot(const struct page *const page, const pgprot_t prot) { void *kmap; -- 2.47.2