All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vlastimil Babka <vbabka@suse.cz>
To: Joonsoo Kim <iamjoonsoo.kim@lge.com>, Hui Zhu <zhuhui@xiaomi.com>
Cc: akpm@linux-foundation.org, lauraa@codeaurora.org,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	teawater@gmail.com
Subject: Re: [PATCH v2] CMA: page_isolation: check buddy before access it
Date: Wed, 06 May 2015 09:55:39 +0200	[thread overview]
Message-ID: <5549C8FB.7080404@suse.cz> (raw)
In-Reply-To: <20150506062801.GA12737@js1304-P5Q-DELUXE>

On 6.5.2015 8:28, Joonsoo Kim wrote:
> On Tue, May 05, 2015 at 11:22:59AM +0800, Hui Zhu wrote:
>>
>> diff --git a/mm/page_isolation.c b/mm/page_isolation.c
>> index 755a42c..eb22d1f 100644
>> --- a/mm/page_isolation.c
>> +++ b/mm/page_isolation.c
>> @@ -101,7 +101,8 @@ void unset_migratetype_isolate(struct page *page, unsigned migratetype)
>>  			buddy_idx = __find_buddy_index(page_idx, order);
>>  			buddy = page + (buddy_idx - page_idx);
>>  
>> -			if (!is_migrate_isolate_page(buddy)) {
>> +			if (!pfn_valid_within(page_to_pfn(buddy))
>> +			    || !is_migrate_isolate_page(buddy)) {
>>  				__isolate_free_page(page, order);
>>  				kernel_map_pages(page, (1 << order), 1);
>>  				set_page_refcounted(page);
> 
> Hello,
> 
> This isolation is for merging buddy pages. If buddy is not valid, we
> don't need to isolate page, because we can't merge them.
> I think that correct code would be:
> 
> pfn_valid_within(page_to_pfn(buddy)) &&
>         !is_migrate_isolate_page(buddy)
> 
> But, isolation and free here is safe operation so your code will work
> fine.

Ah damnit, you're right. But now you got me thinking about it more, and
paranoid... I thought I saw more bugs since the buddy might be in different zone
and we are not locking that zone, but then again it's probably fine, just very
tricky. Then I thought it could be simplified but then not again. Guess I'll
just run away fast :)

> Thanks.
> 

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

WARNING: multiple messages have this Message-ID (diff)
From: Vlastimil Babka <vbabka@suse.cz>
To: Joonsoo Kim <iamjoonsoo.kim@lge.com>, Hui Zhu <zhuhui@xiaomi.com>
Cc: akpm@linux-foundation.org, lauraa@codeaurora.org,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	teawater@gmail.com
Subject: Re: [PATCH v2] CMA: page_isolation: check buddy before access it
Date: Wed, 06 May 2015 09:55:39 +0200	[thread overview]
Message-ID: <5549C8FB.7080404@suse.cz> (raw)
In-Reply-To: <20150506062801.GA12737@js1304-P5Q-DELUXE>

On 6.5.2015 8:28, Joonsoo Kim wrote:
> On Tue, May 05, 2015 at 11:22:59AM +0800, Hui Zhu wrote:
>>
>> diff --git a/mm/page_isolation.c b/mm/page_isolation.c
>> index 755a42c..eb22d1f 100644
>> --- a/mm/page_isolation.c
>> +++ b/mm/page_isolation.c
>> @@ -101,7 +101,8 @@ void unset_migratetype_isolate(struct page *page, unsigned migratetype)
>>  			buddy_idx = __find_buddy_index(page_idx, order);
>>  			buddy = page + (buddy_idx - page_idx);
>>  
>> -			if (!is_migrate_isolate_page(buddy)) {
>> +			if (!pfn_valid_within(page_to_pfn(buddy))
>> +			    || !is_migrate_isolate_page(buddy)) {
>>  				__isolate_free_page(page, order);
>>  				kernel_map_pages(page, (1 << order), 1);
>>  				set_page_refcounted(page);
> 
> Hello,
> 
> This isolation is for merging buddy pages. If buddy is not valid, we
> don't need to isolate page, because we can't merge them.
> I think that correct code would be:
> 
> pfn_valid_within(page_to_pfn(buddy)) &&
>         !is_migrate_isolate_page(buddy)
> 
> But, isolation and free here is safe operation so your code will work
> fine.

Ah damnit, you're right. But now you got me thinking about it more, and
paranoid... I thought I saw more bugs since the buddy might be in different zone
and we are not locking that zone, but then again it's probably fine, just very
tricky. Then I thought it could be simplified but then not again. Guess I'll
just run away fast :)

> Thanks.
> 


  parent reply	other threads:[~2015-05-06  7:55 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-04  9:41 [PATCH] CMA: page_isolation: check buddy before access it Hui Zhu
2015-05-04  9:41 ` Hui Zhu
2015-05-04 18:34 ` Laura Abbott
2015-05-04 18:34   ` Laura Abbott
2015-05-05  3:17   ` Hui Zhu
2015-05-05  3:17     ` Hui Zhu
2015-05-05  3:22 ` [PATCH v2] " Hui Zhu
2015-05-05  3:22   ` Hui Zhu
2015-05-05  8:43   ` Vlastimil Babka
2015-05-05  8:43     ` Vlastimil Babka
2015-05-05 21:29   ` Andrew Morton
2015-05-05 21:29     ` Andrew Morton
2015-05-06  1:39     ` Hui Zhu
2015-05-06  1:39       ` Hui Zhu
2015-05-06  6:28   ` Joonsoo Kim
2015-05-06  6:28     ` Joonsoo Kim
2015-05-06  7:09     ` Hui Zhu
2015-05-06  7:09       ` Hui Zhu
2015-05-06  7:55     ` Vlastimil Babka [this message]
2015-05-06  7:55       ` Vlastimil Babka
2015-05-06  7:08 ` [PATCH v3] " Hui Zhu
2015-05-06  7:08   ` Hui Zhu

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=5549C8FB.7080404@suse.cz \
    --to=vbabka@suse.cz \
    --cc=akpm@linux-foundation.org \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=lauraa@codeaurora.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=teawater@gmail.com \
    --cc=zhuhui@xiaomi.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.