From patchwork Fri Oct 21 18:49:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 9389907 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 0632060780 for ; Fri, 21 Oct 2016 18:50:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ED4112A28E for ; Fri, 21 Oct 2016 18:50:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DE8D72A291; Fri, 21 Oct 2016 18:50:15 +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 lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7E0832A28E for ; Fri, 21 Oct 2016 18:50:15 +0000 (UTC) Received: from localhost ([::1]:33805 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bxetS-0003NG-Df for patchwork-qemu-devel@patchwork.kernel.org; Fri, 21 Oct 2016 14:50:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42292) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bxetE-0003N5-3P for qemu-devel@nongnu.org; Fri, 21 Oct 2016 14:50:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bxet9-0002sG-7m for qemu-devel@nongnu.org; Fri, 21 Oct 2016 14:50:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51428) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1bxet8-0002rq-Vv for qemu-devel@nongnu.org; Fri, 21 Oct 2016 14:49:55 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 66E6D4E334; Fri, 21 Oct 2016 18:49:53 +0000 (UTC) Received: from localhost (ovpn-116-161.phx2.redhat.com [10.3.116.161]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9LInqbJ018864; Fri, 21 Oct 2016 14:49:52 -0400 From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Fri, 21 Oct 2016 16:49:48 -0200 Message-Id: <1477075788-26632-1-git-send-email-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 21 Oct 2016 18:49:53 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] target-i386: Print warning when mixing [+-]foo and foo=(on|off) X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Igor Mammedov , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Print a warning when mixing [+-]foo and foo=(on|off) in the -cpu argument in a way that will break in the future. Signed-off-by: Eduardo Habkost --- target-i386/cpu.c | 20 ++++++++++++++++++++ tests/test-x86-cpuid-compat.c | 19 ++++++++++++++----- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/target-i386/cpu.c b/target-i386/cpu.c index d95514c..3943382 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -1973,6 +1973,11 @@ static const char *x86_cpu_feature_name(FeatureWord w, int bitnr) */ static GList *plus_features, *minus_features; +static gint compare_string(gconstpointer a, gconstpointer b) +{ + return g_strcmp0(a, b); +} + /* Parse "+feature,-feature,feature=foo" CPU feature string */ static void x86_cpu_parse_featurestr(const char *typename, char *features, @@ -2022,6 +2027,21 @@ static void x86_cpu_parse_featurestr(const char *typename, char *features, feat2prop(featurestr); name = featurestr; + if (g_list_find_custom(plus_features, name, compare_string)) { + error_report("warning: Ambiguous CPU model string. " + "Don't mix both \"+%s\" and \"%s=%s\"\n" + "warning: Compatibility of ambiguous CPU model " + "strings won't be kept on future QEMU versions", + name, name, val); + } + if (g_list_find_custom(minus_features, name, compare_string)) { + error_report("warning: Ambiguous CPU model string. " + "Don't mix both \"-%s\" and \"%s=%s\"\n" + "warning: Compatibility of ambiguous CPU model " + "strings won't be kept on future QEMU versions", + name, name, val); + } + /* Special case: */ if (!strcmp(name, "tsc-freq")) { int64_t tsc_freq; diff --git a/tests/test-x86-cpuid-compat.c b/tests/test-x86-cpuid-compat.c index 260dd27..6cfcaca 100644 --- a/tests/test-x86-cpuid-compat.c +++ b/tests/test-x86-cpuid-compat.c @@ -76,7 +76,7 @@ static void add_cpuid_test(const char *name, const char *cmdline, qtest_add_data_func(name, args, test_cpuid_prop); } -static void test_plus_minus(void) +static void test_plus_minus_subprocess(void) { char *path; @@ -86,9 +86,8 @@ static void test_plus_minus(void) * 3) Old feature names with underscores (e.g. "sse4_2") * should keep working * - * Note: rules 1 and 2 are planned to be removed soon, but we - * need to keep compatibility for a while until we start - * warning users about it. + * Note: rules 1 and 2 are planned to be removed soon, and + * should generate a warning. */ qtest_start("-cpu pentium,-fpu,+fpu,-mce,mce=on,+cx8,cx8=off,+sse4_1,sse4_2=on"); path = get_cpu0_qom_path(); @@ -108,11 +107,21 @@ static void test_plus_minus(void) g_free(path); } +static void test_plus_minus(void) +{ + g_test_trap_subprocess("/x86/cpuid/parsing-plus-minus/subprocess", 0, 0); + g_test_trap_assert_passed(); + g_test_trap_assert_stderr("*Ambiguous CPU model string. Don't mix both \"-mce\" and \"mce=on\"*"); + g_test_trap_assert_stderr("*Ambiguous CPU model string. Don't mix both \"+cx8\" and \"cx8=off\"*"); + g_test_trap_assert_stdout(""); +} + int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); - qtest_add_func("x86/cpuid/parsing-plus-minus", test_plus_minus); + g_test_add_func("/x86/cpuid/parsing-plus-minus/subprocess", test_plus_minus_subprocess); + g_test_add_func("/x86/cpuid/parsing-plus-minus", test_plus_minus); /* Original level values for CPU models: */ add_cpuid_test("x86/cpuid/phenom/level",