All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Michal Hocko <mhocko@suse.com>,
	Pavel Tatashin <pasha.tatashin@soleen.com>,
	Heiko Carstens <heiko.carstens@de.ibm.com>,
	Martin Schwidefsky <schwidefsky@de.ibm.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Sasha Levin <sashal@kernel.org>,
	linux-mm@kvack.org
Subject: [PATCH AUTOSEL 4.9 28/32] mm, memory_hotplug: is_mem_section_removable do not pass the end of a zone
Date: Sat, 23 Feb 2019 16:09:47 -0500	[thread overview]
Message-ID: <20190223210951.202268-28-sashal@kernel.org> (raw)
In-Reply-To: <20190223210951.202268-1-sashal@kernel.org>

From: Michal Hocko <mhocko@suse.com>

[ Upstream commit efad4e475c312456edb3c789d0996d12ed744c13 ]

Patch series "mm, memory_hotplug: fix uninitialized pages fallouts", v2.

Mikhail Zaslonko has posted fixes for the two bugs quite some time ago
[1].  I have pushed back on those fixes because I believed that it is
much better to plug the problem at the initialization time rather than
play whack-a-mole all over the hotplug code and find all the places
which expect the full memory section to be initialized.

We have ended up with commit 2830bf6f05fb ("mm, memory_hotplug:
initialize struct pages for the full memory section") merged and cause a
regression [2][3].  The reason is that there might be memory layouts
when two NUMA nodes share the same memory section so the merged fix is
simply incorrect.

In order to plug this hole we really have to be zone range aware in
those handlers.  I have split up the original patch into two.  One is
unchanged (patch 2) and I took a different approach for `removable'
crash.

[1] http://lkml.kernel.org/r/20181105150401.97287-2-zaslonko@linux.ibm.com
[2] https://bugzilla.redhat.com/show_bug.cgi?id=1666948
[3] http://lkml.kernel.org/r/20190125163938.GA20411@dhcp22.suse.cz

This patch (of 2):

Mikhail has reported the following VM_BUG_ON triggered when reading sysfs
removable state of a memory block:

 page:000003d08300c000 is uninitialized and poisoned
 page dumped because: VM_BUG_ON_PAGE(PagePoisoned(p))
 Call Trace:
   is_mem_section_removable+0xb4/0x190
   show_mem_removable+0x9a/0xd8
   dev_attr_show+0x34/0x70
   sysfs_kf_seq_show+0xc8/0x148
   seq_read+0x204/0x480
   __vfs_read+0x32/0x178
   vfs_read+0x82/0x138
   ksys_read+0x5a/0xb0
   system_call+0xdc/0x2d8
 Last Breaking-Event-Address:
   is_mem_section_removable+0xb4/0x190
 Kernel panic - not syncing: Fatal exception: panic_on_oops

The reason is that the memory block spans the zone boundary and we are
stumbling over an unitialized struct page.  Fix this by enforcing zone
range in is_mem_section_removable so that we never run away from a zone.

Link: http://lkml.kernel.org/r/20190128144506.15603-2-mhocko@kernel.org
Signed-off-by: Michal Hocko <mhocko@suse.com>
Reported-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Debugged-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Tested-by: Gerald Schaefer <gerald.schaefer@de.ibm.com>
Tested-by: Mikhail Gavrilov <mikhail.v.gavrilov@gmail.com>
Reviewed-by: Oscar Salvador <osalvador@suse.de>
Cc: Pavel Tatashin <pasha.tatashin@soleen.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 mm/memory_hotplug.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index e4c2712980741..a03a401f11b69 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -1471,7 +1471,8 @@ static struct page *next_active_pageblock(struct page *page)
 bool is_mem_section_removable(unsigned long start_pfn, unsigned long nr_pages)
 {
 	struct page *page = pfn_to_page(start_pfn);
-	struct page *end_page = page + nr_pages;
+	unsigned long end_pfn = min(start_pfn + nr_pages, zone_end_pfn(page_zone(page)));
+	struct page *end_page = pfn_to_page(end_pfn);
 
 	/* Check the starting page of each pageblock within the range */
 	for (; page < end_page; page = next_active_pageblock(page)) {
-- 
2.19.1


  parent reply	other threads:[~2019-02-23 21:10 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-23 21:09 [PATCH AUTOSEL 4.9 01/32] vti4: Fix a ipip packet processing bug in 'IPCOMP' virtual tunnel Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 02/32] xfrm: refine validation of template and selector families Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 03/32] perf core: Fix perf_proc_update_handler() bug Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 04/32] perf tools: Handle TOPOLOGY headers with no CPU Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 05/32] IB/{hfi1, qib}: Fix WC.byte_len calculation for UD_SEND_WITH_IMM Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 06/32] iommu/amd: Call free_iova_fast with pfn in map_sg Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 07/32] iommu/amd: Unmap all mapped pages in error path of map_sg Sasha Levin
2019-02-23 21:09   ` Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 08/32] ipvs: Fix signed integer overflow when setsockopt timeout Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 09/32] iommu/amd: Fix IOMMU page flush when detach device from a domain Sasha Levin
2019-02-23 21:09   ` Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 10/32] xtensa: SMP: fix ccount_timer_shutdown Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 11/32] xtensa: SMP: fix secondary CPU initialization Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 12/32] xtensa: smp_lx200_defconfig: fix vectors clash Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 13/32] xtensa: SMP: mark each possible CPU as present Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 14/32] xtensa: SMP: limit number of possible CPUs by NR_CPUS Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 15/32] net: altera_tse: fix msgdma_tx_completion on non-zero fill_level case Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 16/32] net: hns: Fix for missing of_node_put() after of_parse_phandle() Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 17/32] net: hns: Fix wrong read accesses via Clause 45 MDIO protocol Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 18/32] net: stmmac: dwmac-rk: fix error handling in rk_gmac_powerup() Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 19/32] gpio: vf610: Mask all GPIO interrupts Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 20/32] nfs: Fix NULL pointer dereference of dev_name Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 21/32] qed: Fix VF probe failure while FLR Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 22/32] scsi: libfc: free skb when receiving invalid flogi resp Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 23/32] platform/x86: Fix unmet dependency warning for SAMSUNG_Q10 Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 24/32] cifs: fix computation for MAX_SMB2_HDR_SIZE Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 25/32] arm64: kprobe: Always blacklist the KVM world-switch code Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 26/32] x86/kexec: Don't setup EFI info if EFI runtime is not enabled Sasha Levin
2019-02-23 21:09   ` Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 27/32] x86_64: increase stack size for KASAN_EXTRA Sasha Levin
2019-02-23 21:09 ` Sasha Levin [this message]
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 29/32] mm, memory_hotplug: test_pages_in_a_zone do not pass the end of zone Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 30/32] fs/drop_caches.c: avoid softlockups in drop_pagecache_sb() Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 31/32] autofs: drop dentry reference only when it is never used Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 32/32] autofs: fix error return in autofs_fill_super() Sasha Levin

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=20190223210951.202268-28-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=heiko.carstens@de.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=pasha.tatashin@soleen.com \
    --cc=schwidefsky@de.ibm.com \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.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.