Received: by 2002:a25:d783:0:0:0:0:0 with SMTP id o125csp426159ybg; Thu, 19 Mar 2020 02:17:14 -0700 (PDT) X-Google-Smtp-Source: ADFU+vufe4LfXWyTGrUftHUxeQ4Bckg726Qf18+EL2sIRKt2qUj2/88ZPdAVTGI4cL1LiJ5qZLMr X-Received: by 2002:aca:1c13:: with SMTP id c19mr1653672oic.47.1584609434841; Thu, 19 Mar 2020 02:17:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584609434; cv=none; d=google.com; s=arc-20160816; b=LKrQpncQBRXB4tMmDM69IHCM5FYeJ/jJzdDJd18fnpF7I5c4Iak+CNVigFSsEEziuH u/TH5gy/Z4EYKXvT+Rimfqx46283NFxcGGVPbCShC343OyTNIwRLtD03MbqmPzEioLoG jpJu1wijmArZSTbpXBJWeuljCvxFVtosLmzoZsM5fKRcHZG73oH+ppsBh9zow0dF3tcE FwOI24jSM45gQ4HXySONSPw6Awzc8pTQJkn2Wjg8rubQvq3YnFIB59/QzHxungLZR2yb oiXDGKX7vLhDbd+duaRybl99vugLv9W7pay7gHnU+AHif4NKBHMDIFTSMWwVN1kWy8uY 9s+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=U8UC5APjCvGG4FvlZKRtdZMRPjcDiWvq8HnCBDGvERo=; b=mOwZKyFhL0s6o7vgkUC/wII+D0ZQGSh5jN0IifPL845ZGPQMOH/L5ZFgaw6l7YrufK GY0U1MaDVA1A7VoD+p8wNXmGWjISZR1lLtFFLgrHYJn2ZvANGGa4KmdUqmvrgjkj+ccF JBm3fUCzAfP0fuJXKyMcea5KnA2BgdKGnDfSnH+ImjZrCXRV6aCxne2DSo4S6QStnRZZ T7Y6QMxCD+2D0uA+4OjeRKLRh7zWrN4hUFsWLDvtxH7eiF+0fti8uRw9Et3agcMeqS+R Nyun5rqp3/HDkTk7df4aVtozuJ292zCvafVs/8Cesx7s0Pq0Ga/BYyeaSf/qpxQXUh7h MH0A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id g8si899537otk.163.2020.03.19.02.17.02; Thu, 19 Mar 2020 02:17:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1727657AbgCSJPG (ORCPT + 99 others); Thu, 19 Mar 2020 05:15:06 -0400 Received: from 8bytes.org ([81.169.241.247]:51922 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727493AbgCSJOq (ORCPT ); Thu, 19 Mar 2020 05:14:46 -0400 Received: by theia.8bytes.org (Postfix, from userid 1000) id CD01EECC; Thu, 19 Mar 2020 10:14:27 +0100 (CET) From: Joerg Roedel To: x86@kernel.org Cc: hpa@zytor.com, Andy Lutomirski , Dave Hansen , Peter Zijlstra , Thomas Hellstrom , Jiri Slaby , Dan Williams , Tom Lendacky , Juergen Gross , Kees Cook , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, Joerg Roedel , Joerg Roedel Subject: [PATCH 62/70] x86/kvm: Add KVM specific VMMCALL handling under SEV-ES Date: Thu, 19 Mar 2020 10:13:59 +0100 Message-Id: <20200319091407.1481-63-joro@8bytes.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319091407.1481-1-joro@8bytes.org> References: <20200319091407.1481-1-joro@8bytes.org> 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 6efe0410fb72..0e3fc798d719 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -34,6 +34,8 @@ #include #include #include +#include +#include static int kvmapf = 1; @@ -729,13 +731,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.17.1