Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp757600iog; Mon, 13 Jun 2022 12:15:58 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sujao5wVrAOjqXEcEtthvhKDeIjSu2wSm+2YtfR+vV+3wANrexXLG6g8exuWdzhbajDglg X-Received: by 2002:a17:902:eb85:b0:167:987e:2686 with SMTP id q5-20020a170902eb8500b00167987e2686mr433362plg.33.1655147758178; Mon, 13 Jun 2022 12:15:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655147758; cv=none; d=google.com; s=arc-20160816; b=p7MCkfEt1JNGjSkFevRVJqdTT+LLfq2filNZXMgcHdW1DeRLtOpDSMMOaGNf8fKTVX ofoDsUFHhMmIdHS8gc7PRFSTD6ONXmdL9cgNbkip06RkXBzDc9SqU27F6SyfbZA1+rl/ CO+xZum1AfA89qgaE/T74nU1dpXoobhlc5CYp9uojZlwjZiHzLzVkBfs4Z6NZhGtz+Vx nski0F+v95+Jx7IBg4CLSjerCL29jLHaYWmfyXqmuN62Uznf8i2GBMgc4d7U/C1BvBaJ UfT3gBXA0siibFVgLpLfpQd/bwnmR240iOuRlC4IMBxj7u37X5XoroAGA8+NycsUi0gd oK2w== 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=7OtOWClBlY6896CUL2CJUoXz5Le8Wk1ooKrdR/9iq2M=; b=MXBoUhNjn/MIEA8csCwlh/Klh3CY2Fmj9MMHwtOhKUCuhtKDxequKtEM0VLCvV/cft 7RVUsFSYjC0JUE5CsmvSoegX9624vjeU07aB4jw91MOGAgkmBPDUdm8fgAflMsGKRurS AtiIo8f28RjCSKdgvDxNtNNT7/QQ5aiavBbPnOTvx+YYE7OBK/9cvLfN5hR9p63TvaFU BuYVCfc5Ag4Sz3oh9+eYNZNKIiulu7qalHax3TWHF9ahSoN33L9jTk8M1r2eZmz1m7iv GQg205pkp5qIzR6ev4RFCV2NBvMWP8NSocuQvKNoUb0HMEnCqrRPuRs91LxtIfRV/9q1 qK8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=xp0mmWyE; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; 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 z15-20020a655a4f000000b003fb9e704893si10515267pgs.796.2022.06.13.12.15.42; Mon, 13 Jun 2022 12:15:58 -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=xp0mmWyE; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; 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 S1346139AbiFMTLi (ORCPT + 99 others); Mon, 13 Jun 2022 15:11:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347719AbiFMTIG (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 362303700E; Mon, 13 Jun 2022 10:04:35 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id E371821BD6; 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=7OtOWClBlY6896CUL2CJUoXz5Le8Wk1ooKrdR/9iq2M=; b=xp0mmWyEfPaQm+HgDu9ihr5D73ZTYPe7veggysbfEXnAI4CVVUVIEpa1f0FyNiFf2lYknH g1KdLbOxKBEkWIixu7mecIMyTD4oM/KDOwd+1A6knCkskwZmPItQlXudcI7ewSGsysMtqI /Kp+RhmamogNS2jELlF7u+F8cLiQN9g= 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=7OtOWClBlY6896CUL2CJUoXz5Le8Wk1ooKrdR/9iq2M=; b=jM7YYjvLtx6DNW15GGyf0dqs+QE8ufAtcH3oKUItx8uYtMOiFYhJ7OHtlPwP/K7AS862hF 2iooN3q0V9F0fpCw== Received: from vasant-suse.fritz.box (unknown [10.163.24.178]) by relay2.suse.de (Postfix) with ESMTP id AC69E2C141; 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 4/4] KVM SEV-ES: Add tests to validate VC handling for IO instructions Date: Mon, 13 Jun 2022 19:04:20 +0200 Message-Id: <20220613170420.18521-5-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 issuing an IO instruction. 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 | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/arch/x86/tests/sev-test-vc.c b/arch/x86/tests/sev-test-vc.c index 629aa0ca1c86..33ca761bf9cb 100644 --- a/arch/x86/tests/sev-test-vc.c +++ b/arch/x86/tests/sev-test-vc.c @@ -8,7 +8,9 @@ #include #include #include +#include #include +#include #include #include @@ -101,11 +103,36 @@ static void sev_es_nae_dr7_rw(struct kunit *test) native_set_debugreg(7, native_get_debugreg(7))); } +static void sev_es_nae_ioio(struct kunit *test) +{ + unsigned long port = 0x80; + char val = 0; + + check_op(test, SVM_EXIT_IOIO, val = inb(port)); + check_op(test, SVM_EXIT_IOIO, outb(val, port)); + check_op(test, SVM_EXIT_IOIO, insb(port, &val, sizeof(val))); + check_op(test, SVM_EXIT_IOIO, outsb(port, &val, sizeof(val))); +} + +static void sev_es_nae_mmio(struct kunit *test) +{ + unsigned long lapic_ver_pa = APIC_DEFAULT_PHYS_BASE + APIC_LVR; + unsigned long __iomem *lapic = ioremap(lapic_ver_pa, 0x4); + unsigned long lapic_version = 0; + + check_op(test, SVM_VMGEXIT_MMIO_READ, lapic_version = *lapic); + check_op(test, SVM_VMGEXIT_MMIO_WRITE, *lapic = lapic_version); + + iounmap(lapic); +} + 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), + KUNIT_CASE(sev_es_nae_ioio), + KUNIT_CASE(sev_es_nae_mmio), {} }; -- 2.32.0