From patchwork Thu May 15 10:24:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 890156 Delivered-To: patch@linaro.org Received: by 2002:adf:fd8a:0:b0:3a1:f579:ae88 with SMTP id d10csp3059090wrr; Thu, 15 May 2025 03:27:56 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWe7K7bQpyxlqUtE0v96yuztC+2T2D/Y5dMb+VAwJbeCK7dDzA7UFlpFs7FZmaHKpo5YYLmmQ==@linaro.org X-Google-Smtp-Source: AGHT+IEEpVh7M2KZrQJTMm0QYHs3s+y8A55jLFQBNxe992dKumn+jcSP1mXDB+mFR1wjy3YY64XW X-Received: by 2002:a05:6214:3009:b0:6e8:f5db:d78d with SMTP id 6a1803df08f44-6f896e35f47mr111196726d6.23.1747304876035; Thu, 15 May 2025 03:27:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1747304876; cv=none; d=google.com; s=arc-20240605; b=DLuF31PlZO7KIksda7nyHmi2AhJOW87mzSmmFBTmXrpUew5q4yCPsPTNM7EIgF0yU2 PrA4kxZ3MlFfRusKXI5vRr7oPfdlsvWBaDAMVY/bYmaagRK/lXmeTq4GLj+ZpIjSR0F2 v71CjF6HVN5D1U+JWbbeRrl7W+l/LhJc67gYCsJ6AC5VdqkomwJCMHBpiesjsPnfosGj NmTbgapWlGzfhf7G5XCxDSZE0i2P7mVJ8B4SExb05Cmu7W6DnrbzSHgZ+Ijlwg/n+bcy GtOrGg9wPys3W4i66nsOvWa6pdxrJRmaFuG32f0fBTCr7DdlFJRDZPX+GtlNHIHIwYcH 0kIw== 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:to:from :dkim-signature; bh=7QtsMbWF7VE6Px6bLjp5onVkzczQnDLHxWTCi6gF8ps=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=NvJYuSty8ZY9tGVbTG6qtBAO6OMQgb9ifdO8BJ0Iv+UVC93/pjlN3AvZ4ZLNzIv8Cg HQkqPFYqBgFCk586JiY+M/b0X8+p270JEDUNfr+egjZ4ZUCOYvEHOlE4VLq8a27Yb7BL EEGawpNr1hWvpLDNWn9v4fXcyrmHA/dHLz0vsyuS5rjICkLWEpcM0LDMgn/KG2ZPGyi4 xbK4L5jcpCnmGgcTmFAvoymOi7NxRWXeUriUPRm4+Z4BhR5a8WGPh4IL4Fyd8vGb4e9h wkKUQX/Bv8rhrHIUauT3SscXJ63NrlolNhsbUwAjWMpSg1wCfovKKx3zO+6t9tj2CQvf gBYg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="vL7bC4/5"; 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 6a1803df08f44-6f6e39f7a6asi165597256d6.148.2025.05.15.03.27.55 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 15 May 2025 03:27:56 -0700 (PDT) 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="vL7bC4/5"; 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 1uFVmr-0004Jk-Rn; Thu, 15 May 2025 06:26:01 -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 1uFVmo-0004GI-3j for qemu-devel@nongnu.org; Thu, 15 May 2025 06:25:58 -0400 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uFVmm-00086Y-4s for qemu-devel@nongnu.org; Thu, 15 May 2025 06:25:57 -0400 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-43cfba466b2so8367505e9.3 for ; Thu, 15 May 2025 03:25:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1747304754; x=1747909554; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=7QtsMbWF7VE6Px6bLjp5onVkzczQnDLHxWTCi6gF8ps=; b=vL7bC4/5r4i4GuqhwXZAXFaO8mc4/35wlFZbZmipaYUfnxSsRePslhPubL8L/wUmG3 mMJBlu8qF5B9K+t7YZlJArdH/z3CiGUoeWVpIpfASOOsnffVrlK+yKmJBsJKMdZrA7cM J8JOCTi1XUTDqZMq1RCHzul6DCrN7mVJZrZVvuGdsWU30cr0e8YiUqSE3dEoPIP8t8PG RlI7+n9yy4munKFjcyr9fmOvALOHG752xKShBg2eer5pW//2Gv4wRUJbJXtAMLwj7Uvk 7bdPhcQfmG4RY/uNB5sqWu0fL54idCtS4DqKi4egkgslKG/xWEZGWk8ItPn4WvqRYjAL +Bpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747304754; x=1747909554; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7QtsMbWF7VE6Px6bLjp5onVkzczQnDLHxWTCi6gF8ps=; b=xPLS48LPGzn3Or7SGSnSZVjBu7imMkk0xOu2vh15adqecLdZc8b5z7EXsT9weCeGzF vV7bUlZmmPuyVOi0YGcGtchhp4uCRVbJ6Je0JajKSf9J/dzA8N1VMuWsmkAtog0v1NAD wBD3izE4ZA1OOfneWkgH6wq6FvFJb1ukfOgiR4c3RbNVIFhBxGAKyrdA33jT7UN6sAJY nmkhZ1t1ZOp/b/S6ZyX9GILkRpMl0954a2RfKlz4uB5Jql98/0+BNhfvToQu9sGOKb3H ihACtk4e//GHJKlG9gfn1tMu66zbeNp2hwZ3FRG1peAAMcjzkmQ+GoWYQbrzouXqVScE maZQ== X-Gm-Message-State: AOJu0YxMiaRyxd1I9qNSSfSOI3cBKo1ee0hgENqxMrngFbeRtL9FqmQs hLX8dCygNcnl/PB3WTxifpy8VMAYCiN74TcmW7GtKsgi9ynedF62FpuNO4fHKiUIpQXhDr2SWsN +iMQ= X-Gm-Gg: ASbGncskAT4iqAbY0wXxF8zH5I2CbD2ozhQKjQbSLacT/S5Aa73N2y6b2hUqFilg8pE 5LU3RJQWczEk1hOQ3Bsz/zI/vv1In7zEtoTK3klE9EaA+9tDYQisTy8QiQ0B2v2bmYxziwU2Lc+ 7v/KtVRn/9vnQ/Y6qWr2FAVG8rfpUTYan4ReRvcnOzWCXOf0gIyGXoMMqVY/V6AVKikQftYT4XE 0WpBrWPF12L+cZuDfCVgL+ooazExywrn/sHDmceubwcI558joaraR2kSzwdQW0H2uSUif7TwSWC m9kHQu3YhehgBKjw6uuCAZe+doD/uNs93zJ1vD0vyZiKWRBJtr/JTVSzcg== X-Received: by 2002:a05:600c:83c8:b0:442:f485:6fa4 with SMTP id 5b1f17b1804b1-442f971924amr21742645e9.31.1747304754143; Thu, 15 May 2025 03:25:54 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-442f396c3a4sm65657855e9.26.2025.05.15.03.25.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 May 2025 03:25:52 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 03/58] hw/core/cpu-common: Don't init gdbstub until cpu_exec_realizefn() Date: Thu, 15 May 2025 11:24:51 +0100 Message-ID: <20250515102546.2149601-4-peter.maydell@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250515102546.2149601-1-peter.maydell@linaro.org> References: <20250515102546.2149601-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::333; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x333.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 Currently we call gdb_init_cpu() in cpu_common_initfn(), which is very early in the CPU object's init->realize creation sequence. In particular this happens before the architecture-specific subclass's init fn has even run. This means that gdb_init_cpu() can only do things that depend strictly on the class, not on the object, because the CPUState* that it is passed is currently half-initialized. In commit a1f728ecc90cf6c6 we accidentally broke this rule, by adding a call to the gdb_get_core_xml_file method which takes the CPUState. At the moment we get away with this because the only implementation doesn't actually look at the pointer it is passed. However the whole reason we created that method was so that we could make the "which XML file?" decision based on a property of the CPU object, and we currently can't change the Arm implementation of the method to do what we want without causing wrong behaviour or a crash. The ordering restrictions here are: * we must call gdb_init_cpu before: - any call to gdb_register_coprocessor() - any use of the gdb_num_regs field (this is only used in code that's about to call gdb_register_coprocessor() and wants to know the first register number of the set of registers it's about to add) * we must call gdb_init_cpu after CPU properties have been set, which is to say somewhere in realize The function cpu_exec_realizefn() meets both of these requirements, as it is called by the architecture-specific CPU realize function early in realize, before any calls ot gdb_register_coprocessor(). Move the gdb_init_cpu() call to there. Signed-off-by: Peter Maydell Reviewed-by: Edgar E. Iglesias Reviewed-by: Richard Henderson Reviewed-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Message-id: 20250429132200.605611-4-peter.maydell@linaro.org --- hw/core/cpu-common.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c index 92c40b6bf83..39e674aca21 100644 --- a/hw/core/cpu-common.c +++ b/hw/core/cpu-common.c @@ -234,6 +234,8 @@ bool cpu_exec_realizefn(CPUState *cpu, Error **errp) return false; } + gdb_init_cpu(cpu); + /* Wait until cpu initialization complete before exposing cpu. */ cpu_list_add(cpu); @@ -304,7 +306,6 @@ static void cpu_common_initfn(Object *obj) /* cache the cpu class for the hotpath */ cpu->cc = CPU_GET_CLASS(cpu); - gdb_init_cpu(cpu); cpu->cpu_index = UNASSIGNED_CPU_INDEX; cpu->cluster_index = UNASSIGNED_CLUSTER_INDEX; cpu->as = NULL;