From: Thomas Gleixner <tglx@linutronix.de>
To: Alistair Popple <apopple@nvidia.com>
Cc: Dan Williams <dan.j.williams@intel.com>,
dave.hansen@linux.intel.com, luto@kernel.org,
peterz@infradead.org, max8rr8@gmail.com,
linux-kernel@vger.kernel.org, x86@kernel.org,
jhubbard@nvidia.com, Kees Cook <keescook@chromium.org>
Subject: Re: [PATCH 1/1] x86/ioremap: Use is_vmalloc_addr in iounmap
Date: Mon, 12 Aug 2024 15:23:19 +0200 [thread overview]
Message-ID: <87frr9swmw.ffs@tglx> (raw)
In-Reply-To: <87ikw6rrau.ffs@tglx>
On Mon, Aug 12 2024 at 12:03, Thomas Gleixner wrote:
> On Mon, Aug 12 2024 at 17:41, Alistair Popple wrote:
>> The same applies to the rest of the DIRECT_MAP_END users here. Perhaps
>> it would be better to define this as DIRECT_MAP_SIZE and calculate this
>> based off PAGE_OFFSET instead?
>
> Duh, yes. I shouldn't try to write patches at 30C :)
We can avoid the calculation and expose the end of the physical address
space for memory. This time I actually built and ran it :)
Thanks,
tglx
---
arch/x86/include/asm/page_64.h | 1 +
arch/x86/include/asm/pgtable_64_types.h | 2 ++
arch/x86/mm/kaslr.c | 21 ++++++++++++++++++---
include/linux/mm.h | 4 ++++
kernel/resource.c | 6 ++----
mm/memory_hotplug.c | 2 +-
mm/sparse.c | 2 +-
7 files changed, 29 insertions(+), 9 deletions(-)
--- a/arch/x86/include/asm/page_64.h
+++ b/arch/x86/include/asm/page_64.h
@@ -17,6 +17,7 @@ extern unsigned long phys_base;
extern unsigned long page_offset_base;
extern unsigned long vmalloc_base;
extern unsigned long vmemmap_base;
+extern unsigned long physmem_end;
static __always_inline unsigned long __phys_addr_nodebug(unsigned long x)
{
--- a/arch/x86/include/asm/pgtable_64_types.h
+++ b/arch/x86/include/asm/pgtable_64_types.h
@@ -134,10 +134,12 @@ extern unsigned int ptrs_per_p4d;
# define VMALLOC_START vmalloc_base
# define VMALLOC_SIZE_TB (pgtable_l5_enabled() ? VMALLOC_SIZE_TB_L5 : VMALLOC_SIZE_TB_L4)
# define VMEMMAP_START vmemmap_base
+# define PHYSMEM_END physmem_end
#else
# define VMALLOC_START __VMALLOC_BASE_L4
# define VMALLOC_SIZE_TB VMALLOC_SIZE_TB_L4
# define VMEMMAP_START __VMEMMAP_BASE_L4
+# define PHYSMEM_END ((1ULL << MAX_PHYSMEM_BITS) - 1)
#endif /* CONFIG_DYNAMIC_MEMORY_LAYOUT */
/*
--- a/arch/x86/mm/kaslr.c
+++ b/arch/x86/mm/kaslr.c
@@ -47,13 +47,24 @@ static const unsigned long vaddr_end = C
*/
static __initdata struct kaslr_memory_region {
unsigned long *base;
+ unsigned long *end;
unsigned long size_tb;
} kaslr_regions[] = {
- { &page_offset_base, 0 },
- { &vmalloc_base, 0 },
- { &vmemmap_base, 0 },
+ {
+ .base = &page_offset_base,
+ .end = &physmem_end,
+ },
+ {
+ .base = &vmalloc_base,
+ },
+ {
+ .base = &vmemmap_base,
+ },
};
+/* The end of the possible address space for physical memory */
+unsigned long physmem_end __ro_after_init;
+
/* Get size in bytes used by the memory region */
static inline unsigned long get_padding(struct kaslr_memory_region *region)
{
@@ -82,6 +93,8 @@ void __init kernel_randomize_memory(void
BUILD_BUG_ON(vaddr_end != CPU_ENTRY_AREA_BASE);
BUILD_BUG_ON(vaddr_end > __START_KERNEL_map);
+ /* Preset the end of the possible address space for physical memory */
+ physmem_end = ((1ULL << MAX_PHYSMEM_BITS) - 1);
if (!kaslr_memory_enabled())
return;
@@ -134,6 +147,8 @@ void __init kernel_randomize_memory(void
*/
vaddr += get_padding(&kaslr_regions[i]);
vaddr = round_up(vaddr + 1, PUD_SIZE);
+ if (kaslr_regions[i].end)
+ *kaslr_regions[i].end = __pa(vaddr) - 1;
remain_entropy -= entropy;
}
}
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -97,6 +97,10 @@ extern const int mmap_rnd_compat_bits_ma
extern int mmap_rnd_compat_bits __read_mostly;
#endif
+#ifndef PHYSMEM_END
+# define PHYSMEM_END (1UL << (MAX_PHYSMEM_BITS-PAGE_SHIFT))
+#endif
+
#include <asm/page.h>
#include <asm/processor.h>
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -1826,8 +1826,7 @@ static resource_size_t gfr_start(struct
if (flags & GFR_DESCENDING) {
resource_size_t end;
- end = min_t(resource_size_t, base->end,
- (1ULL << MAX_PHYSMEM_BITS) - 1);
+ end = min_t(resource_size_t, base->end, PHYSMEM_END);
return end - size + 1;
}
@@ -1844,8 +1843,7 @@ static bool gfr_continue(struct resource
* @size did not wrap 0.
*/
return addr > addr - size &&
- addr <= min_t(resource_size_t, base->end,
- (1ULL << MAX_PHYSMEM_BITS) - 1);
+ addr <= min_t(resource_size_t, base->end, PHYSMEM_END);
}
static resource_size_t gfr_next(resource_size_t addr, resource_size_t size,
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -1681,7 +1681,7 @@ struct range __weak arch_get_mappable_ra
struct range mhp_get_pluggable_range(bool need_mapping)
{
- const u64 max_phys = (1ULL << MAX_PHYSMEM_BITS) - 1;
+ const u64 max_phys = PHYSMEM_END;
struct range mhp_range;
if (need_mapping) {
--- a/mm/sparse.c
+++ b/mm/sparse.c
@@ -129,7 +129,7 @@ static inline int sparse_early_nid(struc
static void __meminit mminit_validate_memmodel_limits(unsigned long *start_pfn,
unsigned long *end_pfn)
{
- unsigned long max_sparsemem_pfn = 1UL << (MAX_PHYSMEM_BITS-PAGE_SHIFT);
+ unsigned long max_sparsemem_pfn = (PHYSMEM_END + 1) >> PAGE_SHIFT;
/*
* Sanity checks - do not allow an architecture to pass
next prev parent reply other threads:[~2024-08-12 13:23 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-10 10:00 [PATCH 1/1] x86/ioremap: Use is_vmalloc_addr in iounmap Max Ramanouski
2024-08-08 6:12 ` Alistair Popple
2024-08-08 6:44 ` John Hubbard
2024-08-12 6:15 ` Christoph Hellwig
2024-08-08 14:18 ` Thomas Gleixner
2024-08-08 15:58 ` Dan Williams
2024-08-08 16:15 ` Thomas Gleixner
2024-08-08 16:32 ` Dan Williams
2024-08-08 16:39 ` Dan Williams
2024-08-08 18:44 ` Thomas Gleixner
2024-08-08 19:59 ` Dan Williams
2024-08-09 2:28 ` Alistair Popple
2024-08-09 3:55 ` Dan Williams
2024-08-10 17:45 ` Thomas Gleixner
2024-08-12 7:41 ` Alistair Popple
2024-08-12 10:03 ` Thomas Gleixner
2024-08-12 11:46 ` Alistair Popple
2024-08-12 12:10 ` Max R
2024-08-12 13:23 ` Thomas Gleixner [this message]
2024-08-13 1:33 ` Alistair Popple
2024-08-13 8:20 ` Thomas Gleixner
2024-08-13 20:37 ` Thomas Gleixner
2024-08-13 22:29 ` x86/kaslr: Expose and use the end of the physical memory address space Thomas Gleixner
2024-08-14 0:26 ` Alistair Popple
2024-08-14 14:33 ` Dan Williams
2024-08-15 16:11 ` Kees Cook
2024-08-15 22:48 ` Max R
2024-08-16 9:42 ` David Hildenbrand
2024-08-16 9:43 ` [tip: x86/urgent] " tip-bot2 for Thomas Gleixner
2024-08-20 20:38 ` tip-bot2 for Thomas Gleixner
2024-09-22 22:31 ` Guenter Roeck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87frr9swmw.ffs@tglx \
--to=tglx@linutronix.de \
--cc=apopple@nvidia.com \
--cc=dan.j.williams@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=jhubbard@nvidia.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=max8rr8@gmail.com \
--cc=peterz@infradead.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.