From patchwork Mon Aug 1 16:45:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 594720 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b345:0:0:0:0 with SMTP id w5csp3629668maz; Mon, 1 Aug 2022 09:52:38 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tao+n3q7eApO/AlEQFG/RnSRZzAzWCF5keKu8rJ9mCANAF5RQv0pAO2OIejzHMjJ7pAHqB X-Received: by 2002:a37:b306:0:b0:6b6:321:27a6 with SMTP id c6-20020a37b306000000b006b6032127a6mr12242299qkf.262.1659372758120; Mon, 01 Aug 2022 09:52:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659372758; cv=none; d=google.com; s=arc-20160816; b=HCS+qQ469DFQKvlnw4GI9kBfsSIuPTiYdSozvbk2ko00h4l9MM9H4RKQ/YxtNKwV14 yOXNOr7lme87AG7gSvrljDrE99H/LZRaONyyMncAs6LdhdfkDW7Vd5b8OOBjS2tQ5IIn a8Tvog1nvdR2Dx2kTEomwxLxoYuh7SoJpV/IbfLAw1Q1fa9Nx41qO70mQlInMhvu+YrV J5BtmySn6O/Hruz/eZqnmbs0w+H5YrlN7qgDjv2niBM+OA8vg5KZ9Yr5zxT9RiTO8nrq J1X9Nq80ilqV1vgyk72LUzHczupoe5A5d5Qk1D2jSu0uVtyPSoB0fJVJO5zI++rl78rt DgsA== 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:message-id:date:subject:cc:to:from:dkim-signature; bh=Cl7CvDeKfnsPrPWI7EqBvRtwzsiGAx0pECme36wy5aU=; b=pqLoyZ+s9nuBT/8jiNCkJi3MFtxYXabM+XsVBfp/OuQvmo0/KGcb70MjOYyDsr0JYU yhQKwt4Ll6FM5jJwIOAB1tR+L3KddfFYzN7jSXkjTG+hGct5os9MuZDjYFk0CEWrWb9H 7AdG9QHWnE3dCt5cz2eGcH4kcbJQR99AMcq13BYG8wQ5/g2nhVB7pbgvGXKD9LocUkIk ry4Wt1lgOmD0mS6T/l4zuIx6LepCV+X8ui66+vVZuhSf/PRnHTKM2Q4u3sbAIB8Qyq1F M+ezawBZ3CtKYKjSxdUpIjnoWiyLX3Lb6LJztKwUi5Yo7cvuhxxa014u4kZPqoOsa0HD uFtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WUpMKlOP; 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 de17-20020a05620a371100b006b5ec434999si7882346qkb.703.2022.08.01.09.52.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 01 Aug 2022 09:52:38 -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=WUpMKlOP; 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]:44728 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oIYej-0002Q5-GU for patch@linaro.org; Mon, 01 Aug 2022 12:52:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50352) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIYXs-0008GI-Lb for qemu-devel@nongnu.org; Mon, 01 Aug 2022 12:45:37 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]:42596) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oIYXq-0000cO-R6 for qemu-devel@nongnu.org; Mon, 01 Aug 2022 12:45:32 -0400 Received: by mail-wr1-x432.google.com with SMTP id z12so4736507wrs.9 for ; Mon, 01 Aug 2022 09:45:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc; bh=Cl7CvDeKfnsPrPWI7EqBvRtwzsiGAx0pECme36wy5aU=; b=WUpMKlOPPjTlds5sT+kwA9nbwma0SeDlJlRose2qOyGUHC/hkXZgV7NlsTgOf5zaMZ 9wz8+WoZ1eSX/il/h/vLAva3sqyIUCs6nZ7Aw8MYHtuaaObRfyIon4MgCtiJg6dY10Nl vKuVpsCJTBJ/L7bMG0Tu8/HaWUxKtrjN4619Wv4Q7z3F3Dtv88VHcx11G3GI7Y7QjZMS YdSZqHgxwfVdU+vqiTN5uYn1eZaUqEhIuekKhUhXFvE4YjW+jHIhcAJawkYWcOgEydxM sfFBETtYEXQpT9p+IrPi1xbGFRgODoc1+HFb/KiwgGiLzr3GlKzWXd9E6rB++paBDUac L8Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc; bh=Cl7CvDeKfnsPrPWI7EqBvRtwzsiGAx0pECme36wy5aU=; b=mCsO1QiMcsjdAlc5JO2dIOlKNEdyi6OAFGFfas5QyE5sdzKB0FyYv5GNBpbmdyya5G nJgtjXWmtzKAvCXlcWq0NdhH7kcRn/VI39sTsiRtPRaK/zUIiaQjXV0U6sfLdLhSGuOh KWroJFoYsl5lzRzyQCYkf7VQt8fC8IJFl/d4JFafsSyzBF3+pxNTRBVd7pmD3QDpMhte hTJowc6b30S4434QSVbzkuOYP+oSXGkYpzBQa/qlOV8AnrFaf1EnthsiC1rjhAdNV6aP K7ltKMjDGTJ/wA0hy6Ttzzvy4a/qycrNvFbaLuk/9pwfvxnnK8SkGO0zEexm/Ye2t0yc 8a0Q== X-Gm-Message-State: ACgBeo1HOeak8o1geoWD8uO0s7RpNJ/G3+laxLA4CT8f0HB50zqJoC8B zJkaggEUusODBJscG/XL2OYl4Id4WLMWWg== X-Received: by 2002:a5d:498c:0:b0:21f:765:235c with SMTP id r12-20020a5d498c000000b0021f0765235cmr10842566wrq.590.1659372328979; Mon, 01 Aug 2022 09:45:28 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id k13-20020a5d6d4d000000b0021d7ad6b9fdsm12277769wri.57.2022.08.01.09.45.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Aug 2022 09:45:28 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Richard Henderson , Paolo Bonzini , Pavel Dovgalyuk Subject: [PATCH for-7.1] icount: Take iothread lock when running QEMU timers Date: Mon, 1 Aug 2022 17:45:27 +0100 Message-Id: <20220801164527.3134765-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x432.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 --- 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(); } }