linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: linux-kernel@vger.kernel.org, Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org, Qian Cai <cai@lca.pw>,
	Vlastimil Babka <vbabka@suse.cz>, Michal Hocko <mhocko@suse.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	"Peter Zijlstra (Intel)" <peterz@infradead.org>,
	Miles Chen <miles.chen@mediatek.com>,
	Mike Rapoport <rppt@linux.vnet.ibm.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: Re: [PATCH v2] mm/page_owner: Don't access uninitialized memmaps when reading /proc/pagetypeinfo
Date: Mon, 14 Oct 2019 10:36:24 +0200	[thread overview]
Message-ID: <56134a52-6113-c501-395f-30eb53b1408d@redhat.com> (raw)
In-Reply-To: <20191011140638.8160-1-david@redhat.com>

On 11.10.19 16:06, David Hildenbrand wrote:
> From: Qian Cai <cai@lca.pw>
> 
> Uninitialized memmaps contain garbage and in the worst case trigger
> kernel BUGs, especially with CONFIG_PAGE_POISONING. They should not get
> touched.
> 
> For example, when not onlining a memory block that is spanned by a zone
> and reading /proc/pagetypeinfo with CONFIG_DEBUG_VM_PGFLAGS and
> CONFIG_PAGE_POISONING, we can trigger a kernel BUG:
> 
> :/# echo 1 > /sys/devices/system/memory/memory40/online
> :/# echo 1 > /sys/devices/system/memory/memory42/online
> :/# cat /proc/pagetypeinfo > test.file
>    [   42.489856] page:fffff2c585200000 is uninitialized and poisoned
>    [   42.489861] raw: ffffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffff
>    [   42.492235] raw: ffffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffff
>    [   42.493501] page dumped because: VM_BUG_ON_PAGE(PagePoisoned(p))
>    [   42.494533] There is not page extension available.
>    [   42.495358] ------------[ cut here ]------------
>    [   42.496163] kernel BUG at include/linux/mm.h:1107!
>    [   42.497069] invalid opcode: 0000 [#1] SMP NOPTI
> 
> Please not that this change does not affect ZONE_DEVICE, because
> pagetypeinfo_showmixedcount_print() is called from
> mm/vmstat.c:pagetypeinfo_showmixedcount() only for populated zones, and
> ZONE_DEVICE is never populated (zone->present_pages always 0).
> 
> Fixes: f1dd2cd13c4b ("mm, memory_hotplug: do not associate hotadded memory to zones until online") # visible after d0dc12e86b319
> Signed-off-by: Qian Cai <cai@lca.pw>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Vlastimil Babka <vbabka@suse.cz>
> Cc: Michal Hocko <mhocko@suse.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: "Peter Zijlstra (Intel)" <peterz@infradead.org>
> Cc: Miles Chen <miles.chen@mediatek.com>
> Cc: Mike Rapoport <rppt@linux.vnet.ibm.com>
> Cc: Qian Cai <cai@lca.pw>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> [ move check to outer loop, add comment, rephrase description ]
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
> 
> Cai asked me to follow up on:
> 	[PATCH] mm/page_owner: fix a crash after memory offline
> 
> ---
>   mm/page_owner.c | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/page_owner.c b/mm/page_owner.c
> index dee931184788..7d149211f6be 100644
> --- a/mm/page_owner.c
> +++ b/mm/page_owner.c
> @@ -284,7 +284,8 @@ void pagetypeinfo_showmixedcount_print(struct seq_file *m,
>   	 * not matter as the mixed block count will still be correct
>   	 */
>   	for (; pfn < end_pfn; ) {
> -		if (!pfn_valid(pfn)) {
> +		page = pfn_to_online_page(pfn);
> +		if (!page) {
>   			pfn = ALIGN(pfn + 1, MAX_ORDER_NR_PAGES);
>   			continue;
>   		}
> @@ -292,13 +293,13 @@ void pagetypeinfo_showmixedcount_print(struct seq_file *m,
>   		block_end_pfn = ALIGN(pfn + 1, pageblock_nr_pages);
>   		block_end_pfn = min(block_end_pfn, end_pfn);
>   
> -		page = pfn_to_page(pfn);
>   		pageblock_mt = get_pageblock_migratetype(page);
>   
>   		for (; pfn < block_end_pfn; pfn++) {
>   			if (!pfn_valid_within(pfn))
>   				continue;
>   
> +			/* The pageblock is online, no need to recheck. */
>   			page = pfn_to_page(pfn);
>   
>   			if (page_zone(page) != zone)
> 

I guess it's best to just

Cc: stable@vger.kernel.org # v4.13+

here as well. Can be cheery-picked.

@Andrew, can you add that?

-- 

Thanks,

David / dhildenb


  parent reply	other threads:[~2019-10-14  8:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-11 14:06 [PATCH v2] mm/page_owner: Don't access uninitialized memmaps when reading /proc/pagetypeinfo David Hildenbrand
2019-10-14  8:30 ` Vlastimil Babka
2019-10-14  8:36 ` David Hildenbrand [this message]
2019-10-14  8:44 ` Michal Hocko

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=56134a52-6113-c501-395f-30eb53b1408d@redhat.com \
    --to=david@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=cai@lca.pw \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=miles.chen@mediatek.com \
    --cc=peterz@infradead.org \
    --cc=rppt@linux.vnet.ibm.com \
    --cc=tglx@linutronix.de \
    --cc=vbabka@suse.cz \
    /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 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).