From patchwork Wed Aug 28 05:49:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13780627 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 AC4FFC5472D for ; Wed, 28 Aug 2024 05:50:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 355036B009E; Wed, 28 Aug 2024 01:50:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 304EB6B00A0; Wed, 28 Aug 2024 01:50:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 17F186B00A1; Wed, 28 Aug 2024 01:50:01 -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 EC98E6B009E for ; Wed, 28 Aug 2024 01:50:00 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 6939DA1CDD for ; Wed, 28 Aug 2024 05:50:00 +0000 (UTC) X-FDA: 82500578160.27.165104E Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by imf01.hostedemail.com (Postfix) with ESMTP id 71AAF40014 for ; Wed, 28 Aug 2024 05:49:58 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=mkPmlJJp; dmarc=none; spf=pass (imf01.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.214.172 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=1724824101; 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=YNQglkp2lEnIf2YsbVUEYoAS4AW64pe58tBCUjsMipk=; b=wwIFdmFaSyGXX9Xc/5+lo93CFPKY2dr1aOQpyd3DcTwh2Ah4vsxYXKVbADlDVCG6drjWwo zbu2XR8ayhrC5YP6utq8rDBJgskBerYnpkvcf0WdYpTixUwsKjOhU/rEjoP1He2enATGNX lLVdQKq4XYKiRxXZ4wkOApLpabzjeM0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724824101; a=rsa-sha256; cv=none; b=JbDd5VIdb91sTukhHdgznVmoyw5hxULwG2yytx2ypLxC9+ttGMUtI7xK3HjkYBIun1PxgO amyhdZ//yaTsrPfexIqkQYFVgFjlAmS4f8vpt/bGbnQ0kp0kmYpcMcYl/5Scj3CKhsN4Lg s5A7yxUijc+doKrhpHzvFPOahQrwv2I= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=mkPmlJJp; dmarc=none; spf=pass (imf01.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.214.172 as permitted sender) smtp.mailfrom=charlie@rivosinc.com Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-20202df1c2fso1730705ad.1 for ; Tue, 27 Aug 2024 22:49:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724824197; x=1725428997; 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=YNQglkp2lEnIf2YsbVUEYoAS4AW64pe58tBCUjsMipk=; b=mkPmlJJpvyv40A98N9H+Pg0t8Uatlpn6STaJUiGm+rYpfK30cukRkzEFrPrY4hqj2i lftgRKxDrDe97VQ/qNCEDjeJTQgZlSeaTIk+ptelDKXm9r+JCPZ/uesLnabhM1QpZaGc Lwvq6s39LtfSRIGLp8tezCGN1WIbRBFyfln+3CNYz43K7b+E38mkx8nI36ZDtKXPo2en HBGp7pfsTR9uPb8Xyg+kGw5tFGc4uvkTbgpZsIeh2oNYHz9++uhbv0vqn7jvkButFkIo 8Bwdfwz2SiECSFtapRyLR7ukXAYG824BavZIVN2OOl/1sYbzhjpE2wG7EG0rsKO4OvIq Kvlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724824197; x=1725428997; 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=YNQglkp2lEnIf2YsbVUEYoAS4AW64pe58tBCUjsMipk=; b=Z+5cQkWAAtkmci4HCyxtA/UQvulrjzO97F/MbnjibQcvtBe86PcGhraB+YZOMBKwWX 7vJuLlZgIDXPc97mAj9m+m+SmDlT7WxpoNhVl7l2fha/11GpbURCmuHLbfgItqVoyUL5 j0mNxSQHhC6ubt1dlzahnLU95ftqfEEQrCHykqFboNQo9EYAG63PI5HQauGjXo8NWtmb R0RtkU5TEC6lcNUgP3l8D2TA3Q0jcirsBKWSz6PfPcLT0LQ/wr7CB5zIUSmKKWOcjGow MO88VF7GtjGsVcO5HdnSMnVWgdlBQHdbIGl50+7YWtQ+ZeuPomzGFGOJ2elYrjWm7NKx izpg== X-Forwarded-Encrypted: i=1; AJvYcCXRKkh9ZA/6v3qb7OuZXQAPfq02sKpjLL8WgUA7p2XpkJ/PnRp4oE+yXekVVqbTsYRNquCsSxo0Qw==@kvack.org X-Gm-Message-State: AOJu0Yy9w0emq2LoPib+ZSdUvz/3fT/YVFNa0WbnDr83DiNtzAe4bYm2 b+eQBHiyOxO1B9fHJ1V4v90DkJZVYYTFIAui8PhiP8JAtCDLx7wuk1DWyhwNMDg= X-Google-Smtp-Source: AGHT+IFNvFc3w8ZqIqMUtm2tpVZkKTF+VkfsFh2Ia3nc64cPU9VogTthyuHsPbt4BWtQWf7nibqVyQ== X-Received: by 2002:a17:903:35d0:b0:1fc:41c0:7a82 with SMTP id d9443c01a7336-204f9912733mr19643175ad.0.1724824196945; Tue, 27 Aug 2024 22:49:56 -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.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 22:49:56 -0700 (PDT) From: Charlie Jenkins Date: Tue, 27 Aug 2024 22:49:15 -0700 Subject: [PATCH 09/16] loongarch: mm: Support MAP_BELOW_HINT MIME-Version: 1.0 Message-Id: <20240827-patches-below_hint_mmap-v1-9-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=1259; i=charlie@rivosinc.com; h=from:subject:message-id; bh=mXZWgvc5d3nCYQqiz9PUCvFecQkJ9kp2ZooPsTsZSyA=; b=owGbwMvMwCHWx5hUnlvL8Y3xtFoSQ9q5XfFl5t2npeO1W6ydtL9v1qitmfF53Tr5I+FmGy5eX hv8Y0JgRykLgxgHg6yYIgvPtQbm1jv6ZUdFyybAzGFlAhnCwMUpABeJZGTYs2fGyX1L7U5s/pDP 9zI7cOPnH9u8t8ZNYFCaqKg8I9+uk+F/YeihTo3z92Iv3r2a7r74pUGE/VYuj+S6OkvJ82tdPk5 nAgA= X-Developer-Key: i=charlie@rivosinc.com; a=openpgp; fpr=7D834FF11B1D8387E61C776FFB10D1F27D6B1354 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 71AAF40014 X-Stat-Signature: mdddaxc81dwtgeqjp3s9ch3r53ree7db X-Rspam-User: X-HE-Tag: 1724824198-572794 X-HE-Meta: U2FsdGVkX1+UQsnCtVtn7/hwlZkY6FtOkd0dCqkcGSnpa86GkLXS1Crm42IadRGEmSdPA8Y4TrXbvLgG/NRiF9+7puMLUE7U8wXNEuheb7H02fdNg2zWbkpHDV2e1vERgzduhGMcyEWufsK8YQjwbj3F/xYsAP2SzFadHp3xpPb2F1PP78w7lKDM7GuBY7bevljptISG+hA3eLBciZmw2LzQJSuFln4YzDyOz3RvgtGJLaJWsgA25zlMA3h/o54DBu+nIevnI7N19JjrPIpaOyZSgD+WjowzxnM4feTtS6QvI7AaRlhsTO+2IgCPvybBDKcgQkKPm5cP9xjB/faD5Ulzjn8GVEFWK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ity: Ham, tests=bogofilter, spamicity=0.000093, 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 mmap by restricting high_limit to addr when the flag is enabled. Signed-off-by: Charlie Jenkins --- arch/loongarch/mm/mmap.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/arch/loongarch/mm/mmap.c b/arch/loongarch/mm/mmap.c index 889030985135..66a5badf849b 100644 --- a/arch/loongarch/mm/mmap.c +++ b/arch/loongarch/mm/mmap.c @@ -70,6 +70,13 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp, info.flags = VM_UNMAPPED_AREA_TOPDOWN; 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(mm->mmap_base, + (addr + len) - (STACK_TOP - mm->mmap_base)) addr = vm_unmapped_area(&info); if (!(addr & ~PAGE_MASK)) @@ -84,7 +91,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp, } info.low_limit = mm->mmap_base; + info.high_limit = TASK_SIZE; + if (flags & MAP_BELOW_HINT) + info.high_limit = MIN(info.high_limit, addr + len); + return vm_unmapped_area(&info); }