* Re: [PATCH] mm: mmap: Check all failures before set values
[not found] <1440349179-18304-1-git-send-email-gang.chen.5i5j@qq.com>
@ 2015-08-24 11:32 ` Michal Hocko
[not found] ` <55DB1D94.3050404@hotmail.com>
2015-08-24 21:25 ` Andrew Morton
0 siblings, 2 replies; 8+ messages in thread
From: Michal Hocko @ 2015-08-24 11:32 UTC (permalink / raw)
To: gang.chen.5i5j
Cc: akpm, kirill.shutemov, riel, sasha.levin, gang.chen.5i5j,
linux-mm, linux-kernel
On Mon 24-08-15 00:59:39, gang.chen.5i5j@qq.com wrote:
> From: Chen Gang <gang.chen.5i5j@gmail.com>
>
> When failure occurs and return, vma->vm_pgoff is already set, which is
> not a good idea.
Why? The vma is not inserted anywhere and the failure path is supposed
to simply free the vma.
> Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
> ---
> mm/mmap.c | 13 +++++++------
> 1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/mm/mmap.c b/mm/mmap.c
> index 8e0366e..b5a6f09 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -2878,6 +2878,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
> struct vm_area_struct *prev;
> struct rb_node **rb_link, *rb_parent;
>
> + if (find_vma_links(mm, vma->vm_start, vma->vm_end,
> + &prev, &rb_link, &rb_parent))
> + return -ENOMEM;
> + if ((vma->vm_flags & VM_ACCOUNT) &&
> + security_vm_enough_memory_mm(mm, vma_pages(vma)))
> + return -ENOMEM;
> +
> /*
> * The vm_pgoff of a purely anonymous vma should be irrelevant
> * until its first write fault, when page's anon_vma and index
> @@ -2894,12 +2901,6 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
> BUG_ON(vma->anon_vma);
> vma->vm_pgoff = vma->vm_start >> PAGE_SHIFT;
> }
> - if (find_vma_links(mm, vma->vm_start, vma->vm_end,
> - &prev, &rb_link, &rb_parent))
> - return -ENOMEM;
> - if ((vma->vm_flags & VM_ACCOUNT) &&
> - security_vm_enough_memory_mm(mm, vma_pages(vma)))
> - return -ENOMEM;
>
> vma_link(mm, vma, prev, rb_link, rb_parent);
> return 0;
> --
> 1.9.3
--
Michal Hocko
SUSE Labs
^ permalink raw reply [flat|nested] 8+ messages in thread[parent not found: <55DB1D94.3050404@hotmail.com>]
* Re: [PATCH] mm: mmap: Check all failures before set values
[not found] ` <55DB1D94.3050404@hotmail.com>
@ 2015-08-24 13:34 ` Chen Gang
2015-08-24 13:57 ` Michal Hocko
0 siblings, 1 reply; 8+ messages in thread
From: Chen Gang @ 2015-08-24 13:34 UTC (permalink / raw)
To: Michal Hocko
Cc: Andrew Morton, kirill.shutemov, riel, sasha.levin,
gang.chen.5i5j, Linux Memory, kernel mailing list
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="gb2312", Size: 960 bytes --]
On 8/24/15 19:32, Michal Hocko wrote:
> On Mon 24-08-15 00:59:39, gang.chen.5i5j@qq.com wrote:
>>> From: Chen Gang <gang.chen.5i5j@gmail.com>
>>>
>>> When failure occurs and return, vma->vm_pgoff is already set, which is
>>> not a good idea.
> Why? The vma is not inserted anywhere and the failure path is supposed
> to simply free the vma.
>
It can save several insns when failure occurs.
It is always a little better to let the external function suppose fewer
callers' behalf.
It can save the code readers' (especially new readers') time resource
to avoid to analyze why set 'vma->vm_pgoff' before checking '-ENOMEM'
(may it cause issue? or is 'vm_pgoff' related with the next checking?).
Thanks.
--
Chen Gang
Open, share, and attitude like air, water, and life which God blessed
ÿôèº{.nÇ+·®+%Ëÿ±éݶ\x17¥wÿº{.nÇ+·¥{±þG«éÿ{ayº\x1dÊÚë,j\a¢f£¢·hïêÿêçz_è®\x03(éÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?¨èÚ&£ø§~á¶iOæ¬z·vØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?I¥
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH] mm: mmap: Check all failures before set values
2015-08-24 13:34 ` Chen Gang
@ 2015-08-24 13:57 ` Michal Hocko
[not found] ` <55DB9278.2020603@qq.com>
0 siblings, 1 reply; 8+ messages in thread
From: Michal Hocko @ 2015-08-24 13:57 UTC (permalink / raw)
To: Chen Gang
Cc: Andrew Morton, kirill.shutemov, riel, sasha.levin,
gang.chen.5i5j, Linux Memory, kernel mailing list
On Mon 24-08-15 21:34:25, Chen Gang wrote:
> On 8/24/15 19:32, Michal Hocko wrote:
> > On Mon 24-08-15 00:59:39, gang.chen.5i5j@qq.com wrote:
> >>> From: Chen Gang <gang.chen.5i5j@gmail.com>
> >>>
> >>> When failure occurs and return, vma->vm_pgoff is already set, which is
> >>> not a good idea.
> > Why? The vma is not inserted anywhere and the failure path is supposed
> > to simply free the vma.
> >
>
> It can save several insns when failure occurs.
The failure is quite unlikely, though.
> It is always a little better to let the external function suppose fewer
> callers' behalf.
I am sorry but I do not understand what you are saying here.
> It can save the code readers' (especially new readers') time resource
> to avoid to analyze why set 'vma->vm_pgoff' before checking '-ENOMEM'
> (may it cause issue? or is 'vm_pgoff' related with the next checking?).
Then your changelog should be specific about these reasons. "not a good
idea" is definitely not a good justification for a patch. I am not
saying the patch is incorrect I just do not sure it is worth it. The
code is marginally better. But others might think otherwise. The
changelog needs some more work for sure.
--
Michal Hocko
SUSE Labs
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] mm: mmap: Check all failures before set values
2015-08-24 11:32 ` [PATCH] mm: mmap: Check all failures before set values Michal Hocko
[not found] ` <55DB1D94.3050404@hotmail.com>
@ 2015-08-24 21:25 ` Andrew Morton
[not found] ` <55DB93B2.9010705@hotmail.com>
1 sibling, 1 reply; 8+ messages in thread
From: Andrew Morton @ 2015-08-24 21:25 UTC (permalink / raw)
To: Michal Hocko
Cc: gang.chen.5i5j, kirill.shutemov, riel, sasha.levin,
gang.chen.5i5j, linux-mm, linux-kernel
On Mon, 24 Aug 2015 13:32:13 +0200 Michal Hocko <mhocko@kernel.org> wrote:
> On Mon 24-08-15 00:59:39, gang.chen.5i5j@qq.com wrote:
> > From: Chen Gang <gang.chen.5i5j@gmail.com>
> >
> > When failure occurs and return, vma->vm_pgoff is already set, which is
> > not a good idea.
>
> Why? The vma is not inserted anywhere and the failure path is supposed
> to simply free the vma.
Yes, it's pretty marginal but I suppose the code is a bit better with
the patch than without. I did this:
From: Chen Gang <gang.chen.5i5j@gmail.com>
Subject: mm/mmap.c:insert_vm_struct(): check for failure before setting values
There's no point in initializing vma->vm_pgoff if the insertion attempt
will be failing anyway. Run the checks before performing the initialization.
Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
Cc: Michal Hocko <mhocko@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
mm/mmap.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff -puN mm/mmap.c~mm-mmap-check-all-failures-before-set-values mm/mmap.c
--- a/mm/mmap.c~mm-mmap-check-all-failures-before-set-values
+++ a/mm/mmap.c
@@ -2859,6 +2859,13 @@ int insert_vm_struct(struct mm_struct *m
struct vm_area_struct *prev;
struct rb_node **rb_link, *rb_parent;
+ if (find_vma_links(mm, vma->vm_start, vma->vm_end,
+ &prev, &rb_link, &rb_parent))
+ return -ENOMEM;
+ if ((vma->vm_flags & VM_ACCOUNT) &&
+ security_vm_enough_memory_mm(mm, vma_pages(vma)))
+ return -ENOMEM;
+
/*
* The vm_pgoff of a purely anonymous vma should be irrelevant
* until its first write fault, when page's anon_vma and index
@@ -2875,12 +2882,6 @@ int insert_vm_struct(struct mm_struct *m
BUG_ON(vma->anon_vma);
vma->vm_pgoff = vma->vm_start >> PAGE_SHIFT;
}
- if (find_vma_links(mm, vma->vm_start, vma->vm_end,
- &prev, &rb_link, &rb_parent))
- return -ENOMEM;
- if ((vma->vm_flags & VM_ACCOUNT) &&
- security_vm_enough_memory_mm(mm, vma_pages(vma)))
- return -ENOMEM;
vma_link(mm, vma, prev, rb_link, rb_parent);
return 0;
_
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH] mm: mmap: Check all failures before set values
@ 2015-08-23 17:21 Chen Gang
0 siblings, 0 replies; 8+ messages in thread
From: Chen Gang @ 2015-08-23 17:21 UTC (permalink / raw)
To: kernel mailing list, linux-ia64
When failure occurs and return, vma->vm_pgoff is already set, which is
not a good idea.
Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
---
mm/mmap.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/mm/mmap.c b/mm/mmap.c
index 8e0366e..b5a6f09 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2878,6 +2878,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
struct vm_area_struct *prev;
struct rb_node **rb_link, *rb_parent;
+ if (find_vma_links(mm, vma->vm_start, vma->vm_end,
+ &prev, &rb_link, &rb_parent))
+ return -ENOMEM;
+ if ((vma->vm_flags & VM_ACCOUNT) &&
+ security_vm_enough_memory_mm(mm, vma_pages(vma)))
+ return -ENOMEM;
+
/*
* The vm_pgoff of a purely anonymous vma should be irrelevant
* until its first write fault, when page's anon_vma and index
@@ -2894,12 +2901,6 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
BUG_ON(vma->anon_vma);
vma->vm_pgoff = vma->vm_start>> PAGE_SHIFT;
}
- if (find_vma_links(mm, vma->vm_start, vma->vm_end,
- &prev, &rb_link, &rb_parent))
- return -ENOMEM;
- if ((vma->vm_flags & VM_ACCOUNT) &&
- security_vm_enough_memory_mm(mm, vma_pages(vma)))
- return -ENOMEM;
vma_link(mm, vma, prev, rb_link, rb_parent);
return 0;
--
1.9.3
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2015-08-25 21:33 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <1440349179-18304-1-git-send-email-gang.chen.5i5j@qq.com>
2015-08-24 11:32 ` [PATCH] mm: mmap: Check all failures before set values Michal Hocko
[not found] ` <55DB1D94.3050404@hotmail.com>
2015-08-24 13:34 ` Chen Gang
2015-08-24 13:57 ` Michal Hocko
[not found] ` <55DB9278.2020603@qq.com>
2015-08-25 11:35 ` Michal Hocko
[not found] ` <55DCDF7E.6080402@hotmail.com>
2015-08-25 21:33 ` Chen Gang
2015-08-24 21:25 ` Andrew Morton
[not found] ` <55DB93B2.9010705@hotmail.com>
2015-08-24 21:58 ` Chen Gang
2015-08-23 17:21 Chen Gang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®