Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2009778pxa; Mon, 24 Aug 2020 02:23:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyFCwfJmeOFOJzB3E6663LfLGQ9kQoOK+57yHI2479aqkaWPrF1myQaa45DUr70bX9cfhVe X-Received: by 2002:a17:906:37c1:: with SMTP id o1mr4611030ejc.279.1598260996955; Mon, 24 Aug 2020 02:23:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598260996; cv=none; d=google.com; s=arc-20160816; b=0hie+1DwrSLRddSWi07Wya1JilLsg9epzHV0RyY3dKO8/Z6V85i465kY7IIe8Unm1v yxBH8Ug7nxgLsjysiJ49jBwkKgo5kbrZKLVx+KYpTzgxcnGHHpGU4oIzQI4bHu2OwDMM nx2zCxoWlnl0UyodbUI4XKn6A4IuzKBtU2ktJo/LX1Zj7CRT8Ncniuw6QqEQ9Nao5NL2 TYqEF5YdZMt74iT0U6fSII6ne0krQuG6J4NrJZUdPpadOjo0w8nuEA03bRH5IovOIP4g 9qgMkWjMQUT0yApB2SwO8JP337g/hQIGootlt5UEqJ70zhbmoyNfkdR6aK1n+Ak9zt5G Lqyw== 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=OxbocBaPecnJG4jMgUzMem/LGJqqqooH/8+fEG9KyUs=; b=RRM0Fq6EYrlIa+erbXDsaPdWI2iXqhooBeN2XUl3kNhwHtyMldXqmehN3SItPMjUNg 0Mb4qh0Awz2VD3Js7Y8bMJZW2RpfG1U/0n6gO0xnwUYcHylYAEQtZMwwrzU53nEj/Nof di2Rbvp+pVZmQQEyV2hixvzrXY4XlWYte9BzCmBQvrbbLEzxXdBLUDuqRpJwTyta0ijs /N7Wwj6/2UBtrokZRq80COeF4FYM9SFLbpy8vJkzJwAJ3qJ8XEyYgjEEKuEdIenN997Y rCgYe7Jt28s4vqvXNOLLBJBal+FKsFw8aVKRqkNUsF3IszA4tDo+gp0SU2IW6XTZ/thG Dv2w== 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 t21si5712745ejs.708.2020.08.24.02.22.54; Mon, 24 Aug 2020 02:23:16 -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 S1730471AbgHXJUU (ORCPT + 99 others); Mon, 24 Aug 2020 05:20:20 -0400 Received: from 8bytes.org ([81.169.241.247]:36908 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730282AbgHXIzu (ORCPT ); Mon, 24 Aug 2020 04:55:50 -0400 Received: from cap.home.8bytes.org (p4ff2bb8d.dip0.t-ipconnect.de [79.242.187.141]) (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 407D136B; Mon, 24 Aug 2020 10:55:47 +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 v6 02/76] KVM: SVM: Add GHCB definitions Date: Mon, 24 Aug 2020 10:53:57 +0200 Message-Id: <20200824085511.7553-3-joro@8bytes.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200824085511.7553-1-joro@8bytes.org> References: <20200824085511.7553-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..094b8f8fb1d4 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 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; +} __packed; + 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 03dd7bac8034..4368b66615c1 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -4164,6 +4164,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.28.0