From patchwork Thu Sep 5 21:15:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13793001 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 04C02CE7AA3 for ; Thu, 5 Sep 2024 21:16:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8B5706B0089; Thu, 5 Sep 2024 17:16:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8649B6B008C; Thu, 5 Sep 2024 17:16:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 693CE6B0092; Thu, 5 Sep 2024 17:16:23 -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 406A66B0089 for ; Thu, 5 Sep 2024 17:16:23 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id E4895A9225 for ; Thu, 5 Sep 2024 21:16:22 +0000 (UTC) X-FDA: 82531943004.22.DFCE44F Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) by imf01.hostedemail.com (Postfix) with ESMTP id DBE3E40022 for ; Thu, 5 Sep 2024 21:16:20 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=ZpsPPdgk; spf=pass (imf01.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.215.181 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=1725570851; 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=BC+wwN1fePLvWLzJkRJwUgtVdOqgdkSuyAR2hC6nLRw=; b=TlKoqQhF3UBb8VGUqydt6ERKDvdFyVowxNYaAtxlKHRfFe9SA27VkEBHLS46/sfUAvqgOy /CxQv85UtKN1i8gpdpOtTXlbbqYsAptpoCcd2HLs2m0g60Mc/D/qWbNKJlRbNmSGtA0aVu NGngu2HJXTGCB2FzPc/YtrYwk3XTH3Y= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=ZpsPPdgk; spf=pass (imf01.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.215.181 as permitted sender) smtp.mailfrom=charlie@rivosinc.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725570851; a=rsa-sha256; cv=none; b=rjP+OLiVngJeW9FtZL1cDhaVWPFuRMfk+ywxsBZbkAms6K4Q/+uqNUvT5xZQ+758RAripn XyDLK1DxftE4Qq5UDuqv55GEQxBd3Y/hpFmb0OMHMNoiLHABV6IRenFRttK1Ci0jmP8m6G 7p894RZdLMVuhFkB3PA1QXpKNY//p2M= Received: by mail-pg1-f181.google.com with SMTP id 41be03b00d2f7-6c5bcb8e8edso985251a12.2 for ; Thu, 05 Sep 2024 14:16:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1725570979; x=1726175779; 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=BC+wwN1fePLvWLzJkRJwUgtVdOqgdkSuyAR2hC6nLRw=; b=ZpsPPdgkYgBlH6hfTBuGae1E80O9S3VEZ7ZlpbaE+kTHrsV48dulDH4TQhSDpQ+/y4 Jy0YKs4V6JCYTWzykn6zHALE4A4njgy6q9oQ2wIAFT9USHCPCT5BI5uUHykvLPWI7dqR iGOOH0658ueQBc6Jl1ytlftWLHoguIaUoc1kEIHCTl2T9tshKh1KY+w97NCheS7bCs9h heLZ2HIDgoqslGOaAUx5rv3o+pjGNMpfffDThoFw1qfD4zih4gcMXRQBpaqiXErDmFPI AiuTddrUlQFkQNhLTrRKiUzvS8DEQMVP00dnU4F1KYU1IBktN0LGCYVln2DMGZ8ksHJl 6a7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725570979; x=1726175779; 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=BC+wwN1fePLvWLzJkRJwUgtVdOqgdkSuyAR2hC6nLRw=; b=Smc5c1N7F0q+XTZh4h8X9FkGHNlGYN+U50Q30XEmuGes+anEuOEmdGr4iuWJhiDTI8 BXge6nqnJEb41ovffgHwxdWp+to7suX4TEPEa14yiTgmAHvBnrBkW3CoUDtZkuTxJPaG WYKXDZvz1QMWo3kwpV2nVL8N2NRDOxBCDhqQlAe4ouhdOs9XTnq4oYML/jLv1mrEgU0w oIgwatboePgPJRQfMMxecPSi1NuWCr8w/K7KXI0zCiWj3DcjX3TTzf5uibLlcZ1raj/7 Nljf3D1kORfa45hcF1E2n7F5x1I9nEY4XVggOxaBErrrwqaBF2hA5CvzIWVEpFftp1Nc 3VQA== X-Forwarded-Encrypted: i=1; AJvYcCVqxNCiLqaKeJ1m8lTMPsyjyTm40DeqS6eahIoh9UfqTdz5szWdXmFDS+pTony+pSkFXrWkovqZAw==@kvack.org X-Gm-Message-State: AOJu0Ywl2PKH/NeC88cSLD4aleslnOHkabdqP5ajijvUyQLSTIRCRhX6 YrfptZF9c3J1ghwI7B1gXhm4Q6ZXsIKFGfHV58F/Mgi6Evfxs+i0rWunbxftzg0= X-Google-Smtp-Source: AGHT+IEZNTxfv2Eh4MhBvC/nCmC/+9uGBr1mJ2SunSW5zA4oMdQE9dzvz6pYsZBAUp5dcakacvTYeg== X-Received: by 2002:a05:6a20:6f08:b0:1c6:a680:ef3d with SMTP id adf61e73a8af0-1cf1d13329emr317665637.28.1725570979059; Thu, 05 Sep 2024 14:16:19 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7d4fbda7abesm3775746a12.61.2024.09.05.14.16.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2024 14:16:18 -0700 (PDT) From: Charlie Jenkins Date: Thu, 05 Sep 2024 14:15:52 -0700 Subject: [PATCH RFC v3 2/2] selftests/mm: Create ADDR_LIMIT_47BIT test MIME-Version: 1.0 Message-Id: <20240905-patches-below_hint_mmap-v3-2-3cd5564efbbb@rivosinc.com> References: <20240905-patches-below_hint_mmap-v3-0-3cd5564efbbb@rivosinc.com> In-Reply-To: <20240905-patches-below_hint_mmap-v3-0-3cd5564efbbb@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 , Christoph Hellwig , Michal Hocko , "Kirill A. Shutemov" , Chris Torek 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, linux-abi-devel@lists.sourceforge.net, Charlie Jenkins X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2582; i=charlie@rivosinc.com; h=from:subject:message-id; bh=v+6JyaTNEum7sQVRfCLlZa2h0GjRhYNybjctqPTjXjI=; b=owGbwMvMwCHWx5hUnlvL8Y3xtFoSQ9ot+RkaGxaJ/61aKCWQFuW4/RLXZ/ZytuJlXCePW/lm/ BEMfPmgo5SFQYyDQVZMkYXnWgNz6x39sqOiZRNg5rAygQxh4OIUgIl8VmJkmJ40y3j9/d1mFyvf My3sVpqs+9/6YNER2ftWy07b31r7azfDfzfJmfzFLLNYSxYW7GExLQoUvbVs9j2GHob0FXfdby4 9wwcA X-Developer-Key: i=charlie@rivosinc.com; a=openpgp; fpr=7D834FF11B1D8387E61C776FFB10D1F27D6B1354 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: DBE3E40022 X-Stat-Signature: r63w3p5ghyaam9786hb5gd3c5eo5zkch X-Rspam-User: X-HE-Tag: 1725570980-123862 X-HE-Meta: U2FsdGVkX19u9mbDIFkQMJaamBe3xAWpBHt5jabPNjDDKWbW3L8J/WKc+ZVYils7ld7LynADOzTLUTTBPHA/5MLLBZYTBNAcMMvav8q233waTijrAB9mItK32DNZKBNiXezC04ruUt6UPaeCpXkfkgYMEIDGTnvT0aFZ+kxkMz8gW9mSIhAx0hlIRAoQBqh0APGNKHhNrfAaa920DRPmA0igCXQHy51I1qHVqzD7xFI3+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Spu+R6Ov/w0X9X+qmxZe1OehVeDLt5uiq8Kw05KO58DOR4D4s84xl7ffXcwD1Z8BWJ/vGoRvoHvk1XEIXB3kvq1pVpByw9M4lt0pD6TWfqBuSMsWT2t4xsjvUSt6KwBv1+uNV+pVH9K+Ov8mWNG9T+D+jol5SS9isZsAjNQ9A6yr 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: List-Subscribe: List-Unsubscribe: Add a selftest for the ADDR_LIMIT_47BIT personality flag that mmaps until it runs out of space and ensures no addresses are allocated above 47 bits. Signed-off-by: Charlie Jenkins --- tools/testing/selftests/mm/.gitignore | 1 + tools/testing/selftests/mm/Makefile | 1 + tools/testing/selftests/mm/map_47bit_personality.c | 34 ++++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/tools/testing/selftests/mm/.gitignore b/tools/testing/selftests/mm/.gitignore index da030b43e43b..918ef05e180d 100644 --- a/tools/testing/selftests/mm/.gitignore +++ b/tools/testing/selftests/mm/.gitignore @@ -32,6 +32,7 @@ mlock-random-test virtual_address_range gup_test va_128TBswitch +map_47bit_personality map_fixed_noreplace write_to_hugetlbfs hmm-tests diff --git a/tools/testing/selftests/mm/Makefile b/tools/testing/selftests/mm/Makefile index cfad627e8d94..2e95fd545409 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_47bit_personality TEST_GEN_FILES += map_fixed_noreplace TEST_GEN_FILES += map_hugetlb TEST_GEN_FILES += map_populate diff --git a/tools/testing/selftests/mm/map_47bit_personality.c b/tools/testing/selftests/mm/map_47bit_personality.c new file mode 100644 index 000000000000..453412990c21 --- /dev/null +++ b/tools/testing/selftests/mm/map_47bit_personality.c @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Test the ADDR_LIMIT_47BIT personality flag. + */ +#include +#include +#include +#include "../kselftest.h" + +#define LENGTH (100000000) + +#define ADDR_LIMIT_47BIT 0x10000000 +#define BIT47 1UL << 47 + +/* + * Map memory with ADDR_LIMIT_47BIT until no memory left. Ensure that all returned + * addresses are below 47 bits. + */ +int main(int argc, char **argv) +{ + void *addr; + + syscall(__NR_personality, ADDR_LIMIT_47BIT); + + do { + addr = mmap(0, LENGTH, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + } while (addr != MAP_FAILED && (unsigned long)addr < BIT47); + + if (errno == ENOMEM) + ksft_test_result_pass("ADDR_LIMIT_47BIT works\n"); + else + ksft_test_result_fail("mmap returned address above 47 bits with ADDR_LIMIT_47BIT with addr: %p and err: %s\n", + addr, strerror(errno)); +}