From patchwork Thu Aug 29 07:16:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13782679 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 6C6F5C7EE30 for ; Thu, 29 Aug 2024 07:16:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ECD656B00B3; Thu, 29 Aug 2024 03:16:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E57716B00C2; Thu, 29 Aug 2024 03:16:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CCFE96B00C4; Thu, 29 Aug 2024 03:16:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id A555C6B00B3 for ; Thu, 29 Aug 2024 03:16:30 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 5D62B1A03CC for ; Thu, 29 Aug 2024 07:16:30 +0000 (UTC) X-FDA: 82504424940.10.C7568E3 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by imf30.hostedemail.com (Postfix) with ESMTP id 4AAB380023 for ; Thu, 29 Aug 2024 07:16:28 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=1ltJ6ik3; spf=pass (imf30.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.210.178 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=1724915744; 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=9klKwS2bfsiGNUk5X0TeI2il7xQjjU59nEcVHrUHGMg=; b=sHU6aqUl0lsl/PGdJLSqsKbhuY7HKXh5MIVYuBUJbGHoY6RzkIihxysGQllqANrr1qkdL3 1LOONzkviRrcOTuvJBerUzcT7gXIIQljDBkUMw++fEKOiu2Ui4oGy5ytH9EW/BPargLwAG bNme5jpmnGnkGHTM8cGeLsHS9KlmZ80= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=1ltJ6ik3; spf=pass (imf30.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.210.178 as permitted sender) smtp.mailfrom=charlie@rivosinc.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724915744; a=rsa-sha256; cv=none; b=XJkmd2i7QOLQ2fPQGkIOqlWK+S2ZzTZED6dpovT02SCSV01IhYupG/zFDdSGu01ippdUMG 9Y9fzQh385WX3eEWHNm0v5yELbsTzQylDPbkc0cOc5OhoOWiQtZ7EOV7EFPbSr3HQOI3vg S/UNlGHINaqct1ElbaEM5+dmaSXYWGs= Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-7141b04e7a3so300075b3a.3 for ; Thu, 29 Aug 2024 00:16:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724915787; x=1725520587; 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=9klKwS2bfsiGNUk5X0TeI2il7xQjjU59nEcVHrUHGMg=; b=1ltJ6ik3DrK3/jMx3pfYCaIndkTsu3bjMByYRxRuVoDkVWnYJeBCn4n0A2bojIGfNs XrnjNUo3YnX20Qp17mglxflcPLfCNg4eXqxN3ZT6yiw/3CtgGSsSO+bgsHKY0h8duacp iNdvvgcGyRntTKmcfhWYtpOlVIIosnqmPPGOXUty3Zpr/a3ZOIJifcgmNPE5f+HFhBZl 0D/rtS6W0RqegCka91mzWfOwEuuTopQOlkYuWCiA/cxdE3ub60SBZANY9xhtZjjZgKBK Df7Da0eD1USB8xZsE7LR8mUymor39+1J/5RZAcFUMaonE8GhSSW6cZrEHh5ODoHs0lKP C5OQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724915787; x=1725520587; 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=9klKwS2bfsiGNUk5X0TeI2il7xQjjU59nEcVHrUHGMg=; b=CysywXeiPN2vxRQGEcbu342ejW0juNvEN1qsNKonQSyT4/maxWwLHLdYYK/85ld/8b o2rTh/O2ibMpJx7vdYPpZTMJEWUVbP7RuAl7aIv2gYhHfempwPM7GjFy+Uw9oYvC6z5s k4Y2dmb4UwDehKsBMm6N4SYwEOqftNqPTHu3i1mPNFojqSxXdNpwhMu6tzt9O7FSqxC8 lIXU1ls/htSbb3H6LhgLstNiGZNbi0SpMjgiel2KSLEC9dNb4+s7TV9Y2dq+U6Qj+h+m d5bcE6GhS2sgjM1+sQ3FwJWmIunH4aunjIPPysf5Iz2ADQ8bqGsehdFMETaBZ1QMObj+ cTTQ== X-Forwarded-Encrypted: i=1; AJvYcCUyY2EsdHapXn0NqQjRn+2d/zAUZKFxXIVfCinvkk2sE0qrBIWXfubyvuZln4D3I4dvrZzOqf0iYA==@kvack.org X-Gm-Message-State: AOJu0YzAjrCkC2w9adXTVWVgXAz6ctOisLVTQXcQoPHN6F7yKCR0DZL3 g1SBhb1uxJoGvR9kaMr7jrXmzxb9aF6Y1+Rj+FIZNHsgTW3fNpW24wYhTy//ozg= X-Google-Smtp-Source: AGHT+IF3t2cjexZNLvhhEG5lVGM8VXbW+pDj1JAzDu87zeFwskGcSX3PJG32Vb5o0zHIzYY5Gmbt2A== X-Received: by 2002:a05:6a20:e196:b0:1be:c4bb:6f31 with SMTP id adf61e73a8af0-1cce1011dd6mr2308343637.18.1724915786799; Thu, 29 Aug 2024 00:16:26 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7d22e9bef08sm581976a12.58.2024.08.29.00.16.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2024 00:16:26 -0700 (PDT) From: Charlie Jenkins Date: Thu, 29 Aug 2024 00:16:01 -0700 Subject: [PATCH RFC v2 4/4] selftests/mm: Create MAP_BELOW_HINT test MIME-Version: 1.0 Message-Id: <20240829-patches-below_hint_mmap-v2-4-638a28d9eae0@rivosinc.com> References: <20240829-patches-below_hint_mmap-v2-0-638a28d9eae0@rivosinc.com> In-Reply-To: <20240829-patches-below_hint_mmap-v2-0-638a28d9eae0@rivosinc.com> To: Arnd Bergmann , Richard Henderson , Ivan Kokshaysky , Matt Turner , Vineet Gupta , Russell King , Guo Ren , Huacai Chen , WANG Xuerui , Thomas Bogendoerfer , "James E.J. Bottomley" , Helge Deller , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , 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 , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Andy Lutomirski , Peter Zijlstra , Muchun Song , Andrew Morton , "Liam R. Howlett" , Vlastimil Babka , Lorenzo Stoakes , Shuah Khan Cc: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-alpha@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, Charlie Jenkins X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1995; i=charlie@rivosinc.com; h=from:subject:message-id; bh=s/V5Z34t4dT0xkb/r9QmO4zmTWyR+OmvwZt8Wf5I9yo=; b=owGbwMvMwCHWx5hUnlvL8Y3xtFoSQ9oFBcsP6+L/Tm5SuNTuoL5vd1CHFePmle9+1/Le0d5Yp 3hVY8XNjlIWBjEOBlkxRRaeaw3MrXf0y46Klk2AmcPKBDKEgYtTACYikcjwz6bDSmrzHWPjp6+e zUhZGF3tGZgzRbFMebrXzej5O9YXpDH8j7Z7ceLNKc+79Xs9s7LbGbZefbF4gvgksf23zjP3/b/ +jhkA X-Developer-Key: i=charlie@rivosinc.com; a=openpgp; fpr=7D834FF11B1D8387E61C776FFB10D1F27D6B1354 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 4AAB380023 X-Stat-Signature: q651a3c6f7ksy3crdek197c35ga8wgks X-HE-Tag: 1724915788-557034 X-HE-Meta: U2FsdGVkX18RRfZJGARXdT6LJU6DIf5y594ADBExb95ewi7oopvkkEUC6++i5ZqvhWgKI2lLoTJSODHQXlvS9ewTOhADztQW6vtsvVIL7QYsskNTyBWO068FHYZzY9FqAnt4yGYPkhnHg6v0IZfTOQOzfARCTWYdL4VRM87poGumSYRH87/+tqAWUywaMUROrNCH2AyqfQOr+QQ1VHtJRKRUnW4U/byAEXC3UBSzi7Ld2jaavTg5D1Io8tmXc+a2BtpYt3FJRqxGgayXWH0N0yuqEc9lUtsE0T3fe/dysGRJS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BDuYlzaVvfW/TROIZMIM78QwOfOZHnF9gNh3gID1Ap4Xd5mqFfdQ/KQrA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000056, 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 | 32 +++++++++++++++++++++++++++++ 2 files changed, 33 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..55d6cbf90645 --- /dev/null +++ b/tools/testing/selftests/mm/map_below_hint.c @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Test the MAP_BELOW_HINT mmap flag. + */ +#include +#include +#include "../kselftest.h" + +#define ADDR (1 << 20) +#define LENGTH (ADDR / 10000) + +#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, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS | MAP_BELOW_HINT, -1, 0); + } while (addr != MAP_FAILED && (unsigned long)addr <= ADDR); + + if (errno == ENOMEM) + ksft_test_result_pass("MAP_BELOW_HINT works\n"); + else + ksft_test_result_fail("mmap returned address above hint with MAP_BELOW_HINT with error: %s\n", + strerror(errno)); +}