* [PATCH] mm: make 'highmem' symbol ro_after_init
@ 2022-01-24 17:05 Ard Biesheuvel
2022-01-24 18:17 ` David Rientjes
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Ard Biesheuvel @ 2022-01-24 17:05 UTC (permalink / raw)
To: akpm; +Cc: linux-mm, linux-kernel, Ard Biesheuvel
The 'highmem' variable is only set at boot, so we can make it
ro_after_init and prevent it from being corrupted inadvertently, or from
ending up in a contended cacheline.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
mm/memory.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/memory.c b/mm/memory.c
index c125c4969913..50e82cb94ccc 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -106,7 +106,7 @@ EXPORT_SYMBOL(mem_map);
* highstart_pfn must be the same; there must be no gap between ZONE_NORMAL
* and ZONE_HIGHMEM.
*/
-void *high_memory;
+void *high_memory __ro_after_init;
EXPORT_SYMBOL(high_memory);
/*
--
2.30.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] mm: make 'highmem' symbol ro_after_init
2022-01-24 17:05 [PATCH] mm: make 'highmem' symbol ro_after_init Ard Biesheuvel
@ 2022-01-24 18:17 ` David Rientjes
2022-01-24 18:31 ` Matthew Wilcox
2022-01-26 21:38 ` Mike Rapoport
2 siblings, 0 replies; 5+ messages in thread
From: David Rientjes @ 2022-01-24 18:17 UTC (permalink / raw)
To: Ard Biesheuvel; +Cc: akpm, linux-mm, linux-kernel
On Mon, 24 Jan 2022, Ard Biesheuvel wrote:
> diff --git a/mm/memory.c b/mm/memory.c
> index c125c4969913..50e82cb94ccc 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -106,7 +106,7 @@ EXPORT_SYMBOL(mem_map);
> * highstart_pfn must be the same; there must be no gap between ZONE_NORMAL
> * and ZONE_HIGHMEM.
> */
> -void *high_memory;
> +void *high_memory __ro_after_init;
> EXPORT_SYMBOL(high_memory);
>
> /*
Same should be true for the mm/nommu.c variant?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] mm: make 'highmem' symbol ro_after_init
2022-01-24 17:05 [PATCH] mm: make 'highmem' symbol ro_after_init Ard Biesheuvel
2022-01-24 18:17 ` David Rientjes
@ 2022-01-24 18:31 ` Matthew Wilcox
2022-01-26 21:38 ` Mike Rapoport
2 siblings, 0 replies; 5+ messages in thread
From: Matthew Wilcox @ 2022-01-24 18:31 UTC (permalink / raw)
To: Ard Biesheuvel; +Cc: akpm, linux-mm, linux-kernel
On Mon, Jan 24, 2022 at 06:05:55PM +0100, Ard Biesheuvel wrote:
> The 'highmem' variable is only set at boot, so we can make it
> ro_after_init and prevent it from being corrupted inadvertently, or from
> ending up in a contended cacheline.
I'm not against this patch, but it'd be nice to go further and remove
it entirely for !CONFIG_HIGHMEM builds? Adding something like
static inline bool is_high_pfn(unsigned long pfn)
{
#ifdef CONFIG_HIGHMEM
return pfn <= max_low_pfn;
#else
return false;
#endif
}
static inline bool is_high_phys(phys_addr_t pa)
{
return is_high_pfn(pa / PAGE_SIZE);
}
static inline bool is_high_addr(void *addr)
{
return is_high_phys(virt_to_phys(addr));
}
should be all the primitives you need, from a quick grep.
> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
> ---
> mm/memory.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/memory.c b/mm/memory.c
> index c125c4969913..50e82cb94ccc 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -106,7 +106,7 @@ EXPORT_SYMBOL(mem_map);
> * highstart_pfn must be the same; there must be no gap between ZONE_NORMAL
> * and ZONE_HIGHMEM.
> */
> -void *high_memory;
> +void *high_memory __ro_after_init;
> EXPORT_SYMBOL(high_memory);
>
> /*
> --
> 2.30.2
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] mm: make 'highmem' symbol ro_after_init
2022-01-24 17:05 [PATCH] mm: make 'highmem' symbol ro_after_init Ard Biesheuvel
2022-01-24 18:17 ` David Rientjes
2022-01-24 18:31 ` Matthew Wilcox
@ 2022-01-26 21:38 ` Mike Rapoport
2022-01-28 9:07 ` Ard Biesheuvel
2 siblings, 1 reply; 5+ messages in thread
From: Mike Rapoport @ 2022-01-26 21:38 UTC (permalink / raw)
To: Ard Biesheuvel; +Cc: akpm, linux-mm, linux-kernel
On Mon, Jan 24, 2022 at 06:05:55PM +0100, Ard Biesheuvel wrote:
> The 'highmem' variable is only set at boot, so we can make it
> ro_after_init and prevent it from being corrupted inadvertently, or from
> ending up in a contended cacheline.
>
> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Acked-by: Mike Rapoport <rppt@linux.ibm.com>
> ---
> mm/memory.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/memory.c b/mm/memory.c
> index c125c4969913..50e82cb94ccc 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -106,7 +106,7 @@ EXPORT_SYMBOL(mem_map);
> * highstart_pfn must be the same; there must be no gap between ZONE_NORMAL
> * and ZONE_HIGHMEM.
> */
> -void *high_memory;
> +void *high_memory __ro_after_init;
> EXPORT_SYMBOL(high_memory);
>
> /*
> --
> 2.30.2
>
>
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] mm: make 'highmem' symbol ro_after_init
2022-01-26 21:38 ` Mike Rapoport
@ 2022-01-28 9:07 ` Ard Biesheuvel
0 siblings, 0 replies; 5+ messages in thread
From: Ard Biesheuvel @ 2022-01-28 9:07 UTC (permalink / raw)
To: Mike Rapoport
Cc: Andrew Morton, Linux Memory Management List, Linux Kernel Mailing List
On Wed, 26 Jan 2022 at 22:38, Mike Rapoport <rppt@kernel.org> wrote:
>
> On Mon, Jan 24, 2022 at 06:05:55PM +0100, Ard Biesheuvel wrote:
> > The 'highmem' variable is only set at boot, so we can make it
> > ro_after_init and prevent it from being corrupted inadvertently, or from
> > ending up in a contended cacheline.
> >
> > Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
>
> Acked-by: Mike Rapoport <rppt@linux.ibm.com>
>
> > ---
> > mm/memory.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/mm/memory.c b/mm/memory.c
> > index c125c4969913..50e82cb94ccc 100644
> > --- a/mm/memory.c
> > +++ b/mm/memory.c
> > @@ -106,7 +106,7 @@ EXPORT_SYMBOL(mem_map);
> > * highstart_pfn must be the same; there must be no gap between ZONE_NORMAL
> > * and ZONE_HIGHMEM.
> > */
> > -void *high_memory;
> > +void *high_memory __ro_after_init;
> > EXPORT_SYMBOL(high_memory);
> >
> > /*
> > --
> > 2.30.2
> >
> >
>
This turns out to break CONFIG_MEMORY_HOTPLUG on x86, as it updates
max_pfn, max_low_pfn and high_memory after init.
So probably best to make all of those __read_mostly instead.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-01-28 9:08 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-24 17:05 [PATCH] mm: make 'highmem' symbol ro_after_init Ard Biesheuvel
2022-01-24 18:17 ` David Rientjes
2022-01-24 18:31 ` Matthew Wilcox
2022-01-26 21:38 ` Mike Rapoport
2022-01-28 9:07 ` Ard Biesheuvel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).