Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2618046rdg; Mon, 16 Oct 2023 09:31:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFCbEVz282qfy7Jx5WHhGy9YqDeTEVN7Vce5KbRfkcQzs7bR4qY4pbQ715TNzNEQhNWHCyS X-Received: by 2002:a05:6512:2392:b0:503:3707:66ed with SMTP id c18-20020a056512239200b00503370766edmr38663660lfv.34.1697473896845; Mon, 16 Oct 2023 09:31:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697473896; cv=none; d=google.com; s=arc-20160816; b=MnF+Ki4lcuwRg1czJaj/rq4D6tuFO2ejyP206OXkfOnrAdQf2pGBJ8/VF2xc8QlI2C 71lPpQsEDQzMc935QYqe75uheKcovt+7A7Ipa6pfaajR9z0JpIX9D4gXG8SbMYHpCMZS bwg0CPMKaXtsG/+0FXg4zneldBbAo4OCxanf6eG2et2+gg3flkup4t84pVRb5TOPWJiN R5t/qNpar43IH3WgWaWPAtl9fLdW4swhaH4jcygJk0s5RBZR2rRuc+vtz/i72fdYBX1Z x/Fmw2872qksY1sbdEXVXRVGkUrZ1fqYejGi5632IKFJUeyCwdpnPg25wr/OobIxuB9p ZISQ== 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=exDHUPYsB/yGrZyyQtUzxu8mmUDsfEj1PShsaOTuBcU=; fh=lRdU2Q/1zx5DcPdZuWBjshA5VT5Oc9cEhB1tCFiV0Nw=; b=poVpuIxPN6iEJMDQnPU9teOfesh/i1NBL387sTkUnSYiWS/9YX395sTaoOszlHvu0/ DHUdq7apw1DFYCmT5amdDa0WGr9j3n+OfmiBOa0pvF0gA50iK/rQUI9i19YjCEEvkOlF RjShwqTsa7cqdCrt+xI7snGg5Vc80+QPFT4U60iqzZGI8Qr9RhTl143g5YhpVZWQ2+0G H3sE2aSkaQ9oEYQpVaGHn6TWXVJoflOYEUbCK0+PMsuLuel3TivegcATQx6VTNhZNnUE I9kFQ3G2KC0/m0gj5bQrqPfc9o8QlYxWga0nvAFvF+RVz51xbmSqhFKybAJZUMMOyPyG rWEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Gru45sM4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id t9-20020a192d49000000b00507991efe7bsi120910lft.292.2023.10.16.09.31.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 09:31:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Gru45sM4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 80A56807E460; Mon, 16 Oct 2023 09:31:24 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233501AbjJPQaz (ORCPT + 99 others); Mon, 16 Oct 2023 12:30:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232473AbjJPQax (ORCPT ); Mon, 16 Oct 2023 12:30:53 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04D594ECD; Mon, 16 Oct 2023 09:21:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697473272; x=1729009272; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vpXCmlD0snO0WBWWUvJdVYMn9hwOmcv8k5zeczxfXWo=; b=Gru45sM4+ABG8aR2h7PXmFd0FW8lOsbinTa1gkMJTkoTicDKBtprnsmC YrTyBShemzJyN+koxyorvt6ty7Se7lRPJVnWPAe8rpUrW6MF3kA/MgYGV 8hzovgnhodCTXRfJ7lUO2IiDT6DJXS9GFk9TlmC4SehSe0CtSW3zKk9A2 SJ5De1kQXOq2XIl6cLOBHktPmlugQQSjuoAyang50INbiw9JNaUUr7ElW YfRhfeE7cKlj135wY78gJW0h8ia32Q0S1mmEIdQdGBes4kXGGOXUma6ux e+7/vnk6JvN1WRlh4dh70KUdWvnOV/tOZfFgyGkje7ISknLcelpSBaXkr g==; X-IronPort-AV: E=McAfee;i="6600,9927,10865"; a="365825919" X-IronPort-AV: E=Sophos;i="6.03,229,1694761200"; d="scan'208";a="365825919" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2023 09:15:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10865"; a="1087126000" X-IronPort-AV: E=Sophos;i="6.03,229,1694761200"; d="scan'208";a="1087126000" 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; 16 Oct 2023 09:15:26 -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 v16 012/116] KVM: TDX: Retry SEAMCALL on the lack of entropy error Date: Mon, 16 Oct 2023 09:13:24 -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=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Mon, 16 Oct 2023 09:31:24 -0700 (PDT) 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 | 40 +++++++++++++++++++++--------------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/arch/x86/kvm/vmx/tdx_errno.h b/arch/x86/kvm/vmx/tdx_errno.h index ec76740dc6a1..dbee050b2356 100644 --- a/arch/x86/kvm/vmx/tdx_errno.h +++ b/arch/x86/kvm/vmx/tdx_errno.h @@ -14,6 +14,7 @@ #define TDX_OPERAND_INVALID 0xC000010000000000ULL #define TDX_OPERAND_BUSY 0x8000020000000000ULL #define TDX_PREVIOUS_TLB_EPOCH_BUSY 0x8000020100000000ULL +#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 12fd6b8d49e0..a55977626ae3 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,25 +18,30 @@ static inline u64 tdx_seamcall(u64 op, u64 rcx, u64 rdx, u64 r8, u64 r9, struct tdx_module_args *out) { + int retry; u64 ret; - if (out) { - *out = (struct tdx_module_args) { - .rcx = rcx, - .rdx = rdx, - .r8 = r8, - .r9 = r9, - }; - ret = __seamcall_ret(op, out); - } else { - struct tdx_module_args args = { - .rcx = rcx, - .rdx = rdx, - .r8 = r8, - .r9 = r9, - }; - ret = __seamcall(op, &args); - } + /* Mimic the existing rdrand_long() to retry RDRAND_RETRY_LOOPS times. */ + retry = RDRAND_RETRY_LOOPS; + do { + if (out) { + *out = (struct tdx_module_args) { + .rcx = rcx, + .rdx = rdx, + .r8 = r8, + .r9 = r9, + }; + ret = __seamcall_ret(op, out); + } else { + struct tdx_module_args args = { + .rcx = rcx, + .rdx = rdx, + .r8 = r8, + .r9 = r9, + }; + ret = __seamcall(op, &args); + } + } 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