Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp55901pxm; Tue, 22 Feb 2022 16:33:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJyX9VA8ZG+vCTof8nz7obdxYy1x6Hclli1HwSypPJCUzalVAQQcsULDn+RvWTALpfnZNY7G X-Received: by 2002:a17:902:6943:b0:149:7087:9904 with SMTP id k3-20020a170902694300b0014970879904mr25148514plt.126.1645576429809; Tue, 22 Feb 2022 16:33:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645576429; cv=none; d=google.com; s=arc-20160816; b=ttpz62dAvBMNs46u66rzi1KexOPR6gsi/6mZ12mK4DYKClrw47yRaHhg1NM9fayuev RjX+72I61rKJ3pVqEOp3mT6u9Lf7ksT0JUs61nF/eDJQtMstAH49PzYWmG0kHE/pQeTa bU+k0G06+ZqnpZWbsYA2+FxUNv+7J4K3AuWO7GtxJqg05HlstuGT8vXPG3E4awjTdtJr U0n7tgLFFgYcw3wnIo2br49HZN8AO+d/zvzfL2MTnakgVCqppElX6qnxoSsSb68hKpxx x3y3wXLwEEbeZZ1Rx0IZEQURdDza48JrhH/huiUMEmuKumII+R1gqT1A4J1I6Fv5xIHb 4Ngg== 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=xh7uYlpS/JJ/OJgzncHufUuFmwSJQQ2NQe7uhLgePnc=; b=RocgoFZNxFjhratQbD0F4Fr/F0vpXKOtobmyyPeqeMS0NX4nRZ7hF64XX3jkDwlVHe JeHn4FNpgfuZLbuzs7SZJYjUwTKzhUtClTXpPGglhI7T2zGrQheO2dMpD03uKdI9tZnb 7yPSEYRD+DBPuu6mBKDcB89IKfuOQjbSrIx2LBkJo2xvdDzeTwjGkpn448Bi0wv42LPQ f2QJ/hxaSYbk9QmV34YkQ4ot3qCa2+BGbDVLOO6TM54ys7W5KX6vlqL/rOcBvGJBvsTB TbEf8cCnfd+nbPD8FdFZqh5R/K2tmyRn7SNv9O4RVZYXCS0E4QkErI3Fe/QU6BJvUPp0 lmAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=DEP+WJqz; 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 c17si12706149pfr.17.2022.02.22.16.33.32; Tue, 22 Feb 2022 16:33:49 -0800 (PST) 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=DEP+WJqz; 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 S236234AbiBVXSd (ORCPT + 99 others); Tue, 22 Feb 2022 18:18:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235489AbiBVXS0 (ORCPT ); Tue, 22 Feb 2022 18:18:26 -0500 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE7BD90FF6; Tue, 22 Feb 2022 15:18:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645571880; x=1677107880; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7grz1QJ3374vaI95vOpZhd1dAyuBLzPtAYC2SN7sRog=; b=DEP+WJqzdLp+Bdb243fFe37UnNCS0vSeeMHiWoH7e8cjTYN72IbCXM8K YIGyvfc3rlMGjEzjRufS3prpI8pfpR3+M/EZwP6QL56gJkf4Oss0ntS4i SvRgRIx9GrLhxGq8K22q8WWkW4/456lG1HrefH8iniP5p81ILICSyYoJq 3vWn7sPxi0y+/OkNrQPGd74kteBYKrGic7gsUHLdkjbTqG45zK2Etk3My Y2fD4dbqFOFwPOkLNT9OIbvLgjvfl1dMiurvpxwziBWutc5T5bYd2KmJN OdjcDUmsTCxx9k/Kjx6gnHgbkIy3iDqC8+YGVoHQeym5WDJ5XWuoHIPVE Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10266"; a="231810094" X-IronPort-AV: E=Sophos;i="5.88,389,1635231600"; d="scan'208";a="231810094" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Feb 2022 15:18:00 -0800 X-IronPort-AV: E=Sophos;i="5.88,389,1635231600"; d="scan'208";a="776476633" Received: from skoppolu-mobl4.amr.corp.intel.com (HELO skuppusw-desk1.amr.corp.intel.com) ([10.252.138.103]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Feb 2022 15:17:59 -0800 From: Kuppuswamy Sathyanarayanan To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, Hans de Goede , Mark Gross , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: "H . Peter Anvin" , Kuppuswamy Sathyanarayanan , Kuppuswamy Sathyanarayanan , "Kirill A . Shutemov" , Andy Shevchenko , Tony Luck , linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH v1 2/6] x86/tdx: Add tdx_hcall_get_quote() API support Date: Tue, 22 Feb 2022 15:17:31 -0800 Message-Id: <20220222231735.268919-3-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220222231735.268919-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20220222231735.268919-1-sathyanarayanan.kuppuswamy@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_PASS, SPF_NONE,T_SCC_BODY_TEXT_LINE 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 The second stage in the attestation process is for the guest to request the VMM generate and sign a quote based on the TDREPORT acquired earlier. More details about the steps involved in attestation process can be found in TDX Guest-Host Communication Interface (GHCI) for Intel TDX 1.5, section titled "TD attestation" Add tdx_hcall_get_quote() helper function to implement the GetQuote hypercall. More details about the GetQuote TDVMCALL are in the Guest-Host Communication Interface (GHCI) Specification, sec 3.3, titled "VP.VMCALL". This will be used by the TD attestation driver in follow-on patches. Reviewed-by: Tony Luck Reviewed-by: Andi Kleen Signed-off-by: Kuppuswamy Sathyanarayanan --- arch/x86/coco/tdx.c | 46 ++++++++++++++++++++++++++++++++++++++ arch/x86/include/asm/tdx.h | 2 ++ 2 files changed, 48 insertions(+) diff --git a/arch/x86/coco/tdx.c b/arch/x86/coco/tdx.c index f01b03e41572..2c07f9551d3b 100644 --- a/arch/x86/coco/tdx.c +++ b/arch/x86/coco/tdx.c @@ -21,6 +21,7 @@ /* TDX hypercall Leaf IDs */ #define TDVMCALL_MAP_GPA 0x10001 +#define TDVMCALL_GET_QUOTE 0x10002 /* MMIO direction */ #define EPT_READ 0 @@ -38,6 +39,10 @@ #define TDCALL_INVALID_OPERAND 0x8000000000000000 #define TDCALL_OPERAND_BUSY 0x8000020000000000 +/* TDX hypercall error codes */ +#define TDVMCALL_INVALID_OPERAND 0x8000000000000000 +#define TDVMCALL_GPA_IN_USE 0x8000000000000001 + static struct { unsigned int gpa_width; unsigned long attributes; @@ -129,6 +134,47 @@ int tdx_mcall_tdreport(void *data, void *reportdata) } EXPORT_SYMBOL_GPL(tdx_mcall_tdreport); +/* + * tdx_hcall_get_quote() - Generate TDQUOTE using TDREPORT_STRUCT. + * + * @data : Address of 8KB GPA memory which contains + * TDREPORT_STRUCT. + * + * return 0 on success or failure error number. + */ +int tdx_hcall_get_quote(void *data) +{ + u64 ret; + + /* + * Use confidential guest TDX check to ensure this API is only + * used by TDX guest platforms. + */ + if (!data || !cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) + return -EINVAL; + + /* + * Pass the physical address of tdreport data to the VMM + * and trigger the tdquote generation. Quote data will be + * stored back in the same physical address space. More info + * about ABI can be found in TDX Guest-Host-Communication + * Interface (GHCI), sec titled "TDG.VP.VMCALL". + */ + ret = _tdx_hypercall(TDVMCALL_GET_QUOTE, cc_mkdec(virt_to_phys(data)), + 0, 0, 0); + + if (ret) { + if (ret == TDVMCALL_INVALID_OPERAND) + return -EINVAL; + else if (ret == TDVMCALL_GPA_IN_USE) + return -EBUSY; + return -EIO; + } + + return 0; +} +EXPORT_SYMBOL_GPL(tdx_hcall_get_quote); + static void get_info(void) { struct tdx_module_output out; diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h index b2e76ae8fdf1..e93ca229d512 100644 --- a/arch/x86/include/asm/tdx.h +++ b/arch/x86/include/asm/tdx.h @@ -60,6 +60,8 @@ bool tdx_early_handle_ve(struct pt_regs *regs); int tdx_mcall_tdreport(void *data, void *reportdata); +int tdx_hcall_get_quote(void *data); + #else static inline void tdx_early_init(void) { }; -- 2.25.1