From patchwork Wed Mar 30 22:18:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuppuswamy Sathyanarayanan X-Patchwork-Id: 12796426 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32F08C433FE for ; Wed, 30 Mar 2022 22:18:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351528AbiC3WU2 (ORCPT ); Wed, 30 Mar 2022 18:20:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242574AbiC3WUZ (ORCPT ); Wed, 30 Mar 2022 18:20:25 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 600EF22BD5; Wed, 30 Mar 2022 15:18:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1648678719; x=1680214719; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=B/SXSbw/wvdd4mRHtWjAddPGT3KI5g2InIOBTHsjt+I=; b=IwxloTx8V/DQFT/xaAVChNrWYRz7HTIE/6JROBpyrauePIwTvkuOsZML nH23UDQ5tcINTv11EhDBLPH+jT+W4Wyj/az4xuJS5Z5msr9yXHynHtSqQ XBbA4zrCD9owPKrpmkR6gDKoveZ1UVXmdbnhPCl3bvT8aW8/PxvXMHBjX Ujc/II2Oo/Q9z8bf3TZPZ0suoiNhkQ7h6szb0Zo0CWX9Uvhzsfdh+tmiY r4X75M/oFtMV1eOm9G/vSbfOoSelMY59pKVTQZ+h682DbMMwGBvaaChhM hWHn0siqxICLasddOw6pT4hdtjYpDBfxhTvzGHjdfRZ0aetOm4hNyxWC5 g==; X-IronPort-AV: E=McAfee;i="6200,9189,10302"; a="346095962" X-IronPort-AV: E=Sophos;i="5.90,223,1643702400"; d="scan'208";a="346095962" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2022 15:18:23 -0700 X-IronPort-AV: E=Sophos;i="5.90,223,1643702400"; d="scan'208";a="788171878" Received: from ksanitha-mobl3.amr.corp.intel.com (HELO skuppusw-desk1.amr.corp.intel.com) ([10.209.123.221]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2022 15:18:22 -0700 From: Kuppuswamy Sathyanarayanan To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Hans de Goede , Mark Gross Cc: "H . Peter Anvin" , Kuppuswamy Sathyanarayanan , "Kirill A . Shutemov" , Tony Luck , Andi Kleen , linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH v2 3/6] x86/tdx: Add SetupEventNotifyInterrupt TDX hypercall support Date: Wed, 30 Mar 2022 15:18:02 -0700 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org SetupEventNotifyInterrupt TDX hypercall is used by guest TD to specify which interrupt vector to use as an event-notify vector to the VMM. Such registered vector is also used by Host VMM to notify about completion of GetQuote requests to the Guest TD. Add tdx_hcall_set_notify_intr() helper function to implement the SetupEventNotifyInterrupt hypercall. This will be used by the TD guest attestation driver. Details about the SetupEventNotifyInterrupt TDVMCALL can be found in TDX Guest-Host Communication Interface (GHCI) Specification, sec 3.5 "VP.VMCALL". Reviewed-by: Tony Luck Reviewed-by: Andi Kleen Acked-by: Kirill A. Shutemov Signed-off-by: Kuppuswamy Sathyanarayanan --- arch/x86/coco/tdx/tdx.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index 54b54e321c63..14ba87b1e885 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -22,6 +22,7 @@ /* TDX hypercall Leaf IDs */ #define TDVMCALL_MAP_GPA 0x10001 #define TDVMCALL_GET_QUOTE 0x10002 +#define TDVMCALL_SETUP_NOTIFY_INTR 0x10004 /* MMIO direction */ #define EPT_READ 0 @@ -198,6 +199,38 @@ int tdx_hcall_get_quote(void *data, u64 len) } EXPORT_SYMBOL_GPL(tdx_hcall_get_quote); +/* + * tdx_hcall_set_notify_intr() - Setup Event Notify Interrupt Vector. + * + * @vector : Vector address to be used for notification. + * + * return 0 on success or failure error number. + */ +static int tdx_hcall_set_notify_intr(u8 vector) +{ + u64 ret; + + /* Minimum vector value allowed is 32 */ + if (vector < 32) + return -EINVAL; + + /* + * Register callback vector address with VMM. More details + * about the ABI can be found in TDX Guest-Host-Communication + * Interface (GHCI), sec titled + * "TDG.VP.VMCALL". + */ + ret = _tdx_hypercall(TDVMCALL_SETUP_NOTIFY_INTR, vector, 0, 0, 0); + + if (ret) { + if (ret == TDCALL_INVALID_OPERAND) + return -EINVAL; + return -EIO; + } + + return 0; +} + static u64 get_cc_mask(void) { struct tdx_module_output out;