Debian Codegraph @

tests/slbpacaflush.c

raw symbols SCIP
1 /*
2 * libhugetlbfs - Easy use of Linux hugepages
3 * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public License
7 * as published by the Free Software Foundation; either version 2.1 of
8 * the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 /* Test rationale:
20 *
21 * ppc64 kernels (prior to 2.6.15-rc5) have a bug in the hugepage SLB
22 * flushing path. After opening new hugetlb areas, we update the
23 * masks in the thread_struct, copy to the PACA, then do slbies on
24 * each CPU. The trouble is we only copy to the PACA on the CPU where
25 * we're opening the segments, which can leave a stale copy in the
26 * PACAs on other CPUs.
27 *
28 * This can be triggered either with multiple threads sharing the mm,
29 * or with a single thread which is migrated from one CPU, to another
30 * (where the mapping occurs), then back again (where we touch the
31 * stale SLB). We use the second method in this test, since it's
32 * easier to force (using sched_setaffinity). However it relies on a
33 * close-to-idle system, if any process other than a kernel thread
34 * runs on the first CPU between runs of the test process, the SLB
35 * will be flushed and we won't trigger the bug, hence the
36 * PASS_INCONCLUSIVE(). Obviously, this test won't work on a 1-cpu
37 * system (should get CONFIG() on the sched_setaffinity()).
38 */
39
40 #define _GNU_SOURCE
41
42 #include <stdio.h>
43 #include <stdlib.h>
44 #include <string.h>
45 #include <errno.h>
46 #include <unistd.h>
47 #include <sys/mman.h>
48 #include <sched.h>
49
50 #include <hugetlbfs.h>
51
52 #include "hugetests.h"
53
54 int main(int argc, char *argv[])
55 {
56 long hpage_size;
57 int fd;
58 void *p;
59 volatile unsigned long *q;
60 int online_cpus[2], err;
61 cpu_set_t cpu0, cpu1;
62
63 test_init(argc, argv);
64
65 hpage_size = check_hugepagesize();
66 check_online_cpus(online_cpus, 2);
67
68 fd = hugetlbfs_unlinked_fd();
69 if (fd < 0)
70 FAIL("hugetlbfs_unlinked_fd()");
71
72 CPU_ZERO(&cpu0);
73 CPU_SET(online_cpus[0], &cpu0);
74 CPU_ZERO(&cpu1);
75 CPU_SET(online_cpus[1], &cpu1);
76
77 err = sched_setaffinity(getpid(), CPU_SETSIZE/8, &cpu0);
78 if (err != 0)
79 CONFIG("sched_setaffinity(cpu%d): %s", online_cpus[0],
80 strerror(errno));
81
82 err = sched_setaffinity(getpid(), CPU_SETSIZE/8, &cpu1);
83 if (err != 0)
84 CONFIG("sched_setaffinity(cpu%d): %s", online_cpus[1],
85 strerror(errno));
86
87 p = mmap(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
88 if (p == MAP_FAILED)
89 FAIL("mmap(): %s", strerror(errno));
90
91 err = sched_setaffinity(getpid(), CPU_SETSIZE/8, &cpu0);
92 if (err != 0)
93 CONFIG("sched_setaffinity(cpu%d): %s", online_cpus[0],
94 strerror(errno));
95
96 q = (volatile unsigned long *)(p + getpagesize());
97 *q = 0xdeadbeef;
98
99 PASS_INCONCLUSIVE();
100 }