From patchwork Wed Aug 28 05:49:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13780630 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A5E9C5472D for ; Wed, 28 Aug 2024 05:50:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1B3C56B00A4; Wed, 28 Aug 2024 01:50:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 159646B00A6; Wed, 28 Aug 2024 01:50:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EC4C66B00A7; Wed, 28 Aug 2024 01:50:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id C9B896B00A4 for ; Wed, 28 Aug 2024 01:50:10 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 8894E1C4F2E for ; Wed, 28 Aug 2024 05:50:10 +0000 (UTC) X-FDA: 82500578580.19.F06A8CB Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by imf17.hostedemail.com (Postfix) with ESMTP id 943E240003 for ; Wed, 28 Aug 2024 05:50:08 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="w9K6g5/g"; spf=pass (imf17.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.214.182 as permitted sender) smtp.mailfrom=charlie@rivosinc.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724824165; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=mnBGdEXd1SbkXIrtxJgk/JDNcWExLMEwccaijei9Lbw=; b=ndRT8mMbEhFiZrgyGUfh7nVSs7bMr2/PSaqZwcfj5wmcvXjbzOfK1OUIj274JbHhlBHyws N2D8/8bTDadgU0xpg+9A9m2Q+rpXYicMd+5LOLsjhVLD2VcOi3PbLnQ6JlYNBF0WNJQZfs RBhZ9vsRodCbeCHPyrxGaeCcH+llPBk= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="w9K6g5/g"; spf=pass (imf17.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.214.182 as permitted sender) smtp.mailfrom=charlie@rivosinc.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724824165; a=rsa-sha256; cv=none; b=AhXtwUUI/18BbKRLRU6zsaGo69np6TELjDPB0hMQCw3qAj0jqABh2BZlabz3C2gl+1ArTe sJKop+n0dgJ9/HlHNnelFtEoSzlJph849ulZTWexzDrQ9SFDiDJQjUVXD3Bt816EulO23v qK/SFPE0cDcZVGD3dMjwzhnP3olO4AA= Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-202318c4f45so65337645ad.0 for ; Tue, 27 Aug 2024 22:50:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724824207; x=1725429007; darn=kvack.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=mnBGdEXd1SbkXIrtxJgk/JDNcWExLMEwccaijei9Lbw=; b=w9K6g5/g7T0zcYjoQ1hHB0DJx1B6X3PSKlEJi+i7P7txn2cfT7Bb2+3Un9G6mHYbYK tDAJBBC04iLwLpprZaj9BE60Y+bYM5z/4DX4ZZotV0wrvqy+y3cB9MXIQnW37VsRua6K dvvusntN+K7xlb3esv5Bbk2O5VAtOmFtxbsjCB0aYSWaitkp24Wxbp37IJorBbw6PDAm 14/8FTtYgUnqW3IKl5ySDwr+fEM6u7Na/XsNS7mpIWeI4dbb9zusBCXpVS8MAZyAUs+R myGsb/4+HaTn551073zwaAaAQYqY3XZsTaVZBoThRePmK+n4sNIKo/zYz93E56/kYrcg ox3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724824207; x=1725429007; 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=mnBGdEXd1SbkXIrtxJgk/JDNcWExLMEwccaijei9Lbw=; b=KUrFQXGGIQRjA9mlrnr0T7sFOEH/ER11UpRGRbSsF+edP5nmRph4qb5rjlu+ZwJJy+ MWfGXdYhSlIkrdz8KtQbSq7rhcvRmrRG3UVHjNWABt/3QrTfMOxuNxlaV7E/rb61HzZV W7FyzG9hGyMfsKW15Z3wQMV3Yewa2ggeOa2PWSbDRQcKEK7tjHCZnFXM+OV/GBiuznlP pQ6fcpiJtmISpGs7bHyewd7Bs03f6jVfezMpeVEg/c5Fk4qx9xIc28WKy0DtLxhfYkXU 9qyV9uRfrviAVjwABAZiLKOuhcOAOYzyboqAgix+28XJOdwYEsMEOi/1CrXUKuksdabC hqmQ== X-Forwarded-Encrypted: i=1; AJvYcCU5bNLPlIdLefVu1KmWLInHK8Z0kl9/wX5sZNsGxnKHLlBj2WahrOBlVjMm0fnM5kjp5Hu7/6Rhew==@kvack.org X-Gm-Message-State: AOJu0YxF0k4r6g8j/5EyrDZDeGu9yS7ieJ9VnZ69bMW9tiweJmpmQrE+ LQpctj3aPzHR9OfFvsWhOFBQV8RUTl+Cw19dV+MS5Hj6TUgsUvVxpZ/ySvatD6A= X-Google-Smtp-Source: AGHT+IEsQQCnEuxvR964+0rX/KlAEG5qqvky10H/EfSUq5MJAsWWGO7Ld//wKHkIp7XPnG+kf0G25w== X-Received: by 2002:a17:902:cf07:b0:202:60e:7700 with SMTP id d9443c01a7336-204f9a548eemr12735035ad.7.1724824207147; Tue, 27 Aug 2024 22:50:07 -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.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 22:50:06 -0700 (PDT) From: Charlie Jenkins Date: Tue, 27 Aug 2024 22:49:18 -0700 Subject: [PATCH 12/16] parisc: mm: Support MAP_BELOW_HINT MIME-Version: 1.0 Message-Id: <20240827-patches-below_hint_mmap-v1-12-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=2500; i=charlie@rivosinc.com; h=from:subject:message-id; bh=RM+/CbqQAwiDfaQaSk6aR6JgRkcXqI3LycpAEGdsrx8=; b=owGbwMvMwCHWx5hUnlvL8Y3xtFoSQ9q5XQl7j2395l162Zz3ULDsob8MjXdzJ1/bXx7d7Lq5e d+zLQfcO0pZGMQ4GGTFFFl4rjUwt97RLzsqWjYBZg4rE8gQBi5OAZjIAVaGfwp5ZTFJes0Kym85 OvJO+pR7Lg+83rfo09z/TvfTNed8SmX4751+T74tYdaFrpd5nh9q5rfzOL+4IN+53YNdoEni27c l3AA= X-Developer-Key: i=charlie@rivosinc.com; a=openpgp; fpr=7D834FF11B1D8387E61C776FFB10D1F27D6B1354 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 943E240003 X-Stat-Signature: k4mx8kkxbzns56bwxz5fo85qbbh3o55q X-HE-Tag: 1724824208-39101 X-HE-Meta: U2FsdGVkX19EV/SQT9eA2n6Fyf1hdDA5IcJEGKPLLyF847iHWf9+bJDkX+rN8xQMPk1G4bKg6k4t/NnPu6Yxmpo8Htlq0fJeV46jRwyiao5+Q/zQ3DC05whDvyTx+96atv+nIlKQEi+aqGpI4FTOpQAmafK0uinnRX+pZkIIeIbBiJpmp5qpNY1Y6Ip4m0nii837CCWILhKVY7ehsM3aGFrr+E1WSphXxXf+cLDHhcfevg748gHT0tH3TWHIkkENZkfeUaKJblLXGqWuJlKABPBaIEr5fXeuYL0LH7urG3hhTqbE9RYPpUqgBW6tifOGdgO3la3gDzq8mmveCecZjyUa1T7zlKaXz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ogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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/parisc/include/uapi/asm/mman.h | 1 + arch/parisc/kernel/sys_parisc.c | 9 +++++++++ tools/arch/parisc/include/uapi/asm/mman.h | 1 + 3 files changed, 11 insertions(+) diff --git a/arch/parisc/include/uapi/asm/mman.h b/arch/parisc/include/uapi/asm/mman.h index 68c44f99bc93..44925ef8ac44 100644 --- a/arch/parisc/include/uapi/asm/mman.h +++ b/arch/parisc/include/uapi/asm/mman.h @@ -26,6 +26,7 @@ #define MAP_HUGETLB 0x80000 /* create a huge page mapping */ #define MAP_FIXED_NOREPLACE 0x100000 /* MAP_FIXED which doesn't unmap underlying mapping */ #define MAP_UNINITIALIZED 0 /* uninitialized anonymous mmap */ +#define MAP_BELOW_HINT 0x200000 /* give out address that is below (inclusive) hint address */ #define MS_SYNC 1 /* synchronous memory sync */ #define MS_ASYNC 2 /* sync memory asynchronously */ diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c index f7722451276e..feccb60cf746 100644 --- a/arch/parisc/kernel/sys_parisc.c +++ b/arch/parisc/kernel/sys_parisc.c @@ -148,6 +148,13 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp, info.flags = VM_UNMAPPED_AREA_TOPDOWN; 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)); addr = vm_unmapped_area(&info); if (!(addr & ~PAGE_MASK)) return addr; @@ -163,6 +170,8 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp, info.low_limit = mm->mmap_base; info.high_limit = mmap_upper_limit(NULL); + if (flags & MAP_BELOW_HINT) + info.high_limit = MIN(info.high_limit, addr + len); return vm_unmapped_area(&info); } diff --git a/tools/arch/parisc/include/uapi/asm/mman.h b/tools/arch/parisc/include/uapi/asm/mman.h index 4cc88a642e10..297acc0f7b2a 100644 --- a/tools/arch/parisc/include/uapi/asm/mman.h +++ b/tools/arch/parisc/include/uapi/asm/mman.h @@ -40,4 +40,5 @@ /* MAP_32BIT is undefined on parisc, fix it for perf */ #define MAP_32BIT 0 #define MAP_UNINITIALIZED 0 +#define MAP_BELOW_MAP 0x200000 #endif