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: 13782685 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (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 15795176AB4 for ; Thu, 29 Aug 2024 07:16:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724915776; cv=none; b=OyirfF6vSl65ROqZRuE9kr9eHnumcipN5fCAw+tbPuBIOF9rNrq1xYwDdso0qCd/ImdRaBSN0N42hObieOZRRTTvvae4xIObEqbaVr4EVIE2TDpZ6vLF+uA+86+k8ZfsPw8s+qEEfgFMKYOnxjQSMKggBu8RYerKiAVmSbnPLc8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724915776; c=relaxed/simple; bh=ge3WwvXZyWhWUVXepQG4dDA/ByeZCzK4otcQJ4z3f6Q=; h=From:Subject:Date:Message-Id:MIME-Version:Content-Type:To:Cc; b=XvSYAp5NDfu/XszAcKNpb3SXG8Qm1XgNksHXD/G0valXdU/idZJzJp17oGjnW+ORmeebG8jJiVgeS47q9QE90j99Au5QipgYCz/KhsXNmgO7DqbfDAJ9rUKICMT7CNMX4UwU675DonvcibI8Rvck8N5VsSKbpBJPuzsBPbTKoXI= 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=q4RZcxgo; arc=none smtp.client-ip=209.85.210.171 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="q4RZcxgo" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-71434174201so303853b3a.0 for ; Thu, 29 Aug 2024 00:16:13 -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=vger.kernel.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=q4RZcxgolHi7zNPZG7F9KT9yxVCaRkprX1FRJYUuJ07QBsQ/tbr/ErDMLFQV4rE3u0 Nze8ofXW1CUuk9B6AcedQkslWhmttInjoR8pGBYh7NL6hvj7PLbjHabZXBmuOgiUDpfa z6df59hehO0roGsH+4BffFfsRenUVvsr2tkNtrz6HO3Q6XZSF0hI2wuiw2u1jZQMZkhV ZV9HQMlAw5Sk5mMRfQdrHF6v/Nmkh2plgaBO85bKx59ODkqQyj4i3Wk0W4RPWCCtv8Yc fF9zb/uoXIo19t6S47maxp3HLd2KxvcGqlOIQKULNguaLIQsnxtDEEAQmV9fYQExtXWR A6FQ== 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=ixWashNh2VOM3F+ySZodbRfsA67J1E+PmHMcnVlguGbY3J3H6t6NfYijQ+NE1nz1yB O04EHEmuWxSNaoLBCxG+zt4y04cusbfMKhNruN7/QAS3sNh092XExTltpoGgv2Zgo1xV Acm8jL5WUSfkMK/MLVyLiORz3HMnvzOCSdSh7hSEwYiYxAQkXP+4rq87pLGiTlNzuxAu UrN0fKceaa3pYyB4h0lHD7WRMv3Y6sQA4oz8247xnoR8OW5txgti5hI/ycRbmUcslu0c 4UO0h51IOMrtidr5vja704wt+dGb/bkbVoO0P8NZx0/H8EyZdT6YyaJbj/a0vIik7EAJ 3OnA== X-Forwarded-Encrypted: i=1; AJvYcCUSW2wUkiUrH36kNKm9kfqkspcnz5cQcraabi9mMagtam4NX1aag/A+ELHxA8/klTYkwcf0Y7ytpQ==@vger.kernel.org X-Gm-Message-State: AOJu0YzKfh1R+UfFE3wGsHd+MO39wWm4NyDa41gX6YHMRUU4KlCz5R5H sYP1viXAUR8Mvw5yn4iR2+oJ/dyzO1+3Or4boyu49SPLN0OH50epFtMPgby3pwE= 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> Precedence: bulk X-Mailing-List: linux-sh@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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