Add basic project files, together with local stubs of required headers. Update tools/include/slab.h to include definitions used by memblock.
Unified · Split
| @@ -12423,6 +12423,7 @@ S: Maintained · 12422 unmodified lines | |||
| 12423 | F: Documentation/core-api/boot-time-mm.rst | 12423 | F: Documentation/core-api/boot-time-mm.rst |
| 12424 | F: include/linux/memblock.h | 12424 | F: include/linux/memblock.h |
| 12425 | F: mm/memblock.c | 12425 | F: mm/memblock.c |
| 12426 | F: tools/testing/memblock/ | ||
| 12426 | 12427 | ||
| 12427 | MEMORY CONTROLLER DRIVERS | 12428 | MEMORY CONTROLLER DRIVERS |
| 12428 | M: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com> | 12429 | M: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com> |
| @@ -13,6 +13,16 @@ · 12 unmodified lines | |||
| 13 | void *kmalloc(size_t size, gfp_t gfp); | 13 | void *kmalloc(size_t size, gfp_t gfp); |
| 14 | void kfree(void *p); | 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 | static inline void *kzalloc(size_t size, gfp_t gfp) | 26 | static inline void *kzalloc(size_t size, gfp_t gfp) |
| 17 | { | 27 | { |
| 18 | return kmalloc(size, gfp | __GFP_ZERO); | 28 | return kmalloc(size, gfp | __GFP_ZERO); |
| @@ -0,0 +1,4 @@ | |||
| 1 | main | ||
| 2 | memblock.c | ||
| 3 | linux/memblock.h | ||
| 4 | asm/cmpxchg.h | ||
| @@ -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 | ||
| @@ -0,0 +1,5 @@ | |||
| 1 | /* SPDX-License-Identifier: GPL-2.0 */ | ||
| 2 | #ifndef _TOOLS_DMA_H | ||
| 3 | #define _TOOLS_DMA_H | ||
| 4 | |||
| 5 | #endif | ||
| @@ -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 | ||
| @@ -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 | } | ||
| @@ -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 | ||
| @@ -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 | ||
| @@ -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,0 +1,19 @@ | |||
| 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 | ||
| @@ -0,0 +1,35 @@ | |||
| 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 | ||
| @@ -0,0 +1,25 @@ | |||
| 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 | ||
| @@ -0,0 +1,6 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 2 | |||
| 3 | int main(int argc, char **argv) | ||
| 4 | { | ||
| 5 | return 0; | ||
| 6 | } | ||
| @@ -0,0 +1,20 @@ | |||
| 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 | } | ||
| @@ -0,0 +1,17 @@ | |||
| 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 | ||