[PATCH] gpiolib: fix possible use after free on label

2018-10-24 Thread Muchun Song
(), gpiochip_is_requested()). To be on the safe side: duplicate the string with kstrdup_const() so that if an unaware user passes an address to a stack-allocated buffer, we won't get the arbitrary label. Signed-off-by: Muchun Song --- drivers/gpio/gpiolib.c | 9 + 1 file changed, 9 insertions(+) diff

[PATCH] sched/core: Introduce set_next_task() helper for better code readability

2018-10-26 Thread Muchun Song
ake the code more readable. Signed-off-by: Muchun Song --- kernel/sched/deadline.c | 19 ++- kernel/sched/rt.c | 24 +++- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c index 91e4202b0

Re: [PATCH] gpiolib: fix possible use after free on label

2018-10-31 Thread Muchun Song
Hi Linus, Thanks for your review. Linus Walleij 于2018年10月31日周三 下午6:32写道: > > Hi Muchun, > > thanks for your patch! > > On Wed, Oct 24, 2018 at 3:41 PM Muchun Song wrote: > > > gpiod_request_commit() copies the pointer to the label > > passed as an argument o

[PATCH v2] gpiolib: Fix possible use after free on label

2018-11-01 Thread Muchun Song
(), gpiochip_is_requested()). To be on the safe side: duplicate the string with kstrdup_const() so that if an unaware user passes an address to a stack-allocated buffer, we won't get the arbitrary label. Also fix gpiod_set_consumer_name(). Signed-off-by: Muchun Song --- drivers/gpio/gpiolib.c| 25

[PATCH v2] sched/core: Introduce set_next_task() helper for better code readability

2018-11-01 Thread Muchun Song
rev, struct rq_flags *rf) { /* do something else ... */ put_prev_task(rq, prev); /* pick next task p */ set_next_task(rq, p); /* do something else ... */ } put_prev_task() can match set_next_task(), which can make the code more readable. Signed-off-by: Muc

[PATCH] sched/rt: Remove unnecessary CONFIG_RT_GROUP_SCHED in rt_se_prio()

2018-10-30 Thread Muchun Song
When CONFIG_RT_GROUP_SCHED is not configured, group_rt_rq() will return NULL. With this patch applied, we also can get the same result. Because the compiler will help us optimize the code. So, we can remove unnecessary CONFIG_RT_GROUP_SCHED in rt_se_prio(). Signed-off-by: Muchun Song

[PATCH RESEND] gpiolib: Fix possible use after free on label

2018-10-30 Thread Muchun Song
(), gpiochip_is_requested()). To be on the safe side: duplicate the string with kstrdup_const() so that if an unaware user passes an address to a stack-allocated buffer, we won't get the arbitrary label. Signed-off-by: Muchun Song --- drivers/gpio/gpiolib.c | 9 + 1 file changed, 9 insertions(+) diff

[PATCH] sched/rt: Fix a comment in pick_next_task_rt()

2018-10-26 Thread Muchun Song
d. Fix the comment in pick_next_task_rt() to avoid confusing. Signed-off-by: Muchun Song --- kernel/sched/rt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c index 2e2955a8cf8f..a21ea6021929 100644 --- a/kernel/sched/rt.c +++ b/kernel/sched/rt.c

[PATCH] sched/rt: Remove unnecessary check for next_task in push_rt_task()

2018-11-02 Thread Muchun Song
uct rq *rq) { BUG_ON(task_current(rq, p)); } The task_current() will check if task p and rq->curr are equal. So, we can remove the unnecessary check in push_rt_task(). Signed-off-by: Muchun Song --- kernel/sched/rt.c | 5 - 1 file changed, 5 deletions(-) diff --git a/kernel

[PATCH v2] sched/core: Remove unnecessary check for next_task in push_{rt,dl}_task()

2018-11-03 Thread Muchun Song
uct *pick_next_pushable{_dl}_task(struct rq *rq) { BUG_ON(task_current(rq, p)); } The task_current() will check if task p and rq->curr are equal. So, we can remove the unnecessary check in push_{rt,dl}_task(). Signed-off-by: Muchun Song --- Changes in v2: -also remove unnecessary

Re: [PATCH v2] sched/core: Introduce set_next_task() helper for better code readability

2018-11-01 Thread Muchun Song
Hi, Peter Thanks for your review. Just update commit message. So there is no difference between them on the code. Yours, Muchun Song Peter Zijlstra 于2018年11月2日周五 上午12:52写道: > > > > What if anything is the difference with v1 (which I found yesterday and > have pending testing).

[PATCH] driver core: Replace simple_strtol by kstrtoint

2018-10-28 Thread Muchun Song
The simple_strtol() function is deprecated, use kstrtoint() instead. Signed-off-by: Muchun Song --- drivers/base/dd.c | 5 - 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/base/dd.c b/drivers/base/dd.c index 169412ee4ae8..940abad069c0 100644 --- a/drivers/base/dd.c

Re: [PATCH] sched/rt: Introduce prio_{higher,lower}() helper for comparing RT task prority

2018-11-07 Thread Muchun Song
Hi Peter, Thanks for your review. Peter Zijlstra 于2018年11月8日周四 上午1:31写道: > > On Thu, Nov 08, 2018 at 12:15:05AM +0800, Muchun Song wrote: > > We use a value to represent the priority of the RT task. But a smaller > > value corresponds to a higher priority. If there are t

Re: [PATCH] sched/rt: Introduce prio_lower() helper for comparing RT task prority

2018-11-08 Thread Muchun Song
Hi Peter, This is v2 patch. I'm sorry that I forgot to add the word "v2" to the subject. Yours, Muchun Song

[PATCH] sched/rt: Introduce prio_lower() helper for comparing RT task prority

2018-11-08 Thread Muchun Song
readable. Signed-off-by: Muchun Song --- kernel/sched/rt.c | 54 --- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c index 9aa3287ce301..4808684607b9 100644 --- a/kernel/sched/rt.c +++ b/kernel/sched/rt.c

[PATCH] sched/fair: Make some variables static

2018-11-09 Thread Muchun Song
The variables are local to the source and do not need to be in global scope, so make them static. Signed-off-by: Muchun Song --- kernel/sched/fair.c | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index f622fc858d7a

Re: [PATCH] sched/rt: Introduce prio_{higher,lower}() helper for comparing RT task prority

2018-11-12 Thread Muchun Song
Hi Peter, Ingo Molnar 于2018年11月12日周一 下午2:57写道: > > > * Peter Zijlstra wrote: > > > I think you only need the less thing, because: > > > > static inline bool prio_lower(int a, int b) > > { > > return a > b; > > } > > I'd say that should be named rt_prio_lower(), even if it's local to >

[PATCH] driver core: Add branch prediction hints in really_probe()

2018-11-06 Thread Muchun Song
If condition is false in most cases. So, add an unlikely() to the if condition, so that the optimizer assumes that the condition is false. Signed-off-by: Muchun Song --- drivers/base/dd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/base/dd.c b/drivers/base

[PATCH v3] sched/rt: Introduce rt_prio_lower() helper for comparing RT task prority

2018-11-14 Thread Muchun Song
readable. Signed-off-by: Muchun Song --- kernel/sched/rt.c | 57 +-- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c index 9aa3287ce301..f28157c8212b 100644 --- a/kernel/sched/rt.c +++ b/kernel/sched

[PATCH] sched/fair: Clean up update_blocked_averages()

2018-11-14 Thread Muchun Song
is enabled or not. That is rt, dl and irq's load_avg update. So let the update_others_load_avg() do it. Signed-off-by: Muchun Song --- kernel/sched/fair.c | 59 + 1 file changed, 38 insertions(+), 21 deletions(-) diff --git a/kernel/sched/fair.c b/kernel

[PATCH] sched/fair: Make capacity_margin static

2018-11-08 Thread Muchun Song
The variable capacity_margin local to the source and do not need to be in global scope, so make it static. Signed-off-by: Muchun Song --- kernel/sched/fair.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 340a2d8d49cb

[PATCH] sched/rt: Introduce prio_{higher,lower}() helper for comparing RT task prority

2018-11-07 Thread Muchun Song
more readable. Signed-off-by: Muchun Song --- kernel/sched/rt.c | 68 --- 1 file changed, 46 insertions(+), 22 deletions(-) diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c index 9aa3287ce301..adf0f653c963 100644 --- a/kernel/sched/rt.c +++ b/kernel

Re: [PATCH] driver core: Add branch prediction hints in really_probe()

2018-11-06 Thread Muchun Song
11月6日周二 下午10:30写道: > > On Tue, Nov 6, 2018 at 2:47 PM Muchun Song wrote: > > > > If condition is false in most cases. So, add an unlikely() to the if > > condition, so that the optimizer assumes that the condition is false. > > > > Signed-off-by: Muchun Song

Re: [PATCH] driver core: Add branch prediction hints in really_probe()

2018-11-06 Thread Muchun Song
Hi Rafael, > > On Tue, Nov 6, 2018 at 3:43 PM Muchun Song wrote: > > > > Hi Rafael, > > > > If we want the driver core to test driver remove functions, we can > > enable CONFIG_DEBUG_TEST_DRIVER_REMOVE. This option is > > just for testing it.

[PATCH] sched/rt: Add a check for calling update_curr_rt()

2018-11-06 Thread Muchun Song
We may dequeue prev's rt_rq in put_prev_task() only when RT bandwidth is enabled. If RT bandwidth is disabled, it is unnecessary for us to call update_curr_rt(). So we add a check there. Signed-off-by: Muchun Song --- kernel/sched/rt.c | 7 --- 1 file changed, 4 insertions(+), 3 deletions

Re: [PATCH] timers: Make the lower-level timer function first call than higher-level

2018-11-19 Thread Muchun Song
Hi John, Thanks for your review. John Stultz 于2018年11月20日周二 上午2:16写道: > > On Mon, Nov 19, 2018 at 6:10 AM, Muchun Song wrote: > > The elements of the heads array are a linked list of timer events that > > expire at the current time. And it can contain up to LVL_DEPTH levels

[PATCH RESEND v2] sched/core: Remove unnecessary check for next_task in push_{rt,dl}_task()

2018-11-26 Thread Muchun Song
uct *pick_next_pushable{_dl}_task(struct rq *rq) { BUG_ON(task_current(rq, p)); return p; } The task_current() will check if task p and rq->curr are equal. So, we can remove the unnecessary check in push_{rt,dl}_task(). Signed-off-by: Muchun Song --- kernel/sched/deadline

[PATCH RESEND v3] sched/rt: Introduce rt_prio_lower() helper for comparing RT task prority

2018-11-26 Thread Muchun Song
readable. Signed-off-by: Muchun Song --- kernel/sched/rt.c | 57 +-- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c index 9aa3287ce301..f28157c8212b 100644 --- a/kernel/sched/rt.c +++ b/kernel/sched

Re: [PATCH] timers: Make the lower-level timer function first call than higher-level

2018-11-28 Thread Muchun Song
Hi tglx, I'm sorry. Thanks for your reminder. Thomas Gleixner 于2018年11月28日周三 下午11:15写道: > > Song, > > On Wed, 21 Nov 2018, Thomas Gleixner wrote: > > On Tue, 20 Nov 2018, Muchun Song wrote: > > > Follow the current code logic, the timer0 function is called un

[PATCH RESEND] sched/fair: Clean up update_blocked_averages()

2018-11-26 Thread Muchun Song
is enabled or not. That is rt, dl and irq's load_avg update. So let the update_others_load_avg() do it. Signed-off-by: Muchun Song --- kernel/sched/fair.c | 59 + 1 file changed, 38 insertions(+), 21 deletions(-) diff --git a/kernel/sched/fair.c b/kernel

[PATCH] timers: Make the lower-level timer function first call than higher-level

2018-11-19 Thread Muchun Song
, in the higher-level is called first than the lower-level function. I think it might be better to call the lower-level timer function first than the higher-level function. Because the lower-level has the smaller granularity and delay has less impact on higher-level. So fix it. Signed-off-by: Muchun Song

Re: [External] [PATCH v2 2/5] hugetlb: convert page_huge_active() HPageMigratable flag

2021-01-21 Thread Muchun Song
an_movable_pages already deals with these races, so removing the check > is acceptable. Add comment to racy code. > > Signed-off-by: Mike Kravetz Reviewed-by: Muchun Song Thanks. > --- > fs/hugetlbfs/inode.c | 2 +- > include/linux/hugetlb.h| 5 +++

Re: [External] Re: [PATCH v12 04/13] mm/hugetlb: Free the vmemmap pages associated with each HugeTLB page

2021-01-14 Thread Muchun Song
On Thu, Jan 14, 2021 at 7:52 PM Oscar Salvador wrote: > > On Thu, Jan 14, 2021 at 06:54:30PM +0800, Muchun Song wrote: > > I think this approach may be only suitable for generic huge page only. > > So we can implement it only for huge page. > > > > Hi Oscar, >

Re: [External] Re: [PATCH v5 3/5] mm: hugetlb: fix a race between freeing and dissolving the page

2021-01-14 Thread Muchun Song
On Thu, Jan 14, 2021 at 9:20 PM Michal Hocko wrote: > > On Thu 14-01-21 18:35:13, Muchun Song wrote: > > There is a race condition between __free_huge_page() > > and dissolve_free_huge_page(). > > > > CPU0: CPU1: > > > >

Re: [External] Re: [PATCH v12 04/13] mm/hugetlb: Free the vmemmap pages associated with each HugeTLB page

2021-01-14 Thread Muchun Song
On Tue, Jan 12, 2021 at 4:05 PM Oscar Salvador wrote: > > On Wed, Jan 06, 2021 at 10:19:22PM +0800, Muchun Song wrote: > > Every HugeTLB has more than one struct page structure. We __know__ that > > we only use the first 4(HUGETLB_CGROUP_MIN_ORDER) struct page structures >

[PATCH v5 3/5] mm: hugetlb: fix a race between freeing and dissolving the page

2021-01-14 Thread Muchun Song
tplug: enable memory hotplug to handle hugepage") Signed-off-by: Muchun Song Reviewed-by: Mike Kravetz Cc: sta...@vger.kernel.org --- mm/hugetlb.c | 41 + 1 file changed, 41 insertions(+) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 4741d60f8955..1

[PATCH v5 4/5] mm: hugetlb: fix a race between isolating and freeing page

2021-01-14 Thread Muchun Song
on CPU0. Meanwhile, we free it to the buddy allocator on CPU1. Then, we can trigger a BUG_ON on CPU0. Because it is already freed to the buddy allocator. Fixes: c8721bbbdd36 ("mm: memory-hotplug: enable memory hotplug to handle hugepage") Signed-off-by: Muchun Song Reviewed-by: Mike Krav

[PATCH v5 5/5] mm: hugetlb: remove VM_BUG_ON_PAGE from page_huge_active

2021-01-14 Thread Muchun Song
CONFIG_DEBUG_VM is enabled. Just remove the VM_BUG_ON_PAGE. Fixes: 7e1f049efb86 ("mm: hugetlb: cleanup using paeg_huge_active()") Signed-off-by: Muchun Song Reviewed-by: Mike Kravetz Acked-by: Michal Hocko Cc: sta...@vger.kernel.org --- mm/hugetlb.c | 3 +-- 1 file changed, 1 inser

[PATCH v5 1/5] mm: migrate: do not migrate HugeTLB page whose refcount is one

2021-01-14 Thread Muchun Song
for regular pages and this patch does the same for hugetlb pages. Although the likelyhood of the race is rather small for hugetlb pages it makes sense the two code paths in sync. Signed-off-by: Muchun Song Reviewed-by: Mike Kravetz Acked-by: Yang Shi Acked-by: Michal Hocko Reviewed-by: David

[PATCH v5 0/5] Fix some bugs about HugeTLB code

2021-01-14 Thread Muchun Song
n patch #3. Changelog since v1 -> v2: - Export set_page_huge_active() in patch #2 to fix. - Using head[3].mapping to indicate the page is freed in patch #3. - Flush @free_hpage_work in patch #4. Muchun Song (5): mm: migrate: do not migrate HugeTLB page whose refcount is one mm: hugetlbfs: fix cannot mi

[PATCH v5 2/5] mm: hugetlbfs: fix cannot migrate the fallocated HugeTLB page

2021-01-14 Thread Muchun Song
set_page_huge_active, just leave clear_page_huge_active as static. Because there are no external users. Fixes: 70c3547e36f5 (hugetlbfs: add hugetlbfs_fallocate()) Signed-off-by: Muchun Song Acked-by: Michal Hocko Reviewed-by: Mike Kravetz Reviewed-by: Oscar Salvador Cc: sta...@vger.kernel.org --- fs/hugetlbfs

Re: [External] Re: [PATCH v12 04/13] mm/hugetlb: Free the vmemmap pages associated with each HugeTLB page

2021-01-14 Thread Muchun Song
On Thu, Jan 14, 2021 at 7:27 AM Mike Kravetz wrote: > > On 1/13/21 1:20 AM, Oscar Salvador wrote: > > On Tue, Jan 12, 2021 at 07:33:33PM +0800, Muchun Song wrote: > >>> It seems a bit odd to only pass "start" for the BUG_ON. > >>>

Re: [External] Re: [PATCH 2/5] hugetlb: convert page_huge_active() to HP_Migratable flag

2021-01-15 Thread Muchun Song
On Sat, Jan 16, 2021 at 12:26 PM Matthew Wilcox wrote: > > On Fri, Jan 15, 2021 at 04:31:02PM -0800, Mike Kravetz wrote: > > +++ b/fs/hugetlbfs/inode.c > > @@ -735,7 +735,7 @@ static long hugetlbfs_fallocate(struct file *file, int > > mode, loff_t offset, > > > >

Re: [External] Re: [PATCH v5 3/5] mm: hugetlb: fix a race between freeing and dissolving the page

2021-01-14 Thread Muchun Song
On Thu, Jan 14, 2021 at 11:38 PM Michal Hocko wrote: > > On Thu 14-01-21 21:47:36, Muchun Song wrote: > > On Thu, Jan 14, 2021 at 9:20 PM Michal Hocko wrote: > [...] > > > > @@ -1770,6 +1789,28 @@ int dissolve_free_huge_page(struct page *page) > > > >

Re: [PATCH] hugetlbfs: make BUG_ON(!inode) takes effect in hugetlbfs_setattr

2021-01-18 Thread Muchun Song
On Sat, Jan 16, 2021 at 5:11 PM Miaohe Lin wrote: > > When we reach here with inode = NULL, we should have crashed as inode has > already been dereferenced via hstate_inode. In order to make BUG_ON(!inode) > takes effect, we should defer initializing hstate until we really need it. > Also do this

Re: [External] Re: [PATCH v13 03/12] mm: hugetlb: free the vmemmap pages associated with each HugeTLB page

2021-01-22 Thread Muchun Song
On Sat, Jan 23, 2021 at 9:00 AM Mike Kravetz wrote: > > X-Gm-Spam: 0 > X-Gm-Phishy: 0 > > On 1/17/21 7:10 AM, Muchun Song wrote: > > Every HugeTLB has more than one struct page structure. We __know__ that > > we only use the first 4(HUGETLB_CGROUP_MIN_ORDER) struct p

Re: [External] [PATCH v3 4/5] hugetlb: convert PageHugeTemporary() to HPageTemporary flag

2021-01-22 Thread Muchun Song
within > hugetlb code where we know we are dealing with a hugetlb page. > Therefore, the check can be eliminated. > > Signed-off-by: Mike Kravetz > Reviewed-by: Oscar Salvador Reviewed-by: Muchun Song > --- > include/linux/hugetlb.h |

Re: [External] Re: [PATCH v13 05/12] mm: hugetlb: allocate the vmemmap pages associated with each HugeTLB page

2021-01-25 Thread Muchun Song
On Mon, Jan 25, 2021 at 5:15 PM David Hildenbrand wrote: > > On 25.01.21 08:41, Muchun Song wrote: > > On Mon, Jan 25, 2021 at 2:40 PM Muchun Song > > wrote: > >> > >> On Mon, Jan 25, 2021 at 8:05 AM David Rientjes wrote: > >>> &g

Re: [PATCH v13 00/12] Free some vmemmap pages of HugeTLB page

2021-01-20 Thread Muchun Song
On Sun, Jan 17, 2021 at 11:12 PM Muchun Song wrote: > > Hi all, > > This patch series will free some vmemmap pages(struct page structures) > associated with each hugetlbpage when preallocated to save memory. > > In order to reduce the difficulty of the first version o

Re: [External] [PATCH v2 5/5] hugetlb: convert PageHugeFreed to HPageFreed flag

2021-01-20 Thread Muchun Song
On Wed, Jan 20, 2021 at 9:31 AM Mike Kravetz wrote: > > Use new hugetlb specific HPageFreed flag to replace the > PageHugeFreed interfaces. > > Signed-off-by: Mike Kravetz Reviewed-by: Muchun Song > --- > include/linux/hugetlb.h | 3 +++ > mm/h

Re: [External] Re: [PATCH v13 00/12] Free some vmemmap pages of HugeTLB page

2021-01-20 Thread Muchun Song
On Wed, Jan 20, 2021 at 9:10 PM Oscar Salvador wrote: > > On Wed, Jan 20, 2021 at 08:52:50PM +0800, Muchun Song wrote: > > Hi Oscar and Mike, > > > > Any suggestions about this version? Looking forward to your > > review. Thanks a lot. > > Hi Muchun, > >

Re: [External] Re: [PATCH 3/6] mm: hugetlb: fix a race between freeing and dissolving the page

2021-01-05 Thread Muchun Song
On Wed, Jan 6, 2021 at 7:22 AM Mike Kravetz wrote: > > On 1/4/21 6:55 PM, Muchun Song wrote: > > On Tue, Jan 5, 2021 at 8:02 AM Mike Kravetz wrote: > >> > >> On 1/3/21 10:58 PM, Muchun Song wrote: > >>> There is a race condition between __free_hug

[PATCH v2 0/6] Fix some bugs about HugeTLB code

2021-01-06 Thread Muchun Song
This patch series aims to fix some bugs and add some improvements. Changelog since v1 -> v2: - Export set_page_huge_active() in patch #2 to fix. - Using head[3].mapping to indicate the page is freed in patch #3. - Flush @free_hpage_work in patch #4. Muchun Song (6): mm: migrate:

[PATCH v2 4/6] mm: hugetlb: add return -EAGAIN for dissolve_free_huge_page

2021-01-06 Thread Muchun Song
When dissolve_free_huge_page() races with __free_huge_page(), we can do a retry. Because the race window is small. Signed-off-by: Muchun Song --- mm/hugetlb.c | 26 +- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index

[PATCH v2 2/6] mm: hugetlbfs: fix cannot migrate the fallocated HugeTLB page

2021-01-06 Thread Muchun Song
: 70c3547e36f5 (hugetlbfs: add hugetlbfs_fallocate()) Signed-off-by: Muchun Song --- fs/hugetlbfs/inode.c| 3 ++- include/linux/hugetlb.h | 2 ++ mm/hugetlb.c| 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index b5c109703daa

[PATCH v2 5/6] mm: hugetlb: fix a race between isolating and freeing page

2021-01-06 Thread Muchun Song
on CPU0. Meanwhile, we free it to the buddy allocator on CPU1. Then, we can trigger a BUG_ON on CPU0. Because it is already freed to the buddy allocator. Fixes: c8721bbbdd36 ("mm: memory-hotplug: enable memory hotplug to handle hugepage") Signed-off-by: Muchun Song Reviewed-by: Mi

[PATCH v2 6/6] mm: hugetlb: remove VM_BUG_ON_PAGE from page_huge_active

2021-01-06 Thread Muchun Song
CONFIG_DEBUG_VM is enabled. Just remove the VM_BUG_ON_PAGE. Fixes: 7e1f049efb86 ("mm: hugetlb: cleanup using paeg_huge_active()") Signed-off-by: Muchun Song Reviewed-by: Mike Kravetz --- mm/hugetlb.c | 1 - 1 file changed, 1 deletion(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 67

[PATCH v2 3/6] mm: hugetlb: fix a race between freeing and dissolving the page

2021-01-06 Thread Muchun Song
d36 ("mm: memory-hotplug: enable memory hotplug to handle hugepage") Signed-off-by: Muchun Song --- mm/hugetlb.c | 38 ++ 1 file changed, 38 insertions(+) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 4741d60f8955..8ff138c17129 100644 --- a/mm/hugetlb.c

[PATCH v2 1/6] mm: migrate: do not migrate HugeTLB page whose refcount is one

2021-01-06 Thread Muchun Song
If the refcount is one when it is migrated, it means that the page was freed from under us. So we are done and do not need to migrate. Signed-off-by: Muchun Song Reviewed-by: Mike Kravetz Acked-by: Yang Shi --- mm/migrate.c | 6 ++ 1 file changed, 6 insertions(+) diff --git a/mm

[PATCH v12 00/13] Free some vmemmap pages of HugeTLB page

2021-01-06 Thread Muchun Song
ysis in the cover letter. - Use vmemap pmd table lock instead of a hugetlb specific global lock. Changelog in v1 -> v2: - Fix do not call dissolve_compound_page in alloc_huge_page_vmemmap(). - Fix some typo and code style problems. - Remove unused handle_vmemmap_fault(). - Merge some comm

[PATCH v12 03/13] mm: Introduce VM_WARN_ON_PAGE macro

2021-01-06 Thread Muchun Song
Very similar to VM_WARN_ON_ONCE_PAGE and VM_BUG_ON_PAGE, add VM_WARN_ON_PAGE macro. Signed-off-by: Muchun Song --- include/linux/mmdebug.h | 8 1 file changed, 8 insertions(+) diff --git a/include/linux/mmdebug.h b/include/linux/mmdebug.h index 5d0767cb424a..eff5b13a6945 100644

[PATCH v12 01/13] mm/memory_hotplug: Factor out bootmem core functions to bootmem_info.c

2021-01-06 Thread Muchun Song
any functional change. Signed-off-by: Muchun Song Acked-by: Mike Kravetz Reviewed-by: Oscar Salvador Reviewed-by: David Hildenbrand --- arch/x86/mm/init_64.c | 3 +- include/linux/bootmem_info.h | 40 + include/linux/memory_hotplug.h | 27 - mm/Makefile

[PATCH v12 06/13] mm/hugetlb: Allocate the vmemmap pages associated with each HugeTLB page

2021-01-06 Thread Muchun Song
When we free a HugeTLB page to the buddy allocator, we should allocate the vmemmap pages associated with it. We can do that in the __free_hugepage() before freeing it to buddy. Signed-off-by: Muchun Song --- include/linux/mm.h | 2 ++ mm/hugetlb.c | 2 ++ mm/hugetlb_vmemmap.c | 15

[PATCH v12 04/13] mm/hugetlb: Free the vmemmap pages associated with each HugeTLB page

2021-01-06 Thread Muchun Song
, which means the feature is disabled. We will enable it once all the infrastructure is there. Signed-off-by: Muchun Song --- include/linux/bootmem_info.h | 27 +- include/linux/mm.h | 3 + mm/Makefile | 1 + mm/hugetlb.c | 3 + mm

[PATCH v12 07/13] mm/hugetlb: Set the PageHWPoison to the raw error page

2021-01-06 Thread Muchun Song
Because we reuse the first tail vmemmap page frame and remap it with read-only, we cannot set the PageHWPosion on a tail page. So we can use the head[4].private to record the real error page index and set the raw error page PageHWPoison later. Signed-off-by: Muchun Song Reviewed-by: Oscar

[PATCH v12 11/13] mm/hugetlb: Introduce nr_free_vmemmap_pages in the struct hstate

2021-01-06 Thread Muchun Song
. Signed-off-by: Muchun Song Acked-by: Mike Kravetz Reviewed-by: Oscar Salvador --- include/linux/hugetlb.h | 3 +++ mm/hugetlb.c| 1 + mm/hugetlb_vmemmap.c| 25 + mm/hugetlb_vmemmap.h| 10 ++ 4 files changed, 35 insertions(+), 4 deletions(-) diff

[PATCH v12 09/13] mm/hugetlb: Introduce PageHugeInflight

2021-01-06 Thread Muchun Song
to indicate that the HugeTLB page is already freed from hugepage pool but not freed to buddy allocator yet. When we hit the inflight page, we just need to flush the work. Signed-off-by: Muchun Song --- mm/hugetlb.c | 38 +- 1 file changed, 37 insertions(+), 1

[PATCH v12 08/13] mm/hugetlb: Flush work when dissolving a HugeTLB page

2021-01-06 Thread Muchun Song
We should flush work when dissolving a HugeTLB page to make sure that the HugeTLB page is freed to the buddy allocator. Because the caller of dissolve_free_huge_pages() relies on this guarantee. Signed-off-by: Muchun Song Reviewed-by: Oscar Salvador --- mm/hugetlb.c | 18 +- 1

[PATCH v12 12/13] mm/hugetlb: Gather discrete indexes of tail page

2021-01-06 Thread Muchun Song
. Signed-off-by: Muchun Song Reviewed-by: Oscar Salvador --- include/linux/hugetlb.h| 14 ++ include/linux/hugetlb_cgroup.h | 15 +-- mm/hugetlb.c | 25 - mm/hugetlb_vmemmap.c | 8 4 files changed, 43

[PATCH v12 05/13] mm/hugetlb: Defer freeing of HugeTLB pages

2021-01-06 Thread Muchun Song
GFP_ATOMIC to allocate the vmemmap pages. The update_hpage_vmemmap_workfn() is where the call to allocate vmemmmap pages will be inserted. Signed-off-by: Muchun Song Reviewed-by: Mike Kravetz --- mm/hugetlb.c | 74 ++-- mm/hugetlb_vmemmap.c | 12

[PATCH v12 02/13] mm/hugetlb: Introduce a new config HUGETLB_PAGE_FREE_VMEMMAP

2021-01-06 Thread Muchun Song
other code which frees vmemmap, this config option depends on HAVE_BOOTMEM_INFO_NODE. The routine register_page_bootmem_info() is used to register bootmem info. Therefore, make sure register_page_bootmem_info is enabled if HUGETLB_PAGE_FREE_VMEMMAP is defined. Signed-off-by: Muchun Song Reviewed

[PATCH v12 10/13] mm/hugetlb: Add a kernel parameter hugetlb_free_vmemmap

2021-01-06 Thread Muchun Song
Add a kernel parameter hugetlb_free_vmemmap to enable the feature of freeing unused vmemmap pages associated with each hugetlb page on boot. Signed-off-by: Muchun Song Reviewed-by: Oscar Salvador Reviewed-by: Barry Song --- Documentation/admin-guide/kernel-parameters.txt | 14

[PATCH v12 13/13] mm/hugetlb: Optimize the code with the help of the compiler

2021-01-06 Thread Muchun Song
We cannot optimize if a "struct page" crosses page boundaries. If it is true, we can optimize the code with the help of a compiler. When free_vmemmap_pages_per_hpage() returns zero, most functions are optimized by the compiler. Signed-off-by: Muchun Song --- include/linux/hugetlb.h |

Re: [External] Re: [PATCH v2 1/6] mm: migrate: do not migrate HugeTLB page whose refcount is one

2021-01-06 Thread Muchun Song
On Thu, Jan 7, 2021 at 12:13 AM Michal Hocko wrote: > > On Wed 06-01-21 16:47:34, Muchun Song wrote: > > If the refcount is one when it is migrated, it means that the page > > was freed from under us. So we are done and do not need to migrate. > > Is this common enou

Re: [External] Re: [PATCH v2 2/6] mm: hugetlbfs: fix cannot migrate the fallocated HugeTLB page

2021-01-06 Thread Muchun Song
On Thu, Jan 7, 2021 at 12:35 AM Michal Hocko wrote: > > On Wed 06-01-21 16:47:35, Muchun Song wrote: > > Because we only can isolate a active page via isolate_huge_page() > > and hugetlbfs_fallocate() forget to mark it as active, we cannot > > isolate and migrate those pa

Re: [External] Re: [PATCH v2 3/6] mm: hugetlb: fix a race between freeing and dissolving the page

2021-01-06 Thread Muchun Song
On Thu, Jan 7, 2021 at 5:00 AM Mike Kravetz wrote: > > On 1/6/21 8:56 AM, Michal Hocko wrote: > > On Wed 06-01-21 16:47:36, Muchun Song wrote: > >> There is a race condition between __free_huge_page() > >> and dissolve_free_huge_page(). > >>

Re: [External] Re: [PATCH v2 4/6] mm: hugetlb: add return -EAGAIN for dissolve_free_huge_page

2021-01-06 Thread Muchun Song
On Thu, Jan 7, 2021 at 1:07 AM Michal Hocko wrote: > > On Wed 06-01-21 16:47:37, Muchun Song wrote: > > When dissolve_free_huge_page() races with __free_huge_page(), we can > > do a retry. Because the race window is small. > > Is this a bug fix or mere optimization. I hav

Re: [External] Re: [PATCH v2 3/6] mm: hugetlb: fix a race between freeing and dissolving the page

2021-01-06 Thread Muchun Song
On Thu, Jan 7, 2021 at 12:56 AM Michal Hocko wrote: > > On Wed 06-01-21 16:47:36, Muchun Song wrote: > > There is a race condition between __free_huge_page() > > and dissolve_free_huge_page(). > > > > CPU0: CPU1: > > > >

Re: [External] Re: [PATCH v2 3/6] mm: hugetlb: fix a race between freeing and dissolving the page

2021-01-07 Thread Muchun Song
On Thu, Jan 7, 2021 at 4:41 PM Michal Hocko wrote: > > On Thu 07-01-21 13:39:38, Muchun Song wrote: > > On Thu, Jan 7, 2021 at 12:56 AM Michal Hocko wrote: > > > > > > On Wed 06-01-21 16:47:36, Muchun Song wrote: > > > > There is

Re: [External] Re: [PATCH v2 4/6] mm: hugetlb: add return -EAGAIN for dissolve_free_huge_page

2021-01-07 Thread Muchun Song
On Thu, Jan 7, 2021 at 4:39 PM Michal Hocko wrote: > > On Thu 07-01-21 11:11:41, Muchun Song wrote: > > On Thu, Jan 7, 2021 at 1:07 AM Michal Hocko wrote: > > > > > > On Wed 06-01-21 16:47:37, Muchun Song wrote: > > > > When dissolve_free_huge_pa

Re: [External] Re: [PATCH v2 0/6] Fix some bugs about HugeTLB code

2021-01-07 Thread Muchun Song
On Thu, Jan 7, 2021 at 5:30 PM David Hildenbrand wrote: > > On 06.01.21 09:47, Muchun Song wrote: > > This patch series aims to fix some bugs and add some improvements. > > > > Changelog since v1 -> v2: > > - Export set_page_huge_active() in patch #2 to f

Re: [External] Re: [PATCH v2 0/6] Fix some bugs about HugeTLB code

2021-01-07 Thread Muchun Song
On Thu, Jan 7, 2021 at 6:10 PM David Hildenbrand wrote: > > On 07.01.21 10:40, Muchun Song wrote: > > On Thu, Jan 7, 2021 at 5:30 PM David Hildenbrand wrote: > >> > >> On 06.01.21 09:47, Muchun Song wrote: > >>> This patch series aims

Re: [External] Re: [PATCH v2 1/6] mm: migrate: do not migrate HugeTLB page whose refcount is one

2021-01-07 Thread Muchun Song
On Thu, Jan 7, 2021 at 7:16 PM Michal Hocko wrote: > > On Thu 07-01-21 10:52:21, Muchun Song wrote: > > On Thu, Jan 7, 2021 at 12:13 AM Michal Hocko wrote: > > > > > > On Wed 06-01-21 16:47:34, Muchun Song wrote: > > > > If the refcount is one w

Re: [External] Re: [PATCH v2 3/6] mm: hugetlb: fix a race between freeing and dissolving the page

2021-01-07 Thread Muchun Song
On Thu, Jan 7, 2021 at 7:18 PM Michal Hocko wrote: > > On Thu 07-01-21 16:53:13, Muchun Song wrote: > > On Thu, Jan 7, 2021 at 4:41 PM Michal Hocko wrote: > > > > > > On Thu 07-01-21 13:39:38, Muchun Song wrote: > > > > On Thu, J

Re: [External] Re: [PATCH v2 3/6] mm: hugetlb: fix a race between freeing and dissolving the page

2021-01-07 Thread Muchun Song
On Thu, Jan 7, 2021 at 8:38 PM Michal Hocko wrote: > > On Thu 07-01-21 19:38:00, Muchun Song wrote: > > On Thu, Jan 7, 2021 at 7:18 PM Michal Hocko wrote: > > > > > > On Thu 07-01-21 16:53:13, Muchun Song wrote: > > > > On Thu,

Re: [External] Re: [PATCH v2 3/6] mm: hugetlb: fix a race between freeing and dissolving the page

2021-01-07 Thread Muchun Song
On Thu, Jan 7, 2021 at 10:11 PM Michal Hocko wrote: > > On Thu 07-01-21 20:59:33, Muchun Song wrote: > > On Thu, Jan 7, 2021 at 8:38 PM Michal Hocko wrote: > [...] > > > Right. Can we simply back off in the dissolving path when ref count is > > > 0 &

Re: [External] Re: [PATCH v2 3/6] mm: hugetlb: fix a race between freeing and dissolving the page

2021-01-07 Thread Muchun Song
On Fri, Jan 8, 2021 at 9:08 AM Mike Kravetz wrote: > > On 1/7/21 7:11 AM, Muchun Song wrote: > > On Thu, Jan 7, 2021 at 10:11 PM Michal Hocko wrote: > >> > >> On Thu 07-01-21 20:59:33, Muchun Song wrote: > >>> On Thu, Jan 7, 2021 at 8:38 PM Michal Hoc

[PATCH v4 2/6] mm: hugetlbfs: fix cannot migrate the fallocated HugeTLB page

2021-01-12 Thread Muchun Song
set_page_huge_active, just leave clear_page_huge_active as static. Because there are no external users. Fixes: 70c3547e36f5 (hugetlbfs: add hugetlbfs_fallocate()) Signed-off-by: Muchun Song Acked-by: Michal Hocko Reviewed-by: Mike Kravetz Cc: sta...@vger.kernel.org --- fs/hugetlbfs/inode.c| 3 ++- include

[PATCH v4 1/6] mm: migrate: do not migrate HugeTLB page whose refcount is one

2021-01-12 Thread Muchun Song
for regular pages and this patch does the same for hugetlb pages. Although the likelyhood of the race is rather small for hugetlb pages it makes sense the two code paths in sync. Signed-off-by: Muchun Song Reviewed-by: Mike Kravetz Acked-by: Yang Shi Acked-by: Michal Hocko --- mm/migrate.c | 6

[PATCH v4 0/6] Fix some bugs about HugeTLB code

2021-01-12 Thread Muchun Song
ce v2 -> v3: - Update commit log. - Using head[3].private to indicate the page is freed in patch #3. Changelog since v1 -> v2: - Export set_page_huge_active() in patch #2 to fix. - Using head[3].mapping to indicate the page is freed in patch #3. - Flush @free_hpage_work in pat

[PATCH v4 3/6] mm: hugetlb: fix a race between freeing and dissolving the page

2021-01-12 Thread Muchun Song
tplug: enable memory hotplug to handle hugepage") Signed-off-by: Muchun Song Reviewed-by: Mike Kravetz Cc: sta...@vger.kernel.org --- mm/hugetlb.c | 26 ++ 1 file changed, 26 insertions(+) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 4741d60f8955..4a9011e121

[PATCH v4 4/6] mm: hugetlb: retry dissolve page when hitting race

2021-01-12 Thread Muchun Song
, it is an optimization for increasing the success rate of dissolving page. Signed-off-by: Muchun Song --- mm/hugetlb.c | 20 ++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 4a9011e12175..898e4ea43e13 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c

[PATCH v4 6/6] mm: hugetlb: remove VM_BUG_ON_PAGE from page_huge_active

2021-01-12 Thread Muchun Song
CONFIG_DEBUG_VM is enabled. Just remove the VM_BUG_ON_PAGE. Fixes: 7e1f049efb86 ("mm: hugetlb: cleanup using paeg_huge_active()") Signed-off-by: Muchun Song Reviewed-by: Mike Kravetz Acked-by: Michal Hocko Cc: sta...@vger.kernel.org --- mm/hugetlb.c | 3 +-- 1 file changed, 1 inser

[PATCH v4 5/6] mm: hugetlb: fix a race between isolating and freeing page

2021-01-12 Thread Muchun Song
on CPU0. Meanwhile, we free it to the buddy allocator on CPU1. Then, we can trigger a BUG_ON on CPU0. Because it is already freed to the buddy allocator. Fixes: c8721bbbdd36 ("mm: memory-hotplug: enable memory hotplug to handle hugepage") Signed-off-by: Muchun Song Reviewed-by: Mike Krav

Re: [External] Re: [PATCH v12 12/13] mm/hugetlb: Gather discrete indexes of tail page

2021-01-13 Thread Muchun Song
On Thu, Jan 14, 2021 at 8:18 AM Mike Kravetz wrote: > > On 1/6/21 6:19 AM, Muchun Song wrote: > > For HugeTLB page, there are more metadata to save in the struct page. > > But the head struct page cannot meet our needs, so we have to abuse > > other tail struct pa

Re: [External] Re: [PATCH v12 03/13] mm: Introduce VM_WARN_ON_PAGE macro

2021-01-13 Thread Muchun Song
On Thu, Jan 14, 2021 at 6:31 AM Mike Kravetz wrote: > > On 1/6/21 6:19 AM, Muchun Song wrote: > > Very similar to VM_WARN_ON_ONCE_PAGE and VM_BUG_ON_PAGE, add > > VM_WARN_ON_PAGE macro. > > > > Signed-off-by: Muchun Song > > --- > > include/linux/mmd

[PATCH v6 3/5] mm: hugetlb: fix a race between freeing and dissolving the page

2021-01-15 Thread Muchun Song
t page(s) already in the buddy allocator. Fixes: c8721bbbdd36 ("mm: memory-hotplug: enable memory hotplug to handle hugepage") Signed-off-by: Muchun Song Reviewed-by: Mike Kravetz Cc: sta...@vger.kernel.org --- mm/hugetlb.c | 39 +++ 1 file chan

[PATCH v6 2/5] mm: hugetlbfs: fix cannot migrate the fallocated HugeTLB page

2021-01-15 Thread Muchun Song
set_page_huge_active, just leave clear_page_huge_active as static. Because there are no external users. Fixes: 70c3547e36f5 (hugetlbfs: add hugetlbfs_fallocate()) Signed-off-by: Muchun Song Acked-by: Michal Hocko Reviewed-by: Mike Kravetz Reviewed-by: Oscar Salvador Cc: sta...@vger.kernel.org --- fs/hugetlbfs

[PATCH v6 4/5] mm: hugetlb: fix a race between isolating and freeing page

2021-01-15 Thread Muchun Song
on CPU0. Meanwhile, we free it to the buddy allocator on CPU1. Then, we can trigger a BUG_ON on CPU0. Because it is already freed to the buddy allocator. Fixes: c8721bbbdd36 ("mm: memory-hotplug: enable memory hotplug to handle hugepage") Signed-off-by: Muchun Song Reviewed-by: Mike Krav

[PATCH v6 5/5] mm: hugetlb: remove VM_BUG_ON_PAGE from page_huge_active

2021-01-15 Thread Muchun Song
CONFIG_DEBUG_VM is enabled. Just remove the VM_BUG_ON_PAGE. Fixes: 7e1f049efb86 ("mm: hugetlb: cleanup using paeg_huge_active()") Signed-off-by: Muchun Song Reviewed-by: Mike Kravetz Acked-by: Michal Hocko Cc: sta...@vger.kernel.org --- mm/hugetlb.c | 3 +-- 1 file changed, 1 inser

  1   2   3   4   5   6   7   8   9   10   >