From patchwork Fri Dec 12 16:06:14 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 5483701 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 30923BEEBA for ; Fri, 12 Dec 2014 16:06:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 25656201C8 for ; Fri, 12 Dec 2014 16:06:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 015772017D for ; Fri, 12 Dec 2014 16:06:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935062AbaLLQGl (ORCPT ); Fri, 12 Dec 2014 11:06:41 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47869 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935037AbaLLQG2 (ORCPT ); Fri, 12 Dec 2014 11:06:28 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sBCG6S9g008494 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Fri, 12 Dec 2014 11:06:28 -0500 Received: from hawk.usersys.redhat.com (dhcp-1-108.brq.redhat.com [10.34.1.108]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id sBCG6Kml007006; Fri, 12 Dec 2014 11:06:27 -0500 From: Andrew Jones To: kvm@vger.kernel.org Subject: [PATCH 07/10] x86: xsave: use report Date: Fri, 12 Dec 2014 17:06:14 +0100 Message-Id: <1418400377-17388-8-git-send-email-drjones@redhat.com> In-Reply-To: <1418400377-17388-1-git-send-email-drjones@redhat.com> References: <1418400377-17388-1-git-send-email-drjones@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Andrew Jones --- x86/xsave.c | 150 +++++++++++++++++++++++------------------------------------- 1 file changed, 56 insertions(+), 94 deletions(-) diff --git a/x86/xsave.c b/x86/xsave.c index cd2cdceefca26..e471835b42fd9 100644 --- a/x86/xsave.c +++ b/x86/xsave.c @@ -65,134 +65,103 @@ uint64_t get_supported_xcr0(void) #define XSTATE_SSE 0x2 #define XSTATE_YMM 0x4 -static int total_tests, fail_tests; - -void pass_if(int condition) -{ - total_tests ++; - if (condition) - printf("Pass!\n"); - else { - printf("Fail!\n"); - fail_tests ++; - } -} - void test_xsave(void) { unsigned long cr4; uint64_t supported_xcr0; uint64_t test_bits; u64 xcr0; - int r; printf("Legal instruction testing:\n"); + supported_xcr0 = get_supported_xcr0(); printf("Supported XCR0 bits: 0x%x\n", supported_xcr0); - printf("Check minimal XSAVE required bits: "); test_bits = XSTATE_FP | XSTATE_SSE; - pass_if((supported_xcr0 & test_bits) == test_bits); + report("Check minimal XSAVE required bits", + (supported_xcr0 & test_bits) == test_bits); - printf("Set CR4 OSXSAVE: "); cr4 = read_cr4(); - r = write_cr4_checking(cr4 | X86_CR4_OSXSAVE); - pass_if(r == 0); - - printf("Check CPUID.1.ECX.OSXSAVE - expect 1: "); - pass_if(check_cpuid_1_ecx(CPUID_1_ECX_OSXSAVE)); + report("Set CR4 OSXSAVE", write_cr4_checking(cr4 | X86_CR4_OSXSAVE) == 0); + report("Check CPUID.1.ECX.OSXSAVE - expect 1", + check_cpuid_1_ecx(CPUID_1_ECX_OSXSAVE)); - printf(" Legal tests\n"); - printf(" xsetbv(XCR_XFEATURE_ENABLED_MASK, XSTATE_FP): "); + printf("\tLegal tests\n"); test_bits = XSTATE_FP; - r = xsetbv_checking(XCR_XFEATURE_ENABLED_MASK, test_bits); - pass_if(r == 0); - printf(" xsetbv(XCR_XFEATURE_ENABLED_MASK, " - "XSTATE_FP | XSTATE_SSE): "); + report("\t\txsetbv(XCR_XFEATURE_ENABLED_MASK, XSTATE_FP)", + xsetbv_checking(XCR_XFEATURE_ENABLED_MASK, test_bits) == 0); + test_bits = XSTATE_FP | XSTATE_SSE; - r = xsetbv_checking(XCR_XFEATURE_ENABLED_MASK, test_bits); - pass_if(r == 0); - printf(" xgetbv(XCR_XFEATURE_ENABLED_MASK): "); - r = xgetbv_checking(XCR_XFEATURE_ENABLED_MASK, &xcr0); - pass_if(r == 0); - printf(" Illegal tests\n"); - printf(" xsetbv(XCR_XFEATURE_ENABLED_MASK, 0) - expect #GP: "); + report("\t\txsetbv(XCR_XFEATURE_ENABLED_MASK, XSTATE_FP | XSTATE_SSE)", + xsetbv_checking(XCR_XFEATURE_ENABLED_MASK, test_bits) == 0); + report(" xgetbv(XCR_XFEATURE_ENABLED_MASK)", + xgetbv_checking(XCR_XFEATURE_ENABLED_MASK, &xcr0) == 0); + + printf("\tIllegal tests\n"); test_bits = 0; - r = xsetbv_checking(XCR_XFEATURE_ENABLED_MASK, test_bits); - pass_if(r == GP_VECTOR); - printf(" xsetbv(XCR_XFEATURE_ENABLED_MASK, XSTATE_SSE) " - "- expect #GP: "); + report("\t\txsetbv(XCR_XFEATURE_ENABLED_MASK, 0) - expect #GP", + xsetbv_checking(XCR_XFEATURE_ENABLED_MASK, test_bits) == GP_VECTOR); + test_bits = XSTATE_SSE; - r = xsetbv_checking(XCR_XFEATURE_ENABLED_MASK, test_bits); - pass_if(r == GP_VECTOR); + report("\t\txsetbv(XCR_XFEATURE_ENABLED_MASK, XSTATE_SSE) - expect #GP", + xsetbv_checking(XCR_XFEATURE_ENABLED_MASK, test_bits) == GP_VECTOR); + if (supported_xcr0 & XSTATE_YMM) { - printf(" xsetbv(XCR_XFEATURE_ENABLED_MASK, " - "XSTATE_YMM) - expect #GP: "); test_bits = XSTATE_YMM; - r = xsetbv_checking(XCR_XFEATURE_ENABLED_MASK, test_bits); - pass_if(r == GP_VECTOR); - printf(" xsetbv(XCR_XFEATURE_ENABLED_MASK, " - "XSTATE_FP | XSTATE_YMM) - expect #GP: "); + report("\t\txsetbv(XCR_XFEATURE_ENABLED_MASK, XSTATE_YMM) - expect #GP", + xsetbv_checking(XCR_XFEATURE_ENABLED_MASK, test_bits) == GP_VECTOR); + test_bits = XSTATE_FP | XSTATE_YMM; - r = xsetbv_checking(XCR_XFEATURE_ENABLED_MASK, test_bits); - pass_if(r == GP_VECTOR); + report("\t\txsetbv(XCR_XFEATURE_ENABLED_MASK, XSTATE_FP | XSTATE_YMM) - expect #GP", + xsetbv_checking(XCR_XFEATURE_ENABLED_MASK, test_bits) == GP_VECTOR); } - printf(" xsetbv(XCR_XFEATURE_ILLEGAL_MASK, XSTATE_FP) " - "- expect #GP: "); + test_bits = XSTATE_SSE; - r = xsetbv_checking(XCR_XFEATURE_ILLEGAL_MASK, test_bits); - pass_if(r == GP_VECTOR); - printf(" xgetbv(XCR_XFEATURE_ILLEGAL_MASK, XSTATE_FP) " - "- expect #GP: "); + report("\t\txsetbv(XCR_XFEATURE_ILLEGAL_MASK, XSTATE_FP) - expect #GP", + xsetbv_checking(XCR_XFEATURE_ILLEGAL_MASK, test_bits) == GP_VECTOR); + test_bits = XSTATE_SSE; - r = xsetbv_checking(XCR_XFEATURE_ILLEGAL_MASK, test_bits); - pass_if(r == GP_VECTOR); + report("\t\txgetbv(XCR_XFEATURE_ILLEGAL_MASK, XSTATE_FP) - expect #GP", + xsetbv_checking(XCR_XFEATURE_ILLEGAL_MASK, test_bits) == GP_VECTOR); - printf("Unset CR4 OSXSAVE: "); cr4 &= ~X86_CR4_OSXSAVE; - r = write_cr4_checking(cr4); - pass_if(r == 0); - printf("Check CPUID.1.ECX.OSXSAVE - expect 0: "); - pass_if(check_cpuid_1_ecx(CPUID_1_ECX_OSXSAVE) == 0); - printf(" Illegal tests:\n"); - printf(" xsetbv(XCR_XFEATURE_ENABLED_MASK, XSTATE_FP) - expect #UD: "); + report("Unset CR4 OSXSAVE", write_cr4_checking(cr4) == 0); + report("Check CPUID.1.ECX.OSXSAVE - expect 0", + check_cpuid_1_ecx(CPUID_1_ECX_OSXSAVE) == 0); + + printf("\tIllegal tests:\n"); test_bits = XSTATE_FP; - r = xsetbv_checking(XCR_XFEATURE_ENABLED_MASK, test_bits); - pass_if(r == UD_VECTOR); - printf(" xsetbv(XCR_XFEATURE_ENABLED_MASK, " - "XSTATE_FP | XSTATE_SSE) - expect #UD: "); + report("\t\txsetbv(XCR_XFEATURE_ENABLED_MASK, XSTATE_FP) - expect #UD", + xsetbv_checking(XCR_XFEATURE_ENABLED_MASK, test_bits) == UD_VECTOR); + test_bits = XSTATE_FP | XSTATE_SSE; - r = xsetbv_checking(XCR_XFEATURE_ENABLED_MASK, test_bits); - pass_if(r == UD_VECTOR); - printf(" Illegal tests:\n"); - printf(" xgetbv(XCR_XFEATURE_ENABLED_MASK) - expect #UD: "); - r = xgetbv_checking(XCR_XFEATURE_ENABLED_MASK, &xcr0); - pass_if(r == UD_VECTOR); + report("\t\txsetbv(XCR_XFEATURE_ENABLED_MASK, XSTATE_FP | XSTATE_SSE) - expect #UD", + xsetbv_checking(XCR_XFEATURE_ENABLED_MASK, test_bits) == UD_VECTOR); + + printf("\tIllegal tests:\n"); + report("\txgetbv(XCR_XFEATURE_ENABLED_MASK) - expect #UD", + xgetbv_checking(XCR_XFEATURE_ENABLED_MASK, &xcr0) == UD_VECTOR); } void test_no_xsave(void) { unsigned long cr4; u64 xcr0; - int r; - printf("Check CPUID.1.ECX.OSXSAVE - expect 0: "); - pass_if(check_cpuid_1_ecx(CPUID_1_ECX_OSXSAVE) == 0); + report("Check CPUID.1.ECX.OSXSAVE - expect 0", + check_cpuid_1_ecx(CPUID_1_ECX_OSXSAVE) == 0); printf("Illegal instruction testing:\n"); - printf("Set OSXSAVE in CR4 - expect #GP: "); cr4 = read_cr4(); - r = write_cr4_checking(cr4 | X86_CR4_OSXSAVE); - pass_if(r == GP_VECTOR); + report("Set OSXSAVE in CR4 - expect #GP", + write_cr4_checking(cr4 | X86_CR4_OSXSAVE) == GP_VECTOR); - printf("Execute xgetbv - expect #UD: "); - r = xgetbv_checking(XCR_XFEATURE_ENABLED_MASK, &xcr0); - pass_if(r == UD_VECTOR); + report("Execute xgetbv - expect #UD", + xgetbv_checking(XCR_XFEATURE_ENABLED_MASK, &xcr0) == UD_VECTOR); - printf("Execute xsetbv - expect #UD: "); - r = xsetbv_checking(XCR_XFEATURE_ENABLED_MASK, 0x3); - pass_if(r == UD_VECTOR); + report("Execute xsetbv - expect #UD", + xsetbv_checking(XCR_XFEATURE_ENABLED_MASK, 0x3) == UD_VECTOR); } int main(void) @@ -205,12 +174,5 @@ int main(void) printf("CPU don't has XSAVE feature\n"); test_no_xsave(); } - printf("Total test: %d\n", total_tests); - if (fail_tests == 0) - printf("ALL PASS!\n"); - else { - printf("Fail %d tests.\n", fail_tests); - return 1; - } - return 0; + return report_summary(); }