From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from eu-smtp-delivery-151.mimecast.com ([185.58.85.151]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ohHlj-00EJfs-S7 for linux-um@lists.infradead.org; Sat, 08 Oct 2022 21:54:07 +0000 From: David Laight Subject: RE: [PATCH v3 3/5] treewide: use get_random_u32() when possible Date: Sat, 8 Oct 2022 21:53:33 +0000 Message-ID: <69080fb8cace486db4e28e2e90f1d550@AcuMS.aculab.com> References: <20221006165346.73159-1-Jason@zx2c4.com> <20221006165346.73159-4-Jason@zx2c4.com> <848ed24c-13ef-6c38-fd13-639b33809194@csgroup.eu> <6396875c-146a-acf5-dd9e-7f93ba1b4bc3@csgroup.eu> <501b0fc3-6c67-657f-781e-25ee0283bc2e@csgroup.eu> <202210071010.52C672FA9@keescook> In-Reply-To: MIME-Version: 1.0 Content-Language: en-US List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-um" Errors-To: linux-um-bounces+geert=linux-m68k.org@lists.infradead.org To: "'Jason A. Donenfeld'" , Kees Cook Cc: Christophe Leroy , "linux-kernel@vger.kernel.org" , "patches@lists.linux.dev" , Andreas Noever , Andrew Morton , "Andy Shevchenko , Borislav Petkov" , Catalin Marinas , =?utf-8?B?Q2hyaXN0b3BoIELDtmhtd2FsZGVy?= , Christoph Hellwig , Daniel Borkmann , "Dave Airlie , Dave Hansen , David S . Miller" , Eric Dumazet , Florian Westphal , Greg Kroah-Hartman , "H . Peter Anvin" , "Heiko Carstens , Helge Deller , Herbert Xu" , Huacai Chen , "Hugh Dickins , Jakub Kicinski , James E . J . Bottomley , Jan Kara , Jason Gunthorpe" , Jens Axboe , Johannes Berg , Jonathan Corbet , "Jozsef Kadlecsik , KP Singh , Marco Elver" , Mauro Carvalho Chehab , "Michael Ellerman , Pablo Neira Ayuso , Paolo Abeni" , Peter Zijlstra , Richard Weinberger , Russell King , Theodore Ts'o , Thomas Bogendoerfer , Thomas Gleixner , Thomas Graf , Ulf Hansson , Vignesh Raghavendra , WANG Xuerui , Will Deacon , Yury Norov , "dri-devel@lists.freedesktop.org" , "kasan-dev@googlegroups.com" , "kernel-janitors@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "linux-block@vger.kernel.org" , "linux-crypto@vger.kernel.org" , "linux-doc@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" , "linux-media@vger.kernel.org" , "linux-mips@vger.kernel.org" , "linux-mm@kvack.org" , "linux-mmc@vger.kernel.org" , "linux-mtd@lists.infradead.org" , "linux-nvme@lists.infradead.org" , "linux-parisc@vger.kernel.org" , "linux-rdma@vger.kernel.org" , "linux-s390@vger.kernel.org" , "linux-um@lists.infradead.org" , "linux-usb@vger.kernel.org" , "linux-wireless@vger.kernel.org" , "linuxppc-dev@lists.ozlabs.org" , "loongarch@lists.linux.dev" , "netdev@vger.kernel.org" , "sparclinux@vger.kernel.org" , "x86@kernel.org" , =?utf-8?B?VG9rZSBIw7hpbGFuZC1Kw7hyZ2Vuc2Vu?= , Chuck Lever , Jan Kara From: Jason A. Donenfeld > Sent: 07 October 2022 18:56 ... > > Given these kinds of less mechanical changes, it may make sense to split > > these from the "trivial" conversions in a treewide patch. The chance of > > needing a revert from the simple 1:1 conversions is much lower than the > > need to revert by-hand changes. > > > > The Cocci script I suggested in my v1 review gets 80% of the first > > patch, for example. > > I'll split things up into a mechanical step and a non-mechanical step. > Good idea. I'd also do something about the 'get_random_int() & 3' cases. (ie remainder by 2^n-1) These can be converted to 'get_random_u8() & 3' (etc). So they only need one random byte (not 4) and no multiply. Possibly something based on (the quickly typed, and not C): #define get_random_below(val) [ if (builtin_constant(val)) BUILD_BUG_ON(!val || val > 0x100000000ull) if (!(val & (val - 1)) { if (val <= 0x100) return get_random_u8() & (val - 1); if (val <= 0x10000) return get_random_u16() & (val - 1); return get_random_u32() & (val - 1); } } BUILD_BUG_ON(sizeof (val) > 4); return ((u64)get_random_u32() * val) >> 32; } get_random_below() is a much better name than prandom_u32_max(). David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales) _______________________________________________ linux-um mailing list linux-um@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-um