Skip to content

Commit 16802e5

Browse files
drobnikrppt
authored andcommitted
memblock tests: Add skeleton of the memblock simulator
Add basic project files, together with local stubs of required headers. Update tools/include/slab.h to include definitions used by memblock. Signed-off-by: Karolina Drobnik <[email protected]> Signed-off-by: Mike Rapoport <[email protected]> Link: https://lore.kernel.org/r/d296fceb023a04b316a31fbff9acf1e76ac684e4.1643796665.git.karolinadrobnik@gmail.com
1 parent 6218327 commit 16802e5

File tree

16 files changed

+279
-0
lines changed

16 files changed

+279
-0
lines changed

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12423,6 +12423,7 @@ S: Maintained
1242312423
F: Documentation/core-api/boot-time-mm.rst
1242412424
F: include/linux/memblock.h
1242512425
F: mm/memblock.c
12426+
F: tools/testing/memblock/
1242612427

1242712428
MEMORY CONTROLLER DRIVERS
1242812429
M: Krzysztof Kozlowski <[email protected]>

tools/include/linux/slab.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@
1313
void *kmalloc(size_t size, gfp_t gfp);
1414
void kfree(void *p);
1515

16+
bool slab_is_available(void);
17+
18+
enum slab_state {
19+
DOWN,
20+
PARTIAL,
21+
PARTIAL_NODE,
22+
UP,
23+
FULL
24+
};
25+
1626
static inline void *kzalloc(size_t size, gfp_t gfp)
1727
{
1828
return kmalloc(size, gfp | __GFP_ZERO);

tools/testing/memblock/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
main
2+
memblock.c
3+
linux/memblock.h
4+
asm/cmpxchg.h

tools/testing/memblock/Makefile

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
3+
# Memblock simulator requires AddressSanitizer (libasan) and liburcu development
4+
# packages installed
5+
CFLAGS += -I. -I../../include -Wall -O2 -fsanitize=address \
6+
-fsanitize=undefined -D CONFIG_PHYS_ADDR_T_64BIT
7+
LDFLAGS += -fsanitize=address -fsanitize=undefined
8+
TARGETS = main
9+
OFILES = main.o memblock.o lib/slab.o mmzone.o slab.o
10+
EXTR_SRC = ../../../mm/memblock.c
11+
12+
ifeq ($(BUILD), 32)
13+
CFLAGS += -m32
14+
LDFLAGS += -m32
15+
endif
16+
17+
# Process user parameters
18+
include scripts/Makefile.include
19+
20+
main: $(OFILES)
21+
22+
$(OFILES): include
23+
24+
include: ../../../include/linux/memblock.h ../../include/linux/*.h \
25+
../../include/asm/*.h
26+
27+
@mkdir -p linux
28+
test -L linux/memblock.h || ln -s ../../../../include/linux/memblock.h linux/memblock.h
29+
test -L asm/cmpxchg.h || ln -s ../../../arch/x86/include/asm/cmpxchg.h asm/cmpxchg.h
30+
31+
memblock.c: $(EXTR_SRC)
32+
test -L memblock.c || ln -s $(EXTR_SRC) memblock.c
33+
34+
clean:
35+
$(RM) $(TARGETS) $(OFILES) linux/memblock.h memblock.c asm/cmpxchg.h
36+
37+
help:
38+
@echo 'Memblock simulator'
39+
@echo ''
40+
@echo 'Available targets:'
41+
@echo ' main - Build the memblock simulator'
42+
@echo ' clean - Remove generated files and symlinks in the directory'
43+
@echo ''
44+
@echo 'Configuration:'
45+
@echo ' make NUMA=1 - simulate enabled NUMA'
46+
@echo ' make MOVABLE_NODE=1 - override `movable_node_is_enabled`'
47+
@echo ' definition to simulate movable NUMA nodes'
48+
@echo ' make 32BIT_PHYS_ADDR_T=1 - Use 32 bit physical addresses'
49+
50+
vpath %.c ../../lib
51+
52+
.PHONY: clean include help

tools/testing/memblock/asm/dma.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _TOOLS_DMA_H
3+
#define _TOOLS_DMA_H
4+
5+
#endif

tools/testing/memblock/internal.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* SPDX-License-Identifier: GPL-2.0-or-later */
2+
#ifndef _MM_INTERNAL_H
3+
#define _MM_INTERNAL_H
4+
5+
struct page {};
6+
7+
void memblock_free_pages(struct page *page, unsigned long pfn,
8+
unsigned int order)
9+
{
10+
}
11+
12+
#endif

tools/testing/memblock/lib/slab.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
#include <linux/slab.h>
3+
4+
enum slab_state slab_state;
5+
6+
bool slab_is_available(void)
7+
{
8+
return slab_state >= UP;
9+
}

tools/testing/memblock/linux/init.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _LINUX_INIT_H
3+
#define _LINUX_INIT_H
4+
5+
#include <linux/compiler.h>
6+
#include <asm/export.h>
7+
#include <linux/memory_hotplug.h>
8+
9+
#define __section(section) __attribute__((__section__(section)))
10+
11+
#define __initconst
12+
#define __meminit
13+
#define __meminitdata
14+
#define __refdata
15+
#define __initdata
16+
17+
struct obs_kernel_param {
18+
const char *str;
19+
int (*setup_func)(char *st);
20+
int early;
21+
};
22+
23+
#define __setup_param(str, unique_id, fn, early) \
24+
static const char __setup_str_##unique_id[] __initconst \
25+
__aligned(1) = str; \
26+
static struct obs_kernel_param __setup_##unique_id \
27+
__used __section(".init.setup") \
28+
__aligned(__alignof__(struct obs_kernel_param)) = \
29+
{ __setup_str_##unique_id, fn, early }
30+
31+
#define early_param(str, fn) \
32+
__setup_param(str, fn, fn, 1)
33+
34+
#endif

tools/testing/memblock/linux/kernel.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
#ifndef _MEMBLOCK_LINUX_KERNEL_H
3+
#define _MEMBLOCK_LINUX_KERNEL_H
4+
5+
#include <../../include/linux/kernel.h>
6+
#include <linux/errno.h>
7+
#include <string.h>
8+
#include <linux/printk.h>
9+
#include <linux/linkage.h>
10+
#include <linux/kconfig.h>
11+
12+
#endif
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
#ifndef _KMEMLEAK_H
3+
#define _KMEMLEAK_H
4+
5+
static inline void kmemleak_free_part_phys(phys_addr_t phys, size_t size)
6+
{
7+
}
8+
9+
static inline void kmemleak_alloc_phys(phys_addr_t phys, size_t size,
10+
int min_count, gfp_t gfp)
11+
{
12+
}
13+
14+
static inline void dump_stack(void)
15+
{
16+
}
17+
18+
#endif

0 commit comments

Comments
 (0)