Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1707348ybh; Tue, 14 Jul 2020 05:22:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzFQpotRkM1YX/v3NQnZ9RRBQVB2mZP9zSdJknA784fr2Tvxs4AJuRwexIu42MQruGACbhI X-Received: by 2002:a17:906:a28b:: with SMTP id i11mr4150388ejz.524.1594729331573; Tue, 14 Jul 2020 05:22:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594729331; cv=none; d=google.com; s=arc-20160816; b=QclYsTqC8UH9xWPOfgPsgJbIU8ql/km3FXslZ7oWd2QGZnlMRfs2X8vNVg8+xmfwRQ em5DlppchoDeGfMrxDW+g8MHw12PnlA9nCt47Kr2h4grBf9wjd8zqkEbs71huC1etzNZ hgQ/V/lhDD7pWoUGKExgfIq2R6Ml29jxSA/ywG0yk9hsMEcBJokq/VeiXtfq6x5Fm5jk XdT98Ir25CsO4nvzsOA4BtLLGv2Icv+5eOGCRpcPKRGRdXey7vjnRDU7H/m7B+sq9rxv Rh5iL1MG8alNJR64PKPFa0bsM39KmXeW9ANuL1MR8Y3J0z25fYtQaf81jJLMSxWa/NVC KaKQ== 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=vmBu7Tk/AkCqqvcjTTqNSJpK+28RRp37gYsezoK8zSo=; b=fFcY2Mu4Rc17WN7tQEPiiulyiOIItKoH6kJgTT38khJQ5UUuWwwp1F0dtlTdcsSQdw o95P4136mX6OT1MejoBDpbj2y0Z4g0TEXXdS/sb5FuvnCz+qHagOlJFC3RY7kDoLY6bX hrI/irwUVMByO5kHx/T8ulr/Ezsj5xwQKckEfS825zFg/yULUxPkz5D4H5GRinL2RX0Q FVRdhkot7uyGEzuhTLTFpVrWGbJedlCoCOWgRuU29wZqAUxTj2HWbTbrDoCNEERfJHMB btgtxYWsKHs5za/dfG4+3PdapOKjiDNPAbFtHopMh85lbBhoHE8xONvcBwxzQRNqiE/k S8pQ== 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 l9si11459257ejq.76.2020.07.14.05.21.47; Tue, 14 Jul 2020 05:22:11 -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 S1728116AbgGNMKh (ORCPT + 99 others); Tue, 14 Jul 2020 08:10:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726354AbgGNMKg (ORCPT ); Tue, 14 Jul 2020 08:10:36 -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 76084C061794; Tue, 14 Jul 2020 05:10:36 -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 C708A293; Tue, 14 Jul 2020 14:10:33 +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 v4 01/75] KVM: SVM: Add GHCB definitions Date: Tue, 14 Jul 2020 14:08:03 +0200 Message-Id: <20200714120917.11253-2-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: Tom Lendacky Extend the vmcb_safe_area with SEV-ES fields and add a new 'struct ghcb' which will be used for guest-hypervisor communication. Signed-off-by: Tom Lendacky Signed-off-by: Joerg Roedel --- arch/x86/include/asm/svm.h | 45 +++++++++++++++++++++++++++++++++++++- arch/x86/kvm/svm/svm.c | 2 ++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h index 8a1f5382a4ea..9a3e0b802716 100644 --- a/arch/x86/include/asm/svm.h +++ b/arch/x86/include/asm/svm.h @@ -200,13 +200,56 @@ struct __attribute__ ((__packed__)) vmcb_save_area { u64 br_to; u64 last_excp_from; u64 last_excp_to; + + /* + * The following part of the save area is valid only for + * SEV-ES guests when referenced through the GHCB. + */ + u8 reserved_7[104]; + u64 reserved_8; /* rax already available at 0x01f8 */ + u64 rcx; + u64 rdx; + u64 rbx; + u64 reserved_9; /* rsp already available at 0x01d8 */ + u64 rbp; + u64 rsi; + u64 rdi; + u64 r8; + u64 r9; + u64 r10; + u64 r11; + u64 r12; + u64 r13; + u64 r14; + u64 r15; + u8 reserved_10[16]; + u64 sw_exit_code; + u64 sw_exit_info_1; + u64 sw_exit_info_2; + u64 sw_scratch; + u8 reserved_11[56]; + u64 xcr0; + u8 valid_bitmap[16]; + u64 x87_state_gpa; +}; + +struct __attribute__ ((__packed__)) ghcb { + struct vmcb_save_area save; + u8 reserved_save[2048 - sizeof(struct vmcb_save_area)]; + + u8 shared_buffer[2032]; + + u8 reserved_1[10]; + u16 protocol_version; /* negotiated SEV-ES/GHCB protocol version */ + u32 ghcb_usage; }; static inline void __unused_size_checks(void) { - BUILD_BUG_ON(sizeof(struct vmcb_save_area) != 0x298); + BUILD_BUG_ON(sizeof(struct vmcb_save_area) != 1032); BUILD_BUG_ON(sizeof(struct vmcb_control_area) != 256); + BUILD_BUG_ON(sizeof(struct ghcb) != 4096); } struct __attribute__ ((__packed__)) vmcb { diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index c0da4dd78ac5..af6dc22437c1 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -4099,6 +4099,8 @@ static struct kvm_x86_init_ops svm_init_ops __initdata = { static int __init svm_init(void) { + __unused_size_checks(); + return kvm_init(&svm_init_ops, sizeof(struct vcpu_svm), __alignof__(struct vcpu_svm), THIS_MODULE); } -- 2.27.0