Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp4951352ybv; Tue, 11 Feb 2020 06:26:52 -0800 (PST) X-Google-Smtp-Source: APXvYqwBGJbKka6idDNM2xZBYQ3Y2v/HZMRKZIX+P5rtZ8M2p9MyA5/bXs+nRvnJUkTe1ujm71Gh X-Received: by 2002:aca:54cc:: with SMTP id i195mr2992580oib.126.1581431212641; Tue, 11 Feb 2020 06:26:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581431212; cv=none; d=google.com; s=arc-20160816; b=geGbGBtU9yyECD1fCw1seA6kXjGFFyltSsest8TLz0aZnSluP+Pn5HcYEHKwddSHz9 a/gLL0SRmIKhbljUz5IFIvf03FkoT7cHsZv7ORdfKuMqdDfrI2njgjCqzHmyRRCf7LxQ oJ4QRcm9NSto1ENEAzyw9ibErciqp3nrCaqWQwfFnTNwevToL2un36GS0n+qKXd+diba AAnCVd1c1do1UdAvRmME2mcbqKhH/7erq6G1wqI2lYnT+HhyN56lqfa3rNIxxO2T2FLm n08YDjwRajBq1B4tsmSCSSW/TjVSlIi7fohLO6JYMeY41dmQt4WlZ9jyM/YjhyFXU2Zi b2og== 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=G3f4WUPTuAmumrHzM3xMkESLndRA0O4IscywR2BJvQ4=; b=f0wzhsclIm7E5ZQynriUoWmCnUiq2t+OsKk/G5T2xJNOuGPhl53Lux2qGPrPJav8Sa ZVEOcZ62eSe8r5aDuywu7mwfDDFzT8J2dOk+GEpLgMQhMh6VY9oIafJP8DW3qimrrsar VAogufSfiOvVDRqyKizEKQVW5h3usGrh0Vdcw8c6NnzuL30kq0duXwiv1pTD5EJglWeG utdUY/86RjojqOnlyAFULnwdYA8ohqXXQBOKVLgeBjl7fiX9vSbK2MHSfP+tLNeNe7Sp lwV9QLqFbNswGJR+Ap73jOIa/yPWArxUo96mqU11swqfQ1GaMeROQjHVxy4hTkesad2o Tu0Q== 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 q26si1742360oij.38.2020.02.11.06.26.40; Tue, 11 Feb 2020 06:26:52 -0800 (PST) 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 S1730141AbgBKN7Y (ORCPT + 99 others); Tue, 11 Feb 2020 08:59:24 -0500 Received: from 8bytes.org ([81.169.241.247]:51808 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729385AbgBKNxJ (ORCPT ); Tue, 11 Feb 2020 08:53:09 -0500 Received: by theia.8bytes.org (Postfix, from userid 1000) id 88765342; Tue, 11 Feb 2020 14:53:07 +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 02/62] KVM: SVM: Add GHCB Accessor functions Date: Tue, 11 Feb 2020 14:51:56 +0100 Message-Id: <20200211135256.24617-3-joro@8bytes.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200211135256.24617-1-joro@8bytes.org> References: <20200211135256.24617-1-joro@8bytes.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Joerg Roedel Building a correct GHCB for the hypervisor requires setting valid bits in the GHCB. Simplify that process by providing accessor functions to set values and to update the valid bitmap. Signed-off-by: Joerg Roedel --- arch/x86/include/asm/svm.h | 61 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h index f36288c659b5..e4e9f6bacfaa 100644 --- a/arch/x86/include/asm/svm.h +++ b/arch/x86/include/asm/svm.h @@ -333,4 +333,65 @@ struct __attribute__ ((__packed__)) vmcb { #define SVM_CR0_SELECTIVE_MASK (X86_CR0_TS | X86_CR0_MP) +/* GHCB Accessor functions */ + +#define DEFINE_GHCB_INDICES(field) \ + u16 idx = offsetof(struct vmcb_save_area, field) / 8; \ + u16 byte_idx = idx / 8; \ + u16 bit_idx = idx % 8; \ + BUILD_BUG_ON(byte_idx > ARRAY_SIZE(ghcb->save.valid_bitmap)); + +#define GHCB_SET_VALID(ghcb, field) \ + { \ + DEFINE_GHCB_INDICES(field) \ + (ghcb)->save.valid_bitmap[byte_idx] |= BIT(bit_idx); \ + } + +#define DEFINE_GHCB_SETTER(field) \ + static inline void \ + ghcb_set_##field(struct ghcb *ghcb, u64 value) \ + { \ + GHCB_SET_VALID(ghcb, field) \ + (ghcb)->save.field = value; \ + } + +#define DEFINE_GHCB_ACCESSORS(field) \ + static inline bool ghcb_is_valid_##field(const struct ghcb *ghcb) \ + { \ + DEFINE_GHCB_INDICES(field) \ + return !!((ghcb)->save.valid_bitmap[byte_idx] \ + & BIT(bit_idx)); \ + } \ + \ + static inline void \ + ghcb_set_##field(struct ghcb *ghcb, u64 value) \ + { \ + GHCB_SET_VALID(ghcb, field) \ + (ghcb)->save.field = value; \ + } + +DEFINE_GHCB_ACCESSORS(cpl) +DEFINE_GHCB_ACCESSORS(rip) +DEFINE_GHCB_ACCESSORS(rsp) +DEFINE_GHCB_ACCESSORS(rax) +DEFINE_GHCB_ACCESSORS(rcx) +DEFINE_GHCB_ACCESSORS(rdx) +DEFINE_GHCB_ACCESSORS(rbx) +DEFINE_GHCB_ACCESSORS(rbp) +DEFINE_GHCB_ACCESSORS(rsi) +DEFINE_GHCB_ACCESSORS(rdi) +DEFINE_GHCB_ACCESSORS(r8) +DEFINE_GHCB_ACCESSORS(r9) +DEFINE_GHCB_ACCESSORS(r10) +DEFINE_GHCB_ACCESSORS(r11) +DEFINE_GHCB_ACCESSORS(r12) +DEFINE_GHCB_ACCESSORS(r13) +DEFINE_GHCB_ACCESSORS(r14) +DEFINE_GHCB_ACCESSORS(r15) +DEFINE_GHCB_ACCESSORS(sw_exit_code) +DEFINE_GHCB_ACCESSORS(sw_exit_info_1) +DEFINE_GHCB_ACCESSORS(sw_exit_info_2) +DEFINE_GHCB_ACCESSORS(sw_scratch) +DEFINE_GHCB_ACCESSORS(xcr0) + #endif -- 2.17.1