Skip to contentSkip to conversation

Fix unmap for shared page tables

PATCH In review Dave McCracken 2 participants 2 messages Oct 11, 2002

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix unmap for shared page tables

I realized I got the unmap code wrong for shared page tables. Here's a patch that fixes the problem plus optimizes the exit case. It should also fix Paul Larson's BUG().

Dave McCracken

======================================================================
Dave McCracken IBM Linux Base Kernel Team 1-512-838-3059
[email protected] T/L 678-3059

./mm/mmap.c +17 -29
@@ -24,7 +24,10 @@
 #include <asm/tlb.h>
 
 extern void unmap_page_range(mmu_gather_t *,struct vm_area_struct *vma, unsigned long address, unsigned long size);
-extern void unmap_all_pages(mmu_gather_t *tlb, struct mm_struct *mm, unsigned long address, unsigned long end);
+#ifdef CONFIG_SHAREPTE
+extern void unmap_shared_range(struct mm_struct *mm, unsigned long address, unsigned long end);
+#endif
+extern void unmap_all_pages(struct mm_struct *mm);
 extern void clear_page_tables(mmu_gather_t *tlb, unsigned long first, int nr);
 
 /*
@@ -984,6 +987,10 @@
 {
 	mmu_gather_t *tlb;
 
+#ifdef CONFIG_SHAREPTE
+	/* Make sure all the pte pages in the range are unshared if necessary */
+	unmap_shared_range(mm, start, end);
+#endif
 	tlb = tlb_gather_mmu(mm, 0);
 
 	do {
@@ -1267,9 +1274,7 @@
 /* Release all mmaps. */
 void exit_mmap(struct mm_struct * mm)
 {
-	mmu_gather_t *tlb;
 	struct vm_area_struct * mpnt;
-	int unmap_vma = mm->total_vm < UNMAP_THRESHOLD;
 
 	profile_exit_mmap(mm);
  
@@ -1277,39 +1282,14 @@
  
 	spin_lock(&mm->page_table_lock);
 
-	tlb = tlb_gather_mmu(mm, 1);
-
 	flush_cache_mm(mm);
-	mpnt = mm->mmap;
-	while (mpnt) {
-		unsigned long start = mpnt->vm_start;
-		unsigned long end = mpnt->vm_end;
 
-		/*
-		 * If the VMA has been charged for, account for its
-		 * removal
-		 */
-		if (mpnt->vm_flags & VM_ACCOUNT)
-			vm_unacct_memory((end - start) >> PAGE_SHIFT);
-
-		mm->map_count--;
-		if (is_vm_hugetlb_page(mpnt))
-			mpnt->vm_ops->close(mpnt);
-		else if (unmap_vma)
-			unmap_page_range(tlb, mpnt, start, end);
-		mpnt = mpnt->vm_next;
-	}
+	unmap_all_pages(mm);
 
 	/* This is just debugging */
 	if (mm->map_count)
 		BUG();
 
-	if (!unmap_vma)
-		unmap_all_pages(tlb, mm, 0, TASK_SIZE);
-
-	clear_page_tables(tlb, FIRST_USER_PGD_NR, USER_PTRS_PER_PGD);
-	tlb_finish_mmu(tlb, 0, TASK_SIZE);
-
 	mpnt = mm->mmap;
 	mm->mmap = mm->mmap_cache = NULL;
 	mm->mm_rb = RB_ROOT;
@@ -1325,6 +1305,14 @@
 	 */
 	while (mpnt) {
 		struct vm_area_struct * next = mpnt->vm_next;
+
+		/*
+		 * If the VMA has been charged for, account for its
+		 * removal
+		 */
+		if (mpnt->vm_flags & VM_ACCOUNT)
+			vm_unacct_memory((mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT);
+
 		remove_shared_vm_struct(mpnt);
 		if (mpnt->vm_ops) {
 			if (mpnt->vm_ops->close)
./mm/memory.c +167 -43

275 lines not on this page · raw message

#1 lore raw
Quoted 4 lines · Dave McCracken

I realized I got the unmap code wrong for shared page tables. Here's a patch that fixes the problem plus optimizes the exit case. It should also fix Paul Larson's BUG().

I tried 2.5.41-mm3+this patch and got a LOT of errors during boot, and periodically while it was running (it did boot though). Test machine was pIII-700, 16 GB and I didn't run LTP since I don't think I could see through all the other stuff if it did produce a BUG or an oops. Here is a snip of some of it, along with random garbage it spit out over the serial console. It looked like maybe crond was unhappy with something. Ksymoops didn't seem happy trying to extract anything else from this. I tried 2.5.41-mm3 by itself and did not get this.

Thanks,
Paul Larson

Unable to handle kernel paging request at virtual address 4212e3b0
 printing eip:
4207ac55
*pde = 5a5a5a5a
Oops: 0007
CPU:    0
EIP:    0023:[<4207ac55>]    Not tainted
EFLAGS: 00010246

EIP is at E Using_Versions+0x4207ac54/0xc011a67f
eax: 00000001 ebx: 4213030c ecx: 00000000 edx: 00000000
esi: 0804e020 edi: 4212dfa0 ebp: bffffba8 esp: bffffb90
ds: 002b es: 002b ss: 002b
Process crond (pid: 1149, threadinfo=f6ea2000 task=f63ca080)
<6>note: crond[1149] exited with preempt_count 1

Unable to handle kernel paging request at virtual address 4212e3b0
 printing eip:
4207ac55
*pde = 00000000
Oops: 0007
CPU:    0
EIP:    0023:[<4207ac55>]    Not tainted
EFLAGS: 00010246

EIP is at E Using_Versions+0x4207ac54/0xc011a67f
eax: 00000001 ebx: 4213030c ecx: 00000000 edx: 00000000
esi: 0804e020 edi: 4212dfa0 ebp: bffffba8 esp: bffffb90
ds: 002b es: 002b ss: 002b
Process crond (pid: 1150, threadinfo=f63ba000 task=f6c006a0)
<6>note: crond[1150] exited with preempt_count 1

Unable to handle kernel paging request at virtual address 4212e3b0
 printing eip:
4207ac55
*pde = 5a5a5a5a
Oops: 0007
CPU:    0
EIP:    0023:[<4207ac55>]    Not tainted
EFLAGS: 00010246

EIP is at E Using_Versions+0x4207ac54/0xc011a67f
eax: 00000001 ebx: 4213030c ecx: 00000000 edx: 00000000
esi: 0804e020 edi: 4212dfa0 ebp: bffffba8 esp: bffffb90
ds: 002b es: 002b ss: 002b
Process crond (pid: 1151, threadinfo=f63c2000 task=f7c92d20)
<6>note: crond[1151] exited with preempt_count 1

Unable to handle kernel paging request at virtual address 4212e3b0
 printing eip:
4207ac55
*pde = 5a5a5a5a
Oops: 0007
CPU:    0
EIP:    0023:[<4207ac55>]    Not tainted
EFLAGS: 00010246

EIP is at E Using_Versions+0x4207ac54/0xc011a67f
eax: 00000001 ebx: 4213030c ecx: 00000000 edx: 00000000
esi: 0804e020 edi: 4212dfa0 ebp: bffffba8 esp: bffffb90
ds: 002b es: 002b ss: 002b
Process crond (pid: 1152, threadinfo=f638a000 task=f6b0b9a0)
<6>note: crond[1152] exited with preempt_count 1
Unab<<<1l1>>e1U>UUn tnnabaaolbbl ee thalo e tn dolt hhaneaon ddkhllaeene rd nklkeeeerrl knn erepenl lae ppaalggg iinginpgna r eggre iqrueeqnsuqgt ueersest qattu< v4esi> t<r4ta><uta4 al >t va idatvr itdrvuesritrasutal ula42a1dl 2 daderadde3brsdres0 se4s s122 ep4123rb12in02e
bbng00 p tei33

riin p :tpirpin
nrgti4 i2nn0egit7 aipe:cinp
g5 :54

      2

07p4*:2ap
c5e c057ad
54 5
*5pa0d*75eaa p5dc= ae55 55=aa

                              5
*55apOad5e5 aoa
as             =p5
a050a05a7
         5a
CPU:    0
EIP:    0023:[<4207ac55>]    Not tainted
EFLAGS: 00010246

EIP is at E Using_Versions+0x4207ac54/0xc011a67f
eax: 00000001 ebx: 4213030c ecx: 00000000 edx: 00000000
esi: 0804e020 edi: 4212dfa0 ebp: bffffba8 esp: bffffb90
ds: 002b es: 002b ss: 002b
Process crond (pid: 1153, threadinfo=f637a000 task=f63ca080)
O<o6ps>:no 0t0e:0 7
on d cr
[11CP5U3:] e x i1t
wEiIPth: p r e0em0p2t3:_c[<o4un2t0 71ac
5>] Not tainted 5
EFLAGS: 00010246
EIP is at E Using_Versions+0x4207ac54/0xc011a67f
eax: 00000001 ebx: 4213030c ecx: 00000000 edx: 00000000
esi: 0804e020 edi: 4212dfa0 ebp: bffffba8 esp: bffffb90
ds: 002b es: 002b ss: 002b
Process crond (pid: 1156, threadinfo=f6374000 task=f6c006a0)
O<op6>sn: o0t0e0:7
ro n c
[1C1P56U]: e xi 2te
wEiItPh: pr e 0e0m2p3t_:c[<ou4n2t07 1a
55>] Not tainted c
EFLAGS: 00010246
EIP is at E Using_Versions+0x4207ac54/0xc011a67f
eax: 00000001 ebx: 4213030c ecx: 00000000 edx: 00000000
esi: 0804e020 edi: 4212dfa0 ebp: bffffba8 esp: bffffb90
ds: 002b es: 002b ss: 002b
Process crond (pid: 1155, threadinfo=f6376000 task=f6bed340)
O<op6s:> n0ot00e:7
r on c
d[C1P15U5: ] ex i4
d EIwPit:h p r0e0em2p3:t[_c<o4u2n07t ac15

Quoted 1 line

] Not tainted 5

EFLAGS: 00010246
EIP is at E Using_Versions+0x4207ac54/0xc011a67f
eax: 00000001 ebx: 4213030c ecx: 00000000 edx: 00000000
esi: 0804e020 edi: 4212dfa0 ebp: bffffba8 esp: bffffb90
ds: 002b es: 002b ss: 002b
Process crond (pid: 1154, threadinfo=f6378000 task=f6bec6c0)
<6>note: crond[1154] exited with preempt_count 1

Unable to handle kernel paging request at virtual address 4212e3b0
 printing eip:
4207ac55
*pde = 5a5a5a5a
Oops: 0007
CPU:    0
EIP:    0023:[<4207ac55>]    Not tainted
EFLAGS: 00010246

EIP is at E Using_Versions+0x4207ac54/0xc011a67f
eax: 00000001 ebx: 4213030c ecx: 00000000 edx: 00000000
esi: 0804e020 edi: 4212dfa0 ebp: bffffba8 esp: bffffb90
ds: 002b es: 002b ss: 002b
Process crond (pid: 1212, threadinfo=f62f8000 task=f6c006a0)
<6>note: crond[1212] exited with preempt_count 1

Unable to handle kernel paging request at virtual address 4212e3b0
 printing eip:
4207ac55
*pde = 00360833
Oops: 0007
CPU:    0
EIP:    0023:[<4207ac55>]    Not tainted
EFLAGS: 00010246

EIP is at E Using_Versions+0x4207ac54/0xc011a67f
eax: 00000001 ebx: 4213030c ecx: 00000000 edx: 00000000
esi: 0804e020 edi: 4212dfa0 ebp: bffffba8 esp: bffffb90
ds: 002b es: 002b ss: 002b
Process crond (pid: 1273, threadinfo=f6252000 task=cc175340)
<6>note: crond[1273] exited with preempt_count 1

Unable to handle kernel paging request at virtual address 4212e3b0
 printing eip:
4207ac55
*pde = 00000000
Oops: 0007
CPU:    0
EIP:    0023:[<4207ac55>]    Not tainted
EFLAGS: 00010246

EIP is at E Using_Versions+0x4207ac54/0xc011a67f
eax: 00000001 ebx: 4213030c ecx: 00000000 edx: 00000000
esi: 0804e020 edi: 4212dfa0 ebp: bffffba8 esp: bffffb90
ds: 002b es: 002b ss: 002b
Process crond (pid: 1275, threadinfo=f6214000 task=f63cb340)
<6>note: crond[1275] exited with preempt_count 1
bad: scheduling while atomic!

Call Trace:
 [<c011614f>] do_schedule+0x2f/0x380
 [<c012f024>] sys_munmap+0x44/0x70
 [<c01071fa>] work_resched+0x5/0x16

Unable to handle kernel paging request at virtual address 4212e3b0
 printing eip:
4207ac55
*pde = 5a5a5a5a
Oops: 0007
CPU:    0
EIP:    0023:[<4207ac55>]    Not tainted
EFLAGS: 00010246

EIP is at E Using_Versions+0x4207ac54/0xc011a67f
eax: 00000001 ebx: 4213030c ecx: 00000000 edx: 00000000
esi: 0804e020 edi: 4212dfa0 ebp: bffffba8 esp: bffffb90
ds: 002b es: 002b ss: 002b
Process crond (pid: 1280, threadinfo=f61c2000 task=cc175980)
<6>note: crond[1280] exited with preempt_count 1
Una<<b1>leU1 >nUatnbaol hbalee nttdloo eh ak ehnrdannleedll ek e krneprnaeegli lp apnaggg iirnneg qrgu eqreseuteqsuet a<stt v4i> r<att4u

Quoted 1 line

val i arattd udvalirr etassd u4d2ar1l2 esae3ddsb0r

ss2 p412r2in12teei3nb3g b0 e4
e 0
p:p r
irinnt4it2nig ne0g 7aeiipc5:p5

                              :

4*<2p407>ad42e0 =7a cc5055050

                             0

000*0p<d1

Quoted 1 line

* =Op o5pdase5 =:a 5a00500a00

0700
00

CPU:    0
EIP:    0023:[<4207ac55>]    Not tainted
EFLAGS: 00010246

EIP is at E Using_Versions+0x4207ac54/0xc011a67f
eax: 00000001 ebx: 4213030c ecx: 00000000 edx: 00000000
esi: 0804e020 edi: 4212dfa0 ebp: bffffba8 esp: bffffb90
ds: 002b es: 002b ss: 002b
Process crond (pid: 1284, threadinfo=f6c7a000 task=f6b0b9a0)
O<o6ps>n:o 0te00: 7
ron d c
[12C8PU4]: e xi t5
d EwiItPh: pr e 0e0mp23t_:[co<4un2t07 1a
55>] Not tainted c
EFLAGS: 00010246
EIP is at E Using_Versions+0x4207ac54/0xc011a67f
eax: 00000001 ebx: 4213030c ecx: 00000000 edx: 00000000
esi: 0804e020 edi: 4212dfa0 ebp: bffffba8 esp: bffffb90
ds: 002b es: 002b ss: 002b
Process crond (pid: 1285, threadinfo=f6182000 task=f6caa040)
O<o6p>s:n ot0e0:0 7c

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/