From patchwork Sat May 29 09:13:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudio Fontana X-Patchwork-Id: 12287799 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DFE52C4708F for ; Sat, 29 May 2021 09:13:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BB9CD611ED for ; Sat, 29 May 2021 09:13:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229698AbhE2JOz (ORCPT ); Sat, 29 May 2021 05:14:55 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:44582 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229559AbhE2JOy (ORCPT ); Sat, 29 May 2021 05:14:54 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id A4B061FD30; Sat, 29 May 2021 09:13:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1622279597; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0hLBajeRODOVVhWrr6yKi1f/oM4Ln7sgbWW5uEPEvTE=; b=0uGjpplLxqUTEB79TkM4cFa0eSNhh78ebQWWqXfjjjBzJG7UZWWwDDNQNolkYRoIp8o093 vyEitrHyq3Eb9ZGNFYmCQRlodoOY0vtjwYion0s5764mShPmYKw9K9vxMAgH3HHLtvBE3M XVXarFa9M310ed5wjMgraMfxrsiuOSA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1622279597; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0hLBajeRODOVVhWrr6yKi1f/oM4Ln7sgbWW5uEPEvTE=; b=vGoHCr0/TC8F6hAH+jRrWhyqtXjAdz5wTJB2EaosnveK81laxZoTtyMv3l+SNup8i06Rhx m70xq+E2vGI4GFBg== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id 3369911A98; Sat, 29 May 2021 09:13:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1622279596; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0hLBajeRODOVVhWrr6yKi1f/oM4Ln7sgbWW5uEPEvTE=; b=kEiKiziEswBdOkQG8HJioFXYra1faue59deYhFUwdwr8Vzee/VZIkuiDSby2y/RDO0rHxD 4vSceUSIqKMM60Nq3VuFqYG2zfqomsGhPb7l9HzhaF41YSrPhL3ukEWIEJ1hfv/3GeeZqG AXs32MGy1S/D4zpxBfX7DKUyCsRr+J0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1622279596; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0hLBajeRODOVVhWrr6yKi1f/oM4Ln7sgbWW5uEPEvTE=; b=zM2TaNGtJ0i6jNWmLY5MAolJi5F7/J/aLmCejfweg96pBm4j30hnCkOpTE9POWRe7XooK8 GAu+ooWTzu/zCdBA== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id IK6uCqwFsmCbEwAALh3uQQ (envelope-from ); Sat, 29 May 2021 09:13:16 +0000 From: Claudio Fontana To: Peter Maydell , Paolo Bonzini , Eduardo Habkost , Siddharth Chandrasekaran , =?utf-8?q?Philippe_Mathieu-Dau?= =?utf-8?q?d=C3=A9?= Cc: Claudio Fontana , "Michael S . Tsirkin" , kvm@vger.kernel.org, Marcelo Tosatti , Richard Henderson , Cameron Esfahani , Roman Bolshakov , qemu-devel@nongnu.org Subject: [PATCH 1/2] i386: reorder call to cpu_exec_realizefn in x86_cpu_realizefn Date: Sat, 29 May 2021 11:13:12 +0200 Message-Id: <20210529091313.16708-2-cfontana@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210529091313.16708-1-cfontana@suse.de> References: <20210529091313.16708-1-cfontana@suse.de> MIME-Version: 1.0 Authentication-Results: imap.suse.de; none X-Spamd-Result: default: False [1.00 / 100.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; REPLY(-4.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_TWELVE(0.00)[13]; MID_CONTAINS_FROM(1.00)[]; RCVD_NO_TLS_LAST(0.10)[]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2] Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org we need to expand features first, before we attempt to check them in the accel realizefn code called by cpu_exec_realizefn(). At the same time we need checks for code_urev and host_cpuid_required, and modifications to cpu->mwait to happen after the initial setting of them inside the accel realizefn code. Partial Fix. Fixes: 48afe6e4eabf ("i386: split cpu accelerators from cpu.c, using AccelCPUClass") Signed-off-by: Claudio Fontana --- target/i386/cpu.c | 56 +++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 9e211ac2ce..6bcb7dbc2c 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -6133,34 +6133,6 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) Error *local_err = NULL; static bool ht_warned; - /* Process Hyper-V enlightenments */ - x86_cpu_hyperv_realize(cpu); - - cpu_exec_realizefn(cs, &local_err); - if (local_err != NULL) { - error_propagate(errp, local_err); - return; - } - - if (xcc->host_cpuid_required && !accel_uses_host_cpuid()) { - g_autofree char *name = x86_cpu_class_get_model_name(xcc); - error_setg(&local_err, "CPU model '%s' requires KVM or HVF", name); - goto out; - } - - if (cpu->ucode_rev == 0) { - /* The default is the same as KVM's. */ - if (IS_AMD_CPU(env)) { - cpu->ucode_rev = 0x01000065; - } else { - cpu->ucode_rev = 0x100000000ULL; - } - } - - /* mwait extended info: needed for Core compatibility */ - /* We always wake on interrupt even if host does not have the capability */ - cpu->mwait.ecx |= CPUID_MWAIT_EMX | CPUID_MWAIT_IBE; - if (cpu->apic_id == UNASSIGNED_APIC_ID) { error_setg(errp, "apic-id property was not initialized properly"); return; @@ -6190,6 +6162,34 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) & CPUID_EXT2_AMD_ALIASES); } + /* Process Hyper-V enlightenments */ + x86_cpu_hyperv_realize(cpu); + + cpu_exec_realizefn(cs, &local_err); + if (local_err != NULL) { + error_propagate(errp, local_err); + return; + } + + if (xcc->host_cpuid_required && !accel_uses_host_cpuid()) { + g_autofree char *name = x86_cpu_class_get_model_name(xcc); + error_setg(&local_err, "CPU model '%s' requires KVM or HVF", name); + goto out; + } + + if (cpu->ucode_rev == 0) { + /* The default is the same as KVM's. */ + if (IS_AMD_CPU(env)) { + cpu->ucode_rev = 0x01000065; + } else { + cpu->ucode_rev = 0x100000000ULL; + } + } + + /* mwait extended info: needed for Core compatibility */ + /* We always wake on interrupt even if host does not have the capability */ + cpu->mwait.ecx |= CPUID_MWAIT_EMX | CPUID_MWAIT_IBE; + /* For 64bit systems think about the number of physical bits to present. * ideally this should be the same as the host; anything other than matching * the host can cause incorrect guest behaviour. From patchwork Sat May 29 09:13:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudio Fontana X-Patchwork-Id: 12287801 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 15B1FC4708E for ; Sat, 29 May 2021 09:13:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E4617611ED for ; Sat, 29 May 2021 09:13:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229724AbhE2JO4 (ORCPT ); Sat, 29 May 2021 05:14:56 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:36714 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229723AbhE2JOz (ORCPT ); Sat, 29 May 2021 05:14:55 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id ADBB121915; Sat, 29 May 2021 09:13:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1622279598; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+RLLpKzaG6cee9YoeuvdoRHLOhiqV7lPKVjXnQJR+5c=; b=ykylH80xEmwxgMd21Qls+Am+RypWoqSTD20zrUMEAKHyvYo32N13VBtqkNUBSn9bPFOlmp wD08aKkXlJlyRMwO+gUvcgzNQqxQ5T1r1sNjzRa3lp/2KfoDy7Uny1fPtG+ol2p2lX8gA7 A9YL/fgbeg0Klc0TSlSbiW81iwI+8Sk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1622279598; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+RLLpKzaG6cee9YoeuvdoRHLOhiqV7lPKVjXnQJR+5c=; b=VUMBoPN7OJgUBq3ojM8vbVmDbzggH7zjcBinnkn5SNbz6NlbY72o2YYlaT1iYHD9hc5Pj9 AYD9y77TYu77UABA== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id C3FD4118DD; Sat, 29 May 2021 09:13:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1622279598; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+RLLpKzaG6cee9YoeuvdoRHLOhiqV7lPKVjXnQJR+5c=; b=ykylH80xEmwxgMd21Qls+Am+RypWoqSTD20zrUMEAKHyvYo32N13VBtqkNUBSn9bPFOlmp wD08aKkXlJlyRMwO+gUvcgzNQqxQ5T1r1sNjzRa3lp/2KfoDy7Uny1fPtG+ol2p2lX8gA7 A9YL/fgbeg0Klc0TSlSbiW81iwI+8Sk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1622279598; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+RLLpKzaG6cee9YoeuvdoRHLOhiqV7lPKVjXnQJR+5c=; b=VUMBoPN7OJgUBq3ojM8vbVmDbzggH7zjcBinnkn5SNbz6NlbY72o2YYlaT1iYHD9hc5Pj9 AYD9y77TYu77UABA== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id cPj/La0FsmCbEwAALh3uQQ (envelope-from ); Sat, 29 May 2021 09:13:17 +0000 From: Claudio Fontana To: Peter Maydell , Paolo Bonzini , Eduardo Habkost , Siddharth Chandrasekaran , =?utf-8?q?Philippe_Mathieu-Dau?= =?utf-8?q?d=C3=A9?= Cc: Claudio Fontana , "Michael S . Tsirkin" , kvm@vger.kernel.org, Marcelo Tosatti , Richard Henderson , Cameron Esfahani , Roman Bolshakov , qemu-devel@nongnu.org Subject: [PATCH 2/2] i386: run accel_cpu_instance_init as instance_post_init Date: Sat, 29 May 2021 11:13:13 +0200 Message-Id: <20210529091313.16708-3-cfontana@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210529091313.16708-1-cfontana@suse.de> References: <20210529091313.16708-1-cfontana@suse.de> MIME-Version: 1.0 Authentication-Results: imap.suse.de; none X-Spamd-Result: default: False [1.00 / 100.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; REPLY(-4.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_TWELVE(0.00)[13]; MID_CONTAINS_FROM(1.00)[]; RCVD_NO_TLS_LAST(0.10)[]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2] Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This partially fixes host and max cpu initialization, by running the accel cpu initialization only after all instance init functions are called for all X86 cpu subclasses. Partial Fix. Fixes: 48afe6e4eabf ("i386: split cpu accelerators from cpu.c, using AccelCPUClass") Signed-off-by: Claudio Fontana --- target/i386/cpu.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 6bcb7dbc2c..ae148fbd2f 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -6422,6 +6422,11 @@ static void x86_cpu_register_feature_bit_props(X86CPUClass *xcc, x86_cpu_register_bit_prop(xcc, name, w, bitnr); } +static void x86_cpu_post_initfn(Object *obj) +{ + accel_cpu_instance_init(CPU(obj)); +} + static void x86_cpu_initfn(Object *obj) { X86CPU *cpu = X86_CPU(obj); @@ -6473,9 +6478,6 @@ static void x86_cpu_initfn(Object *obj) if (xcc->model) { x86_cpu_load_model(cpu, xcc->model); } - - /* if required, do accelerator-specific cpu initializations */ - accel_cpu_instance_init(CPU(obj)); } static int64_t x86_cpu_get_arch_id(CPUState *cs) @@ -6810,6 +6812,8 @@ static const TypeInfo x86_cpu_type_info = { .parent = TYPE_CPU, .instance_size = sizeof(X86CPU), .instance_init = x86_cpu_initfn, + .instance_post_init = x86_cpu_post_initfn, + .abstract = true, .class_size = sizeof(X86CPUClass), .class_init = x86_cpu_common_class_init,