From patchwork Thu Jan 2 21:17:53 2025 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: 854752 Delivered-To: patch@linaro.org Received: by 2002:a5d:4888:0:b0:385:e875:8a9e with SMTP id g8csp7968589wrq; Thu, 2 Jan 2025 13:19:12 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUfe36Y2eOzHswxNNEkjvyXFiMHoEcQrQtULo63+dVVoCszGferIdxJTqCB3A9qWJetxGaHQg==@linaro.org X-Google-Smtp-Source: AGHT+IEsA+zfa1Oo+hiy12Sg3c1zFDJQkFfcaF7qhG7xyzoW+5od5x/PcoMXXKLrhsMCSJSsKjdV X-Received: by 2002:a05:622a:5c90:b0:467:56f9:b9f1 with SMTP id d75a77b69052e-46a53e49d94mr700188911cf.22.1735852752258; Thu, 02 Jan 2025 13:19:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1735852752; cv=none; d=google.com; s=arc-20240605; b=Z/pGS7A38P0FotOEQG/wzN1F+d3zhu79WO8bMLcPe/aWsXcM/CB9c+4EuLOoI53yEB RM+hWlEzo2FquNOyAeokSVbqn+HJhUJjOSHmYneIxmc/UGEM6abIx6kbKNJJgn09lD5s RFzAteBxAP7G9oWmiZBSSgcRJKHCvMwyjMBeQLcG06cxsu8v1qXQ+VAqyNg7MfUXMVn+ FmcXEYl45CTLVirS5TBIhhC6Mf1mQNy3EXcRZ9G6YWtgVh3tskLKKjIsUCmIc/Xi2lsZ ArTT8bEoGo1xW4TjiSg1NzLxLARjZUfOPF0h1D7XMbXhJYyTn8ezD2mMfEDsWXvy4AHC 60yA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=XroMYY0R/MiabM3vxlKI8plZjULUSdM7o1GYxaZu1lI=; fh=Yr6y3Q7nw9Pkn2BMoDtN0XGcR8Ktn+gkbMNk1sAP+Hw=; b=Gq8WV+SWb3Ejxe0gE5hbOAg+pMhk51kU+irMZCfY0DCzRxNGshBkbmhz+zeaElf9EK iZVuGCVlEfVP1F/f0IUhwWbeaqk1+jJ84a8xf3v1G0cCQNW8Od8jXnUeh1VnwcZcvWo6 mxRwourxYgnyx2TLz9TQhxdOUSpRgvTs9jpijBsdJgbBtxDiUruHWhfLxIQRdzNju4AT SkNbM9qFPoOZZ07pWk30caT/4KHvR6Unwy9uU/rbNRwpp2bfjGyUiSPxZ6xnh7pZ6b/u BKLaWeQ2NPl+gz+P5losUEyElWJoIsiz4VIPOA7U4GFQRX15yAM6npCSvYEbJM4+CobK Hv4g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yQQSuWpc; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-46a3ebc5e05si335344051cf.489.2025.01.02.13.19.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jan 2025 13:19:12 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yQQSuWpc; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tTSaG-00043c-Rr; Thu, 02 Jan 2025 16:18:24 -0500 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 1tTSa4-00040f-Sw for qemu-devel@nongnu.org; Thu, 02 Jan 2025 16:18:17 -0500 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tTSa1-0001Lb-0o for qemu-devel@nongnu.org; Thu, 02 Jan 2025 16:18:10 -0500 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-436326dcb1cso77460205e9.0 for ; Thu, 02 Jan 2025 13:18:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1735852687; x=1736457487; darn=nongnu.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=XroMYY0R/MiabM3vxlKI8plZjULUSdM7o1GYxaZu1lI=; b=yQQSuWpc9y/Cr2HdsP4qqCH2wd8qRMVC0Wle2L2kZL3rJoo+x9zzUhmDRcUCtW1s96 kZM70kKZ4cqbHAaR+qGxkmwXMcKGHeBGAs3NSh3vHk4UEER9N77hg0BHqYyRumI5Enb9 Dgq4igHsh/QJEok9mJNXyCQ6A2g/duEJkhxEvRn8gshuSgz3XL6Pfoi5Nu/q4KrqJJct uNw7dBQqY6NuqBbwmTmfasklfCGrjgKnHLF74tatLeCFfM9/Etg1IMiwc4m3RKYO2Sdb bpIrfCR8OypB5i35Z1YugiIKjyG6+qEESoaAQYD9MIMp4Tnlxe2DbDS0qVL3d1QW31fh CeDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735852687; x=1736457487; 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=XroMYY0R/MiabM3vxlKI8plZjULUSdM7o1GYxaZu1lI=; b=xOCWU4eKai/j3bEfL4JIymGf1cBWcMZizNHqpdHxWDSKKR9OdvERBVKSlrooigFkKM HnIbyP041Lx+dxZHNsIyqArDmxWfqr7U+5BbfRDcrZ7TanU5jzmuHkUChflHvTHwh8Rr ZdTc3ancaK7/7do7H5Ohfv+ffv4ARs23Gv9PSPcHJ7bLzORkZcZzUrgMZkXi/jy1/r9d WPdWEBDU2wuiFME29vk0UuQcmOLkxVyROZ0Wg/HBEpzZpYvVJJeIfb0ctbyeDKsbIdNy 0HyWo5jsnzSI3KYMqehcBE9HUk4PzPYTRjFTovviTYQgY+bbyCZ03FPUD0/4h1Uy9FDP mEgg== X-Gm-Message-State: AOJu0YwQ+a9PWIrfhzoiDgF5Q3uPpylPlxW0fPkt4NXS4W1k7GRuqXrm GCXRTZROObSWDPXet53Gsajzi3+w0PypIVYaSGj41N12e0mYLQrqJx26Qk2WqW85oNc1tRSDaEu 2hPOQkw== X-Gm-Gg: ASbGncuEfALacavKzxE6d62mNeJ4INNUsyJcQ+o0qfnN/3RAr1Qsx175erucvhWlYpN SW3VYQEGUdYO1+vDOugSbDOLXKq7GAw2DMuQQSiLZSYOeOe2P959W7Y/wgowVy4AGppiHdSeoWE vnpAkJ9C2+bc4+B6R8JI+CNMwFG9g1cYMjY5DctLkHPyZZVM4zkDKXkhIWwjbc29LSfvqF7x0qa B1Lru2+vLmdp36I+yDJhxYY7mCiHVR/iRUoZEuGIKYFqBVSsrBbYagEeXKPXqHgSmP6XVmgz0h1 IOihg3D4RbFItyRSuz5hJjC8B9V6x5o= X-Received: by 2002:a05:6000:471a:b0:38a:69a9:afb1 with SMTP id ffacd0b85a97d-38a69a9b17amr136101f8f.0.1735852687121; Thu, 02 Jan 2025 13:18:07 -0800 (PST) Received: from localhost.localdomain (88-187-86-199.subs.proxad.net. [88.187.86.199]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38a1c8acabbsm38724383f8f.93.2025.01.02.13.18.06 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 02 Jan 2025 13:18:06 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , "Michael S. Tsirkin" , Richard Henderson , Paolo Bonzini , David Hildenbrand , Zhenwei Pi , Marcel Apfelbaum , "Gonglei (Arei)" , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Peter Xu , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Fam Zheng , Eduardo Habkost Subject: [PATCH v4 1/8] qdev: Implement qdev_create_fake_machine() for user emulation Date: Thu, 2 Jan 2025 22:17:53 +0100 Message-ID: <20250102211800.79235-2-philmd@linaro.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250102211800.79235-1-philmd@linaro.org> References: <20250102211800.79235-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::335; envelope-from=philmd@linaro.org; helo=mail-wm1-x335.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org When a QDev instance is realized, qdev_get_machine() ends up called. In the next commit, qdev_get_machine() will require a "machine" container to be always present. To satisfy this QOM containers design, Implement qdev_create_fake_machine() which creates a fake "machine" container for user emulation. On system emulation, qemu_create_machine() is called from qemu_init(). For user emulation, since the TCG accelerator always calls tcg_init_machine(), we use it to hook our fake machine creation. Suggested-by: Peter Xu Signed-off-by: Philippe Mathieu-Daudé Acked-by: Peter Xu Reviewed-by: Richard Henderson --- include/hw/qdev-core.h | 10 ++++++++++ accel/tcg/tcg-all.c | 8 +++++++- hw/core/qdev-user.c | 21 +++++++++++++++++++++ hw/core/meson.build | 1 + 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 hw/core/qdev-user.c diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index e6ef80b7fd0..b83b1439968 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -1027,6 +1027,16 @@ const char *qdev_fw_name(DeviceState *dev); void qdev_assert_realized_properly(void); Object *qdev_get_machine(void); +/** + * qdev_create_fake_machine(): Create a fake machine container. + * + * .. note:: + * This function is a kludge for user emulation (USER_ONLY) + * because when thread (TYPE_CPU) are realized, qdev_realize() + * access a machine container. + */ +Object *qdev_create_fake_machine(void); + /** * qdev_get_human_name() - Return a human-readable name for a device * @dev: The device. Must be a valid and non-NULL pointer. diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c index c2565758876..95adaacee82 100644 --- a/accel/tcg/tcg-all.c +++ b/accel/tcg/tcg-all.c @@ -35,7 +35,9 @@ #include "qemu/atomic.h" #include "qapi/qapi-builtin-visit.h" #include "qemu/units.h" -#if !defined(CONFIG_USER_ONLY) +#if defined(CONFIG_USER_ONLY) +#include "hw/qdev-core.h" +#else #include "hw/boards.h" #endif #include "internal-common.h" @@ -124,6 +126,10 @@ static int tcg_init_machine(MachineState *ms) tcg_prologue_init(); #endif +#ifdef CONFIG_USER_ONLY + qdev_create_fake_machine(); +#endif + return 0; } diff --git a/hw/core/qdev-user.c b/hw/core/qdev-user.c new file mode 100644 index 00000000000..f816340db5a --- /dev/null +++ b/hw/core/qdev-user.c @@ -0,0 +1,21 @@ +/* + * QDev helpers specific to user emulation. + * + * Copyright 2025 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#include "qemu/osdep.h" +#include "qom/object.h" +#include "hw/qdev-core.h" + +Object *qdev_create_fake_machine(void) +{ + Object *fake_machine_obj; + + fake_machine_obj = object_property_add_new_container(object_get_root(), + "machine"); + object_property_add_new_container(fake_machine_obj, "unattached"); + + return fake_machine_obj; +} diff --git a/hw/core/meson.build b/hw/core/meson.build index ce9dfa3f4bf..65a1698ed1f 100644 --- a/hw/core/meson.build +++ b/hw/core/meson.build @@ -46,3 +46,4 @@ system_ss.add(files( 'vm-change-state-handler.c', 'clock-vmstate.c', )) +user_ss.add(files('qdev-user.c'))