From patchwork Thu Feb 16 14:23: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: 654041 Delivered-To: patch@linaro.org Received: by 2002:adf:f90f:0:0:0:0:0 with SMTP id b15csp381716wrr; Thu, 16 Feb 2023 06:25:59 -0800 (PST) X-Google-Smtp-Source: AK7set9TxG3p9p+cMVQXLH92ZXftiKs/Be9Ga6JqWKDT7/wcSZlSGcY/KJB7H5/Qqqbu54kVR0Kw X-Received: by 2002:ac8:5910:0:b0:3b9:dd01:6f1f with SMTP id 16-20020ac85910000000b003b9dd016f1fmr10724377qty.39.1676557559797; Thu, 16 Feb 2023 06:25:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676557559; cv=none; d=google.com; s=arc-20160816; b=HX4ZUqeW77M7/3nWKaJUSk3IgJI1zAabooTeQ+syrRYa+GB6pxj9xdYYgBMNN+hC2K mkC79qpdBhZrHujrlDpcL0Lg8WkA6Ea9lnTUx8aRfVZULipVivha96by7caKR3iDyy9Z kt5iOapfLaKkUoVANWXE+5dYKgcYZ+z4YIntcS+Gj2Sj0XRmkN+4RrMJzg6Ig0crpVpV JMMtgUWHqVUeKnncZMFq9JzwJPcpnHWEV8llg/VugvoMVw97OoPQeiVFl5ItmIodyC8K mixT2gx0uK2AcIU5XOX4B6r7iRfxYmvyR+l+vX/5vhv6Gl/lfdqNWZIcO5wmO6tYdLyY 1O/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; 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=Mp16C8opTjs5capPqEpUNYeRp9xjtzcoAR4MvUbLxj4=; b=l3/zWbQm8tQWjUFlFWSZst2yZ60DOPkXBX/i1B07FbDWf8LeifZfiPt8U9EnLgLMnn /5mldJQqW/xyCnisa9pkIsZyyWlLSJbtuHac5kGpkrmbPEuFfngnWkvigf/IFjseGTxR B0oGT3Wrmkg7LUBwqueI63l4Lq9AW6ZQgPELMfLb5yCADCN2niRWa3XMAZM6OYjb2rht sJNXrj1btoAR7oUtFn9fU3GvTC47daiIAZlRBB/x8m1xzMrA0djcIK1scmqmIEG2+OJK qtF+OMLBJ4if2PvOlQ3McNDpCWMuV4MLf0ucQm/v6etikBRObY4X2+jIEVJ/H/jVbS2+ rdQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="H6p4daE/"; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id h13-20020ac8584d000000b003b84ddeae65si1655081qth.120.2023.02.16.06.25.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 16 Feb 2023 06:25:59 -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="H6p4daE/"; 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 Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSfAy-0005dh-R7; Thu, 16 Feb 2023 09:23:56 -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 1pSfAw-0005d6-LX for qemu-devel@nongnu.org; Thu, 16 Feb 2023 09:23:54 -0500 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pSfAv-00079r-4h for qemu-devel@nongnu.org; Thu, 16 Feb 2023 09:23:54 -0500 Received: by mail-wm1-x32e.google.com with SMTP id r18so1678221wmq.5 for ; Thu, 16 Feb 2023 06:23:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=Mp16C8opTjs5capPqEpUNYeRp9xjtzcoAR4MvUbLxj4=; b=H6p4daE/Kz3tCO31ndsJ/BJM2mMtyqWplOw7nhJDYtNnepPf6xGO8z87MEh4lqTIYv BggD/hXpaI5snCBZH5DlV1svBtmLWIEhE8RL7SiHo4v1MpNGyjr9Z9rsqBx4nPagxLQ0 zJY0BmDTDiY8Uj9u2cPLm1uEkKP6/YZCT7oisyuYufzA3FvLbgc6SIFogHbDNtjV4GO/ 6VtmwpWunTGBLUO07MQMkgBPkmWpRGuK2XXOd4HR79/JNE+lVAjRCXNqFEgq9ntxJB+u pAyrIg6082amKhKrs/Jn+vD1ChIrbP2n7ac5IuLdY0nnNc0FaJ+926XuDCSiBNnXViJ4 b3Xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=Mp16C8opTjs5capPqEpUNYeRp9xjtzcoAR4MvUbLxj4=; b=DCesnjjxmVgOPAqOgrZu0SeLg15OllIJ4c6dEy1+VMlHSshaN8cG8ORl2JsVznOeId aKkYWCmIc5Lo55/OlRNDyJMHjy3iksI5CtlrmHgqOvAgtWa0XkIdd5n9MySZDV2tWtZl O8ZPs2W+JI/cdr2FSWJmMiK7iIxlWk8sYrOlnOsUk5Rd+PKwi4tDuPfEPDUPczf3wMEM LuxuRNgrBcXn9AFPdLLWdFRAdfd0Iwk/fenKzmkgKav1d8SX8Au+/t9BhjAQLgRA8cge VeVdfjuR3AaINx6Bf5Pypa1xLMeccWXycf855boMAixt+POmliDYoRZ3EtPDbu77Gs6G DfiA== X-Gm-Message-State: AO0yUKXWjbk/SJ3NShYPwz7Y0DLtfAaf9lEniM3Val+tSLbJNIU1JF5C JIRpW8gLicAZN3psp4wAS2pHApIsPOseXS3u X-Received: by 2002:a05:600c:18a6:b0:3e2:f80:3df1 with SMTP id x38-20020a05600c18a600b003e20f803df1mr1794039wmp.19.1676557432074; Thu, 16 Feb 2023 06:23:52 -0800 (PST) Received: from localhost.localdomain ([81.0.6.76]) by smtp.gmail.com with ESMTPSA id a4-20020a05600c348400b003df5be8987esm5562823wmq.20.2023.02.16.06.23.50 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 16 Feb 2023 06:23:51 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Richard Henderson , Dapeng Mi , Sean Christopherson , Bin Meng , Zhuocheng Ding , =?utf-8?q?Alex_Benn=C3=A9e?= , Zhenyu Wang , qemu-riscv@nongnu.org, Alistair Francis , Zhao Liu , "Edgar E. Iglesias" , Paolo Bonzini , Marcel Apfelbaum , Robert Hoo , Yanan Wang , qemu-arm@nongnu.org, Peter Maydell , =?utf-8?q?Ph?= =?utf-8?q?ilippe_Mathieu-Daud=C3=A9?= , Palmer Dabbelt , Like Xu , Alistair Francis , Zhao Liu , Eduardo Habkost Subject: [PATCH 2/5] hw/cpu/cluster: Only add CPU objects to CPU cluster Date: Thu, 16 Feb 2023 15:23:35 +0100 Message-Id: <20230216142338.82982-3-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230216142338.82982-1-philmd@linaro.org> References: <20230216142338.82982-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=philmd@linaro.org; helo=mail-wm1-x32e.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=ham 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 Do not recursively add CPU and all their children objects. Simply iterate on the cluster direct children, which must be of TYPE_CPU. Otherwise raise an error. Signed-off-by: Philippe Mathieu-Daudé --- hw/cpu/cluster.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/hw/cpu/cluster.c b/hw/cpu/cluster.c index bf3e27e945..b0cdf7d931 100644 --- a/hw/cpu/cluster.c +++ b/hw/cpu/cluster.c @@ -39,12 +39,19 @@ typedef struct CallbackData { static bool add_cpu_to_cluster(Object *obj, void *opaque, Error **errp) { CallbackData *cbdata = opaque; - CPUState *cpu = (CPUState *)object_dynamic_cast(obj, TYPE_CPU); + CPUState *cpu; - if (cpu) { - cpu->cluster_index = cbdata->cluster->cluster_id; - cbdata->cpu_count++; + cpu = (CPUState *)object_dynamic_cast(obj, TYPE_CPU); + if (!cpu) { + error_setg(errp, "cluster %s can only accept CPU types (got %s)", + object_get_canonical_path(OBJECT(cbdata->cluster)), + object_get_typename(obj)); + return false; } + + cpu->cluster_index = cbdata->cluster->cluster_id; + cbdata->cpu_count++; + return true; } @@ -63,8 +70,9 @@ static void cpu_cluster_realize(DeviceState *dev, Error **errp) return; } - object_child_foreach_recursive(cluster_obj, add_cpu_to_cluster, - &cbdata, NULL); + if (!object_child_foreach(cluster_obj, add_cpu_to_cluster, &cbdata, errp)) { + return; + } /* * A cluster with no CPUs is a bug in the board/SoC code that created it;