From nobody Mon Jun 29 22:16:37 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A90BC433FE for ; Wed, 2 Feb 2022 11:03:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343708AbiBBLDx (ORCPT ); Wed, 2 Feb 2022 06:03:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343679AbiBBLDr (ORCPT ); Wed, 2 Feb 2022 06:03:47 -0500 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A406C061714 for ; Wed, 2 Feb 2022 03:03:47 -0800 (PST) Received: by mail-lf1-x12b.google.com with SMTP id f10so13330541lfu.8 for ; Wed, 02 Feb 2022 03:03:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=E0Y7uqcHEMtC/3cR+10U0WbGQ+c4SstF679jAzBhdPg=; b=X9MdoDs/kLV4cb9pPZDNqnpAmGEmumpyN5907blV0bYbQvCp+SGTVjPhk7PXrhca2k 8lYfOiwsdmwGpIRoJOYflFeS8DKeSbyNpcKczBRvrdUyu40X0r9iQK8zls9DHNVbXFXt OTYpQU07c6zKax8dgMTnbGA23kzCjCaCFyLUKWTMw9Ik3dmqC6eMG/tc704VcnFiMHkC 2dxOABajO/ksmz4T9xaR1TciEm4mSVlKIJTt0RfvAXhK5fhzt/O2nYVJJCQ7nNfB2eBi fyog0vNLxe3EbJtQC/ToQyWO0igb4+YeUmgMHGNFls+ob1lI3gQek/SpaFDeSkWKkN3E U9Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=E0Y7uqcHEMtC/3cR+10U0WbGQ+c4SstF679jAzBhdPg=; b=mKjTUUGnelaQIo7yNIZ03QzROitnHoPfsp8LV0yaMKN1ZkuiU5wItBbFQUey7DFHG9 /dRguEYhHfxB+bHleQmxn8QZxtfbav96cN7c03pYEvZzqUl5qZj6lQHcvlg2W6vXf9Xh zhTdD+nP331e9jZEMecLQ9hJc0nnCYtNRv1v5GgA6J5hRQf1n9EZcZbJQPjsrATtFmdK XfxkiROBDwZPMksyeb++P4THN0Y7NuYjo6Rl25g698K6vVuaX0+GQ0KGIMXNuV0oqpFv oJBOMqAPDMlm+O/88QmXMxWCyGZ2OyirxkeZRvqZhoU/v358iIqCEUS99ewIKcJ9m5N2 A8zQ== X-Gm-Message-State: AOAM531hz1QzwAO5RsFoXFpyOBl/b1C0mlAlYCF9tmCz+pS6Hb4ResGX BzluzU1bE/q2Vaovr0FDc7A= X-Google-Smtp-Source: ABdhPJzJZ1GEdA2aoR6Ez0SI6XBSLsCqPP7a8YloGUvcGjD8Zvb768Sd3DNkYtqcuwmPPVNNBwislw== X-Received: by 2002:a05:6512:228a:: with SMTP id f10mr13803059lfu.22.1643799825825; Wed, 02 Feb 2022 03:03:45 -0800 (PST) Received: from localhost.localdomain (staticline-31-183-164-222.toya.net.pl. [31.183.164.222]) by smtp.gmail.com with ESMTPSA id r14sm4503937lfr.129.2022.02.02.03.03.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 03:03:45 -0800 (PST) From: Karolina Drobnik To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, rppt@kernel.org, linux-kernel@vger.kernel.org, Karolina Drobnik Subject: [PATCH v2 01/16] tools: Move gfp.h and slab.h from radix-tree to lib Date: Wed, 2 Feb 2022 12:03:00 +0100 Message-Id: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Merge radix-tree definitions from gfp.h and slab.h with these in tools/lib, so they can be used in other test suites. Fix style issues in slab.h. Update radix-tree test files. Signed-off-by: Karolina Drobnik --- tools/include/linux/gfp.h | 28 ++++++++++++++ .../radix-tree =3D> include}/linux/slab.h | 15 ++++---- tools/lib/slab.c | 38 +++++++++++++++++++ tools/testing/radix-tree/Makefile | 3 +- tools/testing/radix-tree/linux.c | 27 ------------- tools/testing/radix-tree/linux/gfp.h | 33 ---------------- 6 files changed, 76 insertions(+), 68 deletions(-) rename tools/{testing/radix-tree =3D> include}/linux/slab.h (68%) create mode 100644 tools/lib/slab.c delete mode 100644 tools/testing/radix-tree/linux/gfp.h diff --git a/tools/include/linux/gfp.h b/tools/include/linux/gfp.h index 22030756fbc0..b238dbc9eb85 100644 --- a/tools/include/linux/gfp.h +++ b/tools/include/linux/gfp.h @@ -1,4 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0 */ #ifndef _TOOLS_INCLUDE_LINUX_GFP_H #define _TOOLS_INCLUDE_LINUX_GFP_H =20 +#include + +#define __GFP_BITS_SHIFT 26 +#define __GFP_BITS_MASK ((gfp_t)((1 << __GFP_BITS_SHIFT) - 1)) + +#define __GFP_HIGH 0x20u +#define __GFP_IO 0x40u +#define __GFP_FS 0x80u +#define __GFP_NOWARN 0x200u +#define __GFP_ZERO 0x8000u +#define __GFP_ATOMIC 0x80000u +#define __GFP_ACCOUNT 0x100000u +#define __GFP_DIRECT_RECLAIM 0x400000u +#define __GFP_KSWAPD_RECLAIM 0x2000000u + +#define __GFP_RECLAIM (__GFP_DIRECT_RECLAIM | __GFP_KSWAPD_RECLAIM) + +#define GFP_ZONEMASK 0x0fu +#define GFP_ATOMIC (__GFP_HIGH | __GFP_ATOMIC | __GFP_KSWAPD_RECLAIM) +#define GFP_KERNEL (__GFP_RECLAIM | __GFP_IO | __GFP_FS) +#define GFP_NOWAIT (__GFP_KSWAPD_RECLAIM) + +static inline bool gfpflags_allow_blocking(const gfp_t gfp_flags) +{ + return !!(gfp_flags & __GFP_DIRECT_RECLAIM); +} + #endif /* _TOOLS_INCLUDE_LINUX_GFP_H */ diff --git a/tools/testing/radix-tree/linux/slab.h b/tools/include/linux/sl= ab.h similarity index 68% rename from tools/testing/radix-tree/linux/slab.h rename to tools/include/linux/slab.h index 2958830ce4d7..07d7930d4003 100644 --- a/tools/testing/radix-tree/linux/slab.h +++ b/tools/include/linux/slab.h @@ -1,20 +1,21 @@ /* SPDX-License-Identifier: GPL-2.0 */ -#ifndef SLAB_H -#define SLAB_H +#ifndef _TOOLS_SLAB_H +#define _TOOLS_SLAB_H =20 #include #include =20 -#define SLAB_HWCACHE_ALIGN 1 #define SLAB_PANIC 2 #define SLAB_RECLAIM_ACCOUNT 0x00020000UL /* Objects are rec= laimable */ =20 -void *kmalloc(size_t size, gfp_t); -void kfree(void *); +#define kzalloc_node(size, flags, node) kmalloc(size, flags) + +void *kmalloc(size_t size, gfp_t gfp); +void kfree(void *p); =20 static inline void *kzalloc(size_t size, gfp_t gfp) { - return kmalloc(size, gfp | __GFP_ZERO); + return kmalloc(size, gfp | __GFP_ZERO); } =20 void *kmem_cache_alloc(struct kmem_cache *cachep, int flags); @@ -24,4 +25,4 @@ struct kmem_cache *kmem_cache_create(const char *name, un= signed int size, unsigned int align, unsigned int flags, void (*ctor)(void *)); =20 -#endif /* SLAB_H */ +#endif /* _TOOLS_SLAB_H */ diff --git a/tools/lib/slab.c b/tools/lib/slab.c new file mode 100644 index 000000000000..959997fb0652 --- /dev/null +++ b/tools/lib/slab.c @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include + +#include +#include +#include +#include + +int kmalloc_nr_allocated; +int kmalloc_verbose; + +void *kmalloc(size_t size, gfp_t gfp) +{ + void *ret; + + if (!(gfp & __GFP_DIRECT_RECLAIM)) + return NULL; + + ret =3D malloc(size); + uatomic_inc(&kmalloc_nr_allocated); + if (kmalloc_verbose) + printf("Allocating %p from malloc\n", ret); + if (gfp & __GFP_ZERO) + memset(ret, 0, size); + return ret; +} + +void kfree(void *p) +{ + if (!p) + return; + uatomic_dec(&kmalloc_nr_allocated); + if (kmalloc_verbose) + printf("Freeing %p to malloc\n", p); + free(p); +} diff --git a/tools/testing/radix-tree/Makefile b/tools/testing/radix-tree/M= akefile index aa6abfe0749c..c4ea4fbb0bfc 100644 --- a/tools/testing/radix-tree/Makefile +++ b/tools/testing/radix-tree/Makefile @@ -5,7 +5,8 @@ CFLAGS +=3D -I. -I../../include -g -Og -Wall -D_LGPL_SOURCE= -fsanitize=3Daddress \ LDFLAGS +=3D -fsanitize=3Daddress -fsanitize=3Dundefined LDLIBS+=3D -lpthread -lurcu TARGETS =3D main idr-test multiorder xarray -CORE_OFILES :=3D xarray.o radix-tree.o idr.o linux.o test.o find_bit.o bit= map.o +CORE_OFILES :=3D xarray.o radix-tree.o idr.o linux.o test.o find_bit.o bit= map.o \ + slab.o OFILES =3D main.o $(CORE_OFILES) regression1.o regression2.o regression3.o= \ regression4.o tag_check.o multiorder.o idr-test.o iteration_check.o \ iteration_check_2.o benchmark.o diff --git a/tools/testing/radix-tree/linux.c b/tools/testing/radix-tree/li= nux.c index 2d9c59df60de..81539f543954 100644 --- a/tools/testing/radix-tree/linux.c +++ b/tools/testing/radix-tree/linux.c @@ -14,7 +14,6 @@ =20 int nr_allocated; int preempt_count; -int kmalloc_verbose; int test_verbose; =20 struct kmem_cache { @@ -78,32 +77,6 @@ void kmem_cache_free(struct kmem_cache *cachep, void *ob= jp) pthread_mutex_unlock(&cachep->lock); } =20 -void *kmalloc(size_t size, gfp_t gfp) -{ - void *ret; - - if (!(gfp & __GFP_DIRECT_RECLAIM)) - return NULL; - - ret =3D malloc(size); - uatomic_inc(&nr_allocated); - if (kmalloc_verbose) - printf("Allocating %p from malloc\n", ret); - if (gfp & __GFP_ZERO) - memset(ret, 0, size); - return ret; -} - -void kfree(void *p) -{ - if (!p) - return; - uatomic_dec(&nr_allocated); - if (kmalloc_verbose) - printf("Freeing %p to malloc\n", p); - free(p); -} - struct kmem_cache * kmem_cache_create(const char *name, unsigned int size, unsigned int align, unsigned int flags, void (*ctor)(void *)) diff --git a/tools/testing/radix-tree/linux/gfp.h b/tools/testing/radix-tre= e/linux/gfp.h deleted file mode 100644 index 32159c08a52e..000000000000 --- a/tools/testing/radix-tree/linux/gfp.h +++ /dev/null @@ -1,33 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef _GFP_H -#define _GFP_H - -#include - -#define __GFP_BITS_SHIFT 26 -#define __GFP_BITS_MASK ((gfp_t)((1 << __GFP_BITS_SHIFT) - 1)) - -#define __GFP_HIGH 0x20u -#define __GFP_IO 0x40u -#define __GFP_FS 0x80u -#define __GFP_NOWARN 0x200u -#define __GFP_ZERO 0x8000u -#define __GFP_ATOMIC 0x80000u -#define __GFP_ACCOUNT 0x100000u -#define __GFP_DIRECT_RECLAIM 0x400000u -#define __GFP_KSWAPD_RECLAIM 0x2000000u - -#define __GFP_RECLAIM (__GFP_DIRECT_RECLAIM|__GFP_KSWAPD_RECLAIM) - -#define GFP_ZONEMASK 0x0fu -#define GFP_ATOMIC (__GFP_HIGH|__GFP_ATOMIC|__GFP_KSWAPD_RECLAIM) -#define GFP_KERNEL (__GFP_RECLAIM | __GFP_IO | __GFP_FS) -#define GFP_NOWAIT (__GFP_KSWAPD_RECLAIM) - - -static inline bool gfpflags_allow_blocking(const gfp_t gfp_flags) -{ - return !!(gfp_flags & __GFP_DIRECT_RECLAIM); -} - -#endif --=20 2.30.2 From nobody Mon Jun 29 22:16:37 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1EABAC433F5 for ; Wed, 2 Feb 2022 11:03:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343679AbiBBLD5 (ORCPT ); Wed, 2 Feb 2022 06:03:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343698AbiBBLDt (ORCPT ); Wed, 2 Feb 2022 06:03:49 -0500 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F172C06173D for ; Wed, 2 Feb 2022 03:03:49 -0800 (PST) Received: by mail-lf1-x12a.google.com with SMTP id x23so39972021lfc.0 for ; Wed, 02 Feb 2022 03:03:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tPBQi8ycxhPpw53EXEIDBSTw4oWSjfC+savcVruO6uA=; b=WwJEQWCdRXYwuNZHU31R7DkmCRUmetwI212MToybeZfZl73Z2bgI61i/prVZBsmiMv xLpe0VeJ9vRbMAGPPCvd7iBO334mUeCA6rfmbR/nU60j0PVn7zIR59eNG5ynX2BmxDL3 nJ4lVVET9OgPdIh2k19zLRytNiCzdIYBaIkZuyY8PxEWdcU4JsNh0wfhBW399E0RYxQ+ A68Q2zug2k05hy4980Dqwd6WdkNGDse4KSnPgnw8GBZ97EuKD19OrmEu1j7CyT48xpMd 0pbitjUTNkkZLCDDmGU1pMcNUR6EeKIXq6dZE/XAP424Uies6IKpxL+3LAf/LDrHRf9z 9qHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tPBQi8ycxhPpw53EXEIDBSTw4oWSjfC+savcVruO6uA=; b=C0c7VgrQq9fH/HyJX/C9zvIACPWIHZ6Xftd8MWAybNqJ1dRGEgPPQYUEoJ330BmuaC 47199dZbj2CP1howRat+itJPGq/GW53y+zzW4EdxfWZ0Q+nX2Fv24BISqFbBkQo9XgGu xuDbTz1SZAeEBl4pEas3wnnYTDMGHUFGcevvRKTkqyYvouj4NEWpP+VwJxPMmFXM/yEL DYomb+cZy9djcmkSvvGAffZ7FpBZIoVst6oiVQHIER1mkOeLYllljC7ie/hHspCfVyYl x/Jmov7ZBl4oJyUkgYPPX5Wl7J6sfO/mVSdAla/9UBwnKrs9STzZecj3RISBZTa7uVMd ceNQ== X-Gm-Message-State: AOAM5319ennB+/3Il/opc1rRudiC7zMy+hC1C1r2UoeXI5ygDtCfO93I CjtjEi8VD2vT2njygvB8fFs= X-Google-Smtp-Source: ABdhPJzcHdDlLm5cSeqsRu39mdUwsKjFNhyPaj1lsd6ekCzFFQSkkTiYv1Rsuj484bEvkf4aF7RqCw== X-Received: by 2002:a05:6512:32cd:: with SMTP id f13mr22538137lfg.306.1643799827782; Wed, 02 Feb 2022 03:03:47 -0800 (PST) Received: from localhost.localdomain (staticline-31-183-164-222.toya.net.pl. [31.183.164.222]) by smtp.gmail.com with ESMTPSA id r14sm4503937lfr.129.2022.02.02.03.03.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 03:03:47 -0800 (PST) From: Karolina Drobnik To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, rppt@kernel.org, linux-kernel@vger.kernel.org, Karolina Drobnik Subject: [PATCH v2 02/16] tools/include: Add phys_addr_t to types.h Date: Wed, 2 Feb 2022 12:03:01 +0100 Message-Id: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Update types.h file to include phys_addr_t typedef so it can be used in testing. Signed-off-by: Karolina Drobnik --- tools/include/linux/types.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/include/linux/types.h b/tools/include/linux/types.h index 6e14a533ab4e..35cedaf191e8 100644 --- a/tools/include/linux/types.h +++ b/tools/include/linux/types.h @@ -64,6 +64,12 @@ typedef __u64 __bitwise __be64; typedef __u16 __bitwise __sum16; typedef __u32 __bitwise __wsum; =20 +#ifdef CONFIG_PHYS_ADDR_T_64BIT +typedef u64 phys_addr_t; +#else +typedef u32 phys_addr_t; +#endif + typedef struct { int counter; } atomic_t; --=20 2.30.2 From nobody Mon Jun 29 22:16:37 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 627F5C433F5 for ; Wed, 2 Feb 2022 11:04:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343741AbiBBLD7 (ORCPT ); Wed, 2 Feb 2022 06:03:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343680AbiBBLDv (ORCPT ); Wed, 2 Feb 2022 06:03:51 -0500 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4679EC061714 for ; Wed, 2 Feb 2022 03:03:51 -0800 (PST) Received: by mail-lf1-x12f.google.com with SMTP id x23so39972179lfc.0 for ; Wed, 02 Feb 2022 03:03:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0AfNznDv6b7CrorpQrureC1eis+2zp1+WJpTDBcjrg8=; b=n6IPg815Ohs/oagqZPKlGwYugQoYojfBPew2vXyYz3U2qVCOUccVMjAuEN34twcOAf c8IAEIB9HIsjqneB8W0yCxJvZxOu4oSzhU26KbN7Cj1EeK1NC51eiILXU5TD86qTJKd9 b2whegXWE40h+D2VYkPoqm6Yis33QfpE1rUS1iCG0HswN36cnNrgMt3Di/A92lzxTfbm k9nBszBFqXsohIvSL/RdZwp8f/va+MmiDGQQCakigIHpFSI5P/WOT+zcPVEaTbZ3WACU juRQExn9wef2NHpUetNwLi2o04c+AGL0xKq0mHJPgwS/HuK7Wb/hpIRbmbr9N30V6Qvf iyNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0AfNznDv6b7CrorpQrureC1eis+2zp1+WJpTDBcjrg8=; b=VJsPWlfIxlzBZkMTrMoQ9GXrGr0efCYOXuqxku4YRtA5VHkqYN/BKzCg0/r5vdQlY4 1QFbMbMMWLg4z5o7OV7PvvsY57IOypQVcOOFJYUTce5q/VlP3j17Mg4LggOPvSjCyXGA rS3ylX0uFiEuVh2L97sv+M7rHvcA9Z5DaGUg1m52L6ESV+wAawVnTJgPKPkdpi6HQePy GHaFMcbkjSn+RbPNkG8Vm12dJvbcAll+vNumoxKRrhqq0kYOcYsuZtQc9aftSVZEJPlb ou/R+broUZtj0Q58aTeN1HYPONi0RIV0T0zPHRGAXE3+tMNBYEaZ6W1KtEZbrN6bLTpc g3jQ== X-Gm-Message-State: AOAM532Q7HQfC2gkol+R3YZGUPqj6TVl7xGkJNjNUEbbMxdpZMMGQvYR 5X0bXBTMQ98iyAXhTlaHnIs= X-Google-Smtp-Source: ABdhPJw0DqLHRPGt/CiIfQOjJeP+7WnZ5gOjm0b71s1NbD+VJ0L5hxMvtXcX0Ee3QhvzEFd3LVoGCg== X-Received: by 2002:ac2:5f53:: with SMTP id 19mr22341777lfz.560.1643799829686; Wed, 02 Feb 2022 03:03:49 -0800 (PST) Received: from localhost.localdomain (staticline-31-183-164-222.toya.net.pl. [31.183.164.222]) by smtp.gmail.com with ESMTPSA id r14sm4503937lfr.129.2022.02.02.03.03.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 03:03:49 -0800 (PST) From: Karolina Drobnik To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, rppt@kernel.org, linux-kernel@vger.kernel.org, Karolina Drobnik Subject: [PATCH v2 03/16] tools/include: Add _RET_IP_ and math definitions to kernel.h Date: Wed, 2 Feb 2022 12:03:02 +0100 Message-Id: <230fea382cb1e1659cdd52a55201854d38a0a149.1643796665.git.karolinadrobnik@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add max_t, min_t and clamp functions, together with _RET_IP_ definition, so they can be used in testing. Signed-off-by: Karolina Drobnik --- tools/include/linux/kernel.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/include/linux/kernel.h b/tools/include/linux/kernel.h index 9701e8307db0..4b0673bf52c2 100644 --- a/tools/include/linux/kernel.h +++ b/tools/include/linux/kernel.h @@ -15,6 +15,8 @@ #define UINT_MAX (~0U) #endif =20 +#define _RET_IP_ ((unsigned long)__builtin_return_address(0)) + #define PERF_ALIGN(x, a) __PERF_ALIGN_MASK(x, (typeof(x))(a)-1) #define __PERF_ALIGN_MASK(x, mask) (((x)+(mask))&~(mask)) =20 @@ -51,6 +53,10 @@ _min1 < _min2 ? _min1 : _min2; }) #endif =20 +#define max_t(type, x, y) max((type)x, (type)y) +#define min_t(type, x, y) min((type)x, (type)y) +#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi) + #ifndef BUG_ON #ifdef NDEBUG #define BUG_ON(cond) do { if (cond) {} } while (0) --=20 2.30.2 From nobody Mon Jun 29 22:16:37 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4BA6AC433EF for ; Wed, 2 Feb 2022 11:04:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241111AbiBBLEC (ORCPT ); Wed, 2 Feb 2022 06:04:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236410AbiBBLDx (ORCPT ); Wed, 2 Feb 2022 06:03:53 -0500 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7D4AC06173D for ; Wed, 2 Feb 2022 03:03:52 -0800 (PST) Received: by mail-lf1-x129.google.com with SMTP id n8so39818076lfq.4 for ; Wed, 02 Feb 2022 03:03:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ni5LWXsIdvXQT5/BHLGBj8Xv8S8a5SpvUuYuO5CqlTQ=; b=kQMSrAAjI+pGgQ8SlI7flQGHgATskFtcVSsGFmCJJ8bWB9j7HLn6o0tz+dKR5V1Iu3 pJeqP0UT6KkL+4dg/IMM3Qqk65FntjaeicFvJREmCu/3N1TTAOze+61vomGoOc+t8f9t V8wr8QPrYHlC8XnROE/k9ytRBlWoffBmqwdzqk5bCkHOkhKotCEd+PU23JoY4raGiZwG CzejVTCz/QF2GCp7jK/dw2Yt1HIrb96C86GFdiP992FPpy49oZa3DD18vdmsPG+Kzwpj 7tsQlyacjvDGLS9Xvw7NJ4SuZjzLII3fAqx4hnAENjia3ekGa3tguU2YIf9mQodprjVx RCLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ni5LWXsIdvXQT5/BHLGBj8Xv8S8a5SpvUuYuO5CqlTQ=; b=dz9dtUuGResBk44mvpK50FSE1UuQ6pxG3Er+ICXuaaSMVbOPfTDmuM/5xRY5+Q25OS yEF9oiyWS1Lg1tkbbsK4bMmyxraGFRYaJ+Hn85IRUtfI2+FRp8csulXAknWraZ5tV9mL DT8GoAwYAXokS0zt7M3l2/baPgXZ8yvgMiV9etZu+JgiTRcvpSUXRMeFqY4w6jqYhGhz +ABV84pSZMoiNNfLs6SM8pKbrX1g0nLANLbIPqQc0R3nKkY8Y62dQGochPxqDIs05E99 o9EPYkvooZORIGCX4+9Hl8CM0+m9nvqEn7I2QkGEvnHTf756WWb8TFk4RDE/IHZ1Cho0 gzZw== X-Gm-Message-State: AOAM532nLCSc7YUH+E6t87Q+Qm66e+RnYi5f8aTLem/RlHraccQZcLVS VyFq/XV3ckysIJqwga3vThAjxxctBh0= X-Google-Smtp-Source: ABdhPJwX9zIpPiaQznX4WrTegPGXBWM9JZIncOyVQRXmZKFqn0uyB8WvaDPXETkhWrVksn2itSiWjA== X-Received: by 2002:ac2:46ed:: with SMTP id q13mr22025537lfo.99.1643799831178; Wed, 02 Feb 2022 03:03:51 -0800 (PST) Received: from localhost.localdomain (staticline-31-183-164-222.toya.net.pl. [31.183.164.222]) by smtp.gmail.com with ESMTPSA id r14sm4503937lfr.129.2022.02.02.03.03.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 03:03:50 -0800 (PST) From: Karolina Drobnik To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, rppt@kernel.org, linux-kernel@vger.kernel.org, Karolina Drobnik Subject: [PATCH v2 04/16] tools/include: Update atomic definitions Date: Wed, 2 Feb 2022 12:03:03 +0100 Message-Id: <082fde69debc36bfc56cdb413d847dcd6b1e36dd.1643796665.git.karolinadrobnik@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add atomic_long_set function to atomic.h and atomic_long_t type to types.h so they can be used in testing. Signed-off-by: Karolina Drobnik --- tools/include/linux/atomic.h | 2 ++ tools/include/linux/types.h | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/tools/include/linux/atomic.h b/tools/include/linux/atomic.h index 00a6c4ca562b..01907b33537e 100644 --- a/tools/include/linux/atomic.h +++ b/tools/include/linux/atomic.h @@ -4,6 +4,8 @@ =20 #include =20 +void atomic_long_set(atomic_long_t *v, long i); + /* atomic_cmpxchg_relaxed */ #ifndef atomic_cmpxchg_relaxed #define atomic_cmpxchg_relaxed atomic_cmpxchg diff --git a/tools/include/linux/types.h b/tools/include/linux/types.h index 35cedaf191e8..5908e58c3598 100644 --- a/tools/include/linux/types.h +++ b/tools/include/linux/types.h @@ -74,6 +74,10 @@ typedef struct { int counter; } atomic_t; =20 +typedef struct { + long counter; +} atomic_long_t; + #ifndef __aligned_u64 # define __aligned_u64 __u64 __attribute__((aligned(8))) #endif --=20 2.30.2 From nobody Mon Jun 29 22:16:37 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D779FC433EF for ; Wed, 2 Feb 2022 11:04:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343787AbiBBLEF (ORCPT ); Wed, 2 Feb 2022 06:04:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343662AbiBBLDz (ORCPT ); Wed, 2 Feb 2022 06:03:55 -0500 Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D4EBC061714 for ; Wed, 2 Feb 2022 03:03:55 -0800 (PST) Received: by mail-lj1-x233.google.com with SMTP id c7so27807488ljr.13 for ; Wed, 02 Feb 2022 03:03:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=35RmHaXHeK6m669VGWye938TGxDNkaZqMu9rSBAQF5s=; b=iriYzWQQQuIEbwIOBGA7gwki+VWO7WGgX0RWVj4GkjUWR+x9I0WaoUPnrY5Cnuvle/ sXpOo6Okrj63d6O2su7feqzRGbXcv/jFHnwmUPR8ogS7Tqp2phkfJVslXD9AoM6nEeZR un7Omyth80LhWDVTi/fZPbezrRrRIwQn9WmgxL4QhZcQkLJxnHfqhkpblYTb2FsaJ1aC vGiomCvAh3ASV7HdCTgDonFWHHXUkxuo5sPKdvCZUcsc1eAaKAGiby4BdNVXz1H3WasR Kq9UUk7NxpS1H7RDWF8zWYKoWPUEbjKeYdgH1cWqRDLMRPErEVdq+2ZR3Solup9alXPO CvkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=35RmHaXHeK6m669VGWye938TGxDNkaZqMu9rSBAQF5s=; b=lPicT8QrOvf78Efgj1QAHz70n+jz64tOFRwIgr1IfN/+rj/tn83z0cnTAatREz7v0X JkWWTBOGvJJMBXby7jef2R0tdbNLNstcnIf71kQMm4m2mlQ932QJX+2zEV/a9bzReTQ5 j48s+fkn39hyUk4FBXho9kCRMOAGpFPBtFR34sMfk9vO6g1FG8v6xHKvN45FWzzQu53X 7YIjeAmE3RWMJ3BQPqbQV+v4plsmYXvSffOTH6Wg99bsPXyeqMYoOgzpaj5lPSKz7QVk 0FOqzCWiGVz0Q+gGRXYaRb4vpj5OhZ6JAcPd3gJrp1/dlvFcz6fQOvd9RE2OWnEPrkf8 Adkg== X-Gm-Message-State: AOAM533M+kTnIkTgd/tRrvgGK/A5bnlzPewn4Z4CDAkBfoBD3B7ZQtek sQNAOiwOtGs4WjVas/sGxQ7sxpR5LeA= X-Google-Smtp-Source: ABdhPJzf5EQFzhhhN2QtspLpurN74Ru+mcLyZF07LMqC3jwh3X5/Z3PJtlCYF9CkFA35hYyQXB4ZfQ== X-Received: by 2002:a2e:502:: with SMTP id 2mr18883481ljf.445.1643799833296; Wed, 02 Feb 2022 03:03:53 -0800 (PST) Received: from localhost.localdomain (staticline-31-183-164-222.toya.net.pl. [31.183.164.222]) by smtp.gmail.com with ESMTPSA id r14sm4503937lfr.129.2022.02.02.03.03.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 03:03:52 -0800 (PST) From: Karolina Drobnik To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, rppt@kernel.org, linux-kernel@vger.kernel.org, Karolina Drobnik Subject: [PATCH v2 05/16] tools/include: Add mm.h file Date: Wed, 2 Feb 2022 12:03:04 +0100 Message-Id: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add a stubbed mm.h file with dummy page-related definitions, memory alignment and physical to virtual address conversions, so they can be used in testing. Signed-off-by: Karolina Drobnik --- tools/include/linux/mm.h | 42 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tools/include/linux/mm.h diff --git a/tools/include/linux/mm.h b/tools/include/linux/mm.h new file mode 100644 index 000000000000..a03d9bba5151 --- /dev/null +++ b/tools/include/linux/mm.h @@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _TOOLS_LINUX_MM_H +#define _TOOLS_LINUX_MM_H + +#include +#include + +#define PAGE_SHIFT 12 +#define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT) +#define PAGE_MASK (~(PAGE_SIZE - 1)) + +#define PHYS_ADDR_MAX (~(phys_addr_t)0) + +#define __ALIGN_KERNEL(x, a) __ALIGN_KERNEL_MASK(x, (typeof(x))(a) - 1) +#define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask)) +#define ALIGN(x, a) __ALIGN_KERNEL((x), (a)) +#define ALIGN_DOWN(x, a) __ALIGN_KERNEL((x) - ((a) - 1), (a)) + +#define PAGE_ALIGN(addr) ALIGN(addr, PAGE_SIZE) + +#define __va(x) ((void *)((unsigned long)(x))) +#define __pa(x) ((unsigned long)(x)) + +#define pfn_to_page(pfn) ((void *)((pfn) * PAGE_SIZE)) + +#define phys_to_virt phys_to_virt +static inline void *phys_to_virt(unsigned long address) +{ + return __va(address); +} + +void reserve_bootmem_region(phys_addr_t start, phys_addr_t end); + +static inline void totalram_pages_inc(void) +{ +} + +static inline void totalram_pages_add(long count) +{ +} + +#endif --=20 2.30.2 From nobody Mon Jun 29 22:16:37 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6FE1C433F5 for ; Wed, 2 Feb 2022 11:04:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343819AbiBBLEK (ORCPT ); Wed, 2 Feb 2022 06:04:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343703AbiBBLD4 (ORCPT ); Wed, 2 Feb 2022 06:03:56 -0500 Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6851FC06173D for ; Wed, 2 Feb 2022 03:03:56 -0800 (PST) Received: by mail-lj1-x232.google.com with SMTP id t9so28291118lji.12 for ; Wed, 02 Feb 2022 03:03:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=100iRySg13jRbyYYPEv3/nn8V1TwHUUo9Gya4DuFw3Y=; b=OW2OZc67gckPCB6/EQ8p6tgVM02YOZg/lTlZsdTRvpaIgrmNps/d8ZUlnZ/Qic6fHh WIaFU2hVMNAK7ucpbrt2+sJwwGN8mtQScHNLrJIxvYDaWAy91BYIAvnSF1V53/uzknT3 2wq7kl0Zae3n1/yCcLyHLGQcjaZwV+1qDQfWUjRIUV9GtYWBEOtkuKjtimy2/8dalScz McOtuy+0euhNw8DqvyTPJrLp/OzMuaQF3ALyOXUCxL8WHAeb1OYleo+u8aWJG4y5NiVo eEpRj8zvxgcWcByAEuOdi1nmKSQmk9gvFRq+rOEVUH86Ctge7zUEuqLnSdOgyTjfzMAi DlMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=100iRySg13jRbyYYPEv3/nn8V1TwHUUo9Gya4DuFw3Y=; b=HJzSc2RvLW7CLPi5d8R4c4v98s2Gdjw69CSD8NSaJcDFXNG6l+tDs4LJxlH88J5Lg6 h3z1fiGk2EKcll46muD+zsMmM7OMzvsUHdyQq5fColhcsZV2jD84m8fz2K6O8Zu4YbYJ LpySANOCUdA7o87vbfA9+JUwq70tXrEGdItpUZobsMBS3ah4L/0SIemo1jckaph6/Fqu JqEBBRl/A037cwBTiph+m/UOB24iNwO5eH0I0QSa5g3oeFZrDjYsqldEvzooHh/nuBKT QpFoD+6buyhOh2JBX5uSOlapWPqVVnCufnbb0LUj0h8tzJX10Jeb7foWooM4yLRC/3FP nEXw== X-Gm-Message-State: AOAM531lRhKcsvIGLhMRgdK8Cn/Z98RtmQwZUOcD1MuRwpZofUmT7hNA 8lzGiS+9k/8fnLVsPARgZFc= X-Google-Smtp-Source: ABdhPJwedQ4oNRP3Zi0OF/J7s0rXaRiHl7TLBC5htK0I4kBF6mFjCrF0jKW1G9qjYdimAlpvWpx5aA== X-Received: by 2002:a2e:b16e:: with SMTP id a14mr18947294ljm.35.1643799834775; Wed, 02 Feb 2022 03:03:54 -0800 (PST) Received: from localhost.localdomain (staticline-31-183-164-222.toya.net.pl. [31.183.164.222]) by smtp.gmail.com with ESMTPSA id r14sm4503937lfr.129.2022.02.02.03.03.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 03:03:54 -0800 (PST) From: Karolina Drobnik To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, rppt@kernel.org, linux-kernel@vger.kernel.org, Karolina Drobnik Subject: [PATCH v2 06/16] tools/include: Add cache.h stub Date: Wed, 2 Feb 2022 12:03:05 +0100 Message-Id: <5e02865094aaf56dd30772722799e53f4130ebc8.1643796665.git.karolinadrobnik@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add a dummy version of the cache header. Signed-off-by: Karolina Drobnik --- tools/include/linux/cache.h | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 tools/include/linux/cache.h diff --git a/tools/include/linux/cache.h b/tools/include/linux/cache.h new file mode 100644 index 000000000000..9e9d585f0b9d --- /dev/null +++ b/tools/include/linux/cache.h @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _TOOLS_LINUX_CACHE_H +#define _TOOLS_LINUX_CACHE_H + +#define L1_CACHE_SHIFT 5 +#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT) + +#define SMP_CACHE_BYTES L1_CACHE_BYTES + +#endif --=20 2.30.2 From nobody Mon Jun 29 22:16:37 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88F76C433F5 for ; Wed, 2 Feb 2022 11:04:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343807AbiBBLEI (ORCPT ); Wed, 2 Feb 2022 06:04:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343723AbiBBLD6 (ORCPT ); Wed, 2 Feb 2022 06:03:58 -0500 Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [IPv6:2a00:1450:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCB6CC06173B for ; Wed, 2 Feb 2022 03:03:57 -0800 (PST) Received: by mail-lj1-x230.google.com with SMTP id c7so27807709ljr.13 for ; Wed, 02 Feb 2022 03:03:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yT95iXzR6dpzPFKNDISp4lTVmaXmzkxChM4JvbaJZPc=; b=iE4mdeqPfE1Mph/jaMT/zW+hVNWX5q/8onyC5syYIgeK/cdmF9RU0lwItEMI1zaCIg PpuKogF9p3TxVtsIua5w6lL7kTZtfwDawFsem54t2Fa0m6lUbyh31bYIxUV1qqQZmDDx BOeR/QsI/W+gHzgAUVPBUlncB8cATRj6/sHukQ3jAGK2HAPX1CxaeSw5X1XNvHiJiq1k 1RNsoO0GFROkqc82G6k1/RQHTdXwONWkootRGqtdGnlDGRWyEqJtkM7Ou0OKzAOK/cqk RGKyTjBJAi6hefkUfLCKokGBv+3R3BJAPwA07DW5jKaK5HFNInUBcfGbfEXfT2sRhM26 K5oA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yT95iXzR6dpzPFKNDISp4lTVmaXmzkxChM4JvbaJZPc=; b=nWmNODl09flfxuAbtByjR8sa3u6M8qEfHRAvQPPQKhgOXHYhOKa8UMPzwMbJt1qQmt KXEutLlLARUKgtleg0YuFhNCNqBRAH+Ag0+p4r9mHljjlOW4FOYSQF0sY5EaJShu7+I6 cY4H26Pt5cWUrMT4m+wvpd8P1MPcq4mgV6QyNi2+M1ldfZs6/SSQH8kPwJyliaS/orV1 t0+LNa8rucOSoldmUWX0Cl91GjttAR7mJ7fasr0BWFJMwu6wbYiuUJOGNm+6JEec916j kRg5iuGuu4wwMaAENGWajUWYZ50uUCqki7uD2Rqb6pgtXpncMj6U1KkRhtSnZ+ova0uo /qjQ== X-Gm-Message-State: AOAM533qLSB9uL7+52qgV4yeHdlGkcAis201kDvuCovthswzF4wplPuc TQ1Gmr22OO12GLKdOkEzFYI= X-Google-Smtp-Source: ABdhPJzgBZbfgR9GawWUkwNaS8vMZNF0FJJGJ4e8v5IYrgP+TAk9VPoIPqWHSgiJkWxwsncnYTwUBg== X-Received: by 2002:a05:651c:a0f:: with SMTP id k15mr16823902ljq.80.1643799836226; Wed, 02 Feb 2022 03:03:56 -0800 (PST) Received: from localhost.localdomain (staticline-31-183-164-222.toya.net.pl. [31.183.164.222]) by smtp.gmail.com with ESMTPSA id r14sm4503937lfr.129.2022.02.02.03.03.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 03:03:55 -0800 (PST) From: Karolina Drobnik To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, rppt@kernel.org, linux-kernel@vger.kernel.org, Karolina Drobnik Subject: [PATCH v2 07/16] tools/include: Add io.h stub Date: Wed, 2 Feb 2022 12:03:06 +0100 Message-Id: <3e8d42cbd01382d956d393cf3bb2a6d639dfdd97.1643796665.git.karolinadrobnik@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add a dummy io.h header. Signed-off-by: Karolina Drobnik --- tools/include/linux/io.h | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 tools/include/linux/io.h diff --git a/tools/include/linux/io.h b/tools/include/linux/io.h new file mode 100644 index 000000000000..e129871fe661 --- /dev/null +++ b/tools/include/linux/io.h @@ -0,0 +1,5 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _TOOLS_IO_H +#define _TOOLS_IO_H + +#endif --=20 2.30.2 From nobody Mon Jun 29 22:16:37 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C25DC4332F for ; Wed, 2 Feb 2022 11:04:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343832AbiBBLEM (ORCPT ); Wed, 2 Feb 2022 06:04:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343740AbiBBLD7 (ORCPT ); Wed, 2 Feb 2022 06:03:59 -0500 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30870C06173E for ; Wed, 2 Feb 2022 03:03:59 -0800 (PST) Received: by mail-lf1-x132.google.com with SMTP id f10so13331600lfu.8 for ; Wed, 02 Feb 2022 03:03:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sNs/YC3QiYenr3GANxWYR7pSc71WK+SMMsFAwX5F+fg=; b=OrUL6R1VdOCyt4DHOzKb3U0lSiUDUjKMkBAOBuO3x/wlkdS+XasKS52HTlCiwCbePU Bv7C7ckNehqifsdJKXMbRrwzfrJ5jNemCJR1P0i37Z44SUm0Ep9OXHFOYl4CnPszWM3W nZuI+bfx6KmOk8hVgAkvVyjGUfQFqhgZ5Nq1RLylPewKQMRhtGOQrd1vidDBvwFRp2CA rDnYzoULpSReuIcaR0dBj52TXlx2oUm5cjewxf0uLXv0gWSU61SZ/yqwIsW9xiRz5cIp FDyerRR/c9OkDWmv7zjXuKLw/KETw6JKoHOV65tymsV1HHJEkzj5DTSxiFMELyZwaWq/ +UgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sNs/YC3QiYenr3GANxWYR7pSc71WK+SMMsFAwX5F+fg=; b=W/5QXiIznqhnnq3JjGmeLqZvrzIQ6aQgiO+mjyUzP7Eop8jX0vgNKcKcSfi8jmaFoB aikTjFMreL0m7y1SetCkh0041K9qeaX4+Iuapmx3zcp/N7281+Wo2lU51+mXGQB2vImv gWgJB7sCtnlvWDVtkxjtyX2H2+t5KakmUf59an3DE8+6zcllFR30CWSkJnqvJypo0TKi i0Q6c8r0oEY/Cfz+Q5naic4YT193Le9dLBJL1x7dIM2k25RJU5tXGfccNBQiU/Em16X3 gMYc/rhbHRoGIO549u2XB9pCidP/FcGzM4zrCo1BeM88pJK6ZDPuRuGbALm8uzseKOi7 hLkg== X-Gm-Message-State: AOAM5311JJCliA4DDCQV0Avr9zwsaVwH9qP3IGUnf1nDui+or10iqP+u rhKFrj5ftTAOyA4sSNEsswo= X-Google-Smtp-Source: ABdhPJySwmroBSIuxOQEqIYwYJUYcouxEo3LAxCYYAts+oUUc6IRw/0BqJd1GNNe0Zgd5wMxe1iN/w== X-Received: by 2002:a05:6512:3487:: with SMTP id v7mr22242867lfr.310.1643799837592; Wed, 02 Feb 2022 03:03:57 -0800 (PST) Received: from localhost.localdomain (staticline-31-183-164-222.toya.net.pl. [31.183.164.222]) by smtp.gmail.com with ESMTPSA id r14sm4503937lfr.129.2022.02.02.03.03.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 03:03:57 -0800 (PST) From: Karolina Drobnik To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, rppt@kernel.org, linux-kernel@vger.kernel.org, Karolina Drobnik Subject: [PATCH v2 08/16] tools/include: Add pfn.h stub Date: Wed, 2 Feb 2022 12:03:07 +0100 Message-Id: <1bdc02125963f945bf90dd8cb37c404cc0688af2.1643796665.git.karolinadrobnik@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add a stubbed pfn header with definitions used in testing. Signed-off-by: Karolina Drobnik --- tools/include/linux/pfn.h | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 tools/include/linux/pfn.h diff --git a/tools/include/linux/pfn.h b/tools/include/linux/pfn.h new file mode 100644 index 000000000000..7512a58189eb --- /dev/null +++ b/tools/include/linux/pfn.h @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _TOOLS_LINUX_PFN_H_ +#define _TOOLS_LINUX_PFN_H_ + +#include + +#define PFN_UP(x) (((x) + PAGE_SIZE - 1) >> PAGE_SHIFT) +#define PFN_DOWN(x) ((x) >> PAGE_SHIFT) +#define PFN_PHYS(x) ((phys_addr_t)(x) << PAGE_SHIFT) +#endif --=20 2.30.2 From nobody Mon Jun 29 22:16:37 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04BB5C433F5 for ; Wed, 2 Feb 2022 11:04:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343750AbiBBLEX (ORCPT ); Wed, 2 Feb 2022 06:04:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343756AbiBBLEB (ORCPT ); Wed, 2 Feb 2022 06:04:01 -0500 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28E1FC061744 for ; Wed, 2 Feb 2022 03:04:01 -0800 (PST) Received: by mail-lf1-x135.google.com with SMTP id i34so19513577lfv.2 for ; Wed, 02 Feb 2022 03:04:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xpVlgTajQnqvJqRBDECMdTOPT5OH4VewpY+I2k89SJw=; b=KTxXcoTi64NY8Y934prTF0adkrL4z14Y61yYIWmmshg5rY5ZxuO2xIFvQ8lOlGpw4q 9tLIcsukBa9zEqHAc46MsKkrJQLX9XTu34RwLZiqRa/EGd4Y7zJzJD1MC48CrPHo+D8L Y8zLmsXCMVmg2umgooaXOpE2XAdkNXWUVJdYZxQxNJp/wm1RddxmwFxS5xdxyoLmjWii yCPdTONhC6k5jqoYwcwwpypqJnA0ZnMU18AQz1SWcl7ghtTlonR98/Uvl/I8cENkU8Nk MNxYMEApYhLWB+dVJqkb6IILbYNMVM0gm31ma2dM1ivAaadptq9uEQ3SLLbAOX0IAn8w ctxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xpVlgTajQnqvJqRBDECMdTOPT5OH4VewpY+I2k89SJw=; b=B63Lcq093yG57emrONVzj7TtBkhBaX7TToEwTPkuyJX35gKtJ6I9XJuvR+NDeTnznJ q56kGCrNd/xkFCSpkocLd22mIYgn7nLEwBrgisolCNqeMHL+qZH0Z1KihnucfoPkAuXx baj8/NxKAPTwg1OArGVEqyfF7u3K0RdNuxheSl3YbCvHSuVsMG6PH854BQh7QsSTGQvI 3BLIeQo6M0MVKNKVCZ3oZ6PlUoUtlnJnZlGTf+YE0+qz844WRtHtt+NNEPOt+B5Ri3EL Cifr26rY8YvpwwmCg5slTW+FQjv+3pk8KciKubXYYuBHvOciOApzHAjd+xBSvCfX6wu6 sgnw== X-Gm-Message-State: AOAM532XGNZ0xGve+llzhw4tXgeGM05ECHzRoqwWLKzBM4to1YtKddrq IHrEPT873RWMn3l65AgUdBQ= X-Google-Smtp-Source: ABdhPJyzQYQ1cX6D53RlAyOvCuRYgn0WsOWnSNuQhfJ8XHfT6mWbulgsMfUd+7chrt0cHcYisD7xCQ== X-Received: by 2002:ac2:4c4c:: with SMTP id o12mr21907306lfk.182.1643799839573; Wed, 02 Feb 2022 03:03:59 -0800 (PST) Received: from localhost.localdomain (staticline-31-183-164-222.toya.net.pl. [31.183.164.222]) by smtp.gmail.com with ESMTPSA id r14sm4503937lfr.129.2022.02.02.03.03.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 03:03:58 -0800 (PST) From: Karolina Drobnik To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, rppt@kernel.org, linux-kernel@vger.kernel.org, Karolina Drobnik Subject: [PATCH v2 09/16] tools/include: Add debugfs.h stub Date: Wed, 2 Feb 2022 12:03:08 +0100 Message-Id: <80fceff27934094873cc3f0656d22e802dfcce78.1643796665.git.karolinadrobnik@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add a dummy debugfs.h header. Signed-off-by: Karolina Drobnik --- tools/include/linux/debugfs.h | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 tools/include/linux/debugfs.h diff --git a/tools/include/linux/debugfs.h b/tools/include/linux/debugfs.h new file mode 100644 index 000000000000..4ba06140b1be --- /dev/null +++ b/tools/include/linux/debugfs.h @@ -0,0 +1,5 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _TOOLS_DEBUGFS_H +#define _TOOLS_DEBUGFS_H + +#endif --=20 2.30.2 From nobody Mon Jun 29 22:16:37 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72B0BC433F5 for ; Wed, 2 Feb 2022 11:04:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343727AbiBBLE0 (ORCPT ); Wed, 2 Feb 2022 06:04:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343697AbiBBLEG (ORCPT ); Wed, 2 Feb 2022 06:04:06 -0500 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B76C4C06174A for ; Wed, 2 Feb 2022 03:04:02 -0800 (PST) Received: by mail-lf1-x132.google.com with SMTP id k13so7542151lfg.9 for ; Wed, 02 Feb 2022 03:04:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=frSxJsenabMGYgz0iYH0G/tZpbsKwlTyJiIBXkslbKA=; b=VqvfK+mJwe35fv5IGXARk4nhqGyaq7TsJDgSIvhsno7rcN+kyAWf7SNo0jQS+r/RZ4 KFxdvpvYsUamXQsRLJGp+pXIj6SGBDJZFk8VrFT3RirLo+IAy2FKCIDJAtG5opOohABL l1FYRHI5v+xj3erHVKohqVZqKrs3hTnu0AqoXt87rfvzjasSgt0p2klPk7itipgwcZtl vtSZgDyj178NPDSEw4lb3cOF7W++XoJ2jsfUNWwGzOINUFIHzeikUtAqFaowMiOF69u7 t3T6luTeKVbNlpthOO/eUYZXHxe2twU+xnZrlp6YHQKtOFqrjNFg0NxbJAhWP/scbAvL oI4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=frSxJsenabMGYgz0iYH0G/tZpbsKwlTyJiIBXkslbKA=; b=20zGypJejmorHd4Y8r41n75k8Cg2BkkV/BUQnZWdztLjuT25/qCAYBXKGsN5OktCcv jDMztoaNP27lO+XjDasxsg4jO7gpStcdp+BswhUi9je4tvWGh+0//vIaQLRknphPXlOa IeiFPdTmHFh7Gn/D1o7j3OKV0i9RgHcrRmlAD8AolpRHFHXdzIkFyi/rlBJEoSLRVZQ4 PQ5edBGsAdBNXx0x/1qSG3PJVAwHSKixP1lEFY2RM8uM93EAtExq83xh2axrsUYQzp9X LGpgSP0u1nAxRkR18sWsNCNM0HXhr/4vUdfxbSluGQaLGoXgGPBE9RmCRNOuImBvUNNM Uw0w== X-Gm-Message-State: AOAM531+af0sk8jfLgaqPHjqwVPtztuedn6gSJL6MwRqg5mnCkrOjjnn ptA3fIZJxFfsbjKnRGYYNbY= X-Google-Smtp-Source: ABdhPJws6G1iAazt3hqXhISVwa1U+jVQuk1ODxJP7q/Y5LSdKb9PKgw6etgnPnEt78WwChs4W5Mumw== X-Received: by 2002:a05:6512:3b9b:: with SMTP id g27mr22655463lfv.655.1643799841057; Wed, 02 Feb 2022 03:04:01 -0800 (PST) Received: from localhost.localdomain (staticline-31-183-164-222.toya.net.pl. [31.183.164.222]) by smtp.gmail.com with ESMTPSA id r14sm4503937lfr.129.2022.02.02.03.04.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 03:04:00 -0800 (PST) From: Karolina Drobnik To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, rppt@kernel.org, linux-kernel@vger.kernel.org, Karolina Drobnik Subject: [PATCH v2 10/16] memblock tests: Add skeleton of the memblock simulator Date: Wed, 2 Feb 2022 12:03:09 +0100 Message-Id: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 --- MAINTAINERS | 1 + tools/include/linux/slab.h | 10 ++++ tools/testing/memblock/.gitignore | 4 ++ tools/testing/memblock/Makefile | 52 +++++++++++++++++++ tools/testing/memblock/asm/dma.h | 5 ++ tools/testing/memblock/internal.h | 12 +++++ tools/testing/memblock/lib/slab.c | 9 ++++ tools/testing/memblock/linux/init.h | 34 ++++++++++++ tools/testing/memblock/linux/kernel.h | 12 +++++ tools/testing/memblock/linux/kmemleak.h | 18 +++++++ tools/testing/memblock/linux/memory_hotplug.h | 19 +++++++ tools/testing/memblock/linux/mmzone.h | 35 +++++++++++++ tools/testing/memblock/linux/printk.h | 25 +++++++++ tools/testing/memblock/main.c | 6 +++ tools/testing/memblock/mmzone.c | 20 +++++++ .../testing/memblock/scripts/Makefile.include | 17 ++++++ 16 files changed, 279 insertions(+) create mode 100644 tools/testing/memblock/.gitignore create mode 100644 tools/testing/memblock/Makefile create mode 100644 tools/testing/memblock/asm/dma.h create mode 100644 tools/testing/memblock/internal.h create mode 100644 tools/testing/memblock/lib/slab.c create mode 100644 tools/testing/memblock/linux/init.h create mode 100644 tools/testing/memblock/linux/kernel.h create mode 100644 tools/testing/memblock/linux/kmemleak.h create mode 100644 tools/testing/memblock/linux/memory_hotplug.h create mode 100644 tools/testing/memblock/linux/mmzone.h create mode 100644 tools/testing/memblock/linux/printk.h create mode 100644 tools/testing/memblock/main.c create mode 100644 tools/testing/memblock/mmzone.c create mode 100644 tools/testing/memblock/scripts/Makefile.include diff --git a/MAINTAINERS b/MAINTAINERS index f41088418aae..86ae61c39171 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -12406,6 +12406,7 @@ S: Maintained F: Documentation/core-api/boot-time-mm.rst F: include/linux/memblock.h F: mm/memblock.c +F: tools/testing/memblock/ =20 MEMORY CONTROLLER DRIVERS M: Krzysztof Kozlowski diff --git a/tools/include/linux/slab.h b/tools/include/linux/slab.h index 07d7930d4003..f41d8a0eb1a4 100644 --- a/tools/include/linux/slab.h +++ b/tools/include/linux/slab.h @@ -13,6 +13,16 @@ void *kmalloc(size_t size, gfp_t gfp); void kfree(void *p); =20 +bool slab_is_available(void); + +enum slab_state { + DOWN, + PARTIAL, + PARTIAL_NODE, + UP, + FULL +}; + static inline void *kzalloc(size_t size, gfp_t gfp) { return kmalloc(size, gfp | __GFP_ZERO); diff --git a/tools/testing/memblock/.gitignore b/tools/testing/memblock/.gi= tignore new file mode 100644 index 000000000000..654338e0be52 --- /dev/null +++ b/tools/testing/memblock/.gitignore @@ -0,0 +1,4 @@ +main +memblock.c +linux/memblock.h +asm/cmpxchg.h diff --git a/tools/testing/memblock/Makefile b/tools/testing/memblock/Makef= ile new file mode 100644 index 000000000000..e43ed9de9bcf --- /dev/null +++ b/tools/testing/memblock/Makefile @@ -0,0 +1,52 @@ +# SPDX-License-Identifier: GPL-2.0 + +# Memblock simulator requires AddressSanitizer (libasan) and liburcu devel= opment +# packages installed +CFLAGS +=3D -I. -I../../include -Wall -O2 -fsanitize=3Daddress \ + -fsanitize=3Dundefined -D CONFIG_PHYS_ADDR_T_64BIT +LDFLAGS +=3D -fsanitize=3Daddress -fsanitize=3Dundefined +TARGETS =3D main +OFILES =3D main.o memblock.o lib/slab.o mmzone.o slab.o +EXTR_SRC =3D ../../../mm/memblock.c + +ifeq ($(BUILD), 32) + CFLAGS +=3D -m32 + LDFLAGS +=3D -m32 +endif + +# Process user parameters +include scripts/Makefile.include + +main: $(OFILES) + +$(OFILES): include + +include: ../../../include/linux/memblock.h ../../include/linux/*.h \ + ../../include/asm/*.h + + @mkdir -p linux + test -L linux/memblock.h || ln -s ../../../../include/linux/memblock.h li= nux/memblock.h + test -L asm/cmpxchg.h || ln -s ../../../arch/x86/include/asm/cmpxchg.h as= m/cmpxchg.h + +memblock.c: $(EXTR_SRC) + test -L memblock.c || ln -s $(EXTR_SRC) memblock.c + +clean: + $(RM) $(TARGETS) $(OFILES) linux/memblock.h memblock.c asm/cmpxchg.h + +help: + @echo 'Memblock simulator' + @echo '' + @echo 'Available targets:' + @echo ' main - Build the memblock simulator' + @echo ' clean - Remove generated files and symlinks in the directory' + @echo '' + @echo 'Configuration:' + @echo ' make NUMA=3D1 - simulate enabled NUMA' + @echo ' make MOVABLE_NODE=3D1 - override `movable_node_is_enabled= `' + @echo ' definition to simulate movable NUMA= nodes' + @echo ' make 32BIT_PHYS_ADDR_T=3D1 - Use 32 bit physical addresses' + +vpath %.c ../../lib + +.PHONY: clean include help diff --git a/tools/testing/memblock/asm/dma.h b/tools/testing/memblock/asm/= dma.h new file mode 100644 index 000000000000..13ff8e5d22ef --- /dev/null +++ b/tools/testing/memblock/asm/dma.h @@ -0,0 +1,5 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _TOOLS_DMA_H +#define _TOOLS_DMA_H + +#endif diff --git a/tools/testing/memblock/internal.h b/tools/testing/memblock/int= ernal.h new file mode 100644 index 000000000000..94b52a8718b5 --- /dev/null +++ b/tools/testing/memblock/internal.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef _MM_INTERNAL_H +#define _MM_INTERNAL_H + +struct page {}; + +void memblock_free_pages(struct page *page, unsigned long pfn, + unsigned int order) +{ +} + +#endif diff --git a/tools/testing/memblock/lib/slab.c b/tools/testing/memblock/lib= /slab.c new file mode 100644 index 000000000000..6be6020328fb --- /dev/null +++ b/tools/testing/memblock/lib/slab.c @@ -0,0 +1,9 @@ +// SPDX-License-Identifier: GPL-2.0 +#include + +enum slab_state slab_state; + +bool slab_is_available(void) +{ + return slab_state >=3D UP; +} diff --git a/tools/testing/memblock/linux/init.h b/tools/testing/memblock/l= inux/init.h new file mode 100644 index 000000000000..828e0ee0bc6c --- /dev/null +++ b/tools/testing/memblock/linux/init.h @@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_INIT_H +#define _LINUX_INIT_H + +#include +#include +#include + +#define __section(section) __attribute__((__section__(section= ))) + +#define __initconst +#define __meminit +#define __meminitdata +#define __refdata +#define __initdata + +struct obs_kernel_param { + const char *str; + int (*setup_func)(char *st); + int early; +}; + +#define __setup_param(str, unique_id, fn, early) \ + static const char __setup_str_##unique_id[] __initconst \ + __aligned(1) =3D str; \ + static struct obs_kernel_param __setup_##unique_id \ + __used __section(".init.setup") \ + __aligned(__alignof__(struct obs_kernel_param)) =3D \ + { __setup_str_##unique_id, fn, early } + +#define early_param(str, fn) \ + __setup_param(str, fn, fn, 1) + +#endif diff --git a/tools/testing/memblock/linux/kernel.h b/tools/testing/memblock= /linux/kernel.h new file mode 100644 index 000000000000..d2f148bd8902 --- /dev/null +++ b/tools/testing/memblock/linux/kernel.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _MEMBLOCK_LINUX_KERNEL_H +#define _MEMBLOCK_LINUX_KERNEL_H + +#include <../../include/linux/kernel.h> +#include +#include +#include +#include +#include + +#endif diff --git a/tools/testing/memblock/linux/kmemleak.h b/tools/testing/memblo= ck/linux/kmemleak.h new file mode 100644 index 000000000000..462f8c5e8aa0 --- /dev/null +++ b/tools/testing/memblock/linux/kmemleak.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _KMEMLEAK_H +#define _KMEMLEAK_H + +static inline void kmemleak_free_part_phys(phys_addr_t phys, size_t size) +{ +} + +static inline void kmemleak_alloc_phys(phys_addr_t phys, size_t size, + int min_count, gfp_t gfp) +{ +} + +static inline void dump_stack(void) +{ +} + +#endif diff --git a/tools/testing/memblock/linux/memory_hotplug.h b/tools/testing/= memblock/linux/memory_hotplug.h new file mode 100644 index 000000000000..47988765a219 --- /dev/null +++ b/tools/testing/memblock/linux/memory_hotplug.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_MEMORY_HOTPLUG_H +#define _LINUX_MEMORY_HOTPLUG_H + +#include +#include +#include +#include + +static inline bool movable_node_is_enabled(void) +{ +#ifdef MOVABLE_NODE + return true; +#else + return false; +#endif +} + +#endif diff --git a/tools/testing/memblock/linux/mmzone.h b/tools/testing/memblock= /linux/mmzone.h new file mode 100644 index 000000000000..7c2eb5c9bb54 --- /dev/null +++ b/tools/testing/memblock/linux/mmzone.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _TOOLS_MMZONE_H +#define _TOOLS_MMZONE_H + +#include + +struct pglist_data *first_online_pgdat(void); +struct pglist_data *next_online_pgdat(struct pglist_data *pgdat); + +#define for_each_online_pgdat(pgdat) \ + for (pgdat =3D first_online_pgdat(); \ + pgdat; \ + pgdat =3D next_online_pgdat(pgdat)) + +enum zone_type { + __MAX_NR_ZONES +}; + +#define MAX_NR_ZONES __MAX_NR_ZONES +#define MAX_ORDER 11 +#define MAX_ORDER_NR_PAGES (1 << (MAX_ORDER - 1)) + +#define pageblock_order (MAX_ORDER - 1) +#define pageblock_nr_pages BIT(pageblock_order) + +struct zone { + atomic_long_t managed_pages; +}; + +typedef struct pglist_data { + struct zone node_zones[MAX_NR_ZONES]; + +} pg_data_t; + +#endif diff --git a/tools/testing/memblock/linux/printk.h b/tools/testing/memblock= /linux/printk.h new file mode 100644 index 000000000000..61af424d8c6c --- /dev/null +++ b/tools/testing/memblock/linux/printk.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _PRINTK_H +#define _PRINTK_H + +#include +#include + +/* + * memblock_dbg is called with u64 arguments that don't match the "%llu" + * specifier in printf. This results in warnings that cannot be fixed with= out + * modifying memblock.c, which we wish to avoid. As these messaged are not= used + * in testing anyway, the mismatch can be ignored. + */ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wformat" +#define printk printf +#pragma GCC diagnostic push + +#define pr_info printk +#define pr_debug printk +#define pr_cont printk +#define pr_err printk +#define pr_warn printk + +#endif diff --git a/tools/testing/memblock/main.c b/tools/testing/memblock/main.c new file mode 100644 index 000000000000..62958da35d0f --- /dev/null +++ b/tools/testing/memblock/main.c @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +int main(int argc, char **argv) +{ + return 0; +} diff --git a/tools/testing/memblock/mmzone.c b/tools/testing/memblock/mmzon= e.c new file mode 100644 index 000000000000..7b0909e8b759 --- /dev/null +++ b/tools/testing/memblock/mmzone.c @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#include + +struct pglist_data *first_online_pgdat(void) +{ + return NULL; +} + +struct pglist_data *next_online_pgdat(struct pglist_data *pgdat) +{ + return NULL; +} + +void reserve_bootmem_region(phys_addr_t start, phys_addr_t end) +{ +} + +void atomic_long_set(atomic_long_t *v, long i) +{ +} diff --git a/tools/testing/memblock/scripts/Makefile.include b/tools/testin= g/memblock/scripts/Makefile.include new file mode 100644 index 000000000000..699b0d6cda07 --- /dev/null +++ b/tools/testing/memblock/scripts/Makefile.include @@ -0,0 +1,17 @@ +# SPDX-License-Identifier: GPL-2.0 +# Definitions for user-provided arguments + +# Simulate CONFIG_NUMA=3Dy +ifeq ($(NUMA), 1) + CFLAGS +=3D -D CONFIG_NUMA +endif + +# Simulate movable NUMA memory regions +ifeq ($(MOVABLE_NODE), 1) + CFLAGS +=3D -D MOVABLE_NODE +endif + +# Use 32 bit physical addresses +ifeq ($(32BIT_PHYS_ADDR_T), 1) + CFLAGS +=3D -U CONFIG_PHYS_ADDR_T_64BIT +endif --=20 2.30.2 From nobody Mon Jun 29 22:16:37 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4ADCFC433EF for ; Wed, 2 Feb 2022 11:04:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343824AbiBBLEa (ORCPT ); Wed, 2 Feb 2022 06:04:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343793AbiBBLEG (ORCPT ); Wed, 2 Feb 2022 06:04:06 -0500 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6446CC061751 for ; Wed, 2 Feb 2022 03:04:04 -0800 (PST) Received: by mail-lf1-x12f.google.com with SMTP id u6so39787675lfm.10 for ; Wed, 02 Feb 2022 03:04:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=N4kQ7fCJQ83r9kjg6pIOnmCnBUnFX1leJDY6JkaRj+I=; b=VCWp1/CXErfDv2Si1Pb/0PNFj0BpYEAaoZj/+jKibP0b5cXP2y1E/YqFS0UBPQVp1g VECS2+1yJsPv5eJX3WlFnzEV7abFllvb16b0DSENlnUItUUIN0XJWqlPUaV3zF/TLAVQ BHoIuOxr9ytZrBiPPrSTozaI2/URo9Smr5x3zqP4E8JHHuHDH1r3G9sUKR7xsUqiKw+i XAVBxTjbyF4kN2F3SQVxTuLCvisSBXXop5VhHA6BPEAZg/G9d10GdacFF9+Ux3DgWEBu gvrJi/6VSZ8w0LXRHCssuKYCvLsA1NuVCC0a7UwN1BbeXf+MzZYh8oL/ZEio03Dtc3iH x1UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=N4kQ7fCJQ83r9kjg6pIOnmCnBUnFX1leJDY6JkaRj+I=; b=pFGTuBecy0djROA5EE7Q80IWh9Xb1/yqpcv3NC1CJMfFAH3LacT479lB+IGwHm3MQe Rglfa9M/KGvi9i6goL+5Q7NjwvM2ipN9KBCQlD/wshN1c4xiXYUCLCZn3RvnhzIlYRtD pv6GSYZU7kg1f8PWifS10jOnInOoMhlHBal/CUEu/ERgR/hxauAc6/GrTZN+w8Z6hr8z ejo9cy+S2ZpbFq4aBgKkK/5oSGjUvR3wk0JzcQE39H6YzEqqCl1Ngl3tJm2Vg5aLTxZx KbGW1lQ8oBhqoqNXac53ZAVxBoY8fBsJqU1Pp2F2O0xGCCMQNBlSleNXfm3cUVBvmKGP Euow== X-Gm-Message-State: AOAM530XvD+NKa4+yf8jsvHDPW1AehYZkPG5zWvrGA3hmGHrMza/ZB7p 0kwH03+VPxeaGPyNE6TRrVw= X-Google-Smtp-Source: ABdhPJyCsJagbftgFxK2KvEqWWcPAQVBWfOi40WcO5VfiKDerxcwIHDP/STqsOYl6D6jHgRCJGdr5A== X-Received: by 2002:a05:6512:31d3:: with SMTP id j19mr24517829lfe.112.1643799842782; Wed, 02 Feb 2022 03:04:02 -0800 (PST) Received: from localhost.localdomain (staticline-31-183-164-222.toya.net.pl. [31.183.164.222]) by smtp.gmail.com with ESMTPSA id r14sm4503937lfr.129.2022.02.02.03.04.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 03:04:02 -0800 (PST) From: Karolina Drobnik To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, rppt@kernel.org, linux-kernel@vger.kernel.org, Karolina Drobnik Subject: [PATCH v2 11/16] memblock tests: Add memblock reset function Date: Wed, 2 Feb 2022 12:03:10 +0100 Message-Id: <8c185aa7e0dd68c2c7e937c9a06c90ae413e240f.1643796665.git.karolinadrobnik@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Memblock simulator needs to be able to reset memblock data structures between different test cases. Add a function that sets all fields to their default values. Add a test checking if memblock is being initialized to expected values. Signed-off-by: Karolina Drobnik --- tools/testing/memblock/Makefile | 4 ++- tools/testing/memblock/main.c | 2 ++ tools/testing/memblock/tests/basic_api.c | 32 ++++++++++++++++++++++++ tools/testing/memblock/tests/basic_api.h | 10 ++++++++ tools/testing/memblock/tests/common.c | 27 ++++++++++++++++++++ tools/testing/memblock/tests/common.h | 15 +++++++++++ 6 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 tools/testing/memblock/tests/basic_api.c create mode 100644 tools/testing/memblock/tests/basic_api.h create mode 100644 tools/testing/memblock/tests/common.c create mode 100644 tools/testing/memblock/tests/common.h diff --git a/tools/testing/memblock/Makefile b/tools/testing/memblock/Makef= ile index e43ed9de9bcf..29715327a2d3 100644 --- a/tools/testing/memblock/Makefile +++ b/tools/testing/memblock/Makefile @@ -6,7 +6,9 @@ CFLAGS +=3D -I. -I../../include -Wall -O2 -fsanitize=3Daddr= ess \ -fsanitize=3Dundefined -D CONFIG_PHYS_ADDR_T_64BIT LDFLAGS +=3D -fsanitize=3Daddress -fsanitize=3Dundefined TARGETS =3D main -OFILES =3D main.o memblock.o lib/slab.o mmzone.o slab.o +TEST_OFILES =3D tests/basic_api.o tests/common.o +DEP_OFILES =3D memblock.o lib/slab.o mmzone.o slab.o +OFILES =3D main.o $(DEP_OFILES) $(TEST_OFILES) EXTR_SRC =3D ../../../mm/memblock.c =20 ifeq ($(BUILD), 32) diff --git a/tools/testing/memblock/main.c b/tools/testing/memblock/main.c index 62958da35d0f..da65b0adee91 100644 --- a/tools/testing/memblock/main.c +++ b/tools/testing/memblock/main.c @@ -1,6 +1,8 @@ // SPDX-License-Identifier: GPL-2.0-or-later +#include "tests/basic_api.h" =20 int main(int argc, char **argv) { + memblock_basic_checks(); return 0; } diff --git a/tools/testing/memblock/tests/basic_api.c b/tools/testing/membl= ock/tests/basic_api.c new file mode 100644 index 000000000000..7f2597b3dd4d --- /dev/null +++ b/tools/testing/memblock/tests/basic_api.c @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#include +#include +#include "basic_api.h" + +#define EXPECTED_MEMBLOCK_REGIONS 128 + +static int memblock_initialization_check(void) +{ + reset_memblock(); + + assert(memblock.memory.regions); + assert(memblock.memory.cnt =3D=3D 1); + assert(memblock.memory.max =3D=3D EXPECTED_MEMBLOCK_REGIONS); + assert(strcmp(memblock.memory.name, "memory") =3D=3D 0); + + assert(memblock.reserved.regions); + assert(memblock.reserved.cnt =3D=3D 1); + assert(memblock.memory.max =3D=3D EXPECTED_MEMBLOCK_REGIONS); + assert(strcmp(memblock.reserved.name, "reserved") =3D=3D 0); + + assert(!memblock.bottom_up); + assert(memblock.current_limit =3D=3D MEMBLOCK_ALLOC_ANYWHERE); + + return 0; +} + +int memblock_basic_checks(void) +{ + memblock_initialization_check(); + return 0; +} diff --git a/tools/testing/memblock/tests/basic_api.h b/tools/testing/membl= ock/tests/basic_api.h new file mode 100644 index 000000000000..1ceecfca1f47 --- /dev/null +++ b/tools/testing/memblock/tests/basic_api.h @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef _MEMBLOCK_BASIC_H +#define _MEMBLOCK_BASIC_H + +#include +#include "common.h" + +int memblock_basic_checks(void); + +#endif diff --git a/tools/testing/memblock/tests/common.c b/tools/testing/memblock= /tests/common.c new file mode 100644 index 000000000000..03de6eab0c3c --- /dev/null +++ b/tools/testing/memblock/tests/common.c @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#include "tests/common.h" +#include + +#define INIT_MEMBLOCK_REGIONS 128 +#define INIT_MEMBLOCK_RESERVED_REGIONS INIT_MEMBLOCK_REGIONS + +void reset_memblock(void) +{ + memset(memblock.memory.regions, 0, + memblock.memory.cnt * sizeof(struct memblock_region)); + memset(memblock.reserved.regions, 0, + memblock.reserved.cnt * sizeof(struct memblock_region)); + + memblock.memory.cnt =3D 1; + memblock.memory.max =3D INIT_MEMBLOCK_REGIONS; + memblock.memory.name =3D "memory"; + memblock.memory.total_size =3D 0; + + memblock.reserved.cnt =3D 1; + memblock.reserved.max =3D INIT_MEMBLOCK_RESERVED_REGIONS; + memblock.reserved.name =3D "reserved"; + memblock.reserved.total_size =3D 0; + + memblock.bottom_up =3D false; + memblock.current_limit =3D MEMBLOCK_ALLOC_ANYWHERE; +} diff --git a/tools/testing/memblock/tests/common.h b/tools/testing/memblock= /tests/common.h new file mode 100644 index 000000000000..48efc4270ea1 --- /dev/null +++ b/tools/testing/memblock/tests/common.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef _MEMBLOCK_TEST_H +#define _MEMBLOCK_TEST_H + +#include +#include + +struct region { + phys_addr_t base; + phys_addr_t size; +}; + +void reset_memblock(void); + +#endif --=20 2.30.2 From nobody Mon Jun 29 22:16:37 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 758F0C433EF for ; Wed, 2 Feb 2022 11:04:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343680AbiBBLEg (ORCPT ); Wed, 2 Feb 2022 06:04:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343699AbiBBLEG (ORCPT ); Wed, 2 Feb 2022 06:04:06 -0500 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0AB4C061756 for ; Wed, 2 Feb 2022 03:04:05 -0800 (PST) Received: by mail-lf1-x12f.google.com with SMTP id o12so39786145lfg.12 for ; Wed, 02 Feb 2022 03:04:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=S1q+vnglpO2PDv2QmjtSXkjrsf77H3g2pU/xh3PtXsQ=; b=Y+DAZbn7eBikKhOJb2t9zhFEsRzaD/h+bqx/Rt2MsDKzuKW0hfWPa/iUULVUEg5/9Y vayvDgZsNytsm/a4RYCcGjgx6D2Ki+NxDyLZqHqHkD6NLji62qaHhU2IsovYrlTNTZwf ah3Na4V51uQhxKaDgrpet+o/CbIf6Vy8Lvrf2Sb689tp8f4nrGar8tMcgA/f7GrKRg+O 7Wh07HNSJNbIvSQifSN8mGTCwWFkSUKFPPUgpUjo9gsmdR4JFJVnuh1guvOe9wgOlrYk Vq5ZuOF4JZ2qKIPuwgDWbVDcTLTTWIALK2SnkyLuGcFheUP0jGY9pMNc4V7pZ5vF74/K anig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=S1q+vnglpO2PDv2QmjtSXkjrsf77H3g2pU/xh3PtXsQ=; b=3+vFGOI/4qZoTENadkHGYLvKLV0/zHRbJ83IIYMWDyrknGTeV8Qo9M9FT+WnkirH5f l5j702eZTAMKc/j44SIOWyNGLVDu3EmBrKFVV2lY2FlS14PzeSYnQNg+YuwjpVkP+P9d Qy08E24q/yYa0q1iP5Sr6x8e5k/jMO5Fq5rC/vRNbfQCR9ZfxNXRofAVk15DiB55Hzmg PdtPUSJW8P6W0QZ78i699J537XvmA7i0/PCpztaq7qssTjKeTxar1RTXL7bVR+/hzwf8 MZRH1DvRufxtD3VdWUG8tZpKrHIyhQNw8qMzwk/KqE97cg14A+58NdYfSBh5znLLGPqb aFgA== X-Gm-Message-State: AOAM532kLIczpFadiu3hgVh6Bj3qCfLHLD8Rra+FC8tedZS53YzbM0rR +xtJ6aV6/a8ke447ni+qz5mJXwa78Xk= X-Google-Smtp-Source: ABdhPJzi0lUvtnDJD5AmL/bTe3Q4E9I6wrM8gyW0zCmvqqg+iKWlNqrCmdOtXcEnFhBybVQl3/IIbw== X-Received: by 2002:ac2:4e0c:: with SMTP id e12mr22803927lfr.437.1643799844101; Wed, 02 Feb 2022 03:04:04 -0800 (PST) Received: from localhost.localdomain (staticline-31-183-164-222.toya.net.pl. [31.183.164.222]) by smtp.gmail.com with ESMTPSA id r14sm4503937lfr.129.2022.02.02.03.04.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 03:04:03 -0800 (PST) From: Karolina Drobnik To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, rppt@kernel.org, linux-kernel@vger.kernel.org, Karolina Drobnik Subject: [PATCH v2 12/16] memblock tests: Add memblock_add tests Date: Wed, 2 Feb 2022 12:03:11 +0100 Message-Id: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add checks for adding a new region in different scenarios: - The region does not overlap with existing entries - The region overlaps with one of the previous entries: from the top (its end address is bigger than the base of the existing region) or from the bottom (its base address is smaller than the end address of one of the regions) - The region is within an already defined region - The same region is added twice to the collection of available memory regions Add checks for memblock initialization to verify it sets memblock data structures to expected values. Signed-off-by: Karolina Drobnik --- tools/testing/memblock/tests/basic_api.c | 215 +++++++++++++++++++++++ 1 file changed, 215 insertions(+) diff --git a/tools/testing/memblock/tests/basic_api.c b/tools/testing/membl= ock/tests/basic_api.c index 7f2597b3dd4d..6c047b7b31ab 100644 --- a/tools/testing/memblock/tests/basic_api.c +++ b/tools/testing/memblock/tests/basic_api.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include #include +#include #include "basic_api.h" =20 #define EXPECTED_MEMBLOCK_REGIONS 128 @@ -25,8 +26,222 @@ static int memblock_initialization_check(void) return 0; } =20 +/* + * A simple test that adds a memory block of a specified base address + * and size to the collection of available memory regions (memblock.memory= ). + * It checks if a new entry was created and if region counter and total me= mory + * were correctly updated. + */ +static int memblock_add_simple_check(void) +{ + struct memblock_region *rgn; + + rgn =3D &memblock.memory.regions[0]; + + struct region r =3D { + .base =3D SZ_1G, + .size =3D SZ_4M + }; + + reset_memblock(); + memblock_add(r.base, r.size); + + assert(rgn->base =3D=3D r.base); + assert(rgn->size =3D=3D r.size); + + assert(memblock.memory.cnt =3D=3D 1); + assert(memblock.memory.total_size =3D=3D r.size); + + return 0; +} + +/* + * A test that tries to add two memory blocks that don't overlap with one = another. + * It checks if two correctly initialized entries were added to the collec= tion + * of available memory regions (memblock.memory) and if this change was re= flected + * in memblock.memory's total size and region counter. + */ +static int memblock_add_disjoint_check(void) +{ + struct memblock_region *rgn1, *rgn2; + + rgn1 =3D &memblock.memory.regions[0]; + rgn2 =3D &memblock.memory.regions[1]; + + struct region r1 =3D { + .base =3D SZ_1G, + .size =3D SZ_8K + }; + struct region r2 =3D { + .base =3D SZ_1G + SZ_16K, + .size =3D SZ_8K + }; + + reset_memblock(); + memblock_add(r1.base, r1.size); + memblock_add(r2.base, r2.size); + + assert(rgn1->base =3D=3D r1.base); + assert(rgn1->size =3D=3D r1.size); + + assert(rgn2->base =3D=3D r2.base); + assert(rgn2->size =3D=3D r2.size); + + assert(memblock.memory.cnt =3D=3D 2); + assert(memblock.memory.total_size =3D=3D r1.size + r2.size); + + return 0; +} + +/* + * A test that tries to add two memory blocks, where the second one overla= ps + * with the beginning of the first entry (that is r1.base < r2.base + r2.s= ize). + * After this, it checks if two entries are merged into one region that st= arts + * at r2.base and has size of two regions minus their intersection. It also + * verifies the reported total size of the available memory and region cou= nter. + */ +static int memblock_add_overlap_top_check(void) +{ + struct memblock_region *rgn; + phys_addr_t total_size; + + rgn =3D &memblock.memory.regions[0]; + + struct region r1 =3D { + .base =3D SZ_512M, + .size =3D SZ_1G + }; + struct region r2 =3D { + .base =3D SZ_256M, + .size =3D SZ_512M + }; + + total_size =3D (r1.base - r2.base) + r1.size; + + reset_memblock(); + memblock_add(r1.base, r1.size); + memblock_add(r2.base, r2.size); + + assert(rgn->base =3D=3D r2.base); + assert(rgn->size =3D=3D total_size); + + assert(memblock.memory.cnt =3D=3D 1); + assert(memblock.memory.total_size =3D=3D total_size); + + return 0; +} + +/* + * A test that tries to add two memory blocks, where the second one overla= ps + * with the end of the first entry (that is r2.base < r1.base + r1.size). + * After this, it checks if two entries are merged into one region that st= arts + * at r1.base and has size of two regions minus their intersection. It ver= ifies + * that memblock can still see only one entry and has a correct total size= of + * the available memory. + */ +static int memblock_add_overlap_bottom_check(void) +{ + struct memblock_region *rgn; + phys_addr_t total_size; + + rgn =3D &memblock.memory.regions[0]; + + struct region r1 =3D { + .base =3D SZ_128M, + .size =3D SZ_512M + }; + struct region r2 =3D { + .base =3D SZ_256M, + .size =3D SZ_1G + }; + + total_size =3D (r2.base - r1.base) + r2.size; + + reset_memblock(); + memblock_add(r1.base, r1.size); + memblock_add(r2.base, r2.size); + + assert(rgn->base =3D=3D r1.base); + assert(rgn->size =3D=3D total_size); + + assert(memblock.memory.cnt =3D=3D 1); + assert(memblock.memory.total_size =3D=3D total_size); + + return 0; +} + +/* + * A test that tries to add two memory blocks, where the second one is + * within the range of the first entry (that is r1.base < r2.base && + * r2.base + r2.size < r1.base + r1.size). It checks if two entries are me= rged + * into one region that stays the same. The counter and total size of avai= lable + * memory are expected to not be updated. + */ +static int memblock_add_within_check(void) +{ + struct memblock_region *rgn; + + rgn =3D &memblock.memory.regions[0]; + + struct region r1 =3D { + .base =3D SZ_8M, + .size =3D SZ_32M + }; + struct region r2 =3D { + .base =3D SZ_16M, + .size =3D SZ_1M + }; + + reset_memblock(); + memblock_add(r1.base, r1.size); + memblock_add(r2.base, r2.size); + + assert(rgn->base =3D=3D r1.base); + assert(rgn->size =3D=3D r1.size); + + assert(memblock.memory.cnt =3D=3D 1); + assert(memblock.memory.total_size =3D=3D r1.size); + + return 0; +} + +/* + * A simple test that tries to add the same memory block twice. The counter + * and total size of available memory are expected to not be updated. + */ +static int memblock_add_twice_check(void) +{ + struct region r =3D { + .base =3D SZ_16K, + .size =3D SZ_2M + }; + + reset_memblock(); + + memblock_add(r.base, r.size); + memblock_add(r.base, r.size); + + assert(memblock.memory.cnt =3D=3D 1); + assert(memblock.memory.total_size =3D=3D r.size); + + return 0; +} + +static int memblock_add_checks(void) +{ + memblock_add_simple_check(); + memblock_add_disjoint_check(); + memblock_add_overlap_top_check(); + memblock_add_overlap_bottom_check(); + memblock_add_within_check(); + memblock_add_twice_check(); + + return 0; +} + int memblock_basic_checks(void) { memblock_initialization_check(); + memblock_add_checks(); return 0; } --=20 2.30.2 From nobody Mon Jun 29 22:16:37 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46BD8C433EF for ; Wed, 2 Feb 2022 11:04:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343781AbiBBLEi (ORCPT ); Wed, 2 Feb 2022 06:04:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343856AbiBBLEQ (ORCPT ); Wed, 2 Feb 2022 06:04:16 -0500 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23584C06173B for ; Wed, 2 Feb 2022 03:04:07 -0800 (PST) Received: by mail-lf1-x136.google.com with SMTP id a28so39785765lfl.7 for ; Wed, 02 Feb 2022 03:04:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wo9oDoTr9+opMofUsU18MLG30yml/POvjUCw9DWmUTs=; b=o1rU8PIpltWepZP+5N7r9V3PtFLNLH6wMPx4DvttXOwgoPXYQwal3K/obrXKLZKnei xomAfrBY+phjcjzRAb5SNwF7M4SiVFifEGk8CxBQOi0pjuHLIVm4eznqRwc5/ffNpPDa k7aDs693+btHlT7VO8DXe/MbvK/VaSx9lrkknyPlzOtFgNIXIb30ZSFiOiEQHl1Sukj0 OhGrRKQKrObo9gH+6LWd3Zg0t1IsDoDy4fbv5VSaaE0OFLW3l10ZmDgTvm1H5jsG/bzi 8UURER61P1arBEEAGlNX/aMMp0DcJsvjwMDXkPf/PumUehl+ig8rK/tLGogD7jG67dZn 4Mgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wo9oDoTr9+opMofUsU18MLG30yml/POvjUCw9DWmUTs=; b=W4ZNrMH5iqPrZQGTwpiK1JwFgQIrBQZJOx1hnddSYTbFonLkztqayCaQ4O+BlNwVPp NzNY5CN/cYdvVMAH+zHwkcgHf1DcibK/WBiJaJzvMNQEmFgozG0Ifq1M1dHtwJ+k2yDV 5QtQmgD2byT8PF2saCak/Xhleto+1f56YGNaGDoYe1LK6tLy//SIeiEkpJfuth8XS0qe aqyzV84NukhLP0ZyMA0RJ9oTO4L4AIi/IWcaQteK98Gl4go8o3Qe2821kPcIzBBNd3Lg o9y1/u5xRAUGQdLYBDnxEkRbrRMvYB2+H0ack6GqrSQyZZs9xVYJDcWvP85rCKz5EMjo F2Vw== X-Gm-Message-State: AOAM532DrxIyZs2pc4PayI5F+cfbgu2L3NFmLioNomEa7VT5mdOKNXmD b6jAwyIAOESKV9f65GPFkhM= X-Google-Smtp-Source: ABdhPJzBr1HreI0HQmXg87ltcy+WXra0I0o3KQK3FcN0ytPZkFQs4PFCGIqH7poEXFJckzhnH7oZ4Q== X-Received: by 2002:a05:6512:2295:: with SMTP id f21mr22525606lfu.435.1643799845442; Wed, 02 Feb 2022 03:04:05 -0800 (PST) Received: from localhost.localdomain (staticline-31-183-164-222.toya.net.pl. [31.183.164.222]) by smtp.gmail.com with ESMTPSA id r14sm4503937lfr.129.2022.02.02.03.04.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 03:04:05 -0800 (PST) From: Karolina Drobnik To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, rppt@kernel.org, linux-kernel@vger.kernel.org, Karolina Drobnik Subject: [PATCH v2 13/16] memblock tests: Add memblock_reserve tests Date: Wed, 2 Feb 2022 12:03:12 +0100 Message-Id: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add checks for marking a region as reserved in different scenarios: - The region does not overlap with existing entries - The region overlaps with one of the previous entries: from the top (its end address is bigger than the base of the existing region) or from the bottom (its base address is smaller than the end address of one of the regions) - The region is within an already defined region - The same region is marked as reserved twice Signed-off-by: Karolina Drobnik --- tools/testing/memblock/tests/basic_api.c | 213 +++++++++++++++++++++++ 1 file changed, 213 insertions(+) diff --git a/tools/testing/memblock/tests/basic_api.c b/tools/testing/membl= ock/tests/basic_api.c index 6c047b7b31ab..b055ff262d23 100644 --- a/tools/testing/memblock/tests/basic_api.c +++ b/tools/testing/memblock/tests/basic_api.c @@ -239,9 +239,222 @@ static int memblock_add_checks(void) return 0; } =20 + /* + * A simple test that marks a memory block of a specified base address + * and size as reserved and to the collection of reserved memory regions + * (memblock.reserved). It checks if a new entry was created and if region + * counter and total memory size were correctly updated. + */ +static int memblock_reserve_simple_check(void) +{ + struct memblock_region *rgn; + + rgn =3D &memblock.reserved.regions[0]; + + struct region r =3D { + .base =3D SZ_2G, + .size =3D SZ_128M + }; + + reset_memblock(); + memblock_reserve(r.base, r.size); + + assert(rgn->base =3D=3D r.base); + assert(rgn->size =3D=3D r.size); + + return 0; +} + +/* + * A test that tries to mark two memory blocks that don't overlap as reser= ved + * and checks if two entries were correctly added to the collection of res= erved + * memory regions (memblock.reserved) and if this change was reflected in + * memblock.reserved's total size and region counter. + */ +static int memblock_reserve_disjoint_check(void) +{ + struct memblock_region *rgn1, *rgn2; + + rgn1 =3D &memblock.reserved.regions[0]; + rgn2 =3D &memblock.reserved.regions[1]; + + struct region r1 =3D { + .base =3D SZ_256M, + .size =3D SZ_16M + }; + struct region r2 =3D { + .base =3D SZ_512M, + .size =3D SZ_512M + }; + + reset_memblock(); + memblock_reserve(r1.base, r1.size); + memblock_reserve(r2.base, r2.size); + + assert(rgn1->base =3D=3D r1.base); + assert(rgn1->size =3D=3D r1.size); + + assert(rgn2->base =3D=3D r2.base); + assert(rgn2->size =3D=3D r2.size); + + assert(memblock.reserved.cnt =3D=3D 2); + assert(memblock.reserved.total_size =3D=3D r1.size + r2.size); + + return 0; +} + +/* + * A test that tries to mark two memory blocks as reserved, where the seco= nd one + * overlaps with the beginning of the first (that is r1.base < r2.base + r= 2.size). + * It checks if two entries are merged into one region that starts at r2.b= ase + * and has size of two regions minus their intersection. The test also ver= ifies + * that memblock can still see only one entry and has a correct total size= of + * the reserved memory. + */ +static int memblock_reserve_overlap_top_check(void) +{ + struct memblock_region *rgn; + phys_addr_t total_size; + + rgn =3D &memblock.reserved.regions[0]; + + struct region r1 =3D { + .base =3D SZ_1G, + .size =3D SZ_1G + }; + struct region r2 =3D { + .base =3D SZ_128M, + .size =3D SZ_1G + }; + + total_size =3D (r1.base - r2.base) + r1.size; + + reset_memblock(); + memblock_reserve(r1.base, r1.size); + memblock_reserve(r2.base, r2.size); + + assert(rgn->base =3D=3D r2.base); + assert(rgn->size =3D=3D total_size); + + assert(memblock.reserved.cnt =3D=3D 1); + assert(memblock.reserved.total_size =3D=3D total_size); + + return 0; +} + +/* + * A test that tries to mark two memory blocks as reserved, where the seco= nd + * one overlaps with the end of the first entry (that is r2.base < r1.base= + r1.size). + * It checks if two entries are merged into one region that starts at r1.b= ase + * and has size of two regions minus their intersection. It verifies that = memblock + * can still see only one entry and has a correct total size of the reserv= ed memory. + */ +static int memblock_reserve_overlap_bottom_check(void) +{ + struct memblock_region *rgn; + phys_addr_t total_size; + + rgn =3D &memblock.reserved.regions[0]; + + struct region r1 =3D { + .base =3D SZ_2K, + .size =3D SZ_128K + }; + struct region r2 =3D { + .base =3D SZ_128K, + .size =3D SZ_128K + }; + + total_size =3D (r2.base - r1.base) + r2.size; + + reset_memblock(); + memblock_reserve(r1.base, r1.size); + memblock_reserve(r2.base, r2.size); + + assert(rgn->base =3D=3D r1.base); + assert(rgn->size =3D=3D total_size); + + assert(memblock.reserved.cnt =3D=3D 1); + assert(memblock.reserved.total_size =3D=3D total_size); + + return 0; +} + +/* + * A test that tries to mark two memory blocks as reserved, where the seco= nd one + * is within the range of the first entry (that is (r1.base < r2.base) && + * (r2.base + r2.size < r1.base + r1.size)). It checks if two entries are = merged + * into one region that stays the same. The counter and total size of avai= lable + * memory are expected to not be updated. + */ +static int memblock_reserve_within_check(void) +{ + struct memblock_region *rgn; + + rgn =3D &memblock.reserved.regions[0]; + + struct region r1 =3D { + .base =3D SZ_1M, + .size =3D SZ_8M + }; + struct region r2 =3D { + .base =3D SZ_2M, + .size =3D SZ_64K + }; + + reset_memblock(); + memblock_reserve(r1.base, r1.size); + memblock_reserve(r2.base, r2.size); + + assert(rgn->base =3D=3D r1.base); + assert(rgn->size =3D=3D r1.size); + + assert(memblock.reserved.cnt =3D=3D 1); + assert(memblock.reserved.total_size =3D=3D r1.size); + + return 0; +} + +/* + * A simple test that tries to reserve the same memory block twice. + * The region counter and total size of reserved memory are expected to not + * be updated. + */ +static int memblock_reserve_twice_check(void) +{ + struct region r =3D { + .base =3D SZ_16K, + .size =3D SZ_2M + }; + + reset_memblock(); + + memblock_reserve(r.base, r.size); + memblock_reserve(r.base, r.size); + + assert(memblock.reserved.cnt =3D=3D 1); + assert(memblock.reserved.total_size =3D=3D r.size); + + return 0; +} + +static int memblock_reserve_checks(void) +{ + memblock_reserve_simple_check(); + memblock_reserve_disjoint_check(); + memblock_reserve_overlap_top_check(); + memblock_reserve_overlap_bottom_check(); + memblock_reserve_within_check(); + memblock_reserve_twice_check(); + + return 0; +} + int memblock_basic_checks(void) { memblock_initialization_check(); memblock_add_checks(); + memblock_reserve_checks(); + return 0; } --=20 2.30.2 From nobody Mon Jun 29 22:16:37 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62306C433EF for ; Wed, 2 Feb 2022 11:04:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232171AbiBBLEn (ORCPT ); Wed, 2 Feb 2022 06:04:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343861AbiBBLEQ (ORCPT ); Wed, 2 Feb 2022 06:04:16 -0500 Received: from mail-lj1-x234.google.com (mail-lj1-x234.google.com [IPv6:2a00:1450:4864:20::234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4661C06173E for ; Wed, 2 Feb 2022 03:04:08 -0800 (PST) Received: by mail-lj1-x234.google.com with SMTP id q127so28363582ljq.2 for ; Wed, 02 Feb 2022 03:04:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Hy7Dd2f91UDJKml61GqO51OOP6//JtRGeIoiva3Pj4s=; b=hWkfIui+gxpbLh2BPaL2aGtfyYaKHcp4xjQS9FMtAU1ZXoSx+pdqXlsqHxAs5rrJdu r8C7jF0edJt/ShpCP8A1AuMeTmyNJhmVa8LL9cFNgLAp/ri/V7lkoxUVSHu4wWVNY3eD lLNXhT2J8d9LwVxAVONMrDjhZSaVgJMQiD04c/lksq1dSAJP5wXqRlowohzXwLvP2OTj A7BV1qMkx35bg0z1/pQxZ1HeS7y9QqL5ksSIXBKs+T2n/SJqGZNnGQLlhT429S7aPAgt R+2EXzl5P2DKWkDtt9sVw3X02V8ixNDpOv31RaeBa/98c2CM0d6mlnlXYS1tyzp1/ODv /K+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Hy7Dd2f91UDJKml61GqO51OOP6//JtRGeIoiva3Pj4s=; b=2fu/fTL4MKr08Xs0v2loL+qORT66aO08PLrG5W3Mw/3gkIhYKoLmoKr90WJXCKZ+V2 vq6rJcGon25zPfQqVXtoaYrFJsR4tSLBBtjA8juLdIpt+HgyqtTDZPDLx8o1yoHV7Ams Py2M7f4wZ5dnu+7hKP6qYI+r4uVg7DBEJTUZ4uAqODH4BeRK5aMA8CbprE1hKNj3kKQy ps7MSDui6F3m6gLO4Gdf03GO8V91lOiY38qFbO+WTr0jYrfWlYajeaXK78bhCc1WYvKu DuoN/7/WWVolGIeTLUESQk0P+8yRN5fuxlZoGkHCHTQReojZ6YHQvr+0B5lhFJgonyJU efHQ== X-Gm-Message-State: AOAM531dfBAUugZSEu4lfeE+UP/lXZKlG9FfQGPv0dfXvucxBrbpDuaG mzDjKLLqhW3szVYi7JEtwEI= X-Google-Smtp-Source: ABdhPJy4ZUVUTqMEwlvM7qv5wc/wjd51q7EKuO8jIaWMRcUtjk+QKhtOa2tW0JXo/LWxTBbiOmZxFA== X-Received: by 2002:a2e:a4a9:: with SMTP id g9mr20061973ljm.289.1643799847040; Wed, 02 Feb 2022 03:04:07 -0800 (PST) Received: from localhost.localdomain (staticline-31-183-164-222.toya.net.pl. [31.183.164.222]) by smtp.gmail.com with ESMTPSA id r14sm4503937lfr.129.2022.02.02.03.04.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 03:04:06 -0800 (PST) From: Karolina Drobnik To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, rppt@kernel.org, linux-kernel@vger.kernel.org, Karolina Drobnik Subject: [PATCH v2 14/16] memblock tests: Add memblock_remove tests Date: Wed, 2 Feb 2022 12:03:13 +0100 Message-Id: <8e6aa005407bbe1a75b75e85ac04ebb51318a52a.1643796665.git.karolinadrobnik@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add checks for removing a region from available memory in different scenarios: - The requested region matches one in the collection of available memory regions - The requested region does not exist in memblock.memory - The region overlaps with one of the entries: from the top (its end address is bigger than the base of the existing region) or from the bottom (its base address is smaller than the end address of one of the regions) - The region is within an already defined region Signed-off-by: Karolina Drobnik --- tools/testing/memblock/tests/basic_api.c | 203 +++++++++++++++++++++++ 1 file changed, 203 insertions(+) diff --git a/tools/testing/memblock/tests/basic_api.c b/tools/testing/membl= ock/tests/basic_api.c index b055ff262d23..96af80bf9df9 100644 --- a/tools/testing/memblock/tests/basic_api.c +++ b/tools/testing/memblock/tests/basic_api.c @@ -450,11 +450,214 @@ static int memblock_reserve_checks(void) return 0; } =20 + /* + * A simple test that tries to remove the first entry of the array of ava= ilable + * memory regions. By "removing" a region we mean overwriting it with the= next + * region in memblock.memory. To check this is the case, the test adds tw= o memory + * blocks and verifies that the value of the latter was used to erase r1 = region. + * It also checks if the region counter and total size were updated to ex= pected + * values. + */ +static int memblock_remove_simple_check(void) +{ + struct memblock_region *rgn; + + rgn =3D &memblock.memory.regions[0]; + + struct region r1 =3D { + .base =3D SZ_2K, + .size =3D SZ_4K + }; + struct region r2 =3D { + .base =3D SZ_128K, + .size =3D SZ_4M + }; + + reset_memblock(); + memblock_add(r1.base, r1.size); + memblock_add(r2.base, r2.size); + memblock_remove(r1.base, r1.size); + + assert(rgn->base =3D=3D r2.base); + assert(rgn->size =3D=3D r2.size); + + assert(memblock.memory.cnt =3D=3D 1); + assert(memblock.memory.total_size =3D=3D r2.size); + + return 0; +} + + /* + * A test that tries to remove a region that was not registered as availa= ble + * memory (i.e. has no corresponding entry in memblock.memory). It verifi= es + * that array, regions counter and total size were not modified. + */ +static int memblock_remove_absent_check(void) +{ + struct memblock_region *rgn; + + rgn =3D &memblock.memory.regions[0]; + + struct region r1 =3D { + .base =3D SZ_512K, + .size =3D SZ_4M + }; + struct region r2 =3D { + .base =3D SZ_64M, + .size =3D SZ_1G + }; + + reset_memblock(); + memblock_add(r1.base, r1.size); + memblock_remove(r2.base, r2.size); + + assert(rgn->base =3D=3D r1.base); + assert(rgn->size =3D=3D r1.size); + + assert(memblock.memory.cnt =3D=3D 1); + assert(memblock.memory.total_size =3D=3D r1.size); + + return 0; +} + +/* + * A test that tries to remove a region which overlaps with the beginning = of + * the already existing entry r1 (that is r1.base < r2.base + r2.size). It + * checks if only the intersection of both regions is removed from the ava= ilable + * memory pool. The test also checks if the regions counter and total size= are + * updated to expected values. + */ +static int memblock_remove_overlap_top_check(void) +{ + struct memblock_region *rgn; + phys_addr_t r1_end, r2_end, total_size; + + rgn =3D &memblock.memory.regions[0]; + + struct region r1 =3D { + .base =3D SZ_32M, + .size =3D SZ_32M + }; + struct region r2 =3D { + .base =3D SZ_16M, + .size =3D SZ_32M + }; + + r1_end =3D r1.base + r1.size; + r2_end =3D r2.base + r2.size; + total_size =3D r1_end - r2_end; + + reset_memblock(); + memblock_add(r1.base, r1.size); + memblock_remove(r2.base, r2.size); + + assert(rgn->base =3D=3D r1.base + r2.base); + assert(rgn->size =3D=3D total_size); + + assert(memblock.memory.cnt =3D=3D 1); + assert(memblock.memory.total_size =3D=3D total_size); + + return 0; +} + +/* + * A test that tries to remove a region which overlaps with the end of the + * first entry (that is r2.base < r1.base + r1.size). It checks if only the + * intersection of both regions is removed from the available memory pool. + * The test also checks if the regions counter and total size are updated = to + * expected values. + */ +static int memblock_remove_overlap_bottom_check(void) +{ + struct memblock_region *rgn; + phys_addr_t total_size; + + rgn =3D &memblock.memory.regions[0]; + + struct region r1 =3D { + .base =3D SZ_2M, + .size =3D SZ_64M + }; + struct region r2 =3D { + .base =3D SZ_32M, + .size =3D SZ_256M + }; + + total_size =3D r2.base - r1.base; + + reset_memblock(); + memblock_add(r1.base, r1.size); + memblock_remove(r2.base, r2.size); + + assert(rgn->base =3D=3D r1.base); + assert(rgn->size =3D=3D total_size); + + assert(memblock.memory.cnt =3D=3D 1); + assert(memblock.memory.total_size =3D=3D total_size); + return 0; +} + +/* + * A test that tries to remove a region which is within the range of the a= lready + * existing entry (that is (r1.base < r2.base) && (r2.base + r2.size < r1.= base + r1.size)). + * It checks if the region is split into two - one that ends at r2.base an= d second + * that starts at r2.base + size, with appropriate sizes. The test also ch= ecks if + * the region counter and total size were updated to expected values. + */ +static int memblock_remove_within_check(void) +{ + struct memblock_region *rgn1, *rgn2; + phys_addr_t r1_size, r2_size, total_size; + + rgn1 =3D &memblock.memory.regions[0]; + rgn2 =3D &memblock.memory.regions[1]; + + struct region r1 =3D { + .base =3D SZ_1M, + .size =3D SZ_32M + }; + struct region r2 =3D { + .base =3D SZ_16M, + .size =3D SZ_1M + }; + + r1_size =3D r2.base - r1.base; + r2_size =3D (r1.base + r1.size) - (r2.base + r2.size); + total_size =3D r1_size + r2_size; + + reset_memblock(); + memblock_add(r1.base, r1.size); + memblock_remove(r2.base, r2.size); + + assert(rgn1->base =3D=3D r1.base); + assert(rgn1->size =3D=3D r1_size); + + assert(rgn2->base =3D=3D r2.base + r2.size); + assert(rgn2->size =3D=3D r2_size); + + assert(memblock.memory.cnt =3D=3D 2); + assert(memblock.memory.total_size =3D=3D total_size); + + return 0; +} + +static int memblock_remove_checks(void) +{ + memblock_remove_simple_check(); + memblock_remove_absent_check(); + memblock_remove_overlap_top_check(); + memblock_remove_overlap_bottom_check(); + memblock_remove_within_check(); + + return 0; +} + int memblock_basic_checks(void) { memblock_initialization_check(); memblock_add_checks(); memblock_reserve_checks(); + memblock_remove_checks(); =20 return 0; } --=20 2.30.2 From nobody Mon Jun 29 22:16:37 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8446FC433EF for ; Wed, 2 Feb 2022 11:04:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243160AbiBBLEl (ORCPT ); Wed, 2 Feb 2022 06:04:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241181AbiBBLER (ORCPT ); Wed, 2 Feb 2022 06:04:17 -0500 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 819D4C06175B for ; Wed, 2 Feb 2022 03:04:10 -0800 (PST) Received: by mail-lf1-x134.google.com with SMTP id p27so39906631lfa.1 for ; Wed, 02 Feb 2022 03:04:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xsGfx9/8KzrBT+1sl0kUz+F3kyiF2mtw3RnNVnjQqWU=; b=YtfjlK0ztjIEEsuUCSKM4bqNMMcawSyHhzHcumOe5w0nKvqvl3X2dT+dB/mAD/O5NM ktkNBQwpJoPe2ArBLbGtI/blHvexqhgJwLxHwMAg7UdlCqBFrLcKAy5at+mTljTooYk1 b7/Psa3+kdM7uOd0xhZXSO09mEdV9PKRG0SBxaZdM1AQSO9xIIJw5VxQ4/BMULz42MRD 5zlrfUI6CuxKignTE4EXO5EKT+v3jXIkw6R87gVjlwzBogCk6I00RbNVL7C30pztQrta KSfCnUIgatFvvmReZHEq+2/1KOBDDrpFgz08EJgdan9pDm9sF+RDVYey9N0Eh1eMhpoJ SZGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xsGfx9/8KzrBT+1sl0kUz+F3kyiF2mtw3RnNVnjQqWU=; b=Wfb6Au+r359myaqQ2pElCf4v83I1xFl8Xe6bSUwvKs7UPtnGJ2jXmXJ+a7mTGwm9kO /t32YosEfYMzwKm/NDYGmNzOIS5UcguvEn8BVIZ3VR7pSySBMW+VPEf8XlxKSjJszoxV CgYJb5hWSHQJkr03MAVPwY3iXnw6V9ftNCXxkF+VuvSw5U9GWP5+xNXRaaMs3OI9idKi /YCmk2f8HtSql5Y7R65NUW2v0TQ+Cn5FBnCy/c7OGTeAPpD6W2gS8WtFDYrQprUlwcqu N0rGriv6BedaEEzMCNKUwcZ33FAPxi0jgHf+O6ZcHUCwe02j+rkCQmdSYUTm9SKWLaRy hA8A== X-Gm-Message-State: AOAM531+moRufziNMLGIEuH/mIJ0YMbBBRQdH3sd3gGEJt6aMU1MH2Om +ZPAlfFvywpwGimUcG04qZU= X-Google-Smtp-Source: ABdhPJzVT8cd94vbPxGc0nxIGNlrqOnQ6oDaCVeqJHB9EtPpJj6BOJCsOi8IyP049cXXGOw+y1HUVA== X-Received: by 2002:a05:6512:12c6:: with SMTP id p6mr14815847lfg.268.1643799848868; Wed, 02 Feb 2022 03:04:08 -0800 (PST) Received: from localhost.localdomain (staticline-31-183-164-222.toya.net.pl. [31.183.164.222]) by smtp.gmail.com with ESMTPSA id r14sm4503937lfr.129.2022.02.02.03.04.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 03:04:08 -0800 (PST) From: Karolina Drobnik To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, rppt@kernel.org, linux-kernel@vger.kernel.org, Karolina Drobnik Subject: [PATCH v2 15/16] memblock tests: Add memblock_add_node test Date: Wed, 2 Feb 2022 12:03:14 +0100 Message-Id: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add a simple test for NUMA-aware variant of memblock_add function. Signed-off-by: Karolina Drobnik --- tools/testing/memblock/tests/basic_api.c | 34 ++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tools/testing/memblock/tests/basic_api.c b/tools/testing/membl= ock/tests/basic_api.c index 96af80bf9df9..02eb88358a58 100644 --- a/tools/testing/memblock/tests/basic_api.c +++ b/tools/testing/memblock/tests/basic_api.c @@ -55,6 +55,39 @@ static int memblock_add_simple_check(void) return 0; } =20 +/* + * A simple test that adds a memory block of a specified base address, size + * NUMA node and memory flags to the collection of available memory region= s. + * It checks if the new entry, region counter and total memory size have + * expected values. + */ +static int memblock_add_node_simple_check(void) +{ + struct memblock_region *rgn; + + rgn =3D &memblock.memory.regions[0]; + + struct region r =3D { + .base =3D SZ_1M, + .size =3D SZ_16M + }; + + reset_memblock(); + memblock_add_node(r.base, r.size, 1, MEMBLOCK_HOTPLUG); + + assert(rgn->base =3D=3D r.base); + assert(rgn->size =3D=3D r.size); +#ifdef CONFIG_NUMA + assert(rgn->nid =3D=3D 1); +#endif + assert(rgn->flags =3D=3D MEMBLOCK_HOTPLUG); + + assert(memblock.memory.cnt =3D=3D 1); + assert(memblock.memory.total_size =3D=3D r.size); + + return 0; +} + /* * A test that tries to add two memory blocks that don't overlap with one = another. * It checks if two correctly initialized entries were added to the collec= tion @@ -230,6 +263,7 @@ static int memblock_add_twice_check(void) static int memblock_add_checks(void) { memblock_add_simple_check(); + memblock_add_node_simple_check(); memblock_add_disjoint_check(); memblock_add_overlap_top_check(); memblock_add_overlap_bottom_check(); --=20 2.30.2 From nobody Mon Jun 29 22:16:37 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42F46C433F5 for ; Wed, 2 Feb 2022 11:04:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343918AbiBBLEr (ORCPT ); Wed, 2 Feb 2022 06:04:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343783AbiBBLER (ORCPT ); Wed, 2 Feb 2022 06:04:17 -0500 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0880DC06175E for ; Wed, 2 Feb 2022 03:04:12 -0800 (PST) Received: by mail-lf1-x12b.google.com with SMTP id b9so39808542lfq.6 for ; Wed, 02 Feb 2022 03:04:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fXs9Z9PQYCruMdcrfaMtY0ndpO2Xn6EDlt3MZzXYgdU=; b=Dba5XaJ4YA9vpc0hY5gn45LFbLkG/VzuAUztdk53/XTRWBh6s761tDC/A3IF9fnCze /+glyw8MSR1ID6IHiJ/cnI0y/V9M7hQ9NCNTrfZPzRBvwQrtxytnB2KCDvQb6r+z2RtW 8622a/Asuu1bjdAq6NmBzW8+bCABmCKpi6MQR4a6GEU2wmDB4ICldMvLYK6rW+8aVrMV U+vMKFGCV3OOQYWwqTCQs0qm3T68s0XscVj7YpEbsaA8w9YEzjNveZLPo1W/MMa7l3p6 6Nck9ktAKT06GNvBgQlvPCzvETxBPW3zCbNi4vOYksN63nFZK57tFMrJPjJLWZF43eUF n4Ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fXs9Z9PQYCruMdcrfaMtY0ndpO2Xn6EDlt3MZzXYgdU=; b=Ncf91KMqpoANedy7Scbhs8b9DSX/HRimW2poI51TF9HNHUCdVOgHjLLWC7HUTd4jhA bwJZ3OxG8JkOyRGWS7K9QKPEck33brxBTb3UMQq5He53shTH7SjjKJ8j9grSBaLDssol 9zpFGrCdi8CseczxM8f8mQNxpjQ2AP4mcjK2dvT9L1wZA2aiwtysp9hVfoQ70GAcj+Yn OwGSWTI5SgX2SLSpyCUQajmK4+4Hy5dsXpBUoikzl9tdpqRzJ1Dx0vfX92sIA3tSW7UT mitYSHO7wiVt4rOYwkuBkYjAMx6TZRYH6S++CU6Ruh4o/cn1EJ8x3DAW3dX4iIgvuovz wMzQ== X-Gm-Message-State: AOAM530JKI7VMFv7VmV0LKBZfoxafZ+gSAQSgCyXVrIcE0AZ0CHkk0y8 CkVmxAQeVlZdr8JtUcCtIB8= X-Google-Smtp-Source: ABdhPJxR1zuszDMGjwGZeutMvY35G28bmpwlvPOGrKcn1rCWt6gy9RgtvgaRkVsAv3cFx97J4LRhBA== X-Received: by 2002:a05:6512:3f99:: with SMTP id x25mr10847382lfa.235.1643799850317; Wed, 02 Feb 2022 03:04:10 -0800 (PST) Received: from localhost.localdomain (staticline-31-183-164-222.toya.net.pl. [31.183.164.222]) by smtp.gmail.com with ESMTPSA id r14sm4503937lfr.129.2022.02.02.03.04.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 03:04:09 -0800 (PST) From: Karolina Drobnik To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, rppt@kernel.org, linux-kernel@vger.kernel.org, Karolina Drobnik Subject: [PATCH v2 16/16] memblock tests: Add memblock_free tests Date: Wed, 2 Feb 2022 12:03:15 +0100 Message-Id: <30af95c82754ad8029404c3b528a5ef1c05d1ed6.1643796665.git.karolinadrobnik@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add checks for removing a region from reserved memory in different scenarios: - The requested region matches one in the collection of reserved memory regions - The requested region does not exist in memblock.reserved - The region overlaps with one of the entries: from the top (its end address is bigger than the base of the existing region) or from the bottom (its base address is smaller than the end address of one of the regions) - The region is within an already defined region Signed-off-by: Karolina Drobnik --- tools/testing/memblock/tests/basic_api.c | 199 +++++++++++++++++++++++ 1 file changed, 199 insertions(+) diff --git a/tools/testing/memblock/tests/basic_api.c b/tools/testing/membl= ock/tests/basic_api.c index 02eb88358a58..568b05b52883 100644 --- a/tools/testing/memblock/tests/basic_api.c +++ b/tools/testing/memblock/tests/basic_api.c @@ -686,12 +686,211 @@ static int memblock_remove_checks(void) return 0; } =20 +/* + * A simple test that tries to free a memory block that was marked earlier= as + * reserved. By "freeing" a region we mean overwriting it with the next en= try + * in memblock.reserved. To check this is the case, the test reserves two = memory + * regions and verifies that the value of the latter was used to erase r1 = region. + * The test also checks if the region counter and total size were updated. + */ +static int memblock_free_simple_check(void) +{ + struct memblock_region *rgn; + + rgn =3D &memblock.reserved.regions[0]; + + struct region r1 =3D { + .base =3D SZ_4M, + .size =3D SZ_1M + }; + struct region r2 =3D { + .base =3D SZ_8M, + .size =3D SZ_1M + }; + + reset_memblock(); + memblock_reserve(r1.base, r1.size); + memblock_reserve(r2.base, r2.size); + memblock_free((void *)r1.base, r1.size); + + assert(rgn->base =3D=3D r2.base); + assert(rgn->size =3D=3D r2.size); + + assert(memblock.reserved.cnt =3D=3D 1); + assert(memblock.reserved.total_size =3D=3D r2.size); + + return 0; +} + + /* + * A test that tries to free a region that was not marked as reserved (i.= e. has + * no corresponding entry in memblock.reserved). It verifies that array, = regions + * counter and total size were not modified. + */ +static int memblock_free_absent_check(void) +{ + struct memblock_region *rgn; + + rgn =3D &memblock.reserved.regions[0]; + + struct region r1 =3D { + .base =3D SZ_2M, + .size =3D SZ_8K + }; + struct region r2 =3D { + .base =3D SZ_16M, + .size =3D SZ_128M + }; + + reset_memblock(); + memblock_reserve(r1.base, r1.size); + memblock_free((void *)r2.base, r2.size); + + assert(rgn->base =3D=3D r1.base); + assert(rgn->size =3D=3D r1.size); + + assert(memblock.reserved.cnt =3D=3D 1); + assert(memblock.reserved.total_size =3D=3D r1.size); + + return 0; +} + +/* + * A test that tries to free a region which overlaps with the beginning of + * the already existing entry r1 (that is r1.base < r2.base + r2.size). It + * checks if only the intersection of both regions is freed. The test also + * checks if the regions counter and total size are updated to expected va= lues. + */ +static int memblock_free_overlap_top_check(void) +{ + struct memblock_region *rgn; + phys_addr_t total_size; + + rgn =3D &memblock.reserved.regions[0]; + + struct region r1 =3D { + .base =3D SZ_8M, + .size =3D SZ_32M + }; + struct region r2 =3D { + .base =3D SZ_1M, + .size =3D SZ_8M + }; + + total_size =3D (r1.size + r1.base) - (r2.base + r2.size); + + reset_memblock(); + memblock_reserve(r1.base, r1.size); + memblock_free((void *)r2.base, r2.size); + + assert(rgn->base =3D=3D r2.base + r2.size); + assert(rgn->size =3D=3D total_size); + + assert(memblock.reserved.cnt =3D=3D 1); + assert(memblock.reserved.total_size =3D=3D total_size); + + return 0; +} + +/* + * A test that tries to free a region which overlaps with the end of the + * first entry (that is r2.base < r1.base + r1.size). It checks if only the + * intersection of both regions is freed. The test also checks if the regi= ons + * counter and total size are updated to expected values. + */ +static int memblock_free_overlap_bottom_check(void) +{ + struct memblock_region *rgn; + phys_addr_t total_size; + + rgn =3D &memblock.reserved.regions[0]; + + struct region r1 =3D { + .base =3D SZ_8M, + .size =3D SZ_32M + }; + struct region r2 =3D { + .base =3D SZ_32M, + .size =3D SZ_32M + }; + + total_size =3D r2.base - r1.base; + + reset_memblock(); + memblock_reserve(r1.base, r1.size); + memblock_free((void *)r2.base, r2.size); + + assert(rgn->base =3D=3D r1.base); + assert(rgn->size =3D=3D total_size); + + assert(memblock.reserved.cnt =3D=3D 1); + assert(memblock.reserved.total_size =3D=3D total_size); + + return 0; +} + +/* + * A test that tries to free a region which is within the range of the alr= eady + * existing entry (that is (r1.base < r2.base) && (r2.base + r2.size < r1.= base + r1.size)). + * It checks if the region is split into two - one that ends at r2.base an= d second + * that starts at r2.base + size, with appropriate sizes. It is expected t= hat + * the region counter and total size fields were updated t reflect that ch= ange. + */ +static int memblock_free_within_check(void) +{ + struct memblock_region *rgn1, *rgn2; + phys_addr_t r1_size, r2_size, total_size; + + rgn1 =3D &memblock.reserved.regions[0]; + rgn2 =3D &memblock.reserved.regions[1]; + + struct region r1 =3D { + .base =3D SZ_1M, + .size =3D SZ_8M + }; + struct region r2 =3D { + .base =3D SZ_4M, + .size =3D SZ_1M + }; + + r1_size =3D r2.base - r1.base; + r2_size =3D (r1.base + r1.size) - (r2.base + r2.size); + total_size =3D r1_size + r2_size; + + reset_memblock(); + memblock_reserve(r1.base, r1.size); + memblock_free((void *)r2.base, r2.size); + + assert(rgn1->base =3D=3D r1.base); + assert(rgn1->size =3D=3D r1_size); + + assert(rgn2->base =3D=3D r2.base + r2.size); + assert(rgn2->size =3D=3D r2_size); + + assert(memblock.reserved.cnt =3D=3D 2); + assert(memblock.reserved.total_size =3D=3D total_size); + + return 0; +} + +static int memblock_free_checks(void) +{ + memblock_free_simple_check(); + memblock_free_absent_check(); + memblock_free_overlap_top_check(); + memblock_free_overlap_bottom_check(); + memblock_free_within_check(); + + return 0; +} + int memblock_basic_checks(void) { memblock_initialization_check(); memblock_add_checks(); memblock_reserve_checks(); memblock_remove_checks(); + memblock_free_checks(); =20 return 0; } --=20 2.30.2