From patchwork Thu Aug 29 07:16:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13782683 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (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 4C61A189912 for ; Thu, 29 Aug 2024 07:16:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724915786; cv=none; b=LX8NbxKQVrxlUFbBBwWYZfdE7BUBK7YuCKQ0ufMl3bE42ZCW7T0FNMkVayftwR0GYcWEdSdf8UBmEo06qz/GoVpukRffd1pht1xu1HuKC3nISGpMvIyqbWOBK2B0nabz3Teid0jFDrsz7XJPOoi9pzCJhCF5OTfqbuydEWiCepk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724915786; c=relaxed/simple; bh=awlA0FQ8vwXq3Nn6i3BedGsUxTSd4n1W8+rk6Ti/shY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=t/S1qh86OevMVzteq77kWHbK7+b+oCpFJzfLcjJv/VYqFx+WKJFkqy45/q4Ls3hZ9tYVyq5Plz3Ff75Zy2Sy+f4VzPwqlR9QayLuIxJpbTOangL5CnWySzUVPVGpQKVT+V70oM7wPvrzNbufOghXTM1K6rIPCocDf+cTbJ2yYM0= 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=TjlS0Dp3; arc=none smtp.client-ip=209.85.210.175 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="TjlS0Dp3" Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-71423704ef3so259603b3a.3 for ; Thu, 29 Aug 2024 00:16:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724915783; x=1725520583; 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=eRZz0v4roamBPZuEY8lRo6reatKDFS+11+O4EIK+5eU=; b=TjlS0Dp3sIxhtH7AFdqO92T0ekVteFvdM+sCF5XyVv3XoycyrhONnJ5b6l4bIU+OXU +sM9soxzMteqCXnirEEXJSH9rVi3ilb/X8s8bRYA+g3lYee7AhNvl7VtDS6pnFaMhxTv 0HSYtb06lIjFA3ce2rAstRVnUeVgtcdW+ZLvQoT8WeAljgbzOTABTuwyPcKoCY8Tvrp+ ZKgYGOxjv5kvmn3JSuEi2pmb5ig94MwY0FU++0EWq+ww/K0g6vcSjogl5p2zAQLbxPYz k1m/GWaNu+Y8K7iyqjo91CJA67a0L83bX3b5HOFeosk1frp1SEtBuzxs/5nrEhHdyynv SYrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724915783; x=1725520583; 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=eRZz0v4roamBPZuEY8lRo6reatKDFS+11+O4EIK+5eU=; b=vwNW9QFGDsk/savb4IK1M+JktaJ7IPolKtJ1Vfg4743kIWSvMwG0aOuBFfmgrbxYb+ Jly+zguSMM27ZaVXwrBJZuNlh60d5a04yAGJjnCdbxBYHNrDqlvtDo2JQbN8H9jn4h+y mCcoELwbcc9IFw/IuuDPFGgYqknB9yh4q9KEk407EUPUBfStPJxIoYextRQp8vXIGkUN ghKZIYnHy+XdaZjthksvLipoxyww0qA1ksd++2wz9WLQUu34RyDqP6C18ZjNQKA8IGMv /Njfm8GRdYzMKDADG8pWnMs6nPYWOdPdMeyNAfcib0fWkATGx/Y7kuxEkACpfnC9ooC+ 3kXQ== X-Forwarded-Encrypted: i=1; AJvYcCW4aA/LuKhSQDaQOQAkbA3iLloWNpqhE/uYHWWqtiAcAm2pNE004Ei5wuzhDRQ0dN2ojELJ5nvWPjjIk34=@vger.kernel.org X-Gm-Message-State: AOJu0YxYzcrIwf8qrCc4/6eQcX9XI2qLpRqY5xDGGBcXoIlf6m6oxWy7 gQa7viONBJP0b88poRtaW3D2FzUXGd3WK16/OJ8HESyH9fun+4YbOlFz0WTLQc0= X-Google-Smtp-Source: AGHT+IESlo3+HNMz8Vyf9gnK2kr34iORO0t8ZckMgQQJOrmm4rJ0EngcQswLax6rU2xQbGZPh7/0eg== X-Received: by 2002:a05:6a20:6f88:b0:1c4:7dbc:d21a with SMTP id adf61e73a8af0-1cce104dce4mr1887803637.32.1724915783368; Thu, 29 Aug 2024 00:16:23 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7d22e9bef08sm581976a12.58.2024.08.29.00.16.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2024 00:16:22 -0700 (PDT) From: Charlie Jenkins Date: Thu, 29 Aug 2024 00:16:00 -0700 Subject: [PATCH RFC v2 3/4] mm: Support MAP_BELOW_HINT in vm_unmapped_area() Precedence: bulk X-Mailing-List: linux-parisc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240829-patches-below_hint_mmap-v2-3-638a28d9eae0@rivosinc.com> References: <20240829-patches-below_hint_mmap-v2-0-638a28d9eae0@rivosinc.com> In-Reply-To: <20240829-patches-below_hint_mmap-v2-0-638a28d9eae0@rivosinc.com> To: Arnd Bergmann , Richard Henderson , Ivan Kokshaysky , Matt Turner , Vineet Gupta , Russell King , Guo Ren , Huacai Chen , WANG Xuerui , Thomas Bogendoerfer , "James E.J. Bottomley" , Helge Deller , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , 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 , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Andy Lutomirski , Peter Zijlstra , Muchun Song , Andrew Morton , "Liam R. Howlett" , Vlastimil Babka , Lorenzo Stoakes , Shuah Khan Cc: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-alpha@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, Charlie Jenkins X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=991; i=charlie@rivosinc.com; h=from:subject:message-id; bh=awlA0FQ8vwXq3Nn6i3BedGsUxTSd4n1W8+rk6Ti/shY=; b=owGbwMvMwCHWx5hUnlvL8Y3xtFoSQ9oFBUtNRaX7W4IPbnI+Ms3hivNnCcHEiLSn/wN2Mfr8Y bUwSP3TUcrCIMbBICumyMJzrYG59Y5+2VHRsgkwc1iZQIYwcHEKwES8tjMyvNn0V3yhfGTAnNVL rI6JakxSy1zhtaNTK7Nm7eOzb9jnWDIy3NjktX5Wn9/XRXLVu44d2/Xri3n+zz1GZcf0P1w88Pv nEX4A X-Developer-Key: i=charlie@rivosinc.com; a=openpgp; fpr=7D834FF11B1D8387E61C776FFB10D1F27D6B1354 To ensure that all memory allocations comply with the new MAP_BELOW_HINT flag, set the high_limit in vm_unmapped_area() to the hint address + length at most. All callers to this function set the high_limit to something reasonable, usually with space for a random offset and a gap for the stack. To respect the provided high_limit, take the minimum of hint+length and the given high_limit. Signed-off-by: Charlie Jenkins --- mm/mmap.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/mmap.c b/mm/mmap.c index 34ba0db23678..459ad380c673 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1766,6 +1766,9 @@ unsigned long vm_unmapped_area(struct vm_unmapped_area_info *info) { unsigned long addr; + if (info->hint != 0 && info->mmap_flags & MAP_BELOW_HINT) + info->high_limit = MIN(info->high_limit, info->hint + info->length); + if (info->flags & VM_UNMAPPED_AREA_TOPDOWN) addr = unmapped_area_topdown(info); else