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 1A629C5321D for ; Mon, 26 Aug 2024 08:27:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AEFD76B0246; Mon, 26 Aug 2024 04:27:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A9F2B6B02FD; Mon, 26 Aug 2024 04:27:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 919186B02FE; Mon, 26 Aug 2024 04:27:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 703DE6B0246 for ; Mon, 26 Aug 2024 04:27:31 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 113E8140D39 for ; Mon, 26 Aug 2024 08:27:31 +0000 (UTC) X-FDA: 82493717502.12.721F525 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf27.hostedemail.com (Postfix) with ESMTP id 5E3564000D for ; Mon, 26 Aug 2024 08:27:29 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=zx2c4.com header.s=20210105 header.b=G+es6dtJ; dmarc=pass (policy=quarantine) header.from=zx2c4.com; spf=pass (imf27.hostedemail.com: domain of "SRS0=kq7x=PZ=zx2c4.com=Jason@kernel.org" designates 147.75.193.91 as permitted sender) smtp.mailfrom="SRS0=kq7x=PZ=zx2c4.com=Jason@kernel.org" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724660786; a=rsa-sha256; cv=none; b=76eB95SaVtA13xeGpgdfZpTVnOh25xQpXme97FRvYx31l//bieLEXo753UvctPngpvAyaf JlO5oTjCqJtSscX+MVn+Q2eMncJcbNEQ+WFAr1F9VqX0LOh9qNRt20gOfwWlM6HoXsPUtU 3RKc/PI75Js65LnfMyz9hEM0VVP9VUM= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=zx2c4.com header.s=20210105 header.b=G+es6dtJ; dmarc=pass (policy=quarantine) header.from=zx2c4.com; spf=pass (imf27.hostedemail.com: domain of "SRS0=kq7x=PZ=zx2c4.com=Jason@kernel.org" designates 147.75.193.91 as permitted sender) smtp.mailfrom="SRS0=kq7x=PZ=zx2c4.com=Jason@kernel.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724660786; 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=HBUmQTDhGzpRlPPsawchQxtsrEP7CCWrGrVX0xuqkFU=; b=5uU9WAwi7+HOWQ6NpZAxrkiL5GTvDhQgRoCqHfdpzXCG8uAVbEwRq/R8x/Q+jSNbD4IXnp 8fKyathsBjZ51p9In3d+yi7xiaAc2rvvg2U5Nr/iZnPTmxB+TJavJyXDJiN2nrhk9VtVya Sfjywag8Bcg48TqWduRp+AccS5E/BD0= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id D178EA42008; Mon, 26 Aug 2024 08:27:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E1164C8CDD3; Mon, 26 Aug 2024 08:17:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1724660223; h=from:from: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; bh=HBUmQTDhGzpRlPPsawchQxtsrEP7CCWrGrVX0xuqkFU=; b=G+es6dtJI+WdfXP/RQZRpJVmw+L7y4//5XG1cNyFbgtT4lVYwh1zPdS8zRYE7pYEOQOEki TsL3YKWBg+PZmKHNR6I88paWRAUxfSXKDLMR4TfUocs2r4RP+Vb9eYYFuZRfwZEIQam7j3 UacCwC9xjKUV4ZgUbKdPU2VtnWlD9kk= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id cf114949 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 26 Aug 2024 08:17:02 +0000 (UTC) Date: Mon, 26 Aug 2024 10:16:54 +0200 From: "Jason A. Donenfeld" To: Christophe Leroy Cc: Michael Ellerman , Nicholas Piggin , Naveen N Rao , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Theodore Ts'o , Arnd Bergmann , Andrew Morton , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Vincenzo Frascino , Shuah Khan , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-trace-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH v2 06/17] vdso: Change getrandom's generation to unsigned long Message-ID: References: <525b48eb79978ddba2d1b8ee23b27bd6c5b0b4ee.1724309198.git.christophe.leroy@csgroup.eu> <7d58be73-a8e5-4ec7-bbdc-238b0c25c77b@csgroup.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <7d58be73-a8e5-4ec7-bbdc-238b0c25c77b@csgroup.eu> X-Rspamd-Queue-Id: 5E3564000D X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: qg85u4r4po4z3uiykjb43mprrg5466kf X-HE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ZBlf44V+lvzoHIMmwk8LYakqkylZZBybUlnTVCJsQv3dwOb4hK/8aQFMEBEKx+W7Nc7k1yNYO1T4DFHyboC/3GcBVOc2NcpcUfRyFZLFSYbSzPcoDN/1aLx/tOfr9KvkAZfHcqOYSej5rkVy5IaeUj9FFlCbnyBiwyjAJhuLTIPJJN40uUMCNfpcGe9hp5kz+L+GIv+4cs3agVm/f6GPv3JlNq3XspCwprbE7yBS325Q+fj7c3D1pvHY4bJ1xefcQoi/W6iCk4UGsWuf1OoRussuJqPB92vzd+RY/rXYT3tPeYKf4CVAhGM7k6ysrA/DC1ExAuvUs7yTUCjOJ+nlatF7sQkQw8fzhRa/BRFYeeqKzat8vhPpZcp1xSQyOf4IUtmRjrAPDnFx6GESX3Lm1drYLLJTYbntH1gGZXULTB6x6xS0As2ksmEkxC40wvYdMKN7Fy/pWAHh55dYwj5rYs6UGDgtiRNgG34l9xw4nrcCD20gPsm49F72kliTSgu+kxDJ9snJ2ETj6a/2j4/k2ZaDEnm59k50F5RM4CdcfT7UVqoKWCTmCcnTJ 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 Mon, Aug 26, 2024 at 10:01:17AM +0200, Christophe Leroy wrote: > > > Le 26/08/2024 à 09:50, Jason A. Donenfeld a écrit : > > On Thu, Aug 22, 2024 at 09:13:14AM +0200, Christophe Leroy wrote: > >> Performing SMP atomic operations on u64 fails on powerpc32. > >> > >> Random driver generation is handled as unsigned long not u64, > >> see for instance base_cnrg or struct crng. > >> > >> Use the same type for vDSO's getrandom as it gets copied > >> from the above. This is also in line with the local > >> current_generation which is already an unsigned long. > > > > This isn't going to work when 32-bit userspace tries to access a 64-bit > > kernel. > > > > I had "fixed" this with a vdso_kernel_ulong type way back in an earlier > > version: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Flkml%2F20240528122352.2485958-5-Jason%40zx2c4.com%2F%23Z31include%3Avdso%3Atypes.h&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C41747dd989164267c1cc08dcc5a3c424%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C638602554376441761%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=Tf9ShSN6aOOFZ1HymAmHhj0xhQ6BUtHJX95t50gsp9k%3D&reserved=0 > > > > But tglx pointed out in that thread that this actually isn't necessary: > > > > | All of this is pointless because if a 32-bit application runs on a > > | 64-bit kernel it has to use the 64-bit 'generation'. So why on earth do > > | we need magic here for a 32-bit kernel? > > | > > | Just use u64 for both and spare all this voodoo. We're seriously not > > | "optimizing" for 32-bit kernels. > > | > > | All what happens on a 32-bit kernel is that the RNG will store the > > | unsigned long (32bit) generation into a 64bit variable: > > | > > | smp_store_release(&_vdso_rng_data.generation, next_gen + 1); > > | > > | As the upper 32bit are always zero, there is no issue vs. load store > > | tearing at all. So there is zero benefit for this aside of slightly > > | "better" user space code when running on a 32-bit kernel. Who cares? > > > > So I just got rid of it and used a u64 as he suggested. > > > > However, there's also an additional reason why it's not worth churning > > further over this - because VM_DROPPABLE is 64-bit only (due to flags in > > vma bits), likely so is vDSO getrandom() for the time being. So I think > > it makes more sense to retool this series to be ppc64, and then if you > > really really want 32-bit and can convince folks it matters, then all of > > these parts (for example, here, the fact that the smp helper doesn't > > want to tear) can be fixed up in a separate series. > > So yes I really really want it on ppc32 because this is the only type of > boards I have and this is really were we need getrandom() to be > optimised, indeed ppc64 was sherry-on-the-cake in my series, I just > added it because it was easy to do after doing ppc32. I saw that you did in fact find a bit on ppc32 for VM_DROPPABLE. So it looks at least possible. Because of this generation counter business, I still think it might make sense to do in two steps, though, first doing 64-bit, and then doing 32-bit after. As for the generation counter error you're seeing, I guess what we want is smp_store_release memory ordering semantics, but letting tearing happen (since the upper 32-bits will be zero anyway). I'm not sure the best way to do this, whether it's a new helper, or doing a WRITE_ONCE together with an smp barrier, or what. But I imagine it's something like that. Jason