Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2409438pxp; Fri, 18 Mar 2022 09:56:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxiJmxQt0C+GzsWwVAeBPG+e2tAyJshPmATBoNSnOYtmMJfjqZAkv5vEU/dqLDRU19dWk5w X-Received: by 2002:a05:6402:d0e:b0:418:f011:275e with SMTP id eb14-20020a0564020d0e00b00418f011275emr10280735edb.323.1647622570684; Fri, 18 Mar 2022 09:56:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647622570; cv=none; d=google.com; s=arc-20160816; b=BNmxn/r4tKJhvJxop9WWIGPm09r3TEG+Ruy3nzfb/HUMioVE1bGz8JzhXbI9C+P3ZF fwyQypg8SOVSp/Tl/UajrWp2YSBX50TsSPy41d09WL+tCkPY/DNpJo9MXimivfwwhfqx z8IU5+f+JFZjyF25S2eQuhGcjrFKvxDgH1QTT1Azpdh818xzz7n/2AZPJ1PK/CzwWcut FADVPFSlM6oDB6VOELSkFQ+I1he6yawK95zCSLLVL6ngx7jirrU+cUr5Gp8PJjhumgSN uFH9Nrst66GkxAgLyMInzf3g7rDkA8CgHM1/2rsRxrhdC4Na4T0KhCTZb7/NrorOBe0O jdeg== 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=yiXOPvkp8VR9vIy/4EGvKMzLNQNlSpkWfG8vLlPrxcI=; b=m3SE9SjQszXo4M/V93tPqo1PMA20510lbRyc4MJdVx9sp0OPVX744fSZrnpLUW6um6 RvfW1SVRu8+qF3L0kzYSShvrL0sOxho9RzrV/OTmAxzdKCjP9F5AITVg5EKchhXLTk43 wUWdki+cQhpI8de/lg/G5cjB5ZCswq+fvvCbW960t5wnjOq0fdFiA6Ae7KNQ4PQAL8A3 sDQfUPSaUoyhcB/3IzFFOQYMz+a10kNoro0VTvA8+w7hC9Tcs20Fad1HVZpDLvJEnNUm TPwkYHCQCVaP0qE5/x0EMEQjetTXKpG6PdOJ2QfpDu4P5kf2RmHnYUXE0lEcb0bI8khc 6C1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=NqHEpkmZ; 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 f11-20020a170906738b00b006df76385c8fsi1485500ejl.303.2022.03.18.09.55.45; Fri, 18 Mar 2022 09:56:10 -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=NqHEpkmZ; 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 S229792AbiCRKtN (ORCPT + 99 others); Fri, 18 Mar 2022 06:49:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235474AbiCRKsJ (ORCPT ); Fri, 18 Mar 2022 06:48:09 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EDDF22C578B; Fri, 18 Mar 2022 03:46:51 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 857121F390; 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=yiXOPvkp8VR9vIy/4EGvKMzLNQNlSpkWfG8vLlPrxcI=; b=NqHEpkmZiI4BlagA2vqZUR2q+FhmA3x5WzQBWJMWALNPtjW2CdLtVldVyXNy++5CFJqA0f 1k8qzeGEu/jWrTixXBfKSsarPAvl8kX3dOnyMBi5ePyXFzspmN1xuhfQ3gKq7S7unqYsC2 6jTUzkkCvUDE6NpbL4zeBvwnGxcyvcc= 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=yiXOPvkp8VR9vIy/4EGvKMzLNQNlSpkWfG8vLlPrxcI=; b=SoMUvQXsytd/+YPxpqes/k46jUQIH/ujkxBjScmGBBefcSe8Z9rNiTj1b2WSgb4QhQgyOr eg67SgX9gI8hgrBg== Received: from vasant-suse.suse.de (unknown [10.163.24.178]) by relay2.suse.de (Postfix) with ESMTP id 46AB0A3B81; Fri, 18 Mar 2022 10:46:50 +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 4/4] x86/tests: Add tests for AMD SEV-ES #VC handling Date: Fri, 18 Mar 2022 11:46:46 +0100 Message-Id: <20220318104646.8313-5-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 IO instructions. 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. 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 b27b9f114a12..d0e742e2bf9f 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 @@ -111,11 +113,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