Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3358311pxk; Mon, 7 Sep 2020 10:32:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJybaYqexCTN39YYKHUsSKi3VMc1imb9KSOZLLIsv8BNKDDI1qn7HOKugBBvXcKXge2gtJyM X-Received: by 2002:a05:6402:1b9a:: with SMTP id cc26mr22383876edb.30.1599499974186; Mon, 07 Sep 2020 10:32:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599499974; cv=none; d=google.com; s=arc-20160816; b=f/XzNglocz9Qdaf7ce9Lm7mHcTyEoxVGJDh4a/6GgCC061RGGBKENRQWLkRF2wzLAG RUjUfVutm2ar7hTSLW4qLs9ga1S0Ev+t7U0TXypINjx6BFNSUPW/xO9k29ZjdGccON6Y +6rvlcCD0C8kW489DhgCzyEa4ldBsVFVCufD1/IPC3crWwsHHoNNWLpCtIXhHAQGRzCN ZRqxFbnfBdKXJRvOgQL5TZaiQ09BqE/ZqN/gfiX6e0hlKUwaUsBLThaIppll0gwaCO+9 LLLtJ0Eh7DI0HC9gMFD3xJQDnPnyr+M85G0/NwLxynARSykclojgqVbRf7/ZeeW/I9fy NCeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Q2ArgV9CgLsVLmmLB2STlZo05+Nq8z4hncpMc9eKaLQ=; b=e1eOIdU7Iw5w3OF4aeJO/QsuPmSsCc7YJu5VyAkFljQzINcUcsJGIHp2un7UDBfF60 QF+lz0htrAB8PWYCm4ybDwk4t/8aO6LI2RkapkBzlrj7cs+MtYcDBWxfNrZuRAh3Js3Y sspXyFZV8BIL7z89JFxvqIaISj/fQ5q0SVt81RFvteJRQiGwvu/U9PAcds/5ILEGw/3Q A4w0+mljmj/PNCLRLETuZPUR/XwH96TCJzwjrFLNJe7tlrNmYsHTFS2IN+Wh5h2vd9JG OV/xe2kA1hUTN+a7m2NV8PXjeupJQGgoloYmbHAmsL/Nvfxas6zTlMSk9na3p3DG5rSg 1aLQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 39si1341992edr.435.2020.09.07.10.32.32; Mon, 07 Sep 2020 10:32:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731299AbgIGR3Q (ORCPT + 99 others); Mon, 7 Sep 2020 13:29:16 -0400 Received: from 8bytes.org ([81.169.241.247]:43656 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729525AbgIGNTh (ORCPT ); Mon, 7 Sep 2020 09:19:37 -0400 Received: from cap.home.8bytes.org (p549add56.dip0.t-ipconnect.de [84.154.221.86]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by theia.8bytes.org (Postfix) with ESMTPSA id E99F63AA4; Mon, 7 Sep 2020 15:17:15 +0200 (CEST) From: Joerg Roedel To: x86@kernel.org Cc: Joerg Roedel , Joerg Roedel , Doug Covelli , Tom Lendacky , hpa@zytor.com, Andy Lutomirski , Dave Hansen , Peter Zijlstra , Jiri Slaby , Dan Williams , Juergen Gross , Kees Cook , David Rientjes , Cfir Cohen , Erdem Aktas , Masami Hiramatsu , Mike Stunes , Sean Christopherson , Martin Radev , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH v7 64/72] x86/vmware: Add VMware specific handling for VMMCALL under SEV-ES Date: Mon, 7 Sep 2020 15:16:05 +0200 Message-Id: <20200907131613.12703-65-joro@8bytes.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200907131613.12703-1-joro@8bytes.org> References: <20200907131613.12703-1-joro@8bytes.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Doug Covelli Add VMware specific handling for #VC faults caused by VMMCALL instructions. Signed-off-by: Doug Covelli Signed-off-by: Tom Lendacky [ jroedel@suse.de: - Adapt to different paravirt interface ] Co-developed-by: Joerg Roedel Signed-off-by: Joerg Roedel --- arch/x86/kernel/cpu/vmware.c | 50 ++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c index 9b6fafa69be9..924571fe5864 100644 --- a/arch/x86/kernel/cpu/vmware.c +++ b/arch/x86/kernel/cpu/vmware.c @@ -33,6 +33,7 @@ #include #include #include +#include #undef pr_fmt #define pr_fmt(fmt) "vmware: " fmt @@ -476,10 +477,49 @@ static bool __init vmware_legacy_x2apic_available(void) (eax & (1 << VMWARE_CMD_LEGACY_X2APIC)) != 0; } +#ifdef CONFIG_AMD_MEM_ENCRYPT +static void vmware_sev_es_hcall_prepare(struct ghcb *ghcb, + struct pt_regs *regs) +{ + /* Copy VMWARE specific Hypercall parameters to the GHCB */ + ghcb_set_rip(ghcb, regs->ip); + ghcb_set_rbx(ghcb, regs->bx); + ghcb_set_rcx(ghcb, regs->cx); + ghcb_set_rdx(ghcb, regs->dx); + ghcb_set_rsi(ghcb, regs->si); + ghcb_set_rdi(ghcb, regs->di); + ghcb_set_rbp(ghcb, regs->bp); +} + +static bool vmware_sev_es_hcall_finish(struct ghcb *ghcb, struct pt_regs *regs) +{ + if (!(ghcb_rbx_is_valid(ghcb) && + ghcb_rcx_is_valid(ghcb) && + ghcb_rdx_is_valid(ghcb) && + ghcb_rsi_is_valid(ghcb) && + ghcb_rdi_is_valid(ghcb) && + ghcb_rbp_is_valid(ghcb))) + return false; + + regs->bx = ghcb->save.rbx; + regs->cx = ghcb->save.rcx; + regs->dx = ghcb->save.rdx; + regs->si = ghcb->save.rsi; + regs->di = ghcb->save.rdi; + regs->bp = ghcb->save.rbp; + + return true; +} +#endif + const __initconst struct hypervisor_x86 x86_hyper_vmware = { - .name = "VMware", - .detect = vmware_platform, - .type = X86_HYPER_VMWARE, - .init.init_platform = vmware_platform_setup, - .init.x2apic_available = vmware_legacy_x2apic_available, + .name = "VMware", + .detect = vmware_platform, + .type = X86_HYPER_VMWARE, + .init.init_platform = vmware_platform_setup, + .init.x2apic_available = vmware_legacy_x2apic_available, +#ifdef CONFIG_AMD_MEM_ENCRYPT + .runtime.sev_es_hcall_prepare = vmware_sev_es_hcall_prepare, + .runtime.sev_es_hcall_finish = vmware_sev_es_hcall_finish, +#endif }; -- 2.28.0