Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1703987ybh; Tue, 14 Jul 2020 05:17:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyH0LQ5WvKeCeHyqLL13JrHtBU2JBtiIzaJoNuNxVDIm5tmCYq4kIoGYNzsHWIoOu7aj3Oq X-Received: by 2002:a17:906:2296:: with SMTP id p22mr4106917eja.510.1594729024666; Tue, 14 Jul 2020 05:17:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594729024; cv=none; d=google.com; s=arc-20160816; b=LXWXZnPnjI3bj8sn8RP2Z7nHgaScebav2ScAbfD+zxa1Op1dVkvWjkkFCfO4zJ5C/Q jfdQdufj9I6I8O6RMDunx/sZxfkH//60GJA2SqVnG5sMuQhZSmje+NAgyUkFbXB+yc/7 aaSIiocE2qyraIXT8AEgbIhN/UrpgJeRL7xqMjFUaA83Si6U/sfQ2hBOEpj9dJaetAF6 3ngZhOgu2OcYcAwiIz5V+8aVKS7Ro/jEE0+LQ7ggOVYpazuQrk5yTYJwXSnputiOqAen +jvKD98KuRXzHL0WeOr8BjwLYMdbm0P3jVmhMA4qTI1JUqqwbMCY7YhZTHIhrYYmDDD6 JzJg== 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=mxXYBTpC/nLEUNc5dd3tdCVvPtWqUcwaSO3Sbv2SpiQ=; b=FuDp53ugvbPYCTJE0ptJ5hcHf3i2nIcdaZ0ltSTid+QVSgu60LYy4BnzhZq99VjmXM cjcGv2gejmVgQra76FwCWVfKXPsn/LqZxRxFQoyu0ikO60HD1I6EvDQ15/w5gbXx9475 sv5v0HHc3rQ9RErGf+eamuplftyOWHDA6F8NpFYiYtkGCB1upJTX+rJ7WdpIJ/gPp5mp 6oI+nyiacv8z/6lv47IG8caKBRPaCCPLzcxd6NtYrFZCB4tV0Veyo56Ctg9QJRocf91d lvCk7IATmwN3/Zl7P7tV3WuLwf9yp0i1XumveZscnX/CuA+RW6zjR22+j+5zleio98yT 2xgw== 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 92si10776815edj.9.2020.07.14.05.16.39; Tue, 14 Jul 2020 05:17:04 -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 S1728879AbgGNMNb (ORCPT + 99 others); Tue, 14 Jul 2020 08:13:31 -0400 Received: from 8bytes.org ([81.169.241.247]:53376 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728467AbgGNMLI (ORCPT ); Tue, 14 Jul 2020 08:11:08 -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 3E292FC1; Tue, 14 Jul 2020 14:11:02 +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 53/75] x86/sev-es: Handle MSR events Date: Tue, 14 Jul 2020 14:08:55 +0200 Message-Id: <20200714120917.11253-54-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 Implement a handler for #VC exceptions caused by RDMSR/WRMSR instructions. Signed-off-by: Tom Lendacky [ jroedel@suse.de: Adapt to #VC handling infrastructure ] Co-developed-by: Joerg Roedel Signed-off-by: Joerg Roedel --- arch/x86/kernel/sev-es.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/arch/x86/kernel/sev-es.c b/arch/x86/kernel/sev-es.c index bbd839a9d9a1..cbe158091f18 100644 --- a/arch/x86/kernel/sev-es.c +++ b/arch/x86/kernel/sev-es.c @@ -407,6 +407,31 @@ static bool vc_slow_virt_to_phys(struct ghcb *ghcb, struct es_em_ctxt *ctxt, /* Include code shared with pre-decompression boot stage */ #include "sev-es-shared.c" +static enum es_result vc_handle_msr(struct ghcb *ghcb, struct es_em_ctxt *ctxt) +{ + struct pt_regs *regs = ctxt->regs; + enum es_result ret; + u64 exit_info_1; + + /* Is it a WRMSR? */ + exit_info_1 = (ctxt->insn.opcode.bytes[1] == 0x30) ? 1 : 0; + + ghcb_set_rcx(ghcb, regs->cx); + if (exit_info_1) { + ghcb_set_rax(ghcb, regs->ax); + ghcb_set_rdx(ghcb, regs->dx); + } + + ret = sev_es_ghcb_hv_call(ghcb, ctxt, SVM_EXIT_MSR, exit_info_1, 0); + + if ((ret == ES_OK) && (!exit_info_1)) { + regs->ax = ghcb->save.rax; + regs->dx = ghcb->save.rdx; + } + + return ret; +} + /* * This function runs on the first #VC exception after the kernel * switched to virtual addresses. @@ -762,6 +787,9 @@ static enum es_result vc_handle_exitcode(struct es_em_ctxt *ctxt, case SVM_EXIT_IOIO: result = vc_handle_ioio(ghcb, ctxt); break; + case SVM_EXIT_MSR: + result = vc_handle_msr(ghcb, ctxt); + break; case SVM_EXIT_NPF: result = vc_handle_mmio(ghcb, ctxt); break; -- 2.27.0