Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp1537615imw; Tue, 5 Jul 2022 11:08:06 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uRL2oSp1Zs53xja50zfHLGHLKUM/G8FKIXuEeHEFweZ+inVOBkN73C186JYH/zVLaRUW3o X-Received: by 2002:a63:86c6:0:b0:412:518a:8eef with SMTP id x189-20020a6386c6000000b00412518a8eefmr9314416pgd.298.1657044485820; Tue, 05 Jul 2022 11:08:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657044485; cv=none; d=google.com; s=arc-20160816; b=XYNpyktfmkIDBMsXUQx88FbefrYn5KrPa7/4Mhq8fJraAg0lG8Fq6QQhpBubQnirhc 4yMWeWSGxI/bnI0l/FMQmXeCeZdp6gow6YSX3jG39hB98f804lGMsohz+W3U/C2TtDSo 8majvVWioBPcryOOsEAp3VVQ/O8j7Ys1MMfVloqBqHltoVC+tlCkFSqog4dfFTPga6Ta FoaJroSd7PBFiKrCxsmgyiSsaLEf8n0UtgJbmVrxcc/72dei4agDF9cna6tANn0UEhmI hY6b4PqJ5arWZ5Iv3mAdSbUDwXfU5jEl4O6gHfKZWwgpaqyc4h7svtmwYvag5gH7lhLF 4qWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=xP6EvhJHSIVlx0Vjph8NPwyfuRz1b1SjJhWMAVht9Es=; b=dS6lW29LcRIAxF7Vb8dHCRMJ/v2i1rKDvwrgr2sqnNaC6zpUbdbPf0ZGQZkwqgkx8V PI2XeBPbg/DhlaFF29KbrF1qIMZMD4cqCdDuPWaZcegyGJla0a61ay+gv8sVMKP3U7Ob CmlbFYahmyHg2rToCRwgl3IBW4pqPRd3kOl7cJX/X18OmPLSKTe57imyb4n5hSzbG1cQ 6Nj4fSk6XTeeb8nRpMQ1iV5Wy/qczKIbXbAqolUuC8vT4QOmB+zr5Y8tTdafhmDcgcrH rkneZ3zp61vPjmHLVTMLb0jrLPjVOH3Dje0z92oxbwhUvAb8Oy7qrthz1dkepGSLBKyh 6JLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=KwKWNCZ4; 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 m21-20020a63f615000000b003fbd7285a83si43193137pgh.817.2022.07.05.11.07.42; Tue, 05 Jul 2022 11:08:05 -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=KwKWNCZ4; 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 S232869AbiGERrs (ORCPT + 99 others); Tue, 5 Jul 2022 13:47:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231867AbiGERrr (ORCPT ); Tue, 5 Jul 2022 13:47:47 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 818D91DA60; Tue, 5 Jul 2022 10:47:46 -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 265GoWNe027944; Tue, 5 Jul 2022 17:47:46 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : date : mime-version : subject : to : cc : references : from : in-reply-to : content-type : content-transfer-encoding; s=pp1; bh=xP6EvhJHSIVlx0Vjph8NPwyfuRz1b1SjJhWMAVht9Es=; b=KwKWNCZ4cSdVr1JWZHlmauZDPLcvrBv5R5vShYoaBoQkwpE7rO+t3DHZ4Cw6Cmzb/SJT 1zBhUwShOvTekmv5jVd64Y2AdRf3DDiC80tg2xRb5l6+vohN7cFWd4VuKauS8gqDoE71 JUKcfZlj/i1bB6Bgvy39pYFIPdE+Jnr4jDFhZJeuLrfAtvFG6chjtwOEJKrTkDN4E6PU GrIsfMqOqSUf47a+Bo+MXiV5BwCJs07hnX4AHAcdXCu/pB0f9i5EB6f5qluvFSONnOQ5 MaxNYBI6w9pgVa34fjXfA+UHMX4t5NQHWC4C/BdOvrlRxAMzpeyJee9oQBRiZH89YnJG qA== Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3h4s61sdwd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 05 Jul 2022 17:47:45 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 265HZYEl008267; Tue, 5 Jul 2022 17:47:43 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma03ams.nl.ibm.com with ESMTP id 3h2dn8vb2f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 05 Jul 2022 17:47:43 +0000 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 265Hleh710813896 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 5 Jul 2022 17:47:40 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 00D9042042; Tue, 5 Jul 2022 17:47:40 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8F4914203F; Tue, 5 Jul 2022 17:47:39 +0000 (GMT) Received: from [9.171.76.195] (unknown [9.171.76.195]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 5 Jul 2022 17:47:39 +0000 (GMT) Message-ID: <30e681b2-a411-cdb1-4b46-243db25abeef@linux.ibm.com> Date: Tue, 5 Jul 2022 19:47:37 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH v1 1/1] s390/arch_random: Buffer true random data Content-Language: en-US To: "Jason A. Donenfeld" Cc: Harald Freudenberger , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Juergen Christ , linux-crypto@vger.kernel.org, linux-s390@vger.kernel.org References: <20220705112712.4433-1-dengler@linux.ibm.com> <20220705112712.4433-2-dengler@linux.ibm.com> <9a0561c0-68f7-b630-4440-3ca32bf28dc2@linux.ibm.com> From: Holger Dengler In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: h8mwWmFMrB7huOB_h80MG51nvJxj6ORP X-Proofpoint-ORIG-GUID: h8mwWmFMrB7huOB_h80MG51nvJxj6ORP 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-05_14,2022-06-28_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 impostorscore=0 adultscore=0 mlxscore=0 phishscore=0 suspectscore=0 spamscore=0 bulkscore=0 lowpriorityscore=0 mlxlogscore=971 malwarescore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2207050076 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,NICE_REPLY_A,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 Hi Jason, On 05/07/2022 18:35, Jason A. Donenfeld wrote: > Hi Holger, > > On Tue, Jul 05, 2022 at 06:27:59PM +0200, Holger Dengler wrote: >> 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 thing to keep in mind is that it's used at boot time, when > technically IRQs are turned off, so it appears like interrupt context > depending on which way you squint. But boot time obviously isn't a > problem. So be sure that's not the usage you're seeing. Ok, let me check this. I will also think about the tree-wide cleanup you mentioned in an earlier mail. It looks, that s390 could fill the block.rdseed with a single call. >> 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. > > As a last ditch, maybe that's best. Maybe... Do you know off hand how > many cycles each call takes? I don't know the exact number of cycles, but as I mentioned in the coverletter, the trng instruction is one of the specialties of the s390 platform. It looks like an instruction, but it is some kind of firmware executed (it is called millicode). These kind of long-running instructions are also interruptable and can resume. A trng call runs for minimal ~20-190us for 32 bytes. 20us on newer machine generations, 190us on older ones. These are not 100% exact measurements, but the dimension should be correct. > >> 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()) { > > in_interrupt() is deprecated. You want in_hardirq() here. You'll also > want to verify that this doesn't prevent random_init() from working. > > Jason -- Mit freundlichen Grüßen / Kind regards Holger Dengler -- IBM Systems, Linux on IBM Z Development dengler@linux.ibm.com