Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1702862ybh; Tue, 14 Jul 2020 05:15:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzxRlR6wb5K4CwF8B5zSvbZ+ODE0yVHtEetJEf5zfNvr/VTNajmXQPOVNgLjnBUApR3+nUv X-Received: by 2002:a17:906:4a45:: with SMTP id a5mr4105877ejv.384.1594728922739; Tue, 14 Jul 2020 05:15:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594728922; cv=none; d=google.com; s=arc-20160816; b=if1pM+F3MDfs9e9X4BRnYzCu8mx7/m0Twaq5zGcrD3MdiKdSXSyRDV+icPSLxQ1WBg vwh/9jR6V19swnnhNoaLJ/t1VngMNTa9odxfGvU0Rb9ebDsx4ejmUksubF6dzXbqCIXT osx9NE19WWg3JE+d9su1K8w5dKPmizZG9oFu/Kj86MTJLWiQGy81KN6NptPwsfQCdgjr GDcWRynk1Yizbi6nvQD9z07HvMgTL9ULd1w1yY/C387+sSebqjCPp4r+5nnD0YPpoMNp 15SCTej5li53fHZEhAPIrvXG+Op1F5gq69niPCgJ8Bi23DuMtxDGMVsl66jwK2d/9qDG tRtQ== 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=Gzo/46BGZfIQGtNGCnc9sgXgAWHzXv+T5g55ysmm65s=; b=Eh0EEEcrnSCAalvH8/yTunI+m0AXHkhOd4iqRqHVemUUjZSDrFo5Kz0wD8MT+PQkIU T6BqtLFJOP1Q4GrmT5xrE2xe+1PPQ/EjY0XXlroMY+QD5gdOeUWzanLv6DqoBz+5oLfV /ihWfe7HAznsOX4v7RoncBluwJdQJ0nAiZi66mvJouqUtE/jkcs1SkVNo5EGuRMDLXY1 NWmi6HK5yRuXK/2eZj+vGpMKbo5FAp/te5T0BM44OXxA03tutRRajB3TnjgXkwNDmFRt Nkg5iJKQeh3B9s9qcV09yn7CsVWjcbh4+UfX3LEyOPQLtxMJn3kud2LCvWlWdjIoQxAB Tb+w== 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 dt4si13061543ejc.34.2020.07.14.05.14.57; Tue, 14 Jul 2020 05:15:22 -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 S1728747AbgGNMMO (ORCPT + 99 others); Tue, 14 Jul 2020 08:12:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728581AbgGNMLT (ORCPT ); Tue, 14 Jul 2020 08:11:19 -0400 Received: from theia.8bytes.org (8bytes.org [IPv6:2a01:238:4383:600:38bc:a715:4b6d:a889]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AEC8C061755; Tue, 14 Jul 2020 05:11:19 -0700 (PDT) Received: from cap.home.8bytes.org (p5b006776.dip0.t-ipconnect.de [91.0.103.118]) (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 8C00DFDF; Tue, 14 Jul 2020 14:11:09 +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 v4 66/75] x86/vmware: Add VMware specific handling for VMMCALL under SEV-ES Date: Tue, 14 Jul 2020 14:09:08 +0200 Message-Id: <20200714120917.11253-67-joro@8bytes.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200714120917.11253-1-joro@8bytes.org> References: <20200714120917.11253-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..d2129d5e8373 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_is_valid_rbx(ghcb) && + ghcb_is_valid_rcx(ghcb) && + ghcb_is_valid_rdx(ghcb) && + ghcb_is_valid_rsi(ghcb) && + ghcb_is_valid_rdi(ghcb) && + ghcb_is_valid_rbp(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.27.0