From patchwork Wed Aug 28 05:49:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13780634 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 9EA3DC5474A for ; Wed, 28 Aug 2024 05:50:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 32FBA6B00AD; Wed, 28 Aug 2024 01:50:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2B7E36B00AE; Wed, 28 Aug 2024 01:50:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0E57E6B00AF; Wed, 28 Aug 2024 01:50:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id DE29B6B00AD for ; Wed, 28 Aug 2024 01:50:24 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 6CE19A1C6B for ; Wed, 28 Aug 2024 05:50:24 +0000 (UTC) X-FDA: 82500579168.18.75F69D1 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by imf01.hostedemail.com (Postfix) with ESMTP id 66BB940017 for ; Wed, 28 Aug 2024 05:50:22 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=1UttVT29; spf=pass (imf01.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.214.173 as permitted sender) smtp.mailfrom=charlie@rivosinc.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724824106; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=n1bnpMYTna27bSqlaeNn9zMkLMdTuL1lgzvNhNTdiTs=; b=Ms9hgy4CqnH2LOCFvZ6KySr9bkvGB9iLZGlOhXJ6EoV4c5lcEW8V8SdvbkcyeO0GYHOVm4 XOtO36+vHxboy0FgurVdoognhDZcPYyzPjq+4ZTTvj/NiQ+HmgIclmnJixn4Dn3mCwN6iV icbMMQJ/nhkhsUEMCfq5UoTHgN6xq0w= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=1UttVT29; spf=pass (imf01.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.214.173 as permitted sender) smtp.mailfrom=charlie@rivosinc.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724824106; a=rsa-sha256; cv=none; b=yWI0XfbbfsJhYHztiRsJUSrhEx8RmzzGKTxXX3TP8XPmRKo/ZpOMLVTMweJczw2qMfWW+w +DqOtekKUWh+hL4bnGRdFwoZV/xCg74Rur4rx+W6NU03biiryVQkj5dSNF0P1o4fxbR/Bu kXJuhuYVFTxE00AwXnQK7TASNWgdwM4= Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-20202df1c2fso1733085ad.1 for ; Tue, 27 Aug 2024 22:50:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724824221; x=1725429021; darn=kvack.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=n1bnpMYTna27bSqlaeNn9zMkLMdTuL1lgzvNhNTdiTs=; b=1UttVT29GIjos/tIx0WO8/cahE0cVSohVIT+ZqQLKdZ+vm6/XDhgnlFj2BmkJzxs6M Sb3NfMhomPFMDcvbdRVwyMywf7PmxZ+IiW6HtA6qy1uYNsxXWWhsrW7zb3ovy6yZ92vv MkuISmX9TFtV5o7B/kewnyfTIrwV0KaivgogH0xnQ87l4fjZ+Sy0t3Qh+c3i438kUiIh GXwAzFiqEDqrAMoheeut6vpyJxJiQvfKIiBFciDqK5dmTk7b8yLAie5XIlT/QpyMvYUQ PQCesxKnuyFvK/doNSJH1tACj+bzd1Ik+vYEJvLUFMjTmeRuIvQfMViOvd9lDFi2E79H A13g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724824221; x=1725429021; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=n1bnpMYTna27bSqlaeNn9zMkLMdTuL1lgzvNhNTdiTs=; b=hDiU3HvjfwLFdPKsVLiDWmoC4za3BwNmlU/rIZ97LdH7wloWNhbl2A2R5W6v0ueUxz jLjArqXlZVX5Y8uJFMoq1Oll+5TZILEehOh/hQ0SFgvWVArOehdlXu6rUsAQbCZUg7mV SqBSEo627zax5y9REMjfJxbA8UhZuM8w1672U3ZTYW2AKBMmknLchLMwxJtazWAxgqA1 DrIVR+3WaTFM6NHQt8NGPHf18wKlsvsamPVscx7neyUBwhvfZhzueIogux//BhU6LPSc SB+pdRs7zxC/rbxpreyj9a9G7+7YmfMpRI5rL0GQizvQDh71jEMk0lWNq3+iw46doWmD dReg== X-Forwarded-Encrypted: i=1; AJvYcCVQDk4Ni5EiNB0AUw8KmZYegfHzteR2tCJvBfyMuSeTl1w6wk+E+sm9mmT7+27u3bwY9kNrchv6Yw==@kvack.org X-Gm-Message-State: AOJu0YzCG89vHvTI6HjNtF/qqL2HCpqUO1Pakz8qj0TW2C+ssy2v2q9+ yAlfImj8ZRCJi645L3KZX0kbe8hEFnO34spLAN17mdWvVd/xYIAmLKPB1mIMBbQ= X-Google-Smtp-Source: AGHT+IGQeeMMIWRhlzvEY447u73v0bcDYqggMB4NKbY4CT7iyrW8LbpZG4Gsc+7GkkDRX2iCA5iJHw== X-Received: by 2002:a17:903:35d0:b0:1fc:41c0:7a82 with SMTP id d9443c01a7336-204f9912733mr19656305ad.0.1724824220864; Tue, 27 Aug 2024 22:50:20 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203855df0c4sm92092495ad.157.2024.08.27.22.50.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 22:50:20 -0700 (PDT) From: Charlie Jenkins Date: Tue, 27 Aug 2024 22:49:22 -0700 Subject: [PATCH 16/16] selftests/mm: Create MAP_BELOW_HINT test MIME-Version: 1.0 Message-Id: <20240827-patches-below_hint_mmap-v1-16-46ff2eb9022d@rivosinc.com> References: <20240827-patches-below_hint_mmap-v1-0-46ff2eb9022d@rivosinc.com> In-Reply-To: <20240827-patches-below_hint_mmap-v1-0-46ff2eb9022d@rivosinc.com> To: Arnd Bergmann , Paul Walmsley , Palmer Dabbelt , Albert Ou , Catalin Marinas , Will Deacon , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Muchun Song , Andrew Morton , "Liam R. Howlett" , Vlastimil Babka , Lorenzo Stoakes , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Huacai Chen , WANG Xuerui , Russell King , Thomas Bogendoerfer , "James E.J. Bottomley" , Helge Deller , Alexander Gordeev , Gerald Schaefer , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Sven Schnelle , Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , "David S. Miller" , Andreas Larsson , Shuah Khan , Alexandre Ghiti Cc: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, Palmer Dabbelt , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-kselftest@vger.kernel.org, Charlie Jenkins X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1906; i=charlie@rivosinc.com; h=from:subject:message-id; bh=bFLw7L4BlwG3KLICmNgvPIAvf1/5Sm3GeWEQAkx1eJA=; b=owGbwMvMwCHWx5hUnlvL8Y3xtFoSQ9q5XYnPPfbbPo8yeWL66+yxo/N6BS8nd1/7qNQhsOWpf 3tQ+KzTHaUsDGIcDLJiiiw81xqYW+/olx0VLZsAM4eVCWQIAxenAEzkdAYjwwau79apS3QeSJmm 67cdPe+1+9TsAsXmhc0Xrt4+G6VRe5aR4ekEGZPT2yyYhB/f/i4QYfZn696jodpGS1YWP+X48/d dEQMA X-Developer-Key: i=charlie@rivosinc.com; a=openpgp; fpr=7D834FF11B1D8387E61C776FFB10D1F27D6B1354 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 66BB940017 X-Stat-Signature: oxubgedptpbui7i9hiuhiqh3bscu1h7j X-Rspam-User: X-HE-Tag: 1724824222-70790 X-HE-Meta: U2FsdGVkX185AeXsetzoJzXNRCwF2DBXHZcubgEMbcHrtvw2oviom6Ap/ocHPeQxtyyxZ/flHAPvuo0cPLKPvSY6HrymcMZlwkJQ9Qkshi1tP7uYgfIyf22FN70yaIahWVduxeWPolQORgp/Wq7rZUEWra23XvYpQ+q8okyw6GsiYW/N12ovjF/0HqnJqvciw+DurnwHEJ+AOAynT8lB0ZCGm29HauZ3hEDwV6Dh00kXmppQShGcE8OsHsxBUxdsCUk4Ic53OhUtYDoGiJcTjg/Ra8XffGIjitAp2YW5b7eyd1o0Yml05B7u8eJGXF3eft61PbuWDVOGpnaAofiMlTg5tlhABu3z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6Nw2Kquxwbg+L5oFVMvgydmBX8toH5nJLixtYEPH5g== X-Bogosity: Ham, tests=bogofilter, spamicity=0.001915, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add a selftest for MAP_BELOW_HINT that maps until it runs out of space below the hint address. Signed-off-by: Charlie Jenkins --- tools/testing/selftests/mm/Makefile | 1 + tools/testing/selftests/mm/map_below_hint.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/tools/testing/selftests/mm/Makefile b/tools/testing/selftests/mm/Makefile index cfad627e8d94..4e2de85267b5 100644 --- a/tools/testing/selftests/mm/Makefile +++ b/tools/testing/selftests/mm/Makefile @@ -50,6 +50,7 @@ TEST_GEN_FILES += hugepage-shm TEST_GEN_FILES += hugepage-vmemmap TEST_GEN_FILES += khugepaged TEST_GEN_FILES += madv_populate +TEST_GEN_FILES += map_below_hint TEST_GEN_FILES += map_fixed_noreplace TEST_GEN_FILES += map_hugetlb TEST_GEN_FILES += map_populate diff --git a/tools/testing/selftests/mm/map_below_hint.c b/tools/testing/selftests/mm/map_below_hint.c new file mode 100644 index 000000000000..305274c5af49 --- /dev/null +++ b/tools/testing/selftests/mm/map_below_hint.c @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Test the MAP_BELOW_HINT mmap flag. + */ +#include +#include "../kselftest.h" + +#define ADDR 0x1000000UL +#define LENGTH (ADDR / 100) + +#define MAP_BELOW_HINT 0x8000000 /* Not defined in all libc */ + +/* + * Map memory with MAP_BELOW_HINT until no memory left. Ensure that all returned + * addresses are below the hint. + */ +int main(int argc, char **argv) +{ + void *addr; + + do { + addr = mmap((void *)ADDR, LENGTH, MAP_ANONYMOUS, MAP_BELOW_HINT, -1, 0); + } while (addr == MAP_FAILED && (unsigned long)addr <= ADDR); + + if (addr != MAP_FAILED && (unsigned long)addr > ADDR) + ksft_exit_fail_msg("mmap returned address above hint with MAP_BELOW_HINT\n"); + + ksft_test_result_pass("MAP_BELOW_HINT works\n"); +}