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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1868FC433EF for ; Mon, 25 Jul 2022 09:28:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=zcyt6RlUKO27/wKxLqMt1H3y/PBiVAqF67X9kdRqUlQ=; b=4YwL4yWQqr0Q06 lPNm/XEUECcGGRtOFFuEsdsQD0H51tsOQsggjWUS6kd23YV7zEKgELQXDkFjuXP9bTPdSV21DVnnL HZcfwqOyuvEUOQmaVY9cqwfLpmTyKDtdWSBwZa6sgMS63PAR5w6UP1PkeBDTR6a3SnqgTtuG+EKgp YXcbZYOYMQIyjW5vTY0Eic5xQqCnSDVmokD0ghzA5Lg+rJ8FHfI5Pao+/a2Q9p684bsWDQrwqYYe3 tGiaOQb40YMQxiebMYlpih8Oms0034VTUAf7yTsKBV7MwVbxvPfeZ5ji5TkqCcL0A35aw3XV5VHJ8 rx3I06enkjwRYM0rWovA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oFuMQ-007YBc-Hu; Mon, 25 Jul 2022 09:26:47 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oFuMI-007Y4m-0N for linux-arm-kernel@lists.infradead.org; Mon, 25 Jul 2022 09:26:40 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 04006B80E1A; Mon, 25 Jul 2022 09:26:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF553C341D2; Mon, 25 Jul 2022 09:26:32 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="LZX4uVNM" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1658741191; 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: in-reply-to:in-reply-to:references:references; bh=zvNrHbTIYzgB0tkOGhVVxAdAHnHebTQeizi3weVIsK0=; b=LZX4uVNMACi/jB4HVvKJPq0/mnjxBgfqakoAfLysChDi3HgisD6QaHOYw75ZyyrX1xLahm XBKjHTCSVOHHHqTDjtlokbIDkMCdeoLQsma7KWe93PAIV8RSzydcGwPf7ehG3FWP89FhMN /bS3mQsDtxO03rpH0kQYPGkVIqqeD5I= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id d5a3a065 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Mon, 25 Jul 2022 09:26:30 +0000 (UTC) Date: Mon, 25 Jul 2022 11:26:27 +0200 From: "Jason A. Donenfeld" To: Borislav Petkov Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, x86@kernel.org, Will Deacon , Alexander Gordeev , Thomas Gleixner , "H . Peter Anvin" , Catalin Marinas , Heiko Carstens , Johannes Berg , Mark Rutland , Harald Freudenberger , Michael Ellerman Subject: Re: [PATCH v3] random: handle archrandom with multiple longs Message-ID: References: <20220719130207.147536-1-Jason@zx2c4.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220725_022638_640553_5D6C6DF2 X-CRM114-Status: GOOD ( 23.46 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list 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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Boris, On Mon, Jul 25, 2022 at 11:19:01AM +0200, Borislav Petkov wrote: > On Tue, Jul 19, 2022 at 03:02:07PM +0200, Jason A. Donenfeld wrote: > > Since callers need to check this return value and loop anyway, each arch > > implementation does not bother implementing its own loop to try again to > > fill the maximum number of longs. Additionally, all existing callers > > pass in a constant max_longs parameter. > > Hmm, maybe this has come up already but it reads weird. > > If I have a function arch_get_random_longs(), I'd expect it to give me > the number of longs I requested or say, error. > > Why do the callers need to loop? > > If I have to loop, I'd call the "get me one long" function and loop N > times. Answered partially in the commit message you quoted and partially here: https://lore.kernel.org/lkml/YtqIbrds53EuyqPE@zx2c4.com/ Note that arch_get_random_longs() is not a general purpose function. For that there used to be get_random_bytes_arch(), but that no longer exists as people shouldn't be using this stuff directly. arch_get_random_longs() is a special purpose function mainly intended for use by the RNG itself. More directly, the reason we don't want to error is because the use case has fallbacks meant to handle errors. The cascade looks like this (quoting from the other email): unsigned long array[whatever]; for (i = 0; i < ARRAY_SIZE(array);) { longs = arch_get_random_seed_longs(&array[i], ARRAY_SIZE(array) - i); if (longs) { i += longs; continue; } longs = arch_get_random_longs(&array[i], ARRAY_SIZE(array) - i); if (longs) { i += longs; continue; } array[i++] = random_get_entropy(); } It tries to get the best that it can as much as it can, but isn't going to block or do anything too nuts for that. Anyway, from an x86 perspective, I can't imagine you object to this change, right? Codegen is the same. Jason _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel