From: Nick Piggin <npiggin@suse.de>
To: Andrew Morton <akpm@osdl.org>
Cc: Linux Kernel <linux-kernel@vger.kernel.org>,
Linux Memory Management <linux-mm@kvack.org>,
Hugh Dickins <hugh@veritas.com>
Subject: [patch 6/5] mm: find_vm_area locking fixes
Date: Thu, 20 Apr 2006 19:27:35 +0200 [thread overview]
Message-ID: <20060420172735.GC21660@wotan.suse.de> (raw)
In-Reply-To: <20060228202202.14172.60409.sendpatchset@linux.site>
Bite the bullet and try to get the locking correct the first^Wsecond time.
(subtle bugs like area->flagas modification not having the right memory
consistency could be a nightmare to track down)
Signed-off-by: Nick Piggin <npiggin@suse.de>
Index: linux-2.6/mm/vmalloc.c
===================================================================
--- linux-2.6.orig/mm/vmalloc.c
+++ linux-2.6/mm/vmalloc.c
@@ -256,16 +256,15 @@ struct vm_struct *get_vm_area_node(unsig
return __get_vm_area_node(size, flags, VMALLOC_START, VMALLOC_END, node);
}
-static struct vm_struct *find_vm_area(void *addr)
+/* Caller must hold vmlist_lock */
+static struct vm_struct *__find_vm_area(void *addr)
{
struct vm_struct *tmp;
- write_lock(&vmlist_lock);
for (tmp = vmlist; tmp != NULL; tmp = tmp->next) {
if (tmp->addr == addr)
break;
}
- write_unlock(&vmlist_lock);
return tmp;
}
@@ -529,9 +528,10 @@ void *vmalloc_user(unsigned long size)
void *ret;
ret = __vmalloc(size, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL);
- area = find_vm_area(ret);
- BUG_ON(!area);
+ write_lock(&vmlist_lock);
+ area = __find_vm_area(ret);
area->flags |= VM_USERMAP;
+ write_unlock(&vmlist_lock);
return ret;
}
@@ -604,9 +604,10 @@ void *vmalloc_32_user(unsigned long size
void *ret;
ret = __vmalloc(size, GFP_KERNEL | __GFP_ZERO, PAGE_KERNEL);
- area = find_vm_area(ret);
- BUG_ON(!area);
+ write_lock(&vmlist_lock);
+ area = __find_vm_area(ret);
area->flags |= VM_USERMAP;
+ write_unlock(&vmlist_lock);
return ret;
}
@@ -712,15 +713,17 @@ int remap_vmalloc_range(struct vm_area_s
if ((PAGE_SIZE-1) & (unsigned long)addr)
return -EINVAL;
- area = find_vm_area(addr);
+ read_lock(&vmlist_lock);
+ area = __find_vm_area(addr);
if (!area)
- return -EINVAL;
+ goto out_einval_locked;
if (!(area->flags & VM_USERMAP))
- return -EINVAL;
+ goto out_einval_locked;
if (usize + (pgoff << PAGE_SHIFT) > area->size - PAGE_SIZE)
- return -EINVAL;
+ goto out_einval_locked;
+ read_unlock(&vmlist_lock);
addr = (void *)((unsigned long)addr + (pgoff << PAGE_SHIFT));
do {
@@ -738,6 +741,10 @@ int remap_vmalloc_range(struct vm_area_s
vma->vm_flags |= VM_RESERVED;
return ret;
+
+out_einval_locked:
+ read_unlock(&vmlist_lock);
+ return -EINVAL;
}
EXPORT_SYMBOL(remap_vmalloc_range);
--
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>
next prev parent reply other threads:[~2006-04-20 17:27 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-04-20 17:06 [patch 0/5] mm: improve remapping of vmalloc regions Nick Piggin
2006-04-20 17:06 ` [patch 1/5] mm: remap_vmalloc_range Nick Piggin
2006-04-20 17:22 ` Christoph Hellwig
2006-04-20 17:33 ` Nick Piggin
2006-04-20 18:09 ` Nick Piggin
2006-04-20 17:06 ` [patch 2/5] mm: deprecate vmalloc_to_pfn Nick Piggin
2006-04-20 17:22 ` Christoph Hellwig
2006-04-20 17:36 ` Nick Piggin
2006-04-20 20:03 ` Andrew Morton
2006-04-20 17:06 ` [patch 3/5] mm: remove rvmalloc Nick Piggin
2006-04-20 17:06 ` [patch 4/5] mm: extra remap_vmalloc_range check Nick Piggin
2006-04-20 17:07 ` [patch 5/5] drivers: leave vm_flags alone Nick Piggin
2006-04-20 17:27 ` Nick Piggin [this message]
2006-04-20 18:14 ` [patch][rfc] improve remap_vmalloc_range callers' return values Nick Piggin
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=20060420172735.GC21660@wotan.suse.de \
--to=npiggin@suse.de \
--cc=akpm@osdl.org \
--cc=hugh@veritas.com \
--cc=linux-kernel@vger.kernel.org \
--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).