linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: Fix incorrect pfn passed to untrack_pfn in remap_pfn_range
@ 2016-04-22 10:31 Yongji Xie
  2016-04-22 18:38 ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Yongji Xie @ 2016-04-22 10:31 UTC (permalink / raw)
  To: linux-mm, linux-kernel
  Cc: akpm, kirill.shutemov, jmarchan, mingo, vbabka, dave.hansen,
	dan.j.williams, matthew.r.wilcox, aarcange, mhocko, luto, dahi,
	Yongji Xie

We used generic hooks in remap_pfn_range to help archs to
track pfnmap regions. The code is something like:

int remap_pfn_range()
{
	...
	track_pfn_remap(vma, &prot, pfn, addr, PAGE_ALIGN(size));
	...
	pfn -= addr >> PAGE_SHIFT;
	...
	untrack_pfn(vma, pfn, PAGE_ALIGN(size));
	...
}

Here we can easily find the pfn is changed but not recovered
before untrack_pfn() is called. That's incorrect.

Signed-off-by: Yongji Xie <xyjxie@linux.vnet.ibm.com>
---
 mm/memory.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/mm/memory.c b/mm/memory.c
index 098f00d..cb9e0c4 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -1755,6 +1755,7 @@ int remap_pfn_range(struct vm_area_struct *vma, unsigned long addr,
 			break;
 	} while (pgd++, addr = next, addr != end);
 
+	pfn += (end - PAGE_ALIGN(size)) >> PAGE_SHIFT;
 	if (err)
 		untrack_pfn(vma, pfn, PAGE_ALIGN(size));
 
-- 
1.7.9.5

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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm: Fix incorrect pfn passed to untrack_pfn in remap_pfn_range
  2016-04-22 10:31 [PATCH] mm: Fix incorrect pfn passed to untrack_pfn in remap_pfn_range Yongji Xie
@ 2016-04-22 18:38 ` Andrew Morton
  2016-04-24  3:44   ` Yongji Xie
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2016-04-22 18:38 UTC (permalink / raw)
  To: Yongji Xie
  Cc: linux-mm, linux-kernel, kirill.shutemov, jmarchan, mingo, vbabka,
	dave.hansen, dan.j.williams, matthew.r.wilcox, aarcange, mhocko,
	luto, dahi

On Fri, 22 Apr 2016 18:31:28 +0800 Yongji Xie <xyjxie@linux.vnet.ibm.com> wrote:

> We used generic hooks in remap_pfn_range to help archs to
> track pfnmap regions. The code is something like:
> 
> int remap_pfn_range()
> {
> 	...
> 	track_pfn_remap(vma, &prot, pfn, addr, PAGE_ALIGN(size));
> 	...
> 	pfn -= addr >> PAGE_SHIFT;
> 	...
> 	untrack_pfn(vma, pfn, PAGE_ALIGN(size));
> 	...
> }
> 
> Here we can easily find the pfn is changed but not recovered
> before untrack_pfn() is called. That's incorrect.

What are the runtime effects of this bug?

> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -1755,6 +1755,7 @@ int remap_pfn_range(struct vm_area_struct *vma, unsigned long addr,
>  			break;
>  	} while (pgd++, addr = next, addr != end);
>  
> +	pfn += (end - PAGE_ALIGN(size)) >> PAGE_SHIFT;
>  	if (err)
>  		untrack_pfn(vma, pfn, PAGE_ALIGN(size));

I'm having trouble understanding this.  Wouldn't it be better to simply
save the track_pfn_remap() call's `pfn' arg in a new local variable?

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm: Fix incorrect pfn passed to untrack_pfn in remap_pfn_range
  2016-04-22 18:38 ` Andrew Morton
@ 2016-04-24  3:44   ` Yongji Xie
  0 siblings, 0 replies; 3+ messages in thread
From: Yongji Xie @ 2016-04-24  3:44 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-mm, linux-kernel, kirill.shutemov, jmarchan, mingo, vbabka,
	dave.hansen, dan.j.williams, matthew.r.wilcox, aarcange, mhocko,
	luto, dahi

On 2016/4/23 2:38, Andrew Morton wrote:
> On Fri, 22 Apr 2016 18:31:28 +0800 Yongji Xie <xyjxie@linux.vnet.ibm.com> wrote:
>
>> We used generic hooks in remap_pfn_range to help archs to
>> track pfnmap regions. The code is something like:
>>
>> int remap_pfn_range()
>> {
>> 	...
>> 	track_pfn_remap(vma, &prot, pfn, addr, PAGE_ALIGN(size));
>> 	...
>> 	pfn -= addr >> PAGE_SHIFT;
>> 	...
>> 	untrack_pfn(vma, pfn, PAGE_ALIGN(size));
>> 	...
>> }
>>
>> Here we can easily find the pfn is changed but not recovered
>> before untrack_pfn() is called. That's incorrect.
> What are the runtime effects of this bug?

Noi 1/4 ? this is just a fix in theory:-) .

>> --- a/mm/memory.c
>> +++ b/mm/memory.c
>> @@ -1755,6 +1755,7 @@ int remap_pfn_range(struct vm_area_struct *vma, unsigned long addr,
>>   			break;
>>   	} while (pgd++, addr = next, addr != end);
>>   
>> +	pfn += (end - PAGE_ALIGN(size)) >> PAGE_SHIFT;
>>   	if (err)
>>   		untrack_pfn(vma, pfn, PAGE_ALIGN(size));
> I'm having trouble understanding this.  Wouldn't it be better to simply
> save the track_pfn_remap() call's `pfn' arg in a new local variable?
>

Yes, it's a little difficult to understand this. I will send a v2 soon.

Thanks,
Yongji

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-04-24  3:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-22 10:31 [PATCH] mm: Fix incorrect pfn passed to untrack_pfn in remap_pfn_range Yongji Xie
2016-04-22 18:38 ` Andrew Morton
2016-04-24  3:44   ` Yongji Xie

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