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: 13780876 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1C695C5474A for ; Wed, 28 Aug 2024 08:00:44 +0000 (UTC) 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=2ZNyOGhNzxXpDsMDkKW+j5yTNoo9hPR66Ut+YbmUqXs=; b=M3mro6+EpqbuxL RdlHTeXUQSMjaOchmk5mTTZYG271eHCD5ftbPlcoA7UpaUBrDWGE5iVXizcLJ6Izu/8uLwGsxPREm tZ+38A2+cDUrcLEI8cmIlrQXE1JnK0tOCVvbUNHPzsMQFGTydeAaKdN9v9Z5xiYkt6n+ai1sohNnf nTO559XtDRB3mtOMGBzamFl3Hpf1IbxBaqMaI0JhLZd3DeLUL5zr04RztJ5YgXXphTNZ62VuDSF9n pX4U39pa3nK46zF+buA/4A0VSlSxRRtmPEko6/fAXaFMFNFftg/gb7mYI1pYD2vXYQl9+eXc/V1MQ EAiJTbBgwDAmxG1BZNEQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sjDbd-0000000ERKO-1XOo; Wed, 28 Aug 2024 08:00:41 +0000 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sjBZL-0000000DyOb-3UPX for linux-riscv@lists.infradead.org; Wed, 28 Aug 2024 05:50:13 +0000 Received: by mail-pg1-x533.google.com with SMTP id 41be03b00d2f7-7cd895682fcso2352456a12.0 for ; Tue, 27 Aug 2024 22:50:11 -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.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=AarzQWw7jN5pNetRW1c1iMmZVGfhSNhFxAvdf8X4j7o=; b=o6/0KmYCyKKI6wrsq2RkRNSaqOzNEzmLSDUCU0nqXvQA+AHMZvkaHH5y+86I5vxBCQ ekudef2sfmsYE0vSw2jhKfqIA8d275TCSO3SbeDHSCyGWXzidMa2emXTowiIcrMzoCDC 346BnABaz6YDa9/U34ZrjrtKadsxD/evThZN2cHptZWiFyHpNwIRn1qQLS0kA647Ly+H ke0YtM5a2exJx4CNLNbn9zmlBMpVnTSGTsAXZDAhMOj1/TRim9Cgrs4HpsT6OF9fDZR3 lL8W/0xYYVdZXqw8hooHSuar4+SpzseLOCObJFi8GEgXIbv7vzIapAM7FAmETAWCepGK KE5Q== 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=fwYHugZlcZ7epT4rjU8mxmc3PekTGYweeEhrQ6IUTumgHG9UDgVHflWeDnSjuf6aIN dwOHDLK6BPNRLci5e0Zw6rSVMOHQEbtP7QwjFtl+c761a5IUZ3njoQo1GsUklYjDhjJu LeeyIupIU9xL9u9fEO3fXxGyPdZ9oSZUGWhffd7vmeohg1bz10xjxWQYQQHCFDjwxdrr aZxpBJ1G3tlncSWOYRWwIWftJAoEWgl8gvdOv5gYyYZBqmHyKkbgzi0aj64efAQwDHrL fWkKsAzw8HYlPWvVoGAO5QrTrT0PLwzYV+Bk9zkdJ++mUhx3xIKUh+VTmBfobMODgbiK nZqg== X-Forwarded-Encrypted: i=1; AJvYcCWTFrjYHqnAT2qLIqTacuagFfs260Pg/mGb7injsM7uk8J0aR9Ulnuwc/FxIGIqJ/wisP1PB5Y5I4onKg==@lists.infradead.org X-Gm-Message-State: AOJu0Yw1pVZT6C6nsttbESUz+8Sq4U1vQ3RewvZU3SGJEjchorbVF45E TQ5rh3jbrFeLmG5fC3iTe6qHmeuKSXPbvodtz4cbgXBbOn3zYYelL+uK18L7YTA= 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240827_225011_934130_82CA4449 X-CRM114-Status: GOOD ( 11.80 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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;