From patchwork Thu Aug 29 07:15:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13782676 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 40CD9C7EE31 for ; Thu, 29 Aug 2024 07:16:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C35F76B00BC; Thu, 29 Aug 2024 03:16:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BBC226B00BE; Thu, 29 Aug 2024 03:16:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A0E8B6B00C0; Thu, 29 Aug 2024 03:16:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 7EF746B00BC for ; Thu, 29 Aug 2024 03:16:20 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 25854409D2 for ; Thu, 29 Aug 2024 07:16:20 +0000 (UTC) X-FDA: 82504424520.26.8F9D738 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) by imf11.hostedemail.com (Postfix) with ESMTP id 1EEAF4002C for ; Thu, 29 Aug 2024 07:16:17 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=cwxzA9EH; spf=pass (imf11.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.215.176 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=1724915689; 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=K+PlWd5TxPsjPig/hDVlAKKLZn98jtqGVu2vnt7YwwU=; b=ARgr1VlkJzfPPa9u4ZSwqYzrYq1eTn8QzhuXuWPBZkALdXLZg8LQIJ3/SOnOBtfTWRxw0/ 813eVJKQn3EWZXlhfaGh38weluVLR5cDy7l7USKmvC+pcZl9r+E4H6ZVDysIALOdcLMMug 8Viqd+GAD9r8bjWD5Wqyu+gnEsgbfSE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724915689; a=rsa-sha256; cv=none; b=428DrVc70tIrMDsqgPOr4CuFyd9aMoox2mlfgk7JCsa0OiFkv+svSSyJ8S16PkoJU8ODEo XUevG5IHscfvaQm1JvPr8TWiZZn87/DHfGhK/ZSIdA6DD7xF68bLsefgXMkMsECtZrqGJ/ dsYWyFD+4UNA5aRu4Zeao0xKK3FpkLo= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=cwxzA9EH; spf=pass (imf11.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.215.176 as permitted sender) smtp.mailfrom=charlie@rivosinc.com; dmarc=none Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-7ae3d7222d4so204778a12.3 for ; Thu, 29 Aug 2024 00:16:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724915777; x=1725520577; 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=K+PlWd5TxPsjPig/hDVlAKKLZn98jtqGVu2vnt7YwwU=; b=cwxzA9EHbnyAyS60GWO/EfFBPeVzF5gFASuQaDD6XgnDwPNxCdFiKvdo/GAotmdII4 kfNPsOTqR6VwtIL1JCd2PD25AdY8nmp3jbbMRv/rUMHbQMWnSTcx1CNNwVroDGFak9yU 4cNoSrpCxQ6NxGT2wuLFNlk+AOngizHlT/FaNm/zUyAPym3csc9Kf0eHfSEo5XCu8lgE ccajbtaBQHZN/6GK/SAH1mthTahhrN/hAkXx0W4ShIiVvFOIUUV533CASGSfAm2hNH6g NWaP67gxZIC6gErTLAYXMSQE5AoiltW3DQWlALiZ1R/7NucCYF37USx2Nv7MG1/U2kUt Q16A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724915777; x=1725520577; 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=K+PlWd5TxPsjPig/hDVlAKKLZn98jtqGVu2vnt7YwwU=; b=vIOmPwzySgWcgtoyL1MoA10A7Yt2nLkvJZag1EddU/BeO/PkL8PAUWBJRb3RQtIFk1 eoQUJ1odJDhoRQKOI8bXm5QiHnVROGkegcCFkJCHfX69rNC+tcQXILlVHq2Wk+8AXU/n cWomJUjvafbE5ELd8rLculOu2kwsA2M6CEUApfCpD2xAcLuZM9/lFxX+0Dtd9Mf4b6dE 1CmUeiIooaK+azaub1x9+tUp82RDY+CcRe1eBttrCmKgl/Bvzti3MxF/xvwQksr+y+9t J4OCB8V0vwOyn/51yPVkK/Gyo6LQEs/ZFD4AbPMQvxKBmp3DmrkCa+zCPDEiHMjFNY3+ Fg2Q== X-Forwarded-Encrypted: i=1; AJvYcCUm0n2ALVKwY/X6xEJHa/oJQ8s4d/9nyxpr7+XzMkF6YDU5qkG7tFjxjinLm+ZZVDFajtgcX7LUgg==@kvack.org X-Gm-Message-State: AOJu0Yw3PxgUI9MqQMCik/ORn7TNHEWXCNWmrngXwf0k1NN/Yspk/M6z gK/c0dYoKiL9GBSij1vz2sz00NRaU07cJtmsDTUWu/q+FQSZTdpbFupSkZ82ZwQ= X-Google-Smtp-Source: AGHT+IFLTY1yKSBMzZ5xgis43aJyn47zOLzwLd2defzztxCwj/TAmDuOoW0Odpywez2pOZ4X8GI8+g== X-Received: by 2002:a05:6a21:164e:b0:1c3:b16d:9ebf with SMTP id adf61e73a8af0-1cce10103d0mr1908062637.15.1724915776548; Thu, 29 Aug 2024 00:16:16 -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.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2024 00:16:15 -0700 (PDT) From: Charlie Jenkins Date: Thu, 29 Aug 2024 00:15:58 -0700 Subject: [PATCH RFC v2 1/4] mm: Add MAP_BELOW_HINT MIME-Version: 1.0 Message-Id: <20240829-patches-below_hint_mmap-v2-1-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=1708; i=charlie@rivosinc.com; h=from:subject:message-id; bh=BFQJVSzGcUiBI/yFP8LdbUQD3Uj+U8GuBEaXAXz6ZKc=; b=owGbwMvMwCHWx5hUnlvL8Y3xtFoSQ9oFBYuLDvF9d6RNyqKnPc++ZptxLkm788kE4fk8m6PdD Gf/eyDdUcrCIMbBICumyMJzrYG59Y5+2VHRsgkwc1iZQIYwcHEKwEQUHjP8FT4q7/qhylvttk3+ XKO3ddmdn3jey344uGPfdmlzxi+3HBkZXsjbfilaf335tejK27Ovnk67EVP0NumF3oyGea6eXuV VHAA= X-Developer-Key: i=charlie@rivosinc.com; a=openpgp; fpr=7D834FF11B1D8387E61C776FFB10D1F27D6B1354 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 1EEAF4002C X-Stat-Signature: sq4n5oa6wpj1p5bwqz8ecpzp7czniphe X-HE-Tag: 1724915777-691042 X-HE-Meta: U2FsdGVkX18HWYgiOCy4e3vE4NcoJfXzylGcDpzbHCApvGtL0dU0tXktVjq2EuOL9QRonYYYpc0Ng//sRaZPWU2Qbs5Q0IvfKQ7SNCNTlqj0dWgVH8xonPy5LgJKkFbpeq+pR4XutIIiMib10g8ChO3qylB/j4D6vdPub4Fz8XZB5aL5ynhDDHs2ImXXLIVN8ByZqM/4KTHeh0cVBO0z7meZSwPeX+7L5jF1DWmaoal8ZBJVinB81PT04HQA2ADlqJaAFzxyOBNn2pkDq0o+T2YyE+RKrVLBSKb4Wy9uzvNQhXeDh1O3dX98rSfyH5J/FK2Lo3Recx0ArB3LDS3VvsmsI2AY6hKKqVFBKxmBbnI2blGQ90UoC0KZbhrWPMA3e5ibkAdMduCaY4fiPi/Nt1jTAK0m6DsDik/Cqi4ksrFCV+M0kfVJzU4bgcztrJ3OM1phs+8ccB1VqqJcAYRWlxaCpiwDFTMR0dslxYHH4OlwGwUnlmMZEK6quxXcPxX4Vpm0ZF73d8Jr2UohAyFMREFDqKhDSedVOwBc4vBuV9dPnrPpbyQWr5Zwc7/tc7c47ELpu5dLPj14LRQ5G2W23x0UWYV42jEiIwsfAjjSozjDHB3gUQJJQ1Itre4I+Fe1dmp8Fs1O3xBh/OZ5sf2LBNea2JHbl0P8N0u6AnJ9WGZK46l+BZmchJowmaxretOKYcO/EVs7r4rzAqgHtF0kgnK/z3EQ76XhVEhw9/n4sAw1PVo//xINFNjiAbJrFvJWD/5qWfR7VnHl9fravUqexe/YZfTjexS7986H08IjHKaUkSEVDfx8EsgZol17+JPzZcETc0LVPPDg7nCsRc1Jxw6tWd5aYBJpWkGO6ONbKcuuLQjsGX0zeN33/VihGTQbGo3ob8bqfSNTDjl6Orr696aDLuH4s7vtqT/Q3CAMuhiJdsHB3a7tRn4J1yTJ54Kkyyo6lun9ehOryUfn2NS XhvE2HFD GIWi6UVT/ZfM1zG0TuTjMdqE1MDeeh+UhXWzHnQp2RphFK0yls22KCtkEEhk/nrQJT1IZrNbUno0WvJddHdslRSQqLkDkGSHTDHlRbR19HZJiZrx13cUEnMeRR/OisNDarayWrbx/2vxMSfcnjhPz3GCeOEJ4CxN38cQ9sNF6Zeu7WHOny+NfKyWetEv6dj1sYf47L51CJkwkgzQpawgA0ROsChEMFL6w5TtBdceD0Yj3/R6ElYXDS/etr9IjUJGbqz5axmT+zQdmZA980w9bHWFiC5hh66cvOV+iLSx0ckmBSWgnCeHUEh+kLzhXRuu+JWAXicYiU0rhBYhxUHU79aZOri5guJUaMBbykyc6kA94lTu/gMXbS58IFe6PR9xEO9Wu3x+Iwh62grgjVw/v5ThIe6/LPgtlG/bCcvQ+rZmyd59OSRrxCyOuCQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Some applications rely on placing data in free bits addresses allocated by mmap. Various architectures (eg. x86, arm64, powerpc) restrict the address returned by mmap to be less than the 48-bit address space, unless the hint address uses more than 47 bits (the 48th bit is reserved for the kernel address space). To make this behavior explicit and more versatile across all architectures, define a mmap flag that allows users to define an arbitrary upper limit on addresses returned by mmap. Signed-off-by: Charlie Jenkins --- include/uapi/asm-generic/mman-common.h | 1 + tools/include/uapi/asm-generic/mman-common.h | 1 + 2 files changed, 2 insertions(+) diff --git a/include/uapi/asm-generic/mman-common.h b/include/uapi/asm-generic/mman-common.h index 6ce1f1ceb432..03ac13d9aa37 100644 --- a/include/uapi/asm-generic/mman-common.h +++ b/include/uapi/asm-generic/mman-common.h @@ -32,6 +32,7 @@ #define MAP_UNINITIALIZED 0x4000000 /* For anonymous mmap, memory could be * uninitialized */ +#define MAP_BELOW_HINT 0x8000000 /* give out address that is below (inclusive) hint address */ /* * Flags for mlock diff --git a/tools/include/uapi/asm-generic/mman-common.h b/tools/include/uapi/asm-generic/mman-common.h index 6ce1f1ceb432..03ac13d9aa37 100644 --- a/tools/include/uapi/asm-generic/mman-common.h +++ b/tools/include/uapi/asm-generic/mman-common.h @@ -32,6 +32,7 @@ #define MAP_UNINITIALIZED 0x4000000 /* For anonymous mmap, memory could be * uninitialized */ +#define MAP_BELOW_HINT 0x8000000 /* give out address that is below (inclusive) hint address */ /* * Flags for mlock From patchwork Thu Aug 29 07:15:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13782677 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 BB82BC7EE2E for ; Thu, 29 Aug 2024 07:16:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3A9616B00A6; Thu, 29 Aug 2024 03:16:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 358F76B00A7; Thu, 29 Aug 2024 03:16:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 184156B00A8; Thu, 29 Aug 2024 03:16:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id E300D6B00A6 for ; Thu, 29 Aug 2024 03:16:23 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 8F3D9A77AA for ; Thu, 29 Aug 2024 07:16:23 +0000 (UTC) X-FDA: 82504424646.05.1904C0B Received: from mail-io1-f43.google.com (mail-io1-f43.google.com [209.85.166.43]) by imf05.hostedemail.com (Postfix) with ESMTP id 86861100009 for ; Thu, 29 Aug 2024 07:16:21 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=EY1KFkHI; spf=pass (imf05.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.166.43 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=1724915737; 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=Sbwm6yYi8fii0SQTFAzAiKdXxaRuHZnv4HbMCIc+vRk=; b=rZXFyvpu5uioyb4WAhvwL/M7errj5oV4i2gK0zoEfwg0wk/mJY31gpPN8/xdv6I/82g3wb +FjfZQkgz3uN5Xxk2wBfsBTOiFrPo9iH7/C+m2n5HmUY42G5ut+aBfpHfsPRU5GfZj/9YN e9GxtAW4wtUF6Q7mlVNgUwTlviNLez8= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=EY1KFkHI; spf=pass (imf05.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.166.43 as permitted sender) smtp.mailfrom=charlie@rivosinc.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724915737; a=rsa-sha256; cv=none; b=ZNgOYcJWa9CMQwWICkFypeV8k7jzypizhIYyi/Ebc6P5MTQ9x1d6SqkbLmQIc09E8UsKzH 0miyBFvVSvzw+OHwoIH8zPbvYXsBV1Rhe4SgbjPnd7ZmkmhN5oRbnYnfIEnxUKB+IzX1Q4 QJ2TN9RhqI1qIjcDyRQiA/T2rwSDnsI= Received: by mail-io1-f43.google.com with SMTP id ca18e2360f4ac-829e3fbcb87so16715439f.0 for ; Thu, 29 Aug 2024 00:16:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724915780; x=1725520580; 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=Sbwm6yYi8fii0SQTFAzAiKdXxaRuHZnv4HbMCIc+vRk=; b=EY1KFkHInwDlQUmLImnqQBmMoVl3HiDYo1FSBk848dAuJ9JcuItf5bEhiGnqKgWG5S V7BRUWky3LmOQl27s6rZAgkTyznokZpzskRKzVqaD3RS51wONsh78doiz7vaPFYOLGMO LoJg3NiczsH1kuB3IwWiKaTmIreyR8lO6uyNC2F6AmXtRx6W8PErlmZ11qKyIxkdgFs4 S+togzhZQpRxhtJyoS2kCsW47BQLJQ7fo6xlSTOBNBqTjXMEqyFo8aRAxub3k5ophExv wwChd13EmiK76dUYuZpHlL6ywEl3CJ2NzeY6Qu7wPQxZsMGqYsj6rZ6Uz4u2Sq00JCXo iu0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724915780; x=1725520580; 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=Sbwm6yYi8fii0SQTFAzAiKdXxaRuHZnv4HbMCIc+vRk=; b=FihTNrPVn7WrXy1pJZkKylnUJCeWW5GLT1tuMeZkkINwLcHd8fiqI7OtWTjQQ1u0Xo CP8kEvgzHju7h1Q4qS8wpH8Eb/OpJ4/I+383y2x1t59OeifJYWa1g4HyCGXxRxPGbgi4 X+VhuarKt49N+e3VxBr6M/giXz9qGt9g/kHHKfMJQnClNgBa6cXJiV2XKuMZBPCRhVzu I2+YBYExfLdKqtg5+SQjNwvOHKvxnCNyJvPS5MZECPjqpYBQA2ghVcaTlII3KpiEZ+UZ 8g37dGWAM3vW4NxH7B9T9TqDI4zvjCcpAPAKIkE5geYzA9DllveLoLFl8zaUJyYfLgGb JGdA== X-Forwarded-Encrypted: i=1; AJvYcCVPHYEQFsKHgeeHKIxUKKmHOLZgc5HG+4HQETMnvlFhjHgUEiAtxzXY6tOE8e302zm2GW0X/tG2SA==@kvack.org X-Gm-Message-State: AOJu0YwLamDlB7BGsaFnlPuhhFFlPcvmdLiTt4/0MrvbQBTD/p17BUPY OUnMg/TqKCpnAUWhs/wxe187LQID0zxH3y4v5YupzMxCeKZhOfy1H/b/uEFAW+8= X-Google-Smtp-Source: AGHT+IGgPVGnJtoSfqPS27dHBhsP9wE8tGpecq2SA+TpeFejfd/21/ZqZVX0hSOoHcWSmw9m6xWNXw== X-Received: by 2002:a05:6602:150e:b0:803:c955:eda8 with SMTP id ca18e2360f4ac-82a11010e13mr213412239f.6.1724915779989; Thu, 29 Aug 2024 00:16:19 -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.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2024 00:16:19 -0700 (PDT) From: Charlie Jenkins Date: Thu, 29 Aug 2024 00:15:59 -0700 Subject: [PATCH RFC v2 2/4] mm: Add hint and mmap_flags to struct vm_unmapped_area_info MIME-Version: 1.0 Message-Id: <20240829-patches-below_hint_mmap-v2-2-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=13798; i=charlie@rivosinc.com; h=from:subject:message-id; bh=cJo+DjHYKAKtcF7uVNq5Hkp7bg1tB/ALtneNIYjVApc=; b=owGbwMvMwCHWx5hUnlvL8Y3xtFoSQ9oFBYsZBaJsp/MFz8f+MGk86RnpUeMrsf76l5QvfwVzH bi3fE/oKGVhEONgkBVTZOG51sDceke/7Kho2QSYOaxMIEMYuDgFYCJhqQx/pZw4Kv/yqWcskTot +DC45Z2Xbmt3sqXCfbPzz4uE9X7UMvyPfD0x5fXhZqutguJLblpd/5tsrJGyOK/8zPKTp3N1Txs xAQA= X-Developer-Key: i=charlie@rivosinc.com; a=openpgp; fpr=7D834FF11B1D8387E61C776FFB10D1F27D6B1354 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 86861100009 X-Stat-Signature: 36yreyixytdm7i5wu3qz8nhdsx74iiyk X-HE-Tag: 1724915781-749995 X-HE-Meta: U2FsdGVkX19Gwsqry3TJYQWtosM52GfSR6uvXjVe2EfkFExq3bvtSxgNbXbI8n3tgcKG6fz9MUHY0h1uvoAUCZkndgrqXBgd5bF8+QEHt97kLFJrax6X4vQyWywfGvha6pud3GgI2ooJ4yP1pxyFoItk3L/QZcH+VVqL6izPLjtTXkGPGdkBi/fEIOkR82zGYkguCRYBhevgogk5QKrjmIiG0FTLivTF0kqJofnk/7w6NbKl6LI52/n0EjYLU0kG67G7fC7NP1OP+nAo8SuZU8+Zw20dxGgwPcdQoB3/8V2yi//sPSvFT16r9aq8Y3s4qD0T1cpyXjCMnIQF7jp5tBnE9Ka73pbTNQJ8+bZ5GDuejyZY9QbJX8aRjOU6CWOB1c+H+nxqxbf5O30gcD+odrAlWTR6RV28vIbn0HE24hWcdXSfjjiAjfBzD5YpauACS7JPX+HWV0L1GjEa7X8W8w4J2eA57IYR0Cme6BctsEtpFSq4dKYIO8w6esyunt44dQTs5okcH2zrMbmJF9XZ3JAas//3OaTGqvGK/l6C1W75bHvzN5KfduaGPvLJ73V4eSslbVmmjEFUyn8u8cxYP4FVKjU3MbRdVW3r7yXE/Upa2ewidunsj16liZjIliVWsRwn94XNaCz9kDLTPnDy109dkY10A3eK6x/eEhElgQlEVo8A7Z+QByJCGzlHU6iQewIp/HyUWgHO3PEU60FtaryQJ6CzSv8S7Ls9HHRRC9x26p7SWtYJEMDrn/SdjktqTQrGUpi8u41YhKiJ7YTrPXi8ynUogccCa++Im+YOfRwA1WNAAVgODdyBvD+SXqDcdVLKo0Evg+4d+uf5DxfpH5IwTB/aagLx4SEirmTmMRh9EeiDR1kwYbkbLanYSB00Py8cZ8HbK9joDMhGgvZmTCpSOBYNEywFAX0r9XtDtpFSffaIvWOgyv3NdCsGjw625LC9FIjA/sBpY0Xg+yD j4r9sqks HpBjo1rcOPjE5eqPHw3gUsPJTqC6TG0zCzFb4wW/kG5oA+fz6md3iG/6gQr/5+LQ/e84PkkPQkkeGGxZ5anTsnK3VNvuo3DdwxIT1nRaLtDKAbHC42cx5qQyL19F1YohjZX1SCZ/oz05BsVFt8yKtkhDN1Eks/erFYMjbgwysdiY5CyH50DbUz3KTmtumRYgeH/xkJZdwKXkzTbYXwLbIB6G0DGPdQLVTNyx8Lyo2Sq5Isy1Xe1YqdQGPqHW/OErsomP2qqbmgiR2AX0QL/1JSe43Nki9rH1HLgTIVaYn9RJg3Q6tDGHToqI6A8M/zhcAl96m/ZHGtzH3Dd+hntOBcuqpohlZsmZRQR9Fc1lpFjPnNqBxGBuF1a7PR+DIwaNIIHLuePe6whbraIVioJv/xPgNBDIg5yKww3p0hk7KWHRw2bu09GT8RN7w9Q== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The hint address and mmap_flags are necessary to determine if MAP_BELOW_HINT requirements are satisfied. Signed-off-by: Charlie Jenkins --- arch/alpha/kernel/osf_sys.c | 2 ++ arch/arc/mm/mmap.c | 3 +++ arch/arm/mm/mmap.c | 7 +++++++ arch/csky/abiv1/mmap.c | 3 +++ arch/loongarch/mm/mmap.c | 3 +++ arch/mips/mm/mmap.c | 3 +++ arch/parisc/kernel/sys_parisc.c | 3 +++ arch/powerpc/mm/book3s64/slice.c | 7 +++++++ arch/s390/mm/hugetlbpage.c | 4 ++++ arch/s390/mm/mmap.c | 6 ++++++ arch/sh/mm/mmap.c | 6 ++++++ arch/sparc/kernel/sys_sparc_32.c | 3 +++ arch/sparc/kernel/sys_sparc_64.c | 6 ++++++ arch/sparc/mm/hugetlbpage.c | 4 ++++ arch/x86/kernel/sys_x86_64.c | 6 ++++++ arch/x86/mm/hugetlbpage.c | 4 ++++ fs/hugetlbfs/inode.c | 4 ++++ include/linux/mm.h | 2 ++ mm/mmap.c | 6 ++++++ 19 files changed, 82 insertions(+) diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c index e5f881bc8288..6903700afd12 100644 --- a/arch/alpha/kernel/osf_sys.c +++ b/arch/alpha/kernel/osf_sys.c @@ -1223,6 +1223,8 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len, info.length = len; info.low_limit = addr; info.high_limit = limit; + info.hint = addr; + info.mmap_flags = flags; return vm_unmapped_area(&info); } diff --git a/arch/arc/mm/mmap.c b/arch/arc/mm/mmap.c index 69a915297155..5922cb51e029 100644 --- a/arch/arc/mm/mmap.c +++ b/arch/arc/mm/mmap.c @@ -29,6 +29,9 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr, struct vm_area_struct *vma; struct vm_unmapped_area_info info = {}; + info.hint = addr; + info.mmap_flags = flags; + /* * We enforce the MAP_FIXED case. */ diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c index d65d0e6ed10a..04d9234f049a 100644 --- a/arch/arm/mm/mmap.c +++ b/arch/arm/mm/mmap.c @@ -36,6 +36,9 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr, int aliasing = cache_is_vipt_aliasing(); struct vm_unmapped_area_info info = {}; + info.hint = addr; + info.mmap_flags = flags; + /* * We only need to do colour alignment if either the I or D * caches alias. @@ -56,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr, if (len > TASK_SIZE) return -ENOMEM; + if (addr) { if (do_align) addr = COLOUR_ALIGN(addr, pgoff); @@ -88,6 +92,9 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, int aliasing = cache_is_vipt_aliasing(); struct vm_unmapped_area_info info = {}; + info.hint = addr; + info.mmap_flags = flags; + /* * We only need to do colour alignment if either the I or D * caches alias. diff --git a/arch/csky/abiv1/mmap.c b/arch/csky/abiv1/mmap.c index 7f826331d409..0be4913c6cf3 100644 --- a/arch/csky/abiv1/mmap.c +++ b/arch/csky/abiv1/mmap.c @@ -35,6 +35,9 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr, .align_offset = pgoff << PAGE_SHIFT }; + info.hint = addr; + info.mmap_flags = flags; + /* * We only need to do colour alignment if either the I or D * caches alias. diff --git a/arch/loongarch/mm/mmap.c b/arch/loongarch/mm/mmap.c index 889030985135..7d1e8be20519 100644 --- a/arch/loongarch/mm/mmap.c +++ b/arch/loongarch/mm/mmap.c @@ -27,6 +27,9 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp, int do_color_align; struct vm_unmapped_area_info info = {}; + info.hint = addr; + info.mmap_flags = flags; + if (unlikely(len > TASK_SIZE)) return -ENOMEM; diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c index 7e11d7b58761..22e8f9c8eaa0 100644 --- a/arch/mips/mm/mmap.c +++ b/arch/mips/mm/mmap.c @@ -36,6 +36,9 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp, int do_color_align; struct vm_unmapped_area_info info = {}; + info.hint = addr; + info.mmap_flags = flags; + if (unlikely(len > TASK_SIZE)) return -ENOMEM; diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c index f7722451276e..2ac53f148624 100644 --- a/arch/parisc/kernel/sys_parisc.c +++ b/arch/parisc/kernel/sys_parisc.c @@ -108,6 +108,9 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp, .length = len }; + info.hint = addr; + info.mmap_flags = flags; + if (unlikely(len > TASK_SIZE)) return -ENOMEM; diff --git a/arch/powerpc/mm/book3s64/slice.c b/arch/powerpc/mm/book3s64/slice.c index ef3ce37f1bb3..f0e2550af6d0 100644 --- a/arch/powerpc/mm/book3s64/slice.c +++ b/arch/powerpc/mm/book3s64/slice.c @@ -286,6 +286,10 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm, .length = len, .align_mask = PAGE_MASK & ((1ul << pshift) - 1), }; + + info.hint = addr; + info.mmap_flags = flags; + /* * Check till the allow max value for this mmap request */ @@ -331,6 +335,9 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm, }; unsigned long min_addr = max(PAGE_SIZE, mmap_min_addr); + info.hint = addr; + info.mmap_flags = flags; + /* * If we are trying to allocate above DEFAULT_MAP_WINDOW * Add the different to the mmap_base. diff --git a/arch/s390/mm/hugetlbpage.c b/arch/s390/mm/hugetlbpage.c index ded0eff58a19..dc38f7022037 100644 --- a/arch/s390/mm/hugetlbpage.c +++ b/arch/s390/mm/hugetlbpage.c @@ -254,6 +254,8 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file, info.low_limit = current->mm->mmap_base; info.high_limit = TASK_SIZE; info.align_mask = PAGE_MASK & ~huge_page_mask(h); + info.hint = addr; + info.mmap_flags = flags; return vm_unmapped_area(&info); } @@ -270,6 +272,8 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file, info.low_limit = PAGE_SIZE; info.high_limit = current->mm->mmap_base; info.align_mask = PAGE_MASK & ~huge_page_mask(h); + info.hint = addr; + info.mmap_flags = flags; addr = vm_unmapped_area(&info); /* diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c index 206756946589..001345df61b6 100644 --- a/arch/s390/mm/mmap.c +++ b/arch/s390/mm/mmap.c @@ -88,6 +88,9 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, struct vm_area_struct *vma; struct vm_unmapped_area_info info = {}; + info.hint = addr; + info.mmap_flags = flags; + if (len > TASK_SIZE - mmap_min_addr) return -ENOMEM; @@ -123,6 +126,9 @@ unsigned long arch_get_unmapped_area_topdown(struct file *filp, unsigned long ad struct mm_struct *mm = current->mm; struct vm_unmapped_area_info info = {}; + info.hint = addr; + info.mmap_flags = flags; + /* requested length too big for entire address space */ if (len > TASK_SIZE - mmap_min_addr) return -ENOMEM; diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c index bee329d4149a..ab1f5613b5e2 100644 --- a/arch/sh/mm/mmap.c +++ b/arch/sh/mm/mmap.c @@ -59,6 +59,9 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, int do_colour_align; struct vm_unmapped_area_info info = {}; + info.hint = addr; + info.mmap_flags = flags; + if (flags & MAP_FIXED) { /* We do not accept a shared mapping if it would violate * cache aliasing constraints. @@ -107,6 +110,9 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, int do_colour_align; struct vm_unmapped_area_info info = {}; + info.hint = addr; + info.mmap_flags = flags; + if (flags & MAP_FIXED) { /* We do not accept a shared mapping if it would violate * cache aliasing constraints. diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c index 08a19727795c..bcc3242e003d 100644 --- a/arch/sparc/kernel/sys_sparc_32.c +++ b/arch/sparc/kernel/sys_sparc_32.c @@ -43,6 +43,9 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi { struct vm_unmapped_area_info info = {}; + info.hint = addr; + info.mmap_flags = flags; + if (flags & MAP_FIXED) { /* We do not accept a shared mapping if it would violate * cache aliasing constraints. diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c index d9c3b34ca744..05de444d66f6 100644 --- a/arch/sparc/kernel/sys_sparc_64.c +++ b/arch/sparc/kernel/sys_sparc_64.c @@ -95,6 +95,9 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi int do_color_align; struct vm_unmapped_area_info info = {}; + info.hint = addr; + info.mmap_flags = flags; + if (flags & MAP_FIXED) { /* We do not accept a shared mapping if it would violate * cache aliasing constraints. @@ -155,6 +158,9 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, int do_color_align; struct vm_unmapped_area_info info = {}; + info.hint = addr; + info.mmap_flags = flags; + /* This should only ever run for 32-bit processes. */ BUG_ON(!test_thread_flag(TIF_32BIT)); diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c index cc91ca7a1e18..148064142628 100644 --- a/arch/sparc/mm/hugetlbpage.c +++ b/arch/sparc/mm/hugetlbpage.c @@ -40,6 +40,8 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp, info.low_limit = TASK_UNMAPPED_BASE; info.high_limit = min(task_size, VA_EXCLUDE_START); info.align_mask = PAGE_MASK & ~huge_page_mask(h); + info.hint = addr; + info.mmap_flags = flags; addr = vm_unmapped_area(&info); if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) { @@ -71,6 +73,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, info.low_limit = PAGE_SIZE; info.high_limit = mm->mmap_base; info.align_mask = PAGE_MASK & ~huge_page_mask(h); + info.hint = addr; + info.mmap_flags = flags; addr = vm_unmapped_area(&info); /* diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c index 01d7cd85ef97..248a210c2b0b 100644 --- a/arch/x86/kernel/sys_x86_64.c +++ b/arch/x86/kernel/sys_x86_64.c @@ -129,6 +129,9 @@ arch_get_unmapped_area_vmflags(struct file *filp, unsigned long addr, unsigned l struct vm_unmapped_area_info info = {}; unsigned long begin, end; + info.hint = addr; + info.mmap_flags = flags; + if (flags & MAP_FIXED) return addr; @@ -167,6 +170,9 @@ arch_get_unmapped_area_topdown_vmflags(struct file *filp, unsigned long addr0, unsigned long addr = addr0; struct vm_unmapped_area_info info = {}; + info.hint = addr; + info.mmap_flags = flags; + /* requested length too big for entire address space */ if (len > TASK_SIZE) return -ENOMEM; diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c index 807a5859a3c4..d3f8cec4895d 100644 --- a/arch/x86/mm/hugetlbpage.c +++ b/arch/x86/mm/hugetlbpage.c @@ -29,6 +29,8 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file, info.length = len; info.low_limit = get_mmap_base(1); + info.hint = addr; + info.mmap_flags = flags; /* * If hint address is above DEFAULT_MAP_WINDOW, look for unmapped area @@ -52,6 +54,8 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file, info.length = len; info.low_limit = PAGE_SIZE; info.high_limit = get_mmap_base(0); + info.hint = addr; + info.mmap_flags = flags; /* * If hint address is above DEFAULT_MAP_WINDOW, look for unmapped area diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index 9f6cff356796..4b35eadd2ad8 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -182,6 +182,8 @@ hugetlb_get_unmapped_area_bottomup(struct file *file, unsigned long addr, info.low_limit = current->mm->mmap_base; info.high_limit = arch_get_mmap_end(addr, len, flags); info.align_mask = PAGE_MASK & ~huge_page_mask(h); + info.hint = addr; + info.mmap_flags = flags; return vm_unmapped_area(&info); } @@ -197,6 +199,8 @@ hugetlb_get_unmapped_area_topdown(struct file *file, unsigned long addr, info.low_limit = PAGE_SIZE; info.high_limit = arch_get_mmap_base(addr, current->mm->mmap_base); info.align_mask = PAGE_MASK & ~huge_page_mask(h); + info.hint = addr; + info.mmap_flags = flags; addr = vm_unmapped_area(&info); /* diff --git a/include/linux/mm.h b/include/linux/mm.h index 6549d0979b28..b5fcb9dfb942 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3445,6 +3445,8 @@ struct vm_unmapped_area_info { unsigned long align_mask; unsigned long align_offset; unsigned long start_gap; + unsigned long hint; + unsigned long mmap_flags; }; extern unsigned long vm_unmapped_area(struct vm_unmapped_area_info *info); diff --git a/mm/mmap.c b/mm/mmap.c index d0dfc85b209b..34ba0db23678 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1796,6 +1796,9 @@ generic_get_unmapped_area(struct file *filp, unsigned long addr, struct vm_unmapped_area_info info = {}; const unsigned long mmap_end = arch_get_mmap_end(addr, len, flags); + info.hint = addr; + info.mmap_flags = flags; + if (len > mmap_end - mmap_min_addr) return -ENOMEM; @@ -1841,6 +1844,9 @@ generic_get_unmapped_area_topdown(struct file *filp, unsigned long addr, struct vm_unmapped_area_info info = {}; const unsigned long mmap_end = arch_get_mmap_end(addr, len, flags); + info.hint = addr; + info.mmap_flags = flags; + /* requested length too big for entire address space */ if (len > mmap_end - mmap_min_addr) return -ENOMEM; From patchwork Thu Aug 29 07:16:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13782678 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 2BFF3C7EE30 for ; Thu, 29 Aug 2024 07:16:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B00A06B00BE; Thu, 29 Aug 2024 03:16:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9E7996B00C0; Thu, 29 Aug 2024 03:16:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 815566B00C2; Thu, 29 Aug 2024 03:16:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 5C7336B00BE for ; Thu, 29 Aug 2024 03:16:27 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id D6A57809F5 for ; Thu, 29 Aug 2024 07:16:26 +0000 (UTC) X-FDA: 82504424772.24.054CBAF Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) by imf04.hostedemail.com (Postfix) with ESMTP id D538040006 for ; Thu, 29 Aug 2024 07:16:24 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=gMOQJgJO; spf=pass (imf04.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.210.182 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=1724915740; 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=eRZz0v4roamBPZuEY8lRo6reatKDFS+11+O4EIK+5eU=; b=yCuwVCsAJ2GKvejfhAslmk0c3NPaWluKw1jERAyEDLgY0kdwzDWmePE3E4BKGYWkft7i2K EdXiky5ikYPHJzlT+vUmC344JO7gpgcaRw5iZbpVbdOGGOTFSbbJokXwoMmHIkwzf5lRPV yDrMtDArvldqvtJz/LwvZ5ulKPLbncc= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=gMOQJgJO; spf=pass (imf04.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.210.182 as permitted sender) smtp.mailfrom=charlie@rivosinc.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724915740; a=rsa-sha256; cv=none; b=RF0Zj9pPh3a+B4R4MER8xJSlwtgECw2hAIs9rZRiAb/5WJSLophGr4VtoZ4678IHjn75U+ CjwN92QVgVXu/LSMbB3VXuzusN00okFt3ochuJRYnNLpKh+QvKoloqpcWlizp4BBzkL4k6 XOxi0XXW1F0x5zX8nA443YxdsGzUXfg= Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-7141285db14so309484b3a.1 for ; Thu, 29 Aug 2024 00:16:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724915783; x=1725520583; 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=eRZz0v4roamBPZuEY8lRo6reatKDFS+11+O4EIK+5eU=; b=gMOQJgJOf//Z83kIHy1Mtt5Hjp/en15aTIusuV14jddlCZYrCpeV0oL+qgZdCzz4dG 7hK99xUx/hdAOiqCcJd17edOUfe9ievvxJ0OQ8TUdrFNa0d+v6TmX7Wwk5B8VrG9bZrj Ff9za/IlI/+sj7M1irnjhxEaDDLfKxf4m3Ve5MmvntiOYfo9JrDrAZgbfRrObyopNita JCjdJ72P+xfdwacug7CTnnDF6YemCfDLmZTAJ7cH2mU2D1Z9kyXhU7dQ6KFFBhiZLovZ 1g3BwcOjuY5effMZkJ/eMabyHOLaSdRjO0OzXcZMhmrC0MLDC+mTUlGzxXaKddzCbvSP ZzWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724915783; x=1725520583; 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=eRZz0v4roamBPZuEY8lRo6reatKDFS+11+O4EIK+5eU=; b=fENBUrHXT8is3bO2cJZB4mJ443ZM7YWxL2lqJXFbOKtaVZnIbJhfYHScPQkgTyJ5rh sotEJCcSCK9E5fBBQI6sFr+A6Xq2jU8UcuV5cjgi48XkYeUg419KbswcKbD3pd+YSAm3 ruBBlKk/gF+LJxouchYVHi9ukljggSOrTkgNjbHPSqxfxpt6NmUl3Yp2sHZ6d8idcdKc QpylVyKu/E36uHLnD1t5dS8lLulKErugWUX9UlLV3nh0jkZf5vbm6X5Mj+uQKduHLkFv Oy4bVRyi7tWSWfaCbFlUgQJ6ceUaP2wJ/iI6BOSLPrc+XleEf5MLmNserVHKV3C58N9w zcSQ== X-Forwarded-Encrypted: i=1; AJvYcCXVZFfTJ/YxR5YUk8L2FWO6BXpzWPlSe/SguSAmr016l2aAzFtNcqoEF9m6oE8IjcUq1S2lMAHbMg==@kvack.org X-Gm-Message-State: AOJu0YxLTmrDHTezcKjxUXvb7lT9NTRH1vXllwRf2rI0p6JHX3tfqybM aJgi9R6AWg8e545BPc0K1W+UwUcAeN76OUPLSlGmGWQlLlbP8+F+bAGKpsJ7U/eEExN9DAclAo9 e X-Google-Smtp-Source: AGHT+IESlo3+HNMz8Vyf9gnK2kr34iORO0t8ZckMgQQJOrmm4rJ0EngcQswLax6rU2xQbGZPh7/0eg== X-Received: by 2002:a05:6a20:6f88:b0:1c4:7dbc:d21a with SMTP id adf61e73a8af0-1cce104dce4mr1887803637.32.1724915783368; Thu, 29 Aug 2024 00:16:23 -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.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2024 00:16:22 -0700 (PDT) From: Charlie Jenkins Date: Thu, 29 Aug 2024 00:16:00 -0700 Subject: [PATCH RFC v2 3/4] mm: Support MAP_BELOW_HINT in vm_unmapped_area() MIME-Version: 1.0 Message-Id: <20240829-patches-below_hint_mmap-v2-3-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=991; i=charlie@rivosinc.com; h=from:subject:message-id; bh=awlA0FQ8vwXq3Nn6i3BedGsUxTSd4n1W8+rk6Ti/shY=; b=owGbwMvMwCHWx5hUnlvL8Y3xtFoSQ9oFBUtNRaX7W4IPbnI+Ms3hivNnCcHEiLSn/wN2Mfr8Y bUwSP3TUcrCIMbBICumyMJzrYG59Y5+2VHRsgkwc1iZQIYwcHEKwES8tjMyvNn0V3yhfGTAnNVL rI6JakxSy1zhtaNTK7Nm7eOzb9jnWDIy3NjktX5Wn9/XRXLVu44d2/Xri3n+zz1GZcf0P1w88Pv nEX4A X-Developer-Key: i=charlie@rivosinc.com; a=openpgp; fpr=7D834FF11B1D8387E61C776FFB10D1F27D6B1354 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: D538040006 X-Stat-Signature: 999dc9zwhsqqu6rn73tgbgt6gx6ggiaq X-HE-Tag: 1724915784-591428 X-HE-Meta: U2FsdGVkX1+3HrdwibeeCm6JWbEqI7vOC4RVlgucz61fSJPQzJT08+yIFYtOWquAQ0xYekMl6GITqtAA7JdCqi6rN9gsTwtu9evG2Kk0/UVwg5nKd1fDB9uVvQwaG+fNsI/p1c+RGscwepE3k9KczGhKqzJ8RDzpGv+URnFmpiwja8eq8dTpNlzcgnxhkBIfVDi6bxBAH+BmVMb+q+oj5dDSCG0gtN9pMnGheeEXxN56JCLWYIcfcDYDy7XdhBOdH/prdgLtyylZ9jPWmfdv+c2OzAEjQn0gF8Foko2huDEBdeM+KHV2s7E2tYuzJCQ9+2RO8a7t3wSTA/TtCC+oNEdsinKyMUdVhv8T8AalwoFrizfV6uxOL0tQUngn1olYvP8GY9Oif+eYu76JsN+oCRx8Hi9BuYSZJDqwWyp0UTDx5xqNPH3zW9d2Jpo6FYg7mSmVtjCMSjuruEnbK1NMrcJQeSd+RycYOzcWYnD6YJ+Zn/RBF0b+gqJgMwvtyFLtVGZXG5t73M4OdQXtlLkYaXRtUBiQ2iJlqRZWl73uEbspxYVadL3R0XdL/Gf/VEBA1KnYMCEV1aZwCUQIVpwhJPQl+jMBX4/JWTEwlLdpHmiU5KKdW0K/489z1u9ly5mNjlXUBDvabGD+Go/rNA5qlYT7ubnxmY3Q717bknv8W5qyxRfYTgat/idA0xcNj1OcW9bQ6E18W6SQUwNxlwU+uEBahq7QaQKzgNjUqiYWMrQGYzt1Nf+AjOftJwggYiX2mQBuVKjghcHidIJQdkoXGbx+UhvDwlsMX5l+x3OPI8ijI6RefrSHV/TUW2Pz7UkEnGXl6CQIzylokKMARdzsMpv6TawwFVu28GfG+I07NOwKiGtpFyu/2e5ykfz2WSU3PpDJKP/66UGPQ5Rn0HLpzOn7YY7vXDbDA2K8Id5XNok7QwFfbUxlBLjahhrRtWiYpzwHpkR/l+OVFuTO2i6 K4IZkfxx QEejL8ZrB+YofqujQxAHhHdYI7+oEUo7C++3GLQJyegG01X4YjRh83r8PXw7uZ4/1dRPEXdvK3blc/UvgJd8Biarfj9ZjX7SJWS2iabdDZGgRJg8nOV59sCc9dURt3UhzXCJJkp4s2NacVKHhy5JKXdeFcyr9Y0wm9XM8qQtQF0IAWb7+GvyBt02UAwptO3cxleRSjtbT7Ija4zpdnZD01SR7y9cinu7Lb3Y4SuieOkHMHazkmYMScNEwUI0J0uSoBcugJnWxL5ul5jDLLZolUZ8FyGr5UhWi3pBCoOkY0lr+w3zDWbtO5NP7+8r2AAUpSS4Sr9/3TnquUsA98b65Sle/kFWrvMmyIMtH7mBQiTW4BNXSmOK25J2AKvgUNrYLsoZEwN3xu/WrXA8v+WwTgUp7Q7aV277A2lwoZxv/g3nN/ID3JkvCJY599w== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000003, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: To ensure that all memory allocations comply with the new MAP_BELOW_HINT flag, set the high_limit in vm_unmapped_area() to the hint address + length at most. All callers to this function set the high_limit to something reasonable, usually with space for a random offset and a gap for the stack. To respect the provided high_limit, take the minimum of hint+length and the given high_limit. Signed-off-by: Charlie Jenkins --- mm/mmap.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/mmap.c b/mm/mmap.c index 34ba0db23678..459ad380c673 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 (info->hint != 0 && info->mmap_flags & MAP_BELOW_HINT) + info->high_limit = MIN(info->high_limit, info->hint + info->length); + if (info->flags & VM_UNMAPPED_AREA_TOPDOWN) addr = unmapped_area_topdown(info); else 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/dysGRJSkwiuBzbIx0w15OkE/EYgK2HxfMgmBkrkvieqXrEW476JRgKqnGRSC5lXvDpJKaZMa6bRMt/vs60BdXz45IUKc9VNVO3vyeLy7aO/s474D8wSgtqy+FkdR8V+edko7PxeEdDHcNzphO7xeM95Yq4FRZsgvYAl43YgcksvK0eJT4NEcSvbQmeGIMvscfHpYZmzpqlbGZnkDZmQWiS1ZDw2Mk+fc8J0y3PnKafdrjEXKzDK1DsdUzsh7LMT7TKFKWv1krb8du5iRGQDD7JNL6Cp7/pmcCFxDms70hfyHdXROhpYDZpZNRt2yNg4/6y/kKYSq8n2vskBtEas5u2QRAIfiwgrG1BhpS9p1eLbOXlJv+8f1epYY3N6Ubji9FQ7NxVM/NR3FE+Eo+yQCAdAWHn0ksgPGj8OoSwQHCdqmzz5E3vDweqKthzt3lzY1YmXkBqiNm0tMmSKgXbFxRcwXpuTo+1xdEODTAKLOd9rnhVWiIgXDvUjAwgLcUB+c6NOTJOWfcW1AJ9eO3NXTQiFA3/V++DJumnUwU9jHneCvdNolftmeHz0s6pKbotHNfrrktttLLwSry8msRRXAJwQurxEWnZBv3oePKHxADCyJr2wfTlyrNKFT+RSi3ZRgXAy5tYE6gJKlX87qmXAYhOcLeEi9srjEBWipT7TYQOr96 1kPWdPHz 3BlBIrBj4lZQgB3CLErUsNnZIL6aLHyhigCAsJu/N9Vn4StbEhgOoCufymbEYbbxkSNwM8ntmYENqCZ0YTGcGMDItjgRFfouKYVT7DF61nKoTSaDy4jBOHV5XaLtBl+1nDYSSV/iTUimmO1mA0GGIzwUrzqP9rsU5uX3A0zYtpWz/n2B4D1U1/Sa5VfBb+iPt+bX9JyIlc6shOK5vxvl3PKe7ejjCp0oVeyM4yGLFLEKNpvRCXSs9MMl+uTQgGPw2LNG2ziJxGBzq6kLCLHUM/zgqaBtoTg5mh8zdVRR6zHnCaZvauha2W8u6fXEy+Ws+S3PSizNrw2rqbrilYWu3cd40xa3iVd4qBrymAcGO4/IMax8nhzMK+CJgpwhMcuC/2BDuYlzaVvfW/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)); +}