From patchwork Thu Sep 5 21:15:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13792999 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 14566CE7A9F for ; Thu, 5 Sep 2024 21:16:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 50A856B0083; Thu, 5 Sep 2024 17:16:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4B98B6B0085; Thu, 5 Sep 2024 17:16:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 334966B0088; Thu, 5 Sep 2024 17:16:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 128AE6B0083 for ; Thu, 5 Sep 2024 17:16:17 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 86D541A0B60 for ; Thu, 5 Sep 2024 21:16:16 +0000 (UTC) X-FDA: 82531942752.01.4300CA1 Received: from mail-ot1-f44.google.com (mail-ot1-f44.google.com [209.85.210.44]) by imf17.hostedemail.com (Postfix) with ESMTP id 7D52940015 for ; Thu, 5 Sep 2024 21:16:13 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=wljAJ3sU; spf=pass (imf17.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.210.44 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=1725570948; 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=h1RxVlhkB8p72E7vZJvb+Ijp4614DvwE9gm+Vso2ack=; b=lnicyVZdYch8arAtCN8u9rsx97AdrZ4jl9mrtrLoQCb2AWJtnI3Y1YYAq5TNabewzV6GJ5 K0my8lmTGdHz/k42fnt2qAwE413BzAlLnOJW5rwGCPcai5PZQaxZDPZ8+cMcJjLLGBRh2M mrVoai1xyQf4H44rVPj7VuC08XuEePE= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=wljAJ3sU; spf=pass (imf17.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.210.44 as permitted sender) smtp.mailfrom=charlie@rivosinc.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725570948; a=rsa-sha256; cv=none; b=osqKpuq8MGbgu316bbog7Y7paixPerdlyV8w9vAYNlpHqfwa1wNxDTm6tEg5xJ9uf6ZLuk W3QIyzZn/UAy9lDNERXL+M7cXtJ9b4OVayjDh7UMu3rTi9CiJcOsKAQMSKRT0AYse9PqM0 rrUccCg+EnHVLyq+AHWLSrqjVKXadxI= Received: by mail-ot1-f44.google.com with SMTP id 46e09a7af769-70f63afb792so690784a34.1 for ; Thu, 05 Sep 2024 14:16:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1725570972; x=1726175772; 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=h1RxVlhkB8p72E7vZJvb+Ijp4614DvwE9gm+Vso2ack=; b=wljAJ3sUVAz4ztWcUulH9SMSpFhpHyC+11RC24bsJFaa4B3bWVpy6h/k2rflQV80TH HPm1j+0OOBdvz0xyavL4VGOJPf/GAkky2de/PZgd0889jTI/1M3VCpDTA5/3YVGh5hkz 7IoMy+3q0Lnck2gj28tvB71u959UM/a9G8xNKDRirpPvgMnnzU6ZBOHP1/uwA4MwKZw1 msrEGJMYfCIub5P6Fx0/AuKR+t0GLZw0wNjbmFEGAHKqJmMgUKddtonds7u2U36cb8l7 srRIl0n3+cu9TSeBZWGmM6CvuIM5MkTWxjl6+NRzDOS4gPWtDBNvy9BUiGRVhsyOlBNi TwAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725570972; x=1726175772; 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=h1RxVlhkB8p72E7vZJvb+Ijp4614DvwE9gm+Vso2ack=; b=TVMj/UfAplrOlrTkTYnK93f6MhJpFP2AgvJoGSJRaoSHUMsI5rLikH5Pp+QPs2ZyiV JI3oAMcN7z/KeslFPVhHJBkkM3wK9PL3XbR1PvL+L1rw1Lhfs7kKd5rlHr722VTUqhF3 aJZct8v33MTlPcc/MEkzsI0+UpSn7yEBDqbfqxAwTw9Rf7xdQTWw+lT2HawguI8382Hw xjTtiS+pU0QqPdjRTUwbANrM3Zr68iWHuTRNgTHEe3KrWBwwhUfesJ3VTOSCX60RubH7 +R3vxasmViF/Ur8VQFW5s5q7hYUu+MY6aIgYb+tWGUhrT/B/PELXL/N/P4099i/l6xYo bvyQ== X-Forwarded-Encrypted: i=1; AJvYcCVVEhGctiaa6PxqgFsBzCqWHIVFQ1vhCbk8nosAMeavsMD1BfrDlh4zj+4V6DSvSu7IB4adURIXAw==@kvack.org X-Gm-Message-State: AOJu0YwnjK1szZD63Ggqgs1tSQrSu9PXaoKMtzibBR+CFKCAbNq601KV Lmg2q4VupVIhbG5rrOV1bkm5wOOoHt0Vn11M0pV12P4vTR36cpgMNswsBN5LinA= X-Google-Smtp-Source: AGHT+IFUGglg1gI40db05Oyw57X6jum9/dYSwirPMN5y+AFduyw81mLgzW8++XC4iGt5jarfSGqHMg== X-Received: by 2002:a05:6358:4709:b0:1b8:3498:5ab2 with SMTP id e5c5f4694b2df-1b8386e10e6mr71603755d.18.1725570972065; Thu, 05 Sep 2024 14:16:12 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7d4fbda7abesm3775746a12.61.2024.09.05.14.16.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2024 14:16:11 -0700 (PDT) From: Charlie Jenkins Subject: [PATCH RFC v3 0/2] mm: Introduce ADDR_LIMIT_47BIT personality flag Date: Thu, 05 Sep 2024 14:15:50 -0700 Message-Id: <20240905-patches-below_hint_mmap-v3-0-3cd5564efbbb@rivosinc.com> MIME-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAIYf2mYC/4XNTQrCMBAF4KtI1kaS6b8rQfAAbkVKmk7NgG1KU qJSendDVyKIyzeP+d7MPDpCz/abmTkM5MkOMSTbDdNGDTfk1MbMQEAqSij4qCZt0PMG7/ZRGxq muu/VyBuZtEWlUOosY/F7dNjRc5Uv7Hw6sms8GvKTda91Lci1+gsHyQVP864DbCoB0B4cBetp0 Dtt+5UN8ElVvymIVJ6UCsq2QoXii1qW5Q0BYjuXEQEAAA== 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 , Christoph Hellwig , Michal Hocko , "Kirill A. Shutemov" , Chris Torek 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, linux-abi-devel@lists.sourceforge.net, Charlie Jenkins X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=5488; i=charlie@rivosinc.com; h=from:subject:message-id; bh=8yDjUN3v9pzHbAJkU962KdEeNCXYhTKg/kSM+xczGS8=; b=owGbwMvMwCHWx5hUnlvL8Y3xtFoSQ9ot+f6nvpcl97tY5XM5HRGwunrS/1hN4Jrc4J63aWdPl kkz5fzoKGVhEONgkBVTZOG51sDceke/7Kho2QSYOaxMIEMYuDgFYCIbvBgZfjQZPtnyo0T8l+3r pTc0r/6LOCzwZu3XBXX7mfYvU6k4cI2R4YF4V0iLZoGQYvmDbN1ZIvanHjMsmvbgwI2pnto/ozc e4gMA X-Developer-Key: i=charlie@rivosinc.com; a=openpgp; fpr=7D834FF11B1D8387E61C776FFB10D1F27D6B1354 X-Rspam-User: X-Stat-Signature: 1rgioxd6sxfukparnqmdzsemdxipwmi6 X-Rspamd-Queue-Id: 7D52940015 X-Rspamd-Server: rspam11 X-HE-Tag: 1725570973-233714 X-HE-Meta: U2FsdGVkX19vmUEfe1VNU4hsprfa+MZWGAQmrkegQUQX4Xm+DDIBGm6AsMMz9vK5LHlkhNTJnUYa2cRVFZLYN/fZId87BUayl2TSLkuFohG7f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BxxUd70G/u5ZDRln0RZ5VhvAP+Gi7RvusqIOWn1X+iiL6BaB4dVPnG9+SNYFmCatPHMYtWv4UoUwntgy+RSLsWKLw2SE+DHgVX7yt5xpTOdw+66imc9z6q+a7GOWqzTLa0LlrXKGwOedBE6OrF7A/otGrlfdLIPyKBiNmLaTxv393+U/9p76UD9MJLJOMoC6l75HyxXZMEHGvZ4lM8rcEmwfcIAXb7dy 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), provide a flag to the personality syscall that can be used to ensure an application works in any arbitrary VA space. A similar feature has already been implemented by the personality syscall in ADDR_LIMIT_32BIT. 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 To: Christoph Hellwig To: Michal Hocko To: "Kirill A. Shutemov" To: Chris Torek 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 Cc: linux-abi-devel@lists.sourceforge.net 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 Changes in v3: - Use a personality flag instead of an mmap flag - Link to v2: https://lore.kernel.org/r/20240829-patches-below_hint_mmap-v2-0-638a28d9eae0@rivosinc.com Acked-by: Guo Ren Tested-by: Jiaxun Yang --- Charlie Jenkins (2): mm: Add personality flag to limit address to 47 bits selftests/mm: Create ADDR_LIMIT_47BIT test include/uapi/linux/personality.h | 1 + mm/mmap.c | 3 ++ tools/testing/selftests/mm/.gitignore | 1 + tools/testing/selftests/mm/Makefile | 1 + tools/testing/selftests/mm/map_47bit_personality.c | 34 ++++++++++++++++++++++ 5 files changed, 40 insertions(+) --- base-commit: 5be63fc19fcaa4c236b307420483578a56986a37 change-id: 20240827-patches-below_hint_mmap-b13d79ae1c55