From patchwork Tue Aug 9 12:13:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 596218 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b345:0:0:0:0 with SMTP id w5csp4121635maz; Tue, 9 Aug 2022 05:17:22 -0700 (PDT) X-Google-Smtp-Source: AA6agR6DBjFmw2TeVpW/tgUBlZIHylF8TnrFgibYBeivaj6wnoGX4PWRuJtxoR3dxWDie71laBBE X-Received: by 2002:a05:622a:1a0b:b0:33e:d364:13d8 with SMTP id f11-20020a05622a1a0b00b0033ed36413d8mr20066665qtb.341.1660047442481; Tue, 09 Aug 2022 05:17:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660047442; cv=none; d=google.com; s=arc-20160816; b=jZaZxfozw5+sUNocPLyqKP4EQt3BmYtv6rhkfllhlyErsur7aJ3xh6iN7WKc7/inTP 4BBXv2KtLN4KXuvr4knwppf0Hk8Se83TAGsCVKNDPt+Klgj5WiZt1IrDgVnUiMgkDUou dj1ci/hiRx1nqRnCA1/RWELZfDXbgmgapY1TeCfGiWFu3+uZHrmzsrWNB/OFT2hpQD4E 5s2OIf6KceTBei1yJmxFe+GVi3R1qIPoEhDb1TVNrWRSWLZq2odAa1g9GE73L+5VNzy3 ehWLbRaw/9JMqE+WVkcgKgzfazohctsa4iJy7HB9JLjSQFno5IzxbvUuQ9fNsvbhN/pS Fcww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=Q/Vdb4g3NvCJHLVVaiYB9dNbfKbq468Y1+VUKHCVpbE=; b=N/pufMEtRuDdEIlnAvRVfKvEKA0Afj+lKPSQKjJpFC4++18vm/kUaO071D/Fa9FGdC 762Agy0HhA02Su9dB3leQm4yCaf/EU94Z8bMtmDT0E5haWZJTgSRfgORd8812bqmB05o WOrAy+Emabmj/RgF4JNQQSChS/Kp4UZHDGfjTxLf1s2B89bMyxYlwzaHt/s7HFGlvdOB haPYYlEekT07ZCrz/Cyx1kfNrJCAXdaA2kYbi4KCxaHm6PLesFvlCxHjREJJPS9VJZn2 xfjw9SjI0FJ9KSX/xJGqxW0OszkfUkE0UlU9opt7ceqss05jLowo/k3WCXMof0Dbaw9H RVsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AyR5jSTL; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id u14-20020a05620a0c4e00b006b8d79c90bdsi9112183qki.215.2022.08.09.05.17.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 09 Aug 2022 05:17:22 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AyR5jSTL; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:48256 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oLOAj-0000ck-Uh for patch@linaro.org; Tue, 09 Aug 2022 08:17:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44598) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oLO6m-0006sN-9r for qemu-devel@nongnu.org; Tue, 09 Aug 2022 08:13:16 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]:42715) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oLO6j-0003b2-VI for qemu-devel@nongnu.org; Tue, 09 Aug 2022 08:13:15 -0400 Received: by mail-wm1-x334.google.com with SMTP id s11-20020a1cf20b000000b003a52a0945e8so4028121wmc.1 for ; Tue, 09 Aug 2022 05:13:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc; bh=Q/Vdb4g3NvCJHLVVaiYB9dNbfKbq468Y1+VUKHCVpbE=; b=AyR5jSTL/PrVgDNx8eFQ+2pUE6FOkPO9Tddb9txeGeew9Jq2AdOw0NcgHuRZFcWx90 sJkezhIPyiuMVzC0lxt6CxTHgoVBgUEndP4Iz6EdKF3U45YQmUlFRNK+2F6RpmdOc+IS mji+Za0D8IiRUfDlAZs8D3jyOCEstqRTN+RTgdLuHJup54OuAMIlE54A1GkIKGSSXlSv +fe8jgnX/AXKQxaVaSgrsNLakUyn8ClcSkGgsYXRVK7nPe52eIjEMAzYfjqKqOmnNR39 SsbTR6e5kxw6XXQm4nq5pwQ+HGj0nPqgXbJs3a1ehJcgrBPJ/uswhjnx+livC/1o3dz0 OzgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc; bh=Q/Vdb4g3NvCJHLVVaiYB9dNbfKbq468Y1+VUKHCVpbE=; b=pcHdDsGyXq6gyiWqanF/2oYNM0V0cD7ElRhEMFD7k6D25yd+PkAIE5cJ8W8RajDcDh 9Ndn2RXronkSfRDI5q3Jn9XTvhW/dOEUsqZbXdC6LhLPrvE0FjNFCk0RPmqXv1/q+jIV 8N1CeKBjeP57tKx1tsKSyF96pQV+yLrMAoyp3uNJnAUYPk5Sf5OhrB7MLKWcHWKJVEAd QXpXjmpTIRRuqt5c4wzPesHrmqNdKb7Ab6cEx/PtSl73gk0F5HPyIDQC9H6QPU4TUKf4 KqFDR7VkLZubnHoPlVSoBl03wg1HTOqaI04MRF0p7xrQWZIHEXZVZbEk3Yv0/OolPAlO a6gA== X-Gm-Message-State: ACgBeo10MURrcZgpP/pVu0AL18/PmPbP/Kl2kr44ThSZEr5kXF348U3r tFqc18gW811DARDvUZtq1scS+ZDSMX4XoA== X-Received: by 2002:a05:600c:3c8c:b0:3a5:372e:aba8 with SMTP id bg12-20020a05600c3c8c00b003a5372eaba8mr8413944wmb.162.1660047190840; Tue, 09 Aug 2022 05:13:10 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id o2-20020a05600c510200b003a55e5d0d54sm2423169wms.36.2022.08.09.05.13.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Aug 2022 05:13:10 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 1/1] icount: Take iothread lock when running QEMU timers Date: Tue, 9 Aug 2022 13:13:07 +0100 Message-Id: <20220809121307.560286-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220809121307.560286-1-peter.maydell@linaro.org> References: <20220809121307.560286-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::334; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x334.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The function icount_prepare_for_run() is called with the iothread unlocked, but it can call icount_notify_aio_contexts() which will run qemu timer handlers. Those are supposed to be run only with the iothread lock held, so take the lock while we do that. Since icount mode runs everything on a single thread anyway, not holding the lock is likely mostly not going to introduce races, but it can cause us to trip over assertions that we do hold the lock, such as the one reported in issue 1130. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1130 Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Tested-by: Pavel Dovgalyuk Message-id: 20220801164527.3134765-1-peter.maydell@linaro.org --- accel/tcg/tcg-accel-ops-icount.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/accel/tcg/tcg-accel-ops-icount.c b/accel/tcg/tcg-accel-ops-icount.c index 8f1dda4344c..84cc7421be8 100644 --- a/accel/tcg/tcg-accel-ops-icount.c +++ b/accel/tcg/tcg-accel-ops-icount.c @@ -109,7 +109,13 @@ void icount_prepare_for_run(CPUState *cpu) replay_mutex_lock(); if (cpu->icount_budget == 0) { + /* + * We're called without the iothread lock, so must take it while + * we're calling timer handlers. + */ + qemu_mutex_lock_iothread(); icount_notify_aio_contexts(); + qemu_mutex_unlock_iothread(); } }