Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2477558ybv; Fri, 21 Feb 2020 16:42:15 -0800 (PST) X-Google-Smtp-Source: APXvYqypFZq2juYoBkx8LWHcB6VHyd2+G7ijV1ZVMSl0x6kogLKtGBMRbEKaOctPK+XnfMapZf4f X-Received: by 2002:a05:6830:1498:: with SMTP id s24mr32659093otq.79.1582332135573; Fri, 21 Feb 2020 16:42:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582332135; cv=none; d=google.com; s=arc-20160816; b=bX7GmsGuqBjK+BQ6igZlGP3SDeUD5IpeLKIMXRuA0nmEU0NTImPyHtIli1zMwhDwGY lkFtkfar0aokfB7z+xlTrc/vq5B3pX5j++P05CLa3Bcf7+yxNvPtveXarEE/jHZ41Hcx OoVcdRB45J8Qxtl5FG5gXCptZXdrvKu1v7tqpQUU79Z8rg1LjqgnvpyJNqIOvPXXezFx /r2CI+euNurjSXjqDqMojv7mXsIK+w2wgRtkE24SagKjkdNtbOSlf9jQm/p6jyrs4tSg Eb2GwNX5igq5qf4PvJpf+mJxSxaAFqSGApkSELMMIvQ09MqAqdjM8r3OR44zPcSvqyuW +HOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=Fv0i3xh8mKcXZ58w/oX3tiv5rwMSGOD+e2G1GltWt0w=; b=ELv29FiOYW2QZ12Lxbzim4XlSd6DgJKxu6e3Kp0hgUWe0AwYY5wdy8iXFOfblJL4Ef 3cakUsuqHW5fKZiRmxfaVCp7jvIiEfUBZA7NDm7ESal6Id5eGf1jw1PIEQznkrLtEJLL a+xnGmFkfSF3lnLQHeomFXUE0bfcBF9LsicovIqCH2NKaKwagj5aVj6cdMGArisRAmMy LTUxeblM0BZbl0/xSdkXH2ImUGAHu+sNneRfvayjJbaAVegaWeNVGLlmRrgClPPFVGPC 45JqNhOi1Z+m24sJr3xU5DkFcTcFyMrYAgcTiFicOm7aDP4vQUmoQMgszpnMeJDiQobH 8uHw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l17si2331727otp.248.2020.02.21.16.42.03; Fri, 21 Feb 2020 16:42:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726943AbgBVAll (ORCPT + 99 others); Fri, 21 Feb 2020 19:41:41 -0500 Received: from outgoing-auth-1.mit.edu ([18.9.28.11]:58454 "EHLO outgoing.mit.edu" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726697AbgBVAlk (ORCPT ); Fri, 21 Feb 2020 19:41:40 -0500 Received: from callcc.thunk.org (guestnat-104-133-8-109.corp.google.com [104.133.8.109] (may be forged)) (authenticated bits=0) (User authenticated as tytso@ATHENA.MIT.EDU) by outgoing.mit.edu (8.14.7/8.12.4) with ESMTP id 01M0fXsg017796 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Feb 2020 19:41:35 -0500 Received: by callcc.thunk.org (Postfix, from userid 15806) id 7717F4211EF; Fri, 21 Feb 2020 19:41:33 -0500 (EST) Date: Fri, 21 Feb 2020 19:41:33 -0500 From: "Theodore Y. Ts'o" To: "Jason A. Donenfeld" Cc: Tony Luck , Greg Kroah-Hartman , Linux Kernel Mailing List Subject: Re: [PATCH] random: always use batched entropy for get_random_u{32,64} Message-ID: <20200222004133.GC873427@mit.edu> References: <20200216161836.1976-1-Jason@zx2c4.com> <20200216182319.GA54139@kroah.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 21, 2020 at 09:08:19PM +0100, Jason A. Donenfeld wrote: > On Thu, Feb 20, 2020 at 11:29 PM Tony Luck wrote: > > > > Also ... what's the deal with a spin_lock on a per-cpu structure? > > > > batch = raw_cpu_ptr(&batched_entropy_u64); > > spin_lock_irqsave(&batch->batch_lock, flags); > > if (batch->position % ARRAY_SIZE(batch->entropy_u64) == 0) { > > extract_crng((u8 *)batch->entropy_u64); > > batch->position = 0; > > } > > ret = batch->entropy_u64[batch->position++]; > > spin_unlock_irqrestore(&batch->batch_lock, flags); > > > > Could we just disable interrupts and pre-emption around the entropy extraction? > > Probably, yes... We can address this in a separate patch. No, we can't; take a look at invalidate_batched_entropy(), where we need invalidate all of per-cpu batched entropy from a single CPU after we have initialized the the CRNG. Since most of the time after CRNG initialization, the spinlock for each CPU will be on that CPU's cacheline, the time to take and release the spinlock is not going to be material. - Ted