Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp2298070ybh; Fri, 24 Jul 2020 09:14:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxuoKhFwEi2HW8oPhpLTonsTtfZIsU4QWxMaBERZKpNAIodV/k3TLBpM3nPKrrGqIjr1OGd X-Received: by 2002:a17:906:b0d:: with SMTP id u13mr9668766ejg.342.1595607261381; Fri, 24 Jul 2020 09:14:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595607261; cv=none; d=google.com; s=arc-20160816; b=ZyBbJH2Qtc/xNynt9RsRl+a0OOIAaRvC3XbIZmnB30k57WOPvMCJgu3fdtB/bW9pRn PU9T1aVv8bKp4XhAK9kSbeBSGPqN/GHZkNdS0Fy+QSOebtQRgly28K0sm5Qzdr1yQw24 Cs3VXJXXpFl1HyoVc4sQQnLFqER02oHjI8WXeBHQbD3JbRUrZnYT3xPEx+E+tGgh8J3h 8Cr2Ei4DJ4c+tMolDDg5w6tPJhO1dewfEnCRLHa2TY+Dv9H4NRgpDOAv83ahKWOhkq5b ZOr3hsNstYYUAVmYXcUxl5pMaJQxR/1JWYiU1+muCpaC4n8iFmhJr3a7/nuWRmk+GA06 vm9A== 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=i916v1Mhxbum1/YBH4mkauXQUhOn47lUrXTGx3pybtsy/8BeT1Kqd4+e/mHVhAcVmF Z9Fdsy9tvBRk7SzMlX9rOtjlTDrKg9WkaZN0z7gQ82sVuKAtlc2dVbZKuTK9OmcvQ5M9 ci1gZXxjyL6hr80RtnNUl27Wqmhwhlswt7W+7rU8QRIlKvc6zjOuGhLHR74cWmS51otC yh5upIKNzqNknso3vZzUSwbHAK7UTDnfuUzKu+RnIsaIIfE9Okhj/tUAw1hrd/eyfjgB 8kOqwvsRl4TzTmJg8stP2n/Xh22DXDSOJo+7h8QT4jthHXWggh2VnJCzvPUm4Qkhbfrg tlDw== 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 y19si782774edv.611.2020.07.24.09.13.58; Fri, 24 Jul 2020 09:14:21 -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 S1728206AbgGXQL2 (ORCPT + 99 others); Fri, 24 Jul 2020 12:11:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726754AbgGXQD7 (ORCPT ); Fri, 24 Jul 2020 12:03:59 -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 9A4ADC0619D3; Fri, 24 Jul 2020 09:03:59 -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 9412F6FA; Fri, 24 Jul 2020 18:03:56 +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 v5 01/75] KVM: SVM: Add GHCB definitions Date: Fri, 24 Jul 2020 18:02:22 +0200 Message-Id: <20200724160336.5435-2-joro@8bytes.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200724160336.5435-1-joro@8bytes.org> References: <20200724160336.5435-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