From mboxrd@z Thu Jan 1 00:00:00 1970 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 57692C433FE for ; Mon, 28 Feb 2022 14:47:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AE7BC8D0009; Mon, 28 Feb 2022 09:47:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A97348D0001; Mon, 28 Feb 2022 09:47:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 936B38D0009; Mon, 28 Feb 2022 09:47:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0112.hostedemail.com [216.40.44.112]) by kanga.kvack.org (Postfix) with ESMTP id 859058D0001 for ; Mon, 28 Feb 2022 09:47:27 -0500 (EST) Received: from smtpin31.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 4231C8249980 for ; Mon, 28 Feb 2022 14:47:27 +0000 (UTC) X-FDA: 79192466934.31.CE8B236 Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) by imf25.hostedemail.com (Postfix) with ESMTP id 55FF8A000D for ; Mon, 28 Feb 2022 14:47:27 +0000 (UTC) Received: by mail-lj1-f169.google.com with SMTP id s25so17731187lji.5 for ; Mon, 28 Feb 2022 06:47:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dODaVYwjD7geqFx/VYp9W8G2RuqYSXTNScA1eN7itG0=; b=LZaAe03qJIgVLKW0ROcUF5NtBYIHelCM2LrCq5VA5D5lRnAEbYXzNSRTOTJo2qQT4s I/JDuliC/5lLGARf5qXerJN94Fzlhycn7DfMGj02lslArMjroM8pgQqhwPF+7fxPMyyX SxjeJXuWbWneu83tRzDRi6vvT0Ao6MQ0Bu0H8jviuPVMswymwSAV/56jUNJMRMskVNi8 Vd5R2NgXMKDo8W1b2RzoTpcmzN8j7CWzWXIh9GcDRZqJ8EvXRwchvWYVnYsZMZ7xH5Kt cq+9OgOWhVBbttHtUGT5clurr92m4ch4lNgaGqN9oQWZ+149WJdDIWha7kQ63s17EvBB MhxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dODaVYwjD7geqFx/VYp9W8G2RuqYSXTNScA1eN7itG0=; b=6p1g46dsunGu2nRAxErU+JJknTyeCzFqFESzyJynQMDkwAVo/ZUhyyoIR9XyPLPQWl vKjh2n6Bh6oHIdhOH0l/vZ32Hwac/tXjXRv1lYMZsK+wWccHDFWiWcOvcvHA27J3P+8G Llrou2gjU+8bIteCd/v4PtPyCfrwshfJmwqukvIgCF1lh2b31C7gP1BWY/aIV3yFuLSo S7hk4CIO/ELxN0WnttRmvoB7b8gOh0WhFqOLrIIS7w/+9y8VY9EE6aFvVDIbkW+xM7Qo PnrjFDHo9WA26OxIIJUOSJX2pOLErTy0LfWSO2+j8oFUgrqFNNuXNLUcFCWfiwtT4QEM SdhQ== X-Gm-Message-State: AOAM530YsetKIIOkWJhLjz/MRENNlDj5tr7c0MFam2aqAFiPDONi8+sr B5A9dcPjDtbhcJpkiKGNkIo0nWM+FlM= X-Google-Smtp-Source: ABdhPJzvP0DsMR+uBiVybsUZ/9RqLjAPnDO5Uwmg2UTv5N8cZp0XtxXxyIrbL5MaQ4F5xC+2mT0uDg== X-Received: by 2002:a2e:954:0:b0:241:73c:cb5e with SMTP id 81-20020a2e0954000000b00241073ccb5emr14833424ljj.86.1646059645459; Mon, 28 Feb 2022 06:47:25 -0800 (PST) Received: from elysium.toya.net.pl (staticline-31-183-165-244.toya.net.pl. [31.183.165.244]) by smtp.gmail.com with ESMTPSA id r14-20020ac252ae000000b00443f3cbc03asm993996lfm.6.2022.02.28.06.47.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 06:47:25 -0800 (PST) From: Karolina Drobnik To: linux-mm@kvack.org Cc: rppt@kernel.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, Karolina Drobnik Subject: [PATCH 6/9] memblock tests: Add memblock_alloc_from tests for bottom up Date: Mon, 28 Feb 2022 15:46:48 +0100 Message-Id: <506cf5293c8a21c012b7ea87b14af07754d3e656.1646055639.git.karolinadrobnik@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 55FF8A000D X-Stat-Signature: 3fk1uoghn6jnpfnpou1aeghn3xg6h1g4 X-Rspam-User: Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=LZaAe03q; spf=pass (imf25.hostedemail.com: domain of karolinadrobnik@gmail.com designates 209.85.208.169 as permitted sender) smtp.mailfrom=karolinadrobnik@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam07 X-HE-Tag: 1646059647-699727 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000075, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add checks for memblock_alloc_from for bottom up allocation direction. The tested scenarios are: - Not enough space to allocate memory at the minimal address - Minimal address parameter is smaller than the start address of the available memory - Minimal address parameter is too close to the end of the available memory Add test case wrappers to test both directions in the same context. Signed-off-by: Karolina Drobnik --- .../memblock/tests/alloc_helpers_api.c | 175 +++++++++++++++++- 1 file changed, 171 insertions(+), 4 deletions(-) diff --git a/tools/testing/memblock/tests/alloc_helpers_api.c b/tools/tes= ting/memblock/tests/alloc_helpers_api.c index dc5152adcc5b..963a966db461 100644 --- a/tools/testing/memblock/tests/alloc_helpers_api.c +++ b/tools/testing/memblock/tests/alloc_helpers_api.c @@ -209,16 +209,183 @@ static int alloc_from_top_down_min_addr_cap_check(= void) return 0; } -int memblock_alloc_helpers_checks(void) +/* + * A test that tries to allocate a memory region above an address that i= s too + * close to the end of the memory: + * + * + + * |-----------+ + | + * | rgn | | | + * +-----------+--------------+-----+ + * ^ ^ + * | | + * Aligned address min_addr + * boundary + * + * Expect to prioritize granting memory over satisfying the minimal addr= ess + * requirement. Allocation happens at beginning of the available memory. + */ +static int alloc_from_bottom_up_high_addr_check(void) { - reset_memblock_attributes(); - dummy_physical_memory_init(); + struct memblock_region *rgn =3D &memblock.reserved.regions[0]; + void *allocated_ptr =3D NULL; + + phys_addr_t size =3D SZ_32; + phys_addr_t min_addr; + + setup_memblock(); + + /* The address is too close to the end of the memory */ + min_addr =3D memblock_end_of_DRAM() - SZ_8; + + allocated_ptr =3D memblock_alloc_from(size, SMP_CACHE_BYTES, min_addr); + + assert(allocated_ptr); + assert(rgn->size =3D=3D size); + assert(rgn->base =3D=3D memblock_start_of_DRAM()); + + assert(memblock.reserved.cnt =3D=3D 1); + assert(memblock.reserved.total_size =3D=3D size); + + return 0; +} +/* + * A test that tries to allocate a memory region when there is no space + * available above the minimal address above a certain address: + * + * + + * |-----------+ +-------------------| + * | rgn | | | + * +-----------+----+-------------------+ + * ^ + * | + * min_addr + * + * Expect to prioritize granting memory over satisfying the minimal addr= ess + * requirement and to allocate at the beginning of the available memory. + */ +static int alloc_from_bottom_up_no_space_above_check(void) +{ + struct memblock_region *rgn =3D &memblock.reserved.regions[0]; + void *allocated_ptr =3D NULL; + + phys_addr_t r1_size =3D SZ_64; + phys_addr_t min_addr; + phys_addr_t r2_size; + + setup_memblock(); + + min_addr =3D memblock_start_of_DRAM() + SZ_128; + r2_size =3D memblock_end_of_DRAM() - min_addr; + + /* No space above this address */ + memblock_reserve(min_addr - SMP_CACHE_BYTES, r2_size); + + allocated_ptr =3D memblock_alloc_from(r1_size, SMP_CACHE_BYTES, min_add= r); + + assert(allocated_ptr); + assert(rgn->base =3D=3D memblock_start_of_DRAM()); + assert(rgn->size =3D=3D r1_size); + + assert(memblock.reserved.cnt =3D=3D 2); + assert(memblock.reserved.total_size =3D=3D r1_size + r2_size); + + return 0; +} + +/* + * A test that tries to allocate a memory region with a minimal address = below + * the start address of the available memory. Expect to allocate a regio= n + * at the beginning of the available memory. + */ +static int alloc_from_bottom_up_min_addr_cap_check(void) +{ + struct memblock_region *rgn =3D &memblock.reserved.regions[0]; + void *allocated_ptr =3D NULL; + + phys_addr_t r1_size =3D SZ_64; + phys_addr_t min_addr; + phys_addr_t start_addr; + + setup_memblock(); + + start_addr =3D (phys_addr_t)memblock_start_of_DRAM(); + min_addr =3D start_addr - SMP_CACHE_BYTES * 3; + + allocated_ptr =3D memblock_alloc_from(r1_size, SMP_CACHE_BYTES, min_add= r); + + assert(allocated_ptr); + assert(rgn->base =3D=3D start_addr); + assert(rgn->size =3D=3D r1_size); + + assert(memblock.reserved.cnt =3D=3D 1); + assert(memblock.reserved.total_size =3D=3D r1_size); + + return 0; +} + +/* Test case wrappers */ +static int alloc_from_simple_check(void) +{ + memblock_set_bottom_up(false); + alloc_from_simple_generic_check(); + memblock_set_bottom_up(true); alloc_from_simple_generic_check(); + + return 0; +} + +static int alloc_from_misaligned_check(void) +{ + memblock_set_bottom_up(false); alloc_from_misaligned_generic_check(); + memblock_set_bottom_up(true); + alloc_from_misaligned_generic_check(); + + return 0; +} + +static int alloc_from_high_addr_check(void) +{ + memblock_set_bottom_up(false); alloc_from_top_down_high_addr_check(); - alloc_from_top_down_min_addr_cap_check(); + memblock_set_bottom_up(true); + alloc_from_bottom_up_high_addr_check(); + + return 0; +} + +static int alloc_from_no_space_above_check(void) +{ + memblock_set_bottom_up(false); alloc_from_top_down_no_space_above_check(); + memblock_set_bottom_up(true); + alloc_from_bottom_up_no_space_above_check(); + + return 0; +} + +static int alloc_from_min_addr_cap_check(void) +{ + memblock_set_bottom_up(false); + alloc_from_top_down_min_addr_cap_check(); + memblock_set_bottom_up(true); + alloc_from_bottom_up_min_addr_cap_check(); + + return 0; +} + +int memblock_alloc_helpers_checks(void) +{ + reset_memblock_attributes(); + dummy_physical_memory_init(); + + alloc_from_simple_check(); + alloc_from_misaligned_check(); + alloc_from_high_addr_check(); + alloc_from_no_space_above_check(); + alloc_from_min_addr_cap_check(); dummy_physical_memory_cleanup(); -- 2.30.2