From patchwork Thu Aug 29 07:15:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13782675 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 F327CC7EE30 for ; Thu, 29 Aug 2024 07:16:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5CD5C6B009F; Thu, 29 Aug 2024 03:16:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 554AF6B00A3; Thu, 29 Aug 2024 03:16:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 37F586B00BA; Thu, 29 Aug 2024 03:16:17 -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 1077D6B009F for ; Thu, 29 Aug 2024 03:16:17 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id B7D03A9F1B for ; Thu, 29 Aug 2024 07:16:16 +0000 (UTC) X-FDA: 82504424352.25.3C6D556 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) by imf01.hostedemail.com (Postfix) with ESMTP id B9FC340011 for ; Thu, 29 Aug 2024 07:16:14 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=qmW5m+1x; dmarc=none; spf=pass (imf01.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.210.182 as permitted sender) smtp.mailfrom=charlie@rivosinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724915675; 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=BzAtIL6RDQhGfK05hmJR7MmcGIg9Atw6OyAgLvdRB8w=; b=6qi1+zMY+jrGHe1ooxioJ8vx0jY4z9plarbTj/B1m0hEm+8y+A+61yxMAStSqQdMOKyrb5 ImpUOqBa5yncUehYXWKBzQMWtZffA3Ay/5vsykkrGXmyKEHL+Eu5GQP44M0oE8qy0sXkca 8UuaA5gUNfC3Qk1Ix0NWFPZcCYkt0JE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724915675; a=rsa-sha256; cv=none; b=DZvE2ydn6iy/K9fuYqCnDU9i+VSxBoj2OZM/wy3s+fBZ+/7gHpIablhuVqaE1qBG2nNsh9 X31IbD7QuV+8PeLuEPqw9VqARrlotUqiPiMWKloKprLt+2WtDx65JyffWDQlRVyatJHhAB sTL5yPv41cHPCsviCV47UXSyteh53mY= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=qmW5m+1x; dmarc=none; spf=pass (imf01.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.210.182 as permitted sender) smtp.mailfrom=charlie@rivosinc.com Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-71434174201so303850b3a.0 for ; Thu, 29 Aug 2024 00:16:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724915773; x=1725520573; 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=BzAtIL6RDQhGfK05hmJR7MmcGIg9Atw6OyAgLvdRB8w=; b=qmW5m+1x4QMqHQJ28jqoV9K43V+rK4I5bnYwLKOma/t2a5ASBOU5nNqLPHYolK6IiV J0c+IlOQkYYtK7Vx/03op5DHd56S4Wh9+l+WPCJle1Fo0QoMSyTNiHdE9/8hlIi6nP4Q 4Aue6eL9KN5DCam4Qx+36BaFK5FeHukl7F9zcVTx5b9I0Gkhe077COeGU2xGOMP1L6dm tyyZsGvZEM6SK5fQEPBCqFRKBXaHRX6K3rsHjb90yMQvgBFCNWHiTQI/N4v+nNhFKAQl eBgggVmr+DUybY1RgdyakVVGNwUiQUoDEzA+fWfKd7MOLxgtmxUfeEMr64bl72Gl4vtU tiLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724915773; x=1725520573; 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=BzAtIL6RDQhGfK05hmJR7MmcGIg9Atw6OyAgLvdRB8w=; b=WAWaZJAZS/R8JeV5XNDmGFjPZ16Yb0oNl8NCtT2rIUvik76v6eBhenZoE+4ufh38WZ pH1GSV0H7An+9TmRXWqcx+kRH0APLpUszcaXS1lMHFCXJDG7AK8p5KXZ3274AtBg7Z39 VPQ/IBDzXAWSQV4H0nRRVFo5M5zWL83D4N0LqnZ3QcAG606FVCSVUTn/2o3ss8s1NhZP kC5g8EUqnS00W724iL0oJDI+7Vdg7TdsBkCr1rBy70+6D/4lhMCcvhiR/uHNGoKlSLD0 E4ADZVrg/nq5ZBXH++gqWNR5T/DIbAmClIdythhWBlZedCbVDdTx195lTQhMxCEGh+o4 7+Mg== X-Forwarded-Encrypted: i=1; AJvYcCVV42cJ3n5pVjVSs/Q2uyGMrhnt2fbpLaowf2JO/NQj1WI5+A0qJkQehKvU5cUhU+0+o7G84vg/EQ==@kvack.org X-Gm-Message-State: AOJu0YxA3w/QP5KqfwmH2R50SGI+91d/O6laUTJnnkdRaSibwQ5KfGip Oz7jk6IukoS+lSsT/XasfkZZjUyMJ7D2ybrJsf1IprfwE3t+MIjp5aPvsqg97Rs= X-Google-Smtp-Source: AGHT+IHrzBJ2Fgit9cV9vJs1usISWUDgya5+GeDNPqBqFu2p0vbtJbTyW9MLD5/YHjShE4BhfoWnAg== X-Received: by 2002:a05:6a20:b728:b0:1cc:e5bc:37de with SMTP id adf61e73a8af0-1cce5bc3a28mr493971637.39.1724915773108; Thu, 29 Aug 2024 00:16:13 -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.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2024 00:16:12 -0700 (PDT) From: Charlie Jenkins Subject: [PATCH RFC v2 0/4] mm: Introduce MAP_BELOW_HINT Date: Thu, 29 Aug 2024 00:15:57 -0700 Message-Id: <20240829-patches-below_hint_mmap-v2-0-638a28d9eae0@rivosinc.com> MIME-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAC0g0GYC/4WNQQrCMBREr1L+2kgSW2tdCYIHcCulpOmv+WCSk pSolN7d0Au4fDPMmwUiBsII52KBgIkieZdB7grQRrknMhoyg+Sy5CdZs0nN2mBkPb78uzPk5s5 aNbFeHIa6USh0VUFeTwFH+mzmB9xvV2hzaCjOPny3tyS26q84CcZZeRxHiX3DpRwugZKP5PRee wvtuq4/Hwm3e8YAAAA= 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=6188; i=charlie@rivosinc.com; h=from:subject:message-id; bh=ge3WwvXZyWhWUVXepQG4dDA/ByeZCzK4otcQJ4z3f6Q=; b=owGbwMvMwCHWx5hUnlvL8Y3xtFoSQ9oFBQOjmt83Ze5+Y5jJwf/h4bocwxO7Tt0q2Kl8lUP5K V9S/v9ZHaUsDGIcDLJiiiw81xqYW+/olx0VLZsAM4eVCWQIAxenAEyk3oORoS/Re2N8R6fkDV2R mFveRs1dnurLCyI0LhvtFJlbWLXDnuG/J6uoq83X57P4m4ztnkiJ+tQFH1Eo3Fff8GpduMeUgAR mAA== X-Developer-Key: i=charlie@rivosinc.com; a=openpgp; fpr=7D834FF11B1D8387E61C776FFB10D1F27D6B1354 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: B9FC340011 X-Stat-Signature: cy77bgrpq8x8wsppay4bufzijt79k7ny X-Rspam-User: X-HE-Tag: 1724915774-654721 X-HE-Meta: U2FsdGVkX18Pe+DWFlQ86yVizkgsjiVMG1Fnd/6ktYfWimf+V2zT0uxtFS9LcBuu0m5jPFFwExeczWW4nACJw15BF1GkkSOxb/pGTqxRcN+7o0vXJ2jAA+nQeiahSUdyNyfaLvwYGc5SReyDEToBxgvtiEtKJbgRW5JoqxW4shZt90KeJpeJu997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9ahMxiegcePLOM8GPfEGSreRTi9BKCF2RIOyjdzTidE8F+SbXh2zc= X-Bogosity: 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: 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 48-bit address space, unless the hint address uses more than 47 bits (the 48th bit is reserved for the kernel address space). The riscv architecture needs a way to similarly restrict the virtual address space. On the riscv port of OpenJDK an error is thrown if attempted to run on the 57-bit address space, called sv57 [1]. golang has a comment that sv57 support is not complete, but there are some workarounds to get it to mostly work [2]. These applications work on x86 because x86 does an implicit 47-bit restriction of mmap() address that contain a hint address that is less than 48 bits. Instead of implicitly restricting the address space on riscv (or any current/future architecture), a flag would allow users to opt-in to this behavior rather than opt-out as is done on other architectures. This is desirable because it is a small class of applications that do pointer masking. This flag will also allow seemless compatibility between all architectures, so applications like Go and OpenJDK that use bits in a virtual address can request the exact number of bits they need in a generic way. The flag can be checked inside of vm_unmapped_area() so that this flag does not have to be handled individually by each architecture. Link: https://github.com/openjdk/jdk/blob/f080b4bb8a75284db1b6037f8c00ef3b1ef1add1/src/hotspot/cpu/riscv/vm_version_riscv.cpp#L79 [1] Link: https://github.com/golang/go/blob/9e8ea567c838574a0f14538c0bbbd83c3215aa55/src/runtime/tagptr_64bit.go#L47 [2] To: Arnd Bergmann To: Richard Henderson To: Ivan Kokshaysky To: Matt Turner To: Vineet Gupta To: Russell King To: Guo Ren To: Huacai Chen To: WANG Xuerui To: Thomas Bogendoerfer To: James E.J. Bottomley To: Helge Deller To: Michael Ellerman To: Nicholas Piggin To: Christophe Leroy To: Naveen N Rao 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: Thomas Gleixner To: Ingo Molnar To: Borislav Petkov To: Dave Hansen To: x86@kernel.org To: H. Peter Anvin To: Andy Lutomirski To: Peter Zijlstra To: Muchun Song To: Andrew Morton To: Liam R. Howlett To: Vlastimil Babka To: Lorenzo Stoakes To: Shuah Khan Cc: linux-arch@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: linux-alpha@vger.kernel.org Cc: linux-snps-arc@lists.infradead.org Cc: linux-arm-kernel@lists.infradead.org Cc: linux-csky@vger.kernel.org Cc: loongarch@lists.linux.dev Cc: linux-mips@vger.kernel.org Cc: linux-parisc@vger.kernel.org Cc: linuxppc-dev@lists.ozlabs.org Cc: linux-s390@vger.kernel.org Cc: linux-sh@vger.kernel.org Cc: sparclinux@vger.kernel.org Cc: linux-mm@kvack.org Cc: linux-kselftest@vger.kernel.org Signed-off-by: Charlie Jenkins Changes in v2: - Added much greater detail to cover letter - Removed all code that touched architecture specific code and was able to factor this out into all generic functions, except for flags that needed to be added to vm_unmapped_area_info - Made this an RFC since I have only tested it on riscv and x86 - Link to v1: https://lore.kernel.org/r/20240827-patches-below_hint_mmap-v1-0-46ff2eb9022d@rivosinc.com --- Charlie Jenkins (4): mm: Add MAP_BELOW_HINT mm: Add hint and mmap_flags to struct vm_unmapped_area_info mm: Support MAP_BELOW_HINT in vm_unmapped_area() selftests/mm: Create MAP_BELOW_HINT test arch/alpha/kernel/osf_sys.c | 2 ++ arch/arc/mm/mmap.c | 3 +++ arch/arm/mm/mmap.c | 7 ++++++ arch/csky/abiv1/mmap.c | 3 +++ arch/loongarch/mm/mmap.c | 3 +++ arch/mips/mm/mmap.c | 3 +++ arch/parisc/kernel/sys_parisc.c | 3 +++ arch/powerpc/mm/book3s64/slice.c | 7 ++++++ arch/s390/mm/hugetlbpage.c | 4 ++++ arch/s390/mm/mmap.c | 6 ++++++ arch/sh/mm/mmap.c | 6 ++++++ arch/sparc/kernel/sys_sparc_32.c | 3 +++ arch/sparc/kernel/sys_sparc_64.c | 6 ++++++ arch/sparc/mm/hugetlbpage.c | 4 ++++ arch/x86/kernel/sys_x86_64.c | 6 ++++++ arch/x86/mm/hugetlbpage.c | 4 ++++ fs/hugetlbfs/inode.c | 4 ++++ include/linux/mm.h | 2 ++ include/uapi/asm-generic/mman-common.h | 1 + mm/mmap.c | 9 ++++++++ tools/include/uapi/asm-generic/mman-common.h | 1 + tools/testing/selftests/mm/Makefile | 1 + tools/testing/selftests/mm/map_below_hint.c | 32 ++++++++++++++++++++++++++++ 23 files changed, 120 insertions(+) --- base-commit: 5be63fc19fcaa4c236b307420483578a56986a37 change-id: 20240827-patches-below_hint_mmap-b13d79ae1c55