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: 13780663 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 941E6156864 for ; Wed, 28 Aug 2024 05:50:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724824206; cv=none; b=cdGofTEmTsRRqk7OIeA5Kp8xJQ1utQuDEaNtDqMrWU4qHsGl9oeRO1EZH3sNnKmXMlGkUlsEPFFqhG4Kqg1d34+r58JnTUNe+8qdPRSCIdB66UJjwQVLFFS4LtTmNzyS+J5BDwmQtV0AbdOLhrQ+SJMJt6h+ts5NiXAKawBtCXw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724824206; c=relaxed/simple; bh=hr+5sO+DwZ7b30hixHrcXcBJzkXJVKP+oyQ8pDF00F0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ry6iF35+IoLvPOU/T0uo0hQMbp3Gu0PtMDO1dtie9CxMkk7d3ab7yDMxlQsVK+wzPtSMk/qFoZRhQ68UmWxBw/FWqBB/8VajTqbyCI7tvikd4lE7q1OJakzjhenF3kHrPw25OOjlAL8w+WNLg15pjTUubWzSTDnUg7z/msN2f7g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=i/DlY6+9; arc=none smtp.client-ip=209.85.210.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="i/DlY6+9" Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-714287e4083so5645103b3a.2 for ; Tue, 27 Aug 2024 22:50:04 -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=vger.kernel.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=i/DlY6+91BMwTMLrYCJbVrcsqFZX5TnuTZHdn7NHW6At73EUQzp3275EVaiQksc5No vSTIWqYzrQ14jtlswG2T4nYXlWQ+MWlPGXU/p87qMpaYyfc7ZelWr/GtjOthsyv7os90 Dt+Z2YTG6JQhRMUUEhYFJskIOslQztgaORA88y5sC9rHSb4vj3FZ+38OSUr7kjxg6dQm hHxlp7lp86xhC/859VTr5zUNMiHlfyL6rGszjGb51NgKxLOi4sctT08v8n+awHu6AzIt 5MEMK/Jcm1TtIapG517Vo3XumP3cbGVg45eVwwd3IaH//US1cKHPD77lAo3rt73Rzq0J KLiQ== 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=XORBUjFZUQhylLLqco0Fvg8rfyBpGwGKpMi2pKHTwlLdDxq9kdLOQuw4S5016A50eL MeFhnTdz4umobXM0G0+9yM5V8aUiw6yUCEf9OnETc8TUaSCWdKlf8/SJvhtxzjNMS14D PY9dVUsNQXp5/e0yGummYmduzLMVnsp+lLS4mvhZTzvgtcMlveInk4YQkfmRHtDh3Hv2 3en0HsOAXExEPTDS+b9cMzGgSUrviEanbKcY340Ggf0QGMhYthT4d/QGW5yIp3aP0Baf oFtmjUZ2ipnRLpMosZccfOF7qAub3QGw3GtqoBBzVov0l++7ZbcuVo77AxG3Rxl2GoWR rNAw== X-Forwarded-Encrypted: i=1; AJvYcCWCeDOkhaDKIUI8JzfSUlO0NPIw9V8/uItljxxTumGvYQbduYYlGxHSuPLbB2L2QaeBtDpmQLB0VQ==@vger.kernel.org X-Gm-Message-State: AOJu0YwYG0hCVWKiJ/HXzxi5MRQ4nFBS8PmjXmQDF+/JwN304XuNs385 YjKmf3pSdx1/ChJCjbr0Df3SdHSly/f9XWojXNNR6Qs3xxqxnNXddwoouJGnJqM= 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 Precedence: bulk X-Mailing-List: linux-sh@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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); }