From patchwork Thu Jan 11 14:23:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 761853 Delivered-To: patch@linaro.org Received: by 2002:a5d:6e02:0:b0:337:62d3:c6d5 with SMTP id h2csp2422875wrz; Thu, 11 Jan 2024 06:25:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IHdIuGtGuDvBNf/dQaj8LW5OsQN8C90BQMY/AUYDnweK/YU4CCqDUXMrj63NOMgfufF2Qsc X-Received: by 2002:ac8:57c8:0:b0:429:a66a:2560 with SMTP id w8-20020ac857c8000000b00429a66a2560mr746233qta.19.1704983154278; Thu, 11 Jan 2024 06:25:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704983154; cv=none; d=google.com; s=arc-20160816; b=x/w662M4LE/K+ppSL9/97TZTpikkXGkorWXZXRKdDXRQ4R3mEIHhD0tSDWA8RD1KqY v1Zj4AdCnFktBPadSXay0ALu/AuHy2cTBReRDnu+X+7qJNmlYaFPTaA+JhUgzKh55zvV aQG7Zor+rTocURkywdG1F+QDFwlv/LBCwG1ZeH6vneYYRHB5wVoNcZ+XioGZNXmqtGti jWmIuHxRKT24Mv/jl8btLnDLhvaBFRNscO+MgK6aMIPczWomlE1R6l30qUj9tBbM/9sD 6x9l3psagKJyZfzRWNI8jKMWZMBKMInNf8WYE+5/IiqFEceyszWDcEjO5n4AmxYFjxa1 nzXA== 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=ln64hRwHlJJ0pQEAuAxOaAua0Oss5Jze+kXnvVQ8J9Y=; fh=4xQMyYYtmbynAmJxwWPpZ6ivTwZNkSfAt6fhFI9aNBQ=; b=I7tmcobCdIupFJCoP50IBuD74joYY4pnWR2A4bAOdvxg3VkgxSHhkGSlh4Vmuc29QI giRC3nFou3GuaXx74ZDJgS9kz5erUxFvF8gnFcEEUgE8uSBO6B0TvehIqAl5LPNz1TUF O4fm2h/wPvc2jCKcsauH6Tr6AsiPDk/ZAaey86G4GGOG1ubT3DRFRz3ZafYSQNbXLNvf iKheiWKY7U5Ds9UwVPwgxxDXFZzPQ3kdSOSpOTvgz6Rx34n+8x1oaP0sea3h/tnuy2bl bbJS7eadvlcrMX73uELQXymkiA1+fhClOXU/f/BJ8jCKGE9tPiI0Tl2JK49vIQzYrvMJ YDMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qVCWhdnj; 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 z9-20020a05622a060900b00428366bfccdsi976550qta.555.2024.01.11.06.25.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 11 Jan 2024 06:25:54 -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=qVCWhdnj; 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 1rNvyX-0004NK-Ne; Thu, 11 Jan 2024 09:24:05 -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 1rNvyT-0004Lw-GZ for qemu-devel@nongnu.org; Thu, 11 Jan 2024 09:24:01 -0500 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rNvyR-0002V6-Bx for qemu-devel@nongnu.org; Thu, 11 Jan 2024 09:24:00 -0500 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-3368abe1093so4265725f8f.2 for ; Thu, 11 Jan 2024 06:23:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704983036; x=1705587836; 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=ln64hRwHlJJ0pQEAuAxOaAua0Oss5Jze+kXnvVQ8J9Y=; b=qVCWhdnjMNRsk4KgqDKJDOleIlTIvsqnp1GHOKKcXIF7DengGwMBrBIGLMeCwfTX7w XMTuMTZg1fVn66R0WkW0j2sXALLHTbl9PIcffAuJa8VCh9u6XTBWbDse2RC2W3mPcA0B X0dQemz/ObxZkIca8udQKEJ0jhRXUmpht5xv2qKCwB+boC6NIHNj5dwJrxwIbEWSLrZn Ixh5eiO126xHcJV301zIkd2K9Ij0RJ9iThWBBM3GQ5SJZIr6NQZXexD2eiAgnOKHzUlH SF0s1qyOUSW51mf3JnGHcFsCUZ28g1eQXORzlOS2HEN/vpRlUKV8IIJdhIUaI0KE+WpV 3FfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704983036; x=1705587836; 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=ln64hRwHlJJ0pQEAuAxOaAua0Oss5Jze+kXnvVQ8J9Y=; b=FgjFPW01w3Tqqp7x5KgDM9V1X+wkaRwmurJFfMTsKN4Hogr6oCy1CsgUvX3iZPk+Gp n7No1MdU2ACICYck5PxZOVwh7R+Xo2W2UmojX9rcX5VTuTR0tzkE6C/bFHqL9JZgEBma kXax0PLjcF3gzsG11awRRn+2M4YaXplRHeWisP6uXQCtVRse6GzwsGMf2o8wY4zOxH3c mqQStWtddbNvfSsmD78kyKS9baFkPNu9OWmua8+XrUcHF98anfQDLbG5CCNfNzT8tAWO hUfa8g+x4M/glXlO9IoQD+cPC+Q2vd1QRmBTMagE8FtTAYDcsz+MDqJNcpsX75+v4u6k 8WPg== X-Gm-Message-State: AOJu0Yw2ODJooSBOX5LsbBjyQVV6GO32ErC25XJ461QkV7M5D8YCMXZ8 jEXh19Hvy7ZMWlR+TOlJqsWikAdcHSj1XHTPJyXB2BltwU+4gg== X-Received: by 2002:adf:eb01:0:b0:336:60ea:319d with SMTP id s1-20020adfeb01000000b0033660ea319dmr574008wrn.63.1704983036016; Thu, 11 Jan 2024 06:23:56 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id h7-20020adff4c7000000b0033677aae2e2sm1349000wrp.107.2024.01.11.06.23.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 06:23:55 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , =?utf-8?q?Alex_Benn?= =?utf-8?q?=C3=A9e?= , Mahmoud Mandour , Richard Henderson , Paolo Bonzini , Alexandre Iooss Subject: [PATCH 05/12] tests/plugin/mem: fix race condition with callbacks Date: Thu, 11 Jan 2024 18:23:18 +0400 Message-ID: <20240111142326.1743444-6-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240111142326.1743444-1-pierrick.bouvier@linaro.org> References: <20240111142326.1743444-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42f; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wr1-x42f.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-bounces+patch=linaro.org@nongnu.org Introduce a lock so global count is correct. This was found by comparing with new inline per_vcpu inline op. Signed-off-by: Pierrick Bouvier Reviewed-by: Richard Henderson --- tests/plugin/mem.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/plugin/mem.c b/tests/plugin/mem.c index 44e91065ba7..beca8232342 100644 --- a/tests/plugin/mem.c +++ b/tests/plugin/mem.c @@ -22,6 +22,7 @@ static uint64_t io_count; static bool do_inline, do_callback; static bool do_haddr; static enum qemu_plugin_mem_rw rw = QEMU_PLUGIN_MEM_RW; +static GMutex lock; static void plugin_exit(qemu_plugin_id_t id, void *p) { @@ -42,6 +43,7 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) static void vcpu_mem(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo, uint64_t vaddr, void *udata) { + g_mutex_lock(&lock); if (do_haddr) { struct qemu_plugin_hwaddr *hwaddr; hwaddr = qemu_plugin_get_hwaddr(meminfo, vaddr); @@ -53,6 +55,7 @@ static void vcpu_mem(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo, } else { cb_mem_count++; } + g_mutex_unlock(&lock); } static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)