From nobody Sat Apr 20 11:34:07 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1663718817; cv=none; d=zohomail.com; s=zohoarc; b=foGWw+XIJBI4qJ8QdI/wrjeT3LmwG8emZKmqymNC5kNjq0DVGtUS/IMN0tue7Axl6JkrQaLs8i0qUYhk4noryFGqfUYIEd3CuzQO+M7Gkbef/lFLK+kUh2LUDXbJjq920Kro8mPWD0BG05CypJNKwGJZu8nDA5+l00Of2Ys8mpk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1663718817; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Nq13aToG9AQhbr4EScEaPEhP5YTaWi+1UK6cTWaKltc=; b=IwRqQS5JzRb1W3jkHhP1+j7xhd3XmtQDQ5lUkillD3S6uQiudFLWN+UjbCSsu4+9YFuI/Q9fs50bFm+d0SRhUoFoA4bTOGpf+WmgXBqer+gUwdk2boEJ3V8d9bnH93EG/8UjqEcFuJHdCzyPSohG4UA7xlqm0HzyWc3RDFb3IU0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1663718817037916.1502752135068; Tue, 20 Sep 2022 17:06:57 -0700 (PDT) Received: from localhost ([::1]:49386 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oanGR-0002WI-Pn for importer@patchew.org; Tue, 20 Sep 2022 20:06:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53876) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oalsq-0007N4-8K for qemu-devel@nongnu.org; Tue, 20 Sep 2022 18:38:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:49039) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oalsV-00083B-SP for qemu-devel@nongnu.org; Tue, 20 Sep 2022 18:38:27 -0400 Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-587-SfJILhwLOwyGFMAx5tOwqw-1; Tue, 20 Sep 2022 18:38:04 -0400 Received: by mail-qt1-f199.google.com with SMTP id fy20-20020a05622a5a1400b0035bef08641dso2863120qtb.18 for ; Tue, 20 Sep 2022 15:38:04 -0700 (PDT) Received: from localhost.localdomain (bras-base-aurron9127w-grc-46-70-31-27-79.dsl.bell.ca. [70.31.27.79]) by smtp.gmail.com with ESMTPSA id de4-20020a05620a370400b006bbb07ebd83sm697499qkb.108.2022.09.20.15.38.02 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 20 Sep 2022 15:38:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663713485; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Nq13aToG9AQhbr4EScEaPEhP5YTaWi+1UK6cTWaKltc=; b=L8ht4GKuCRF0KF1kszXyBu6tvShEjlJE1i0pSr/daFb8evPEMUi8diOXv26asOrRFkTUNC 3/aT6WAQ4Ll+/2ZhrSrqVHKiSK46++tDFqJvSDoN12KdeJdOKKBMEIFvRTkqkerD82HKq+ xquezABQAosHtfTDifL7P7zLeWKE97w= X-MC-Unique: SfJILhwLOwyGFMAx5tOwqw-1 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; bh=Nq13aToG9AQhbr4EScEaPEhP5YTaWi+1UK6cTWaKltc=; b=MjgTmzLZwwb3BsBBKTbH0uGxSPWpU7btloNldMBVUR/II2KVD1eE+8xrLXFYkto49U 6uTpWbe5F1MduwqyRQMSJY9vBI/AGzp81i1vSy+rdbF+sWuCFSjiBLDziMdBOv8qRZkp ba7Xe/vsoK87TabTRdLHwqaPpDTBGdkd+3LFCTzI533HDhBexw1P53Ag9gMU8CkfJXQG j7XEZ01ClpgPpbAMBKr4S/rLdDzuE+ny0ND4h2z0lhRj2R3x0QoqVx/KxNiafYf5TYGz jDFMhOp+6F0DBN+keHEuRVJ93BYM5K4SNhSqLTNlENS1EU0vIg0xDSkY6kgq+DuHdxQw ydlQ== X-Gm-Message-State: ACrzQf2A0MRlkNHUZnIM2GqpZxtPRmChEmg43rQlMSZ/KTie3+aPUkiO gmNaoSpQ4USblSErScAkPzzyhiki/oYNeNAA6VyS5KL0qb9WbzE1Zo9cT3vosvohyHiIKxeKwl8 kQBpU1vqTcmCS4u6l/60PqS94YaxTImMa4op5unISYICP2KfVa0WAOl0Eitg0bkCU X-Received: by 2002:a05:6214:2342:b0:473:e142:f758 with SMTP id hu2-20020a056214234200b00473e142f758mr21496211qvb.83.1663713483825; Tue, 20 Sep 2022 15:38:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM79qZMjDQxwCJcn8T6bwAgTKWhK4edorZJIOyvQThmyVyjQcR+X+qOE/+6zKwmr/QEnYCTtew== X-Received: by 2002:a05:6214:2342:b0:473:e142:f758 with SMTP id hu2-20020a056214234200b00473e142f758mr21496190qvb.83.1663713483574; Tue, 20 Sep 2022 15:38:03 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: "Dr . David Alan Gilbert" , "Daniel P . Berrange" , Leonardo Bras Soares Passos , peterx@redhat.com, Juan Quintela Subject: [PATCH 1/5] migration: Fix possible deadloop of ram save process Date: Tue, 20 Sep 2022 18:37:56 -0400 Message-Id: <20220920223800.47467-2-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220920223800.47467-1-peterx@redhat.com> References: <20220920223800.47467-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1663718818566100001 Content-Type: text/plain; charset="utf-8" When starting ram saving procedure (especially at the completion phase), always set last_seen_block to non-NULL to make sure we can always correctly detect the case where "we've migrated all the dirty pages". Then we'll guarantee both last_seen_block and pss.block will be valid always before the loop starts. See the comment in the code for some details. Signed-off-by: Peter Xu Reviewed-by: Dr. David Alan Gilbert --- migration/ram.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index dc1de9ddbc..1d42414ecc 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2546,14 +2546,22 @@ static int ram_find_and_save_block(RAMState *rs) return pages; } =20 + /* + * Always keep last_seen_block/last_page valid during this procedure, + * because find_dirty_block() relies on these values (e.g., we compare + * last_seen_block with pss.block to see whether we searched all the + * ramblocks) to detect the completion of migration. Having NULL value + * of last_seen_block can conditionally cause below loop to run foreve= r. + */ + if (!rs->last_seen_block) { + rs->last_seen_block =3D QLIST_FIRST_RCU(&ram_list.blocks); + rs->last_page =3D 0; + } + pss.block =3D rs->last_seen_block; pss.page =3D rs->last_page; pss.complete_round =3D false; =20 - if (!pss.block) { - pss.block =3D QLIST_FIRST_RCU(&ram_list.blocks); - } - do { again =3D true; found =3D get_queued_page(rs, &pss); --=20 2.32.0 From nobody Sat Apr 20 11:34:07 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1663718550; cv=none; d=zohomail.com; s=zohoarc; b=jbZk7mS6Zy+QX2TA9doTHnM5ItCpg5kdCZ636aYPQf/Og6+DXQIyMpqWsstrVYq4ynuNzhpzpIL2+wv+4rsqMCCrH+tdKoLlSBU0itYuzazqBDW7Oaem/FkNCeZA0MKf8m7sR1zvnsWqNRgzL50J4c8TKTYdi6fdVwyEjS4M3Oo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1663718550; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=4d6wNdJVnWaHfunZXTn5EfI6vsKLdU6f2hPjDDIoWd0=; b=UfzfHhkWfwt7aR445xqCNUyHF+sShQgh9i5OXVj9qZPstLrjIQcTgBPpqo8hpTQJZlvPOiQZLofAf/CY1p9jwjyfaRPFRmLoJ8CrWRfSjKTIwO5z1b4VcqNqLdT5Api+vkFn7CYRL8yrW9AJZ9EPPcWGWvom7ovLpxcfEpSbkMI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1663718550084778.3720583498502; Tue, 20 Sep 2022 17:02:30 -0700 (PDT) Received: from localhost ([::1]:34790 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oanC7-0005xU-QX for importer@patchew.org; Tue, 20 Sep 2022 20:02:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53882) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oalsq-0007NN-9j for qemu-devel@nongnu.org; Tue, 20 Sep 2022 18:38:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:24833) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oalsW-00083F-Bn for qemu-devel@nongnu.org; Tue, 20 Sep 2022 18:38:28 -0400 Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-76-Zj1UQ1TaOxu4-h_cviH2Vw-1; Tue, 20 Sep 2022 18:38:05 -0400 Received: by mail-qk1-f200.google.com with SMTP id k2-20020a05620a414200b006ceec443c8bso3088497qko.14 for ; Tue, 20 Sep 2022 15:38:05 -0700 (PDT) Received: from localhost.localdomain (bras-base-aurron9127w-grc-46-70-31-27-79.dsl.bell.ca. [70.31.27.79]) by smtp.gmail.com with ESMTPSA id de4-20020a05620a370400b006bbb07ebd83sm697499qkb.108.2022.09.20.15.38.03 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 20 Sep 2022 15:38:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663713486; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4d6wNdJVnWaHfunZXTn5EfI6vsKLdU6f2hPjDDIoWd0=; b=faJ3ZTdl5t0z+Zb+UdMF8L+msdXfb5CkOOqOnl5VI3KccwSv1mZ2shoc5r7n3iAc1cH47O LaiWpHswOGNZDlp7JUI5ZR3APxOug30DIqGoZ2qsD8RmS6i/qNrLfQPc49Dff8TbZjthmq ghhaU+gPH62vMk9y08uPPLxXDLtLXDE= X-MC-Unique: Zj1UQ1TaOxu4-h_cviH2Vw-1 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; bh=4d6wNdJVnWaHfunZXTn5EfI6vsKLdU6f2hPjDDIoWd0=; b=QpCyt22FM+8mYGM1robw+jHirIpE6lossn2gVROQhgHXzjsaGaOUQ6TXHPw59GckiL uaxNwrydiSMHnJjO6jZ11oNKqP/kumU6Aa6rLWpAqqfwOLr2wqZQ5WTem4Sq97EbZ6Q3 BoGJRasO+mfn9VkPoqyJZwCjYiGflnoJI/9TGAzf5ZTa/dTdxbwt4ockGBxnJhJjCGOF BGfBgv9/D3b5Y/5IZwh233T1QW7N0VpX0KJrFsZnyNzVRhOYb2Yz9/iZAcjhEyL2lx7M 8j8bflBCsrdJQTQMfFk2TWjE8ExmDQ1ruCRMXzaGEhGedR4KBaALg81OEokRDXINAHu0 A17Q== X-Gm-Message-State: ACrzQf2II1g75oKvWc6xrljqghZZt8YuY7SIMkxsee3fHqokA/g4dFdC fJyafw3owIa8wjxQmpnfK0kt8WEOke/LUuM+wED3lQOC7HciBiOxMgBcWLT/2Txq09/VdFHb9Gw txG4VPmepIgZnEWlqpSeGvQhRzS8PbgKuwS285jgttF3J6iZTfMO6tAohNUGjpGri X-Received: by 2002:a05:620a:998:b0:6ce:6069:c713 with SMTP id x24-20020a05620a099800b006ce6069c713mr18450220qkx.181.1663713484840; Tue, 20 Sep 2022 15:38:04 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5QkQ8sjWqg9fUDYjfjNGxQ32orDz0f8uEicE/gMXokI/sr2525d/YshZmRh/Db9W1Fweik/g== X-Received: by 2002:a05:620a:998:b0:6ce:6069:c713 with SMTP id x24-20020a05620a099800b006ce6069c713mr18450201qkx.181.1663713484564; Tue, 20 Sep 2022 15:38:04 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: "Dr . David Alan Gilbert" , "Daniel P . Berrange" , Leonardo Bras Soares Passos , peterx@redhat.com, Juan Quintela Subject: [PATCH 2/5] migration: Fix race on qemu_file_shutdown() Date: Tue, 20 Sep 2022 18:37:57 -0400 Message-Id: <20220920223800.47467-3-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220920223800.47467-1-peterx@redhat.com> References: <20220920223800.47467-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1663718550641100001 Content-Type: text/plain; charset="utf-8" In qemu_file_shutdown(), there's a possible race if with current order of operation. There're two major things to do: (1) Do real shutdown() (e.g. shutdown() syscall on socket) (2) Update qemufile's last_error We must do (2) before (1) otherwise there can be a race condition like: page receiver other thread ------------- ------------ qemu_get_buffer() do shutdown() returns 0 (buffer all zero) (meanwhile we didn't check this retcode) try to detect IO error last_error=3D=3DNULL, IO okay install ALL-ZERO page set last_error --> guest crash! To fix this, we can also check retval of qemu_get_buffer(), but not all APIs can be properly checked and ultimately we still need to go back to qemu_file_get_error(). E.g. qemu_get_byte() doesn't return error. Maybe some day a rework of qemufile API is really needed, but for now keep using qemu_file_get_error() and fix it by not allowing that race condition to happen. Here shutdown() is indeed special because the last_error was emulated. For real -EIO errors it'll always be set when e.g. sendmsg() error triggers so we won't miss those ones, only shutdown() is a bit tricky here. Cc: Daniel P. Berrange Signed-off-by: Peter Xu Reviewed-by: Dr. David Alan Gilbert --- migration/qemu-file.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 4f400c2e52..2d5f74ffc2 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -79,6 +79,30 @@ int qemu_file_shutdown(QEMUFile *f) int ret =3D 0; =20 f->shutdown =3D true; + + /* + * We must set qemufile error before the real shutdown(), otherwise + * there can be a race window where we thought IO all went though + * (because last_error=3D=3DNULL) but actually IO has already stopped. + * + * If without correct ordering, the race can happen like this: + * + * page receiver other thread + * ------------- ------------ + * qemu_get_buffer() + * do shutdown() + * returns 0 (buffer all zero) + * (we didn't check this retcode) + * try to detect IO error + * last_error=3D=3DNULL, IO okay + * install ALL-ZERO page + * set last_error + * --> guest crash! + */ + if (!f->last_error) { + qemu_file_set_error(f, -EIO); + } + if (!qio_channel_has_feature(f->ioc, QIO_CHANNEL_FEATURE_SHUTDOWN)) { return -ENOSYS; @@ -88,9 +112,6 @@ int qemu_file_shutdown(QEMUFile *f) ret =3D -EIO; } =20 - if (!f->last_error) { - qemu_file_set_error(f, -EIO); - } return ret; } =20 --=20 2.32.0 From nobody Sat Apr 20 11:34:07 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1663718842; cv=none; d=zohomail.com; s=zohoarc; b=YeMk06r/JSx3FjLoDjVhYCnxXPw30IqcNK8BInwtTWjuv6yhD+U0HUmMbYtlDsGpEORRg6WLe7ZABxseV/KTsKXyjgavFWk5lZVAuDtlMhNE7XKYprrzSRCq42EOQtEF2HoggCGnAdfOcwXZz93KlJD4pJqA8F7sUg7DcSogsog= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1663718842; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0XVf+orfGCsPIiWN3l0aR530llnvOFKGwsBNJGUsUSI=; b=aGBTkrUTZSPXHhpdoGjK95OiGaDjuW9XyH0hzqtRLhNidH6DIWka2LsnWgrU8iv69SwdAX1CXSczOlLp7tq4u9vf2OuFIJMyBcgzrmHaBCiaNoZd580e9CdzCs7Z5og+KRnXRfhLsUiODOwFhICw6zTLBNkaWqGcptI5m/4JZSU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1663718842534624.1000376625778; Tue, 20 Sep 2022 17:07:22 -0700 (PDT) Received: from localhost ([::1]:47846 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oanGr-0003TE-FO for importer@patchew.org; Tue, 20 Sep 2022 20:07:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53878) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oalsq-0007NG-9W for qemu-devel@nongnu.org; Tue, 20 Sep 2022 18:38:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:58881) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oalsX-00083N-9V for qemu-devel@nongnu.org; Tue, 20 Sep 2022 18:38:28 -0400 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-548-mkFGLCNkPc6eO6Pg82KBYA-1; Tue, 20 Sep 2022 18:38:06 -0400 Received: by mail-qv1-f70.google.com with SMTP id g4-20020ad45424000000b004a9bb302c85so3034406qvt.22 for ; Tue, 20 Sep 2022 15:38:06 -0700 (PDT) Received: from localhost.localdomain (bras-base-aurron9127w-grc-46-70-31-27-79.dsl.bell.ca. [70.31.27.79]) by smtp.gmail.com with ESMTPSA id de4-20020a05620a370400b006bbb07ebd83sm697499qkb.108.2022.09.20.15.38.04 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 20 Sep 2022 15:38:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663713487; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0XVf+orfGCsPIiWN3l0aR530llnvOFKGwsBNJGUsUSI=; b=bJtkPYAESGXqlVjsFh3AWrX33swsITEark32m3zv4gLZaO69j+Zm/5GxemKtdby1aNbxcF GPO6ynx5F9wVWlRAgC0CGDCPUJgSGPMkd1uvBqHzO7nnq6mGed0ft9ziXy2LT4HSj24zGf WAcKIvYar7iZN3bLyUcgGnAvuMS/UYQ= X-MC-Unique: mkFGLCNkPc6eO6Pg82KBYA-1 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; bh=0XVf+orfGCsPIiWN3l0aR530llnvOFKGwsBNJGUsUSI=; b=soxpbwsH155PoyDev5cD1Xil2hDFVTNhVfwwSOzLFt1W0jPMdO4JkXnyDA3EctwzW8 wFThAIJlgfpMKRASj2hUfvRd/wTrbeuKMcbo6hZM2ysE8hnXZVnOPCOYnZoP5Uz+07zE +n8QgnNCwWOfIRKukE5UmZR0IfwfZlxKAUWhNG4EpUo2tCup0/3+SOIDUfV9DPchubxV Uj8d1/clqMwtglbIMny0w5JggVoo9iJzQxL301dLoVQVOjY91Y2G2xFo9kzgE/ja1lmV szUOPsERowlcyKyMKiupSfJ/4WfY37ppooh3BdHcrm9FFIXL5LLNx+jeteLw46q+wxEg N+rQ== X-Gm-Message-State: ACrzQf3drZe+a4q7rIuFTGpCifnZMXsgewAC+1WKVkCQyYybyjiR2qTj 8i3yugeyPjnrgPZoRVbMFoQppg3mbX164S08V87QDWzB2JQRoKzmgR0N9A1kYJHlGnXU3clHD+B 3ns6wQrf0DjyCXV7NmgpjVzYacsOQvsOtwugd7jKVziiieL8JcGA2WFB5ojju72wq X-Received: by 2002:a05:6214:2528:b0:4ad:6fa4:4170 with SMTP id gg8-20020a056214252800b004ad6fa44170mr231182qvb.113.1663713485943; Tue, 20 Sep 2022 15:38:05 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7S5uDSbODjLRlC56UDvQ+11TjV2SXEk0XrBH7zFpVkrcntQtGcRYToGgJouXj0XadmWpEugg== X-Received: by 2002:a05:6214:2528:b0:4ad:6fa4:4170 with SMTP id gg8-20020a056214252800b004ad6fa44170mr231167qvb.113.1663713485685; Tue, 20 Sep 2022 15:38:05 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: "Dr . David Alan Gilbert" , "Daniel P . Berrange" , Leonardo Bras Soares Passos , peterx@redhat.com, Juan Quintela Subject: [PATCH 3/5] migration: Disallow xbzrle with postcopy Date: Tue, 20 Sep 2022 18:37:58 -0400 Message-Id: <20220920223800.47467-4-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220920223800.47467-1-peterx@redhat.com> References: <20220920223800.47467-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1663718844579100001 Content-Type: text/plain; charset="utf-8" It's not supported since the 1st day, as ram_load_postcopy does not handle RAM_SAVE_FLAG_XBZRLE. Mark it disabled explicitly. Signed-off-by: Peter Xu --- migration/migration.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/migration/migration.c b/migration/migration.c index bb8bbddfe4..fb4066dfb4 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1268,6 +1268,11 @@ static bool migrate_caps_check(bool *cap_list, error_setg(errp, "Postcopy is not compatible with ignore-share= d"); return false; } + + if (cap_list[MIGRATION_CAPABILITY_XBZRLE]) { + error_setg(errp, "Postcopy is not compatible with xbzrle"); + return false; + } } =20 if (cap_list[MIGRATION_CAPABILITY_BACKGROUND_SNAPSHOT]) { --=20 2.32.0 From nobody Sat Apr 20 11:34:07 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1663717319; cv=none; d=zohomail.com; s=zohoarc; b=WxmAoNJSBfbjFUO2cdNiaKULaR5MU/blgafYu1NcQ0UHcqm7MPKWi+4OrXfYAcAIhFI1znpRixxT6Qeyn/Pm6D5PwtF4xoXyuQxSbGaJ4VGmZDqnB9KlhaYq16KBnjH3YXkXVqhdxhEJ9nYtjwGLZVCRBpZaBsiszXpwxwrj6Vk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1663717319; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dOg7YzY/mkr3otFyOnd2Dn/gzU4N2yp13eSItCpsyek=; b=QRBaaJmH18NHXg0g33gvKR7JcUnFSGsORTaCJOqJwFlFsFvlqTGanqWun0E+N8CcIHkX8LfzTBkrVBXCNfbvViWB45Z+2Gxbvmu16fW2PHjoFA/IVeNH8aZiD2DdBTbypkk9HlNxzOkC1ufusK2lVOLqlKVTnqqK17wiYeW0aiw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1663717319518413.4992485000754; Tue, 20 Sep 2022 16:41:59 -0700 (PDT) Received: from localhost ([::1]:37550 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oamsH-0001kX-Sl for importer@patchew.org; Tue, 20 Sep 2022 19:41:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44122) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oalsh-0006sM-4x for qemu-devel@nongnu.org; Tue, 20 Sep 2022 18:38:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:27832) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oalsX-00083U-HD for qemu-devel@nongnu.org; Tue, 20 Sep 2022 18:38:17 -0400 Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-647-qB9oTsFVNJincN832VpdGQ-1; Tue, 20 Sep 2022 18:38:07 -0400 Received: by mail-qk1-f199.google.com with SMTP id v15-20020a05620a0f0f00b006ceab647023so3086474qkl.13 for ; Tue, 20 Sep 2022 15:38:07 -0700 (PDT) Received: from localhost.localdomain (bras-base-aurron9127w-grc-46-70-31-27-79.dsl.bell.ca. [70.31.27.79]) by smtp.gmail.com with ESMTPSA id de4-20020a05620a370400b006bbb07ebd83sm697499qkb.108.2022.09.20.15.38.05 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 20 Sep 2022 15:38:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663713488; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dOg7YzY/mkr3otFyOnd2Dn/gzU4N2yp13eSItCpsyek=; b=S8CYjqQ9WpPeC8p2At2pzX70RFW/W7xXbldFZ4vBbI6wvOq7XJ5ai+EtnQZh4hqjKDIwh5 MhQvaX1sH36c3rMou1ej0/uqoWlJdtBVHst60xptqQCexa35wlVe2URBoNW3Re49v+p/Do NvFPwxXUVClPYa2rwNEE4wuJHLHnpZs= X-MC-Unique: qB9oTsFVNJincN832VpdGQ-1 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; bh=dOg7YzY/mkr3otFyOnd2Dn/gzU4N2yp13eSItCpsyek=; b=LI+ZBVqGNIUf5rdNk2ZHEMd6N0cSsoHM1Q+q2WjbOpZ4WyTYYalaXgYdAhvUbvjx/a 23BihNxgRacCc5fWZytQrWlsALVYla1XBhoYje1j7zimdfuG7mFlagBJa4JuQ/Z5eAfj sbsZB8lMWXKj/BBoGwps4MPgAhbaAx0KpYj7FH9HGL4mPbUXHBqp69r9DVUAfSbEwIlB sfXye2ISNP56JUi7GXGimm72aTMfy9Rk3sz5y08gL3Utz7qsbewR0dRMyJQD4WjAtFzA 5ENBZyKcDugZv0TWddjot6bFLQDCCmZ+smkuLGIT9z1nnWALLlQ759gil83z1RbklNj9 yRKg== X-Gm-Message-State: ACrzQf1Y7VtpbsqeFVsqpq54tMXOoyYKZuOie3yGOF1J273sL1A8az01 OvMlkPGN9dhzg12WJDS0uT8Gf0Lsr5J5DELPwA9hkrXjwWVrZXRiiRstQKNDhbbWvxf/qpsFtmW 6fDX38AypWuOmkNHMXkn715E2+JiZmBHpkcBPHV6qlWBLE2Q+xGl9Q4ZIX8Yq9vSa X-Received: by 2002:a05:622a:54d:b0:35c:f693:d754 with SMTP id m13-20020a05622a054d00b0035cf693d754mr6056042qtx.181.1663713487194; Tue, 20 Sep 2022 15:38:07 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Kp849JM4xPq/fx4/0T/b3iS1FvDj9Sl/auChUiwOdgYDmYnP7WJ5o+6R0vjUzjjRrb4IflQ== X-Received: by 2002:a05:622a:54d:b0:35c:f693:d754 with SMTP id m13-20020a05622a054d00b0035cf693d754mr6056023qtx.181.1663713486937; Tue, 20 Sep 2022 15:38:06 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: "Dr . David Alan Gilbert" , "Daniel P . Berrange" , Leonardo Bras Soares Passos , peterx@redhat.com, Juan Quintela Subject: [PATCH 4/5] migration: Disallow postcopy preempt to be used with compress Date: Tue, 20 Sep 2022 18:37:59 -0400 Message-Id: <20220920223800.47467-5-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220920223800.47467-1-peterx@redhat.com> References: <20220920223800.47467-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1663717320609100001 Content-Type: text/plain; charset="utf-8" The preempt mode requires the capability to assign channel for each of the page, while the compression logic will currently assign pages to different compress thread/local-channel so potentially they're incompatible. Signed-off-by: Peter Xu Reviewed-by: Dr. David Alan Gilbert --- migration/migration.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/migration/migration.c b/migration/migration.c index fb4066dfb4..07c74a79a2 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1341,6 +1341,17 @@ static bool migrate_caps_check(bool *cap_list, error_setg(errp, "Postcopy preempt requires postcopy-ram"); return false; } + + /* + * Preempt mode requires urgent pages to be sent in separate + * channel, OTOH compression logic will disorder all pages into + * different compression channels, which is not compatible with the + * preempt assumptions on channel assignments. + */ + if (cap_list[MIGRATION_CAPABILITY_COMPRESS]) { + error_setg(errp, "Postcopy preempt not compatible with compres= s"); + return false; + } } =20 return true; --=20 2.32.0 From nobody Sat Apr 20 11:34:07 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1663716994; cv=none; d=zohomail.com; s=zohoarc; b=Eue4Gl+XtcdMQiIxlXC7oUkh4YV8vuK4tUIT7qt5NM+VJKicu4ORGs6Kh9TAjuJLGnXsRjk2wuEJR231eqeXm7nvBO7pk8vyfKZRwH5HAag9dqNkt5tiGT65pzbJrXLRM47Xndel4W+URHo2LFuK7nt/8au1U4YqflGd2LW+Xhc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1663716994; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=uCb2yxc2rwK/M7X4ZHbaziR3/FCtU0FEFxkcoR5+zKo=; b=OP/vNeX+ZmtLueb9CAzOF88BjErL9QSEmg9LzWFfwD+ADOAqc4HuJpsf4tQPF4YCI2YKxgfqGx231gmCchvTZiVsbawPP2He9iHLxse+CznMwHY+zL6k4zB5D/4F+j6x00DW+jnQZxXKWt7an/zFG9xQcyMkSDV9+QYEHZCMXXo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1663716994816743.5244014582572; Tue, 20 Sep 2022 16:36:34 -0700 (PDT) Received: from localhost ([::1]:33150 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oamn2-00047l-4k for importer@patchew.org; Tue, 20 Sep 2022 19:36:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44124) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oalsh-0006xH-1t for qemu-devel@nongnu.org; Tue, 20 Sep 2022 18:38:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:52367) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oalsZ-00083a-0Y for qemu-devel@nongnu.org; Tue, 20 Sep 2022 18:38:18 -0400 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-645-ERSL1uYIMwCZy1fI8iy1HA-1; Tue, 20 Sep 2022 18:38:09 -0400 Received: by mail-qv1-f70.google.com with SMTP id kl19-20020a056214519300b004ad1c1ad474so3045479qvb.10 for ; Tue, 20 Sep 2022 15:38:09 -0700 (PDT) Received: from localhost.localdomain (bras-base-aurron9127w-grc-46-70-31-27-79.dsl.bell.ca. [70.31.27.79]) by smtp.gmail.com with ESMTPSA id de4-20020a05620a370400b006bbb07ebd83sm697499qkb.108.2022.09.20.15.38.07 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 20 Sep 2022 15:38:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663713490; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uCb2yxc2rwK/M7X4ZHbaziR3/FCtU0FEFxkcoR5+zKo=; b=ZG8KwKAFMM1RXg+aOQuRWQrD0/UAkTlAC9Rv8xZdwr/sTTOSVl9Sj2Bj0wdOsfWKp5F3bX RNq16u2oupH7Lc3mWN4+DjhVS3U5uH/QcZKhJtfp9A6P1Qx0cTQCc55j3cZfz9f3sshjpp XwUTqxv+AVsNTMHFGBOLG6VebH/aJss= X-MC-Unique: ERSL1uYIMwCZy1fI8iy1HA-1 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; bh=uCb2yxc2rwK/M7X4ZHbaziR3/FCtU0FEFxkcoR5+zKo=; b=yhOXzTvIPz4skXd2rRgROnSOjHU19Ar+enM+TvaI3Cabk/3RqFKdkHx89lEXs2GtjH W4HZYUakDL8iyG9S69qqYdqaFk478GMy6CyR7Yg9bWSGRG7kqfsvMSF3+/BUr7P7CO6L XRdXLdTzIw2UZ4hsFWP0DZWdPam2sF2kBGi6jeSWcTj/N/aC+YUu0suX8M9lX626lETE +Vb64yib5eK/2eug9yeb2twXy1rgWgbvQ1qbCQD5GV4+9OPIb/42dhZYmpjQ4aEZAvzH 8tsKps7btE3simEzlTlNaMg+qXESkjQ25oUNrTODNjU1v7WitmeF8v8GB3x3yMOsuU8m v7Eg== X-Gm-Message-State: ACrzQf3b+DvvB1G+lgyL27SRALeMsvfr0figilASHKPU0Cc1jdbcEJpb Vg9+RUjJs9x5qcCKlJCXAOSk+YBMZfpI2FBERF/P0d9BAoq9VcNZBNgcLmEWfuqxsjhNq0Xpg0S 06j8ARpc7D6gjAusnl5kPuvmgSKBDw0GQaTaOqJIQUnA6TSKA1CpE286yAIzN9awo X-Received: by 2002:a05:6214:4106:b0:4ac:9160:747b with SMTP id kc6-20020a056214410600b004ac9160747bmr21152949qvb.28.1663713488346; Tue, 20 Sep 2022 15:38:08 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7JS4Ewus8qm8AYU9E4MyrjgDqXhtjiFCtJ7ollEyzhfifS0JCb3yHAj95pYpf9AYUBSPaXvA== X-Received: by 2002:a05:6214:4106:b0:4ac:9160:747b with SMTP id kc6-20020a056214410600b004ac9160747bmr21152932qvb.28.1663713488085; Tue, 20 Sep 2022 15:38:08 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: "Dr . David Alan Gilbert" , "Daniel P . Berrange" , Leonardo Bras Soares Passos , peterx@redhat.com, Juan Quintela Subject: [PATCH 5/5] migration: Use non-atomic ops for clear log bitmap Date: Tue, 20 Sep 2022 18:38:00 -0400 Message-Id: <20220920223800.47467-6-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220920223800.47467-1-peterx@redhat.com> References: <20220920223800.47467-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1663716996732100001 Content-Type: text/plain; charset="utf-8" Since we already have bitmap_mutex to protect either the dirty bitmap or the clear log bitmap, we don't need atomic operations to set/clear/test on the clear log bitmap. Switching all ops from atomic to non-atomic versions, meanwhile touch up the comments to show which lock is in charge. Introduced non-atomic version of bitmap_test_and_clear_atomic(), mostly the same as the atomic version but simplified a few places, e.g. dropped the "old_bits" variable, and also the explicit memory barriers. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu --- include/exec/ram_addr.h | 11 +++++----- include/exec/ramblock.h | 3 +++ include/qemu/bitmap.h | 1 + util/bitmap.c | 45 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 5 deletions(-) diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index f3e0c78161..5092a2e0ff 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -42,7 +42,8 @@ static inline long clear_bmap_size(uint64_t pages, uint8_= t shift) } =20 /** - * clear_bmap_set: set clear bitmap for the page range + * clear_bmap_set: set clear bitmap for the page range. Must be with + * bitmap_mutex held. * * @rb: the ramblock to operate on * @start: the start page number @@ -55,12 +56,12 @@ static inline void clear_bmap_set(RAMBlock *rb, uint64_= t start, { uint8_t shift =3D rb->clear_bmap_shift; =20 - bitmap_set_atomic(rb->clear_bmap, start >> shift, - clear_bmap_size(npages, shift)); + bitmap_set(rb->clear_bmap, start >> shift, clear_bmap_size(npages, shi= ft)); } =20 /** - * clear_bmap_test_and_clear: test clear bitmap for the page, clear if set + * clear_bmap_test_and_clear: test clear bitmap for the page, clear if set. + * Must be with bitmap_mutex held. * * @rb: the ramblock to operate on * @page: the page number to check @@ -71,7 +72,7 @@ static inline bool clear_bmap_test_and_clear(RAMBlock *rb= , uint64_t page) { uint8_t shift =3D rb->clear_bmap_shift; =20 - return bitmap_test_and_clear_atomic(rb->clear_bmap, page >> shift, 1); + return bitmap_test_and_clear(rb->clear_bmap, page >> shift, 1); } =20 static inline bool offset_in_ramblock(RAMBlock *b, ram_addr_t offset) diff --git a/include/exec/ramblock.h b/include/exec/ramblock.h index 6cbedf9e0c..adc03df59c 100644 --- a/include/exec/ramblock.h +++ b/include/exec/ramblock.h @@ -53,6 +53,9 @@ struct RAMBlock { * and split clearing of dirty bitmap on the remote node (e.g., * KVM). The bitmap will be set only when doing global sync. * + * It is only used during src side of ram migration, and it is + * protected by the global ram_state.bitmap_mutex. + * * NOTE: this bitmap is different comparing to the other bitmaps * in that one bit can represent multiple guest pages (which is * decided by the `clear_bmap_shift' variable below). On diff --git a/include/qemu/bitmap.h b/include/qemu/bitmap.h index 82a1d2f41f..3ccb00865f 100644 --- a/include/qemu/bitmap.h +++ b/include/qemu/bitmap.h @@ -253,6 +253,7 @@ void bitmap_set(unsigned long *map, long i, long len); void bitmap_set_atomic(unsigned long *map, long i, long len); void bitmap_clear(unsigned long *map, long start, long nr); bool bitmap_test_and_clear_atomic(unsigned long *map, long start, long nr); +bool bitmap_test_and_clear(unsigned long *map, long start, long nr); void bitmap_copy_and_clear_atomic(unsigned long *dst, unsigned long *src, long nr); unsigned long bitmap_find_next_zero_area(unsigned long *map, diff --git a/util/bitmap.c b/util/bitmap.c index f81d8057a7..8d12e90a5a 100644 --- a/util/bitmap.c +++ b/util/bitmap.c @@ -240,6 +240,51 @@ void bitmap_clear(unsigned long *map, long start, long= nr) } } =20 +bool bitmap_test_and_clear(unsigned long *map, long start, long nr) +{ + unsigned long *p =3D map + BIT_WORD(start); + const long size =3D start + nr; + int bits_to_clear =3D BITS_PER_LONG - (start % BITS_PER_LONG); + unsigned long mask_to_clear =3D BITMAP_FIRST_WORD_MASK(start); + bool dirty =3D false; + + assert(start >=3D 0 && nr >=3D 0); + + /* First word */ + if (nr - bits_to_clear > 0) { + if ((*p) & mask_to_clear) { + dirty =3D true; + } + *p &=3D ~mask_to_clear; + nr -=3D bits_to_clear; + bits_to_clear =3D BITS_PER_LONG; + p++; + } + + /* Full words */ + if (bits_to_clear =3D=3D BITS_PER_LONG) { + while (nr >=3D BITS_PER_LONG) { + if (*p) { + dirty =3D true; + *p =3D 0; + } + nr -=3D BITS_PER_LONG; + p++; + } + } + + /* Last word */ + if (nr) { + mask_to_clear &=3D BITMAP_LAST_WORD_MASK(size); + if ((*p) & mask_to_clear) { + dirty =3D true; + } + *p &=3D ~mask_to_clear; + } + + return dirty; +} + bool bitmap_test_and_clear_atomic(unsigned long *map, long start, long nr) { unsigned long *p =3D map + BIT_WORD(start); --=20 2.32.0