From patchwork Wed Aug 28 05:49:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13780629 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 431B4C5472D for ; Wed, 28 Aug 2024 05:50:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CA3336B00A5; Wed, 28 Aug 2024 01:50:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C54786B00A4; Wed, 28 Aug 2024 01:50:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AA8326B00A5; Wed, 28 Aug 2024 01:50:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 8862A6B00A3 for ; Wed, 28 Aug 2024 01:50:07 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 471EA1C603F for ; Wed, 28 Aug 2024 05:50:07 +0000 (UTC) X-FDA: 82500578454.18.81AE56A Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) by imf21.hostedemail.com (Postfix) with ESMTP id 4C7771C0007 for ; Wed, 28 Aug 2024 05:50:05 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=zVSxkCp0; dmarc=none; spf=pass (imf21.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.215.181 as permitted sender) smtp.mailfrom=charlie@rivosinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724824140; a=rsa-sha256; cv=none; b=mjtnLzpdCPMNMhEwy2HYcajMt5aEzoBmIEMSnm+jw9HgPR+MGbQoWLHJijBOdmdM/Svoa/ H8KM3VE/ebKBzWutQop/5acSTe1BLZKlqbWIYjJkPP5omkp1bhsjjdWePYwNNSKdp1IUEF caT1Hq2EYl/O/WriwHSPTVPbTrjTsf0= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=zVSxkCp0; dmarc=none; spf=pass (imf21.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.215.181 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=1724824140; 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=cPn63wqFJg/NhDtyE6TA0coeolvG0b692sVkrxs6h6w=; b=QjeLcBdgyIBVh5DCArLukbkWBqCb5oFFhQaT3c6H1Syyi6GcldovTGIel+AAZLOAMG8Qxx WWws/dsShHaee7aeAaKde1cbOyZRk60DyR+rwlHbiFE7J+sCoXsvUPS2v+p2EzCXmkX73h B5sxsfchgOuvoW4pWle0ZCdMVzFk13E= Received: by mail-pg1-f181.google.com with SMTP id 41be03b00d2f7-7163489149eso3858573a12.1 for ; Tue, 27 Aug 2024 22:50:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724824204; x=1725429004; 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=cPn63wqFJg/NhDtyE6TA0coeolvG0b692sVkrxs6h6w=; b=zVSxkCp03iFGmaWKpn8G+LVsVJT4d3xRbEM9Lj19/2F9ZFXM6NLMKFiIWUlyu11OMN OjD4oftvGr56cJ15uqtTR/jANPRFdqYdGSEg3pETUJ6D5YKa02WLBfoSxnGj++0x90pH YBjvtPefjI6C2LdC5g7yHzE/cixOZQtmKap9e7RjNAiichtjoaL20yprnI74Fh5dJ4zz qOumD1WtFSwFQTAKrZLKmeRNGEqUy5Z//xYboYTp3LEwXqwigbpF5NIqjdv/zIG6ELbk 2EPEmGB+B9xYO5G6uoBDJ7iWe6JR1bhqm91vSLH2f/jjeaGIwVZ5PsE3P9rgaKME6i6g +pxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724824204; x=1725429004; 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=cPn63wqFJg/NhDtyE6TA0coeolvG0b692sVkrxs6h6w=; b=hy7DYZL2QLOF5ZujV/ReVTfsoptYd123yiC7Ycnk8DPyXZOr2oG+QGjz2ZX3jinoCS 71AwPgBgaUUERBbBWr7WQmVWHnFGNErZ5UAvHmygNik+lJMtFnQJfBBuwbhmVuUXHIin RTDVPaiHhy1guAazEBKu2uxe1ojvUF+SH/vdUf9Gusapa0rUPr5k/kI2fk/Kkss/LdZq jraJdzPEI+o/V5S+HGLPZRc7zQrWFKm7F2Cxww5iEJEyc8A4oDahuvEOp/jwfeo2dzkM W24mdNVnU+xt3Yw809xEchdzfQcNVNDTUfTY7oerWdll4PfP0DPIntKziC+sGq28SvyI WOUw== X-Forwarded-Encrypted: i=1; AJvYcCWm/mVZrFStOhB006Sf9VvIfMNdXnoJMQ1lv8LXhF6QcMvB6ADVfJEtLaJ7D52wFciLqWaANitEXQ==@kvack.org X-Gm-Message-State: AOJu0YzJ2E95yul/b3IoQkvCcZmeyFstT0bK2O4Kw5eGjClt0+lJyNC1 jPHYHvo7oVX40bHFK32Ai1WYgr4KMXQTC16unvm9ytBICbFdF5erAHOw5uUoxA0= X-Google-Smtp-Source: AGHT+IExz2l4cJy30WX6CK7UJnnTV99XpNodRNjqDrqaX9iShx7VT4aEy+MVWDHksfv413xg6BHqWQ== X-Received: by 2002:a05:6a20:c6c1:b0:1c3:b61c:57cb with SMTP id adf61e73a8af0-1cc8b63e7admr19641639637.53.1724824203730; Tue, 27 Aug 2024 22:50:03 -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.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 22:50:02 -0700 (PDT) From: Charlie Jenkins Date: Tue, 27 Aug 2024 22:49:17 -0700 Subject: [PATCH 11/16] mips: mm: Support MAP_BELOW_HINT MIME-Version: 1.0 Message-Id: <20240827-patches-below_hint_mmap-v1-11-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=1222; i=charlie@rivosinc.com; h=from:subject:message-id; bh=hr+5sO+DwZ7b30hixHrcXcBJzkXJVKP+oyQ8pDF00F0=; b=owGbwMvMwCHWx5hUnlvL8Y3xtFoSQ9q5XQkfk1qWxrKnZbieZ1K/6LSwKGjL0hcztOaE2KQe3 3vFh3FJRykLgxgHg6yYIgvPtQbm1jv6ZUdFyybAzGFlAhnCwMUpABMReMjwm1XqYMYTd7kZ029e Ywn89Unq1bGI6TwyXnVzFq65HWqvWsnIcHriXK9fRsZbv646duvxv8pFDmYGX/naxDT1E9+JfDu ykAsA X-Developer-Key: i=charlie@rivosinc.com; a=openpgp; fpr=7D834FF11B1D8387E61C776FFB10D1F27D6B1354 X-Rspamd-Queue-Id: 4C7771C0007 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 1sseceifpssaomcy3x4h5sxaperrhw9u X-HE-Tag: 1724824205-413365 X-HE-Meta: U2FsdGVkX19HR9fiRIHazRsZuI1UMF5Hoj2rlSR83+7xcrOVAKsSG7pdyEF2ZRxG1/Yzdoc6PNL1y8Kh8rJwzTR+ndWgX0JZKXZWTlaoEAx4UAyfobW/W/Q1iMLK+jzJNHEBShJxVbshG0S/qv+ij+p/DcvCwffSx4MxzQ9rnkikHGZrgRfrHcaRyKldb5Jge5AgZL426SJFK4xYiZf8scQDr65pnnMFBvuDpAX0OwHcVumJKo5fLy6genTimMC6rUUtHafHGE3uLM2d0g2zLbg+s3mNCGQGpzJunL0p6i0sIHq0VXM7NHw3/XU5qhJo7NVM6sKdOFHPjWI76grVyFQXahaI7xl/llu2xOsQCXKkxVdU8B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ofilter, spamicity=0.000002, 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/mips/mm/mmap.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c index 7e11d7b58761..1595fda284cd 100644 --- a/arch/mips/mm/mmap.c +++ b/arch/mips/mm/mmap.c @@ -79,6 +79,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(info.high_limit, + (addr + len) - (STACK_TOP - mm->mmap_base)); addr = vm_unmapped_area(&info); if (!(addr & ~PAGE_MASK)) @@ -94,6 +101,8 @@ 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); }