From patchwork Thu Jun 22 15:27:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFkaW0gS3LEjW3DocWZ?= X-Patchwork-Id: 9804703 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B818360386 for ; Thu, 22 Jun 2017 15:27:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A7DA128696 for ; Thu, 22 Jun 2017 15:27:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9C127286A3; Thu, 22 Jun 2017 15:27:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3B5CD28696 for ; Thu, 22 Jun 2017 15:27:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752075AbdFVP10 (ORCPT ); Thu, 22 Jun 2017 11:27:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41518 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751193AbdFVP1Z (ORCPT ); Thu, 22 Jun 2017 11:27:25 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 87085C0099FD for ; Thu, 22 Jun 2017 15:27:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 87085C0099FD Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=rkrcmar@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 87085C0099FD Received: from potion (unknown [10.43.2.65]) by smtp.corp.redhat.com (Postfix) with SMTP id C0F4D171D3; Thu, 22 Jun 2017 15:27:23 +0000 (UTC) Received: by potion (sSMTP sendmail emulation); Thu, 22 Jun 2017 17:27:22 +0200 From: =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= To: kvm@vger.kernel.org Cc: Paolo Bonzini , P J P Subject: [kvm-unit-tests PATCH 1/2] x86: move syscall MSR testcase to separate test Date: Thu, 22 Jun 2017 17:27:06 +0200 Message-Id: <20170622152707.18399-2-rkrcmar@redhat.com> In-Reply-To: <20170622152707.18399-1-rkrcmar@redhat.com> References: <20170622152707.18399-1-rkrcmar@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 22 Jun 2017 15:27:25 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Paolo Bonzini The next patch will need to force AMD as the vendor. Do not pollute msr.flat with that; make a separate executable. Signed-off-by: Paolo Bonzini Signed-off-by: Radim Krčmář --- x86/Makefile.x86_64 | 1 + x86/msr.c | 19 ------------------- x86/syscall.c | 28 ++++++++++++++++++++++++++++ x86/unittests.cfg | 3 +++ 4 files changed, 32 insertions(+), 19 deletions(-) create mode 100644 x86/syscall.c diff --git a/x86/Makefile.x86_64 b/x86/Makefile.x86_64 index 30f82a6aeeed..fd34cce5a286 100644 --- a/x86/Makefile.x86_64 +++ b/x86/Makefile.x86_64 @@ -12,6 +12,7 @@ tests = $(TEST_DIR)/access.flat $(TEST_DIR)/apic.flat \ $(TEST_DIR)/pcid.flat $(TEST_DIR)/debug.flat \ $(TEST_DIR)/ioapic.flat $(TEST_DIR)/memory.flat \ $(TEST_DIR)/pku.flat $(TEST_DIR)/hyperv_clock.flat +tests += $(TEST_DIR)/syscall.flat tests += $(TEST_DIR)/svm.flat tests += $(TEST_DIR)/vmx.flat tests += $(TEST_DIR)/tscdeadline_latency.flat diff --git a/x86/msr.c b/x86/msr.c index 1d4003144bb5..91351a3e4acd 100644 --- a/x86/msr.c +++ b/x86/msr.c @@ -94,23 +94,6 @@ static void test_msr_rw(int msr_index, unsigned long long input, unsigned long l report("%s", expected == r, sptr); } -static void test_syscall_lazy_load(void) -{ -#ifdef __x86_64__ - extern void syscall_target(); - u16 cs = read_cs(), ss = read_ss(); - ulong tmp; - - wrmsr(MSR_EFER, rdmsr(MSR_EFER) | EFER_SCE); - wrmsr(MSR_LSTAR, (ulong)syscall_target); - wrmsr(MSR_STAR, (uint64_t)cs << 32); - asm volatile("pushf; syscall; syscall_target: popf" : "=c"(tmp) : : "r11"); - write_ss(ss); - // will crash horribly if broken - report("MSR_*STAR eager loading", true); -#endif -} - int main(int ac, char **av) { int i, j; @@ -124,8 +107,6 @@ int main(int ac, char **av) } } - test_syscall_lazy_load(); - return report_summary(); } diff --git a/x86/syscall.c b/x86/syscall.c new file mode 100644 index 000000000000..d791edd6155d --- /dev/null +++ b/x86/syscall.c @@ -0,0 +1,28 @@ +/* msr tests */ + +#include "libcflat.h" +#include "processor.h" +#include "msr.h" +#include "desc.h" + +static void test_syscall_lazy_load(void) +{ + extern void syscall_target(); + u16 cs = read_cs(), ss = read_ss(); + ulong tmp; + + wrmsr(MSR_EFER, rdmsr(MSR_EFER) | EFER_SCE); + wrmsr(MSR_LSTAR, (ulong)syscall_target); + wrmsr(MSR_STAR, (uint64_t)cs << 32); + asm volatile("pushf; syscall; syscall_target: popf" : "=c"(tmp) : : "r11"); + write_ss(ss); + // will crash horribly if broken + report("MSR_*STAR eager loading", true); +} + +int main(int ac, char **av) +{ + test_syscall_lazy_load(); + + return report_summary(); +} diff --git a/x86/unittests.cfg b/x86/unittests.cfg index 3f3ad2a7daa5..2575ae6b3d5b 100644 --- a/x86/unittests.cfg +++ b/x86/unittests.cfg @@ -151,6 +151,9 @@ file = s3.flat [sieve] file = sieve.flat +[syscall] +file = syscall.flat + [tsc] file = tsc.flat extra_params = -cpu kvm64,+rdtscp