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: 13780675 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C3B84C5474A for ; Wed, 28 Aug 2024 05:50:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=iTsS+AJ6jMaQ0vA4gSjUEcqBd/H/664HUFo4Gie4UrM=; b=OnwsRyxodmzt7y lJu0t5lQtKB5BsnPTshqekvP52M5Jvo6W/p/FLyZBA7eck5d0+DW/+X9s/tpbbBzaIOAt0ieO3esa oA1L5VmdY8RTpq+8os3JcTyvcvbcjPoAgMju6O++O5kpEnbnsG8r1AmwvWB1rkciKnrih1Q53UkQ9 ZoH/3z9UelvQ44Ji6vsno20cvD8P47C/wNbPviUoo9ktkFSv9K0MzHX74mXMKbF0kz9ECJ+bzZt7h uF6rBSwD+hAXxpAgrCnfQUVd/kQeXBOPlEwae3jQFQ1HsRvGF4V0L+hxK0ToaTUBS1fK1NdMKnawo A54Gzx1CODTWzyoeUdZA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sjBZ6-0000000Dy98-2IWS; Wed, 28 Aug 2024 05:49:56 +0000 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sjBYx-0000000Dy01-3Dr9 for linux-riscv@lists.infradead.org; Wed, 28 Aug 2024 05:49:50 +0000 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-201e64607a5so45277305ad.2 for ; Tue, 27 Aug 2024 22:49:47 -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=lists.infradead.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=mNHqZGQT5eVQWNhvpmk+emo2sYoEedpRCFRiG3jTDFNUTF82IcnlXmcqDnwycWfuFR hKkVauitPM0PL0ESByDE9fXiRdpBkaLIbiszRSDBvMKULurMLG8NvJ27YH0Bpuv/QskU FnE7lN5ALs8Iz/wqbwjS0oQAMxPe1EQVMehKfLIaQ70x4GKEcMje4eFjKJYlyqWVrlWi kQBEqzKrSUzGUw6ufDf4q4rBPJtIAt40yyTeVFRwNarkkoM9eJKzN9mSyEwZiMUGtn71 9LKe6qqS8++K8H14iNpyUV+90MWwXv8MgpG5dE/a7awZt4C1Ikgdbv2VlHtFSYQV2rR4 1uwQ== 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=StuFoDqQu55DKW3jVm2Lm0uyVpfapppvgR8A25g+EqVqDD/mjlxPqTi8d/CRLCMfqv WegklrkSGSN/dUtDTFJT81Aor1EqvnEYJtPChtU66WULmqn/xAJ9HT0Qc8uL3hL+t/LI syIONy/BoFObZa89vQzFn3v8GBIyvps9TPtea8l1ntj7ZBkw1pN4XNtB3noHf/DBflVZ m2KFsX5ssMydGGD7LqVIMGmjY+5F9xWZwiPKWd+v9PauuIvjlMcP0lT+npgjmS4L452z pFpYl1VgZOIbXjFvA8zzpukCzKgYGK+g9jff8UKZkV80ottcT0qgNuZ91sD0z9MANzp9 xyzg== X-Forwarded-Encrypted: i=1; AJvYcCUCGwOSZHCHpZ9Hwhg5bsnW6EC4V8+uCfQCBYQ7tz2bsiWPjyVupcsCPTVIwO3oTuk+9kxZiWv+peKumQ==@lists.infradead.org X-Gm-Message-State: AOJu0YzWMikelE6EhNoD4JnrZPG+beHM83dnOAktg+0oFzxGbGPjgrQ2 tzNd7xHKtZMRRqcR37W63VaNSwQqPxT2c2/V2NnTjqxMVCtxe/q5pDLQfQk606o= 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240827_224948_122500_8855976F X-CRM114-Status: GOOD ( 11.99 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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;