Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1703733ybh; Tue, 14 Jul 2020 05:16:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxmPeAkvp31uTeDOxfrH5LIOHtoLLjU7g4CXjGVqYTsdZ+/gh3cX5upimRxOEriNkgYpWKp X-Received: by 2002:a17:907:42cb:: with SMTP id nz19mr4082530ejb.447.1594729002754; Tue, 14 Jul 2020 05:16:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594729002; cv=none; d=google.com; s=arc-20160816; b=y/cvpoO3L9/1oy/RLuSUFSOnmbxrLMXzmsnJ0ji48gtuPsCu9ltu3KSGj2EeOel4H6 0zEOCUu8V1lrQOk9bQ1xU0glDUD4+Dk49SXi/tBdAff+QCrj6a+V8G6dDVKKf2Ksi0eT /q5s0c3QNZn6eyVLd1MNx8MLmSrIg5F5LtlL7XnYSaexEbH8V+EG+hmyjr4G0dRG+Pe2 lNbV9T01pJTFbfMqp1FHJ6vEa8olDrVPwZrgcaisvYNuDsFIWKniTI2ezMGvghEPMByS QM/v5ETndDqbLNK1vWWRUEiWp4AWE7UAVKH0QXY2xVi2IqT/upATtDqlg5w9V5ATDsNU sR/w== 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=7YQbOgX20+IKvZ0Eswt50M+AOgIKmKQzw0+4eZIa5Do=; b=hOdZq/teRf00eLpK8yAEcwkCzqmsBPWqLML/c999T7Vo51C8ybcVKQD74iv3p/EHQQ 6p/5FJV999gsrZ/cKFRANGAJr9epR1z8LT3HHgS5CCIsWYzybOCZT+cnv1V86JZHq7jf iQ3xHaFu1ErxKElgJsoHNkTI/Ov6EmqSz705rnkKte3csCN0HBe5F/XTHS7oYDugoQo9 3MsqRNxdbTl2uKly/59iZ0974xbH+f+TMM3hvs2yuxL2oqL2E+IUwu9GbDvHcvikJuBk oOPi3Aua7RKKzbZsd80vE7OadXXmCiZkT2VL5ox8HilplWW/82/k7kSEZ79SK8iMj5fz twqw== 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 u25si11565416ejr.632.2020.07.14.05.16.18; Tue, 14 Jul 2020 05:16:42 -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 S1728853AbgGNMNP (ORCPT + 99 others); Tue, 14 Jul 2020 08:13:15 -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 S1728500AbgGNMLL (ORCPT ); Tue, 14 Jul 2020 08:11:11 -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 934E7FC8; Tue, 14 Jul 2020 14:11:04 +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 57/75] x86/sev-es: Handle RDPMC Events Date: Tue, 14 Jul 2020 14:08:59 +0200 Message-Id: <20200714120917.11253-58-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 RDPMC 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 | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/arch/x86/kernel/sev-es.c b/arch/x86/kernel/sev-es.c index 0e69d498f008..6258bc8074fd 100644 --- a/arch/x86/kernel/sev-es.c +++ b/arch/x86/kernel/sev-es.c @@ -859,6 +859,25 @@ static enum es_result vc_handle_wbinvd(struct ghcb *ghcb, return sev_es_ghcb_hv_call(ghcb, ctxt, SVM_EXIT_WBINVD, 0, 0); } +static enum es_result vc_handle_rdpmc(struct ghcb *ghcb, struct es_em_ctxt *ctxt) +{ + enum es_result ret; + + ghcb_set_rcx(ghcb, ctxt->regs->cx); + + ret = sev_es_ghcb_hv_call(ghcb, ctxt, SVM_EXIT_RDPMC, 0, 0); + if (ret != ES_OK) + return ret; + + if (!(ghcb_is_valid_rax(ghcb) && ghcb_is_valid_rdx(ghcb))) + return ES_VMM_ERROR; + + ctxt->regs->ax = ghcb->save.rax; + ctxt->regs->dx = ghcb->save.rdx; + + return ES_OK; +} + static enum es_result vc_handle_exitcode(struct es_em_ctxt *ctxt, struct ghcb *ghcb, unsigned long exit_code) @@ -876,6 +895,9 @@ static enum es_result vc_handle_exitcode(struct es_em_ctxt *ctxt, case SVM_EXIT_RDTSCP: result = vc_handle_rdtsc(ghcb, ctxt, exit_code); break; + case SVM_EXIT_RDPMC: + result = vc_handle_rdpmc(ghcb, ctxt); + break; case SVM_EXIT_CPUID: result = vc_handle_cpuid(ghcb, ctxt); break; -- 2.27.0