From patchwork Mon Sep 18 16:02:33 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: 13390067 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 AEC00CD37B0 for ; Mon, 18 Sep 2023 16:39:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230326AbjIRQjE (ORCPT ); Mon, 18 Sep 2023 12:39:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230343AbjIRQiv (ORCPT ); Mon, 18 Sep 2023 12:38:51 -0400 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 851A144B3 for ; Mon, 18 Sep 2023 09:09:21 -0700 (PDT) Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-52fe27898e9so5461757a12.0 for ; Mon, 18 Sep 2023 09:09:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695053360; x=1695658160; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=R37K2a/Smepsc2iyIaDJqnazCMcEJOOAaYAXmsK0XT0=; b=XGsyrNMUYh74ccQisEZGdYH00pr+SirbulPY0LWeYMNQjNKE2D7xVsAyb1j9vFyDOO YuLu/kMoQ1xtY44qynndyEemka3DrYP1xvPhs9JvGTEBA1kgQPy78LuqQP8AOkAwgHPX Je4Vj9TpVmuU8a3sYwYp0uL7v81PW9hXQ1lPUw3GyUy3vuDMz1FTtIsXHW4raNLoRqIz VruPaXimOOCenxjcixu1z4tXjuRuyETfz8h2ZqFhopzhFRKHzZY5AlaiA+sLf5KJRB8o QuI8ZephY3tlsJa2F7AGrMHXo78GwWIUZj/Gni1NyJfpOw8YZdHgVNW1dqEy6UK/iogg otsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695053360; x=1695658160; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=R37K2a/Smepsc2iyIaDJqnazCMcEJOOAaYAXmsK0XT0=; b=YwlDWubUJCYO+O7QPhIhSdDjiusHhEpZWcuDa1C9qKXgH3QoxPdZ0GSNvuW9KPDskn ngUOG38omvN7cGces/OeOKbx1rdziG33vlEVDRTNU0JyPL+Ld8vmPgyZO5sG0sPu6Vhl Gk6eveepgnB8idHWgtjRijHFumCPyoFcRNgFDgd4twEeZfKbkkZFgjNbuRASXx2vDMYH uQMWBZu6Lzy4hfsnF2zMZujL4uFPyMH4lYmro9Wnv49cNbvhYZndm+GqZDTzTMgk6JBR 9CDZCaXswCuSxuvp+9P0iF04BgYJik+HiYhmI0CCZAzxvd+i3QexccybqA/TFvnLPXXd Q0yw== X-Gm-Message-State: AOJu0YxymPjUK7FnWfn8IOGPkrgrcXxZMjLt9NGzY6uMinTdTACinh5U zz0/9yvPGRCWc88GLu+RMclpGyhOloo9ZNSzOLheR7Wt X-Google-Smtp-Source: AGHT+IHGtyYBQwLAMwFhSgR4DVjVUaGUpdsvPj2BatAS0H6me1yGIyefW0SsMEvxluQ7CDP796y45Q== X-Received: by 2002:a17:907:a0c6:b0:9a1:cb2c:b55c with SMTP id hw6-20020a170907a0c600b009a1cb2cb55cmr6526293ejc.35.1695052978973; Mon, 18 Sep 2023 09:02:58 -0700 (PDT) Received: from localhost.localdomain (static-212-193-78-212.thenetworkfactory.nl. [212.78.193.212]) by smtp.gmail.com with ESMTPSA id rl20-20020a1709076c1400b009adc81c0c7esm5428731ejc.107.2023.09.18.09.02.57 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 18 Sep 2023 09:02:58 -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 00/22] exec/cpu: Call cpu_exec_realizefn() once in cpu_common_realize() Date: Mon, 18 Sep 2023 18:02:33 +0200 Message-ID: <20230918160257.30127-1-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Hi, TL;DR: This series factor duplicated common code in CPUs DeviceRealize() handlers out, moving as a single call in cpu_common_realize(). In an effort to have most of: - CPU core code independant of accelerators - CPU core code target agnostic - CPU target code independant of accelerators - and cpu_reset() called automatically without having to rely on global QEMUResetHandler, I'm working on the core CPU code, unfortunately touching files in all targets. I suppose them term "exec" used in various areas of QEMU started from what we call today "accel[erators]" [*]. So cpu_exec_realizefn() can be read as cpu_accel_realize(), or "generic code where an accelerator realizes its internal fields on an abstract (target independent) CPU". This series moves a common pattern used in all target's cpu_realize() handlers to the common cpu_exec_realizefn(). Some optional code is used to check CPU requested features are compatible with the accelerator possibilities. We extracted this code as CPUClass::verify_accel_features() handler. Better name welcomed :) Some targets were calling cpu_reset() *before* cpu_common_realizefn(), we moved it *after* (since RESET shouldn't happen before REALIZE). I still have to audit each target to confirm there are no side effects. Besides this cpu_reset() change, the rest should be relatively trivial to review, still I'd like feedback from the respective target maintainers for the "move HW creation after vCPU one" patches. Regards, Phil. Follow-up: Make cpu_reset() accel-agnostic and move it to cpu_common_realize() (not trivial due to KVM run_on_cpu() calls). [*] If Paolo/Richard confirm, I might post series renaming various APIs s/exec/accel/, because various headers meaning aren't clear to me. Philippe Mathieu-Daudé (21): target/i386: Only realize existing APIC device hw/intc/apic: Pass CPU using QOM link property target/i386/kvm: Correct comment in kvm_cpu_realize() exec/cpu: Never call cpu_reset() before cpu_realize() exec/cpu: Call qemu_init_vcpu() once in cpu_common_realize() exec/cpu: Call cpu_remove_sync() once in cpu_common_unrealize() exec/cpu: RFC Destroy vCPU address spaces in cpu_common_unrealize() target/arm: Create timers *after* accelerator vCPU is realized target/hppa: Create timer *after* accelerator vCPU is realized target/nios2: Create IRQs *after* accelerator vCPU is realized target/mips: Create clock *after* accelerator vCPU is realized target/xtensa: Create IRQs *after* accelerator vCPU is realized target/sparc: Init CPU environment *after* accelerator vCPU is realized exec/cpu: Introduce CPUClass::verify_accel_features() target/arm: Extract verify_accel_features() from cpu_realize() target/i386: Extract verify_accel_features() from cpu_realize() target/s390x: Call s390_cpu_realize_sysemu from s390_realize_cpu_model target/s390x: Have s390_realize_cpu_model() return a boolean target/s390x: Use s390_realize_cpu_model() as verify_accel_features() exec/cpu: Have cpu_exec_realize() return a boolean exec/cpu: Call cpu_exec_realizefn() once in cpu_common_realize() xianglai li (1): exec/cpu: Introduce the CPU address space destruction function include/exec/cpu-common.h | 8 ++++ include/hw/core/cpu.h | 7 +++- target/s390x/s390x-internal.h | 4 +- cpu.c | 11 ++++- hw/core/cpu-common.c | 15 +++++++ hw/intc/apic_common.c | 2 + softmmu/physmem.c | 24 +++++++++++ target/alpha/cpu.c | 10 ----- target/arm/cpu.c | 53 ++++++++++++------------ target/avr/cpu.c | 10 +---- target/cris/cpu.c | 11 +---- target/hexagon/cpu.c | 11 +---- target/hppa/cpu.c | 20 ++------- target/i386/cpu-sysemu.c | 20 ++++----- target/i386/cpu.c | 77 ++++++++++++++++++----------------- target/i386/kvm/kvm-cpu.c | 3 +- target/loongarch/cpu.c | 11 +---- target/m68k/cpu.c | 11 +---- target/microblaze/cpu.c | 9 ---- target/mips/cpu.c | 27 ++++-------- target/nios2/cpu.c | 20 +++------ target/openrisc/cpu.c | 11 +---- target/ppc/cpu_init.c | 8 ---- target/riscv/cpu.c | 10 +---- target/rx/cpu.c | 11 +---- target/s390x/cpu-sysemu.c | 3 +- target/s390x/cpu.c | 21 +--------- target/s390x/cpu_models.c | 16 +++++--- target/sh4/cpu.c | 11 +---- target/sparc/cpu.c | 10 ----- target/tricore/cpu.c | 10 +---- target/xtensa/cpu.c | 13 +----- 32 files changed, 189 insertions(+), 299 deletions(-)