Skip to content

Commit afa684f

Browse files
cpwickmanLinus Torvalds
authored andcommitted
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>
1 parent f9b7cba commit afa684f

1 file changed

Lines changed: 8 additions & 18 deletions

File tree

‎drivers/char/mspec.c‎

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -155,23 +155,22 @@ mspec_open(struct vm_area_struct *vma)
155155
* mspec_close
156156
*
157157
* 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.
159159
*/
160160
static void
161161
mspec_close(struct vm_area_struct *vma)
162162
{
163163
struct vma_data *vdata;
164-
int index, last_index, result;
164+
int index, last_index;
165165
unsigned long my_page;
166166

167167
vdata = vma->vm_private_data;
168168

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

171-
spin_lock(&vdata->lock);
172-
index = (vma->vm_start - vdata->vm_start) >> PAGE_SHIFT;
173-
last_index = (vma->vm_end - vdata->vm_start) >> PAGE_SHIFT;
174-
for (; index < last_index; index++) {
172+
last_index = (vdata->vm_end - vdata->vm_start) >> PAGE_SHIFT;
173+
for (index = 0; index < last_index; index++) {
175174
if (vdata->maddr[index] == 0)
176175
continue;
177176
/*
@@ -180,28 +179,19 @@ mspec_close(struct vm_area_struct *vma)
180179
*/
181180
my_page = vdata->maddr[index];
182181
vdata->maddr[index] = 0;
183-
spin_unlock(&vdata->lock);
184-
result = mspec_zero_block(my_page, PAGE_SIZE);
185-
if (!result)
182+
if (!mspec_zero_block(my_page, PAGE_SIZE))
186183
uncached_free_page(my_page);
187184
else
188185
printk(KERN_WARNING "mspec_close(): "
189-
"failed to zero page %i\n",
190-
result);
191-
spin_lock(&vdata->lock);
186+
"failed to zero page %ld\n", my_page);
192187
}
193-
spin_unlock(&vdata->lock);
194-
195-
if (!atomic_dec_and_test(&vdata->refcnt))
196-
return;
197188

198189
if (vdata->flags & VMD_VMALLOCED)
199190
vfree(vdata);
200191
else
201192
kfree(vdata);
202193
}
203194

204-
205195
/*
206196
* mspec_nopfn
207197
*

0 commit comments

Comments
 (0)