All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chao Fan <fanc.fnst@cn.fujitsu.com>
To: Baoquan He <bhe@redhat.com>
Cc: <akpm@linux-foundation.org>, <linux-mm@kvack.org>,
	<linux-kernel@vger.kernel.org>, <x86@kernel.org>,
	<yasu.isimatu@gmail.com>, <keescook@chromium.org>,
	<indou.takao@jp.fujitsu.com>, <caoj.fnst@cn.fujitsu.com>,
	<douly.fnst@cn.fujitsu.com>, <mhocko@suse.com>, <vbabka@suse.cz>,
	<mgorman@techsingularity.net>, <fanc.fnst@cn.fujitsu.com>
Subject: Re: Bug report about KASLR and ZONE_MOVABLE
Date: Thu, 12 Jul 2018 09:19:54 +0800	[thread overview]
Message-ID: <20180712011954.GC6742@localhost.localdomain> (raw)
In-Reply-To: <20180711124008.GF2070@MiWiFi-R3L-srv>

On Wed, Jul 11, 2018 at 08:40:08PM +0800, Baoquan He wrote:
>Please try this v3 patch:
>
>From 9850d3de9c02e570dc7572069a9749a8add4c4c7 Mon Sep 17 00:00:00 2001
>From: Baoquan He <bhe@redhat.com>
>Date: Wed, 11 Jul 2018 20:31:51 +0800
>Subject: [PATCH v3] mm, page_alloc: find movable zone after kernel text
>
>In find_zone_movable_pfns_for_nodes(), when try to find the starting
>PFN movable zone begins in each node, kernel text position is not
>considered. KASLR may put kernel after which movable zone begins.
>
>Fix it by finding movable zone after kernel text on that node.
>
>Signed-off-by: Baoquan He <bhe@redhat.com>
>---
> mm/page_alloc.c | 20 +++++++++++++++-----
> 1 file changed, 15 insertions(+), 5 deletions(-)
>
>diff --git a/mm/page_alloc.c b/mm/page_alloc.c
>index 1521100..390eb35 100644
>--- a/mm/page_alloc.c
>+++ b/mm/page_alloc.c
>@@ -6547,7 +6547,7 @@ static unsigned long __init early_calculate_totalpages(void)
> static void __init find_zone_movable_pfns_for_nodes(void)
> {
> 	int i, nid;
>-	unsigned long usable_startpfn;
>+	unsigned long usable_startpfn, real_startpfn;
> 	unsigned long kernelcore_node, kernelcore_remaining;
> 	/* save the state before borrow the nodemask */
> 	nodemask_t saved_node_state = node_states[N_MEMORY];
>@@ -6681,10 +6681,20 @@ static void __init find_zone_movable_pfns_for_nodes(void)
> 			if (start_pfn >= end_pfn)
> 				continue;

Hi Baoquan,

Thanks for your quick reply and PATCH.
I think it can work well after reviewing the code. But I think the new
variable 'real_startpfn' is unnecessary. How about this:

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 6d00f746c2fd..0fc9c4283947 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -6492,6 +6492,10 @@ static void __init find_zone_movable_pfns_for_nodes(void)
                        if (start_pfn >= end_pfn)
                                continue;

+                       if (pfn_to_nid(PFN_UP(_etext)) == i)
+                               usable_startpfn = max(usable_startpfn,
+                                                 PFN_UP(_etext));
+
                        /* Account for what is only usable for kernelcore */
                        if (start_pfn < usable_startpfn) {
                                unsigned long kernel_pages;

I think the logic of these two method are the same, and this method
change less code. If I am wrong, please let me know.

Thanks,
Chao Fan

> 
>+			/*
>+			 * KASLR may put kernel near tail of node memory,
>+			 * start after kernel on that node to find PFN
>+			 * which zone begins.
>+			 */
>+			if (pfn_to_nid(PFN_UP(_etext)) == i)
>+				real_startpfn = max(usable_startpfn,
>+						PFN_UP(_etext))
>+			else
>+				real_startpfn = usable_startpfn;
> 			/* Account for what is only usable for kernelcore */
>-			if (start_pfn < usable_startpfn) {
>+			if (start_pfn < real_startpfn) {
> 				unsigned long kernel_pages;
>-				kernel_pages = min(end_pfn, usable_startpfn)
>+				kernel_pages = min(end_pfn, real_startpfn)
> 								- start_pfn;
> 
> 				kernelcore_remaining -= min(kernel_pages,
>@@ -6693,7 +6703,7 @@ static void __init find_zone_movable_pfns_for_nodes(void)
> 							required_kernelcore);
> 
> 				/* Continue if range is now fully accounted */
>-				if (end_pfn <= usable_startpfn) {
>+				if (end_pfn <= real_startpfn) {
> 
> 					/*
> 					 * Push zone_movable_pfn to the end so
>@@ -6704,7 +6714,7 @@ static void __init find_zone_movable_pfns_for_nodes(void)
> 					zone_movable_pfn[nid] = end_pfn;
> 					continue;
> 				}
>-				start_pfn = usable_startpfn;
>+				start_pfn = real_startpfn;
> 			}
> 
> 			/*
>-- 
>2.1.0
>
>
>



WARNING: multiple messages have this Message-ID (diff)
From: Chao Fan <fanc.fnst@cn.fujitsu.com>
To: Baoquan He <bhe@redhat.com>
Cc: akpm@linux-foundation.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org, x86@kernel.org,
	yasu.isimatu@gmail.com, keescook@chromium.org,
	indou.takao@jp.fujitsu.com, caoj.fnst@cn.fujitsu.com,
	douly.fnst@cn.fujitsu.com, mhocko@suse.com, vbabka@suse.cz,
	mgorman@techsingularity.net, fanc.fnst@cn.fujitsu.com
Subject: Re: Bug report about KASLR and ZONE_MOVABLE
Date: Thu, 12 Jul 2018 09:19:54 +0800	[thread overview]
Message-ID: <20180712011954.GC6742@localhost.localdomain> (raw)
In-Reply-To: <20180711124008.GF2070@MiWiFi-R3L-srv>

On Wed, Jul 11, 2018 at 08:40:08PM +0800, Baoquan He wrote:
>Please try this v3 patch:
>
>From 9850d3de9c02e570dc7572069a9749a8add4c4c7 Mon Sep 17 00:00:00 2001
>From: Baoquan He <bhe@redhat.com>
>Date: Wed, 11 Jul 2018 20:31:51 +0800
>Subject: [PATCH v3] mm, page_alloc: find movable zone after kernel text
>
>In find_zone_movable_pfns_for_nodes(), when try to find the starting
>PFN movable zone begins in each node, kernel text position is not
>considered. KASLR may put kernel after which movable zone begins.
>
>Fix it by finding movable zone after kernel text on that node.
>
>Signed-off-by: Baoquan He <bhe@redhat.com>
>---
> mm/page_alloc.c | 20 +++++++++++++++-----
> 1 file changed, 15 insertions(+), 5 deletions(-)
>
>diff --git a/mm/page_alloc.c b/mm/page_alloc.c
>index 1521100..390eb35 100644
>--- a/mm/page_alloc.c
>+++ b/mm/page_alloc.c
>@@ -6547,7 +6547,7 @@ static unsigned long __init early_calculate_totalpages(void)
> static void __init find_zone_movable_pfns_for_nodes(void)
> {
> 	int i, nid;
>-	unsigned long usable_startpfn;
>+	unsigned long usable_startpfn, real_startpfn;
> 	unsigned long kernelcore_node, kernelcore_remaining;
> 	/* save the state before borrow the nodemask */
> 	nodemask_t saved_node_state = node_states[N_MEMORY];
>@@ -6681,10 +6681,20 @@ static void __init find_zone_movable_pfns_for_nodes(void)
> 			if (start_pfn >= end_pfn)
> 				continue;

Hi Baoquan,

Thanks for your quick reply and PATCH.
I think it can work well after reviewing the code. But I think the new
variable 'real_startpfn' is unnecessary. How about this:

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 6d00f746c2fd..0fc9c4283947 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -6492,6 +6492,10 @@ static void __init find_zone_movable_pfns_for_nodes(void)
                        if (start_pfn >= end_pfn)
                                continue;

+                       if (pfn_to_nid(PFN_UP(_etext)) == i)
+                               usable_startpfn = max(usable_startpfn,
+                                                 PFN_UP(_etext));
+
                        /* Account for what is only usable for kernelcore */
                        if (start_pfn < usable_startpfn) {
                                unsigned long kernel_pages;

I think the logic of these two method are the same, and this method
change less code. If I am wrong, please let me know.

Thanks,
Chao Fan

> 
>+			/*
>+			 * KASLR may put kernel near tail of node memory,
>+			 * start after kernel on that node to find PFN
>+			 * which zone begins.
>+			 */
>+			if (pfn_to_nid(PFN_UP(_etext)) == i)
>+				real_startpfn = max(usable_startpfn,
>+						PFN_UP(_etext))
>+			else
>+				real_startpfn = usable_startpfn;
> 			/* Account for what is only usable for kernelcore */
>-			if (start_pfn < usable_startpfn) {
>+			if (start_pfn < real_startpfn) {
> 				unsigned long kernel_pages;
>-				kernel_pages = min(end_pfn, usable_startpfn)
>+				kernel_pages = min(end_pfn, real_startpfn)
> 								- start_pfn;
> 
> 				kernelcore_remaining -= min(kernel_pages,
>@@ -6693,7 +6703,7 @@ static void __init find_zone_movable_pfns_for_nodes(void)
> 							required_kernelcore);
> 
> 				/* Continue if range is now fully accounted */
>-				if (end_pfn <= usable_startpfn) {
>+				if (end_pfn <= real_startpfn) {
> 
> 					/*
> 					 * Push zone_movable_pfn to the end so
>@@ -6704,7 +6714,7 @@ static void __init find_zone_movable_pfns_for_nodes(void)
> 					zone_movable_pfn[nid] = end_pfn;
> 					continue;
> 				}
>-				start_pfn = usable_startpfn;
>+				start_pfn = real_startpfn;
> 			}
> 
> 			/*
>-- 
>2.1.0
>
>
>

  parent reply	other threads:[~2018-07-12  1:21 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-11  9:42 Bug report about KASLR and ZONE_MOVABLE Chao Fan
2018-07-11 10:04 ` Chao Fan
2018-07-11 10:16 ` Chao Fan
2018-07-11 10:41 ` Baoquan He
2018-07-11 10:41   ` Baoquan He
2018-07-11 10:49   ` Baoquan He
2018-07-11 10:49     ` Baoquan He
2018-07-11 12:40     ` Baoquan He
2018-07-11 12:40       ` Baoquan He
2018-07-11 17:59       ` [PATCH v3] mm, page_alloc: find movable zone after kernel text kbuild test robot
2018-07-11 19:02       ` kbuild test robot
2018-07-12  1:19       ` Chao Fan [this message]
2018-07-12  1:19         ` Bug report about KASLR and ZONE_MOVABLE Chao Fan
2018-07-12 12:08         ` Baoquan He
2018-07-12  5:49       ` Dou Liyang
2018-07-12  5:49         ` Dou Liyang
2018-07-12  6:01         ` Chao Fan
2018-07-12  6:01           ` Chao Fan
2018-07-12 12:32           ` Michal Hocko
2018-07-12 23:52             ` Baoquan He
2018-07-12 23:52               ` Baoquan He
2018-07-13  1:44               ` Chao Fan
2018-07-13  1:44                 ` Chao Fan
2018-07-16 11:38               ` Michal Hocko
2018-07-16 13:02                 ` Baoquan He
2018-07-16 15:24                   ` Michal Hocko
2018-07-17  1:51                     ` Baoquan He
2018-07-17  8:22                       ` Michal Hocko
2018-07-11 12:41     ` Baoquan He

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=20180712011954.GC6742@localhost.localdomain \
    --to=fanc.fnst@cn.fujitsu.com \
    --cc=akpm@linux-foundation.org \
    --cc=bhe@redhat.com \
    --cc=caoj.fnst@cn.fujitsu.com \
    --cc=douly.fnst@cn.fujitsu.com \
    --cc=indou.takao@jp.fujitsu.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@techsingularity.net \
    --cc=mhocko@suse.com \
    --cc=vbabka@suse.cz \
    --cc=x86@kernel.org \
    --cc=yasu.isimatu@gmail.com \
    /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.