From patchwork Tue Mar 12 20:14:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 779787 Delivered-To: patch@linaro.org Received: by 2002:a5d:604e:0:b0:33e:7753:30bd with SMTP id j14csp2204456wrt; Tue, 12 Mar 2024 13:16:26 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWzblbPSEPC/RTxMfuxVHD2HEKVw3Bznq+5YQJ47xyULOwtNMZwk/hk4tKfu2hrh7A7A3O1DkwiYIeq0mAjngpu X-Google-Smtp-Source: AGHT+IG4Nbr1HDIbnZJdpZgKHoX+NLT3UjqKqLCvWHUyUR6CQzCubj30A//E63xasznJzCFohoTQ X-Received: by 2002:a05:6808:448a:b0:3c1:e580:12a with SMTP id eq10-20020a056808448a00b003c1e580012amr1589608oib.38.1710274586172; Tue, 12 Mar 2024 13:16:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1710274586; cv=none; d=google.com; s=arc-20160816; b=Q5vVAtHkHZBZ2Dp1Ppxs5apNWn93FffyIm9IokidTCuAiuR8QlkZ48Si2QMGnR2wIl UD0IM/bIkHBM9fh2gXA3XNn5AmoYwte8kBGCmSLYlElUTCITlGrRJTq6BTaptlzYdBU7 zd+XkT38rRi2Z6cngPxaHKsjXkKuJu5Lx8JEE+AZjnNWK8gz+e5uUUmgpop8HF5LO13q +3TRsRiqyGYA+ILbditEV4Kr29NoUctPB6OJ5+PEkRqL91XyUl7bIMlmGYImhaFIDOkY tvC52Fgce9deBuo05sr/jmoJNkS49tYS9dzNvx+3FVlAajtagbnHh78n5fr7xxPUZJDg jyXw== 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=eKgsu7QFjVLGSprUDHjOGJwaVzxS/YEnXMOQmjF1L3E=; fh=7UWA2RRneThTkX+dTrZkoV4po8/WMFgf92effoPAD5Y=; b=qvo6gfh62NdxUcbTyUcTANEdTUEpMzp92Hl4QXlb4qM6NSLQ7PZ/MAZbLcK14Yole8 y/MEX5Pxwh7CveTkTIEpc23H8VZQksaDG1MVAkpL3RCnHmAQqzMNjzJK25/AxUxwYY+h ubDZ1OrUobVNgzWUqKBnEPG0iSWs6q2gFQycS1x3Zuh+oikuhgfHjvd9CEs3KSDrrmgg 9AQqin3Huj5eBEvixM2s0ZM0XrTl0wZa8qjzBHRHYTbaHLKPfQ7bmdOZzD2O0ZVAPobZ ctO0zUveKJGM7cpUlqDPz8GAwLt59G5Dmci0egIOLAKRgXmpOxr+EoNHTn1rSqoZDe9W 0Idg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NciexrSE; 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 f12-20020ac85d0c000000b0042f512f97afsi3267785qtx.780.2024.03.12.13.16.25 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 12 Mar 2024 13:16:26 -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=NciexrSE; 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 1rk8Xb-0001rp-DN; Tue, 12 Mar 2024 16:16:03 -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 1rk8XE-0001py-O4 for qemu-devel@nongnu.org; Tue, 12 Mar 2024 16:15:42 -0400 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rk8X0-0001OY-1i for qemu-devel@nongnu.org; Tue, 12 Mar 2024 16:15:27 -0400 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-413e613316cso2475315e9.1 for ; Tue, 12 Mar 2024 13:15:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1710274524; x=1710879324; 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=eKgsu7QFjVLGSprUDHjOGJwaVzxS/YEnXMOQmjF1L3E=; b=NciexrSEsXlrPIvX0KYN7uoJn5DN5ULnl+I9bFF69sGluT8jLXfPlSfhMX/w4PBh8p 5j97wiUlpoBSHTXKFJMCdYJ9TZ6I7u1N5/YrDu6SZGG76r4nDc9RPout611EEazyerTE et5xeT2m4BOUXHJXRRm4bn7SP5ld9lsUVTZ2h7xkg6nMgi49rCX/bK84UrpYmLoTGHT1 QzC96OoMPT+vNl14kI0yguHf08A/lxoYDbjtr61or3v/tu3QKR58Ks73ztWoQiYclabe jSSYKHN6mcp6GLb8sJTcj002V9kjmn+PwpI9IBGPhEo8qhcc4Fb26Lpq93hJ3hPK9en3 hAeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710274524; x=1710879324; 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=eKgsu7QFjVLGSprUDHjOGJwaVzxS/YEnXMOQmjF1L3E=; b=kzUA7YdvX0Mh3VFLtGqlQaVPiFPX7KYC4fVVHOBv2kyH2wXd1JyKmPiXBb0ecT5u7R sCuMPkLzopx0sOTAb24EFMDslCCxQwpYJEbDDZyA9OdSD9j6BBpqK7j/d2YA/2dAlZnF qTnm/G5fWKWtqfb7/JdsEOU+SvKplN7MN2Xl8iKyE+PlrpF73kJoi2i5NEFCjruz+HIW OV4qpKaWYSIKmFJ5Q8ca4rMwx5SIL5KyMCK+mPpmQToL6tKf2a/GpYa9Xs+rIIFcjsom PWGg2MAiN+QYaEmjFkt0pwXy0Q0TLOBXoGb9UQrUgAZwbG7nmWzUl6CqY+ywvonDjMIJ TYBg== X-Gm-Message-State: AOJu0Yx3vfY3L22NjcoggHF8MDcFyNseZ5KrOSh0jBHTcZfCHQdAaJ8D rTvQ3n+pk/bIpw3GbC3bN0GuOl2Uv1KtsLOJBI2vzWEPnoCZ/EBYNw8+dOwFJfhFn2czjdVs/ZK rf28= X-Received: by 2002:adf:e445:0:b0:33e:7cc6:9936 with SMTP id t5-20020adfe445000000b0033e7cc69936mr305337wrm.21.1710274523950; Tue, 12 Mar 2024 13:15:23 -0700 (PDT) Received: from m1x-phil.lan ([176.187.206.139]) by smtp.gmail.com with ESMTPSA id q18-20020adf9dd2000000b0033e90e98886sm7230234wre.71.2024.03.12.13.15.21 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 12 Mar 2024 13:15:23 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: David Hildenbrand , Richard Henderson , Nicholas Piggin , Peter Xu , Paolo Bonzini , Thomas Huth , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH-for-9.0 v2 3/3] physmem: Fix migration dirty bitmap coherency with TCG memory access Date: Tue, 12 Mar 2024 21:14:58 +0100 Message-ID: <20240312201458.79532-4-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240312201458.79532-1-philmd@linaro.org> References: <20240312201458.79532-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::331; envelope-from=philmd@linaro.org; helo=mail-wm1-x331.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 From: Nicholas Piggin The fastpath in cpu_physical_memory_sync_dirty_bitmap() to test large aligned ranges forgot to bring the TCG TLB up to date after clearing some of the dirty memory bitmap bits. This can result in stores though the TCG TLB not setting the dirty memory bitmap and ultimately causes memory corruption / lost updates during migration from a TCG host. Fix this by calling cpu_physical_memory_dirty_bits_cleared() when dirty bits have been cleared. Fixes: aa8dc044772 ("migration: synchronize memory bitmap 64bits at a time") Signed-off-by: Nicholas Piggin Tested-by: Thomas Huth Message-ID: <20240219061731.232570-1-npiggin@gmail.com> [PMD: Split patch in 2: part 2/2, slightly adapt description] Signed-off-by: Philippe Mathieu-Daudé --- include/exec/ram_addr.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index b060ea9176..de45ba7bc9 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -513,6 +513,9 @@ uint64_t cpu_physical_memory_sync_dirty_bitmap(RAMBlock *rb, idx++; } } + if (num_dirty) { + cpu_physical_memory_dirty_bits_cleared(start, length); + } if (rb->clear_bmap) { /*