From patchwork Sat Jul 29 00:36:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13332826 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E2523C001DE for ; Sat, 29 Jul 2023 00:39:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Reply-To:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID :References:Mime-Version:In-Reply-To:Date:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=xTTNp28C4H/6VeBg1sFpwnt6T3/BJr4DKe+z+tWt1jQ=; b=4DbEqiZV6E9gVd lVNxLXXBmLQX/tgYeK/jaPaZ3RKsM/By0plvI/NyAi0zg11UoZJLpkBCUq0XnoXu7tbWAQAIFvJGp vmXFtzVkgxHB92ar8ATeE4zxEZfBihZO+SCabzeyz6wfAH8PzVGxmbP4o2NaXCdrYnG3BBwQSIxDP 7LNTmI2E0ISKDj9JTLzNWFPyPkRdQZvNu3Vf/Pkphd3vEx8UtEtHcy++iJo2pZ6rPoF7tPEK3tD31 3vKLJYY6scGxjNrZz1iy52WLMv18vOioOHIjPrFYqC1d7kfI8/hxYwlqIhbXP4w/phs7H8gsriooe BJ/gDKVnEuE0KQn0qZpA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qPXyY-005dVT-19; Sat, 29 Jul 2023 00:38:30 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qPXxp-005d6I-09 for linux-arm-kernel@lists.infradead.org; Sat, 29 Jul 2023 00:37:46 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d0d27cd9db9so4686344276.0 for ; Fri, 28 Jul 2023 17:37:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1690591063; x=1691195863; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=sEeXYbzgZRVXR5YLFfEtQVAczR2xalSf9MVNMlCNrPc=; b=510yqVUE3dJrmTFvMRZmUgU2asXSH3DoFW0Fghi574CxyywdgdIv8Y/diDFElXqlyf jU6KsQmAZf71nxPH+MSup9/mIF1uemfLZbDWceTG4BdkFGD9rcuSR2n/9/0/bk8De/N9 25VV8tPUNlntY3Fv3oSuGTysrAQ/6Y6iPssCSdafPx304Mq6vNfG78lBD+9VDgXAqZkq em5cPcrt8KHlMBFm8vm0+E08hW/a6en+YbJ7ZZAKPcaON8hlum758WmUnT3f2Lw6PHXK Z/cAhUBz5bE1+QxdbyvOLhdn7yGVpm4px3BGKkYiY2arDrtsqFhkBbGF+doEA8uqBr8T 5T5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690591063; x=1691195863; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=sEeXYbzgZRVXR5YLFfEtQVAczR2xalSf9MVNMlCNrPc=; b=L3UxtrrF3hy2BJ4pRfD6LsmPVxGWVgmLJlSl5pNXLYIA67EObeOV7k4EiAqZLELXhy Nxso/SdVE3AcCFbePq2abbOLTodeBt96znAMdY+gwFC5OSsqtnp6hHxTyLXksGLoPRiG fPCkGQ6/HoQ81lv3HBykj9sDMe2mc7KW1RfKq4msoWLr+ovL7rJ1Ulb87Spt2O9dm/rJ mk5Nq+vmgeujruZdhg6YqgO6uFjP0ZKfKUoWD/c8jyNUpgvjugePWYj4TxkvcOtQPGA0 23bSQrSG+pU6yLNeiLb/EytVQRvuUgo6HLO9uNXaeVJgV5HgSnX/yNQOc2isYeKKC6ph Tlpw== X-Gm-Message-State: ABy/qLa+eEVwdxKJI/zbdgk351UpHwr3IxhjDADNZzfXKzxq6/KMegiF 0v0oEnr0oyS+zw9qQGq6cjIONHQ9eHI= X-Google-Smtp-Source: APBJJlEwkcPph7CHbR1bEzAaGPD5/cOkJGSBy5rl0bnU2QuHcdpuQJe7rfYazvWjgBg8IHQMVGr/YJUq7Ok= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:11cb:b0:d16:7ccc:b406 with SMTP id n11-20020a05690211cb00b00d167cccb406mr31838ybu.5.1690591063821; Fri, 28 Jul 2023 17:37:43 -0700 (PDT) Date: Fri, 28 Jul 2023 17:36:39 -0700 In-Reply-To: <20230729003643.1053367-1-seanjc@google.com> Mime-Version: 1.0 References: <20230729003643.1053367-1-seanjc@google.com> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog Message-ID: <20230729003643.1053367-31-seanjc@google.com> Subject: [PATCH v4 30/34] KVM: selftests: Convert VMX's PMU capabilities test to printf guest asserts From: Sean Christopherson To: Paolo Bonzini , Marc Zyngier , Oliver Upton , Christian Borntraeger , Janosch Frank , Claudio Imbrenda Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, Sean Christopherson , Thomas Huth , " =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= " , Aaron Lewis X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230728_173745_098104_7E762F5D X-CRM114-Status: GOOD ( 12.53 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Sean Christopherson Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Convert x86's VMX PMU capabilities test to use printf-based guest asserts. Opportunstically add a helper to do the WRMSR+assert so as to reduce the amount of copy+paste needed to spit out debug information. Signed-off-by: Sean Christopherson --- .../selftests/kvm/x86_64/vmx_pmu_caps_test.c | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c b/tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c index 34efd57c2b32..ba09d5a01c39 100644 --- a/tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c +++ b/tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c @@ -10,6 +10,7 @@ * and check it can be retrieved with KVM_GET_MSR, also test * the invalid LBR formats are rejected. */ +#define USE_GUEST_ASSERT_PRINTF 1 #define _GNU_SOURCE /* for program_invocation_short_name */ #include @@ -52,23 +53,24 @@ static const union perf_capabilities format_caps = { .pebs_format = -1, }; +static void guest_test_perf_capabilities_gp(uint64_t val) +{ + uint8_t vector = wrmsr_safe(MSR_IA32_PERF_CAPABILITIES, val); + + __GUEST_ASSERT(vector == GP_VECTOR, + "Expected #GP for value '0x%llx', got vector '0x%x'", + val, vector); +} + static void guest_code(uint64_t current_val) { - uint8_t vector; int i; - vector = wrmsr_safe(MSR_IA32_PERF_CAPABILITIES, current_val); - GUEST_ASSERT_2(vector == GP_VECTOR, current_val, vector); + guest_test_perf_capabilities_gp(current_val); + guest_test_perf_capabilities_gp(0); - vector = wrmsr_safe(MSR_IA32_PERF_CAPABILITIES, 0); - GUEST_ASSERT_2(vector == GP_VECTOR, 0, vector); - - for (i = 0; i < 64; i++) { - vector = wrmsr_safe(MSR_IA32_PERF_CAPABILITIES, - current_val ^ BIT_ULL(i)); - GUEST_ASSERT_2(vector == GP_VECTOR, - current_val ^ BIT_ULL(i), vector); - } + for (i = 0; i < 64; i++) + guest_test_perf_capabilities_gp(current_val ^ BIT_ULL(i)); GUEST_DONE(); } @@ -95,7 +97,7 @@ static void test_guest_wrmsr_perf_capabilities(union perf_capabilities host_cap) switch (get_ucall(vcpu, &uc)) { case UCALL_ABORT: - REPORT_GUEST_ASSERT_2(uc, "val = 0x%lx, vector = %lu"); + REPORT_GUEST_ASSERT(uc); break; case UCALL_DONE: break;