Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2007387pxa; Mon, 24 Aug 2020 02:17:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxVx7UBf6hTY3FO/nLzWT1LVSeRQBDCAyAB4EA6FjUcjHk1BIu2Ple3FIqUGTynImi9IH/t X-Received: by 2002:a17:906:1f96:: with SMTP id t22mr4541612ejr.381.1598260653301; Mon, 24 Aug 2020 02:17:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598260653; cv=none; d=google.com; s=arc-20160816; b=x6BvMp0K7UH2QyFgWFm5ofju4N767b52ZP+pknhVU2svwLrIGlITtzyVp+g+4U8MKb w9BP3gw8w76uSPWRgqlj7IuGhDA+TmJluOEPpc56OS2lL50XpSLd7gZ5q1pwJICiwzn1 HJ7DL6mkV7ttbzT/skkzaCVWaedG9HwJBi5SqWPtsXptDKZoaTUGqXcqv+0RSZ7xjFQI 3LN9Tugxr3pc3JOmmwqZU/h0HdAQK7L2AIVA4yvOguuyFIsC4KA3HatJrzcCboLHM2cV UnC7xvlRxCbzCb09qm7E+xh9gVK+DcjM8xWzYRaSw4mX5YMpE/fUdsbxrb1IgIKfHBaq APsw== 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=83ukUvVH28yionDPab/cvKAR8QWJ1wfgyQXz4gBdbrQ=; b=BEcpKtDZFLX3C3okUN1D/z7NlFflDUoYHBxGlD1f3rfXpHOa4AB0f0jk9qkUmnT4GA NMvnA8tm/iypEOu6qLngHnIQn7vdLX9NrpbOhaHotYYQewadoJT/pb4IkxHHO/4bCpg7 S0PNKCTt25crmu6AiSee2Qf66/blz/Afj7swODFr14+cyoQpNw7sSM353EEFwsV6hmG0 A0xI+X44RYQgRJJCXdW4Snpm+pD9nGNM8bmbpmuOaKmREo8YM8xtOmSMTMlV8A8A00Mt hK1A6tuSRlZl9Y3dvcmaIMEkZjD3z2zMlfRwu5ayKs1/2mIIVpyDQAJNz4TLZL432iXx 7+QA== 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 v15si6192444edy.90.2020.08.24.02.17.10; Mon, 24 Aug 2020 02:17:33 -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 S1728852AbgHXJPi (ORCPT + 99 others); Mon, 24 Aug 2020 05:15:38 -0400 Received: from 8bytes.org ([81.169.241.247]:37380 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730417AbgHXI4C (ORCPT ); Mon, 24 Aug 2020 04:56:02 -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 ABCE1E50; Mon, 24 Aug 2020 10:56:00 +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 27/76] x86/sev-es: Add CPUID handling to #VC handler Date: Mon, 24 Aug 2020 10:54:22 +0200 Message-Id: <20200824085511.7553-28-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 Handle #VC exceptions caused by CPUID instructions. These happen in early boot code when the KASLR code checks for RDTSC. Signed-off-by: Tom Lendacky [ jroedel@suse.de: Adapt to #VC handling framework ] Co-developed-by: Joerg Roedel Signed-off-by: Joerg Roedel Link: https://lore.kernel.org/r/20200724160336.5435-27-joro@8bytes.org --- arch/x86/boot/compressed/sev-es.c | 4 ++++ arch/x86/kernel/sev-es-shared.c | 35 +++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/arch/x86/boot/compressed/sev-es.c b/arch/x86/boot/compressed/sev-es.c index 4f2fc7a85c2f..851d7af29d79 100644 --- a/arch/x86/boot/compressed/sev-es.c +++ b/arch/x86/boot/compressed/sev-es.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -183,6 +184,9 @@ void do_boot_stage2_vc(struct pt_regs *regs, unsigned long exit_code) case SVM_EXIT_IOIO: result = vc_handle_ioio(boot_ghcb, &ctxt); break; + case SVM_EXIT_CPUID: + result = vc_handle_cpuid(boot_ghcb, &ctxt); + break; default: result = ES_UNSUPPORTED; break; diff --git a/arch/x86/kernel/sev-es-shared.c b/arch/x86/kernel/sev-es-shared.c index bae7cf28455b..a6b41910b8ab 100644 --- a/arch/x86/kernel/sev-es-shared.c +++ b/arch/x86/kernel/sev-es-shared.c @@ -432,3 +432,38 @@ static enum es_result vc_handle_ioio(struct ghcb *ghcb, struct es_em_ctxt *ctxt) return ret; } + +static enum es_result vc_handle_cpuid(struct ghcb *ghcb, + struct es_em_ctxt *ctxt) +{ + struct pt_regs *regs = ctxt->regs; + u32 cr4 = native_read_cr4(); + enum es_result ret; + + ghcb_set_rax(ghcb, regs->ax); + ghcb_set_rcx(ghcb, regs->cx); + + if (cr4 & X86_CR4_OSXSAVE) + /* Safe to read xcr0 */ + ghcb_set_xcr0(ghcb, xgetbv(XCR_XFEATURE_ENABLED_MASK)); + else + /* xgetbv will cause #GP - use reset value for xcr0 */ + ghcb_set_xcr0(ghcb, 1); + + ret = sev_es_ghcb_hv_call(ghcb, ctxt, SVM_EXIT_CPUID, 0, 0); + if (ret != ES_OK) + return ret; + + if (!(ghcb_rax_is_valid(ghcb) && + ghcb_rbx_is_valid(ghcb) && + ghcb_rcx_is_valid(ghcb) && + ghcb_rdx_is_valid(ghcb))) + return ES_VMM_ERROR; + + regs->ax = ghcb->save.rax; + regs->bx = ghcb->save.rbx; + regs->cx = ghcb->save.rcx; + regs->dx = ghcb->save.rdx; + + return ES_OK; +} -- 2.28.0