From patchwork Mon Jan 6 20:02:52 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: 13927808 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (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 BAC941DFD84 for ; Mon, 6 Jan 2025 20:03:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736193792; cv=none; b=hNBM947nsxMaP1dAKg9HZsK00sEJjgTLqL3LDzcWHuk4lKBDeroXLaRm5RJdhg8C8Wgf42PPCbaIYs4sECcyx2fdFHlnp3NGw2NxaWtnFsY1vmbJHH1PsIx02EBdCqO2VyFy8rjEy0CBlRZpi6jUjFian5VggqSPmyYFVC4Gl8E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736193792; c=relaxed/simple; bh=Ak+0noH2olxVQpIo1L31xnnodJjTrz0gw+USwBojjz4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bJ3fG5zpbfGD7MPTt97CdqMaWvH5Aq28iodNNyW3gNeZ6L8eKmTpMYdRq/PLBNXRs6k8wkrTQRZH0KMFWqvv8E7iPRldGKLxD9w/2FSVSWuXUgcE3K3MzsUptY1i4lKq/J3taVTknlYHfi9mOD02AgKUs/zyBd58R0krlhQY2cw= 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=FtFTpxiB; arc=none smtp.client-ip=209.85.221.41 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="FtFTpxiB" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-3863703258fso9209144f8f.1 for ; Mon, 06 Jan 2025 12:03:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736193789; x=1736798589; 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=Gw/8miEe/PnaBFePSWTnOg3qI2ZvVUjrjdrVrAxgzBI=; b=FtFTpxiBe1AcYGJZmJxROmdzoEyI8qgZ+h3laLGOWvbT98PebI4PHNOPlwxpbqWdbM 0mMHYS/fDRa2VNqac0BcOwSoS5KHCa80E4Y57h8zqyTQR4xSJzEWzPonzZezdb36A978 cuiiGc2zRUwzKdIQJdId/UQH+DZ+gf6ORP+mZzVaCx6NchyihzaFAeyJ4hh1oF8ijqpn UQjjClSfyFrK4Gq641sLLbLjoHpg1J/meNLJWniBw2pMagaFKJSN+m/sdn0BC59v3ki+ eBq/R61xJgKcDbnLbWpBCRLDGOrbD4NZdwmF3kEokx1KgJZBJjjxFGi3bzCzZkEbc+jX A3Xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736193789; x=1736798589; 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=Gw/8miEe/PnaBFePSWTnOg3qI2ZvVUjrjdrVrAxgzBI=; b=Y0j99e31skD3xG3Xn9s7SzUUYEFIK72CVG5+Ro93/k3q0k4WeTfSPP15ETutPr+tyk eD7ItNnYKhvqfZidI/HUQGvGn2CIw7L2st3f27eBA7ZejJSWjCI5CZ/P++MgeRvhtjyr QX5EClvBd/xZaffJAOm4jBWf/4iWq3pllRGh6XLyQLfklRuKD94WfU/kgOOXxVh4KYJ5 wL+8rxf79wMqJ6wdDJy3WF79zC+/EAzaieitcBoJllmkpnw3MSLAkDwBb+9kwMuLAMV9 F0/ZgFg+SgtLfc8ha6D4HtzxS2RxNjStBACKKFfawb97YXiRMfk7xk0RxQl1qBSy4fPz +Ypg== X-Forwarded-Encrypted: i=1; AJvYcCXyLBBXB0cOuOB5lyvh+DfjKRdhH1akgPZdk1tg26IudkMkp+WILy5Z4bhd5e9c4+uXbRY=@vger.kernel.org X-Gm-Message-State: AOJu0YzQznLR8qqvrFO+Kyv/FoJfuUl4rMDq85DCfDq//HObG0fwdg/Y 963wt5s0QCs5Wk1I82mq5wogDZ43TVa29Oi8LLI76dcUW+yYNDo/wNhqg+McWX8= X-Gm-Gg: ASbGnctPsGqwEJrNISIpDS/qlMtGEGTwtXGzGIvn0ictZuFx0qHuC739ViRxX/94mxB r30LzSDJLp/RnoIi2Ov/fcZJ7+xmEP9QN1hTw9ozoyl7Vd6IsJUQQ3iw7NGYu5K955ePvMlind2 rUEiMXm9j96sH3XRPomxtg0pIt/IXRFuckkeu/zOSg3SsRLj841aYo5GjMM7KzyxLmD8eobn9KA o44BEN8Ir7ZSJTcijma97zHTxlwj3iiAGMLdrF7s8G9YlaBM/h7xP/NnrNLzoNxgIaq+25zUA6G 80jII4A74mLYq7RHNbzgDtyNoD/TKFA= X-Google-Smtp-Source: AGHT+IE81N1RplBD8FCsdoj95sqyVSqitqWpe38bLlQuumoNL1lLDdZMOpwBwgd43Npz//MFxfo/tw== X-Received: by 2002:a5d:64ac:0:b0:38a:4df5:a08 with SMTP id ffacd0b85a97d-38a7923b959mr440924f8f.22.1736193788891; Mon, 06 Jan 2025 12:03:08 -0800 (PST) Received: from localhost.localdomain (88-187-86-199.subs.proxad.net. [88.187.86.199]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43665cd9c29sm559552815e9.14.2025.01.06.12.03.07 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 06 Jan 2025 12:03:08 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Daniel Henrique Barboza , =?utf-8?b?RnLDqWQ=?= =?utf-8?b?w6lyaWMgQmFycmF0?= , Stefano Stabellini , Ilya Leoshkevich , Cameron Esfahani , Paolo Bonzini , kvm@vger.kernel.org, Alexander Graf , Paul Durrant , David Hildenbrand , Halil Pasic , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Marcel Apfelbaum , xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, =?utf-8?q?C=C3=A9dric_?= =?utf-8?q?Le_Goater?= , Yanan Wang , Reinoud Zandijk , Peter Maydell , qemu-s390x@nongnu.org, Riku Voipio , Anthony PERARD , Alistair Francis , Sunil Muthuswamy , Christian Borntraeger , Nicholas Piggin , Richard Henderson , Marcelo Tosatti , Thomas Huth , Roman Bolshakov , "Edgar E . Iglesias" , Zhao Liu , Phil Dennis-Jordan , David Woodhouse , Harsh Prateek Bora , Nina Schoetterl-Glausch , "Edgar E. Iglesias" , Eduardo Habkost , qemu-ppc@nongnu.org, Daniel Henrique Barboza , "Michael S. Tsirkin" , Anton Johansson Subject: [RFC PATCH 1/7] cpus: Restrict CPU_FOREACH_SAFE() to user emulation Date: Mon, 6 Jan 2025 21:02:52 +0100 Message-ID: <20250106200258.37008-2-philmd@linaro.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250106200258.37008-1-philmd@linaro.org> References: <20250106200258.37008-1-philmd@linaro.org> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Daniel Henrique Barboza --- include/hw/core/cpu.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index c3ca0babcb3..48d90f50a71 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -594,8 +594,11 @@ extern CPUTailQ cpus_queue; #define first_cpu QTAILQ_FIRST_RCU(&cpus_queue) #define CPU_NEXT(cpu) QTAILQ_NEXT_RCU(cpu, node) #define CPU_FOREACH(cpu) QTAILQ_FOREACH_RCU(cpu, &cpus_queue, node) + +#if defined(CONFIG_USER_ONLY) #define CPU_FOREACH_SAFE(cpu, next_cpu) \ QTAILQ_FOREACH_SAFE_RCU(cpu, &cpus_queue, node, next_cpu) +#endif extern __thread CPUState *current_cpu; From patchwork Mon Jan 6 20:02: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: 13927809 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (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 788411DED44 for ; Mon, 6 Jan 2025 20:03:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736193800; cv=none; b=txwyjvqiGWRM2CYN8eZZsixjNhdmZLASYrFjcW4TzseoCKmqYsUx42ph59ESp7viu6KTdIqTEN/vkymZZjoR4n1DVwi/TpfG+ATML1INXwMa8nozKRBsM2B0y/Js/eYI5evQXUwagX3UyesqKwHAY7VZGtT3nCrXkFOhzogXyGQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736193800; c=relaxed/simple; bh=Gzob3myfhJ77HbtIdJeXGuH6Ojs0DaIU+RlrJQQt4nU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mvsIreYZqMP0iGEsnThCUND7QudJ4bjEMHJ8xRcwC8pD3FfOQbzMiGCznXq0/4t/8h3IoVe5doai1iGpvGNSDFARGjbcbUL//EkAgsBwLVEiVoRKazrxcE9qOYn35JWxZJxq6UZpnYNEpBIHboAHgccGrfoETTQzNiEZflK+7QM= 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=BeM+Muqn; arc=none smtp.client-ip=209.85.128.48 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="BeM+Muqn" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-43635796b48so89317975e9.0 for ; Mon, 06 Jan 2025 12:03:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736193795; x=1736798595; 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=xubr80DdDK1TQnuEw657hT2ILmCSL1Bi/K/I0ME5hpI=; b=BeM+Muqn9+y2leTxSHxPDumk6kl8KeObfVlhu+r9IttzZMdG4DZ1Q3ZgPytZotef// RwclS4eYj+QRg4YmcMG/IdRyII3Uwxk8Zp6jLA2mv34CgYJCEgDCqzvJ26Xvac4b3OG6 /Gt4srgkEwUP0JcqnQ+Ap/PdiAzOAf0onIm4/WbTF4kFVmi72gwnqkoMEYYFY/ur4KC5 Pw+ahcTVA2V1GDy92TjGxG5zK4K8lDX7/eIS7juHI2FoORM1WvVFKP9U5Uilaa8vOBKK N2SW2KIUePyXuZx7ZMhLsaoM5SsVO4UDNqwvRoZ+hm51jCTrVAH+WMSTgaHknale0byT xGlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736193795; x=1736798595; 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=xubr80DdDK1TQnuEw657hT2ILmCSL1Bi/K/I0ME5hpI=; b=lG29La2ezNJznJKK/cb8fLfftTd4gXG97hRjElb1al5uYU4I8TCWf5/mkT18evuAqq FpBaCeg1DkuzuQAxqEqinAva/BYgmJVxET3jW79cLu4dNyBQSavRFbWyJ8s+XreN2nJw OBuDaIBsbsMTBIM6gAMiI+y48YJHovlmRHRCQ+G4dOsK9p1CQzHxX/pJSuYra7WKsLwe sh1gPcxE6USuG/MkGc1FAaXxjRMWywpQB3OvIdjW9svR4enLn6ZryJVymlZ9POmhRUuz 8pnCFmYITwfouKUuOUse8AAqedYzfVDmRjLD8vnGiBdXBl9R7SPCBybVkV55QWfTEx5z o2WA== X-Forwarded-Encrypted: i=1; AJvYcCW4TyBMiTLClD9beVwH8+Q4h92p49lnfLI2UIk8255Lw53ILXQpD3GKgTha3hdZFvScrGQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxPn6WXuVRYuC5Wgy4ZEOl+468ml2qqsNI818Uzxjg9mtRH5JL9 xFlthu0oyJBcoqa78FGAr5aPnm51LWQObIgJnMczAPRfnqW+QZjJJ5bY9ts6c7w= X-Gm-Gg: ASbGncvhtn25dnvk6Sme3ylsZnfg3ZB1SE5C1s2EocQtjBznIqXiinRWNR7Mq0U7/p+ 7yVPJo18olH4m7DdwsQ78D2MjpmmhF4o8JylHrg5T/go50ncTU74OOL0Eqp85JRjrsPJISb+GC+ L4RNNMdsBscrWNd4Ht8zd95ECGw+MrRfzHHo0Lu4ktCiX02VB4XVhymOA6TVraRQNjrpcF47V7w KoA5KoEf9ANi0XXRqXf5IHjm4xOQB6pTrpnYjTVqHvDZIwFIIxxYCNZznmjP5SoA/tPKAFdBX/k o3cZFhwl55vhLeyFrGttXhzxO6zIsEk= X-Google-Smtp-Source: AGHT+IG6hn6gQ1rEDpo0RUo5rK6HsOddWfOpcS85mXtVNMxlfkCCUdnnKaA6rQB2Q6OTZ5JLDkEevw== X-Received: by 2002:a05:600c:1d12:b0:436:1b86:f05 with SMTP id 5b1f17b1804b1-436dc20b0c1mr4405765e9.11.1736193795597; Mon, 06 Jan 2025 12:03:15 -0800 (PST) Received: from localhost.localdomain (88-187-86-199.subs.proxad.net. [88.187.86.199]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4366128a353sm577748615e9.42.2025.01.06.12.03.12 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 06 Jan 2025 12:03:15 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Daniel Henrique Barboza , =?utf-8?b?RnLDqWQ=?= =?utf-8?b?w6lyaWMgQmFycmF0?= , Stefano Stabellini , Ilya Leoshkevich , Cameron Esfahani , Paolo Bonzini , kvm@vger.kernel.org, Alexander Graf , Paul Durrant , David Hildenbrand , Halil Pasic , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Marcel Apfelbaum , xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, =?utf-8?q?C=C3=A9dric_?= =?utf-8?q?Le_Goater?= , Yanan Wang , Reinoud Zandijk , Peter Maydell , qemu-s390x@nongnu.org, Riku Voipio , Anthony PERARD , Alistair Francis , Sunil Muthuswamy , Christian Borntraeger , Nicholas Piggin , Richard Henderson , Marcelo Tosatti , Thomas Huth , Roman Bolshakov , "Edgar E . Iglesias" , Zhao Liu , Phil Dennis-Jordan , David Woodhouse , Harsh Prateek Bora , Nina Schoetterl-Glausch , "Edgar E. Iglesias" , Eduardo Habkost , qemu-ppc@nongnu.org, Daniel Henrique Barboza , "Michael S. Tsirkin" , Anton Johansson Subject: [RFC PATCH 2/7] cpus: Introduce AccelOpsClass::get_cpus_queue() Date: Mon, 6 Jan 2025 21:02:53 +0100 Message-ID: <20250106200258.37008-3-philmd@linaro.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250106200258.37008-1-philmd@linaro.org> References: <20250106200258.37008-1-philmd@linaro.org> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We want the ability to iterate over vCPUs of a specific accelerator. Introduce cpus_get_accel_cpus_queue() to be used by accelerator common code, and expose the get_cpus_queue() in AccelOpsClass, so each accelerator can register its own queue of vCPUs. Signed-off-by: Philippe Mathieu-Daudé --- include/hw/core/cpu.h | 8 ++++++++ include/system/accel-ops.h | 6 ++++++ accel/tcg/user-exec-stub.c | 5 +++++ cpu-common.c | 10 ++++++++++ system/cpus.c | 5 +++++ 5 files changed, 34 insertions(+) diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 48d90f50a71..5ae9bb64d6e 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -591,6 +591,14 @@ static inline CPUArchState *cpu_env(CPUState *cpu) typedef QTAILQ_HEAD(CPUTailQ, CPUState) CPUTailQ; extern CPUTailQ cpus_queue; +/** + * cpus_get_accel_cpus_queue: + * @cpu: The vCPU to get the accelerator #CPUTailQ. + * + * Returns the #CPUTailQ associated with the accelerator of the vCPU. + */ +CPUTailQ *cpus_get_accel_cpus_queue(CPUState *cpu); + #define first_cpu QTAILQ_FIRST_RCU(&cpus_queue) #define CPU_NEXT(cpu) QTAILQ_NEXT_RCU(cpu, node) #define CPU_FOREACH(cpu) QTAILQ_FOREACH_RCU(cpu, &cpus_queue, node) diff --git a/include/system/accel-ops.h b/include/system/accel-ops.h index 137fb96d444..fe59f728bfc 100644 --- a/include/system/accel-ops.h +++ b/include/system/accel-ops.h @@ -12,6 +12,7 @@ #include "exec/vaddr.h" #include "qom/object.h" +#include "hw/core/cpu.h" #define ACCEL_OPS_SUFFIX "-ops" #define TYPE_ACCEL_OPS "accel" ACCEL_OPS_SUFFIX @@ -37,6 +38,11 @@ struct AccelOpsClass { bool (*cpus_are_resettable)(void); void (*cpu_reset_hold)(CPUState *cpu); + /** + * get_cpus_queue: + * Returns the #CPUTailQ maintained by this accelerator. + */ + CPUTailQ *(*get_cpus_queue)(void); void (*create_vcpu_thread)(CPUState *cpu); /* MANDATORY NON-NULL */ void (*kick_vcpu_thread)(CPUState *cpu); bool (*cpu_thread_is_idle)(CPUState *cpu); diff --git a/accel/tcg/user-exec-stub.c b/accel/tcg/user-exec-stub.c index 4fbe2dbdc88..cb76cec76be 100644 --- a/accel/tcg/user-exec-stub.c +++ b/accel/tcg/user-exec-stub.c @@ -18,6 +18,11 @@ void cpu_exec_reset_hold(CPUState *cpu) { } +CPUTailQ *cpus_get_accel_cpus_queue(CPUState *cpu) +{ + return NULL; +} + /* User mode emulation does not support record/replay yet. */ bool replay_exception(void) diff --git a/cpu-common.c b/cpu-common.c index 4248b2d727e..ff8db9c7f9d 100644 --- a/cpu-common.c +++ b/cpu-common.c @@ -82,6 +82,7 @@ unsigned int cpu_list_generation_id_get(void) void cpu_list_add(CPUState *cpu) { static bool cpu_index_auto_assigned; + CPUTailQ *accel_cpus_queue = cpus_get_accel_cpus_queue(cpu); QEMU_LOCK_GUARD(&qemu_cpu_list_lock); if (cpu->cpu_index == UNASSIGNED_CPU_INDEX) { @@ -92,17 +93,26 @@ void cpu_list_add(CPUState *cpu) assert(!cpu_index_auto_assigned); } QTAILQ_INSERT_TAIL_RCU(&cpus_queue, cpu, node); + if (accel_cpus_queue) { + QTAILQ_INSERT_TAIL_RCU(accel_cpus_queue, cpu, node); + } + cpu_list_generation_id++; } void cpu_list_remove(CPUState *cpu) { + CPUTailQ *accel_cpus_queue = cpus_get_accel_cpus_queue(cpu); + QEMU_LOCK_GUARD(&qemu_cpu_list_lock); if (!QTAILQ_IN_USE(cpu, node)) { /* there is nothing to undo since cpu_exec_init() hasn't been called */ return; } + if (accel_cpus_queue) { + QTAILQ_REMOVE_RCU(accel_cpus_queue, cpu, node); + } QTAILQ_REMOVE_RCU(&cpus_queue, cpu, node); cpu->cpu_index = UNASSIGNED_CPU_INDEX; cpu_list_generation_id++; diff --git a/system/cpus.c b/system/cpus.c index 99f83806c16..972df6ab061 100644 --- a/system/cpus.c +++ b/system/cpus.c @@ -209,6 +209,11 @@ void cpu_exec_reset_hold(CPUState *cpu) } } +CPUTailQ *cpus_get_accel_cpus_queue(CPUState *cpu) +{ + return cpus_accel ? cpus_accel->get_cpus_queue() : NULL; +} + int64_t cpus_get_virtual_clock(void) { /* From patchwork Mon Jan 6 20:02:54 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: 13927810 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.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 6B33E1DF97C for ; Mon, 6 Jan 2025 20:03:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736193806; cv=none; b=AMqlx24/S18GeTEB0ONCo9HHr0LlBBMSc2CWm4CfkFpLdw8uMPH1OTC0yzi+mVt4IGOM793dAp1z0zDee3YUGIDI/dPG16qBh4SfDFJ/c5uKvZnkClYgCXBk6srasBd2hyVJwI5oM0ueDVn3Lah1JJz+k8Elhyt9JPpuaOFG71M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736193806; c=relaxed/simple; bh=jZ7uM/5ls9f5amJ9Rvsz2L3dolKK9SGFYa4mZLTw/k8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=By1OhPsxE4CTC/j7fIJVWT7dnyy/KHZc2Tw3c0gWL4iIp0xtUmdYMDInFp8FKkSZW2igOs9CEjHz0cP861trQYmqoDRZjLFgXXH8kUxZDtjoMETuRi45EeXGi3EFiJ8EXos9TsPwaDqhofqv45xHNKUV5Fw5eIZYqdfMv8t7QS8= 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=livjnYzL; arc=none smtp.client-ip=209.85.128.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="livjnYzL" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-4362bae4d7dso106049015e9.1 for ; Mon, 06 Jan 2025 12:03:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736193803; x=1736798603; 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=FEstRp4e2Qb00qEl2/J4TP29Zm1C+ONgiSLe4ofc5Fw=; b=livjnYzLN/IHGzYYzSFrMcv8pAjVaRIFPdlFZ/6Ll+qfhv8K+TVcuXgO3ziQ28LnvG s2vnRVujNKQUSMUAbdCCjvmHdV+zZW+QkZvcCiJPb95hcyp7PN1/r+dTtI7LngzDDphK HYQ8ynAE5Yj6KjTxOMe4DyMH8a8TND1Lld8PmPgEK55l55U8lvJxLOOPjvcGqL50bc+W 6ijG26V/gy8F2ooLW8yLLAZusbqLiRjK4TO5jCuDCGBgEIVdQZYR7c1cVAczTON937Y6 hq/Nui5sXH4Z4JwuwLPUmT1JiGq15w7xhWs1K+qENToCbUqNc2bTnYxo/kU447LeJBgm JRVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736193803; x=1736798603; 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=FEstRp4e2Qb00qEl2/J4TP29Zm1C+ONgiSLe4ofc5Fw=; b=k1m9AB/Pl+CN76pUzVkw3LoxPto094FSBRAc/L6fsNH0rsoQXOqOCZG/oaHUtvd4nR wqjubWw9HeD+S+V129wOcobRC46mUayjCu0ZSitJhFPM+P56NiDAFUg4c+jndHSCHsFU 7q1CddeMCpkSwO/f3H/TOf+Qyf4lI1fCazyNwgjZTM16k2Nk1j27RLBvG4dRLKfvYoW0 G8Bzk/7F9QEVk4ey0eGh63nLDWXT6geg59niCLVlgFIkwCyJ88XPHluxZkzv1Qu+tW5D mzbJ4uPpZHhRoZkQC+6LLTigdaEr1wt3koPIXhRQFEg2CjtXF3vuhlOFlbOmBP1JrtR3 lfxQ== X-Forwarded-Encrypted: i=1; AJvYcCW3Y4F2JT6VAxaBU0I8Ou3ALDa4MViyI8BcOcugDBlp2wKvGOc0lkbYi27oUWsTR/Dodn0=@vger.kernel.org X-Gm-Message-State: AOJu0Yx5F8vSs3aARng8DRkUB9p3raww2dIaolQfVCBMqe0l/7VZWteC j46jADOH1y9JvAoZC5zp1MXp7RHeEA7ledVou83tNps8Dd2ZSa/CWs9R4ZdtGK4= X-Gm-Gg: ASbGnctCbLOPo/nTz+JkZmK74287dvqjKuR1hUupugrmUHtQAYzxbm7IhSI7V4Qs36T 6/HSnrMgYkkt+Vl/WsAsM8XZPnezz/P/xYO2dkMNCFIrdCr06CCU0jX4fusd/7aTUOrWFVCbg3t WMmcCrECXkl47l+5LOR92ZTKtGpMbIv8WxbrIk78MVGVrKxCwHdAzqInC2W3oIUiUfw3pQSLXvh JzdCVD19r12MFL84+pYyuslKQO2MFiNRbWk9jzqEREzUr92QBy7246dBLXBiQNC4XnqgYj1Ybtc IKwxtlQcWMuiJXY03ya6iVNjzXF8H84= X-Google-Smtp-Source: AGHT+IHMet/slV/sVRHbkbSGWWghuJnC++0pCmETj2WxsmX+/fk8W7s4g7KNnMtjYH7DDkOzwohlVQ== X-Received: by 2002:a05:600c:4f84:b0:434:fec5:4ef5 with SMTP id 5b1f17b1804b1-43668643743mr497181795e9.14.1736193801273; Mon, 06 Jan 2025 12:03:21 -0800 (PST) Received: from localhost.localdomain (88-187-86-199.subs.proxad.net. [88.187.86.199]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4365c08afcbsm586765365e9.21.2025.01.06.12.03.19 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 06 Jan 2025 12:03:20 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Daniel Henrique Barboza , =?utf-8?b?RnLDqWQ=?= =?utf-8?b?w6lyaWMgQmFycmF0?= , Stefano Stabellini , Ilya Leoshkevich , Cameron Esfahani , Paolo Bonzini , kvm@vger.kernel.org, Alexander Graf , Paul Durrant , David Hildenbrand , Halil Pasic , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Marcel Apfelbaum , xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, =?utf-8?q?C=C3=A9dric_?= =?utf-8?q?Le_Goater?= , Yanan Wang , Reinoud Zandijk , Peter Maydell , qemu-s390x@nongnu.org, Riku Voipio , Anthony PERARD , Alistair Francis , Sunil Muthuswamy , Christian Borntraeger , Nicholas Piggin , Richard Henderson , Marcelo Tosatti , Thomas Huth , Roman Bolshakov , "Edgar E . Iglesias" , Zhao Liu , Phil Dennis-Jordan , David Woodhouse , Harsh Prateek Bora , Nina Schoetterl-Glausch , "Edgar E. Iglesias" , Eduardo Habkost , qemu-ppc@nongnu.org, Daniel Henrique Barboza , "Michael S. Tsirkin" , Anton Johansson Subject: [RFC PATCH 3/7] accel/tcg: Implement tcg_get_cpus_queue() Date: Mon, 6 Jan 2025 21:02:54 +0100 Message-ID: <20250106200258.37008-4-philmd@linaro.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250106200258.37008-1-philmd@linaro.org> References: <20250106200258.37008-1-philmd@linaro.org> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use a specific vCPUs queue for our unique software accelerator. Register the AccelOpsClass::get_cpus_queue() handler. Signed-off-by: Philippe Mathieu-Daudé --- accel/tcg/tcg-accel-ops.h | 10 ++++++++++ accel/tcg/tcg-accel-ops.c | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/accel/tcg/tcg-accel-ops.h b/accel/tcg/tcg-accel-ops.h index 6feeb3f3e9b..7b1d6288742 100644 --- a/accel/tcg/tcg-accel-ops.h +++ b/accel/tcg/tcg-accel-ops.h @@ -13,10 +13,20 @@ #define TCG_ACCEL_OPS_H #include "system/cpus.h" +#include "hw/core/cpu.h" void tcg_cpu_destroy(CPUState *cpu); int tcg_cpu_exec(CPUState *cpu); void tcg_handle_interrupt(CPUState *cpu, int mask); void tcg_cpu_init_cflags(CPUState *cpu, bool parallel); +#ifdef CONFIG_USER_ONLY +#define tcg_cpus_queue cpus_queue +#else +/* Guard with qemu_cpu_list_lock */ +extern CPUTailQ tcg_cpus_queue; +#endif + +#define CPU_FOREACH_TCG(cpu) QTAILQ_FOREACH_RCU(cpu, &tcg_cpus_queue, node) + #endif /* TCG_ACCEL_OPS_H */ diff --git a/accel/tcg/tcg-accel-ops.c b/accel/tcg/tcg-accel-ops.c index 6e3f1fa92b2..1fb077f7b38 100644 --- a/accel/tcg/tcg-accel-ops.c +++ b/accel/tcg/tcg-accel-ops.c @@ -47,6 +47,13 @@ /* common functionality among all TCG variants */ +CPUTailQ tcg_cpus_queue = QTAILQ_HEAD_INITIALIZER(tcg_cpus_queue); + +static CPUTailQ *tcg_get_cpus_queue(void) +{ + return &tcg_cpus_queue; +} + void tcg_cpu_init_cflags(CPUState *cpu, bool parallel) { uint32_t cflags; @@ -199,6 +206,7 @@ static inline void tcg_remove_all_breakpoints(CPUState *cpu) static void tcg_accel_ops_init(AccelOpsClass *ops) { + ops->get_cpus_queue = tcg_get_cpus_queue; if (qemu_tcg_mttcg_enabled()) { ops->create_vcpu_thread = mttcg_start_vcpu_thread; ops->kick_vcpu_thread = mttcg_kick_vcpu_thread; From patchwork Mon Jan 6 20:02:55 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: 13927811 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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 88D6C1D799D for ; Mon, 6 Jan 2025 20:03:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736193811; cv=none; b=HvbWnqBhe4heh4GmXlSAp+Kn+slTThHFnqofY9CRk0bZ/njEIaFD06jM8mJ63xq3lGM4KHUC5qTG6jKpBCzEEo/qsFJFG2msb5F1xzFY0WmrO2W8D/0lZQWI+wurGnU1AvOAsafcx93YoolfeNsJMZvWGrkvpHgT0K6mn6Ox0Wg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736193811; c=relaxed/simple; bh=SALFw4F5p5mN8BlcdhgV0DARypbvRTD5Cq1Wr8Zs9xM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=J0XbFWhqe5Hl8/yPcdwIzhdTOAkmHe8FMeY+1R5FX2MBFNbf4FhhhYQFg64ozJJK8mtMKKhfz2KJnaXbIFy0or7c3Ml9oj/88NLrBeys4FDcoZpatk9Id18cxiOLE9HwlOGCfn60RyClL3/fs+OkSux5I4bntGn+BhOEIHxo6Lk= 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=mkkdda3n; arc=none smtp.client-ip=209.85.128.53 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="mkkdda3n" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-43618283d48so106994835e9.1 for ; Mon, 06 Jan 2025 12:03:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736193808; x=1736798608; 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=CfaBEiOdRjHzzwUS3kiFtedqZxggxEJ4hucj9YdleWw=; b=mkkdda3nIizSmlRwM4ja2snwlBbVdcDBMr3PzHjWp5PCyzL4daiX4MuVQ9f67EblUs lYjBOinB/BIW2QatskEdy5MTkYVu9jFzpZmXJHpAFDVfBVA+bYWq36W+3Tb0XwHPQXif jqVtq5k7hklB1Jc3AkotGSdwe2EJ0EkB8fHwejo13b1hVKx0PglJlqpnByVP22E5UjoH 9QedR8HRYuRmMk64ztOSyJuadk3JKipxYWkqa6AeI/XGlRHaGhcOO7IE5f5NEwbHIO06 uYo49DsOWVhPlpsSHGD98aWvqtWdYKCUUCvMkPIJ3vOYzWpIVUeN6YNKkvTUjqfq5fxN 6Fzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736193808; x=1736798608; 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=CfaBEiOdRjHzzwUS3kiFtedqZxggxEJ4hucj9YdleWw=; b=BRsszWilqyQO6pW3ZKspxNIhyLpd1C6VwP1QHu4puHKWMINJBdXQT10X19hnkZMiqs EYYTkqCcgwtRJWh5fs7tFqEHOsaisw70KTulPLJLSLUyTsuxrv0joCXekKNQlek7et2i 6K62lDgrryXIxi1khhA5/NP6kDRc8TyWtA/ejroFLUN/NlfF+OSAudF/eBhNbCQNSQqj D+CjHAMBWdB7lD/vzeqPSMNltw2R0442YLm2KLKVzGYS/r2cOHLs9bJ/P3CcQ82Jlcs6 7BM0jnIiJ5OXj9YHThGohvqnZD9k38/t9sfYPMpYjTALq+QDi86gfOhJaSwtfWxEshs3 YLdQ== X-Forwarded-Encrypted: i=1; AJvYcCUGDXjN+k4uNsVbx6f1BHIaj9YwndCf8XkqLBPVpre1p4pOwk/NbG77ANsKoZlunIxlJhM=@vger.kernel.org X-Gm-Message-State: AOJu0YwFeygrOVcXryYJikuE9risi45NFcadhaXtOWIGd6lJjHtIDM8b 4NVdDGMd3Fxq/GbCwwR56GCcLSNOkf+MXw+iGUGbR1GxwaYKvcrZQJe2CqCmZP4= X-Gm-Gg: ASbGnctXsnSKlm4UeAVL/EiDOkK9apdqDnOV3kASeVziiu1z3jQKyKhbu8DlGbhcNte ZBZQAOo14lCIhxJid5pThrOKCC5oGk9NukaS0p/wt92gWJMwKPAQBHdCPhIzYcwxTovMAjapyTB tbSDVDVjMWRqxlFoi40DUEmhk2AWlt2aup6ysLtdbxc0CSMn57spBK+N7fmFnolT+4OW3dxRiAl DAMr6+1NXAocewUA3k0bFamsnGfXIF31P6h8QUmOTyDHuqldmxTpnu8iTREsgfuR0zbw1ErGwo3 MJAE4FqfdxwHh95icslW6qXCi0JpoDA= X-Google-Smtp-Source: AGHT+IF3+buEkSMAzhBuTtka5TQV/I34nAgDx1rHh3g80/cDyG64W7K1EH4+aemix37pseTOETajew== X-Received: by 2002:a05:600c:4f94:b0:434:f871:1b96 with SMTP id 5b1f17b1804b1-43668b7a1dfmr474821135e9.29.1736193807616; Mon, 06 Jan 2025 12:03:27 -0800 (PST) Received: from localhost.localdomain (88-187-86-199.subs.proxad.net. [88.187.86.199]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43656af6cbbsm610646205e9.3.2025.01.06.12.03.25 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 06 Jan 2025 12:03:26 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Daniel Henrique Barboza , =?utf-8?b?RnLDqWQ=?= =?utf-8?b?w6lyaWMgQmFycmF0?= , Stefano Stabellini , Ilya Leoshkevich , Cameron Esfahani , Paolo Bonzini , kvm@vger.kernel.org, Alexander Graf , Paul Durrant , David Hildenbrand , Halil Pasic , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Marcel Apfelbaum , xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, =?utf-8?q?C=C3=A9dric_?= =?utf-8?q?Le_Goater?= , Yanan Wang , Reinoud Zandijk , Peter Maydell , qemu-s390x@nongnu.org, Riku Voipio , Anthony PERARD , Alistair Francis , Sunil Muthuswamy , Christian Borntraeger , Nicholas Piggin , Richard Henderson , Marcelo Tosatti , Thomas Huth , Roman Bolshakov , "Edgar E . Iglesias" , Zhao Liu , Phil Dennis-Jordan , David Woodhouse , Harsh Prateek Bora , Nina Schoetterl-Glausch , "Edgar E. Iglesias" , Eduardo Habkost , qemu-ppc@nongnu.org, Daniel Henrique Barboza , "Michael S. Tsirkin" , Anton Johansson Subject: [RFC PATCH 4/7] accel/tcg: Use CPU_FOREACH_TCG() Date: Mon, 6 Jan 2025 21:02:55 +0100 Message-ID: <20250106200258.37008-5-philmd@linaro.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250106200258.37008-1-philmd@linaro.org> References: <20250106200258.37008-1-philmd@linaro.org> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Only iterate over TCG vCPUs when running TCG specific code. Signed-off-by: Philippe Mathieu-Daudé --- accel/tcg/cputlb.c | 7 ++++--- accel/tcg/monitor.c | 3 ++- accel/tcg/tb-maint.c | 7 ++++--- accel/tcg/tcg-accel-ops-rr.c | 10 +++++----- accel/tcg/tcg-accel-ops.c | 8 ++++---- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index b4ccf0cdcb7..06f34df808b 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -48,6 +48,7 @@ #endif #include "tcg/tcg-ldst.h" #include "tcg/oversized-guest.h" +#include "tcg-accel-ops.h" /* DEBUG defines, enable DEBUG_TLB_LOG to log to the CPU_LOG_MMU target */ /* #define DEBUG_TLB */ @@ -368,7 +369,7 @@ static void flush_all_helper(CPUState *src, run_on_cpu_func fn, { CPUState *cpu; - CPU_FOREACH(cpu) { + CPU_FOREACH_TCG(cpu) { if (cpu != src) { async_run_on_cpu(cpu, fn, d); } @@ -646,7 +647,7 @@ void tlb_flush_page_by_mmuidx_all_cpus_synced(CPUState *src_cpu, TLBFlushPageByMMUIdxData *d; /* Allocate a separate data block for each destination cpu. */ - CPU_FOREACH(dst_cpu) { + CPU_FOREACH_TCG(dst_cpu) { if (dst_cpu != src_cpu) { d = g_new(TLBFlushPageByMMUIdxData, 1); d->addr = addr; @@ -839,7 +840,7 @@ void tlb_flush_range_by_mmuidx_all_cpus_synced(CPUState *src_cpu, d.bits = bits; /* Allocate a separate data block for each destination cpu. */ - CPU_FOREACH(dst_cpu) { + CPU_FOREACH_TCG(dst_cpu) { if (dst_cpu != src_cpu) { p = g_memdup(&d, sizeof(d)); async_run_on_cpu(dst_cpu, tlb_flush_range_by_mmuidx_async_1, diff --git a/accel/tcg/monitor.c b/accel/tcg/monitor.c index ae1dbeb79f8..98bd937ae20 100644 --- a/accel/tcg/monitor.c +++ b/accel/tcg/monitor.c @@ -19,6 +19,7 @@ #include "tcg/tcg.h" #include "internal-common.h" #include "tb-context.h" +#include "tcg-accel-ops.h" static void dump_drift_info(GString *buf) @@ -131,7 +132,7 @@ static void tlb_flush_counts(size_t *pfull, size_t *ppart, size_t *pelide) CPUState *cpu; size_t full = 0, part = 0, elide = 0; - CPU_FOREACH(cpu) { + CPU_FOREACH_TCG(cpu) { full += qatomic_read(&cpu->neg.tlb.c.full_flush_count); part += qatomic_read(&cpu->neg.tlb.c.part_flush_count); elide += qatomic_read(&cpu->neg.tlb.c.elide_flush_count); diff --git a/accel/tcg/tb-maint.c b/accel/tcg/tb-maint.c index 3f1bebf6ab5..8598c59654f 100644 --- a/accel/tcg/tb-maint.c +++ b/accel/tcg/tb-maint.c @@ -36,6 +36,7 @@ #ifdef CONFIG_USER_ONLY #include "user/page-protection.h" #endif +#include "tcg-accel-ops.h" /* List iterators for lists of tagged pointers in TranslationBlock. */ @@ -771,7 +772,7 @@ static void do_tb_flush(CPUState *cpu, run_on_cpu_data tb_flush_count) } did_flush = true; - CPU_FOREACH(cpu) { + CPU_FOREACH_TCG(cpu) { tcg_flush_jmp_cache(cpu); } @@ -885,13 +886,13 @@ static void tb_jmp_cache_inval_tb(TranslationBlock *tb) if (tb_cflags(tb) & CF_PCREL) { /* A TB may be at any virtual address */ - CPU_FOREACH(cpu) { + CPU_FOREACH_TCG(cpu) { tcg_flush_jmp_cache(cpu); } } else { uint32_t h = tb_jmp_cache_hash_func(tb->pc); - CPU_FOREACH(cpu) { + CPU_FOREACH_TCG(cpu) { CPUJumpCache *jc = cpu->tb_jmp_cache; if (qatomic_read(&jc->array[h].tb) == tb) { diff --git a/accel/tcg/tcg-accel-ops-rr.c b/accel/tcg/tcg-accel-ops-rr.c index 028b385af9a..e5ce285efb9 100644 --- a/accel/tcg/tcg-accel-ops-rr.c +++ b/accel/tcg/tcg-accel-ops-rr.c @@ -42,7 +42,7 @@ void rr_kick_vcpu_thread(CPUState *unused) { CPUState *cpu; - CPU_FOREACH(cpu) { + CPU_FOREACH_TCG(cpu) { cpu_exit(cpu); }; } @@ -116,7 +116,7 @@ static void rr_wait_io_event(void) rr_start_kick_timer(); - CPU_FOREACH(cpu) { + CPU_FOREACH_TCG(cpu) { qemu_wait_io_event_common(cpu); } } @@ -129,7 +129,7 @@ static void rr_deal_with_unplugged_cpus(void) { CPUState *cpu; - CPU_FOREACH(cpu) { + CPU_FOREACH_TCG(cpu) { if (cpu->unplug && !cpu_can_run(cpu)) { tcg_cpu_destroy(cpu); break; @@ -160,7 +160,7 @@ static int rr_cpu_count(void) if (cpu_list_generation_id_get() != last_gen_id) { cpu_count = 0; - CPU_FOREACH(cpu) { + CPU_FOREACH_TCG(cpu) { ++cpu_count; } last_gen_id = cpu_list_generation_id_get(); @@ -201,7 +201,7 @@ static void *rr_cpu_thread_fn(void *arg) qemu_cond_wait_bql(first_cpu->halt_cond); /* process any pending work */ - CPU_FOREACH(cpu) { + CPU_FOREACH_TCG(cpu) { current_cpu = cpu; qemu_wait_io_event_common(cpu); } diff --git a/accel/tcg/tcg-accel-ops.c b/accel/tcg/tcg-accel-ops.c index 1fb077f7b38..371bbaa0307 100644 --- a/accel/tcg/tcg-accel-ops.c +++ b/accel/tcg/tcg-accel-ops.c @@ -144,7 +144,7 @@ static int tcg_insert_breakpoint(CPUState *cs, int type, vaddr addr, vaddr len) switch (type) { case GDB_BREAKPOINT_SW: case GDB_BREAKPOINT_HW: - CPU_FOREACH(cpu) { + CPU_FOREACH_TCG(cpu) { err = cpu_breakpoint_insert(cpu, addr, BP_GDB, NULL); if (err) { break; @@ -154,7 +154,7 @@ static int tcg_insert_breakpoint(CPUState *cs, int type, vaddr addr, vaddr len) case GDB_WATCHPOINT_WRITE: case GDB_WATCHPOINT_READ: case GDB_WATCHPOINT_ACCESS: - CPU_FOREACH(cpu) { + CPU_FOREACH_TCG(cpu) { err = cpu_watchpoint_insert(cpu, addr, len, xlat_gdb_type(cpu, type), NULL); if (err) { @@ -175,7 +175,7 @@ static int tcg_remove_breakpoint(CPUState *cs, int type, vaddr addr, vaddr len) switch (type) { case GDB_BREAKPOINT_SW: case GDB_BREAKPOINT_HW: - CPU_FOREACH(cpu) { + CPU_FOREACH_TCG(cpu) { err = cpu_breakpoint_remove(cpu, addr, BP_GDB); if (err) { break; @@ -185,7 +185,7 @@ static int tcg_remove_breakpoint(CPUState *cs, int type, vaddr addr, vaddr len) case GDB_WATCHPOINT_WRITE: case GDB_WATCHPOINT_READ: case GDB_WATCHPOINT_ACCESS: - CPU_FOREACH(cpu) { + CPU_FOREACH_TCG(cpu) { err = cpu_watchpoint_remove(cpu, addr, len, xlat_gdb_type(cpu, type)); if (err) { From patchwork Mon Jan 6 20:02:56 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: 13927812 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (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 5A8F51DF981 for ; Mon, 6 Jan 2025 20:03:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736193818; cv=none; b=QorhqyUz0OVHmJDJ1Y6F0x/QyPc6CFgdWqW1Y6EZ2xRbZYhhOUf4VT4nAwdC0ISZJWWY3VlvPelqlBFtXnFwGgfcaresbxsdbqWS0hsSqPUSi1YZNiAu7qZbOa05Fe8+riLwhwcIgewC/caa53GEejBLLLrki/9pmNAiNdV+Ijs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736193818; c=relaxed/simple; bh=+IrMKbazEv/2Tm1YENOmcIwzVPuD29IvWSa/xeIasLQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nb8IXyUu7ugRVF0ecSO0CL//m/FmO+FjGbUQzeDNE/ekEH1JXG04Ff/aSA0LxnPJji5NKtHtb9qt4Z7oENJyn1mqsxfIW/ioKKZeyQnAHHbL8BbzH2VO5T1Cfh4PbZonztyLRhmyEGnjqHDnFUUoxKVwPQU30YVmdyASWRb65Ok= 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=ANl7Or5x; arc=none smtp.client-ip=209.85.221.49 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="ANl7Or5x" Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-385e1fcb0e1so8141555f8f.2 for ; Mon, 06 Jan 2025 12:03:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736193813; x=1736798613; 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=zxJ3+xb03FIgQb6HyhO+0vTNSYN1GRLEa0EnbI36swA=; b=ANl7Or5xlPd68N9rNBVoKoj1XMVU6uQ0kH/3LyN3iFMeW/fEPCA4ryUIjjhqCuvmvk mrJ/u0dtqvBtQuIxm89ZiLstVFp81VmhsQJpGLZ/loI08j7qeCv1sUPcxWNy6zQPlL0p ZqxYZJL4T7KbEzpHLQsUaEX9sQWB3LuI9fRK2X+U/Ef/IvQFmoH41ngTwZ7LKQ2xdScz l6fQOwX+s5cpcRY8wxrM66nwiiZjvQgx8lAheWYVsMV/OKU9KkYp9KcOYffO3ZIGgr63 5RowGTPa7hZu7THsbWLPzcJYc9IgjFi4l679bX4rVJRQZ2v7vNBAMpnHAibs0Xo0tV/6 62OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736193813; x=1736798613; 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=zxJ3+xb03FIgQb6HyhO+0vTNSYN1GRLEa0EnbI36swA=; b=ed25/+YNwKoocmyJyYA0Mg9XxusV+tPVOfKUqln3H21McvOd9i9XmwCQfLphxxl05i o7xK30v+WUhFiF/2TLsHwgxBDdJEnBv3JhfZ72iPhkmMnd8xUwML4IOBC8qo0nhO31gZ Qnwt9qk5Pjbm4x+1m940btp3O9trJiwkKHa4UYPjvfVd7sv9die08EkrZo8gt6ztrKuS NsL0Boj3EoqDztwUwiacoFPgUN5A87JAsS0x95xg5UpIiIqEvUUMYC6dnzP0USga0Bce 1O3F5Qp9j/OxRpnINcULgoWBLP37pDkT8c9uQtBJ/Dgavi3PEAqy0cXVNTw7MmVGjUOb cwgg== X-Forwarded-Encrypted: i=1; AJvYcCULphsJhmR1AqNwS8643PNhxwiP/1pXCp1qBfespHTrxRdsl3/1JN208zAgXnXfVnV0bk4=@vger.kernel.org X-Gm-Message-State: AOJu0YysnUCAlUY4mvhT2pPYbieFlKi5tV+4pMFa4alL5ZDlZURS/a2b KdGTUOQANQrNqqnteqXDfZ0Erfr3oQohdHPX23spoJjXzLkAxD9u8ZnnVBGvhLE= X-Gm-Gg: ASbGncuqUadbbHdhGIu0M2GWUKQTwqdmK3UsxhVyGFoXgTkLFqeDwkpLSpArA0VnRII BLG4iarYvAjVaijF1ApmPqhEZwrVawRr9PfWa1Hc0qKgXtBLU/o5Z/oerUou5Yr+Jvjw2jZ90sy DRptMVvu+6frW0XN87qR5rbU9nct64gdNiR2SIZ+m/OeUE1lr7jS3LMFw0cxQkvCv2Y4qOuhHrM 7JSwlV2lzqeG7IeyOQNLCdbRTLsOKutAyJk4jrHp2rg9auEvphyT+RzhqDW8ZZThyNf1oZSndmT XrLwr/jnMQVJFSC3Qd+obgmQnCLg1Ag= X-Google-Smtp-Source: AGHT+IGoS13s7EdoAdq3NUY+QaACk4mt67qvYvBPAyuPr3+V1znGvuXeRZNJwXBUnZIrDNw4J4+93w== X-Received: by 2002:adf:a3d9:0:b0:38a:39ad:3e31 with SMTP id ffacd0b85a97d-38a39ad4128mr24752061f8f.57.1736193813254; Mon, 06 Jan 2025 12:03:33 -0800 (PST) Received: from localhost.localdomain (88-187-86-199.subs.proxad.net. [88.187.86.199]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43656af6d02sm618987535e9.1.2025.01.06.12.03.31 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 06 Jan 2025 12:03:32 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Daniel Henrique Barboza , =?utf-8?b?RnLDqWQ=?= =?utf-8?b?w6lyaWMgQmFycmF0?= , Stefano Stabellini , Ilya Leoshkevich , Cameron Esfahani , Paolo Bonzini , kvm@vger.kernel.org, Alexander Graf , Paul Durrant , David Hildenbrand , Halil Pasic , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Marcel Apfelbaum , xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, =?utf-8?q?C=C3=A9dric_?= =?utf-8?q?Le_Goater?= , Yanan Wang , Reinoud Zandijk , Peter Maydell , qemu-s390x@nongnu.org, Riku Voipio , Anthony PERARD , Alistair Francis , Sunil Muthuswamy , Christian Borntraeger , Nicholas Piggin , Richard Henderson , Marcelo Tosatti , Thomas Huth , Roman Bolshakov , "Edgar E . Iglesias" , Zhao Liu , Phil Dennis-Jordan , David Woodhouse , Harsh Prateek Bora , Nina Schoetterl-Glausch , "Edgar E. Iglesias" , Eduardo Habkost , qemu-ppc@nongnu.org, Daniel Henrique Barboza , "Michael S. Tsirkin" , Anton Johansson Subject: [RFC PATCH 5/7] accel/hw: Implement hw_accel_get_cpus_queue() Date: Mon, 6 Jan 2025 21:02:56 +0100 Message-ID: <20250106200258.37008-6-philmd@linaro.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250106200258.37008-1-philmd@linaro.org> References: <20250106200258.37008-1-philmd@linaro.org> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We can only run a single hardware accelerator at a time, so add a generic hw_accel_get_cpus_queue() helper in accel-system.c, a file common to all HW accelerators. Register AccelOpsClass::get_cpus_queue() for each HW accelerator. Add a generic CPU_FOREACH_HWACCEL() macro. Signed-off-by: Philippe Mathieu-Daudé --- include/system/hw_accel.h | 9 +++++++++ accel/accel-system.c | 8 ++++++++ accel/kvm/kvm-accel-ops.c | 1 + accel/xen/xen-all.c | 1 + target/i386/nvmm/nvmm-accel-ops.c | 1 + target/i386/whpx/whpx-accel-ops.c | 1 + 6 files changed, 21 insertions(+) diff --git a/include/system/hw_accel.h b/include/system/hw_accel.h index 380e9e640b6..12664cac6f9 100644 --- a/include/system/hw_accel.h +++ b/include/system/hw_accel.h @@ -2,6 +2,7 @@ * QEMU Hardware accelerators support * * Copyright 2016 Google, Inc. + * Copyright 2025 Linaro Ltd. * * This work is licensed under the terms of the GNU GPL, version 2 or later. * See the COPYING file in the top-level directory. @@ -17,6 +18,14 @@ #include "system/whpx.h" #include "system/nvmm.h" +/* Guard with qemu_cpu_list_lock */ +extern CPUTailQ hw_accel_cpus_queue; + +#define CPU_FOREACH_HWACCEL(cpu) \ + QTAILQ_FOREACH_RCU(cpu, &hw_accel_cpus_queue, node) + +CPUTailQ *hw_accel_get_cpus_queue(void); + void cpu_synchronize_state(CPUState *cpu); void cpu_synchronize_post_reset(CPUState *cpu); void cpu_synchronize_post_init(CPUState *cpu); diff --git a/accel/accel-system.c b/accel/accel-system.c index a7596aef59d..60877ea7a28 100644 --- a/accel/accel-system.c +++ b/accel/accel-system.c @@ -27,9 +27,17 @@ #include "qemu/accel.h" #include "hw/boards.h" #include "system/cpus.h" +#include "system/hw_accel.h" #include "qemu/error-report.h" #include "accel-system.h" +CPUTailQ hw_accel_cpus_queue = QTAILQ_HEAD_INITIALIZER(hw_accel_cpus_queue); + +CPUTailQ *hw_accel_get_cpus_queue(void) +{ + return &hw_accel_cpus_queue; +} + int accel_init_machine(AccelState *accel, MachineState *ms) { AccelClass *acc = ACCEL_GET_CLASS(accel); diff --git a/accel/kvm/kvm-accel-ops.c b/accel/kvm/kvm-accel-ops.c index a81e8f3b03b..5f4001860d5 100644 --- a/accel/kvm/kvm-accel-ops.c +++ b/accel/kvm/kvm-accel-ops.c @@ -93,6 +93,7 @@ static void kvm_accel_ops_class_init(ObjectClass *oc, void *data) { AccelOpsClass *ops = ACCEL_OPS_CLASS(oc); + ops->get_cpus_queue = hw_accel_get_cpus_queue; ops->create_vcpu_thread = kvm_start_vcpu_thread; ops->cpu_thread_is_idle = kvm_vcpu_thread_is_idle; ops->cpus_are_resettable = kvm_cpus_are_resettable; diff --git a/accel/xen/xen-all.c b/accel/xen/xen-all.c index 852e9fbe5fe..ac5ed2dfb80 100644 --- a/accel/xen/xen-all.c +++ b/accel/xen/xen-all.c @@ -150,6 +150,7 @@ static void xen_accel_ops_class_init(ObjectClass *oc, void *data) { AccelOpsClass *ops = ACCEL_OPS_CLASS(oc); + ops->get_cpus_queue = hw_accel_get_cpus_queue; ops->create_vcpu_thread = dummy_start_vcpu_thread; } diff --git a/target/i386/nvmm/nvmm-accel-ops.c b/target/i386/nvmm/nvmm-accel-ops.c index e7b56662fee..bb407c68e14 100644 --- a/target/i386/nvmm/nvmm-accel-ops.c +++ b/target/i386/nvmm/nvmm-accel-ops.c @@ -84,6 +84,7 @@ static void nvmm_accel_ops_class_init(ObjectClass *oc, void *data) { AccelOpsClass *ops = ACCEL_OPS_CLASS(oc); + ops->get_cpus_queue = hw_accel_get_cpus_queue; ops->create_vcpu_thread = nvmm_start_vcpu_thread; ops->kick_vcpu_thread = nvmm_kick_vcpu_thread; diff --git a/target/i386/whpx/whpx-accel-ops.c b/target/i386/whpx/whpx-accel-ops.c index ab2e014c9ea..191214ca81d 100644 --- a/target/i386/whpx/whpx-accel-ops.c +++ b/target/i386/whpx/whpx-accel-ops.c @@ -86,6 +86,7 @@ static void whpx_accel_ops_class_init(ObjectClass *oc, void *data) { AccelOpsClass *ops = ACCEL_OPS_CLASS(oc); + ops->get_cpus_queue = hw_accel_get_cpus_queue; ops->create_vcpu_thread = whpx_start_vcpu_thread; ops->kick_vcpu_thread = whpx_kick_vcpu_thread; ops->cpu_thread_is_idle = whpx_vcpu_thread_is_idle; From patchwork Mon Jan 6 20:02:57 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: 13927813 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 B68461D5CF4 for ; Mon, 6 Jan 2025 20:03:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736193822; cv=none; b=en5JU1kTz9OMJIfqrpFqFbXuQce3TIDpnFXNbPcGRdBF1DTmkFBsAp0cj131OI/4sFUhbUUaqsNf4hRp8OVCjDpH9wRcjmr36xzw33zC6wSiC0VZQa6SNk7Q/hozxWGcB6HXSIvNj6vEdSBgDgnmJeCEU5rmnZSa+VAtdv4xl7U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736193822; c=relaxed/simple; bh=cdFEZ+6OmCW3roDp0Ig6SRyhJR/845jzb1sKUfd4Y0g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nUehr1RNLlT4PqLyHL4xHve4/JidNHV9XH7BBlLGcZPTD3JM9X4apDMygpPEgcHlVAcvVJcwHbey5Hbkz3/2UD2nTe7ygoMlBnagPTyMWH67994ZTDDPW32p2/u5o7GEVEhzc2t1eZrgmubYdGCW8ofmmo1kmWqrCHqdiZeYtRw= 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=onn1kn17; arc=none smtp.client-ip=209.85.128.41 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="onn1kn17" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-43634b570c1so106121935e9.0 for ; Mon, 06 Jan 2025 12:03:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736193819; x=1736798619; 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=sQToL39oc1IIGRZ4x4DJpAbte9qYHUOsWxQUB+w3STI=; b=onn1kn17hTzwU2anu/vJc+ArC6eAdWFu4GfvR1j0aYkLR+WFUC68ZYOuJqEq9ebnbw 6LMxyxxvZPqrLizjPq16y/0rW8cI00bAKn3/lQTLZzfMEJb1gH1PsLIfmuYE9ND+LJMf fv4lcMc/KQk1r7TRodmF60gvloXRIFqzp1HxpP7G99yXMnU06miU50BwC+YvdFscxCH9 BRtvw8WcAIWrV+o3kJF/EpONqnBtLjOn5Q7rX5v2Q67wVmpGl/P8kkRODdcEMu2apHkN aib3Y8Rmb/cF7UGujZogxoIPZ0q9mxuP5yt+Xm2oCqgdlTU6Rqs+4wMLoAN45eW2SkdK bY8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736193819; x=1736798619; 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=sQToL39oc1IIGRZ4x4DJpAbte9qYHUOsWxQUB+w3STI=; b=F40FLKMIoHGEvPU8wicHRNf3l8U2V76V/XlQebMl9pbYwKUKsSRp0el0tg/k6uwzZB UMMDEqUVI0vHZBvsLdBwM/3NgbZLlGy2a7WQE1jHoC1YBJcAklJpasIgkewEByi4luBx aPcIkhgt6zhtSW/qjzUQExKYr4kxftW5bDKCtJA9RNTLmuxh+2E+TE+prpepkH6GLxk5 4Kep8SDIpCw8iBCiE7mexoxY+X9UpYVfIw8MMtGgkjwQhebBfZJmttT2zkhrL1J6mEiM 2WrArZPaRuW0ZcceQyKWRYNovxTTMer+9pxG3gWasbgdaK1N6bBI8cZ65wmblj0uZgGj G/vA== X-Forwarded-Encrypted: i=1; AJvYcCXWJw7EH+sHutQWdEIDk5abNJTI8fHbIWeGc4n+CmQssaK33b62Ah67l/r2mH1eg1kF0hs=@vger.kernel.org X-Gm-Message-State: AOJu0YzHB7HnPLCXqjrcMENVZeG5c71HXLm9M02cgWrgSzOTwo2LnHS7 xqwUFX4/7iApjQMaL5JZFjEztTivN9ujOU6CrkvGr4oQ232H6xwcpn++VErF+8I= X-Gm-Gg: ASbGncv8Besyxa0cJ8xU/nPPDW9s4zNOMY7cbXkuTjhg5FbyCC9qjmkqpydG8WKJpfA 3QS9Uuu3iG7j9tQn2PZQvLsiNLUtQsWyUy9ccBHOp0FzzPRxLCyAMI+xNLQsDv2V3oHavFAMGWU duWrcQpK6fRz5AFIEuXVKrx1Hoz+AEH/mX10mABv/pR21T8xs9H65V7NcRf3myxgySRY63SgIyA 2ImokcDuv+/rbzXwfeF834bazaVbarBOL/nnQ9jwc05D7XeGXoJh3Ejjp6A+2RvNxXE5AQ56tf4 sXMyMNJsSP0dlD9RbCCVlOtgU5EZYt0= X-Google-Smtp-Source: AGHT+IFXiDdVgmnTH4sfktC8/xKNinP6K1bHXh0LE5bFlepNSrMiJFLvtHvHs4neclwfX3Zl5Vm/Iw== X-Received: by 2002:a05:600c:5112:b0:434:faa9:5266 with SMTP id 5b1f17b1804b1-436c2b5b491mr121041605e9.13.1736193818909; Mon, 06 Jan 2025 12:03:38 -0800 (PST) Received: from localhost.localdomain (88-187-86-199.subs.proxad.net. [88.187.86.199]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4367086e40esm543882975e9.30.2025.01.06.12.03.37 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 06 Jan 2025 12:03:38 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Daniel Henrique Barboza , =?utf-8?b?RnLDqWQ=?= =?utf-8?b?w6lyaWMgQmFycmF0?= , Stefano Stabellini , Ilya Leoshkevich , Cameron Esfahani , Paolo Bonzini , kvm@vger.kernel.org, Alexander Graf , Paul Durrant , David Hildenbrand , Halil Pasic , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Marcel Apfelbaum , xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, =?utf-8?q?C=C3=A9dric_?= =?utf-8?q?Le_Goater?= , Yanan Wang , Reinoud Zandijk , Peter Maydell , qemu-s390x@nongnu.org, Riku Voipio , Anthony PERARD , Alistair Francis , Sunil Muthuswamy , Christian Borntraeger , Nicholas Piggin , Richard Henderson , Marcelo Tosatti , Thomas Huth , Roman Bolshakov , "Edgar E . Iglesias" , Zhao Liu , Phil Dennis-Jordan , David Woodhouse , Harsh Prateek Bora , Nina Schoetterl-Glausch , "Edgar E. Iglesias" , Eduardo Habkost , qemu-ppc@nongnu.org, Daniel Henrique Barboza , "Michael S. Tsirkin" , Anton Johansson Subject: [RFC PATCH 6/7] accel/hvf: Use CPU_FOREACH_HVF() Date: Mon, 6 Jan 2025 21:02:57 +0100 Message-ID: <20250106200258.37008-7-philmd@linaro.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250106200258.37008-1-philmd@linaro.org> References: <20250106200258.37008-1-philmd@linaro.org> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Only iterate over HVF vCPUs when running HVF specific code. Signed-off-by: Philippe Mathieu-Daudé --- include/system/hvf_int.h | 4 ++++ accel/hvf/hvf-accel-ops.c | 9 +++++---- target/arm/hvf/hvf.c | 4 ++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/include/system/hvf_int.h b/include/system/hvf_int.h index 42ae18433f0..3cf64faabd1 100644 --- a/include/system/hvf_int.h +++ b/include/system/hvf_int.h @@ -11,6 +11,8 @@ #ifndef HVF_INT_H #define HVF_INT_H +#include "system/hw_accel.h" + #ifdef __aarch64__ #include typedef hv_vcpu_t hvf_vcpuid; @@ -74,4 +76,6 @@ int hvf_put_registers(CPUState *); int hvf_get_registers(CPUState *); void hvf_kick_vcpu_thread(CPUState *cpu); +#define CPU_FOREACH_HVF(cpu) CPU_FOREACH_HWACCEL(cpu) + #endif diff --git a/accel/hvf/hvf-accel-ops.c b/accel/hvf/hvf-accel-ops.c index 945ba720513..bbbe2f8d45b 100644 --- a/accel/hvf/hvf-accel-ops.c +++ b/accel/hvf/hvf-accel-ops.c @@ -504,7 +504,7 @@ static int hvf_insert_breakpoint(CPUState *cpu, int type, vaddr addr, vaddr len) } } - CPU_FOREACH(cpu) { + CPU_FOREACH_HVF(cpu) { err = hvf_update_guest_debug(cpu); if (err) { return err; @@ -543,7 +543,7 @@ static int hvf_remove_breakpoint(CPUState *cpu, int type, vaddr addr, vaddr len) } } - CPU_FOREACH(cpu) { + CPU_FOREACH_HVF(cpu) { err = hvf_update_guest_debug(cpu); if (err) { return err; @@ -560,7 +560,7 @@ static void hvf_remove_all_breakpoints(CPUState *cpu) QTAILQ_FOREACH_SAFE(bp, &hvf_state->hvf_sw_breakpoints, entry, next) { if (hvf_arch_remove_sw_breakpoint(cpu, bp) != 0) { /* Try harder to find a CPU that currently sees the breakpoint. */ - CPU_FOREACH(tmpcpu) + CPU_FOREACH_HVF(tmpcpu) { if (hvf_arch_remove_sw_breakpoint(tmpcpu, bp) == 0) { break; @@ -572,7 +572,7 @@ static void hvf_remove_all_breakpoints(CPUState *cpu) } hvf_arch_remove_all_hw_breakpoints(); - CPU_FOREACH(cpu) { + CPU_FOREACH_HVF(cpu) { hvf_update_guest_debug(cpu); } } @@ -581,6 +581,7 @@ static void hvf_accel_ops_class_init(ObjectClass *oc, void *data) { AccelOpsClass *ops = ACCEL_OPS_CLASS(oc); + ops->get_cpus_queue = hw_accel_get_cpus_queue; ops->create_vcpu_thread = hvf_start_vcpu_thread; ops->kick_vcpu_thread = hvf_kick_vcpu_thread; diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c index 0afd96018e0..13400ff0d5f 100644 --- a/target/arm/hvf/hvf.c +++ b/target/arm/hvf/hvf.c @@ -2269,10 +2269,10 @@ static void hvf_arch_set_traps(void) /* Check whether guest debugging is enabled for at least one vCPU; if it * is, enable exiting the guest on all vCPUs */ - CPU_FOREACH(cpu) { + CPU_FOREACH_HVF(cpu) { should_enable_traps |= cpu->accel->guest_debug_enabled; } - CPU_FOREACH(cpu) { + CPU_FOREACH_HVF(cpu) { /* Set whether debug exceptions exit the guest */ r = hv_vcpu_set_trap_debug_exceptions(cpu->accel->fd, should_enable_traps); From patchwork Mon Jan 6 20:02:58 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: 13927814 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.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 95E5F1DF24B for ; Mon, 6 Jan 2025 20:03:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736193831; cv=none; b=ox8kD0cT1dNMlDzZtz1QnitiM3L+3HbLHWTdqBz4r6MtiDaJfm/h35dVVjCYf2clzgG7OVL7PYIY9DcrBH39oGcQgDcO1k6F5G9awwjp+d8xp8fX9yK/FoAW+EyBBImmXat7Spk3TFDhsjNYOJRUCxlJA/XbQmpVZSrLgIGWO7w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736193831; c=relaxed/simple; bh=qzuBmNQH3znmhd3VNLozKF0kfAq08JeYKtjdXh2hp1Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=f8de76k3GPoL5wq6Kph6+54aT9VZVkVjenXK8DZ4MbEQM6iRuhE/P3TJYgEyK2ySkxPahqp9nb4crFeZBlSgp4RWva6L4zun0nLysA27TkHZHtqIH402PbMZtvFYvwrB36YK031b4e8UzybOQl1V/9MghyXrrOQr1PNbVf9vhWg= 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=mFrayqa7; arc=none smtp.client-ip=209.85.128.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="mFrayqa7" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4361f796586so152703775e9.3 for ; Mon, 06 Jan 2025 12:03:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736193827; x=1736798627; 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=iQTkKmwN0la/zq4/AmggU7ruV8aWhlAE2m8oe1Or7Yc=; b=mFrayqa7eRWKsfi68pRUDs5njnYt2eQrYQlNWFG8zpKxBj+ffg7dDqM2XbMQzP+AKp MidlZlNhmlK2tNLh6/T338oAPuhI30s10euqTjjZQ5HFl+/qMhGHdPPPGUbrqplUc6AU XbJUFyPrvPeRz/tqod2R0A+hVpZPAr7tcdxNLtM41Fp3CmIQT33khMsLU9sq0apIVNWn 2FFlZd4NFlhB2FhVU0ggOy+mnZ68UrjifPTjddwVsFiEuDj4htQv1+5fOlIsY4E/vFBt M2Wbj7HJHeBPd5vMWUppLJtdi6UXADiMPEf5szChbAOkJVvaUCd6xc3YUF/tVfRBRllj j/fA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736193828; x=1736798628; 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=iQTkKmwN0la/zq4/AmggU7ruV8aWhlAE2m8oe1Or7Yc=; b=oOPCXvKaZ+Bbw+7H2XcADR8e6GfjbtcyZlBsIEY1jj8mz9PqkEo5pzmFLtPzgGvWXh DvE3CSCZssZajnWNQ4i4c38kXTb2KZdFJFq9RFZYHkgTipPL/UlExaKYO4Jrl0Ufd7H1 5PLbFNI/tRr+BLbRE5ndL4qv3OfI5sJlVniUiRyrI/wtxUuRxO6AT8CwyFoEZRgiSn+Y +Bd3edTipPDywS3zHyTE3YBSq+AmDh1QKk6SipG06N2Ev/L7Zqst+kuh2QDBbR0TJiK7 Mxt2Tq6qrUKyovwRIlDFyoZ4eN4Ygnnos993HEaikQl4o/SR9pKRvi/KoOuSVn4btDus RMHg== X-Forwarded-Encrypted: i=1; AJvYcCUDw1iGChSvf2WpTqZHKrqMjIIsDxGsd4r1Lg8KO7cRjpSrwtN/VTC/wOULd8CI4c6inw8=@vger.kernel.org X-Gm-Message-State: AOJu0YxwFV8iZQkPTyS3DvcL28cSZJgDaChMrcMUA2j8P2A02qVbI/ag I1NdEtGuRljqkw5rIPd8V8QMjaVHwt9lPAyEM6Rx2IZRR6hIeOblL7qFJtetApA= X-Gm-Gg: ASbGncsPA1HS1elbdEzJv51BZ7nk7hGhi3mZcZPsUs+N6wGqIvO3y5ZiCL5bL84LtFY zehHjx3k2Ihj/rmoj32Nb18Fgh7pt/a3ouxfuysC3izQqKmb60CH3+9HAA9+yXYXbalqT+J+t9Y r3mMU5+2DLA0+uCzyul8KI6F/zdtpQN+M5QlGFuNm6LLbEqu78i2abKCi2o8txLfn4RogMIwH6r Jm8jyjNSUVV8eqA4y0qvaJ4Grn4sIMFAxC4DXASycm1PXDTApkS+eziboXWKV8IYocVhQcxJAHQ 5AX8DemM11Fjq1FGf8jIYDzoW6QbpZQ= X-Google-Smtp-Source: AGHT+IHDE/cbM5Uz3mC6dPWI+SKnpmJxnVL7+eC7vPChMfg/0MfF0CSgk918tvS7UmQNdLQuffdZDw== X-Received: by 2002:a5d:6c64:0:b0:385:f6f4:f8e with SMTP id ffacd0b85a97d-38a223ff1cemr40988273f8f.50.1736193825978; Mon, 06 Jan 2025 12:03:45 -0800 (PST) Received: from localhost.localdomain (88-187-86-199.subs.proxad.net. [88.187.86.199]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-436723cb159sm525092965e9.16.2025.01.06.12.03.42 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 06 Jan 2025 12:03:44 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Daniel Henrique Barboza , =?utf-8?b?RnLDqWQ=?= =?utf-8?b?w6lyaWMgQmFycmF0?= , Stefano Stabellini , Ilya Leoshkevich , Cameron Esfahani , Paolo Bonzini , kvm@vger.kernel.org, Alexander Graf , Paul Durrant , David Hildenbrand , Halil Pasic , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Marcel Apfelbaum , xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, =?utf-8?q?C=C3=A9dric_?= =?utf-8?q?Le_Goater?= , Yanan Wang , Reinoud Zandijk , Peter Maydell , qemu-s390x@nongnu.org, Riku Voipio , Anthony PERARD , Alistair Francis , Sunil Muthuswamy , Christian Borntraeger , Nicholas Piggin , Richard Henderson , Marcelo Tosatti , Thomas Huth , Roman Bolshakov , "Edgar E . Iglesias" , Zhao Liu , Phil Dennis-Jordan , David Woodhouse , Harsh Prateek Bora , Nina Schoetterl-Glausch , "Edgar E. Iglesias" , Eduardo Habkost , qemu-ppc@nongnu.org, Daniel Henrique Barboza , "Michael S. Tsirkin" , Anton Johansson Subject: [RFC PATCH 7/7] accel/kvm: Use CPU_FOREACH_KVM() Date: Mon, 6 Jan 2025 21:02:58 +0100 Message-ID: <20250106200258.37008-8-philmd@linaro.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250106200258.37008-1-philmd@linaro.org> References: <20250106200258.37008-1-philmd@linaro.org> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Only iterate over KVM vCPUs when running KVM specific code. Signed-off-by: Philippe Mathieu-Daudé --- include/system/kvm_int.h | 3 +++ accel/kvm/kvm-all.c | 14 +++++++------- hw/i386/kvm/clock.c | 3 ++- hw/intc/spapr_xive_kvm.c | 5 +++-- hw/intc/xics_kvm.c | 5 +++-- target/i386/kvm/kvm.c | 4 ++-- target/i386/kvm/xen-emu.c | 2 +- target/s390x/kvm/kvm.c | 2 +- target/s390x/kvm/stsi-topology.c | 3 ++- 9 files changed, 24 insertions(+), 17 deletions(-) diff --git a/include/system/kvm_int.h b/include/system/kvm_int.h index 4de6106869b..0ef4c336b18 100644 --- a/include/system/kvm_int.h +++ b/include/system/kvm_int.h @@ -13,6 +13,7 @@ #include "qapi/qapi-types-common.h" #include "qemu/accel.h" #include "qemu/queue.h" +#include "system/hw_accel.h" #include "system/kvm.h" #include "hw/boards.h" #include "hw/i386/topology.h" @@ -168,6 +169,8 @@ struct KVMState char *device; }; +#define CPU_FOREACH_KVM(cpu) CPU_FOREACH_HWACCEL(cpu) + void kvm_memory_listener_register(KVMState *s, KVMMemoryListener *kml, AddressSpace *as, int as_id, const char *name); diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index c65b790433c..9b26b286865 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -872,7 +872,7 @@ static uint64_t kvm_dirty_ring_reap_locked(KVMState *s, CPUState* cpu) if (cpu) { total = kvm_dirty_ring_reap_one(s, cpu); } else { - CPU_FOREACH(cpu) { + CPU_FOREACH_KVM(cpu) { total += kvm_dirty_ring_reap_one(s, cpu); } } @@ -935,7 +935,7 @@ static void kvm_cpu_synchronize_kick_all(void) { CPUState *cpu; - CPU_FOREACH(cpu) { + CPU_FOREACH_KVM(cpu) { run_on_cpu(cpu, do_kvm_cpu_synchronize_kick, RUN_ON_CPU_NULL); } } @@ -3535,7 +3535,7 @@ int kvm_insert_breakpoint(CPUState *cpu, int type, vaddr addr, vaddr len) } } - CPU_FOREACH(cpu) { + CPU_FOREACH_KVM(cpu) { err = kvm_update_guest_debug(cpu, 0); if (err) { return err; @@ -3574,7 +3574,7 @@ int kvm_remove_breakpoint(CPUState *cpu, int type, vaddr addr, vaddr len) } } - CPU_FOREACH(cpu) { + CPU_FOREACH_KVM(cpu) { err = kvm_update_guest_debug(cpu, 0); if (err) { return err; @@ -3592,7 +3592,7 @@ void kvm_remove_all_breakpoints(CPUState *cpu) QTAILQ_FOREACH_SAFE(bp, &s->kvm_sw_breakpoints, entry, next) { if (kvm_arch_remove_sw_breakpoint(cpu, bp) != 0) { /* Try harder to find a CPU that currently sees the breakpoint. */ - CPU_FOREACH(tmpcpu) { + CPU_FOREACH_KVM(tmpcpu) { if (kvm_arch_remove_sw_breakpoint(tmpcpu, bp) == 0) { break; } @@ -3603,7 +3603,7 @@ void kvm_remove_all_breakpoints(CPUState *cpu) } kvm_arch_remove_all_hw_breakpoints(); - CPU_FOREACH(cpu) { + CPU_FOREACH_KVM(cpu) { kvm_update_guest_debug(cpu, 0); } } @@ -4384,7 +4384,7 @@ static void query_stats_cb(StatsResultList **result, StatsTarget target, stats_args.result.stats = result; stats_args.names = names; stats_args.errp = errp; - CPU_FOREACH(cpu) { + CPU_FOREACH_KVM(cpu) { if (!apply_str_list_filter(cpu->parent_obj.canonical_path, targets)) { continue; } diff --git a/hw/i386/kvm/clock.c b/hw/i386/kvm/clock.c index 63be5088420..f2638cf2c22 100644 --- a/hw/i386/kvm/clock.c +++ b/hw/i386/kvm/clock.c @@ -17,6 +17,7 @@ #include "qemu/host-utils.h" #include "qemu/module.h" #include "system/kvm.h" +#include "system/kvm_int.h" #include "system/runstate.h" #include "system/hw_accel.h" #include "kvm/kvm_i386.h" @@ -196,7 +197,7 @@ static void kvmclock_vm_state_change(void *opaque, bool running, if (!cap_clock_ctrl) { return; } - CPU_FOREACH(cpu) { + CPU_FOREACH_KVM(cpu) { run_on_cpu(cpu, do_kvmclock_ctrl, RUN_ON_CPU_NULL); } } else { diff --git a/hw/intc/spapr_xive_kvm.c b/hw/intc/spapr_xive_kvm.c index 26d30b41c15..08354f08512 100644 --- a/hw/intc/spapr_xive_kvm.c +++ b/hw/intc/spapr_xive_kvm.c @@ -14,6 +14,7 @@ #include "target/ppc/cpu.h" #include "system/cpus.h" #include "system/kvm.h" +#include "system/kvm_int.h" #include "system/runstate.h" #include "hw/ppc/spapr.h" #include "hw/ppc/spapr_cpu_core.h" @@ -678,7 +679,7 @@ int kvmppc_xive_post_load(SpaprXive *xive, int version_id) * 'post_load' handler of XiveTCTX because the machine is not * necessarily connected to the KVM device at that time. */ - CPU_FOREACH(cs) { + CPU_FOREACH_KVM(cs) { PowerPCCPU *cpu = POWERPC_CPU(cs); ret = kvmppc_xive_cpu_set_state(spapr_cpu_state(cpu)->tctx, &local_err); @@ -795,7 +796,7 @@ int kvmppc_xive_connect(SpaprInterruptController *intc, uint32_t nr_servers, kvmppc_xive_change_state_handler, xive); /* Connect the presenters to the initial VCPUs of the machine */ - CPU_FOREACH(cs) { + CPU_FOREACH_KVM(cs) { PowerPCCPU *cpu = POWERPC_CPU(cs); ret = kvmppc_xive_cpu_connect(spapr_cpu_state(cpu)->tctx, errp); diff --git a/hw/intc/xics_kvm.c b/hw/intc/xics_kvm.c index ee72969f5f1..aed2ad44363 100644 --- a/hw/intc/xics_kvm.c +++ b/hw/intc/xics_kvm.c @@ -29,6 +29,7 @@ #include "qapi/error.h" #include "trace.h" #include "system/kvm.h" +#include "system/kvm_int.h" #include "hw/ppc/spapr.h" #include "hw/ppc/spapr_cpu_core.h" #include "hw/ppc/xics.h" @@ -418,7 +419,7 @@ int xics_kvm_connect(SpaprInterruptController *intc, uint32_t nr_servers, kvm_gsi_direct_mapping = true; /* Create the presenters */ - CPU_FOREACH(cs) { + CPU_FOREACH_KVM(cs) { PowerPCCPU *cpu = POWERPC_CPU(cs); icp_kvm_realize(DEVICE(spapr_cpu_state(cpu)->icp), &local_err); @@ -434,7 +435,7 @@ int xics_kvm_connect(SpaprInterruptController *intc, uint32_t nr_servers, } /* Connect the presenters to the initial VCPUs of the machine */ - CPU_FOREACH(cs) { + CPU_FOREACH_KVM(cs) { PowerPCCPU *cpu = POWERPC_CPU(cs); icp_set_kvm_state(spapr_cpu_state(cpu)->icp, &local_err); if (local_err) { diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 2f66e63b880..437911d6c6a 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -329,7 +329,7 @@ void kvm_synchronize_all_tsc(void) CPUState *cpu; if (kvm_enabled()) { - CPU_FOREACH(cpu) { + CPU_FOREACH_KVM(cpu) { run_on_cpu(cpu, do_kvm_synchronize_tsc, RUN_ON_CPU_NULL); } } @@ -2847,7 +2847,7 @@ static void *kvm_msr_energy_thread(void *data) * Identify the vcpu threads * Calculate the number of vcpu per package */ - CPU_FOREACH(cpu) { + CPU_FOREACH_KVM(cpu) { for (int i = 0; i < num_threads; i++) { if (cpu->thread_id == thd_stat[i].thread_id) { thd_stat[i].is_vcpu = true; diff --git a/target/i386/kvm/xen-emu.c b/target/i386/kvm/xen-emu.c index e81a2458812..36ae9c11252 100644 --- a/target/i386/kvm/xen-emu.c +++ b/target/i386/kvm/xen-emu.c @@ -1422,7 +1422,7 @@ int kvm_xen_soft_reset(void) return err; } - CPU_FOREACH(cpu) { + CPU_FOREACH_KVM(cpu) { async_run_on_cpu(cpu, do_vcpu_soft_reset, RUN_ON_CPU_NULL); } diff --git a/target/s390x/kvm/kvm.c b/target/s390x/kvm/kvm.c index db645a48133..a02e78ce807 100644 --- a/target/s390x/kvm/kvm.c +++ b/target/s390x/kvm/kvm.c @@ -1559,7 +1559,7 @@ static void handle_diag_318(S390CPU *cpu, struct kvm_run *run) return; } - CPU_FOREACH(t) { + CPU_FOREACH_KVM(t) { run_on_cpu(t, s390_do_cpu_set_diag318, RUN_ON_CPU_HOST_ULONG(diag318_info)); } diff --git a/target/s390x/kvm/stsi-topology.c b/target/s390x/kvm/stsi-topology.c index c8d6389cd87..cf1a9b5d218 100644 --- a/target/s390x/kvm/stsi-topology.c +++ b/target/s390x/kvm/stsi-topology.c @@ -10,6 +10,7 @@ #include "cpu.h" #include "hw/s390x/sclp.h" #include "hw/s390x/cpu-topology.h" +#include "system/kvm_int.h" QEMU_BUILD_BUG_ON(S390_CPU_ENTITLEMENT_LOW != 1); QEMU_BUILD_BUG_ON(S390_CPU_ENTITLEMENT_MEDIUM != 2); @@ -256,7 +257,7 @@ static void s390_topology_fill_list_sorted(S390TopologyList *topology_list) QTAILQ_INSERT_HEAD(topology_list, &sentinel, next); - CPU_FOREACH(cs) { + CPU_FOREACH_KVM(cs) { S390TopologyId id = s390_topology_from_cpu(S390_CPU(cs)); S390TopologyEntry *entry = NULL, *tmp;