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: 13780608 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0C979158D81 for ; Wed, 28 Aug 2024 05:49:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724824192; cv=none; b=Rgf/Ze3v5iiB8b8tmpAUjaVIaInAM2l4D6oVbbypCuYaM+dKj/zZMeGzFU5T/H/Op4mxRf6Cpv7uKDreLe+94FZQg+Q9hD71GFVrtx/+IzvmEmHRu95aIPa6OU1FymWZS6axu4NvbA5gt7M30uh8u1QED8Z7E2zc52qsIC8ZEeQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724824192; c=relaxed/simple; bh=efrv8gA6WD0kUzxMoz7FX/k/QnHAbRwwUgR0y2hEUd8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=oBjgCxerI79rWnQno2JMWnUeqPbb3AcKG1xZuk9jK9B8Uk7Eehhp1PulvH3rT2LkTnIvShPS6ftxsdm/hQV+YHKjNGNdC6m6GC5B15GfdswlmZUaN7zUS4N13Bez/6DqB6S8LGcwDMhKCF9niMpj5C3doEBd9gGUdQvaneFHCLU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=xHkxY+Tq; arc=none smtp.client-ip=209.85.214.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="xHkxY+Tq" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-2023dd9b86aso50366415ad.1 for ; Tue, 27 Aug 2024 22:49:50 -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=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=01svQ9ue7Mr4CWZ3Wn0HVoOhr4xAPnLaZCO9CnTXUgc=; b=xHkxY+Tqnax3ywVHWyBD2R9IZoxXX5+jyVDhT2/MUchy1ONegKg5Ar80c8eSI2FTDf 80ls4IqX4MGlY2JzotSBJ+SF+TM7FY2AxxhZ3Fp/6DNPeFT3w49bVLFcSNnmNxSiZE8H aEPiTcZcL0d5zdp/O0XDYpti9mVBtQ3TCgU3EbPU913l1kqN0YZYsCAS+MPOQLejk3p8 hN+W9PO+c57qRYomlNUudAb3zf+54Rka8BMVWKwOjHiUBnbRAjSUBW/89EOE5/VEnWI4 QGJE0gqm+mD1f36EgQpgszxOPaK2RwsXjKUCZHDdm/9DUPTISZrdWs2vdYnctq0C61Jc UaqA== 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=oWAjPcAatedpw6Zb8MkRPvuSnLlz4ZZYSqScjFSqWvt+KKJcwiZmepJnSEIW2I/VDP tAPp5VvVejtXBvuWmVeH7K6Mddi2fIKlI3WIYa3fkxsuU2Vc1g4cpsBTN5TMw/je8yx3 LrX5l+t8UEbqnNLPJfro/MFg5Jh952UF7sRZa8B/4Pk+hCmZoNBGkVJKdnyyNOqUSZ0x ZlbrRYcW9naT+AEWHPwgMsSrkrN8iIxgFBrRrYfoWFgHgH3EsfFY4k4QmdjhxdLf3Pgx e3jXxc/3hz4gQ6wS5N7oueli2zD46Njq+hv6DNNzKPcBqzH4TtiwKE4p0M7PXPqArGXO Ugvg== X-Forwarded-Encrypted: i=1; AJvYcCUw6olMAW8XrecIlulE13OjerpwKX71yYXrHYA6osYrhjjxjjI3+MwITbEF6YFY6e+GsTaHtDyl0qTC@vger.kernel.org X-Gm-Message-State: AOJu0Yw4qnEdjG+ipzhqRdM4g7IavOWLXlbYH1TQf6swko0M7KIb2zHq MdW9YAaCb6Lo9Oz6Vs2NHQ7G4bHR1s3KICcAMBLml/YSC3rfX1d59CKtKQMC8qU= 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 Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: 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 */