* [PATCH 1/1] mmap.c: find_vma: remove if(mm) check
@ 2012-03-26 23:49 Kautuk Consul
2012-03-27 22:12 ` Andrew Morton
0 siblings, 1 reply; 3+ messages in thread
From: Kautuk Consul @ 2012-03-26 23:49 UTC (permalink / raw)
To: Andrew Morton, Hugh Dickins, Al Viro, KAMEZAWA Hiroyuki,
KOSAKI Motohiro
Cc: linux-mm, linux-kernel, Kautuk Consul
find_vma is called from kernel code where it is absolutely
sure that the mm_struct arg being passed to it is non-NULL.
Remove the if(mm) check.
This will also serve the purpose of mandating that the execution
context(user-mode/kernel-mode) be known before find_vma is called.
Also fixed 2 checkpatch.pl errors in the declaration
of the rb_node and vma_tmp local variables.
I have tested this patch on my x86 PC and there are no crashes
due to this in the course of normal desktop execution.
Signed-off-by: Kautuk Consul <consul.kautuk@gmail.com>
---
mm/mmap.c | 54 ++++++++++++++++++++++++++----------------------------
1 files changed, 26 insertions(+), 28 deletions(-)
diff --git a/mm/mmap.c b/mm/mmap.c
index a7bf6a3..2b2fe67 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1587,35 +1587,33 @@ EXPORT_SYMBOL(get_unmapped_area);
/* Look up the first VMA which satisfies addr < vm_end, NULL if none. */
struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
{
- struct vm_area_struct *vma = NULL;
-
- if (mm) {
- /* Check the cache first. */
- /* (Cache hit rate is typically around 35%.) */
- vma = mm->mmap_cache;
- if (!(vma && vma->vm_end > addr && vma->vm_start <= addr)) {
- struct rb_node * rb_node;
-
- rb_node = mm->mm_rb.rb_node;
- vma = NULL;
-
- while (rb_node) {
- struct vm_area_struct * vma_tmp;
-
- vma_tmp = rb_entry(rb_node,
- struct vm_area_struct, vm_rb);
-
- if (vma_tmp->vm_end > addr) {
- vma = vma_tmp;
- if (vma_tmp->vm_start <= addr)
- break;
- rb_node = rb_node->rb_left;
- } else
- rb_node = rb_node->rb_right;
- }
- if (vma)
- mm->mmap_cache = vma;
+ struct vm_area_struct *vma;
+
+ /* Check the cache first. */
+ /* (Cache hit rate is typically around 35%.) */
+ vma = mm->mmap_cache;
+ if (!(vma && vma->vm_end > addr && vma->vm_start <= addr)) {
+ struct rb_node *rb_node;
+
+ rb_node = mm->mm_rb.rb_node;
+ vma = NULL;
+
+ while (rb_node) {
+ struct vm_area_struct *vma_tmp;
+
+ vma_tmp = rb_entry(rb_node,
+ struct vm_area_struct, vm_rb);
+
+ if (vma_tmp->vm_end > addr) {
+ vma = vma_tmp;
+ if (vma_tmp->vm_start <= addr)
+ break;
+ rb_node = rb_node->rb_left;
+ } else
+ rb_node = rb_node->rb_right;
}
+ if (vma)
+ mm->mmap_cache = vma;
}
return vma;
}
--
1.7.5.4
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
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 1/1] mmap.c: find_vma: remove if(mm) check
2012-03-26 23:49 [PATCH 1/1] mmap.c: find_vma: remove if(mm) check Kautuk Consul
@ 2012-03-27 22:12 ` Andrew Morton
2012-03-28 3:43 ` Kautuk Consul
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2012-03-27 22:12 UTC (permalink / raw)
To: Kautuk Consul
Cc: Hugh Dickins, Al Viro, KAMEZAWA Hiroyuki, KOSAKI Motohiro,
linux-mm, linux-kernel
On Mon, 26 Mar 2012 19:49:27 -0400
Kautuk Consul <consul.kautuk@gmail.com> wrote:
> find_vma is called from kernel code where it is absolutely
> sure that the mm_struct arg being passed to it is non-NULL.
>
> Remove the if(mm) check.
It's odd that the if(mm) test exists - I wonder why it was originally
added. My repo only goes back ten years, and it's there in 2.4.18.
Any code which calls find_vma() without an mm is surely pretty busted?
Still, I think I'd prefer to do
if (WARN_ON_ONCE(!mm))
return NULL;
then let that bake for a kernel release, just to find out if we have a
weird caller out there, such as a function which is called by both user
threads and by kernel threads.
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/1] mmap.c: find_vma: remove if(mm) check
2012-03-27 22:12 ` Andrew Morton
@ 2012-03-28 3:43 ` Kautuk Consul
0 siblings, 0 replies; 3+ messages in thread
From: Kautuk Consul @ 2012-03-28 3:43 UTC (permalink / raw)
To: Andrew Morton
Cc: Hugh Dickins, Al Viro, KAMEZAWA Hiroyuki, KOSAKI Motohiro,
linux-mm, linux-kernel
On Wed, Mar 28, 2012 at 3:42 AM, Andrew Morton
<akpm@linux-foundation.org> wrote:
> On Mon, 26 Mar 2012 19:49:27 -0400
> Kautuk Consul <consul.kautuk@gmail.com> wrote:
>
>> find_vma is called from kernel code where it is absolutely
>> sure that the mm_struct arg being passed to it is non-NULL.
>>
>> Remove the if(mm) check.
>
> It's odd that the if(mm) test exists - I wonder why it was originally
> added. My repo only goes back ten years, and it's there in 2.4.18.
>
> Any code which calls find_vma() without an mm is surely pretty busted?
>
>
> Still, I think I'd prefer to do
>
> if (WARN_ON_ONCE(!mm))
> return NULL;
>
yes, I agree. that is safe for now as there are a huge number of calls
to this API.
> then let that bake for a kernel release, just to find out if we have a
> weird caller out there, such as a function which is called by both user
> threads and by kernel threads.
ok. I'll spin another one and send it to you with your suggestions in a day or
two when I go back home after my day job.
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
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:[~2012-03-28 3:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-26 23:49 [PATCH 1/1] mmap.c: find_vma: remove if(mm) check Kautuk Consul
2012-03-27 22:12 ` Andrew Morton
2012-03-28 3:43 ` Kautuk Consul
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).