From mboxrd@z Thu Jan 1 00:00:00 1970 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 51EA4FC6181 for ; Fri, 13 Sep 2024 21:04:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 921C96B00B7; Fri, 13 Sep 2024 17:04:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8A9046B00BB; Fri, 13 Sep 2024 17:04:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6AE456B00BD; Fri, 13 Sep 2024 17:04:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 441386B00B7 for ; Fri, 13 Sep 2024 17:04:16 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id EC9B01A0C06 for ; Fri, 13 Sep 2024 21:04:15 +0000 (UTC) X-FDA: 82560942870.22.E95A0ED Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by imf04.hostedemail.com (Postfix) with ESMTP id DABCD40028 for ; Fri, 13 Sep 2024 21:04:13 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=EQcmXEjj; spf=pass (imf04.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.214.172 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=1726261347; 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=pGN098PfFZ1p39RZKtno/bb1iGOxyKkQDSILC8HyAbs=; b=uqPLerb+rxphgDmn0E9coCjxdHQ3Yb8TBMZvzTYhUj13vbWcKyKWeApSQ2TXpKfxSYNXS+ 5a9LuRHrW/tKPGbzV5i0tAWh+sLdkg7qo85D1hfzUqWy2g3rECR7B3uiSAClit09X4slFK ueJyZ5gGX3ujwfYgI7pUwcSd13A1DKE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726261347; a=rsa-sha256; cv=none; b=Ug6kQXm5iAFH2jCXzYP3tAzTG9PWytUt/8I8SH2zIJkZ4tppfd+y+WaO9AozHBQ8un38OX RGStCZAFg1ADwzAUKRgfxFZAq/aMm6CIq1aNvt+kd9U2nvMySArwbEoRELB3ylO7pPl/1C kqo68JHmj0c+ygfEPzma0mIkh+i3lWw= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=EQcmXEjj; spf=pass (imf04.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.214.172 as permitted sender) smtp.mailfrom=charlie@rivosinc.com; dmarc=none Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-2068acc8a4fso13331715ad.1 for ; Fri, 13 Sep 2024 14:04:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1726261452; x=1726866252; darn=kvack.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=pGN098PfFZ1p39RZKtno/bb1iGOxyKkQDSILC8HyAbs=; b=EQcmXEjj03ZWAzr+jE93NYT8VQBI5KDPBN8fXgOKKp2ITWHUH8p7kGnXjacIiDkYHe IK8vYoSMZYQqPwWvbkqDK2lxb6ivkpfr/8IJ0A6uYF21aFnYKbJ4NMbTQignh76gJL0W 5AAP5OkEgWxlTgMTKj1MSF0j6Xq+ot2gO7xhhQ7kxfhpOAHJhDg90AmwGdV2My/dZ1Dr +NdkmN+raQuRw0otLyDau9vmP47Oim3aleUqMnXs1tzkXuIXKZ8CGQ+/ytB/opD+JTS+ ye8+wf+prznTAMXN4KfnoU6VsgXGVHUAZJbcCw4E2k9VfrM5XDjy9XdSmob5mwIZ6bIg kqVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726261452; x=1726866252; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=pGN098PfFZ1p39RZKtno/bb1iGOxyKkQDSILC8HyAbs=; b=anSPW28+ThAdGfK5U+sNcBCn0l6933zXLry8HdREPO6yhIfirUFTzTxyi/ptJ4jigt VRWZjH3ayFY5Yu3BAMPudCvj0WSMM5jogaOaiFAqhAWPSbLvTvNVPZF5tXZHRWg0r7Ya aofVt5vZM6GKc85A0d3c64tKlA23+a0y4+JUglP5daX6ODueuSb1apsq9KDqBj/XrV++ 3lEDyv19DOcYDDnLzdlU/u3I3OxelLt9OiUGQy5pnPB33RPgtr8wvF/G5r/N/ZS2pAwN 3oDpBiUU9hgMAW0egZgwhzxaeegH78RkAXw8lnZAgLyoAaThERfN6/Gzu/5RqCSGdiWB sQMA== X-Forwarded-Encrypted: i=1; AJvYcCUtRoANuE3S9xwD1AT4pDhQETmfg9oe5zqAWCACh8otdz/HRBzXw0HfpACVqb/1/HfywKPoLqaeng==@kvack.org X-Gm-Message-State: AOJu0YwZT1M04rwggyyQ/Raph4y0fNrmu40Jtqf2Tgw9xouBkLFzJ/Kq PHuEbj5/jWP7NtT26nYs4pZyhh6v3U3YGk9VaHWszEvI4nlsbkpMPnoNJFAnUFQ= X-Google-Smtp-Source: AGHT+IHQy68+7/4em5wfAX0phJQ7a7VsNC8xlp5lvUp2N1zpKPOlth6aUECbhTSHxYBYBN7icOc/wA== X-Received: by 2002:a17:902:f54f:b0:207:457f:b8a6 with SMTP id d9443c01a7336-2078262ccc1mr54571405ad.12.1726261452005; Fri, 13 Sep 2024 14:04:12 -0700 (PDT) Received: from ghost ([50.145.13.30]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-207945da8c9sm608475ad.17.2024.09.13.14.04.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 14:04:11 -0700 (PDT) Date: Fri, 13 Sep 2024 14:04:06 -0700 From: Charlie Jenkins To: Lorenzo Stoakes Cc: Catalin Marinas , "Liam R. Howlett" , Arnd Bergmann , guoren , Richard Henderson , Ivan Kokshaysky , Matt Turner , Vineet Gupta , Russell King , 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 , Vlastimil Babka , shuah , Christoph Hellwig , Michal Hocko , "Kirill A. Shutemov" , Chris Torek , Linux-Arch , 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 Subject: Re: [PATCH RFC v3 1/2] mm: Add personality flag to limit address to 47 bits Message-ID: References: <20240905-patches-below_hint_mmap-v3-1-3cd5564efbbb@rivosinc.com> <9fc4746b-8e9d-4a75-b966-e0906187e6b7@app.fastmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: DABCD40028 X-Stat-Signature: 9po1a1yiugdi3y8ay3yybbwu5oocmn9o X-HE-Tag: 1726261453-733363 X-HE-Meta: U2FsdGVkX1/tXYh7mbBWKYmOZg3bmsJtTGgwdo5Uz46WU0UNmgRB2x2fIx42ZrogAbdGexKzT+UVnzrQp3so41bR+b4vGNpd7V+zWYYwpa50KsXvBwlnVH1ARyu4s/gnGcUV1U8jUfUtzksLX1Vv+KOV7hwVLVJSMgvknKgV2yW8M2EviYt3z2dm8zDbsmAAP4RfFmP6elAwc98sH4YBfNLXgCM6XDEu9MtK77w4j39WDKu2QsQrnTzSH8Pbqu/wCn1A1cHBB+V0WDJaN/Sgkc7QXul/DpG+wCRdNQlGsjlaZFGcUCajDBThhgHIFMPs1NWOJchGlpp+M/3U0vwo3vRzk5RgSu2QRahLToH26FM7M8NxkXfPUhJWpqiHhByCOvz3IEfrT/YhhflsSC4kjZTlfmFxZs8ZAPwqCV3sFiRvi7v8PhjsBm7GLcVvMjYMZAlvtS7FTuT09jxaSEyOEcIXYI/TSO/SA9Rc9YEBByy6+/wRl2GO2hn1HopYkHcSYIJgVwIw7KYPj8EHA7Ta4V5NizARHY77F36WJI4jaV43C9cvpuQ+rdLAZSZuY/A59QXSPbgj/8TyyltQAeBVypTWD42Sm3n4WaeIULWZoitRw4nuKcnEJCpacTG9FS3Q+jTN2Bpj/cTTFb1KUK9yaIlj6LbYqZlDBlhjtzGY3mR4SATm7SYC9nfKhZxQtLknrRISiEBLEffYlEz6E7i1Ss33Tyyltb8SqHxC21dU2NBKf1cysBo/GreecPwSjn74z+12Un0ytNDm4M12bMzvXkj/OyUvnGHVyLt2aK/ph1/iwEVqI1+NAbsnc9jF1V0prZglDWaIJ0uSGxSTMDW3FGCmLa01+Igpj1Kk1UJT3XLewMnzhuDRlU1mhV8KflmFx/nKtgMTuptsCJWENnS0kS+wlsXamS3RygvSvBSz6XoDSYU1gqPIcUOgCiU8seusxIjmODceyo3ZT1bciBA dJZJXAik +X5SINlgGoXiUIcXwZpMh3/ZjzqNAADn6HuIMywWnoeFDAoxlhNeXeezqrwJ6B7X4z3Q1JItEdc4iuijRVvKOaZyB7CJQ1hk0dp6yTiLK+xRuk4k2BEYIUF63QJab27F3ROGCIeXUyOVQaDDPD9pVt9pNMWGgZPSqINl6xDtYI/IoTQfqpYT+w7daT5YS2ZR8MT86UJ0tpRfrnpu1lTfnDw7Yf8Ojb+EmTkKTlrx82wqKETkxNMREZ8FpxSNKA1PFkE1xn+TfKLAu/+HKYxibv0E2FuKQ0NycJCgAcOpj1J1nfbYGqYFA1YlvVMgMzl8th48yIJnkf3Ftg9mrnz9aMFXVqOrCcJk4czZstS6+tRGanSs/HSaiiu9r2gsLihESASKmQgEK8AI6AQB0OnXqKK6LbNcstUJK/3EPsAniHS+RtbQ02YR50XzHECQvziZS0X6U4kPVdXzP6avdhFvhsWQ1E6oPvlfEkE3AFcgGNMf2W41lfZgqZsWuass9xsP+r/mu/u+P+Mc/orgy93ksU7nDAq2r/F1WoCcRE/jttIO4c9wM8tMczbJezA== 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: On Fri, Sep 13, 2024 at 08:41:34AM +0100, Lorenzo Stoakes wrote: > On Wed, Sep 11, 2024 at 11:18:12PM GMT, Charlie Jenkins wrote: > > On Wed, Sep 11, 2024 at 07:21:27PM +0100, Catalin Marinas wrote: > > > On Tue, Sep 10, 2024 at 05:45:07PM -0700, Charlie Jenkins wrote: > > > > On Tue, Sep 10, 2024 at 03:08:14PM -0400, Liam R. Howlett wrote: > > > > > * Catalin Marinas [240906 07:44]: > > > > > > On Fri, Sep 06, 2024 at 09:55:42AM +0000, Arnd Bergmann wrote: > > > > > > > On Fri, Sep 6, 2024, at 09:14, Guo Ren wrote: > > > > > > > > On Fri, Sep 6, 2024 at 3:18 PM Arnd Bergmann wrote: > > > > > > > >> It's also unclear to me how we want this flag to interact with > > > > > > > >> the existing logic in arch_get_mmap_end(), which attempts to > > > > > > > >> limit the default mapping to a 47-bit address space already. > > > > > > > > > > > > > > > > To optimize RISC-V progress, I recommend: > > > > > > > > > > > > > > > > Step 1: Approve the patch. > > > > > > > > Step 2: Update Go and OpenJDK's RISC-V backend to utilize it. > > > > > > > > Step 3: Wait approximately several iterations for Go & OpenJDK > > > > > > > > Step 4: Remove the 47-bit constraint in arch_get_mmap_end() > > > > > > Point 4 is an ABI change. What guarantees that there isn't still > > > software out there that relies on the old behaviour? > > > > Yeah I don't think it would be desirable to remove the 47 bit > > constraint in architectures that already have it. > > > > > > > > > > > > I really want to first see a plausible explanation about why > > > > > > > RISC-V can't just implement this using a 47-bit DEFAULT_MAP_WINDOW > > > > > > > like all the other major architectures (x86, arm64, powerpc64), > > > > > > > > > > > > FWIW arm64 actually limits DEFAULT_MAP_WINDOW to 48-bit in the default > > > > > > configuration. We end up with a 47-bit with 16K pages but for a > > > > > > different reason that has to do with LPA2 support (I doubt we need this > > > > > > for the user mapping but we need to untangle some of the macros there; > > > > > > that's for a separate discussion). > > > > > > > > > > > > That said, we haven't encountered any user space problems with a 48-bit > > > > > > DEFAULT_MAP_WINDOW. So I also think RISC-V should follow a similar > > > > > > approach (47 or 48 bit default limit). Better to have some ABI > > > > > > consistency between architectures. One can still ask for addresses above > > > > > > this default limit via mmap(). > > > > > > > > > > I think that is best as well. > > > > > > > > > > Can we please just do what x86 and arm64 does? > > > > > > > > I responded to Arnd in the other thread, but I am still not convinced > > > > that the solution that x86 and arm64 have selected is the best solution. > > > > The solution of defaulting to 47 bits does allow applications the > > > > ability to get addresses that are below 47 bits. However, due to > > > > differences across architectures it doesn't seem possible to have all > > > > architectures default to the same value. Additionally, this flag will be > > > > able to help users avoid potential bugs where a hint address is passed > > > > that causes upper bits of a VA to be used. > > > > > > The reason we added this limit on arm64 is that we noticed programs > > > using the top 8 bits of a 64-bit pointer for additional information. > > > IIRC, it wasn't even openJDK but some JavaScript JIT. We could have > > > taught those programs of a new flag but since we couldn't tell how many > > > are out there, it was the safest to default to a smaller limit and opt > > > in to the higher one. Such opt-in is via mmap() but if you prefer a > > > prctl() flag, that's fine by me as well (though I think this should be > > > opt-in to higher addresses rather than opt-out of the higher addresses). > > > > The mmap() flag was used in previous versions but was decided against > > because this feature is more useful if it is process-wide. A > > personality() flag was chosen instead of a prctl() flag because there > > existed other flags in personality() that were similar. I am tempted to > > use prctl() however because then we could have an additional arg to > > select the exact number of bits that should be reserved (rather than > > being fixed at 47 bits). > > I am very much not in favour of a prctl(), it would require us to add state > limiting the address space and the timing of it becomes critical. Then we > have the same issue we do with the other proposals as to - what happens if > this is too low? > > What is 'too low' varies by architecture, and for 32-bit architectures > could get quite... problematic. > > And again, wha is the RoI here - we introducing maintenance burden and edge > cases vs. the x86 solution in order to... accommodate things that need more > than 128 TiB of address space? A problem that does not appear to exist in > reality? > > I suggested the personality approach as the least impactful compromise way > of this series working, but I think after what Arnd has said (and please > forgive me if I've missed further discussion have been dipping in and out > of this!) - adapting risc v to the approach we take elsewhere seems the > most sensible solution to me. > > This remains something we can revisit in future if this turns out to be > egregious. > I appreciate Arnd's comments, but I do not think that making 47-bit the default is the best solution for riscv. On riscv, support for 48-bit address spaces was merged in 5.17 and support for 57-bit address spaces was merged in 5.18 without changing the default addresses provided by mmap(). It could be argued that this was a mistake, however since at the time there didn't exist hardware with larger address spaces it wasn't an issue. The applications that existed at the time that relied on the smaller address spaces have not been able to move to larger address spaces. Making a 47-bit user-space address space default solves the problem, but that is not arch agnostic, and can't be since of the varying differences in page table sizes across architectures, which is the other part of the problem I am trying to solve. > > > > Opting-in to the higher address space is reasonable. However, it is not > > my preference, because the purpose of this flag is to ensure that > > allocations do not exceed 47-bits, so it is a clearer ABI to have the > > applications that want this guarantee to be the ones setting the flag, > > rather than the applications that want the higher bits setting the flag. > > Perfect is the enemy of the good :) and an idealised solution may not end > up being something everybody can agree on. Yes you are totally right! Although this is not my ideal solution, it sufficiently accomplishes the goal so I think it is reasonable to implement this as a personality flag. > > > > > - Charlie > > > > > > > > -- > > > Catalin > > > > > >