From patchwork Fri Oct 25 02:25:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 1183721 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="dBXRTcF2"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46zp066lqXz9sPk for ; Fri, 25 Oct 2019 13:26:44 +1100 (AEDT) Received: from localhost ([::1]:54524 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNpJI-00022b-Qq for incoming@patchwork.ozlabs.org; Thu, 24 Oct 2019 22:26:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39486) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNpIh-00022O-7L for qemu-devel@nongnu.org; Thu, 24 Oct 2019 22:26:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNpIg-0007YV-4w for qemu-devel@nongnu.org; Thu, 24 Oct 2019 22:26:03 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:25146) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNpIg-0007YF-1k for qemu-devel@nongnu.org; Thu, 24 Oct 2019 22:26:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571970361; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=A4eZCQ4DtIKc5OyXVLekec+UhUjUI8Xusz0XAGuqf8E=; b=dBXRTcF2JtgOICr7tPoiIuz/E6Xg3YKGECCVNVBp4Xd0c7vz8eHdaZODIR8BwNFAepFhD9 G9KYohIEck/nnYXw/d5lcq+1KKL80/3TaoqnrPDPXlIzMEzc1+C/DfcQMjve15WDUQRJ+3 1IQIkqFnQ35Tk1Rr3bZ65gHwpY3m/lo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-9-ZTIH5A0IOdWh1JVzspZWtQ-1; Thu, 24 Oct 2019 22:25:58 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 741271800DC7; Fri, 25 Oct 2019 02:25:57 +0000 (UTC) Received: from localhost (ovpn-116-62.gru2.redhat.com [10.97.116.62]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0734A1001B20; Fri, 25 Oct 2019 02:25:56 +0000 (UTC) From: Eduardo Habkost To: qemu-devel@nongnu.org Subject: [PATCH 1/7] i386: Use g_autofree at x86_cpu_list_entry() Date: Thu, 24 Oct 2019 23:25:47 -0300 Message-Id: <20191025022553.25298-2-ehabkost@redhat.com> In-Reply-To: <20191025022553.25298-1-ehabkost@redhat.com> References: <20191025022553.25298-1-ehabkost@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: ZTIH5A0IOdWh1JVzspZWtQ-1 X-Mimecast-Spam-Score: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Markus Armbruster , Igor Mammedov , Paolo Bonzini , Jiri Denemark , Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Make the code shorter and simpler. Signed-off-by: Eduardo Habkost --- target/i386/cpu.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 0de8a22e1e..5b7c5b1177 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -3976,9 +3976,9 @@ static void x86_cpu_list_entry(gpointer data, gpointer user_data) { ObjectClass *oc = data; X86CPUClass *cc = X86_CPU_CLASS(oc); - char *name = x86_cpu_class_get_model_name(cc); - char *desc = g_strdup(cc->model_description); - char *alias_of = x86_cpu_class_get_alias_of(cc); + g_autofree char *name = x86_cpu_class_get_model_name(cc); + g_autofree char *desc = g_strdup(cc->model_description); + g_autofree char *alias_of = x86_cpu_class_get_alias_of(cc); if (!desc && alias_of) { if (cc->model && cc->model->version == CPU_VERSION_AUTO) { @@ -3992,9 +3992,6 @@ static void x86_cpu_list_entry(gpointer data, gpointer user_data) } qemu_printf("x86 %-20s %-48s\n", name, desc); - g_free(name); - g_free(desc); - g_free(alias_of); } /* list available CPU models and flags */ From patchwork Fri Oct 25 02:25:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 1183725 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="cTwAiM5k"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46zp3B0LHNz9sP4 for ; Fri, 25 Oct 2019 13:29:26 +1100 (AEDT) Received: from localhost ([::1]:54570 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNpLv-0006wT-Rw for incoming@patchwork.ozlabs.org; Thu, 24 Oct 2019 22:29:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39503) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNpIj-00022c-EB for qemu-devel@nongnu.org; Thu, 24 Oct 2019 22:26:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNpIi-0007Z6-9D for qemu-devel@nongnu.org; Thu, 24 Oct 2019 22:26:05 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:23169 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNpIi-0007Yu-5M for qemu-devel@nongnu.org; Thu, 24 Oct 2019 22:26:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571970363; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=skzxznZMQb+hQ2LViMb7cCRGTVd6o+H0baPEAle9Hp0=; b=cTwAiM5kiBeINnwU5mnAouJR3YTFcQuLWLZtS78DtHHFaI8alQjqyzjieS4QSMMqTDC0t2 pUNQlqd0xtJ+z7oWEnrfUtIwIKl5i2fWDkmAuvNSy0FkinjuoE81rDJ3yBZJUSTd82r8y3 I6Xc/rxWRft6BoCNBdkyvlHOJT0+tXI= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-378-2IYdbWHlN9aWnwFL-cGtDg-1; Thu, 24 Oct 2019 22:26:00 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 448C647B; Fri, 25 Oct 2019 02:25:59 +0000 (UTC) Received: from localhost (ovpn-116-62.gru2.redhat.com [10.97.116.62]) by smtp.corp.redhat.com (Postfix) with ESMTP id D0C91600C6; Fri, 25 Oct 2019 02:25:58 +0000 (UTC) From: Eduardo Habkost To: qemu-devel@nongnu.org Subject: [PATCH 2/7] i386: Add default_version parameter to CPU version functions Date: Thu, 24 Oct 2019 23:25:48 -0300 Message-Id: <20191025022553.25298-3-ehabkost@redhat.com> In-Reply-To: <20191025022553.25298-1-ehabkost@redhat.com> References: <20191025022553.25298-1-ehabkost@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: 2IYdbWHlN9aWnwFL-cGtDg-1 X-Mimecast-Spam-Score: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Markus Armbruster , Igor Mammedov , Paolo Bonzini , Jiri Denemark , Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Not all CPU version lookup code will use default_cpu_version: we'll change query-cpu-definitions to optionally get a machine type argument. Make CPU version resolving functions get an explicit default_version argument. All callers are being changed to use default_cpu_version as argument, so no behavior is being changed yet. Signed-off-by: Eduardo Habkost --- target/i386/cpu.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 5b7c5b1177..843f8c4b68 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -3187,11 +3187,12 @@ static X86CPUVersion x86_cpu_model_last_version(const X86CPUModel *model) } /* Return the actual version being used for a specific CPU model */ -static X86CPUVersion x86_cpu_model_resolve_version(const X86CPUModel *model) +static X86CPUVersion x86_cpu_model_resolve_version(const X86CPUModel *model, + X86CPUVersion default_version) { X86CPUVersion v = model->version; if (v == CPU_VERSION_AUTO) { - v = default_cpu_version; + v = default_version; } if (v == CPU_VERSION_LATEST) { return x86_cpu_model_last_version(model); @@ -3958,14 +3959,15 @@ static char *x86_cpu_class_get_model_id(X86CPUClass *xc) return r; } -static char *x86_cpu_class_get_alias_of(X86CPUClass *cc) +static char *x86_cpu_class_get_alias_of(X86CPUClass *cc, + X86CPUVersion default_version) { X86CPUVersion version; if (!cc->model || !cc->model->is_alias) { return NULL; } - version = x86_cpu_model_resolve_version(cc->model); + version = x86_cpu_model_resolve_version(cc->model, default_version); if (version <= 0) { return NULL; } @@ -3978,7 +3980,7 @@ static void x86_cpu_list_entry(gpointer data, gpointer user_data) X86CPUClass *cc = X86_CPU_CLASS(oc); g_autofree char *name = x86_cpu_class_get_model_name(cc); g_autofree char *desc = g_strdup(cc->model_description); - g_autofree char *alias_of = x86_cpu_class_get_alias_of(cc); + g_autofree char *alias_of = x86_cpu_class_get_alias_of(cc, default_cpu_version); if (!desc && alias_of) { if (cc->model && cc->model->version == CPU_VERSION_AUTO) { @@ -4045,7 +4047,7 @@ static void x86_cpu_definition_entry(gpointer data, gpointer user_data) * doesn't break compatibility with previous QEMU versions. */ if (default_cpu_version != CPU_VERSION_LEGACY) { - info->alias_of = x86_cpu_class_get_alias_of(cc); + info->alias_of = x86_cpu_class_get_alias_of(cc, default_cpu_version); info->has_alias_of = !!info->alias_of; } @@ -4116,7 +4118,7 @@ static void x86_cpu_apply_props(X86CPU *cpu, PropValue *props) static void x86_cpu_apply_version_props(X86CPU *cpu, X86CPUModel *model) { const X86CPUVersionDefinition *vdef; - X86CPUVersion version = x86_cpu_model_resolve_version(model); + X86CPUVersion version = x86_cpu_model_resolve_version(model, default_cpu_version); if (version == CPU_VERSION_LEGACY) { return; From patchwork Fri Oct 25 02:25:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 1183723 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="IdSuUrdZ"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46zp0B45J1z9sP4 for ; Fri, 25 Oct 2019 13:26:50 +1100 (AEDT) Received: from localhost ([::1]:54532 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNpJP-00027d-QX for incoming@patchwork.ozlabs.org; Thu, 24 Oct 2019 22:26:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39517) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNpIk-00024i-Nd for qemu-devel@nongnu.org; Thu, 24 Oct 2019 22:26:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNpIj-0007ZP-O9 for qemu-devel@nongnu.org; Thu, 24 Oct 2019 22:26:06 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:46229 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNpIj-0007ZG-L6 for qemu-devel@nongnu.org; Thu, 24 Oct 2019 22:26:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571970365; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oXiQ9VZ+z74ls5xgndM1WghFumLiYi+xPQ8+MWj6qls=; b=IdSuUrdZdBCjiHIXnwOOV4zlbv5UmXa+LM7rERPVVv0/Ql8ZqHYg3c2+utvXslBJcFBrcq kcxuj7F8Qa2iZYub0/ce3Fc2QPHc16RiPwST/Qp/xf1R5jjHkoYgbhagCsF6YDRV6vrS7j 3FMMTTUSGpwzjgTfMC2iloYnO6IIMw0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-39-5asOPNm8NGW8_G9muFsRPw-1; Thu, 24 Oct 2019 22:26:02 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 467431800DC7; Fri, 25 Oct 2019 02:26:01 +0000 (UTC) Received: from localhost (ovpn-116-62.gru2.redhat.com [10.97.116.62]) by smtp.corp.redhat.com (Postfix) with ESMTP id C685C5D712; Fri, 25 Oct 2019 02:26:00 +0000 (UTC) From: Eduardo Habkost To: qemu-devel@nongnu.org Subject: [PATCH 3/7] i386: Don't use default_cpu_version at "-cpu help" Date: Thu, 24 Oct 2019 23:25:49 -0300 Message-Id: <20191025022553.25298-4-ehabkost@redhat.com> In-Reply-To: <20191025022553.25298-1-ehabkost@redhat.com> References: <20191025022553.25298-1-ehabkost@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: 5asOPNm8NGW8_G9muFsRPw-1 X-Mimecast-Spam-Score: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Markus Armbruster , Igor Mammedov , Paolo Bonzini , Jiri Denemark , Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The output of "-cpu help" doesn't change depending on the machine type, already. We can remove usage of default_cpu_version and keep output exactly the same. Signed-off-by: Eduardo Habkost --- target/i386/cpu.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 843f8c4b68..8cecc669b3 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -3980,10 +3980,11 @@ static void x86_cpu_list_entry(gpointer data, gpointer user_data) X86CPUClass *cc = X86_CPU_CLASS(oc); g_autofree char *name = x86_cpu_class_get_model_name(cc); g_autofree char *desc = g_strdup(cc->model_description); - g_autofree char *alias_of = x86_cpu_class_get_alias_of(cc, default_cpu_version); - if (!desc && alias_of) { - if (cc->model && cc->model->version == CPU_VERSION_AUTO) { + if (!desc && cc->model && cc->model->is_alias) { + g_autofree char *alias_of = + x86_cpu_class_get_alias_of(cc, CPU_VERSION_AUTO); + if (!alias_of) { desc = g_strdup("(alias configured by machine type)"); } else { desc = g_strdup_printf("(alias of %s)", alias_of); From patchwork Fri Oct 25 02:25:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 1183726 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="YOyfKRa0"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46zp3F3tMgz9sP4 for ; Fri, 25 Oct 2019 13:29:29 +1100 (AEDT) Received: from localhost ([::1]:54574 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNpLz-0007U9-Bd for incoming@patchwork.ozlabs.org; Thu, 24 Oct 2019 22:29:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39536) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNpIp-0002C5-Ml for qemu-devel@nongnu.org; Thu, 24 Oct 2019 22:26:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNpIn-0007aQ-AM for qemu-devel@nongnu.org; Thu, 24 Oct 2019 22:26:10 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:48647 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNpIn-0007aJ-7D for qemu-devel@nongnu.org; Thu, 24 Oct 2019 22:26:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571970368; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=C1cNalAwrJV0DyhikBx4irI+M0/L+czcaXHTP5IwohM=; b=YOyfKRa0H7IFl+E/q7Cj8tM1depHFU7OLjGxZAwAFz3mFJQbgXHSCb8O+ns+Pm5Xsa5Z77 5CBKNjeOY0h7FATlpRbA61cjZhgoGg9uzEacqhdwd+Bc2YWANYWjVaXEJPU49u8unvE80d ZmFI5uZms+9LQDZ/cdutFevq7lBW4NA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-177-YOZEUWc6MEeymIB4zKdGuA-1; Thu, 24 Oct 2019 22:26:05 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9374547B; Fri, 25 Oct 2019 02:26:04 +0000 (UTC) Received: from localhost (ovpn-116-62.gru2.redhat.com [10.97.116.62]) by smtp.corp.redhat.com (Postfix) with ESMTP id CF64D600C6; Fri, 25 Oct 2019 02:26:02 +0000 (UTC) From: Eduardo Habkost To: qemu-devel@nongnu.org Subject: [PATCH 4/7] machine: machine_find_class() function Date: Thu, 24 Oct 2019 23:25:50 -0300 Message-Id: <20191025022553.25298-5-ehabkost@redhat.com> In-Reply-To: <20191025022553.25298-1-ehabkost@redhat.com> References: <20191025022553.25298-1-ehabkost@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: YOZEUWc6MEeymIB4zKdGuA-1 X-Mimecast-Spam-Score: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Markus Armbruster , Igor Mammedov , Paolo Bonzini , Jiri Denemark , Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Move find_machine() from vl.c to core/machine.c and rename it to machine_find_class(), so it can be reused by other code. The function won't reuse the results of the previous object_class_get_list() call like it did in vl.c, but this shouldn't be a problem because the function is expected to be called only once during regular QEMU usage. Signed-off-by: Eduardo Habkost --- include/hw/boards.h | 1 + hw/core/machine.c | 16 ++++++++++++++++ vl.c | 17 +---------------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/include/hw/boards.h b/include/hw/boards.h index de45087f34..0ab7138c63 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -76,6 +76,7 @@ void machine_set_cpu_numa_node(MachineState *machine, Error **errp); void machine_class_allow_dynamic_sysbus_dev(MachineClass *mc, const char *type); +MachineClass *machine_find_class(const char *name); /** diff --git a/hw/core/machine.c b/hw/core/machine.c index 1689ad3bf8..53dae1cd08 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -1143,6 +1143,22 @@ void machine_run_board_init(MachineState *machine) machine_class->init(machine); } +MachineClass *machine_find_class(const char *name) +{ + g_autoptr(GSList) machines = object_class_get_list(TYPE_MACHINE, false); + GSList *el; + + for (el = machines; el; el = el->next) { + MachineClass *mc = el->data; + + if (!strcmp(mc->name, name) || !g_strcmp0(mc->alias, name)) { + return mc; + } + } + + return NULL; +} + static const TypeInfo machine_info = { .name = TYPE_MACHINE, .parent = TYPE_OBJECT, diff --git a/vl.c b/vl.c index 4489cfb2bb..8901455ee7 100644 --- a/vl.c +++ b/vl.c @@ -1306,21 +1306,6 @@ static int usb_parse(const char *cmdline) MachineState *current_machine; -static MachineClass *find_machine(const char *name, GSList *machines) -{ - GSList *el; - - for (el = machines; el; el = el->next) { - MachineClass *mc = el->data; - - if (!strcmp(mc->name, name) || !g_strcmp0(mc->alias, name)) { - return mc; - } - } - - return NULL; -} - static MachineClass *find_default_machine(GSList *machines) { GSList *el; @@ -2485,7 +2470,7 @@ static MachineClass *machine_parse(const char *name, GSList *machines) exit(0); } - mc = find_machine(name, machines); + mc = machine_find_class(name); if (!mc) { error_report("unsupported machine type"); error_printf("Use -machine help to list supported machines\n"); From patchwork Fri Oct 25 02:25:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 1183728 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="aNshZF23"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46zp5j0tVFz9sP4 for ; Fri, 25 Oct 2019 13:31:36 +1100 (AEDT) Received: from localhost ([::1]:54600 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNpO1-00024g-Pt for incoming@patchwork.ozlabs.org; Thu, 24 Oct 2019 22:31:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39549) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNpIq-0002FH-Ql for qemu-devel@nongnu.org; Thu, 24 Oct 2019 22:26:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNpIp-0007au-Ef for qemu-devel@nongnu.org; Thu, 24 Oct 2019 22:26:12 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:48475 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNpIp-0007am-BF for qemu-devel@nongnu.org; Thu, 24 Oct 2019 22:26:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571970371; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DE2UszUNbiBVXoqbZD/Azq3pCR41ajOgVbw26AFRtxk=; b=aNshZF23DJvKtg+XykDa1MkCTeJrROTfRypMhClbMDgR1FfXBP8qrpa4t3bxCL1NNrNMc6 +v0m/Yhkdlz6PLTLrEfG6OdjoNEyzqDyVqZtcG/ax1vesiVH1xiD+c0NZJ0YqCvplxKRwk 8cIErT+y+MvJDrzn0bzkw4L98CroMBc= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-215-_9tcNk31Nr-HVTmvWKOcUQ-1; Thu, 24 Oct 2019 22:26:07 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7D76D107AD31; Fri, 25 Oct 2019 02:26:06 +0000 (UTC) Received: from localhost (ovpn-116-62.gru2.redhat.com [10.97.116.62]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0FF8B608C1; Fri, 25 Oct 2019 02:26:05 +0000 (UTC) From: Eduardo Habkost To: qemu-devel@nongnu.org Subject: [PATCH 5/7] i386: Remove x86_cpu_set_default_version() function Date: Thu, 24 Oct 2019 23:25:51 -0300 Message-Id: <20191025022553.25298-6-ehabkost@redhat.com> In-Reply-To: <20191025022553.25298-1-ehabkost@redhat.com> References: <20191025022553.25298-1-ehabkost@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: _9tcNk31Nr-HVTmvWKOcUQ-1 X-Mimecast-Spam-Score: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Markus Armbruster , Igor Mammedov , Paolo Bonzini , Jiri Denemark , Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" We will introduce code that will return machine-type-specific from other machines (not the current one), so we'll need a helper for getting the default CPU version from a machine class. With the new helper, we don't need the machine init function to call x86_cpu_set_default_version() anymore: we can just look at the machine class of the current machine. Replace the default_cpu_version static variable with a default_cpu_version() function that will look at qdev_get_machine(). Signed-off-by: Eduardo Habkost --- include/hw/i386/pc.h | 5 ++++- target/i386/cpu.h | 6 ------ hw/i386/pc.c | 3 --- target/i386/cpu.c | 28 ++++++++++++++++++++-------- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 37bfd95113..00ac726ebc 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -113,7 +113,10 @@ typedef struct PCMachineClass { /* Compat options: */ - /* Default CPU model version. See x86_cpu_set_default_version(). */ + /* + * Default CPU model version for CPU models having + * version == CPU_VERSION_AUTO. + */ int default_cpu_version; /* ACPI compat: */ diff --git a/target/i386/cpu.h b/target/i386/cpu.h index cedb5bc205..aa17c79b43 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -2168,12 +2168,6 @@ void x86_cpu_change_kvm_default(const char *prop, const char *value); typedef int X86CPUVersion; -/* - * Set default CPU model version for CPU models having - * version == CPU_VERSION_AUTO. - */ -void x86_cpu_set_default_version(X86CPUVersion version); - /* Return name of 32-bit register, from a R_* constant */ const char *get_register_name_32(unsigned int reg); diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 4b1904237e..64ec995172 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1503,9 +1503,6 @@ void pc_cpus_init(PCMachineState *pcms) const CPUArchIdList *possible_cpus; MachineState *ms = MACHINE(pcms); MachineClass *mc = MACHINE_GET_CLASS(pcms); - PCMachineClass *pcmc = PC_MACHINE_CLASS(mc); - - x86_cpu_set_default_version(pcmc->default_cpu_version); /* Calculates the limit to CPU APIC ID values * diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 8cecc669b3..5dbd379331 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -57,6 +57,7 @@ #include "hw/xen/xen.h" #include "hw/i386/apic_internal.h" #include "hw/boards.h" +#include "hw/i386/pc.h" #endif #include "disas/capstone.h" @@ -3165,14 +3166,25 @@ static PropValue tcg_default_props[] = { }; -X86CPUVersion default_cpu_version = CPU_VERSION_LATEST; +#ifdef CONFIG_USER_ONLY +static X86CPUVersion default_cpu_version(void) +{ + return CPU_VERSION_LATEST; +} +#else +static X86CPUVersion default_cpu_version_for_machine(MachineClass *mc) +{ + PCMachineClass *pcmc = + (PCMachineClass *)object_class_dynamic_cast(OBJECT_CLASS(mc), TYPE_PC_MACHINE); + return pcmc ? pcmc->default_cpu_version : CPU_VERSION_LATEST; +} -void x86_cpu_set_default_version(X86CPUVersion version) +static X86CPUVersion default_cpu_version(void) { - /* Translating CPU_VERSION_AUTO to CPU_VERSION_AUTO doesn't make sense */ - assert(version != CPU_VERSION_AUTO); - default_cpu_version = version; + return default_cpu_version_for_machine(MACHINE_GET_CLASS(qdev_get_machine())); } +#endif + static X86CPUVersion x86_cpu_model_last_version(const X86CPUModel *model) { @@ -4047,8 +4059,8 @@ static void x86_cpu_definition_entry(gpointer data, gpointer user_data) * Old machine types won't report aliases, so that alias translation * doesn't break compatibility with previous QEMU versions. */ - if (default_cpu_version != CPU_VERSION_LEGACY) { - info->alias_of = x86_cpu_class_get_alias_of(cc, default_cpu_version); + if (default_cpu_version() != CPU_VERSION_LEGACY) { + info->alias_of = x86_cpu_class_get_alias_of(cc, default_cpu_version()); info->has_alias_of = !!info->alias_of; } @@ -4119,7 +4131,7 @@ static void x86_cpu_apply_props(X86CPU *cpu, PropValue *props) static void x86_cpu_apply_version_props(X86CPU *cpu, X86CPUModel *model) { const X86CPUVersionDefinition *vdef; - X86CPUVersion version = x86_cpu_model_resolve_version(model, default_cpu_version); + X86CPUVersion version = x86_cpu_model_resolve_version(model, default_cpu_version()); if (version == CPU_VERSION_LEGACY) { return; From patchwork Fri Oct 25 02:25:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 1183729 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="MT+fGoom"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46zp5s116xz9sPk for ; Fri, 25 Oct 2019 13:31:44 +1100 (AEDT) Received: from localhost ([::1]:54604 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNpO9-0002Zb-FT for incoming@patchwork.ozlabs.org; Thu, 24 Oct 2019 22:31:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39560) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNpIs-0002JD-Qo for qemu-devel@nongnu.org; Thu, 24 Oct 2019 22:26:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNpIr-0007bV-If for qemu-devel@nongnu.org; Thu, 24 Oct 2019 22:26:14 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:31516 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNpIr-0007bL-FA for qemu-devel@nongnu.org; Thu, 24 Oct 2019 22:26:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571970372; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pbB5R4thUE5Gt4DY003mthYNBru3RU5to81ayHIC/6M=; b=MT+fGoomE7YMgONFLfjCE1pnv7ZcWWltd9aOBLJBReDiUDDrxrifMagjeA4pU9A/hOi7eX 12/bQjgxY0Oda59KbabU8PsvbA19yKnVLlq2g4vBwf5eH8ZxTDGNGFliRQ3AebnExPl7xs j7F6g0Qo8BToKxmXwgQ32w+Uh4Bk2Q4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-166-A0qb6TAJNZ-04Y3SQS7j5A-1; Thu, 24 Oct 2019 22:26:09 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6CB2B800D49; Fri, 25 Oct 2019 02:26:08 +0000 (UTC) Received: from localhost (ovpn-116-62.gru2.redhat.com [10.97.116.62]) by smtp.corp.redhat.com (Postfix) with ESMTP id F1DA660600; Fri, 25 Oct 2019 02:26:07 +0000 (UTC) From: Eduardo Habkost To: qemu-devel@nongnu.org Subject: [PATCH 6/7] i386: Don't use default_cpu_version() inside query-cpu-definitions Date: Thu, 24 Oct 2019 23:25:52 -0300 Message-Id: <20191025022553.25298-7-ehabkost@redhat.com> In-Reply-To: <20191025022553.25298-1-ehabkost@redhat.com> References: <20191025022553.25298-1-ehabkost@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: A0qb6TAJNZ-04Y3SQS7j5A-1 X-Mimecast-Spam-Score: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Markus Armbruster , Igor Mammedov , Paolo Bonzini , Jiri Denemark , Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" We will change query-cpu-definitions to have a new `machine` parameter. Make the machine-specific parts of that code explicit instead of calling default_cpu_version(), so we can change it to use the new parameter later. As the code now has a dependency on MachineClass, wrap it inside a !CONFIG_USER_ONLY ifdef. The function was never used by *-user, anyway. This patch shouldn't introduce any behavior change. Results of query-cpu-definition will be exactly the same. Signed-off-by: Eduardo Habkost --- target/i386/cpu.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 5dbd379331..67d1eca4ed 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -3877,6 +3877,7 @@ static void x86_cpu_get_unavailable_features(Object *obj, Visitor *v, visit_type_strList(v, "unavailable-features", &result, errp); } +#ifndef CONFIG_USER_ONLY /* Check for missing features that may prevent the CPU class from * running using the current machine and accelerator. */ @@ -3914,6 +3915,7 @@ static void x86_cpu_class_check_missing_features(X86CPUClass *xcc, object_unref(OBJECT(xc)); } +#endif /* Print all cpuid feature names in featureset */ @@ -4039,11 +4041,17 @@ void x86_cpu_list(void) g_list_free(names); } +#ifndef CONFIG_USER_ONLY +typedef struct X86CPUDefinitionArgs { + CpuDefinitionInfoList *cpu_list; + X86CPUVersion default_version; +} X86CPUDefinitionArgs; + static void x86_cpu_definition_entry(gpointer data, gpointer user_data) { ObjectClass *oc = data; X86CPUClass *cc = X86_CPU_CLASS(oc); - CpuDefinitionInfoList **cpu_list = user_data; + X86CPUDefinitionArgs *args = user_data; CpuDefinitionInfoList *entry; CpuDefinitionInfo *info; @@ -4059,25 +4067,30 @@ static void x86_cpu_definition_entry(gpointer data, gpointer user_data) * Old machine types won't report aliases, so that alias translation * doesn't break compatibility with previous QEMU versions. */ - if (default_cpu_version() != CPU_VERSION_LEGACY) { - info->alias_of = x86_cpu_class_get_alias_of(cc, default_cpu_version()); + if (args->default_version != CPU_VERSION_LEGACY) { + info->alias_of = x86_cpu_class_get_alias_of(cc, args->default_version); info->has_alias_of = !!info->alias_of; } entry = g_malloc0(sizeof(*entry)); entry->value = info; - entry->next = *cpu_list; - *cpu_list = entry; + entry->next = args->cpu_list; + args->cpu_list = entry; } CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) { - CpuDefinitionInfoList *cpu_list = NULL; - GSList *list = get_sorted_cpu_model_list(); - g_slist_foreach(list, x86_cpu_definition_entry, &cpu_list); + X86CPUDefinitionArgs args = { .cpu_list = NULL }; + GSList *list; + MachineClass *mc = MACHINE_GET_CLASS(qdev_get_machine()); + + args.default_version = default_cpu_version_for_machine(mc); + list = get_sorted_cpu_model_list(); + g_slist_foreach(list, x86_cpu_definition_entry, &args); g_slist_free(list); - return cpu_list; + return args.cpu_list; } +#endif static uint64_t x86_cpu_get_supported_feature_word(FeatureWord w, bool migratable_only) From patchwork Fri Oct 25 02:25:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 1183724 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="cctgRqoK"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46zp0f4Pbpz9sPl for ; Fri, 25 Oct 2019 13:27:14 +1100 (AEDT) Received: from localhost ([::1]:54550 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNpJn-0002iq-VC for incoming@patchwork.ozlabs.org; Thu, 24 Oct 2019 22:27:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39589) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNpIz-0002VQ-D3 for qemu-devel@nongnu.org; Thu, 24 Oct 2019 22:26:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNpIx-0007dY-NJ for qemu-devel@nongnu.org; Thu, 24 Oct 2019 22:26:21 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:28152 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNpIx-0007dJ-Ie for qemu-devel@nongnu.org; Thu, 24 Oct 2019 22:26:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571970379; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=s4Vx6o5A+aCOtwYxTcn/YHkF+JyMjbufP9FhFqhT+cc=; b=cctgRqoK88+5fWwNFwbx3TFQDTTzEZeTRh5M9nHCP+72A/6kDF7GVmxS0OLiyjlS8WhGWu ILAt90oESVn743WtTKiQTFNjY+P4Fu8PGslRkxF5dBKRHSsyKFbnv6XyXZ6njhbXaxl5MW QPfiXwTdtMrd0eLl/J5KKoYtb2PVTgw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-174-pWuI0ASOPj-Jm0Zxy2bIvg-1; Thu, 24 Oct 2019 22:26:15 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 50CDF1800DC7; Fri, 25 Oct 2019 02:26:13 +0000 (UTC) Received: from localhost (ovpn-116-62.gru2.redhat.com [10.97.116.62]) by smtp.corp.redhat.com (Postfix) with ESMTP id EC4C64129; Fri, 25 Oct 2019 02:26:09 +0000 (UTC) From: Eduardo Habkost To: qemu-devel@nongnu.org Subject: [PATCH 7/7] cpu: Add `machine` parameter to query-cpu-definitions Date: Thu, 24 Oct 2019 23:25:53 -0300 Message-Id: <20191025022553.25298-8-ehabkost@redhat.com> In-Reply-To: <20191025022553.25298-1-ehabkost@redhat.com> References: <20191025022553.25298-1-ehabkost@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: pWuI0ASOPj-Jm0Zxy2bIvg-1 X-Mimecast-Spam-Score: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Aleksandar Markovic , David Hildenbrand , Aleksandar Rikalo , Cornelia Huck , Markus Armbruster , Halil Pasic , Christian Borntraeger , qemu-s390x@nongnu.org, qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Igor Mammedov , Paolo Bonzini , Jiri Denemark , David Gibson , Aurelien Jarno , Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The new parameter can be used by management software to query for CPU model alias information for multiple machines without restarting QEMU. Signed-off-by: Eduardo Habkost --- qapi/machine-target.json | 14 +++++++- target/arm/helper.c | 4 ++- target/i386/cpu.c | 16 +++++++-- target/mips/helper.c | 4 ++- target/ppc/translate_init.inc.c | 4 ++- target/s390x/cpu_models.c | 4 ++- tests/acceptance/x86_cpu_model_versions.py | 42 ++++++++++++++++++++++ 7 files changed, 81 insertions(+), 7 deletions(-) diff --git a/qapi/machine-target.json b/qapi/machine-target.json index 55310a6aa2..7bff3811fe 100644 --- a/qapi/machine-target.json +++ b/qapi/machine-target.json @@ -281,6 +281,10 @@ # # @alias-of: Name of CPU model this model is an alias for. The target of the # CPU model alias may change depending on the machine type. +# If the @machine argument was provided to query-cpu-definitions, +# alias information that machine type will be returned. +# If @machine is not provided, alias information for +# the current machine will be returned. # Management software is supposed to translate CPU model aliases # in the VM configuration, because aliases may stop being # migration-safe in the future (since 4.1) @@ -317,9 +321,17 @@ # # Return a list of supported virtual CPU definitions # +# @machine: Name of machine type. The command returns some data +# that machine-specific. This overrides the machine type +# used to look up that information. This can be used, +# for example, to query machine-specific CPU model aliases +# without restarting QEMU (since 4.2) +# # Returns: a list of CpuDefInfo # # Since: 1.2.0 ## -{ 'command': 'query-cpu-definitions', 'returns': ['CpuDefinitionInfo'], +{ 'command': 'query-cpu-definitions', + 'data': { '*machine': 'str' }, + 'returns': ['CpuDefinitionInfo'], 'if': 'defined(TARGET_PPC) || defined(TARGET_ARM) || defined(TARGET_I386) || defined(TARGET_S390X) || defined(TARGET_MIPS)' } diff --git a/target/arm/helper.c b/target/arm/helper.c index 0d9a2d2ab7..96f9fe7fff 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -6965,7 +6965,9 @@ static void arm_cpu_add_definition(gpointer data, gpointer user_data) *cpu_list = entry; } -CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) +CpuDefinitionInfoList *qmp_query_cpu_definitions(bool has_machine, + const char *machine, + Error **errp) { CpuDefinitionInfoList *cpu_list = NULL; GSList *list; diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 67d1eca4ed..ae633793ed 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -4078,11 +4078,23 @@ static void x86_cpu_definition_entry(gpointer data, gpointer user_data) args->cpu_list = entry; } -CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) +CpuDefinitionInfoList *qmp_query_cpu_definitions(bool has_machine, + const char *machine, + Error **errp) { X86CPUDefinitionArgs args = { .cpu_list = NULL }; GSList *list; - MachineClass *mc = MACHINE_GET_CLASS(qdev_get_machine()); + MachineClass *mc; + + if (!has_machine) { + mc = MACHINE_GET_CLASS(qdev_get_machine()); + } else { + mc = machine_find_class(machine); + if (!mc) { + error_setg(errp, "Machine type '%s' not found", machine); + return NULL; + } + } args.default_version = default_cpu_version_for_machine(mc); list = get_sorted_cpu_model_list(); diff --git a/target/mips/helper.c b/target/mips/helper.c index a2b6459b05..a73c767462 100644 --- a/target/mips/helper.c +++ b/target/mips/helper.c @@ -1481,7 +1481,9 @@ static void mips_cpu_add_definition(gpointer data, gpointer user_data) *cpu_list = entry; } -CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) +CpuDefinitionInfoList *qmp_query_cpu_definitions(bool has_machine, + const char *machine, + Error **errp) { CpuDefinitionInfoList *cpu_list = NULL; GSList *list; diff --git a/target/ppc/translate_init.inc.c b/target/ppc/translate_init.inc.c index ba726dec4d..4493309c4c 100644 --- a/target/ppc/translate_init.inc.c +++ b/target/ppc/translate_init.inc.c @@ -10350,7 +10350,9 @@ static void ppc_cpu_defs_entry(gpointer data, gpointer user_data) *first = entry; } -CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) +CpuDefinitionInfoList *qmp_query_cpu_definitions(bool has_machine, + const char *machine, + Error **errp) { CpuDefinitionInfoList *cpu_list = NULL; GSList *list; diff --git a/target/s390x/cpu_models.c b/target/s390x/cpu_models.c index 7e92fb2e15..e40f1f6bec 100644 --- a/target/s390x/cpu_models.c +++ b/target/s390x/cpu_models.c @@ -456,7 +456,9 @@ static void create_cpu_model_list(ObjectClass *klass, void *opaque) *cpu_list = entry; } -CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) +CpuDefinitionInfoList *qmp_query_cpu_definitions(bool has_machine, + const char *machine, + Error **errp) { struct CpuDefinitionInfoListData list_data = { .list = NULL, diff --git a/tests/acceptance/x86_cpu_model_versions.py b/tests/acceptance/x86_cpu_model_versions.py index 5fc9ca4bc6..79c5250243 100644 --- a/tests/acceptance/x86_cpu_model_versions.py +++ b/tests/acceptance/x86_cpu_model_versions.py @@ -234,6 +234,48 @@ class X86CPUModelAliases(avocado_qemu.Test): self.validate_aliases(cpus) + def test_machine_arg_none(self): + """Check if unversioned CPU model is an alias pointing to right version""" + vm1 = self.get_vm() + vm1.add_args('-S') + vm1.set_machine('pc-i440fx-4.0') + vm1.launch() + cpus1 = dict((m['name'], m.get('alias-of')) for m in vm1.command('query-cpu-definitions', machine='none')) + vm1.shutdown() + + vm2 = self.get_vm() + vm2.add_args('-S') + vm2.set_machine('none') + vm2.launch() + cpus2 = dict((m['name'], m.get('alias-of')) for m in vm2.command('query-cpu-definitions')) + vm1.shutdown() + + self.assertEquals(cpus1, cpus2) + + def test_machine_arg_4_1(self): + """Check if unversioned CPU model is an alias pointing to right version""" + vm1 = self.get_vm() + vm1.add_args('-S') + vm1.set_machine('pc-i440fx-4.0') + vm1.launch() + cpus1 = dict((m['name'], m.get('alias-of')) for m in vm1.command('query-cpu-definitions', machine='pc-i440fx-4.1')) + vm1.shutdown() + + vm2 = self.get_vm() + vm2.add_args('-S') + vm2.set_machine('pc-i440fx-4.1') + vm2.launch() + cpus2 = dict((m['name'], m.get('alias-of')) for m in vm2.command('query-cpu-definitions')) + vm1.shutdown() + + self.assertEquals(cpus1, cpus2) + + def test_invalid_machine(self): + self.vm.add_args('-S') + self.vm.launch() + r = self.vm.qmp('query-cpu-definitions', machine='invalid-machine-123') + self.assertIn('error', r) + class CascadelakeArchCapabilities(avocado_qemu.Test): """