Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1093691rdb; Tue, 30 Jan 2024 07:44:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IHvzUEXHJYbTB7blBgmTAHAHXR92gq8UQTDHyA95gu4nI5LD/xjE5tXWk2MJ/YuBqI1pwFb X-Received: by 2002:a05:6214:2469:b0:685:6c2e:c86e with SMTP id im9-20020a056214246900b006856c2ec86emr1997195qvb.9.1706629491918; Tue, 30 Jan 2024 07:44:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706629491; cv=pass; d=google.com; s=arc-20160816; b=EPoGEZKVfFU83YSRye4jTQPlVrv/Ycdsbci/ThzvWIapLd0oYBpnu2WP1UKfOnLDgq u5cgGhifKPhv1TzZlTWsZwCu6c0gbcblbNvjA9FIBnjpWnJEg+Sr2U5G1NlbSVUDXKqS XlghGTF3otNYNZWwLgzNGN8nrJ3JeJRJwmBEC7P7c8eM6P2SqEc3uRROlELohEhDBwQ8 j9gzMM/eideS4gkbdyE+xC+2idadV//ZBq1h9UOIgcoqtg/Mdpi9+qL0dN1DmEZvYE47 zGRdpFdykd6D9Qgt4v0lKnKpEDwRX8SOfRk5ghT4yHDCop1xe9zNHrEFP5uIItGhIMY6 2fvw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=+ZS7yNvcEtfwoAXW5XDnmlreoqMG4v2JR5Qu+ZMcXnc=; fh=qF//TTtsqcyDaVt1QIk6ERa2vYI7s0ae5Pj/TFfLls0=; b=ZYA2al11xmzpWGqxX5yAfrNVxkOCKKRI/F+aGwf1ptdD/S/R2gu4MGO/UMAZODP4X1 1dmyk/5ZxpL9k+sgooYTCxFiHS0e7spfp9UEYYTeAu3eRR4ZjdYYjEeKKTOplsqVDs5s 3CKo+OYgohRWB8NYMrQsa394GHZ2AqkND3IRHMhc/e8NwBz5BFqwq1GsccXppQoBb6fE hwWuuonl1s+q96hTDxOJgNnAcGxR3jmLdNF1WHwcVF8OWZvd82udkKEir1kSI0k7kIhc PhRpX7gTKrgZXgmZZAnsseJoTRTyUbeuj1B1IzJIoNdRkobCrtOHBBJEWnm7OE0wCPEj WHCA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=EdlJKpyG; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-44864-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44864-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id a2-20020a05620a16c200b0077f69b7dbd2si5832817qkn.176.2024.01.30.07.44.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 07:44:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-44864-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=EdlJKpyG; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-44864-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44864-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 5CB501C23FD3 for ; Tue, 30 Jan 2024 15:44:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 93FC686129; Tue, 30 Jan 2024 15:44:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="EdlJKpyG" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 29F21823AA for ; Tue, 30 Jan 2024 15:44:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.11 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706629479; cv=none; b=O6P6vCD5YijUfWfU5tqh7KI3QIgAAF53WJ2gdYBUtg1+/7dt5qV4oPmOepTTPkuG1C4lsJMxEWkNjgd4wpwIx5WnHTUKiY4ZgTNPHjFaTeiiuTZZ+cS9+lBAtWDVK/9J399KRBM4EkEZ2blq2PiJj6XYs6B21vuXt0CO9Q20EbE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706629479; c=relaxed/simple; bh=H9m5L+gl6b+V+BQn2ouEpS21xEZtO77MxusqWCRPkaM=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=G+KYnghwau4hOiW2ezK8QqaM74aForTPVreOdRsN82DIw2abdZgxZ5XvPZmKF/fS9j2/f64mJdg3sY5paXB5wDrlehO8GWeN3KjmA8oIcC9Jyteds87ooS0tN72ozT4oCXvmgV7rb5CvNbY0qIzUnOrE5SVJRIiott5SELNMbL4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=EdlJKpyG; arc=none smtp.client-ip=192.198.163.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706629477; x=1738165477; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=H9m5L+gl6b+V+BQn2ouEpS21xEZtO77MxusqWCRPkaM=; b=EdlJKpyGfF4k8PVqe7dVLLIbXIkL30td6eV1oBQRKuYjUplI9aReL+a0 80GTlzvSg/tEnVJtet/msJTHB7YxCiFN7Fi6aB1emSx/jkYj5gt0tYpg0 O8ERZ+9xrNmpgSBlgkqAmDWcG7tJBhPtgdfAn9BUoOV1QDSEEB3UD7BV0 iLeFL8xl8snCdpswpNQd7TxML53IaXraxXzvvE6J7YWhS/VwRrkL8kmd1 RLv6NBRHYRoV4CafFwCXDPNneCz9i3co26rs9fiUiZmABb8BTFqnJLgoK P8z+XGE3PHiT0I9oLlRP4G5r/tdDcOlpfgxVjWpNa2tDcRQmmytA0omIo Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10969"; a="9984005" X-IronPort-AV: E=Sophos;i="6.05,230,1701158400"; d="scan'208";a="9984005" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jan 2024 07:44:36 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,230,1701158400"; d="scan'208";a="3751415" Received: from pangchin-mobl3.amr.corp.intel.com (HELO [10.209.54.246]) ([10.209.54.246]) by fmviesa003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jan 2024 07:44:35 -0800 Message-ID: <62c3cd00-d072-4daa-8e67-442d52325cde@linux.intel.com> Date: Tue, 30 Jan 2024 07:44:34 -0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/2] x86/random: Retry on RDSEED failure Content-Language: en-US To: "Kirill A. Shutemov" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , x86@kernel.org, Theodore Ts'o , "Jason A. Donenfeld" Cc: Elena Reshetova , Jun Nakajima , Tom Lendacky , "Kalra, Ashish" , Sean Christopherson , linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org References: <20240130083007.1876787-1-kirill.shutemov@linux.intel.com> From: Kuppuswamy Sathyanarayanan In-Reply-To: <20240130083007.1876787-1-kirill.shutemov@linux.intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 1/30/24 12:30 AM, Kirill A. Shutemov wrote: > The function rdrand_long() retries 10 times before returning failure to > the caller. On the other hand, rdseed_long() gives up on the first > failure. > > According to the Intel SDM, both instructions should follow the same > retry approach. This information can be found in the section titled > "Random Number Generator Instructions". > > To align the behavior of rdseed_long() with rdrand_long(), it should be > modified to retry 10 times before giving up. > > Signed-off-by: Kirill A. Shutemov > --- Change looks good to me. Reviewed-by: Kuppuswamy Sathyanarayanan Wondering whether this needs to go to stable trees? > arch/x86/include/asm/archrandom.h | 16 ++++++++++++---- > 1 file changed, 12 insertions(+), 4 deletions(-) > > diff --git a/arch/x86/include/asm/archrandom.h b/arch/x86/include/asm/archrandom.h > index 02bae8e0758b..918c5880de9e 100644 > --- a/arch/x86/include/asm/archrandom.h > +++ b/arch/x86/include/asm/archrandom.h > @@ -33,11 +33,19 @@ static inline bool __must_check rdrand_long(unsigned long *v) > > static inline bool __must_check rdseed_long(unsigned long *v) > { > + unsigned int retry = RDRAND_RETRY_LOOPS; > bool ok; > - asm volatile("rdseed %[out]" > - CC_SET(c) > - : CC_OUT(c) (ok), [out] "=r" (*v)); > - return ok; > + > + do { > + asm volatile("rdseed %[out]" > + CC_SET(c) > + : CC_OUT(c) (ok), [out] "=r" (*v)); > + > + if (ok) > + return true; > + } while (--retry); > + > + return false; > } > > /* -- Sathyanarayanan Kuppuswamy Linux Kernel Developer