Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp4923670ybv; Tue, 11 Feb 2020 06:01:25 -0800 (PST) X-Google-Smtp-Source: APXvYqw2WhB4p7Hc5WOFUJ31jSaOsZhbP1BUEFlIT+hCzGm+U2iA5Y4VZGgrDLRoZh4xDh1UAktC X-Received: by 2002:aca:ec46:: with SMTP id k67mr2843582oih.43.1581429685029; Tue, 11 Feb 2020 06:01:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581429685; cv=none; d=google.com; s=arc-20160816; b=I1kQJXrBRx7m6GpWOZYa1/+vqvkhjpWKMq7NxJ2Ji6EGECd/bV3KNv6qZr0s+YKIIM hkgCYuEB4J/QghNa5GA97qObbk1ilIaVX/ow+u0vWk/b5fUnmSoZeXATqWyz+NpLGNVQ 68ckix3PuJLNdKiH5q/qWtD+pKuvH8GGE+O3Zm2ybaoQuzKlRDQIRPLleW36s7sRYLYx 8ybBk7VqoC+OOHFaKL9d9WNXRb7Q/TC0vmT1db6uqfbGxoJLbiP/XoUG/6rV0pLsULS9 /MhHh86a0ePCj99CSxNPqu3rNm9cybxEhGJzBUyIWQ52BdQWUbkeebAalfEokZeiE07x pqGw== 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=bSrq1P24o/hSF1Sdo4El2lO5oEI6e4dLItDYSYhLYFE=; b=bF1FoFnuVfNLrAb95K++hZaep0Z5BnjtcCKk1nqjireyx6FenP5+eADka8F/TFV3zK Se2w013f6ijlxiqU7epJF2B+Yw8LExJHpJqkcsZc47BKD1Zq72XIaawVGPEzSrFt8JG2 Ei+Kcp1ysFEjTGQiD8Oz6s+5zKnNm8Bl3dPjKE4AqQmC/0mV/kmwCJRahb5CHvRwk7Ep wdPHUulf/oZlNSAqUIbC2WCGJ0wvqRhcenTRLmgV1j58q+SRpC+qBnEgsDVJwemhkx8W R+f7Ggr0ueheuuiFIm8tCRH73Sg2sLj4szzQMThb8ncoRMHcrY/ipFFbkmtc65GzMHrT N7dw== 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 r82si1720274oie.116.2020.02.11.06.01.12; Tue, 11 Feb 2020 06:01:25 -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 S1729751AbgBKNzG (ORCPT + 99 others); Tue, 11 Feb 2020 08:55:06 -0500 Received: from 8bytes.org ([81.169.241.247]:52306 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729587AbgBKNx2 (ORCPT ); Tue, 11 Feb 2020 08:53:28 -0500 Received: by theia.8bytes.org (Postfix, from userid 1000) id 30D16E9A; Tue, 11 Feb 2020 14:53:16 +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 50/62] x86/sev-es: Handle VMMCALL Events Date: Tue, 11 Feb 2020 14:52:44 +0100 Message-Id: <20200211135256.24617-51-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: Tom Lendacky Implement a handler for #VC exceptions caused by VMMCALL instructions. This patch is only a starting point, VMMCALL emulation under SEV-ES needs further hypervisor-specific changes to provide additional state. 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 | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/arch/x86/kernel/sev-es.c b/arch/x86/kernel/sev-es.c index 8f1e84da6fa6..6bd2cae7eb9c 100644 --- a/arch/x86/kernel/sev-es.c +++ b/arch/x86/kernel/sev-es.c @@ -341,6 +341,26 @@ static enum es_result handle_mwait(struct ghcb *ghcb, struct es_em_ctxt *ctxt) return ghcb_hv_call(ghcb, ctxt, SVM_EXIT_MWAIT, 0, 0); } +static enum es_result handle_vmmcall(struct ghcb *ghcb, + struct es_em_ctxt *ctxt) +{ + enum es_result ret; + + ghcb_set_rax(ghcb, ctxt->regs->ax); + ghcb_set_cpl(ghcb, user_mode(ctxt->regs) ? 3 : 0); + + ret = ghcb_hv_call(ghcb, ctxt, SVM_EXIT_VMMCALL, 0, 0); + if (ret != ES_OK) + return ret; + + if (!ghcb_is_valid_rax(ghcb)) + return ES_VMM_ERROR; + + ctxt->regs->ax = ghcb->save.rax; + + return ES_OK; +} + static enum es_result handle_vc_exception(struct es_em_ctxt *ctxt, struct ghcb *ghcb, unsigned long exit_code, @@ -374,6 +394,9 @@ static enum es_result handle_vc_exception(struct es_em_ctxt *ctxt, case SVM_EXIT_MSR: result = handle_msr(ghcb, ctxt); break; + case SVM_EXIT_VMMCALL: + result = handle_vmmcall(ghcb, ctxt); + break; case SVM_EXIT_WBINVD: result = handle_wbinvd(ghcb, ctxt); break; -- 2.17.1