Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp269604rwb; Tue, 25 Jul 2023 15:46:47 -0700 (PDT) X-Google-Smtp-Source: APBJJlElLCOLV6NLTnzyI9o+FwA1M38nib2J2lrpSO5GxmSRdhneqH8T3IowgbRQRkV7LSGo0lec X-Received: by 2002:a05:6a20:32aa:b0:127:3fea:500a with SMTP id g42-20020a056a2032aa00b001273fea500amr281692pzd.27.1690325207761; Tue, 25 Jul 2023 15:46:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690325207; cv=none; d=google.com; s=arc-20160816; b=JqxHvnBWAR/Uofar6ZekhhxE+RhCsbuFI0T9Nj5StoBhOtPkLKR8V5vFOIi0qpXFc2 f+cFfARjkXF31bv1q1jj8dRFmb5Z33hYgAQ5/7S/DDoTYMPGnZ2KU6Ozw3CguZFx3pmI 8etDN+2t344ce7kAF6Nx0sVQSXFLE9IHvRVI2I875hlo9WbemTzYf9mj1MTXu3d3/Kj3 a0mGUDT5/WLUJz+6SMrWIzjMY8OLIHK7jHM23XEC4m28yjECHbZzHWMxILMGOJmaF+h/ Ad12CCi8tcPvCWudY+F1imrfjL/6k4DG8LkXvvuqvwI4gi4PHRUunGjHBMBlXCAs7qQV TeSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=QajrGAGIi8bzVMzoLYoLHPdwyfy28zlzlG+Rc9yP1ZM=; fh=juxwNcA6iKwLISFgUCNwdoIYC0NKLUseq3xZdq25RR4=; b=lwg+1WrAyNqjBlthytkT2djE/FvjKqPeLJw4Wdf211gQx8vixfzyQqQa5yfSMHvqf9 ISjSiHE6Nb+jLeJPZbfSP1vlO1yOkWrBp3U2GwVUbQiALKZaJRyJgoa2/T+4j+N3pHtw uuQWrYG7jPSBnARoN6h+KSZEFg98KGCwLvVc3J5++5WnLKWa/Ie8adnZpxNNQOCQvAXP rYqx41p8hnklvPce6P6d4ObXSVdz8q66hBpjznsxRgtDo58pYz9Iokl+CalbFMaZFEtr 1BPOWEN3tBDgQ7CgY7g5vfiTfIltmzTUiPOxjfnUp0Jz/6ueYNDGvYeraIznXNKdWjTZ lZCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dKTqci6B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d15-20020a056a00244f00b00682ad3438besi12445394pfj.214.2023.07.25.15.46.36; Tue, 25 Jul 2023 15:46:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@intel.com header.s=Intel header.b=dKTqci6B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232014AbjGYWQi (ORCPT + 99 others); Tue, 25 Jul 2023 18:16:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231186AbjGYWPl (ORCPT ); Tue, 25 Jul 2023 18:15:41 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DF45E47; Tue, 25 Jul 2023 15:15:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690323340; x=1721859340; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MkHfcpMwySOcGOfR6N8gvbfjq2Uw4EljfqsyyqkNNzc=; b=dKTqci6BL8cNhhwZQ/dgGUETXmdI6CyBD8rkg3FyvTH4tCMryM/DC8Pv E8ztLwB+oZ1TR1gCF+FO2lWowcLHmcD3utvRvo71KTYwUIVXgimQK3abr dSu2WiRu5RFKzZ7VvEUMZvIIDBQOHUL8ffzKvcPTMAhfV84nGvNRI03UO X3oUAAPVJQzAU6YwtP6an+YxhJOmOmzfGxEfYo86bWhOlNu8nzEkZ0wPZ Cm8IS3V67SPEVvpXBYwiJFt3B/wmsE/KwoldvNRT/aSditNRWXRaH1PXb 8apzf1KxVb/Ds8C7xdexUPumm2xDsvdB9Nmmm0gIWc/vyWdJZnwrhT1+/ A==; X-IronPort-AV: E=McAfee;i="6600,9927,10782"; a="357863087" X-IronPort-AV: E=Sophos;i="6.01,231,1684825200"; d="scan'208";a="357863087" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jul 2023 15:15:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10782"; a="1056938803" X-IronPort-AV: E=Sophos;i="6.01,231,1684825200"; d="scan'208";a="1056938803" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jul 2023 15:15:19 -0700 From: isaku.yamahata@intel.com To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Paolo Bonzini , erdemaktas@google.com, Sean Christopherson , Sagi Shahar , David Matlack , Kai Huang , Zhi Wang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com Subject: [PATCH v15 012/115] KVM: TDX: Retry SEAMCALL on the lack of entropy error Date: Tue, 25 Jul 2023 15:13:23 -0700 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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-kernel@vger.kernel.org From: Isaku Yamahata Some SEAMCALL may return TDX_RND_NO_ENTROPY error when the entropy is lacking. Retry SEAMCALL on the error following rdrand_long() to retry RDRAND_RETRY_LOOPS times. Signed-off-by: Isaku Yamahata --- arch/x86/kvm/vmx/tdx_errno.h | 1 + arch/x86/kvm/vmx/tdx_ops.h | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/vmx/tdx_errno.h b/arch/x86/kvm/vmx/tdx_errno.h index 56cfd2f558fa..53dc14ba9107 100644 --- a/arch/x86/kvm/vmx/tdx_errno.h +++ b/arch/x86/kvm/vmx/tdx_errno.h @@ -14,6 +14,7 @@ #define TDX_INTERRUPTED_RESUMABLE 0x8000000300000000ULL #define TDX_OPERAND_INVALID 0xC000010000000000ULL #define TDX_OPERAND_BUSY 0x8000020000000000ULL +#define TDX_RND_NO_ENTROPY 0x8000020300000000ULL #define TDX_VCPU_NOT_ASSOCIATED 0x8000070200000000ULL #define TDX_KEY_GENERATION_FAILED 0x8000080000000000ULL #define TDX_KEY_STATE_INCORRECT 0xC000081100000000ULL diff --git a/arch/x86/kvm/vmx/tdx_ops.h b/arch/x86/kvm/vmx/tdx_ops.h index 76eddecdca12..d588a5507f5a 100644 --- a/arch/x86/kvm/vmx/tdx_ops.h +++ b/arch/x86/kvm/vmx/tdx_ops.h @@ -6,6 +6,7 @@ #include +#include #include #include #include @@ -17,9 +18,14 @@ static inline u64 tdx_seamcall(u64 op, u64 rcx, u64 rdx, u64 r8, u64 r9, struct tdx_module_output *out) { + int retry; u64 ret; - ret = __seamcall(op, rcx, rdx, r8, r9, out); + /* Mimic the existing rdrand_long() to retry RDRAND_RETRY_LOOPS times. */ + retry = RDRAND_RETRY_LOOPS; + do { + ret = __seamcall(op, rcx, rdx, r8, r9, out); + } while (unlikely(ret == TDX_RND_NO_ENTROPY) && --retry); if (unlikely(ret == TDX_SEAMCALL_UD)) { /* * SEAMCALLs fail with TDX_SEAMCALL_UD returned when VMX is off. -- 2.25.1