linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Huang Shijie <shijie8@gmail.com>
To: Hugh Dickins <hugh.dickins@tiscali.co.uk>
Cc: akpm@linux-foundation.org, linux-mm@kvack.org
Subject: Re: [PATCH] swapfile : fix the wrong return value
Date: Thu, 04 Mar 2010 15:00:18 +0800	[thread overview]
Message-ID: <4B8F5A82.2030805@gmail.com> (raw)
In-Reply-To: <alpine.LSU.2.00.1003040029210.28735@sister.anvils>


>> If the __swap_duplicate returns a negative value except of the -ENOMEM,
>> but the err is zero at this time, the return value of swap_duplicate is
>> wrong in this situation.
>>
>> The caller, such as try_to_unmap_one(), will do the wrong operations too
>> in this situation.
>>
>> This patch fix it.
>>
>> Signed-off-by: Huang Shijie<shijie8@gmail.com>
>> ---
>>   mm/swapfile.c |    2 +-
>>   1 files changed, 1 insertions(+), 1 deletions(-)
>>
>> diff --git a/mm/swapfile.c b/mm/swapfile.c
>> index 6c0585b..191d8fa 100644
>> --- a/mm/swapfile.c
>> +++ b/mm/swapfile.c
>> @@ -2161,7 +2161,7 @@ int swap_duplicate(swp_entry_t entry)
>>   {
>>   	int err = 0;
>>
>> -	while (!err&&  __swap_duplicate(entry, 1) == -ENOMEM)
>> +	while (!err&&  (err = __swap_duplicate(entry, 1)) == -ENOMEM)
>>   		err = add_swap_count_continuation(entry, GFP_ATOMIC);
>>   	return err;
>>   }
>> -- 
>>      
> I was on the point of Ack'ing your patch, and despairing at my confusion,
> when I realized what's actually going on here - the key is (look at 2.6.32)
> swap_duplicate() used to be a void function (no error code whatsoever),
> until I added the -ENOMEM for swap_count_continuation.  And in fact your
> patch is wrong, copy_one_pte() does not want to add swap_count_continuation
>    
Yes,you are right, my patch is wrong in this situation.
> in the case when it hits a corrupt pte (one which looks like a swap entry).
>
> But you're absolutely right that it cries out for a comment:
>
>
> [PATCH] mm: add comment on swap_duplicate's error code
>
> swap_duplicate()'s loop appears to miss out on returning the error code
> from __swap_duplicate(), except when that's -ENOMEM.  In fact this is
> intentional: prior to -ENOMEM for swap_count_continuation, swap_duplicate()
> was void (and the case only occurs when copy_one_pte() hits a corrupt pte).
>    
only?

There are several paths calling the try_to_unmap(), Could you sure that
the swap entries are valid in all the paths ?

For the sake of the stability of the system, I perfer to export all the 
error value,
and check it carefully.

What about my following patch?

> But that's surprising behaviour, which certainly deserves a comment.
>
> Reported-by: Huang Shijie<shijie8@gmail.com>
> Signed-off-by: Hugh Dickins<hughd@google.com>
> ---
>
>   mm/swapfile.c |    6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
>
> --- 2633/mm/swapfile.c	2010-02-24 18:52:17.000000000 +0000
> +++ linux/mm/swapfile.c	2010-03-04 00:11:35.000000000 +0000
> @@ -2155,7 +2155,11 @@ void swap_shmem_alloc(swp_entry_t entry)
>   }
>
>   /*
> - * increase reference count of swap entry by 1.
> + * Increase reference count of swap entry by 1.
> + * Returns 0 for success, or -ENOMEM if a swap_count_continuation is required
> + * but could not be atomically allocated.  Returns 0, just as if it succeeded,
> + * if __swap_duplicate() fails for another reason (-EINVAL or -ENOENT), which
> + * might occur if a page table entry has got corrupted.
>    */
>   int swap_duplicate(swp_entry_t entry)
>   {
>
>    

--
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>

  reply	other threads:[~2010-03-04  7:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-02  3:38 [PATCH] swapfile : fix the wrong return value Huang Shijie
2010-03-04  0:37 ` Hugh Dickins
2010-03-04  7:00   ` Huang Shijie [this message]
2010-03-04  7:28     ` Hugh Dickins
2010-03-04  7:48       ` Huang Shijie
2010-03-04  7:14 ` [PATCH] swapfile : export more return values for swap_duplicate() Huang Shijie

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=4B8F5A82.2030805@gmail.com \
    --to=shijie8@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=hugh.dickins@tiscali.co.uk \
    --cc=linux-mm@kvack.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 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).