From patchwork Wed Aug 28 05:49:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13780680 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 3031EC5474A for ; Wed, 28 Aug 2024 05:50:36 +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=gI98YrTKS+SmGurGN10p1Qs0VsOzZayk2DI9TDSwrNg=; b=kM5+5heAKOWmNG FCALt5D1lEmogGf1wkFnx9vvBEDvn4wDvUsJal21CT7QSm0Ed112PkwPsfIJbFuoDK5pKIgAMPDOX p2QsC/fi0wWR7JXvNb7TQ6tT+YtKnorgEzE0B9ubA1h4xbzEKaZx2OYd9HmmJEB5bZ5qUAr/IcIGM +AMla6qNoP0gNk4ukUNjY50tTC6degn6LN5Wn+VGDfKYf3gbjZ9RIUaXVlYcDn3rg66VLxV/+PYqM XqF/XbKHJPXkdwzNHJnZPLyFyRrS+Od5I1plJGleOYiiXApud97G1bjhSZ2iosVI6jrsoicymJ2OZ 5PkeGs5eID1AZDdAWMLg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sjBZg-0000000DyiA-3JIE; Wed, 28 Aug 2024 05:50:32 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sjBZY-0000000Dya6-2Qi9 for linux-riscv@bombadil.infradead.org; Wed, 28 Aug 2024 05:50:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Sender:Reply-To:Content-ID:Content-Description; bh=74ih38qyFApS59Oo5hAHcKEdd4ieUrnz9WHar/pXDMA=; b=DpU5ujsBqp1rSj2t/8v3Mgrwtu RjR8fz/oB3DmRXbZ6Co2wvb666sDcSEsrLg9bP7U4mUarJquTWvad4Jw5FaA1jcu23Djb3te2huZH aaxeezTuCD5QXnbWkOx8uHM/XYMpUq+bOeq0xqqyiURxI81wptEY3Bco6hzBsC3ModxXmet7dBJZ6 dHSewKMZQ1VKKUCpwSbiDSHfwpxawf+BJVvjnlHqC8unXlLfoTnE30pmJSH8ZTyVA1uzjfHPASpUb zL+/+kX3wzfgEHGcdPOf00iSk3f3UvC/v8qRtsgFL7lEUQCJHnYCNsUBRqNdkqL5CP9xezqfcoM2j 3pjv5VEQ==; Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sjBZR-0000000B30c-3jEt for linux-riscv@lists.infradead.org; Wed, 28 Aug 2024 05:50:23 +0000 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-2025031eb60so55565605ad.3 for ; Tue, 27 Aug 2024 22:50:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724824214; x=1725429014; 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=74ih38qyFApS59Oo5hAHcKEdd4ieUrnz9WHar/pXDMA=; b=rq5fx3XaZQVFBfbUmBlNSo95ovfv5Ia1J+gul7R2x3SpssvSBEx1KqZp6w9jHApeD0 Xnc8+CADo5AqQlpUPULP48oYIb52IfQzoXmhMz3L5mnmkVBBS9VzVDK+vr7ZxF44E2Qb Vrk1Mu/PEbv8IkAhQRKyl6Qz9aho5MqbrqQkm4flNHAmwRk0Au+HQ8uFFGIzMj/HxLjk D99kztI63It1FQUe2/wyNPQDOrpDh+ER4PaD8w3cRf584a7Q8DvVokJnuv0oOK8A+F7r SwdTvKeSpjYWBfaXtWeComqgfFbHaXBoQSbKtUe2b2/bPAcJoUqb3o7DZUx+l4G7+7aQ aHcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724824214; x=1725429014; 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=74ih38qyFApS59Oo5hAHcKEdd4ieUrnz9WHar/pXDMA=; b=OEECzc5LCUK2ztca2HZQ4hxl4a/DvMh8Ot8mk/agSRvoale55YY9Z+vPYL15+WAvTX s4U2/sCr68Y3odfOa4d2MWtAuGPD60Nrt6zEH6+p7kHk0X63msZyzwIh9SJTJu7mjD15 CB2n8Yv5cVkkzXwmHIg1GTtt22hFkpTX4yn8Q0CUuejS8qdlFdlKGIQy6Irvdb4RFe7r i8WgPLpFBHySRE7wA9OkciTnpdg+C+XTxoj6z1MCLxDw+MDwBt9ITs16TCb4m9FcmDbj XzXqWdx0q+Nc2I9I4KQ40Gz/10EUsTQ9NaJ7156doOsLDsaM0wrcLDMh3w2DfIma6dfV 7gjg== X-Forwarded-Encrypted: i=1; AJvYcCWRHh9fAs9QQAo79S4KAUlPFOOajjEItL4ngIrdOx4w0Ao+v96Ua0JIexzYrQPp2/W9NiZmUgA0SMLDQQ==@lists.infradead.org X-Gm-Message-State: AOJu0Yw/imMO8d/9DZEz3ZJxdtskxElsm9DlVK/KzqfnFYoiwAF+bXPU Rm30u5inCy885qSYqZJ4ABvev+vrQVG1hS1YrTxPMGCHTRh+FYdFl1HkMNe34o8= X-Google-Smtp-Source: AGHT+IHaxH8ov/UqUPxBA8x0bmmHbs3R6mKOF+WDurSlvopgHqFjxqmjotSQ0dAp9h1od2RsPmTDOA== X-Received: by 2002:a17:902:e852:b0:200:ac2c:6785 with SMTP id d9443c01a7336-2039e44cbcdmr164066655ad.3.1724824213959; Tue, 27 Aug 2024 22:50:13 -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.50.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 22:50:13 -0700 (PDT) From: Charlie Jenkins Date: Tue, 27 Aug 2024 22:49:20 -0700 Subject: [PATCH 14/16] sh: mm: Support MAP_BELOW_HINT MIME-Version: 1.0 Message-Id: <20240827-patches-below_hint_mmap-v1-14-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=1729; i=charlie@rivosinc.com; h=from:subject:message-id; bh=RSW/tCXIl3OqIq1wugK/BMhqzVxC+hGCJaNgaxgxyH4=; b=owGbwMvMwCHWx5hUnlvL8Y3xtFoSQ9q5XYlVP75VR006aZFn+70kVT1K4PGO6plPeD6ttY1Ib fZuvX6uo5SFQYyDQVZMkYXnWgNz6x39sqOiZRNg5rAygQxh4OIUgInsXsrw34+bSWfTiYerug+W bJm2uPHhi6ei0zVPGCvcutghUP70ggcjQ8uKDy93HJCN5MpSDQ5Y9+eF9/TONIm5nufepW33SA2 /wgMA 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-20240828_065021_355705_1653A145 X-CRM114-Status: GOOD ( 11.72 ) 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 mmap by restricting high_limit to addr when the flag is enabled. Signed-off-by: Charlie Jenkins --- arch/sh/mm/mmap.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c index bee329d4149a..867f6598b7d0 100644 --- a/arch/sh/mm/mmap.c +++ b/arch/sh/mm/mmap.c @@ -91,6 +91,8 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, info.length = len; info.low_limit = TASK_UNMAPPED_BASE; info.high_limit = TASK_SIZE; + if (flags & MAP_BELOW_HINT) + info.high_limit = MIN(info.high_limit, addr + len); info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0; info.align_offset = pgoff << PAGE_SHIFT; return vm_unmapped_area(&info); @@ -141,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, info.length = len; info.low_limit = PAGE_SIZE; info.high_limit = mm->mmap_base; + if (flags & MAP_BELOW_HINT) + /* + * Subtract (STACK_TOP - mm->mmap_base) to get random + * offset defined in mmap_base() in mm/util.c + */ + info.high_limit = MIN(info.high_limit, (addr + len) - (STACK_TOP - mm->mmap_base)); info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0; info.align_offset = pgoff << PAGE_SHIFT; addr = vm_unmapped_area(&info); @@ -156,6 +164,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, info.flags = 0; info.low_limit = TASK_UNMAPPED_BASE; info.high_limit = TASK_SIZE; + if (flags & MAP_BELOW_HINT) + info.high_limit = MIN(info.high_limit, addr + len); addr = vm_unmapped_area(&info); }