Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1701148ybh; Tue, 14 Jul 2020 05:12:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzXgpNJj/ATVDS3fpctgOpXso/B3PeiZ4lVRy0nl3NGnRrs5TpP/3frGtf7bE5MsNH7dUQ3 X-Received: by 2002:aa7:c816:: with SMTP id a22mr4231295edt.28.1594728754471; Tue, 14 Jul 2020 05:12:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594728754; cv=none; d=google.com; s=arc-20160816; b=oA0FlHXmsBUMArRRGyil1HjdtIVi0RI9Ix8b8QUu4fA/D3KvZuT8u9qGMzWKmd7mQK zSspr6RpJ/gNT+AkAcUYHFIREq7kxiydIE8QFoezifeHIcausj4pItgqlppZg4UcolIK CLjHyDXNlReasd4D2SmhQUt4xLvgZVlvjS6E1q1y2pz3Kr5m01DsWqM90Y76GO5pH2AE DewqNYpI3fNHu1YFUA2HEZnVX2NPujIHZywRaC8Xa1gZ7iozaPpY7DV+z+lmOJCF0seX YqpmxcmOphrBtWIoeqpo5mkA2Je7ELHlqKAbEphEm3GDVjPBmvKPXv7TOXlUvm/37NcK b8MQ== 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=FBw3ev9tK3X7fDE1CfWjhx9rZyfDADF7I+JlPsd1Gro=; b=unlfWf5gFdKr1lBxtCMpFkHxdkMLkEiphgeajy3fzQgwHxAwEsn//yefrtVbvHcuZA z4UCWHZ4YsDXwwoaHk1b+7uU64xZ6qD60HcVgCldvtTFKywD2Y2t8F3ifJs/o8a964pQ bRxQYg2jFjInv3nEojHYJn09aFImtJ1zugmKI4TCMbh4A2F0GkaTJHMP4GcuTIC2rYJW 6V300xX4VS85iqfH3ixCQUeJln1roc2GzN0K9x/xgK8J8CriwCALd0ER3CVZ28YxGXG7 fCDJxl+8KHzgUp+rS3m9Wwj/yax8XFh2uzmEZDSwta5RnA06VPa8DvXr4uV96G6anQV0 ZEzg== 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 l9si11459257ejq.76.2020.07.14.05.12.09; Tue, 14 Jul 2020 05:12:34 -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 S1728614AbgGNMLX (ORCPT + 99 others); Tue, 14 Jul 2020 08:11:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728541AbgGNMLQ (ORCPT ); Tue, 14 Jul 2020 08:11:16 -0400 Received: from theia.8bytes.org (8bytes.org [IPv6:2a01:238:4383:600:38bc:a715:4b6d:a889]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40E4DC061755; Tue, 14 Jul 2020 05:11:16 -0700 (PDT) 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 BBDEEFD9; Tue, 14 Jul 2020 14:11:06 +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 61/75] x86/sev-es: Handle VMMCALL Events Date: Tue, 14 Jul 2020 14:09:03 +0200 Message-Id: <20200714120917.11253-62-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 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 541f8994eb21..013dcdfeb613 100644 --- a/arch/x86/kernel/sev-es.c +++ b/arch/x86/kernel/sev-es.c @@ -895,6 +895,26 @@ static enum es_result vc_handle_mwait(struct ghcb *ghcb, return ES_OK; } +static enum es_result vc_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 = sev_es_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 vc_handle_exitcode(struct es_em_ctxt *ctxt, struct ghcb *ghcb, unsigned long exit_code) @@ -928,6 +948,9 @@ static enum es_result vc_handle_exitcode(struct es_em_ctxt *ctxt, case SVM_EXIT_MSR: result = vc_handle_msr(ghcb, ctxt); break; + case SVM_EXIT_VMMCALL: + result = vc_handle_vmmcall(ghcb, ctxt); + break; case SVM_EXIT_WBINVD: result = vc_handle_wbinvd(ghcb, ctxt); break; -- 2.27.0