From patchwork Tue Dec 12 08:35:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 10106489 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 73B72602B3 for ; Tue, 12 Dec 2017 08:35:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 62A8F29783 for ; Tue, 12 Dec 2017 08:35:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 55CDC29813; Tue, 12 Dec 2017 08:35:52 +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 4949C29783 for ; Tue, 12 Dec 2017 08:35:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752172AbdLLIft (ORCPT ); Tue, 12 Dec 2017 03:35:49 -0500 Received: from mga06.intel.com ([134.134.136.31]:50482 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752111AbdLLIfp (ORCPT ); Tue, 12 Dec 2017 03:35:45 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Dec 2017 00:35:44 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,394,1508828400"; d="scan'208";a="186213835" Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.142]) by fmsmga006.fm.intel.com with ESMTP; 12 Dec 2017 00:35:42 -0800 From: Haozhong Zhang To: kvm@vger.kernel.org Cc: Paolo Bonzini , Eduardo Habkost , Haozhong Zhang Subject: [kvm-unit-tests PATCH] x86/memory: pass host clwb and clflushopt support information Date: Tue, 12 Dec 2017 16:35:24 +0800 Message-Id: <20171212083524.3765-1-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.14.1 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Intel VMX cannot intercept guest clwb and clflushopt. When clwb and clflushopt are not exposed in guest cpuid, clwb and clflushopt instructions in this test case can still succeed without #UD on the host CPU which has clwb and clflushopt support, though failures with UD are expected. In order to avoid false alarms in such cases, introduce the following two arguments "has_clwb" and "has_clflushopt" to allow users to specify whether clwb and clflushopt are supported on the host CPU. Signed-off-by: Haozhong Zhang --- x86/memory.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/x86/memory.c b/x86/memory.c index cd1eb46..03ff7d3 100644 --- a/x86/memory.c +++ b/x86/memory.c @@ -23,10 +23,29 @@ static void handle_ud(struct ex_regs *regs) regs->rip += isize; } +/* + * Intel VMX cannot intercept guest clwb and clflushopt. When clwb and + * clflushopt are not exposed in guest cpuid, clwb and clflushopt + * instructions in this test case can still succeed without #UD on + * the host CPU which has clwb and clflushopt support. In order to avoid + * false alarms in such cases, introduce the following two arguments + * to allow users to specify whether clwb and clflushopt are supported on + * the host CPU: + * - has_clwb: indicates clwb is supported on the host CPU + * - has_clflushopt: indicates clflushopt is supported on the host CPU + */ int main(int ac, char **av) { struct cpuid cpuid7, cpuid1; int xfail; + int host_has_clwb = 0, host_has_clflushopt = 0; /* 0: unknown */ + int i; + + for (i = 1; i < ac; i++) + if (!strcmp(av[i], "has_clwb")) + host_has_clwb = 1; + else if (!strcmp(av[i], "has_clflushopt")) + host_has_clflushopt = 1; setup_idt(); handle_exception(UD_VECTOR, handle_ud); @@ -63,13 +82,19 @@ int main(int ac, char **av) ud = 0; /* clflushopt (%rbx): */ asm volatile(".byte 0x66, 0x0f, 0xae, 0x3b" : : "b" (&target)); - report_xfail("clflushopt", xfail, ud == 0); + if (host_has_clflushopt) + report("clflushopt", ud == 0); + else + report_xfail("clflushopt", xfail, ud == 0); xfail = !(cpuid7.b & (1U << 24)); /* CLWB */ ud = 0; /* clwb (%rbx): */ asm volatile(".byte 0x66, 0x0f, 0xae, 0x33" : : "b" (&target)); - report_xfail("clwb", xfail, ud == 0); + if (host_has_clwb) + report("clwb", ud == 0); + else + report_xfail("clwb", xfail, ud == 0); ud = 0; /* clwb requires a memory operand, the following is NOT a valid