Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3356812pxk; Mon, 7 Sep 2020 10:30:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwe3fgvHO3BbEXftU3Y+uX3rm5JnJ1lyYeA1qxSrDC891sZV206zlpCtnbVTfeSgDq8wjr/ X-Received: by 2002:a17:906:a002:: with SMTP id p2mr17599977ejy.290.1599499822486; Mon, 07 Sep 2020 10:30:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599499822; cv=none; d=google.com; s=arc-20160816; b=LDfRoNFGDRDipUnsivjY0qMrwo0vU2Fx35JRKnUGN0Bq/SXctCMq4BtA65WWEuIzKs VxjVD7ArKruB+/2fSCjBTJKPO6Zh+B+QbYUEFOqqIG0sArkXM+gPDc7j0iyaXVGwX1wy 3PMfysdTSCToD7c+LyiHe3MdPnfC2n8vXW8Who6kXYXPBrADg/Jxoz731F3cLKDAol+O tO86aUjmy+xmi3Ca4+GsLdIl76tWLJq/0Lt+J7QQZNcOn14k4EY7gJ4XNP4d+Xd6ekJH inVPjWb9TbFBUUN/gls0OZq2p83H6FeyeVdLvXUNUvwvcCwPaoAwp3DTRzMfUiRyAtr9 ntZw== 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=uxJwJZ2eD2vPliUdCFfbT/P0AGOWrs+LYCnVre32tQY=; b=SgtI9bAHARLBGamjtc26l+wIcg0Sl6X6OvESgpDDwzSjQqX42Tucq6g6RgPwR5Wz3j pLnVfFz+uGDlf6PLqynJ2BH81SgjxCVLpy9is97bJD1nwsgP0sk8vhHxNcLTyZgL/J7y KU5VNw9gPW1jcz+PGdA1MOZ+kX1ku1p+dbTzLDyUerXdax9ay0QLB1I51tfZpNZ6mq+j G1coSHl+zcl6dHOSbqrkhen+nfYTJ+4Nj9AFRBXtkZLLZhWxgKuzfPHxnz5+sEOlQp1f SpgjsvvlfkuR8S3/Hjrym29ZbFBqXp/dWWX+jpe2EeCrkUdjK6w8qWYT9EdbjM7IQjRR 7rBQ== 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 t22si9698712eji.298.2020.09.07.10.30.00; Mon, 07 Sep 2020 10:30: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 S1731199AbgIGR2F (ORCPT + 99 others); Mon, 7 Sep 2020 13:28:05 -0400 Received: from 8bytes.org ([81.169.241.247]:43636 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729522AbgIGNTh (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 708EA3AA3; Mon, 7 Sep 2020 15:17:15 +0200 (CEST) From: Joerg Roedel To: x86@kernel.org Cc: Joerg Roedel , Joerg Roedel , 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 63/72] x86/kvm: Add KVM specific VMMCALL handling under SEV-ES Date: Mon, 7 Sep 2020 15:16:04 +0200 Message-Id: <20200907131613.12703-64-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: Tom Lendacky Implement the callbacks to copy the processor state required by KVM to the GHCB. Signed-off-by: Tom Lendacky [ jroedel@suse.de: - Split out of a larger patch - Adapt to different callback functions ] Co-developed-by: Joerg Roedel Signed-off-by: Joerg Roedel --- arch/x86/kernel/kvm.c | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c index 08320b0b2b27..0f9597275e9c 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -36,6 +36,8 @@ #include #include #include +#include +#include DEFINE_STATIC_KEY_FALSE(kvm_async_pf_enabled); @@ -746,13 +748,34 @@ static void __init kvm_init_platform(void) x86_platform.apic_post_init = kvm_apic_init; } +#if defined(CONFIG_AMD_MEM_ENCRYPT) +static void kvm_sev_es_hcall_prepare(struct ghcb *ghcb, struct pt_regs *regs) +{ + /* RAX and CPL are already in the GHCB */ + ghcb_set_rbx(ghcb, regs->bx); + ghcb_set_rcx(ghcb, regs->cx); + ghcb_set_rdx(ghcb, regs->dx); + ghcb_set_rsi(ghcb, regs->si); +} + +static bool kvm_sev_es_hcall_finish(struct ghcb *ghcb, struct pt_regs *regs) +{ + /* No checking of the return state needed */ + return true; +} +#endif + const __initconst struct hypervisor_x86 x86_hyper_kvm = { - .name = "KVM", - .detect = kvm_detect, - .type = X86_HYPER_KVM, - .init.guest_late_init = kvm_guest_init, - .init.x2apic_available = kvm_para_available, - .init.init_platform = kvm_init_platform, + .name = "KVM", + .detect = kvm_detect, + .type = X86_HYPER_KVM, + .init.guest_late_init = kvm_guest_init, + .init.x2apic_available = kvm_para_available, + .init.init_platform = kvm_init_platform, +#if defined(CONFIG_AMD_MEM_ENCRYPT) + .runtime.sev_es_hcall_prepare = kvm_sev_es_hcall_prepare, + .runtime.sev_es_hcall_finish = kvm_sev_es_hcall_finish, +#endif }; static __init int activate_jump_labels(void) -- 2.28.0