Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp2665492imw; Wed, 6 Jul 2022 09:39:43 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uOWSRz15ZWq5znIuoxLLHx6OlE24flqsKn9fi9/KS6D7CeIrhzBVMjXcu6KcpP8qlsSh2B X-Received: by 2002:a17:906:cc96:b0:728:baf0:ba03 with SMTP id oq22-20020a170906cc9600b00728baf0ba03mr39364902ejb.52.1657125583152; Wed, 06 Jul 2022 09:39:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657125583; cv=none; d=google.com; s=arc-20160816; b=KJDWwNKgI8PTjbZhSoEeArSjVwoyeRKSvx8D7kO//wunBEKhMJ6K6XZXLTiv9Wr347 RmPc9LTbm5jsFbBqCAAmuI6Kw2avL3j5Ls0CTBoESELNbLhmrDwKiBP2Kn5fqCP6l2ph F8fhIRWYcDVCm0dsAdMO+wtD4Ncsl51yjwwPLjhfNaMXlgHBYUQw0sf1B/dUagG+i10i WgtHWIDvEGh49lvYHOpenwm5MRLurO3QVhMoa4lciDbeV7uBWv+5KCjs6YLzPoxFrJtH ClFntefnul+1al1vYo3vuzra9f+OqrKZ+j4F4/F24FKoZwlhJ7M9qK7CkdX3PyXGtUke cpAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:message-id:user-agent :references:in-reply-to:reply-to:subject:cc:to:from:date :mime-version:dkim-signature; bh=ATG1fi8yFZlnZlKbbnantI0OIyJL3cLAzEGjwRRJQE0=; b=F8Bu+wqKsVR5TLtXLgASgeO2kulhFGjy5yXj3iH3kk6INnpYmy7ZNwAPyRZJ8/S/KT fh/4h4Mp2rjPsm/B3m5CL164A/7kkeiOk3btjP8WSOfgMJdHRKjRHn2TgrIRozeBg3pt SjtZ/mWa9yQbWU3h8LE5oOEl/5x5aU/cUVRdm5NkRiK8VLr6UlmZRBf4bBNwyG5Y/Rsn zCeFg+/WEV0nhzDXIoSD9aqkm94skY4L0/f0M28Dlyx5D2mJFA28ltWMRmBmeIRm8zKM F1wI9ZNqij82kn+EV7qcd4vtCv5tFP1vi1a4y310RSB3dBCq6whJJkTB5yev+f4q2rZe dX5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=jCc8CNjS; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ec2-20020a170906b6c200b00711c9e20c40si2166776ejb.243.2022.07.06.09.39.09; Wed, 06 Jul 2022 09:39:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=jCc8CNjS; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234571AbiGFQSh (ORCPT + 99 others); Wed, 6 Jul 2022 12:18:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232948AbiGFQSd (ORCPT ); Wed, 6 Jul 2022 12:18:33 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B652165D1; Wed, 6 Jul 2022 09:18:30 -0700 (PDT) Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 266G5upj017500; Wed, 6 Jul 2022 16:18:30 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=mime-version : date : from : to : cc : subject : reply-to : in-reply-to : references : message-id : content-type : content-transfer-encoding; s=pp1; bh=ATG1fi8yFZlnZlKbbnantI0OIyJL3cLAzEGjwRRJQE0=; b=jCc8CNjSuUB9J9M3bJnJ10UkN7h5oAQNR318pVUbzZuBjPxrZjvfFKF+LG2P1dFXt/Gs XF0Reh+OVWNHCL6fwqbw+WlMjvxBKsRUi13um3lY8m5j9iiCxsU+fuXlTaL9cq42ICkc UiwKk1/8N4rZR2YNDAfSNW4cCe4fyWZFNxYogSHRaokSBYxJkVHEbafXysVOwYIlmajp LwFS6V9jRE110J5G6Z7BYkXzvxhLKjdJxCABRBMknO6/Uee5woWdivmx+s87fCQZ/H65 2C/sgIn6mmiAnpP1P6ZzYm3Y0wfwxSVG6NQzaXMZ3TrE6JSU/Cb3faPMbl6tuoL0GicU aA== Received: from ppma01wdc.us.ibm.com (fd.55.37a9.ip4.static.sl-reverse.com [169.55.85.253]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3h5844jk49-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Jul 2022 16:18:29 +0000 Received: from pps.filterd (ppma01wdc.us.ibm.com [127.0.0.1]) by ppma01wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 266G5NiA020192; Wed, 6 Jul 2022 16:18:28 GMT Received: from b01cxnp22034.gho.pok.ibm.com (b01cxnp22034.gho.pok.ibm.com [9.57.198.24]) by ppma01wdc.us.ibm.com with ESMTP id 3h4ud1nhwk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Jul 2022 16:18:28 +0000 Received: from b01ledav001.gho.pok.ibm.com (b01ledav001.gho.pok.ibm.com [9.57.199.106]) by b01cxnp22034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 266GIS0E46137608 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 6 Jul 2022 16:18:28 GMT Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1846A2805A; Wed, 6 Jul 2022 16:18:28 +0000 (GMT) Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A5BFA28058; Wed, 6 Jul 2022 16:18:27 +0000 (GMT) Received: from ltc.linux.ibm.com (unknown [9.10.229.42]) by b01ledav001.gho.pok.ibm.com (Postfix) with ESMTP; Wed, 6 Jul 2022 16:18:27 +0000 (GMT) MIME-Version: 1.0 Date: Wed, 06 Jul 2022 18:18:27 +0200 From: Harald Freudenberger To: Holger Dengler , Jason@zx2c4.com Cc: Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Juergen Christ , linux-crypto@vger.kernel.org, linux-s390@vger.kernel.org Subject: Re: [PATCH v1 1/1] s390/arch_random: Buffer true random data Reply-To: freude@linux.ibm.com In-Reply-To: References: <20220705112712.4433-1-dengler@linux.ibm.com> <20220705112712.4433-2-dengler@linux.ibm.com> <9a0561c0-68f7-b630-4440-3ca32bf28dc2@linux.ibm.com> User-Agent: Roundcube Webmail/1.4.13 Message-ID: <7e65130c6e66ce7a9f9eb469eb7e64e0@linux.ibm.com> X-Sender: freude@linux.ibm.com Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: vxrZlVQP750xsGy5PQ0kewc6HzhruI3e X-Proofpoint-ORIG-GUID: vxrZlVQP750xsGy5PQ0kewc6HzhruI3e X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-07-06_09,2022-06-28_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1011 priorityscore=1501 lowpriorityscore=0 phishscore=0 suspectscore=0 impostorscore=0 adultscore=0 mlxlogscore=777 spamscore=0 mlxscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2206140000 definitions=main-2207060064 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On 2022-07-05 18:27, Holger Dengler wrote: > Hi Jason, > > On 05/07/2022 17:11, Jason A. Donenfeld wrote: >> Hi Holger, >> >> On Tue, Jul 05, 2022 at 04:58:30PM +0200, Holger Dengler wrote: >>> It is true, that the performance of the instruction is not really >>> relevant, but only for calls outside of an interrupt context. I did >>> some ftrace logging for the s390_random_get_seed_long() calls, and - >>> as you said - there are a few calls per minute. But there was also >>> some repeating calls in interrupt context. On systems with a huge >>> interrupt load, this can cause severe performance impacts. I've no >> >> It'd be interesting to know more about this. The way you get >> arch_random_get_seed_long() from irq context is: >> >> get_random_{bytes,int,long,u32,u64}() >> crng_make_state() >> crng_reseed() <-- Rarely >> extract_entropy() >> arch_get_random_seed_long() >> >> So if an irq user of get_random_xx() is the unlucky one in the minute >> span who has to call crng_reseed() then, yea, that'll happen. But I >> wonder about this luck aspect. What scenarios are you seeing where >> this >> happens all the time? Which driver is using random bytes *so* commonly >> from irq context? Not that, per say, there's anything wrong with that, >> but it could be eyebrow raising, and might point to de facto solutions >> that mostly take care of this. > > I saw a few calls in interrupt context during my tracing, but I didn't > look to see which ones they were. Let me figure that out in the next > few days and provide more information on that. > >> One such direction might be making a driver that does such a thing do >> it >> a little bit less, somehow. Another direction would be preferring >> non-irqs to handle crng_reseed(), but not disallowing irqs entirely, >> with a patch something like the one below. Or maybe there are other >> ideas. > > Reduce the number of trng in interrupt context is a possibility, but - > in my opinion - only one single trng instruction call in interrupt > context in one too much. > > For the moment, I would propose to drop the buffering but also return > false, if arch_random_get_seed_long() is called in interrupt context. > > diff --git a/arch/s390/include/asm/archrandom.h > b/arch/s390/include/asm/archrandom.h > index 2c6e1c6ecbe7..711357bdc464 100644 > --- a/arch/s390/include/asm/archrandom.h > +++ b/arch/s390/include/asm/archrandom.h > @@ -32,7 +32,8 @@ static inline bool __must_check > arch_get_random_int(unsigned int *v) > > static inline bool __must_check arch_get_random_seed_long(unsigned > long *v) > { > - if (static_branch_likely(&s390_arch_random_available)) { > + if (static_branch_likely(&s390_arch_random_available) && > + !in_interrupt()) { > cpacf_trng(NULL, 0, (u8 *)v, sizeof(*v)); > atomic64_add(sizeof(*v), &s390_arch_random_counter); > return true; > > (on-top of your commit, without our buffering patch) > >> >> But all this is to say that having some more of the "mundane" details >> about this might actually help us. >> >> Jason >> >> diff --git a/drivers/char/random.c b/drivers/char/random.c >> index e3dd1dd3dd22..81df8cdf2a62 100644 >> --- a/drivers/char/random.c >> +++ b/drivers/char/random.c >> @@ -270,6 +270,9 @@ static bool crng_has_old_seed(void) >> static bool early_boot = true; >> unsigned long interval = CRNG_RESEED_INTERVAL; >> >> + if (in_hardirq()) >> + interval += HZ * 10; >> + >> if (unlikely(READ_ONCE(early_boot))) { >> time64_t uptime = ktime_get_seconds(); >> if (uptime >= CRNG_RESEED_INTERVAL / HZ * 2) >> Hi Holger and Jason I tried to find out what is the reason of the invocations in interrupt context. First I have to admit that there is in fact not much of arch_get_random_seed_long() invocation any more in the recent kernel (5.19-rc5). I see about 100 invocations within 10 minutes with an LPAR running some qperf and dd dumps on dasds test load. About half of these invocations is in interrupt context. I dump_stack()ed some of these and I always catch the function kfence_guarded_alloc() prandom_u32_max() prandom_u32() get_random_u32() _get_random_bytes() crng_make_state() crng_reseed() extract_entropy() arch_get_random_seed_long() However, with so few invocations it should not make any harm when there is a even very expensive trng() invocation in interrupt context. But I think we should check, if this is really something to backport to the older kernels where arch_get_random_seed_long() is called really frequency. Harald Freudenberger