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: 13780665 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) (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 7920515B99D for ; Wed, 28 Aug 2024 05:50:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724824213; cv=none; b=L6Yc84NXOZm54qPsoKkE+uIumw2d55fdle/3LOX2aFQCtztnNRFCREF1ufFa9Pbsd99q2dUpd1bygdVhbxPrhsxJlu+cZl5nL+4Uea6Rk3twOdqec4QRU4KLIrZEz0UTosIn+EQ92wrdc/2qeIq/a0AkRskNzBETv3ZFJxCOmZ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724824213; c=relaxed/simple; bh=LDlOb3puh00G9LsastMFHCdP3tuzGW5CWMac22J4/f0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Uy2BDmbzcdDt9HS9JeJuxr7J9knPe0q83CUZR7Rzgcbqzw2renT3l5mb/OvrPrprLWRCiRKcQQgL68ehn3c9UgeWAOtBJKoUqkcECEyaCRgZIKL92Pmpj7pKIqo7c327G8XJTYTr3PS9b3DQVwDeBk7lU+B9E2tt2VAVYJt02+8= 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=WOUEfXng; arc=none smtp.client-ip=209.85.215.180 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="WOUEfXng" Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-76cb5b6b3e4so3982697a12.1 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=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=AarzQWw7jN5pNetRW1c1iMmZVGfhSNhFxAvdf8X4j7o=; b=WOUEfXngpjQ87wuOKKNoWVcSr0ck/IjM1p/QVhgggmTQtsSfLD35lLHQTr7aopno83 tA430b/vzZMEmQEkDQECZ7audo+xxtt1G/yRKW5h+7VxAyICk8YlWqsjPmS1lJKL7NHy /uarLE1WvsohbnJe+k9OIpWTZOlpNKnnNIR2Qj3Te8mlYRCyVE4ftY0KbJWLtoq1XSEA UyyH45C5FAuB37iz/HbrArCjs/Y3OnAtF0GaCTNJOu5aXqJz41SqzaWdwjCY9c+JRMiG tuL3/8ER4PHR0YOj4AVA0mFcOauL3v1lz7da+c/FF8PvW2bVmvXu/hCjcQSp1tl/OJ0b MEbA== 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=owzKKyJJiVbc64r1V1s9vWFeyjkWNNkvJhqN/ZrxE3t+IONTAt6laN/lwFLlKxwoEb Ms5JF9jnHgNm66Uz0oNCBX3HM8u5Dy2r9/CYQDyiPy6dFgiaLVcO3My6rajF8WLZqGpk Vrm84GRJ06yubOZYsViKpzJwWTAZQUqYirGgGEnOcnjXSnsoNigGFidudMBRZ65ahWRB YdLpfHBt0QybwaoeQP5IOkJxh4QDARthAVny7Ykm+nU45q0vx46FBD2fRV+fXIPppDXr eXsOoYjPegqunKHIQsfLEQ5Im3FG9AobNJubbONDJvfsCI/fuL5WDgFqZPkc7Obtl8fl Bb+A== X-Forwarded-Encrypted: i=1; AJvYcCUEUoLkvbe2yITHpXYAAT/LxkCtMYrJ7kV30+AXsuB3D1BEMtsaMwP5+bwUhjhI71szQ7dd/l8E3A==@vger.kernel.org X-Gm-Message-State: AOJu0Yx/KTLEho/PR+iPQxuY9G5Bx28WLNnAc+wBLbVOq6K+T15tsHvj uJPk6NH/mibLpQ8pN7VYGKYpRH/JbbLnlkoYxof+vkQm4cN2xJCczzD40eAUSWA= 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 Precedence: bulk X-Mailing-List: linux-sh@vger.kernel.org List-Id: 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;