Skip to content

Commit d4033af

Browse files
JoonsooKimtorvalds
authored andcommitted
mm, vmalloc: iterate vmap_area_list, instead of vmlist, in vmallocinfo()
This patch is a preparatory step for removing vmlist entirely. For above purpose, we change iterating a vmap_list codes to iterating a vmap_area_list. It is somewhat trivial change, but just one thing should be noticed. Using vmap_area_list in vmallocinfo() introduce ordering problem in SMP system. In s_show(), we retrieve some values from vm_struct. vm_struct's values is not fully setup when va->vm is assigned. Full setup is notified by removing VM_UNLIST flag without holding a lock. When we see that VM_UNLIST is removed, it is not ensured that vm_struct has proper values in view of other CPUs. So we need smp_[rw]mb for ensuring that proper values is assigned when we see that VM_UNLIST is removed. Therefore, this patch not only change a iteration list, but also add a appropriate smp_[rw]mb to right places. Signed-off-by: Joonsoo Kim <js1304@gmail.com> Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp> Cc: Chris Metcalf <cmetcalf@tilera.com> Cc: Dave Anderson <anderson@redhat.com> Cc: Eric Biederman <ebiederm@xmission.com> Cc: Guan Xuetao <gxt@mprc.pku.edu.cn> Cc: Ingo Molnar <mingo@kernel.org> Cc: Vivek Goyal <vgoyal@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent f98782d commit d4033af

File tree

1 file changed

+42
-13
lines changed

1 file changed

+42
-13
lines changed

mm/vmalloc.c

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,7 +1304,14 @@ static void insert_vmalloc_vmlist(struct vm_struct *vm)
13041304
{
13051305
struct vm_struct *tmp, **p;
13061306

1307+
/*
1308+
* Before removing VM_UNLIST,
1309+
* we should make sure that vm has proper values.
1310+
* Pair with smp_rmb() in show_numa_info().
1311+
*/
1312+
smp_wmb();
13071313
vm->flags &= ~VM_UNLIST;
1314+
13081315
write_lock(&vmlist_lock);
13091316
for (p = &vmlist; (tmp = *p) != NULL; p = &tmp->next) {
13101317
if (tmp->addr >= vm->addr)
@@ -2542,36 +2549,40 @@ void pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms)
25422549

25432550
#ifdef CONFIG_PROC_FS
25442551
static void *s_start(struct seq_file *m, loff_t *pos)
2545-
__acquires(&vmlist_lock)
2552+
__acquires(&vmap_area_lock)
25462553
{
25472554
loff_t n = *pos;
2548-
struct vm_struct *v;
2555+
struct vmap_area *va;
25492556

2550-
read_lock(&vmlist_lock);
2551-
v = vmlist;
2552-
while (n > 0 && v) {
2557+
spin_lock(&vmap_area_lock);
2558+
va = list_entry((&vmap_area_list)->next, typeof(*va), list);
2559+
while (n > 0 && &va->list != &vmap_area_list) {
25532560
n--;
2554-
v = v->next;
2561+
va = list_entry(va->list.next, typeof(*va), list);
25552562
}
2556-
if (!n)
2557-
return v;
2563+
if (!n && &va->list != &vmap_area_list)
2564+
return va;
25582565

25592566
return NULL;
25602567

25612568
}
25622569

25632570
static void *s_next(struct seq_file *m, void *p, loff_t *pos)
25642571
{
2565-
struct vm_struct *v = p;
2572+
struct vmap_area *va = p, *next;
25662573

25672574
++*pos;
2568-
return v->next;
2575+
next = list_entry(va->list.next, typeof(*va), list);
2576+
if (&next->list != &vmap_area_list)
2577+
return next;
2578+
2579+
return NULL;
25692580
}
25702581

25712582
static void s_stop(struct seq_file *m, void *p)
2572-
__releases(&vmlist_lock)
2583+
__releases(&vmap_area_lock)
25732584
{
2574-
read_unlock(&vmlist_lock);
2585+
spin_unlock(&vmap_area_lock);
25752586
}
25762587

25772588
static void show_numa_info(struct seq_file *m, struct vm_struct *v)
@@ -2582,6 +2593,11 @@ static void show_numa_info(struct seq_file *m, struct vm_struct *v)
25822593
if (!counters)
25832594
return;
25842595

2596+
/* Pair with smp_wmb() in insert_vmalloc_vmlist() */
2597+
smp_rmb();
2598+
if (v->flags & VM_UNLIST)
2599+
return;
2600+
25852601
memset(counters, 0, nr_node_ids * sizeof(unsigned int));
25862602

25872603
for (nr = 0; nr < v->nr_pages; nr++)
@@ -2595,7 +2611,20 @@ static void show_numa_info(struct seq_file *m, struct vm_struct *v)
25952611

25962612
static int s_show(struct seq_file *m, void *p)
25972613
{
2598-
struct vm_struct *v = p;
2614+
struct vmap_area *va = p;
2615+
struct vm_struct *v;
2616+
2617+
if (va->flags & (VM_LAZY_FREE | VM_LAZY_FREEING))
2618+
return 0;
2619+
2620+
if (!(va->flags & VM_VM_AREA)) {
2621+
seq_printf(m, "0x%pK-0x%pK %7ld vm_map_ram\n",
2622+
(void *)va->va_start, (void *)va->va_end,
2623+
va->va_end - va->va_start);
2624+
return 0;
2625+
}
2626+
2627+
v = va->vm;
25992628

26002629
seq_printf(m, "0x%pK-0x%pK %7ld",
26012630
v->addr, v->addr + v->size, v->size);

0 commit comments

Comments
 (0)