From patchwork Mon Sep 18 16:02:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13389979 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93DACCD37B0 for ; Mon, 18 Sep 2023 16:05:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229888AbjIRQFM (ORCPT ); Mon, 18 Sep 2023 12:05:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229963AbjIRQFI (ORCPT ); Mon, 18 Sep 2023 12:05:08 -0400 Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [IPv6:2a00:1450:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BAC0F30C1 for ; Mon, 18 Sep 2023 09:03:52 -0700 (PDT) Received: by mail-lj1-x22b.google.com with SMTP id 38308e7fff4ca-2bffd6c1460so25542671fa.3 for ; Mon, 18 Sep 2023 09:03:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695052984; x=1695657784; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YY2zRc5UQ1ttBDAhQdzUYI1/2Fa0E28wpiBNWWnnf1g=; b=eWi3S/iiKr9RjgREjPL/yrs63YwjNxQbfu9bt339CgVyccD3bhoifgl/L6bhE27F1s dAn0C725urmuSNJTUTKCMjaHPpPwF8qKRJ6QURkIpgUVquIWyyYK67vyFP3m+qMLMSNa vTE6OAWtOkgLFZsC8VcZaSPAH+p0HsHEDj8OBLzh1nW4Y34G+taJ3DjcvNVRAglRBPXQ bo8uOATnPpXpOAI2VzqSGpawjLhFLo7+ZHFwWXShObNJAjNeF0tQw7gzSfOcgTlBFCZC BR9SN6kLqgmb3EhPSG3UNeZcvfSDdoSbXGzcLmnlMCxCVWwPml/4T73auYaTBaeHk+Nq jlaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695052984; x=1695657784; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YY2zRc5UQ1ttBDAhQdzUYI1/2Fa0E28wpiBNWWnnf1g=; b=IUM3Pltuz4nIG/QtznSdZKeDoua27ioGWWW8x0/wrgZVghD+HfroMHMFzCefQFuPIU yYT8YstlsjkJy4uVaUtgw1nLwoRxJy2Q+vZhLWJyFc66Qm5HTZj6CbYqw5gWReY0ksAB pP8Ibj4gg1VGKHs9GyiMOfGBKVrDP3kQpHz8C0YavegjYaMll2fj7ArIf3FBkyvk4JNU xWy94WTYI7uGjAVsszdd8OyOYiIEC2/DMJiRhwCb3ALCr66+fEQOBpxfNRhmCBcOY8id V/6y2brG9X/e2PAkgIz3widWJQlPejxIcaBDIfBhCKpZuevVhbyBcslr5ado4hxUhDJg 8x7A== X-Gm-Message-State: AOJu0Yw2QXUUUGenNVYva7fY91h1qkxmGAcsRdG1p05cBq7aTTAkheDX 0uSNR0aob3VgyhXwsNN3CwKavg== X-Google-Smtp-Source: AGHT+IFFWaHmceQaMQCtP1tx1U1BqdKcHKrYFUd0/PUiwjaiOXpmM2RbiU2HoQiVRUd/I863ShUWOQ== X-Received: by 2002:a2e:3614:0:b0:2b9:f27f:e491 with SMTP id d20-20020a2e3614000000b002b9f27fe491mr9068179lja.42.1695052984526; Mon, 18 Sep 2023 09:03:04 -0700 (PDT) Received: from localhost.localdomain (static-212-193-78-212.thenetworkfactory.nl. [212.78.193.212]) by smtp.gmail.com with ESMTPSA id x5-20020a1709065ac500b00993664a9987sm6574017ejs.103.2023.09.18.09.03.02 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 18 Sep 2023 09:03:04 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Laurent Vivier , Paolo Bonzini , Max Filippov , David Hildenbrand , Peter Xu , Anton Johansson , Peter Maydell , kvm@vger.kernel.org, Marek Vasut , David Gibson , Brian Cain , Yoshinori Sato , "Edgar E . Iglesias" , Claudio Fontana , Daniel Henrique Barboza , Artyom Tarasenko , Marcelo Tosatti , qemu-ppc@nongnu.org, Liu Zhiwei , Aurelien Jarno , Ilya Leoshkevich , Daniel Henrique Barboza , Bastian Koppelmann , =?utf-8?q?C=C3=A9dric_?= =?utf-8?q?Le_Goater?= , Alistair Francis , Alessandro Di Federico , Song Gao , Marcel Apfelbaum , Chris Wulff , "Michael S. Tsirkin" , Alistair Francis , Fabiano Rosas , qemu-s390x@nongnu.org, Yanan Wang , Luc Michel , Weiwei Li , Bin Meng , Stafford Horne , Xiaojuan Yang , "Daniel P . Berrange" , Thomas Huth , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-arm@nongnu.org, Jiaxun Yang , Richard Henderson , Aleksandar Rikalo , Bernhard Beschow , Mark Cave-Ayland , qemu-riscv@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Nicholas Piggin , Greg Kurz , Michael Rolnik , Eduardo Habkost , Markus Armbruster , Palmer Dabbelt Subject: [PATCH 01/22] target/i386: Only realize existing APIC device Date: Mon, 18 Sep 2023 18:02:34 +0200 Message-ID: <20230918160257.30127-2-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230918160257.30127-1-philmd@linaro.org> References: <20230918160257.30127-1-philmd@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org APIC state is created under a certain condition, use the same condition to realize it. Having a NULL APIC state is a bug: use assert(). Signed-off-by: Philippe Mathieu-Daudé --- target/i386/cpu-sysemu.c | 9 +++------ target/i386/cpu.c | 8 +++++--- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/target/i386/cpu-sysemu.c b/target/i386/cpu-sysemu.c index 2375e48178..6a164d3769 100644 --- a/target/i386/cpu-sysemu.c +++ b/target/i386/cpu-sysemu.c @@ -272,9 +272,7 @@ void x86_cpu_apic_create(X86CPU *cpu, Error **errp) APICCommonState *apic; APICCommonClass *apic_class = apic_get_class(errp); - if (!apic_class) { - return; - } + assert(apic_class); cpu->apic_state = DEVICE(object_new_with_class(OBJECT_CLASS(apic_class))); object_property_add_child(OBJECT(cpu), "lapic", @@ -293,9 +291,8 @@ void x86_cpu_apic_realize(X86CPU *cpu, Error **errp) APICCommonState *apic; static bool apic_mmio_map_once; - if (cpu->apic_state == NULL) { - return; - } + assert(cpu->apic_state); + qdev_realize(DEVICE(cpu->apic_state), NULL, errp); /* Map APIC MMIO area */ diff --git a/target/i386/cpu.c b/target/i386/cpu.c index b2a20365e1..a23d4795e0 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -7448,9 +7448,11 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) } #ifndef CONFIG_USER_ONLY - x86_cpu_apic_realize(cpu, &local_err); - if (local_err != NULL) { - goto out; + if (cpu->env.features[FEAT_1_EDX] & CPUID_APIC || ms->smp.cpus > 1) { + x86_cpu_apic_realize(cpu, &local_err); + if (local_err != NULL) { + goto out; + } } #endif /* !CONFIG_USER_ONLY */ cpu_reset(cs); From patchwork Mon Sep 18 16:02:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13390174 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64C82C46CA1 for ; Mon, 18 Sep 2023 17:20:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230285AbjIRQeR (ORCPT ); Mon, 18 Sep 2023 12:34:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230206AbjIRQd6 (ORCPT ); Mon, 18 Sep 2023 12:33:58 -0400 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87E9176A0 for ; Mon, 18 Sep 2023 09:12:01 -0700 (PDT) Received: by mail-ej1-x631.google.com with SMTP id a640c23a62f3a-9936b3d0286so628935666b.0 for ; Mon, 18 Sep 2023 09:12:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695053518; x=1695658318; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lJh8A0itxnh0qEmv9jrQE8icd48ukduXjwQKR8H2Trw=; b=OhFKFbNTncaL0FlWnpvOsuT/+oearkCPJNKMPMW0lC73rlwj0g580fuUJa0uy1arfI LQUSkgp0GSK5RaEwXfKwVod8Y184Om55a8Uoj2r0LR1CuPMh7e4uOEqRhrth3CvbTRZN 2+jjC8ade+R7I2Zfq69hXxfFQ4LmJhPCptZtTPPkUWSUqpkLGS8bQ03cQ0OTmlksWLkg aA3c9tnTkY2AqMJ/UQ62Jc73nINyV99ndkw9LJe1spNu23WEyJUTukdkPwOq8eahOUD5 GEm8oK+iIQeC8lWZhD744Lp96GvibrtDusJJ9a+xpKaprb4XdL0vDvcqXEyrx3q3y94K GF+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695053518; x=1695658318; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lJh8A0itxnh0qEmv9jrQE8icd48ukduXjwQKR8H2Trw=; b=tO8cn3Oj+G3/rMwIZNM4ZLEMXoxqfdVG9y1vaLYPOxVs87aLPEj58Ngw2PW4B9sHga B7FN5bvjjIslELNxNdvHaSsmGkckunhgbFGSlH8TftKphLUqsR3IL/QpCR7PUdRLgoEo LNx0jNjZhIIPGilBL+OecTkL6BiFMwJoii2yalLT34usqusyvwEj8kylDQnEKkkeGDbW H6jymG1+mu0Pe75u5C/EYDrAJj+JeZVlBkxJ7pMelan6RYpRYlDridnFPAWoGcFsR5rw GXlMccVO7yvqSVfrfw1ZWUlGfnLTN2x72g8g2GY0taMUTbMUPboFIF7epJK0cThH8Mh1 5bOQ== X-Gm-Message-State: AOJu0Yx6lTNSplfXzhmIPuyYBVWWe9aFpkjKSl8BXDyPgorr2j0ZtQKy OVLz7IV+mNOsJLa3mf9SbKi1Pjwxbm7nlzTNJyPPt+Qy X-Google-Smtp-Source: AGHT+IENcyvi+doZG3AFC4PIQIYrRhEsNXfli8+UC+v7xx7kqnWdf8S7ahUZm+Cso8ML7TazVXsAxw== X-Received: by 2002:a17:907:7754:b0:9ae:1b64:94c0 with SMTP id kx20-20020a170907775400b009ae1b6494c0mr1603066ejc.55.1695052989741; Mon, 18 Sep 2023 09:03:09 -0700 (PDT) Received: from localhost.localdomain (static-212-193-78-212.thenetworkfactory.nl. [212.78.193.212]) by smtp.gmail.com with ESMTPSA id y16-20020a170906559000b0099b7276235esm6699286ejp.93.2023.09.18.09.03.08 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 18 Sep 2023 09:03:09 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Laurent Vivier , Paolo Bonzini , Max Filippov , David Hildenbrand , Peter Xu , Anton Johansson , Peter Maydell , kvm@vger.kernel.org, Marek Vasut , David Gibson , Brian Cain , Yoshinori Sato , "Edgar E . Iglesias" , Claudio Fontana , Daniel Henrique Barboza , Artyom Tarasenko , Marcelo Tosatti , qemu-ppc@nongnu.org, Liu Zhiwei , Aurelien Jarno , Ilya Leoshkevich , Daniel Henrique Barboza , Bastian Koppelmann , =?utf-8?q?C=C3=A9dric_?= =?utf-8?q?Le_Goater?= , Alistair Francis , Alessandro Di Federico , Song Gao , Marcel Apfelbaum , Chris Wulff , "Michael S. Tsirkin" , Alistair Francis , Fabiano Rosas , qemu-s390x@nongnu.org, Yanan Wang , Luc Michel , Weiwei Li , Bin Meng , Stafford Horne , Xiaojuan Yang , "Daniel P . Berrange" , Thomas Huth , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-arm@nongnu.org, Jiaxun Yang , Richard Henderson , Aleksandar Rikalo , Bernhard Beschow , Mark Cave-Ayland , qemu-riscv@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Nicholas Piggin , Greg Kurz , Michael Rolnik , Eduardo Habkost , Markus Armbruster , Palmer Dabbelt Subject: [PATCH 02/22] hw/intc/apic: Pass CPU using QOM link property Date: Mon, 18 Sep 2023 18:02:35 +0200 Message-ID: <20230918160257.30127-3-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230918160257.30127-1-philmd@linaro.org> References: <20230918160257.30127-1-philmd@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org QOM objects shouldn't access each other internals fields except using the QOM API. Declare the 'cpu' and 'base-addr' properties, set them using object_property_set_link() and qdev_prop_set_uint32() respectively. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Igor Mammedov --- hw/intc/apic_common.c | 2 ++ target/i386/cpu-sysemu.c | 11 ++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/hw/intc/apic_common.c b/hw/intc/apic_common.c index 68ad30e2f5..e28f7402ab 100644 --- a/hw/intc/apic_common.c +++ b/hw/intc/apic_common.c @@ -394,6 +394,8 @@ static Property apic_properties_common[] = { true), DEFINE_PROP_BOOL("legacy-instance-id", APICCommonState, legacy_instance_id, false), + DEFINE_PROP_LINK("cpu", APICCommonState, cpu, TYPE_X86_CPU, X86CPU *), + DEFINE_PROP_UINT32("base-addr", APICCommonState, apicbase, 0), DEFINE_PROP_END_OF_LIST(), }; diff --git a/target/i386/cpu-sysemu.c b/target/i386/cpu-sysemu.c index 6a164d3769..6edfb7e2af 100644 --- a/target/i386/cpu-sysemu.c +++ b/target/i386/cpu-sysemu.c @@ -269,7 +269,6 @@ APICCommonClass *apic_get_class(Error **errp) void x86_cpu_apic_create(X86CPU *cpu, Error **errp) { - APICCommonState *apic; APICCommonClass *apic_class = apic_get_class(errp); assert(apic_class); @@ -279,11 +278,13 @@ void x86_cpu_apic_create(X86CPU *cpu, Error **errp) OBJECT(cpu->apic_state)); object_unref(OBJECT(cpu->apic_state)); + if (!object_property_set_link(OBJECT(cpu->apic_state), "cpu", + OBJECT(cpu), errp)) { + return; + } qdev_prop_set_uint32(cpu->apic_state, "id", cpu->apic_id); - /* TODO: convert to link<> */ - apic = APIC_COMMON(cpu->apic_state); - apic->cpu = cpu; - apic->apicbase = APIC_DEFAULT_ADDRESS | MSR_IA32_APICBASE_ENABLE; + qdev_prop_set_uint32(cpu->apic_state, "base-addr", + APIC_DEFAULT_ADDRESS | MSR_IA32_APICBASE_ENABLE); } void x86_cpu_apic_realize(X86CPU *cpu, Error **errp) From patchwork Mon Sep 18 16:02:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13390094 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 374A2CD37B0 for ; Mon, 18 Sep 2023 16:42:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230486AbjIRQmz (ORCPT ); Mon, 18 Sep 2023 12:42:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229665AbjIRQmm (ORCPT ); Mon, 18 Sep 2023 12:42:42 -0400 Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [IPv6:2a00:1450:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F167844B7 for ; Mon, 18 Sep 2023 09:03:54 -0700 (PDT) Received: by mail-lj1-x230.google.com with SMTP id 38308e7fff4ca-2b962535808so74829351fa.0 for ; Mon, 18 Sep 2023 09:03:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695052995; x=1695657795; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MazgQXWzZA8uxNgPyG3XxGvrbp91MALAwpKlSsIULzk=; b=UmZqXPs1tP5SRqdWko0AcqEAteC1dCM5coCmlXgGdHZhdrnZ07dXDuuEKzdCqpMVyK av7whqbiI55qGzspAldiwiIMbQM+BLgPEqU/F9YyVZaRnhZqftdWIF0zzUR72BgtjdnI U2hFNkWPcb7WI0QyrLhrlFnsWbAcE0L5t92Ne50EzOogdzOZKtrRv4CPwCboI6Ifog6Y AufZCelsut9jRy0JLgW5tPqd1mvi1Twov4OFOhTLT83FkCCGZ0WGNplPY12/N2qU1q9Y WzX2AcEmi+9KLj46Gy31wyG+nhZ1zVUPSbITqgYri1MiyKWibRZ7iQ2/L2AivAeeD3Wb dSoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695052995; x=1695657795; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MazgQXWzZA8uxNgPyG3XxGvrbp91MALAwpKlSsIULzk=; b=oTREwfWtuIEhhHFacNPP+ZhW77F3JACwDNvp4Ojp+m4MOOsjfXLRXBOmVfztjaCMCb unPGHkqtL7ZBhem+TfiUs0bJUm9Gmp8JZPpfKz5pMneif0Ptxj1JE8PW7OKswtT/si5P RnAAuI//rx/0XUaXJS+EwWMKUApDgVtLGXBmAjSrMzdiLBrB96K9nfWvXNCGYWpq9eVE evxTiZep/pS/RfDnHhTHGPJZdyOHTlldBYVVEfw8JRr8jXtTwBxkp6zxIBczZ0VxhqWQ zcJQ8c4VM6hEH6GG8Q7IRlq3muQ5LQM7zIfqnmu2r3BBcf5uzNlZFClR6zVvY+4hjPkg llsA== X-Gm-Message-State: AOJu0YxZmS4Y6t5/TmEnZ497SRbNdLtGiQgM/J8nCYlH7cDemzmEX1cd 0C0uLvb7w5LmdYC1bfNPPG+0AA== X-Google-Smtp-Source: AGHT+IG8278V/bx3bmgpaUhHZZUcMrkwCw5Xh6lMORAxCV90jlud9/Vt30zNUM+Rqe+3rVD6prsUKA== X-Received: by 2002:a2e:8ed0:0:b0:2c0:d06:9e65 with SMTP id e16-20020a2e8ed0000000b002c00d069e65mr2857839ljl.8.1695052995061; Mon, 18 Sep 2023 09:03:15 -0700 (PDT) Received: from localhost.localdomain (static-212-193-78-212.thenetworkfactory.nl. [212.78.193.212]) by smtp.gmail.com with ESMTPSA id r11-20020a170906350b00b009934b1eb577sm6608438eja.77.2023.09.18.09.03.13 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 18 Sep 2023 09:03:14 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Laurent Vivier , Paolo Bonzini , Max Filippov , David Hildenbrand , Peter Xu , Anton Johansson , Peter Maydell , kvm@vger.kernel.org, Marek Vasut , David Gibson , Brian Cain , Yoshinori Sato , "Edgar E . Iglesias" , Claudio Fontana , Daniel Henrique Barboza , Artyom Tarasenko , Marcelo Tosatti , qemu-ppc@nongnu.org, Liu Zhiwei , Aurelien Jarno , Ilya Leoshkevich , Daniel Henrique Barboza , Bastian Koppelmann , =?utf-8?q?C=C3=A9dric_?= =?utf-8?q?Le_Goater?= , Alistair Francis , Alessandro Di Federico , Song Gao , Marcel Apfelbaum , Chris Wulff , "Michael S. Tsirkin" , Alistair Francis , Fabiano Rosas , qemu-s390x@nongnu.org, Yanan Wang , Luc Michel , Weiwei Li , Bin Meng , Stafford Horne , Xiaojuan Yang , "Daniel P . Berrange" , Thomas Huth , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-arm@nongnu.org, Jiaxun Yang , Richard Henderson , Aleksandar Rikalo , Bernhard Beschow , Mark Cave-Ayland , qemu-riscv@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Nicholas Piggin , Greg Kurz , Michael Rolnik , Eduardo Habkost , Markus Armbruster , Palmer Dabbelt Subject: [PATCH 03/22] target/i386/kvm: Correct comment in kvm_cpu_realize() Date: Mon, 18 Sep 2023 18:02:36 +0200 Message-ID: <20230918160257.30127-4-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230918160257.30127-1-philmd@linaro.org> References: <20230918160257.30127-1-philmd@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Igor Mammedov --- target/i386/kvm/kvm-cpu.c | 1 + 1 file changed, 1 insertion(+) diff --git a/target/i386/kvm/kvm-cpu.c b/target/i386/kvm/kvm-cpu.c index 7237378a7d..1fe62ce176 100644 --- a/target/i386/kvm/kvm-cpu.c +++ b/target/i386/kvm/kvm-cpu.c @@ -37,6 +37,7 @@ static bool kvm_cpu_realizefn(CPUState *cs, Error **errp) * -> cpu_exec_realizefn(): * -> accel_cpu_realizefn() * kvm_cpu_realizefn() -> host_cpu_realizefn() + * -> cpu_common_realizefn() * -> check/update ucode_rev, phys_bits, mwait */ if (cpu->max_features) { From patchwork Mon Sep 18 16:02:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13390019 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BCDE7C46CA1 for ; Mon, 18 Sep 2023 16:19:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230208AbjIRQTi (ORCPT ); Mon, 18 Sep 2023 12:19:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230150AbjIRQTX (ORCPT ); Mon, 18 Sep 2023 12:19:23 -0400 Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [IPv6:2a00:1450:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4816249C0 for ; Mon, 18 Sep 2023 09:03:57 -0700 (PDT) Received: by mail-lj1-x236.google.com with SMTP id 38308e7fff4ca-2bffdf50212so24642881fa.1 for ; Mon, 18 Sep 2023 09:03:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695053000; x=1695657800; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IHtTfQAIBirG1HCAZXzmunPPBo4zEHxiDOOzxMZ7AZo=; b=bnIhsulw7eoci7Ylexnfw0ZRWTRo/BvZhn2yefZ3ACfXZab+3/qHVbvsCrweNRZqxu gWblhhZZXOK0fds6jzaVN3MXOLr2hpaOHvANRoJLYCdIG7rbnQpsuGRXpED6K+7QqOBB /UWo5y9jfDUjzYrBP6spgmBMoqPDO0/YZqSleyZ59Bo+OmYP3vA+diKoVqHcihmBwQfd beqpLNydbg0cRKjliT07hkU65XA0jlgYOoTurhQfStYnc/wQv1xQmDiNOO4vGagBJF5K 3+LyrC2xLAWzj7+tXaw4GlOM9LVdP7syqpeTBqyKRzQheaUXmh/Gtfm2oO5iF0cp/1+w ptGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695053000; x=1695657800; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IHtTfQAIBirG1HCAZXzmunPPBo4zEHxiDOOzxMZ7AZo=; b=vaV7S7MjnwQwHlFjs1z8fCs6CJuG5uC9i7x6/AyL4LbosbATNQ68VIHyv+Ij7Rmf7k tdBfdWPT2Mijn6OuYaVIiGAB88nnpXGBTm2Pz7gIZ3Uo3x7m2Yt6EVu6ywHRi0c6EUbo 3ELCNfFxPYeDzAnc/Y2LElOZwOHoSWAv009F17wUFyiIQuizxd1V8Glkzo12Fv554mGg 2xUtnsFsgjKr67YoMc95C2H9w8q8pXJB+1DliG501SaK8EV7xjVJfF8qkT1Cb+H89uB3 Dwrb0XBbJ5NjoT8qRGPlYBQdkaeebpFAL1MaElK49jOaPd+11Biu6Pnap1pnwLEKbE0Q lhVw== X-Gm-Message-State: AOJu0YwPCcEnBwyhfKSzElRNOwhPuXwIXyLtkosmhYTv2A5rNk1hIvil J/QhrOJAlj9UQWFnVrZt04p1LQ== X-Google-Smtp-Source: AGHT+IEWZ8OvbK8IRiy/Jhtc4eSQt1wBjNiYifGIN1NUEuxb4lugjSxo6X0cKrO69EMr+Le0e2o0NA== X-Received: by 2002:a2e:a178:0:b0:2ba:6519:c50f with SMTP id u24-20020a2ea178000000b002ba6519c50fmr8070679ljl.52.1695053000497; Mon, 18 Sep 2023 09:03:20 -0700 (PDT) Received: from localhost.localdomain (static-212-193-78-212.thenetworkfactory.nl. [212.78.193.212]) by smtp.gmail.com with ESMTPSA id e7-20020a1709067e0700b0099bd0b5a2bcsm6658963ejr.101.2023.09.18.09.03.18 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 18 Sep 2023 09:03:19 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Laurent Vivier , Paolo Bonzini , Max Filippov , David Hildenbrand , Peter Xu , Anton Johansson , Peter Maydell , kvm@vger.kernel.org, Marek Vasut , David Gibson , Brian Cain , Yoshinori Sato , "Edgar E . Iglesias" , Claudio Fontana , Daniel Henrique Barboza , Artyom Tarasenko , Marcelo Tosatti , qemu-ppc@nongnu.org, Liu Zhiwei , Aurelien Jarno , Ilya Leoshkevich , Daniel Henrique Barboza , Bastian Koppelmann , =?utf-8?q?C=C3=A9dric_?= =?utf-8?q?Le_Goater?= , Alistair Francis , Alessandro Di Federico , Song Gao , Marcel Apfelbaum , Chris Wulff , "Michael S. Tsirkin" , Alistair Francis , Fabiano Rosas , qemu-s390x@nongnu.org, Yanan Wang , Luc Michel , Weiwei Li , Bin Meng , Stafford Horne , Xiaojuan Yang , "Daniel P . Berrange" , Thomas Huth , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-arm@nongnu.org, Jiaxun Yang , Richard Henderson , Aleksandar Rikalo , Bernhard Beschow , Mark Cave-Ayland , qemu-riscv@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Nicholas Piggin , Greg Kurz , Michael Rolnik , Eduardo Habkost , Markus Armbruster , Palmer Dabbelt Subject: [RFC PATCH 04/22] exec/cpu: Never call cpu_reset() before cpu_realize() Date: Mon, 18 Sep 2023 18:02:37 +0200 Message-ID: <20230918160257.30127-5-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230918160257.30127-1-philmd@linaro.org> References: <20230918160257.30127-1-philmd@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org QDev instance is expected to be in an unknown state until full object realization. Thus we shouldn't call DeviceReset() on an unrealized instance. Move the cpu_reset() call from *before* the parent realize() handler (effectively cpu_common_realizefn) to *after* it. Signed-off-by: Philippe Mathieu-Daudé --- RFC: I haven't audited all the call sites, but plan to do it, amending the result to this patch description. This used to be a problem on some targets, but as of today's master this series pass make check-{qtest,avocado}. --- target/arm/cpu.c | 2 +- target/avr/cpu.c | 2 +- target/cris/cpu.c | 2 +- target/hexagon/cpu.c | 3 +-- target/i386/cpu.c | 2 +- target/loongarch/cpu.c | 2 +- target/m68k/cpu.c | 2 +- target/mips/cpu.c | 2 +- target/nios2/cpu.c | 2 +- target/openrisc/cpu.c | 2 +- target/riscv/cpu.c | 2 +- target/rx/cpu.c | 2 +- target/s390x/cpu.c | 2 +- target/sh4/cpu.c | 2 +- target/tricore/cpu.c | 2 +- 15 files changed, 15 insertions(+), 16 deletions(-) diff --git a/target/arm/cpu.c b/target/arm/cpu.c index b9e09a702d..6aca036b85 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -2278,9 +2278,9 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) } qemu_init_vcpu(cs); - cpu_reset(cs); acc->parent_realize(dev, errp); + cpu_reset(cs); } static ObjectClass *arm_cpu_class_by_name(const char *cpu_model) diff --git a/target/avr/cpu.c b/target/avr/cpu.c index 8f741f258c..84d353f30e 100644 --- a/target/avr/cpu.c +++ b/target/avr/cpu.c @@ -120,9 +120,9 @@ static void avr_cpu_realizefn(DeviceState *dev, Error **errp) return; } qemu_init_vcpu(cs); - cpu_reset(cs); mcc->parent_realize(dev, errp); + cpu_reset(cs); } static void avr_cpu_set_int(void *opaque, int irq, int level) diff --git a/target/cris/cpu.c b/target/cris/cpu.c index a6a93c2359..079872a5cc 100644 --- a/target/cris/cpu.c +++ b/target/cris/cpu.c @@ -152,10 +152,10 @@ static void cris_cpu_realizefn(DeviceState *dev, Error **errp) return; } - cpu_reset(cs); qemu_init_vcpu(cs); ccc->parent_realize(dev, errp); + cpu_reset(cs); } #ifndef CONFIG_USER_ONLY diff --git a/target/hexagon/cpu.c b/target/hexagon/cpu.c index f155936289..7edc32701f 100644 --- a/target/hexagon/cpu.c +++ b/target/hexagon/cpu.c @@ -346,9 +346,8 @@ static void hexagon_cpu_realize(DeviceState *dev, Error **errp) "hexagon-hvx.xml", 0); qemu_init_vcpu(cs); - cpu_reset(cs); - mcc->parent_realize(dev, errp); + cpu_reset(cs); } static void hexagon_cpu_init(Object *obj) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index a23d4795e0..7faaa6915f 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -7455,9 +7455,9 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) } } #endif /* !CONFIG_USER_ONLY */ - cpu_reset(cs); xcc->parent_realize(dev, &local_err); + cpu_reset(cs); out: if (local_err != NULL) { diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c index 65f9320e34..8029e70e76 100644 --- a/target/loongarch/cpu.c +++ b/target/loongarch/cpu.c @@ -565,10 +565,10 @@ static void loongarch_cpu_realizefn(DeviceState *dev, Error **errp) loongarch_cpu_register_gdb_regs_for_features(cs); - cpu_reset(cs); qemu_init_vcpu(cs); lacc->parent_realize(dev, errp); + cpu_reset(cs); } #ifndef CONFIG_USER_ONLY diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c index 70d58471dc..2bc0a62f0e 100644 --- a/target/m68k/cpu.c +++ b/target/m68k/cpu.c @@ -321,10 +321,10 @@ static void m68k_cpu_realizefn(DeviceState *dev, Error **errp) m68k_cpu_init_gdb(cpu); - cpu_reset(cs); qemu_init_vcpu(cs); mcc->parent_realize(dev, errp); + cpu_reset(cs); } static void m68k_cpu_initfn(Object *obj) diff --git a/target/mips/cpu.c b/target/mips/cpu.c index 63da1948fd..8d6f633f72 100644 --- a/target/mips/cpu.c +++ b/target/mips/cpu.c @@ -492,10 +492,10 @@ static void mips_cpu_realizefn(DeviceState *dev, Error **errp) fpu_init(env, env->cpu_model); mvp_init(env); - cpu_reset(cs); qemu_init_vcpu(cs); mcc->parent_realize(dev, errp); + cpu_reset(cs); } static void mips_cpu_initfn(Object *obj) diff --git a/target/nios2/cpu.c b/target/nios2/cpu.c index bc5cbf81c2..876a6dcad2 100644 --- a/target/nios2/cpu.c +++ b/target/nios2/cpu.c @@ -217,12 +217,12 @@ static void nios2_cpu_realizefn(DeviceState *dev, Error **errp) realize_cr_status(cs); qemu_init_vcpu(cs); - cpu_reset(cs); /* We have reserved storage for cpuid; might as well use it. */ cpu->env.ctrl[CR_CPUID] = cs->cpu_index; ncc->parent_realize(dev, errp); + cpu_reset(cs); } #ifndef CONFIG_USER_ONLY diff --git a/target/openrisc/cpu.c b/target/openrisc/cpu.c index 61d748cfdc..cd25f1e9d5 100644 --- a/target/openrisc/cpu.c +++ b/target/openrisc/cpu.c @@ -142,9 +142,9 @@ static void openrisc_cpu_realizefn(DeviceState *dev, Error **errp) } qemu_init_vcpu(cs); - cpu_reset(cs); occ->parent_realize(dev, errp); + cpu_reset(cs); } static void openrisc_cpu_initfn(Object *obj) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index f227c7664e..7566757346 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1532,9 +1532,9 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) #endif qemu_init_vcpu(cs); - cpu_reset(cs); mcc->parent_realize(dev, errp); + cpu_reset(cs); } #ifndef CONFIG_USER_ONLY diff --git a/target/rx/cpu.c b/target/rx/cpu.c index 157e57da0f..c9c8443cbd 100644 --- a/target/rx/cpu.c +++ b/target/rx/cpu.c @@ -138,9 +138,9 @@ static void rx_cpu_realize(DeviceState *dev, Error **errp) } qemu_init_vcpu(cs); - cpu_reset(cs); rcc->parent_realize(dev, errp); + cpu_reset(cs); } static void rx_cpu_set_irq(void *opaque, int no, int request) diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c index df167493c3..0f0b11fd73 100644 --- a/target/s390x/cpu.c +++ b/target/s390x/cpu.c @@ -254,6 +254,7 @@ static void s390_cpu_realizefn(DeviceState *dev, Error **errp) s390_cpu_gdb_init(cs); qemu_init_vcpu(cs); + scc->parent_realize(dev, &err); /* * KVM requires the initial CPU reset ioctl to be executed on the target * CPU thread. CPU hotplug under single-threaded TCG will not work with @@ -266,7 +267,6 @@ static void s390_cpu_realizefn(DeviceState *dev, Error **errp) cpu_reset(cs); } - scc->parent_realize(dev, &err); out: error_propagate(errp, err); } diff --git a/target/sh4/cpu.c b/target/sh4/cpu.c index 61769ffdfa..656d71f74a 100644 --- a/target/sh4/cpu.c +++ b/target/sh4/cpu.c @@ -228,10 +228,10 @@ static void superh_cpu_realizefn(DeviceState *dev, Error **errp) return; } - cpu_reset(cs); qemu_init_vcpu(cs); scc->parent_realize(dev, errp); + cpu_reset(cs); } static void superh_cpu_initfn(Object *obj) diff --git a/target/tricore/cpu.c b/target/tricore/cpu.c index 133a9ac70e..a3610aecca 100644 --- a/target/tricore/cpu.c +++ b/target/tricore/cpu.c @@ -118,10 +118,10 @@ static void tricore_cpu_realizefn(DeviceState *dev, Error **errp) if (tricore_has_feature(env, TRICORE_FEATURE_131)) { set_feature(env, TRICORE_FEATURE_13); } - cpu_reset(cs); qemu_init_vcpu(cs); tcc->parent_realize(dev, errp); + cpu_reset(cs); } From patchwork Mon Sep 18 16:02:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13389980 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71285C46CA1 for ; Mon, 18 Sep 2023 16:05:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230010AbjIRQFR (ORCPT ); Mon, 18 Sep 2023 12:05:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230007AbjIRQFK (ORCPT ); Mon, 18 Sep 2023 12:05:10 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A03E49E6 for ; Mon, 18 Sep 2023 09:04:01 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-9adb9fa7200so949020766b.0 for ; Mon, 18 Sep 2023 09:04:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695053006; x=1695657806; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Rh71yvz4DZJTCq6SFL6CUf5QPqPF3br4cLaD1F+Juuo=; b=PQpQM4mipbPGLqFAxeL6U4c1HXIW83jmGHwm4R1nMgpJjq29HBc+INIqN4cU6FAd8w /3PGymzlP1/b/IpSVMP7olBZFpU5T0DssF8ZRMm8f39pyws/zjNywnm8wIwBKgasvPj3 OcVlqfnL36ykHCgzZda7K/kwMcK19F1dConZSa1pJOWq+XPyP2UNo26phn10CsptGTdt VK1sAJcndbba3yy33Rfz4PqT2Xg0Y3N2qE5VEgs5XyseQPOoRuC/RBj0c6DTiK02MIyM uyjsXORDb6Tu2/ShoJSGYXXYml2PIJNq4UPMuk9/d8iDSFARU+bQV60W9v3szIKiB0h1 35vA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695053006; x=1695657806; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Rh71yvz4DZJTCq6SFL6CUf5QPqPF3br4cLaD1F+Juuo=; b=juFoRz6mk/2FoIyH0ZU/p3fGzYlIlIGOJhmOx6YNTV1fj8VbtpkXNzphlmX2Oo9uBZ zOJlO4t9UeHnhir0ecLxDI/MvE+DHGOyWhRTKk8dxS1ztpMQcTgdSnsCCrboOWy+Ltpm ILtnXUDzRHXWL1WI865kSs7GrPh/OA2JQVJDGS6Tw7/bCgSGGSoSP8J78C9qLHCLh6wD unoOnpaD0NMo1I4Pn1XkenUqBWBfHkhmks8rz9QwP/20yuGOCXYxhGOT6liKDTgPvkoF YIRFir/YuuTQdAv7nd737Wfs+D3U7kIhr2HT2nfg/osIn+hId2o8RreF24n854FlonmX w7/w== X-Gm-Message-State: AOJu0Yx1papM9r+fmi8ZN4FIRvU322SedN+fFVPPzVlGm8nVP/UKitRB dDRxUUD1Ro+UhQw9IOhhPvzjHg== X-Google-Smtp-Source: AGHT+IHIXwv/SUuPL+RG4eoM3NTPC1WqPc2dc059AGReJPi585Aaau6eIEYTrSN5HoNAF0VfnJBfAg== X-Received: by 2002:a17:907:948d:b0:9aa:1794:945b with SMTP id dm13-20020a170907948d00b009aa1794945bmr143370ejc.22.1695053005806; Mon, 18 Sep 2023 09:03:25 -0700 (PDT) Received: from localhost.localdomain (static-212-193-78-212.thenetworkfactory.nl. [212.78.193.212]) by smtp.gmail.com with ESMTPSA id n8-20020a170906378800b0099cd008c1a4sm6609045ejc.136.2023.09.18.09.03.24 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 18 Sep 2023 09:03:25 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Laurent Vivier , Paolo Bonzini , Max Filippov , David Hildenbrand , Peter Xu , Anton Johansson , Peter Maydell , kvm@vger.kernel.org, Marek Vasut , David Gibson , Brian Cain , Yoshinori Sato , "Edgar E . Iglesias" , Claudio Fontana , Daniel Henrique Barboza , Artyom Tarasenko , Marcelo Tosatti , qemu-ppc@nongnu.org, Liu Zhiwei , Aurelien Jarno , Ilya Leoshkevich , Daniel Henrique Barboza , Bastian Koppelmann , =?utf-8?q?C=C3=A9dric_?= =?utf-8?q?Le_Goater?= , Alistair Francis , Alessandro Di Federico , Song Gao , Marcel Apfelbaum , Chris Wulff , "Michael S. Tsirkin" , Alistair Francis , Fabiano Rosas , qemu-s390x@nongnu.org, Yanan Wang , Luc Michel , Weiwei Li , Bin Meng , Stafford Horne , Xiaojuan Yang , "Daniel P . Berrange" , Thomas Huth , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-arm@nongnu.org, Jiaxun Yang , Richard Henderson , Aleksandar Rikalo , Bernhard Beschow , Mark Cave-Ayland , qemu-riscv@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Nicholas Piggin , Greg Kurz , Michael Rolnik , Eduardo Habkost , Markus Armbruster , Palmer Dabbelt Subject: [PATCH 05/22] exec/cpu: Call qemu_init_vcpu() once in cpu_common_realize() Date: Mon, 18 Sep 2023 18:02:38 +0200 Message-ID: <20230918160257.30127-6-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230918160257.30127-1-philmd@linaro.org> References: <20230918160257.30127-1-philmd@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org qemu_init_vcpu() is called in each ${target}_cpu_realize() before the call to parent_realize(), which is cpu_common_realizefn(). Call it once there. Signed-off-by: Philippe Mathieu-Daudé --- hw/core/cpu-common.c | 3 +++ target/alpha/cpu.c | 2 -- target/arm/cpu.c | 2 -- target/avr/cpu.c | 1 - target/cris/cpu.c | 2 -- target/hexagon/cpu.c | 1 - target/hppa/cpu.c | 1 - target/i386/cpu.c | 4 +--- target/loongarch/cpu.c | 2 -- target/m68k/cpu.c | 2 -- target/microblaze/cpu.c | 2 -- target/mips/cpu.c | 2 -- target/nios2/cpu.c | 1 - target/openrisc/cpu.c | 2 -- target/ppc/cpu_init.c | 1 - target/riscv/cpu.c | 2 -- target/rx/cpu.c | 2 -- target/s390x/cpu.c | 1 - target/sh4/cpu.c | 2 -- target/sparc/cpu.c | 2 -- target/tricore/cpu.c | 1 - target/xtensa/cpu.c | 2 -- 22 files changed, 4 insertions(+), 36 deletions(-) diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c index ced66c2b34..a3b8de7054 100644 --- a/hw/core/cpu-common.c +++ b/hw/core/cpu-common.c @@ -204,6 +204,9 @@ static void cpu_common_realizefn(DeviceState *dev, Error **errp) } } + /* Create CPU address space and vCPU thread */ + qemu_init_vcpu(cpu); + if (dev->hotplugged) { cpu_synchronize_post_init(cpu); cpu_resume(cpu); diff --git a/target/alpha/cpu.c b/target/alpha/cpu.c index 270ae787b1..eb78318bb8 100644 --- a/target/alpha/cpu.c +++ b/target/alpha/cpu.c @@ -82,8 +82,6 @@ static void alpha_cpu_realizefn(DeviceState *dev, Error **errp) return; } - qemu_init_vcpu(cs); - acc->parent_realize(dev, errp); } diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 6aca036b85..fc3772025c 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -2277,8 +2277,6 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) } } - qemu_init_vcpu(cs); - acc->parent_realize(dev, errp); cpu_reset(cs); } diff --git a/target/avr/cpu.c b/target/avr/cpu.c index 84d353f30e..d3460b3960 100644 --- a/target/avr/cpu.c +++ b/target/avr/cpu.c @@ -119,7 +119,6 @@ static void avr_cpu_realizefn(DeviceState *dev, Error **errp) error_propagate(errp, local_err); return; } - qemu_init_vcpu(cs); mcc->parent_realize(dev, errp); cpu_reset(cs); diff --git a/target/cris/cpu.c b/target/cris/cpu.c index 079872a5cc..671693a362 100644 --- a/target/cris/cpu.c +++ b/target/cris/cpu.c @@ -152,8 +152,6 @@ static void cris_cpu_realizefn(DeviceState *dev, Error **errp) return; } - qemu_init_vcpu(cs); - ccc->parent_realize(dev, errp); cpu_reset(cs); } diff --git a/target/hexagon/cpu.c b/target/hexagon/cpu.c index 7edc32701f..5b9bb3fe83 100644 --- a/target/hexagon/cpu.c +++ b/target/hexagon/cpu.c @@ -345,7 +345,6 @@ static void hexagon_cpu_realize(DeviceState *dev, Error **errp) NUM_VREGS + NUM_QREGS, "hexagon-hvx.xml", 0); - qemu_init_vcpu(cs); mcc->parent_realize(dev, errp); cpu_reset(cs); } diff --git a/target/hppa/cpu.c b/target/hppa/cpu.c index 11022f9c99..49082bd2ba 100644 --- a/target/hppa/cpu.c +++ b/target/hppa/cpu.c @@ -131,7 +131,6 @@ static void hppa_cpu_realizefn(DeviceState *dev, Error **errp) return; } - qemu_init_vcpu(cs); acc->parent_realize(dev, errp); #ifndef CONFIG_USER_ONLY diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 7faaa6915f..cb41d30aab 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -7425,15 +7425,13 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) mce_init(cpu); - qemu_init_vcpu(cs); - /* * Most Intel and certain AMD CPUs support hyperthreading. Even though QEMU * fixes this issue by adjusting CPUID_0000_0001_EBX and CPUID_8000_0008_ECX * based on inputs (sockets,cores,threads), it is still better to give * users a warning. * - * NOTE: the following code has to follow qemu_init_vcpu(). Otherwise + * NOTE: the following code has to follow cpu_common_realize(). Otherwise * cs->nr_threads hasn't be populated yet and the checking is incorrect. */ if (IS_AMD_CPU(env) && diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c index 8029e70e76..dc0ac39833 100644 --- a/target/loongarch/cpu.c +++ b/target/loongarch/cpu.c @@ -565,8 +565,6 @@ static void loongarch_cpu_realizefn(DeviceState *dev, Error **errp) loongarch_cpu_register_gdb_regs_for_features(cs); - qemu_init_vcpu(cs); - lacc->parent_realize(dev, errp); cpu_reset(cs); } diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c index 2bc0a62f0e..3da316bc30 100644 --- a/target/m68k/cpu.c +++ b/target/m68k/cpu.c @@ -321,8 +321,6 @@ static void m68k_cpu_realizefn(DeviceState *dev, Error **errp) m68k_cpu_init_gdb(cpu); - qemu_init_vcpu(cs); - mcc->parent_realize(dev, errp); cpu_reset(cs); } diff --git a/target/microblaze/cpu.c b/target/microblaze/cpu.c index 03c2c4db1f..1f19a6e07d 100644 --- a/target/microblaze/cpu.c +++ b/target/microblaze/cpu.c @@ -221,8 +221,6 @@ static void mb_cpu_realizefn(DeviceState *dev, Error **errp) return; } - qemu_init_vcpu(cs); - version = cpu->cfg.version ? cpu->cfg.version : DEFAULT_CPU_VERSION; for (i = 0; mb_cpu_lookup[i].name && version; i++) { if (strcmp(mb_cpu_lookup[i].name, version) == 0) { diff --git a/target/mips/cpu.c b/target/mips/cpu.c index 8d6f633f72..0aea69aaf9 100644 --- a/target/mips/cpu.c +++ b/target/mips/cpu.c @@ -492,8 +492,6 @@ static void mips_cpu_realizefn(DeviceState *dev, Error **errp) fpu_init(env, env->cpu_model); mvp_init(env); - qemu_init_vcpu(cs); - mcc->parent_realize(dev, errp); cpu_reset(cs); } diff --git a/target/nios2/cpu.c b/target/nios2/cpu.c index 876a6dcad2..7a92fc5f2c 100644 --- a/target/nios2/cpu.c +++ b/target/nios2/cpu.c @@ -216,7 +216,6 @@ static void nios2_cpu_realizefn(DeviceState *dev, Error **errp) } realize_cr_status(cs); - qemu_init_vcpu(cs); /* We have reserved storage for cpuid; might as well use it. */ cpu->env.ctrl[CR_CPUID] = cs->cpu_index; diff --git a/target/openrisc/cpu.c b/target/openrisc/cpu.c index cd25f1e9d5..e4ec95ca7f 100644 --- a/target/openrisc/cpu.c +++ b/target/openrisc/cpu.c @@ -141,8 +141,6 @@ static void openrisc_cpu_realizefn(DeviceState *dev, Error **errp) return; } - qemu_init_vcpu(cs); - occ->parent_realize(dev, errp); cpu_reset(cs); } diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c index 7ab5ee92d9..e2c06c1f32 100644 --- a/target/ppc/cpu_init.c +++ b/target/ppc/cpu_init.c @@ -6833,7 +6833,6 @@ static void ppc_cpu_realize(DeviceState *dev, Error **errp) init_ppc_proc(cpu); ppc_gdb_init(cs, pcc); - qemu_init_vcpu(cs); pcc->parent_realize(dev, errp); diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 7566757346..4f7ae55359 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1531,8 +1531,6 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) } #endif - qemu_init_vcpu(cs); - mcc->parent_realize(dev, errp); cpu_reset(cs); } diff --git a/target/rx/cpu.c b/target/rx/cpu.c index c9c8443cbd..089df61790 100644 --- a/target/rx/cpu.c +++ b/target/rx/cpu.c @@ -137,8 +137,6 @@ static void rx_cpu_realize(DeviceState *dev, Error **errp) return; } - qemu_init_vcpu(cs); - rcc->parent_realize(dev, errp); cpu_reset(cs); } diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c index 0f0b11fd73..416ac6c4e0 100644 --- a/target/s390x/cpu.c +++ b/target/s390x/cpu.c @@ -252,7 +252,6 @@ static void s390_cpu_realizefn(DeviceState *dev, Error **errp) qemu_register_reset(s390_cpu_machine_reset_cb, S390_CPU(dev)); #endif s390_cpu_gdb_init(cs); - qemu_init_vcpu(cs); scc->parent_realize(dev, &err); /* diff --git a/target/sh4/cpu.c b/target/sh4/cpu.c index 656d71f74a..e6690daf9a 100644 --- a/target/sh4/cpu.c +++ b/target/sh4/cpu.c @@ -228,8 +228,6 @@ static void superh_cpu_realizefn(DeviceState *dev, Error **errp) return; } - qemu_init_vcpu(cs); - scc->parent_realize(dev, errp); cpu_reset(cs); } diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c index 130ab8f578..2fdc95eda9 100644 --- a/target/sparc/cpu.c +++ b/target/sparc/cpu.c @@ -782,8 +782,6 @@ static void sparc_cpu_realizefn(DeviceState *dev, Error **errp) return; } - qemu_init_vcpu(cs); - scc->parent_realize(dev, errp); } diff --git a/target/tricore/cpu.c b/target/tricore/cpu.c index a3610aecca..0142cf556d 100644 --- a/target/tricore/cpu.c +++ b/target/tricore/cpu.c @@ -118,7 +118,6 @@ static void tricore_cpu_realizefn(DeviceState *dev, Error **errp) if (tricore_has_feature(env, TRICORE_FEATURE_131)) { set_feature(env, TRICORE_FEATURE_13); } - qemu_init_vcpu(cs); tcc->parent_realize(dev, errp); cpu_reset(cs); diff --git a/target/xtensa/cpu.c b/target/xtensa/cpu.c index acaf8c905f..300d19d45c 100644 --- a/target/xtensa/cpu.c +++ b/target/xtensa/cpu.c @@ -174,8 +174,6 @@ static void xtensa_cpu_realizefn(DeviceState *dev, Error **errp) cs->gdb_num_regs = xcc->config->gdb_regmap.num_regs; - qemu_init_vcpu(cs); - xcc->parent_realize(dev, errp); } From patchwork Mon Sep 18 16:02:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13390092 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8DD2CC46CA1 for ; Mon, 18 Sep 2023 16:42:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230438AbjIRQmh (ORCPT ); Mon, 18 Sep 2023 12:42:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230440AbjIRQmU (ORCPT ); Mon, 18 Sep 2023 12:42:20 -0400 Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [IPv6:2a00:1450:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5B3A3A9B for ; Mon, 18 Sep 2023 09:04:04 -0700 (PDT) Received: by mail-lj1-x22c.google.com with SMTP id 38308e7fff4ca-2b9c907bc68so78621831fa.2 for ; Mon, 18 Sep 2023 09:04:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695053011; x=1695657811; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PkWYWSxfkqk4N63ErKsmSMdZBfBTpiMgD55n/Z94pZY=; b=xLQU8Lfb4Bm3xgvdBHP62byB3NDN5vgEtqvAYsSokcKH0P6Xcj6d2r/o1SPKD2sWoK BVzMkrrpr3qGFducXEx9u0xhTkrP2BFFOcWPyZEbiuR+5mZJJGAy7W/icZEBZ/ZVzwmF vbI3PjFv9SWFHtGuO8d17Wj7vfW24RQS2bUY7x1/dIVzXhNuzZ1bpuczbyqjNVA9i7xZ G/3miTIsGz88puVc6nTNN508/LQhs9QUDeYEMoG0SlfLdYxHDojaXRcQsFA3KrkiGsNG eHdfGzZoj6gzeh+Ne+nEc6HFsSOuD8s4zRH/XkydSQOUCYSpxY8PB5ajsoKf77DiwX1d M+SQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695053011; x=1695657811; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PkWYWSxfkqk4N63ErKsmSMdZBfBTpiMgD55n/Z94pZY=; b=bVi0UW9j/2fLH/iymKeV2v3JoUHYtzDG4WvXKzBfcDzL6wpIMImdrbbFGViPPBPncQ 3FvUR7yHe0wIGP1hZiIvIBCjWg18ykcAX47ZV6C0h8E0VT1kyVfvrxBA4BZHy3vDYlwK XrVOQSIEgw7C+/P8EDNWu95roCdqtyvJhZWRfShzDOv0XB/aXHZ7U13jJtpTtzI07iBe MesZeRrcjafzl4KPoFToqifNoMu3dQrBsAH7odBVZVgZeNA7p3pnjRIRTlAH93kseDQd X8hrUSMMI83mwqttAkT79TKgqkH6ofCkoW3zV5jKL/y9hCkMfxiZIlO2D4a6bLtpcj5c DbOg== X-Gm-Message-State: AOJu0YyEVuecqWfUGWWLcmKnPVXSmSrZMlCw5q8iLc7lLBnbKKzmzd9S hjhkLsZ55+oJfVxADo9M1Pfpfg== X-Google-Smtp-Source: AGHT+IG9O7CyLiK/FqL5kcaE3CE/w3qepssp8f0K4INaJRuY2qrHmvactqhGEUSaLUJRFKiBVFJyXQ== X-Received: by 2002:a2e:330c:0:b0:2b6:d13a:8e34 with SMTP id d12-20020a2e330c000000b002b6d13a8e34mr7309381ljc.46.1695053010845; Mon, 18 Sep 2023 09:03:30 -0700 (PDT) Received: from localhost.localdomain (static-212-193-78-212.thenetworkfactory.nl. [212.78.193.212]) by smtp.gmail.com with ESMTPSA id o15-20020a1709061d4f00b0099cf840527csm6708419ejh.153.2023.09.18.09.03.29 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 18 Sep 2023 09:03:30 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Laurent Vivier , Paolo Bonzini , Max Filippov , David Hildenbrand , Peter Xu , Anton Johansson , Peter Maydell , kvm@vger.kernel.org, Marek Vasut , David Gibson , Brian Cain , Yoshinori Sato , "Edgar E . Iglesias" , Claudio Fontana , Daniel Henrique Barboza , Artyom Tarasenko , Marcelo Tosatti , qemu-ppc@nongnu.org, Liu Zhiwei , Aurelien Jarno , Ilya Leoshkevich , Daniel Henrique Barboza , Bastian Koppelmann , =?utf-8?q?C=C3=A9dric_?= =?utf-8?q?Le_Goater?= , Alistair Francis , Alessandro Di Federico , Song Gao , Marcel Apfelbaum , Chris Wulff , "Michael S. Tsirkin" , Alistair Francis , Fabiano Rosas , qemu-s390x@nongnu.org, Yanan Wang , Luc Michel , Weiwei Li , Bin Meng , Stafford Horne , Xiaojuan Yang , "Daniel P . Berrange" , Thomas Huth , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-arm@nongnu.org, Jiaxun Yang , Richard Henderson , Aleksandar Rikalo , Bernhard Beschow , Mark Cave-Ayland , qemu-riscv@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Nicholas Piggin , Greg Kurz , Michael Rolnik , Eduardo Habkost , Markus Armbruster , Palmer Dabbelt Subject: [PATCH 06/22] exec/cpu: Call cpu_remove_sync() once in cpu_common_unrealize() Date: Mon, 18 Sep 2023 18:02:39 +0200 Message-ID: <20230918160257.30127-7-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230918160257.30127-1-philmd@linaro.org> References: <20230918160257.30127-1-philmd@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org While create_vcpu_thread() creates a vCPU thread, its counterpart is cpu_remove_sync(), which join and destroy the thread. create_vcpu_thread() is called in qemu_init_vcpu(), itself called in cpu_common_realizefn(). Since we don't have qemu_deinit_vcpu() helper (we probably don't need any), simply destroy the thread in cpu_common_unrealizefn(). Note: only the PPC and X86 targets were calling cpu_remove_sync(), meaning all other targets were leaking the thread when the vCPU was unrealized (mostly when vCPU are hot-unplugged). Signed-off-by: Philippe Mathieu-Daudé --- hw/core/cpu-common.c | 3 +++ target/i386/cpu.c | 1 - target/ppc/cpu_init.c | 2 -- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c index a3b8de7054..e5841c59df 100644 --- a/hw/core/cpu-common.c +++ b/hw/core/cpu-common.c @@ -221,6 +221,9 @@ static void cpu_common_unrealizefn(DeviceState *dev) /* NOTE: latest generic point before the cpu is fully unrealized */ cpu_exec_unrealizefn(cpu); + + /* Destroy vCPU thread */ + cpu_remove_sync(cpu); } static void cpu_common_initfn(Object *obj) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index cb41d30aab..d79797d963 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -7470,7 +7470,6 @@ static void x86_cpu_unrealizefn(DeviceState *dev) X86CPUClass *xcc = X86_CPU_GET_CLASS(dev); #ifndef CONFIG_USER_ONLY - cpu_remove_sync(CPU(dev)); qemu_unregister_reset(x86_cpu_machine_reset_cb, dev); #endif diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c index e2c06c1f32..24d4e8fa7e 100644 --- a/target/ppc/cpu_init.c +++ b/target/ppc/cpu_init.c @@ -6853,8 +6853,6 @@ static void ppc_cpu_unrealize(DeviceState *dev) pcc->parent_unrealize(dev); - cpu_remove_sync(CPU(cpu)); - destroy_ppc_opcodes(cpu); } From patchwork Mon Sep 18 16:02:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13390087 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75822CD37B0 for ; Mon, 18 Sep 2023 16:39:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230155AbjIRQja (ORCPT ); Mon, 18 Sep 2023 12:39:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229709AbjIRQjQ (ORCPT ); Mon, 18 Sep 2023 12:39:16 -0400 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD33D1B1 for ; Mon, 18 Sep 2023 09:11:17 -0700 (PDT) Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-502984f5018so7818607e87.3 for ; Mon, 18 Sep 2023 09:11:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695053474; x=1695658274; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kTBjPJZgBk13UdBUXwIisPTyIoW0XcuNCZty165NaD0=; b=WKpn98SV6of9c1lnbWY3PSv8hh6KASrw0feSpACl9JhxETN7d6WhzVBxDE1WP3FiL5 7X/sY9FxUG9QpUC1non50cWeb8eAgi27KMh/phpbj9Ii+1PgHOr3CJhT27ryTNRl7nFd pxm5RyRvM/BzbjXM7P4YN/+ch4paWWLaWvRN9vv+OEGDdQ8rHpGjqk1/hC6Kej1iMIm7 D66T1I0lwOoHIDRafMjTkSR25WgLX9DTRtTxCDU7LFvjmRsMdjiTgd2VqJmB8db8ZYDE WEuqqMsqpMEfNMpeSQONMOzISw6elY2FFH4G6jVTJhJaIgtiecKF5fBjTBxl0AWstMJU K3BQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695053474; x=1695658274; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kTBjPJZgBk13UdBUXwIisPTyIoW0XcuNCZty165NaD0=; b=VTYsrPkmROsnV797IgI6RR3xLBU3EnJjatuN4lofbUzikBqMllcGjSOsF9VXsLDThX wmuHBA/Q4aD+pkQDrApA6VG9tTFgSHAjkmz+9yZTN+OzsBDXAov2ihZnyhzdlMW77Yw2 +at+1pA0ITOfHbbH6kZTkiXMbMuYCNHFRG6RPkgtFMWdvoTqwBunWHNNsux9zP4yKUzT 2x4wphPi1AqjTjV3Yl+sdl4nybieIFFvI8PJz7amYhFQdJcvCyLd8GGL/iNtX1uVbDEK EfPlV1dZleOAmRimsHI0i848tkleHPW2T6nUpHfiMLWGDn3mdy0jY/jx7KQAtb4j5KGv RaSg== X-Gm-Message-State: AOJu0Yy8hSal8TD2txzKPgFZG55tWMuh+Z67KGSKhvgQFGCkS2GGpNF+ dXhuu1UJiheA/gdNtm9f+qJc2R+FWDHndZiZuq/DVibJ X-Google-Smtp-Source: AGHT+IFq/QL5z5bo/y5y/kDRcLT1d9XsePcCQP72fHn+R4rgmGpcF6OIn0/xzDT8r3fspp9H+r5Uyw== X-Received: by 2002:a05:6402:1bc8:b0:530:be79:49e7 with SMTP id ch8-20020a0564021bc800b00530be7949e7mr6068787edb.37.1695053016011; Mon, 18 Sep 2023 09:03:36 -0700 (PDT) Received: from localhost.localdomain (static-212-193-78-212.thenetworkfactory.nl. [212.78.193.212]) by smtp.gmail.com with ESMTPSA id eh16-20020a0564020f9000b005256aaa6e7asm1688491edb.78.2023.09.18.09.03.34 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 18 Sep 2023 09:03:35 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Laurent Vivier , Paolo Bonzini , Max Filippov , David Hildenbrand , Peter Xu , Anton Johansson , Peter Maydell , kvm@vger.kernel.org, Marek Vasut , David Gibson , Brian Cain , Yoshinori Sato , "Edgar E . Iglesias" , Claudio Fontana , Daniel Henrique Barboza , Artyom Tarasenko , Marcelo Tosatti , qemu-ppc@nongnu.org, Liu Zhiwei , Aurelien Jarno , Ilya Leoshkevich , Daniel Henrique Barboza , Bastian Koppelmann , =?utf-8?q?C=C3=A9dric_?= =?utf-8?q?Le_Goater?= , Alistair Francis , Alessandro Di Federico , Song Gao , Marcel Apfelbaum , Chris Wulff , "Michael S. Tsirkin" , Alistair Francis , Fabiano Rosas , qemu-s390x@nongnu.org, Yanan Wang , Luc Michel , Weiwei Li , Bin Meng , Stafford Horne , Xiaojuan Yang , "Daniel P . Berrange" , Thomas Huth , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-arm@nongnu.org, Jiaxun Yang , Richard Henderson , Aleksandar Rikalo , Bernhard Beschow , Mark Cave-Ayland , qemu-riscv@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Nicholas Piggin , Greg Kurz , Michael Rolnik , Eduardo Habkost , Markus Armbruster , Palmer Dabbelt , xianglai li , "Salil Mehta" , Igor Mammedov , Ani Sinha , Bibo Mao Subject: [PATCH 07/22] exec/cpu: Introduce the CPU address space destruction function Date: Mon, 18 Sep 2023 18:02:40 +0200 Message-ID: <20230918160257.30127-8-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230918160257.30127-1-philmd@linaro.org> References: <20230918160257.30127-1-philmd@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: xianglai li Introduce new function to destroy CPU address space resources for cpu hot-(un)plug. Co-authored-by: "Salil Mehta" Cc: "Salil Mehta" Cc: Xiaojuan Yang Cc: Song Gao Cc: "Michael S. Tsirkin" Cc: Igor Mammedov Cc: Ani Sinha Cc: Paolo Bonzini Cc: Richard Henderson Cc: Eduardo Habkost Cc: Marcel Apfelbaum Cc: "Philippe Mathieu-Daudé" Cc: Yanan Wang Cc: "Daniel P. Berrangé" Cc: Peter Xu Cc: David Hildenbrand Cc: Bibo Mao Signed-off-by: xianglai li Message-ID: <3a4fc2a3df4b767c3c296a7da3bc15ca9c251316.1694433326.git.lixianglai@loongson.cn> --- include/exec/cpu-common.h | 8 ++++++++ include/hw/core/cpu.h | 1 + softmmu/physmem.c | 24 ++++++++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h index 41788c0bdd..eb56a228a2 100644 --- a/include/exec/cpu-common.h +++ b/include/exec/cpu-common.h @@ -120,6 +120,14 @@ size_t qemu_ram_pagesize_largest(void); */ void cpu_address_space_init(CPUState *cpu, int asidx, const char *prefix, MemoryRegion *mr); +/** + * cpu_address_space_destroy: + * @cpu: CPU for which address space needs to be destroyed + * @asidx: integer index of this address space + * + * Note that with KVM only one address space is supported. + */ +void cpu_address_space_destroy(CPUState *cpu, int asidx); void cpu_physical_memory_rw(hwaddr addr, void *buf, hwaddr len, bool is_write); diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 92a4234439..c90cf3a162 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -366,6 +366,7 @@ struct CPUState { QSIMPLEQ_HEAD(, qemu_work_item) work_list; CPUAddressSpace *cpu_ases; + int cpu_ases_ref_count; int num_ases; AddressSpace *as; MemoryRegion *memory; diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 18277ddd67..c75e3e8042 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -761,6 +761,7 @@ void cpu_address_space_init(CPUState *cpu, int asidx, if (!cpu->cpu_ases) { cpu->cpu_ases = g_new0(CPUAddressSpace, cpu->num_ases); + cpu->cpu_ases_ref_count = cpu->num_ases; } newas = &cpu->cpu_ases[asidx]; @@ -774,6 +775,29 @@ void cpu_address_space_init(CPUState *cpu, int asidx, } } +void cpu_address_space_destroy(CPUState *cpu, int asidx) +{ + CPUAddressSpace *cpuas; + + assert(asidx < cpu->num_ases); + assert(asidx == 0 || !kvm_enabled()); + assert(cpu->cpu_ases); + + cpuas = &cpu->cpu_ases[asidx]; + if (tcg_enabled()) { + memory_listener_unregister(&cpuas->tcg_as_listener); + } + + address_space_destroy(cpuas->as); + + cpu->cpu_ases_ref_count--; + if (cpu->cpu_ases_ref_count == 0) { + g_free(cpu->cpu_ases); + cpu->cpu_ases = NULL; + } + +} + AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx) { /* Return the AddressSpace corresponding to the specified index */ From patchwork Mon Sep 18 16:02:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13390093 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14B5FC46CA1 for ; Mon, 18 Sep 2023 16:42:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230497AbjIRQmn (ORCPT ); Mon, 18 Sep 2023 12:42:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230398AbjIRQmY (ORCPT ); Mon, 18 Sep 2023 12:42:24 -0400 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B280A2D69 for ; Mon, 18 Sep 2023 09:04:08 -0700 (PDT) Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-51e28cac164so12373095a12.1 for ; Mon, 18 Sep 2023 09:04:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695053021; x=1695657821; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fSCS2zUfZAE6ogrinmDPrOXdED/BfB+BaLaX0u0zcLg=; b=DrsWzepJBQKFVAtKapF2DbXUL7A+GJxmCStgp/qH2o5iu+8icPa6iZk1+xQIGgqFrc hpIfaNb7PIN0g3GYs/XMTF/aVOtHieYKIM/EPFg+G0wpd1I6OOc34aYok/LANaNCOl90 wQAYPMBNnYbvlFPhq04fpR+tFmAMVc4Wo5VOSuSJXk7926X0bmO52JmhNju17yiRKicC J4n0Rm2TClt1SiWGcQT8+NGFIScdEbSXkDyNVkpHg5uaFkZ6VdzH1sOaDSDzAKkH35ZA OYUiUR1DDKc3fbqVKwz0EwBgBX7O+aV26FDjAYtiQ2es6/ct+4H2TTqApA7iyzcd94ae kAxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695053021; x=1695657821; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fSCS2zUfZAE6ogrinmDPrOXdED/BfB+BaLaX0u0zcLg=; b=xH4zSRtMaflNV0JYCSzwD4D8YSGgh2985Sg16jDXKo8B9kJiOqb8iFgKnx7Oi/nqgI A9ht2yFO1i8wrMElKqiBAA/EGVCsP19gDuAnprXsJamIQnW50akIuSLjNhI2HIMz9mxl B9YcBLcgZSJTcnImKqDuENKWJjFCzMMP2PZ8nvcyEjmKFUVDLQWWeRyFp/oA63K1l44u K1ePxuZRe4BJpu/N13tSb9yq+wS4P+KXZPDVCfvICs/V3Z1tmpWByblE5q0psXU4ogay CFZLajqBVhknyL3ikkKQ1r250Peb3kZUP3iiP4Bpt8yWwkPrBZ8tu3hgQpqXXAFAdaYC WZ/w== X-Gm-Message-State: AOJu0YylvlSbdtVgH7tNKtvFzyXN4ffJTgtG/S6WMD634KGe2bHabGGx p3RmCsZsP7E9kfD70pG+9M/tow== X-Google-Smtp-Source: AGHT+IFbTianQZOGFuSjVlX566F74BXdJs5acopl7EmpAQkaG51ohmS+uPCdYH5B96NaIiVcrKe7YA== X-Received: by 2002:a17:907:62a6:b0:9ad:cbc0:9f47 with SMTP id nd38-20020a17090762a600b009adcbc09f47mr116109ejc.12.1695053021006; Mon, 18 Sep 2023 09:03:41 -0700 (PDT) Received: from localhost.localdomain (static-212-193-78-212.thenetworkfactory.nl. [212.78.193.212]) by smtp.gmail.com with ESMTPSA id ck9-20020a0564021c0900b005231e3d89efsm2684962edb.31.2023.09.18.09.03.39 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 18 Sep 2023 09:03:40 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Laurent Vivier , Paolo Bonzini , Max Filippov , David Hildenbrand , Peter Xu , Anton Johansson , Peter Maydell , kvm@vger.kernel.org, Marek Vasut , David Gibson , Brian Cain , Yoshinori Sato , "Edgar E . Iglesias" , Claudio Fontana , Daniel Henrique Barboza , Artyom Tarasenko , Marcelo Tosatti , qemu-ppc@nongnu.org, Liu Zhiwei , Aurelien Jarno , Ilya Leoshkevich , Daniel Henrique Barboza , Bastian Koppelmann , =?utf-8?q?C=C3=A9dric_?= =?utf-8?q?Le_Goater?= , Alistair Francis , Alessandro Di Federico , Song Gao , Marcel Apfelbaum , Chris Wulff , "Michael S. Tsirkin" , Alistair Francis , Fabiano Rosas , qemu-s390x@nongnu.org, Yanan Wang , Luc Michel , Weiwei Li , Bin Meng , Stafford Horne , Xiaojuan Yang , "Daniel P . Berrange" , Thomas Huth , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-arm@nongnu.org, Jiaxun Yang , Richard Henderson , Aleksandar Rikalo , Bernhard Beschow , Mark Cave-Ayland , qemu-riscv@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Nicholas Piggin , Greg Kurz , Michael Rolnik , Eduardo Habkost , Markus Armbruster , Palmer Dabbelt Subject: [PATCH 08/22] exec/cpu: RFC Destroy vCPU address spaces in cpu_common_unrealize() Date: Mon, 18 Sep 2023 18:02:41 +0200 Message-ID: <20230918160257.30127-9-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230918160257.30127-1-philmd@linaro.org> References: <20230918160257.30127-1-philmd@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org We create at least one vCPU address space by default in qemu_init_vcpu(), itself called in cpu_common_realizefn(). Since we don't have qemu_deinit_vcpu() helper (we probably don't need any), simply destroy all the address spaces in cpu_common_unrealizefn(), *after* the thread is destroyed. Note: all targets were leaking the vCPU address spaces upon vCPU unrealize (like hot-unplugged actions). Signed-off-by: Philippe Mathieu-Daudé --- hw/core/cpu-common.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c index e5841c59df..35c0cc4dad 100644 --- a/hw/core/cpu-common.c +++ b/hw/core/cpu-common.c @@ -224,6 +224,11 @@ static void cpu_common_unrealizefn(DeviceState *dev) /* Destroy vCPU thread */ cpu_remove_sync(cpu); + + /* Destroy CPU address space */ + for (unsigned idx = 0; idx < cpu->num_ases; idx++) { + cpu_address_space_destroy(cpu, idx); + } } static void cpu_common_initfn(Object *obj) From patchwork Mon Sep 18 16:02:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13390088 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 386F5CD37B0 for ; Mon, 18 Sep 2023 16:42:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230348AbjIRQm1 (ORCPT ); Mon, 18 Sep 2023 12:42:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230346AbjIRQmO (ORCPT ); Mon, 18 Sep 2023 12:42:14 -0400 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8530930FC for ; Mon, 18 Sep 2023 09:04:11 -0700 (PDT) Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-991c786369cso637508466b.1 for ; Mon, 18 Sep 2023 09:04:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695053026; x=1695657826; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hSVRQGIJEmce1VSEx8yaDe0o7AipRr5BDfgLzGOyz48=; b=M2kBVeM3dI60skb5HWNU5zPVPQw4We/Zu1++N/sMSBDSlWRIPW8ZRgsfEI5DhTO4Y/ 8PXyb7qsYu8kTS+sEb2W9ktjLRaLrCY0FRyncACqpxoa+YdWKinIgdR+u3tKibg07XBP DCns4AQ6x6/4HwQC9VCAWca8Mruk9RIII9UhWbnbwu4ctbjjkDOQ7NRZhRj+oCpWd9Di wnToxbwGG6Of53KO7HvE7QktEzwjR/zXAvkflgw4ui21VuvgaFyvUK63Axr/v+NkQQrm w88qB9GGiBDRRDRgYWc0mLOsuB1M0A471U2hlOnV0lkLx5JhmzHSUY/zRf51CAR+UKv9 8Q1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695053026; x=1695657826; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hSVRQGIJEmce1VSEx8yaDe0o7AipRr5BDfgLzGOyz48=; b=iMSHnf/NRT66slhfqjn0eraeVYUpMgJJEpw2Kpo1Qle03qrH3egc3+AzHKmvdlF58E WCT5Jx2pbh3eVMay3hnWcEUyxyehg9NEBZWNufgAglIQNugsP34i7RxaiOdXowIdqKYO 5QDmrgQNi8iGEDLlChbucPRsPundgiEFGmgK5mV9D6UWYesopXMl3yxJDuSjbnQdDhKr nacI+nVk94OePQo0vw8xCn4Z2V90gA2NAe+AcwfOA/W5HZCChPrKkVSa7XUV62wQ9FQz sh5+0rA/NJFVyLYJyfArBvPmPJ1Hcue94iWcaBZTcj3j5CCVa25maKlSuG0Wych4hmsG 7dYw== X-Gm-Message-State: AOJu0YxpiftjhkFtns1CmG0kfV4/Q5j0dCoptxHjMMsCkDsWqkpMCAzC XizIN0wt3zUHSp6uG6UlpZdrOg== X-Google-Smtp-Source: AGHT+IG4piDQtxZVYFiU0HjN8n/Q699dig17N/FQPVs1xyeDcBS2KjVyyREmZ08RNzkeawSSuXGK6A== X-Received: by 2002:a17:906:74d5:b0:9a1:8ee9:cc0b with SMTP id z21-20020a17090674d500b009a18ee9cc0bmr8829825ejl.21.1695053026100; Mon, 18 Sep 2023 09:03:46 -0700 (PDT) Received: from localhost.localdomain (static-212-193-78-212.thenetworkfactory.nl. [212.78.193.212]) by smtp.gmail.com with ESMTPSA id g5-20020a170906394500b0099bc038eb2bsm6614676eje.58.2023.09.18.09.03.44 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 18 Sep 2023 09:03:45 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Laurent Vivier , Paolo Bonzini , Max Filippov , David Hildenbrand , Peter Xu , Anton Johansson , Peter Maydell , kvm@vger.kernel.org, Marek Vasut , David Gibson , Brian Cain , Yoshinori Sato , "Edgar E . Iglesias" , Claudio Fontana , Daniel Henrique Barboza , Artyom Tarasenko , Marcelo Tosatti , qemu-ppc@nongnu.org, Liu Zhiwei , Aurelien Jarno , Ilya Leoshkevich , Daniel Henrique Barboza , Bastian Koppelmann , =?utf-8?q?C=C3=A9dric_?= =?utf-8?q?Le_Goater?= , Alistair Francis , Alessandro Di Federico , Song Gao , Marcel Apfelbaum , Chris Wulff , "Michael S. Tsirkin" , Alistair Francis , Fabiano Rosas , qemu-s390x@nongnu.org, Yanan Wang , Luc Michel , Weiwei Li , Bin Meng , Stafford Horne , Xiaojuan Yang , "Daniel P . Berrange" , Thomas Huth , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-arm@nongnu.org, Jiaxun Yang , Richard Henderson , Aleksandar Rikalo , Bernhard Beschow , Mark Cave-Ayland , qemu-riscv@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Nicholas Piggin , Greg Kurz , Michael Rolnik , Eduardo Habkost , Markus Armbruster , Palmer Dabbelt Subject: [PATCH 09/22] target/arm: Create timers *after* accelerator vCPU is realized Date: Mon, 18 Sep 2023 18:02:42 +0200 Message-ID: <20230918160257.30127-10-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230918160257.30127-1-philmd@linaro.org> References: <20230918160257.30127-1-philmd@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Architecture specific hardware doesn't have a particular dependency on the accelerator vCPU (created with cpu_exec_realizefn), and can be initialized *after* the vCPU is realized. Doing so allows further generic API simplification (in few commits). Signed-off-by: Philippe Mathieu-Daudé --- target/arm/cpu.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/target/arm/cpu.c b/target/arm/cpu.c index fc3772025c..46d3f70d63 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -1748,7 +1748,15 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) return; } } +#endif + cpu_exec_realizefn(cs, &local_err); + if (local_err != NULL) { + error_propagate(errp, local_err); + return; + } + +#ifndef CONFIG_USER_ONLY { uint64_t scale; @@ -1776,12 +1784,6 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) } #endif - cpu_exec_realizefn(cs, &local_err); - if (local_err != NULL) { - error_propagate(errp, local_err); - return; - } - arm_cpu_finalize_features(cpu, &local_err); if (local_err != NULL) { error_propagate(errp, local_err); From patchwork Mon Sep 18 16:02:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13390001 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC514C46CA1 for ; Mon, 18 Sep 2023 16:18:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230103AbjIRQSO (ORCPT ); Mon, 18 Sep 2023 12:18:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230012AbjIRQSC (ORCPT ); Mon, 18 Sep 2023 12:18:02 -0400 Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 133CDCF4 for ; Mon, 18 Sep 2023 09:04:15 -0700 (PDT) Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-5031426b626so2063493e87.3 for ; Mon, 18 Sep 2023 09:04:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695053031; x=1695657831; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dCQpcHiGYl2b5PMw9sHU7Xzs4il9aZ3go8echWC+OUY=; b=TLTCmuWT1Byc58c/W3YshvclXkn1rzKiKOc71GGQ5Bk2pT7sf8FEJsyF0SIs+IMVfb qRUQUEkta7xOl0Ih4pJ/U1bC+NG8G8qBM1KW1mXOT/e1QntSODpCut/TbyHPBXCKSe6B uLiND/bIvmbu2dlFy2dQTdnKC1FZd8YMnODI9eOFSN8o8h9TtiptpuJXGtgF+PRwo19d UuZojQVJhowHgTiB0D5YeybyUpjVHvzXCevl5mK51Jnokr0XdwjPYc5MCdQwjCtMS3Uh msfjLT/clsWaBk3E84+l2sS9yQBuSTM9tBMTnqJzVa1123z8tvP0hzFFHzxMY8j+ygZD xxIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695053031; x=1695657831; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dCQpcHiGYl2b5PMw9sHU7Xzs4il9aZ3go8echWC+OUY=; b=XnmDfMnY82A0roHiBO8suwy6ZxuV81Z3omG9C4l8mCuk9iRW1CEEuJ0L+Ku8rq2Seb Wy87t2QxV5tCMdFlMa7u0rFum0dPR44loBX1rQiWa/Nob8IXvyzI7AC1L8t3GEETwTq9 jVlUfCH8yTosvufkEg9MBh7vaeL9fE8XSsL0IY10hY9kwbQ6DTjfeWIhQGCDTHbmvbCe 2D+qrxdJi2DY/CJ2H5JSaM4FETBDZPhcpoPqnes5k6eFxl7Uv9EN1u7sOoiw+sMUKPsy 4vIYNOXCcXZZ+hIciln6DRYlugcztc3IVwRz51vT/Hheus2SHTUwr7LNMa3FV3RKmqTh Ck/w== X-Gm-Message-State: AOJu0YyGfyt2Eov3fGjk2GMmT1qJmgEjz6CUjY6EIi7QFfcI7qffgoIV oPE5Y0SNnaA8Aok3HVADTgrNdg== X-Google-Smtp-Source: AGHT+IGy+sW3/rMWVgA+iQsVUNjPLRtt/VMoay0ZFOuWvfTpfSlLeQiHWwG9NxI8+yiSPP5hV5k4jw== X-Received: by 2002:a05:6512:3a9:b0:4fe:5860:7abf with SMTP id v9-20020a05651203a900b004fe58607abfmr6929316lfp.13.1695053031505; Mon, 18 Sep 2023 09:03:51 -0700 (PDT) Received: from localhost.localdomain (static-212-193-78-212.thenetworkfactory.nl. [212.78.193.212]) by smtp.gmail.com with ESMTPSA id n3-20020a50cc43000000b0053132e5ea61sm913803edi.30.2023.09.18.09.03.49 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 18 Sep 2023 09:03:51 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Laurent Vivier , Paolo Bonzini , Max Filippov , David Hildenbrand , Peter Xu , Anton Johansson , Peter Maydell , kvm@vger.kernel.org, Marek Vasut , David Gibson , Brian Cain , Yoshinori Sato , "Edgar E . Iglesias" , Claudio Fontana , Daniel Henrique Barboza , Artyom Tarasenko , Marcelo Tosatti , qemu-ppc@nongnu.org, Liu Zhiwei , Aurelien Jarno , Ilya Leoshkevich , Daniel Henrique Barboza , Bastian Koppelmann , =?utf-8?q?C=C3=A9dric_?= =?utf-8?q?Le_Goater?= , Alistair Francis , Alessandro Di Federico , Song Gao , Marcel Apfelbaum , Chris Wulff , "Michael S. Tsirkin" , Alistair Francis , Fabiano Rosas , qemu-s390x@nongnu.org, Yanan Wang , Luc Michel , Weiwei Li , Bin Meng , Stafford Horne , Xiaojuan Yang , "Daniel P . Berrange" , Thomas Huth , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-arm@nongnu.org, Jiaxun Yang , Richard Henderson , Aleksandar Rikalo , Bernhard Beschow , Mark Cave-Ayland , qemu-riscv@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Nicholas Piggin , Greg Kurz , Michael Rolnik , Eduardo Habkost , Markus Armbruster , Palmer Dabbelt Subject: [PATCH 10/22] target/hppa: Create timer *after* accelerator vCPU is realized Date: Mon, 18 Sep 2023 18:02:43 +0200 Message-ID: <20230918160257.30127-11-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230918160257.30127-1-philmd@linaro.org> References: <20230918160257.30127-1-philmd@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Architecture specific hardware doesn't have a particular dependency on the accelerator vCPU (created with cpu_exec_realizefn), and can be initialized *after* the vCPU is realized. Doing so allows further generic API simplification (in few commits). Signed-off-by: Philippe Mathieu-Daudé --- target/hppa/cpu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/target/hppa/cpu.c b/target/hppa/cpu.c index 49082bd2ba..b0d106b6c7 100644 --- a/target/hppa/cpu.c +++ b/target/hppa/cpu.c @@ -131,8 +131,6 @@ static void hppa_cpu_realizefn(DeviceState *dev, Error **errp) return; } - acc->parent_realize(dev, errp); - #ifndef CONFIG_USER_ONLY { HPPACPU *cpu = HPPA_CPU(cs); @@ -140,6 +138,8 @@ static void hppa_cpu_realizefn(DeviceState *dev, Error **errp) hppa_cpu_alarm_timer, cpu); } #endif + + acc->parent_realize(dev, errp); } static void hppa_cpu_initfn(Object *obj) From patchwork Mon Sep 18 16:02:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13390068 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1CDC7CD37B0 for ; Mon, 18 Sep 2023 16:39:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230341AbjIRQjL (ORCPT ); Mon, 18 Sep 2023 12:39:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230063AbjIRQi6 (ORCPT ); Mon, 18 Sep 2023 12:38:58 -0400 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A9A572B2 for ; Mon, 18 Sep 2023 09:11:56 -0700 (PDT) Received: by mail-lf1-x12b.google.com with SMTP id 2adb3069b0e04-50308217223so2963411e87.3 for ; Mon, 18 Sep 2023 09:11:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695053515; x=1695658315; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=I+18fO8c7Dk0qCgNhOL8JkONKbHnDNHi1cgc68a1fr4=; b=LzCn+vfH3n+LrDRQU6qdQlYv4/2HMwzGWSAVKSYbe+8Y5pAgOfc0ZXI3Sflufv2xTp sZSa6b/JAY6PNuQJmc5VnoPYYwoFhlM0U1PgC25oiiIXXiRWZ3BUuwUQlejFx59Gu93n dvdd0cO7URmQ/oh8Hcu+LS3V6eO5cC3ElJapV1n4oEn6IDuKHS8KWmbdsXLMkc4jXqK4 EzyrVu2m3NhFGyiAXAQOkEPbIfglOh2bVkD1QxVlShC1fAPKjzs2TusEMZxIg3leswKM rCrw8zrTaoPaK/henG7OZLe+eoa7NyIU6ivbzSecsRRUNcS8CJRedcseMPbo0YFBrG/v FU3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695053515; x=1695658315; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=I+18fO8c7Dk0qCgNhOL8JkONKbHnDNHi1cgc68a1fr4=; b=IU5xXOExvB/WRwZIYeDKqlpn8hzsGuZgsVMfao5cIUTyJBcHd+SHdCfckAegHoz9QY SezkZa9lZqFhLFP7Iifp0YVIoO6+lVstzE865DpI/aZJPVysVpiT39u6kcT13uP93OqE NZLVhgs/l1CLezgO8tzjKkvSOcXLtUaa4HEQY6KFvfJ0bnho2IJtGryIvo95IIOa7ZuL smISHVYzMHUmIe/xfW2LxfOkBm/e+bhZL3nk4zHQI893lad8u6owy/S2DYQCknC7SSe8 LCe3E1U6e79hx0eoh9P0040uYBsv13njDE0hybUO/lKNpYh9M81iWW9TkecAb73ueEuN 4zPA== X-Gm-Message-State: AOJu0YwEkz/SscqpAdAuNSyGrH1qbbDrEd2DcW8z+MSIUiWAe2pJfFAH OERknoXThZBHT44678VuYiP30vWfBQwN6NjneGoa+yEN X-Google-Smtp-Source: AGHT+IGkFn7qy0jz8oacmoGjjfPL41FojFiYCtkDQb0dCjnyLoNnL5YigEsFHJXz/34UHFIkqAHEBQ== X-Received: by 2002:a17:906:74db:b0:9ad:e3f0:f335 with SMTP id z27-20020a17090674db00b009ade3f0f335mr6095624ejl.70.1695053037410; Mon, 18 Sep 2023 09:03:57 -0700 (PDT) Received: from localhost.localdomain (static-212-193-78-212.thenetworkfactory.nl. [212.78.193.212]) by smtp.gmail.com with ESMTPSA id qt11-20020a170906eceb00b009a19fa8d2e9sm6481188ejb.206.2023.09.18.09.03.55 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 18 Sep 2023 09:03:56 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Laurent Vivier , Paolo Bonzini , Max Filippov , David Hildenbrand , Peter Xu , Anton Johansson , Peter Maydell , kvm@vger.kernel.org, Marek Vasut , David Gibson , Brian Cain , Yoshinori Sato , "Edgar E . Iglesias" , Claudio Fontana , Daniel Henrique Barboza , Artyom Tarasenko , Marcelo Tosatti , qemu-ppc@nongnu.org, Liu Zhiwei , Aurelien Jarno , Ilya Leoshkevich , Daniel Henrique Barboza , Bastian Koppelmann , =?utf-8?q?C=C3=A9dric_?= =?utf-8?q?Le_Goater?= , Alistair Francis , Alessandro Di Federico , Song Gao , Marcel Apfelbaum , Chris Wulff , "Michael S. Tsirkin" , Alistair Francis , Fabiano Rosas , qemu-s390x@nongnu.org, Yanan Wang , Luc Michel , Weiwei Li , Bin Meng , Stafford Horne , Xiaojuan Yang , "Daniel P . Berrange" , Thomas Huth , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-arm@nongnu.org, Jiaxun Yang , Richard Henderson , Aleksandar Rikalo , Bernhard Beschow , Mark Cave-Ayland , qemu-riscv@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Nicholas Piggin , Greg Kurz , Michael Rolnik , Eduardo Habkost , Markus Armbruster , Palmer Dabbelt Subject: [PATCH 11/22] target/nios2: Create IRQs *after* accelerator vCPU is realized Date: Mon, 18 Sep 2023 18:02:44 +0200 Message-ID: <20230918160257.30127-12-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230918160257.30127-1-philmd@linaro.org> References: <20230918160257.30127-1-philmd@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Architecture specific hardware doesn't have a particular dependency on the accelerator vCPU (created with cpu_exec_realizefn), and can be initialized *after* the vCPU is realized. Doing so allows further generic API simplification (in few commits). Signed-off-by: Philippe Mathieu-Daudé --- target/nios2/cpu.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/target/nios2/cpu.c b/target/nios2/cpu.c index 7a92fc5f2c..f500ca7ba2 100644 --- a/target/nios2/cpu.c +++ b/target/nios2/cpu.c @@ -201,14 +201,6 @@ static void nios2_cpu_realizefn(DeviceState *dev, Error **errp) Nios2CPUClass *ncc = NIOS2_CPU_GET_CLASS(dev); Error *local_err = NULL; -#ifndef CONFIG_USER_ONLY - if (cpu->eic_present) { - qdev_init_gpio_in_named(DEVICE(cpu), eic_set_irq, "EIC", 1); - } else { - qdev_init_gpio_in_named(DEVICE(cpu), iic_set_irq, "IRQ", 32); - } -#endif - cpu_exec_realizefn(cs, &local_err); if (local_err != NULL) { error_propagate(errp, local_err); @@ -220,6 +212,14 @@ static void nios2_cpu_realizefn(DeviceState *dev, Error **errp) /* We have reserved storage for cpuid; might as well use it. */ cpu->env.ctrl[CR_CPUID] = cs->cpu_index; +#ifndef CONFIG_USER_ONLY + if (cpu->eic_present) { + qdev_init_gpio_in_named(DEVICE(cpu), eic_set_irq, "EIC", 1); + } else { + qdev_init_gpio_in_named(DEVICE(cpu), iic_set_irq, "IRQ", 32); + } +#endif + ncc->parent_realize(dev, errp); cpu_reset(cs); } From patchwork Mon Sep 18 16:02:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13390051 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23009C46CA1 for ; Mon, 18 Sep 2023 16:33:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230272AbjIRQdv (ORCPT ); Mon, 18 Sep 2023 12:33:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229843AbjIRQd2 (ORCPT ); Mon, 18 Sep 2023 12:33:28 -0400 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76A9C7DAD for ; Mon, 18 Sep 2023 09:12:26 -0700 (PDT) Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-50307acd445so3036189e87.0 for ; Mon, 18 Sep 2023 09:12:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695053544; x=1695658344; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DBZjR8eqTRO2FcjHJbn6UW72+cRDsZ12eh5J24aMJRM=; b=haspA+XP0LsiyjV075ImbvGI2G6QezOcMkCNOOeBt3WgQGvpfzlghwViDOuEfD1g/L VypNe2MQ3ZOKuaZfW0d/SK88QT3ZezVn2bPUU/l1htDeV6nEOWnT6pQYouKit6ggZpyd 9MswgzN9xRk5cqHlHZ83tQbsCuFPmWf7ENOWNQCIMfB4NODYaIvDRbFBksLB1OxwJ37Y +gUC2xw/fDh92xE2H6eFhGL+t+4EXfJo3DOxr/xczW1rEe2tODkniwQPVOloHzhdmjhg AoWPZn+dCdMvp5BftXaXaizxRndr7aZOHqLtzRkJomxl0Jxuba07UK+ufWEbtXDLMmbL gPtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695053544; x=1695658344; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DBZjR8eqTRO2FcjHJbn6UW72+cRDsZ12eh5J24aMJRM=; b=HrsF1ZLIfP631hOTJZ1Z9isyl/bfCE8I2zLwHR7Nt7e3XB1aYXU8cpaTvKgY+vbJ2Z RNg3RnvVUngZhiBkwP8T1SOKfDI/wcWZZxMFBPDn9xnYl9fzvIcawjlXdD70EtNKWga7 qRqNQGWqvi62z28UVWudJM8sXS55YTdpe+nAiutzgsb9FePAAvC+gXVJQ/OqeKQTc5Qa jRJ1Gszcvsaly3Lp5W7IhfuV9OtcPDriXA9ryGpkKFh/nql0pxiC2EV4Fub/aWQVAL6d GhE9DF4Plezh9OjkOPRchsDg5FwacclXsCtbaUY3AqND2Iqy3x3w6mTllk+wdF9+Eois I/tQ== X-Gm-Message-State: AOJu0YwdjpJDv5B12UsqQii6ogHz5qnhxH5B7ENgK602bJR0+hhh1OfK UlaJyu4axvdMxygpvPCwQC4PRYtBEWTfWMRUFNEHZ6wr X-Google-Smtp-Source: AGHT+IFSQh3aSy8WNfVsJ8gBPwr/UHTrTRJ5GVnUXxcFo9z61kuLhRihhFERCd0BfPS6IwLRcpPE5w== X-Received: by 2002:a17:906:209b:b0:9a9:fa50:1fa8 with SMTP id 27-20020a170906209b00b009a9fa501fa8mr8796931ejq.40.1695053042868; Mon, 18 Sep 2023 09:04:02 -0700 (PDT) Received: from localhost.localdomain (static-212-193-78-212.thenetworkfactory.nl. [212.78.193.212]) by smtp.gmail.com with ESMTPSA id z15-20020a170906240f00b0099bd1ce18fesm6723198eja.10.2023.09.18.09.04.01 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 18 Sep 2023 09:04:02 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Laurent Vivier , Paolo Bonzini , Max Filippov , David Hildenbrand , Peter Xu , Anton Johansson , Peter Maydell , kvm@vger.kernel.org, Marek Vasut , David Gibson , Brian Cain , Yoshinori Sato , "Edgar E . Iglesias" , Claudio Fontana , Daniel Henrique Barboza , Artyom Tarasenko , Marcelo Tosatti , qemu-ppc@nongnu.org, Liu Zhiwei , Aurelien Jarno , Ilya Leoshkevich , Daniel Henrique Barboza , Bastian Koppelmann , =?utf-8?q?C=C3=A9dric_?= =?utf-8?q?Le_Goater?= , Alistair Francis , Alessandro Di Federico , Song Gao , Marcel Apfelbaum , Chris Wulff , "Michael S. Tsirkin" , Alistair Francis , Fabiano Rosas , qemu-s390x@nongnu.org, Yanan Wang , Luc Michel , Weiwei Li , Bin Meng , Stafford Horne , Xiaojuan Yang , "Daniel P . Berrange" , Thomas Huth , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-arm@nongnu.org, Jiaxun Yang , Richard Henderson , Aleksandar Rikalo , Bernhard Beschow , Mark Cave-Ayland , qemu-riscv@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Nicholas Piggin , Greg Kurz , Michael Rolnik , Eduardo Habkost , Markus Armbruster , Palmer Dabbelt Subject: [PATCH 12/22] target/mips: Create clock *after* accelerator vCPU is realized Date: Mon, 18 Sep 2023 18:02:45 +0200 Message-ID: <20230918160257.30127-13-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230918160257.30127-1-philmd@linaro.org> References: <20230918160257.30127-1-philmd@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Architecture specific hardware doesn't have a particular dependency on the accelerator vCPU (created with cpu_exec_realizefn), and can be initialized *after* the vCPU is realized. Doing so allows further generic API simplification (in few commits). Signed-off-by: Philippe Mathieu-Daudé --- target/mips/cpu.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/target/mips/cpu.c b/target/mips/cpu.c index 0aea69aaf9..7c81e6c356 100644 --- a/target/mips/cpu.c +++ b/target/mips/cpu.c @@ -464,20 +464,6 @@ static void mips_cpu_realizefn(DeviceState *dev, Error **errp) MIPSCPUClass *mcc = MIPS_CPU_GET_CLASS(dev); Error *local_err = NULL; - if (!clock_get(cpu->clock)) { -#ifndef CONFIG_USER_ONLY - if (!qtest_enabled()) { - g_autofree char *cpu_freq_str = freq_to_str(CPU_FREQ_HZ_DEFAULT); - - warn_report("CPU input clock is not connected to any output clock, " - "using default frequency of %s.", cpu_freq_str); - } -#endif - /* Initialize the frequency in case the clock remains unconnected. */ - clock_set_hz(cpu->clock, CPU_FREQ_HZ_DEFAULT); - } - mips_cp0_period_set(cpu); - cpu_exec_realizefn(cs, &local_err); if (local_err != NULL) { error_propagate(errp, local_err); @@ -492,6 +478,20 @@ static void mips_cpu_realizefn(DeviceState *dev, Error **errp) fpu_init(env, env->cpu_model); mvp_init(env); + if (!clock_get(cpu->clock)) { +#ifndef CONFIG_USER_ONLY + if (!qtest_enabled()) { + g_autofree char *cpu_freq_str = freq_to_str(CPU_FREQ_HZ_DEFAULT); + + warn_report("CPU input clock is not connected to any output clock, " + "using default frequency of %s.", cpu_freq_str); + } +#endif + /* Initialize the frequency in case the clock remains unconnected. */ + clock_set_hz(cpu->clock, CPU_FREQ_HZ_DEFAULT); + } + mips_cp0_period_set(cpu); + mcc->parent_realize(dev, errp); cpu_reset(cs); } From patchwork Mon Sep 18 16:02:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13390000 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 015D3CD13D2 for ; Mon, 18 Sep 2023 16:18:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230147AbjIRQSJ (ORCPT ); Mon, 18 Sep 2023 12:18:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229802AbjIRQR5 (ORCPT ); Mon, 18 Sep 2023 12:17:57 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 193DE2D75 for ; Mon, 18 Sep 2023 09:11:24 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id 4fb4d7f45d1cf-52a49a42353so5785268a12.2 for ; Mon, 18 Sep 2023 09:11:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695053483; x=1695658283; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YpBrxdgyPGajszRQj4tnQ2gfsy466T4SLwv71ztnz3k=; b=SszZNijQT/yp5ZpkflRip3fRzo82wxbzEfG6dRif3yB6LzHKUlQoqQDa977SuyoTtv X54RWNTtemaC0VGVOgjVv9IlQfqL7ovEw15y+NbUqI5W1ofrIl8io0hpNwYPPHN1sgmW Y8ntWs/UCeLIZN4X5sSDfBUxhMOOCxrElRUiB9fqkWCXTQcKnIVH3DZXTvr0lJmyBJck gbyNKXaDeMI27OA/PK7LEuPmzAdmMBKJ4veQFdLEpZW9b2XQxvHJk8NacQIqFQdQPsxl fCrcj2/6TrmhjUMbClUBvsUzkzY6o/vV1h+3s3OYuIOSejQKPM0x7dehBhpN4vumH3go IIjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695053483; x=1695658283; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YpBrxdgyPGajszRQj4tnQ2gfsy466T4SLwv71ztnz3k=; b=VmLERxGVqm/BlwKIjeOcuK9wwoN6Z5Qr9hxSt8AWWCC0Hsi28+Aft8h1cesEj2mOOq vVrJT5uAOQEV/ymReDlKpZLk7ft69/Z4dB3ildjNeJeHSehcWxQsz+r6Xjx9X3LBqVdT jPXtUzy4q5xr45FRGrKP3W4PzKtTRaNITswpsXc54Da8ghWrM/DibWevZ722m7Nxy+8X 3vdBpEftvCb7NGacI613EGMBKeDeJ7fsDWM4oeNg60sSXShF1FFcxQrSTWpa7gbjlIMB lmgNj65KSZjjopez9YbFgf9VkfC7U23fe69gzt6O3GO7wiafFb8BH7Su8s5Res++DTYJ Mejw== X-Gm-Message-State: AOJu0YwrKSzSYmZFZQAoh1EMbl4ROo4nlUDZzdkqaWtL5wh0lswJfAbB JSCiU9bkdup1UJGZoQhY9Be/xNAvcElB4/U1HHoYU8Xg X-Google-Smtp-Source: AGHT+IG6EnV1NPtLa02ojf1AOOFHw9u/ZZVKTH8rmKjYxc3URy3huazjFDCLq8lcPx0zxuOm3uW8nA== X-Received: by 2002:a17:907:2cd8:b0:9a5:c9a4:ba1a with SMTP id hg24-20020a1709072cd800b009a5c9a4ba1amr8408544ejc.59.1695053048266; Mon, 18 Sep 2023 09:04:08 -0700 (PDT) Received: from localhost.localdomain (static-212-193-78-212.thenetworkfactory.nl. [212.78.193.212]) by smtp.gmail.com with ESMTPSA id n4-20020a170906088400b009928b4e3b9fsm6613541eje.114.2023.09.18.09.04.06 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 18 Sep 2023 09:04:07 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Laurent Vivier , Paolo Bonzini , Max Filippov , David Hildenbrand , Peter Xu , Anton Johansson , Peter Maydell , kvm@vger.kernel.org, Marek Vasut , David Gibson , Brian Cain , Yoshinori Sato , "Edgar E . Iglesias" , Claudio Fontana , Daniel Henrique Barboza , Artyom Tarasenko , Marcelo Tosatti , qemu-ppc@nongnu.org, Liu Zhiwei , Aurelien Jarno , Ilya Leoshkevich , Daniel Henrique Barboza , Bastian Koppelmann , =?utf-8?q?C=C3=A9dric_?= =?utf-8?q?Le_Goater?= , Alistair Francis , Alessandro Di Federico , Song Gao , Marcel Apfelbaum , Chris Wulff , "Michael S. Tsirkin" , Alistair Francis , Fabiano Rosas , qemu-s390x@nongnu.org, Yanan Wang , Luc Michel , Weiwei Li , Bin Meng , Stafford Horne , Xiaojuan Yang , "Daniel P . Berrange" , Thomas Huth , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-arm@nongnu.org, Jiaxun Yang , Richard Henderson , Aleksandar Rikalo , Bernhard Beschow , Mark Cave-Ayland , qemu-riscv@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Nicholas Piggin , Greg Kurz , Michael Rolnik , Eduardo Habkost , Markus Armbruster , Palmer Dabbelt Subject: [PATCH 13/22] target/xtensa: Create IRQs *after* accelerator vCPU is realized Date: Mon, 18 Sep 2023 18:02:46 +0200 Message-ID: <20230918160257.30127-14-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230918160257.30127-1-philmd@linaro.org> References: <20230918160257.30127-1-philmd@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Architecture specific hardware doesn't have a particular dependency on the accelerator vCPU (created with cpu_exec_realizefn), and can be initialized *after* the vCPU is realized. Doing so allows further generic API simplification (in few commits). Signed-off-by: Philippe Mathieu-Daudé --- target/xtensa/cpu.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/target/xtensa/cpu.c b/target/xtensa/cpu.c index 300d19d45c..bbfd2d42a8 100644 --- a/target/xtensa/cpu.c +++ b/target/xtensa/cpu.c @@ -162,10 +162,6 @@ static void xtensa_cpu_realizefn(DeviceState *dev, Error **errp) XtensaCPUClass *xcc = XTENSA_CPU_GET_CLASS(dev); Error *local_err = NULL; -#ifndef CONFIG_USER_ONLY - xtensa_irq_init(&XTENSA_CPU(dev)->env); -#endif - cpu_exec_realizefn(cs, &local_err); if (local_err != NULL) { error_propagate(errp, local_err); @@ -174,6 +170,10 @@ static void xtensa_cpu_realizefn(DeviceState *dev, Error **errp) cs->gdb_num_regs = xcc->config->gdb_regmap.num_regs; +#ifndef CONFIG_USER_ONLY + xtensa_irq_init(&XTENSA_CPU(dev)->env); +#endif + xcc->parent_realize(dev, errp); } From patchwork Mon Sep 18 16:02:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13389999 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AA06EC46CA1 for ; Mon, 18 Sep 2023 16:18:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230038AbjIRQSH (ORCPT ); Mon, 18 Sep 2023 12:18:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230037AbjIRQR5 (ORCPT ); Mon, 18 Sep 2023 12:17:57 -0400 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10C32A2 for ; Mon, 18 Sep 2023 09:09:43 -0700 (PDT) Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-52f3ba561d9so10226824a12.1 for ; Mon, 18 Sep 2023 09:09:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695053381; x=1695658181; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wbLvVhCdjkLoKVSI3XlIe8h3b/C8JwK6Lt4fUZyBeQw=; b=MSEwH4vKfd0quO6q5e7dnGQrLGblqgd85rR3+R1OP9mzcGRwYJ77anICgeWWvtQvq3 tXOReoA3QkkryDhvazpG2E4LAr9c8saaqDUSuFS9PWunhZkPqwUFc3Rwt2OSku8zGDwP 37eEzBnbePhYGrhk63TkdlficlUJwX3UfadffN+0gwMbzTi9v08uR0dpIBKt67LnmfEk boHbFZfgqsuRac7qipNXCixXQnRcgTJS22mzBuAvDJJAEqConIZl4PJoPnlPn4B96xdc AWdzsXIMLq1CnbAKRIADJtUcFIhDxDWLkzANX544ObBYPM+VVBtI6T217ZNY8CGGdrQf cW6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695053381; x=1695658181; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wbLvVhCdjkLoKVSI3XlIe8h3b/C8JwK6Lt4fUZyBeQw=; b=xOrA0aGUm+58geGcdrWuHi1rFgJt5wHInPocM6+UE/zFsjGupA4hVSWEMKgCzTdfNW XglZ5UW2AGeG4hGbATvWK7IDMMTD6x3qrEdO9CVjyAr1TYlVbTUEbVQmeIpA49CaIXQn x/jIjEf/PCQ9jyMp7Lx6A0vO4+sk3cF1jgJ9yQQmCHHRiuil8bR6gFUFrWxnk0nLuiMy 5VFcHWNtVUSL1fwY2JpwcLuYXfFWhUwibF7hMvUiiuzyd4mSSTX+nwyGEV4ziZ4Wwmaj d7L/O/JTwU4KBugW8Qhu2m7uFtA57R1nQwHBlkkUenMz6tb2vZJdz++VJ7cWV9HRDgwk qMrw== X-Gm-Message-State: AOJu0YygsArK/Lem8MNGZo+CjAMWRkcGjywerAu/+qB4K7XuDc9mjeit slqyY7gjcmkd6nrasFoBN0XRogrgtb/9NfEjsDdC6pUP X-Google-Smtp-Source: AGHT+IGUIRL/Cj2QgpL/SWnZOOte/5aXBCe8PvtqKJ8rdHwjYW7XrtiQqR5SrkqTU7jQZeCu2Klurw== X-Received: by 2002:a17:906:311a:b0:9a9:f0e6:904e with SMTP id 26-20020a170906311a00b009a9f0e6904emr154241ejx.16.1695053053645; Mon, 18 Sep 2023 09:04:13 -0700 (PDT) Received: from localhost.localdomain (static-212-193-78-212.thenetworkfactory.nl. [212.78.193.212]) by smtp.gmail.com with ESMTPSA id n26-20020a170906119a00b00997cce73cc7sm6586020eja.29.2023.09.18.09.04.11 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 18 Sep 2023 09:04:13 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Laurent Vivier , Paolo Bonzini , Max Filippov , David Hildenbrand , Peter Xu , Anton Johansson , Peter Maydell , kvm@vger.kernel.org, Marek Vasut , David Gibson , Brian Cain , Yoshinori Sato , "Edgar E . Iglesias" , Claudio Fontana , Daniel Henrique Barboza , Artyom Tarasenko , Marcelo Tosatti , qemu-ppc@nongnu.org, Liu Zhiwei , Aurelien Jarno , Ilya Leoshkevich , Daniel Henrique Barboza , Bastian Koppelmann , =?utf-8?q?C=C3=A9dric_?= =?utf-8?q?Le_Goater?= , Alistair Francis , Alessandro Di Federico , Song Gao , Marcel Apfelbaum , Chris Wulff , "Michael S. Tsirkin" , Alistair Francis , Fabiano Rosas , qemu-s390x@nongnu.org, Yanan Wang , Luc Michel , Weiwei Li , Bin Meng , Stafford Horne , Xiaojuan Yang , "Daniel P . Berrange" , Thomas Huth , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-arm@nongnu.org, Jiaxun Yang , Richard Henderson , Aleksandar Rikalo , Bernhard Beschow , Mark Cave-Ayland , qemu-riscv@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Nicholas Piggin , Greg Kurz , Michael Rolnik , Eduardo Habkost , Markus Armbruster , Palmer Dabbelt Subject: [PATCH 14/22] target/sparc: Init CPU environment *after* accelerator vCPU is realized Date: Mon, 18 Sep 2023 18:02:47 +0200 Message-ID: <20230918160257.30127-15-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230918160257.30127-1-philmd@linaro.org> References: <20230918160257.30127-1-philmd@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org These fields from the environment don't affect how accelerators create their vCPU thread. We can safely reorder them *after* the cpu_exec_realizefn() call. Doing so allows further generic API simplification (in the next commit). Signed-off-by: Philippe Mathieu-Daudé --- target/sparc/cpu.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c index 2fdc95eda9..88157fcd33 100644 --- a/target/sparc/cpu.c +++ b/target/sparc/cpu.c @@ -756,6 +756,12 @@ static void sparc_cpu_realizefn(DeviceState *dev, Error **errp) SPARCCPU *cpu = SPARC_CPU(dev); CPUSPARCState *env = &cpu->env; + cpu_exec_realizefn(cs, &local_err); + if (local_err != NULL) { + error_propagate(errp, local_err); + return; + } + #if defined(CONFIG_USER_ONLY) if ((env->def.features & CPU_FEATURE_FLOAT)) { env->def.features |= CPU_FEATURE_FLOAT128; @@ -776,12 +782,6 @@ static void sparc_cpu_realizefn(DeviceState *dev, Error **errp) env->version |= env->def.nwindows - 1; #endif - cpu_exec_realizefn(cs, &local_err); - if (local_err != NULL) { - error_propagate(errp, local_err); - return; - } - scc->parent_realize(dev, errp); } From patchwork Mon Sep 18 16:02:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13390091 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B105C46CA1 for ; Mon, 18 Sep 2023 16:42:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230472AbjIRQmf (ORCPT ); Mon, 18 Sep 2023 12:42:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229864AbjIRQmS (ORCPT ); Mon, 18 Sep 2023 12:42:18 -0400 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93E9B1727 for ; Mon, 18 Sep 2023 09:05:02 -0700 (PDT) Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-986d8332f50so638393166b.0 for ; Mon, 18 Sep 2023 09:05:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695053058; x=1695657858; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=NjaIM1Qc6nHbnxZLIT5jjyB717NwyoCy1EteOD4KAlE=; b=qqBtnTQUBVmH8Adkd4X0AhyVbVdXNfDZG7t+B+TYQZRDL7XyxOYC7aVG7vGmpOcdvw /dpFyQz3B+Y0CwZB2i4kA83dDutQ/8Oto2DYd57Xgys76J5f+DzuLAS052XPDDz4VVV+ 8NSAKywqDq/eAHyTJdB/QkRIdm5eCJmhNjYk8qzyBRQCx1eI33wigqXiJ6UPbH2PCIDZ b5wudXt3L564M5SnITjPQ6ZR1xmLX3K6pPd16gIU1LswPcQx7fgU/S2Gy4n9XJgYy1Op lK1XXNIwQB1/wcS/+0k+40VEhvO5qZlVQdkGr4tyr5ZKU/gC4ys46tAaE8fsIU9BZ1Mt Sxwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695053058; x=1695657858; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NjaIM1Qc6nHbnxZLIT5jjyB717NwyoCy1EteOD4KAlE=; b=CMEB55ltQnTirQG8OtO98algtqMgip/ELBtllbLbtGAd3vwwD8qLvsZDCKub2Z0bRZ EjXZdZtCvT3nDfdvweZGL8nrU7SA4Fc3WQ8Jsdph/zas243bRQGgXz0VcAFbbmQwoOQe O+xq9ThWnSqBcJN1qg7kCQrMRuJVSThcuIXVTZ8wv92xv0eZxY2L1w82qM1jNpVGbOi6 zAJ2EHRe4EaRNwisX7KVGwbf4lZpzytt5D+RIyLLsGPeZlWTvAj2bdbGqaRwtaqEryKo ZnZTDQn97c0JbfD2VmSFhtkybxQfJrrM1HLIDasjbIhCKCrQSS3G/v1F8oitgliieP4y eW0A== X-Gm-Message-State: AOJu0Yz2SjeI7KBl/+hDCoM72LijdjD44Aq8pLydxgjxLs5SSWX8v4nA Z9/e0ygANcEPyA64+qBaaAXEJg== X-Google-Smtp-Source: AGHT+IH1BGqTiq3uZIcjIgDgFSn4hEE/bGsbSKhsdURXDBkyUNQTShuSyFgzOD2PM8QK12Z2NIlVUQ== X-Received: by 2002:a17:907:75f1:b0:9a1:da9a:f1c2 with SMTP id jz17-20020a17090775f100b009a1da9af1c2mr7861010ejc.11.1695053058645; Mon, 18 Sep 2023 09:04:18 -0700 (PDT) Received: from localhost.localdomain (static-212-193-78-212.thenetworkfactory.nl. [212.78.193.212]) by smtp.gmail.com with ESMTPSA id f13-20020a170906390d00b00982a92a849asm6628019eje.91.2023.09.18.09.04.17 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 18 Sep 2023 09:04:18 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Laurent Vivier , Paolo Bonzini , Max Filippov , David Hildenbrand , Peter Xu , Anton Johansson , Peter Maydell , kvm@vger.kernel.org, Marek Vasut , David Gibson , Brian Cain , Yoshinori Sato , "Edgar E . Iglesias" , Claudio Fontana , Daniel Henrique Barboza , Artyom Tarasenko , Marcelo Tosatti , qemu-ppc@nongnu.org, Liu Zhiwei , Aurelien Jarno , Ilya Leoshkevich , Daniel Henrique Barboza , Bastian Koppelmann , =?utf-8?q?C=C3=A9dric_?= =?utf-8?q?Le_Goater?= , Alistair Francis , Alessandro Di Federico , Song Gao , Marcel Apfelbaum , Chris Wulff , "Michael S. Tsirkin" , Alistair Francis , Fabiano Rosas , qemu-s390x@nongnu.org, Yanan Wang , Luc Michel , Weiwei Li , Bin Meng , Stafford Horne , Xiaojuan Yang , "Daniel P . Berrange" , Thomas Huth , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-arm@nongnu.org, Jiaxun Yang , Richard Henderson , Aleksandar Rikalo , Bernhard Beschow , Mark Cave-Ayland , qemu-riscv@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Nicholas Piggin , Greg Kurz , Michael Rolnik , Eduardo Habkost , Markus Armbruster , Palmer Dabbelt Subject: [PATCH 15/22] exec/cpu: Introduce CPUClass::verify_accel_features() Date: Mon, 18 Sep 2023 18:02:48 +0200 Message-ID: <20230918160257.30127-16-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230918160257.30127-1-philmd@linaro.org> References: <20230918160257.30127-1-philmd@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Some CPUs need to check the requested features are compatible with the requested accelerator. This has to be done *before* the accelerator realizes a vCPU. Introduce the verify_accel_features() handler and call it just before accel_cpu_realizefn(). Signed-off-by: Philippe Mathieu-Daudé --- include/hw/core/cpu.h | 4 ++++ cpu.c | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index c90cf3a162..1e940f6bb5 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -103,6 +103,9 @@ struct SysemuCPUOps; * @class_by_name: Callback to map -cpu command line model name to an * instantiatable CPU type. * @parse_features: Callback to parse command line arguments. + * @verify_accel_features: Callback to verify if all requested CPU are + * compatible with the requested accelerator. Called before the + * accelerator realize a vCPU. * @reset_dump_flags: #CPUDumpFlags to use for reset logging. * @has_work: Callback for checking if there is work to do. * @memory_rw_debug: Callback for GDB memory access. @@ -183,6 +186,7 @@ struct CPUClass { * class data that depends on the accelerator, see accel/accel-common.c. */ void (*init_accel_cpu)(struct AccelCPUClass *accel_cpu, CPUClass *cc); + bool (*verify_accel_features)(CPUState *cs, Error **errp); /* * Keep non-pointer data at the end to minimize holes. diff --git a/cpu.c b/cpu.c index 0769b0b153..84b03c09ac 100644 --- a/cpu.c +++ b/cpu.c @@ -136,6 +136,11 @@ void cpu_exec_realizefn(CPUState *cpu, Error **errp) /* cache the cpu class for the hotpath */ cpu->cc = CPU_GET_CLASS(cpu); + if (cpu->cc->verify_accel_features + && !cpu->cc->verify_accel_features(cpu, errp)) { + return false; + } + if (!accel_cpu_realizefn(cpu, errp)) { return; } From patchwork Mon Sep 18 16:02:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13390020 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA6F2C46CA1 for ; Mon, 18 Sep 2023 16:19:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229969AbjIRQTr (ORCPT ); Mon, 18 Sep 2023 12:19:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230026AbjIRQT2 (ORCPT ); Mon, 18 Sep 2023 12:19:28 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40355CEC for ; Mon, 18 Sep 2023 09:10:56 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-403012f276dso50790725e9.0 for ; Mon, 18 Sep 2023 09:10:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695053440; x=1695658240; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=s5SThQE8VrEigaiBVVD1aPn+S9Eqq7fLgyN+q+7eopw=; b=Gh03zHCe7gK1jzIbBWZcdDMy6iDkfsp1t5W7J6Gy7qNIt3qF3uUbF3lMBLlBpdKkGI BazjU4mVcdms/RlcNVNh9AH8cWn6XF1Xnb5u4hJwNqeOqlckPBgngmH5zPyiBfD7OPm7 KcWzyIyNTGtOXEK35xremOZUE0TwS3/ZAJBsITqpZixyAsdtjR7rVb8XzPbMXdk+1ej8 QHoZ5Zqzgnk5A+rt2p8HVx6I6vdWL+sW7mjysclW2M3jWqcfQZuN7U3kT9YgAzihwjaG 5E64Cs1lGb0G14XZNMdzYcG0dndM/L1eHjGXWABzwFADD+2aDjwG6kBjMc3+Dac6gQFK T4uA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695053440; x=1695658240; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=s5SThQE8VrEigaiBVVD1aPn+S9Eqq7fLgyN+q+7eopw=; b=ivdw3StIMHq3GrwIsjNExwoHcdPKtNOri/myhn0zyJROeUHiJlc6BeK4oukNSVFJnz OFU/fRvOO2dV32KiC7ihaNZxIUQb3snxFmDIrwNzUDuz5BvetYMoCs2h5+qvbo6S4y6K qkssxw3jA0/Em3bPwFG6Sy70uQ23PL1TTwU+aFd0AkgmuUsyV5KHgNvyZo0X/EjTCQtz rbrp+19VqFMVhpxHkgwM1DsnVi700YTEtBhDwFixDmjCQUhp5DJgrPCuqyWRI3bFSLzM Wh4vEZj4p3ohU9c6elZkdJzrNzdszlPjP81oHwq9ndoHOsslIoQPTInwSWvIt+S7moBz k2zw== X-Gm-Message-State: AOJu0YzsiZnNC1cg9v5NYn4DHen4CRdMfCw/JGdOuDAI45BVYWSkqflX 1WDq5tgsCjF5Wd3p7qD8HRou+MkNUCdmwytjhIjaDOWA X-Google-Smtp-Source: AGHT+IFdhAv8NMQe3eDFfz6fXbmFXmpOAUlZ51p/ozjG+nSdvaZT7LZnHlxk4GI+z0N+RInhKW7YXQ== X-Received: by 2002:a17:906:768f:b0:9ad:fb23:21cf with SMTP id o15-20020a170906768f00b009adfb2321cfmr4715553ejm.15.1695053064161; Mon, 18 Sep 2023 09:04:24 -0700 (PDT) Received: from localhost.localdomain (static-212-193-78-212.thenetworkfactory.nl. [212.78.193.212]) by smtp.gmail.com with ESMTPSA id c26-20020a170906341a00b00993470682e5sm6646928ejb.32.2023.09.18.09.04.22 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 18 Sep 2023 09:04:23 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Laurent Vivier , Paolo Bonzini , Max Filippov , David Hildenbrand , Peter Xu , Anton Johansson , Peter Maydell , kvm@vger.kernel.org, Marek Vasut , David Gibson , Brian Cain , Yoshinori Sato , "Edgar E . Iglesias" , Claudio Fontana , Daniel Henrique Barboza , Artyom Tarasenko , Marcelo Tosatti , qemu-ppc@nongnu.org, Liu Zhiwei , Aurelien Jarno , Ilya Leoshkevich , Daniel Henrique Barboza , Bastian Koppelmann , =?utf-8?q?C=C3=A9dric_?= =?utf-8?q?Le_Goater?= , Alistair Francis , Alessandro Di Federico , Song Gao , Marcel Apfelbaum , Chris Wulff , "Michael S. Tsirkin" , Alistair Francis , Fabiano Rosas , qemu-s390x@nongnu.org, Yanan Wang , Luc Michel , Weiwei Li , Bin Meng , Stafford Horne , Xiaojuan Yang , "Daniel P . Berrange" , Thomas Huth , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-arm@nongnu.org, Jiaxun Yang , Richard Henderson , Aleksandar Rikalo , Bernhard Beschow , Mark Cave-Ayland , qemu-riscv@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Nicholas Piggin , Greg Kurz , Michael Rolnik , Eduardo Habkost , Markus Armbruster , Palmer Dabbelt Subject: [PATCH 16/22] target/arm: Extract verify_accel_features() from cpu_realize() Date: Mon, 18 Sep 2023 18:02:49 +0200 Message-ID: <20230918160257.30127-17-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230918160257.30127-1-philmd@linaro.org> References: <20230918160257.30127-1-philmd@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org When looking at the arm_cpu_realizefn() method, most of the code run before the cpu_exec_realizefn() call checks whether the requested CPU features are compatible with the requested accelerator. Extract this code to a dedicated handler matching our recently added CPUClass::verify_accel_features() handler. Signed-off-by: Philippe Mathieu-Daudé --- target/arm/cpu.c | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 46d3f70d63..a551383fd3 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -1675,19 +1675,10 @@ void arm_cpu_finalize_features(ARMCPU *cpu, Error **errp) } } -static void arm_cpu_realizefn(DeviceState *dev, Error **errp) +static bool arm_cpu_verify_accel_features(CPUState *cs, Error **errp) { - CPUState *cs = CPU(dev); - ARMCPU *cpu = ARM_CPU(dev); - ARMCPUClass *acc = ARM_CPU_GET_CLASS(dev); + ARMCPU *cpu = ARM_CPU(cs); CPUARMState *env = &cpu->env; - int pagebits; - Error *local_err = NULL; - - /* Use pc-relative instructions in system-mode */ -#ifndef CONFIG_USER_ONLY - cs->tcg_cflags |= CF_PCREL; -#endif /* If we needed to query the host kernel for the CPU features * then it's possible that might have failed in the initfn, but @@ -1699,10 +1690,13 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) } else { error_setg(errp, "Failed to retrieve host CPU features"); } - return; + return false; } #ifndef CONFIG_USER_ONLY + /* Use pc-relative instructions in system-mode */ + cs->tcg_cflags |= CF_PCREL; + /* The NVIC and M-profile CPU are two halves of a single piece of * hardware; trying to use one without the other is a command line * error and will result in segfaults if not caught here. @@ -1710,12 +1704,12 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) if (arm_feature(env, ARM_FEATURE_M)) { if (!env->nvic) { error_setg(errp, "This board cannot be used with Cortex-M CPUs"); - return; + return false; } } else { if (env->nvic) { error_setg(errp, "This board can only be used with Cortex-M CPUs"); - return; + return false; } } @@ -1733,23 +1727,35 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) error_setg(errp, "Cannot enable %s when using an M-profile guest CPU", current_accel_name()); - return; + return false; } if (cpu->has_el3) { error_setg(errp, "Cannot enable %s when guest CPU has EL3 enabled", current_accel_name()); - return; + return false; } if (cpu->tag_memory) { error_setg(errp, "Cannot enable %s when guest CPUs has MTE enabled", current_accel_name()); - return; + return false; } } #endif + return true; +} + +static void arm_cpu_realizefn(DeviceState *dev, Error **errp) +{ + CPUState *cs = CPU(dev); + ARMCPU *cpu = ARM_CPU(dev); + ARMCPUClass *acc = ARM_CPU_GET_CLASS(dev); + CPUARMState *env = &cpu->env; + int pagebits; + Error *local_err = NULL; + cpu_exec_realizefn(cs, &local_err); if (local_err != NULL) { error_propagate(errp, local_err); @@ -2383,6 +2389,7 @@ static void arm_cpu_class_init(ObjectClass *oc, void *data) &acc->parent_phases); cc->class_by_name = arm_cpu_class_by_name; + cc->verify_accel_features = arm_cpu_verify_accel_features; cc->has_work = arm_cpu_has_work; cc->dump_state = arm_cpu_dump_state; cc->set_pc = arm_cpu_set_pc; From patchwork Mon Sep 18 16:02:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13390100 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9AD2CD37B0 for ; Mon, 18 Sep 2023 16:45:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229986AbjIRQpj (ORCPT ); Mon, 18 Sep 2023 12:45:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229665AbjIRQpT (ORCPT ); Mon, 18 Sep 2023 12:45:19 -0400 Received: from mail-lj1-x22f.google.com (mail-lj1-x22f.google.com [IPv6:2a00:1450:4864:20::22f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A89861A5 for ; Mon, 18 Sep 2023 09:10:28 -0700 (PDT) Received: by mail-lj1-x22f.google.com with SMTP id 38308e7fff4ca-2bffdf50212so24780581fa.1 for ; Mon, 18 Sep 2023 09:10:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695053426; x=1695658226; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZP1Jq5UriapAIWJmFwmSYSQUUVqpdEGdHuUn9UNvH2c=; b=Sa7jQTAmeO+PCW88D6d6oLjctD7vUw7AriFjDWuIQLw2tL8klrZMWxtovvNkVG5KSV 8URESMwCvnjb0r/13BUyWd86GNmYdYWxDvEPtx9V8QavBXUiVIEp2QvFwyTehw2GJGkh v/MFdm1XFoqlvacjQP/WphM8BARvQ8Hgxka00Q9K4RgzrrfARLqv63m3wkqnW9dydWuQ N3DRUfY2SttjzDGxZtlQvOkY3/tuHHTgd2tSOgtLzi469lggws4pj6Aabz9eX6xaqei0 r3BImaVFwafAerHc/N3QQ6JgnKJwrX4aedNSbs+YVwqKKaayRnyXFT+quAuO3zpsksOl 62Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695053426; x=1695658226; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZP1Jq5UriapAIWJmFwmSYSQUUVqpdEGdHuUn9UNvH2c=; b=NLnq4bk1cdopce/5zCrmA8Dykd3+brV5964efdEw9N9KKbKxTjmwU3lQ3eMlzXKxGs TUDZePYCLaA6Aqe9iMhReBcN8YrapfepObEcqgnYhmJB0lhpbIlolYIgZJUTq8PJutYy c/lpCb2xS0ZOb8VHZzTEcriT6fMsnpFfGYZYnmWFA7rNEq3qSS76I3R9cbCwoDgDoxFs 1l4lpdSsWUaLBTn1931qsQSA17MzmPS2kbr6hsNrNi98R4FuoTOCRYMbz9EENu8SMm0E /VPpPkp48Tt4ybx2SLKipTWPEAuQn7S1ZkV9uc7u+PLcbpyfMEMNGMhOJNlh/e+TBF8u L2Cw== X-Gm-Message-State: AOJu0YxvIsoOnWX3lw66dOBjn8JYoKqNZrqew5IcGCqKc5aHpfGiju84 oEii+Gjv7kUajg3Y4X76W5939FgsDW6Sv9jOKVDNJyrC X-Google-Smtp-Source: AGHT+IHqyjalPcNFI3j/eC2mJhJCqyXLJDQU80ViEPpsSEn13nBGjwNzQvCpQXl9ahmUuhJ660k6zA== X-Received: by 2002:a05:6512:31cd:b0:503:1722:bf3a with SMTP id j13-20020a05651231cd00b005031722bf3amr3370635lfe.1.1695053069418; Mon, 18 Sep 2023 09:04:29 -0700 (PDT) Received: from localhost.localdomain (static-212-193-78-212.thenetworkfactory.nl. [212.78.193.212]) by smtp.gmail.com with ESMTPSA id ec31-20020a0564020d5f00b00530a9488623sm4149603edb.46.2023.09.18.09.04.27 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 18 Sep 2023 09:04:28 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Laurent Vivier , Paolo Bonzini , Max Filippov , David Hildenbrand , Peter Xu , Anton Johansson , Peter Maydell , kvm@vger.kernel.org, Marek Vasut , David Gibson , Brian Cain , Yoshinori Sato , "Edgar E . Iglesias" , Claudio Fontana , Daniel Henrique Barboza , Artyom Tarasenko , Marcelo Tosatti , qemu-ppc@nongnu.org, Liu Zhiwei , Aurelien Jarno , Ilya Leoshkevich , Daniel Henrique Barboza , Bastian Koppelmann , =?utf-8?q?C=C3=A9dric_?= =?utf-8?q?Le_Goater?= , Alistair Francis , Alessandro Di Federico , Song Gao , Marcel Apfelbaum , Chris Wulff , "Michael S. Tsirkin" , Alistair Francis , Fabiano Rosas , qemu-s390x@nongnu.org, Yanan Wang , Luc Michel , Weiwei Li , Bin Meng , Stafford Horne , Xiaojuan Yang , "Daniel P . Berrange" , Thomas Huth , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-arm@nongnu.org, Jiaxun Yang , Richard Henderson , Aleksandar Rikalo , Bernhard Beschow , Mark Cave-Ayland , qemu-riscv@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Nicholas Piggin , Greg Kurz , Michael Rolnik , Eduardo Habkost , Markus Armbruster , Palmer Dabbelt Subject: [PATCH 17/22] target/i386: Extract verify_accel_features() from cpu_realize() Date: Mon, 18 Sep 2023 18:02:50 +0200 Message-ID: <20230918160257.30127-18-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230918160257.30127-1-philmd@linaro.org> References: <20230918160257.30127-1-philmd@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org When looking at the x86_cpu_realizefn() method, most of the code run before the cpu_exec_realizefn() call checks whether the requested CPU features are compatible with the requested accelerator. Extract this code to a dedicated handler matching our recently added CPUClass::verify_accel_features() handler. Signed-off-by: Philippe Mathieu-Daudé --- target/i386/cpu.c | 62 +++++++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index d79797d963..2884733397 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -7208,26 +7208,19 @@ static void x86_cpu_hyperv_realize(X86CPU *cpu) cpu->hyperv_limits[2] = 0; } -static void x86_cpu_realizefn(DeviceState *dev, Error **errp) +/* + * note: the call to the framework needs to happen after feature expansion, + * but before the checks/modifications to ucode_rev, mwait, phys_bits. + * These may be set by the accel-specific code, + * and the results are subsequently checked / assumed in x86_cpu_realizefn(). + */ +static bool x86_cpu_verify_accel_features(CPUState *cs, Error **errp) { - CPUState *cs = CPU(dev); - X86CPU *cpu = X86_CPU(dev); - X86CPUClass *xcc = X86_CPU_GET_CLASS(dev); + X86CPU *cpu = X86_CPU(cs); CPUX86State *env = &cpu->env; Error *local_err = NULL; - static bool ht_warned; unsigned requested_lbr_fmt; - /* Use pc-relative instructions in system-mode */ -#ifndef CONFIG_USER_ONLY - cs->tcg_cflags |= CF_PCREL; -#endif - - if (cpu->apic_id == UNASSIGNED_APIC_ID) { - error_setg(errp, "apic-id property was not initialized properly"); - return; - } - /* * Process Hyper-V enlightenments. * Note: this currently has to happen before the expansion of CPU features. @@ -7236,7 +7229,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) x86_cpu_expand_features(cpu, &local_err); if (local_err) { - goto out; + return false; } /* @@ -7246,7 +7239,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) if (cpu->lbr_fmt != ~PERF_CAP_LBR_FMT) { if ((cpu->lbr_fmt & PERF_CAP_LBR_FMT) != cpu->lbr_fmt) { error_setg(errp, "invalid lbr-fmt"); - return; + return false; } env->features[FEAT_PERF_CAPABILITIES] &= ~PERF_CAP_LBR_FMT; env->features[FEAT_PERF_CAPABILITIES] |= cpu->lbr_fmt; @@ -7265,13 +7258,13 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) if (!cpu->enable_pmu) { error_setg(errp, "vPMU: LBR is unsupported without pmu=on"); - return; + return false; } if (requested_lbr_fmt != host_lbr_fmt) { error_setg(errp, "vPMU: the lbr-fmt value (0x%x) does not match " "the host value (0x%x).", requested_lbr_fmt, host_lbr_fmt); - return; + return false; } } @@ -7282,7 +7275,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) accel_uses_host_cpuid() ? "Host doesn't support requested features" : "TCG doesn't support requested features"); - goto out; + return false; } /* On AMD CPUs, some CPUID[8000_0001].EDX bits must match the bits on @@ -7296,12 +7289,28 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) x86_cpu_set_sgxlepubkeyhash(env); - /* - * note: the call to the framework needs to happen after feature expansion, - * but before the checks/modifications to ucode_rev, mwait, phys_bits. - * These may be set by the accel-specific code, - * and the results are subsequently checked / assumed in this function. - */ + return true; +} + +static void x86_cpu_realizefn(DeviceState *dev, Error **errp) +{ + CPUState *cs = CPU(dev); + X86CPU *cpu = X86_CPU(dev); + X86CPUClass *xcc = X86_CPU_GET_CLASS(dev); + CPUX86State *env = &cpu->env; + Error *local_err = NULL; + static bool ht_warned; + + /* Use pc-relative instructions in system-mode */ +#ifndef CONFIG_USER_ONLY + cs->tcg_cflags |= CF_PCREL; +#endif + + if (cpu->apic_id == UNASSIGNED_APIC_ID) { + error_setg(errp, "apic-id property was not initialized properly"); + return; + } + cpu_exec_realizefn(cs, &local_err); if (local_err != NULL) { error_propagate(errp, local_err); @@ -7950,6 +7959,7 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data) cc->class_by_name = x86_cpu_class_by_name; cc->parse_features = x86_cpu_parse_featurestr; + cc->verify_accel_features = x86_cpu_verify_accel_features; cc->has_work = x86_cpu_has_work; cc->dump_state = x86_cpu_dump_state; cc->set_pc = x86_cpu_set_pc; From patchwork Mon Sep 18 16:02:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13390090 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5AB44CD37B0 for ; Mon, 18 Sep 2023 16:42:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230394AbjIRQme (ORCPT ); Mon, 18 Sep 2023 12:42:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230365AbjIRQmS (ORCPT ); Mon, 18 Sep 2023 12:42:18 -0400 Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [IPv6:2a00:1450:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94BFB1731 for ; Mon, 18 Sep 2023 09:05:02 -0700 (PDT) Received: by mail-lj1-x22b.google.com with SMTP id 38308e7fff4ca-2bcb50e194dso74354761fa.3 for ; Mon, 18 Sep 2023 09:05:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695053075; x=1695657875; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CLYCBr4NSqb4Srk/T+P7jn9AmbCAT10Txre246ezJ94=; b=HSf8yjt+bOEHTC6NTjwv+GgSjKmm2P2WIHZxcE+NB6tWgKVoLUa7xZoHQAkFGoOGF5 Q/9L20OSiVwS52pn8lA3XnA2L76kXOtnSP3+dWErpWjOofbboanjUsElPOEOdzWehtUw SaOlYj3kTOSdgTxj3KfxbhMYUQmmSNVNwzsa9HtoQmhhinVq5ptynNYrmK2OCOx9Ilrh +ADqGU7FM+UEfbKoIxullyZX43SruP38qLJoHJIGISuJhcUJfdBvLfh6yf8z/zuFW5SY 7Csu/fiqqwEaVMPfxNVnPc7FxHGyeJbBTvPoZ+/Z7s6yHUXaNvUJTjAgXDNatqkU3o1F D/TQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695053075; x=1695657875; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CLYCBr4NSqb4Srk/T+P7jn9AmbCAT10Txre246ezJ94=; b=wdsgV5qoI0DdUImXTPnLnYXCZja/YUoUV7BIJpGNhYWhjnAyyLjpY0LKGqy/lGiYn7 QvWjjxbNw3t65RXyTVErNMKInTXdwK/wr0ZRxgK4BS9Fb0EjWvXpr1ITBC0x2orm9g2e C86JPASzFPAdV+8A1vmgSgSdNTjka5pNoFTf1SPRhs7MvB1WMDzFr/7qPhfdE/8x70+f UmwQYDDgBQdlJ0xwXxxQ9n4RT0ppeJIsd+XOR1kitnifsa3UQ7dzfOqmjc6Q/8Q8T1m/ XYBkxodXNn22pNqeJQlrscRA6wIMPN0npCMPS1lHqf1hiVOAHYt799coYRxKwBHWMql5 lB9Q== X-Gm-Message-State: AOJu0YwspqAzyh0WDc+9p8RnnlS7tr0WWvoI5k8P+DndsP+0KkL/HIjn J/gPYWvPoiSdproF5lEGLJLang== X-Google-Smtp-Source: AGHT+IEszpq6z0T8KHVLe1aYl3TXIxtDx0wMS/QiHJe0YDjbBZ7toGFiwcuS0GxUEQgehFRPXlIxjg== X-Received: by 2002:a2e:8046:0:b0:2bc:b821:84ad with SMTP id p6-20020a2e8046000000b002bcb82184admr8047755ljg.16.1695053075234; Mon, 18 Sep 2023 09:04:35 -0700 (PDT) Received: from localhost.localdomain (static-212-193-78-212.thenetworkfactory.nl. [212.78.193.212]) by smtp.gmail.com with ESMTPSA id f10-20020a170906560a00b0099d0c0bb92bsm6569110ejq.80.2023.09.18.09.04.33 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 18 Sep 2023 09:04:34 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Laurent Vivier , Paolo Bonzini , Max Filippov , David Hildenbrand , Peter Xu , Anton Johansson , Peter Maydell , kvm@vger.kernel.org, Marek Vasut , David Gibson , Brian Cain , Yoshinori Sato , "Edgar E . Iglesias" , Claudio Fontana , Daniel Henrique Barboza , Artyom Tarasenko , Marcelo Tosatti , qemu-ppc@nongnu.org, Liu Zhiwei , Aurelien Jarno , Ilya Leoshkevich , Daniel Henrique Barboza , Bastian Koppelmann , =?utf-8?q?C=C3=A9dric_?= =?utf-8?q?Le_Goater?= , Alistair Francis , Alessandro Di Federico , Song Gao , Marcel Apfelbaum , Chris Wulff , "Michael S. Tsirkin" , Alistair Francis , Fabiano Rosas , qemu-s390x@nongnu.org, Yanan Wang , Luc Michel , Weiwei Li , Bin Meng , Stafford Horne , Xiaojuan Yang , "Daniel P . Berrange" , Thomas Huth , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-arm@nongnu.org, Jiaxun Yang , Richard Henderson , Aleksandar Rikalo , Bernhard Beschow , Mark Cave-Ayland , qemu-riscv@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Nicholas Piggin , Greg Kurz , Michael Rolnik , Eduardo Habkost , Markus Armbruster , Palmer Dabbelt Subject: [PATCH 18/22] target/s390x: Call s390_cpu_realize_sysemu from s390_realize_cpu_model Date: Mon, 18 Sep 2023 18:02:51 +0200 Message-ID: <20230918160257.30127-19-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230918160257.30127-1-philmd@linaro.org> References: <20230918160257.30127-1-philmd@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org s390_cpu_realize_sysemu() runs some checks for the TCG accelerator, previous to creating the vCPU. s390_realize_cpu_model() also does run some checks for KVM. Move the sysemu call to s390_realize_cpu_model(). Having a single call before cpu_exec_realizefn() will allow us to factor a verify_accel_features() handler out in a pair of commits. Directly pass a S390CPU* to s390_cpu_realize_sysemu() to simplify. Signed-off-by: Philippe Mathieu-Daudé --- target/s390x/s390x-internal.h | 2 +- target/s390x/cpu-sysemu.c | 3 +-- target/s390x/cpu.c | 6 ------ target/s390x/cpu_models.c | 4 ++++ 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/target/s390x/s390x-internal.h b/target/s390x/s390x-internal.h index 825252d728..781ac08458 100644 --- a/target/s390x/s390x-internal.h +++ b/target/s390x/s390x-internal.h @@ -241,7 +241,7 @@ uint32_t calc_cc(CPUS390XState *env, uint32_t cc_op, uint64_t src, uint64_t dst, unsigned int s390_cpu_halt(S390CPU *cpu); void s390_cpu_unhalt(S390CPU *cpu); void s390_cpu_init_sysemu(Object *obj); -bool s390_cpu_realize_sysemu(DeviceState *dev, Error **errp); +bool s390_cpu_realize_sysemu(S390CPU *cpu, Error **errp); void s390_cpu_finalize(Object *obj); void s390_cpu_class_init_sysemu(CPUClass *cc); void s390_cpu_machine_reset_cb(void *opaque); diff --git a/target/s390x/cpu-sysemu.c b/target/s390x/cpu-sysemu.c index 8112561e5e..5178736c46 100644 --- a/target/s390x/cpu-sysemu.c +++ b/target/s390x/cpu-sysemu.c @@ -122,9 +122,8 @@ void s390_cpu_init_sysemu(Object *obj) s390_cpu_set_state(S390_CPU_STATE_STOPPED, cpu); } -bool s390_cpu_realize_sysemu(DeviceState *dev, Error **errp) +bool s390_cpu_realize_sysemu(S390CPU *cpu, Error **errp) { - S390CPU *cpu = S390_CPU(dev); MachineState *ms = MACHINE(qdev_get_machine()); unsigned int max_cpus = ms->smp.max_cpus; diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c index 416ac6c4e0..7257d4bc19 100644 --- a/target/s390x/cpu.c +++ b/target/s390x/cpu.c @@ -237,12 +237,6 @@ static void s390_cpu_realizefn(DeviceState *dev, Error **errp) goto out; } -#if !defined(CONFIG_USER_ONLY) - if (!s390_cpu_realize_sysemu(dev, &err)) { - goto out; - } -#endif - cpu_exec_realizefn(cs, &err); if (err != NULL) { goto out; diff --git a/target/s390x/cpu_models.c b/target/s390x/cpu_models.c index 98f14c09c2..f030be0d55 100644 --- a/target/s390x/cpu_models.c +++ b/target/s390x/cpu_models.c @@ -612,6 +612,10 @@ void s390_realize_cpu_model(CPUState *cs, Error **errp) cpu->env.cpuid = deposit64(cpu->env.cpuid, CPU_PHYS_ADDR_SHIFT, CPU_PHYS_ADDR_BITS, cpu->env.core_id); } + + if (!s390_cpu_realize_sysemu(cpu, &err)) { + return; + } #endif } From patchwork Mon Sep 18 16:02:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13389981 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97C4FCD13D2 for ; Mon, 18 Sep 2023 16:05:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230033AbjIRQFU (ORCPT ); Mon, 18 Sep 2023 12:05:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229928AbjIRQFN (ORCPT ); Mon, 18 Sep 2023 12:05:13 -0400 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D71E5170E for ; Mon, 18 Sep 2023 09:05:03 -0700 (PDT) Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-2c012232792so14663941fa.0 for ; Mon, 18 Sep 2023 09:05:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695053080; x=1695657880; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ikcGGGCIJyFk0iGLkDvtO0LMxTWmhw6kUdLFh+619DA=; b=E+x5SBB0lz8rH3HI5p89VaIovH2KYbmYY/mn6sDrUSaJz5JGOcESbPt5FCmgS1ho++ hVFXegbA1enPJS7e10JRsHQWsVgQQcSNR9XfJkMmjM26UzCDMgD1Y5nhTjaRZhVC1o/c 3Q57+ner0vetyE+HW1Lh4zE7SG/mGeYvptbxqxog60SkjRIpBXJbn47Wi+19+yBynmTi hzTKQq252o1hnX+RLBa8d2T3EdkTIXEUkN357NvJNGylnw0NuEdV3DCFy4GhGZIX1tyj iOR0cG0l7HxMhL4vJr+wvUkq3GYDhkLtRnkjsaBIcSisynhDHwReVRhjpH7uxoHYwI3o jaXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695053080; x=1695657880; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ikcGGGCIJyFk0iGLkDvtO0LMxTWmhw6kUdLFh+619DA=; b=jX/9U05DhpuGfrGwVU5cr7/geF3U3GlT+GXqFCRmhNXw4cc0gcwSqYKhSdTusrnh6x FsjOb0H5DldrP5UfBqIhW0G3XdlxqDQoTs771x26F5/NmRE2t4p4WgIYkhTrqozoiZOf HdGn9+qp6sSPH+iALlmS3YA01iNZ9kF36peNu++P3dNqyFT8XhFBfOD+JzdTkvSGVN2k DkIaK53lHsS8IAl1c4zTGCFxq4z7QSsZy5FinazkrgC9Vd+kB0eQkuQaWzmooRBmr+W+ g9B0LbLYyaBQTcMyW+MS5dQNLJmp23RGel9AEvgYv3tZPBSV615ApGeT8uXN1W9s3LJ1 WMTw== X-Gm-Message-State: AOJu0YyfGe7nfFvO3U/PCDSTXcnsFv9NjeQgWL77k7Z1A9sLVsljkOC2 5ObeRn1Thvj2i73JfnINjBULcg== X-Google-Smtp-Source: AGHT+IHPFOPTiS8G0DN7xrPnBYP1slspvTMlXj8JaMLUiuGi38+IN9Um/ZAXVcnl3VSwqkREENA1iw== X-Received: by 2002:a2e:9d42:0:b0:2b9:e53f:e1fd with SMTP id y2-20020a2e9d42000000b002b9e53fe1fdmr7980710ljj.34.1695053080249; Mon, 18 Sep 2023 09:04:40 -0700 (PDT) Received: from localhost.localdomain (static-212-193-78-212.thenetworkfactory.nl. [212.78.193.212]) by smtp.gmail.com with ESMTPSA id v24-20020a1709060b5800b0098951bb4dc3sm6599465ejg.184.2023.09.18.09.04.38 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 18 Sep 2023 09:04:39 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Laurent Vivier , Paolo Bonzini , Max Filippov , David Hildenbrand , Peter Xu , Anton Johansson , Peter Maydell , kvm@vger.kernel.org, Marek Vasut , David Gibson , Brian Cain , Yoshinori Sato , "Edgar E . Iglesias" , Claudio Fontana , Daniel Henrique Barboza , Artyom Tarasenko , Marcelo Tosatti , qemu-ppc@nongnu.org, Liu Zhiwei , Aurelien Jarno , Ilya Leoshkevich , Daniel Henrique Barboza , Bastian Koppelmann , =?utf-8?q?C=C3=A9dric_?= =?utf-8?q?Le_Goater?= , Alistair Francis , Alessandro Di Federico , Song Gao , Marcel Apfelbaum , Chris Wulff , "Michael S. Tsirkin" , Alistair Francis , Fabiano Rosas , qemu-s390x@nongnu.org, Yanan Wang , Luc Michel , Weiwei Li , Bin Meng , Stafford Horne , Xiaojuan Yang , "Daniel P . Berrange" , Thomas Huth , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-arm@nongnu.org, Jiaxun Yang , Richard Henderson , Aleksandar Rikalo , Bernhard Beschow , Mark Cave-Ayland , qemu-riscv@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Nicholas Piggin , Greg Kurz , Michael Rolnik , Eduardo Habkost , Markus Armbruster , Palmer Dabbelt Subject: [PATCH 19/22] target/s390x: Have s390_realize_cpu_model() return a boolean Date: Mon, 18 Sep 2023 18:02:52 +0200 Message-ID: <20230918160257.30127-20-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230918160257.30127-1-philmd@linaro.org> References: <20230918160257.30127-1-philmd@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Following the example documented since commit e3fe3988d7 ("error: Document Error API usage rules"), have s390_realize_cpu_model() return a boolean indicating whether an error is set or not. Signed-off-by: Philippe Mathieu-Daudé --- target/s390x/s390x-internal.h | 2 +- target/s390x/cpu.c | 3 +-- target/s390x/cpu_models.c | 12 +++++++----- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/target/s390x/s390x-internal.h b/target/s390x/s390x-internal.h index 781ac08458..67f21f53a9 100644 --- a/target/s390x/s390x-internal.h +++ b/target/s390x/s390x-internal.h @@ -260,7 +260,7 @@ static inline void s390_cpu_unhalt(S390CPU *cpu) /* cpu_models.c */ void s390_cpu_model_class_register_props(ObjectClass *oc); -void s390_realize_cpu_model(CPUState *cs, Error **errp); +bool s390_realize_cpu_model(CPUState *cs, Error **errp); S390CPUModel *get_max_cpu_model(Error **errp); void apply_cpu_model(const S390CPUModel *model, Error **errp); ObjectClass *s390_cpu_class_by_name(const char *name); diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c index 7257d4bc19..1a44a6d2b2 100644 --- a/target/s390x/cpu.c +++ b/target/s390x/cpu.c @@ -232,8 +232,7 @@ static void s390_cpu_realizefn(DeviceState *dev, Error **errp) Error *err = NULL; /* the model has to be realized before qemu_init_vcpu() due to kvm */ - s390_realize_cpu_model(cs, &err); - if (err) { + if (!s390_realize_cpu_model(cs, &err)) { goto out; } diff --git a/target/s390x/cpu_models.c b/target/s390x/cpu_models.c index f030be0d55..0605073dc3 100644 --- a/target/s390x/cpu_models.c +++ b/target/s390x/cpu_models.c @@ -567,7 +567,7 @@ S390CPUModel *get_max_cpu_model(Error **errp) return &max_model; } -void s390_realize_cpu_model(CPUState *cs, Error **errp) +bool s390_realize_cpu_model(CPUState *cs, Error **errp) { Error *err = NULL; S390CPUClass *xcc = S390_CPU_GET_CLASS(cs); @@ -576,19 +576,19 @@ void s390_realize_cpu_model(CPUState *cs, Error **errp) if (xcc->kvm_required && !kvm_enabled()) { error_setg(errp, "CPU definition requires KVM"); - return; + return false; } if (!cpu->model) { /* no host model support -> perform compatibility stuff */ apply_cpu_model(NULL, errp); - return; + return false; } max_model = get_max_cpu_model(errp); if (!max_model) { error_prepend(errp, "CPU models are not available: "); - return; + return false; } /* copy over properties that can vary */ @@ -601,7 +601,7 @@ void s390_realize_cpu_model(CPUState *cs, Error **errp) check_compatibility(max_model, cpu->model, &err); if (err) { error_propagate(errp, err); - return; + return false; } apply_cpu_model(cpu->model, errp); @@ -617,6 +617,8 @@ void s390_realize_cpu_model(CPUState *cs, Error **errp) return; } #endif + + return true; } static void get_feature(Object *obj, Visitor *v, const char *name, From patchwork Mon Sep 18 16:02:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13390066 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76DACCD37B0 for ; Mon, 18 Sep 2023 16:35:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229865AbjIRQfr (ORCPT ); Mon, 18 Sep 2023 12:35:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229901AbjIRQfT (ORCPT ); Mon, 18 Sep 2023 12:35:19 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD3357DBB for ; Mon, 18 Sep 2023 09:12:29 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-40476ce8b2fso40864245e9.3 for ; Mon, 18 Sep 2023 09:12:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695053548; x=1695658348; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=y7slh/pNTWelLfh1FzXsOutH1+zxCT/FLHdOf8nTB6I=; b=q0KcQo2KVWnKZDombc6Jx6vXOjJ0S4RVxmLvSf7KN8Ej5/rjHLk1JjIegT6TQ67xPr +YBD9iADYzlVmF9tDkYp6hqlkKPmtmKS/d4Rpx68Z5Nx6n0hvPS1s47L6GsileLFvXHj rbaHG3HBTbeCTbPQXKFF/ebujU1ywy1UpLF8ScvX70f0Pd++AZt+bO9AawAb/hdUsA2C lK09ewdbTwHS9t8aImPtH9+E4ieyxOJ1A0yPP17b+3DKnIjC4uSe7R7cbpcXg3jHR6ZX tiJu9DobWPaCKOmVP375GLnJImOdIogdqZ61t1od1P+X1PK6x5Fl7xG4xRU7/pUlO5uk NL4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695053548; x=1695658348; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=y7slh/pNTWelLfh1FzXsOutH1+zxCT/FLHdOf8nTB6I=; b=OnXdnRllB8r69DVEdEsPKbdtcpjp531CE9CDg6rrhVPXk3hP5OI2++ER8cBMhKBSdG IVIBuJ2xI84/VdMOmoaP0jAHyu8rU6jEDIQg8HXONSh/kiLngERbA16Pjm3Smj24wwrx E1mNAjKxZfv2IaPJhQQtAHwMhpVna+vX0zU8/0w0CjHaDbFGpje+k7kx9hZgjtwQh15J tWmW/ipzvguvWjZhZiT1KKX3v5dvLkBkzqguuthBxDtAjMGKA1XiqGwrona0pDR/w9CM eTNQjzDXg+gYKg2Qe3G5pq1ttVKFblw2QQpNmmBX18X5N7EVCq06OULD1m5DjOxTnFe0 srmw== X-Gm-Message-State: AOJu0YxSqFT9R/2v9kL9YhUqxOxPguwlVIU7y1ZFdXlc0QKUBw2EnksE /D6t7+Rn5SkB335AuR5fmSoN+zDEww3NSBgtrRS8kZ5I X-Google-Smtp-Source: AGHT+IF1uzqoMGcGEAlyaETsh01GEqG5TP+8vhZBqOT31xYKgtT4aKTdO73/67eFYWfUVkYSZ8Rjqw== X-Received: by 2002:a17:907:75f1:b0:9a5:cc73:a2a5 with SMTP id jz17-20020a17090775f100b009a5cc73a2a5mr6784701ejc.1.1695053085243; Mon, 18 Sep 2023 09:04:45 -0700 (PDT) Received: from localhost.localdomain (static-212-193-78-212.thenetworkfactory.nl. [212.78.193.212]) by smtp.gmail.com with ESMTPSA id lt10-20020a170906fa8a00b009737b8d47b6sm6568567ejb.203.2023.09.18.09.04.43 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 18 Sep 2023 09:04:44 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Laurent Vivier , Paolo Bonzini , Max Filippov , David Hildenbrand , Peter Xu , Anton Johansson , Peter Maydell , kvm@vger.kernel.org, Marek Vasut , David Gibson , Brian Cain , Yoshinori Sato , "Edgar E . Iglesias" , Claudio Fontana , Daniel Henrique Barboza , Artyom Tarasenko , Marcelo Tosatti , qemu-ppc@nongnu.org, Liu Zhiwei , Aurelien Jarno , Ilya Leoshkevich , Daniel Henrique Barboza , Bastian Koppelmann , =?utf-8?q?C=C3=A9dric_?= =?utf-8?q?Le_Goater?= , Alistair Francis , Alessandro Di Federico , Song Gao , Marcel Apfelbaum , Chris Wulff , "Michael S. Tsirkin" , Alistair Francis , Fabiano Rosas , qemu-s390x@nongnu.org, Yanan Wang , Luc Michel , Weiwei Li , Bin Meng , Stafford Horne , Xiaojuan Yang , "Daniel P . Berrange" , Thomas Huth , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-arm@nongnu.org, Jiaxun Yang , Richard Henderson , Aleksandar Rikalo , Bernhard Beschow , Mark Cave-Ayland , qemu-riscv@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Nicholas Piggin , Greg Kurz , Michael Rolnik , Eduardo Habkost , Markus Armbruster , Palmer Dabbelt Subject: [PATCH 20/22] target/s390x: Use s390_realize_cpu_model() as verify_accel_features() Date: Mon, 18 Sep 2023 18:02:53 +0200 Message-ID: <20230918160257.30127-21-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230918160257.30127-1-philmd@linaro.org> References: <20230918160257.30127-1-philmd@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org s390_realize_cpu_model() checks if CPU model and definitions are compatible with the KVM / TCG accelerators, before realizing the vCPU. Use it directly as CPUClass::verify_accel_features() handler (called from cpu_exec_realizefn()). Signed-off-by: Philippe Mathieu-Daudé --- target/s390x/cpu.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c index 1a44a6d2b2..983dbfe563 100644 --- a/target/s390x/cpu.c +++ b/target/s390x/cpu.c @@ -231,11 +231,6 @@ static void s390_cpu_realizefn(DeviceState *dev, Error **errp) S390CPUClass *scc = S390_CPU_GET_CLASS(dev); Error *err = NULL; - /* the model has to be realized before qemu_init_vcpu() due to kvm */ - if (!s390_realize_cpu_model(cs, &err)) { - goto out; - } - cpu_exec_realizefn(cs, &err); if (err != NULL) { goto out; @@ -329,6 +324,7 @@ static void s390_cpu_class_init(ObjectClass *oc, void *data) scc->reset = s390_cpu_reset; cc->class_by_name = s390_cpu_class_by_name, + cc->verify_accel_features = s390_realize_cpu_model; cc->has_work = s390_cpu_has_work; cc->dump_state = s390_cpu_dump_state; cc->query_cpu_fast = s390_query_cpu_fast; From patchwork Mon Sep 18 16:02:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13390089 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B4AC6CD37B0 for ; Mon, 18 Sep 2023 16:42:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230305AbjIRQma (ORCPT ); Mon, 18 Sep 2023 12:42:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229731AbjIRQmQ (ORCPT ); Mon, 18 Sep 2023 12:42:16 -0400 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95A401712 for ; Mon, 18 Sep 2023 09:04:56 -0700 (PDT) Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-500a8b2b73eso7543003e87.0 for ; Mon, 18 Sep 2023 09:04:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695053091; x=1695657891; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GMzTvk0FEO6I+ReA5ceoXcLeA6ER1WjzLpFKcs1vmU4=; b=POxpTtvRLsy2KrAPmkEKhjGKXMfIUvVFSGXJNTSc6J/LJUUwFqKL52eAggUZEzTyCw rahSekiU1eGAlWdauZ4zZGLgJ2vgrNZFvqJPSs4Kve2QpqHF+om4n3yTM5A6Yk5YPXQq Ska0KVFnjzJcXEQk36xDyeSu9YcdW1ZlageIzWPHwmusD9SFWWRPeuur7HCLG/o0i3xS j2shSeWCNEknu68rEncQXIj3+i2OYVGeBSm9rTB//3eHwIgII9B2jzPJX0ATlg2OrZfT qrIi3OqPC2E/CLrqBM9jPWdW8AJ7OhY24o/hWHueNdFZa6+apXAXkqmMoDpvosIIzfbf Fzjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695053091; x=1695657891; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GMzTvk0FEO6I+ReA5ceoXcLeA6ER1WjzLpFKcs1vmU4=; b=FdzijzIXK5UNkMqqOfMdnQTQE9bcI86LyOUzm3O586CeBv2jHYF4ie+2OXlqp71in9 MQ+W1fm8exSxCxf2ZzRAfCWz4S3zQx8vcu/g1/tSDIZSo1FpjXiusVWc2frcNybWKQ3l gAyJwrMvo7QGtRiDNp+zLtDLhGRbkSgZAOtT9O/jgeshWXzrrjTZUzo6BZ/C/O6ECedJ TPi+WOLyZY1nVLf4KtJYzhYmgJ06e+jV/MdN/gcORJA+mABBXkJsGxrULJraRBHsAKwq 2ByZtswE7n3g+3s2v1aQTABHDNqaJC6spw4YyWdASVvatNxORwOBZI5C25nOCBzgGAMR gT3A== X-Gm-Message-State: AOJu0YzkvcN9mhiBpCwcNHrFu88KoRbhXMsxGNUViiEgZ/5hMOcJhMkH Pih/s+SABpGJsH93dhbEArk3jA== X-Google-Smtp-Source: AGHT+IF2lowlwslUXKPMUOsRhTSe1sID6DU3fFY6oz4zaM9BZXy8URyT0npkn+KMnJlFujwR995gHQ== X-Received: by 2002:a05:6512:3f8:b0:503:95d:f2bd with SMTP id n24-20020a05651203f800b00503095df2bdmr4180507lfq.34.1695053091074; Mon, 18 Sep 2023 09:04:51 -0700 (PDT) Received: from localhost.localdomain (static-212-193-78-212.thenetworkfactory.nl. [212.78.193.212]) by smtp.gmail.com with ESMTPSA id i8-20020a0564020f0800b005309eb7544fsm4528407eda.45.2023.09.18.09.04.48 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 18 Sep 2023 09:04:50 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Laurent Vivier , Paolo Bonzini , Max Filippov , David Hildenbrand , Peter Xu , Anton Johansson , Peter Maydell , kvm@vger.kernel.org, Marek Vasut , David Gibson , Brian Cain , Yoshinori Sato , "Edgar E . Iglesias" , Claudio Fontana , Daniel Henrique Barboza , Artyom Tarasenko , Marcelo Tosatti , qemu-ppc@nongnu.org, Liu Zhiwei , Aurelien Jarno , Ilya Leoshkevich , Daniel Henrique Barboza , Bastian Koppelmann , =?utf-8?q?C=C3=A9dric_?= =?utf-8?q?Le_Goater?= , Alistair Francis , Alessandro Di Federico , Song Gao , Marcel Apfelbaum , Chris Wulff , "Michael S. Tsirkin" , Alistair Francis , Fabiano Rosas , qemu-s390x@nongnu.org, Yanan Wang , Luc Michel , Weiwei Li , Bin Meng , Stafford Horne , Xiaojuan Yang , "Daniel P . Berrange" , Thomas Huth , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-arm@nongnu.org, Jiaxun Yang , Richard Henderson , Aleksandar Rikalo , Bernhard Beschow , Mark Cave-Ayland , qemu-riscv@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Nicholas Piggin , Greg Kurz , Michael Rolnik , Eduardo Habkost , Markus Armbruster , Palmer Dabbelt Subject: [PATCH 21/22] exec/cpu: Have cpu_exec_realize() return a boolean Date: Mon, 18 Sep 2023 18:02:54 +0200 Message-ID: <20230918160257.30127-22-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230918160257.30127-1-philmd@linaro.org> References: <20230918160257.30127-1-philmd@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Following the example documented since commit e3fe3988d7 ("error: Document Error API usage rules"), have cpu_exec_realizefn() return a boolean indicating whether an error is set or not. Signed-off-by: Philippe Mathieu-Daudé --- include/hw/core/cpu.h | 2 +- cpu.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 1e940f6bb5..3dc6968428 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -1014,7 +1014,7 @@ G_NORETURN void cpu_abort(CPUState *cpu, const char *fmt, ...) /* $(top_srcdir)/cpu.c */ void cpu_class_init_props(DeviceClass *dc); void cpu_exec_initfn(CPUState *cpu); -void cpu_exec_realizefn(CPUState *cpu, Error **errp); +bool cpu_exec_realizefn(CPUState *cpu, Error **errp); void cpu_exec_unrealizefn(CPUState *cpu); /** diff --git a/cpu.c b/cpu.c index 84b03c09ac..96ae440b81 100644 --- a/cpu.c +++ b/cpu.c @@ -131,7 +131,7 @@ const VMStateDescription vmstate_cpu_common = { }; #endif -void cpu_exec_realizefn(CPUState *cpu, Error **errp) +bool cpu_exec_realizefn(CPUState *cpu, Error **errp) { /* cache the cpu class for the hotpath */ cpu->cc = CPU_GET_CLASS(cpu); @@ -142,7 +142,7 @@ void cpu_exec_realizefn(CPUState *cpu, Error **errp) } if (!accel_cpu_realizefn(cpu, errp)) { - return; + return false; } /* NB: errp parameter is unused currently */ @@ -169,6 +169,8 @@ void cpu_exec_realizefn(CPUState *cpu, Error **errp) vmstate_register(NULL, cpu->cpu_index, cpu->cc->sysemu_ops->legacy_vmsd, cpu); } #endif /* CONFIG_USER_ONLY */ + + return true; } void cpu_exec_unrealizefn(CPUState *cpu) From patchwork Mon Sep 18 16:02:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13390069 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D2C73CD13D2 for ; Mon, 18 Sep 2023 16:39:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230345AbjIRQjO (ORCPT ); Mon, 18 Sep 2023 12:39:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229527AbjIRQjC (ORCPT ); Mon, 18 Sep 2023 12:39:02 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6BA9E4F for ; Mon, 18 Sep 2023 09:11:10 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-404fbfac998so21530715e9.3 for ; Mon, 18 Sep 2023 09:11:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695053465; x=1695658265; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TI3/KBb/+3Te5uOTKkyhQWXS4VS0D1UFt2aGwQADGyc=; b=Qo/8g+flRNZNIVirRtb6FFYTVQGozTZ9+tAhytzm1akqjf0soVvDCpHViqWq9ErTvA 5akN8Vn4myXmtdjSxl6TnztbcHifyYCVXILaCqKuqFcBZS/VKdIe7VuQBnm/bgKIvM0P GdnTiXKfE38JgKeteG6CnJ0nXbo+guBghyLzfNEjk5CpcPaefyuSMNLqrsefH5OD38Dq 6iCO0yrKgnLVps/7hqeMDwVkKP9oJ71g7LMKkmD51vbvxS7oMrduxWrGRFLqRcf4u3TT RPMxn8DFScEkoXuYEF4kkKMGHD06wWfl2OuFwqlF0L2zo86xROxhuwRc1IQwJXSiJx7+ Pmpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695053465; x=1695658265; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TI3/KBb/+3Te5uOTKkyhQWXS4VS0D1UFt2aGwQADGyc=; b=fmCVWW/V3fPkTuw+Ehj7CJIphdLrYfkFd+Kz7fSYWn2e9EMoN75YEVc6yuQY58Mrod NTOPNgmkiUWU/o9cKfdvHrjbc+QNYH61yGOEdaWbnOZR/M/YPNs0GldByMass/w6PbMh 7L5E2fiaeinjhL+K8MbR6y1iud49bW23LWaswiXLX8Hi0GmVXDbr0Y+GxGW8PDkiD7cS JNyksHNbaorpBIw4HU9KEPMBwqatZwbM2Ncxi/cJnAvZtOYF6VexmEoTkns7SRdrfQNK OP+Ntuz/97wW0k/uJDOACi0AGqawhaKenUD6iOKtXjSwVt2VL7qASYvKpMsnh0gnxT2m rnAQ== X-Gm-Message-State: AOJu0Yxd9+O7iX+CQ/oqmzjNaQpLAH5mBhAKq0eDgyTdoesYXMcSp263 dOn1hFj5gh1AgzpXyccsl2sPJ9u2gMWnjmkMgSktCJgV X-Google-Smtp-Source: AGHT+IE8tHvaLGMz9Bg2ooXF3ZqMqPFeliYGvN3VlPRFdqErpxTJBqw3FnvE/+Bds7Ty0U2MCoDi/A== X-Received: by 2002:ac2:4887:0:b0:503:56f:c655 with SMTP id x7-20020ac24887000000b00503056fc655mr4625310lfc.57.1695053096666; Mon, 18 Sep 2023 09:04:56 -0700 (PDT) Received: from localhost.localdomain (static-212-193-78-212.thenetworkfactory.nl. [212.78.193.212]) by smtp.gmail.com with ESMTPSA id fd14-20020a056402388e00b005307e75d24dsm5026981edb.17.2023.09.18.09.04.55 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 18 Sep 2023 09:04:56 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Laurent Vivier , Paolo Bonzini , Max Filippov , David Hildenbrand , Peter Xu , Anton Johansson , Peter Maydell , kvm@vger.kernel.org, Marek Vasut , David Gibson , Brian Cain , Yoshinori Sato , "Edgar E . Iglesias" , Claudio Fontana , Daniel Henrique Barboza , Artyom Tarasenko , Marcelo Tosatti , qemu-ppc@nongnu.org, Liu Zhiwei , Aurelien Jarno , Ilya Leoshkevich , Daniel Henrique Barboza , Bastian Koppelmann , =?utf-8?q?C=C3=A9dric_?= =?utf-8?q?Le_Goater?= , Alistair Francis , Alessandro Di Federico , Song Gao , Marcel Apfelbaum , Chris Wulff , "Michael S. Tsirkin" , Alistair Francis , Fabiano Rosas , qemu-s390x@nongnu.org, Yanan Wang , Luc Michel , Weiwei Li , Bin Meng , Stafford Horne , Xiaojuan Yang , "Daniel P . Berrange" , Thomas Huth , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-arm@nongnu.org, Jiaxun Yang , Richard Henderson , Aleksandar Rikalo , Bernhard Beschow , Mark Cave-Ayland , qemu-riscv@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Nicholas Piggin , Greg Kurz , Michael Rolnik , Eduardo Habkost , Markus Armbruster , Palmer Dabbelt Subject: [PATCH 22/22] exec/cpu: Call cpu_exec_realizefn() once in cpu_common_realize() Date: Mon, 18 Sep 2023 18:02:55 +0200 Message-ID: <20230918160257.30127-23-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230918160257.30127-1-philmd@linaro.org> References: <20230918160257.30127-1-philmd@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org cpu_exec_realizefn() is called in each ${target}_cpu_realize(), before calling their parent_realize(), which is simply cpu_common_realizefn(). Directly call it there instead. Signed-off-by: Philippe Mathieu-Daudé --- hw/core/cpu-common.c | 4 ++++ target/alpha/cpu.c | 8 -------- target/arm/cpu.c | 6 ------ target/avr/cpu.c | 7 ------- target/cris/cpu.c | 7 ------- target/hexagon/cpu.c | 7 ------- target/hppa/cpu.c | 15 ++------------- target/i386/cpu.c | 6 ------ target/i386/kvm/kvm-cpu.c | 4 ++-- target/loongarch/cpu.c | 7 ------- target/m68k/cpu.c | 7 ------- target/microblaze/cpu.c | 7 ------- target/mips/cpu.c | 7 ------- target/nios2/cpu.c | 7 ------- target/openrisc/cpu.c | 7 ------- target/ppc/cpu_init.c | 5 ----- target/riscv/cpu.c | 6 ------ target/rx/cpu.c | 7 ------- target/s390x/cpu.c | 5 ----- target/sh4/cpu.c | 7 ------- target/sparc/cpu.c | 8 -------- target/tricore/cpu.c | 7 ------- target/xtensa/cpu.c | 7 ------- 23 files changed, 8 insertions(+), 150 deletions(-) diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c index 35c0cc4dad..8901c482a0 100644 --- a/hw/core/cpu-common.c +++ b/hw/core/cpu-common.c @@ -204,6 +204,10 @@ static void cpu_common_realizefn(DeviceState *dev, Error **errp) } } + if (!cpu_exec_realizefn(cpu, errp)) { + return; + } + /* Create CPU address space and vCPU thread */ qemu_init_vcpu(cpu); diff --git a/target/alpha/cpu.c b/target/alpha/cpu.c index eb78318bb8..85834c4d61 100644 --- a/target/alpha/cpu.c +++ b/target/alpha/cpu.c @@ -72,15 +72,7 @@ static void alpha_cpu_disas_set_info(CPUState *cpu, disassemble_info *info) static void alpha_cpu_realizefn(DeviceState *dev, Error **errp) { - CPUState *cs = CPU(dev); AlphaCPUClass *acc = ALPHA_CPU_GET_CLASS(dev); - Error *local_err = NULL; - - cpu_exec_realizefn(cs, &local_err); - if (local_err != NULL) { - error_propagate(errp, local_err); - return; - } acc->parent_realize(dev, errp); } diff --git a/target/arm/cpu.c b/target/arm/cpu.c index a551383fd3..d8eaa186cd 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -1756,12 +1756,6 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) int pagebits; Error *local_err = NULL; - cpu_exec_realizefn(cs, &local_err); - if (local_err != NULL) { - error_propagate(errp, local_err); - return; - } - #ifndef CONFIG_USER_ONLY { uint64_t scale; diff --git a/target/avr/cpu.c b/target/avr/cpu.c index d3460b3960..e512ad46d3 100644 --- a/target/avr/cpu.c +++ b/target/avr/cpu.c @@ -112,13 +112,6 @@ static void avr_cpu_realizefn(DeviceState *dev, Error **errp) { CPUState *cs = CPU(dev); AVRCPUClass *mcc = AVR_CPU_GET_CLASS(dev); - Error *local_err = NULL; - - cpu_exec_realizefn(cs, &local_err); - if (local_err != NULL) { - error_propagate(errp, local_err); - return; - } mcc->parent_realize(dev, errp); cpu_reset(cs); diff --git a/target/cris/cpu.c b/target/cris/cpu.c index 671693a362..9fb69ecda4 100644 --- a/target/cris/cpu.c +++ b/target/cris/cpu.c @@ -144,13 +144,6 @@ static void cris_cpu_realizefn(DeviceState *dev, Error **errp) { CPUState *cs = CPU(dev); CRISCPUClass *ccc = CRIS_CPU_GET_CLASS(dev); - Error *local_err = NULL; - - cpu_exec_realizefn(cs, &local_err); - if (local_err != NULL) { - error_propagate(errp, local_err); - return; - } ccc->parent_realize(dev, errp); cpu_reset(cs); diff --git a/target/hexagon/cpu.c b/target/hexagon/cpu.c index 5b9bb3fe83..17785e2921 100644 --- a/target/hexagon/cpu.c +++ b/target/hexagon/cpu.c @@ -332,13 +332,6 @@ static void hexagon_cpu_realize(DeviceState *dev, Error **errp) { CPUState *cs = CPU(dev); HexagonCPUClass *mcc = HEXAGON_CPU_GET_CLASS(dev); - Error *local_err = NULL; - - cpu_exec_realizefn(cs, &local_err); - if (local_err != NULL) { - error_propagate(errp, local_err); - return; - } gdb_register_coprocessor(cs, hexagon_hvx_gdb_read_register, hexagon_hvx_gdb_write_register, diff --git a/target/hppa/cpu.c b/target/hppa/cpu.c index b0d106b6c7..a87028b275 100644 --- a/target/hppa/cpu.c +++ b/target/hppa/cpu.c @@ -121,22 +121,11 @@ void hppa_cpu_do_unaligned_access(CPUState *cs, vaddr addr, static void hppa_cpu_realizefn(DeviceState *dev, Error **errp) { - CPUState *cs = CPU(dev); HPPACPUClass *acc = HPPA_CPU_GET_CLASS(dev); - Error *local_err = NULL; - - cpu_exec_realizefn(cs, &local_err); - if (local_err != NULL) { - error_propagate(errp, local_err); - return; - } #ifndef CONFIG_USER_ONLY - { - HPPACPU *cpu = HPPA_CPU(cs); - cpu->alarm_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, - hppa_cpu_alarm_timer, cpu); - } + cpu->alarm_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, + hppa_cpu_alarm_timer, HPPA_CPU(dev)); #endif acc->parent_realize(dev, errp); diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 2884733397..c170e2976b 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -7311,12 +7311,6 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) return; } - 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); diff --git a/target/i386/kvm/kvm-cpu.c b/target/i386/kvm/kvm-cpu.c index 1fe62ce176..0f52649779 100644 --- a/target/i386/kvm/kvm-cpu.c +++ b/target/i386/kvm/kvm-cpu.c @@ -34,10 +34,10 @@ static bool kvm_cpu_realizefn(CPUState *cs, Error **errp) * * x86_cpu_realize(): * -> x86_cpu_expand_features() - * -> cpu_exec_realizefn(): + * -> cpu_common_realizefn() + * -> cpu_exec_realizefn(): * -> accel_cpu_realizefn() * kvm_cpu_realizefn() -> host_cpu_realizefn() - * -> cpu_common_realizefn() * -> check/update ucode_rev, phys_bits, mwait */ if (cpu->max_features) { diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c index dc0ac39833..d61dcaebca 100644 --- a/target/loongarch/cpu.c +++ b/target/loongarch/cpu.c @@ -555,13 +555,6 @@ static void loongarch_cpu_realizefn(DeviceState *dev, Error **errp) { CPUState *cs = CPU(dev); LoongArchCPUClass *lacc = LOONGARCH_CPU_GET_CLASS(dev); - Error *local_err = NULL; - - cpu_exec_realizefn(cs, &local_err); - if (local_err != NULL) { - error_propagate(errp, local_err); - return; - } loongarch_cpu_register_gdb_regs_for_features(cs); diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c index 3da316bc30..c6740e0e78 100644 --- a/target/m68k/cpu.c +++ b/target/m68k/cpu.c @@ -309,16 +309,9 @@ static void m68k_cpu_realizefn(DeviceState *dev, Error **errp) CPUState *cs = CPU(dev); M68kCPU *cpu = M68K_CPU(dev); M68kCPUClass *mcc = M68K_CPU_GET_CLASS(dev); - Error *local_err = NULL; register_m68k_insns(&cpu->env); - cpu_exec_realizefn(cs, &local_err); - if (local_err != NULL) { - error_propagate(errp, local_err); - return; - } - m68k_cpu_init_gdb(cpu); mcc->parent_realize(dev, errp); diff --git a/target/microblaze/cpu.c b/target/microblaze/cpu.c index 1f19a6e07d..5194911ad4 100644 --- a/target/microblaze/cpu.c +++ b/target/microblaze/cpu.c @@ -207,13 +207,6 @@ static void mb_cpu_realizefn(DeviceState *dev, Error **errp) uint8_t version_code = 0; const char *version; int i = 0; - Error *local_err = NULL; - - cpu_exec_realizefn(cs, &local_err); - if (local_err != NULL) { - error_propagate(errp, local_err); - return; - } if (cpu->cfg.addr_size < 32 || cpu->cfg.addr_size > 64) { error_setg(errp, "addr-size %d is out of range (32 - 64)", diff --git a/target/mips/cpu.c b/target/mips/cpu.c index 7c81e6c356..4f15dcea44 100644 --- a/target/mips/cpu.c +++ b/target/mips/cpu.c @@ -462,13 +462,6 @@ static void mips_cpu_realizefn(DeviceState *dev, Error **errp) MIPSCPU *cpu = MIPS_CPU(dev); CPUMIPSState *env = &cpu->env; MIPSCPUClass *mcc = MIPS_CPU_GET_CLASS(dev); - Error *local_err = NULL; - - cpu_exec_realizefn(cs, &local_err); - if (local_err != NULL) { - error_propagate(errp, local_err); - return; - } env->exception_base = (int32_t)0xBFC00000; diff --git a/target/nios2/cpu.c b/target/nios2/cpu.c index f500ca7ba2..fc753bb1be 100644 --- a/target/nios2/cpu.c +++ b/target/nios2/cpu.c @@ -199,13 +199,6 @@ static void nios2_cpu_realizefn(DeviceState *dev, Error **errp) CPUState *cs = CPU(dev); Nios2CPU *cpu = NIOS2_CPU(cs); Nios2CPUClass *ncc = NIOS2_CPU_GET_CLASS(dev); - Error *local_err = NULL; - - cpu_exec_realizefn(cs, &local_err); - if (local_err != NULL) { - error_propagate(errp, local_err); - return; - } realize_cr_status(cs); diff --git a/target/openrisc/cpu.c b/target/openrisc/cpu.c index e4ec95ca7f..438146c681 100644 --- a/target/openrisc/cpu.c +++ b/target/openrisc/cpu.c @@ -133,13 +133,6 @@ static void openrisc_cpu_realizefn(DeviceState *dev, Error **errp) { CPUState *cs = CPU(dev); OpenRISCCPUClass *occ = OPENRISC_CPU_GET_CLASS(dev); - Error *local_err = NULL; - - cpu_exec_realizefn(cs, &local_err); - if (local_err != NULL) { - error_propagate(errp, local_err); - return; - } occ->parent_realize(dev, errp); cpu_reset(cs); diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c index 24d4e8fa7e..99087ee57c 100644 --- a/target/ppc/cpu_init.c +++ b/target/ppc/cpu_init.c @@ -6809,11 +6809,6 @@ static void ppc_cpu_realize(DeviceState *dev, Error **errp) PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu); Error *local_err = NULL; - cpu_exec_realizefn(cs, &local_err); - if (local_err != NULL) { - error_propagate(errp, local_err); - return; - } if (cpu->vcpu_id == UNASSIGNED_CPU_INDEX) { cpu->vcpu_id = cs->cpu_index; } diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 4f7ae55359..62be6d88fc 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1503,12 +1503,6 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) RISCVCPUClass *mcc = RISCV_CPU_GET_CLASS(dev); Error *local_err = NULL; - cpu_exec_realizefn(cs, &local_err); - if (local_err != NULL) { - error_propagate(errp, local_err); - return; - } - if (tcg_enabled()) { riscv_cpu_realize_tcg(dev, &local_err); if (local_err != NULL) { diff --git a/target/rx/cpu.c b/target/rx/cpu.c index 089df61790..db951ff988 100644 --- a/target/rx/cpu.c +++ b/target/rx/cpu.c @@ -129,13 +129,6 @@ static void rx_cpu_realize(DeviceState *dev, Error **errp) { CPUState *cs = CPU(dev); RXCPUClass *rcc = RX_CPU_GET_CLASS(dev); - Error *local_err = NULL; - - cpu_exec_realizefn(cs, &local_err); - if (local_err != NULL) { - error_propagate(errp, local_err); - return; - } rcc->parent_realize(dev, errp); cpu_reset(cs); diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c index 983dbfe563..e305928651 100644 --- a/target/s390x/cpu.c +++ b/target/s390x/cpu.c @@ -231,11 +231,6 @@ static void s390_cpu_realizefn(DeviceState *dev, Error **errp) S390CPUClass *scc = S390_CPU_GET_CLASS(dev); Error *err = NULL; - cpu_exec_realizefn(cs, &err); - if (err != NULL) { - goto out; - } - #if !defined(CONFIG_USER_ONLY) qemu_register_reset(s390_cpu_machine_reset_cb, S390_CPU(dev)); #endif diff --git a/target/sh4/cpu.c b/target/sh4/cpu.c index e6690daf9a..a3fc034ea5 100644 --- a/target/sh4/cpu.c +++ b/target/sh4/cpu.c @@ -220,13 +220,6 @@ static void superh_cpu_realizefn(DeviceState *dev, Error **errp) { CPUState *cs = CPU(dev); SuperHCPUClass *scc = SUPERH_CPU_GET_CLASS(dev); - Error *local_err = NULL; - - cpu_exec_realizefn(cs, &local_err); - if (local_err != NULL) { - error_propagate(errp, local_err); - return; - } scc->parent_realize(dev, errp); cpu_reset(cs); diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c index 88157fcd33..f0b2187f3b 100644 --- a/target/sparc/cpu.c +++ b/target/sparc/cpu.c @@ -750,18 +750,10 @@ static ObjectClass *sparc_cpu_class_by_name(const char *cpu_model) static void sparc_cpu_realizefn(DeviceState *dev, Error **errp) { - CPUState *cs = CPU(dev); SPARCCPUClass *scc = SPARC_CPU_GET_CLASS(dev); - Error *local_err = NULL; SPARCCPU *cpu = SPARC_CPU(dev); CPUSPARCState *env = &cpu->env; - cpu_exec_realizefn(cs, &local_err); - if (local_err != NULL) { - error_propagate(errp, local_err); - return; - } - #if defined(CONFIG_USER_ONLY) if ((env->def.features & CPU_FEATURE_FLOAT)) { env->def.features |= CPU_FEATURE_FLOAT128; diff --git a/target/tricore/cpu.c b/target/tricore/cpu.c index 0142cf556d..5319a6841e 100644 --- a/target/tricore/cpu.c +++ b/target/tricore/cpu.c @@ -95,13 +95,6 @@ static void tricore_cpu_realizefn(DeviceState *dev, Error **errp) TriCoreCPU *cpu = TRICORE_CPU(dev); TriCoreCPUClass *tcc = TRICORE_CPU_GET_CLASS(dev); CPUTriCoreState *env = &cpu->env; - Error *local_err = NULL; - - cpu_exec_realizefn(cs, &local_err); - if (local_err != NULL) { - error_propagate(errp, local_err); - return; - } /* Some features automatically imply others */ if (tricore_has_feature(env, TRICORE_FEATURE_162)) { diff --git a/target/xtensa/cpu.c b/target/xtensa/cpu.c index bbfd2d42a8..c7bdd0980a 100644 --- a/target/xtensa/cpu.c +++ b/target/xtensa/cpu.c @@ -160,13 +160,6 @@ static void xtensa_cpu_realizefn(DeviceState *dev, Error **errp) { CPUState *cs = CPU(dev); XtensaCPUClass *xcc = XTENSA_CPU_GET_CLASS(dev); - Error *local_err = NULL; - - cpu_exec_realizefn(cs, &local_err); - if (local_err != NULL) { - error_propagate(errp, local_err); - return; - } cs->gdb_num_regs = xcc->config->gdb_regmap.num_regs;