From patchwork Fri Aug 27 03:12:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zixuan Wang X-Patchwork-Id: 12461155 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72323C432BE for ; Fri, 27 Aug 2021 03:12:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5A36D60F6F for ; Fri, 27 Aug 2021 03:12:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244164AbhH0DNo (ORCPT ); Thu, 26 Aug 2021 23:13:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244100AbhH0DNm (ORCPT ); Thu, 26 Aug 2021 23:13:42 -0400 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D55B3C061757 for ; Thu, 26 Aug 2021 20:12:54 -0700 (PDT) Received: by mail-pf1-x449.google.com with SMTP id h10-20020a056a00170a00b003e31c4d9992so2213405pfc.23 for ; Thu, 26 Aug 2021 20:12:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=Qz364tHRAJ7dP0GQYPGE0P0hbUEMQJvVz6b5KTAgE7E=; b=rQtnQCIRf/agAPpzYjcXG7j1LQuaBaIyqiBfub4K8iun6kji5eA+XV6xse6BsRJUDa IQF912b9rKlW/0M82oK3FXHTio3Q43KQD7Y+LQCMjtFzjWrUHL1Og/eMoR1WI4DjkXye PTnpSTAOcpIdUauj+UkAu3V5uQSqN1a/6Z1McR9SgvcCSIEfrmIS3y10pP3tak2703TJ lal1uCCvE6LW/4pDoaEvmundqM2pB1uF8eHaWNlzytipabFTCJ3nqgZh3c+ux05oy9vD RAhB19ALY/gMaItOZTWPhl2bweh+H95emTRZoHIk/JxmQ5gtHYh4gOP6wAy4zofSOWg/ 5itQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Qz364tHRAJ7dP0GQYPGE0P0hbUEMQJvVz6b5KTAgE7E=; b=FDPp0Tfx4HMMcIvLMXSsrYnbmxFTuxtrRqm1j56DF0mta70ndxlbBwhuTAkvWbS1fg hAnvctf/qgnw4Ld5x6Jd3PZyMhAqatAV79lxxExzEulsk1VP5dliOPqlgiK7Z1qpVTIt wZmZYxS1BQ51bSN22MK3mDAf2OVB1j/mN/V51jLEVJSYHSF50GnCVonUWpLNxT6PRHPs RNhF4iSQrOEkEugGO3Aeo9IY+zwzy0P6aNeQjbqeXPvTFq5NKXX2OXLcbwsJ+Yy81Ovp XNyQMZik/nK3l5eB/y2xzBtI369ksriJlg2XvYGnF4lSanJZUKgbVGXlpPwZPuM/vGKA +/XA== X-Gm-Message-State: AOAM531Pr3Y+Ud7UmN4GRtjBRUK59A1fbF/QRx9cswFzP2QCd+Y0Yqra 1ORkUDYBvtBz733JbfapEQyBjIS2AnzJiq4WKTuNKWdHpT+RA2DfDt1We+K6L1xK9Qa6WslBMOa e7ylZpgwcqxrtObprqbZbUHYCa2n7OzKy0VNNzKsgDn8t7vkuOv+XXbrNr0hvjAaIJaR+ X-Google-Smtp-Source: ABdhPJwImo/T88iRiHHkN6lNf2ehUGO8/S3BpeEHG7ohI3SSZjVH0sSHih+5JQrrEya8bG6a8FyMNUJ9/xxRP6JV X-Received: from zxwang42.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2936]) (user=zixuanwang job=sendgmr) by 2002:a62:3887:0:b0:3f2:6c5a:8a92 with SMTP id f129-20020a623887000000b003f26c5a8a92mr4677725pfa.8.1630033974271; Thu, 26 Aug 2021 20:12:54 -0700 (PDT) Date: Fri, 27 Aug 2021 03:12:22 +0000 In-Reply-To: <20210827031222.2778522-1-zixuanwang@google.com> Message-Id: <20210827031222.2778522-18-zixuanwang@google.com> Mime-Version: 1.0 References: <20210827031222.2778522-1-zixuanwang@google.com> X-Mailer: git-send-email 2.33.0.259.gc128427fd7-goog Subject: [kvm-unit-tests PATCH v2 17/17] x86 AMD SEV-ES: Add test cases From: Zixuan Wang To: kvm@vger.kernel.org, pbonzini@redhat.com, drjones@redhat.com Cc: marcorr@google.com, baekhw@google.com, tmroeder@google.com, erdemaktas@google.com, rientjes@google.com, seanjc@google.com, brijesh.singh@amd.com, Thomas.Lendacky@amd.com, varad.gautam@suse.com, jroedel@suse.de, bp@suse.de Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org SEV-ES introduces #VC handler for guest/host communications, e.g., accessing MSR, executing CPUID. This commit provides test cases to check if SEV-ES is enabled and if rdmsr/wrmsr are handled correctly in SEV-ES. Signed-off-by: Zixuan Wang --- x86/amd_sev.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/x86/amd_sev.c b/x86/amd_sev.c index a07a48f..21a491c 100644 --- a/x86/amd_sev.c +++ b/x86/amd_sev.c @@ -13,6 +13,7 @@ #include "libcflat.h" #include "x86/processor.h" #include "x86/amd_sev.h" +#include "msr.h" #define EXIT_SUCCESS 0 #define EXIT_FAILURE 1 @@ -55,10 +56,39 @@ static int test_sev_activation(void) return EXIT_SUCCESS; } +static int test_sev_es_activation(void) +{ + if (!(rdmsr(MSR_SEV_STATUS) & SEV_ES_ENABLED_MASK)) { + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} + +static int test_sev_es_msr(void) +{ + /* + * With SEV-ES, rdmsr/wrmsr trigger #VC exception. If #VC is handled + * correctly, rdmsr/wrmsr should work like without SEV-ES and not crash + * the guest VM. + */ + u64 val = 0x1234; + wrmsr(MSR_TSC_AUX, val); + if(val != rdmsr(MSR_TSC_AUX)) { + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} + int main(void) { int rtn; rtn = test_sev_activation(); report(rtn == EXIT_SUCCESS, "SEV activation test."); + rtn = test_sev_es_activation(); + report(rtn == EXIT_SUCCESS, "SEV-ES activation test."); + rtn = test_sev_es_msr(); + report(rtn == EXIT_SUCCESS, "SEV-ES MSR test."); return report_summary(); }