From patchwork Thu Jan 26 11:22:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 647110 Delivered-To: patch@linaro.org Received: by 2002:a17:522:b9de:b0:4b9:b062:db3b with SMTP id fj30csp188403pvb; Thu, 26 Jan 2023 03:31:14 -0800 (PST) X-Google-Smtp-Source: AMrXdXsk+TIWo98OpyhI/SHH2okG3cNVxtbKx1M54RDUk/veBZT2rAJBRt4VZxvzqCGmwGXg+D8x X-Received: by 2002:ac8:7395:0:b0:3ac:c2b8:19 with SMTP id t21-20020ac87395000000b003acc2b80019mr48428253qtp.19.1674732674058; Thu, 26 Jan 2023 03:31:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674732674; cv=none; d=google.com; s=arc-20160816; b=wVqEpFHG6jul0rcW8DdjUi8x66MLU8n0GW/2SsODDpwYr3iJ4vMhWW9I9maLNJzLn6 KRklSZ3fcSi9VWnvjc9Bnoq8ZzNiiy2HEWvPr6lIRPs1+jOpDVs2OZafp+PHczbyxcG/ UBl0FyHk6DiLSPsXgZ8bsH4x3T+J8VW8Qf6GZcwaHEb07J6tK61an0PGiQqL27DXFFKT aKRfm1gh6U47Uf5z4VvatGpNbnwBYj70DHHDMb3ErJbfSBoltGB9nyFTl6F+rZaSQI4p odH9wRsiPKsQSbrZwdpD8vHM52IkOE7EuPuG2oyz7KVt6B2sPqgIDTnr8/F2GQJo8Qc3 eIDQ== 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:cc:to :from:dkim-signature; bh=Dxqv1wYRpSn53E/nUZT1yc2AZ9KkmDIimuwl5F539Pg=; b=YlH1qrkbqJ4HVXJnc9DQ+0465Q/KOK2B9jbWYDm5l5aWVj3Od7EzIwHkIrlxjiU4Ai ayZPcxkOfh92WT0cCxwR6tsuPPh/8ZOcsv3H4tQfGP46fmY/gSh2Je9GSc0rP8FYpw81 VRZzxB7z1Nyazh9fkn282RTh6dA9KdWM3/QFUX6M3SvwP3FEfRFjlgxup08TNKcgqZt2 N0FrUKjmhUqgwkS/Za0eJ7hHN/O3QiL3Q7t7rYSFhsFc7X31SqzRDMZ5+f6CPldWerEe yc5jnDehL9ayO1Ve3Zr6s6HevfKZ5gxikkkX90uoy7RzSl4/z49zDfXJNcU3OtkBQlmI /Xbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UmGqPgcH; 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 u10-20020ac858ca000000b003b633c2b328si517109qta.516.2023.01.26.03.31.13 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 26 Jan 2023 03:31:14 -0800 (PST) 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=UmGqPgcH; 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] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pL0La-0003V1-Or; Thu, 26 Jan 2023 06:23:14 -0500 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 1pL0LU-0002sa-9Z for qemu-devel@nongnu.org; Thu, 26 Jan 2023 06:23:08 -0500 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pL0LS-0003hj-6p for qemu-devel@nongnu.org; Thu, 26 Jan 2023 06:23:07 -0500 Received: by mail-wm1-x336.google.com with SMTP id f25-20020a1c6a19000000b003da221fbf48so906630wmc.1 for ; Thu, 26 Jan 2023 03:23:05 -0800 (PST) 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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Dxqv1wYRpSn53E/nUZT1yc2AZ9KkmDIimuwl5F539Pg=; b=UmGqPgcHwRjDFzb8yZqMNA7/lydxW4B9patxi3MPuydLJUpWZDseyHwJquwGSB9/NH kpx0sbDrU8ZDLy4OB+NRP9DoSVa7q3wNB7sW5IqLP9Q7h6nPSYa9nFuQdTqxXRmQjEcz QCb29bqfRbAapdeO197dtL6Q2IWTXnj+F1Sx9o8U7sHkZv2pER+41YUJqE+o5Vf1sjm4 V3h95xHX75Zc5cdz80N8BmGclpF3GUUCqyePSH6fW6SJpMau6djyImuBCbH/lTbDb/pZ SjgS1gVGlOFxAlymF2m54iOz1jVG4hXwjJQEn6CsVG3/bGE5a7VZ2wNrLwRJKbURhmZI +Fgw== 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:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Dxqv1wYRpSn53E/nUZT1yc2AZ9KkmDIimuwl5F539Pg=; b=UYmjtWWZ8ZQIyRC49UcI0jEtWHqa1+wUeIj7jxATwmO4M67f29N2Vy9MLXft0YG/Iy Eq8C0INSQO6xbt4/XPOwqwOHMWmAKdjjll5vBNXGb5h91E6r3kCfXJG0Av41B+gZFmJi uIviouPuqGfjRU00qFoxVDavXJ9UkwuyBwR81UtQ+cozo6G6VwsAiclkF71Kh6fFB4sk F99C3zYOis3PTzg3T2ZcW+tRfgS+Ef1aPvVGJ2wFC/PK9+vkIDJUZigZp62aaD6aJjd1 uuPIh6TiO/zVG+DQiPgdHVU96cIcQRncaD1m9acDc191i+zEBcppDDe1y/HW7Xt7m1NY TXzA== X-Gm-Message-State: AFqh2kr6dOmljpubIGg3w/Fe5ATKs+9bdaRyGvWReZqq5bKDx7asrLQE KYiZXFuNqKorJmmv7aZe6iD5ixPayGvcGhhF X-Received: by 2002:a05:600c:3b07:b0:3d1:cdf7:debf with SMTP id m7-20020a05600c3b0700b003d1cdf7debfmr33726409wms.26.1674732185341; Thu, 26 Jan 2023 03:23:05 -0800 (PST) Received: from zen.linaroharston ([185.81.254.11]) by smtp.gmail.com with ESMTPSA id h15-20020a05600c2caf00b003d974076f13sm1345540wmc.3.2023.01.26.03.22.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jan 2023 03:23:01 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 3DBC31FFC2; Thu, 26 Jan 2023 11:22:59 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, Emilio Cota , Richard Henderson , =?utf-8?q?Philippe_Mathie?= =?utf-8?q?u-Daud=C3=A9?= , =?utf-8?q?Alex_Benn=C3=A9e?= , Alexandre Iooss , Mahmoud Mandour Subject: [PULL 30/35] plugins: make qemu_plugin_user_exit's locking order consistent with fork_start's Date: Thu, 26 Jan 2023 11:22:45 +0000 Message-Id: <20230126112250.2584701-31-alex.bennee@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230126112250.2584701-1-alex.bennee@linaro.org> References: <20230126112250.2584701-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::336; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x336.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 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-bounces+patch=linaro.org@nongnu.org From: Emilio Cota To fix potential deadlocks as reported by tsan. Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Emilio Cota Message-Id: <20230111151628.320011-6-cota@braap.org> Signed-off-by: Alex Bennée Message-Id: <20230124180127.1881110-31-alex.bennee@linaro.org> diff --git a/plugins/core.c b/plugins/core.c index ccb770a485..728bacef95 100644 --- a/plugins/core.c +++ b/plugins/core.c @@ -500,10 +500,17 @@ void qemu_plugin_user_exit(void) enum qemu_plugin_event ev; CPUState *cpu; - QEMU_LOCK_GUARD(&plugin.lock); - + /* + * Locking order: we must acquire locks in an order that is consistent + * with the one in fork_start(). That is: + * - start_exclusive(), which acquires qemu_cpu_list_lock, + * must be called before acquiring plugin.lock. + * - tb_flush(), which acquires mmap_lock(), must be called + * while plugin.lock is not held. + */ start_exclusive(); + qemu_rec_mutex_lock(&plugin.lock); /* un-register all callbacks except the final AT_EXIT one */ for (ev = 0; ev < QEMU_PLUGIN_EV_MAX; ev++) { if (ev != QEMU_PLUGIN_EV_ATEXIT) { @@ -513,13 +520,12 @@ void qemu_plugin_user_exit(void) } } } - - tb_flush(current_cpu); - CPU_FOREACH(cpu) { qemu_plugin_disable_mem_helpers(cpu); } + qemu_rec_mutex_unlock(&plugin.lock); + tb_flush(current_cpu); end_exclusive(); /* now it's safe to handle the exit case */