From patchwork Wed Aug 28 05:49:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 1977636 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=mR0iZWHO; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev+bounces-642-incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wtwh13vk0z1yfn for ; Wed, 28 Aug 2024 17:16:33 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Wtwh12mwKz2ydW; Wed, 28 Aug 2024 17:16:33 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::62a" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724824172; cv=none; b=BqJyb9Tt5ztk+C5U4Dqwo5zQUABXiMjuZQ/2KZPukdl4tU4j/Uhal537LriqOeJMu2MbZGg3wjGnY4EDkoNdQiUd3tq45HPHvgR31yM996wXq/dyHKSrbtDVFfOrgjDNkqvtBr69yYflvWxr55ngNNNyVcDc5VHG6fnp7CQ5mQpmi1/glmn8aslZ8u4FxLov9Cep2Yd+T8hKm7nLtNWNx0vonJsOVwojBMdDmp3Xq9w8RD3FzHJthI3YP7OIBGEfEB2INv7v2QL+Fjxt5q7ul4mbAbIV3+a9XU+kvdouUSonO2UwMxRNDDhCQtVyhljrqLbMk9v2rMZtNAX3YooHSw== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724824172; c=relaxed/relaxed; bh=s842qMNTVJPdnaHjTgUH53HGzrqC8L35w1DIbWpmxjE=; h=Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Google-Smtp-Source: X-Received:Received:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; b=G/CqX89a/kHY3G6R/7k28cehvjEoUEMH8NTRKI7Nl9dm2vNloj1nb6b5MFB7ksf8w61KmDvuM+yjDmMfmoA7632kPc/f2wepFraziDJOsL1nOEpGjGXBYGDKpidDTmlumS0ilNMKHk82keXnC3hYqkNxvVwe/osSa6d4lCAp/tqux1vk79CH0oAilSB8yEIlYS5NQfvHAMhay+rjtIWR8lzyD7uHFFFhCwAxLZvVkz5YwhyMnGt7lZ+85CBK30Y1ViZKMTzZ6Cee8dFwNDBTrQItPUQQTxrNlIkVSHAkjrS2+buJT89fMvgrR3C8KUZgqb31GNQgsPwJbb4Cy9xSDA== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=mR0iZWHO; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::62a; helo=mail-pl1-x62a.google.com; envelope-from=charlie@rivosinc.com; receiver=lists.ozlabs.org) smtp.mailfrom=rivosinc.com Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=mR0iZWHO; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=rivosinc.com (client-ip=2607:f8b0:4864:20::62a; helo=mail-pl1-x62a.google.com; envelope-from=charlie@rivosinc.com; receiver=lists.ozlabs.org) Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Wttlc15GDz2y8l for ; Wed, 28 Aug 2024 15:49:32 +1000 (AEST) Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-201fbd0d7c2so52360485ad.0 for ; Tue, 27 Aug 2024 22:49:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724824169; x=1725428969; darn=lists.ozlabs.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=s842qMNTVJPdnaHjTgUH53HGzrqC8L35w1DIbWpmxjE=; b=mR0iZWHO4flXnMF3dNX6lTSbTu8KWPO3eeMrw/PzBGPMOiM/4PM1RE2dQMuVsMsMNA 5YjfLyCbh5qRtT5XrDnoyRVQ/zmgCA2mFh48S/6wY+3jzvQ5tas2Vz9xdDwuaGt/gOOB ehx3lCNgGgVGOb6Jc5Hu3EOe9j8m9tuldXdVtLtZd2ZEYFg8I2vXug9NFsEbNKFC2y9j eM3qnZvJ9zsKjwFi6HR+1fG5+HxayxY544lxqxVusPA1Tm/x0sqR9msZGn6PwgMWGxMx Hz07cK9Eyb4x6h5tEE71xbWF250ZuJpxl78mYZlwlUUlwWlxdJxIEC9ZkWuqc4mOUIHc owMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724824169; x=1725428969; 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=s842qMNTVJPdnaHjTgUH53HGzrqC8L35w1DIbWpmxjE=; b=o5ykw2lGfsywtgO2oF0UziWvRFNIz9bBg96BLLunuO1nNYC4lQEgyON1fLCExlIIve /YTRu4VoXGtiD/H+YNc4wGI2RfyBHd7hnRE13JydT+pnmjc7Rx8kL7joSW3Alzv5/hyW QfZSvQRHnAHav3XAhckU5XJvognOKO76E3oPC0ydRxUENCafBi0OYAa5qhxFwC1Y55VH CgjVevBvRVWbNWLqOjYxImTRvFUy/wz1UQgYQc1ILbnIgdsiz3RVyWDaKzPSDVqgy9Gh M2FOrBcKglgP926psoGXFzTjrBpIijdFE1/TrTLdb36kBZiiVbDKEBB3GfMkMuB+WScN OLJw== X-Forwarded-Encrypted: i=1; AJvYcCWpw0fyntA7kDHOI4aQrDN4/H0c294nIlkNExYiGerHgHLH6oNpGq7I5UHnOwKTVzEUMh36GRdw+H6RjH8=@lists.ozlabs.org X-Gm-Message-State: AOJu0YxhrHefgVs5lyhETOURcXwU3n34xbqa7Lp9KIrTPEHVjY5TbWYa vE6ZNBJHW9Ph2e4Zx2leN0wTjXLbDdvUQB0dHNaH7J6AsDyF+MhHrUJhf0uFcfY= X-Google-Smtp-Source: AGHT+IE7iBIF/ncsUM+UTT7p6QlENkfnsLUglL71vzMDiTXQo3W/0gxhDidIM3IPRiHs8W/EU5lCPQ== X-Received: by 2002:a17:902:ce83:b0:1fd:92a7:6ccc with SMTP id d9443c01a7336-204f9ba22b4mr11347335ad.30.1724824169192; Tue, 27 Aug 2024 22:49:29 -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.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 22:49:28 -0700 (PDT) From: Charlie Jenkins Date: Tue, 27 Aug 2024 22:49:07 -0700 Subject: [PATCH 01/16] mm: Add MAP_BELOW_HINT X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Post: List-Subscribe: , , List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240827-patches-below_hint_mmap-v1-1-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=1656; i=charlie@rivosinc.com; h=from:subject:message-id; bh=tmMz4K99F0U2eFjTmXZPsRyQ5BJlKhVYtlPfqgJsjxI=; b=owGbwMvMwCHWx5hUnlvL8Y3xtFoSQ9q5XbFSzP1yPpXBlYea467kRPvaspyLaj1+ty58k+rfy b+vtHB1lLIwiHEwyIopsvBca2BuvaNfdlS0bALMHFYmkCEMXJwCMBGZFoa/UreElT5ecG2dxnH1 4+SJG05OW30u9uBl4X2J5vXXMs59v8LIcOvZs96dRZxGwS//rJlxOfEru+W5B7X39RYcjRI4YV7 3gA8A X-Developer-Key: i=charlie@rivosinc.com; a=openpgp; fpr=7D834FF11B1D8387E61C776FFB10D1F27D6B1354 Some applications rely on placing data in free bits addresses allocated by mmap. Various architectures (eg. x86, arm64, powerpc) restrict the address returned by mmap to be less than the maximum address space, unless the hint address is greater than this value. To make this behavior explicit and more versatile across all architectures, define a mmap flag that allows users to define an arbitrary upper limit on addresses returned by mmap. Signed-off-by: Charlie Jenkins --- include/uapi/asm-generic/mman-common.h | 1 + tools/include/uapi/asm-generic/mman-common.h | 1 + 2 files changed, 2 insertions(+) diff --git a/include/uapi/asm-generic/mman-common.h b/include/uapi/asm-generic/mman-common.h index 6ce1f1ceb432..03ac13d9aa37 100644 --- a/include/uapi/asm-generic/mman-common.h +++ b/include/uapi/asm-generic/mman-common.h @@ -32,6 +32,7 @@ #define MAP_UNINITIALIZED 0x4000000 /* For anonymous mmap, memory could be * uninitialized */ +#define MAP_BELOW_HINT 0x8000000 /* give out address that is below (inclusive) hint address */ /* * Flags for mlock diff --git a/tools/include/uapi/asm-generic/mman-common.h b/tools/include/uapi/asm-generic/mman-common.h index 6ce1f1ceb432..03ac13d9aa37 100644 --- a/tools/include/uapi/asm-generic/mman-common.h +++ b/tools/include/uapi/asm-generic/mman-common.h @@ -32,6 +32,7 @@ #define MAP_UNINITIALIZED 0x4000000 /* For anonymous mmap, memory could be * uninitialized */ +#define MAP_BELOW_HINT 0x8000000 /* give out address that is below (inclusive) hint address */ /* * Flags for mlock From patchwork Wed Aug 28 05:49:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 1977637 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=T4Bh5nkm; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev+bounces-643-incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wtwh75grtz1yfn for ; Wed, 28 Aug 2024 17:16:39 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Wtwh72gL0z2ygG; Wed, 28 Aug 2024 17:16:39 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::62b" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724824176; cv=none; b=SPR2FkVGaZpVGGGyJM8iFYPPOyXKA9hIE4eMyqZmO3Gc00qCpDNN8ijLMdYiPmgl8Uyk8XLF2CgUpSgoHTc69AzYUWTaVTmWIGmvHOEVaN1K+hWfjMVb6ZEZooYJ6lIQKth/vgIpALY4yv3BIimcAtKaHEVb2Eup6GtRYGNG/3Jf1nvGUtiUELTaMU0ECkAEqsBNntGrKYHTyYBWJUpyp8bYdQyhEVqUpug1TybfUIZjBznSvcNVr+BOd+0mdNviFZtIJ80LqdYSiK1cDc1hc3+mhGrlAZw6yLV6iuQOUxem4JI6jk4KzDqFHrPFhKYExE+FachYHbX0avqgmZVO1g== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724824176; c=relaxed/relaxed; bh=moiMY/9kOk6Xzt0Khn1FkF8wyTL4BDNBgOSp+BMugag=; h=Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Google-Smtp-Source: X-Received:Received:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; b=GNnpefCBI4eTSLL3+rPrs7y7ilLjBfaUrxlxkNbJqiyxv9zu2BEd8Set8oYNE9QkoBg7UAqQ57GeBSS2+d8XDP9I58qjOSypFSZ9fejdBF4ZOyOcomeGJW+5+hzn03QbpUDoe+nD6Uh2MfRL6A4fojQWwNzZ/zgewg5m06iV+9qgIJoOPLIII+YphlQl//waB2qUdmbyAGRBKJMIcZR5/wGJCG2VWxikYf2rf6WmzhqsRtBZu5XqDZjMIE+2f8wR/oHOeVnMYGf6+m01UW3k+zrIK4/rdjNEJqR9XwdxfK362OjL5GGVIe1uA6NIxPXwKzl2F7KIevHY0z++r2w0Lg== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=T4Bh5nkm; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::62b; helo=mail-pl1-x62b.google.com; envelope-from=charlie@rivosinc.com; receiver=lists.ozlabs.org) smtp.mailfrom=rivosinc.com Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=T4Bh5nkm; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=rivosinc.com (client-ip=2607:f8b0:4864:20::62b; helo=mail-pl1-x62b.google.com; envelope-from=charlie@rivosinc.com; receiver=lists.ozlabs.org) Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Wttlg5jvVz2y8l for ; Wed, 28 Aug 2024 15:49:35 +1000 (AEST) Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1fc47abc040so55315415ad.0 for ; Tue, 27 Aug 2024 22:49:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724824173; x=1725428973; darn=lists.ozlabs.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=moiMY/9kOk6Xzt0Khn1FkF8wyTL4BDNBgOSp+BMugag=; b=T4Bh5nkm0NQrsPGxypGVEv3YSSCLQJiQjsnPfntgqiVSsDyLJo0mE8Zkyks/dBnJkF J4d7LxqvhQ7kGL77mcQXIFgpzDhcnLIRYHUtvMULt00d7fs9LQSM/SVIijlr5yQ4us4F zYPkkm/svDiK7wCxyI+Eg5CBTnyVgYdSI9+UA0/J+ZdohO9H6wqwRyc63irVXMQeYITk RgPnK5g57PQaXN8khgYGTd7HTi6xDJC8Iprt1KC1qKXXQEHLV4tM7/cBGl+FRUfGoIGo W/ah/l+f1oxFdbNC9RistEP/xDRU7sCbD3RmdwPPJB9bOh1WW/4nf7voTrAhZclRiMaP HP9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724824173; x=1725428973; 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=moiMY/9kOk6Xzt0Khn1FkF8wyTL4BDNBgOSp+BMugag=; b=HLhV66U7N0qppOzacWelaj3/QoBkPcipWTdXPGFITCB77qJoQpeJZFMQS50uYdTMz2 Tr0If7bwm6lTHBVCsJVg2DLJaGTGeZeZ2x0YYumLCrbPS+9oxJM30j0g4wclXfHwihfb rgsJmunb09LRjqdaIJtZwH19+7ew4tKMTLEstSN6+hJj9Cc+nSozpWDXmiTyrE2bf8k3 //DdzFvumahCJ2Db9v7vAHHJ+HPvSIMEkbqpd+6z8MH0FPrSA9GIH6ujMjrGUvL2TcZ4 IQE73ePfNfGYrid7Tu6VnmL7u5L8UC+Etca1zaTQM+/uTmbqzSQjcrLKMfTrm/wQHONA LOhg== X-Forwarded-Encrypted: i=1; AJvYcCX46QYnbE9tZ6lHp3i5dj+LTMbmcyuYua0tXpAgP23Y8MkVBQb6hYwxQULtw9H7zA6IXBdDVNLdhy4duEQ=@lists.ozlabs.org X-Gm-Message-State: AOJu0YxNKbJt1bNHKusg+kk+zvthrtM8zP8c8LjnJfwJN8ATRgTykXqG qsxzeRmzrXxWCrIh0sGrj5O/EZplk+prXQpE1NrSABAO9TXDKrHxJJKPmZkTjp0wpAFVm9YEFpY s X-Google-Smtp-Source: AGHT+IE+xcDspGauSp7IVmRnQSeJseOyw+wVLX4elXR4/BGbU1fHY0MaCzZG4/pxtEucaF+r97Z9DQ== X-Received: by 2002:a17:903:124b:b0:202:4079:1c19 with SMTP id d9443c01a7336-2039e47589dmr164242605ad.14.1724824172722; Tue, 27 Aug 2024 22:49:32 -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.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 22:49:31 -0700 (PDT) From: Charlie Jenkins Date: Tue, 27 Aug 2024 22:49:08 -0700 Subject: [PATCH 02/16] riscv: mm: Do not restrict mmap address based on hint X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Post: List-Subscribe: , , List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240827-patches-below_hint_mmap-v1-2-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=2260; i=charlie@rivosinc.com; h=from:subject:message-id; bh=YMF9irkRUC4sRvnkdcE8hTIaJNmeFPHDQEKHg4RlOyw=; b=owGbwMvMwCHWx5hUnlvL8Y3xtFoSQ9q5XbEGN52ULpq4/39venW688upWgwFDj9spqW3rOd57 Wdme6Ooo5SFQYyDQVZMkYXnWgNz6x39sqOiZRNg5rAygQxh4OIUgInoxjIyLPq831JpspB17kOr jRV1b1+9OjXz6TVOvZStd2IFbrHtWM3wV9buiFXmKu3sWVt1RJfzLlfjNmD+lbK6aQ3rc0+mG/t jOAA= X-Developer-Key: i=charlie@rivosinc.com; a=openpgp; fpr=7D834FF11B1D8387E61C776FFB10D1F27D6B1354 The hint address should not forcefully restrict the addresses returned by mmap as this causes mmap to report ENOMEM when there is memory still available. Signed-off-by: Charlie Jenkins Fixes: b5b4287accd7 ("riscv: mm: Use hint address in mmap if available") Fixes: add2cc6b6515 ("RISC-V: mm: Restrict address space for sv39,sv48,sv57") Closes: https://lore.kernel.org/linux-kernel/ZbxTNjQPFKBatMq+@ghost/T/#mccb1890466bf5a488c9ce7441e57e42271895765 --- This patch is pulled from [1] for ease of review of this series. Link: https://lore.kernel.org/lkml/20240826-riscv_mmap-v1-2-cd8962afe47f@rivosinc.com/T/ [1] --- arch/riscv/include/asm/processor.h | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/arch/riscv/include/asm/processor.h b/arch/riscv/include/asm/processor.h index 8702b8721a27..1015f2a49917 100644 --- a/arch/riscv/include/asm/processor.h +++ b/arch/riscv/include/asm/processor.h @@ -14,36 +14,14 @@ #include -/* - * addr is a hint to the maximum userspace address that mmap should provide, so - * this macro needs to return the largest address space available so that - * mmap_end < addr, being mmap_end the top of that address space. - * See Documentation/arch/riscv/vm-layout.rst for more details. - */ #define arch_get_mmap_end(addr, len, flags) \ ({ \ - unsigned long mmap_end; \ - typeof(addr) _addr = (addr); \ - if ((_addr) == 0 || is_compat_task() || \ - ((_addr + len) > BIT(VA_BITS - 1))) \ - mmap_end = STACK_TOP_MAX; \ - else \ - mmap_end = (_addr + len); \ - mmap_end; \ + STACK_TOP_MAX; \ }) -#define arch_get_mmap_base(addr, base) \ +#define arch_get_mmap_base(addr, base, flags) \ ({ \ - unsigned long mmap_base; \ - typeof(addr) _addr = (addr); \ - typeof(base) _base = (base); \ - unsigned long rnd_gap = DEFAULT_MAP_WINDOW - (_base); \ - if ((_addr) == 0 || is_compat_task() || \ - ((_addr + len) > BIT(VA_BITS - 1))) \ - mmap_base = (_base); \ - else \ - mmap_base = (_addr + len) - rnd_gap; \ - mmap_base; \ + base; \ }) #ifdef CONFIG_64BIT From patchwork Wed Aug 28 05:49:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 1977638 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=AdtJeYP/; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev+bounces-644-incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WtwhH22rJz1yfn for ; Wed, 28 Aug 2024 17:16:47 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4WtwhG3pqLz2yhM; Wed, 28 Aug 2024 17:16:46 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::632" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724824179; cv=none; b=UtT4DKz4ygweQOnJPpz6KDzTgC83TertPUE6rf9hfmlAPykRBheflFVvRfcEVWUdtJLo860Q/PscFyMht2XMOnE2bA6Yi7UkerGjZ46Ph9Je+SDG96V8Awdni3+TEVaY1mQhsr9GDe1ydx2O24EuD1E+Fr18MuORVdY766kux1b5JRCB8+S2bh60PgE6gqcoS57RvPK8otx5FDtqcG8pq+b+wBpLM/Ty2VroAwCmHpzCyp4wrQm4df8qRxKfdx2llT/M0KQpP3W7JelL9ASXcgi8GYpTxbWzoTK/9fgfIpjdRKdU4zSXv+fCqbN9YLYzrJBM92koiPyLc+qA6tfbXw== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724824179; c=relaxed/relaxed; bh=TGbwsGUaSgh3SYkS7pHaMfmAZns1s9a6v7xPbD2XVAI=; h=Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Google-Smtp-Source: X-Received:Received:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; b=Alx3EKs+I2X3aBOUWtP47zzCSrVxhacKKHEgaIgpybvXkXVzWhWQ2Unv7xyMlGHkxqdVTunCaOIPjaWUZGjw0JxBgjnDG6cY2KlE1NK1aiL0Jyhd+sdcFfuOFDEFeSiw3LXIADTN1VoidwDalfngUnSSrPBRGWo04sJsuT0HkarFdtYqHvAtJcKw8GhEhOjpWi/VIgK7UKkgSWBpBNmCHhj52ve6O1tKtRnO0plm6Z1ggUFeE4P+WmRvJMtpCdIVcEo+yfsR0YELUtI36X0Rh4XaixKyBwyer/B0j/PlqJPJVdaOK1nrQhliVecooAgq0RJEE2OiL2gpvOEoL+jNDQ== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=AdtJeYP/; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::632; helo=mail-pl1-x632.google.com; envelope-from=charlie@rivosinc.com; receiver=lists.ozlabs.org) smtp.mailfrom=rivosinc.com Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=AdtJeYP/; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=rivosinc.com (client-ip=2607:f8b0:4864:20::632; helo=mail-pl1-x632.google.com; envelope-from=charlie@rivosinc.com; receiver=lists.ozlabs.org) Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Wttll1wQkz2y8l for ; Wed, 28 Aug 2024 15:49:39 +1000 (AEST) Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-201fbd0d7c2so52361185ad.0 for ; Tue, 27 Aug 2024 22:49:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724824177; x=1725428977; darn=lists.ozlabs.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=TGbwsGUaSgh3SYkS7pHaMfmAZns1s9a6v7xPbD2XVAI=; b=AdtJeYP/YxH261zBuONAG+izWdza4W9O1gft4TqV569VeN552GoPluOu/QxO9Cl88o og11hL8AzQA84+S8OoRhMDJGO4ZP6TZv04tj1sO+oAxD8npl3siFhXnZIAR6vyY1iQBA jMfrAg1Uz0D/PO6UPk6Y10h6iW4kxQm/JXoilqfAw8JAYy2Z+q6ak6v1dbiecscg2my+ mCzQdC0aAOEKo0InHj7RAZhPeZ/OsiuJRIaijxVYpYZrzfHuGsGjYBbBr6ZWV4eceFSR nioZ+Mpu8SAN/P4A1ch9nYvGteE4uMSVBhRGfjCwtxCkFiSla12D//UEzWYEiAsGR0Bl 0sEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724824177; x=1725428977; 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=TGbwsGUaSgh3SYkS7pHaMfmAZns1s9a6v7xPbD2XVAI=; b=RYy6XSnCpcIaAnOp+0uMLgO0M3xh8saJB4aArguacYOWWCKyIpEOwT/S8XeluI2d2m kGDVuL42mgPU3liohcXR5cFQoWxjvcRncZ+dZg2umNVa7s1TtHMLaEO+cZIpstzhAH+u 8+pKMvnL0SLX+V/AbuyNOuhtQ59u9vrFDwwfYqh53Q83SjIuU0qB3lj/4oQABPiLOBiG m9MfGnl3PXuFO5rzUUsnO9b5TZ3CSGgm+nEUTXyKjl+gSk9EK8WveoVLv7eIRRNdQBWv hxN3nEYZue37GUwP+eltdAbE3/DIBAskvZzHMDlaqpcCODLg7swnuGTKf5fBvT0d0skH GewA== X-Forwarded-Encrypted: i=1; AJvYcCUFj2iFgLHPWXnXfebCy5dcDJDAq96eREJMKrMMfHtbwZ0Ogt9UJbQv/+ukF45uZRJqwyDeeES4OZB0TG0=@lists.ozlabs.org X-Gm-Message-State: AOJu0Yz3Ia93xLCAbij3ZEPStjr3UKfUcCZY3TqCrzVebsRZ1LJWOrQP sSJlFVWk9DScCvGzBI/YYl7TzuRXh0uXKLu7R69YbN+yg8hplE1hJyw1G2iN6PE= X-Google-Smtp-Source: AGHT+IETeUynSugovs7+A+AN20czg30Ola2aofBrInbwTCbD60I4EWjQ5oF17Pp044tfVMlW9N70GQ== X-Received: by 2002:a17:902:f946:b0:1fb:6ea1:6a with SMTP id d9443c01a7336-204f9bf6b4fmr8673095ad.42.1724824176426; Tue, 27 Aug 2024 22:49:36 -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.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 22:49:35 -0700 (PDT) From: Charlie Jenkins Date: Tue, 27 Aug 2024 22:49:09 -0700 Subject: [PATCH 03/16] mm: Add flag and len param to arch_get_mmap_base() X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Post: List-Subscribe: , , List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240827-patches-below_hint_mmap-v1-3-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=3681; i=charlie@rivosinc.com; h=from:subject:message-id; bh=deEFSUhsRdIX0bdzxWoQYKSiKJBAsZhcTOjbVXT5+ls=; b=owGbwMvMwCHWx5hUnlvL8Y3xtFoSQ9q5XbEKPQVKN+QOfCnd/vQAx7Mm0aicnIfvMk/aT/p2R eLJrUMHOkpZGMQ4GGTFFFl4rjUwt97RLzsqWjYBZg4rE8gQBi5OAZiI/GeGP5ySTrLnNmwQmXLz 8w+bnE++e2VFjGTvdAadNPbzvHntw1tGhs53DbPX/utm9fCf+JHzi+Xvmwkm0w5eV/OMyrFcaSf ykBcA X-Developer-Key: i=charlie@rivosinc.com; a=openpgp; fpr=7D834FF11B1D8387E61C776FFB10D1F27D6B1354 The flag and len param is required in arch_get_mmap_base() to implement MAP_BELOW_HINT. Signed-off-by: Charlie Jenkins --- arch/arm64/include/asm/processor.h | 2 +- arch/powerpc/include/asm/task_size_64.h | 2 +- arch/riscv/include/asm/processor.h | 2 +- fs/hugetlbfs/inode.c | 2 +- include/linux/sched/mm.h | 2 +- mm/mmap.c | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/arm64/include/asm/processor.h b/arch/arm64/include/asm/processor.h index f77371232d8c..a67ca119bb91 100644 --- a/arch/arm64/include/asm/processor.h +++ b/arch/arm64/include/asm/processor.h @@ -95,7 +95,7 @@ #define arch_get_mmap_end(addr, len, flags) \ (((addr) > DEFAULT_MAP_WINDOW) ? TASK_SIZE : DEFAULT_MAP_WINDOW) -#define arch_get_mmap_base(addr, base) ((addr > DEFAULT_MAP_WINDOW) ? \ +#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 */ diff --git a/arch/powerpc/include/asm/task_size_64.h b/arch/powerpc/include/asm/task_size_64.h index 5a709951c901..239b363841aa 100644 --- a/arch/powerpc/include/asm/task_size_64.h +++ b/arch/powerpc/include/asm/task_size_64.h @@ -72,7 +72,7 @@ #define STACK_TOP_MAX TASK_SIZE_USER64 #define STACK_TOP (is_32bit_task() ? STACK_TOP_USER32 : STACK_TOP_USER64) -#define arch_get_mmap_base(addr, base) \ +#define arch_get_mmap_base(addr, len, base, flags) \ (((addr) > DEFAULT_MAP_WINDOW) ? (base) + TASK_SIZE - DEFAULT_MAP_WINDOW : (base)) #define arch_get_mmap_end(addr, len, flags) \ diff --git a/arch/riscv/include/asm/processor.h b/arch/riscv/include/asm/processor.h index 1015f2a49917..7ff559bf46f2 100644 --- a/arch/riscv/include/asm/processor.h +++ b/arch/riscv/include/asm/processor.h @@ -19,7 +19,7 @@ STACK_TOP_MAX; \ }) -#define arch_get_mmap_base(addr, base, flags) \ +#define arch_get_mmap_base(addr, len, base, flags) \ ({ \ base; \ }) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index 9f6cff356796..05a52f85dba9 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -195,7 +195,7 @@ hugetlb_get_unmapped_area_topdown(struct file *file, unsigned long addr, info.flags = VM_UNMAPPED_AREA_TOPDOWN; info.length = len; info.low_limit = PAGE_SIZE; - info.high_limit = arch_get_mmap_base(addr, current->mm->mmap_base); + info.high_limit = arch_get_mmap_base(addr, len, current->mm->mmap_base, flags); info.align_mask = PAGE_MASK & ~huge_page_mask(h); addr = vm_unmapped_area(&info); diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h index 91546493c43d..265b43855d0b 100644 --- a/include/linux/sched/mm.h +++ b/include/linux/sched/mm.h @@ -174,7 +174,7 @@ static inline void mm_update_next_owner(struct mm_struct *mm) #endif #ifndef arch_get_mmap_base -#define arch_get_mmap_base(addr, base) (base) +#define arch_get_mmap_base(addr, len, base, flags) (base) #endif extern void arch_pick_mmap_layout(struct mm_struct *mm, diff --git a/mm/mmap.c b/mm/mmap.c index d0dfc85b209b..27a7f2be3f68 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1861,7 +1861,7 @@ generic_get_unmapped_area_topdown(struct file *filp, unsigned long addr, info.flags = VM_UNMAPPED_AREA_TOPDOWN; info.length = len; info.low_limit = PAGE_SIZE; - info.high_limit = arch_get_mmap_base(addr, mm->mmap_base); + info.high_limit = arch_get_mmap_base(addr, len, mm->mmap_base, flags); addr = vm_unmapped_area(&info); /* From patchwork Wed Aug 28 05:49:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 1977639 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=U4oVX8q7; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev+bounces-645-incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WtwhR0x9qz1yfn for ; Wed, 28 Aug 2024 17:16:55 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4WtwhQ6DNqz2yjN; Wed, 28 Aug 2024 17:16:54 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::42b" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724824182; cv=none; b=dSTduHTctyosH4NpPZbknqQjJBbhQ1VrWowYLPtQKqR0re1SQ4wA2CuV43tHYIinMZl6y73nDuBpxR3WbfOoCxDr9pBX+SfvT+KmzOkKcZPTwQJ4fErq/6cbeEsv0N/Mvj47mM6oUlmTFMaF8hxfl9O2VU75oSjpFsTTpfWAYFyV1kwgukN8Ul3o0ckFy5ytsuJtOcb7Dsg56sd7e59Xp/pa818Keuufc49ySlScSBC/ADnVVwSt2mJ6npOWt/+CkcJQ94uQtX11G7QYpuWbCh6ZeSsFHuANd1AkLfaovZu18O0USoIwKQxdZnb8GildE9x6bh6UqLAauXOJuHysCg== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724824182; c=relaxed/relaxed; bh=g+f5iieqZfHqFwlVhHOpYZvOeyZcJe//7AT/XT4juc0=; h=Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Google-Smtp-Source: X-Received:Received:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; b=m+j520i6e6MA+gmSlGwxKqKSO6XnlStdlY325bkBZxJszUb70v1A9DThzrSeevw/uqnXLeCOsXK3Mz5a6ydYzrMyj0obSpOL4/3reyOKJNTysdJ6YIXuD25VJxKjaFWesH4spT0t0t3D3xcECKfLFci/HKBx+jyj3v0SQ7lDy/zqLTG+M0ouVy3OfigvTrM0rOHzZaRdBCdZxGw6uud+tYbb2fvxOAPAyHq0CH5qFIBgVSdWIndTi1GbKifiSsWfuu+h70PUIt1FQ1E3j3rEm12I19AsU6NCtDceCtlv3K68tz7amYaDAwEezdrFpFGKfvLgQnM9TtkEhkfw1vCYIA== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=U4oVX8q7; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::42b; helo=mail-pf1-x42b.google.com; envelope-from=charlie@rivosinc.com; receiver=lists.ozlabs.org) smtp.mailfrom=rivosinc.com Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=U4oVX8q7; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=rivosinc.com (client-ip=2607:f8b0:4864:20::42b; helo=mail-pf1-x42b.google.com; envelope-from=charlie@rivosinc.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Wttln5Wd4z2y8l for ; Wed, 28 Aug 2024 15:49:41 +1000 (AEST) Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-7142e4dddbfso4925902b3a.0 for ; Tue, 27 Aug 2024 22:49:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724824180; x=1725428980; darn=lists.ozlabs.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=g+f5iieqZfHqFwlVhHOpYZvOeyZcJe//7AT/XT4juc0=; b=U4oVX8q7FvntVMetDpXnGOjqPI2IVwoC+hhXwg2PuFjbF2vDftK0kqpdAssKR3/gQX qBd9Yij4g7tpF0tsa6SD0VZsSULlHHDCZ71VEZcKjmMJDeavGQfYwS1n68amX081bV5c Qi0jyvjQBqEQWofp44N+AU2gg6EVSCYGTHXPZnwTu9HrPdH5nHeYICfZTSTzelUvXKii IDSCprnFFTgPU9UINlhs8C+GOOx1zq3Y4lhoJBm53l9+UIFwLNwMSqaV8nWxATHfsnKD qJohUySuuoxCUnB/1kBTzDBDTrlzZfhKskFsRmTPgfTtVY/Yr7j9C7hJ2f2WnBZo6Y2a 6/ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724824180; x=1725428980; 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=g+f5iieqZfHqFwlVhHOpYZvOeyZcJe//7AT/XT4juc0=; b=I2Jge4zAWDY0QS8SYd6CggaVziPY5fx2pnt5a70tFnn1wslg4Rg1e0W6o0ZIKaovq2 dCPqw8XE3UfKlknwmRK1bU3gLIebTzevqcyOfzBgrUGmY1uiUbomTY2/L5QD8mze8oZY iRnmLl2UvIXm14igdgf3Y8cpxl7DBQ9xDwaCuODvn68pR9E7t/RqGOMua+3KYEjAplkE UX7VPPmze+4YFz2RMmNCcfNmFcG0H+kA/Rzds/jZBT89/y2Lj2BhMkugZ/euUPuId7wB 48qBRyKsy27yvUwNF4SvCHGbEFAkU7OnBzSjCxs+52+7FnHpjAhGKBvSxwhrRNWiwUbD bIRw== X-Forwarded-Encrypted: i=1; AJvYcCWdLiig3CGW8B0p78N+Yy8IsbVpf3gm1Qpi0ZXodyNqg3OknZcVlichtpRWU4I6nWdhpjzho/+c3zmqUAM=@lists.ozlabs.org X-Gm-Message-State: AOJu0YzyjgmXLH33KPivkFci9FGdNgBSdDlSa8U7cVmW9JcBeS/ZRRnK vZF3E47MOrAL3v+qlV/JBkUC21p/UzaqM4cFmH9rEhP6Q59oKmbj6OjBTi9IknE= X-Google-Smtp-Source: AGHT+IGKYEbmAbccdwLglj8Rtz7Ncms8BNc+Vjhrih2XUvI/cV2bfefpghFryVXCiPvCQUUiKdRNjQ== X-Received: by 2002:a05:6a21:3401:b0:1c6:a777:4cfa with SMTP id adf61e73a8af0-1cc8b475035mr13030363637.13.1724824179851; Tue, 27 Aug 2024 22:49:39 -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.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 22:49:39 -0700 (PDT) From: Charlie Jenkins Date: Tue, 27 Aug 2024 22:49:10 -0700 Subject: [PATCH 04/16] mm: Add generic MAP_BELOW_HINT X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Post: List-Subscribe: , , List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240827-patches-below_hint_mmap-v1-4-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=2165; i=charlie@rivosinc.com; h=from:subject:message-id; bh=+G9/grHdHxL6H0Lnh65S6ISh5epJb2mrAov/AP0hs9c=; b=owGbwMvMwCHWx5hUnlvL8Y3xtFoSQ9q5XXGZXkeVtgeold2b3dqjkt+vEXMu6H6oc1bJNYtbJ 3aetlzTUcrCIMbBICumyMJzrYG59Y5+2VHRsgkwc1iZQIYwcHEKwERWFTEyNKap9S5rOHHkFBPT SkUp8yq1Cd/4ljyftDBFnmW663I5b4Z/RluSpK/6drw7JD8vOuPN75znwc73OQp/v/2R9GK2Tfl mPgA= X-Developer-Key: i=charlie@rivosinc.com; a=openpgp; fpr=7D834FF11B1D8387E61C776FFB10D1F27D6B1354 Make the generic implementation of arch_get_mmap_base() and arch_get_mmap_end() support MAP_BELOW_HINT. Signed-off-by: Charlie Jenkins --- include/linux/sched/mm.h | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h index 265b43855d0b..c350bb5ac0a2 100644 --- a/include/linux/sched/mm.h +++ b/include/linux/sched/mm.h @@ -9,6 +9,7 @@ #include #include #include +#include /* * Routines for handling mm_structs @@ -170,11 +171,40 @@ static inline void mm_update_next_owner(struct mm_struct *mm) #ifdef CONFIG_MMU #ifndef arch_get_mmap_end -#define arch_get_mmap_end(addr, len, flags) (TASK_SIZE) +#define arch_get_mmap_end(addr, len, flags) \ +({ \ + unsigned long mmap_end; \ + typeof(flags) _flags = (flags); \ + typeof(addr) _addr = (addr); \ + typeof(len) _len = (len); \ + mmap_end = TASK_SIZE; \ + if (_flags & MAP_BELOW_HINT && _addr != 0) \ + mmap_end = MIN(mmap_end, _addr + _len); \ + mmap_end; \ +}) #endif #ifndef arch_get_mmap_base -#define arch_get_mmap_base(addr, len, base, flags) (base) +/* + * rnd_gap is defined to be (STACK_TOP - _base) due to the definition of + * mmap_base in mm/util.c + * + * Assumes ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT, which all architectures that + * implement generic mmap use + */ +#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 = STACK_TOP - _base; \ + mmap_base = _base; \ + if (_flags & MAP_BELOW_HINT && _addr != 0) \ + mmap_base = MIN(mmap_base, (_addr + _len) - rnd_gap); \ + mmap_base; \ +}) #endif extern void arch_pick_mmap_layout(struct mm_struct *mm, From patchwork Wed Aug 28 05:49:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 1977640 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=mXES7vwf; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev+bounces-646-incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wtwhd30K4z1yfn for ; Wed, 28 Aug 2024 17:17:05 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Wtwhd1rbjz2yk7; Wed, 28 Aug 2024 17:17:05 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::62e" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724824186; cv=none; b=FFJ6k43RtbzcCkg9PJwxAsl0/4Ge7cS2qtHdpvZaqiGNenMJ6JnKNbib4ZO8BV/5CGfJ3ETcFZbt/ZSuhrweK+0fs/lHICivpqTT2Hz8fRY+dXsZe0xltEYWad7ztl/NjjM7aK2fEfAJpvhf82FDRXB8rUMgVDEJS53+QxvalZxKLhaDrs5qeKSl3N97fpPzvYZpnv0mdA1pD1GCnU3pq7995tztUHtKBpOStdNKtIaQD6yCnJ/FuQc9qFzlRb8BNscpA8mcsA4vQPBzd3blvatNwoN2DCDOAXUS18FwhklMkxEe3hNAgPzWC8Vi2q9g0krUvepy4oHOS0FLAR1AaA== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724824186; c=relaxed/relaxed; bh=Q5srBcKEXlmg65Adrhp9lVjL7ktMhhBJWYWob6ko31g=; h=Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Google-Smtp-Source: X-Received:Received:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; b=TJ038FZqpjmNHcoOr5gb/dG/Rgca54UnGsgrxgtnLGvEFCqHH60cP7yX4cFypvYzpsaefk7zikFD4/ziwkheBuGgmc0l5e2iuZxuFZK7CTxPpgM+UmupQ5cenkRsSwqF6J/WmgQtaTJK6lXSB2fx/LVnS9tEwRE1vBUztv4E1wWMqkC7Z1aITR5oZ5M/HHXxS8anFgZjxVSx+YTvY7YG4Bsuh4ke3ktyUjDFNMoeZc+W6Ky2vYgp+zuFo1RXP08TAZ3yhM8jTxhpaM6rTjNkeu7Ceq4iwBXzILPBh15JgDOnIMgbN9/N1rvLTkBNjsmc7RG6aq3hmgQE3RlPWe+YDg== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=mXES7vwf; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::62e; helo=mail-pl1-x62e.google.com; envelope-from=charlie@rivosinc.com; receiver=lists.ozlabs.org) smtp.mailfrom=rivosinc.com Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=mXES7vwf; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=rivosinc.com (client-ip=2607:f8b0:4864:20::62e; helo=mail-pl1-x62e.google.com; envelope-from=charlie@rivosinc.com; receiver=lists.ozlabs.org) Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Wttlt1KYvz2y8l for ; Wed, 28 Aug 2024 15:49:46 +1000 (AEST) Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-202376301e6so49035285ad.0 for ; Tue, 27 Aug 2024 22:49:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724824183; x=1725428983; darn=lists.ozlabs.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=Q5srBcKEXlmg65Adrhp9lVjL7ktMhhBJWYWob6ko31g=; b=mXES7vwfWLLqpllCvdAJ5SvaAA0dJL8Y0gVAU36cR5Ezw2Sr9yXLb2x78njOoia3JV SwtSOlP3wpw1bCvsE1KG6h2ttdrwM489z0TWBuOYyol2UcJN2N4Kll8TJxuwZnoOkuvJ vN6tqeYI1oaeVfGFJ/i57/A7sCVOKfHZSIbu80zDMN5+u7sxsYXMAqBgFdxoWgu3cYUv EQKTMTTiDBxHBVBoySpwebQ/3KK3ZvBZ1zalGLUUuHagF5piXAjtUmsoWJ5luboruTzb Vs3cLqXTSyuwLxZ45tAdAEdDF3NGE/vTvrCc3PGpR79ZqapzwcLIbDnDvqTmezC4eD28 0nQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724824183; x=1725428983; 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=Q5srBcKEXlmg65Adrhp9lVjL7ktMhhBJWYWob6ko31g=; b=XzFn3YbbgK3cWZQpKlDB41Uqw4rt6mjHNeSGvMJ7nEKNqiDAXitoFKun4G4mf7MDSH AIaRPWcmVm/11YFUQlyY+8tgbW5QMUp/GovyzC8ehISN060U9dhfUHnnKETyjm6y+5T2 7piV011qIcUo46h1N8bkRYaY6nEklqleco5jXmOaK/zscXqSiaE43gSOw01c0FYtAEXd aSpN1vLuP7+QgYnHAfdAC/2klUQ3+INuRfP3S2vEx7NWf9WaI9LXP0LD/E/kdymJatmq 4CNguatIw0zfLu8l/90kpVdnucmFHfhwfMrMtlHGc8vgxZ4W+MiFx3OB9r7tgaWWD/Mk dh9Q== X-Forwarded-Encrypted: i=1; AJvYcCVfXQTgqIrekX1656wIzwWzeLt9U+X8o+cIxP3LHzZao8FxwglKCnR8b9/RwcEMnRpU4k8Ct6R+plos99w=@lists.ozlabs.org X-Gm-Message-State: AOJu0Yw/P4Gs6zhA27sUVKOvtV6H7HOEYeNgdpNYcQLbj9ykUTzXZjiN suks56pU/9dHivqYQOf6HCY9EVIwot1GDrocrdXqPV2dqg1o8ERDcKYCILk6ts4= X-Google-Smtp-Source: AGHT+IGHu+eM9GywkA2KKhkiXH1gwQVKDtYtrmu0o3xp962KqVz7yKVZ3UFfIj7ogPOJug6LrKMhnQ== X-Received: by 2002:a17:902:e54c:b0:1fb:3474:9500 with SMTP id d9443c01a7336-2039e4ab846mr148619915ad.27.1724824183237; Tue, 27 Aug 2024 22:49:43 -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.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 22:49:42 -0700 (PDT) From: Charlie Jenkins Date: Tue, 27 Aug 2024 22:49:11 -0700 Subject: [PATCH 05/16] riscv: mm: Support MAP_BELOW_HINT X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Post: List-Subscribe: , , List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240827-patches-below_hint_mmap-v1-5-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=921; i=charlie@rivosinc.com; h=from:subject:message-id; bh=h9Jl0isly8hfO1RunVOJNqZoeZvdanuDoXET0lufwJg=; b=owGbwMvMwCHWx5hUnlvL8Y3xtFoSQ9q5XXFHufOLGl2Wf1oQkLR82ZWndTOfPt314eCzeyv3r BZKWtO7oKOUhUGMg0FWTJGF51oDc+sd/bKjomUTYOawMoEMYeDiFICJNPxjZOjefGX9Tl/G6Irp nxS+dN0zOpEeMVEk78LzG1JnNgQw8RYzMpwwaro+TU52Snefw54npdeqTGoNrXMnik1KMY5Wjl7 KxwgA X-Developer-Key: i=charlie@rivosinc.com; a=openpgp; fpr=7D834FF11B1D8387E61C776FFB10D1F27D6B1354 When adding support for MAP_BELOW_HINT, the riscv implementation becomes identical to the default implementation, so arch_get_mmap_base() and arch_get_mmap_end() can be removed. Signed-off-by: Charlie Jenkins --- arch/riscv/include/asm/processor.h | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/arch/riscv/include/asm/processor.h b/arch/riscv/include/asm/processor.h index 7ff559bf46f2..20b4ba7d32be 100644 --- a/arch/riscv/include/asm/processor.h +++ b/arch/riscv/include/asm/processor.h @@ -14,16 +14,6 @@ #include -#define arch_get_mmap_end(addr, len, flags) \ -({ \ - STACK_TOP_MAX; \ -}) - -#define arch_get_mmap_base(addr, len, base, flags) \ -({ \ - base; \ -}) - #ifdef CONFIG_64BIT #define DEFAULT_MAP_WINDOW (UL(1) << (MMAP_VA_BITS - 1)) #define STACK_TOP_MAX TASK_SIZE_64 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: 1977641 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=cf6TdYci; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev+bounces-647-incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wtwhm256dz1yfn for ; Wed, 28 Aug 2024 17:17:12 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Wtwhm1GCPz2yks; Wed, 28 Aug 2024 17:17:12 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::62f" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724824189; cv=none; b=iDkACw7n+uIjcNxe7g6mgAkoRz4G4x45ZtaM1LpJQEXut4dnw5Wv2DNXD7yuvWPVbEl1rmZBUQGP5CMXaGdpEZ71iRNkYtxp8Aeua94vZeN656jhDQ+U4okRDdhzs4f2Ue9fuhQczFeoyp4gh3XzRvshtk+OkK8JfoG0Jnmjujur8vPN+x9aVIOJFDAJ6MXirBvtIc4/ekpG7RAdTat5Cflag2VArIeKlt8Nq7K8aSDRgPvN26v705gwwt1zkuQlmX21wcyYTdvXMlcZnm95cmkqGzabxFmxlDkqINtnyUFBI7cN356hps3PzwKJtGfxVwD/a7DrhHEptr+8QXKN9A== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724824189; c=relaxed/relaxed; bh=fVwUzK3Wi136bLF1beJbPIYrhSgOvSQiUtDec+6VrAU=; h=Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Google-Smtp-Source: X-Received:Received:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; b=hGWf699G+y4+0Mj3PvN7kfXU868I6P9fANUvWrtZaOqMj1dhOauw1pGowlP5EbPlFS63XGRIFU6A0Mz1N0YanMzusOoSGAIzVSs2RunJGv1cpw2KxXaauouLgurNUpfE2DCqsrcfhwvVwa3FJXtC71uZ68ht2GkiEkcuo80zJIil0WeLpOasVnh2rmlFOXgxQq71cWVUPDe32bTX7o1TwdvCK37HVzAOUJAEpxLoA4V5ljeic/f9RgOJ+2aJBB5Ns9u84kBdrzIfkLQtdN43emdeVWTKMDsqXgpNzjFgZ48vBgeNYU86l32Kp6QXRUMM7YLjeT3VS6F24yw1Z6N9vA== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=cf6TdYci; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::62f; helo=mail-pl1-x62f.google.com; envelope-from=charlie@rivosinc.com; receiver=lists.ozlabs.org) smtp.mailfrom=rivosinc.com Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=cf6TdYci; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=rivosinc.com (client-ip=2607:f8b0:4864:20::62f; helo=mail-pl1-x62f.google.com; envelope-from=charlie@rivosinc.com; receiver=lists.ozlabs.org) Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Wttlx5MbLz2y8l for ; Wed, 28 Aug 2024 15:49:49 +1000 (AEST) Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-2021a99af5eso57401055ad.1 for ; Tue, 27 Aug 2024 22:49:49 -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.ozlabs.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=cf6TdYciXAo/LeLUlFR7cxo0LMooUS3NcYTbMWa68v/K0x2u1vFdVZp/pJxdqILRFt pXIQ3G4MDXWIZe+TNHRPgeKAFWoSoXolkBZq/RjGfBhpi9rvZCFg+j5rUp64HFdUtdpO Xavs8vBrbcxvgv/rI8N7+f+wQWBLKnKfwcwMwvvYyCk9oagq4XunhNFn2OJVhzEUQknl dXVNE0q3RaT2hxKTuc3NyE9hkdenWI1U0OWLAjN0UpHjWTn9JWzX1DJKb8MWhYzZuGQv GyBbH7RNFhdQHGeLrLlxtxaSuKKaUbJvR6dihErm4NYe8j6o6xpe6FDiDNcUrzWbbv7G BuvQ== 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=FM4BXkROzL3n0rpJ+d1yAeXdO+uR4U/wj1F3ygeOq+pSFGyqIXGOcUpgVzLPT1ZE40 OquDAnlqKPOHl1jS9I285C+06BBPrPaniqCVRF714hQxuiFfn6R+IkwOizfGyIsYtPwr /ZghkgAVWqfkoYVfPDhcuSDMu2wiNQHAzlVpwcrCHr9qbXHHvfFjbdNWtBqPaKOCdDfN yLRAew7mAGUO9pNvSBMHW8HFbsuxkxwOHgX0OREAizNXEe+ibAgloGbCVUK5CfUXUdet nOuPM+zImMCfaxHMCjd1JTVVpOkXPm9/kwk4PWTO+GLhRhHn0M7xfV3CRSjrebhfnDgy vntg== X-Forwarded-Encrypted: i=1; AJvYcCWfzCrkI91kyN0VrtOPX7nqdQY0vP67aGRCAC8eY91zjNN3VZqOF3Dz543fLbMCRMe8d1SuTAvhLmRKP1U=@lists.ozlabs.org X-Gm-Message-State: AOJu0YwQqw89CqEl3ifCZpv7m/Q/6gSofvtkISO8uWJCK8KwWNn30IXJ ic4O6Jnmb/rw6UXN+ZdAr1XWEltlvCym+1WsCcsuHa8N3wDWI0BFoLEohownHWw= 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 X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Post: List-Subscribe: , , List-Unsubscribe: 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 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; From patchwork Wed Aug 28 05:49:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 1977642 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=1rbmgISf; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev+bounces-648-incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wtwhw34Syz1yfn for ; Wed, 28 Aug 2024 17:17:20 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Wtwhw1yY7z2ym2; Wed, 28 Aug 2024 17:17:20 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::629" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724824193; cv=none; b=UPkNA0NJcXKAaKtyK6bcRhf9A+u7nDqmoERc6pDlZ2TJJrUXZa0v9Fq1EEyWBP+XpMk04OAkbN9+juAGQgL2MtcvP+iskMVGwab0MonRHLYJV7jLkpUnt2NRbZXVEgEhpDXcTA9CCubB3DLY8C/SdOLF18s/VZeDYXghuKhFQeizm/n9IasFyhn6YXIT4z60W4XcO6LVdBBbKpttYcobvjB5dRaWxV2Bd/hlTAZKmLI+jZrjTq+7/uRSzOxXCWS6m25+qAYHtUaG6iRs5Yd14dPO3bw6Uu30nWoTiozCcPy5Do2D2PDSjXXhXo2JUkyUKjPSdpGfZkoORlrlSGnl8g== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724824193; c=relaxed/relaxed; bh=01svQ9ue7Mr4CWZ3Wn0HVoOhr4xAPnLaZCO9CnTXUgc=; h=Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Google-Smtp-Source: X-Received:Received:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; b=h4rZxoSh6LDe7iJmQzvd9FeyrxILhZZ2iLE5HseftT7w7YIGdkVqTpTjKJCTh2FDCzszmhHx7h6r59z7gd2ZiDMt7C/unt+IoqLmbndknjqNF0c7fG7JLBkJPyD1nwVy17Xmt2kxjRo1eHOq3lRW45FPDvVaxJuQNHPg75EYbc/2+566mX0YOD7GgyiAp8YnkXqGmkeghBk6NWBqfsEVHbYAtWiTN5cQTkCpIEtQdjvYPUa1vHrws1h87j6TI0em/1BK5vrq0FrDAHHdnI9I9/Onau/4H/17gQNVM0/pQChaVpjOHOeFZPoM2yuggjWpLwyoP+zaJZqeP35IgxVbIw== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=1rbmgISf; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::629; helo=mail-pl1-x629.google.com; envelope-from=charlie@rivosinc.com; receiver=lists.ozlabs.org) smtp.mailfrom=rivosinc.com Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=1rbmgISf; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=rivosinc.com (client-ip=2607:f8b0:4864:20::629; helo=mail-pl1-x629.google.com; envelope-from=charlie@rivosinc.com; receiver=lists.ozlabs.org) Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Wttm127ZCz2y8l for ; Wed, 28 Aug 2024 15:49:53 +1000 (AEST) Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-2020b730049so49696325ad.3 for ; Tue, 27 Aug 2024 22:49:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724824190; x=1725428990; darn=lists.ozlabs.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=01svQ9ue7Mr4CWZ3Wn0HVoOhr4xAPnLaZCO9CnTXUgc=; b=1rbmgISfwFIN5KDNY5FRIoA75PPDuFkO7X+Rsy7cczn5ptXPdMC4PjUwt/wL+0Gtqf acN+Oh5V9YceYqxI3YpeGurwioZDwLjnsVJJgrj/9WIG3sOzW87DWHJhYPtviz9X1UWF XdgqgOJy7gxRLl7niNE3DS3rphRjV/lRhJn3Od8kLK6Xkf21Z64tdwFGUVnSqWg22j/D kjjRcVceO86UfHvf6vhrTOoF2gvVFAy3cF5TPOvt1q+Qo0of7APKm/gitiLfgCNWq2FH 4JTJa5rWxogxPVZwfPYLk1aKO57rxWkFzT+W3VG9Wd9khnKtlC58Te+IeNyAPalPGLH0 DLEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724824190; x=1725428990; 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=01svQ9ue7Mr4CWZ3Wn0HVoOhr4xAPnLaZCO9CnTXUgc=; b=dQBvuawBqZAhwQu4QZLgsmdNtK1JwQriuTPc80DuVwvpMUcMWy96bLqQbiaYVngUWd EOMXbl/DuXmqRbm22mWTjmG0c+rgzIUwjKMQAf1ypNkw40QxGKNtsvK7aAmE3VWO5iSN OGWQ1b2VQPayGiy/z6mp7JhxfoZ95GA3qIjA+sspWW7MThh5inIqdZQi9t8m60MLNpJF F4oAs9JjKqs90SHyPsEwcV10VVAeqgb6BuOuWyO5DmuNFqqTQ536ivqLJRHVNSNNd5Ut rr6rrIj4VYDR/Es+wzenvey++vmghRraRG+9MYu9g5THIbJluKRDKWmvApntI/3tBeYy 1RtQ== X-Forwarded-Encrypted: i=1; AJvYcCU22e+fZXPS+x2+O5ypXmygwlo7lkjvik1Rf3UP4VHlsjHl2ABIOU1kF6YcCLLOkxNADcc7J788nnX4Y+I=@lists.ozlabs.org X-Gm-Message-State: AOJu0YxPYw452qKQ/7D7n/ue09i5It5QDuENBFgr52S9T+A5tVJd+2cz aMMVWKWuOK3Cb0H4iJ/ZFVrv1BHSMxCgSXv+kdNazip54eYDlSXZHIPahgbfbBQ= X-Google-Smtp-Source: AGHT+IFEjwUM/ElshIB7y6tneVtatsCyua8fDLSA2/rXWwDoWBaTV3bT3kKjnxkFupcj6i3KTQazzg== X-Received: by 2002:a17:903:41c6:b0:1fa:449:1dd6 with SMTP id d9443c01a7336-2039e510e6emr137316635ad.48.1724824190164; Tue, 27 Aug 2024 22:49:50 -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.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 22:49:49 -0700 (PDT) From: Charlie Jenkins Date: Tue, 27 Aug 2024 22:49:13 -0700 Subject: [PATCH 07/16] powerpc: mm: Support MAP_BELOW_HINT X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Post: List-Subscribe: , , List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240827-patches-below_hint_mmap-v1-7-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=2284; i=charlie@rivosinc.com; h=from:subject:message-id; bh=efrv8gA6WD0kUzxMoz7FX/k/QnHAbRwwUgR0y2hEUd8=; b=owGbwMvMwCHWx5hUnlvL8Y3xtFoSQ9q5XfETrh9IO7T/uFjUxMhNQooG1iuWi1pdtJg6YcLD7 VUZ209HdpSyMIhxMMiKKbLwXGtgbr2jX3ZUtGwCzBxWJpAhDFycAjARbV+GvyIzjrH36plzvXDr 3H/Wo2jj7SdL50ufO/vC42XF9noOjvuMDF8DvSaxHlpya2VRHMuNXyrdOxW6nj44wHJxyn8TwWv XdrEDAA== X-Developer-Key: i=charlie@rivosinc.com; a=openpgp; fpr=7D834FF11B1D8387E61C776FFB10D1F27D6B1354 Add support for MAP_BELOW_HINT to arch_get_mmap_base() and arch_get_mmap_end(). Signed-off-by: Charlie Jenkins --- arch/powerpc/include/asm/task_size_64.h | 36 +++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/arch/powerpc/include/asm/task_size_64.h b/arch/powerpc/include/asm/task_size_64.h index 239b363841aa..a37a5a81365d 100644 --- a/arch/powerpc/include/asm/task_size_64.h +++ b/arch/powerpc/include/asm/task_size_64.h @@ -72,12 +72,36 @@ #define STACK_TOP_MAX TASK_SIZE_USER64 #define STACK_TOP (is_32bit_task() ? STACK_TOP_USER32 : STACK_TOP_USER64) -#define arch_get_mmap_base(addr, len, base, flags) \ - (((addr) > DEFAULT_MAP_WINDOW) ? (base) + TASK_SIZE - DEFAULT_MAP_WINDOW : (base)) +#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_end(addr, len, flags) \ - (((addr) > DEFAULT_MAP_WINDOW) || \ - (((flags) & MAP_FIXED) && ((addr) + (len) > 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) || \ + (((_flags) & MAP_FIXED) && ((_addr) + (_len) > DEFAULT_MAP_WINDOW))\ + ? TASK_SIZE : DEFAULT_MAP_WINDOW) \ + mmap_end; \ +}) #endif /* _ASM_POWERPC_TASK_SIZE_64_H */ From patchwork Wed Aug 28 05:49:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 1977643 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=Ru4rCAui; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev+bounces-649-incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wtwj268Jnz1yfn for ; Wed, 28 Aug 2024 17:17:26 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Wtwj24z3hz2ynL; Wed, 28 Aug 2024 17:17:26 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::632" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724824195; cv=none; b=M2td51zCp7p371mYv1dn0YhJIhZo8gSevpLCDtuPiJKg4pXR7g9OprL4avEQ4IEYhHeilUw/mimF5bA5JeIIxTgMpupGbBGx9Ct12mhjhqWQqDxIBD1c4TrDDGdiXOSIm/Rf+5VtalsMJVIieUblS5P58/QwdpKeshikGuBl6qgZIKKLFlqERg/ONc/xHjOJ/aGnbFyb0ucdO3jWqoPrpx+NXAgCZ4VLjfrN8/P8EIs8o2kGvPJ8asTCuvZlyMSFwDpbkbOect6F0ydiDnVTXcEyXZArbskszXUj0XAd0UBceejyI3rBkpxvtDZMPYuOdglpfV6Gx/jIUNSjwNMnzQ== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724824195; c=relaxed/relaxed; bh=WPJ0dF9cF6J1lv0FlFvR4vKxUsSQiAia4h2dvI+DMjw=; h=Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Google-Smtp-Source: X-Received:Received:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; b=WwDFAxbJ9N9oNqcBO1Q4cQajSoqAbKPezhBk+cufLueLDVQjZ7RcdU4fiXMtkHsfDkMes/uH8Vsnsk0+Xqp8tD9CjGEaPyrriV2yvFINFa94Uu/utjJzJ3tGs8i7TOIt7vPpIjQ7+o/AGxa5+3NzNC7NC4raBLHa+6P6OeYs/jIcCDBMs+Iqpf5dZ9GrlK16Cu8wIFEcx6BpXZYtDmmSRAm3V2xwhAMorHnshqmcAq4pukc58OKDKdsoOQo+vkKsFi0pDAwFBIUdsViiks+ajVPtYtQUjeWv+hZVOZ0CING5RHu3x1DqsnL+e8AGXuKEVym3XnQhf7ToYOd4dGDGig== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=Ru4rCAui; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::632; helo=mail-pl1-x632.google.com; envelope-from=charlie@rivosinc.com; receiver=lists.ozlabs.org) smtp.mailfrom=rivosinc.com Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=Ru4rCAui; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=rivosinc.com (client-ip=2607:f8b0:4864:20::632; helo=mail-pl1-x632.google.com; envelope-from=charlie@rivosinc.com; receiver=lists.ozlabs.org) Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Wttm34XGfz2y8l for ; Wed, 28 Aug 2024 15:49:55 +1000 (AEST) Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-201fbd0d7c2so52362895ad.0 for ; Tue, 27 Aug 2024 22:49:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724824194; x=1725428994; darn=lists.ozlabs.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=WPJ0dF9cF6J1lv0FlFvR4vKxUsSQiAia4h2dvI+DMjw=; b=Ru4rCAuiKL9cQkK8lca/TcKm1dwKCbwpNkgkW30l0GM7T9xPMFV9r0EpKUbcI5MZZ3 yBkPihu3YQY2w3HsoHaDYStrM3Dl3uKYlmEknyCGSIZAPvXQv+wKT1YQnmMyTZmCo+Cx oQp/+3ttmnvN86u/Fiz16jBIS5zLyICdR9Jzlv0p7wY5U6CVN4zPC10OwtyZmfHOF6Kl ZrNvspF46pqpYjqHK4CJOerWFRwPx/CBCB6CgLGCQpRh/N44KzUxk7GkzDGBHOWOy3YB okjAsonMGLnWaA7e5jJ02mPV3SpHUxq34bjqp9jdvaOY+tdI9LMyN+ST8pgFX2R3OYZa +wog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724824194; x=1725428994; 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=WPJ0dF9cF6J1lv0FlFvR4vKxUsSQiAia4h2dvI+DMjw=; b=iH0Q29nLAOqMPihBi5er9KKq6uTHqmbVRpmQpCva0J18laMVSbw6ej8aHKpHlD+JN4 eMXUImu9qKJturtxN/+ytERofKNGTBEnlZU+H2EcjTgRAwVG665q1YstK3PB4pebdcvZ D9fbVHkOOHwrPBbFR3q4/epyjbqO+t7GmsEnxh5oPMLIdZ0eMkeFViiPoHHV5HE8HonP UcW2gAZi3SlrW2pfbzPEpOFidOrpbGDrPM4poEdg3u8YbRRoJFtiGzdGuBF9rLeDeB54 1fQye6ITFW9JxCMtIEoFdoLLdsHyaeHcFPLlvwL7r1OybryeXT1eq/L/EzHANGbBQ+MV IQSw== X-Forwarded-Encrypted: i=1; AJvYcCUu2f88ysPj4r79oTDlLRfblvARYa6HkjHgCblY0mYDyt2kh+D9qI4zSRwJXbn7CBTOV57M3ysQ2TtQm4Y=@lists.ozlabs.org X-Gm-Message-State: AOJu0YyN6N3pcegnVAafSE6/lP5EioopHMlvMKofPTzV+a1VlSuIIs8O YeUK8AeM7RXi84+2wP4jWIYohuuox1Crv5GQaKW6iwxUmr+4K3QMarb/cmsuGeM= X-Google-Smtp-Source: AGHT+IGIwf3MFbsmI5L/nn36QcLF0tw2dizRywserImseYHkgoEBii3QkvkJxB3CCAhauX+R+NVkZg== X-Received: by 2002:a17:903:41cb:b0:1fb:90e1:c8c0 with SMTP id d9443c01a7336-204f9c50d18mr13883795ad.63.1724824193604; Tue, 27 Aug 2024 22:49:53 -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.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 22:49:52 -0700 (PDT) From: Charlie Jenkins Date: Tue, 27 Aug 2024 22:49:14 -0700 Subject: [PATCH 08/16] x86: mm: Support MAP_BELOW_HINT X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Post: List-Subscribe: , , List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240827-patches-below_hint_mmap-v1-8-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=2933; i=charlie@rivosinc.com; h=from:subject:message-id; bh=/49vITxLNj+RJRh4dWyqxf17jS8h791m43d/wmsbi4g=; b=owGbwMvMwCHWx5hUnlvL8Y3xtFoSQ9q5XfH5mu/c9Rrzlz8/vq1gj25AnkDItFvB5j/EjQ7d2 dgpWufVUcrCIMbBICumyMJzrYG59Y5+2VHRsgkwc1iZQIYwcHEKwERiehj+Oxm+8In6am8suLjK Qbj6ukzK61nfEx9q7X3ecc3HVutSBcP/QCmOFDVPG+uvAsGmtk+sN15sO6WrIvn+0Hvj8ITPYtt ZAA== 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/x86/kernel/sys_x86_64.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c index 01d7cd85ef97..fa16b38f3702 100644 --- a/arch/x86/kernel/sys_x86_64.c +++ b/arch/x86/kernel/sys_x86_64.c @@ -86,7 +86,7 @@ SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len, return ksys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT); } -static void find_start_end(unsigned long addr, unsigned long flags, +static void find_start_end(unsigned long addr, unsigned long len, unsigned long flags, unsigned long *begin, unsigned long *end) { if (!in_32bit_syscall() && (flags & MAP_32BIT)) { @@ -106,10 +106,14 @@ static void find_start_end(unsigned long addr, unsigned long flags, } *begin = get_mmap_base(1); + if (in_32bit_syscall()) *end = task_size_32bit(); else *end = task_size_64bit(addr > DEFAULT_MAP_WINDOW); + + if (flags & MAP_BELOW_HINT) + *end = MIN(*end, addr + len); } static inline unsigned long stack_guard_placement(vm_flags_t vm_flags) @@ -132,7 +136,7 @@ arch_get_unmapped_area_vmflags(struct file *filp, unsigned long addr, unsigned l if (flags & MAP_FIXED) return addr; - find_start_end(addr, flags, &begin, &end); + find_start_end(addr, len, flags, &begin, &end); if (len > end) return -ENOMEM; @@ -166,6 +170,7 @@ arch_get_unmapped_area_topdown_vmflags(struct file *filp, unsigned long addr0, struct mm_struct *mm = current->mm; unsigned long addr = addr0; struct vm_unmapped_area_info info = {}; + unsigned long task_size, mmap_base; /* requested length too big for entire address space */ if (len > TASK_SIZE) @@ -198,7 +203,8 @@ arch_get_unmapped_area_topdown_vmflags(struct file *filp, unsigned long addr0, else info.low_limit = PAGE_SIZE; - info.high_limit = get_mmap_base(0); + mmap_base = get_mmap_base(0); + info.high_limit = mmap_base; info.start_gap = stack_guard_placement(vm_flags); /* @@ -210,6 +216,19 @@ arch_get_unmapped_area_topdown_vmflags(struct file *filp, unsigned long addr0, */ if (addr > DEFAULT_MAP_WINDOW && !in_32bit_syscall()) info.high_limit += TASK_SIZE_MAX - DEFAULT_MAP_WINDOW; + if (flags & MAP_BELOW_HINT) { +#ifdef CONFIG_HAVE_ARCH_COMPAT_MMAP_BASES + task_size = task_size_32bit(); +#else + task_size = task_size_64bit(0); +#endif + /* + * mmap_base is defined by PAGE_ALIGN(task_size - gap - rnd) so + * subtract out the task_size to isolate the gap + rnd. + */ + info.high_limit = MIN(info.high_limit, + (addr + len) - (task_size - mmap_base)); + } info.align_offset = pgoff << PAGE_SHIFT; if (filp) { 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: 1977644 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=pFRD3xjn; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev+bounces-650-incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wtwj92D8lz1yfn for ; Wed, 28 Aug 2024 17:17:33 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Wtwj90hDYz2ypV; Wed, 28 Aug 2024 17:17:33 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::62f" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724824199; cv=none; b=Zv2mI9y4bvAA9LuN7zFRG8/OUwlM345gV3rcKEyJpmfU0/DTv49VOhbq4lAe8sAEJLpI7Nqso01EB3pO6J+m10l09LlEvj/Ooi5hvRj0UNLo7CmCTKl+MntU+7yf9t0qHW7LSJJkri8bO2HtC1sEKvsrbyoSUPnx49cmLUEBNde4rR7WoldQc21pXMPdh7omy8ext8YlxBX+TLG7L9VyHFjwekwF7LJFynBGB7WjBS9gVC3db3g/c/u8GJCKfsbvR5q2xEkuinwwoaulbSvbNeG3RVMbKv+8yI9zag7Lzkf3c7Znj0gKEwnC8/1gNYv74D5nhSyZd023tWkuTKIPZQ== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724824199; c=relaxed/relaxed; bh=YNQglkp2lEnIf2YsbVUEYoAS4AW64pe58tBCUjsMipk=; h=Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Google-Smtp-Source: X-Received:Received:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; b=mOoHTGz13jgP+0zXgPNb74sMF2/dD3GreE3agwlGSbczB2vDd8BLk7QwN64EKd/RmPUpZ6Alx4vEwX+LW0smntEYx1aFaTIo1cdjD9j2nsSDtfp38C9qc1z9xsxy2UpdIgPmjFL5nyjaSbsCfT9PpAJDB5tqQpon/6FBE8it/pjCqYdThDqxoqThqCppcJVsjXPXfyyi9cZtCvzcg1evcuDI3El4OE0zOt81lUqtQViDKiPMoDG95zM4IJx4zyBXa6utTKd8TTwQgLhWvIImNoB0UA1J3/On2360t4OF/vFbdI6hwadEoKAw8ETSb4wcxMkFl4g8Q9YQGNIzDT69PA== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=pFRD3xjn; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::62f; helo=mail-pl1-x62f.google.com; envelope-from=charlie@rivosinc.com; receiver=lists.ozlabs.org) smtp.mailfrom=rivosinc.com Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=pFRD3xjn; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=rivosinc.com (client-ip=2607:f8b0:4864:20::62f; helo=mail-pl1-x62f.google.com; envelope-from=charlie@rivosinc.com; receiver=lists.ozlabs.org) Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Wttm66SBrz2y8l for ; Wed, 28 Aug 2024 15:49:58 +1000 (AEST) Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-2021c03c13aso2179355ad.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=lists.ozlabs.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=pFRD3xjnUBw81LZgKy+zBzKvZHXyRWgE/gdEatIf0HnYaIoShoANCL8H9JhkQ0Iecs gn0AusuTAz5sc/yGtqOsKfTrOWVqnqKJasoBpYlP8icwOyFpzhFTnnZuw70+gkteStsh DZY+LbkZ7pn3n0Ki9nsVMQygiYuQQ5sgJ9VobJdQOxhKhCzOyLOkr1Q6U7blyMMxXfi0 pPYxZCBqIl8vNT9A4eIpU5izZ3VobSr3fGtDnT9zmlsy7gylKWY90Rk4pxC7hnuTR7UB 52EWXTXryICuKbsS626adXezTrA9O3siO1g8KEcrAO1WIB6LI4ahILU+fMkuU7E9X51Z AI4A== 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=cKL/3JLND0MmL7/I/9E4XGMi+Nq1EV88gA2gU6jBNygiqZwr1Dd1Zm5oZ+/9LD8m4z 6eDBHckWYFZ5dfN2PZgwbpYLX/auvvARJKhdfcZyJoKjsQCvNFWBASyaDmILHahEaPLk 4GLf+7bV/4E34vxg0KzwVoSV3dMtC19A12goCYSDuFl4leBqi4jAn2ZcuE8mWzIgLojG tADmE9LoXm/ALy5bq9a/z+pT8LNPu4iJoS6sWccis/4QmZPGPtlRKao9NXt/6Y3QLOTZ sGQEjjPPLKU//XoupFAyFeWpt7QOXQjKfLRqyHaESg1KNq2QsRMQbQT5WlLorZb9I1FV E4Iw== X-Forwarded-Encrypted: i=1; AJvYcCVnCikZzN06C3PSPMGNfG7d2Mwnzcg6qBgAAT3twgE3fIvZfBq5/vhmKq5GzBvhMg4xgI8lqqhBMIvig5Q=@lists.ozlabs.org X-Gm-Message-State: AOJu0YxqWugreMM87V6J9ksLQoCLe8rzCdj+yIoIbrZCaMHfVrjQybFo Gdkp6qda+JI38oGhbGhdX1lNXPL6laGFi5snUap8PIy23RpMpX3veLn1Srud/ts= 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 X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Post: List-Subscribe: , , List-Unsubscribe: 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 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); } From patchwork Wed Aug 28 05:49:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 1977645 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=HbvRqk3N; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev+bounces-651-incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WtwjH5whHz1yfn for ; Wed, 28 Aug 2024 17:17:39 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4WtwjH1gwJz2ysc; Wed, 28 Aug 2024 17:17:39 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::634" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724824203; cv=none; b=HIPxP8b5xJKSl5Rrko4BkCUfov8gk3FxftwbM7fLy9sP9uSvIvWrEzLXbRUaoVPYHxsvhLt1Phs8XRO6ZMDmijh1ypZJsNmaJ9ni8V++JsIq6rdviWIJ2KvGPPBN4fHJt4c7myZL1Qf8eNxQ2l8hc5xWR2CPh8D7SD1VSIiJTCtif4FmnBgI9K0GYYqd0Cn40Gl6A+yf9kJAdnxxjnQ9H27DeHCiW/xQGThElXHI+4UAFxGQIbnRuhQAwnh2rYARfku4CMAod1Cy7XbqvU88ptbT4MAri6sKLO6isI8cuKSRUndnVvjXLr1rrGmTfwxq1ljsMcbc/DcsMt4ECPSpuQ== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724824203; c=relaxed/relaxed; bh=hfZJveM1parb4u035pYGD3zTISJbrOiZGzu54vNwlmI=; h=Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Google-Smtp-Source: X-Received:Received:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; b=SGsY8w7oyH/7Y6x7khXVWvXAdsMEXTODAp26z3/tmi7X9ur9L68xi7OMZ3q6FfUWU/fJJGWFd/rSOU5mGfa1FeabN/jlT6ObZJ2YERlsvluufY0BXY8viufeDmiLbv7vI3F/d+i4XhUec8T4DWr6HoYmYt9bjlLpVfBRJ1BH3nuTNnf0Z1Nm6cSegSEREUIy0mHHNZQE+MyNY3vqEJBlTtDyBsegZDt4EnulwZw5jCVI8A/ubKoN9OW37/ctiHa/oa/h84qGLqqsD1kmdcZCE5w7MTfFmIMbc4lKEf0XtX9YmftvVY+CZ1KQxGPf8YjmykaBsmYQE2udoGHgyKJKMA== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=HbvRqk3N; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::634; helo=mail-pl1-x634.google.com; envelope-from=charlie@rivosinc.com; receiver=lists.ozlabs.org) smtp.mailfrom=rivosinc.com Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=HbvRqk3N; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=rivosinc.com (client-ip=2607:f8b0:4864:20::634; helo=mail-pl1-x634.google.com; envelope-from=charlie@rivosinc.com; receiver=lists.ozlabs.org) Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4WttmC3BGVz2y8l for ; Wed, 28 Aug 2024 15:50:03 +1000 (AEST) Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-201e52ca0caso44856555ad.3 for ; Tue, 27 Aug 2024 22:50:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724824200; x=1725429000; darn=lists.ozlabs.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=hfZJveM1parb4u035pYGD3zTISJbrOiZGzu54vNwlmI=; b=HbvRqk3NBz5zKQNq/MMjxWS4udvVs6zasoVvYle8E7vMcQXEyxRsZ8VZekUBSiTAKP t+qeeqH7FKpr3xoeDnOp29ZaneGdF4/za3jHmb5CJHiDLkHUTRV8deTLtfepRaxkcGFe CQYw830AyijVKcC6MnAe23VAp6YrMB6/8vPM5hrp0KUUOVo2wtsQSlEaSo6L5tnZO9vL bhmKrfMGEVqAAEnKKX2X+L2GT9YxGqyt5tUfkmkKqr2grqR+06iI+ihy84DvgXCgAzR5 1RMVqJ+QsBs/yDnaFHcs58qdIkCWDrH4BnMe4RCQFPK9j6NwPc+pD/mp5RRc0g4dB+0s JgLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724824200; x=1725429000; 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=hfZJveM1parb4u035pYGD3zTISJbrOiZGzu54vNwlmI=; b=fEwskMN2FUN2YMP+779Su4m0J4qwAzCTOrawjzaqJy82CNjkSby7/u7eYsHZiQgJ3v GiXID9+vBalP3ycxngnsG8TEudCfAzBDEYD1AbpuUfEntB/VqQDMSRQV1IvukJjSsKAb bzcnPc3PRfnfzbcmIES7az8Di5bEsB//MbJ7mfvEB0iI5fxqH35LhcGBcqjlU/PucTTG QVm1UHohynyNKj6IKZR0MPGxSW3IVbMkHZRnEouPgg7q1+g410Mbt60FtB6WEwWjgrSK zCk6glvi4uSDOHxij2Vp2IejFGm+TEyqNL7wbgYnwuDGJ8215qi6C8jRIe4Hu0/bJje2 f01w== X-Forwarded-Encrypted: i=1; AJvYcCXXMpx0Yh1p25j41T+zfDCWzbXH0q/+GOCpw0A091tlnShhm9D84mH7wKvj9VuyMYdDk4zKTm+Fmhrp83s=@lists.ozlabs.org X-Gm-Message-State: AOJu0YxzmFMZSXZGkvmWWciwPSa274KgOhE4xIy3e1sviV9aYCvEsYn/ 2frlsbQh9BYaFvVVcx75zj7QXYNcI34fxqYrQLXHmF6Segw4Tm1w3cvM19gfCdw= X-Google-Smtp-Source: AGHT+IF596NtgPi2otbs5poJBgAoGUDj9IXzCrdKWZMEp8cIFyXQZx8MxZQO71jW2zsopg6SUNTImQ== X-Received: by 2002:a17:903:2352:b0:201:f065:2b2c with SMTP id d9443c01a7336-2039e4fbbe2mr155506935ad.55.1724824200296; Tue, 27 Aug 2024 22:50:00 -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.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 22:49:59 -0700 (PDT) From: Charlie Jenkins Date: Tue, 27 Aug 2024 22:49:16 -0700 Subject: [PATCH 10/16] arm: mm: Support MAP_BELOW_HINT X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Post: List-Subscribe: , , List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240827-patches-below_hint_mmap-v1-10-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=1701; i=charlie@rivosinc.com; h=from:subject:message-id; bh=1syBnrvTSOlOGGJG9VxttpQivuBkydj5+eNQ5N/relM=; b=owGbwMvMwCHWx5hUnlvL8Y3xtFoSQ9q5XfH7+5/NObdD1TC7as2nnrut80uYIpiTE6QKMsStV jRo9UV3lLIwiHEwyIopsvBca2BuvaNfdlS0bALMHFYmkCEMXJwCMJH3iowMbzKLnvWynRbmDQrg 3uNwlaGFp7De9nT0tCfZV9Zxzb2swMjwZeP9u8Jhqpz79ln+TNZVkXSd3DxD3/DEm3BhhnWsrp8 4AQ== 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/arm/mm/mmap.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c index d65d0e6ed10a..fa0c79447b78 100644 --- a/arch/arm/mm/mmap.c +++ b/arch/arm/mm/mmap.c @@ -71,6 +71,8 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr, info.length = len; 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); info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0; info.align_offset = pgoff << PAGE_SHIFT; return vm_unmapped_area(&info); @@ -122,6 +124,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, info.length = len; info.low_limit = FIRST_USER_ADDRESS; 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_align ? (PAGE_MASK & (SHMLBA - 1)) : 0; info.align_offset = pgoff << PAGE_SHIFT; addr = vm_unmapped_area(&info); @@ -137,6 +145,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, info.flags = 0; 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); addr = vm_unmapped_area(&info); } 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: 1977646 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=serfCQJL; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev+bounces-652-incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WtwjP6lwXz1yfn for ; Wed, 28 Aug 2024 17:17:45 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4WtwjN636tz2ytm; Wed, 28 Aug 2024 17:17:44 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::42e" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724824207; cv=none; b=UScKE2SjatI4Onm8aUo3strEIddn0tlvE2uNYuVOxpSRCA0r4piVe5HtkwoydT9uDIlRXvq1GgTPOL8DNDp95HMPbIN5jfkHY3DSBdQrL8p5nbJKj/IWGtNMs1gZRIVWmLoEKNv93Vff5Nh+ihgiTTJC21r4yI20cFhPV9LRbUMAxUsMeTHbfIuctdoP9LqlpaIhFCJwytViFdbsIxcEjDdSDWYPrPl2w/MJRpCZk81Qir75lCFdiyZUg8UITQgIipW48FmWEp5skXZEertyCmTxY2PRHmpaHRhox0TotI0QlTyKHjbKqms+Yt4tqXtSgIL1/Dk1s1Y6cwjQBgeWjg== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724824207; c=relaxed/relaxed; bh=cPn63wqFJg/NhDtyE6TA0coeolvG0b692sVkrxs6h6w=; h=Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Google-Smtp-Source: X-Received:Received:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; b=Oj4RUC+eR5fT9i49irx3GigkDX5LZzUF02mX2kC8pBO+iHoJ0GIXbeF3NwdMD7Tg2ksxCqLQoonFxIMCvL/OVwZxbv2bq2CZS9xM97cYdNUD+eTZw0ZbSN759QRdm0MRcRri8XRrtx26OTgdFmotaq2MlXV1D06vjLKqFuuCmSf1Jx1Qbb5oWp8zlDROOT31BVlCY2CLF8+lAkoxO10xX6/VRd6OvUJPGX/l5MzJ2bHEdRh9lPolg9BKcmhk3UR/14iv9D0CFiIUUIC9IW7QGfElYZRmr501bFBqGGx+uaLHHKHZ+REZWnjlzOZwJ+ULznNmo9O8vxO9GjV2Hk8YPg== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=serfCQJL; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::42e; helo=mail-pf1-x42e.google.com; envelope-from=charlie@rivosinc.com; receiver=lists.ozlabs.org) smtp.mailfrom=rivosinc.com Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=serfCQJL; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=rivosinc.com (client-ip=2607:f8b0:4864:20::42e; helo=mail-pf1-x42e.google.com; envelope-from=charlie@rivosinc.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4WttmG5Nvxz2y8l for ; Wed, 28 Aug 2024 15:50:06 +1000 (AEST) Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-7143185edf2so5288872b3a.0 for ; Tue, 27 Aug 2024 22:50:06 -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=lists.ozlabs.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=serfCQJL0cy5P6tJQKIXG0XvB4P3TamDJc4RE9kGGc0hrUliMe8yf7xFrQwLcdzast Jle6SA72p0X6kT5gYzM+isp1N5ass4oodGDfE8TiYBb6RLyHGWLU01ZuhJTr+WEQtSyg UJcKcYoePfX2FqDJDxdd5fntQRJaImVNByzutzRYH3RCoM1usd6sCOjuE+aixKCFhADw WSaZRGO+1DJdue0t0SWIKYkrgWYfWF+GiqGhaiIXlIkchchYfRRSgzPolTDLX2w5+jAC LhwP7WrEIUtmjMj46ey4Ajw9mE0Zd4mglaf9cSgU/lVZuwJLQsnfKY+XfWvkMYE418A9 5LVg== 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=j4C2v3Hng2WatX9ApamjgQlAJX2ut5ha+4lC3lGQyHCC+sruv+OLa4sf7OxvALoWo1 1I9lFDiYFc4ZeXQPWj0uR9fS1Lv1cXI2+ZnP2VY9ZVMbcHiOzFMIzxwuLvK4H7T8Uj0W slzlVkS4P0KAKKa5EljE4ifZt8U12x+uqbvLo4K824HNvoWO25sYDlLxlb/bjfYui2B5 VNaKGZ0BnuObtmVwFxLOKEyvslLqdqhil8JjKbwEdEKNm21NAdObRG9GVrjAIo1RlJQC iDhwaWE1ddhqfu3VG7ZItxj0tIXlsVMMpSmhlTDrDweJ2YWrrls7XwZT2+ldtWTkRUTF v07Q== X-Forwarded-Encrypted: i=1; AJvYcCW+pF9gaaKLWPiZ3udLFPRs6tIWYBm096B+mrNH+VlcksgSaube88uqiUY+l4rB4qeL44KBN/F3W+RO7Lw=@lists.ozlabs.org X-Gm-Message-State: AOJu0YxqqMu5L9q3c0NPWnH4937AwcCtGLWti+PeISETWxO5Qe9DmLYX dT0orjblwNYkrMJ7zOkl0L6hDssu/cx1LqjUtA7RbhYV8KlXjCPtMYBCJgU+lJk= 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 X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Post: 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); } From patchwork Wed Aug 28 05:49:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 1977647 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=PMaRUmmr; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev+bounces-653-incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WtwjY43Rxz1yfn for ; Wed, 28 Aug 2024 17:17:53 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4WtwjY17X3z2ywC; Wed, 28 Aug 2024 17:17:53 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::634" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724824209; cv=none; b=IWvYbQcMNaiA/KTB9uMrsNdLa8lM+8vrdSiLTtEjgEHCSTP8CYH7L/b+IoSdiCk/V2IIgcuhKdEhkWPK+lwGa1obHRa5jLwIA0cNbgUMc7QD2wBijVrI/Au3zcTgG9E+lanS1ckQja1V8HKDWtWAIM1d3utnCGA429uXWD5oQM0bh8pQ3IybVQivSVZhemKu+3Vx0Lgxx+P/63sNxxWQjdAATR0xis158DLxgr8ij2aHrbKquUlD+6OhnfVb43Mr5rJYWdN41VoXaSuS6hHP8TQEKHzkuf9vqLDELqQGBKlWkLnGvwIYOIWo5819n4aoWnL0ayw3Geyr376n5mXsTw== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724824209; c=relaxed/relaxed; bh=mnBGdEXd1SbkXIrtxJgk/JDNcWExLMEwccaijei9Lbw=; h=Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Google-Smtp-Source: X-Received:Received:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; b=KtN30hNOkESoWSRgic1U77EP8RTNpuLV5YgR7Wq03D8C1K46KglLQudLE2MgKkoR9yPkFKyHquJFtop64LtIdfpULTVQDQlTo3o7A+RCIdgq5984Jz4cSBPixwKRO8yeflscObmzpJgrYnLGOr9hEhc6PPfuAoZnGCpQ9FxkcPM2B7oU+KVnyoRCc6P/5zsBVeEhyP2Uf/rk3iC07mDmAV07mE6NsRkZRwi9TioCqQNy1gPHETn+LZJ7r7vegmhhz3mqe+qKcniX7h7XOVTe87rEtwDSMzdeOqYnPOHYN1+uA+e9yhn+RVXEa6p07TmJRF/39bk5Si3yueeLkYlZeQ== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=PMaRUmmr; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::634; helo=mail-pl1-x634.google.com; envelope-from=charlie@rivosinc.com; receiver=lists.ozlabs.org) smtp.mailfrom=rivosinc.com Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=PMaRUmmr; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=rivosinc.com (client-ip=2607:f8b0:4864:20::634; helo=mail-pl1-x634.google.com; envelope-from=charlie@rivosinc.com; receiver=lists.ozlabs.org) Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4WttmK078tz2y8l for ; Wed, 28 Aug 2024 15:50:09 +1000 (AEST) Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-204f52fe74dso5247605ad.1 for ; Tue, 27 Aug 2024 22:50:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724824207; x=1725429007; darn=lists.ozlabs.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=mnBGdEXd1SbkXIrtxJgk/JDNcWExLMEwccaijei9Lbw=; b=PMaRUmmrPEKsce+u1wXsd/WmahiOIItHjt7U74UdsU9jozsJZHIGKI7+gt8dvxXirq 2DZ3WlEoAKldADi5s+1mhqU7FNC49BSB0Cjl76lG98CTSjtSxdXdSIc6crhZXzetUcEi tb2dElOoa7eApiRm3q0auQKK6GYf9zjAit5IxCXc7YhnGGFJwW/GthC57dVBq5lOdpb+ IA+vnZqnxvItiJnVj6QxNRECf/XBCL0inpab4zgiOEOv9BU9a6yx3viMCiYMrNqmusVB d5aAg9YusOMMBGOsozYX9rRf7PxROr0GVDw22jFK9+gAHN4o5k5A3AKOvLVsh5nTtMOH 8VxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724824207; x=1725429007; 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=mnBGdEXd1SbkXIrtxJgk/JDNcWExLMEwccaijei9Lbw=; b=DbwXLlbMJ+GZv04fyrtFjmRTkYRiA5mVP3fOUo0pXSdedo2Q72UQTtZ0ubm2NX+Rhz zq6hpyxhusfiUmdhOaLiY8ElAoatbUYmhsygTrWfyAU3EqoSUJs4ydWyXGygfoYSElm3 JjiVr5XziYgzeQaPB3KrUA6cOIsmPw0JI+46ssQ4fOlk7vJgz23jmgYrDg9ANyZC0qIM WDRx0J7pSluF0Z4fKL4PJSmOh4AwNSmmZnTaLW9Rw6Jl8pNXzx5F21b3/MW6zPw36PxJ n+a1XMx6rcBApMlcrmcBddTsqzFTpjC7zq4slGIe9GfyCnreoThtN8yGJyq5WCLmDUrM LyVg== X-Forwarded-Encrypted: i=1; AJvYcCXmtZL73AE/ZTg4oDKnSrrAUnuShkIcVnOvFszi5nhFjHuL/Yjzay3wVkxBEalbusn1CSuwOmdT+Knf7xI=@lists.ozlabs.org X-Gm-Message-State: AOJu0YwrsJxFYZOvGWAf0zat00u67OQlg7NIFeMLwMVoBOIMOPTZKkE+ YmPEO1BdAVutMRHR6kvKEz+MVGQzN3/dQjsVcprJqH0XHnm4jFYv2OHQGpgWB6M= X-Google-Smtp-Source: AGHT+IEsQQCnEuxvR964+0rX/KlAEG5qqvky10H/EfSUq5MJAsWWGO7Ld//wKHkIp7XPnG+kf0G25w== X-Received: by 2002:a17:902:cf07:b0:202:60e:7700 with SMTP id d9443c01a7336-204f9a548eemr12735035ad.7.1724824207147; Tue, 27 Aug 2024 22:50:07 -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.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 22:50:06 -0700 (PDT) From: Charlie Jenkins Date: Tue, 27 Aug 2024 22:49:18 -0700 Subject: [PATCH 12/16] parisc: mm: Support MAP_BELOW_HINT X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Post: List-Subscribe: , , List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240827-patches-below_hint_mmap-v1-12-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=2500; i=charlie@rivosinc.com; h=from:subject:message-id; bh=RM+/CbqQAwiDfaQaSk6aR6JgRkcXqI3LycpAEGdsrx8=; b=owGbwMvMwCHWx5hUnlvL8Y3xtFoSQ9q5XQl7j2395l162Zz3ULDsob8MjXdzJ1/bXx7d7Lq5e d+zLQfcO0pZGMQ4GGTFFFl4rjUwt97RLzsqWjYBZg4rE8gQBi5OAZjIAVaGfwp5ZTFJes0Kym85 OvJO+pR7Lg+83rfo09z/TvfTNed8SmX4751+T74tYdaFrpd5nh9q5rfzOL+4IN+53YNdoEni27c l3AA= 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/parisc/include/uapi/asm/mman.h | 1 + arch/parisc/kernel/sys_parisc.c | 9 +++++++++ tools/arch/parisc/include/uapi/asm/mman.h | 1 + 3 files changed, 11 insertions(+) diff --git a/arch/parisc/include/uapi/asm/mman.h b/arch/parisc/include/uapi/asm/mman.h index 68c44f99bc93..44925ef8ac44 100644 --- a/arch/parisc/include/uapi/asm/mman.h +++ b/arch/parisc/include/uapi/asm/mman.h @@ -26,6 +26,7 @@ #define MAP_HUGETLB 0x80000 /* create a huge page mapping */ #define MAP_FIXED_NOREPLACE 0x100000 /* MAP_FIXED which doesn't unmap underlying mapping */ #define MAP_UNINITIALIZED 0 /* uninitialized anonymous mmap */ +#define MAP_BELOW_HINT 0x200000 /* give out address that is below (inclusive) hint address */ #define MS_SYNC 1 /* synchronous memory sync */ #define MS_ASYNC 2 /* sync memory asynchronously */ diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c index f7722451276e..feccb60cf746 100644 --- a/arch/parisc/kernel/sys_parisc.c +++ b/arch/parisc/kernel/sys_parisc.c @@ -148,6 +148,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)) return addr; @@ -163,6 +170,8 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp, info.low_limit = mm->mmap_base; info.high_limit = mmap_upper_limit(NULL); + if (flags & MAP_BELOW_HINT) + info.high_limit = MIN(info.high_limit, addr + len); return vm_unmapped_area(&info); } diff --git a/tools/arch/parisc/include/uapi/asm/mman.h b/tools/arch/parisc/include/uapi/asm/mman.h index 4cc88a642e10..297acc0f7b2a 100644 --- a/tools/arch/parisc/include/uapi/asm/mman.h +++ b/tools/arch/parisc/include/uapi/asm/mman.h @@ -40,4 +40,5 @@ /* MAP_32BIT is undefined on parisc, fix it for perf */ #define MAP_32BIT 0 #define MAP_UNINITIALIZED 0 +#define MAP_BELOW_MAP 0x200000 #endif From patchwork Wed Aug 28 05:49:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 1977648 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=wFB7feF+; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev+bounces-654-incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wtwjk4RWcz1yfn for ; Wed, 28 Aug 2024 17:18:02 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Wtwjk3Bxlz2yx7; Wed, 28 Aug 2024 17:18:02 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::529" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724824213; cv=none; b=LSIpoNdoqs7R7OlPe8rMEFMI+e+RelPxrUtSPi6SVu29mUjrWa9hsnng6VU9SzgRFaWVg58l6Z5RlUBWJmBG+DJ2f5pri+6cQfg2ZmnxRYp6TwO8thOO6Kyrgsn7XK11pFZxZARTAgUJzEDA5S82ooRgFEOxvKokWoyLRUwegCUqxPpvy3B+tzPxcEqXyrJFZwoXPcxf4ntGB4gqY3ASYLucaBMk3Pwf09s+7OdPz1Mdaw3QpWuRe4B7GhgyKP6GtfJGowfZi/SCa+5E/wkUfe09UF1OBhSWtpLcszgKujhHKJtYCYeJ4u8FGlFU2iHVaoNQ967WBFj6UdCmCGQCxQ== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724824213; c=relaxed/relaxed; bh=AarzQWw7jN5pNetRW1c1iMmZVGfhSNhFxAvdf8X4j7o=; h=Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Google-Smtp-Source: X-Received:Received:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; b=MXYylszzcmjh3j/MmSmh3qNwD3Ao6AVqZZPs/+ld6iHzK5/ZUNYeqo6e4r8jtymXtZRR7ZkjPUBJ4MFxMAoLgwL3bR3qJfnJLApCZM2W6Pe1GjIqmsrSzPIXzpKYJZX6kGEhzTCSm7wfoov70maEiwKbGNQGo7ViG08qY9LL/TfgoNbV3RirEMoMASkN3/jnXQjJDy/R9DnjSsYieygCWWoLgkjvuj9u7fEwWv0W+I0fFB0h76fQX0i2+8xKV65ElYsV4rwoqqfQ1lw9q6byBCuh+gkUKGW4tyIZSJNuGil3Kx+8MJshKQGc+6USCXQDHQdsHydzj0KkhrU8TcjZHw== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=wFB7feF+; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::529; helo=mail-pg1-x529.google.com; envelope-from=charlie@rivosinc.com; receiver=lists.ozlabs.org) smtp.mailfrom=rivosinc.com Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=wFB7feF+; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=rivosinc.com (client-ip=2607:f8b0:4864:20::529; helo=mail-pg1-x529.google.com; envelope-from=charlie@rivosinc.com; receiver=lists.ozlabs.org) Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4WttmP24kSz2y8l for ; Wed, 28 Aug 2024 15:50:13 +1000 (AEST) Received: by mail-pg1-x529.google.com with SMTP id 41be03b00d2f7-7cd8d2731d1so4170534a12.3 for ; Tue, 27 Aug 2024 22:50:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724824211; x=1725429011; darn=lists.ozlabs.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=AarzQWw7jN5pNetRW1c1iMmZVGfhSNhFxAvdf8X4j7o=; b=wFB7feF+21gnLxKuHpAbKy8QRan2hlak+2QiNPOOYHpnHpkYAaoUAlFboiLIIe+QqN RSfN6dPSJmx6rL109iLAieWvMOwcFjzh+aAd7b71JZQIcaWI4DUMLl+kJzbreQj2MgJR CT7dQ2ZPRcF7CIV/ev777vzT5XDwN9h2QqDU667rL8E/I9inTvhoJ8gL9v3UFiaxqI5d e749Xwj+vuBrbWQG5Evaye+r7QQnOGC0jl38JJxF/jvV7WiP0RSd3UCRFn8hPitiJU9Y gei1WdtDLMN5CyEcmJnGWT6euZm3a0XIAdhnt/Q7D1KFqdAoPzSoloizSq0nhPkpgqiA oi2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724824211; x=1725429011; 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=AarzQWw7jN5pNetRW1c1iMmZVGfhSNhFxAvdf8X4j7o=; b=e21dHAbmjqv09dWsLZ5lvpfquAdc44Cl16q4cJLHnp4f7+Kw4eon+AsRCe8k+HpOIN Z+XLAitfHUybhW6GAlC1sSM32mFNXEXfwKtMiVSvU/qcd0ou1kr3QHaIItBx1caXT0of P2FZF6yJ/RZiyMhucQGhVTO9LmjghfZ4wo71OTKh9ShPy0744HRFrYjHbUYtUPq4J/Yq Au6bwQpPpWFPbhpRLONcAWDSSgYxxvHdUOSgaxcRxnDdgnGQ81l7gfeazJh4PcDYNY/I Icq7kQde+t8y1ZU5GYMXOeXPenir1g7cPMORmAsvLrb9a53zHxinxUpXG0U9EtlqCLUs OQUw== X-Forwarded-Encrypted: i=1; AJvYcCU2WuDMlUVmHAKwUfkRgCSmdRV41OAXnkLBKvtpbKkbNzCX1GVza1W/n8TLOGyFUv4qs2h67/6AJ5UqBeE=@lists.ozlabs.org X-Gm-Message-State: AOJu0YxrNzyN38JM06TwsA1L4QFfIAdBbdsnuK4k03ROziAQjbILKgA3 aRqAdB9MxJGiSehT++VBGPd65nq16upr3rPXGVdHnoKGbCFzM7QbDdTrKryjEtg= X-Google-Smtp-Source: AGHT+IGSDxOLe5G0EzaI75j/pi3mF3L/KyOur/N+gUKJdt7aHyrcvZDzyi6uPsaAVyWSE2f/rnhW5w== X-Received: by 2002:a05:6a21:2d8f:b0:1cc:cdb6:c11a with SMTP id adf61e73a8af0-1cccdb6c913mr2470861637.24.1724824210534; Tue, 27 Aug 2024 22:50:10 -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.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 22:50:09 -0700 (PDT) From: Charlie Jenkins Date: Tue, 27 Aug 2024 22:49:19 -0700 Subject: [PATCH 13/16] s390: mm: Support MAP_BELOW_HINT X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Post: List-Subscribe: , , List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240827-patches-below_hint_mmap-v1-13-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=1730; i=charlie@rivosinc.com; h=from:subject:message-id; bh=LDlOb3puh00G9LsastMFHCdP3tuzGW5CWMac22J4/f0=; b=owGbwMvMwCHWx5hUnlvL8Y3xtFoSQ9q5XQkTzp+9JuBqJbUp4CZHz86P7jsl/+dUPtx28/aiw uJ/F77s7ShlYRDjYJAVU2ThudbA3HpHv+yoaNkEmDmsTCBDGLg4BWAilewM/zPyq60vOxt27XXL PhSUqxi9dMWuaSXlSf4nvq4JmxBdu5+RYfa1r9wzZq5YzaDtGr2m541pUMtOl1Xnuf/rbZGaqVf Eyg0A 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/s390/mm/mmap.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c index 206756946589..29e20351ca85 100644 --- a/arch/s390/mm/mmap.c +++ b/arch/s390/mm/mmap.c @@ -105,6 +105,8 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, info.length = len; 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); info.align_mask = get_align_mask(filp, flags); info.align_offset = pgoff << PAGE_SHIFT; addr = vm_unmapped_area(&info); @@ -143,6 +145,12 @@ unsigned long arch_get_unmapped_area_topdown(struct file *filp, unsigned long ad 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 = get_align_mask(filp, flags); info.align_offset = pgoff << PAGE_SHIFT; addr = vm_unmapped_area(&info); @@ -158,6 +166,8 @@ unsigned long arch_get_unmapped_area_topdown(struct file *filp, unsigned long ad info.flags = 0; info.low_limit = TASK_UNMAPPED_BASE; info.high_limit = TASK_SIZE; + if (flags & MAP_BELOW_HINT) + info.high_limit = MIN(TASK_SIZE, addr + len); addr = vm_unmapped_area(&info); if (offset_in_page(addr)) return addr; 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: 1977650 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=tyGjbk0b; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev+bounces-655-incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wtwjs3XVPz1yfn for ; Wed, 28 Aug 2024 17:18:09 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Wtwjs2MKjz2yyJ; Wed, 28 Aug 2024 17:18:09 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::633" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724824217; cv=none; b=FEEaDC+wZ9+o1AnQcn3Y1SiOrpKk3kDPXys4ncWbwy+ht33JL+/1FlIUS9MXZBHBwVVMNyDw/Y2NMcI3odIxFQ6PNm6xDrM4tRpcXxcXomoCa457Nq4Y3220uTc1awHEFot5La4ce0193ZPdUWbx+u2qFxUM2HTAAbGgEPoX4+wx/2ubGAA6KQ5w/0EgvvhY73hqjogZSbhLSKzRnB15BxI6XYkwH34plwCiudVVkhGlrhYl/8CJUzrq9NBJzWjGskp74S9/DQcGr5xJthE4CeGxoUz8q4jEgMAs9YOSHD2gdQu39hp2R3+xN1PTzJGP2pAQdzzkrC3n8cdvr34BLg== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724824217; c=relaxed/relaxed; bh=74ih38qyFApS59Oo5hAHcKEdd4ieUrnz9WHar/pXDMA=; h=Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Google-Smtp-Source: X-Received:Received:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; b=Uidj1uA1A3fB02qPy/SxFzhEcVdV7H6u2JlGuffUVW5n46isrnmrjaMoYbykMDcFVJnp1MYAl569bDwysZ8ftPe4JJPLM4K0lBK3jjKQEuVoq+Z6aZs+IfREnScNC5GPzOZoiLI7N27zG4GY/fAsm4WokmP7glrc/SUyYoLi4nK2jXh6brGm0kjMpW/1wkFKbg33Rxx7R2QDAC6kEoQVExQOL7e2/B05+uYavqmCP8ubYggiEzm4r69SiXQprg7i8x/CoLzTC15V00ZwEvKWHXrYeYF0sBR/Xn2jAGCHjfBtWSOXDFfWHjO7gbJWQ+lntRJgOUJFAtsZtKMNSzrDAg== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=tyGjbk0b; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::633; helo=mail-pl1-x633.google.com; envelope-from=charlie@rivosinc.com; receiver=lists.ozlabs.org) smtp.mailfrom=rivosinc.com Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=tyGjbk0b; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=rivosinc.com (client-ip=2607:f8b0:4864:20::633; helo=mail-pl1-x633.google.com; envelope-from=charlie@rivosinc.com; receiver=lists.ozlabs.org) Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4WttmT03jzz2y8l for ; Wed, 28 Aug 2024 15:50:16 +1000 (AEST) Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-2025031eb60so55565575ad.3 for ; Tue, 27 Aug 2024 22:50:16 -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.ozlabs.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=tyGjbk0bX1+zdr2YGHWu+C7v+cHRyMzTHWa2c0dxUI/V1lSJrQoJqlLbNu6nZlNgy5 2x63wfhLPvMwKZiJAyVxyFD11W00cDgJHgNCfvFJm/Vd60pdnilE0IZyWTJov/MC48AZ 5VfBUTIjCns5FMaLbMaeOIRIa73eV867u4v64iB2+bnuOVjIG0rjJlv0q01zE5vvIbe5 /IaRPE3isVKpVYoXN8/qkxSX7NU5XOed8pb+gXYg+48Aqr6Cb1bVQvbUPBpdORb9n/VN 6BG9wxgz29wlz8cvowLUPbxiK7w8A0F+/nQTtYw9yhKFQtnyqqfPH6gdq6GQvJsWVXJ/ ozDg== 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=A3TniCniGGoDY1FxYDWQP6G1PVyexeVVIiWnfvsUOKieMmzHgM1mXUlrCIZlMPSsNT Kr3ZC3IwojzFIi/NEo4oK1Hz+P01tMKUA0cMScT25Yb9w8JESC2M8kVjkDhjYjjt8H3w LJFUxjndHcehtycI2xaZyq4HG9+LCpM7nU8RROERBErxzr5W3NPlYb821FVvhZqOw7EO 5olJWdsTxpLRYorjGOGhVPB5mOroUxq7ruNFLgGIdLgxE1zX0soWPqV9cxrdoanbMIUX A3RJrGP6ksrHGovFyAxYRVpthMu6YCRl8d8p2+sfQ5prwPlcR4UIu5GD0iq1IPLwp7J+ k3uw== X-Forwarded-Encrypted: i=1; AJvYcCWE22X2Xo0yhkxKfAHDedTUojBsv0yAmDw2353UywzebHV5gMBwTUjTO48SNTbEf2h9jK4LOonGRVfHFik=@lists.ozlabs.org X-Gm-Message-State: AOJu0Yz2fy0bUZ4EV/K8mUK11MX1FCVXCJQC+8AZ4ijOKRQ9EXLGcEOX fFM9OArjvtWMovXVYhBLVBQjGw9NkhLuEohpdcyeHEIX38Twe/yfsZ+oobawX60= 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 X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Post: List-Subscribe: , , List-Unsubscribe: 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 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); } From patchwork Wed Aug 28 05:49:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 1977651 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=WMrFr1U/; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev+bounces-656-incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wtwk03WZ7z1yfn for ; Wed, 28 Aug 2024 17:18:16 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Wtwk02Gm8z3005; Wed, 28 Aug 2024 17:18:16 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::633" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724824219; cv=none; b=BhYqfxJGUR+ZUMiPSbQVAwe2G84FWetulilpjUbNP1suV3fWczG9m+jXdWT9UBJe2SIjr3yVruE/LuiT7oCCOCwbdrfplV7Izn/IzbHESAIShs76MSvVmkJsMDX2JSIKAW0aG3VJ9eqpmqodlhJGS1nPwZbP+mh3ecNQ8yiaCiLQ7NcPMVBnyn3sd0XccIqTU4U4bv9DE9/ckuEKIYFbRWsmcVcYwEQr/GOPa0jUt0pMbBTkQTfwMTIA5pnwUDlOJ10Vd0P9oD38/a8eKnYfATpQq+cZfjfgp/0uQv43LFR+PcE0MVV5k62CjTYfMpeN+r4oV96QTDxARnzhekjuEA== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724824219; c=relaxed/relaxed; bh=N47VMRtMS+23qmQV6QvpGjMmEbWavAKSyy/PH2d+fuI=; h=Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Google-Smtp-Source: X-Received:Received:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; b=cm/wcU8206RsME5L+NQI90T0LC5TwJlXaSwiqqWdyi2UAjevGO1Yp/C7tfYopxyByllVeXLLj5crj1+wZk/YtEwG58k3yxyZNgNSRVgcoO7FLsPfPIZlVvWe8Lm2XVvTv0ipHNVLPZ2VAaOggOutvCpv10a7U8q6FTp1Fc4G7QUJYTUBliMTUci4DFQWdhaBqGRQ7vxniL6NKB8B9GNOoCLaEUHy8pKeSFZR/ss5itBq53NkjZuXMdbxasWzWKJpmk+o4xNeKRIEXGthakCsKQs2oSeASOSj4vdxpVoVPdsR0uSUPD51L2uA8kbp7Yd4s5OEi6JmE1vC+dT4fg8/Mw== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=WMrFr1U/; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::633; helo=mail-pl1-x633.google.com; envelope-from=charlie@rivosinc.com; receiver=lists.ozlabs.org) smtp.mailfrom=rivosinc.com Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=WMrFr1U/; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=rivosinc.com (client-ip=2607:f8b0:4864:20::633; helo=mail-pl1-x633.google.com; envelope-from=charlie@rivosinc.com; receiver=lists.ozlabs.org) Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4WttmW1zn4z2y8l for ; Wed, 28 Aug 2024 15:50:19 +1000 (AEST) Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-201f2b7fe0dso54344695ad.1 for ; Tue, 27 Aug 2024 22:50:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724824217; x=1725429017; darn=lists.ozlabs.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=N47VMRtMS+23qmQV6QvpGjMmEbWavAKSyy/PH2d+fuI=; b=WMrFr1U/Nqda3GLL/15+bSRmqbEuwdjHmFIoc08hjlfuDSSyUkOS+QjcMwRli2u44E 3/GHyaMa5YqRmc88/0VDofPNpUN4qxzuOqjSb8mswp6FrLxaHYbniYpQAgNzjBWtU1m6 t6osqTObtv9wx3ERgYhBoquFtgw1UKKZSeA2OX1aan7HU6RNMYRWyzEcrC9424r/e6+a 4o2z1qOxYRf65E9xWCNgEQFurk39/ds9nswvf/R5ud6iwzJn37sY5HXrWNm529hmJljV mODy+H30DIiUf0ya2/TpCkPgQ21+poWRtU34jx37Vvl+jxuxTyKmg1jGS1MomT6y7tDp jUtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724824217; x=1725429017; 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=N47VMRtMS+23qmQV6QvpGjMmEbWavAKSyy/PH2d+fuI=; b=UL09ka0LcY5M4iPR6QZtJik4AE675XG7H/urJqFAI3o+H7VOVGXWXADC931S16OzkV EzC7QH+8Vp3BbTYI5I9kDHMQRtMqK+KicLyeLW9HfoASmXyvJ4HQlL4Up0Y6ZwoH6dli Bhj2imwrgs1rqGVKiaXhrTpqojBVQsDrmZB+a5vYPyGbXHoKRltSgMC7tKNRLd1glayW iANI/+UheGC452gvQi9/q34ftf/pZKYvPJpDNf+ET2DGXkN6VnRHPNjW/A55GLLSKiX+ tuBnYMdG2a/EAGBSvS1ZoXeiAvvhC6VPtrV0+EgSn4X+XdgFQscAAMzb0XsvLWYqCdCi egXg== X-Forwarded-Encrypted: i=1; AJvYcCUCnXa+QTK3O5sofWY+xU9V5X/aCx5CNE03aQ9ZZ+L3c22Xjbygbdq0yoyyxGqSPWBNpeuiHTKGzRLD8RM=@lists.ozlabs.org X-Gm-Message-State: AOJu0YydMHG4klH9co8n+jFV3ZFQ8KGgT8VgZKNjJxG61BPXB4n7uXmX K3pvXkpMp4tGX371R3Q8bT7KyeGGw/93WfbXHQNJX7Rgwl9NjCN48u00ZVSqxRA= X-Google-Smtp-Source: AGHT+IE/8VPZ5WR+s//SHKXEyZvEaL/le/g9NWegqdCzDXKzmKgVVr+pZGJ3+/nFrNKyDvBxKE7OYQ== X-Received: by 2002:a17:902:da87:b0:202:18de:b419 with SMTP id d9443c01a7336-2039e544ea3mr139583445ad.63.1724824217429; Tue, 27 Aug 2024 22:50:17 -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.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 22:50:16 -0700 (PDT) From: Charlie Jenkins Date: Tue, 27 Aug 2024 22:49:21 -0700 Subject: [PATCH 15/16] sparc: mm: Support MAP_BELOW_HINT X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Post: List-Subscribe: , , List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240827-patches-below_hint_mmap-v1-15-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=2007; i=charlie@rivosinc.com; h=from:subject:message-id; bh=wabvkTSjqwqq+1cwlxkGF9sQYYmBw7yR2/kPTnsB9SA=; b=owGbwMvMwCHWx5hUnlvL8Y3xtFoSQ9q5XYlrm85cSrl9L9mw2HGFibquxLlDQQX5BVPY7r2Kn Fj9yFu3o5SFQYyDQVZMkYXnWgNz6x39sqOiZRNg5rAygQxh4OIUgInUNTIynHcLq9918a3O8avu Dw03fBV2dVbdxHna5i+P48xVwp561Qz/s5amcHn+vlr756VDtfCFS81padcPXfr2ZkdR7ZMDnv/ PsgMA 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/sparc/kernel/sys_sparc_64.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c index d9c3b34ca744..b9ce9988551a 100644 --- a/arch/sparc/kernel/sys_sparc_64.c +++ b/arch/sparc/kernel/sys_sparc_64.c @@ -129,6 +129,8 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi info.length = len; info.low_limit = TASK_UNMAPPED_BASE; info.high_limit = min(task_size, VA_EXCLUDE_START); + if (flags & MAP_BELOW_HINT) + info.high_limit = MIN(info.high_limit, addr + len); info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0; info.align_offset = pgoff << PAGE_SHIFT; addr = vm_unmapped_area(&info); @@ -137,6 +139,8 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi VM_BUG_ON(addr != -ENOMEM); info.low_limit = VA_EXCLUDE_END; info.high_limit = task_size; + if (flags & MAP_BELOW_HINT) + info.high_limit = MIN(info.high_limit, addr + len); addr = vm_unmapped_area(&info); } @@ -192,6 +196,8 @@ 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) + info.high_limit = MIN(info.high_limit, addr + len); info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0; info.align_offset = pgoff << PAGE_SHIFT; addr = vm_unmapped_area(&info); @@ -207,6 +213,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 = STACK_TOP32; + if (flags & MAP_BELOW_HINT) + info.high_limit = MIN(info.high_limit, addr + len); addr = vm_unmapped_area(&info); } From patchwork Wed Aug 28 05:49:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 1977652 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=haCBsk9h; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev+bounces-657-incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wtwk915S0z1yfn for ; Wed, 28 Aug 2024 17:18:25 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Wtwk8731Gz3013; Wed, 28 Aug 2024 17:18:24 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::632" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724824223; cv=none; b=SrRLvz5oG8/DQToeFvMzHr/20zjiXCVvb60/IgVry8rYdqEsxSgHFtwT71U/Zkry1bjbQXFQ2/vwTC2++bX3P344ZRFbRtQtFNKZHt2aaVRy+C2rrvxlMwqMvOjk84JLngFrVFn7/8a8kbxOtdjQQx7HUw+naLg3EEHltgChheZ2m8FdO4wMHYg0UdIPBIQdEymtQSTCagObcB9WiZazqPJR/8LJxDKmiTeLLPm7oAjY+Ba0VlsiJYDxqTmydcoyKn5C2VxrRLAMVjQH6+hw9WQsP43PYp7LBI6KGwbH+JzV7OSrUvp+eoOlVXxa79oU/wN518gXlZ8aJTJDD/QQdA== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1724824223; c=relaxed/relaxed; bh=n1bnpMYTna27bSqlaeNn9zMkLMdTuL1lgzvNhNTdiTs=; h=Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Google-Smtp-Source: X-Received:Received:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; b=T7acqMiB+krMBA4wv+zwEWY/yc6T0v3ytp1YrPmHGwJck6T6QwJByMTDOlZKwSvIElw7D4HUtO2nRAr/L70hr4Y3SFUrz0tFsiPPkYtqBule7ZEMPoOB69CaKARpHiC0Q/ozfo/7IM/5OkYXJg+dAEJgW8Xt4DrqjY+icZuukia0CS5IAz/J1vn+W3cI0m92pEnxst8hBvrjtOEXi3RkI1e3+3d9uUWLztQXUN1oos0hz8gWP0orZr2nQC9/UljV5eGlvprG4Gn4QiB7XLo55JFRkemXmcCtEHt8VHfulAJye89J4X1MiLnSXo7NS9bunCymoROKwY63I2It7/Wiqw== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=haCBsk9h; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::632; helo=mail-pl1-x632.google.com; envelope-from=charlie@rivosinc.com; receiver=lists.ozlabs.org) smtp.mailfrom=rivosinc.com Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=haCBsk9h; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=rivosinc.com (client-ip=2607:f8b0:4864:20::632; helo=mail-pl1-x632.google.com; envelope-from=charlie@rivosinc.com; receiver=lists.ozlabs.org) Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4WttmZ500Hz2y8l for ; Wed, 28 Aug 2024 15:50:22 +1000 (AEST) Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-202089e57d8so1743835ad.0 for ; Tue, 27 Aug 2024 22:50:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724824221; x=1725429021; darn=lists.ozlabs.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=n1bnpMYTna27bSqlaeNn9zMkLMdTuL1lgzvNhNTdiTs=; b=haCBsk9hwYQjCW4y6bIYIX+M8L2MufRwKCw3YourmK+ENYcGFZxZWFNJMV4cBmM4Dz 5kHq1P4bIQQtqLAKZLBPdq1tGcej/tJXrCDTGSuFAoW0UpTIKQ3qvi0Yw8IElAddzd4d 4D+4FrdE98w0j/MC2r+4AZf2M8gYgyiqEu4flBIAvN6gLNX6GK8COYNHys7FDSRph8rd PKx0U0hqs+V1lu7U9/3t1i7fOszH5Mxi7+Wp/9MbajJ0uVPTB+mR4/mpnaJAmUOHsmdV vidC1hmwsgLk2fkbxhRy/5ukLOIFRvrq5jnnay5aRJixWD+KIdpat7miKEj4W+6VvWP0 XPfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724824221; x=1725429021; 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=n1bnpMYTna27bSqlaeNn9zMkLMdTuL1lgzvNhNTdiTs=; b=WgS7fkIFviHn1QtpkWT57aS4IaCoqe34rJYiWxJB/bpBv20GdAgX6L0AtX5zCZaFrR FokgGU6dVoOCRvH83pqEcQQHx3Kf6A0GjYH7smgntMOcPKGKte35otqSCkLLu0/ZfDwf ZUmV5/S2W6/hf0mB/gS/L7OOeizKj+D/MMguNJbRCUsyq6C1NIbx9SFcyuUcdxIGjuoX tv5fu3WypTdSfYUeRO1o/tChtl5FADn4Idoo3KOklp8LGJas+FEPc9Ws3fKj8btzbgkN Km6+Qs8uq9spD6tSCEbAZJQJeP+F1i1/We/C8Jj1CMhZpQa3hgZVd1SZG18Zu9c8aPTX Zv2A== X-Forwarded-Encrypted: i=1; AJvYcCXduU7qMgYG9Z290c5yXZRFa8mqtxVhy4Ou6xQntFFRDymVR4KI+AeEHbMWT8dwKYTnqb3e3WJeLVyGDM0=@lists.ozlabs.org X-Gm-Message-State: AOJu0YysUMN5+rN2FVqj4gB2CrUoDduhgOuWrhuDREWtjIFS/NXysQP0 fCXu4a6fOf2XIEG/tlZdAeHfm4lcOq4NuktkukqfbXYZSiwwgS/dG9zg/kI82FU= X-Google-Smtp-Source: AGHT+IGQeeMMIWRhlzvEY447u73v0bcDYqggMB4NKbY4CT7iyrW8LbpZG4Gsc+7GkkDRX2iCA5iJHw== X-Received: by 2002:a17:903:35d0:b0:1fc:41c0:7a82 with SMTP id d9443c01a7336-204f9912733mr19656305ad.0.1724824220864; Tue, 27 Aug 2024 22:50:20 -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.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 22:50:20 -0700 (PDT) From: Charlie Jenkins Date: Tue, 27 Aug 2024 22:49:22 -0700 Subject: [PATCH 16/16] selftests/mm: Create MAP_BELOW_HINT test X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Post: List-Subscribe: , , List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240827-patches-below_hint_mmap-v1-16-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=1906; i=charlie@rivosinc.com; h=from:subject:message-id; bh=bFLw7L4BlwG3KLICmNgvPIAvf1/5Sm3GeWEQAkx1eJA=; b=owGbwMvMwCHWx5hUnlvL8Y3xtFoSQ9q5XYnPPfbbPo8yeWL66+yxo/N6BS8nd1/7qNQhsOWpf 3tQ+KzTHaUsDGIcDLJiiiw81xqYW+/olx0VLZsAM4eVCWQIAxenAEzkdAYjwwau79apS3QeSJmm 67cdPe+1+9TsAsXmhc0Xrt4+G6VRe5aR4ekEGZPT2yyYhB/f/i4QYfZn696jodpGS1YWP+X48/d dEQMA X-Developer-Key: i=charlie@rivosinc.com; a=openpgp; fpr=7D834FF11B1D8387E61C776FFB10D1F27D6B1354 Add a selftest for MAP_BELOW_HINT that maps until it runs out of space below the hint address. Signed-off-by: Charlie Jenkins --- tools/testing/selftests/mm/Makefile | 1 + tools/testing/selftests/mm/map_below_hint.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/tools/testing/selftests/mm/Makefile b/tools/testing/selftests/mm/Makefile index cfad627e8d94..4e2de85267b5 100644 --- a/tools/testing/selftests/mm/Makefile +++ b/tools/testing/selftests/mm/Makefile @@ -50,6 +50,7 @@ TEST_GEN_FILES += hugepage-shm TEST_GEN_FILES += hugepage-vmemmap TEST_GEN_FILES += khugepaged TEST_GEN_FILES += madv_populate +TEST_GEN_FILES += map_below_hint TEST_GEN_FILES += map_fixed_noreplace TEST_GEN_FILES += map_hugetlb TEST_GEN_FILES += map_populate diff --git a/tools/testing/selftests/mm/map_below_hint.c b/tools/testing/selftests/mm/map_below_hint.c new file mode 100644 index 000000000000..305274c5af49 --- /dev/null +++ b/tools/testing/selftests/mm/map_below_hint.c @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Test the MAP_BELOW_HINT mmap flag. + */ +#include +#include "../kselftest.h" + +#define ADDR 0x1000000UL +#define LENGTH (ADDR / 100) + +#define MAP_BELOW_HINT 0x8000000 /* Not defined in all libc */ + +/* + * Map memory with MAP_BELOW_HINT until no memory left. Ensure that all returned + * addresses are below the hint. + */ +int main(int argc, char **argv) +{ + void *addr; + + do { + addr = mmap((void *)ADDR, LENGTH, MAP_ANONYMOUS, MAP_BELOW_HINT, -1, 0); + } while (addr == MAP_FAILED && (unsigned long)addr <= ADDR); + + if (addr != MAP_FAILED && (unsigned long)addr > ADDR) + ksft_exit_fail_msg("mmap returned address above hint with MAP_BELOW_HINT\n"); + + ksft_test_result_pass("MAP_BELOW_HINT works\n"); +}