Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp411425pxp; Sat, 19 Mar 2022 06:06:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxwyGpte9rTBbnrQnuj+0zdIVjhzgyRz0vz7JiQsPqTEUXXoBsQDl4CgIVMtqKufmpJns2y X-Received: by 2002:a17:902:7606:b0:153:8441:b5d0 with SMTP id k6-20020a170902760600b001538441b5d0mr4210330pll.120.1647695178211; Sat, 19 Mar 2022 06:06:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647695178; cv=none; d=google.com; s=arc-20160816; b=YDDEqHNNAe6hdn2n4d1H6XyMxv7qZx6z1xcDwrR7vfSW/3fULtVONHorpSkNt8aEyk JXZCZ51MYkqi4es8hUx8Ex+HaLPQcIuYkB7872a/erXCFESkd8V4NgmZUR903QSXRE/z VMxLNQHUtYffUdK/t8qx4SMby9aLdMHyKtjvB8HkMWjzS38uBlJsHt8GUQikvc6kUGDs NSn30BU1xfF5W1ktoJwLKZHOVrndMrdLLsBCPqZCArYoAldCnilUogcnC4yil+8/w0f4 6xdVTSsixpPMxo1s5vE4NmcrMAsU19ySgLkPreNSBQqV+g+ZpSbUC21FwzVo1D1vN+25 kYlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=HDW6ckspDYiNhcLAML+q7aqaHELakVIP97c3x8+sbgQ=; b=jdxuI7iKW/I9bwC28qlw8hAcF+MUC/J2ZywkSn7k8hHAmlEapAQAEzNPfbyEXJiYly oDHp/BrmR5mnsfO19ntBbJU/L73bhIa+j8gNHP5bFPvIaYMTRuPBeVY0MUk2YQ+alyCD psz+EL+yt2Y94mZMIZ2FDFpC90wSMEUZwrL0CLsGS8QW5wN0WaE+PJw3RItMtAqS1Oa0 r3P9tiGsQGSK4A5UKzNgolMguPJm4z0iE31xjvQqG4mCrsjnC57xAiSZxfpAZ2rnu3Od y/oJ9DO3iZ8tDdO1yB4jBffUCM5VC6MeXR6N6ISqLnTyOmGgQTEzqr5Pq/4kK70J/Mj1 oRlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=bD3GFiha; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=iNF91EfW; 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=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r10-20020a056a00216a00b004fa6589243csi2151691pff.220.2022.03.19.06.06.06; Sat, 19 Mar 2022 06:06:18 -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=@suse.de header.s=susede2_rsa header.b=bD3GFiha; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=iNF91EfW; 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=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235344AbiCRKtW (ORCPT + 99 others); Fri, 18 Mar 2022 06:49:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235473AbiCRKsJ (ORCPT ); Fri, 18 Mar 2022 06:48:09 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 998432C8B78; Fri, 18 Mar 2022 03:46:51 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 3AF1E21106; Fri, 18 Mar 2022 10:46:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1647600410; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HDW6ckspDYiNhcLAML+q7aqaHELakVIP97c3x8+sbgQ=; b=bD3GFihajRpqiBoblzKTilmYKrC4TEejWxqkWKHbF11HBR5eIXdrabjiuGmPggyhV0Nd+L 9vOXLXhotko8p3LATl7oQyldOhkq4gnY3FBSIRllTCnuY6pAgJcE8oqN8+Z85vhEb1Yl7e HvUcG3RGCprynmcCLuSEkZaQWfcPL70= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1647600410; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HDW6ckspDYiNhcLAML+q7aqaHELakVIP97c3x8+sbgQ=; b=iNF91EfWP7JHo2u6EYID/1CayhJ4tYRhsbyFir4p2BLg9RxzXBIKs7THQViZS45ksSNdJT DONeTnoiMjhzXsAg== Received: from vasant-suse.suse.de (unknown [10.163.24.178]) by relay2.suse.de (Postfix) with ESMTP id D50C8A3B83; Fri, 18 Mar 2022 10:46:49 +0000 (UTC) From: Vasant Karasulli To: linux-kernel@vger.kernel.org, jroedel@suse.de, kvm@vger.kernel.org Cc: bp@alien8.de, x86@kernel.org, thomas.lendacky@amd.com, varad.gautam@suse.com, Vasant Karasulli Subject: [PATCH v6 3/4] x86/tests: Add tests for AMD SEV-ES #VC handling Date: Fri, 18 Mar 2022 11:46:45 +0100 Message-Id: <20220318104646.8313-4-vkarasulli@suse.de> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220318104646.8313-1-vkarasulli@suse.de> References: <20220318104646.8313-1-vkarasulli@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 KUnit based tests to validate Linux's VC handling for instructions accessing registers such as MSR and DR7. These tests: 1. install a kretprobe on the #VC handler (sev_es_ghcb_hv_call, to access GHCB before/after the resulting VMGEXIT). 2. trigger an NAE by accessing either MSR or DR7. 3. check that the kretprobe was hit with the right exit_code available in GHCB. Signed-off-by: Vasant Karasulli --- arch/x86/tests/sev-test-vc.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/arch/x86/tests/sev-test-vc.c b/arch/x86/tests/sev-test-vc.c index 9d415b9708dc..b27b9f114a12 100644 --- a/arch/x86/tests/sev-test-vc.c +++ b/arch/x86/tests/sev-test-vc.c @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -99,9 +100,22 @@ static void sev_es_nae_wbinvd(struct kunit *test) check_op(test, SVM_EXIT_WBINVD, wbinvd()); } +static void sev_es_nae_msr(struct kunit *test) +{ + check_op(test, SVM_EXIT_MSR, __rdmsr(MSR_IA32_TSC)); +} + +static void sev_es_nae_dr7_rw(struct kunit *test) +{ + check_op(test, SVM_EXIT_WRITE_DR7, + native_set_debugreg(7, native_get_debugreg(7))); +} + static struct kunit_case sev_es_vc_testcases[] = { KUNIT_CASE(sev_es_nae_cpuid), KUNIT_CASE(sev_es_nae_wbinvd), + KUNIT_CASE(sev_es_nae_msr), + KUNIT_CASE(sev_es_nae_dr7_rw), {} }; -- 2.32.0