Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1534283 > unrolled thread
| Started by | Will Deacon <will.deacon@arm.com> |
|---|---|
| First post | 2016-12-01 17:50 +0100 |
| Last post | 2016-12-02 15:50 +0100 |
| Articles | 3 — 2 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: [PATCH v2] arm64: mm: Fix memmap to be initialized for the entire section Will Deacon <will.deacon@arm.com> - 2016-12-01 17:50 +0100
Re: [PATCH v2] arm64: mm: Fix memmap to be initialized for the entire section James Morse <james.morse@arm.com> - 2016-12-01 18:30 +0100
Re: [PATCH v2] arm64: mm: Fix memmap to be initialized for the entire section James Morse <james.morse@arm.com> - 2016-12-02 15:50 +0100
| From | Will Deacon <will.deacon@arm.com> |
|---|---|
| Date | 2016-12-01 17:50 +0100 |
| Subject | Re: [PATCH v2] arm64: mm: Fix memmap to be initialized for the entire section |
| Message-ID | <sJCIy-6wt-15@gated-at.bofh.it> |
On Wed, Nov 30, 2016 at 07:21:31PM +0100, Robert Richter wrote:
> On ThunderX systems with certain memory configurations we see the
> following BUG_ON():
>
> kernel BUG at mm/page_alloc.c:1848!
>
> This happens for some configs with 64k page size enabled. The BUG_ON()
> checks if start and end page of a memmap range belongs to the same
> zone.
>
> The BUG_ON() check fails if a memory zone contains NOMAP regions. In
> this case the node information of those pages is not initialized. This
> causes an inconsistency of the page links with wrong zone and node
> information for that pages. NOMAP pages from node 1 still point to the
> mem zone from node 0 and have the wrong nid assigned.
>
> The reason for the mis-configuration is a change in pfn_valid() which
> reports pages marked NOMAP as invalid:
>
> 68709f45385a arm64: only consider memblocks with NOMAP cleared for linear mapping
>
> This causes pages marked as nomap being no long reassigned to the new
> zone in memmap_init_zone() by calling __init_single_pfn().
>
> Fixing this by restoring the old behavior of pfn_valid() to use
> memblock_is_memory(). Also changing users of pfn_valid() in arm64 code
> to use memblock_is_map_memory() where necessary. This only affects
> code in ioremap.c. The code in mmu.c still can use the new version of
> pfn_valid().
>
> As a consequence, pfn_valid() can not be used to check if a physical
> page is RAM. It just checks if there is an underlying memmap with a
> valid struct page. Moreover, for performance reasons the whole memmap
> (with pageblock_nr_pages number of pages) has valid pfns (SPARSEMEM
> config). The memory range is extended to fit the alignment of the
> memmap. Thus, pfn_valid() may return true for pfns that do not map to
> physical memory. Those pages are simply not reported to the mm, they
> are not marked reserved nor added to the list of free pages. Other
> functions such a page_is_ram() or memblock_is_map_ memory() must be
> used to check for memory and if the page can be mapped with the linear
> mapping.
>
> Since NOMAP mem ranges may need to be mapped with different mem
> attributes (e.g. read-only or non-caching) we can not use linear
> mapping here. The use of memblock_is_memory() in pfn_valid() may not
> break this behaviour. Since commit:
>
> e7cd190385d1 arm64: mark reserved memblock regions explicitly in iomem
>
> NOMAP mem resources are no longer marked as system RAM (IORESOURCE_
> SYSTEM_RAM). Now page_is_ram() and region_intersects() (see
> memremap()) do not detect NOMAP mem as system ram and NOMAP mem is not
> added to the linear mapping as system RAM is.
>
> v2:
>
> * Added Ack
> * updated description to reflect the discussion
>
> Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> Signed-off-by: Robert Richter <rrichter@cavium.com>
> ---
> arch/arm64/mm/init.c | 2 +-
> arch/arm64/mm/ioremap.c | 5 +++--
> 2 files changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
> index 212c4d1e2f26..166911f4a2e6 100644
> --- a/arch/arm64/mm/init.c
> +++ b/arch/arm64/mm/init.c
> @@ -147,7 +147,7 @@ static void __init zone_sizes_init(unsigned long min, unsigned long max)
> #ifdef CONFIG_HAVE_ARCH_PFN_VALID
> int pfn_valid(unsigned long pfn)
> {
> - return memblock_is_map_memory(pfn << PAGE_SHIFT);
> + return memblock_is_memory(pfn << PAGE_SHIFT);
> }
> EXPORT_SYMBOL(pfn_valid);
> #endif
> diff --git a/arch/arm64/mm/ioremap.c b/arch/arm64/mm/ioremap.c
> index 01e88c8bcab0..c17c220b0c48 100644
> --- a/arch/arm64/mm/ioremap.c
> +++ b/arch/arm64/mm/ioremap.c
> @@ -21,6 +21,7 @@
> */
>
> #include <linux/export.h>
> +#include <linux/memblock.h>
> #include <linux/mm.h>
> #include <linux/vmalloc.h>
> #include <linux/io.h>
> @@ -55,7 +56,7 @@ static void __iomem *__ioremap_caller(phys_addr_t phys_addr, size_t size,
> /*
> * Don't allow RAM to be mapped.
> */
> - if (WARN_ON(pfn_valid(__phys_to_pfn(phys_addr))))
> + if (WARN_ON(memblock_is_map_memory(phys_addr)))
> return NULL;
>
> area = get_vm_area_caller(size, VM_IOREMAP, caller);
> @@ -96,7 +97,7 @@ EXPORT_SYMBOL(__iounmap);
> void __iomem *ioremap_cache(phys_addr_t phys_addr, size_t size)
> {
> /* For normal memory we already have a cacheable mapping. */
> - if (pfn_valid(__phys_to_pfn(phys_addr)))
> + if (memblock_is_map_memory(phys_addr))
> return (void __iomem *)__phys_to_virt(phys_addr);
Thanks for sending out the new patch. Whilst I'm still a bit worried about
changing pfn_valid like this, I guess we'll just have to fix up any callers
which suffer from this change.
Acked-by: Will Deacon <will.deacon@arm.com>
I'd like to see this sit in -next for a bit before we send it further.
Will
[toc] | [next] | [standalone]
| From | James Morse <james.morse@arm.com> |
|---|---|
| Date | 2016-12-01 18:30 +0100 |
| Subject | Re: [PATCH v2] arm64: mm: Fix memmap to be initialized for the entire section |
| Message-ID | <sJDlf-7gi-27@gated-at.bofh.it> |
| In reply to | #1534283 |
Hi Robert, Will, On 01/12/16 16:45, Will Deacon wrote: > On Wed, Nov 30, 2016 at 07:21:31PM +0100, Robert Richter wrote: >> On ThunderX systems with certain memory configurations we see the >> following BUG_ON(): >> >> kernel BUG at mm/page_alloc.c:1848! >> >> This happens for some configs with 64k page size enabled. The BUG_ON() >> checks if start and end page of a memmap range belongs to the same >> zone. >> >> The BUG_ON() check fails if a memory zone contains NOMAP regions. In >> this case the node information of those pages is not initialized. This >> causes an inconsistency of the page links with wrong zone and node >> information for that pages. NOMAP pages from node 1 still point to the >> mem zone from node 0 and have the wrong nid assigned. >> >> The reason for the mis-configuration is a change in pfn_valid() which >> reports pages marked NOMAP as invalid: >> >> 68709f45385a arm64: only consider memblocks with NOMAP cleared for linear mapping >> >> This causes pages marked as nomap being no long reassigned to the new >> zone in memmap_init_zone() by calling __init_single_pfn(). >> >> Fixing this by restoring the old behavior of pfn_valid() to use >> memblock_is_memory(). Also changing users of pfn_valid() in arm64 code >> to use memblock_is_map_memory() where necessary. This only affects >> code in ioremap.c. The code in mmu.c still can use the new version of >> pfn_valid(). >> >> As a consequence, pfn_valid() can not be used to check if a physical >> page is RAM. It just checks if there is an underlying memmap with a >> valid struct page. Moreover, for performance reasons the whole memmap >> (with pageblock_nr_pages number of pages) has valid pfns (SPARSEMEM >> config). The memory range is extended to fit the alignment of the >> memmap. Thus, pfn_valid() may return true for pfns that do not map to >> physical memory. Those pages are simply not reported to the mm, they >> are not marked reserved nor added to the list of free pages. Other >> functions such a page_is_ram() or memblock_is_map_ memory() must be >> used to check for memory and if the page can be mapped with the linear >> mapping. [...] > Thanks for sending out the new patch. Whilst I'm still a bit worried about > changing pfn_valid like this, I guess we'll just have to fix up any callers > which suffer from this change. Hibernate's core code falls foul of this. This patch causes a panic when copying memory to build the 'image'[0]. saveable_page() in kernel/power/snapshot.c broadly assumes that pfn_valid() pages can be accessed. Fortunately the core code exposes pfn_is_nosave() which we can extend to catch 'nomap' pages, but only if they are also marked as PageReserved(). Are there any side-effects of marking all the nomap regions with mark_page_reserved()? (it doesn't appear to be the case today). Patches incoming... Thanks, James [0] panic trace root@juno-r1:~# echo disk > /sys/power/state [ 56.914184] PM: Syncing filesystems ... [ 56.918853] done. [ 56.920826] Freezing user space processes ... (elapsed 0.001 seconds) done. [ 56.930383] PM: Preallocating image memory... done (allocated 97481 pages) [ 60.566084] PM: Allocated 389924 kbytes in 3.62 seconds (107.71 MB/s) [ 60.572576] Freezing remaining freezable tasks ... (elapsed 0.001 seconds) done. [ 60.604877] PM: freeze of devices complete after 23.146 msecs [ 60.611230] PM: late freeze of devices complete after 0.578 msecs [ 60.618609] PM: noirq freeze of devices complete after 1.247 msecs [ 60.624833] Disabling non-boot CPUs ... [ 60.649112] CPU1: shutdown [ 60.651823] psci: CPU1 killed. [ 60.701055] CPU2: shutdown [ 60.703766] psci: CPU2 killed. [ 60.745002] IRQ11 no longer affine to CPU3 [ 60.745043] CPU3: shutdown [ 60.751890] psci: CPU3 killed. [ 60.784966] CPU4: shutdown [ 60.787676] psci: CPU4 killed. [ 60.824916] IRQ8 no longer affine to CPU5 [ 60.824920] IRQ9 no longer affine to CPU5 [ 60.824927] IRQ18 no longer affine to CPU5 [ 60.824931] IRQ20 no longer affine to CPU5 [ 60.824951] CPU5: shutdown [ 60.843975] psci: CPU5 killed. [ 60.857989] PM: Creating hibernation image: [ 60.857989] PM: Need to copy 96285 pages [ 60.857989] Unable to handle kernel paging request at virtual address ffff8000794a0000 [ 60.857989] pgd = ffff800975190000 [ 60.857989] [ffff8000794a0000] *pgd=0000000000000000[ 60.857989] [ 60.857989] Internal error: Oops: 96000007 [#1] PREEMPT SMP [ 60.857989] Modules linked in: [ 60.857989] CPU: 0 PID: 2366 Comm: bash Not tainted 4.9.0-rc7-00001-gecf7c47af54d #6346 [ 60.857989] Hardware name: ARM Juno development board (r1) (DT) [ 60.857989] task: ffff8009766d3200 task.stack: ffff800975fec000 [ 60.857989] PC is at swsusp_save+0x250/0x2c8 [ 60.857989] LR is at swsusp_save+0x214/0x2c8 [ 60.857989] pc : [<ffff000008100bd0>] lr : [<ffff000008100b94>] pstate: 200003c5 [ 60.857989] sp : ffff800975fefb50 [ 60.857989] x29: ffff800975fefb50 x28: ffff800975fec000 [ 60.857989] x27: ffff0000088c2000 x26: 0000000000000040 [ 60.857989] x25: 00000000000f94a0 x24: ffff000008e437e8 [ 60.857989] x23: 000000000001781d x22: ffff000008bee000 [ 60.857989] x21: ffff000008e437f8 x20: ffff000008e43878 [ 60.857989] x19: ffff7e0000000000 x18: 0000000000000006 [ 60.857989] x17: 0000000000000000 x16: 00000000000005d0 [ 60.857989] x15: ffff000008e43e95 x14: 00000000000001d9 [ 60.857989] x13: 0000000000000001 x12: ffff7e0000000000 [ 60.857989] x11: ffff7e0025ffffc0 x10: 0000000025ffffc0 [ 60.857989] x9 : 000000000000012f x8 : ffff80096cd04ce0 [ 60.857989] x7 : 0000000000978000 x6 : 0000000000000076 [ 60.857989] x5 : fffffffffffffff8 x4 : 0000000000080000 [ 60.857989] x3 : ffff8000794a0000 x2 : ffff800959d83000 [ 60.857989] x1 : 0000000000000000 x0 : ffff7e0001e52800 [ 60.857989] Process bash (pid: 2366, stack limit = 0xffff800975fec020) [ 60.857989] Stack: (0xffff800975fefb50 to 0xffff800975ff0000) [ 60.857989] Call trace: [ 60.857989] [<ffff000008100bd0>] swsusp_save+0x250/0x2c8 [ 60.857989] [<ffff0000080936ec>] swsusp_arch_suspend+0xb4/0x100 [ 60.857989] [<ffff0000080fe670>] hibernation_snapshot+0x278/0x318 [ 60.857989] [<ffff0000080fef10>] hibernate+0x1d0/0x268 [ 60.857989] [<ffff0000080fc954>] state_store+0xdc/0x100 [ 60.857989] [<ffff00000838419c>] kobj_attr_store+0x14/0x28 [ 60.857989] [<ffff00000825be68>] sysfs_kf_write+0x48/0x58 [ 60.857989] [<ffff00000825b1f8>] kernfs_fop_write+0xb0/0x1d8 [ 60.857989] [<ffff0000081e2ddc>] __vfs_write+0x1c/0x110 [ 60.857989] [<ffff0000081e3bd8>] vfs_write+0xa0/0x1b8 [ 60.857989] [<ffff0000081e4f44>] SyS_write+0x44/0xa0 [ 60.857989] [<ffff000008082ef0>] el0_svc_naked+0x24/0x28 [ 60.857989] Code: d37ae442 d37ae463 b2514042 b2514063 (f8636820) [ 60.857989] ---[ end trace d0265b757c9dd571 ]--- [ 60.857989] ------------[ cut here ]------------
[toc] | [prev] | [next] | [standalone]
| From | James Morse <james.morse@arm.com> |
|---|---|
| Date | 2016-12-02 15:50 +0100 |
| Subject | Re: [PATCH v2] arm64: mm: Fix memmap to be initialized for the entire section |
| Message-ID | <sJXjX-58s-25@gated-at.bofh.it> |
| In reply to | #1534325 |
Hi Robert, On 02/12/16 07:11, Robert Richter wrote: > On 01.12.16 17:26:55, James Morse wrote: >> On 01/12/16 16:45, Will Deacon wrote: >>> Thanks for sending out the new patch. Whilst I'm still a bit worried about >>> changing pfn_valid like this, I guess we'll just have to fix up any callers >>> which suffer from this change. >> >> Hibernate's core code falls foul of this. This patch causes a panic when copying >> memory to build the 'image'[0]. >> saveable_page() in kernel/power/snapshot.c broadly assumes that pfn_valid() >> pages can be accessed. >> >> Fortunately the core code exposes pfn_is_nosave() which we can extend to catch >> 'nomap' pages, but only if they are also marked as PageReserved(). >> >> Are there any side-effects of marking all the nomap regions with >> mark_page_reserved()? (it doesn't appear to be the case today). > > Reserving the page adds it to the memory management which is what we > would like to avoid for NOMAP pages. I don't believe we should do > this. Since NOMAP is to some degree now core functionality I would > rather implement pfn_is_nomap() that defaults to pfn_is_valid() but > calls memblock_is_nomap() for arm64 or does something equivalent. I thought the adjust_managed_page_count() code was just fiddling with some counters. I will change it to call SetPageReserved() directly which will just set the bit in struct page's flags. I will post these shortly as the 'fixes' way of solving the hibernate fallout. I guess any arch that uses memblock nomap needs core code to take account of it, but at the moment that is just arm/arm64. If we are adding new pfn_is_ calls, we could try and clean up pfn_valid() users to use pfn_is_memory(), pfn_is_mapped() or pfn_has_memmap(). Part of the problem is 'valid' means different things to different people. > The question arises what to do with that mem at all. There could be > mappings by the kernel, e.g. of acpi tables. We can't assume the mem > regions still come out the same from the BIOS during resume. Unfortunately we have to assume this. If the firmware reserved regions move around in memory we can't resume from hibernate. Other OS also require this not to happen. ([0] 'firmware memory requirements') Hibernate core code checks the number of pages of kernel memory is the same before trying to resume. If you just move the allocations around this will panic during resume as the resume kernel will have surprising holes in its linear map. x86 recently grew an MD5sum check of the e820 memory map, I intend to do the same for memblock. The theory is this would only happen if you change the hardware in some way, and that otherwise the firmware is entirely deterministic... > Do we > need to save the mem? I can't answer that as I don't know much about > hibernation yet. Hibernate only save/restores the linear map and CPU state. We expect firmware to put equivalent data in the same places for its nomap regions. If the region belongs to a device, its up to the device driver to tidy up. (It has freeze/thaw/resume callbacks to do this). Thanks, James [0] https://msdn.microsoft.com/en-gb/windows/hardware/commercialize/manufacture/desktop/uefi-requirements-boot-time-runtime-hibernation-state--s4
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web