From nobody Sat Sep 6 00:37:16 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1754679710; cv=none; d=zohomail.com; s=zohoarc; b=JJGNZANu/m+hVVSiJGCRnQAbhvBM/3clUtNoczQg/NqrUjAIi3VNZaMzCwVaHaUhPOplC2jTeOIiYdw6/F+6UyhkOCYHbZMgXOYT0YCaT/llIUBDItEY9cu7KsLXwmhzXJkxjuDjZkZLv8wXyKRpHcTK5IpQLYkM9mEHQHUOWCQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1754679710; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=sKBBDyOhm3KB0EsnURIQG+Cs3th/O37nyJmS8J3TRyU=; b=fM8YqKp/ntBWA8inw9z9zCTADlKPpmZZ3Nal7KFUsi3y3Lytr5rA2HKoIj4iRcT3oRjmSDwe0qvVuulD3pRxEyccrpXwz2EMvM69srYq8lUYZWPWMvKvXYk1oxQlcL6zyEjSL7JcTYaPJmlYidcH/HV5KnxcsCiEOKZomjPhpRY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1754679710735324.5031098548583; Fri, 8 Aug 2025 12:01:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ukSJD-0006Cf-9z; Fri, 08 Aug 2025 14:59:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ukSJA-0006C6-Ub for qemu-devel@nongnu.org; Fri, 08 Aug 2025 14:59:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ukSJ9-0006fX-6T for qemu-devel@nongnu.org; Fri, 08 Aug 2025 14:59:16 -0400 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-37-2TJqDGNgMoixtesoVMjI9A-1; Fri, 08 Aug 2025 14:59:13 -0400 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-3b793f76a46so1652398f8f.2 for ; Fri, 08 Aug 2025 11:59:13 -0700 (PDT) Received: from [192.168.10.48] ([151.49.234.144]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b8e054036bsm21594609f8f.31.2025.08.08.11.59.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Aug 2025 11:59:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1754679554; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sKBBDyOhm3KB0EsnURIQG+Cs3th/O37nyJmS8J3TRyU=; b=Ky89HJTz4RxlneOpJoKMztUK+MdLkmzJvocPPu0v03ig2UvfpCVndRBqQOums76cG/GU8v BlB7S7eZPj6enKbONrxLUQkWCcppaqNUbrZiO3pQqKKhS5fFixccRTHNUbINEzHobIS617 3EQRh5wczY5JvIzgJo+CDDxScuKCgGc= X-MC-Unique: 2TJqDGNgMoixtesoVMjI9A-1 X-Mimecast-MFC-AGG-ID: 2TJqDGNgMoixtesoVMjI9A_1754679552 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754679551; x=1755284351; 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=sKBBDyOhm3KB0EsnURIQG+Cs3th/O37nyJmS8J3TRyU=; b=jM+ZvOGqH11zhZGnE7LFc9r1DuOjBRG/1sOuSkaEOCYys8LqzXmZQMakGITAsWR8MG 8CH8Oh6E6THWy1eaolLkbz8Sd5ji/4CZkyW82oJszuu3JLL++l+AWaEKdjEFoLqpl6S5 JDgIkWv6UB3pA5m6tiWTY12u/1JldsCu+8R95Q8AdSd/NNaa+nQS62IcXjG4fUMouya5 2/P1mW1UJc7gXJQSBnH6Y1bo3OE4zkFU8/oriyimER+33vcEx0jlK4y0qziFWe6azzml IC2mrtsdo7HPfjQ/FzfAvlIOqP97ZKAduA9RApAfNNKhfOigp4cMlpUTm/ILI1KM/Ajk jp/A== X-Gm-Message-State: AOJu0YwPXLfYfg4DyRKTyKNKOEMmm5TKRC0bOesH5Q+ID893wc4WSS3u l3xprxlbRgJnsMAdNSjgu/s3FAbxFbwIPIi9n69B3aQADEdH5vRrbR88cc7pF5htSm2gp4zriLv 8XGy39eZTWnZfuvKMhscKpIrQZSeYz4d+Kw8XguV4TWIU1cP9rDjRl7A3MVXp98MUpMqAyGQldX aT+/uMyUq07Bz5urdFz0cIW+UDV+2JomFfZnCHgWkL X-Gm-Gg: ASbGnctcE3iBm3tNoK48jdRjhS4xg+wCg8nhZUnBKNJJrv6VsU6s9bzoJaFPdyg6JSI /lnRw8z+T0qJe1jQhouXAWaRnvLBKDoq0DReXYl49jkeF2icJEZMIaGMjARyB06bjtBrS78+VuA 36pWUVAPhMfRNudf4X95VBcOwJCGf4vkqXUl6lYDzqtqu9D5IBCFqqlTdhP0kYh8lM16VV3xBTJ TW6Y95S1uZf9y005hwmpkdLFjEvSdpapU7z6OV1TvmikiubQEfKbTJiI5tbwN0M3mnPh5asNMD1 6dfcfGMD8JKBbUMlYOf2ANzPWf4GIhxABrUNoKQJqLmU X-Received: by 2002:a05:6000:4382:b0:3b8:f863:672c with SMTP id ffacd0b85a97d-3b900b7af6amr3729168f8f.33.1754679550822; Fri, 08 Aug 2025 11:59:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEF7NUjpOHQx3OSeNP9ENS9vtmkk/K7diUejXGwPcUJxdwJK5fbuDPzGf2XY2kVDBe5teeaeA== X-Received: by 2002:a05:6000:4382:b0:3b8:f863:672c with SMTP id ffacd0b85a97d-3b900b7af6amr3729143f8f.33.1754679550205; Fri, 08 Aug 2025 11:59:10 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: imammedo@redhat.com, richard.henderson@linaro.org, peterx@redhat.com Subject: [PATCH 1/8] accel: use store_release/load_acquire for cross-thread exit_request Date: Fri, 8 Aug 2025 20:58:58 +0200 Message-ID: <20250808185905.62776-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250808185905.62776-1-pbonzini@redhat.com> References: <20250808185905.62776-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1754679711643116600 Content-Type: text/plain; charset="utf-8" cpu->exit_request do not use a load-acquire/store-release pair right now, but this means that cpu_exit() does not store it after any flags that are read in the slow path. Probably everything is protected one way or the other by the BQL, because after reading cpu->exit_request the CPU thread often goes to sleep (by waiting on the BQL-protected cpu->halt_cond), but it's not clear. Use load-acquire/store-release consistently. Signed-off-by: Paolo Bonzini Reviewed-by: Peter Xu Reviewed-by: Richard Henderson --- accel/kvm/kvm-all.c | 19 +++++++++---------- accel/tcg/cpu-exec.c | 7 +++++-- accel/tcg/tcg-accel-ops-rr.c | 2 +- hw/core/cpu-common.c | 3 ++- target/i386/nvmm/nvmm-all.c | 5 ++--- target/i386/whpx/whpx-all.c | 3 ++- 6 files changed, 21 insertions(+), 18 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 890d5ea9f86..57e35960125 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -3029,10 +3029,6 @@ static void kvm_eat_signals(CPUState *cpu) =20 if (kvm_immediate_exit) { qatomic_set(&cpu->kvm_run->immediate_exit, 0); - /* Write kvm_run->immediate_exit before the cpu->exit_request - * write in kvm_cpu_exec. - */ - smp_wmb(); return; } =20 @@ -3187,7 +3183,8 @@ int kvm_cpu_exec(CPUState *cpu) } =20 kvm_arch_pre_run(cpu, run); - if (qatomic_read(&cpu->exit_request)) { + /* Corresponding store-release is in cpu_exit. */ + if (qatomic_load_acquire(&cpu->exit_request)) { trace_kvm_interrupt_exit_request(); /* * KVM requires us to reenter the kernel after IO exits to com= plete @@ -3197,13 +3194,15 @@ int kvm_cpu_exec(CPUState *cpu) kvm_cpu_kick_self(); } =20 - /* Read cpu->exit_request before KVM_RUN reads run->immediate_exit. - * Matching barrier in kvm_eat_signals. - */ - smp_rmb(); - run_ret =3D kvm_vcpu_ioctl(cpu, KVM_RUN, 0); =20 + /* + * After writing cpu->exit_request, cpu_exit() sends a signal that= writes + * kvm->run->immediate_exit. The signal is always happening after= the + * write to cpu->exit_request so, if KVM read kvm->run->immediate_= exit + * as true, cpu->exit_request will always read as true. + */ + attrs =3D kvm_arch_post_run(cpu, run); =20 #ifdef KVM_HAVE_MCE_INJECTION diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c index 82867f456c1..4bd9ee01c19 100644 --- a/accel/tcg/cpu-exec.c +++ b/accel/tcg/cpu-exec.c @@ -849,8 +849,11 @@ static inline bool cpu_handle_interrupt(CPUState *cpu, bql_unlock(); } =20 - /* Finally, check if we need to exit to the main loop. */ - if (unlikely(qatomic_read(&cpu->exit_request)) || icount_exit_request(= cpu)) { + /* + * Finally, check if we need to exit to the main loop. + * The corresponding store-release is in cpu_exit. + */ + if (unlikely(qatomic_load_acquire(&cpu->exit_request)) || icount_exit_= request(cpu)) { qatomic_set(&cpu->exit_request, 0); if (cpu->exception_index =3D=3D -1) { cpu->exception_index =3D EXCP_INTERRUPT; diff --git a/accel/tcg/tcg-accel-ops-rr.c b/accel/tcg/tcg-accel-ops-rr.c index 6eec5c9eee9..1e551e92d6d 100644 --- a/accel/tcg/tcg-accel-ops-rr.c +++ b/accel/tcg/tcg-accel-ops-rr.c @@ -242,7 +242,7 @@ static void *rr_cpu_thread_fn(void *arg) cpu =3D first_cpu; } =20 - while (cpu && cpu_work_list_empty(cpu) && !cpu->exit_request) { + while (cpu && cpu_work_list_empty(cpu) && !qatomic_load_acquire(&c= pu->exit_request)) { /* Store rr_current_cpu before evaluating cpu_can_run(). */ qatomic_set_mb(&rr_current_cpu, cpu); =20 diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c index 39e674aca21..f189ce861c9 100644 --- a/hw/core/cpu-common.c +++ b/hw/core/cpu-common.c @@ -84,7 +84,8 @@ void cpu_reset_interrupt(CPUState *cpu, int mask) =20 void cpu_exit(CPUState *cpu) { - qatomic_set(&cpu->exit_request, 1); + /* Ensure cpu_exec will see the reason why the exit request was set. = */ + qatomic_store_release(&cpu->exit_request, 1); /* Ensure cpu_exec will see the exit request after TCG has exited. */ smp_wmb(); qatomic_set(&cpu->neg.icount_decr.u16.high, -1); diff --git a/target/i386/nvmm/nvmm-all.c b/target/i386/nvmm/nvmm-all.c index c1ac74c4f04..a5e3485c1f8 100644 --- a/target/i386/nvmm/nvmm-all.c +++ b/target/i386/nvmm/nvmm-all.c @@ -743,7 +743,8 @@ nvmm_vcpu_loop(CPUState *cpu) =20 nvmm_vcpu_pre_run(cpu); =20 - if (qatomic_read(&cpu->exit_request)) { + /* Corresponding store-release is in cpu_exit. */ + if (qatomic_load_acquire(&cpu->exit_request)) { #if NVMM_USER_VERSION >=3D 2 nvmm_vcpu_stop(vcpu); #else @@ -751,8 +752,6 @@ nvmm_vcpu_loop(CPUState *cpu) #endif } =20 - /* Read exit_request before the kernel reads the immediate exit fl= ag */ - smp_rmb(); ret =3D nvmm_vcpu_run(mach, vcpu); if (ret =3D=3D -1) { error_report("NVMM: Failed to exec a virtual processor," diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index 878cdd1668c..9f88e368d4d 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -1714,7 +1714,8 @@ static int whpx_vcpu_run(CPUState *cpu) if (exclusive_step_mode =3D=3D WHPX_STEP_NONE) { whpx_vcpu_pre_run(cpu); =20 - if (qatomic_read(&cpu->exit_request)) { + /* Corresponding store-release is in cpu_exit. */ + if (qatomic_load_acquire(&cpu->exit_request)) { whpx_vcpu_kick(cpu); } } --=20 2.50.1 From nobody Sat Sep 6 00:37:16 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1754679632; cv=none; d=zohomail.com; s=zohoarc; b=Xi8mFtiBRv3vkrW8Z4GijBwu72zDu6CwuyZPLknriW/wns1RyZWcn1hnCJeay64UlVHoXnVFBcGXPPj9zfWsiHUzV9cAbM8437aPxvJ6BDqy+Iy8MsrAFmLQJRnXknJc1UaYgL20ZWmcD8yeavr6BJET1M1rH13wjrdk/OCt000= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1754679632; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Kq5SJZitYm77HsWLsoPLECQfDLAC1Pk673DMPfDg9po=; b=fvc+Kx6uaGdCm2g9/zxhur+l2ButZLMZLUwCHLq2wWP6WtZ8xAboOS6i5EYzNRGNtl7VEZ3+VWYP4JOgXod12e6Qn4dMoVSbZmpHC/F0RG8bNGf6Qa/Qk/+vNg+H5bGefGTAMwqgqTRRWQTpLAD3bTEQK2mIasjYEwG8I+wWwwk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1754679632902762.100693191291; Fri, 8 Aug 2025 12:00:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ukSJH-0006Dy-P6; Fri, 08 Aug 2025 14:59:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ukSJE-0006Cu-8k for qemu-devel@nongnu.org; Fri, 08 Aug 2025 14:59:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ukSJC-0006fp-HK for qemu-devel@nongnu.org; Fri, 08 Aug 2025 14:59:19 -0400 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-556-QfBWc6ZSOe2HFBH56MEqDg-1; Fri, 08 Aug 2025 14:59:16 -0400 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-3b7892c42b7so1610397f8f.0 for ; Fri, 08 Aug 2025 11:59:16 -0700 (PDT) Received: from [192.168.10.48] ([151.49.234.144]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-459e586ad64sm143572105e9.20.2025.08.08.11.59.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Aug 2025 11:59:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1754679557; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Kq5SJZitYm77HsWLsoPLECQfDLAC1Pk673DMPfDg9po=; b=KjOI3uaEOyshB+IVXD16QUwgSddX+ZWOp5dNc2Ur01Lp5lT68FBjL7AqnK4VC85cTqzsDc +v66Q66PZqIFtq17nQfJ1v3p9Aos/UpBZKICkmB2hUatMshtfHZJ83QGZBgeXSRpZqhc2E xmCwWjICkHSk/LtDF4uYB8inE8fpvVg= X-MC-Unique: QfBWc6ZSOe2HFBH56MEqDg-1 X-Mimecast-MFC-AGG-ID: QfBWc6ZSOe2HFBH56MEqDg_1754679555 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754679554; x=1755284354; 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=Kq5SJZitYm77HsWLsoPLECQfDLAC1Pk673DMPfDg9po=; b=cOOcNbE3VIRB5zZ7WxkwyGct1it3jL+sO3kbL5n9BPxX1CMkF7EoFH+m3TPadqi+sW 6nELp9+CPxY+HbH0vt/U3O48EJC7Yk9zj/tr3wbECLxLM2K6uMgdG9beeWQFjtEET4Mx Fc9kCbItCROw+kliU7DFnP2+nUhQWiUr/SW0m4lndakx1niTY3Hz8hakPZ8PZxSKH5Yy ksXSGdVAz4Yh0KVT1Q4rbMuK7PrgdbBGPlLXbxCzArYvT8st63NB5EkpK52BP1Lfso1k e4Vmpro1SmhduJUo4HVq98g+Vcm/mJqwGdo1dcNxwJjLq2AI7vng7gvAGRCn/gGrglAg E6yg== X-Gm-Message-State: AOJu0YxVcWHwFp2ymliTpyfsEdaFFclpf0v86+HDi+8C/swI3gLg0snf qT3+17DWRHI1t/vfPReZiflaXiZjb4Lw6Gy4iIa5YrSMgY/52U8O8DJFGemQtYx68VgN9TpBdbi 0uVIDxUbFLNgTWATgUdkgd0K5N4j1OueS1+7ixANg6BrO4K01oN+mTlP2JwJqIyoOJkkTakIQyK KHsFBs4Z28PdgaO14X0a4XL1r9xtYpPxmzHVlfJEK3 X-Gm-Gg: ASbGnctmWQ5QuisGiBmWpdhPuMvU4oKFCNJnb7bRdgqIXn9Ee94Cn49OdJxtzfQD0Vt Un2jJUVnupuJzIbz63SAEMKrfL5lv7UfKyqxQ09UIoYH8VH2qjKNWddkyC9yzviFTvELlQUisAR hwQ0f1tyKSG3qKKvsrqk3p4u/y/I82wK6v8UuHBsfNWyxJ4C+3Hg9D/9Voip4Owvmvmo7YIx0cK Pge/2K2qMJ2vkNmSrpXkb3s3g/QfVk7JiXyiDGa5/E2x0494bGf8UM3gs3W6KKxzO2wB1hm9uAd 5KvDanaHRx1YticvoXnSuAHgg27qEHKLi44nxsgfAPDW X-Received: by 2002:a05:6000:18a6:b0:3b7:825e:2d28 with SMTP id ffacd0b85a97d-3b900b49901mr3270946f8f.9.1754679554216; Fri, 08 Aug 2025 11:59:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF3GFDu25FZWrntGg8UCYix206t1pksINbSXuuV13Jy1TNy6Fr/3OSao3NK0zEvqZGvg25hWw== X-Received: by 2002:a05:6000:18a6:b0:3b7:825e:2d28 with SMTP id ffacd0b85a97d-3b900b49901mr3270931f8f.9.1754679553724; Fri, 08 Aug 2025 11:59:13 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: imammedo@redhat.com, richard.henderson@linaro.org, peterx@redhat.com Subject: [PATCH 2/8] accel/hvf: check exit_request before running the vCPU Date: Fri, 8 Aug 2025 20:58:59 +0200 Message-ID: <20250808185905.62776-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250808185905.62776-1-pbonzini@redhat.com> References: <20250808185905.62776-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1754679634616116600 Content-Type: text/plain; charset="utf-8" This is done by all other accelerators, but was missing for Hypervisor.framework. Signed-off-by: Paolo Bonzini Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- target/arm/hvf/hvf.c | 4 ++++ target/i386/hvf/hvf.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c index b77db99079e..478bc75fee6 100644 --- a/target/arm/hvf/hvf.c +++ b/target/arm/hvf/hvf.c @@ -1927,6 +1927,10 @@ int hvf_vcpu_exec(CPUState *cpu) flush_cpu_state(cpu); =20 bql_unlock(); + /* Corresponding store-release is in cpu_exit. */ + if (qatomic_load_acquire(&cpu->exit_request)) { + hv_vcpus_exit(&cpu->accel->fd, 1); + } r =3D hv_vcpu_run(cpu->accel->fd); bql_lock(); switch (r) { diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c index 8445cadecec..b7c4b849cdf 100644 --- a/target/i386/hvf/hvf.c +++ b/target/i386/hvf/hvf.c @@ -749,6 +749,10 @@ int hvf_vcpu_exec(CPUState *cpu) return EXCP_HLT; } =20 + /* Corresponding store-release is in cpu_exit. */ + if (qatomic_load_acquire(&cpu->exit_request)) { + hv_vcpu_interrupt(&cpu->accel->fd, 1); + } hv_return_t r =3D hv_vcpu_run_until(cpu->accel->fd, HV_DEADLINE_FO= REVER); assert_hvf_ok(r); =20 --=20 2.50.1 From nobody Sat Sep 6 00:37:16 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1754679674; cv=none; d=zohomail.com; s=zohoarc; b=Q6PCtMXdXF6boDDcpo8p9SpHyIGbzBwmmvBXty2x+7bT9f1gw/fmjVK7AfpsbwGLMPU8/As124ppdz/RNbTaRqiscEuYOXxDbW61kHMaw5OgObL9Iy3G6Xn/jHxkRWTsPYKzp/U43HRPxJE2FWru26ixpK8s5Vad/MujWYrpBtw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1754679674; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=mrVXt3xbYChrYy+q8fC6Jz8QBJwcNkprpohDabmVtrs=; b=cmdpUCFAv+CZPJQT7tL4D8Mt3HLVSc7cWFzh8/9PoJH9V4iZDMuTUUTK6/+nAnC42gPmGsuXHw8UNsxM/UBmR2fpuEEvVHmfs6+R1lOcuVPzEZOU2mggJSZbso+aBEy8kTZMNmbhJOoxCyCOj8uQF5EetPHI7uCHEgngEDRZ7uc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1754679674296153.40497801583956; Fri, 8 Aug 2025 12:01:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ukSJI-0006EL-W5; Fri, 08 Aug 2025 14:59:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ukSJG-0006De-RQ for qemu-devel@nongnu.org; Fri, 08 Aug 2025 14:59:22 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ukSJF-0006g2-6I for qemu-devel@nongnu.org; Fri, 08 Aug 2025 14:59:22 -0400 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-576-AUuwm6DPO1KTScFk0vGq6w-1; Fri, 08 Aug 2025 14:59:19 -0400 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-456106b7c4aso12787275e9.0 for ; Fri, 08 Aug 2025 11:59:18 -0700 (PDT) Received: from [192.168.10.48] ([151.49.234.144]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-459e585586esm157348725e9.13.2025.08.08.11.59.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Aug 2025 11:59:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1754679560; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mrVXt3xbYChrYy+q8fC6Jz8QBJwcNkprpohDabmVtrs=; b=LV1LXMl7x5c0u8YLE7dARh9Bn9gzfgw3qsMcocJD6Hk06L9B+C/h8ymU1mS1uIlLcA3En7 fWq3OYtd6sTYIy+8XuyfbQFZHcsQJo1zpGsvKgLl8ucT5Ec3xX6JBtEJOZ5igxTvafAA5A wbu6QiS52KiEVurqGVHvRObdHOhU5JQ= X-MC-Unique: AUuwm6DPO1KTScFk0vGq6w-1 X-Mimecast-MFC-AGG-ID: AUuwm6DPO1KTScFk0vGq6w_1754679558 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754679557; x=1755284357; 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=mrVXt3xbYChrYy+q8fC6Jz8QBJwcNkprpohDabmVtrs=; b=cEDikEHBRxV2xdmPUMeuwy/FkLs8Zo9fW0Gs4ouZ8NLEetwEh8TUoE650RxZuq5Wo7 3MADtg+DjlfyoS8S//MwdDdMyJv8ghcVZMa4eucxvr5UnjpGL0bM7n1+ED1flZS4+CyH b9y3fdjD2oF3gNneiwEeEpNCuBa1gaLswZBH/tjGOlhfmbyojsXo2zq5Zt5rEnC2Qe60 SpLtlSzcetjIVm6rJLc4FTMIuAw6qy6JPwk4aEPqzk1CPx/b3hVsljNiPbH7jV7lLQNZ Dtv1dzuPL/G4ADPRPqH4xynqEdY1VMbGpVMz0L21QSC3khH6vKaAH5yofemeQ4M/eMNB V4rA== X-Gm-Message-State: AOJu0YxR9+TrFGPR1Wc1jrdWJihcq3yI73W3YFAQW4LXzcGn4rjuKchm 8MWkG+FP++qEZmC87BFxS/Dm+oPO0L3S+vqxgvFmhsasG40dtTIKEJNeOhg3w7S5rCxIRXqGmTE JM3Z56SW/yBPGUtyrL2RDaP9QZ+vZs+CxKDMY8+MecptJicCwxeX4EtxfUtYJvNR/i8I1wtr17z MIxWel+TRgfggjUxA7rpDYma6IIaCsSkmRD/ly17jX X-Gm-Gg: ASbGncvY1HYbSD1N5ihHfeVWsuSZh3XAdBkJq9B/GE66RlHExM/MdECWORH2SEp7Hgw Q20yY6SAmj7hUVC17NpvA2MlABdvliMo4yiVT8v8Xr8nwYoS01+ZT/VWu9w6baP2NWiSk/eY3kL BIdVKq4yPexFMmc85+OpZdftqcc3XOkTsxh1hNMstilIkpsSkkyfOQI7I12wHKgIw+tCELXj7yD yhTOOwarS+BworvCNtvKiGE2V92hvsPhaPYWlTEx52rjI+Hdi4ZMXQDkvSf0Bs2MzpIyA1dDFTU QBQ59opTMU9trM/3PUYSEkTELKoyc5xVrkMqGkEcVwkM X-Received: by 2002:a05:600c:3b1b:b0:459:e39e:e5a5 with SMTP id 5b1f17b1804b1-459f51a7fbamr37300325e9.5.1754679556836; Fri, 08 Aug 2025 11:59:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFCM/Pp9WgCSSnWFP5mPwLStDTtNjyCCdnYpR+9+Fr6gKo4jSfZBboHQsaMThahH/+9rZYutQ== X-Received: by 2002:a05:600c:3b1b:b0:459:e39e:e5a5 with SMTP id 5b1f17b1804b1-459f51a7fbamr37300105e9.5.1754679556314; Fri, 08 Aug 2025 11:59:16 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: imammedo@redhat.com, richard.henderson@linaro.org, peterx@redhat.com Subject: [PATCH 3/8] accel: use atomic accesses for exit_request Date: Fri, 8 Aug 2025 20:59:00 +0200 Message-ID: <20250808185905.62776-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250808185905.62776-1-pbonzini@redhat.com> References: <20250808185905.62776-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1754679674957116600 Content-Type: text/plain; charset="utf-8" CPU threads write exit_request as a "note to self" that they need to go out to a slow path. This write happens out of the BQL and can be a data race with another threads' cpu_exit(); use atomic accesses consistently. Signed-off-by: Paolo Bonzini Reviewed-by: Peter Xu Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson --- accel/tcg/tcg-accel-ops-mttcg.c | 2 +- accel/tcg/tcg-accel-ops-rr.c | 4 ++-- hw/ppc/spapr_hcall.c | 6 +++--- target/i386/kvm/kvm.c | 2 +- target/i386/nvmm/nvmm-accel-ops.c | 2 +- target/i386/nvmm/nvmm-all.c | 2 +- target/i386/whpx/whpx-all.c | 6 +++--- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/accel/tcg/tcg-accel-ops-mttcg.c b/accel/tcg/tcg-accel-ops-mttc= g.c index 337b993d3da..39237421757 100644 --- a/accel/tcg/tcg-accel-ops-mttcg.c +++ b/accel/tcg/tcg-accel-ops-mttcg.c @@ -85,7 +85,7 @@ static void *mttcg_cpu_thread_fn(void *arg) qemu_guest_random_seed_thread_part2(cpu->random_seed); =20 /* process any pending work */ - cpu->exit_request =3D 1; + qatomic_set(&cpu->exit_request, 1); =20 do { if (cpu_can_run(cpu)) { diff --git a/accel/tcg/tcg-accel-ops-rr.c b/accel/tcg/tcg-accel-ops-rr.c index 1e551e92d6d..c06f3beef2e 100644 --- a/accel/tcg/tcg-accel-ops-rr.c +++ b/accel/tcg/tcg-accel-ops-rr.c @@ -212,7 +212,7 @@ static void *rr_cpu_thread_fn(void *arg) cpu =3D first_cpu; =20 /* process any pending work */ - cpu->exit_request =3D 1; + qatomic_set(&cpu->exit_request, 1); =20 while (1) { /* Only used for icount_enabled() */ @@ -286,7 +286,7 @@ static void *rr_cpu_thread_fn(void *arg) /* Does not need a memory barrier because a spurious wakeup is oka= y. */ qatomic_set(&rr_current_cpu, NULL); =20 - if (cpu && cpu->exit_request) { + if (cpu && qatomic_read(&cpu->exit_request)) { qatomic_set_mb(&cpu->exit_request, 0); } =20 diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index 1e936f35e44..03a62b047b3 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -509,7 +509,7 @@ static target_ulong h_cede(PowerPCCPU *cpu, SpaprMachin= eState *spapr, if (!cpu_has_work(cs)) { cs->halted =3D 1; cs->exception_index =3D EXCP_HLT; - cs->exit_request =3D 1; + qatomic_set(&cs->exit_request, 1); ppc_maybe_interrupt(env); } =20 @@ -531,7 +531,7 @@ static target_ulong h_confer_self(PowerPCCPU *cpu) } cs->halted =3D 1; cs->exception_index =3D EXCP_HALTED; - cs->exit_request =3D 1; + qatomic_set(&cs->exit_request, 1); ppc_maybe_interrupt(&cpu->env); =20 return H_SUCCESS; @@ -624,7 +624,7 @@ static target_ulong h_confer(PowerPCCPU *cpu, SpaprMach= ineState *spapr, } =20 cs->exception_index =3D EXCP_YIELD; - cs->exit_request =3D 1; + qatomic_set(&cs->exit_request, 1); cpu_loop_exit(cs); =20 return H_SUCCESS; diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 306430a0521..867eabc6969 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -5604,7 +5604,7 @@ int kvm_arch_process_async_events(CPUState *cs) if (env->exception_nr =3D=3D EXCP08_DBLE) { /* this means triple fault */ qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET); - cs->exit_request =3D 1; + qatomic_set(&cs->exit_request, 1); return 0; } kvm_queue_exception(env, EXCP12_MCHK, 0, 0); diff --git a/target/i386/nvmm/nvmm-accel-ops.c b/target/i386/nvmm/nvmm-acce= l-ops.c index 3799260bbde..3658a583bc8 100644 --- a/target/i386/nvmm/nvmm-accel-ops.c +++ b/target/i386/nvmm/nvmm-accel-ops.c @@ -77,7 +77,7 @@ static void nvmm_start_vcpu_thread(CPUState *cpu) */ static void nvmm_kick_vcpu_thread(CPUState *cpu) { - cpu->exit_request =3D 1; + qatomic_set(&cpu->exit_request, 1); cpus_kick_thread(cpu); } =20 diff --git a/target/i386/nvmm/nvmm-all.c b/target/i386/nvmm/nvmm-all.c index a5e3485c1f8..d2d90f38976 100644 --- a/target/i386/nvmm/nvmm-all.c +++ b/target/i386/nvmm/nvmm-all.c @@ -414,7 +414,7 @@ nvmm_vcpu_pre_run(CPUState *cpu) * or commit pending TPR access. */ if (cpu_test_interrupt(cpu, CPU_INTERRUPT_INIT | CPU_INTERRUPT_TPR)) { - cpu->exit_request =3D 1; + qatomic_set(&cpu->exit_request, 1); } =20 if (!has_event && cpu_test_interrupt(cpu, CPU_INTERRUPT_NMI)) { diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index 9f88e368d4d..9b07716121a 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -1489,10 +1489,10 @@ static void whpx_vcpu_pre_run(CPUState *cpu) if (cpu_test_interrupt(cpu, CPU_INTERRUPT_INIT | CPU_INTERRUPT_TPR)) { if (cpu_test_interrupt(cpu, CPU_INTERRUPT_INIT) && !(env->hflags & HF_SMM_MASK)) { - cpu->exit_request =3D 1; + qatomic_set(&cpu->exit_request, 1); } if (cpu_test_interrupt(cpu, CPU_INTERRUPT_TPR)) { - cpu->exit_request =3D 1; + qatomic_set(&cpu->exit_request, 1); } } =20 @@ -1539,7 +1539,7 @@ static void whpx_vcpu_pre_run(CPUState *cpu) if (tpr !=3D vcpu->tpr) { vcpu->tpr =3D tpr; reg_values[reg_count].Reg64 =3D tpr; - cpu->exit_request =3D 1; + qatomic_set(&cpu->exit_request, 1); reg_names[reg_count] =3D WHvX64RegisterCr8; reg_count +=3D 1; } --=20 2.50.1 From nobody Sat Sep 6 00:37:16 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1754679681; cv=none; d=zohomail.com; s=zohoarc; b=RvXqPN3kWwWMpUNh6TQN2Kp5wW6XGs3RHO3PjJYZP0sEEw/6u0QWGyOnmmriXyVk+F179YjswoEA58lVYFbxduXLdkYeVJolGyWnhiAQjt/RuwmWLQaQjkq1tAE8t15alNiyK9oX5LnlV5ZOxAXy4TXvauHwnwVS5d4yVPIeUCw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1754679681; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=0iXq6LWl1KGiN5VNE9pg5mJWSYw365L8S6DEXN3jbo0=; b=kqpVJETgH2cWfNqtIypmcZDOMUw/1CAwcidTfGtdjE/MvaAlemnJWqEaKCv5tMLuxiOlfgHQC5x7jR45ueY6+onYdZLNmGGczYge0RmmF9M1eZWVPykuN0Zardad1b2la5mRQRq2qqVsOFFBZnJUxJfSoA6yjsnPAqIUHHmo6es= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1754679681392775.7122325673677; Fri, 8 Aug 2025 12:01:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ukSJL-0006FI-29; Fri, 08 Aug 2025 14:59:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ukSJI-0006EJ-Qs for qemu-devel@nongnu.org; Fri, 08 Aug 2025 14:59:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ukSJH-0006gC-6C for qemu-devel@nongnu.org; Fri, 08 Aug 2025 14:59:24 -0400 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-97-v3_PJcD7M_O0XQv0rT8uhw-1; Fri, 08 Aug 2025 14:59:21 -0400 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-3b7886bfc16so1463224f8f.1 for ; Fri, 08 Aug 2025 11:59:21 -0700 (PDT) Received: from [192.168.10.48] ([151.49.234.144]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b79c470102sm30983453f8f.53.2025.08.08.11.59.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Aug 2025 11:59:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1754679562; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0iXq6LWl1KGiN5VNE9pg5mJWSYw365L8S6DEXN3jbo0=; b=Seb7ml9idCQqlOprT0jIgOjQqRHmvNMrDrYJqvEQCjmUvtXtIbtqx/vDfbFpg0VjP6s6vP dxya6F1gMffHqAwvAu7uSJ1fUo7AoIyYKJTkwT3wkdXCa/Lqd78keu95xl8VXMFPEP0ciN LBLhLNlwmqfMDT/5YHfTP6FTYE0DSGI= X-MC-Unique: v3_PJcD7M_O0XQv0rT8uhw-1 X-Mimecast-MFC-AGG-ID: v3_PJcD7M_O0XQv0rT8uhw_1754679560 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754679559; x=1755284359; 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=0iXq6LWl1KGiN5VNE9pg5mJWSYw365L8S6DEXN3jbo0=; b=tAheP4z7bP25Vfts4zBxdfpZIq/uzqpSqXgcFvn8BysuAb8NCSz53yykwyO3QErb12 /mJ6CG0C/F8k59wnFSeWAP/ilGnHasbexWSHOHdZADpknDSN8PvGs7NNEzwvNkQZxPcY NNlr1sHRpF6nBYuau+g7lzbWAAH0rYseKVDrqg/awyWs+fQyON/lqVnda13uCc7bldKB IkIt1FDmdyySmihf/2L0l+y99GNyuskDMj1Fe22Mp4chEgr+kfAmLsVs7DCrJTS9gVKu Q3b365xfg/+g7j5P5LdhTyLxCTld5hMU3D67tYdXpb7voc4rG3JrRYG/64D1o4epFNC3 STVg== X-Gm-Message-State: AOJu0YxcrWgFumA7LUfto5fJOJlYA/LxrUaAiAPN2JCBwV2+1m0BIQHx fF+QLudE+9duKxext1Eu2ZuzXNTvhWc/2AeA7+jOT1YJHR69bF9kMqVD89IeLj5qEl9Y75+fWa6 jz0figldgDQqLSTy5gK1B318d7nrRWWoDyZ9arQKEUrlHndur8y1npUiZ1DebfKeogvl/uMxAQV fJ17G2jpBE5kKssm3pvH10qOEgABp+TL9IWLXInufA X-Gm-Gg: ASbGncu7kojVE3CvhFQSPChTIv5Zbk5cTzgfbkrt5pmq02/7RrgDhRcbAzfciVL8CvW rUKnmFvMl//ga/6YWkSkAfSNNggORyUtRMXIASxB+1mO2ddArSw8Ef4uuZlEMC5RxVwzV/0Ceti AqoxA29NTshratY2R9REV/tgbf7JZmNpywRwCmBqKYxnq4IwMyT2eBTkt+Fvyg9ezyZOIUbWbUS gUIBypNS+zj2Q0nKjuHQtYVmdi78usdlN8HbpKicc8NnfUuHWjus0sN7b3hf5uM3Shi2EkkErQz 6eeaa5qbOV5SpYMyKloNqKWlD4qAefe/vbIjbqUJvU5+ X-Received: by 2002:a05:6000:230f:b0:3b7:899c:e867 with SMTP id ffacd0b85a97d-3b900b805dcmr3760224f8f.59.1754679558981; Fri, 08 Aug 2025 11:59:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEDiOfCpTJWGhzTsCf7cuEsCuYlfwrsPnX0M0sgwDYvSStCWouGv9hn625lHKQ6PS6kubDDRQ== X-Received: by 2002:a05:6000:230f:b0:3b7:899c:e867 with SMTP id ffacd0b85a97d-3b900b805dcmr3760210f8f.59.1754679558506; Fri, 08 Aug 2025 11:59:18 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: imammedo@redhat.com, richard.henderson@linaro.org, peterx@redhat.com Subject: [PATCH 4/8] accel/tcg: introduce tcg_kick_vcpu_thread Date: Fri, 8 Aug 2025 20:59:01 +0200 Message-ID: <20250808185905.62776-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250808185905.62776-1-pbonzini@redhat.com> References: <20250808185905.62776-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1754679683656124100 Content-Type: text/plain; charset="utf-8" qemu_cpu_kick() does not always have to set cpu->exit_request, though it does for now. Introduce a function tcg_kick_vcpu_thread() which can be changed in the future to not set cpu->exit_request, and reserve cpu_exit() for when *all accelerators* need to set that flag. Signed-off-by: Paolo Bonzini --- docs/devel/tcg-icount.rst | 2 +- accel/tcg/tcg-accel-ops-mttcg.h | 3 --- include/exec/cpu-common.h | 1 + accel/tcg/cpu-exec.c | 17 ++++++++++++++++- accel/tcg/tcg-accel-ops-mttcg.c | 5 ----- accel/tcg/tcg-accel-ops-rr.c | 2 +- accel/tcg/tcg-accel-ops.c | 2 +- bsd-user/main.c | 2 +- linux-user/main.c | 2 +- 9 files changed, 22 insertions(+), 14 deletions(-) diff --git a/docs/devel/tcg-icount.rst b/docs/devel/tcg-icount.rst index 7df883446a7..a1dcd79e0fd 100644 --- a/docs/devel/tcg-icount.rst +++ b/docs/devel/tcg-icount.rst @@ -37,7 +37,7 @@ translator starts by allocating a budget of instructions = to be executed. The budget of instructions is limited by how long it will be until the next timer will expire. We store this budget as part of a vCPU icount_decr field which shared with the machinery for handling -cpu_exit(). The whole field is checked at the start of every +qemu_cpu_kick(). The whole field is checked at the start of every translated block and will cause a return to the outer loop to deal with whatever caused the exit. =20 diff --git a/accel/tcg/tcg-accel-ops-mttcg.h b/accel/tcg/tcg-accel-ops-mttc= g.h index 8ffa7a9a9fe..5c145cc8595 100644 --- a/accel/tcg/tcg-accel-ops-mttcg.h +++ b/accel/tcg/tcg-accel-ops-mttcg.h @@ -10,9 +10,6 @@ #ifndef TCG_ACCEL_OPS_MTTCG_H #define TCG_ACCEL_OPS_MTTCG_H =20 -/* kick MTTCG vCPU thread */ -void mttcg_kick_vcpu_thread(CPUState *cpu); - /* start an mttcg vCPU thread */ void mttcg_start_vcpu_thread(CPUState *cpu); =20 diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h index 9b658a3f48f..e843b09cc99 100644 --- a/include/exec/cpu-common.h +++ b/include/exec/cpu-common.h @@ -226,6 +226,7 @@ G_NORETURN void cpu_loop_exit(CPUState *cpu); G_NORETURN void cpu_loop_exit_restore(CPUState *cpu, uintptr_t pc); =20 /* accel/tcg/cpu-exec.c */ +void tcg_kick_vcpu_thread(CPUState *cpu); int cpu_exec(CPUState *cpu); =20 /** diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c index 4bd9ee01c19..1a973596d87 100644 --- a/accel/tcg/cpu-exec.c +++ b/accel/tcg/cpu-exec.c @@ -748,6 +748,20 @@ static inline bool cpu_handle_exception(CPUState *cpu,= int *ret) return false; } =20 +void tcg_kick_vcpu_thread(CPUState *cpu) +{ + /* + * Ensure cpu_exec will see the reason why the exit request was set. + * FIXME: this is not always needed. Other accelerators instead + * read interrupt_request and set exit_request on demand from the + * CPU thread; see kvm_arch_pre_run() for example. + */ + qatomic_store_release(&cpu->exit_request, 1); + + /* Ensure cpu_exec will see the exit request after TCG has exited. */ + qatomic_store_release(&cpu->neg.icount_decr.u16.high, -1); +} + static inline bool icount_exit_request(CPUState *cpu) { if (!icount_enabled()) { @@ -774,7 +788,8 @@ static inline bool cpu_handle_interrupt(CPUState *cpu, /* Clear the interrupt flag now since we're processing * cpu->interrupt_request and cpu->exit_request. * Ensure zeroing happens before reading cpu->exit_request or - * cpu->interrupt_request (see also smp_wmb in cpu_exit()) + * cpu->interrupt_request (see also store-release in + * tcg_kick_vcpu_thread()) */ qatomic_set_mb(&cpu->neg.icount_decr.u16.high, 0); =20 diff --git a/accel/tcg/tcg-accel-ops-mttcg.c b/accel/tcg/tcg-accel-ops-mttc= g.c index 39237421757..5757324a8c2 100644 --- a/accel/tcg/tcg-accel-ops-mttcg.c +++ b/accel/tcg/tcg-accel-ops-mttcg.c @@ -123,11 +123,6 @@ static void *mttcg_cpu_thread_fn(void *arg) return NULL; } =20 -void mttcg_kick_vcpu_thread(CPUState *cpu) -{ - cpu_exit(cpu); -} - void mttcg_start_vcpu_thread(CPUState *cpu) { char thread_name[VCPU_THREAD_NAME_SIZE]; diff --git a/accel/tcg/tcg-accel-ops-rr.c b/accel/tcg/tcg-accel-ops-rr.c index c06f3beef2e..87b49377c78 100644 --- a/accel/tcg/tcg-accel-ops-rr.c +++ b/accel/tcg/tcg-accel-ops-rr.c @@ -43,7 +43,7 @@ void rr_kick_vcpu_thread(CPUState *unused) CPUState *cpu; =20 CPU_FOREACH(cpu) { - cpu_exit(cpu); + tcg_kick_vcpu_thread(cpu); }; } =20 diff --git a/accel/tcg/tcg-accel-ops.c b/accel/tcg/tcg-accel-ops.c index 02c7600bb7d..f4d5372866a 100644 --- a/accel/tcg/tcg-accel-ops.c +++ b/accel/tcg/tcg-accel-ops.c @@ -207,7 +207,7 @@ static void tcg_accel_ops_init(AccelClass *ac) =20 if (qemu_tcg_mttcg_enabled()) { ops->create_vcpu_thread =3D mttcg_start_vcpu_thread; - ops->kick_vcpu_thread =3D mttcg_kick_vcpu_thread; + ops->kick_vcpu_thread =3D tcg_kick_vcpu_thread; ops->handle_interrupt =3D tcg_handle_interrupt; } else { ops->create_vcpu_thread =3D rr_start_vcpu_thread; diff --git a/bsd-user/main.c b/bsd-user/main.c index 7e5d4bbce09..20159207040 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -216,7 +216,7 @@ bool qemu_cpu_is_self(CPUState *cpu) =20 void qemu_cpu_kick(CPUState *cpu) { - cpu_exit(cpu); + tcg_kick_vcpu_thread(cpu); } =20 /* Assumes contents are already zeroed. */ diff --git a/linux-user/main.c b/linux-user/main.c index 68972f00a15..dc68fd448b7 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -192,7 +192,7 @@ bool qemu_cpu_is_self(CPUState *cpu) =20 void qemu_cpu_kick(CPUState *cpu) { - cpu_exit(cpu); + tcg_kick_vcpu_thread(cpu); } =20 void task_settid(TaskState *ts) --=20 2.50.1 From nobody Sat Sep 6 00:37:16 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1754679625; cv=none; d=zohomail.com; s=zohoarc; b=PfCIAdbbWCxyUgW08FCSdHgasz41T4nIjWB1ymjOQJYqPp0ZyhWPM4i7lkLjNTozp7QG5o3jVGM/5Q3NUqhi2J3HhgI/FHBDMRZ1+IDQsYOR5KQrGR7YGZCzHKQ0gnzQ5OpQCOcnOVkknwKfMmj5Tcl9V2Hw1kfUga1yIGbNQRI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1754679625; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=eYQcv6qlBgnWelc57LUkepuCpfhOAkj1K2N9G/HXj+M=; b=P3Ef/iaz9NAVo5ZFZrnnOwZZC6iTqdkgj4yoquvHS8DV8bY1UvXsixa6JRu4Pp4wKxZAznlMzZvB7NaiFWysz5/x1Tl80m62+84aOwjklnT9dTei88LrF7ZutNgfFoOFeQy9BztPZ6wvxvZUSE1rDj/x6J3HJDVQ+zHR3gt0k0M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1754679624988588.9401788467585; Fri, 8 Aug 2025 12:00:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ukSJO-0006Gr-Fx; Fri, 08 Aug 2025 14:59:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ukSJM-0006G9-HJ for qemu-devel@nongnu.org; Fri, 08 Aug 2025 14:59:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ukSJL-0006gV-5R for qemu-devel@nongnu.org; Fri, 08 Aug 2025 14:59:28 -0400 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-493-Iy9ZX7rBNE2MO2wOT7Aavg-1; Fri, 08 Aug 2025 14:59:23 -0400 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-3b7892c42b7so1610455f8f.0 for ; Fri, 08 Aug 2025 11:59:23 -0700 (PDT) Received: from [192.168.10.48] ([151.49.234.144]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-459e586a011sm160547325e9.19.2025.08.08.11.59.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Aug 2025 11:59:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1754679565; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eYQcv6qlBgnWelc57LUkepuCpfhOAkj1K2N9G/HXj+M=; b=MxIjN4doXVJ3SNlIdF0bCrBQG+hV5Lzy3u8xG4UY7QJyHKE5fvFaxYxyu0XEYAFRlJ1hOV p3+PD9v2M7Db0Xgd1ZQEYdPsvZ69Ek0gTATVgA0j2V+kynQ88xY7HHH+pbkx6IUqLysRC6 cmamSZHwru8EiGW+mxFEaWpBwyjghvA= X-MC-Unique: Iy9ZX7rBNE2MO2wOT7Aavg-1 X-Mimecast-MFC-AGG-ID: Iy9ZX7rBNE2MO2wOT7Aavg_1754679563 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754679561; x=1755284361; 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=eYQcv6qlBgnWelc57LUkepuCpfhOAkj1K2N9G/HXj+M=; b=qN4tKWWzftsKmqc693NpCuiQfaewO7+ctXm/kQPE8DOaMb2Zu7F4irTegTOVJLhkel zCClo9b9oF284BYTFdFAxr91KDeo4puwh9cRB1W/ze7N672xGKIxx4M0I/g1e7Lb/+pG xypIUjHGUjjP6h2l7kLkysAHIlH6VuLZQu3JZTNpy8ViZUMC4JHrYF8OKu+cpgkE1S9W AwOg4LrjH+LK9B0pjUV6WV3mADAnT0LXqc1hzFcaWVtHpN3U9k0kDB0bfUNWAIsfl4f3 I5QY+VMBq5QSyMSHlnICh+Ek8+zzVQNkDogfLn4tDGy0c5HBBNVcSo6FlSY6W+ni4zFk kqCQ== X-Gm-Message-State: AOJu0Yygr/SV09zgzDvE2tm+ZawI0FkTrbFgGUz6trYgmZfm9X+M/nIM ZdbSb0N3ccFX436u+SZE2ZRPMnTwUAWz0OfZn0EX1Fb1hc9IGEsP95AsklFvEJ4i2WpywncGc/A vUSUu7sYLmDD7DXjEGnAoG6Sd6k22znm9/BeSwIJ3dlI5GA7Y1+AygDwTfEZkfYFsLf+3pS85K2 Zu5Qh1f8Jfk03IzsENEmsJiGjl1qJvvd/LFyyJ4+4t X-Gm-Gg: ASbGncvxaQJ5uc9LFnWFviZ5ofN44M/GFsKHjJljgZ9AteOMfgZRwud9+KHgTHprLnz XwroQ2YtgE5hHtZVoXTvPBdb52Te/L9sWW10RWcDqjqxUOHYj1FFcvNOdc+CWVnL8HLKzCMVFni Hp5I0CkoxmjurQYtO2QZQk5UxWXbvdUhEHbN69Kv65AieiqSWesHD93kczYR/95IivLodpi6u7l bkEuDXaloTVR2ICAZYpwHqVhVUczL+ykL3tpkFVuONUlzw1So2WAWTFntslWQuBuRztWL9i071+ wdywLHL+IAtQehkI8Sed0IDDoxih613Vl0Sle/SljAsu X-Received: by 2002:a05:6000:26ca:b0:3b7:9bfe:4f6f with SMTP id ffacd0b85a97d-3b900b7be30mr3244466f8f.44.1754679561351; Fri, 08 Aug 2025 11:59:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGRNJSHOUZbKQt3AdENiHJb0x+mHxo9v3+VaApJalxphvkHuxZNDUb+RfcypKuuZL9NMZTZCw== X-Received: by 2002:a05:6000:26ca:b0:3b7:9bfe:4f6f with SMTP id ffacd0b85a97d-3b900b7be30mr3244451f8f.44.1754679560891; Fri, 08 Aug 2025 11:59:20 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: imammedo@redhat.com, richard.henderson@linaro.org, peterx@redhat.com Subject: [PATCH 5/8] cpus: remove TCG-ism from cpu_exit() Date: Fri, 8 Aug 2025 20:59:02 +0200 Message-ID: <20250808185905.62776-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250808185905.62776-1-pbonzini@redhat.com> References: <20250808185905.62776-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1754679629170124100 Content-Type: text/plain; charset="utf-8" Now that TCG has its own kick function, make cpu_exit() do the right kick for all accelerators. Signed-off-by: Paolo Bonzini Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson --- hw/core/cpu-common.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c index f189ce861c9..045b1778236 100644 --- a/hw/core/cpu-common.c +++ b/hw/core/cpu-common.c @@ -86,9 +86,7 @@ void cpu_exit(CPUState *cpu) { /* Ensure cpu_exec will see the reason why the exit request was set. = */ qatomic_store_release(&cpu->exit_request, 1); - /* Ensure cpu_exec will see the exit request after TCG has exited. */ - smp_wmb(); - qatomic_set(&cpu->neg.icount_decr.u16.high, -1); + qemu_cpu_kick(cpu); } =20 static int cpu_common_gdb_read_register(CPUState *cpu, GByteArray *buf, in= t reg) --=20 2.50.1 From nobody Sat Sep 6 00:37:16 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1754679632; cv=none; d=zohomail.com; s=zohoarc; b=WSwiV1awGEfHZ7JwPXSLq2NZvyeSoCV2BTvRNsChyjYtYnORVKEX1Daw3H1p8FxksKm0od0tex3WpCHofQSOstqT8hwo/bd0ho6ITd02bSU2vfAw52jw1oA/fm6kuxmMZ1o95eBFp41a2P+pT0bcbPXJcsyAIIkK4rJHUhHaf34= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1754679632; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=GR20SJxOKCiR8K6K57Fhm+/qQuSbGQLIipzG4dDVZgA=; b=V2Zi9Ss7dEmPMklPBXIiti+ZNr7GhMAbdQjAA11F0ql5IUvz/qCEVb1lZ6F+wirdTmTh8BNDBSgkq0c3Zfmh+dShy7rFHUIKcEpbf3dE1tY7N78kolwoM/IqR9UPmK9BjzKy2jdVfAyUT+Y9jOsaIoK/gywbld7ySLdjCT58VTg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1754679632014163.7904053887097; Fri, 8 Aug 2025 12:00:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ukSJU-0006I7-G9; Fri, 08 Aug 2025 14:59:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ukSJR-0006HP-F8 for qemu-devel@nongnu.org; Fri, 08 Aug 2025 14:59:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ukSJP-0006gf-PM for qemu-devel@nongnu.org; Fri, 08 Aug 2025 14:59:33 -0400 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-646-wkEv75eBMIC8QugXBnIWCw-1; Fri, 08 Aug 2025 14:59:27 -0400 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-459e02731a2so17732375e9.0 for ; Fri, 08 Aug 2025 11:59:27 -0700 (PDT) Received: from [192.168.10.48] ([151.49.234.144]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b79c3bc12csm31879242f8f.28.2025.08.08.11.59.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Aug 2025 11:59:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1754679569; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GR20SJxOKCiR8K6K57Fhm+/qQuSbGQLIipzG4dDVZgA=; b=OlOkFa/t8epbHtuxLqfCvSULU5eTqDkHHJp3ln7Q6aOJXYBHk9tAj9bnPZtBCxvpDcp4OT z6FhfC9eDUo4QQB2dQj3a6nXbYztKwOrzVHPg7VNN1qN2IDudqOuJgETiBy8JXvubwsEsb 8jS61M6Mz2CiNwyV1HMi88f8c2bTXzI= X-MC-Unique: wkEv75eBMIC8QugXBnIWCw-1 X-Mimecast-MFC-AGG-ID: wkEv75eBMIC8QugXBnIWCw_1754679565 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754679564; x=1755284364; 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=GR20SJxOKCiR8K6K57Fhm+/qQuSbGQLIipzG4dDVZgA=; b=LaY1nOp/4N3rnVRtQkmj6qyI477YQavNgDKhOvsOnSg400M7RX8QfloSozbt7Ls2AG z688eYtQVvukux0gnrhgul/mCMliA+aOWlFrcgy9yFPvnOzXczK9YmHjHvFI7gCGvuG8 8yO+96kcCW1lrs7K85/5hA+Nn/0zgxQSDTO/F9KXJq6P+6OJdDfVtBPIJ78ND1Oh1cad 9H0m58s1OUX+46Mevrj+H7/0DI8i7SnlNgibBX7OAEuZ1OdEV8F2EWX4Xdfc1AQcXOXj Ev41Lkx74Whxd8fePJtc/wYt6MMuTd9nlDMAFfU9FZcxflPAaiiSOQO++HERPZmHysLm Y8RA== X-Gm-Message-State: AOJu0YwJ/5sGyg3/GJ6ASgVQoy/44YuhiC8qliozM8u1ca/Ri50P+jkj QZshFF1VrXEFx34lHY4OYJ955tMdvuVBeaoOKygOn2PRSvithRDGHxg6tpZ/dnQYG7jAChTZWJp veZD7KdOLDraOHRyIz8Z0dmbJHavw/5dDikaj8/7NKJveBmlA+ue9SbICVZFw8ytsyDW7OQvtfn edAC1p/CVpPS3jUOo/jlM0VkSRNpvcuedg11hbA0Dw X-Gm-Gg: ASbGncu23qpBaWusQa4svh9US6qEu6PR2voziiPhUroWuTZpGIW6FlRUOfUBNjmmQ7n 7mNlgAUFjaLJTwxYefcbwcrEGXYYfpA4/EmePccIrRT3PWGMRUNTOq5ymm2fRuY0RNKqNSPFaCX +OoT0XVzdh60cPBzGQHryjEiEKnyRwRcIvBjwDZKoCW2ZzP0EJHNDu7ByL/4V9xxWJmxqp1xUS2 n1YRNSzzg9MYaSgUiG9UHczJI6g8cJfYUTSZvN5GOX4lDKPAbJCJqBYDC8W1LxJsrdRbNCTmDz/ ZA/3vLCmzf6aZm6vmjlt2ww0A0T/DVbUNGtVtaD+fUaN X-Received: by 2002:a05:600c:4e91:b0:453:6ca:16b1 with SMTP id 5b1f17b1804b1-459f4f144e5mr36298675e9.26.1754679564434; Fri, 08 Aug 2025 11:59:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEawRKQ8Tc2kCFvCDikBq3ptfnro+jhhc8U/Uz/xrcJEVoI0Z/mBXfuswn3UhV8+px8DgOYYQ== X-Received: by 2002:a05:600c:4e91:b0:453:6ca:16b1 with SMTP id 5b1f17b1804b1-459f4f144e5mr36298515e9.26.1754679563917; Fri, 08 Aug 2025 11:59:23 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: imammedo@redhat.com, richard.henderson@linaro.org, peterx@redhat.com Subject: [PATCH 6/8] cpus: properly kick CPUs out of inner execution loop Date: Fri, 8 Aug 2025 20:59:03 +0200 Message-ID: <20250808185905.62776-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250808185905.62776-1-pbonzini@redhat.com> References: <20250808185905.62776-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1754679635329124100 Content-Type: text/plain; charset="utf-8" Now that cpu_exit() actually kicks all accelerators, use it whenever the message to another thread is processed in qemu_wait_io_event() Signed-off-by: Paolo Bonzini --- cpu-common.c | 3 ++- hw/ppc/ppc.c | 2 ++ hw/ppc/spapr_hcall.c | 7 +++---- hw/ppc/spapr_rtas.c | 2 +- replay/replay-events.c | 3 ++- system/cpu-timers.c | 6 +++--- system/cpus.c | 5 +++-- target/arm/tcg/mte_helper.c | 2 +- target/i386/kvm/hyperv.c | 1 - 9 files changed, 17 insertions(+), 14 deletions(-) diff --git a/cpu-common.c b/cpu-common.c index ef5757d23bf..152661df8e9 100644 --- a/cpu-common.c +++ b/cpu-common.c @@ -137,7 +137,8 @@ static void queue_work_on_cpu(CPUState *cpu, struct qem= u_work_item *wi) wi->done =3D false; qemu_mutex_unlock(&cpu->work_mutex); =20 - qemu_cpu_kick(cpu); + /* exit the inner loop and reach qemu_wait_io_event_common(). */ + cpu_exit(cpu); } =20 void do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data da= ta, diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c index 43d0d0e7553..3e436c70413 100644 --- a/hw/ppc/ppc.c +++ b/hw/ppc/ppc.c @@ -190,6 +190,7 @@ static void ppc970_set_irq(void *opaque, int pin, int l= evel) if (level) { trace_ppc_irq_cpu("stop"); cs->halted =3D 1; + cpu_exit(cs); } else { trace_ppc_irq_cpu("restart"); cs->halted =3D 0; @@ -386,6 +387,7 @@ static void ppc40x_set_irq(void *opaque, int pin, int l= evel) if (level) { trace_ppc_irq_cpu("stop"); cs->halted =3D 1; + cpu_exit(cs); } else { trace_ppc_irq_cpu("restart"); cs->halted =3D 0; diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index 03a62b047b3..a64320214b4 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -509,8 +509,8 @@ static target_ulong h_cede(PowerPCCPU *cpu, SpaprMachin= eState *spapr, if (!cpu_has_work(cs)) { cs->halted =3D 1; cs->exception_index =3D EXCP_HLT; - qatomic_set(&cs->exit_request, 1); ppc_maybe_interrupt(env); + cpu_exit(env); } =20 return H_SUCCESS; @@ -531,8 +531,8 @@ static target_ulong h_confer_self(PowerPCCPU *cpu) } cs->halted =3D 1; cs->exception_index =3D EXCP_HALTED; - qatomic_set(&cs->exit_request, 1); ppc_maybe_interrupt(&cpu->env); + cpu_exit(&cpu->env); =20 return H_SUCCESS; } @@ -624,8 +624,7 @@ static target_ulong h_confer(PowerPCCPU *cpu, SpaprMach= ineState *spapr, } =20 cs->exception_index =3D EXCP_YIELD; - qatomic_set(&cs->exit_request, 1); - cpu_loop_exit(cs); + cpu_exit(cs); =20 return H_SUCCESS; } diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c index 78309dbb09d..143bc8c3794 100644 --- a/hw/ppc/spapr_rtas.c +++ b/hw/ppc/spapr_rtas.c @@ -221,7 +221,7 @@ static void rtas_stop_self(PowerPCCPU *cpu, SpaprMachin= eState *spapr, cs->halted =3D 1; ppc_store_lpcr(cpu, env->spr[SPR_LPCR] & ~pcc->lpcr_pm); kvmppc_set_reg_ppc_online(cpu, 0); - qemu_cpu_kick(cs); + cpu_exit(cs); } =20 static void rtas_ibm_suspend_me(PowerPCCPU *cpu, SpaprMachineState *spapr, diff --git a/replay/replay-events.c b/replay/replay-events.c index 8959da9f1fa..a96e47e7740 100644 --- a/replay/replay-events.c +++ b/replay/replay-events.c @@ -118,7 +118,8 @@ void replay_add_event(ReplayAsyncEventKind event_kind, =20 g_assert(replay_mutex_locked()); QTAILQ_INSERT_TAIL(&events_list, event, events); - qemu_cpu_kick(first_cpu); + /* Kick the TCG thread out of tcg_cpu_exec(). */ + cpu_exit(first_cpu); } =20 void replay_bh_schedule_event(QEMUBH *bh) diff --git a/system/cpu-timers.c b/system/cpu-timers.c index cb35fa62b8a..6a00691b8d5 100644 --- a/system/cpu-timers.c +++ b/system/cpu-timers.c @@ -246,14 +246,14 @@ void qemu_timer_notify_cb(void *opaque, QEMUClockType= type) =20 if (qemu_in_vcpu_thread()) { /* - * A CPU is currently running; kick it back out to the + * A CPU is currently running; kick it back out of the * tcg_cpu_exec() loop so it will recalculate its * icount deadline immediately. */ - qemu_cpu_kick(current_cpu); + cpu_exit(current_cpu); } else if (first_cpu) { /* - * qemu_cpu_kick is not enough to kick a halted CPU out of + * cpu_exit() is not enough to kick a halted CPU out of * qemu_tcg_wait_io_event. async_run_on_cpu, instead, * causes cpu_thread_is_idle to return false. This way, * handle_icount_deadline can run. diff --git a/system/cpus.c b/system/cpus.c index 8e543488c30..d2cfa2a9c4e 100644 --- a/system/cpus.c +++ b/system/cpus.c @@ -599,7 +599,7 @@ void cpu_pause(CPUState *cpu) qemu_cpu_stop(cpu, true); } else { cpu->stop =3D true; - qemu_cpu_kick(cpu); + cpu_exit(cpu); } } =20 @@ -639,6 +639,7 @@ void pause_all_vcpus(void) =20 while (!all_vcpus_paused()) { qemu_cond_wait(&qemu_pause_cond, &bql); + /* FIXME: is this needed? */ CPU_FOREACH(cpu) { qemu_cpu_kick(cpu); } @@ -667,7 +668,7 @@ void cpu_remove_sync(CPUState *cpu) { cpu->stop =3D true; cpu->unplug =3D true; - qemu_cpu_kick(cpu); + cpu_exit(cpu); bql_unlock(); qemu_thread_join(cpu->thread); bql_lock(); diff --git a/target/arm/tcg/mte_helper.c b/target/arm/tcg/mte_helper.c index 0efc18a181e..302e899287c 100644 --- a/target/arm/tcg/mte_helper.c +++ b/target/arm/tcg/mte_helper.c @@ -591,7 +591,7 @@ static void mte_async_check_fail(CPUARMState *env, uint= 64_t dirty_ptr, * which is rather sooner than "normal". But the alternative * is waiting until the next syscall. */ - qemu_cpu_kick(env_cpu(env)); + cpu_exit(env_cpu(env)); #endif } =20 diff --git a/target/i386/kvm/hyperv.c b/target/i386/kvm/hyperv.c index 9865120cc43..f7a81bd2700 100644 --- a/target/i386/kvm/hyperv.c +++ b/target/i386/kvm/hyperv.c @@ -81,7 +81,6 @@ int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exi= t *exit) * necessary because memory hierarchy is being changed */ async_safe_run_on_cpu(CPU(cpu), async_synic_update, RUN_ON_CPU_NUL= L); - cpu_exit(CPU(cpu)); =20 return EXCP_INTERRUPT; case KVM_EXIT_HYPERV_HCALL: { --=20 2.50.1 From nobody Sat Sep 6 00:37:16 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1754679694; cv=none; d=zohomail.com; s=zohoarc; b=QHP68JTalnNIQVg8sQwjuWzmTU24u2TsId58AZdv0jlzt3VXRn2UCL3UfiBlohLyUsJy1Rf37htNk5dlVvZmeirkSWM0eP9lOV4YjreiDgwl7ovuzJikJ6hX/n2tnKEzK4sBlvGXBc6GkPyp8ajo2a8VXiJUPu3xAABtJTgnDuI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1754679694; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=jn820PJK97/jK7UY+QSi/KFlnTyM5eBHCqtQu4mxZHw=; b=AjpglTNpFHVPj/Rv+7YWmPnbzqljthJTwynhr10IoWe20YNlGl2n6bQKkAHC+BWk5CtfmZvB9+VI77dOVAgmiMKQyQPtkpOlxu7N6SlUyfZDqNiqkyv0ucy/4p7N+hPmFo2M2n9Xy1p0rR8yvVPcFPYKHid2qUrOcD0ptDtuJfw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1754679694681273.68623771635805; Fri, 8 Aug 2025 12:01:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ukSJR-0006HQ-Hi; Fri, 08 Aug 2025 14:59:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ukSJQ-0006H0-CT for qemu-devel@nongnu.org; Fri, 08 Aug 2025 14:59:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ukSJO-0006gm-QL for qemu-devel@nongnu.org; Fri, 08 Aug 2025 14:59:32 -0400 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-413-Pd0OcQsAPiS-tQYIPoZ0sA-1; Fri, 08 Aug 2025 14:59:29 -0400 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-3b7891afb31so1625396f8f.2 for ; Fri, 08 Aug 2025 11:59:28 -0700 (PDT) Received: from [192.168.10.48] ([151.49.234.144]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b79c3bf956sm31951038f8f.24.2025.08.08.11.59.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Aug 2025 11:59:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1754679570; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jn820PJK97/jK7UY+QSi/KFlnTyM5eBHCqtQu4mxZHw=; b=TDyY87h7SZwmHH0VP2wENwLBP1cBY/tw2xB3BXAPvlL27ANiHgSP8OkwL5nByzvs4eChYh DdF7zz9InVIAawgFams1XVj3/xkl4uPedZyF+tsofeD7t9sxYaOrcEL4RpMip5+bE+VbpQ 2WrD/j+iEzPQi9HGXspIDPIBr8gCjX8= X-MC-Unique: Pd0OcQsAPiS-tQYIPoZ0sA-1 X-Mimecast-MFC-AGG-ID: Pd0OcQsAPiS-tQYIPoZ0sA_1754679568 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754679567; x=1755284367; 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=jn820PJK97/jK7UY+QSi/KFlnTyM5eBHCqtQu4mxZHw=; b=t+86ySx9u1jtC0aSkLpy1G4ZG+bGxhUO5bEpCLIir6kL1c3pSnrKwiVsrNtW3U08SP ji8WlU3UAFD+pnDDXNkCaNMAepgwqVmGX+wu54EyWJbQlP5ZNfw1vKpWUN+oXGK+yX8a EwEldvswfvpDmCW4yY/NCJbr2y52P7cWcO+QgXjha+IV5HK0BxrfMLsNXeQf/34qdnwk hoVdNTc8i9+6NHeujGIexMPFjRfBamgs9LXZ8KO7r9aTtqJ4sRfvjtyo49eTUQbqCoow 9FygR7eM1oOf2jdfxFoNA3tV7YXGrd+5IRyhEQJwXerrcOCdxpkIV9y9Y2Gal0Cumwzy 1tKQ== X-Gm-Message-State: AOJu0Yw2ctQR5T1Mv6f49SIvvpN0SdObPzsMGkdQShLyhVlSJ4rhjvCJ NTOWghasQhDO+PDThGGlujHgI6zzgVHPpgrn2n4LBS7AlI6PQiWw5TQjkK5bKylN5nLVqyyFJG2 W+bQAsDmosdIVbic4ITURdbCv4oNtRGSe15CkFfH0vtD6eYtu5CXnr3vHVG+yTdqI7VbOfxWPyh F1HwMYVz3+ShLtm8rR/SqkJCrDsRPmCNHzzSDhaiGj X-Gm-Gg: ASbGnct+5U3j9c0O2GJ84PV3Te2HuVQ7vWFe3/b6dSp3QD+DQQimIMW0TToRwQ7JNOt mvKHFOJj1eafFUeKb07LlOsIZRTksJgKg9gM3ocMC2oLBbRAE4Ez36t54CVIaTd5v1KIA2V1QFI +9lz7UomFrJv5MUWooW2Z7fafRdertWcK3gq2Nx5FzRCa2eGULsvNX+CuA3yQf45ESNki7ojH7u AYm0gpOC6IE3ye+k8LxLfwl9MZY9Iuf/72xwQzRSQZ5yCNqojtmHDr1GOpvPPaMZV4ctUXFTeMy 3mECsNz1HOiLDGvlI1aeigvGXgqJF6wCSXzAVpb55Gse X-Received: by 2002:a05:6000:420a:b0:3b7:9617:c9d6 with SMTP id ffacd0b85a97d-3b900b7afe2mr3471457f8f.45.1754679566819; Fri, 08 Aug 2025 11:59:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE38YB5T//0PzEBQHbysY3Y/CO4jeFWOCOR3tBEP21/Bb0VSkd6UejIymhJ8hEDozInVG+mCg== X-Received: by 2002:a05:6000:420a:b0:3b7:9617:c9d6 with SMTP id ffacd0b85a97d-3b900b7afe2mr3471440f8f.45.1754679566334; Fri, 08 Aug 2025 11:59:26 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: imammedo@redhat.com, richard.henderson@linaro.org, peterx@redhat.com Subject: [PATCH 7/8] tcg/user: do not set exit_request gratuitously Date: Fri, 8 Aug 2025 20:59:04 +0200 Message-ID: <20250808185905.62776-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250808185905.62776-1-pbonzini@redhat.com> References: <20250808185905.62776-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1754679697485116600 Content-Type: text/plain; charset="utf-8" User-mode emulation correctly uses cpu_exit() whenever it needs to go all the way out of the cpu exec loop. It never uses qemu_cpu_kick(); therefore, there is no need for tcg_kick_vcpu_thread() to set cpu->exit_request again. Signed-off-by: Paolo Bonzini --- accel/tcg/cpu-exec.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c index 1a973596d87..b9da2e3770e 100644 --- a/accel/tcg/cpu-exec.c +++ b/accel/tcg/cpu-exec.c @@ -750,6 +750,7 @@ static inline bool cpu_handle_exception(CPUState *cpu, = int *ret) =20 void tcg_kick_vcpu_thread(CPUState *cpu) { +#ifdef CONFIG_SYSTEM /* * Ensure cpu_exec will see the reason why the exit request was set. * FIXME: this is not always needed. Other accelerators instead @@ -757,6 +758,7 @@ void tcg_kick_vcpu_thread(CPUState *cpu) * CPU thread; see kvm_arch_pre_run() for example. */ qatomic_store_release(&cpu->exit_request, 1); +#endif =20 /* Ensure cpu_exec will see the exit request after TCG has exited. */ qatomic_store_release(&cpu->neg.icount_decr.u16.high, -1); --=20 2.50.1 From nobody Sat Sep 6 00:37:16 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1754679624; cv=none; d=zohomail.com; s=zohoarc; b=ZyPb9e285F6PhtTAEpXJ7zZrMw2UAW8Qv7oCRoD3D8frW6w7Axk2l9D8Ride/Q1kA6+NibUVrMUyOHyU43z9BrzX4TuQ6g8xQnGPVUi9Q20L/6SuHUnB2kRbkcrfKN8OfkQNvOfjROfY1/kbSU13ow6ys36DOHAke8rv8s+NXtc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1754679624; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=d2XHvUBpwg8VKpJHI1tJuy/t/ZJPlJT11M9aWPvcQuQ=; b=Vsux6b/1Q2cvOV+4vARAPdtmGotG0eGRqp0/3Kkpwv8G2nvLwCldWiQqEmB32QusMK0CW1EB3x/bmKoKFSLTd1nIbdlCPyCqNCh6iyyo0EsU/c560bex1HYV7cpg2iJGCAlVql4h0ZsrlnZp0ZAm+PdC9//25dDTGcQINz9rMGU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1754679624930205.04254819980054; Fri, 8 Aug 2025 12:00:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ukSJW-0006Ij-Fu; Fri, 08 Aug 2025 14:59:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ukSJT-0006I0-Pu for qemu-devel@nongnu.org; Fri, 08 Aug 2025 14:59:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ukSJR-0006hF-SL for qemu-devel@nongnu.org; Fri, 08 Aug 2025 14:59:35 -0400 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-515-og6S16JpMlOFh_pzZNUFpw-1; Fri, 08 Aug 2025 14:59:31 -0400 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-3b7886bfc16so1463292f8f.1 for ; Fri, 08 Aug 2025 11:59:31 -0700 (PDT) Received: from [192.168.10.48] ([151.49.234.144]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b79c469582sm30574957f8f.52.2025.08.08.11.59.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Aug 2025 11:59:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1754679573; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=d2XHvUBpwg8VKpJHI1tJuy/t/ZJPlJT11M9aWPvcQuQ=; b=OT9sAmlDV9vfVKvG0XhKvYmuPnWzogENncscjJcaWLzjKDIPuO8ISXLAYIz3/3gO5XUe/3 uL8JDyJlbjaAzS6AhlbUpUWKhgnzsqAwiL1yvKQCW3YOg2pURs9je6ZgOfA8aguG2Wi/s6 Tbi1Eo3c+A3ZxIWGKMKsKR0c6CUX370= X-MC-Unique: og6S16JpMlOFh_pzZNUFpw-1 X-Mimecast-MFC-AGG-ID: og6S16JpMlOFh_pzZNUFpw_1754679571 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754679570; x=1755284370; 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=d2XHvUBpwg8VKpJHI1tJuy/t/ZJPlJT11M9aWPvcQuQ=; b=TiseESi3SMWd8FTN4b+Sa03PlgVRqDjDaPvv8bhrGt7FuYZHMACWOSBqXlTwrlCxnY QQkMYtDpajdC9ZjeB7IgqPeE1uoU2fYFVjWTxfRHx5bI951tYdXTbRrICsBBTrCT0Wvp 24cHFayKyeqHF2zjHdtOuP6Y+TuwmWyotQ/zeUegRXWPBGN5JJhA/wUHQ16A8DT323H7 OQ4J2ak90dTyv3nN0fVqW9awfv72H0UQzou5m+n1TjAdPtxmQNgnRsEVnAJNvljkayGU rwgTHpI84aRNa7b6VfgndGt0pVoo/8qdN4SGH0j51MUqYzCnpbK3QNLmGkGcSY452ocn si5w== X-Gm-Message-State: AOJu0Yw1n7CzTGnXmxb0v9c2Ch1Tbc1x7SuZ4xrqKCTp6MXahc50Nxwl S4nYxyrUDPFmz/oESX8SjiTPZ92I44u7ObskTqCnX3EPJ6kNu6sLtz3OSkJtEPCVTm8i+NU1PBt B35okoJbvw4GpJFBNC6qZJq/q7oY4izHK1hVk8LGez5l8V8V+MnOb7ig77g85tN3ABttXT4Do9+ eMSIHtw1kgyebhNxXgiVDQhclltHiP6+jyjLVSKpzI X-Gm-Gg: ASbGncuwxmEzrBGJcuzcJ4XyxBXZpR4/YdetVmR010WoJYiUDGSEZ83pCZ7R04A/UVf J9iJKxTM4KaRpsLg7JzWQ2MNe4PIIa0m9NIzYgurxJUISWVirkjR1IOG99PhNKFRdbqeZDeHPNr O0NfQ25/SdqWTEaQkwcVdj6lk6aqW5+heGQHZnOt8qN0Gh59fmAXzEiYaADamJ/Oe3xd+n+o6OH RZgGt4e4xR3tX6PmFxnKaQ/a6uBA/3Obk2yImzGrNuhmMmKj9Yvz6HYNb4tsV4Dg1RVHMUeu2Me e0tM+jFg4NMDcceYosCnkQi/+AV/+CUcbV50r54LJmvB X-Received: by 2002:a5d:5d0c:0:b0:3a4:f8fa:8a3a with SMTP id ffacd0b85a97d-3b900b4d2edmr3042324f8f.18.1754679569563; Fri, 08 Aug 2025 11:59:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGUja3DQXvAKiNWluT9lmBxnTPvUxuFbWd4C59nbnBnbB1ud7Pd3+gKhdVZ5S981JR+z010gQ== X-Received: by 2002:a5d:5d0c:0:b0:3a4:f8fa:8a3a with SMTP id ffacd0b85a97d-3b900b4d2edmr3042305f8f.18.1754679569028; Fri, 08 Aug 2025 11:59:29 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: imammedo@redhat.com, richard.henderson@linaro.org, peterx@redhat.com Subject: [PATCH 8/8] accel: make all calls to qemu_wait_io_event look the same Date: Fri, 8 Aug 2025 20:59:05 +0200 Message-ID: <20250808185905.62776-9-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250808185905.62776-1-pbonzini@redhat.com> References: <20250808185905.62776-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1754679627025116600 Content-Type: text/plain; charset="utf-8" There is no reason for some accelerators to use qemu_wait_io_event_common (which is specifically separated for round robin). They can also check on the first pass through the loop as well directly, without setting cpu->exit_request for no particular reason. There is also no need to use qatomic_set_mb() because the ordering of the communication between I/O and vCPU threads is always the same. In the I/O thread: (a) store other memory locations that will be checked if cpu->exit_request or cpu->interrupt_request is 1 (for example cpu->stop or cpu->work_list for cpu->exit_request) (b) cpu_exit(): store-release cpu->exit_request, or (b) cpu_interrupt(): store-release cpu->interrupt_request >>> at this point, cpu->halt_cond is broadcast and the BQL released (c) do the accelerator-specific kick (e.g. write icount_decr for TCG, pthread_kill for KVM, etc.) In the vCPU thread instead the opposite order is respected: (c) the accelerator's execution loop exits thanks to the kick (b) then the inner execution loop checks cpu->interrupt_request and cpu->exit_request. If needed cpu->interrupt_request is converted into cpu->exit_request when work is needed outside the execution loop. (a) then the other memory locations are checked. Some may need to be read under the BQL, and the vCPU thread may also take for the vCPU thread can sleep on cpu->halt_cond; but in principle this step is correct even without the BQL. Signed-off-by: Paolo Bonzini Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- accel/dummy-cpus.c | 2 +- accel/hvf/hvf-accel-ops.c | 2 +- accel/kvm/kvm-accel-ops.c | 3 ++- accel/kvm/kvm-all.c | 2 -- accel/tcg/cpu-exec.c | 1 - accel/tcg/tcg-accel-ops-mttcg.c | 7 ++---- accel/tcg/tcg-accel-ops-rr.c | 38 ++++++++++++++++--------------- accel/tcg/tcg-accel-ops.c | 2 -- system/cpus.c | 1 + target/i386/nvmm/nvmm-accel-ops.c | 6 ++--- target/i386/nvmm/nvmm-all.c | 2 -- target/i386/whpx/whpx-accel-ops.c | 6 ++--- target/i386/whpx/whpx-all.c | 2 -- 13 files changed, 31 insertions(+), 43 deletions(-) diff --git a/accel/dummy-cpus.c b/accel/dummy-cpus.c index 03cfc0fa01e..1f74c727c42 100644 --- a/accel/dummy-cpus.c +++ b/accel/dummy-cpus.c @@ -43,6 +43,7 @@ static void *dummy_cpu_thread_fn(void *arg) qemu_guest_random_seed_thread_part2(cpu->random_seed); =20 do { + qemu_wait_io_event(cpu); bql_unlock(); #ifndef _WIN32 do { @@ -57,7 +58,6 @@ static void *dummy_cpu_thread_fn(void *arg) qemu_sem_wait(&cpu->sem); #endif bql_lock(); - qemu_wait_io_event(cpu); } while (!cpu->unplug); =20 bql_unlock(); diff --git a/accel/hvf/hvf-accel-ops.c b/accel/hvf/hvf-accel-ops.c index d488d6afbac..4ba3e40831f 100644 --- a/accel/hvf/hvf-accel-ops.c +++ b/accel/hvf/hvf-accel-ops.c @@ -192,13 +192,13 @@ static void *hvf_cpu_thread_fn(void *arg) qemu_guest_random_seed_thread_part2(cpu->random_seed); =20 do { + qemu_wait_io_event(cpu); if (cpu_can_run(cpu)) { r =3D hvf_vcpu_exec(cpu); if (r =3D=3D EXCP_DEBUG) { cpu_handle_guest_debug(cpu); } } - qemu_wait_io_event(cpu); } while (!cpu->unplug || cpu_can_run(cpu)); =20 hvf_vcpu_destroy(cpu); diff --git a/accel/kvm/kvm-accel-ops.c b/accel/kvm/kvm-accel-ops.c index b709187c7d7..80f0141a8a6 100644 --- a/accel/kvm/kvm-accel-ops.c +++ b/accel/kvm/kvm-accel-ops.c @@ -47,13 +47,14 @@ static void *kvm_vcpu_thread_fn(void *arg) qemu_guest_random_seed_thread_part2(cpu->random_seed); =20 do { + qemu_wait_io_event(cpu); + if (cpu_can_run(cpu)) { r =3D kvm_cpu_exec(cpu); if (r =3D=3D EXCP_DEBUG) { cpu_handle_guest_debug(cpu); } } - qemu_wait_io_event(cpu); } while (!cpu->unplug || cpu_can_run(cpu)); =20 kvm_destroy_vcpu(cpu); diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 57e35960125..db95e06e768 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -3155,7 +3155,6 @@ int kvm_cpu_exec(CPUState *cpu) trace_kvm_cpu_exec(); =20 if (kvm_arch_process_async_events(cpu)) { - qatomic_set(&cpu->exit_request, 0); return EXCP_HLT; } =20 @@ -3345,7 +3344,6 @@ int kvm_cpu_exec(CPUState *cpu) vm_stop(RUN_STATE_INTERNAL_ERROR); } =20 - qatomic_set(&cpu->exit_request, 0); return ret; } =20 diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c index b9da2e3770e..f474ccb37f5 100644 --- a/accel/tcg/cpu-exec.c +++ b/accel/tcg/cpu-exec.c @@ -871,7 +871,6 @@ static inline bool cpu_handle_interrupt(CPUState *cpu, * The corresponding store-release is in cpu_exit. */ if (unlikely(qatomic_load_acquire(&cpu->exit_request)) || icount_exit_= request(cpu)) { - qatomic_set(&cpu->exit_request, 0); if (cpu->exception_index =3D=3D -1) { cpu->exception_index =3D EXCP_INTERRUPT; } diff --git a/accel/tcg/tcg-accel-ops-mttcg.c b/accel/tcg/tcg-accel-ops-mttc= g.c index 5757324a8c2..04012900a30 100644 --- a/accel/tcg/tcg-accel-ops-mttcg.c +++ b/accel/tcg/tcg-accel-ops-mttcg.c @@ -84,10 +84,9 @@ static void *mttcg_cpu_thread_fn(void *arg) cpu_thread_signal_created(cpu); qemu_guest_random_seed_thread_part2(cpu->random_seed); =20 - /* process any pending work */ - qatomic_set(&cpu->exit_request, 1); - do { + qemu_wait_io_event(cpu); + if (cpu_can_run(cpu)) { int r; bql_unlock(); @@ -112,8 +111,6 @@ static void *mttcg_cpu_thread_fn(void *arg) break; } } - - qemu_wait_io_event(cpu); } while (!cpu->unplug || cpu_can_run(cpu)); =20 tcg_cpu_destroy(cpu); diff --git a/accel/tcg/tcg-accel-ops-rr.c b/accel/tcg/tcg-accel-ops-rr.c index 87b49377c78..205f379b6f8 100644 --- a/accel/tcg/tcg-accel-ops-rr.c +++ b/accel/tcg/tcg-accel-ops-rr.c @@ -211,13 +211,30 @@ static void *rr_cpu_thread_fn(void *arg) =20 cpu =3D first_cpu; =20 - /* process any pending work */ - qatomic_set(&cpu->exit_request, 1); - while (1) { /* Only used for icount_enabled() */ int64_t cpu_budget =3D 0; =20 + if (cpu) { + /* + * This could even reset exit_request for all CPUs, but in pra= ctice + * races between CPU exits and changes to "cpu" are so rare th= at + * there's no advantage in doing so. + */ + qatomic_set(&cpu->exit_request, 0); + } + + if (icount_enabled() && all_cpu_threads_idle()) { + /* + * When all cpus are sleeping (e.g in WFI), to avoid a deadlock + * in the main_loop, wake it up in order to start the warp tim= er. + */ + qemu_notify_event(); + } + + rr_wait_io_event(); + rr_deal_with_unplugged_cpus(); + bql_unlock(); replay_mutex_lock(); bql_lock(); @@ -285,21 +302,6 @@ static void *rr_cpu_thread_fn(void *arg) =20 /* Does not need a memory barrier because a spurious wakeup is oka= y. */ qatomic_set(&rr_current_cpu, NULL); - - if (cpu && qatomic_read(&cpu->exit_request)) { - qatomic_set_mb(&cpu->exit_request, 0); - } - - if (icount_enabled() && all_cpu_threads_idle()) { - /* - * When all cpus are sleeping (e.g in WFI), to avoid a deadlock - * in the main_loop, wake it up in order to start the warp tim= er. - */ - qemu_notify_event(); - } - - rr_wait_io_event(); - rr_deal_with_unplugged_cpus(); } =20 g_assert_not_reached(); diff --git a/accel/tcg/tcg-accel-ops.c b/accel/tcg/tcg-accel-ops.c index f4d5372866a..ad3f29107e1 100644 --- a/accel/tcg/tcg-accel-ops.c +++ b/accel/tcg/tcg-accel-ops.c @@ -82,8 +82,6 @@ int tcg_cpu_exec(CPUState *cpu) ret =3D cpu_exec(cpu); cpu_exec_end(cpu); =20 - qatomic_set_mb(&cpu->exit_request, 0); - return ret; } =20 diff --git a/system/cpus.c b/system/cpus.c index d2cfa2a9c4e..0cc14eae6a0 100644 --- a/system/cpus.c +++ b/system/cpus.c @@ -458,6 +458,7 @@ void qemu_wait_io_event(CPUState *cpu) { bool slept =3D false; =20 + qatomic_set(&cpu->exit_request, false); while (cpu_thread_is_idle(cpu)) { if (!slept) { slept =3D true; diff --git a/target/i386/nvmm/nvmm-accel-ops.c b/target/i386/nvmm/nvmm-acce= l-ops.c index 3658a583bc8..6d2e2542d80 100644 --- a/target/i386/nvmm/nvmm-accel-ops.c +++ b/target/i386/nvmm/nvmm-accel-ops.c @@ -42,16 +42,14 @@ static void *qemu_nvmm_cpu_thread_fn(void *arg) qemu_guest_random_seed_thread_part2(cpu->random_seed); =20 do { + qemu_wait_io_event(cpu); + if (cpu_can_run(cpu)) { r =3D nvmm_vcpu_exec(cpu); if (r =3D=3D EXCP_DEBUG) { cpu_handle_guest_debug(cpu); } } - while (cpu_thread_is_idle(cpu)) { - qemu_cond_wait_bql(cpu->halt_cond); - } - qemu_wait_io_event_common(cpu); } while (!cpu->unplug || cpu_can_run(cpu)); =20 nvmm_destroy_vcpu(cpu); diff --git a/target/i386/nvmm/nvmm-all.c b/target/i386/nvmm/nvmm-all.c index d2d90f38976..09839d45b92 100644 --- a/target/i386/nvmm/nvmm-all.c +++ b/target/i386/nvmm/nvmm-all.c @@ -817,8 +817,6 @@ nvmm_vcpu_loop(CPUState *cpu) cpu_exec_end(cpu); bql_lock(); =20 - qatomic_set(&cpu->exit_request, false); - return ret < 0; } =20 diff --git a/target/i386/whpx/whpx-accel-ops.c b/target/i386/whpx/whpx-acce= l-ops.c index da58805b1a6..611eeedeef7 100644 --- a/target/i386/whpx/whpx-accel-ops.c +++ b/target/i386/whpx/whpx-accel-ops.c @@ -42,16 +42,14 @@ static void *whpx_cpu_thread_fn(void *arg) qemu_guest_random_seed_thread_part2(cpu->random_seed); =20 do { + qemu_wait_io_event(cpu); + if (cpu_can_run(cpu)) { r =3D whpx_vcpu_exec(cpu); if (r =3D=3D EXCP_DEBUG) { cpu_handle_guest_debug(cpu); } } - while (cpu_thread_is_idle(cpu)) { - qemu_cond_wait_bql(cpu->halt_cond); - } - qemu_wait_io_event_common(cpu); } while (!cpu->unplug || cpu_can_run(cpu)); =20 whpx_destroy_vcpu(cpu); diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index 9b07716121a..2e248a0a6d5 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -2050,8 +2050,6 @@ static int whpx_vcpu_run(CPUState *cpu) whpx_last_vcpu_stopping(cpu); } =20 - qatomic_set(&cpu->exit_request, false); - return ret < 0; } =20 --=20 2.50.1