From patchwork Sun Aug 14 05:53:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rebecca Mckeever X-Patchwork-Id: 12942843 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10AD4C25B0F for ; Sun, 14 Aug 2022 05:54:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9B7BF8E0003; Sun, 14 Aug 2022 01:54:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 917CD8E0001; Sun, 14 Aug 2022 01:54:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7B80D8E0003; Sun, 14 Aug 2022 01:54:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 6DBFC8E0001 for ; Sun, 14 Aug 2022 01:54:09 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 4535EAB282 for ; Sun, 14 Aug 2022 05:54:09 +0000 (UTC) X-FDA: 79797132618.08.A9F6E32 Received: from mail-il1-f195.google.com (mail-il1-f195.google.com [209.85.166.195]) by imf30.hostedemail.com (Postfix) with ESMTP id D13F08019F for ; Sun, 14 Aug 2022 05:54:08 +0000 (UTC) Received: by mail-il1-f195.google.com with SMTP id l9so2489695ilq.1 for ; Sat, 13 Aug 2022 22:54:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=TqLTKUmEk/mKGbJa80nE77aaCeS2f2PhLCxbPuooWhk=; b=Q+70lCxo0EOr6ZjULQtULwXoQfFqFrhzmgqGnXuME+BrsXkSjYP3hTsUbnpp1qw43m 1F6K2i2CQKCycUqiGC5ObC9j1BnKh/dxeOxl1qRdJeeFl756TIYVq0Cdz4Yy6uJaEccb T7cm9eYHf//UuNx/gSF5Vgw7Q66vQXTEPwIqZ9kIUu3it4V3EJHPx5/OIeDIxS+tbSm2 O0k9O+veuWtYGdsCjrYkCfd/o5yukBIAFTTWsKBhY/70a0oH2j5KFx6aixZWydOagUfp xCv/B2tiT8441toWEth7/JWx5Y30oN/FMiwPJJtZXMu7AmJgdfR529IUWeaCzuME630I 9KnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=TqLTKUmEk/mKGbJa80nE77aaCeS2f2PhLCxbPuooWhk=; b=73WPdYgku81TCi6hv3b+Z3wQexUScgzYs5rvzp8VQSrCX+4iI6rccfM98s03de74EG KaChliMVPeKh6wcC1CCIvjXvUNgDxTWWw+4mAx5J8AKlGG92GSQVszx+dNJ2GvH/mH5+ ocGZVHAMGY2uDCeZ0X+OrMjSKiq76k7WUVlO+rV1RLT+zslH2Bvrx7+QD+hQDjJ/oBS+ 7+ltb4BxPNg1L14XYcpvqUiOue88iLXbz2dkdIKIt+gpuv+Dq9BImtZw5dWr1FbR4fZ3 GsIT1iHxBjb9uQhYBRVXup9gajpHQgOS667t0EjKL1dWqaLJWk29Gyqlmknv17ljQeDK UDNA== X-Gm-Message-State: ACgBeo1O2DGO/HG/NRniif4c9haVik4lDR/0KtxAhKV8YM+QkaCXGysq dKiNmgLPPho6ZcA1O4ZHv6Y= X-Google-Smtp-Source: AA6agR57m2tbZb2IQQdr4JcN2+O7/qS5xwfmQSAUfTIGFtypLP3eE76NYeUEL1dj9t1cc0w5ype3xw== X-Received: by 2002:a92:cda9:0:b0:2df:a725:6491 with SMTP id g9-20020a92cda9000000b002dfa7256491mr4968030ild.12.1660456448133; Sat, 13 Aug 2022 22:54:08 -0700 (PDT) Received: from sophie (static-198-54-128-70.cust.tzulo.com. [198.54.128.70]) by smtp.gmail.com with ESMTPSA id h8-20020a05660208c800b006882a3bd03fsm432587ioz.16.2022.08.13.22.54.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Aug 2022 22:54:07 -0700 (PDT) From: Rebecca Mckeever To: Mike Rapoport , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: David Hildenbrand , Rebecca Mckeever Subject: [PATCH 1/8] memblock tests: update tests to check if memblock_alloc zeroed memory Date: Sun, 14 Aug 2022 00:53:53 -0500 Message-Id: <02d514d86f212c79e52792b8ecd919156d7a9c20.1660454730.git.remckee0@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660456448; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=TqLTKUmEk/mKGbJa80nE77aaCeS2f2PhLCxbPuooWhk=; b=ZbsNmwXgBzKk3rLWJhrP96lgyVwoDvDHe9JtJgU0NHOHU3gLAIa+MNP8sbiegWtijC+R6v U48XNfklVB/AGVzjd3VYIrQxW/fg7Ea9SWSQLev0L6Tl+elgph6EijRhWm8xwm4Ck9Xeqy kzEAajtCYbR2/lFKwyiFl2F/x3Ionfs= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Q+70lCxo; spf=pass (imf30.hostedemail.com: domain of remckee0@gmail.com designates 209.85.166.195 as permitted sender) smtp.mailfrom=remckee0@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660456448; a=rsa-sha256; cv=none; b=b1kwbCCcIvJny3+F10WeiYc+0UTTRVIzPJX3SNeBPTI5YQjyMGATLi5b21ZkOXatXgMgwz PwgAMxs8Ps7DvY3IItLG8OtquQDd5FzlmFqT9R3s7WWNQAOWNfWOgefewwGHudBpYA6uyK PPJdHvcZY8bjR22zzvDeCRN48s8tYLo= X-Stat-Signature: tp34gin5rttpsmguyg5zy754pa7efuhb X-Rspamd-Queue-Id: D13F08019F Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Q+70lCxo; spf=pass (imf30.hostedemail.com: domain of remckee0@gmail.com designates 209.85.166.195 as permitted sender) smtp.mailfrom=remckee0@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: X-Rspamd-Server: rspam06 X-HE-Tag: 1660456448-402468 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add an assert in memblock_alloc() tests where allocation is expected to occur. The assert checks whether the entire chunk of allocated memory is cleared. The current memblock_alloc() tests do not check whether the allocated memory was zeroed. memblock_alloc() should zero the allocated memory since it is a wrapper for memblock_alloc_try_nid(). Signed-off-by: Rebecca Mckeever Reviewed-by: Shaoqin Huang --- tools/testing/memblock/tests/alloc_api.c | 24 ++++++++++++++++++++++++ tools/testing/memblock/tests/common.c | 7 +++++++ tools/testing/memblock/tests/common.h | 13 +++++++++++++ 3 files changed, 44 insertions(+) diff --git a/tools/testing/memblock/tests/alloc_api.c b/tools/testing/memblock/tests/alloc_api.c index a14f38eb8a89..71c89cb9b2a8 100644 --- a/tools/testing/memblock/tests/alloc_api.c +++ b/tools/testing/memblock/tests/alloc_api.c @@ -22,6 +22,8 @@ static int alloc_top_down_simple_check(void) allocated_ptr = memblock_alloc(size, SMP_CACHE_BYTES); ASSERT_NE(allocated_ptr, NULL); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, size); + ASSERT_EQ(rgn->size, size); ASSERT_EQ(rgn->base, expected_start); @@ -80,6 +82,8 @@ static int alloc_top_down_disjoint_check(void) allocated_ptr = memblock_alloc(r2_size, alignment); ASSERT_NE(allocated_ptr, NULL); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, r2_size); + ASSERT_EQ(rgn1->size, r1.size); ASSERT_EQ(rgn1->base, r1.base); @@ -125,6 +129,8 @@ static int alloc_top_down_before_check(void) allocated_ptr = memblock_alloc(r2_size, SMP_CACHE_BYTES); ASSERT_NE(allocated_ptr, NULL); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, r2_size); + ASSERT_EQ(rgn->size, total_size); ASSERT_EQ(rgn->base, memblock_end_of_DRAM() - total_size); @@ -173,6 +179,8 @@ static int alloc_top_down_after_check(void) allocated_ptr = memblock_alloc(r2_size, SMP_CACHE_BYTES); ASSERT_NE(allocated_ptr, NULL); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, r2_size); + ASSERT_EQ(rgn->size, total_size); ASSERT_EQ(rgn->base, r1.base - r2_size); @@ -223,6 +231,8 @@ static int alloc_top_down_second_fit_check(void) allocated_ptr = memblock_alloc(r3_size, SMP_CACHE_BYTES); ASSERT_NE(allocated_ptr, NULL); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, r3_size); + ASSERT_EQ(rgn->size, r2.size + r3_size); ASSERT_EQ(rgn->base, r2.base - r3_size); @@ -277,6 +287,8 @@ static int alloc_in_between_generic_check(void) allocated_ptr = memblock_alloc(r3_size, SMP_CACHE_BYTES); ASSERT_NE(allocated_ptr, NULL); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, r3_size); + ASSERT_EQ(rgn->size, total_size); ASSERT_EQ(rgn->base, r1.base - r2.size - r3_size); @@ -418,6 +430,8 @@ static int alloc_limited_space_generic_check(void) allocated_ptr = memblock_alloc(available_size, SMP_CACHE_BYTES); ASSERT_NE(allocated_ptr, NULL); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, available_size); + ASSERT_EQ(rgn->size, MEM_SIZE); ASSERT_EQ(rgn->base, memblock_start_of_DRAM()); @@ -442,6 +456,7 @@ static int alloc_no_memory_generic_check(void) PREFIX_PUSH(); reset_memblock_regions(); + fill_memblock(); allocated_ptr = memblock_alloc(SZ_1K, SMP_CACHE_BYTES); @@ -472,6 +487,8 @@ static int alloc_bottom_up_simple_check(void) allocated_ptr = memblock_alloc(SZ_2, SMP_CACHE_BYTES); ASSERT_NE(allocated_ptr, NULL); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, SZ_2); + ASSERT_EQ(rgn->size, SZ_2); ASSERT_EQ(rgn->base, memblock_start_of_DRAM()); @@ -528,6 +545,7 @@ static int alloc_bottom_up_disjoint_check(void) allocated_ptr = memblock_alloc(r2_size, alignment); ASSERT_NE(allocated_ptr, NULL); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, r2_size); ASSERT_EQ(rgn1->size, r1.size); ASSERT_EQ(rgn1->base, r1.base); @@ -571,6 +589,8 @@ static int alloc_bottom_up_before_check(void) allocated_ptr = memblock_alloc(r1_size, SMP_CACHE_BYTES); ASSERT_NE(allocated_ptr, NULL); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, r1_size); + ASSERT_EQ(rgn->size, total_size); ASSERT_EQ(rgn->base, memblock_start_of_DRAM()); @@ -618,6 +638,8 @@ static int alloc_bottom_up_after_check(void) allocated_ptr = memblock_alloc(r2_size, SMP_CACHE_BYTES); ASSERT_NE(allocated_ptr, NULL); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, r2_size); + ASSERT_EQ(rgn->size, total_size); ASSERT_EQ(rgn->base, r1.base); @@ -669,6 +691,8 @@ static int alloc_bottom_up_second_fit_check(void) allocated_ptr = memblock_alloc(r3_size, SMP_CACHE_BYTES); ASSERT_NE(allocated_ptr, NULL); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, r3_size); + ASSERT_EQ(rgn->size, r2.size + r3_size); ASSERT_EQ(rgn->base, r2.base); diff --git a/tools/testing/memblock/tests/common.c b/tools/testing/memblock/tests/common.c index 76a8ad818f3a..0ca26fe12c38 100644 --- a/tools/testing/memblock/tests/common.c +++ b/tools/testing/memblock/tests/common.c @@ -60,16 +60,23 @@ void reset_memblock_attributes(void) memblock.current_limit = MEMBLOCK_ALLOC_ANYWHERE; } +void fill_memblock(void) +{ + memset(memory_block.base, 1, MEM_SIZE); +} + void setup_memblock(void) { reset_memblock_regions(); memblock_add((phys_addr_t)memory_block.base, MEM_SIZE); + fill_memblock(); } void dummy_physical_memory_init(void) { memory_block.base = malloc(MEM_SIZE); assert(memory_block.base); + fill_memblock(); } void dummy_physical_memory_cleanup(void) diff --git a/tools/testing/memblock/tests/common.h b/tools/testing/memblock/tests/common.h index d396e5423a8e..7a16a7dc8f2c 100644 --- a/tools/testing/memblock/tests/common.h +++ b/tools/testing/memblock/tests/common.h @@ -51,6 +51,18 @@ assert((_expected) < (_seen)); \ } while (0) +/** + * ASSERT_MEM_EQ(): + * Check that the first @_size bytes of @_seen are all equal to @_expected. + * If false, print failed test message (if running with --verbose) and then + * assert. + */ +#define ASSERT_MEM_EQ(_seen, _expected, _size) do { \ + for (int _i = 0; _i < (_size); _i++) { \ + ASSERT_EQ((_seen)[_i], (_expected)); \ + } \ +} while (0) + #define PREFIX_PUSH() prefix_push(__func__) /* @@ -70,6 +82,7 @@ struct region { void reset_memblock_regions(void); void reset_memblock_attributes(void); +void fill_memblock(void); void setup_memblock(void); void dummy_physical_memory_init(void); void dummy_physical_memory_cleanup(void); From patchwork Sun Aug 14 05:53:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rebecca Mckeever X-Patchwork-Id: 12942844 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70643C25B08 for ; Sun, 14 Aug 2022 05:54:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0B4C78E0005; Sun, 14 Aug 2022 01:54:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 065F28E0001; Sun, 14 Aug 2022 01:54:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E21268E0005; Sun, 14 Aug 2022 01:54:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id CE7558E0001 for ; Sun, 14 Aug 2022 01:54:11 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id B01F1AB282 for ; Sun, 14 Aug 2022 05:54:11 +0000 (UTC) X-FDA: 79797132702.23.83C66AC Received: from mail-il1-f196.google.com (mail-il1-f196.google.com [209.85.166.196]) by imf05.hostedemail.com (Postfix) with ESMTP id 63379100055 for ; Sun, 14 Aug 2022 05:54:11 +0000 (UTC) Received: by mail-il1-f196.google.com with SMTP id o14so2494314ilt.2 for ; Sat, 13 Aug 2022 22:54:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=ZU3J1Tgpo6J2fZewTeU+O/Q6QDBwUbPH94LC1fh/cTI=; b=ZTQK81BjL0rTYjPjzhlMNhZqjGEeUb/a8pHwNO4L9XxiVuRU1lt3eEoRpM4E+YIu6J ol7NKSrjSOR3lPufYupFHo0DXwBf1PR6Rr7SyWQN0000u7Zc/d0anaF0Rbmw2099Fqr8 TDPSGGh1AaAPQd0+n0LGTNGAm+HiZ4OD19pz/RQC7QISFniHwzhtojIRNYv5vID4kfJG VP2VPKdB9fFFwnJBt8uWamu+YfB/F6e0Jl8kOC+/5/fJcYxm8TbEuKnrzjCGpXaBmlDf KXuGxzgTlDJ3lCqh2dkMJ9Hm0yAHejlzgPuKQtp0TCvUEyyA7FmwqTo6ieT6aFDXzfxL jUUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=ZU3J1Tgpo6J2fZewTeU+O/Q6QDBwUbPH94LC1fh/cTI=; b=djH5tFk2hkWJldtWUw/2j5ze4NT7+/ULgvEDIyGLpTfmzZ5bCpgzq9yGu4dK7ceIph CyYw2ukXeIYey3dp5PSMiNX9J1AYwWMSLIME+lTESyDd/yNeEugX7HUQezlJUCun59qk IASzgYm6OBqOhwYTPJqQYjuJgoWevuQMI7i49DElNevvWs74s232PePi+mjNNAm6emc7 XOsjhiMBuRpbSfKG8ny1es9v1V+Y2hprR7DXqT5v+DvS12W+Q4BPg2rk28iSYRELsbxS EyxWNZr1VRhMTxsEmnZ17OQnD8SyuH1GmW/YKUirWtG6pw11uq1oSevceCG+YmWwd7Sx MhmQ== X-Gm-Message-State: ACgBeo1O4oPogfXuVP3Stupo4B1KfKdYEERigJE9saYqZVc1DmlsgfrW 5n5xxcRaZcvQK14iAv7eyIg= X-Google-Smtp-Source: AA6agR5WfFQmTHge9k1tDwb/jo2aPSqw4CIIzup15qIOPU0NPYDnVjv7sL7bpKLE+1V6QYJVfgxFhg== X-Received: by 2002:a92:c246:0:b0:2de:b25b:e75 with SMTP id k6-20020a92c246000000b002deb25b0e75mr4859094ilo.246.1660456450696; Sat, 13 Aug 2022 22:54:10 -0700 (PDT) Received: from sophie (static-198-54-128-70.cust.tzulo.com. [198.54.128.70]) by smtp.gmail.com with ESMTPSA id c2-20020a023302000000b003435a9369a3sm1803266jae.8.2022.08.13.22.54.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Aug 2022 22:54:10 -0700 (PDT) From: Rebecca Mckeever To: Mike Rapoport , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: David Hildenbrand , Rebecca Mckeever Subject: [PATCH 2/8] memblock tests: update zeroed memory check for memblock_alloc_* tests Date: Sun, 14 Aug 2022 00:53:54 -0500 Message-Id: <02cad26bef7bc8c7271bba20deac0e5f0bf081c2.1660454730.git.remckee0@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660456451; a=rsa-sha256; cv=none; b=SwJqDN6WoY1qibwjd7bxJwi5Uhueilgq9+M/IolROer/NQRUJWd7NlV1SXIAdOx5djbNE8 An79FHje/izC7fd70hSSXnX6J4GAVidKXZ9fft0euVw2YKWsZIRCh8Z08A5JVV5WpSBtLm 8zOIiHZTIEHXflaeFVl1j9RQ1OQFBpI= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=ZTQK81Bj; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf05.hostedemail.com: domain of remckee0@gmail.com designates 209.85.166.196 as permitted sender) smtp.mailfrom=remckee0@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660456451; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ZU3J1Tgpo6J2fZewTeU+O/Q6QDBwUbPH94LC1fh/cTI=; b=wWFOjdS5zQmftfku2h05F7qRiDPuKY1p2UAzv+5OO9Du1+tx8iS0NWUYN6TYGBe6DA3XYy cAPhsqAcTRJfhzllf1ZJAeRBcwUD1v7cjptDktVTiIqfoE1eV2BnPbA+2K+HW2Td+HVzCm +729DfTcqmAfpUr/DjTl5CWGKe5rzbo= X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 63379100055 Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=ZTQK81Bj; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf05.hostedemail.com: domain of remckee0@gmail.com designates 209.85.166.196 as permitted sender) smtp.mailfrom=remckee0@gmail.com X-Rspam-User: X-Stat-Signature: kujuk1f1cabccijs7hfhxyx3cws8h48q X-HE-Tag: 1660456451-905000 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000036, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Update the assert in memblock_alloc_try_nid() and memblock_alloc_from() tests that checks whether the memory is cleared so that it checks the entire chunk of allocated memory instead of just the first byte. Reviewed-by: David Hildenbrand Signed-off-by: Rebecca Mckeever Reviewed-by: Shaoqin Huang --- .../memblock/tests/alloc_helpers_api.c | 8 +-- tools/testing/memblock/tests/alloc_nid_api.c | 72 +++++-------------- 2 files changed, 20 insertions(+), 60 deletions(-) diff --git a/tools/testing/memblock/tests/alloc_helpers_api.c b/tools/testing/memblock/tests/alloc_helpers_api.c index 1069b4bdd5fd..796527cf3bd2 100644 --- a/tools/testing/memblock/tests/alloc_helpers_api.c +++ b/tools/testing/memblock/tests/alloc_helpers_api.c @@ -19,7 +19,6 @@ static int alloc_from_simple_generic_check(void) { struct memblock_region *rgn = &memblock.reserved.regions[0]; void *allocated_ptr = NULL; - char *b; PREFIX_PUSH(); @@ -31,10 +30,9 @@ static int alloc_from_simple_generic_check(void) min_addr = memblock_end_of_DRAM() - SMP_CACHE_BYTES; allocated_ptr = memblock_alloc_from(size, SMP_CACHE_BYTES, min_addr); - b = (char *)allocated_ptr; ASSERT_NE(allocated_ptr, NULL); - ASSERT_EQ(*b, 0); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, size); ASSERT_EQ(rgn->size, size); ASSERT_EQ(rgn->base, min_addr); @@ -66,7 +64,6 @@ static int alloc_from_misaligned_generic_check(void) { struct memblock_region *rgn = &memblock.reserved.regions[0]; void *allocated_ptr = NULL; - char *b; PREFIX_PUSH(); @@ -79,10 +76,9 @@ static int alloc_from_misaligned_generic_check(void) min_addr = memblock_end_of_DRAM() - (SMP_CACHE_BYTES * 2 - 1); allocated_ptr = memblock_alloc_from(size, SMP_CACHE_BYTES, min_addr); - b = (char *)allocated_ptr; ASSERT_NE(allocated_ptr, NULL); - ASSERT_EQ(*b, 0); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, size); ASSERT_EQ(rgn->size, size); ASSERT_EQ(rgn->base, memblock_end_of_DRAM() - SMP_CACHE_BYTES); diff --git a/tools/testing/memblock/tests/alloc_nid_api.c b/tools/testing/memblock/tests/alloc_nid_api.c index 255fd514e9f5..71b7beb35526 100644 --- a/tools/testing/memblock/tests/alloc_nid_api.c +++ b/tools/testing/memblock/tests/alloc_nid_api.c @@ -19,7 +19,6 @@ static int alloc_try_nid_top_down_simple_check(void) { struct memblock_region *rgn = &memblock.reserved.regions[0]; void *allocated_ptr = NULL; - char *b; PREFIX_PUSH(); @@ -35,11 +34,10 @@ static int alloc_try_nid_top_down_simple_check(void) allocated_ptr = memblock_alloc_try_nid(size, SMP_CACHE_BYTES, min_addr, max_addr, NUMA_NO_NODE); - b = (char *)allocated_ptr; rgn_end = rgn->base + rgn->size; ASSERT_NE(allocated_ptr, NULL); - ASSERT_EQ(*b, 0); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, size); ASSERT_EQ(rgn->size, size); ASSERT_EQ(rgn->base, max_addr - size); @@ -74,7 +72,6 @@ static int alloc_try_nid_top_down_end_misaligned_check(void) { struct memblock_region *rgn = &memblock.reserved.regions[0]; void *allocated_ptr = NULL; - char *b; PREFIX_PUSH(); @@ -91,11 +88,10 @@ static int alloc_try_nid_top_down_end_misaligned_check(void) allocated_ptr = memblock_alloc_try_nid(size, SMP_CACHE_BYTES, min_addr, max_addr, NUMA_NO_NODE); - b = (char *)allocated_ptr; rgn_end = rgn->base + rgn->size; ASSERT_NE(allocated_ptr, NULL); - ASSERT_EQ(*b, 0); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, size); ASSERT_EQ(rgn->size, size); ASSERT_EQ(rgn->base, max_addr - size - misalign); @@ -128,7 +124,6 @@ static int alloc_try_nid_exact_address_generic_check(void) { struct memblock_region *rgn = &memblock.reserved.regions[0]; void *allocated_ptr = NULL; - char *b; PREFIX_PUSH(); @@ -144,11 +139,10 @@ static int alloc_try_nid_exact_address_generic_check(void) allocated_ptr = memblock_alloc_try_nid(size, SMP_CACHE_BYTES, min_addr, max_addr, NUMA_NO_NODE); - b = (char *)allocated_ptr; rgn_end = rgn->base + rgn->size; ASSERT_NE(allocated_ptr, NULL); - ASSERT_EQ(*b, 0); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, size); ASSERT_EQ(rgn->size, size); ASSERT_EQ(rgn->base, min_addr); @@ -183,7 +177,6 @@ static int alloc_try_nid_top_down_narrow_range_check(void) { struct memblock_region *rgn = &memblock.reserved.regions[0]; void *allocated_ptr = NULL; - char *b; PREFIX_PUSH(); @@ -198,10 +191,9 @@ static int alloc_try_nid_top_down_narrow_range_check(void) allocated_ptr = memblock_alloc_try_nid(size, SMP_CACHE_BYTES, min_addr, max_addr, NUMA_NO_NODE); - b = (char *)allocated_ptr; ASSERT_NE(allocated_ptr, NULL); - ASSERT_EQ(*b, 0); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, size); ASSERT_EQ(rgn->size, size); ASSERT_EQ(rgn->base, max_addr - size); @@ -277,7 +269,6 @@ static int alloc_try_nid_min_reserved_generic_check(void) { struct memblock_region *rgn = &memblock.reserved.regions[0]; void *allocated_ptr = NULL; - char *b; PREFIX_PUSH(); @@ -298,10 +289,9 @@ static int alloc_try_nid_min_reserved_generic_check(void) allocated_ptr = memblock_alloc_try_nid(r2_size, SMP_CACHE_BYTES, min_addr, max_addr, NUMA_NO_NODE); - b = (char *)allocated_ptr; ASSERT_NE(allocated_ptr, NULL); - ASSERT_EQ(*b, 0); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, r2_size); ASSERT_EQ(rgn->size, total_size); ASSERT_EQ(rgn->base, reserved_base); @@ -332,7 +322,6 @@ static int alloc_try_nid_max_reserved_generic_check(void) { struct memblock_region *rgn = &memblock.reserved.regions[0]; void *allocated_ptr = NULL; - char *b; PREFIX_PUSH(); @@ -351,10 +340,9 @@ static int alloc_try_nid_max_reserved_generic_check(void) allocated_ptr = memblock_alloc_try_nid(r2_size, SMP_CACHE_BYTES, min_addr, max_addr, NUMA_NO_NODE); - b = (char *)allocated_ptr; ASSERT_NE(allocated_ptr, NULL); - ASSERT_EQ(*b, 0); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, r2_size); ASSERT_EQ(rgn->size, total_size); ASSERT_EQ(rgn->base, min_addr); @@ -389,7 +377,6 @@ static int alloc_try_nid_top_down_reserved_with_space_check(void) struct memblock_region *rgn1 = &memblock.reserved.regions[1]; struct memblock_region *rgn2 = &memblock.reserved.regions[0]; void *allocated_ptr = NULL; - char *b; struct region r1, r2; PREFIX_PUSH(); @@ -417,10 +404,9 @@ static int alloc_try_nid_top_down_reserved_with_space_check(void) allocated_ptr = memblock_alloc_try_nid(r3_size, SMP_CACHE_BYTES, min_addr, max_addr, NUMA_NO_NODE); - b = (char *)allocated_ptr; ASSERT_NE(allocated_ptr, NULL); - ASSERT_EQ(*b, 0); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, r3_size); ASSERT_EQ(rgn1->size, r1.size + r3_size); ASSERT_EQ(rgn1->base, max_addr - r3_size); @@ -456,7 +442,6 @@ static int alloc_try_nid_reserved_full_merge_generic_check(void) { struct memblock_region *rgn = &memblock.reserved.regions[0]; void *allocated_ptr = NULL; - char *b; struct region r1, r2; PREFIX_PUSH(); @@ -483,10 +468,9 @@ static int alloc_try_nid_reserved_full_merge_generic_check(void) allocated_ptr = memblock_alloc_try_nid(r3_size, SMP_CACHE_BYTES, min_addr, max_addr, NUMA_NO_NODE); - b = (char *)allocated_ptr; ASSERT_NE(allocated_ptr, NULL); - ASSERT_EQ(*b, 0); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, r3_size); ASSERT_EQ(rgn->size, total_size); ASSERT_EQ(rgn->base, r2.base); @@ -522,7 +506,6 @@ static int alloc_try_nid_top_down_reserved_no_space_check(void) struct memblock_region *rgn1 = &memblock.reserved.regions[1]; struct memblock_region *rgn2 = &memblock.reserved.regions[0]; void *allocated_ptr = NULL; - char *b; struct region r1, r2; PREFIX_PUSH(); @@ -550,10 +533,9 @@ static int alloc_try_nid_top_down_reserved_no_space_check(void) allocated_ptr = memblock_alloc_try_nid(r3_size, SMP_CACHE_BYTES, min_addr, max_addr, NUMA_NO_NODE); - b = (char *)allocated_ptr; ASSERT_NE(allocated_ptr, NULL); - ASSERT_EQ(*b, 0); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, r3_size); ASSERT_EQ(rgn1->size, r1.size); ASSERT_EQ(rgn1->base, r1.base); @@ -634,7 +616,6 @@ static int alloc_try_nid_top_down_cap_max_check(void) { struct memblock_region *rgn = &memblock.reserved.regions[0]; void *allocated_ptr = NULL; - char *b; PREFIX_PUSH(); @@ -649,10 +630,9 @@ static int alloc_try_nid_top_down_cap_max_check(void) allocated_ptr = memblock_alloc_try_nid(size, SMP_CACHE_BYTES, min_addr, max_addr, NUMA_NO_NODE); - b = (char *)allocated_ptr; ASSERT_NE(allocated_ptr, NULL); - ASSERT_EQ(*b, 0); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, size); ASSERT_EQ(rgn->size, size); ASSERT_EQ(rgn->base, memblock_end_of_DRAM() - size); @@ -674,7 +654,6 @@ static int alloc_try_nid_top_down_cap_min_check(void) { struct memblock_region *rgn = &memblock.reserved.regions[0]; void *allocated_ptr = NULL; - char *b; PREFIX_PUSH(); @@ -689,10 +668,9 @@ static int alloc_try_nid_top_down_cap_min_check(void) allocated_ptr = memblock_alloc_try_nid(size, SMP_CACHE_BYTES, min_addr, max_addr, NUMA_NO_NODE); - b = (char *)allocated_ptr; ASSERT_NE(allocated_ptr, NULL); - ASSERT_EQ(*b, 0); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, size); ASSERT_EQ(rgn->size, size); ASSERT_EQ(rgn->base, memblock_end_of_DRAM() - size); @@ -723,7 +701,6 @@ static int alloc_try_nid_bottom_up_simple_check(void) { struct memblock_region *rgn = &memblock.reserved.regions[0]; void *allocated_ptr = NULL; - char *b; PREFIX_PUSH(); @@ -740,11 +717,10 @@ static int alloc_try_nid_bottom_up_simple_check(void) allocated_ptr = memblock_alloc_try_nid(size, SMP_CACHE_BYTES, min_addr, max_addr, NUMA_NO_NODE); - b = (char *)allocated_ptr; rgn_end = rgn->base + rgn->size; ASSERT_NE(allocated_ptr, NULL); - ASSERT_EQ(*b, 0); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, size); ASSERT_EQ(rgn->size, size); ASSERT_EQ(rgn->base, min_addr); @@ -779,7 +755,6 @@ static int alloc_try_nid_bottom_up_start_misaligned_check(void) { struct memblock_region *rgn = &memblock.reserved.regions[0]; void *allocated_ptr = NULL; - char *b; PREFIX_PUSH(); @@ -797,11 +772,10 @@ static int alloc_try_nid_bottom_up_start_misaligned_check(void) allocated_ptr = memblock_alloc_try_nid(size, SMP_CACHE_BYTES, min_addr, max_addr, NUMA_NO_NODE); - b = (char *)allocated_ptr; rgn_end = rgn->base + rgn->size; ASSERT_NE(allocated_ptr, NULL); - ASSERT_EQ(*b, 0); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, size); ASSERT_EQ(rgn->size, size); ASSERT_EQ(rgn->base, min_addr + (SMP_CACHE_BYTES - misalign)); @@ -836,7 +810,6 @@ static int alloc_try_nid_bottom_up_narrow_range_check(void) { struct memblock_region *rgn = &memblock.reserved.regions[0]; void *allocated_ptr = NULL; - char *b; PREFIX_PUSH(); @@ -852,10 +825,9 @@ static int alloc_try_nid_bottom_up_narrow_range_check(void) allocated_ptr = memblock_alloc_try_nid(size, SMP_CACHE_BYTES, min_addr, max_addr, NUMA_NO_NODE); - b = (char *)allocated_ptr; ASSERT_NE(allocated_ptr, NULL); - ASSERT_EQ(*b, 0); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, size); ASSERT_EQ(rgn->size, size); ASSERT_EQ(rgn->base, memblock_start_of_DRAM()); @@ -890,7 +862,6 @@ static int alloc_try_nid_bottom_up_reserved_with_space_check(void) struct memblock_region *rgn1 = &memblock.reserved.regions[1]; struct memblock_region *rgn2 = &memblock.reserved.regions[0]; void *allocated_ptr = NULL; - char *b; struct region r1, r2; PREFIX_PUSH(); @@ -919,10 +890,9 @@ static int alloc_try_nid_bottom_up_reserved_with_space_check(void) allocated_ptr = memblock_alloc_try_nid(r3_size, SMP_CACHE_BYTES, min_addr, max_addr, NUMA_NO_NODE); - b = (char *)allocated_ptr; ASSERT_NE(allocated_ptr, NULL); - ASSERT_EQ(*b, 0); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, r3_size); ASSERT_EQ(rgn1->size, r1.size); ASSERT_EQ(rgn1->base, max_addr); @@ -964,7 +934,6 @@ static int alloc_try_nid_bottom_up_reserved_no_space_check(void) struct memblock_region *rgn2 = &memblock.reserved.regions[1]; struct memblock_region *rgn3 = &memblock.reserved.regions[0]; void *allocated_ptr = NULL; - char *b; struct region r1, r2; PREFIX_PUSH(); @@ -993,10 +962,9 @@ static int alloc_try_nid_bottom_up_reserved_no_space_check(void) allocated_ptr = memblock_alloc_try_nid(r3_size, SMP_CACHE_BYTES, min_addr, max_addr, NUMA_NO_NODE); - b = (char *)allocated_ptr; ASSERT_NE(allocated_ptr, NULL); - ASSERT_EQ(*b, 0); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, r3_size); ASSERT_EQ(rgn3->size, r3_size); ASSERT_EQ(rgn3->base, memblock_start_of_DRAM()); @@ -1024,7 +992,6 @@ static int alloc_try_nid_bottom_up_cap_max_check(void) { struct memblock_region *rgn = &memblock.reserved.regions[0]; void *allocated_ptr = NULL; - char *b; PREFIX_PUSH(); @@ -1040,10 +1007,9 @@ static int alloc_try_nid_bottom_up_cap_max_check(void) allocated_ptr = memblock_alloc_try_nid(size, SMP_CACHE_BYTES, min_addr, max_addr, NUMA_NO_NODE); - b = (char *)allocated_ptr; ASSERT_NE(allocated_ptr, NULL); - ASSERT_EQ(*b, 0); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, size); ASSERT_EQ(rgn->size, size); ASSERT_EQ(rgn->base, min_addr); @@ -1065,7 +1031,6 @@ static int alloc_try_nid_bottom_up_cap_min_check(void) { struct memblock_region *rgn = &memblock.reserved.regions[0]; void *allocated_ptr = NULL; - char *b; PREFIX_PUSH(); @@ -1081,10 +1046,9 @@ static int alloc_try_nid_bottom_up_cap_min_check(void) allocated_ptr = memblock_alloc_try_nid(size, SMP_CACHE_BYTES, min_addr, max_addr, NUMA_NO_NODE); - b = (char *)allocated_ptr; ASSERT_NE(allocated_ptr, NULL); - ASSERT_EQ(*b, 0); + ASSERT_MEM_EQ((char *)allocated_ptr, 0, size); ASSERT_EQ(rgn->size, size); ASSERT_EQ(rgn->base, memblock_start_of_DRAM()); From patchwork Sun Aug 14 05:53:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rebecca Mckeever X-Patchwork-Id: 12942845 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9DE19C25B06 for ; Sun, 14 Aug 2022 05:54:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 410048E0006; Sun, 14 Aug 2022 01:54:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3C03B8E0001; Sun, 14 Aug 2022 01:54:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2613C8E0006; Sun, 14 Aug 2022 01:54:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 118B28E0001 for ; Sun, 14 Aug 2022 01:54:14 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id DC2691A01F1 for ; Sun, 14 Aug 2022 05:54:13 +0000 (UTC) X-FDA: 79797132786.24.9C9828B Received: from mail-io1-f68.google.com (mail-io1-f68.google.com [209.85.166.68]) by imf27.hostedemail.com (Postfix) with ESMTP id 6ABAE4007E for ; Sun, 14 Aug 2022 05:54:13 +0000 (UTC) Received: by mail-io1-f68.google.com with SMTP id x64so3818061iof.1 for ; Sat, 13 Aug 2022 22:54:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=ILkgh0s9flepsTVscJySAOnLBbfijO6Q0jsQRVlYp2g=; b=Vmr56r0E5Gp4w6hx+69k1/OoBNKL31qc26DEssO6j746fCOQeaXJ1y7eR35X6Lu+iR yLPsywCQjNweOfw3f60pBB3KT+swWKNgHIb9M2JKyws27ADmuBF3vQ5EGrDBCFOvp94n 8Mrmgtymaeqmp9K+3ADADVJVQYB6DMku1TfojSy9tYj9tErA7UfUNcXGu8NANCVlm3gg eUyfyGfE+gDOkmfSWkuV07OFR0OdRoXIrImM/2edpDVK7jgvUUmjGaX87eFHO9TWkhwt bcbjpdDnO7WqNixSsr1Pm9NJ+1yZdSV7RoNvmCsnI9iDPvA52xW1cGxnrTt6X2Q8vSPG Fxkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=ILkgh0s9flepsTVscJySAOnLBbfijO6Q0jsQRVlYp2g=; b=Zb2tx14yKE5rfQCEqrHrgeZ4aML45MXArVgt097uSh1iBZf0oB92OLIjqAK1KTkyjP GQf94ZARXfgoRjSF+Jz9xZJono3gXLQruVnDq2adXR3VRSyqvZU6NFUZMKT605haLlpG UlVyAJrpVHzX94dwo0aydPDgiaBFZMFSjE5p+SIlS427mb9a2kQXxrtPuEgSW2f2hjI0 tkir+1MlykGFpiEihu/aE7yClRoQ8m8txjIwhVmrf5ZX/8FdORoikmYAzLCpNWbGBikP 2DlerzV5PwOrGrO3Ls1TNeufX1PNHkX3HBPPg3g+Q4+vuF2mGrhu/KBDqWfhXto/BEtk BSqw== X-Gm-Message-State: ACgBeo0fk/jtwBjPfvoOeRA2n+EgqdE7KsGiNVsjOgb6Rz5WMGZuOXTx mcyn0vFdvHjK7hvJFL80ZOI= X-Google-Smtp-Source: AA6agR5fSwtKF6fFIiIsxq3c073b8Pn8UpWGkfynSd8Toy4ruDAyb4ubeD7yMxLK1FxRc9MmfARtoA== X-Received: by 2002:a05:6638:250d:b0:340:4915:263 with SMTP id v13-20020a056638250d00b0034049150263mr4792485jat.17.1660456452707; Sat, 13 Aug 2022 22:54:12 -0700 (PDT) Received: from sophie (static-198-54-128-70.cust.tzulo.com. [198.54.128.70]) by smtp.gmail.com with ESMTPSA id x7-20020a056602160700b0067be3f195bcsm3197871iow.5.2022.08.13.22.54.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Aug 2022 22:54:12 -0700 (PDT) From: Rebecca Mckeever To: Mike Rapoport , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: David Hildenbrand , Rebecca Mckeever Subject: [PATCH 3/8] memblock tests: add labels to verbose output for generic alloc tests Date: Sun, 14 Aug 2022 00:53:55 -0500 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660456453; a=rsa-sha256; cv=none; b=n+pXo+DJlOF0TNF37Fm4gXcoJKbAYfcBpUj2Zo8tePVziK8CaICWMu3NCwQM9PhOIQU2YR 0FD28VAKOnGCGtyPfah53KWY3b607a/a8aJWUvgMpc3ODWmLd8cyttdIZvnc3krn+hwc3Y jttGdW3tAIvL+VHCwgct19hGc7Aaa/U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660456453; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ILkgh0s9flepsTVscJySAOnLBbfijO6Q0jsQRVlYp2g=; b=j98/HfgwjD68nCJqpnohim80KLOzDcVVfqFRVToQ0Qy1nxzZ1TDDpxKg5lGoQ6gT2lpNfW TG6UXLWfUEyxDAbtOOYzQoYVTnSs1oD2T/IFXcalCkowxBNaxjJrw3vaT8MPvMP6Jzf6Ue +B2tblwK5Ef+zMtgjUklAf8odBnLUoc= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Vmr56r0E; spf=pass (imf27.hostedemail.com: domain of remckee0@gmail.com designates 209.85.166.68 as permitted sender) smtp.mailfrom=remckee0@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: trn1hu9ugpwnaf1hq5peicqiacnqjctp X-Rspamd-Queue-Id: 6ABAE4007E Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Vmr56r0E; spf=pass (imf27.hostedemail.com: domain of remckee0@gmail.com designates 209.85.166.68 as permitted sender) smtp.mailfrom=remckee0@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: X-Rspamd-Server: rspam04 X-HE-Tag: 1660456453-956910 X-Bogosity: Ham, tests=bogofilter, spamicity=0.089215, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Generic tests for memblock_alloc*() functions do not use separate functions for testing top-down and bottom-up allocation directions. Therefore, the function name that is displayed in the verbose testing output does not include the allocation direction. Add an additional prefix when running generic tests for memblock_alloc*() functions that indicates which allocation direction is set. The prefix will be displayed when the tests are run in verbose mode. Signed-off-by: Rebecca Mckeever --- tools/testing/memblock/tests/alloc_api.c | 36 +++++++------------ .../memblock/tests/alloc_helpers_api.c | 12 +++---- tools/testing/memblock/tests/alloc_nid_api.c | 36 +++++++------------ tools/testing/memblock/tests/common.h | 16 +++++++++ 4 files changed, 44 insertions(+), 56 deletions(-) diff --git a/tools/testing/memblock/tests/alloc_api.c b/tools/testing/memblock/tests/alloc_api.c index 71c89cb9b2a8..73c2c43e702a 100644 --- a/tools/testing/memblock/tests/alloc_api.c +++ b/tools/testing/memblock/tests/alloc_api.c @@ -752,10 +752,8 @@ static int alloc_after_check(void) static int alloc_in_between_check(void) { test_print("\tRunning %s...\n", __func__); - memblock_set_bottom_up(false); - alloc_in_between_generic_check(); - memblock_set_bottom_up(true); - alloc_in_between_generic_check(); + run_top_down(alloc_in_between_generic_check); + run_bottom_up(alloc_in_between_generic_check); return 0; } @@ -774,10 +772,8 @@ static int alloc_second_fit_check(void) static int alloc_small_gaps_check(void) { test_print("\tRunning %s...\n", __func__); - memblock_set_bottom_up(false); - alloc_small_gaps_generic_check(); - memblock_set_bottom_up(true); - alloc_small_gaps_generic_check(); + run_top_down(alloc_small_gaps_generic_check); + run_bottom_up(alloc_small_gaps_generic_check); return 0; } @@ -785,10 +781,8 @@ static int alloc_small_gaps_check(void) static int alloc_all_reserved_check(void) { test_print("\tRunning %s...\n", __func__); - memblock_set_bottom_up(false); - alloc_all_reserved_generic_check(); - memblock_set_bottom_up(true); - alloc_all_reserved_generic_check(); + run_top_down(alloc_all_reserved_generic_check); + run_bottom_up(alloc_all_reserved_generic_check); return 0; } @@ -796,10 +790,8 @@ static int alloc_all_reserved_check(void) static int alloc_no_space_check(void) { test_print("\tRunning %s...\n", __func__); - memblock_set_bottom_up(false); - alloc_no_space_generic_check(); - memblock_set_bottom_up(true); - alloc_no_space_generic_check(); + run_top_down(alloc_no_space_generic_check); + run_bottom_up(alloc_no_space_generic_check); return 0; } @@ -807,10 +799,8 @@ static int alloc_no_space_check(void) static int alloc_limited_space_check(void) { test_print("\tRunning %s...\n", __func__); - memblock_set_bottom_up(false); - alloc_limited_space_generic_check(); - memblock_set_bottom_up(true); - alloc_limited_space_generic_check(); + run_top_down(alloc_limited_space_generic_check); + run_bottom_up(alloc_limited_space_generic_check); return 0; } @@ -818,10 +808,8 @@ static int alloc_limited_space_check(void) static int alloc_no_memory_check(void) { test_print("\tRunning %s...\n", __func__); - memblock_set_bottom_up(false); - alloc_no_memory_generic_check(); - memblock_set_bottom_up(true); - alloc_no_memory_generic_check(); + run_top_down(alloc_no_memory_generic_check); + run_bottom_up(alloc_no_memory_generic_check); return 0; } diff --git a/tools/testing/memblock/tests/alloc_helpers_api.c b/tools/testing/memblock/tests/alloc_helpers_api.c index 796527cf3bd2..1ccf02639ad6 100644 --- a/tools/testing/memblock/tests/alloc_helpers_api.c +++ b/tools/testing/memblock/tests/alloc_helpers_api.c @@ -357,10 +357,8 @@ static int alloc_from_bottom_up_min_addr_cap_check(void) static int alloc_from_simple_check(void) { test_print("\tRunning %s...\n", __func__); - memblock_set_bottom_up(false); - alloc_from_simple_generic_check(); - memblock_set_bottom_up(true); - alloc_from_simple_generic_check(); + run_top_down(alloc_from_simple_generic_check); + run_bottom_up(alloc_from_simple_generic_check); return 0; } @@ -368,10 +366,8 @@ static int alloc_from_simple_check(void) static int alloc_from_misaligned_check(void) { test_print("\tRunning %s...\n", __func__); - memblock_set_bottom_up(false); - alloc_from_misaligned_generic_check(); - memblock_set_bottom_up(true); - alloc_from_misaligned_generic_check(); + run_top_down(alloc_from_misaligned_generic_check); + run_bottom_up(alloc_from_misaligned_generic_check); return 0; } diff --git a/tools/testing/memblock/tests/alloc_nid_api.c b/tools/testing/memblock/tests/alloc_nid_api.c index 71b7beb35526..82fa8ea36320 100644 --- a/tools/testing/memblock/tests/alloc_nid_api.c +++ b/tools/testing/memblock/tests/alloc_nid_api.c @@ -1142,10 +1142,8 @@ static int alloc_try_nid_cap_min_check(void) static int alloc_try_nid_min_reserved_check(void) { test_print("\tRunning %s...\n", __func__); - memblock_set_bottom_up(false); - alloc_try_nid_min_reserved_generic_check(); - memblock_set_bottom_up(true); - alloc_try_nid_min_reserved_generic_check(); + run_top_down(alloc_try_nid_min_reserved_generic_check); + run_bottom_up(alloc_try_nid_min_reserved_generic_check); return 0; } @@ -1153,10 +1151,8 @@ static int alloc_try_nid_min_reserved_check(void) static int alloc_try_nid_max_reserved_check(void) { test_print("\tRunning %s...\n", __func__); - memblock_set_bottom_up(false); - alloc_try_nid_max_reserved_generic_check(); - memblock_set_bottom_up(true); - alloc_try_nid_max_reserved_generic_check(); + run_top_down(alloc_try_nid_max_reserved_generic_check); + run_bottom_up(alloc_try_nid_max_reserved_generic_check); return 0; } @@ -1164,10 +1160,8 @@ static int alloc_try_nid_max_reserved_check(void) static int alloc_try_nid_exact_address_check(void) { test_print("\tRunning %s...\n", __func__); - memblock_set_bottom_up(false); - alloc_try_nid_exact_address_generic_check(); - memblock_set_bottom_up(true); - alloc_try_nid_exact_address_generic_check(); + run_top_down(alloc_try_nid_exact_address_generic_check); + run_bottom_up(alloc_try_nid_exact_address_generic_check); return 0; } @@ -1175,10 +1169,8 @@ static int alloc_try_nid_exact_address_check(void) static int alloc_try_nid_reserved_full_merge_check(void) { test_print("\tRunning %s...\n", __func__); - memblock_set_bottom_up(false); - alloc_try_nid_reserved_full_merge_generic_check(); - memblock_set_bottom_up(true); - alloc_try_nid_reserved_full_merge_generic_check(); + run_top_down(alloc_try_nid_reserved_full_merge_generic_check); + run_bottom_up(alloc_try_nid_reserved_full_merge_generic_check); return 0; } @@ -1186,10 +1178,8 @@ static int alloc_try_nid_reserved_full_merge_check(void) static int alloc_try_nid_reserved_all_check(void) { test_print("\tRunning %s...\n", __func__); - memblock_set_bottom_up(false); - alloc_try_nid_reserved_all_generic_check(); - memblock_set_bottom_up(true); - alloc_try_nid_reserved_all_generic_check(); + run_top_down(alloc_try_nid_reserved_all_generic_check); + run_bottom_up(alloc_try_nid_reserved_all_generic_check); return 0; } @@ -1197,10 +1187,8 @@ static int alloc_try_nid_reserved_all_check(void) static int alloc_try_nid_low_max_check(void) { test_print("\tRunning %s...\n", __func__); - memblock_set_bottom_up(false); - alloc_try_nid_low_max_generic_check(); - memblock_set_bottom_up(true); - alloc_try_nid_low_max_generic_check(); + run_top_down(alloc_try_nid_low_max_generic_check); + run_bottom_up(alloc_try_nid_low_max_generic_check); return 0; } diff --git a/tools/testing/memblock/tests/common.h b/tools/testing/memblock/tests/common.h index 7a16a7dc8f2c..e0dd5b410099 100644 --- a/tools/testing/memblock/tests/common.h +++ b/tools/testing/memblock/tests/common.h @@ -101,4 +101,20 @@ static inline void test_pass_pop(void) prefix_pop(); } +static inline void run_top_down(int (*func)()) +{ + memblock_set_bottom_up(false); + prefix_push("top-down"); + func(); + prefix_pop(); +} + +static inline void run_bottom_up(int (*func)()) +{ + memblock_set_bottom_up(true); + prefix_push("bottom-up"); + func(); + prefix_pop(); +} + #endif From patchwork Sun Aug 14 05:53:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rebecca Mckeever X-Patchwork-Id: 12942846 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80534C25B08 for ; Sun, 14 Aug 2022 05:54:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1C7328E0007; Sun, 14 Aug 2022 01:54:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 176C38E0001; Sun, 14 Aug 2022 01:54:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F0AB08E0007; Sun, 14 Aug 2022 01:54:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id E13758E0001 for ; Sun, 14 Aug 2022 01:54:15 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id C2607AB29B for ; Sun, 14 Aug 2022 05:54:15 +0000 (UTC) X-FDA: 79797132870.15.2D46C1C Received: from mail-io1-f68.google.com (mail-io1-f68.google.com [209.85.166.68]) by imf07.hostedemail.com (Postfix) with ESMTP id 6E2AB40046 for ; Sun, 14 Aug 2022 05:54:15 +0000 (UTC) Received: by mail-io1-f68.google.com with SMTP id r141so272464iod.4 for ; Sat, 13 Aug 2022 22:54:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=2t+DOWlEB0vRRGkl5a8lTXvzwGf7Xd8C9kZbiMM/MLc=; b=J9SiQt4/9D4i9l4YDPfv/CkDxtvcgS0qErp07OhbDJT58SuOClE98CMskOD2JQa4gu 36vXpQHTkyjxM1VmAoDdGFko9X1lxEmjnZ/TDkC2qVHI6O12J3FyHxdB+/TDSscW9V1e iGrZcDdbLh/TjzmZxw+ZqxJILJMSOCIP20uC0V/Nx0BxYupYjBPJoEtpMu9yxo+01mXK Ro3xwZxMM1emc/Yt6CyjaV+gKdOR2UJpl3qH2s8JrAJMVILh1RIgMGaAyUXVV4TTF048 kokt4rU1rhvBNwIyoT8UivPBf03J0Xin3pscy7pkqz2JuLe4vI5VpTOJ3Tb07E0kDwNP wN6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=2t+DOWlEB0vRRGkl5a8lTXvzwGf7Xd8C9kZbiMM/MLc=; b=BZE/WytbTt8Bo0rPv0sP6Q87FMxzOm77wfNiIC0yEUvEJEbYlk0KI+LQ2TSiRtv2iX /LDPM698C7V83xOhegHWmgE1XhBQEPuBlYzzMyPlyXa5quFF2b8Z8A7zc8xkipzekLYL DP8h9YDu3n8pQwCM+Rtg/U6V0KFGmwbJE5zyOgNP8MojvthDHEJHCKqfec+gcOXLtv6j S1Rnsu1Ei+8EDbsA0aBhfrowOh/OjUHhaVdmYiDpny7VyY7dIZZq2rx5QD+kNRgxWYS4 sDEcEtPAz0Y3KhNqoqhRqjpsApixUSPlACoFk7XNn1sYIKvasPsznlj6FrY6w1rW59eQ DzRA== X-Gm-Message-State: ACgBeo30BlIdCJ/try3tA5+YMKpRnOrTv3k8K8Ad6XSnfKL2qKmrQgI9 AxtINGZQPCsP/aE/yrOOajw= X-Google-Smtp-Source: AA6agR791dJ2mgJUdXOatqLGSN+pew7fSuNEmOQjNc0ZMEsG6UU5AYwc/ouK7aBzd7R8YZjO6l/wBg== X-Received: by 2002:a05:6638:13c9:b0:342:7d75:41f0 with SMTP id i9-20020a05663813c900b003427d7541f0mr5051021jaj.268.1660456454757; Sat, 13 Aug 2022 22:54:14 -0700 (PDT) Received: from sophie (static-198-54-128-70.cust.tzulo.com. [198.54.128.70]) by smtp.gmail.com with ESMTPSA id t4-20020a92c904000000b002dd5302804fsm2317185ilp.40.2022.08.13.22.54.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Aug 2022 22:54:14 -0700 (PDT) From: Rebecca Mckeever To: Mike Rapoport , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: David Hildenbrand , Rebecca Mckeever Subject: [PATCH 4/8] memblock tests: add additional tests for basic api and memblock_alloc Date: Sun, 14 Aug 2022 00:53:56 -0500 Message-Id: <816c5d36d18944171b3fa4964ce75d91f8096bf1.1660454730.git.remckee0@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660456455; a=rsa-sha256; cv=none; b=k6K3PmBp83yG6nhYHldhYEsvI12pgrPVnL3rh17o+8WlNAul0KM8rxoAHLqHu2gN5Hh2p0 +BkcNmz4+AnfdBT7YZSasFH+px/KMWOLAWKi2G7S70LBWqGZORa564kgNuwtds5LTCRBOf BMdewjNJdYMsR9H2W9mhm4isl698tak= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="J9SiQt4/"; spf=pass (imf07.hostedemail.com: domain of remckee0@gmail.com designates 209.85.166.68 as permitted sender) smtp.mailfrom=remckee0@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660456455; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=2t+DOWlEB0vRRGkl5a8lTXvzwGf7Xd8C9kZbiMM/MLc=; b=wtGOe3p1aofEfK4ZQd5I2tMc7/I74Oay08At1XFEQiyiTw90hw0Da9Uo7/Iac0cZBmDWdn dMtyZ7FEjRRPpzd3OPiFUMdwNXEc0sSwaAAmceu55tqiGzPkzfE3FuLkAgSYisPje7z2LT AUN7PLxf3rfWKuU0hwY2tS5mySkvlNA= X-Stat-Signature: akhi5gp4o8i68jjuam4cakh9rnyiyuo9 X-Rspamd-Queue-Id: 6E2AB40046 X-Rspam-User: X-Rspamd-Server: rspam03 Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="J9SiQt4/"; spf=pass (imf07.hostedemail.com: domain of remckee0@gmail.com designates 209.85.166.68 as permitted sender) smtp.mailfrom=remckee0@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1660456455-608303 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000012, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add tests for memblock_add(), memblock_reserve(), memblock_remove(), memblock_free(), and memblock_alloc() for the following test scenarios. memblock_add() and memblock_reserve(): - add/reserve a memory block in the gap between two existing memory blocks, and check that the blocks are merged into one region - try to add/reserve memblock regions that extend past PHYS_ADDR_MAX memblock_remove() and memblock_free(): - remove/free a region when it is the only available region + These tests ensure that the first region is overwritten with a "dummy" region when the last remaining region of that type is removed or freed. - remove/free() a region that overlaps with two existing regions of the relevant type - try to remove/free memblock regions that extend past PHYS_ADDR_MAX memblock_alloc(): - try to allocate a region that is larger than the total size of available memory (memblock.memory) Signed-off-by: Rebecca Mckeever --- tools/testing/memblock/tests/alloc_api.c | 44 ++ tools/testing/memblock/tests/basic_api.c | 499 +++++++++++++++++++++++ 2 files changed, 543 insertions(+) diff --git a/tools/testing/memblock/tests/alloc_api.c b/tools/testing/memblock/tests/alloc_api.c index 73c2c43e702a..fe1ee3b2e851 100644 --- a/tools/testing/memblock/tests/alloc_api.c +++ b/tools/testing/memblock/tests/alloc_api.c @@ -470,6 +470,40 @@ static int alloc_no_memory_generic_check(void) return 0; } +/* + * A test that tries to allocate a region that is larger than the total size of + * available memory (memblock.memory): + * + * +-----------------------------------+ + * | new | + * +-----------------------------------+ + * | | + * | | + * +---------------------------------+ + * + * Expect no allocation to happen. + */ +static int alloc_too_large_generic_check(void) +{ + struct memblock_region *rgn = &memblock.reserved.regions[0]; + void *allocated_ptr = NULL; + + PREFIX_PUSH(); + + setup_memblock(); + + allocated_ptr = memblock_alloc(MEM_SIZE + SZ_2, SMP_CACHE_BYTES); + + ASSERT_EQ(allocated_ptr, NULL); + ASSERT_EQ(rgn->size, 0); + ASSERT_EQ(rgn->base, 0); + ASSERT_EQ(memblock.reserved.total_size, 0); + + test_pass_pop(); + + return 0; +} + /* * A simple test that tries to allocate a small memory region. * Expect to allocate an aligned region at the beginning of the available @@ -814,6 +848,15 @@ static int alloc_no_memory_check(void) return 0; } +static int alloc_too_large_check(void) +{ + test_print("\tRunning %s...\n", __func__); + run_top_down(alloc_too_large_generic_check); + run_bottom_up(alloc_too_large_generic_check); + + return 0; +} + int memblock_alloc_checks(void) { const char *func_testing = "memblock_alloc"; @@ -836,6 +879,7 @@ int memblock_alloc_checks(void) alloc_no_space_check(); alloc_limited_space_check(); alloc_no_memory_check(); + alloc_too_large_check(); dummy_physical_memory_cleanup(); diff --git a/tools/testing/memblock/tests/basic_api.c b/tools/testing/memblock/tests/basic_api.c index 66f46f261e66..ef5642d0863b 100644 --- a/tools/testing/memblock/tests/basic_api.c +++ b/tools/testing/memblock/tests/basic_api.c @@ -326,6 +326,102 @@ static int memblock_add_twice_check(void) return 0; } +/* + * A test that tries to add two memory blocks that don't overlap with one + * another and then add a third memory block in the space between the first two: + * + * | +--------+--------+--------+ | + * | | r1 | r3 | r2 | | + * +--------+--------+--------+--------+--+ + * + * Expect to merge the three entries into one region that starts at r1.base + * and has size of r1.size + r2.size + r3.size. The region counter and total + * size of the available memory are updated. + */ +static int memblock_add_between_check(void) +{ + struct memblock_region *rgn; + phys_addr_t total_size; + + rgn = &memblock.memory.regions[0]; + + struct region r1 = { + .base = SZ_1G, + .size = SZ_8K + }; + struct region r2 = { + .base = SZ_1G + SZ_16K, + .size = SZ_8K + }; + struct region r3 = { + .base = SZ_1G + SZ_8K, + .size = SZ_8K + }; + + PREFIX_PUSH(); + + total_size = r1.size + r2.size + r3.size; + + reset_memblock_regions(); + memblock_add(r1.base, r1.size); + memblock_add(r2.base, r2.size); + memblock_add(r3.base, r3.size); + + ASSERT_EQ(rgn->base, r1.base); + ASSERT_EQ(rgn->size, total_size); + + ASSERT_EQ(memblock.memory.cnt, 1); + ASSERT_EQ(memblock.memory.total_size, total_size); + + test_pass_pop(); + + return 0; +} + +/* + * A simple test that tries to add a memory block r when r extends past + * PHYS_ADDR_MAX: + * + * +--------+ + * | r | + * +--------+ + * | +----+ + * | | rgn| + * +----------------------------+----+ + * + * Expect to add a memory block of size PHYS_ADDR_MAX - r.base. Expect the + * total size of available memory and the counter to be updated. + */ +static int memblock_add_near_max_check(void) +{ + struct memblock_region *rgn; + phys_addr_t total_size; + + rgn = &memblock.memory.regions[0]; + + struct region r = { + .base = PHYS_ADDR_MAX - SZ_1M, + .size = SZ_2M + }; + + PREFIX_PUSH(); + + total_size = PHYS_ADDR_MAX - r.base; + + reset_memblock_regions(); + memblock_add(r.base, r.size); + + ASSERT_EQ(rgn->base, r.base); + ASSERT_EQ(rgn->size, total_size); + + ASSERT_EQ(memblock.memory.cnt, 1); + ASSERT_EQ(memblock.memory.total_size, total_size); + + test_pass_pop(); + + return 0; +} + static int memblock_add_checks(void) { prefix_reset(); @@ -339,6 +435,8 @@ static int memblock_add_checks(void) memblock_add_overlap_bottom_check(); memblock_add_within_check(); memblock_add_twice_check(); + memblock_add_between_check(); + memblock_add_near_max_check(); prefix_pop(); @@ -604,6 +702,102 @@ static int memblock_reserve_twice_check(void) return 0; } +/* + * A test that tries to mark two memory blocks that don't overlap as reserved + * and then reserve a third memory block in the space between the first two: + * + * | +--------+--------+--------+ | + * | | r1 | r3 | r2 | | + * +--------+--------+--------+--------+--+ + * + * Expect to merge the three entries into one reserved region that starts at + * r1.base and has size of r1.size + r2.size + r3.size. The region counter and + * total for memblock.reserved are updated. + */ +static int memblock_reserve_between_check(void) +{ + struct memblock_region *rgn; + phys_addr_t total_size; + + rgn = &memblock.reserved.regions[0]; + + struct region r1 = { + .base = SZ_1G, + .size = SZ_8K + }; + struct region r2 = { + .base = SZ_1G + SZ_16K, + .size = SZ_8K + }; + struct region r3 = { + .base = SZ_1G + SZ_8K, + .size = SZ_8K + }; + + PREFIX_PUSH(); + + total_size = r1.size + r2.size + r3.size; + + reset_memblock_regions(); + memblock_reserve(r1.base, r1.size); + memblock_reserve(r2.base, r2.size); + memblock_reserve(r3.base, r3.size); + + ASSERT_EQ(rgn->base, r1.base); + ASSERT_EQ(rgn->size, total_size); + + ASSERT_EQ(memblock.reserved.cnt, 1); + ASSERT_EQ(memblock.reserved.total_size, total_size); + + test_pass_pop(); + + return 0; +} + +/* + * A simple test that tries to reserve a memory block r when r extends past + * PHYS_ADDR_MAX: + * + * +--------+ + * | r | + * +--------+ + * | +----+ + * | | rgn| + * +----------------------------+----+ + * + * Expect to reserve a memory block of size PHYS_ADDR_MAX - r.base. Expect the + * total size of reserved memory and the counter to be updated. + */ +static int memblock_reserve_near_max_check(void) +{ + struct memblock_region *rgn; + phys_addr_t total_size; + + rgn = &memblock.reserved.regions[0]; + + struct region r = { + .base = PHYS_ADDR_MAX - SZ_1M, + .size = SZ_2M + }; + + PREFIX_PUSH(); + + total_size = PHYS_ADDR_MAX - r.base; + + reset_memblock_regions(); + memblock_reserve(r.base, r.size); + + ASSERT_EQ(rgn->base, r.base); + ASSERT_EQ(rgn->size, total_size); + + ASSERT_EQ(memblock.reserved.cnt, 1); + ASSERT_EQ(memblock.reserved.total_size, total_size); + + test_pass_pop(); + + return 0; +} + static int memblock_reserve_checks(void) { prefix_reset(); @@ -616,6 +810,8 @@ static int memblock_reserve_checks(void) memblock_reserve_overlap_bottom_check(); memblock_reserve_within_check(); memblock_reserve_twice_check(); + memblock_reserve_between_check(); + memblock_reserve_near_max_check(); prefix_pop(); @@ -887,6 +1083,155 @@ static int memblock_remove_within_check(void) return 0; } +/* + * A simple test that tries to remove a region r1 from the array of + * available memory regions when r1 is the only available region. + * Expect to add a memory block r1 and then remove r1 so that a dummy + * region is added. The region counter stays the same, and the total size + * is updated. + */ +static int memblock_remove_only_region_check(void) +{ + struct memblock_region *rgn; + + rgn = &memblock.memory.regions[0]; + + struct region r1 = { + .base = SZ_2K, + .size = SZ_4K + }; + + PREFIX_PUSH(); + + reset_memblock_regions(); + memblock_add(r1.base, r1.size); + memblock_remove(r1.base, r1.size); + + ASSERT_EQ(rgn->base, 0); + ASSERT_EQ(rgn->size, 0); + + ASSERT_EQ(memblock.memory.cnt, 1); + ASSERT_EQ(memblock.memory.total_size, 0); + + test_pass_pop(); + + return 0; +} + +/* + * A simple test that tries remove a region r2 from the array of available + * memory regions when r2 extends past PHYS_ADDR_MAX: + * + * +--------+ + * | r2 | + * +--------+ + * | +---+....+ + * | |rgn| | + * +------------------------+---+----+ + * + * Expect that only the portion between PHYS_ADDR_MAX and r2.base is removed. + * Expect the total size of available memory to be updated and the counter to + * not be updated. + */ +static int memblock_remove_near_max_check(void) +{ + struct memblock_region *rgn; + phys_addr_t total_size; + + rgn = &memblock.memory.regions[0]; + + struct region r1 = { + .base = PHYS_ADDR_MAX - SZ_2M, + .size = SZ_2M + }; + + struct region r2 = { + .base = PHYS_ADDR_MAX - SZ_1M, + .size = SZ_2M + }; + + PREFIX_PUSH(); + + total_size = r1.size - (PHYS_ADDR_MAX - r2.base); + + reset_memblock_regions(); + memblock_add(r1.base, r1.size); + memblock_remove(r2.base, r2.size); + + ASSERT_EQ(rgn->base, r1.base); + ASSERT_EQ(rgn->size, total_size); + + ASSERT_EQ(memblock.memory.cnt, 1); + ASSERT_EQ(memblock.memory.total_size, total_size); + + test_pass_pop(); + + return 0; +} + +/* + * A test that tries to remove a region r3 that overlaps with two existing + * regions r1 and r2: + * + * +----------------+ + * | r3 | + * +----------------+ + * | +----+..... ........+--------+ + * | | |r1 : : |r2 | | + * +----+----+----+---+-------+--------+-----+ + * + * Expect that only the intersections of r1 with r3 and r2 with r3 are removed + * from the available memory pool. Expect the total size of available memory to + * be updated and the counter to not be updated. + */ +static int memblock_remove_overlap_two_check(void) +{ + struct memblock_region *rgn1, *rgn2; + phys_addr_t r1_size, r2_size, r2_end, r3_end, total_size; + + rgn1 = &memblock.memory.regions[0]; + rgn2 = &memblock.memory.regions[1]; + + struct region r1 = { + .base = SZ_16M, + .size = SZ_32M + }; + struct region r2 = { + .base = SZ_64M, + .size = SZ_64M + }; + struct region r3 = { + .base = SZ_32M, + .size = SZ_64M + }; + + PREFIX_PUSH(); + + r2_end = r2.base + r2.size; + r3_end = r3.base + r3.size; + r1_size = r3.base - r1.base; + r2_size = r2_end - r3_end; + total_size = r1_size + r2_size; + + reset_memblock_regions(); + memblock_add(r1.base, r1.size); + memblock_add(r2.base, r2.size); + memblock_remove(r3.base, r3.size); + + ASSERT_EQ(rgn1->base, r1.base); + ASSERT_EQ(rgn1->size, r1_size); + + ASSERT_EQ(rgn2->base, r3_end); + ASSERT_EQ(rgn2->size, r2_size); + + ASSERT_EQ(memblock.memory.cnt, 2); + ASSERT_EQ(memblock.memory.total_size, total_size); + + test_pass_pop(); + + return 0; +} + static int memblock_remove_checks(void) { prefix_reset(); @@ -898,6 +1243,9 @@ static int memblock_remove_checks(void) memblock_remove_overlap_top_check(); memblock_remove_overlap_bottom_check(); memblock_remove_within_check(); + memblock_remove_only_region_check(); + memblock_remove_near_max_check(); + memblock_remove_overlap_two_check(); prefix_pop(); @@ -1163,6 +1511,154 @@ static int memblock_free_within_check(void) return 0; } +/* + * A simple test that tries to free a memory block r1 that was marked + * earlier as reserved when r1 is the only available region. + * Expect to reserve a memory block r1 and then free r1 so that r1 is + * overwritten with a dummy region. The region counter stays the same, + * and the total size is updated. + */ +static int memblock_free_only_region_check(void) +{ + struct memblock_region *rgn; + + rgn = &memblock.reserved.regions[0]; + + struct region r1 = { + .base = SZ_2K, + .size = SZ_4K + }; + + PREFIX_PUSH(); + + reset_memblock_regions(); + memblock_reserve(r1.base, r1.size); + memblock_free((void *)r1.base, r1.size); + + ASSERT_EQ(rgn->base, 0); + ASSERT_EQ(rgn->size, 0); + + ASSERT_EQ(memblock.reserved.cnt, 1); + ASSERT_EQ(memblock.reserved.total_size, 0); + + test_pass_pop(); + + return 0; +} + +/* + * A simple test that tries free a region r2 when r2 extends past PHYS_ADDR_MAX: + * + * +--------+ + * | r2 | + * +--------+ + * | +---+....+ + * | |rgn| | + * +------------------------+---+----+ + * + * Expect that only the portion between PHYS_ADDR_MAX and r2.base is freed. + * Expect the total size of reserved memory to be updated and the counter to + * not be updated. + */ +static int memblock_free_near_max_check(void) +{ + struct memblock_region *rgn; + phys_addr_t total_size; + + rgn = &memblock.reserved.regions[0]; + + struct region r1 = { + .base = PHYS_ADDR_MAX - SZ_2M, + .size = SZ_2M + }; + + struct region r2 = { + .base = PHYS_ADDR_MAX - SZ_1M, + .size = SZ_2M + }; + + PREFIX_PUSH(); + + total_size = r1.size - (PHYS_ADDR_MAX - r2.base); + + reset_memblock_regions(); + memblock_reserve(r1.base, r1.size); + memblock_free((void *)r2.base, r2.size); + + ASSERT_EQ(rgn->base, r1.base); + ASSERT_EQ(rgn->size, total_size); + + ASSERT_EQ(memblock.reserved.cnt, 1); + ASSERT_EQ(memblock.reserved.total_size, total_size); + + test_pass_pop(); + + return 0; +} + +/* + * A test that tries to free a reserved region r3 that overlaps with two + * existing reserved regions r1 and r2: + * + * +----------------+ + * | r3 | + * +----------------+ + * | +----+..... ........+--------+ + * | | |r1 : : |r2 | | + * +----+----+----+---+-------+--------+-----+ + * + * Expect that only the intersections of r1 with r3 and r2 with r3 are freed + * from the collection of reserved memory. Expect the total size of reserved + * memory to be updated and the counter to not be updated. + */ +static int memblock_free_overlap_two_check(void) +{ + struct memblock_region *rgn1, *rgn2; + phys_addr_t r1_size, r2_size, r2_end, r3_end, total_size; + + rgn1 = &memblock.reserved.regions[0]; + rgn2 = &memblock.reserved.regions[1]; + + struct region r1 = { + .base = SZ_16M, + .size = SZ_32M + }; + struct region r2 = { + .base = SZ_64M, + .size = SZ_64M + }; + struct region r3 = { + .base = SZ_32M, + .size = SZ_64M + }; + + PREFIX_PUSH(); + + r2_end = r2.base + r2.size; + r3_end = r3.base + r3.size; + r1_size = r3.base - r1.base; + r2_size = r2_end - r3_end; + total_size = r1_size + r2_size; + + reset_memblock_regions(); + memblock_reserve(r1.base, r1.size); + memblock_reserve(r2.base, r2.size); + memblock_free((void *)r3.base, r3.size); + + ASSERT_EQ(rgn1->base, r1.base); + ASSERT_EQ(rgn1->size, r1_size); + + ASSERT_EQ(rgn2->base, r3_end); + ASSERT_EQ(rgn2->size, r2_size); + + ASSERT_EQ(memblock.reserved.cnt, 2); + ASSERT_EQ(memblock.reserved.total_size, total_size); + + test_pass_pop(); + + return 0; +} + static int memblock_free_checks(void) { prefix_reset(); @@ -1174,6 +1670,9 @@ static int memblock_free_checks(void) memblock_free_overlap_top_check(); memblock_free_overlap_bottom_check(); memblock_free_within_check(); + memblock_free_only_region_check(); + memblock_free_near_max_check(); + memblock_free_overlap_two_check(); prefix_pop(); From patchwork Sun Aug 14 05:53:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rebecca Mckeever X-Patchwork-Id: 12942847 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4BAB7C25B06 for ; Sun, 14 Aug 2022 05:54:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E4AD08E0008; Sun, 14 Aug 2022 01:54:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DF9BF8E0001; Sun, 14 Aug 2022 01:54:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C4BE48E0008; Sun, 14 Aug 2022 01:54:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id B3B368E0001 for ; Sun, 14 Aug 2022 01:54:17 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 83B7EA0513 for ; Sun, 14 Aug 2022 05:54:17 +0000 (UTC) X-FDA: 79797132954.09.9F450F5 Received: from mail-il1-f195.google.com (mail-il1-f195.google.com [209.85.166.195]) by imf30.hostedemail.com (Postfix) with ESMTP id 2BBCB801A1 for ; Sun, 14 Aug 2022 05:54:17 +0000 (UTC) Received: by mail-il1-f195.google.com with SMTP id l9so2489769ilq.1 for ; Sat, 13 Aug 2022 22:54:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=V683Hnn2q0/vCvNg5zACgDjgDcSCcwjZhitBaRpwDvQ=; b=hnWrx7hgdfuaDxo41+rNai87UZ1mbRQkGGgRRxtjaRx95RoWQnwhHaXgGRgcTms63Q BF/AO/Usat8RLcHyoQJvdLTeWFLqwPKwpSpzomTfvzOV1A7URE5UFFZ8HqyZqBfIh5+p gp2AIfKUcILS4U3oDcVry3aUf+eMmQHLsWOhtVa+oH4lbik4aQq1mu6gMiWk0Vf391u7 nSea5LTM1C0r4m2a6zKsBV0a0PrbcyXAW4C2+ZjdIjhc4AsaBmpwszqaUA46agtzRoz+ Z8eOQ9uUSfUdwfXTJ7rFrLYO5LZs4Yt2vNp2QMJIE2JUSWRXtNtf0VH3H/ciACP/k8tJ 3LUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=V683Hnn2q0/vCvNg5zACgDjgDcSCcwjZhitBaRpwDvQ=; b=mH7NPIhXFxKo2wXp8ZM/oYmK+z6JKyNo6wgmPuf6IlJJZymS8rHl4zWwfEyMhi0RbZ OgoHrDY8pEDDEbeQZ+zyKtyhN/SXKPQWvLjtiJBshWd1K+qT0N5nDR4C8ObN1gHi41g3 YkvspviPMNRZkk5KYLRWrGli0TY1FcxzQLrR+m0rLtWLE44NGmdtQ5XkWzwvBNsn04NX CB0ZcwEYvv3DRLPCU3059XAmfj91NnJJI7tBsDMKz8agYs82koju4DA2K2C6aQiMhngf a/rEwE0EgMxzbPbm2W5P1cBV3oNgzGXBwuaipGLk2jBn3pk8mLX3PTf+fUJetdVAw4L4 WsFA== X-Gm-Message-State: ACgBeo0ueISsqPNE5/ftZiIkOTYnQ3mCwMjaO/u5gLF9fehod7Er50hu g2/rUU4BtJbz6wfLXMVk+O8= X-Google-Smtp-Source: AA6agR79YY8+gdKUXDqfn42+zgcWVGin9Yh5/pTBmwNLQkvPUawNp1uaP2GpYjnodEDq8gC7iQxOIA== X-Received: by 2002:a05:6e02:160c:b0:2df:6eaa:1239 with SMTP id t12-20020a056e02160c00b002df6eaa1239mr4557398ilu.171.1660456456695; Sat, 13 Aug 2022 22:54:16 -0700 (PDT) Received: from sophie (static-198-54-128-70.cust.tzulo.com. [198.54.128.70]) by smtp.gmail.com with ESMTPSA id h8-20020a05660208c800b006882a3bd03fsm432704ioz.16.2022.08.13.22.54.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Aug 2022 22:54:16 -0700 (PDT) From: Rebecca Mckeever To: Mike Rapoport , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: David Hildenbrand , Rebecca Mckeever Subject: [PATCH 5/8] memblock tests: update alloc_api to test memblock_alloc_raw Date: Sun, 14 Aug 2022 00:53:57 -0500 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660456457; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=V683Hnn2q0/vCvNg5zACgDjgDcSCcwjZhitBaRpwDvQ=; b=pR4+4ItEefb1oWQxBfrU1y+IsUzM7gIgqyedeRH5ZxXeW79z+4SQ6f1qvf9pNJz0Zgj9m/ IoruNf6mWmXb8TCC+rVVM50HS0aJ8iF/oGZtKSrR8CD2/j6sYXQ65NbffpJIR5LZpWdO7k J9qnXcHkgXKL3j5EkL2mR2MORP/LRU4= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=hnWrx7hg; spf=pass (imf30.hostedemail.com: domain of remckee0@gmail.com designates 209.85.166.195 as permitted sender) smtp.mailfrom=remckee0@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660456457; a=rsa-sha256; cv=none; b=eUyXDwsFNlA7zkke6Km5L1PLEnF/+IhTMrExxwl3dz+ZihhL2rOBRiUK8+tdvS5E3WFsGl gLHbyUmL8o4GUItcOKLZx4no5yOIodmABKc9Bvz56hPe00MUji2EA4cqPBId/SnHBwjjch NplVzfEb6JWTCX5R60TKruSH3kGdPSQ= X-Stat-Signature: pdzki191ri98fiw5chg34mbecxn5ir5b X-Rspamd-Queue-Id: 2BBCB801A1 Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=hnWrx7hg; spf=pass (imf30.hostedemail.com: domain of remckee0@gmail.com designates 209.85.166.195 as permitted sender) smtp.mailfrom=remckee0@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: X-Rspamd-Server: rspam06 X-HE-Tag: 1660456457-684193 X-Bogosity: Ham, tests=bogofilter, spamicity=0.003748, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Update memblock_alloc() tests so that they test either memblock_alloc() or memblock_alloc_raw() depending on the value of alloc_test_flags. Run through all the existing tests in memblock_alloc_api twice: once for memblock_alloc() and once for memblock_alloc_raw(). When the tests run memblock_alloc(), they test that the entire memory region is zero. When the tests run memblock_alloc_raw(), they test that the entire memory region is nonzero. Signed-off-by: Rebecca Mckeever --- tools/testing/memblock/tests/alloc_api.c | 106 ++++++++++++++++------- tools/testing/memblock/tests/common.h | 17 ++++ 2 files changed, 90 insertions(+), 33 deletions(-) diff --git a/tools/testing/memblock/tests/alloc_api.c b/tools/testing/memblock/tests/alloc_api.c index fe1ee3b2e851..e3c0dc2174e9 100644 --- a/tools/testing/memblock/tests/alloc_api.c +++ b/tools/testing/memblock/tests/alloc_api.c @@ -1,6 +1,37 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "alloc_api.h" +static const char * const func_testing[] = { + "memblock_alloc", + "memblock_alloc_raw" +}; + +static int alloc_test_flags = TEST_ZEROED; + +static inline const char * const get_func_testing(int flags) +{ + if (flags & TEST_RAW) + return func_testing[1]; + else + return func_testing[0]; +} + +static inline void *run_memblock_alloc(phys_addr_t size, phys_addr_t align) +{ + if (alloc_test_flags & TEST_RAW) + return memblock_alloc_raw(size, align); + else + return memblock_alloc(size, align); +} + +static inline void verify_mem_content(void *mem, int size) +{ + if (alloc_test_flags & TEST_RAW) + ASSERT_MEM_NE((char *)mem, 0, size); + else + ASSERT_MEM_EQ((char *)mem, 0, size); +} + /* * A simple test that tries to allocate a small memory region. * Expect to allocate an aligned region near the end of the available memory. @@ -19,10 +50,10 @@ static int alloc_top_down_simple_check(void) expected_start = memblock_end_of_DRAM() - SMP_CACHE_BYTES; - allocated_ptr = memblock_alloc(size, SMP_CACHE_BYTES); + allocated_ptr = run_memblock_alloc(size, SMP_CACHE_BYTES); ASSERT_NE(allocated_ptr, NULL); - ASSERT_MEM_EQ((char *)allocated_ptr, 0, size); + verify_mem_content(allocated_ptr, size); ASSERT_EQ(rgn->size, size); ASSERT_EQ(rgn->base, expected_start); @@ -79,10 +110,10 @@ static int alloc_top_down_disjoint_check(void) memblock_reserve(r1.base, r1.size); - allocated_ptr = memblock_alloc(r2_size, alignment); + allocated_ptr = run_memblock_alloc(r2_size, alignment); ASSERT_NE(allocated_ptr, NULL); - ASSERT_MEM_EQ((char *)allocated_ptr, 0, r2_size); + verify_mem_content(allocated_ptr, r2_size); ASSERT_EQ(rgn1->size, r1.size); ASSERT_EQ(rgn1->base, r1.base); @@ -126,10 +157,10 @@ static int alloc_top_down_before_check(void) memblock_reserve(memblock_end_of_DRAM() - total_size, r1_size); - allocated_ptr = memblock_alloc(r2_size, SMP_CACHE_BYTES); + allocated_ptr = run_memblock_alloc(r2_size, SMP_CACHE_BYTES); ASSERT_NE(allocated_ptr, NULL); - ASSERT_MEM_EQ((char *)allocated_ptr, 0, r2_size); + verify_mem_content(allocated_ptr, r2_size); ASSERT_EQ(rgn->size, total_size); ASSERT_EQ(rgn->base, memblock_end_of_DRAM() - total_size); @@ -176,10 +207,10 @@ static int alloc_top_down_after_check(void) memblock_reserve(r1.base, r1.size); - allocated_ptr = memblock_alloc(r2_size, SMP_CACHE_BYTES); + allocated_ptr = run_memblock_alloc(r2_size, SMP_CACHE_BYTES); ASSERT_NE(allocated_ptr, NULL); - ASSERT_MEM_EQ((char *)allocated_ptr, 0, r2_size); + verify_mem_content(allocated_ptr, r2_size); ASSERT_EQ(rgn->size, total_size); ASSERT_EQ(rgn->base, r1.base - r2_size); @@ -228,10 +259,10 @@ static int alloc_top_down_second_fit_check(void) memblock_reserve(r1.base, r1.size); memblock_reserve(r2.base, r2.size); - allocated_ptr = memblock_alloc(r3_size, SMP_CACHE_BYTES); + allocated_ptr = run_memblock_alloc(r3_size, SMP_CACHE_BYTES); ASSERT_NE(allocated_ptr, NULL); - ASSERT_MEM_EQ((char *)allocated_ptr, 0, r3_size); + verify_mem_content(allocated_ptr, r3_size); ASSERT_EQ(rgn->size, r2.size + r3_size); ASSERT_EQ(rgn->base, r2.base - r3_size); @@ -284,10 +315,10 @@ static int alloc_in_between_generic_check(void) memblock_reserve(r1.base, r1.size); memblock_reserve(r2.base, r2.size); - allocated_ptr = memblock_alloc(r3_size, SMP_CACHE_BYTES); + allocated_ptr = run_memblock_alloc(r3_size, SMP_CACHE_BYTES); ASSERT_NE(allocated_ptr, NULL); - ASSERT_MEM_EQ((char *)allocated_ptr, 0, r3_size); + verify_mem_content(allocated_ptr, r3_size); ASSERT_EQ(rgn->size, total_size); ASSERT_EQ(rgn->base, r1.base - r2.size - r3_size); @@ -332,7 +363,7 @@ static int alloc_small_gaps_generic_check(void) region_end += gap_size + region_size; } - allocated_ptr = memblock_alloc(region_size, SMP_CACHE_BYTES); + allocated_ptr = run_memblock_alloc(region_size, SMP_CACHE_BYTES); ASSERT_EQ(allocated_ptr, NULL); @@ -356,7 +387,7 @@ static int alloc_all_reserved_generic_check(void) /* Simulate full memory */ memblock_reserve(memblock_start_of_DRAM(), MEM_SIZE); - allocated_ptr = memblock_alloc(SZ_256, SMP_CACHE_BYTES); + allocated_ptr = run_memblock_alloc(SZ_256, SMP_CACHE_BYTES); ASSERT_EQ(allocated_ptr, NULL); @@ -392,7 +423,7 @@ static int alloc_no_space_generic_check(void) /* Simulate almost-full memory */ memblock_reserve(memblock_start_of_DRAM(), reserved_size); - allocated_ptr = memblock_alloc(SZ_1K, SMP_CACHE_BYTES); + allocated_ptr = run_memblock_alloc(SZ_1K, SMP_CACHE_BYTES); ASSERT_EQ(allocated_ptr, NULL); @@ -427,10 +458,10 @@ static int alloc_limited_space_generic_check(void) /* Simulate almost-full memory */ memblock_reserve(memblock_start_of_DRAM(), reserved_size); - allocated_ptr = memblock_alloc(available_size, SMP_CACHE_BYTES); + allocated_ptr = run_memblock_alloc(available_size, SMP_CACHE_BYTES); ASSERT_NE(allocated_ptr, NULL); - ASSERT_MEM_EQ((char *)allocated_ptr, 0, available_size); + verify_mem_content(allocated_ptr, available_size); ASSERT_EQ(rgn->size, MEM_SIZE); ASSERT_EQ(rgn->base, memblock_start_of_DRAM()); @@ -458,7 +489,7 @@ static int alloc_no_memory_generic_check(void) reset_memblock_regions(); fill_memblock(); - allocated_ptr = memblock_alloc(SZ_1K, SMP_CACHE_BYTES); + allocated_ptr = run_memblock_alloc(SZ_1K, SMP_CACHE_BYTES); ASSERT_EQ(allocated_ptr, NULL); ASSERT_EQ(rgn->size, 0); @@ -492,7 +523,7 @@ static int alloc_too_large_generic_check(void) setup_memblock(); - allocated_ptr = memblock_alloc(MEM_SIZE + SZ_2, SMP_CACHE_BYTES); + allocated_ptr = run_memblock_alloc(MEM_SIZE + SZ_2, SMP_CACHE_BYTES); ASSERT_EQ(allocated_ptr, NULL); ASSERT_EQ(rgn->size, 0); @@ -518,10 +549,10 @@ static int alloc_bottom_up_simple_check(void) setup_memblock(); - allocated_ptr = memblock_alloc(SZ_2, SMP_CACHE_BYTES); + allocated_ptr = run_memblock_alloc(SZ_2, SMP_CACHE_BYTES); ASSERT_NE(allocated_ptr, NULL); - ASSERT_MEM_EQ((char *)allocated_ptr, 0, SZ_2); + verify_mem_content(allocated_ptr, SZ_2); ASSERT_EQ(rgn->size, SZ_2); ASSERT_EQ(rgn->base, memblock_start_of_DRAM()); @@ -576,10 +607,10 @@ static int alloc_bottom_up_disjoint_check(void) memblock_reserve(r1.base, r1.size); - allocated_ptr = memblock_alloc(r2_size, alignment); + allocated_ptr = run_memblock_alloc(r2_size, alignment); ASSERT_NE(allocated_ptr, NULL); - ASSERT_MEM_EQ((char *)allocated_ptr, 0, r2_size); + verify_mem_content(allocated_ptr, r2_size); ASSERT_EQ(rgn1->size, r1.size); ASSERT_EQ(rgn1->base, r1.base); @@ -620,10 +651,10 @@ static int alloc_bottom_up_before_check(void) memblock_reserve(memblock_start_of_DRAM() + r1_size, r2_size); - allocated_ptr = memblock_alloc(r1_size, SMP_CACHE_BYTES); + allocated_ptr = run_memblock_alloc(r1_size, SMP_CACHE_BYTES); ASSERT_NE(allocated_ptr, NULL); - ASSERT_MEM_EQ((char *)allocated_ptr, 0, r1_size); + verify_mem_content(allocated_ptr, r1_size); ASSERT_EQ(rgn->size, total_size); ASSERT_EQ(rgn->base, memblock_start_of_DRAM()); @@ -669,10 +700,10 @@ static int alloc_bottom_up_after_check(void) memblock_reserve(r1.base, r1.size); - allocated_ptr = memblock_alloc(r2_size, SMP_CACHE_BYTES); + allocated_ptr = run_memblock_alloc(r2_size, SMP_CACHE_BYTES); ASSERT_NE(allocated_ptr, NULL); - ASSERT_MEM_EQ((char *)allocated_ptr, 0, r2_size); + verify_mem_content(allocated_ptr, r2_size); ASSERT_EQ(rgn->size, total_size); ASSERT_EQ(rgn->base, r1.base); @@ -722,10 +753,10 @@ static int alloc_bottom_up_second_fit_check(void) memblock_reserve(r1.base, r1.size); memblock_reserve(r2.base, r2.size); - allocated_ptr = memblock_alloc(r3_size, SMP_CACHE_BYTES); + allocated_ptr = run_memblock_alloc(r3_size, SMP_CACHE_BYTES); ASSERT_NE(allocated_ptr, NULL); - ASSERT_MEM_EQ((char *)allocated_ptr, 0, r3_size); + verify_mem_content(allocated_ptr, r3_size); ASSERT_EQ(rgn->size, r2.size + r3_size); ASSERT_EQ(rgn->base, r2.base); @@ -857,13 +888,14 @@ static int alloc_too_large_check(void) return 0; } -int memblock_alloc_checks(void) +static int memblock_alloc_checks_internal(int flags) { - const char *func_testing = "memblock_alloc"; + const char *func = get_func_testing(flags); + alloc_test_flags = flags; prefix_reset(); - prefix_push(func_testing); - test_print("Running %s tests...\n", func_testing); + prefix_push(func); + test_print("Running %s tests...\n", func); reset_memblock_attributes(); dummy_physical_memory_init(); @@ -887,3 +919,11 @@ int memblock_alloc_checks(void) return 0; } + +int memblock_alloc_checks(void) +{ + memblock_alloc_checks_internal(TEST_ZEROED); + memblock_alloc_checks_internal(TEST_RAW); + + return 0; +} diff --git a/tools/testing/memblock/tests/common.h b/tools/testing/memblock/tests/common.h index e0dd5b410099..a0594f1e4fe3 100644 --- a/tools/testing/memblock/tests/common.h +++ b/tools/testing/memblock/tests/common.h @@ -12,6 +12,11 @@ #define MEM_SIZE SZ_16K +enum test_flags { + TEST_ZEROED = 0x0, + TEST_RAW = 0x1 +}; + /** * ASSERT_EQ(): * Check the condition @@ -63,6 +68,18 @@ } \ } while (0) +/** + * ASSERT_MEM_NE(): + * Check that none of the first @_size bytes of @_seen are equal to @_expected. + * If false, print failed test message (if running with --verbose) and then + * assert. + */ +#define ASSERT_MEM_NE(_seen, _expected, _size) do { \ + for (int _i = 0; _i < (_size); _i++) { \ + ASSERT_NE((_seen)[_i], (_expected)); \ + } \ +} while (0) + #define PREFIX_PUSH() prefix_push(__func__) /* From patchwork Sun Aug 14 05:53:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rebecca Mckeever X-Patchwork-Id: 12942848 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 61229C25B08 for ; Sun, 14 Aug 2022 05:54:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F33F88E0009; Sun, 14 Aug 2022 01:54:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EBF628E0001; Sun, 14 Aug 2022 01:54:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CE7AA8E0009; Sun, 14 Aug 2022 01:54:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id BEB068E0001 for ; Sun, 14 Aug 2022 01:54:19 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 954FB160689 for ; Sun, 14 Aug 2022 05:54:19 +0000 (UTC) X-FDA: 79797133038.09.9F4879C Received: from mail-il1-f194.google.com (mail-il1-f194.google.com [209.85.166.194]) by imf10.hostedemail.com (Postfix) with ESMTP id 3C87FC01A0 for ; Sun, 14 Aug 2022 05:54:19 +0000 (UTC) Received: by mail-il1-f194.google.com with SMTP id z8so2507413ile.0 for ; Sat, 13 Aug 2022 22:54:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=mrwOFT/FVIpeQilRUSDlN1UFE6zYPVjgWmD8J2V/Rvw=; b=kzOoUtnt+1ScgJ8esSYWaoJQNS0I+4PV9yigMOUggv6Un7yJZpa2YCTxfyI7pmNJCE OchlVt+bRFGASVbrBnqan+ICPglUQP1NW/JQu277PhGvNJDI2PXHFbHhOUR6BTdZhyNw Dicfa0soc5mWdHKIfA9Hhs+EGQRefyT94wFa369xpj1MDMIoBNtNf4u8HsOgogPBnLx5 ppkIXLRVJum8M6IAVYXbkf75ABQzT4m4hrg15N+ORpppsqsrvELpnHhkXa990aij2VbK TOTW0HcwOvaVXqa0vPMppMRwUtfPJcPMf0NP+UOk+nOpovLeP2biej/Qzcq5um6ovfXm olxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=mrwOFT/FVIpeQilRUSDlN1UFE6zYPVjgWmD8J2V/Rvw=; b=yWxQRPMYx8nNQ+3Ey7/0PawDdnNggiskzOCYJveu+PpYeGBSLDMdaoemLxfmywM1w4 ddRdK1y6IBysmqfyH5EKQwjOjr5DuhhqqO3i1W+eKv0ZCjhMG3SD6ZNv4Sq8Rz2VlcN+ dytru0MPp2wI8rmLtUHh1GXGEvSGfPPtA50/AXm3Ta2XBebl7B7N5xUUQmzwprK2BCCD zHKzSF/4airNuwuJae1EVTqIKQxEGmbVW+EFMcYMyu+DpxWOPlGZMH1/r1kRq4Pf+q4B mIuQ2Lau5s2LzJbqg35xf3SFPnZ8ZcRp3LOfU1c0h0hLT52wQl+gj1oE18BYmLGqmeWR OflA== X-Gm-Message-State: ACgBeo0l/kWZilCthvJ/oteV0nsx3NF1qysRmAxOHda5fZx/VvYSUvHm 9//N+6SYOluirCWsB30Ivh8= X-Google-Smtp-Source: AA6agR5YE34UARRXt7XzwTzkmVuH340HkSDCAUvT5f59RLZ+kXqXbh02Efm57RVbCJnfAhEDb7bzZw== X-Received: by 2002:a05:6e02:1caf:b0:2e0:cec1:9f17 with SMTP id x15-20020a056e021caf00b002e0cec19f17mr4801562ill.5.1660456458500; Sat, 13 Aug 2022 22:54:18 -0700 (PDT) Received: from sophie (static-198-54-128-70.cust.tzulo.com. [198.54.128.70]) by smtp.gmail.com with ESMTPSA id u7-20020a056e02110700b002dcafb975c6sm2603415ilk.82.2022.08.13.22.54.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Aug 2022 22:54:18 -0700 (PDT) From: Rebecca Mckeever To: Mike Rapoport , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: David Hildenbrand , Rebecca Mckeever Subject: [PATCH 6/8] memblock tests: update alloc_nid_api to test memblock_alloc_try_nid_raw Date: Sun, 14 Aug 2022 00:53:58 -0500 Message-Id: <4c9b416480a5070f18c3933a1a03296f32c2091b.1660454730.git.remckee0@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660456459; a=rsa-sha256; cv=none; b=tRD3hkRSpy3Wo94dZXovQVxYk4mzgFJL04UQbiN7xaJcHGvt6WQO9VIO99zJphvn5qUcBA KY8HC5a+UIr6tDelENVA6dDtzjPvbfa6YA9JwiyerwHzLEBe83JAod00QaC8xOB/WJF3zi Si8+O78fx257hcib7LN4dwD+wndWluU= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=kzOoUtnt; spf=pass (imf10.hostedemail.com: domain of remckee0@gmail.com designates 209.85.166.194 as permitted sender) smtp.mailfrom=remckee0@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660456459; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=mrwOFT/FVIpeQilRUSDlN1UFE6zYPVjgWmD8J2V/Rvw=; b=U1E3bu6sqRal7cK/iQTWCSIPggojeSKIdVMX6zyd0VtCob0idZMMijRkkj5dy9ncKL23rG TSQj3bs4wvYObL8yT5ghanuXsKPu3oSxCVcQZSi3Z35Q/VsaE/nVXC1FVHEvaaULx4N0iV /qdJieZ7VXG5jeyEnGZG0DLof9haETk= X-Rspamd-Queue-Id: 3C87FC01A0 Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=kzOoUtnt; spf=pass (imf10.hostedemail.com: domain of remckee0@gmail.com designates 209.85.166.194 as permitted sender) smtp.mailfrom=remckee0@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: X-Rspamd-Server: rspam12 X-Stat-Signature: xag7p8ikowja6fcxsagmxyrz1byyectg X-HE-Tag: 1660456459-7277 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000034, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Update memblock_alloc_try_nid() tests so that they test either memblock_alloc_try_nid() or memblock_alloc_try_nid_raw() depending on the value of alloc_nid_test_flags. Run through all the existing tests in alloc_nid_api twice: once for memblock_alloc_try_nid() and once for memblock_alloc_try_nid_raw(). When the tests run memblock_alloc_try_nid(), they test that the entire memory region is zero. When the tests run memblock_alloc_try_nid_raw(), they test that the entire memory region is nonzero. Signed-off-by: Rebecca Mckeever --- tools/testing/memblock/tests/alloc_nid_api.c | 196 ++++++++++++------- 1 file changed, 127 insertions(+), 69 deletions(-) diff --git a/tools/testing/memblock/tests/alloc_nid_api.c b/tools/testing/memblock/tests/alloc_nid_api.c index 82fa8ea36320..e16106d8446b 100644 --- a/tools/testing/memblock/tests/alloc_nid_api.c +++ b/tools/testing/memblock/tests/alloc_nid_api.c @@ -1,6 +1,42 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "alloc_nid_api.h" +static const char * const func_testing[] = { + "memblock_alloc_try_nid", + "memblock_alloc_try_nid_raw" +}; + +static int alloc_nid_test_flags = TEST_ZEROED; + +static inline const char * const get_func_testing(int flags) +{ + if (flags & TEST_RAW) + return func_testing[1]; + else + return func_testing[0]; +} + +static inline void *run_memblock_alloc_try_nid(phys_addr_t size, + phys_addr_t align, + phys_addr_t min_addr, + phys_addr_t max_addr, int nid) +{ + if (alloc_nid_test_flags & TEST_RAW) + return memblock_alloc_try_nid_raw(size, align, min_addr, + max_addr, nid); + else + return memblock_alloc_try_nid(size, align, min_addr, + max_addr, nid); +} + +static inline void verify_mem_content(void *mem, int size) +{ + if (alloc_nid_test_flags & TEST_RAW) + ASSERT_MEM_NE((char *)mem, 0, size); + else + ASSERT_MEM_EQ((char *)mem, 0, size); +} + /* * A simple test that tries to allocate a memory region within min_addr and * max_addr range: @@ -32,12 +68,13 @@ static int alloc_try_nid_top_down_simple_check(void) min_addr = memblock_start_of_DRAM() + SMP_CACHE_BYTES * 2; max_addr = min_addr + SZ_512; - allocated_ptr = memblock_alloc_try_nid(size, SMP_CACHE_BYTES, - min_addr, max_addr, NUMA_NO_NODE); + allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES, + min_addr, max_addr, + NUMA_NO_NODE); rgn_end = rgn->base + rgn->size; ASSERT_NE(allocated_ptr, NULL); - ASSERT_MEM_EQ((char *)allocated_ptr, 0, size); + verify_mem_content(allocated_ptr, size); ASSERT_EQ(rgn->size, size); ASSERT_EQ(rgn->base, max_addr - size); @@ -86,12 +123,13 @@ static int alloc_try_nid_top_down_end_misaligned_check(void) min_addr = memblock_start_of_DRAM() + SMP_CACHE_BYTES * 2; max_addr = min_addr + SZ_512 + misalign; - allocated_ptr = memblock_alloc_try_nid(size, SMP_CACHE_BYTES, - min_addr, max_addr, NUMA_NO_NODE); + allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES, + min_addr, max_addr, + NUMA_NO_NODE); rgn_end = rgn->base + rgn->size; ASSERT_NE(allocated_ptr, NULL); - ASSERT_MEM_EQ((char *)allocated_ptr, 0, size); + verify_mem_content(allocated_ptr, size); ASSERT_EQ(rgn->size, size); ASSERT_EQ(rgn->base, max_addr - size - misalign); @@ -137,12 +175,13 @@ static int alloc_try_nid_exact_address_generic_check(void) min_addr = memblock_start_of_DRAM() + SMP_CACHE_BYTES; max_addr = min_addr + size; - allocated_ptr = memblock_alloc_try_nid(size, SMP_CACHE_BYTES, - min_addr, max_addr, NUMA_NO_NODE); + allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES, + min_addr, max_addr, + NUMA_NO_NODE); rgn_end = rgn->base + rgn->size; ASSERT_NE(allocated_ptr, NULL); - ASSERT_MEM_EQ((char *)allocated_ptr, 0, size); + verify_mem_content(allocated_ptr, size); ASSERT_EQ(rgn->size, size); ASSERT_EQ(rgn->base, min_addr); @@ -189,11 +228,12 @@ static int alloc_try_nid_top_down_narrow_range_check(void) min_addr = memblock_start_of_DRAM() + SZ_512; max_addr = min_addr + SMP_CACHE_BYTES; - allocated_ptr = memblock_alloc_try_nid(size, SMP_CACHE_BYTES, - min_addr, max_addr, NUMA_NO_NODE); + allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES, + min_addr, max_addr, + NUMA_NO_NODE); ASSERT_NE(allocated_ptr, NULL); - ASSERT_MEM_EQ((char *)allocated_ptr, 0, size); + verify_mem_content(allocated_ptr, size); ASSERT_EQ(rgn->size, size); ASSERT_EQ(rgn->base, max_addr - size); @@ -241,8 +281,9 @@ static int alloc_try_nid_low_max_generic_check(void) min_addr = memblock_start_of_DRAM(); max_addr = min_addr + SMP_CACHE_BYTES; - allocated_ptr = memblock_alloc_try_nid(size, SMP_CACHE_BYTES, - min_addr, max_addr, NUMA_NO_NODE); + allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES, + min_addr, max_addr, + NUMA_NO_NODE); ASSERT_EQ(allocated_ptr, NULL); @@ -287,11 +328,12 @@ static int alloc_try_nid_min_reserved_generic_check(void) memblock_reserve(reserved_base, r1_size); - allocated_ptr = memblock_alloc_try_nid(r2_size, SMP_CACHE_BYTES, - min_addr, max_addr, NUMA_NO_NODE); + allocated_ptr = run_memblock_alloc_try_nid(r2_size, SMP_CACHE_BYTES, + min_addr, max_addr, + NUMA_NO_NODE); ASSERT_NE(allocated_ptr, NULL); - ASSERT_MEM_EQ((char *)allocated_ptr, 0, r2_size); + verify_mem_content(allocated_ptr, r2_size); ASSERT_EQ(rgn->size, total_size); ASSERT_EQ(rgn->base, reserved_base); @@ -338,11 +380,12 @@ static int alloc_try_nid_max_reserved_generic_check(void) memblock_reserve(max_addr, r1_size); - allocated_ptr = memblock_alloc_try_nid(r2_size, SMP_CACHE_BYTES, - min_addr, max_addr, NUMA_NO_NODE); + allocated_ptr = run_memblock_alloc_try_nid(r2_size, SMP_CACHE_BYTES, + min_addr, max_addr, + NUMA_NO_NODE); ASSERT_NE(allocated_ptr, NULL); - ASSERT_MEM_EQ((char *)allocated_ptr, 0, r2_size); + verify_mem_content(allocated_ptr, r2_size); ASSERT_EQ(rgn->size, total_size); ASSERT_EQ(rgn->base, min_addr); @@ -402,11 +445,12 @@ static int alloc_try_nid_top_down_reserved_with_space_check(void) memblock_reserve(r1.base, r1.size); memblock_reserve(r2.base, r2.size); - allocated_ptr = memblock_alloc_try_nid(r3_size, SMP_CACHE_BYTES, - min_addr, max_addr, NUMA_NO_NODE); + allocated_ptr = run_memblock_alloc_try_nid(r3_size, SMP_CACHE_BYTES, + min_addr, max_addr, + NUMA_NO_NODE); ASSERT_NE(allocated_ptr, NULL); - ASSERT_MEM_EQ((char *)allocated_ptr, 0, r3_size); + verify_mem_content(allocated_ptr, r3_size); ASSERT_EQ(rgn1->size, r1.size + r3_size); ASSERT_EQ(rgn1->base, max_addr - r3_size); @@ -466,11 +510,12 @@ static int alloc_try_nid_reserved_full_merge_generic_check(void) memblock_reserve(r1.base, r1.size); memblock_reserve(r2.base, r2.size); - allocated_ptr = memblock_alloc_try_nid(r3_size, SMP_CACHE_BYTES, - min_addr, max_addr, NUMA_NO_NODE); + allocated_ptr = run_memblock_alloc_try_nid(r3_size, SMP_CACHE_BYTES, + min_addr, max_addr, + NUMA_NO_NODE); ASSERT_NE(allocated_ptr, NULL); - ASSERT_MEM_EQ((char *)allocated_ptr, 0, r3_size); + verify_mem_content(allocated_ptr, r3_size); ASSERT_EQ(rgn->size, total_size); ASSERT_EQ(rgn->base, r2.base); @@ -531,11 +576,12 @@ static int alloc_try_nid_top_down_reserved_no_space_check(void) memblock_reserve(r1.base, r1.size); memblock_reserve(r2.base, r2.size); - allocated_ptr = memblock_alloc_try_nid(r3_size, SMP_CACHE_BYTES, - min_addr, max_addr, NUMA_NO_NODE); + allocated_ptr = run_memblock_alloc_try_nid(r3_size, SMP_CACHE_BYTES, + min_addr, max_addr, + NUMA_NO_NODE); ASSERT_NE(allocated_ptr, NULL); - ASSERT_MEM_EQ((char *)allocated_ptr, 0, r3_size); + verify_mem_content(allocated_ptr, r3_size); ASSERT_EQ(rgn1->size, r1.size); ASSERT_EQ(rgn1->base, r1.base); @@ -597,8 +643,9 @@ static int alloc_try_nid_reserved_all_generic_check(void) memblock_reserve(r1.base, r1.size); memblock_reserve(r2.base, r2.size); - allocated_ptr = memblock_alloc_try_nid(r3_size, SMP_CACHE_BYTES, - min_addr, max_addr, NUMA_NO_NODE); + allocated_ptr = run_memblock_alloc_try_nid(r3_size, SMP_CACHE_BYTES, + min_addr, max_addr, + NUMA_NO_NODE); ASSERT_EQ(allocated_ptr, NULL); @@ -628,11 +675,12 @@ static int alloc_try_nid_top_down_cap_max_check(void) min_addr = memblock_end_of_DRAM() - SZ_1K; max_addr = memblock_end_of_DRAM() + SZ_256; - allocated_ptr = memblock_alloc_try_nid(size, SMP_CACHE_BYTES, - min_addr, max_addr, NUMA_NO_NODE); + allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES, + min_addr, max_addr, + NUMA_NO_NODE); ASSERT_NE(allocated_ptr, NULL); - ASSERT_MEM_EQ((char *)allocated_ptr, 0, size); + verify_mem_content(allocated_ptr, size); ASSERT_EQ(rgn->size, size); ASSERT_EQ(rgn->base, memblock_end_of_DRAM() - size); @@ -666,11 +714,12 @@ static int alloc_try_nid_top_down_cap_min_check(void) min_addr = memblock_start_of_DRAM() - SZ_256; max_addr = memblock_end_of_DRAM(); - allocated_ptr = memblock_alloc_try_nid(size, SMP_CACHE_BYTES, - min_addr, max_addr, NUMA_NO_NODE); + allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES, + min_addr, max_addr, + NUMA_NO_NODE); ASSERT_NE(allocated_ptr, NULL); - ASSERT_MEM_EQ((char *)allocated_ptr, 0, size); + verify_mem_content(allocated_ptr, size); ASSERT_EQ(rgn->size, size); ASSERT_EQ(rgn->base, memblock_end_of_DRAM() - size); @@ -714,13 +763,13 @@ static int alloc_try_nid_bottom_up_simple_check(void) min_addr = memblock_start_of_DRAM() + SMP_CACHE_BYTES * 2; max_addr = min_addr + SZ_512; - allocated_ptr = memblock_alloc_try_nid(size, SMP_CACHE_BYTES, - min_addr, max_addr, - NUMA_NO_NODE); + allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES, + min_addr, max_addr, + NUMA_NO_NODE); rgn_end = rgn->base + rgn->size; ASSERT_NE(allocated_ptr, NULL); - ASSERT_MEM_EQ((char *)allocated_ptr, 0, size); + verify_mem_content(allocated_ptr, size); ASSERT_EQ(rgn->size, size); ASSERT_EQ(rgn->base, min_addr); @@ -769,13 +818,13 @@ static int alloc_try_nid_bottom_up_start_misaligned_check(void) min_addr = memblock_start_of_DRAM() + misalign; max_addr = min_addr + SZ_512; - allocated_ptr = memblock_alloc_try_nid(size, SMP_CACHE_BYTES, - min_addr, max_addr, - NUMA_NO_NODE); + allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES, + min_addr, max_addr, + NUMA_NO_NODE); rgn_end = rgn->base + rgn->size; ASSERT_NE(allocated_ptr, NULL); - ASSERT_MEM_EQ((char *)allocated_ptr, 0, size); + verify_mem_content(allocated_ptr, size); ASSERT_EQ(rgn->size, size); ASSERT_EQ(rgn->base, min_addr + (SMP_CACHE_BYTES - misalign)); @@ -822,12 +871,12 @@ static int alloc_try_nid_bottom_up_narrow_range_check(void) min_addr = memblock_start_of_DRAM() + SZ_512; max_addr = min_addr + SMP_CACHE_BYTES; - allocated_ptr = memblock_alloc_try_nid(size, SMP_CACHE_BYTES, - min_addr, max_addr, - NUMA_NO_NODE); + allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES, + min_addr, max_addr, + NUMA_NO_NODE); ASSERT_NE(allocated_ptr, NULL); - ASSERT_MEM_EQ((char *)allocated_ptr, 0, size); + verify_mem_content(allocated_ptr, size); ASSERT_EQ(rgn->size, size); ASSERT_EQ(rgn->base, memblock_start_of_DRAM()); @@ -887,12 +936,12 @@ static int alloc_try_nid_bottom_up_reserved_with_space_check(void) memblock_reserve(r1.base, r1.size); memblock_reserve(r2.base, r2.size); - allocated_ptr = memblock_alloc_try_nid(r3_size, SMP_CACHE_BYTES, - min_addr, max_addr, - NUMA_NO_NODE); + allocated_ptr = run_memblock_alloc_try_nid(r3_size, SMP_CACHE_BYTES, + min_addr, max_addr, + NUMA_NO_NODE); ASSERT_NE(allocated_ptr, NULL); - ASSERT_MEM_EQ((char *)allocated_ptr, 0, r3_size); + verify_mem_content(allocated_ptr, r3_size); ASSERT_EQ(rgn1->size, r1.size); ASSERT_EQ(rgn1->base, max_addr); @@ -959,12 +1008,12 @@ static int alloc_try_nid_bottom_up_reserved_no_space_check(void) memblock_reserve(r1.base, r1.size); memblock_reserve(r2.base, r2.size); - allocated_ptr = memblock_alloc_try_nid(r3_size, SMP_CACHE_BYTES, - min_addr, max_addr, - NUMA_NO_NODE); + allocated_ptr = run_memblock_alloc_try_nid(r3_size, SMP_CACHE_BYTES, + min_addr, max_addr, + NUMA_NO_NODE); ASSERT_NE(allocated_ptr, NULL); - ASSERT_MEM_EQ((char *)allocated_ptr, 0, r3_size); + verify_mem_content(allocated_ptr, r3_size); ASSERT_EQ(rgn3->size, r3_size); ASSERT_EQ(rgn3->base, memblock_start_of_DRAM()); @@ -1004,12 +1053,12 @@ static int alloc_try_nid_bottom_up_cap_max_check(void) min_addr = memblock_start_of_DRAM() + SZ_1K; max_addr = memblock_end_of_DRAM() + SZ_256; - allocated_ptr = memblock_alloc_try_nid(size, SMP_CACHE_BYTES, - min_addr, max_addr, - NUMA_NO_NODE); + allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES, + min_addr, max_addr, + NUMA_NO_NODE); ASSERT_NE(allocated_ptr, NULL); - ASSERT_MEM_EQ((char *)allocated_ptr, 0, size); + verify_mem_content(allocated_ptr, size); ASSERT_EQ(rgn->size, size); ASSERT_EQ(rgn->base, min_addr); @@ -1043,12 +1092,12 @@ static int alloc_try_nid_bottom_up_cap_min_check(void) min_addr = memblock_start_of_DRAM(); max_addr = memblock_end_of_DRAM() - SZ_256; - allocated_ptr = memblock_alloc_try_nid(size, SMP_CACHE_BYTES, - min_addr, max_addr, - NUMA_NO_NODE); + allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES, + min_addr, max_addr, + NUMA_NO_NODE); ASSERT_NE(allocated_ptr, NULL); - ASSERT_MEM_EQ((char *)allocated_ptr, 0, size); + verify_mem_content(allocated_ptr, size); ASSERT_EQ(rgn->size, size); ASSERT_EQ(rgn->base, memblock_start_of_DRAM()); @@ -1193,13 +1242,14 @@ static int alloc_try_nid_low_max_check(void) return 0; } -int memblock_alloc_nid_checks(void) +static int memblock_alloc_nid_checks_internal(int flags) { - const char *func_testing = "memblock_alloc_try_nid"; + const char *func = get_func_testing(flags); + alloc_nid_test_flags = flags; prefix_reset(); - prefix_push(func_testing); - test_print("Running %s tests...\n", func_testing); + prefix_push(func); + test_print("Running %s tests...\n", func); reset_memblock_attributes(); dummy_physical_memory_init(); @@ -1225,3 +1275,11 @@ int memblock_alloc_nid_checks(void) return 0; } + +int memblock_alloc_nid_checks(void) +{ + memblock_alloc_nid_checks_internal(TEST_ZEROED); + memblock_alloc_nid_checks_internal(TEST_RAW); + + return 0; +} From patchwork Sun Aug 14 05:53:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rebecca Mckeever X-Patchwork-Id: 12942849 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id EEBDBC25B06 for ; Sun, 14 Aug 2022 05:54:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8CD2C8E000A; Sun, 14 Aug 2022 01:54:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7DEC18E0001; Sun, 14 Aug 2022 01:54:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 60B348E000A; Sun, 14 Aug 2022 01:54:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 52C988E0001 for ; Sun, 14 Aug 2022 01:54:21 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 37721AB29C for ; Sun, 14 Aug 2022 05:54:21 +0000 (UTC) X-FDA: 79797133122.24.CD529AB Received: from mail-il1-f196.google.com (mail-il1-f196.google.com [209.85.166.196]) by imf05.hostedemail.com (Postfix) with ESMTP id DDDE7100197 for ; Sun, 14 Aug 2022 05:54:20 +0000 (UTC) Received: by mail-il1-f196.google.com with SMTP id o14so2494414ilt.2 for ; Sat, 13 Aug 2022 22:54:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=SnDhYdrAcbvGcTO2vU9jv0bvWt3Yk1v2Rp41yYuWQ5Y=; b=jyJHJXdGgxnJHliMAK+EYrp/qvH6ThciPn+bCSwsOKziwkLyYX6MPGlVUCubMP5P+B NMtPAWl/7nwg8cUg8r65aQI8ncSmX7SyCprI3nRYU3kMd9Tjn4p9tQm6yA9z9nuUWVRR PxOqj7+jJ4gADUE6RYNu/tNkBl1TRNlgnyZ2B5BD67koCOumu4Sz9RSZ9CA81l9mxXdF DlUdLdP52LMVa0G5fWRZChr6PIYHdKelTe/PywwwtkTPJpJZp/xGG3Sl+O1fOUhoh607 AClxX3snucMIc2jFqOEs9np8SalmREVGy4dQuVDKMDygLniWlBpWyWc8grFyeqZs6P23 SwNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=SnDhYdrAcbvGcTO2vU9jv0bvWt3Yk1v2Rp41yYuWQ5Y=; b=FoE+sPUVFmRG4N0YPFBVG69VwnmBNYsSFoV+DNnF4SX09We2g9NZSFTpyTup2swYhy xYl0Lu6vC6Iru+nTqebFJjXYKOmjm8pg2CzVy1azu8OzpHXiO+hNGEdwAQwOmJBBIcmG vOfEWR7XN/w7CyXOsiMQWnAgBkTsUgQBNrMpLfWeAkWl90ZVlTRhkQEUEYaWdLyw7PJ5 MzFLf3hEAUcO0d91HJDAelYBzu15Q+wWuf+62p2mLp4s3xXCKROeghxEQnagJzSbB+vC YrC94ApB1UqD0jyObz+ISIzFo7FQ2FNPrRk2AFLCWFsHqwvFwr9Fy4EV1qA9ht77qbHF l60Q== X-Gm-Message-State: ACgBeo16XrVh+F+giiHUnnOgp9Df1zWuOlJ193qcKJHXIkPoz3WKTL7a o0m/0fnIYH4hHhr0pg+hV7c= X-Google-Smtp-Source: AA6agR5A4fVnZwWVC2PDMrTvzD+FcOYVwxg8Kew9QoZsCBpzm3YWd171CU+xXOYjPP670UvnabnUhw== X-Received: by 2002:a92:c246:0:b0:2de:b25b:e75 with SMTP id k6-20020a92c246000000b002deb25b0e75mr4859257ilo.246.1660456460564; Sat, 13 Aug 2022 22:54:20 -0700 (PDT) Received: from sophie (static-198-54-128-70.cust.tzulo.com. [198.54.128.70]) by smtp.gmail.com with ESMTPSA id d13-20020a92d5cd000000b002dd143ee62esm2648816ilq.14.2022.08.13.22.54.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Aug 2022 22:54:20 -0700 (PDT) From: Rebecca Mckeever To: Mike Rapoport , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: David Hildenbrand , Rebecca Mckeever Subject: [PATCH 7/8] memblock tests: add tests for memblock_*bottom_up functions Date: Sun, 14 Aug 2022 00:53:59 -0500 Message-Id: <69524966ac92d93b45a8a8e739434d5fb31e3084.1660454730.git.remckee0@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660456460; a=rsa-sha256; cv=none; b=ZoFFPcAcf0GN2t4Zyqq3j3zqN9as5rzO6gUzqI49aKNEosU/bAX+op/0OJFX21WJrc2uLh 3AUXEUWx/cwstZlvTX1+MKJT9EuMf6s0zm3VNijT6wHsyXZ/Q9kDvpkZpzUDMJagL8Lyxu ssPqXjIdsAJRzRg6Xodf1WS3bwaxJG4= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=jyJHJXdG; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf05.hostedemail.com: domain of remckee0@gmail.com designates 209.85.166.196 as permitted sender) smtp.mailfrom=remckee0@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660456460; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=SnDhYdrAcbvGcTO2vU9jv0bvWt3Yk1v2Rp41yYuWQ5Y=; b=FxxWj+rjthEvqjSHw2oIUtzjzeBEW6/N7Xb2qUSXreINdEQyfH6R9/uwechftrVq6r9vCI oWeORTXHq/MJmdijS8z78f4PPNvdUBx1PXKcI+jDhKSUj0riUZleDLlO/ijqHSMBhWLzUm TB07U44kL3jQEAdTbvvVL7kFQ3C+W8c= X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: DDDE7100197 Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=jyJHJXdG; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf05.hostedemail.com: domain of remckee0@gmail.com designates 209.85.166.196 as permitted sender) smtp.mailfrom=remckee0@gmail.com X-Rspam-User: X-Stat-Signature: 3wft63npyo491m7njop7bwb98as6hmth X-HE-Tag: 1660456460-850703 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000142, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add simple tests for memblock_set_bottom_up() and memblock_bottom_up(). Reviewed-by: David Hildenbrand Signed-off-by: Rebecca Mckeever Reviewed-by: Shaoqin Huang --- tools/testing/memblock/tests/basic_api.c | 45 ++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/tools/testing/memblock/tests/basic_api.c b/tools/testing/memblock/tests/basic_api.c index ef5642d0863b..d7f008e7a12a 100644 --- a/tools/testing/memblock/tests/basic_api.c +++ b/tools/testing/memblock/tests/basic_api.c @@ -1679,6 +1679,50 @@ static int memblock_free_checks(void) return 0; } +static int memblock_set_bottom_up_check(void) +{ + prefix_push("memblock_set_bottom_up"); + + memblock_set_bottom_up(false); + ASSERT_EQ(memblock.bottom_up, false); + memblock_set_bottom_up(true); + ASSERT_EQ(memblock.bottom_up, true); + + reset_memblock_attributes(); + test_pass_pop(); + + return 0; +} + +static int memblock_bottom_up_check(void) +{ + prefix_push("memblock_bottom_up"); + + memblock_set_bottom_up(false); + ASSERT_EQ(memblock_bottom_up(), memblock.bottom_up); + ASSERT_EQ(memblock_bottom_up(), false); + memblock_set_bottom_up(true); + ASSERT_EQ(memblock_bottom_up(), memblock.bottom_up); + ASSERT_EQ(memblock_bottom_up(), true); + + reset_memblock_attributes(); + test_pass_pop(); + + return 0; +} + +static int memblock_bottom_up_checks(void) +{ + test_print("Running memblock_*bottom_up tests...\n"); + + prefix_reset(); + memblock_set_bottom_up_check(); + prefix_reset(); + memblock_bottom_up_check(); + + return 0; +} + int memblock_basic_checks(void) { memblock_initialization_check(); @@ -1686,6 +1730,7 @@ int memblock_basic_checks(void) memblock_reserve_checks(); memblock_remove_checks(); memblock_free_checks(); + memblock_bottom_up_checks(); return 0; } From patchwork Sun Aug 14 05:54:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rebecca Mckeever X-Patchwork-Id: 12942850 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 763CFC25B08 for ; Sun, 14 Aug 2022 05:54:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EE6CA8E000B; Sun, 14 Aug 2022 01:54:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E46E08E0001; Sun, 14 Aug 2022 01:54:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CC1D98E000B; Sun, 14 Aug 2022 01:54:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id BD41D8E0001 for ; Sun, 14 Aug 2022 01:54:23 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 981F8160743 for ; Sun, 14 Aug 2022 05:54:23 +0000 (UTC) X-FDA: 79797133206.20.0B31042 Received: from mail-il1-f193.google.com (mail-il1-f193.google.com [209.85.166.193]) by imf04.hostedemail.com (Postfix) with ESMTP id 4370440044 for ; Sun, 14 Aug 2022 05:54:23 +0000 (UTC) Received: by mail-il1-f193.google.com with SMTP id g18so2493716ilk.4 for ; Sat, 13 Aug 2022 22:54:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=57rgW1sYbO78tij7BVX5WYr55Vq5FbqyewxGMYBSZtk=; b=B/fgMudF1KCEFCKV6FWg8Gz3rGGiLl0m7TNOf0gfhZZp6Wrgxs92Z4hAbQ+aQjouFu X1OEhXaQUMv8zDIRSMsxneJhLVHEOzJrVtY5K5bCqT8vInwovKktKyBO+cfLYVHy9Aj1 9X2hRFjnuKLsoPh+WDybApb5+vLU2URzvWqvDUny2XJetlHCIEFJrgNaHJZTLpofWny0 +OgdAxLv45Bb5QQCWLQxMB3Ji++3isUtoslT8mnlSQWYA1BGe/FApjhKJuhSlCBNGGow 0gqtnCh97tSHuFJ/lKsADY3kBBv14SjhH0sqmEQMJLbuA/BonAIPynG6Y8rUyqSM6zhE RQyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=57rgW1sYbO78tij7BVX5WYr55Vq5FbqyewxGMYBSZtk=; b=ichjIoiJAIxsdnlHldSMz9Oji/fOi3IlDrqEBI9O7M2HqVAfK37tr43oleuPrfQzd1 VPpsSe4vdAAOOzln7962nSadbNf3juN/yGfliD9H3vOoxrKSrJ7FH2CD0edmbF5VIKpK 3e6qNRNmYCw2P8+hXpzLZLGrqp6mu/MmSZ7VnY5kh41+xnsvw1zouUJpXk+TJihVnINs gCols0RJWFcEJw/D/gz6rqp6jzrNLuCNZgag8corvQwtUi9RjSG4L4IL4dlxNJBltZ0W fWNqRwjD1QzhW+UyHFigMV4wWRany8hmQvNQHIVNdBfwwHTwFPJY1zLgB3VvM/X4vEhy Tq6A== X-Gm-Message-State: ACgBeo1uwt/iFTxcLr05YBJEI/ZxS527VfHMNKJ0YNbu7XJHLyofEpF5 IgNe2O3hCAdzmVUJGO81ZWA= X-Google-Smtp-Source: AA6agR406vu4PkQdRHCd5fMLZ7RIpgMg5EM1fsk2ivjCdmJ3HsNQd0botplZ5UriMbe3vmUfiBL3QA== X-Received: by 2002:a05:6e02:2185:b0:2de:9a5a:4993 with SMTP id j5-20020a056e02218500b002de9a5a4993mr4535302ila.182.1660456462573; Sat, 13 Aug 2022 22:54:22 -0700 (PDT) Received: from sophie (static-198-54-128-70.cust.tzulo.com. [198.54.128.70]) by smtp.gmail.com with ESMTPSA id b6-20020a05660214c600b0067b7a057ee8sm3144563iow.25.2022.08.13.22.54.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Aug 2022 22:54:22 -0700 (PDT) From: Rebecca Mckeever To: Mike Rapoport , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: David Hildenbrand , Rebecca Mckeever Subject: [PATCH 8/8] memblock tests: add tests for memblock_trim_memory Date: Sun, 14 Aug 2022 00:54:00 -0500 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660456463; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=57rgW1sYbO78tij7BVX5WYr55Vq5FbqyewxGMYBSZtk=; b=gmcC/MrO3ZdvPJVKUX5YiMU00Y/osgtjvMfeiXRduRM+HinJVxhaa30dEHt3ie7DTkNSkt zIMe+V6lsoqk2we3aLuMEtxHgRwZ2E+NGoVJ5JyMbS9YYSVuVuRMbwe+3mWvyHS7ucKWJz SzZK83bPj9aDXcmMeM94xtSOB7NBXho= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="B/fgMudF"; spf=pass (imf04.hostedemail.com: domain of remckee0@gmail.com designates 209.85.166.193 as permitted sender) smtp.mailfrom=remckee0@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660456463; a=rsa-sha256; cv=none; b=LR2i6mQX0i/Qx8slz9n/UZENxMqqT+F6rOtn0tYxR4s2KftiGlgxcbWyzr8Shc4an0Ek21 2QyzhnYZ9zOTooL7DetAy1XABcIjqM/n2Wd2edLfnLBoIgHFqzPveU3xYkXnzFaFRmhtEE YepxL7xWgPNojwVEvTDDWHTfK+t4nyQ= X-Stat-Signature: ofiyufnw6mdex4xydf31wu7u9eadeskk X-Rspamd-Queue-Id: 4370440044 Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="B/fgMudF"; spf=pass (imf04.hostedemail.com: domain of remckee0@gmail.com designates 209.85.166.193 as permitted sender) smtp.mailfrom=remckee0@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1660456463-421936 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add tests for memblock_trim_memory() for the following scenarios: - all regions aligned - one region unalign that is smaller than the alignment - one region unaligned at the base - one region unaligned at the end Signed-off-by: Rebecca Mckeever --- tools/testing/memblock/tests/basic_api.c | 223 +++++++++++++++++++++++ 1 file changed, 223 insertions(+) diff --git a/tools/testing/memblock/tests/basic_api.c b/tools/testing/memblock/tests/basic_api.c index d7f008e7a12a..c8bb44f20846 100644 --- a/tools/testing/memblock/tests/basic_api.c +++ b/tools/testing/memblock/tests/basic_api.c @@ -8,6 +8,7 @@ #define FUNC_RESERVE "memblock_reserve" #define FUNC_REMOVE "memblock_remove" #define FUNC_FREE "memblock_free" +#define FUNC_TRIM "memblock_trim_memory" static int memblock_initialization_check(void) { @@ -1723,6 +1724,227 @@ static int memblock_bottom_up_checks(void) return 0; } +/* + * A test that tries to trim memory when both ends of the memory region are + * aligned. Expect that the memory will not be trimmed. Expect the counter to + * not be updated. + */ +static int memblock_trim_memory_aligned_check(void) +{ + struct memblock_region *rgn; + phys_addr_t alignment = SMP_CACHE_BYTES; + + rgn = &memblock.memory.regions[0]; + + struct region r = { + .base = alignment, + .size = alignment * 4 + }; + + PREFIX_PUSH(); + + reset_memblock_regions(); + memblock_add(r.base, r.size); + memblock_trim_memory(alignment); + + ASSERT_EQ(rgn->base, r.base); + ASSERT_EQ(rgn->size, r.size); + + ASSERT_EQ(memblock.memory.cnt, 1); + + test_pass_pop(); + + return 0; +} + +/* + * A test that tries to trim memory when there are two available regions, r1 and + * r2. Region r1 is aligned on both ends and region r2 is unaligned on one end + * and smaller than the alignment: + * + * alignment + * |--------| + * | +-----------------+ +------+ | + * | | r1 | | r2 | | + * +--------+-----------------+--------+------+---+ + * ^ ^ ^ ^ ^ + * |________|________|________| | + * | Unaligned address + * Aligned addresses + * + * Expect that r1 will not be trimmed and r2 will be removed. Expect the + * counter to be updated. + */ +static int memblock_trim_memory_too_small_check(void) +{ + struct memblock_region *rgn; + phys_addr_t alignment = SMP_CACHE_BYTES; + + rgn = &memblock.memory.regions[0]; + + struct region r1 = { + .base = alignment, + .size = alignment * 2 + }; + struct region r2 = { + .base = alignment * 4, + .size = alignment - SZ_2 + }; + + PREFIX_PUSH(); + + reset_memblock_regions(); + memblock_add(r1.base, r1.size); + memblock_add(r2.base, r2.size); + memblock_trim_memory(alignment); + + ASSERT_EQ(rgn->base, r1.base); + ASSERT_EQ(rgn->size, r1.size); + + ASSERT_EQ(memblock.memory.cnt, 1); + + test_pass_pop(); + + return 0; +} + +/* + * A test that tries to trim memory when there are two available regions, r1 and + * r2. Region r1 is aligned on both ends and region r2 is unaligned at the base + * and aligned at the end: + * + * Unaligned address + * | + * v + * | +-----------------+ +---------------+ | + * | | r1 | | r2 | | + * +--------+-----------------+----------+---------------+---+ + * ^ ^ ^ ^ ^ ^ + * |________|________|________|________|________| + * | + * Aligned addresses + * + * Expect that r1 will not be trimmed and r2 will be trimmed at the base. + * Expect the counter to not be updated. + */ +static int memblock_trim_memory_unaligned_base_check(void) +{ + struct memblock_region *rgn1, *rgn2; + phys_addr_t alignment = SMP_CACHE_BYTES; + phys_addr_t offset = SZ_2; + phys_addr_t r2_base, r2_size; + + rgn1 = &memblock.memory.regions[0]; + rgn2 = &memblock.memory.regions[1]; + + struct region r1 = { + .base = alignment, + .size = alignment * 2 + }; + struct region r2 = { + .base = alignment * 4 + offset, + .size = alignment * 2 - offset + }; + + PREFIX_PUSH(); + + r2_base = r2.base + (alignment - offset); + r2_size = r2.size - (alignment - offset); + + reset_memblock_regions(); + memblock_add(r1.base, r1.size); + memblock_add(r2.base, r2.size); + memblock_trim_memory(alignment); + + ASSERT_EQ(rgn1->base, r1.base); + ASSERT_EQ(rgn1->size, r1.size); + + ASSERT_EQ(rgn2->base, r2_base); + ASSERT_EQ(rgn2->size, r2_size); + + ASSERT_EQ(memblock.memory.cnt, 2); + + test_pass_pop(); + + return 0; +} + +/* + * A test that tries to trim memory when there are two available regions, r1 and + * r2. Region r1 is aligned on both ends and region r2 is aligned at the base + * and unaligned at the end: + * + * Unaligned address + * | + * v + * | +-----------------+ +---------------+ | + * | | r1 | | r2 | | + * +--------+-----------------+--------+---------------+---+ + * ^ ^ ^ ^ ^ ^ + * |________|________|________|________|________| + * | + * Aligned addresses + * + * Expect that r1 will not be trimmed and r2 will be trimmed at the base. + * Expect the counter to not be updated. + */ +static int memblock_trim_memory_unaligned_end_check(void) +{ + struct memblock_region *rgn1, *rgn2; + phys_addr_t alignment = SMP_CACHE_BYTES; + phys_addr_t offset = SZ_2; + phys_addr_t r2_size; + + rgn1 = &memblock.memory.regions[0]; + rgn2 = &memblock.memory.regions[1]; + + struct region r1 = { + .base = alignment, + .size = alignment * 2 + }; + struct region r2 = { + .base = alignment * 4, + .size = alignment * 2 - offset + }; + + PREFIX_PUSH(); + + r2_size = r2.size - (alignment - offset); + + reset_memblock_regions(); + memblock_add(r1.base, r1.size); + memblock_add(r2.base, r2.size); + memblock_trim_memory(alignment); + + ASSERT_EQ(rgn1->base, r1.base); + ASSERT_EQ(rgn1->size, r1.size); + + ASSERT_EQ(rgn2->base, r2.base); + ASSERT_EQ(rgn2->size, r2_size); + + ASSERT_EQ(memblock.memory.cnt, 2); + + test_pass_pop(); + + return 0; +} + +static int memblock_trim_memory_checks(void) +{ + prefix_reset(); + prefix_push(FUNC_TRIM); + test_print("Running %s tests...\n", FUNC_TRIM); + + memblock_trim_memory_aligned_check(); + memblock_trim_memory_too_small_check(); + memblock_trim_memory_unaligned_base_check(); + memblock_trim_memory_unaligned_end_check(); + + prefix_pop(); + + return 0; +} + int memblock_basic_checks(void) { memblock_initialization_check(); @@ -1731,6 +1953,7 @@ int memblock_basic_checks(void) memblock_remove_checks(); memblock_free_checks(); memblock_bottom_up_checks(); + memblock_trim_memory_checks(); return 0; }