From patchwork Thu May 30 19:42:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 13680681 Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B97615886B for ; Thu, 30 May 2024 19:42:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717098175; cv=none; b=SQI4PAAd4i0naj/4DKgNQaPPZUgR97bqTHlTPvIwL+nsXcz+8VxmXyxWPe25LAiqqOZDUxJ7IkkREJbVh6z9WGiclqFDyasVAOSN41f3oEtnKgQMwv0GtT1en6+FlfauZzldePzeKDqzuAoNVQoP1qm+fvIemwbVNPayEmyh8w0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717098175; c=relaxed/simple; bh=Zu/scKpfMgM1BABTUFtARd2WDozR0rMC1YLexXBGNTM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=FJwLTXRFojbyFbC5vaE52wNsI5NW4Qa2B3CfxPcXd1DErDf6iOC277aTK7UNLnGive8JGLPtRtizklqRx++WYRshdBCgI4YIpEMmIGwU7mfddhJdUFpn4rCAfl2znn/af1UIH6R5IpdacsAlF+Ag0MHa8FZY5e+UvCelc33PQTw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=yRjxVp1r; arc=none smtp.client-ip=209.85.218.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="yRjxVp1r" Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-a62614b9ae1so155638966b.0 for ; Thu, 30 May 2024 12:42:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717098172; x=1717702972; darn=vger.kernel.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=uF3iE8sM7cMEjCs0SvCbRt/oMMRILi0hvudECvvT8YU=; b=yRjxVp1rTgSUkkfvhfaDkoc/8f8NU7sk3mmjYeAwFLkOqvFG3m9RRLfv2WQbEWL6nh QZsZb6H2qMtSoCpTs7/zgpLFyPGiwFkKHXGmr08oUsTqz78bSAqYj+KhnT1otRVrumg6 MAOxaiej2Z5LoRf5oBEX69/2AGQiBzYxng66/hZUsY4bso+NShH8gNz5UeXHImXLgKhP 2DWCiMlrZ6kwFaABeiEUFr+/ojazWdhZk7Tk+bAsxFTl+8QdQ4L4dyC4rJ/NV8cdWB1f V0Lk42jOnYLVY5jzO0ZaezQ3UL46519x3YA969DFxBvcAVjYz/lXU4OESrNx01xM8rpN 3SRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717098172; x=1717702972; 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=uF3iE8sM7cMEjCs0SvCbRt/oMMRILi0hvudECvvT8YU=; b=rrlMMX5inE9merwmg3vooPei88bqSewo8McNCxsOwB/8HF1s80WMMM2tg7kxbhw6aW kssJMPsn1Saz62TaZZ/Ch71nQUJsV3cOzXtYTV5KuwrCgKu8jBAXjE/bRYu+3+nSd0rB w9FpqaqIUY7TiBTzmIhrtFE5jesuZjmuKU1LE5mvqZXe2GJwXyx7bGj1rw4qPZ+bMMaK HqheldlkHXwEKoeVYbsJSp8sBLvJ5WdDVOjLGAem+MoYBeFAVgkk9eNWCQb6Vb5jipx3 5RrwgrABivHa39SuO4C00EnwY+fdJB/pt6DW1ZDfLkGz3OafSF9eb7ZbQX8IvSzqnkIt fJ7g== X-Forwarded-Encrypted: i=1; AJvYcCWra1nsbHhjw0JpY6/L1ae/txhB7WQDkIh0nOKGVdM+AKh/UnZWac+WEzMCQzkOco6QajZ7+IV9HMQBIAXG97O8Jc/m X-Gm-Message-State: AOJu0YyR351vYPGZOByIWJeIv1MQldZUIgAiqInIVheFx2vCQgva5hlU J7t8oM05pYz4Fb6QGcDUBtzDnk/JNHJrg8x1dq+b8oeZlXgjuXZ1ipTRi+EO5CI= X-Google-Smtp-Source: AGHT+IGq5go7pjxVXZoiDIctGP4OrpbOzSdrxavQVhZcrfZhYA5v6u0JB+p8JidVC79uF/koqWAkCw== X-Received: by 2002:a17:906:ae8f:b0:a66:ebc8:ad2c with SMTP id a640c23a62f3a-a66ebd812e1mr100669966b.42.1717098171713; Thu, 30 May 2024 12:42:51 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a67e73faa76sm8314766b.75.2024.05.30.12.42.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 12:42:51 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id A25505F8D5; Thu, 30 May 2024 20:42:50 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Marcel Apfelbaum , Cameron Esfahani , Alexandre Iooss , Yanan Wang , Paolo Bonzini , Eduardo Habkost , Sunil Muthuswamy , Richard Henderson , Pierrick Bouvier , =?utf-8?q?Philippe_Mathieu-?= =?utf-8?q?Daud=C3=A9?= , Mahmoud Mandour , Reinoud Zandijk , =?utf-8?q?Alex_Benn=C3=A9e?= , kvm@vger.kernel.org, Roman Bolshakov Subject: [PATCH 1/5] hw/core: expand on the alignment of CPUState Date: Thu, 30 May 2024 20:42:46 +0100 Message-Id: <20240530194250.1801701-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240530194250.1801701-1-alex.bennee@linaro.org> References: <20240530194250.1801701-1-alex.bennee@linaro.org> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Make the relationship between CPUState, ArchCPU and cpu_env a bit clearer in the kdoc comments. Signed-off-by: Alex Bennée Reviewed-by: Pierrick Bouvier Reviewed-by: Philippe Mathieu-Daudé --- include/hw/core/cpu.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index bb398e8237..35d345371b 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -391,7 +391,8 @@ struct qemu_work_item; #define CPU_UNSET_NUMA_NODE_ID -1 /** - * CPUState: + * struct CPUState - common state of one CPU core or thread. + * * @cpu_index: CPU index (informative). * @cluster_index: Identifies which cluster this CPU is in. * For boards which don't define clusters or for "loose" CPUs not assigned @@ -439,10 +440,15 @@ struct qemu_work_item; * @kvm_fetch_index: Keeps the index that we last fetched from the per-vCPU * dirty ring structure. * - * State of one CPU core or thread. + * @neg_align: The CPUState is the common part of a concrete ArchCPU + * which is allocated when an individual CPU instance is created. As + * such care is taken is ensure there is no gap between between + * CPUState and CPUArchState within ArchCPU. * - * Align, in order to match possible alignment required by CPUArchState, - * and eliminate a hole between CPUState and CPUArchState within ArchCPU. + * @neg: The architectural register state ("cpu_env") immediately follows CPUState + * in ArchCPU and is passed to TCG code. The @neg structure holds some + * common TCG CPU variables which are accessed with a negative offset + * from cpu_env. */ struct CPUState { /*< private >*/ From patchwork Thu May 30 19:42:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 13680683 Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 20668158879 for ; Thu, 30 May 2024 19:42:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717098177; cv=none; b=Cok84fgntXHFUgLOZIT/t0vV0Zbek1QRFB1V9dMOe8qRM7D3WsSWob65p5GstySHHHDWlPUUFj4P6/GeWebcHum4q3aHCguiudh0WlLA31q3l59fy5NZLTHhWMQDQaNmPL0d3cWa9IfrJDvZmZMUXn4o7Sy4YBqxMBxSjaGO9Ao= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717098177; c=relaxed/simple; bh=eeFGxNeoZqvUNfJR35inCr7b5ssaRHsTERxVShcPYhQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=hTpvdJgkmFkVyWqUZ29McTTbyGFsKwsr14UEPERgd+CNxqhHb1lI+9PSOmZ2fb4ZnZbUcWavSJxNaehff45dmjlLHON7eKC0ZUodp5yIc56Q+TfoIM0m5XXGJuQoR0ssHTFjwWbVx3GUW+eYnfu4nLAHQcO62lLfkz4kFuq5sgo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=LRcbljoJ; arc=none smtp.client-ip=209.85.218.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="LRcbljoJ" Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-a5dcb5a0db4so133123066b.2 for ; Thu, 30 May 2024 12:42:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717098173; x=1717702973; darn=vger.kernel.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=Cnc+k2fYpUESVUzqiNhwI1EEtv65T/mceqpj8jrBceI=; b=LRcbljoJQJr1LV7B/H6P4GyitwQ5Q+hK6l8BJX2ZcJziTs20HmqghB8xJGdtVQAgph gthBZHAbCdRQLBDAV3vtIfpjQMHKELsa6X4ZZM4kNBampZRstn32LDbj37MHkfhd2vGU EuYSyEosqJV0Fbgkuh6LtPXPCESCMe0Sa+qlTDUORhG/mSmpill9BUk3RUOglOiNMLid SWSS/kEoJGWgY+ydEksHryCzzqzvkbSavPpHgn76cVBYddh6RlOvhlwR8hhV8TgcU87O AfFaFzZNENapAIglbBthduykYBCwo0NU2Zw2z7kRQyDBC0eOyYsKsWOz8OGZ50TNOoMp Ut7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717098173; x=1717702973; 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=Cnc+k2fYpUESVUzqiNhwI1EEtv65T/mceqpj8jrBceI=; b=uUJo5bjze0Z3ZYclJlUO01YHZ+NeBeLqfk8XRKVrIrs6f+NHk8zRcPcwP3WfcKiy9h CKJTZixxxLH+GF4yHHZ0n6JZJDwh9AJPGqHinBMJclLG2eDkxk+Wc4Jwt4S25+9UF19C i/pdnNHGSFa0zPcDr559IJcZvmeNxe5nPcOC1e5ngKf+hsF9VZkHmnqloJbxsoLiBLap Mvz9+iqXWVne3NBlwBceWbXEZMHT6I/vn4isaF21ZJ7/jdgM6srP3mK5vxJLyyNvqURu K24QJGP6Yy14SBWH+nIEzENxuMyLsRVDgF+N3zEBLN0cg/+wK4wEemNUBoDVnWTmwAeC 5XCg== X-Forwarded-Encrypted: i=1; AJvYcCWvsfwXSaEjpJds3TUn0WWRSo5ZzqoVO3mu1dvYOFD4c3Z+pe81Pi89F/6pt1jXmJZjtABvSsZ7lFUJCksVaYJHRG6p X-Gm-Message-State: AOJu0Ywn2NoMXPWUxpWIy1n1+ZD4Ys2+yH0fh9sljKVJGXGuxD/WCPoi 1yivIleiMczQ/gG+eOHsEFW7oT24U9Rpbv3QaHk2xjdnCQq+ZrYR6B8cNEWivxY= X-Google-Smtp-Source: AGHT+IFVOq8MKMEfrXxp4J5Y6CJd2GA9ZM++5hdN2jPC99fsqqvcLrmD9aX73RbTWxQdJn18BZeDlg== X-Received: by 2002:a17:906:d1c9:b0:a67:aa2b:1032 with SMTP id a640c23a62f3a-a67aa2b10f1mr32855366b.28.1717098173261; Thu, 30 May 2024 12:42:53 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a67ea67b4f8sm7831766b.102.2024.05.30.12.42.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 12:42:51 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id C35165F8E3; Thu, 30 May 2024 20:42:50 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Marcel Apfelbaum , Cameron Esfahani , Alexandre Iooss , Yanan Wang , Paolo Bonzini , Eduardo Habkost , Sunil Muthuswamy , Richard Henderson , Pierrick Bouvier , =?utf-8?q?Philippe_Mathieu-?= =?utf-8?q?Daud=C3=A9?= , Mahmoud Mandour , Reinoud Zandijk , =?utf-8?q?Alex_Benn=C3=A9e?= , kvm@vger.kernel.org, Roman Bolshakov Subject: [PATCH 2/5] cpu: move Qemu[Thread|Cond] setup into common code Date: Thu, 30 May 2024 20:42:47 +0100 Message-Id: <20240530194250.1801701-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240530194250.1801701-1-alex.bennee@linaro.org> References: <20240530194250.1801701-1-alex.bennee@linaro.org> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Aside from the round robin threads this is all common code. By moving the halt_cond setup we also no longer need hacks to work around the race between QOM object creation and thread creation. It is a little ugly to free stuff up for the round robin thread but better it deal with its own specialises than making the other accelerators jump through hoops. Signed-off-by: Alex Bennée Reviewed-by: Pierrick Bouvier Reviewed-by: Philippe Mathieu-Daudé --- include/hw/core/cpu.h | 4 ++++ accel/dummy-cpus.c | 3 --- accel/hvf/hvf-accel-ops.c | 4 ---- accel/kvm/kvm-accel-ops.c | 3 --- accel/tcg/tcg-accel-ops-mttcg.c | 4 ---- accel/tcg/tcg-accel-ops-rr.c | 14 +++++++------- hw/core/cpu-common.c | 5 +++++ target/i386/nvmm/nvmm-accel-ops.c | 3 --- target/i386/whpx/whpx-accel-ops.c | 3 --- 9 files changed, 16 insertions(+), 27 deletions(-) diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 35d345371b..a405119eda 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -404,10 +404,14 @@ struct qemu_work_item; * @tcg_cflags: Pre-computed cflags for this cpu. * @nr_cores: Number of cores within this CPU package. * @nr_threads: Number of threads within this CPU core. + * @thread: Host thread details, only live once @created is #true + * @sem: WIN32 only semaphore used only for qtest + * @thread_id: native thread id of vCPU, only live once @created is #true * @running: #true if CPU is currently running (lockless). * @has_waiter: #true if a CPU is currently waiting for the cpu_exec_end; * valid under cpu_list_lock. * @created: Indicates whether the CPU thread has been successfully created. + * @halt_cond: condition variable sleeping threads can wait on. * @interrupt_request: Indicates a pending interrupt request. * @halted: Nonzero if the CPU is in suspended state. * @stop: Indicates a pending stop request. diff --git a/accel/dummy-cpus.c b/accel/dummy-cpus.c index 20519f1ea4..f32d8c8dc3 100644 --- a/accel/dummy-cpus.c +++ b/accel/dummy-cpus.c @@ -68,9 +68,6 @@ void dummy_start_vcpu_thread(CPUState *cpu) { char thread_name[VCPU_THREAD_NAME_SIZE]; - cpu->thread = g_malloc0(sizeof(QemuThread)); - cpu->halt_cond = g_malloc0(sizeof(QemuCond)); - qemu_cond_init(cpu->halt_cond); snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/DUMMY", cpu->cpu_index); qemu_thread_create(cpu->thread, thread_name, dummy_cpu_thread_fn, cpu, diff --git a/accel/hvf/hvf-accel-ops.c b/accel/hvf/hvf-accel-ops.c index 40d4187d9d..6f1e27ef46 100644 --- a/accel/hvf/hvf-accel-ops.c +++ b/accel/hvf/hvf-accel-ops.c @@ -463,10 +463,6 @@ static void hvf_start_vcpu_thread(CPUState *cpu) */ assert(hvf_enabled()); - cpu->thread = g_malloc0(sizeof(QemuThread)); - cpu->halt_cond = g_malloc0(sizeof(QemuCond)); - qemu_cond_init(cpu->halt_cond); - snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/HVF", cpu->cpu_index); qemu_thread_create(cpu->thread, thread_name, hvf_cpu_thread_fn, diff --git a/accel/kvm/kvm-accel-ops.c b/accel/kvm/kvm-accel-ops.c index 94c828ac8d..c239dfc87a 100644 --- a/accel/kvm/kvm-accel-ops.c +++ b/accel/kvm/kvm-accel-ops.c @@ -66,9 +66,6 @@ static void kvm_start_vcpu_thread(CPUState *cpu) { char thread_name[VCPU_THREAD_NAME_SIZE]; - cpu->thread = g_malloc0(sizeof(QemuThread)); - cpu->halt_cond = g_malloc0(sizeof(QemuCond)); - qemu_cond_init(cpu->halt_cond); snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/KVM", cpu->cpu_index); qemu_thread_create(cpu->thread, thread_name, kvm_vcpu_thread_fn, diff --git a/accel/tcg/tcg-accel-ops-mttcg.c b/accel/tcg/tcg-accel-ops-mttcg.c index c552b45b8e..49814ec4af 100644 --- a/accel/tcg/tcg-accel-ops-mttcg.c +++ b/accel/tcg/tcg-accel-ops-mttcg.c @@ -137,10 +137,6 @@ void mttcg_start_vcpu_thread(CPUState *cpu) g_assert(tcg_enabled()); tcg_cpu_init_cflags(cpu, current_machine->smp.max_cpus > 1); - cpu->thread = g_new0(QemuThread, 1); - cpu->halt_cond = g_malloc0(sizeof(QemuCond)); - qemu_cond_init(cpu->halt_cond); - /* create a thread per vCPU with TCG (MTTCG) */ snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/TCG", cpu->cpu_index); diff --git a/accel/tcg/tcg-accel-ops-rr.c b/accel/tcg/tcg-accel-ops-rr.c index 894e73e52c..84c36c1450 100644 --- a/accel/tcg/tcg-accel-ops-rr.c +++ b/accel/tcg/tcg-accel-ops-rr.c @@ -317,22 +317,22 @@ void rr_start_vcpu_thread(CPUState *cpu) tcg_cpu_init_cflags(cpu, false); if (!single_tcg_cpu_thread) { - cpu->thread = g_new0(QemuThread, 1); - cpu->halt_cond = g_new0(QemuCond, 1); - qemu_cond_init(cpu->halt_cond); + single_tcg_halt_cond = cpu->halt_cond; + single_tcg_cpu_thread = cpu->thread; /* share a single thread for all cpus with TCG */ snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "ALL CPUs/TCG"); qemu_thread_create(cpu->thread, thread_name, rr_cpu_thread_fn, cpu, QEMU_THREAD_JOINABLE); - - single_tcg_halt_cond = cpu->halt_cond; - single_tcg_cpu_thread = cpu->thread; } else { - /* we share the thread */ + /* we share the thread, dump spare data */ + g_free(cpu->thread); + qemu_cond_destroy(cpu->halt_cond); cpu->thread = single_tcg_cpu_thread; cpu->halt_cond = single_tcg_halt_cond; + + /* copy the stuff done at start of rr_cpu_thread_fn */ cpu->thread_id = first_cpu->thread_id; cpu->neg.can_do_io = 1; cpu->created = true; diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c index 0f0a247f56..6cfc01593a 100644 --- a/hw/core/cpu-common.c +++ b/hw/core/cpu-common.c @@ -261,6 +261,11 @@ static void cpu_common_initfn(Object *obj) cpu->nr_threads = 1; cpu->cflags_next_tb = -1; + /* allocate storage for thread info, initialise condition variables */ + cpu->thread = g_new0(QemuThread, 1); + cpu->halt_cond = g_new0(QemuCond, 1); + qemu_cond_init(cpu->halt_cond); + qemu_mutex_init(&cpu->work_mutex); qemu_lockcnt_init(&cpu->in_ioctl_lock); QSIMPLEQ_INIT(&cpu->work_list); diff --git a/target/i386/nvmm/nvmm-accel-ops.c b/target/i386/nvmm/nvmm-accel-ops.c index 6b2bfd9b9c..0ba31201e2 100644 --- a/target/i386/nvmm/nvmm-accel-ops.c +++ b/target/i386/nvmm/nvmm-accel-ops.c @@ -64,9 +64,6 @@ static void nvmm_start_vcpu_thread(CPUState *cpu) { char thread_name[VCPU_THREAD_NAME_SIZE]; - cpu->thread = g_new0(QemuThread, 1); - cpu->halt_cond = g_new0(QemuCond, 1); - qemu_cond_init(cpu->halt_cond); snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/NVMM", cpu->cpu_index); qemu_thread_create(cpu->thread, thread_name, qemu_nvmm_cpu_thread_fn, diff --git a/target/i386/whpx/whpx-accel-ops.c b/target/i386/whpx/whpx-accel-ops.c index 189ae0f140..1a2b4e1c43 100644 --- a/target/i386/whpx/whpx-accel-ops.c +++ b/target/i386/whpx/whpx-accel-ops.c @@ -64,9 +64,6 @@ static void whpx_start_vcpu_thread(CPUState *cpu) { char thread_name[VCPU_THREAD_NAME_SIZE]; - cpu->thread = g_new0(QemuThread, 1); - cpu->halt_cond = g_new0(QemuCond, 1); - qemu_cond_init(cpu->halt_cond); snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/WHPX", cpu->cpu_index); qemu_thread_create(cpu->thread, thread_name, whpx_cpu_thread_fn, From patchwork Thu May 30 19:42:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 13680682 Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BC56915886D for ; Thu, 30 May 2024 19:42:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717098175; cv=none; b=fGJbiw1Yrfos4JkHBnQ2jYsc73A5tE83nFnifD493vKkF+Zfrqa8nadF/HbqQ6xNdmHJsoKLVOOH9Sr8FD5Mg5JVoccc5LMTFt+2y+NiGB0ANwQ3Xwf8MXDBrSl6CNGpzFj4pWoTU70e6ho+2Ki376U6SpetyDODHWE3VkYCcb8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717098175; c=relaxed/simple; bh=VkISwJLqth9HLrk9NR2gJcdXr2r2sl4bt0R/UyCnlZk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=jwl1IdqF6tinJZrUWsgPoimF905TSh9aL9fpl6bXG3IBJZAwvw+xgzFXnukrjibq8F0zDhc4oqRXDF68tRrtJuXNurE7idZ+7wgiLNxUVr2LgJHWzzMHAfx1wFRnBViAlEnKXe2LURXPG6UwDaKx9uU73NjKAOdwgEEqYroRW7U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=yl+hN+o3; arc=none smtp.client-ip=209.85.218.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="yl+hN+o3" Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-a635a74e031so157621366b.0 for ; Thu, 30 May 2024 12:42:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717098172; x=1717702972; darn=vger.kernel.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=32yQbNKYA/0QpYwGyLEbfW3tqRcvc30vIF3lo+QmN14=; b=yl+hN+o3DVE5VXjkkD7gCbWHOmunz+nWVAw6neVBOwj8Je7V0MvqYoYmYP6Adf+HyD woQuDSy9ZerFkR4BrH9YSQMYsfQn8JZdN2OsJWpygavcmX4WL38ZaOyXNtGC+nGNkSN7 pp5YyBQeXQ/z4eGT7TV7durV6bQ0y7ZmX9mhYqMBrS6j30KD+91pwNx8Kab/59qffLJf uktnecI9x39n7RG+TXPg29wMRtFDxUHcNdLT134d0PI8lqITrDpG+O97mprt8/yAMsBm e0+L1pfpAulFp00AjWlBt4gmoMnO++ffUUTL16oLbVdJSFLSHhLdD62YsPeUYrPBWydM 5joA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717098172; x=1717702972; 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=32yQbNKYA/0QpYwGyLEbfW3tqRcvc30vIF3lo+QmN14=; b=exuKyHrjHI/phx0ImA/geRcfF0bIC7DWqK4ISwZFapYr6myuta0vEjMqkmcgno3JqG MhhT/ZRrJuDZxCYIqvPK2rgHctg7YsNZ0FNODmBZ3b6oxHmgSiEJmB99Fj+1KUBd/fO9 y52IRJWH/5ij5yzqzBFXi1Er2pDo4HComLvJJu7luQSJfOkmzCw0tsZnkp7Q6A6R/DH7 FK9kjLCzJdUlU30Hh7rd3zsl25s7vrHPUy6ZMubyf4yr0R3TDhr/tjyamVxQDrlj320p 9I38aAaDWLJIzUaU7q76nmBu6wko2R0TnxUh8mncDxT3xCv0Z+ziCvw1aRnZxzAhprmg kfVA== X-Forwarded-Encrypted: i=1; AJvYcCW8/f+WVpKNpBqNGWq6YhbfaPQ7OA+vxwytARx4rTcsd8SJbjxHPYfuizFxEHgNryuTE7EyX6EX4Y57G6xvLmlojfaR X-Gm-Message-State: AOJu0YxpJ+OKJ7OvPr1EWK9nOqm+v8QjGp/3ozSJLbAI/y0K0TcpAfhu y4aHn4SM1I/q+HfaYczEc+Vrcc57q8xpCd5ahxnIhiHbq04ItRFVUVOCHBIZvjE= X-Google-Smtp-Source: AGHT+IFTafnXNuDoHGvLjw9aFZh+7U9j0vtTJAyWKnYBLNX81Afkye3DJvtDOKRgz1AGcECBR87nFQ== X-Received: by 2002:a17:906:f2d9:b0:a61:42ce:bbe4 with SMTP id a640c23a62f3a-a65e8e507f0mr301550166b.27.1717098171970; Thu, 30 May 2024 12:42:51 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a67eb34204dsm7560266b.191.2024.05.30.12.42.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 12:42:51 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id DA9075F8E5; Thu, 30 May 2024 20:42:50 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Marcel Apfelbaum , Cameron Esfahani , Alexandre Iooss , Yanan Wang , Paolo Bonzini , Eduardo Habkost , Sunil Muthuswamy , Richard Henderson , Pierrick Bouvier , =?utf-8?q?Philippe_Mathieu-?= =?utf-8?q?Daud=C3=A9?= , Mahmoud Mandour , Reinoud Zandijk , =?utf-8?q?Alex_Benn=C3=A9e?= , kvm@vger.kernel.org, Roman Bolshakov Subject: [PATCH 3/5] cpu-target: don't set cpu->thread_id to bogus value Date: Thu, 30 May 2024 20:42:48 +0100 Message-Id: <20240530194250.1801701-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240530194250.1801701-1-alex.bennee@linaro.org> References: <20240530194250.1801701-1-alex.bennee@linaro.org> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The thread_id isn't valid until the threads are created. There is no point setting it here. The only thing that cares about the thread_id is qmp_query_cpus_fast. Signed-off-by: Alex Bennée Reviewed-by: Pierrick Bouvier Reviewed-by: Philippe Mathieu-Daudé --- cpu-target.c | 1 - 1 file changed, 1 deletion(-) diff --git a/cpu-target.c b/cpu-target.c index 5af120e8aa..499facf774 100644 --- a/cpu-target.c +++ b/cpu-target.c @@ -241,7 +241,6 @@ void cpu_exec_initfn(CPUState *cpu) cpu->num_ases = 0; #ifndef CONFIG_USER_ONLY - cpu->thread_id = qemu_get_thread_id(); cpu->memory = get_system_memory(); object_ref(OBJECT(cpu->memory)); #endif From patchwork Thu May 30 19:42:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 13680684 Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6574E15887E for ; Thu, 30 May 2024 19:42:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717098177; cv=none; b=oPp9ZZkkehRWT2zoLnFqbY7C0YjjVSnIvUOwW7JEpgydDH6guUrDOxJojtAM/mqFvNxlq/IOEGiSSROGHH/nsiOXvXZ0GjuakbLOaWAsk9/TPB/8Xtlc7fH8LC9+NT8iCQwSar1Lv2bHZBn5z/u+Kk0BcIwNtMMjL+pWZBSx4Rk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717098177; c=relaxed/simple; bh=Dp9dyvN5Am2cxB/Xcgwh41bu6FnUWnTj5WMWUdHg0WY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=WVNqsUQ9vCMKtlcoFtK6liDLMNh6f6y9479eR1WTSoAiMovdnIhjo1672PLMkHOQ1Zt7U0XT4h0omw1e/dvAl+fvR8ubdPD2Cxjmyq7TAitpcSqWmTpqjZeZqtnQGfLQr+M2ZX5RHzacHx+viUoMwq/NANpkWXktUH8zccPBWgY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=EJrQkhai; arc=none smtp.client-ip=209.85.218.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="EJrQkhai" Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-a62972c88a9so138269066b.1 for ; Thu, 30 May 2024 12:42:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717098174; x=1717702974; darn=vger.kernel.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=uSiuGXiCgmtxSxVezOHytC/a0n/fTNdw2YFzo1KJ2YY=; b=EJrQkhai4XLCqo6wY/7KA0XMYhaE5ja/k40tcapwGgIoJ9LS88LRwgjif9OILKMAPA YsmlWH6s9bqej3vivJuAeeWmL/ErFbEdEVAt7NLncTkwO3IRIRCs6ZNAiY8e6cICS3JG VmJHhDXJh316IKjFLydaGojwChIfpXAkAVva/TYo7z8yY4bCxAT4ypPVZYbxjyK4xZJh ekZtJhFDnWpwDblmBA+ftjigCfIir1Z7w0jEO4bgwDnGMdSfzHu1xgU/oYOv7hao5Gv2 8nrOlHBIcn35LeC2J0fCsLg7tYqsoEYMMgE/hxqUGGiyPnJ90ipWrrAVNWVjKIAvxJY+ IlGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717098174; x=1717702974; 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=uSiuGXiCgmtxSxVezOHytC/a0n/fTNdw2YFzo1KJ2YY=; b=LU/yG2B2AfAFwGPtIdA+U/vPuLWeAmeqs8ktYwBNSFIM7pR359tjo2IcltZEHufVgW pomRwZfl/gQ+wBDI4rzAlIuG2+bizBTKf7Ek7ypXLaQ6wSqmQzLvFNVnuaFlQUA/vMGw inQWnOCzr+28elaZS5G9v6vX4VD04tXsdDQ+Ht23aF6a7Z2Sf9w0di/cURP3VxFDzUCV 2jyCpyLpqTTlXzNTjaGKJzwHqluIj4uv/fRW8aA6F1gx/olsFzcUSWEzorR83kE3Cx7F V3xrwJXV5qtjNT1jhLbxnXuQWwxJzoyy6mrzvcGL6dyCKCZuYJa8k7WLiVikgo86TdYz guQA== X-Forwarded-Encrypted: i=1; AJvYcCU5zlAaK22ggECD6uHZDC5MHNsgxaBEQv1tOszvGmdUjYkFpOZfg8A+WGXU2yAKMZsqMZBDCTMVybC1FMnY21iVgS8/ X-Gm-Message-State: AOJu0Yzq0QtlkAKTE435KLCrz2Rx1ZY+coJURAyu+JL7rZl2M+O0FwqN KBerBb9rL/xzGXUUTMk9mTuGYlKdAR20w/rr+ck3idMRiIgIOW5yZc28hbredGY= X-Google-Smtp-Source: AGHT+IGCaRuVtIWhRyQ8FoN38Rt6/VkrlKQU/oJb9EQPlJPnpazA4r4xUC8i+X5fKyvCMARa5tUTRQ== X-Received: by 2002:a17:907:1dd3:b0:a59:ad15:6142 with SMTP id a640c23a62f3a-a65e92304eemr189379466b.77.1717098173472; Thu, 30 May 2024 12:42:53 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a67eab85f32sm7774166b.180.2024.05.30.12.42.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 12:42:51 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id F38205F8E7; Thu, 30 May 2024 20:42:50 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Marcel Apfelbaum , Cameron Esfahani , Alexandre Iooss , Yanan Wang , Paolo Bonzini , Eduardo Habkost , Sunil Muthuswamy , Richard Henderson , Pierrick Bouvier , =?utf-8?q?Philippe_Mathieu-?= =?utf-8?q?Daud=C3=A9?= , Mahmoud Mandour , Reinoud Zandijk , =?utf-8?q?Alex_Benn=C3=A9e?= , kvm@vger.kernel.org, Roman Bolshakov Subject: [PATCH 4/5] plugins: remove special casing for cpu->realized Date: Thu, 30 May 2024 20:42:49 +0100 Message-Id: <20240530194250.1801701-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240530194250.1801701-1-alex.bennee@linaro.org> References: <20240530194250.1801701-1-alex.bennee@linaro.org> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Now the condition variable is initialised early on we don't need to go through hoops to avoid calling async_run_on_cpu. Signed-off-by: Alex Bennée Reviewed-by: Pierrick Bouvier Reviewed-by: Philippe Mathieu-Daudé --- plugins/core.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/plugins/core.c b/plugins/core.c index 0726bc7f25..badede28cf 100644 --- a/plugins/core.c +++ b/plugins/core.c @@ -65,11 +65,7 @@ static void plugin_cpu_update__locked(gpointer k, gpointer v, gpointer udata) CPUState *cpu = container_of(k, CPUState, cpu_index); run_on_cpu_data mask = RUN_ON_CPU_HOST_ULONG(*plugin.mask); - if (DEVICE(cpu)->realized) { - async_run_on_cpu(cpu, plugin_cpu_update__async, mask); - } else { - plugin_cpu_update__async(cpu, mask); - } + async_run_on_cpu(cpu, plugin_cpu_update__async, mask); } void plugin_unregister_cb__locked(struct qemu_plugin_ctx *ctx, From patchwork Thu May 30 19:42:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 13680685 Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8600C158A02 for ; Thu, 30 May 2024 19:42:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717098177; cv=none; b=JeaPRQ0b2LZEIBzqDHWOkmVTXRtgZfOWa4zH13O5k8Fbm36DDtdI2LOlUstqo7n6ReESComK9CrX6YpI4/045NtgEC19kxrAAv/ll0g2+3n9CoScf9j6vB/A4fQvGPFMDfZcxaQW2lSiz+DoKCZ5bA9i5alSd+7aGQpnVONiQCQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717098177; c=relaxed/simple; bh=rqiSfplPG/xQ9bjs7bp/4NUu5oKzzW9W+LMymGb3Kr4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=UbbSec8aqmGEB/82wSnNFcXrmpFLkm4VWdoxKHPrJgWiV3+2g9cYD7yNqrmdPtQsalifmLhQHESucU/SnrGa0dr2bmVZUGq0a3e2b/4FQPK1Cj/u7dZTpskHrEfH7OrN7MqCj78UtCeb5Ph0FbQhlDmJulfmsWLJJI2lAutwQVY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=Kig9uaye; arc=none smtp.client-ip=209.85.218.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Kig9uaye" Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-a62614b9ae1so155641166b.0 for ; Thu, 30 May 2024 12:42:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717098174; x=1717702974; darn=vger.kernel.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=fPCSTF6BhpGl/BOGWj8t6sMDRxBkBVgL05/HycPv784=; b=Kig9uayer52t6w/D4B1HOj8JSs0Dxpzm2BG8krTzSX0aZuvNBZ/tptS7EgKs5HVZnB rqqJsccZ+w8x7uA966BbdvB1IRBgDAKnf7pMwapz6oLPPrLGQSuPw4UX+sSL/kMOh52k Of9sQXuc/Uy6cjTziPlGtEDUkwpAjHtNmAPOkpAApwUcvKH5VlCE1ychPVWsRlhGBRLR LDwDkXqjiIGeIkdv50QyzQkq1XzKvZnM5fXwwtFlOWJ0QOCxHJEul9Mq3j3ZIuKow3Jz FME6uyfjHRKm+p+1WShzWy2MGIDQ6KGfoaEM3SYde+rtxtY2vs0T65+wv4FhCX7lbsXZ DGIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717098174; x=1717702974; 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=fPCSTF6BhpGl/BOGWj8t6sMDRxBkBVgL05/HycPv784=; b=R8+iC0oVjDnw2IhZnSsrLPMkVR7jvA76sa3tLaUiNc4huRzRi4yfmr8tYA7Q0R2oD3 PcWUhpeIY4sMfaYSVFsyMTsrqcShcLnJcG6HtJfoWQR7bk6uhoHHR8ow3eROJMpRZ2KL Rjo5cgtNlA+BEX9lUgH/pgL4QcM6eiF1GH40J0HabqVaUjcTEVxvvlhJyaEU1qT9EYkH gk6ekfAY39u48Fy3HtMRczhGaIpJgAPikgYxkx0pZgjn0YG4IHs1u78o1QqCyrpNYuJO mVq9mG1rEq1nRTB9Jzx3XR4EME/At8S0LAqWn6ik1+uZKtCV9Sj8YBupdh0EK8EvodWy qi4A== X-Forwarded-Encrypted: i=1; AJvYcCWo3O8cm7VkTI0zyDrZaAotQsbYcB4InRs2u2d9IBKt9oV/8u8apWqAsCo3M75GYk/tGH5Q+YeqaolwXpVSoU1qDIdP X-Gm-Message-State: AOJu0YzDJ/buspmw18DTwqA0Zo/X/QBzryta/s+B5TRInkoUPfnSEL5N pYorQGLFfPZ6x9Z1rmiWcv83Z+jsds9FGLuwE8kn3bdnuQSPchoEEnUn8Tg9FMA= X-Google-Smtp-Source: AGHT+IE6R76QAmiPveib3Be1Nxuw357LnoAEk7dKHLZ8AdvRVSDfuYn+KOWdz8CdSrBFOQdmXMpLAA== X-Received: by 2002:a17:906:7714:b0:a67:da88:149a with SMTP id a640c23a62f3a-a67da881f76mr21672966b.55.1717098173884; Thu, 30 May 2024 12:42:53 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a67eab85c8fsm7754766b.183.2024.05.30.12.42.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 12:42:53 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 16D015F8E9; Thu, 30 May 2024 20:42:51 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Marcel Apfelbaum , Cameron Esfahani , Alexandre Iooss , Yanan Wang , Paolo Bonzini , Eduardo Habkost , Sunil Muthuswamy , Richard Henderson , Pierrick Bouvier , =?utf-8?q?Philippe_Mathieu-?= =?utf-8?q?Daud=C3=A9?= , Mahmoud Mandour , Reinoud Zandijk , =?utf-8?q?Alex_Benn=C3=A9e?= , kvm@vger.kernel.org, Roman Bolshakov Subject: [PATCH 5/5] core/cpu-common: initialise plugin state before thread creation Date: Thu, 30 May 2024 20:42:50 +0100 Message-Id: <20240530194250.1801701-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240530194250.1801701-1-alex.bennee@linaro.org> References: <20240530194250.1801701-1-alex.bennee@linaro.org> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Originally I tried to move where vCPU thread initialisation to later in realize. However pulling that thread (sic) got gnarly really quickly. It turns out some steps of CPU realization need values that can only be determined from the running vCPU thread. However having moved enough out of the thread creation we can now queue work before the thread starts (at least for TCG guests) and avoid the race between vcpu_init and other vcpu states a plugin might subscribe to. Signed-off-by: Alex Bennée Reviewed-by: Pierrick Bouvier Reviewed-by: Philippe Mathieu-Daudé --- hw/core/cpu-common.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c index 6cfc01593a..bf1a7b8892 100644 --- a/hw/core/cpu-common.c +++ b/hw/core/cpu-common.c @@ -222,14 +222,6 @@ static void cpu_common_realizefn(DeviceState *dev, Error **errp) cpu_resume(cpu); } - /* Plugin initialization must wait until the cpu start executing code */ -#ifdef CONFIG_PLUGIN - if (tcg_enabled()) { - cpu->plugin_state = qemu_plugin_create_vcpu_state(); - async_run_on_cpu(cpu, qemu_plugin_vcpu_init__async, RUN_ON_CPU_NULL); - } -#endif - /* NOTE: latest generic point where the cpu is fully realized */ } @@ -273,6 +265,18 @@ static void cpu_common_initfn(Object *obj) QTAILQ_INIT(&cpu->watchpoints); cpu_exec_initfn(cpu); + + /* + * Plugin initialization must wait until the cpu start executing + * code, but we must queue this work before the threads are + * created to ensure we don't race. + */ +#ifdef CONFIG_PLUGIN + if (tcg_enabled()) { + cpu->plugin_state = qemu_plugin_create_vcpu_state(); + async_run_on_cpu(cpu, qemu_plugin_vcpu_init__async, RUN_ON_CPU_NULL); + } +#endif } static void cpu_common_finalize(Object *obj)