From nobody Mon Apr 6 23:20:38 2026 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=1773755175; cv=none; d=zohomail.com; s=zohoarc; b=gNBYMcwhghQlab9SRJoC6VvzRnxj71y2l340CLOLrmFctNylAXMXB/mYOM9YHmrvDn9XC7mAkrrlQ8GzK1RYKFuFI2qwIQ1gmTtlLZ9SQfQoh0UVs6g1w9M/5+NLQvqP8mqZkAp5NU5AALk0+NCKEvctxsSJfEzDIduvmefywWo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773755175; h=Content-Type: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=1Pn5XlEm9Bn7b0QdwUqHqGL4YyqtI7Hz3+MDuG/pbFk=; b=CnPrtqOh1jyxoRsDUrv5QVLd3TaZSmKU4/vCnCbIsh+NlNk+c4ohIoSCLGhZG4fWiQh1FGJhBJtTYfaYYxEeFa/pSuKRDiWZlEKrVViYB3Eswu/5p4URB1MCKDD+yH1mHB2c0mrTArvB2HEUEvFYiKLK2ctPKk4X45/6MDk6Jy8= 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 177375517555996.80392360789904; Tue, 17 Mar 2026 06:46:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w2Ujy-0007nV-CM; Tue, 17 Mar 2026 09:45:46 -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 1w2Ujv-0007lN-JX for qemu-devel@nongnu.org; Tue, 17 Mar 2026 09:45:43 -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 1w2Ujq-0002Ao-8J for qemu-devel@nongnu.org; Tue, 17 Mar 2026 09:45:40 -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-135-6xWL_jTrNPOzRVW6g8Xqag-1; Tue, 17 Mar 2026 09:45:36 -0400 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4868e691614so4222475e9.1 for ; Tue, 17 Mar 2026 06:45:35 -0700 (PDT) Received: from localhost (p200300cfd737d0a83481d97604204561.dip0.t-ipconnect.de. [2003:cf:d737:d0a8:3481:d976:420:4561]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43a03cfd18fsm40701746f8f.36.2026.03.17.06.45.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Mar 2026 06:45:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1773755137; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1Pn5XlEm9Bn7b0QdwUqHqGL4YyqtI7Hz3+MDuG/pbFk=; b=BBCLsqW5lKtF+tq9MyHNjPIzMrkHcefaIA5pXGIVAJr7fzXbYrwQmPGEcv3eDlNBrmE4ce g0lEkQ02869ZFQUVywF6DvloTsB66sHEBXDx+76qSNJLcW8TAS7etWk9n1J6Ok7UOvyEFd ymvB9lUyaaAqLcWxN1XeiCpmnhZu9vM= X-MC-Unique: 6xWL_jTrNPOzRVW6g8Xqag-1 X-Mimecast-MFC-AGG-ID: 6xWL_jTrNPOzRVW6g8Xqag_1773755135 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1773755134; x=1774359934; darn=nongnu.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=1Pn5XlEm9Bn7b0QdwUqHqGL4YyqtI7Hz3+MDuG/pbFk=; b=a1ZqqYJrpv4YpQYf/6QVVqFohf5+yusoBeTy3V7AQyXwZNXB09ABNnB8iUQfnZ/Q22 PTuzrjN9EIWzxojtUftlM71dmqPFMWEvtnrql4bR78SRnKwj/80otz8pd8mpXVbj54yN C+rlc6FRs67wC8Ys3EjoEVQz5gnvtSxFGNxIFV/VB7EOMn3LRqjR1J1zDOYDOKlsLTpJ lwsYEPT+ZlpYkhpSrQTTBzsgZS6l7yADKMDPi8Ckb0/pbROFtw9qYA7yniJzM9BqaXQS TGoEY9dPWoTroJg8+seg79fzjOu8XvrUw9tPJkzphrFR3FuxF5IVRXPHn/831ogFMjxW QkhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773755134; x=1774359934; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=1Pn5XlEm9Bn7b0QdwUqHqGL4YyqtI7Hz3+MDuG/pbFk=; b=IlFG/wTQOyfDqfmmCC3QXAjVn76vZ0euN7nhDFoI+VB8Z3OLMtdMMEuq/YXVhBQqS/ DRxfl1/UpGKFMcphJXvh39s61Jv58yVWidpS7MxTjSBltw0Glg1y0VbE4pfDAPlxfhrN sPBB28Ccb0a5FM1mmqwSXGFktoaPxPRKulQVBJLNnrarbBD2oOA0kOc5E6DSLpS8vD2J +LNGNC7WiwZ/CguNiFjgKT3RiYPl2h2ut3NxawlKPODiZWhpAqJPiGZF8ZUIR4eh9EAg /veaWqzvWJLJcLvPs2ehAD0uHNFUqZF7sMuNTAH/pWV8KRn1W/2W4E2dPHfxvFWLw+HN Oicw== X-Gm-Message-State: AOJu0YyddZvMeq5ex69QS7tDmVMo5uUE9eaPkkJG6FhhWJfFD/gnOwIs oOhohP//cZALLoNNlgwaXZ0otkaqlMhhYH1WS/P0kN9hZZPOLDctncumd5wstmAY+IsAjTnTOjb bKM+PuCqQ4d8fXKuysFsdNx6Br5kyY9K8X1ARyVYsXA8l7HGUaN8LMZM4 X-Gm-Gg: ATEYQzz1p6xxCflm/MuOMA9WYVWSmiGOlnwHeqbcrOHjMwm28bijognGn7jsV8Sl53e sSupnL4vIGx3hib09/qwTeaaWfQ6HaExnpAFHTFzUUt0sGukh9HB65q+5aJe1vgzZappNVgaS89 +DXkTfQKBuYXehT6pzNhu/wqphFwbdQKMheqcZk4S+pIJP89cMqj/rDqbDcvdOM5Xen4P7uULw1 Fvq8I3unUKvLE8UDQ9gOSvWzJu0KvNToxev0ujb6aXyAjKVhmzg4jzxL9UC8ET9ul2Cm8NWGEer SE7BLrVpL0HNSoAoYArx6XN+nSKwEGK1UfrQ2UJWvRKaQ7eUSVugMFvpsBswXGD2xyGRPZGPIKI fGEJ05H7WrYb77pqtC51rIWehI/WvbG/8PF6TvtD4738JiEZ1knrbhw/4l1VIn+ywQD7QiikfCl zwi6U= X-Received: by 2002:a05:600c:46d2:b0:485:3c66:e230 with SMTP id 5b1f17b1804b1-48556728c71mr290417585e9.29.1773755134478; Tue, 17 Mar 2026 06:45:34 -0700 (PDT) X-Received: by 2002:a05:600c:46d2:b0:485:3c66:e230 with SMTP id 5b1f17b1804b1-48556728c71mr290417035e9.29.1773755133889; Tue, 17 Mar 2026 06:45:33 -0700 (PDT) From: Hanna Czenczek To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Czenczek , Kevin Wolf Subject: [PULL 1/2] throttle-group: Fix race condition in throttle_group_restart_queue() Date: Tue, 17 Mar 2026 14:45:20 +0100 Message-ID: <20260317134521.112121-2-hreitz@redhat.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260317134521.112121-1-hreitz@redhat.com> References: <20260317134521.112121-1-hreitz@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=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.819, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.903, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development 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: 1773755191396158500 Content-Type: text/plain; charset="utf-8" From: Alberto Garcia When a timer is fired a pending I/O request is restarted and tg->any_timer_armed is reset so other requests can be scheduled. However we're resetting any_timer_armed first in timer_cb() before the request is actually restarted, and there's a window between both moments in which another thread can arm the same timer, hitting an assertion in throttle_group_restart_queue(). This can be solved by deferring the reset of tg->any_timer_armed to the moment when the queue is actually restarted, which is protected by tg->lock, preventing other threads from arming the timer before that. In addition to that, throttle_group_restart_tgm() is also updated to hold tg->lock while the timer is being inspected. Here we consider three different scenarios: - If the tgm has a timer set, fire it immediately - If another tgm has a timer set, restart the queue anyway - If there is no timer set in this group then simulate a timer that fires immediately, by setting tg->any_timer_armed in order to prevent other threads from arming a timer in the meantime. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3194 Signed-off-by: Alberto Garcia Message-Id: <825598ef34ad384d936da19d634eda75598508f7.1773316842.git.berto@= igalia.com> Signed-off-by: Hanna Czenczek --- block/throttle-groups.c | 79 +++++++++++++++++++++++++++++++---------- 1 file changed, 60 insertions(+), 19 deletions(-) diff --git a/block/throttle-groups.c b/block/throttle-groups.c index 5329ff1fdb..4b1b1944c2 100644 --- a/block/throttle-groups.c +++ b/block/throttle-groups.c @@ -391,6 +391,7 @@ void coroutine_fn throttle_group_co_io_limits_intercept= (ThrottleGroupMember *tgm typedef struct { ThrottleGroupMember *tgm; ThrottleDirection direction; + bool reset_timer_armed; } RestartData; =20 static void coroutine_fn throttle_group_restart_queue_entry(void *opaque) @@ -403,6 +404,9 @@ static void coroutine_fn throttle_group_restart_queue_e= ntry(void *opaque) bool empty_queue; =20 qemu_mutex_lock(&tg->lock); + if (data->reset_timer_armed) { + tg->any_timer_armed[direction] =3D false; + } empty_queue =3D !throttle_group_co_restart_queue(tgm, direction); =20 /* If the request queue was empty then we have to take care of @@ -419,18 +423,23 @@ static void coroutine_fn throttle_group_restart_queue= _entry(void *opaque) } =20 static void throttle_group_restart_queue(ThrottleGroupMember *tgm, - ThrottleDirection direction) + ThrottleDirection direction, + bool reset_timer_armed) { Coroutine *co; RestartData *rd =3D g_new0(RestartData, 1); =20 rd->tgm =3D tgm; rd->direction =3D direction; + rd->reset_timer_armed =3D reset_timer_armed; =20 - /* This function is called when a timer is fired or when - * throttle_group_restart_tgm() is called. Either way, there can + /* If reset_timer_armed is set then this means that this function + * was called when a timer was fired (either from timer_cb() or + * from throttle_group_restart_tgm()). In this case there can * be no timer pending on this tgm at this point */ - assert(!timer_pending(tgm->throttle_timers.timers[direction])); + if (reset_timer_armed) { + assert(!timer_pending(tgm->throttle_timers.timers[direction])); + } =20 qatomic_inc(&tgm->restart_pending); =20 @@ -444,15 +453,50 @@ void throttle_group_restart_tgm(ThrottleGroupMember *= tgm) =20 if (tgm->throttle_state) { for (dir =3D THROTTLE_READ; dir < THROTTLE_MAX; dir++) { - QEMUTimer *t =3D tgm->throttle_timers.timers[dir]; + QEMUTimer *t; + ThrottleState *ts =3D tgm->throttle_state; + ThrottleGroup *tg =3D container_of(ts, ThrottleGroup, ts); + bool reset_timer_armed; + + /* + * This function restarts the tgm's queue immediately. + * This is used for example for callers to drain all requests. + * There are three different scenarios depending on whether + * a timer is armed for this tg and which tgm owns the timer. + */ + + qemu_mutex_lock(&tg->lock); + + t =3D tgm->throttle_timers.timers[dir]; if (timer_pending(t)) { - /* If there's a pending timer on this tgm, fire it now */ + /* + * Case 1: this tgm has a pending timer. + * We can fire the timer immediately. + */ timer_del(t); - timer_cb(tgm, dir); + reset_timer_armed =3D true; + } else if (tg->any_timer_armed[dir]) { + /* + * Case 2: another tgm has a pending timer. + * In this case we can still restart the queue but we + * have to leave any_timer_armed untouched so the + * other tgm's timer is not disrupted. + */ + reset_timer_armed =3D false; } else { - /* Else run the next request from the queue manually */ - throttle_group_restart_queue(tgm, dir); + /* + * Case 3: there is no timer set for this group. + * Here we can simulate a timer that fires immediately, + * so the queue is restarted but no other thread + * can arm a timer in the meantime. + */ + tg->any_timer_armed[dir] =3D true; + reset_timer_armed =3D true; } + + qemu_mutex_unlock(&tg->lock); + + throttle_group_restart_queue(tgm, dir, reset_timer_armed); } } } @@ -499,16 +543,13 @@ void throttle_group_get_config(ThrottleGroupMember *t= gm, ThrottleConfig *cfg) */ static void timer_cb(ThrottleGroupMember *tgm, ThrottleDirection direction) { - ThrottleState *ts =3D tgm->throttle_state; - ThrottleGroup *tg =3D container_of(ts, ThrottleGroup, ts); - - /* The timer has just been fired, so we can update the flag */ - qemu_mutex_lock(&tg->lock); - tg->any_timer_armed[direction] =3D false; - qemu_mutex_unlock(&tg->lock); - - /* Run the request that was waiting for this timer */ - throttle_group_restart_queue(tgm, direction); + /* + * Run the request that was waiting for this timer. + * tg->any_timer_armed needs to be cleared, but we'll do it later + * when the queue is restarted in order to prevent another thread + * from arming the timer before that. + */ + throttle_group_restart_queue(tgm, direction, true); } =20 static void read_timer_cb(void *opaque) --=20 2.53.0 From nobody Mon Apr 6 23:20:38 2026 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=1773755190; cv=none; d=zohomail.com; s=zohoarc; b=k+WbOZl+gcUOJhrZCnSbIGCxvplWENCmkpEmNtbC/qpyfZpgX5yr4rUbxM7ZRmpRXYUT5iVONpzF/dL4hKyr+rWlZrb94MIgAMWVBdfkgf1gzRIz3lmeZRQv5MEyX5NuHHSDFzys6U1Ipkq83yxVtpdEINNKLyC4p1p+wY9tkew= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773755190; h=Content-Type: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=bmGIqL4wPaYFmnanozNn72U4g94lElsPqe9qyukakdI=; b=MvlXAsI28BBsETY9vr6+l1koruUbTu9vZ6SkUgEIpWLcwjlwtzfMGAelG4ixUjjo6Hl/pwSVGOyjVttTPSoAgNuAHSBfzjjmCe61rDp4iQhaIC2BLYby2y0ors+XEo/mhmOy50UmSuYqdE0uOKOsHYriSAU2/xrktlVExRYfMCY= 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 17737551906123.709518103744813; Tue, 17 Mar 2026 06:46:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w2Uk0-0007oi-Gi; Tue, 17 Mar 2026 09:45:48 -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 1w2Ujw-0007m3-SE for qemu-devel@nongnu.org; Tue, 17 Mar 2026 09:45:44 -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 1w2Uju-0002B9-KF for qemu-devel@nongnu.org; Tue, 17 Mar 2026 09:45:44 -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-473-gASXCAACN1iqi9gRVxB6AQ-1; Tue, 17 Mar 2026 09:45:38 -0400 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4839fc4cef6so6812395e9.0 for ; Tue, 17 Mar 2026 06:45:37 -0700 (PDT) Received: from localhost (p200300cfd737d0a83481d97604204561.dip0.t-ipconnect.de. [2003:cf:d737:d0a8:3481:d976:420:4561]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-485563903bbsm193759595e9.0.2026.03.17.06.45.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Mar 2026 06:45:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1773755139; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bmGIqL4wPaYFmnanozNn72U4g94lElsPqe9qyukakdI=; b=Nep4qmsZywoLbycOoZsxGg6WwDjZiDfBrt+PEQNcdHN1rYT6y+I46WhqNwqIHXRGVvyEAA dYHJpDqzZRTvvKV6n7zcGaB9lyJ+GZWu8YvpCXkgzQZ44CJysGA+cizSXoUzSQEPYjpT05 kBhGUCWX0iSqF5BFy1Wy9dP4tMSCQY8= X-MC-Unique: gASXCAACN1iqi9gRVxB6AQ-1 X-Mimecast-MFC-AGG-ID: gASXCAACN1iqi9gRVxB6AQ_1773755137 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1773755136; x=1774359936; darn=nongnu.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=bmGIqL4wPaYFmnanozNn72U4g94lElsPqe9qyukakdI=; b=kQ6TKZJQgNVxYOtsiFwrSw7nddpEAawdtX5NsDSV5UCYhvahYegob/WNx4EubHKCug SZU/hUd/TvCkIT7eV0RhKkyor5xrknngPdinZqoBjX00CVIzetKaGH56LSXlENpq9buk BWOKvcm2tpcOa+HqLzHVXTz5z6UxlJdcqRMmpXjUlpwhYGyBh0wO2nQ/87+judJGLam7 loDhEZExnhdWr+EHWKVIJkRGISXwY4GO/dl0qa3KTdlXk+dJ3KscnTIFkueWNmFnmazG Zk0TejcC2Lg/X5TK65zoDHV1IbsjqVcnxgyd9cD7QBa3At8jAuXHXdq+xhextDYoMwje UHlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773755136; x=1774359936; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=bmGIqL4wPaYFmnanozNn72U4g94lElsPqe9qyukakdI=; b=eOAjOqMtvlZ61zkCugGLiQBs5USM5kqmFcuE3DeEiJiV0IB9QGIijfCKyp8g/WBhSX TG2tpdvLjGj1yBk5PTHRhmg23DH8A2svYiwa6aE0K+u08yvUqH15pmhX5dh7Awjfx5fl x9Lc96hu7cNloSdY+VlxtRbD6GakePhH3/bz9X4O0hzgMNRtOXNXF0If7wIfxQ24R4Df NYiizJF4hAEBsvVONMPU0PRpK/YaG1i5ZUxJVHl8StbES/3lTUIyqTF+cwa7s0WTvrs6 3CnW3tsk9MSc6jkl1CmoAipfb/OtvIayEFqngj9lqQlKqyZtR7wsMCpN3tI8rLGJgeLR /CkA== X-Gm-Message-State: AOJu0YzBZxtc7t6nyVNanGV+11kfbqSenygm3f9n5/b/kDip8c5j7rLi Y4+96HzcioZ/9prqj7FHhadysZGwKb1qI6KQk8ptSRqgrkCfwe2Xb0kgBy1ipWUpEqsQuTsbNQ+ 6RQh24h+YkjAdSFqOzgliUGsrJA/25TP54b6RspyzrxlX9yyAnr1V9ow2f8h+a2o1 X-Gm-Gg: ATEYQzxZ8l+uY+GAFx7nOq0m6S/BwL6JD4lzQWW1PTwl+vBdyHI8N92eRY9Eo8aRUdq z+P9q3rhVsR2FSjm79F9gsUfgIlsPHsDA0uieZvdVYqNtpXGq7NYOB3CUwHf3DkOuYELKk2EkAo NFqgkmLE8GOxL/7BJz4bcdOVtXjMKTT/H8nVeyD3P3SK3kbH0PohlNEbeDcdmfbls7pHsvAgdBO AB3Sa8QMC0nAu4/4oqjQUp+qwHjcJYN5liuaoiLwfT2xmnaGxewcHFDu5Ej1ZzQ7e0eg/krSd4b Bz0oEUUpr3WwDSP+EXfXC2/V3dW5SCBhwvSVYVinNr1SIYZ6G7F9PBrqHsQW+VqZv01wN5xuXnj 3krxXPOEuILF7lumBMLZDQ7sx5JEo90tFcNnmlFgvr8x2N+1VyJSc2LSzBQhh03TYEr5ukOPgLi Llx9Y= X-Received: by 2002:a05:600c:8488:b0:479:13e9:3d64 with SMTP id 5b1f17b1804b1-4856eadba01mr56975355e9.15.1773755136265; Tue, 17 Mar 2026 06:45:36 -0700 (PDT) X-Received: by 2002:a05:600c:8488:b0:479:13e9:3d64 with SMTP id 5b1f17b1804b1-4856eadba01mr56974815e9.15.1773755135749; Tue, 17 Mar 2026 06:45:35 -0700 (PDT) From: Hanna Czenczek To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Czenczek , Kevin Wolf Subject: [PULL 2/2] block/mirror: fix assertion failure upon duplicate complete for job using 'replaces' Date: Tue, 17 Mar 2026 14:45:21 +0100 Message-ID: <20260317134521.112121-3-hreitz@redhat.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260317134521.112121-1-hreitz@redhat.com> References: <20260317134521.112121-1-hreitz@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=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.819, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.903, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development 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: 1773755192221154100 Content-Type: text/plain; charset="utf-8" From: Fiona Ebner If s->replace_blocker was already set by an earlier invocation of mirror_complete(), then there will be an assertion failure when error_setg() is called for it a second time. The bdrv_op_block_all() and bdrv_ref() operations should only be done a single time too. Signed-off-by: Fiona Ebner Message-Id: <20260311145717.668492-2-f.ebner@proxmox.com> Reviewed-by: Hanna Czenczek Signed-off-by: Hanna Czenczek --- block/mirror.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index fa1d975eb9..2fcded9e93 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1276,23 +1276,25 @@ static void mirror_complete(Job *job, Error **errp) return; } =20 - /* block all operations on to_replace bs */ - if (s->replaces) { - s->to_replace =3D bdrv_find_node(s->replaces); - if (!s->to_replace) { - error_setg(errp, "Node name '%s' not found", s->replaces); - return; + if (!s->should_complete) { + /* block all operations on to_replace bs */ + if (s->replaces) { + s->to_replace =3D bdrv_find_node(s->replaces); + if (!s->to_replace) { + error_setg(errp, "Node name '%s' not found", s->replaces); + return; + } + + /* TODO Translate this into child freeze system. */ + error_setg(&s->replace_blocker, + "block device is in use by block-job-complete"); + bdrv_op_block_all(s->to_replace, s->replace_blocker); + bdrv_ref(s->to_replace); } =20 - /* TODO Translate this into child freeze system. */ - error_setg(&s->replace_blocker, - "block device is in use by block-job-complete"); - bdrv_op_block_all(s->to_replace, s->replace_blocker); - bdrv_ref(s->to_replace); + s->should_complete =3D true; } =20 - s->should_complete =3D true; - /* If the job is paused, it will be re-entered when it is resumed */ WITH_JOB_LOCK_GUARD() { if (!job->paused) { --=20 2.53.0