diff options
author | Cliff Wickman <cpw@sgi.com> | 2007-09-25 00:24:41 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-09-25 11:51:04 -0400 |
commit | afa684f6fda6086b229348f0ea21df7c8ad17964 (patch) | |
tree | 2a7c1fb54b6383af854a19f2545ad49abb3dc64a /drivers/char | |
parent | f9b7cba1b8a74c10b0771ca28d4c554aeb9803fc (diff) |
fix "mspec: handle shrinking virtual memory areas"
The vma_data structure may be shared by vma's from multiple tasks, with no
way of knowing which areas are shared or not shared, so release/clear pages
only when the refcount (of vma's) goes to zero.
Signed-off-by: Cliff Wickman <cpw@sgi.com>
Cc: Jes Sorensen <jes@sgi.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/char')
-rw-r--r-- | drivers/char/mspec.c | 26 |
1 files changed, 8 insertions, 18 deletions
diff --git a/drivers/char/mspec.c b/drivers/char/mspec.c index 049a46cc9f87..04ac155d3a07 100644 --- a/drivers/char/mspec.c +++ b/drivers/char/mspec.c | |||
@@ -155,23 +155,22 @@ mspec_open(struct vm_area_struct *vma) | |||
155 | * mspec_close | 155 | * mspec_close |
156 | * | 156 | * |
157 | * Called when unmapping a device mapping. Frees all mspec pages | 157 | * Called when unmapping a device mapping. Frees all mspec pages |
158 | * belonging to the vma. | 158 | * belonging to all the vma's sharing this vma_data structure. |
159 | */ | 159 | */ |
160 | static void | 160 | static void |
161 | mspec_close(struct vm_area_struct *vma) | 161 | mspec_close(struct vm_area_struct *vma) |
162 | { | 162 | { |
163 | struct vma_data *vdata; | 163 | struct vma_data *vdata; |
164 | int index, last_index, result; | 164 | int index, last_index; |
165 | unsigned long my_page; | 165 | unsigned long my_page; |
166 | 166 | ||
167 | vdata = vma->vm_private_data; | 167 | vdata = vma->vm_private_data; |
168 | 168 | ||
169 | BUG_ON(vma->vm_start < vdata->vm_start || vma->vm_end > vdata->vm_end); | 169 | if (!atomic_dec_and_test(&vdata->refcnt)) |
170 | return; | ||
170 | 171 | ||
171 | spin_lock(&vdata->lock); | 172 | last_index = (vdata->vm_end - vdata->vm_start) >> PAGE_SHIFT; |
172 | index = (vma->vm_start - vdata->vm_start) >> PAGE_SHIFT; | 173 | for (index = 0; index < last_index; index++) { |
173 | last_index = (vma->vm_end - vdata->vm_start) >> PAGE_SHIFT; | ||
174 | for (; index < last_index; index++) { | ||
175 | if (vdata->maddr[index] == 0) | 174 | if (vdata->maddr[index] == 0) |
176 | continue; | 175 | continue; |
177 | /* | 176 | /* |
@@ -180,20 +179,12 @@ mspec_close(struct vm_area_struct *vma) | |||
180 | */ | 179 | */ |
181 | my_page = vdata->maddr[index]; | 180 | my_page = vdata->maddr[index]; |
182 | vdata->maddr[index] = 0; | 181 | vdata->maddr[index] = 0; |
183 | spin_unlock(&vdata->lock); | 182 | if (!mspec_zero_block(my_page, PAGE_SIZE)) |
184 | result = mspec_zero_block(my_page, PAGE_SIZE); | ||
185 | if (!result) | ||
186 | uncached_free_page(my_page); | 183 | uncached_free_page(my_page); |
187 | else | 184 | else |
188 | printk(KERN_WARNING "mspec_close(): " | 185 | printk(KERN_WARNING "mspec_close(): " |
189 | "failed to zero page %i\n", | 186 | "failed to zero page %ld\n", my_page); |
190 | result); | ||
191 | spin_lock(&vdata->lock); | ||
192 | } | 187 | } |
193 | spin_unlock(&vdata->lock); | ||
194 | |||
195 | if (!atomic_dec_and_test(&vdata->refcnt)) | ||
196 | return; | ||
197 | 188 | ||
198 | if (vdata->flags & VMD_VMALLOCED) | 189 | if (vdata->flags & VMD_VMALLOCED) |
199 | vfree(vdata); | 190 | vfree(vdata); |
@@ -201,7 +192,6 @@ mspec_close(struct vm_area_struct *vma) | |||
201 | kfree(vdata); | 192 | kfree(vdata); |
202 | } | 193 | } |
203 | 194 | ||
204 | |||
205 | /* | 195 | /* |
206 | * mspec_nopfn | 196 | * mspec_nopfn |
207 | * | 197 | * |