Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1703363ybh; Tue, 14 Jul 2020 05:16:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGorQCM12qaY66rhMcruF8YVdTV8zx4sX2GpzNUCiWOn2wa96+KVS61hnSDe5U3gSiXuCj X-Received: by 2002:a17:906:4e87:: with SMTP id v7mr4176861eju.242.1594728970359; Tue, 14 Jul 2020 05:16:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594728970; cv=none; d=google.com; s=arc-20160816; b=joKu0WgcdxUFutUQr/RZ121GrzyLu9zcbMFT2nk/hGkA48D30x7lQ+Hi025gXlZIwx vBBn8E9YPt+iSwIZhJjjsPxX2WJTxRCcEq5Ls2Dp35V2jIN2DWVrktViVaXFBqasSRPO KT/NHYN/UMuAxobMJX/sLeSQxsgAsLwd9QIq7H7uHJLQ7WDg2fCDvbR05SvnM6oMYKXw Wxwrdw1+uMoAcnwMIY4NWDAG/oAPm+da+82DbVbDae5E/UUWLNJiYQeOB5jE7IJQgLRL Jp54kpc+uHydNenyTPjz3LBnezH9VwQ5cXMBBZlmy+i/pHKsI6/O6de01Uke9mLwFrez FR4g== 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=zsmnrRhHS5Ru81ZdsVevWlCKDi2GL6BkBcF9BOwtwo4=; b=f4Tv7A0f8sHXTNKkUI1tpwkdg9yRn4Ux+EKUsU7kGJcE/TZHmyK1yP18xUpK5OmJoQ zM5CtFVTZufej233IWPZAnnbjUvpVeoPHEyabdTwu+dOJCyAZvGimmO8f2DfY37+XmhK kBuQimLl7R2ZY+MY3bMzV2AqIgvw8gocjtqjQaDPbs5s+r8Mje+1FOx6LuQyp3EO4P0W sqBrZGUsIvhJu2yMg8bkggh1PI/NW9pn4boTmwaCDMdtQn6WmNeXsw+B+owhzpnAo6+C eEJcb7YdRhp6zg4pShlCH864XrHcAVxq15tdctjRUq8L43F68u1IT9DEQI9X4TBV9u3I M38A== 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 e1si11143311ejb.286.2020.07.14.05.15.46; Tue, 14 Jul 2020 05:16:10 -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 S1728400AbgGNMLA (ORCPT + 99 others); Tue, 14 Jul 2020 08:11:00 -0400 Received: from 8bytes.org ([81.169.241.247]:52886 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728263AbgGNMKt (ORCPT ); Tue, 14 Jul 2020 08:10:49 -0400 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 10C829CE; Tue, 14 Jul 2020 14:10: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 v4 26/75] x86/sev-es: Add CPUID handling to #VC handler Date: Tue, 14 Jul 2020 14:08:28 +0200 Message-Id: <20200714120917.11253-27-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 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 --- 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 66d60e34eba0..59884926fae5 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_is_valid_rax(ghcb) && + ghcb_is_valid_rbx(ghcb) && + ghcb_is_valid_rcx(ghcb) && + ghcb_is_valid_rdx(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.27.0