• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 /*
3  * Copyright (C) 2013 LG Electronics.
4  * Author: Joonsoo Kim
5  */
6 
7 /*\
8  * [Description]
9  *
10  * Test to correct handling for reserve count. If no reserved mapping is
11  * created to reserved file region, it should be considered as reserve
12  * mapping. Otherwise, reserve count will be overflowed.
13  */
14 
15 #include "hugetlb.h"
16 
17 #define MNTPOINT "hugetlbfs/"
18 static long hpage_size;
19 static int fd = -1;
20 
run_test(void)21 static void run_test(void)
22 {
23 	unsigned long initial_resv, end_resv;
24 	int fd;
25 	char *p, *q;
26 
27 	initial_resv = SAFE_READ_MEMINFO(MEMINFO_HPAGE_RSVD);
28 
29 	fd = tst_creat_unlinked(MNTPOINT, 0);
30 	p = SAFE_MMAP(NULL, hpage_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
31 
32 	q = SAFE_MMAP(NULL, hpage_size,
33 		PROT_READ | PROT_WRITE, MAP_SHARED | MAP_NORESERVE, fd, 0);
34 
35 	*q = 's';
36 
37 	SAFE_MUNMAP(p, hpage_size);
38 	SAFE_MUNMAP(q, hpage_size);
39 	SAFE_CLOSE(fd);
40 
41 	end_resv = SAFE_READ_MEMINFO(MEMINFO_HPAGE_RSVD);
42 
43 	TST_EXP_EQ_LU(initial_resv, end_resv);
44 }
45 
setup(void)46 static void setup(void)
47 {
48 	hpage_size = tst_get_hugepage_size();
49 }
50 
cleanup(void)51 static void cleanup(void)
52 {
53 	if (fd >= 0)
54 		SAFE_CLOSE(fd);
55 }
56 
57 static struct tst_test test = {
58 	.needs_root = 1,
59 	.mntpoint = MNTPOINT,
60 	.needs_hugetlbfs = 1,
61 	.needs_tmpdir = 1,
62 	.setup = setup,
63 	.cleanup = cleanup,
64 	.test_all = run_test,
65 	.hugepages = {2, TST_NEEDS},
66 };
67