From patchwork Fri Dec 8 17:17:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 175968 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp5599003vqy; Fri, 8 Dec 2023 09:18:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IGLRgLxuJf6xLFcUN1GcS9VZUOK8lFNpsWjsKne+q6Wn/Zre8rNrUwWkOPuOW/MQvYyMX7j X-Received: by 2002:a05:6a20:7d89:b0:190:4b78:99b1 with SMTP id v9-20020a056a207d8900b001904b7899b1mr484475pzj.42.1702055933394; Fri, 08 Dec 2023 09:18:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702055933; cv=none; d=google.com; s=arc-20160816; b=akRunkA4oLj5rPc8O8joB9kZPfLLbIyCqOk8p3Gas/lThMc1APXqmEhanzJTI72qp/ 74MupL8i6h0VrjAAjVjeRTLqn8urocg1wd9Abp/pDL5cGStfASoA1x7u0T98iaNrlHDI XwH9MMtJQ7xtBx25pf4lSSAMjvq5zf4GiWaIpgdr9g+7FjpVp5F//NYxjhDmOuDKZzsj SwUeuKaTF7AoKvqDKo0IYwVmX8ULzLLvkjKlifKg/EAC0tL60iyQmMYOrvHMblncfy0b l/1Ym2ptgyEM5yPCePSoPCIlKg6bcuNhplE5Zv88ufEC0vvNbc/PpOvjBOxvwXRSgQjF /zLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:cc:subject:to:reply-to:sender:from :dkim-signature:dkim-signature:date; bh=Eiuzu+kdXHQQeo0yh16f9Iu6ApXODrsdCTQclFbsApY=; fh=QKoalajLeOVNmJcto7pIRRSy5AgPQphJ9zJ7MpYaYuU=; b=V9IKtxyLdPGHAHSyuyxWSVrzmjZmxdDW0/WUVXrjJswuIqqapk6weaWrtf4GRP9IVp NnGfkVmnKUzbQ7GYb4akSfjMhjeZFe2v/mtkJ53rY4W01HRbSP5N2TYWtgeIYDUe5RYz nQ2NLXb7MHck3P8TxQyh5KREFMi0DQqA39JzteXMSMKPHnbIxVA7jIamx1ShLGI9Lhnf pX8ftEjuz/KcNgf+Yw4b+Rggtc6utJXpUfeY2NEph3K0z+5ul5Wq6gorGggJrwsFWN0L TsjJLYTWPIKJG9XiiJAL5nsvQeD+UgdGNK94V8xmyNAooyJIR+vLXNnugdlBJ/l0pfLk hbsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=oh0SjXkp; dkim=neutral (no key) header.i=@linutronix.de header.b=08Wph+eB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id y184-20020a638ac1000000b005b92a7d88e6si1784421pgd.823.2023.12.08.09.18.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 09:18:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=oh0SjXkp; dkim=neutral (no key) header.i=@linutronix.de header.b=08Wph+eB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 8A85B81C0C8E; Fri, 8 Dec 2023 09:18:38 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1574507AbjLHRSL (ORCPT + 99 others); Fri, 8 Dec 2023 12:18:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235950AbjLHRSB (ORCPT ); Fri, 8 Dec 2023 12:18:01 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF15119B4; Fri, 8 Dec 2023 09:17:30 -0800 (PST) Date: Fri, 08 Dec 2023 17:17:28 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1702055849; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Eiuzu+kdXHQQeo0yh16f9Iu6ApXODrsdCTQclFbsApY=; b=oh0SjXkpYyoKRDqiD3sc56TSeqe29yhprZ4neb8sNGb2/DMH3M2KuxCOMaoNST+aI70FrP V6FNVMmpXOh9r6SrH6oytTo7TSlrxtjR45xMYz+VV4Futg//SLuk2Waxq4sKbAPLFd2qFG 9K10mnOQgFkafnGfVrgjPsKkQAVSoheV3uVWEa6sw6IBbcNMvd9NPZBQlVs8BJhXpsx/Z+ M5KY7BtSWa6OkQri2PPIV7ZeESN0HD2/6xlBpbqVIoIyrLWo7+X7odylbagkzQahrip/kI rUAduJCv8Q1q/iTa9dvmaZUFhoUgF8nfsfYkke/OhO3m53YSz5UO4C47yh9Jiw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1702055849; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Eiuzu+kdXHQQeo0yh16f9Iu6ApXODrsdCTQclFbsApY=; b=08Wph+eB1eq063sqmljbgkEEngPYi0R198o8sHQF5ti1/IWt0/wKFK5QNkvJlRdE5UW60q YZc5hyaZbjtzz3DA== From: "tip-bot2 for Kai Huang" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/tdx] x86/virt/tdx: Handle SEAMCALL no entropy error in common code Cc: Kai Huang , Dave Hansen , "Kirill A. Shutemov" , Kuppuswamy Sathyanarayanan , x86@kernel.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Message-ID: <170205584844.398.11207047321106370195.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Fri, 08 Dec 2023 09:18:38 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784735002047126467 X-GMAIL-MSGID: 1784735002047126467 The following commit has been merged into the x86/tdx branch of tip: Commit-ID: 1e66a7e275393055d98d2306771fe1feadeb1cd6 Gitweb: https://git.kernel.org/tip/1e66a7e275393055d98d2306771fe1feadeb1cd6 Author: Kai Huang AuthorDate: Fri, 08 Dec 2023 09:07:24 -08:00 Committer: Dave Hansen CommitterDate: Fri, 08 Dec 2023 09:12:06 -08:00 x86/virt/tdx: Handle SEAMCALL no entropy error in common code Some SEAMCALLs use the RDRAND hardware and can fail for the same reasons as RDRAND. Use the kernel RDRAND retry logic for them. There are three __seamcall*() variants. Do the SEAMCALL retry in common code and add a wrapper for each of them. Signed-off-by: Kai Huang Signed-off-by: Dave Hansen Reviewed-by: Kirill A. Shutemov Reviewed-by: Kuppuswamy Sathyanarayanan Reviewed-by: Dave Hansen Link: https://lore.kernel.org/all/20231208170740.53979-4-dave.hansen%40intel.com --- arch/x86/include/asm/tdx.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h index e5dd1cb..24c0357 100644 --- a/arch/x86/include/asm/tdx.h +++ b/arch/x86/include/asm/tdx.h @@ -24,6 +24,11 @@ #define TDX_SEAMCALL_GP (TDX_SW_ERROR | X86_TRAP_GP) #define TDX_SEAMCALL_UD (TDX_SW_ERROR | X86_TRAP_UD) +/* + * TDX module SEAMCALL leaf function error codes + */ +#define TDX_RND_NO_ENTROPY 0x8000020300000000ULL + #ifndef __ASSEMBLY__ /* @@ -84,6 +89,27 @@ u64 __seamcall(u64 fn, struct tdx_module_args *args); u64 __seamcall_ret(u64 fn, struct tdx_module_args *args); u64 __seamcall_saved_ret(u64 fn, struct tdx_module_args *args); void tdx_init(void); + +#include + +typedef u64 (*sc_func_t)(u64 fn, struct tdx_module_args *args); + +static inline u64 sc_retry(sc_func_t func, u64 fn, + struct tdx_module_args *args) +{ + int retry = RDRAND_RETRY_LOOPS; + u64 ret; + + do { + ret = func(fn, args); + } while (ret == TDX_RND_NO_ENTROPY && --retry); + + return ret; +} + +#define seamcall(_fn, _args) sc_retry(__seamcall, (_fn), (_args)) +#define seamcall_ret(_fn, _args) sc_retry(__seamcall_ret, (_fn), (_args)) +#define seamcall_saved_ret(_fn, _args) sc_retry(__seamcall_saved_ret, (_fn), (_args)) #else static inline void tdx_init(void) { } #endif /* CONFIG_INTEL_TDX_HOST */