From patchwork Wed Aug 28 05:49:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13780618 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 A4DADC5474A for ; Wed, 28 Aug 2024 05:49:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F3A196B0082; Wed, 28 Aug 2024 01:49:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EEC4F6B0083; Wed, 28 Aug 2024 01:49:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DB2066B0085; Wed, 28 Aug 2024 01:49:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id BEB1A6B0082 for ; Wed, 28 Aug 2024 01:49:29 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 7246C141CDC for ; Wed, 28 Aug 2024 05:49:29 +0000 (UTC) X-FDA: 82500576858.17.C0DFE7B Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) by imf18.hostedemail.com (Postfix) with ESMTP id 5B7211C0008 for ; Wed, 28 Aug 2024 05:49:27 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=wdk34Bly; spf=pass (imf18.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.210.177 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=1724824124; 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: references:dkim-signature; bh=IUFbDMgjzsoT48Z/N2yqe2kry93QHxmitnGNSfp0h7M=; b=guRk/UIEqI9pdpiq6vRxbqO6XcEnj8IXE2yLszx8Or/0ctJV4Qs8rZTjSO0Q0AyFtp0NWJ J0UMcKilMwDOzx+swgCe1Q2/vAzrS8RaPa43Ix1V08/QGTPzjkdudpdmfx8/Lpl9anh6sn 4rjmFC+At/lr49yhbSpvhd/nwxh/JyQ= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=wdk34Bly; spf=pass (imf18.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.210.177 as permitted sender) smtp.mailfrom=charlie@rivosinc.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724824124; a=rsa-sha256; cv=none; b=JZGzm2zssyeBp/XFrkHGO7+pVElG+U/BKrjEUcXQfqQxE0u9i0LYb3RGRZqjAilQQyBftC 3/UVaBjxTnkggfIEj8z3mMCojcA8rilCu7hC44TymcyX7Ktkp31h1aUcY04viwxblQW1vG u0/tQwk+c6Q57dkDueju/bBmH5CxL1o= Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-714262f1bb4so4649222b3a.3 for ; Tue, 27 Aug 2024 22:49:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724824166; x=1725428966; darn=kvack.org; h=cc:to:content-transfer-encoding:mime-version:message-id:date :subject:from:from:to:cc:subject:date:message-id:reply-to; bh=IUFbDMgjzsoT48Z/N2yqe2kry93QHxmitnGNSfp0h7M=; b=wdk34BlyZo3cXdk5FAqbsYElzM1k++fPM7xNagsBuCOVCylhh5KwR/3VxguhiqSU68 AsFyaMpL8TKIl5FFxTAAhx0+H2VTmVSMZehspfjNwrNSh8j2mgaPGz0PzrgkpblM8JkD F0rbJtRuWpKG5DmuNUXvpAl792KyG9Fe+QdJKbSm8ta19Y60KxnENIB98o1sDdGcD2VW FI9OEuQgz28OkjKfXGkOqRdxM5tx4FByYGDhuKTSBnT7tMwajIezZtPQ9DvxNWiJTV07 vdHaX0gIWDPrg+zbcHieNxK+CVoXVQ/uzjWpHFtHlC3vGow9QDCuNYKpUEwEsyq021DZ eJYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724824166; x=1725428966; h=cc:to:content-transfer-encoding:mime-version:message-id:date :subject:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=IUFbDMgjzsoT48Z/N2yqe2kry93QHxmitnGNSfp0h7M=; b=qP1vzeO/QLIe/1hlKwD6ceVY7x5aV8Zk0lFbVuKH4/Xwk0ACjuUxLOl84e0YiXDLYd ovm9xs111gc8aNkFI8tXWcqnA8aqh8MOwLMZGKr0D6k4lejRrYxeufVh3w2dcFeO7BlL uaM7OkJeGKPPUEKcaLDSn5J01LHqeMDpQqnjU7/kpgZtlNAJHccTjhjfIm8qyO5yLTkS GdfgLlrSIeaeEjggiB1LcRRL7KjQwnwAg/GUYEGOtfO7/gY1Sz1qVuct2bat2SmSpMiM ZQL2aWlkP9cYisoSkOmTf/3naVkoHzqd2KN3ows2yTkdSQSYBFZSiJNiMI+CtW1Wi9dJ d9pA== X-Forwarded-Encrypted: i=1; AJvYcCWc/cJQrjhEsHroL0qbscurIEyg4PFHOwSMJi2dqJcNK2ljWlUVwDQHc4vBX19oXMCAW8t8qizrbg==@kvack.org X-Gm-Message-State: AOJu0YxAUSpo93qkY5HHSvyC7dsB5mLF4009SST04VgpevzJseLQpjWS salCVdClplIO0/rGTIPm0gWQAPYy6tgIjX0BkJDtsKYUhO4coTCdP67MVEV402Q= X-Google-Smtp-Source: AGHT+IF6T5IRS6PI9ffePkiTGEXwg74qwFWRmO3+h509ZqjZl31p2gGXC6rr0MOwZENhtWiyWe3S3w== X-Received: by 2002:a05:6a21:78e:b0:1c0:eba5:e192 with SMTP id adf61e73a8af0-1cc8b49d8abmr14865175637.27.1724824165540; Tue, 27 Aug 2024 22:49:25 -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.49.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 22:49:24 -0700 (PDT) From: Charlie Jenkins Subject: [PATCH 00/16] mm: Introduce MAP_BELOW_HINT Date: Tue, 27 Aug 2024 22:49:06 -0700 Message-Id: <20240827-patches-below_hint_mmap-v1-0-46ff2eb9022d@rivosinc.com> MIME-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAFK6zmYC/x3MTQqAIBBA4avErBPSkn6uEhFmUw6UiUYF4d2Tl t/ivRcCesIAXfaCx4sCHTaB5xloo+yKjOZkEIWoikbUzKlTGwxswu24R0P2HPddOTbxcq5bhVx LCal2Hhd6/nM/xPgBQKT3MGkAAAA= 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=6044; i=charlie@rivosinc.com; h=from:subject:message-id; bh=rybnxgXRfasNksP5lSU1TnJeqx+66siNWRNOd7Jshtg=; b=owGbwMvMwCHWx5hUnlvL8Y3xtFoSQ9q5XSH3lM7XXzj5QFjW4OtX+60nZ+rMb1N2D9F5e2t+8 tuSp8uiOkpZGMQ4GGTFFFl4rjUwt97RLzsqWjYBZg4rE8gQBi5OAZjIkUMMf8WSWp0unDgcOEl5 8kUJVXP5KYyTLI0KMiNvKmnOTI5taWBk2Cj+dkXn/qc3T0v2+U/SXhD+ZpOA/e/6H56BP2LNukr 5GQE= X-Developer-Key: i=charlie@rivosinc.com; a=openpgp; fpr=7D834FF11B1D8387E61C776FFB10D1F27D6B1354 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 5B7211C0008 X-Stat-Signature: tc1ucep3wyfx3panbew14b366hymf3mm X-HE-Tag: 1724824167-442644 X-HE-Meta: U2FsdGVkX1/kyJ/7Gsop52Pg6DTjAfku5Q0a66gPBcYXYVvJ3fCSZe1Ca3o+3lwNUzrzcIeXnoB3LqMRyMupC8JSXE8EpOaPfuvWsZFoXJf7WNYmYz4w8hPIjNmosgpRjv6UIDo5jzDusdsn3sfwYk6OUxyF2MwKhWhvbKJllMUUnuIR7CgCOL+b8Oatp+y1jiYL1ZwJglAdaATKDoPUPft5Ciy2SbkszMZHNb7OTs3xB0nAeQdyWqdIuYFu5DHSDjCPoMJ0jnQlhjTPtJ+RogV4yspie+sKMHx012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ity=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: Some applications rely on placing data in free bits addresses allocated by mmap. Various architectures (eg. x86, arm64, powerpc) restrict the address returned by mmap to be less than the maximum address space, unless the hint address is greater than this value. On arm64 this barrier is at 52 bits and on x86 it is at 56 bits. This flag allows applications a way to specify exactly how many bits they want to be left unused by mmap. This eliminates the need for applications to know the page table hierarchy of the system to be able to reason which addresses mmap will be allowed to return. --- riscv made this feature of mmap returning addresses less than the hint address the default behavior. This was in contrast to the implementation of x86/arm64 that have a single boundary at the 5-level page table region. However this restriction proved too great -- the reduced address space when using a hint address was too small. A patch for riscv [1] reverts the behavior that broke userspace. This series serves to make this feature available to all architectures. I have only tested on riscv and x86. There is a tremendous amount of duplicated code in mmap so the implementations across architectures I believe should be mostly consistent. I added this feature to all architectures that implement either arch_get_mmap_end()/arch_get_mmap_base() or arch_get_unmapped_area_topdown()/arch_get_unmapped_area(). I also added it to the default behavior for arch_get_mmap_end()/arch_get_mmap_base(). Link: https://lore.kernel.org/lkml/20240826-riscv_mmap-v1-2-cd8962afe47f@rivosinc.com/T/ [1] To: Arnd Bergmann To: Paul Walmsley To: Palmer Dabbelt To: Albert Ou To: Catalin Marinas To: Will Deacon To: Michael Ellerman To: Nicholas Piggin To: Christophe Leroy To: Naveen N Rao To: Muchun Song To: Andrew Morton To: Liam R. Howlett To: Vlastimil Babka To: Lorenzo Stoakes To: Thomas Gleixner To: Ingo Molnar To: Borislav Petkov To: Dave Hansen To: x86@kernel.org To: H. Peter Anvin To: Huacai Chen To: WANG Xuerui To: Russell King To: Thomas Bogendoerfer To: James E.J. Bottomley To: Helge Deller To: Alexander Gordeev To: Gerald Schaefer To: Heiko Carstens To: Vasily Gorbik To: Christian Borntraeger To: Sven Schnelle To: Yoshinori Sato To: Rich Felker To: John Paul Adrian Glaubitz To: David S. Miller To: Andreas Larsson To: Shuah Khan To: Alexandre Ghiti Cc: linux-arch@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: Palmer Dabbelt Cc: linux-riscv@lists.infradead.org Cc: linux-arm-kernel@lists.infradead.org Cc: linuxppc-dev@lists.ozlabs.org Cc: linux-mm@kvack.org Cc: loongarch@lists.linux.dev Cc: linux-mips@vger.kernel.org Cc: linux-parisc@vger.kernel.org Cc: linux-s390@vger.kernel.org Cc: linux-sh@vger.kernel.org Cc: sparclinux@vger.kernel.org Cc: linux-kselftest@vger.kernel.org Signed-off-by: Charlie Jenkins --- Charlie Jenkins (16): mm: Add MAP_BELOW_HINT riscv: mm: Do not restrict mmap address based on hint mm: Add flag and len param to arch_get_mmap_base() mm: Add generic MAP_BELOW_HINT riscv: mm: Support MAP_BELOW_HINT arm64: mm: Support MAP_BELOW_HINT powerpc: mm: Support MAP_BELOW_HINT x86: mm: Support MAP_BELOW_HINT loongarch: mm: Support MAP_BELOW_HINT arm: mm: Support MAP_BELOW_HINT mips: mm: Support MAP_BELOW_HINT parisc: mm: Support MAP_BELOW_HINT s390: mm: Support MAP_BELOW_HINT sh: mm: Support MAP_BELOW_HINT sparc: mm: Support MAP_BELOW_HINT selftests/mm: Create MAP_BELOW_HINT test arch/arm/mm/mmap.c | 10 ++++++++ arch/arm64/include/asm/processor.h | 34 ++++++++++++++++++++++---- arch/loongarch/mm/mmap.c | 11 +++++++++ arch/mips/mm/mmap.c | 9 +++++++ arch/parisc/include/uapi/asm/mman.h | 1 + arch/parisc/kernel/sys_parisc.c | 9 +++++++ arch/powerpc/include/asm/task_size_64.h | 36 +++++++++++++++++++++++----- arch/riscv/include/asm/processor.h | 32 ------------------------- arch/s390/mm/mmap.c | 10 ++++++++ arch/sh/mm/mmap.c | 10 ++++++++ arch/sparc/kernel/sys_sparc_64.c | 8 +++++++ arch/x86/kernel/sys_x86_64.c | 25 ++++++++++++++++--- fs/hugetlbfs/inode.c | 2 +- include/linux/sched/mm.h | 34 ++++++++++++++++++++++++-- include/uapi/asm-generic/mman-common.h | 1 + mm/mmap.c | 2 +- tools/arch/parisc/include/uapi/asm/mman.h | 1 + tools/include/uapi/asm-generic/mman-common.h | 1 + tools/testing/selftests/mm/Makefile | 1 + tools/testing/selftests/mm/map_below_hint.c | 29 ++++++++++++++++++++++ 20 files changed, 216 insertions(+), 50 deletions(-) --- base-commit: 5be63fc19fcaa4c236b307420483578a56986a37 change-id: 20240827-patches-below_hint_mmap-b13d79ae1c55