Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <karolinadrobnik@gmail.com>
Signed-off-by: Mike Rapoport <rppt@kernel.org>
Link: https://lore.kernel.org/r/d296fceb023a04b316a31fbff9acf1e76ac684e4.1643796665.git.karolinadrobnik@gmail.com

authored by

Karolina Drobnik and committed by
Mike Rapoport
16802e55 62183279

+279
+1
MAINTAINERS
··· 12423 12423 F: Documentation/core-api/boot-time-mm.rst 12424 12424 F: include/linux/memblock.h 12425 12425 F: mm/memblock.c 12426 + F: tools/testing/memblock/ 12426 12427 12427 12428 MEMORY CONTROLLER DRIVERS 12428 12429 M: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
+10
tools/include/linux/slab.h
··· 13 13 void *kmalloc(size_t size, gfp_t gfp); 14 14 void kfree(void *p); 15 15 16 + bool slab_is_available(void); 17 + 18 + enum slab_state { 19 + DOWN, 20 + PARTIAL, 21 + PARTIAL_NODE, 22 + UP, 23 + FULL 24 + }; 25 + 16 26 static inline void *kzalloc(size_t size, gfp_t gfp) 17 27 { 18 28 return kmalloc(size, gfp | __GFP_ZERO);
+4
tools/testing/memblock/.gitignore
··· 1 + main 2 + memblock.c 3 + linux/memblock.h 4 + asm/cmpxchg.h
+52
tools/testing/memblock/Makefile
··· 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
+5
tools/testing/memblock/asm/dma.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef _TOOLS_DMA_H 3 + #define _TOOLS_DMA_H 4 + 5 + #endif
+12
tools/testing/memblock/internal.h
··· 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
+9
tools/testing/memblock/lib/slab.c
··· 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 + }
+34
tools/testing/memblock/linux/init.h
··· 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
+12
tools/testing/memblock/linux/kernel.h
··· 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
+18
tools/testing/memblock/linux/kmemleak.h
··· 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
+19
tools/testing/memblock/linux/memory_hotplug.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef _LINUX_MEMORY_HOTPLUG_H 3 + #define _LINUX_MEMORY_HOTPLUG_H 4 + 5 + #include <linux/numa.h> 6 + #include <linux/pfn.h> 7 + #include <linux/cache.h> 8 + #include <linux/types.h> 9 + 10 + static inline bool movable_node_is_enabled(void) 11 + { 12 + #ifdef MOVABLE_NODE 13 + return true; 14 + #else 15 + return false; 16 + #endif 17 + } 18 + 19 + #endif
+35
tools/testing/memblock/linux/mmzone.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef _TOOLS_MMZONE_H 3 + #define _TOOLS_MMZONE_H 4 + 5 + #include <linux/atomic.h> 6 + 7 + struct pglist_data *first_online_pgdat(void); 8 + struct pglist_data *next_online_pgdat(struct pglist_data *pgdat); 9 + 10 + #define for_each_online_pgdat(pgdat) \ 11 + for (pgdat = first_online_pgdat(); \ 12 + pgdat; \ 13 + pgdat = next_online_pgdat(pgdat)) 14 + 15 + enum zone_type { 16 + __MAX_NR_ZONES 17 + }; 18 + 19 + #define MAX_NR_ZONES __MAX_NR_ZONES 20 + #define MAX_ORDER 11 21 + #define MAX_ORDER_NR_PAGES (1 << (MAX_ORDER - 1)) 22 + 23 + #define pageblock_order (MAX_ORDER - 1) 24 + #define pageblock_nr_pages BIT(pageblock_order) 25 + 26 + struct zone { 27 + atomic_long_t managed_pages; 28 + }; 29 + 30 + typedef struct pglist_data { 31 + struct zone node_zones[MAX_NR_ZONES]; 32 + 33 + } pg_data_t; 34 + 35 + #endif
+25
tools/testing/memblock/linux/printk.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef _PRINTK_H 3 + #define _PRINTK_H 4 + 5 + #include <stdio.h> 6 + #include <asm/bug.h> 7 + 8 + /* 9 + * memblock_dbg is called with u64 arguments that don't match the "%llu" 10 + * specifier in printf. This results in warnings that cannot be fixed without 11 + * modifying memblock.c, which we wish to avoid. As these messaged are not used 12 + * in testing anyway, the mismatch can be ignored. 13 + */ 14 + #pragma GCC diagnostic push 15 + #pragma GCC diagnostic ignored "-Wformat" 16 + #define printk printf 17 + #pragma GCC diagnostic push 18 + 19 + #define pr_info printk 20 + #define pr_debug printk 21 + #define pr_cont printk 22 + #define pr_err printk 23 + #define pr_warn printk 24 + 25 + #endif
+6
tools/testing/memblock/main.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + 3 + int main(int argc, char **argv) 4 + { 5 + return 0; 6 + }
+20
tools/testing/memblock/mmzone.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + #include <linux/mmzone.h> 3 + 4 + struct pglist_data *first_online_pgdat(void) 5 + { 6 + return NULL; 7 + } 8 + 9 + struct pglist_data *next_online_pgdat(struct pglist_data *pgdat) 10 + { 11 + return NULL; 12 + } 13 + 14 + void reserve_bootmem_region(phys_addr_t start, phys_addr_t end) 15 + { 16 + } 17 + 18 + void atomic_long_set(atomic_long_t *v, long i) 19 + { 20 + }
+17
tools/testing/memblock/scripts/Makefile.include
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + # Definitions for user-provided arguments 3 + 4 + # Simulate CONFIG_NUMA=y 5 + ifeq ($(NUMA), 1) 6 + CFLAGS += -D CONFIG_NUMA 7 + endif 8 + 9 + # Simulate movable NUMA memory regions 10 + ifeq ($(MOVABLE_NODE), 1) 11 + CFLAGS += -D MOVABLE_NODE 12 + endif 13 + 14 + # Use 32 bit physical addresses 15 + ifeq ($(32BIT_PHYS_ADDR_T), 1) 16 + CFLAGS += -U CONFIG_PHYS_ADDR_T_64BIT 17 + endif