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: 1978310 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; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=DyjOoPzE; dkim=fail reason="signature verification failed" (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=vjJj8oXK; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (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 4WvZHW0YnTz1yfy for ; Thu, 29 Aug 2024 18:31:01 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=gdHA7LNMUeHOyAjid2hcjxRKxNn02xOdh1EoxwxZseo=; b=DyjOoPzERw4ehP zLlmcp5l9pOnrdQzUNOV2d+V7Df2Gk7WwYdxiObkY2m+ENBEwUmKBqqaNAKG3jg5WLmqNi3TWINst wNqsZK3tYozpAw6QeSfJs6Donxb5cHnrFzwNCp3VMl2i9l55Q37qXgIBKML33TmmnR+6Hh05H4BeG WLWSj4PuwisVoDDX7Anw/Rckc6/dEcBo7cOI7VOm/CDu22uQghS7OKkt6HVHchRQx6O+fMDCJuoIt cl7kXHVtr3pIwESw2hsBLMR4NPjnbe+OHfCemP5gPgpliWt8lHqhZpsIudsFmYuelDNWsSpII9dPD 65CIsj5Zn1KdjvLarsjw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sjaYW-000000019R2-0fTi; Thu, 29 Aug 2024 08:31:00 +0000 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sjZOK-00000000uHd-2UMZ for linux-snps-arc@lists.infradead.org; Thu, 29 Aug 2024 07:16:26 +0000 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-714287e4083so326939b3a.2 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=lists.infradead.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=vjJj8oXKiJrYJ/LMpaGeclaOdOzGQSt8LZyXXDbbZxCL6M54Q27sGpPafCCgxdV6Xp 2pgi4ZC2Kcv+AUwDTGahv3xXHKwGIC5141/M156kaDrZCnsikKylIfL+6UeNOFjHL2r5 GdjgviQiaHdZ0E8DFaMHg5mShO02lXXJnjv6slFaGw+D2tPnd+iG2hRln/bx8W1kxTt3 fx1NHeodilfpR5C2bKHuLjmnvV77ph5wEes6fOVwAj2bGoctVi97X7Oh6zXcmO0tx6lP X8Ugo9GgKAKXkUoCVmORFirWeQ8WkZGknVxHh5kCZ97j1Mmpxl//wPBphinZiIRIVKX3 ZORg== 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=iypHHCNjfnUL+7x647kBGnrwwz0yfg8x7YS0QQqwA0/uxthGJ5f6DwU9Wke2ixRq3G MQOPFqa3IMV1dGu48nmWSLGOE3KyybdTtcTIziHvN45ffk4qjPWIzXpoac0smXLQPfzm yKinK0icqEPTEOAv0jdpak+1gpT6YEMsE+nJlLnHndQjMy3jbKSz2uhK3bkT0KB+n3VS tbI3o5Ai1nbw0iJapTsbpNHgMcIpMbnmT1usA3P113iKpcjwX7ea3MQdo87Ofx/4YyYH Uz2Vg3zQptaHv0Q8e5VV9w/H1AsMrxoVvUXD7HDh+BAJAwK4vALvCOfNdkDBHVnQMqw+ 6blw== X-Forwarded-Encrypted: i=1; AJvYcCU7PROujbWbF7UJmBRQjx6azGLJJS/XBtGWki5jQa6NSNmCL3Ou4a3hdcKl96IOI3kd5U2qFO4WeQ9M5AsHHw==@lists.infradead.org X-Gm-Message-State: AOJu0YyMGjjSxZ9x8qubzLu288Qll+reap/iM80k1ifI0Xqla2w8G4Hu vWSFzBBaLZpIwc505Vyh3Ue3yVS1I1SLSLNEKQiHrgdMny7XwgM4tP3782sJYl0= 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() 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240829_001624_687296_207FD45D X-CRM114-Status: GOOD ( 12.96 ) X-Spam-Score: -1.9 (-) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: 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_ [...] Content analysis details: (-1.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:435 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 T_SCC_BODY_TEXT_LINE No description available. X-BeenThere: linux-snps-arc@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux on Synopsys ARC Processors List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-snps-arc" Errors-To: linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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