From patchwork Wed Aug 28 05:49:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13780624 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 4C899C5474A for ; Wed, 28 Aug 2024 05:49:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CC9A46B0099; Wed, 28 Aug 2024 01:49:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C7AE26B009A; Wed, 28 Aug 2024 01:49:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B43B66B009B; Wed, 28 Aug 2024 01:49:50 -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 94F5D6B0099 for ; Wed, 28 Aug 2024 01:49:50 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 4D2A4141B4B for ; Wed, 28 Aug 2024 05:49:50 +0000 (UTC) X-FDA: 82500577740.11.8908573 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by imf20.hostedemail.com (Postfix) with ESMTP id 55A151C000C for ; Wed, 28 Aug 2024 05:49:48 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=bK98eUWD; spf=pass (imf20.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.214.173 as permitted sender) smtp.mailfrom=charlie@rivosinc.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724824100; 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=fVwUzK3Wi136bLF1beJbPIYrhSgOvSQiUtDec+6VrAU=; b=ScetaDBbKg8hrsy4v/Hx98BCGFTU9lhwQeUMeMlFjDLCU06wUC/c8Jf25HYQXVpOk0K2FW A3zKK0KExmUJEZmneDKIn63lOejfgPoUG05fMcjmkVklQBsisRlumzqUZ5vglW6maXXUgv 5tdzK1LnjIgrT2ST1+RyaWSkGXRPSRk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724824100; a=rsa-sha256; cv=none; b=OymIizH3qjEn39F0NQ6KOtyD2Fmx1zGfq4vU4t3vGPfBfKvTI5JZwNEdawDCvz94AuGq+E YZrcwwQyWlVqOjTEeqWzTiIXj8SYCew6SB45e9kzu1msYFOPLBjmwxuOTwuMGdiqtc4ggd G1K9b5T2VCxK6FRmIQrPrSOumWMUb+8= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=bK98eUWD; spf=pass (imf20.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.214.173 as permitted sender) smtp.mailfrom=charlie@rivosinc.com; dmarc=none Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-202146e9538so56959995ad.3 for ; Tue, 27 Aug 2024 22:49:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724824187; x=1725428987; 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=fVwUzK3Wi136bLF1beJbPIYrhSgOvSQiUtDec+6VrAU=; b=bK98eUWDhraghirmXrccseofkpAs1+014e9lRvIzXoWzK4U+Auw1mQ0yWl8KOfSDXr gLY547z8trff9m4Y++5Puxpho2+NqpCPEHskXnqc17B6g/hdgwh1RfmrJmaL9tyGqVDE 9MuwDL7ZN7bZULszYX60nwdsD34d1/rA+72GA8e1I9ruxnzTfRac1GQ6dNWAKO7SnyMm eeOaMQpO8UytEdg5/4rxZnoCv9QTdPRbvFUoo7e+w3eTbdeLdXYg86GhBfhFY7mLJncC kx+dDmQYiUmlp1kBDwwhTLXOF3nyA4BelCPv4UW0d5DX5gEnBWA1RMrhjnydSuNwnMM1 sXpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724824187; x=1725428987; 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=fVwUzK3Wi136bLF1beJbPIYrhSgOvSQiUtDec+6VrAU=; b=UbisWFQGIbusWWuw6kUnlIVyopV1IG0zHlj4efoCrxEPkxpGGd7oktDCwqkQT7RFsu m+7KuV3B/H2NCpFPCt2P6LWyls9e/hhMi3DlTTz/6Ywdw9s4wBQfZQEjCwmEPxBRLfJo KsnYiDz9jGWlOcj8RUlrc0eh1CnxYPmCsyArRvJ+V3qRw23nc+0Q3ekIrR1faWDD6TqK VIiXZZNJmAQnvmXLMCE+Q6jGAV062/UFAm1Q7LDpyB8TCGwK+bVJN3wTIHC34Rd8Ru0N zUw/aZh/iKNpEcU3fnfrUIiqcx9QDLu6qfdxaGnIc+sloxxWXCz01YEXTP3t3vP7ugT1 kQoA== X-Forwarded-Encrypted: i=1; AJvYcCWtf2B3k7xIOW8UzwxPUJc9ZjVA5J5iUAX0e/YJ440BI1a4GK9t8WrClFG8cnYQEMvLFfer8C85gg==@kvack.org X-Gm-Message-State: AOJu0Yw7Bvk0poBC4zLylakK048HDhaNA3hHzcRL6dffsKvDRTOlVZfG +zRnb0WHyjN9Tp1dqpIuC9P+CA5ffgGA3e4SZ6VoYPWLRrB89CQZJUdXT2GJl1U= X-Google-Smtp-Source: AGHT+IFs6bhbKPqiE/XUyq+o9y28MS2XMnZalJw5Zqf2sXjfONhgRAKfe8uENwidGpxKTHXbXFBJcg== X-Received: by 2002:a17:903:41d1:b0:202:54a5:deaf with SMTP id d9443c01a7336-2039e4fbd80mr220740285ad.57.1724824186699; Tue, 27 Aug 2024 22:49:46 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203855df0c4sm92092495ad.157.2024.08.27.22.49.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 22:49:45 -0700 (PDT) From: Charlie Jenkins Date: Tue, 27 Aug 2024 22:49:12 -0700 Subject: [PATCH 06/16] arm64: mm: Support MAP_BELOW_HINT MIME-Version: 1.0 Message-Id: <20240827-patches-below_hint_mmap-v1-6-46ff2eb9022d@rivosinc.com> References: <20240827-patches-below_hint_mmap-v1-0-46ff2eb9022d@rivosinc.com> In-Reply-To: <20240827-patches-below_hint_mmap-v1-0-46ff2eb9022d@rivosinc.com> To: Arnd Bergmann , Paul Walmsley , Palmer Dabbelt , Albert Ou , Catalin Marinas , Will Deacon , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Muchun Song , Andrew Morton , "Liam R. Howlett" , Vlastimil Babka , Lorenzo Stoakes , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Huacai Chen , WANG Xuerui , Russell King , Thomas Bogendoerfer , "James E.J. Bottomley" , Helge Deller , Alexander Gordeev , Gerald Schaefer , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Sven Schnelle , Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , "David S. Miller" , Andreas Larsson , Shuah Khan , Alexandre Ghiti Cc: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, Palmer Dabbelt , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-kselftest@vger.kernel.org, Charlie Jenkins X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2070; i=charlie@rivosinc.com; h=from:subject:message-id; bh=ib/vcnYDgaY2P7lUbSF3YkIC17EmCG0vvapvjDW6XVw=; b=owGbwMvMwCHWx5hUnlvL8Y3xtFoSQ9q5XXGJ67WyV1982VXredvh0ENd1glLC4s4HJVXs9RbW X20a7/aUcrCIMbBICumyMJzrYG59Y5+2VHRsgkwc1iZQIYwcHEKwETa9BkZOnYYvlBTj2FUnbDH vODh/SmrdzHc++GxrUXG77agmXy8LCPDkyuNIo53Hzx7czND5bWgC3vzEimd+TtdNE+3T847GKz FAwA= X-Developer-Key: i=charlie@rivosinc.com; a=openpgp; fpr=7D834FF11B1D8387E61C776FFB10D1F27D6B1354 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 55A151C000C X-Stat-Signature: xo9jix58sjjwkq4w4shx1r39eneb7bma X-HE-Tag: 1724824188-485463 X-HE-Meta: U2FsdGVkX196MmPJAw1ZssqMW51oaGl1KyykLFaqanMTksTo79ZzTBaaRJIdOiuYvGm8zqJiuyFKuy8iXIplbiOl+1Kb1tbIityeYY1HbT0DOBl2y5tsvmhLdXPOEFPFx2vw72Jb9zzzu4yzoE7xcNwquFXY1Z4IocLXm+AllnYz2x0Fab7dYU3rlClgLQuvND6599OCWsZT0yvhF4bZL3/Orgri16rU2CJb10ElowTH9YheAizuhG6FfXwF/DE97GRTj5eGihtwSneE2zCdjJglO+sAt1da2hRgoQlFiAwnqodujoV8fQq2Yt4nG6QEAXXoKMaRy/HwRoT8sJqx+5RVeyqY4ps/b/U9v3rynsat2S092NvIex+kX+mS9108nO5eDRCu7aBKhroLxmS9ex8gXM5HjNohIbvYiLuzxiet8ATdWakdzGAzjZtdrdjleK685luPiXj8EMMp9lF2P1aWVBgkXbMR4xmDu3fOlM6awMcvnx15fwEqJUFneOKYiwAzJi25gP8CSA7whdQZ+jxBb5dNti6TJcao9nH5xD1yjR4d5Tpe0qi43JOBuXATck6x0sXzWer0TmAeACFtPheknX6M0qOUkW+auRLYrLnTbL5nzvv0TP4hjVIEZfIBgfzvfGgjn/AKKPIsz82Skx3DrQD5dEhWJ+o3Iq8aT+rY4eXofvnixgnNpbjhPm3yWWy/Ff31L/l4DJKxrw1L6CAqN3AUItpi0FfgvVJWecd323Vx/J1dv5V83nnmioK8POMU1uwqPLSp/nMx92OMk8SrKIw+OHnk35v/0TiuKczwgl9xbCd16UmUyxMQY3MRxvBwLy5R4Jt87ktkVgp2hp2mPN1GhhNRfNR4XoVjzWgSLm/bO1kDHErkYWvM6NI3m1Td8bD23Vu3lCLGASdkqwTS6r3MPSyLpAN0WR+9+tLyPi80xe4WS44vKRbeISCyCSURSbctusIz9SYbpgZ 3+MISK8A O+9m9SSQEuUAVJa549AovZ/X+tdP+d/EyVHsi1CB9VSaQFtN64jN4yopnXJdpbV95YuDugXS8cRsnk1007X0ytmpsqD3okjly30/FXA21jq8/HGNffwPxe74OxOy75aXc96j4/LzuiMpFBU7+eNLhUPfuWNHEQdTRStL412WpDHCuwRFu69MaBvPDVJS6KftfLEc47/p1vHwpvkDXKj+9nJiRMd+IRNey3G28Q9bxUI+Eax9QmJaQsptOr10oMSZ0b+AsurgJA+xnSr47Tif8zDSi2Kvb3xRTa8drvf/g4yU+wUAJ9b/gxwX3sY3InatZKrpwQg6aSSq7i7+I47RQOkZ8CJig8zTXGPSU3LlLATL0Cjr1eC7zAADOK80h8H5wtTm66eVyAEu+C88bC3ujlYWal6r0oMsUfax5n+qI9l0+tX0OACC4eeWTZw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000057, 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 support for MAP_BELOW_HINT to arch_get_mmap_base() and arch_get_mmap_end(). Signed-off-by: Charlie Jenkins --- arch/arm64/include/asm/processor.h | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/arch/arm64/include/asm/processor.h b/arch/arm64/include/asm/processor.h index a67ca119bb91..39aabb1619f6 100644 --- a/arch/arm64/include/asm/processor.h +++ b/arch/arm64/include/asm/processor.h @@ -92,12 +92,36 @@ #endif /* CONFIG_COMPAT */ #ifndef CONFIG_ARM64_FORCE_52BIT -#define arch_get_mmap_end(addr, len, flags) \ - (((addr) > DEFAULT_MAP_WINDOW) ? TASK_SIZE : DEFAULT_MAP_WINDOW) +#define arch_get_mmap_end(addr, len, flags) \ +({ \ + unsigned long mmap_end; \ + typeof(flags) _flags = (flags); \ + typeof(addr) _addr = (addr); \ + typeof(len) _len = (len); \ + if (_flags & MAP_BELOW_HINT && _addr != 0 && ((_addr + _len) > BIT(VA_BITS - 1))) \ + mmap_end = (_addr + _len); \ + else \ + mmap_end = ((_addr > DEFAULT_MAP_WINDOW) ? TASK_SIZE : DEFAULT_MAP_WINDOW); \ + mmap_end \ +}) + +#define arch_get_mmap_base(addr, len, base, flags) \ +({ \ + unsigned long mmap_base; \ + typeof(flags) _flags = (flags); \ + typeof(addr) _addr = (addr); \ + typeof(base) _base = (base); \ + typeof(len) _len = (len); \ + unsigned long rnd_gap = DEFAULT_MAP_WINDOW - (_base); \ + if (_flags & MAP_BELOW_HINT && _addr != 0 && ((_addr + _len) > BIT(VA_BITS - 1)))\ + mmap_base = (_addr + _len) - rnd_gap; \ + else \ + mmap_end = ((_addr > DEFAULT_MAP_WINDOW) ? \ + _base + TASK_SIZE - DEFAULT_MAP_WINDOW : \ + _base); \ + mmap_end \ +}) -#define arch_get_mmap_base(addr, len, base, flags) ((addr > DEFAULT_MAP_WINDOW) ? \ - base + TASK_SIZE - DEFAULT_MAP_WINDOW :\ - base) #endif /* CONFIG_ARM64_FORCE_52BIT */ extern phys_addr_t arm64_dma_phys_limit;