From patchwork Thu Sep 5 21:15:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13793000 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 F26ACCE7AA0 for ; Thu, 5 Sep 2024 21:16:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7F0EE6B0085; Thu, 5 Sep 2024 17:16:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 752826B0088; Thu, 5 Sep 2024 17:16:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5A54D6B0089; Thu, 5 Sep 2024 17:16:19 -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 3ABB16B0085 for ; Thu, 5 Sep 2024 17:16:19 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id E0D16A0BAE for ; Thu, 5 Sep 2024 21:16:18 +0000 (UTC) X-FDA: 82531942836.10.16248C2 Received: from mail-ot1-f53.google.com (mail-ot1-f53.google.com [209.85.210.53]) by imf03.hostedemail.com (Postfix) with ESMTP id D6E172001E for ; Thu, 5 Sep 2024 21:16:16 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=uQHebL7z; dmarc=none; spf=pass (imf03.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.210.53 as permitted sender) smtp.mailfrom=charlie@rivosinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725570977; a=rsa-sha256; cv=none; b=EkDJC07JUz5htfVi2bo8Atf4y3Pkn7aQVJ1FAWXL8aZ+FtHjr9gB+0bMAoa9IrDy5cyMWW FNd21skPAhS0bn3UNXAibH2qVftA8Z0TIb9qoP+xb2xXAKSWxRnUpPijVl3dtSuD+UqIfR bJeo1+s4ex/vIEueIFTXe2AM/ZjoTg8= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=uQHebL7z; dmarc=none; spf=pass (imf03.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.210.53 as permitted sender) smtp.mailfrom=charlie@rivosinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725570977; 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=f6U8xmtXOad/vlvI1PiwvXKTTO0WQVhDEUoOSf42FlI=; b=Z8oCjpvmHmTPjHOBAnTve6dlsBAt7gLB1as1jE3dGiBTQY6JVWrg+kXANkZYhk2Gb/di0g w8HtflHwYxw9rjBuylO+TA3jwNBnQfnbd225TgLlz8Daj/dsXIcGERks5vmE7RopGRsi26 Ooj6XZxrMK0CVJCiEGJaxJgtDYScwRs= Received: by mail-ot1-f53.google.com with SMTP id 46e09a7af769-70f6cb5518aso807647a34.1 for ; Thu, 05 Sep 2024 14:16:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1725570976; x=1726175776; 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=f6U8xmtXOad/vlvI1PiwvXKTTO0WQVhDEUoOSf42FlI=; b=uQHebL7zRoDZspOaLlbEMxx7WH0sL8Nh4bgvcq56sk2mlvvszivLqK92FdC5LCboFZ VtsRveuhN7nXaFId+bNQaMo79vXGzCX4iWW0BX4CenUFTyvS/T2nVGIdB/2rn96qVCxH h4RHeR3fxEE3c1U9kXuv7kEyvtYNKDYoizU9h1T6Ry9NfxWi7svd0WWyaMOqFLtR0+RW VTl8OKfYa7G6qD9AX7v4fIrlPe5E/Re4eE8RaMLw3crPlVSN/CSqE5n4zmv3T1rW3nLv 2YhZkYNBAKSHVwvW1dfFNWyIKP+LxHmBxba4rktvn2loXxmRztWHEzU/vZaFyZ46CHbu NmYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725570976; x=1726175776; 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=f6U8xmtXOad/vlvI1PiwvXKTTO0WQVhDEUoOSf42FlI=; b=wolE+wHqCnybIEGzQAXP7oDO+2ZtUoSrEE03fIgooRjJcSZUqCXt/PhcZ7m2OtYe7g 4liJSqHMogicQagdiomMv3sIitwdKL6jnTDtj1EHGiARUmU52024JRnRNzRmzVcWrfwl uiFtsGrByTvVOFc6OauE5zUqM4VBoAFiY53zL6fiZae6i6nFasMzedvb8HWLVaGYYBbj cG6bEUPA2dgd5HbLzIBkxAUD1jwEHEXYdjjZFEeqQDAWNwqnsJ+dfXP/WkSSBwdWWR0y HAgR8+dRBy9JFyZV7PlZ9k8tgI0pfR0mUUYm6W/Aq4vruGdP51I0Def4G0mKhrCwQP/p qsQA== X-Forwarded-Encrypted: i=1; AJvYcCVsSmZde9v8wa6WGDgD3kOuMX7rsH7mBCpkOrRiqSHMDMnsGFtXh10DCDffgcIMACSxmae//U+vvA==@kvack.org X-Gm-Message-State: AOJu0YxCXGWJ7bPhhN0kmVZB4/7+SWfgwq7OzJZZgL1afCE7QQHceFlZ qIhbMe/7lYNGNF3t4JaHN+7jEnBHrFKlB9JbdStX7WumkmbyrRkpWW7XXjSHCTw= X-Google-Smtp-Source: AGHT+IHmMPDz3EnCCj73XeYdf9AhtZ+Ct4KejhsVi5dvIA4rh768bjpktZjdCxUayXeGPhLE3R+w8Q== X-Received: by 2002:a05:6358:4287:b0:1b5:be34:9ad5 with SMTP id e5c5f4694b2df-1b83866e08bmr73366455d.15.1725570975653; Thu, 05 Sep 2024 14:16:15 -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.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2024 14:16:14 -0700 (PDT) From: Charlie Jenkins Date: Thu, 05 Sep 2024 14:15:51 -0700 Subject: [PATCH RFC v3 1/2] mm: Add personality flag to limit address to 47 bits MIME-Version: 1.0 Message-Id: <20240905-patches-below_hint_mmap-v3-1-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=1348; i=charlie@rivosinc.com; h=from:subject:message-id; bh=B2nFsYQPUa93R6MPC6rybC4BjlmBU89eB/xyA3tmSh8=; b=owGbwMvMwCHWx5hUnlvL8Y3xtFoSQ9ot+em/OZQnfrnX8ed38Mt7a5qeTLghH2JpoLVOM/lWE E9Dee3VjlIWBjEOBlkxRRaeaw3MrXf0y46Klk2AmcPKBDKEgYtTACbS9pyRoX//nRvvVlydp7Xm 8/1ihzrxA51eb31tEvRWPpi166jgtMMM/2Pui4Sr/NDPPh503bbDcC77kZANfKUH/kz3LrfLiU2 exg4A X-Developer-Key: i=charlie@rivosinc.com; a=openpgp; fpr=7D834FF11B1D8387E61C776FFB10D1F27D6B1354 X-Rspam-User: X-Stat-Signature: 8byc4x6yffx8pqansniaypkez3a7nody X-Rspamd-Queue-Id: D6E172001E X-Rspamd-Server: rspam02 X-HE-Tag: 1725570976-398181 X-HE-Meta: U2FsdGVkX182N7VGCiHAJZfdHMZIdGuwsRIJ8zF7jNcFRlasntB76Xj2kHQdeRwdOExVWj/bYfk0EeY+24f4EBUoGJdKydRxmBS8DDTD9APjEj8DT3u+avii3t3+ryYuEiaXlszyw8deehgf7pNkUX2U62Oc7x3DBzopYxD2MroabiMP2mbqmqZIJxGPSoXH6i/+e1S8IaNFIm497dVhO+HANV6eBmgknkj5zfPeup05/ni0uGUvBh2lTI+z+xXgYAIwTE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SJey//X6KdzuXqhzw0aqvfIOkh7AFMcHAvcA20dUwOjhbX7IPWDn5KLsRu1NPrNL5VsDAQt/Qmfy6tq3pN30yOcWQ3dI1u/z0RAjGy7bA7SIiM77RCgaBzXhuRmJ1Yw= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000013, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Create a personality flag ADDR_LIMIT_47BIT to support applications that wish to transition from running in environments that support at most 47-bit VAs to environments that support larger VAs. This personality can be set to cause all allocations to be below the 47-bit boundary. Using MAP_FIXED with mmap() will bypass this restriction. Signed-off-by: Charlie Jenkins --- include/uapi/linux/personality.h | 1 + mm/mmap.c | 3 +++ 2 files changed, 4 insertions(+) diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h index 49796b7756af..cd3b8c154d9b 100644 --- a/include/uapi/linux/personality.h +++ b/include/uapi/linux/personality.h @@ -22,6 +22,7 @@ enum { WHOLE_SECONDS = 0x2000000, STICKY_TIMEOUTS = 0x4000000, ADDR_LIMIT_3GB = 0x8000000, + ADDR_LIMIT_47BIT = 0x10000000, }; /* diff --git a/mm/mmap.c b/mm/mmap.c index d0dfc85b209b..a5c7544853e5 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1766,6 +1766,9 @@ unsigned long vm_unmapped_area(struct vm_unmapped_area_info *info) { unsigned long addr; + if (current->personality & ADDR_LIMIT_47BIT) + info->high_limit = MIN(info->high_limit, BIT(47) - 1); + if (info->flags & VM_UNMAPPED_AREA_TOPDOWN) addr = unmapped_area_topdown(info); else 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+MGgtYV2Q9kmaWM7fAC4JXSBghp1oMAocX676xO7JSsdJ6wFpDfbin93jhD+2eKdfP80KrTg+pMxPk5mcBtqz1wyQPLwRPJcijpelJEBZ/4mezyPC0BxIXuy3waqoLF6BMXMRFI/05gnCauwMfM68osTJnbRYCzyeHsVZQXzOhm7NQv2XOWPXMcfFYwq97uTRC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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)); +}