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: 1836271 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=INxTo8Ew; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Rq8jf0Wllz1ync for ; Tue, 19 Sep 2023 02:03:49 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qiGiH-00060W-Hr; Mon, 18 Sep 2023 12:03:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qiGiG-0005yx-2H for qemu-devel@nongnu.org; Mon, 18 Sep 2023 12:03:04 -0400 Received: from mail-ej1-x632.google.com ([2a00:1450:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qiGiD-0003ta-2o for qemu-devel@nongnu.org; Mon, 18 Sep 2023 12:03:03 -0400 Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-986d8332f50so638199666b.0 for ; Mon, 18 Sep 2023 09:03:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695052979; x=1695657779; darn=nongnu.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=INxTo8EwLN4aLX9q3m3G+o7FAqm3qrBb+iJBMhwSHCc8OPPiM5RYZH+mTSxjH/fnTk Y2itOxsL33IxL2ye/rLFJISCZ7o3Rqq2qqpid9l7Jtrg92/U5SVMQccTUEDzWG4HA0BD ywK6Mp4LD+urqc5nAlJYSs5X46iC6my+91jN81mYjxk1hoaerQXH+j/CJrDW3ygkH+oI ht/hkx5B4iSQK5DMnO05hmaYV+QgZ9uJpEHOA3rR4aabzWqKp3cjb31P+AAweGQp4RxK cpZs1HXsSc6Itm1LbLWjK0s2+Te3MtTdi2TLnssBg8hx1fqGdS+aIMgPfv/hKAgP7l+W 0Prw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695052979; x=1695657779; 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=wgIMwmLuSm05QCHNj3fQw8G8LK5hL5AbJur9QXIIPX6V+bF6IyVrw9162WliYV4dSR 0RWJ0Ks6m46e9oE2XV5JfuYZcYYmMatJjgv5kn4IKDsz85nV8q0FADJNNw7j258WIy8u HUwpg0J4oDsttFjFP5Oni2MxXOlAeRfyT8CysfZzOZsq0GJplymcj3D/NGlQd1e2+/YX bfPFEnLY0FlrC3jOq+x/lEp8CE8p3jUSofzILgVlLEn/OPZbG4u9dJuXSS1Nmj4+bex7 jrJnQ6JOy/g/r/MGTDPtO2Tj9Km+ux7LnskXUYW2DOOqKJ9tVJmPv7nz+gEhHCuD53aB iqRg== X-Gm-Message-State: AOJu0YwmQm3aX8Tqcqa17NqOxvDJYeAh29pgXF5ryKoB/LOzShL53bTc So0cgLtLtWc+GvYBbOOh9+aMTDmmLQkcDP+eMOPGtRCX 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 Received-SPF: pass client-ip=2a00:1450:4864:20::632; envelope-from=philmd@linaro.org; helo=mail-ej1-x632.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.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(-)