linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Xiaotian Feng <dfeng@redhat.com>
To: Marcin Slusarz <marcin.slusarz@gmail.com>
Cc: Dan Carpenter <error27@gmail.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
	Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>,
	Jack Steiner <steiner@sgi.com>,
	Suresh Siddha <suresh.b.siddha@intel.com>,
	linux-kernel@vger.kernel.org, x86@kernel.org
Subject: Re: [patch] x86, pat: freeing invalid memtype messages
Date: Fri, 18 Jun 2010 09:58:35 +0800	[thread overview]
Message-ID: <4C1AD2CB.4080905@redhat.com> (raw)
In-Reply-To: <20100617161728.GA2741@joi.lan>

On 06/18/2010 12:17 AM, Marcin Slusarz wrote:
> On Thu, Jun 17, 2010 at 03:45:59PM +0200, Dan Carpenter wrote:
>> Commit 20413f27163 "x86, pat: Fix memory leak in free_memtype" added an
>> error message in free_memtype() if rbt_memtype_erase() returns NULL.
>> The problem is that if CONFIG_X86_PAT is enabled, we use a different
>> implimentation of rbt_memtype_erase() that always returns NULL.
>>
>> I've modified rbt_memtype_erase() to return an ERR_PTR() on errors and
>> made free_memtype() check for that instead.
>>
>> Addresses:  https://bugzilla.kernel.org/show_bug.cgi?id=16205
>>
>> Signed-off-by: Dan Carpenter<error27@gmail.com>
>
> This patch is probably ok, but it does not address my bug.
> I have CONFIG_X86_PAT=y, so rbt_memtype_erase does not always return NULL.

The reason for the warning "swapper:1 freeing invalid memtype \ 
bf799000-bf79a000"
could be two callers reserved "bf799000 - bf79a000". The two callers has 
the same reserve area and same memtype, so the sencond caller will also 
success to reserve "bf799000 - bf79a000".

But at the free stage, if one caller freed "bf799000 - bf79a000", then 
another caller is trying to free "bf799000 - bf79a000", can not find it 
in the rbtree, so pop up an invalid memtype.

>
>> diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
>> index acc15b2..81b7735 100644
>> --- a/arch/x86/mm/pat.c
>> +++ b/arch/x86/mm/pat.c
>> @@ -359,10 +359,10 @@ int free_memtype(u64 start, u64 end)
>>   	entry = rbt_memtype_erase(start, end);
>>   	spin_unlock(&memtype_lock);
>>
>> -	if (!entry) {
>> +	if (IS_ERR(entry)) {
>>   		printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n",
>>   			current->comm, current->pid, start, end);
>> -		return -EINVAL;
>> +		return PTR_ERR(entry);
>>   	}
>>
>>   	kfree(entry);
>> diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
>> index f537087..90e5cbe 100644
>> --- a/arch/x86/mm/pat_rbtree.c
>> +++ b/arch/x86/mm/pat_rbtree.c
>> @@ -236,8 +236,10 @@ struct memtype *rbt_memtype_erase(u64 start, u64 end)
>>   	struct memtype *data;
>>
>>   	data = memtype_rb_exact_match(&memtype_rbroot, start, end);
>> -	if (!data)
>> +	if (!data) {
>> +		data = ERR_PTR(-EINVAL);
>>   		goto out;
>> +	}
>>
>>   	rb_erase(&data->rb,&memtype_rbroot);
>>   out:
>>
>>
>


  parent reply	other threads:[~2010-06-18  1:58 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-17 13:45 [patch] x86, pat: freeing invalid memtype messages Dan Carpenter
2010-06-17 16:17 ` Marcin Slusarz
2010-06-17 16:33   ` Dan Carpenter
2010-06-18  1:58   ` Xiaotian Feng [this message]
2010-06-18  6:47   ` Xiaotian Feng
2010-06-18 17:57     ` Marcin Slusarz
2010-06-21 10:56       ` Xiaotian Feng
2010-06-21 11:02         ` Peter Zijlstra
2010-06-21 11:07           ` Xiaotian Feng
2010-06-21 15:33             ` Marcin Slusarz
2010-06-21 15:41               ` Peter Zijlstra
2010-06-21 17:54                 ` Suresh Siddha
2010-06-21 18:08                   ` Venkatesh Pallipadi
2010-06-21 18:38                     ` Venkatesh Pallipadi
2010-06-21 18:41                       ` Marcin Slusarz
2010-06-21 18:56                         ` Marcin Slusarz
2010-06-22  2:45                   ` Xiaotian Feng
2010-06-22  3:47                     ` Venkatesh Pallipadi

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=4C1AD2CB.4080905@redhat.com \
    --to=dfeng@redhat.com \
    --cc=error27@gmail.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcin.slusarz@gmail.com \
    --cc=mingo@redhat.com \
    --cc=steiner@sgi.com \
    --cc=suresh.b.siddha@intel.com \
    --cc=tglx@linutronix.de \
    --cc=venkatesh.pallipadi@intel.com \
    --cc=x86@kernel.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).