From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) (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 BDAB826AC2 for ; Tue, 30 Jan 2024 08:30:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=134.134.136.31 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706603457; cv=none; b=fDsj2b9F+h9cghXFN4dEvhHOHQSepi48uAGznjRo1l26+fjcsBvMo75gjmM4fJ3rUml5yz2BKUjuzbKYXmXKIyqCwIbNeq5BJlCFQPkMvwOBa61ffcGaoHDgVgqcRmPS1hW8zdA/1Nlwm6D/TFV5jblwRD62fMzGs+GJcqQ5088= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706603457; c=relaxed/simple; bh=AwZwJ5cYVLV4jd8F8avXy7jN4r8TxDP5NN7KpZbNqJY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fBmjpzqhXqs4epO11fEDnsM6btXo3Ph/FAtTZ3F0nAoqnkGWIPIySRICAakRsI50IotJMKbRqoAH0V8Yyh7YXi4d2Xk8rI32KoCCPXSEwVM+HzdSYsNSTdzQT7KlfrvIiPKYrWV1xBhUetfn3Wp7q8s94n7kqtjy7gqVe572cK8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.helo=mgamail.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=TNME18jA; arc=none smtp.client-ip=134.134.136.31 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.helo=mgamail.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="TNME18jA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706603455; x=1738139455; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AwZwJ5cYVLV4jd8F8avXy7jN4r8TxDP5NN7KpZbNqJY=; b=TNME18jATKnZBMKyxYHwkR7Y/H06oinPcSuEtyjCzxYuScMTBO1cEQfQ AnLBb/JGfqas6gAMN0DCjkfnR+dbRSiyLkaB3TRtdthL87NgCPXICG4e1 YE2dxl1gwOXsetIKTlYkTY/eIXucdOeqHHYnctpu/CLOhgkP2pXCBubR/ /N9ERVF9Q+HOm1n9fy2/rmQpHiz+1LY0GH3+M3QYgAFpKAt/6Z8ZS3ODC F5cI4LLIWqj93nAEjT+TVMlVDdpw5wMGNTClauYcFb+Qxpq1aTwcBCgFW KkuHEhVYi7SgAqACIs8awSP34+QeIi8uwAy72Ed4ITvGLi81LMjZYJl8U w==; X-IronPort-AV: E=McAfee;i="6600,9927,10968"; a="467464335" X-IronPort-AV: E=Sophos;i="6.05,707,1701158400"; d="scan'208";a="467464335" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jan 2024 00:30:18 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10968"; a="822120353" X-IronPort-AV: E=Sophos;i="6.05,707,1701158400"; d="scan'208";a="822120353" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga001.jf.intel.com with ESMTP; 30 Jan 2024 00:30:13 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 81FFBB8; Tue, 30 Jan 2024 10:30:12 +0200 (EET) From: "Kirill A. Shutemov" To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , x86@kernel.org, "Theodore Ts'o" , "Jason A. Donenfeld" Cc: Kuppuswamy Sathyanarayanan , Elena Reshetova , Jun Nakajima , Tom Lendacky , "Kalra, Ashish" , Sean Christopherson , linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [PATCH 2/2] x86/random: Issue a warning if RDRAND or RDSEED fails Date: Tue, 30 Jan 2024 10:30:07 +0200 Message-ID: <20240130083007.1876787-2-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240130083007.1876787-1-kirill.shutemov@linux.intel.com> References: <20240130083007.1876787-1-kirill.shutemov@linux.intel.com> Precedence: bulk X-Mailing-List: linux-coco@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit RDRAND and RDSEED instructions rarely fail. Ten retries should be sufficient to account for occasional failures. If the instruction fails more than ten times, it is likely that the hardware is broken or someone is attempting to exceed the rate at which the random number generator hardware can provide random numbers. Issue a warning if ten retries were not enough. Signed-off-by: Kirill A. Shutemov --- arch/x86/include/asm/archrandom.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/arch/x86/include/asm/archrandom.h b/arch/x86/include/asm/archrandom.h index 918c5880de9e..fc8d837fb3b9 100644 --- a/arch/x86/include/asm/archrandom.h +++ b/arch/x86/include/asm/archrandom.h @@ -13,6 +13,12 @@ #include #include +#ifdef KASLR_COMPRESSED_BOOT +#define rd_warn(msg) warn(msg) +#else +#define rd_warn(msg) WARN_ONCE(1, msg) +#endif + #define RDRAND_RETRY_LOOPS 10 /* Unconditional execution of RDRAND and RDSEED */ @@ -28,6 +34,9 @@ static inline bool __must_check rdrand_long(unsigned long *v) if (ok) return true; } while (--retry); + + rd_warn("RDRAND failed\n"); + return false; } @@ -45,6 +54,8 @@ static inline bool __must_check rdseed_long(unsigned long *v) return true; } while (--retry); + rd_warn("RDSEED failed\n"); + return false; } -- 2.43.0