Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp793848iog; Mon, 13 Jun 2022 13:08:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+6rzpXk0Hs9+VMFUX5u0qEVNeyhrLU+h+bQIFYvNy5y4igERgY+DLFN7/oShn7WZfmmxL X-Received: by 2002:a63:6a4a:0:b0:3fd:4f3a:3f0f with SMTP id f71-20020a636a4a000000b003fd4f3a3f0fmr1123437pgc.625.1655150902942; Mon, 13 Jun 2022 13:08:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655150902; cv=none; d=google.com; s=arc-20160816; b=qoXejrNwlgwI7o1BoWu5I98/IuuICcYs1ac27YjRaM3wwo+IerLiMb8IcoX+xRpcCh AB5c3LWeW3bwJ/YCIMWwTUgO9Ihr6IPaQTw/6vVILW0Vy8Evzl0jFv4K8PJHXl/835lo of7Tw6XqddsaWo0X8YWM1Tbh7bkhycwMlyMzkTKChyDSA6ElNeu6Tn9WZ+nwkPDHCW0J Thog9g8rRn2WQi2ILrlgukQbcRI/XRDbLrZyVEoSPyoxnQB7PqFui4yqgvwyL2AEQTGw FFAPcS/l51DYGNaCrn1DMc6O49ZRdJYgnw2Uf6w3fkoHv9IEDW81d8e3Xk8CdTrw6XOz M2sA== 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=y7XqRusKLZHg2MAsYj31tc7FKcxL4xcYD2sDGg0rjck=; b=Zrdv1dIRJVwJod4qFHZDClnSXUSmRiEazePVzPBrHCwLC1B3vt8mjMqGH7Xsmw04zc VeR6Qyw2pNyWppXF2dcjRSZPVexH9faK904hRqwzaHvS4Ioeieac9GH7tYMfJotqLDU4 +DkT5uiMwMU2ZTKl2uH5yn5Z0QQIQRkie0+l6lzHpYFR0rfHTCv7AfO03+jPMiSB4sKv 5jklWBonpYUiuz4DKWdyZL7k7QgV0lR4YpoM2xzu02KypxLoeBZegJH+W9zUx4Kyjkmm 5kW0fmp7GShNgeJMUOoqsixZJ28ARQfrLt4ZxqPYXCD0rvyFJ9RAOljSYLytoLR/w8WI b7Ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=1uGoiuXP; dkim=neutral (no key) header.i=@suse.de; 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 j8-20020a170903024800b00168a2e1fea5si10250139plh.392.2022.06.13.13.08.09; Mon, 13 Jun 2022 13:08:22 -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=1uGoiuXP; dkim=neutral (no key) header.i=@suse.de; 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 S1346159AbiFMTLS (ORCPT + 99 others); Mon, 13 Jun 2022 15:11:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347693AbiFMTIG (ORCPT ); Mon, 13 Jun 2022 15:08:06 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2C2D35262; Mon, 13 Jun 2022 10:04:34 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id A5AFB21B20; Mon, 13 Jun 2022 17:04:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1655139873; 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=y7XqRusKLZHg2MAsYj31tc7FKcxL4xcYD2sDGg0rjck=; b=1uGoiuXPUKuk38YwfxQ/jX0RG/8piqm5i7lVWT4hCP6Kcj485+B2yDRsOBGEegq+hHWsF9 4UrOkwPiz6ZTfjOxVhaLrpb3ABC0etDA9HNeCHJF4cEFefQyw5p1lqjVefO5+oO3jgF52E +WoSsMQsf7FC73XBkp4HvAKDnhRVziY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1655139873; 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=y7XqRusKLZHg2MAsYj31tc7FKcxL4xcYD2sDGg0rjck=; b=ETxTyfqN4F2E592ZrQLZuJb45I5sVfYoswnJy5ON37LkEklgxbDy0l4KKTSkvIkE6o6tJh S4FjFoB1G68ubnCA== Received: from vasant-suse.fritz.box (unknown [10.163.24.178]) by relay2.suse.de (Postfix) with ESMTP id 6E6D92C143; Mon, 13 Jun 2022 17:04:33 +0000 (UTC) From: Vasant Karasulli To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: bp@alien8.de, jroedel@suse.de, thomas.lendacky@amd.com, x86@kernel.org, seanjc@google.com, Vasant Karasulli Subject: [PATCH v7 3/4] KVM: SEV-ES: Add tests to validate VC handling for MSR and DR7 register accesses Date: Mon, 13 Jun 2022 19:04:19 +0200 Message-Id: <20220613170420.18521-4-vkarasulli@suse.de> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220613170420.18521-1-vkarasulli@suse.de> References: <20220613170420.18521-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 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. To run these tests, configuration options CONFIG_X86_TESTS and CONFIG_AMD_SEV_ES_TEST_VC have to be enabled. These tests run at the kernel boot time. Result of the test execution can be monitored in the kernel log. 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 900ca357a273..629aa0ca1c86 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 @@ -89,9 +90,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