Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp771534ioo; Thu, 26 May 2022 14:36:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzoyKzgPstI2HdnQWjYhF0Mb+G4yyRaqZr7gKGTWAg2tLC8dpeOCpgUQ7/vxOjXPUKN+IXP X-Received: by 2002:a17:90b:17c1:b0:1e0:2434:8475 with SMTP id me1-20020a17090b17c100b001e024348475mr4761237pjb.42.1653600994788; Thu, 26 May 2022 14:36:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653600994; cv=none; d=google.com; s=arc-20160816; b=dADGIpyKZmv8+lDAa/1HS19JWmNgy8vWcg32y5MoPRz+6yfLExKgkYoiJtf3Ua66/a dIEt75p+D53hC97B537hVHdx47EjwYQnjMA6MUopnx2yMjqmTtEtczs0E4od/cdH1sOm bWf7Ls1zQ6+cUoCSIJLzCTpNgrxdPh4BkYst+v/gkhX3eu8gEGEqyqYpyPRmmaL6yO27 GXSSApHc+zzw4IaHcDfCRxIM49afBO0ze3kSPfrpO07Gpr3axnIeB90u0HqTOvp/ZlFc uAUNYME+mWtvx5/HIFYwniUgHsZoC8XiFa1Lh4M+HLBKdLAmRps2uXH/IzIBkbDrekv5 T7vA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=lupwoiIHSZjNm5eHKqOy8JlCyVBIv5yC/9yPkxpNszU=; b=v4s27laHaY3M5AujcCv4a6gJHhkKX8uyzhmdiEyGuMMKuZ6sIPpmkEcjnJSeO/9ye7 RuJVXtilAmYWYSeMYRsOybAbVQOA8jCMFSnJ2G5cJ2JDAhzFTwn3JoDCtognsdwEtlcB Ac3AxxhHRG21WuEYQ+n63XBPjnADZ10mLP/S3cDGLWev3De/JdgZ/S9BiGtVDEhILZei RFEWdLrWaellCKQLljxOU3I8J1XUJfZF7VfO7YSb9YM7qpjSkCzwPpanisFTQ+kGBGwd MWOPgJfUg42GNbmcaBD9Lvh4saIkfrkCyo56l6EJkMaB7pL0WnnPkyhggRPrn49Qdig3 x9Ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=jfYeSvEJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t185-20020a635fc2000000b003fa0ab460b0si3656683pgb.839.2022.05.26.14.36.23; Thu, 26 May 2022 14:36:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=jfYeSvEJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241817AbiEXU5R (ORCPT + 99 others); Tue, 24 May 2022 16:57:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241778AbiEXU5K (ORCPT ); Tue, 24 May 2022 16:57:10 -0400 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D89D3B033 for ; Tue, 24 May 2022 13:57:09 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id s10-20020a170902a50a00b00162359521c9so2722565plq.23 for ; Tue, 24 May 2022 13:57:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=lupwoiIHSZjNm5eHKqOy8JlCyVBIv5yC/9yPkxpNszU=; b=jfYeSvEJH6TVFdfqmAQGSWOVWnNJxEe8cvgyyfm7cJc+NUP0MamvlUzq+Or2qri1wU tXuJkNgi6gdZs20UxzlO9LckiD8gc1ewFWvKwSy514IxXuISxbq0aAWC/ABsy6kZE5jD ywG609MHA9DTgBoKAGUTNUXREoy3qoWGjuQyrkGUf/KDQnBvOKpaDNeMhUKcKUitR3nf +8F7Ls6sdcSKGsol/j137oy6quro/SCyWZqexkweR/2S0NHOMoZX7NNRHMElgAFUJwml TmsG+kIXG4KHI4Rr2ZP7pt2sUiXs3v5NmmfRRTdgUx8UvNYCYne0bNyntNxpJEAnnHXQ An5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=lupwoiIHSZjNm5eHKqOy8JlCyVBIv5yC/9yPkxpNszU=; b=Lesua5dCh5wKu36OZuNBaLzETMrjf11UE6rQvxIkl+qYbywhcMQtiqLGFt7k5NHKyA 5gLTrm9Q1/OqbFbUFmunZ0Nuoa6z+sRqX1D9Kq7G09au6ZpdYjmlnZqJzi8gzGrYOz4r EdSMNg1izspXXBAUixx+hCsAg6vx9saKuYTPBHa3fHARAFlsP3HS9EtqFNM1emhIGUNz Q3kZnKInWF7gusDvmRxb/W234bYWIumsxLrtm+9oC/L9JH0jr5QdMRENelSYTf/rrRLv ruaXDgXnuiYeM6TYurLZcM29/6zxOSYsTYXRzQQJpNhS5jlNxPGRdlnre7UGQdvslWMg 4WwA== X-Gm-Message-State: AOAM533fRhu+thRyw53HTx/Pp5PDWEPl6lpuqRHw1WSrO5Obuj9KTRGR 7+VQ9Yj6z2kg1jp3uoivmotMQXqnaWbOz+VF X-Received: from vannapurve2.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:41f8]) (user=vannapurve job=sendgmr) by 2002:a05:6a00:1494:b0:518:b738:5876 with SMTP id v20-20020a056a00149400b00518b7385876mr8184004pfu.58.1653425828701; Tue, 24 May 2022 13:57:08 -0700 (PDT) Date: Tue, 24 May 2022 20:56:45 +0000 In-Reply-To: <20220524205646.1798325-1-vannapurve@google.com> Message-Id: <20220524205646.1798325-3-vannapurve@google.com> Mime-Version: 1.0 References: <20220524205646.1798325-1-vannapurve@google.com> X-Mailer: git-send-email 2.36.1.124.g0e6072fb45-goog Subject: [RFC V1 PATCH 2/3] selftests: kvm: sev: Handle hypercall exit From: Vishal Annapurve To: x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: pbonzini@redhat.com, vkuznets@redhat.com, wanpengli@tencent.com, jmattson@google.com, joro@8bytes.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, shuah@kernel.org, yang.zhong@intel.com, drjones@redhat.com, ricarkol@google.com, aaronlewis@google.com, wei.w.wang@intel.com, kirill.shutemov@linux.intel.com, corbet@lwn.net, hughd@google.com, jlayton@kernel.org, bfields@fieldses.org, akpm@linux-foundation.org, chao.p.peng@linux.intel.com, yu.c.zhang@linux.intel.com, jun.nakajima@intel.com, dave.hansen@intel.com, michael.roth@amd.com, qperret@google.com, steven.price@arm.com, ak@linux.intel.com, david@redhat.com, luto@kernel.org, vbabka@suse.cz, marcorr@google.com, erdemaktas@google.com, pgonda@google.com, nikunj@amd.com, seanjc@google.com, diviness@google.com, maz@kernel.org, dmatlack@google.com, axelrasmussen@google.com, maciej.szmigiero@oracle.com, mizhang@google.com, bgardon@google.com, Vishal Annapurve Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support for forwarding hypercalls to vmm from VC handler. Signed-off-by: Vishal Annapurve --- .../selftests/kvm/lib/x86_64/sev_exitlib.c | 39 ++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/kvm/lib/x86_64/sev_exitlib.c b/tools/testing/selftests/kvm/lib/x86_64/sev_exitlib.c index b3f7b0297e5b..749b9264f90d 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/sev_exitlib.c +++ b/tools/testing/selftests/kvm/lib/x86_64/sev_exitlib.c @@ -199,6 +199,31 @@ static int handle_vc_cpuid(struct ghcb *ghcb, u64 ghcb_gpa, struct ex_regs *regs return 0; } +static int handle_vc_vmmcall(struct ghcb *ghcb, u64 ghcb_gpa, struct ex_regs *regs) +{ + int ret; + + ghcb_set_rax(ghcb, regs->rax); + ghcb_set_rbx(ghcb, regs->rbx); + ghcb_set_rcx(ghcb, regs->rcx); + ghcb_set_rdx(ghcb, regs->rdx); + ghcb_set_rsi(ghcb, regs->rsi); + ghcb_set_cpl(ghcb, 0); + + ret = sev_es_ghcb_hv_call(ghcb, ghcb_gpa, SVM_EXIT_VMMCALL); + if (ret) + return ret; + + if (!ghcb_rax_is_valid(ghcb)) + return 1; + + regs->rax = ghcb->save.rax; + + regs->rip += 3; + + return 0; +} + static int handle_msr_vc_cpuid(struct ex_regs *regs) { uint32_t fn = regs->rax & 0xFFFFFFFF; @@ -239,11 +264,15 @@ static int handle_msr_vc_cpuid(struct ex_regs *regs) int sev_es_handle_vc(void *ghcb, u64 ghcb_gpa, struct ex_regs *regs) { - if (regs->error_code != SVM_EXIT_CPUID) - return 1; + if (regs->error_code == SVM_EXIT_CPUID) { + if (!ghcb) + return handle_msr_vc_cpuid(regs); + + return handle_vc_cpuid(ghcb, ghcb_gpa, regs); + } - if (!ghcb) - return handle_msr_vc_cpuid(regs); + if (regs->error_code == SVM_EXIT_VMMCALL) + return handle_vc_vmmcall(ghcb, ghcb_gpa, regs); - return handle_vc_cpuid(ghcb, ghcb_gpa, regs); + return 1; } -- 2.36.1.124.g0e6072fb45-goog