From nobody Sat May 11 13:02:29 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=1664908164; cv=none; d=zohomail.com; s=zohoarc; b=lzKHkbqchsKrpHNRSyauORHI6cB5IPXJA/ETXi2+8/jylzX56eHOldhqHK46JJHzywMl30Re30NPtQ0bQVwh/0hRNvkszkVNMDPTo957+gx3gwLIHotRcwf859ISbMaVVa8MnGIrZRgSloVOgWnfxIi0OR0DJuo8Ie99do2ED8U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664908164; 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=TYjTCxwzaR6k7X+/FwHHerSAsgrOKjvz+lTgu/qcCzM=; b=Et1o3Kc7OBy5Hc9vriF3SEN7jS/Cs6pQ43rz4O3CzFQZd+mQMpDNkw0qToDZiytUcSBjS84VepjIr9ZjUl1oFp+sbFTRf7wwx8KlL5jBiPjNJZ7dsYYBj9sNXd44aDIK9afUk4dSUGrPmppEU5gG5ay+4pPp7JmSvgMbAzQsipk= 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 16649081649021023.1955563685758; Tue, 4 Oct 2022 11:29:24 -0700 (PDT) Received: from localhost ([::1]:58136 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofmfS-0001M6-N3 for importer@patchew.org; Tue, 04 Oct 2022 14:29:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33696) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofmaz-0007SS-Mr for qemu-devel@nongnu.org; Tue, 04 Oct 2022 14:24:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:48913) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofmaq-0005dh-Do for qemu-devel@nongnu.org; Tue, 04 Oct 2022 14:24:39 -0400 Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-379-IZxmu4K6MzyV76XcarZJAw-1; Tue, 04 Oct 2022 14:24:34 -0400 Received: by mail-qk1-f197.google.com with SMTP id bm21-20020a05620a199500b006cf6a722b16so12270082qkb.0 for ; Tue, 04 Oct 2022 11:24:34 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-46-70-31-27-79.dsl.bell.ca. [70.31.27.79]) by smtp.gmail.com with ESMTPSA id i1-20020ac813c1000000b0035c1e18762csm12334514qtj.84.2022.10.04.11.24.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 11:24:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664907875; 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=TYjTCxwzaR6k7X+/FwHHerSAsgrOKjvz+lTgu/qcCzM=; b=M+zFfMrwm5K4CM4HOPBZf45gvkxkHiEKsOq18MMzY57O0hHMQO9LR/rehBzlxhX0G4bZj7 MD4Q9tdc57mD3BCC6EqmdNdVcN9rgfYCC5oA8cSg2VLVDgluddRoa+ciss4H1MVx8hVmXd KVY6I3s+ISUw2j9mJg/3mcpnc3uYiJk= X-MC-Unique: IZxmu4K6MzyV76XcarZJAw-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=TYjTCxwzaR6k7X+/FwHHerSAsgrOKjvz+lTgu/qcCzM=; b=wIFrfdR8zP3lO3f3OCQ/UR5XCOubOGQDYPgS38WY81m2sESb1FPnpVArf326nd0An+ PyAXd1lk2tld3YQpdOM+Ee45Aux2gqups2lbRhYYvG9tzaXt++r+z/t1U7cpmUa5sett Rtlgu7dGSpFvJRhLax5+rLGsZvcj4ZVwKnY+L3LMBXt2DdYkv1ZkpoMYcEndVv7uqk1L Es2CAZJtBsnZwEEBaV12KXwQpNrWroqkYeZTFZ+w4gJbreWF9tU2erhi6dLLfQ7CJK36 GIUCJXHbsBr3ekjI31DG4+WMc828qMwlEuGoxkvlcYbe3U/j8KAokHG0ZppffKPsXKUx RDAg== X-Gm-Message-State: ACrzQf0SMahbGKzod5EjNcpDdGSFl/LcEviZHWvLYD6dkO22TOy6xC9+ +phr4s73VJao4fY6tYdSdysVkMLVJaD8ylBuNtDHY/oHIrAbAeVlFu6JvaKPds2+4NA2N17NSMa 5OkehRiPf5B6UOyrzNn/MDb96MA4ZP3HTIFW+wv0T+Rz8k3EWFw2e7NEmeQnCL0s1 X-Received: by 2002:a05:622a:13:b0:35d:5558:6bfa with SMTP id x19-20020a05622a001300b0035d55586bfamr20881802qtw.160.1664907873425; Tue, 04 Oct 2022 11:24:33 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7dj/2WfYeorJZ3cW8Sn154yvieu/l5+dREPEcbwBTzMt/QJ1rkxJ7Bn7t+8DNfqqQ2YO56ZA== X-Received: by 2002:a05:622a:13:b0:35d:5558:6bfa with SMTP id x19-20020a05622a001300b0035d55586bfamr20881780qtw.160.1664907873176; Tue, 04 Oct 2022 11:24:33 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: "Daniel P . Berrange" , Leonardo Bras Soares Passos , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Subject: [PATCH v2 1/5] migration: Fix possible infinite loop of ram save process Date: Tue, 4 Oct 2022 14:24:26 -0400 Message-Id: <20221004182430.97638-2-peterx@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221004182430.97638-1-peterx@redhat.com> References: <20221004182430.97638-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: 1664908165972100001 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. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu Reviewed-by: Juan Quintela --- 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.37.3 From nobody Sat May 11 13:02:29 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=1664908516; cv=none; d=zohomail.com; s=zohoarc; b=KQhacfWY0DVZGVuUmulMa3aY/Y0RZQ1wR7PkBQ0cpfjDTAXooF5tBfkPjM0HkwCRFdXzK18wrczkBypzTYMXo5PaHMt6Sx8EBMBp+f4n5dRxxTXFTttJmKUJeQRpi5n3CV5NFoR/GFByLL81ZPXMu9DxYa+6KjKzr711dpjZfds= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664908516; 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=aBo8kaSgzrPlPFCxry/VlgmoCrJ5p25bkvjheGnJSRg=; b=JY4Fd8mY5bE7HbjDf5ZJNnWEjcZoWVd2URi87zmeMW2PE7+6dA4HKcwGferU5B5qlVWd7FMIvzEKqecDHzE1xZ2DPUnw+hCgxdNo8oOHj1ZAwWhxtRFPsussWez+LdZdxa1Fj2bHvpOFJuhyeKR/Pdhf5AJgMcjlpmvgR2hFpOg= 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 1664908516462754.119385524716; Tue, 4 Oct 2022 11:35:16 -0700 (PDT) Received: from localhost ([::1]:47388 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofml8-0005ir-16 for importer@patchew.org; Tue, 04 Oct 2022 14:35:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33694) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofmaz-0007SR-Oa for qemu-devel@nongnu.org; Tue, 04 Oct 2022 14:24:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:28399) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofmar-0005ev-K3 for qemu-devel@nongnu.org; Tue, 04 Oct 2022 14:24:39 -0400 Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-373-anBo071rNF-SeSZXAqpMHA-1; Tue, 04 Oct 2022 14:24:35 -0400 Received: by mail-qv1-f72.google.com with SMTP id q6-20020a0cf5c6000000b004b1999f94bcso3247502qvm.15 for ; Tue, 04 Oct 2022 11:24:35 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-46-70-31-27-79.dsl.bell.ca. [70.31.27.79]) by smtp.gmail.com with ESMTPSA id i1-20020ac813c1000000b0035c1e18762csm12334514qtj.84.2022.10.04.11.24.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 11:24:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664907876; 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=aBo8kaSgzrPlPFCxry/VlgmoCrJ5p25bkvjheGnJSRg=; b=BKSR7+jDNF9QkgwLLM+KrE6wEkIM0CVWGMKjR7tF5CooRLo9b+JmSdq4q2y5QFWuAuGCZC DP3EfKAqaGKkTXflFGPLF2gtrtYhJa4e0LmV9izT8TWEQ/XncVrFEgrQcoDvC+Q7zHAPu2 ulDOSBBwRUQo81LdgDl9sd1yG5UKSt4= X-MC-Unique: anBo071rNF-SeSZXAqpMHA-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=aBo8kaSgzrPlPFCxry/VlgmoCrJ5p25bkvjheGnJSRg=; b=DWwID/Rc+cS4ud/TMsFBMMPcO9R3M1l8C0gxi+0JaxmN8kupf/SZAlOZSCO8djeNnc 99diYadTBTz6djT5d1OLuorxOSRTxN3Nl+9AP12+RuWbATDGpa4Zzo0SvOU4I/U8nKhi UL1X5qZdiOaSenLMVMpuZVI0ad/Hoyg1hpW9oj2VhjZ+2g49b/rBYeUUepIv1Jl4t/72 wrxZOHpYrslz4I7oQSjgLsUKwLO1BPvj4Ed14uP3ma5FdoffzxQZzjDfQJRnG0vWezuV VF0Eg4P/6lunU+aK6XeHgLUEqurDnks02HloaFipk30FrdW/54FHounAIBsPN/NxkjRq d6cQ== X-Gm-Message-State: ACrzQf0D48G1IRA9OwzTU06h3qoe4qQkxMPwAWFs6CdYOWtvAghwD1WY Y79uMf9uJfthqBAx+dpKr0UM8i7SQioOefdokOnUlep39itPOXPH+i3joR18DxWXa+13C+67f61 v404ZSZX4weOBDDCa47BVgHAE+9h9/tl8UpiNm33eLF7xIjvy6bXcf16eRAkJX6ln X-Received: by 2002:a05:622a:64a:b0:389:b7de:1890 with SMTP id a10-20020a05622a064a00b00389b7de1890mr2598558qtb.488.1664907874548; Tue, 04 Oct 2022 11:24:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7bKQtSemJ7ZAsUltXW5gAXYOsEaj96PdRYoi4wm/322OND4eap0iBEI+aFc16dWWUx/tJL1Q== X-Received: by 2002:a05:622a:64a:b0:389:b7de:1890 with SMTP id a10-20020a05622a064a00b00389b7de1890mr2598534qtb.488.1664907874204; Tue, 04 Oct 2022 11:24:34 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: "Daniel P . Berrange" , Leonardo Bras Soares Passos , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Subject: [PATCH v2 2/5] migration: Fix race on qemu_file_shutdown() Date: Tue, 4 Oct 2022 14:24:27 -0400 Message-Id: <20221004182430.97638-3-peterx@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221004182430.97638-1-peterx@redhat.com> References: <20221004182430.97638-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: 1664908516848100001 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 Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu Reviewed-by: Juan Quintela --- 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.37.3 From nobody Sat May 11 13:02:29 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=1664908103; cv=none; d=zohomail.com; s=zohoarc; b=Ys50nc5A5K/AAxKjx2gLYvrCgvTpzgE79SXBNMqoMk18LiYOon85UI33+t3Kfaa7McMhpBreSseDyCLDleaAndJOGa34RpfK0ELpFsSsrrNRYZQFgBlDe4d37kWMh+KJH7SIqxVu3J6SPZ4CgFZc9hwoiAzNIwEvbCqDrGaB5gs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664908103; 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=PK+Pg5jcDoHUqFGn7VW26jtdDrWlWl0PsL539K4vTBg=; b=JpptkpFGK2N+t3PUJ3QayqFXMCDxiBxpziWM4xdJ5Pokg0llEMbMJYaAmcjte/wC4qZscMvdq2bclBOhdUUapSInwv9gfI5GxFJXwkt9P9vGPY6E3H2hYNwTksB/PhrErG9GOFxPYRpqE2rO17q5CXEMuRPdkdXNmL+852Maqrk= 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 1664908103976588.5236583181777; Tue, 4 Oct 2022 11:28:23 -0700 (PDT) Received: from localhost ([::1]:58134 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofmeS-0001Lq-TZ for importer@patchew.org; Tue, 04 Oct 2022 14:28:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33700) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofmb1-0007Sk-Fr for qemu-devel@nongnu.org; Tue, 04 Oct 2022 14:24:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:56519) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofmav-0005f0-8Z for qemu-devel@nongnu.org; Tue, 04 Oct 2022 14:24:44 -0400 Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-27-ZN_N_jAyNhiTZchzEO_iiQ-1; Tue, 04 Oct 2022 14:24:36 -0400 Received: by mail-qt1-f200.google.com with SMTP id ay22-20020a05622a229600b0035bbb349e79so9892542qtb.13 for ; Tue, 04 Oct 2022 11:24:36 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-46-70-31-27-79.dsl.bell.ca. [70.31.27.79]) by smtp.gmail.com with ESMTPSA id i1-20020ac813c1000000b0035c1e18762csm12334514qtj.84.2022.10.04.11.24.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 11:24:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664907877; 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=PK+Pg5jcDoHUqFGn7VW26jtdDrWlWl0PsL539K4vTBg=; b=O/fpSssXcqJXYcR3x+vaOFrjkQqBcHC3Eu4opdheZlZbx192AfrJQi6iSEJ0jT3GPBnWTp /aiEXfyQlfMD45rjF3FxjKh4rF8f5/9ZF2LcKDqe/vnm2bQMBKRUFRFLW2EBVu9jO9OjQ2 1g+bFaVE/jEf8mDKTzj+9MvMzvFFlog= X-MC-Unique: ZN_N_jAyNhiTZchzEO_iiQ-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=PK+Pg5jcDoHUqFGn7VW26jtdDrWlWl0PsL539K4vTBg=; b=7oeithdd2mCWaVCKiaw9Z4JmSofnD/Mi9IERKRo7FZ1n+5IrhcfwvTAQo0zcTwxD/J 8ndInGO1vEHC3GeW6mLGjCqR0pl0SHbpZfl4faT3DTnY3Qxiw87xlmd8KSSd62VnoooL 28CNbAlJvkHt2U285AOsQ9Nn/shoR29wP2sFdCMqynrMVxaRR3f8Yw36WIej+0NfV0z/ WOd+igLkrirFaOAe6N4hfalaf8HkNbZ9GG5LvEA7ZZVxC7WfQbhagmn9Vd2moxmoWkrc ZQMJqewAhuhojHue9uoccIVoULoqopi1VTUIBUGuHiNVljqBAL7QIvfFJgOcOGNK38WB iq5A== X-Gm-Message-State: ACrzQf1rCpJv1WCz7K1mpWgL5YwHON7BNCCG6ZpyQksv4YP0y4tsKaw8 E49OogD5wh82EEtCPgUKGC+tfBQAHKu3zgu5L16IRnRWl7MGej2tFRfPZ6ZYf4Y5sBx8y0WkG2V js6hz1Uvwnovbs9N2b9ULVTC+BXdiS+y3YR/Yfo0JLtbCz8lpAD4QX++cMi24ckRx X-Received: by 2002:a05:620a:15d2:b0:6cf:2d38:9c0d with SMTP id o18-20020a05620a15d200b006cf2d389c0dmr17790328qkm.426.1664907875598; Tue, 04 Oct 2022 11:24:35 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5Rc1McOlTHP6YRW4ACEVEU8B79/UZhbjGtl3LMgdXSc90hSvcXvuTNwgPiQBG9B0P3spDjIA== X-Received: by 2002:a05:620a:15d2:b0:6cf:2d38:9c0d with SMTP id o18-20020a05620a15d200b006cf2d389c0dmr17790303qkm.426.1664907875322; Tue, 04 Oct 2022 11:24:35 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: "Daniel P . Berrange" , Leonardo Bras Soares Passos , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Subject: [PATCH v2 3/5] migration: Disallow postcopy preempt to be used with compress Date: Tue, 4 Oct 2022 14:24:28 -0400 Message-Id: <20221004182430.97638-4-peterx@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221004182430.97638-1-peterx@redhat.com> References: <20221004182430.97638-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: 1664908105705100001 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. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu Reviewed-by: Juan Quintela --- migration/migration.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/migration/migration.c b/migration/migration.c index bb8bbddfe4..844bca1ff6 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1336,6 +1336,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.37.3 From nobody Sat May 11 13:02:29 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=1664908517; cv=none; d=zohomail.com; s=zohoarc; b=AKTlpYh7nsZDSDX2O1pwdWcrMqAGEtBjb0P4DSrJSxDtETlujLIlJx7UMEFoBg5qCpo4jH97j7dpmgOVX1R1Akka8IvdVsc6nwIwogWHzGDVdseBPr/gJIz9mWOFJyQ1OJnJXXRUPYpyweJ+Ckjn3/UDhqlPx/pX6jZr2ePNbB0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664908517; 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=qfnQWUDa5K7pjPq/3m1YfD6y3lwpZcpfMbX0SIbFgHE=; b=ZoDL2Iu+TVsCuIIiUkPLXC9OIwWyJj+bD8UEbHy0bFkEVn6A+hAZ6SBWmdBJCYjy1ImaLUqnoHVmFh+SVOLYV0ubEsOBppqiA1Oed8RTJp1AjykBlPDnfXly4IHUwBmX7xSrwOyxmvm4MtN1J/DgZQc5T0cXLScX+A8SIETL7XY= 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 166490851743159.01036769420159; Tue, 4 Oct 2022 11:35:17 -0700 (PDT) Received: from localhost ([::1]:47390 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofmlA-0005j8-46 for importer@patchew.org; Tue, 04 Oct 2022 14:35:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54802) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofmb3-0007Sr-AJ for qemu-devel@nongnu.org; Tue, 04 Oct 2022 14:24:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:54989) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofmax-0005f7-7E for qemu-devel@nongnu.org; Tue, 04 Oct 2022 14:24:46 -0400 Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-504-Hl6E-ifRPqKSSwPowT1ASw-1; Tue, 04 Oct 2022 14:24:37 -0400 Received: by mail-qk1-f197.google.com with SMTP id d18-20020a05620a241200b006ce80a4d74aso12250137qkn.6 for ; Tue, 04 Oct 2022 11:24:37 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-46-70-31-27-79.dsl.bell.ca. [70.31.27.79]) by smtp.gmail.com with ESMTPSA id i1-20020ac813c1000000b0035c1e18762csm12334514qtj.84.2022.10.04.11.24.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 11:24:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664907878; 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=qfnQWUDa5K7pjPq/3m1YfD6y3lwpZcpfMbX0SIbFgHE=; b=XwsPmxjApwVF7YgwQ7J7QMo2amF/L0wU09sFDJbpZAyKEkHnoi2UJseRBsOI9PT8QzQtSR 0OxjGUnCIAlZ5WyxHXZQGfrU8ZMlftHK+upvYZBbHwO7Gbj3cYmEtc7YRtk7KWCzMojxoO oQlk9gcfzLeFPgVhHdpx2KyzSwudPvs= X-MC-Unique: Hl6E-ifRPqKSSwPowT1ASw-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=qfnQWUDa5K7pjPq/3m1YfD6y3lwpZcpfMbX0SIbFgHE=; b=zwvtsjP+2cwXR3cMXf6bW0U7k9GPKw51cs+B1VtmDsjHvTvytzDBWKDDDoDu/WrZQv F6r+j0LpQ8Q0RSPhb0WulJQDEUvw0c+DbFy5afeDgvATvU4axQc887yZ15i2o+ZYu4eO MGmigPbdMkVXZseKGfGePDmRgDs7aloQ1dv/EgLSlnl7ilmTR2AJdzynGYSzdO/hnUgP 0i4Ygk/XnNG7x+7QMABuuxibgIdKUWlllIQnBABRGLc825bCm0D7q6cwbwyXISvAV1al fMrwhrf0RwWGTA1epLVQ5hx5ATn09HFmasLYOT79iR+2uvUuP+Y00SrGI2vnAWPhym+e mUNQ== X-Gm-Message-State: ACrzQf39s/NCweqLKEB3NjoC5tDbGp30p+vwV6HfL7kp9x+nInfXIY9v 1h4vrFzUuXxB3GeDHoTgoCRHB79CZhp1DzuEOyeXxiKHRPqCOpuup0SDn245td4+o1EVmy2Z3ch zaQRwRUN9wyMKufvOH9uHpblr6HmD321MigwQmhDx2bpYgaK+zav29cRbqL0qJOaF X-Received: by 2002:a05:620a:1926:b0:6ce:ee58:1b12 with SMTP id bj38-20020a05620a192600b006ceee581b12mr17644510qkb.80.1664907877134; Tue, 04 Oct 2022 11:24:37 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6UVBMbajgtBKGOHLmluVa5YtWGpEAA/G/10oEw+eq5ejeDgD7YwTt6LEa6PEoEcRc58EsKMg== X-Received: by 2002:a05:620a:1926:b0:6ce:ee58:1b12 with SMTP id bj38-20020a05620a192600b006ceee581b12mr17644475qkb.80.1664907876676; Tue, 04 Oct 2022 11:24:36 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: "Daniel P . Berrange" , Leonardo Bras Soares Passos , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Subject: [PATCH v2 4/5] migration: Use non-atomic ops for clear log bitmap Date: Tue, 4 Oct 2022 14:24:29 -0400 Message-Id: <20221004182430.97638-5-peterx@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221004182430.97638-1-peterx@redhat.com> References: <20221004182430.97638-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1664908518708100003 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 Reviewed-by: Juan Quintela --- 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.37.3 From nobody Sat May 11 13:02:29 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=1664908111; cv=none; d=zohomail.com; s=zohoarc; b=TFiQxK4gG1A7J0/OaIEz8HNwbpnbtiim6e1q7VjhLpwmqwoMZCb9WcX8d86pW0lYqv5oQDyWeYVIQr+IH1sl9EPIRcL9bUWg31tDto1XCa4E+w3CjyJiFodsfTwwwbkgjgzarDfrWncchEMgo6lNHHkHBVvAHNX1TrV5bKGbOk0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664908111; 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=kuI0g2SiMu8yyfxOSQmN2tHqirIL8PEq/zBM9j5AHm4=; b=Bvo8fTdikFUJS7qt5SVF4S46qsFR2jaPJIhU///+5txMQYY2NWaqVf9lUQO47dxot/4aMde/OaugQlC2VaTOuclHtXYsRm4vT1CBsBy2U/XJBpOv6pFbocuBEKa5O50suO+7yHpfLFCH2Hca2yLX4wS2kLFKRZGImCp2gv/LneQ= 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 1664908111483724.0014555350876; Tue, 4 Oct 2022 11:28:31 -0700 (PDT) Received: from localhost ([::1]:46464 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofmeW-0001JN-4K for importer@patchew.org; Tue, 04 Oct 2022 14:28:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54800) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofmb3-0007Sq-A3 for qemu-devel@nongnu.org; Tue, 04 Oct 2022 14:24:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:35700) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofmax-0005fF-7i for qemu-devel@nongnu.org; Tue, 04 Oct 2022 14:24:46 -0400 Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-351-ecc3KnR8MJ2owOsyE1S97Q-1; Tue, 04 Oct 2022 14:24:38 -0400 Received: by mail-qv1-f72.google.com with SMTP id m7-20020a0ce6e7000000b004ad69308f01so9263591qvn.9 for ; Tue, 04 Oct 2022 11:24:38 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-46-70-31-27-79.dsl.bell.ca. [70.31.27.79]) by smtp.gmail.com with ESMTPSA id i1-20020ac813c1000000b0035c1e18762csm12334514qtj.84.2022.10.04.11.24.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 11:24:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664907879; 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=kuI0g2SiMu8yyfxOSQmN2tHqirIL8PEq/zBM9j5AHm4=; b=dU4pVsmgdMLe0UjOWi6jZ3D+Bui+PSKr25c1udpfqzumwrVXVT4+p6ThDV/HPaYhDUs13m 2SXA44PLAK5PPEi74fEySF+TyMagh2CBbdnizl1LjS7FLciDgKgUIln1v0WFunfjg37cQD Lc39UKd60DxaMFH0MdPlxIxySauO928= X-MC-Unique: ecc3KnR8MJ2owOsyE1S97Q-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=kuI0g2SiMu8yyfxOSQmN2tHqirIL8PEq/zBM9j5AHm4=; b=z+LN3ibLNz2Uk/1uj1mFbyzRXCXFwsnsI9CdLRUFituZrl+zJSZcSmz6Zp6az6K8NC GXKnwjxBtF2weqc0t7hiIaA/8iU+MN1CrQ8TgQXakseYjgFOp5rt7ETrNzHnkoSqx4lJ A6yzZhR/pRE0pq9y+4Fh1ICd9JcSa/dFu11uTs2S0hano2ilhfORyjRupCIs2SRQ9cao iapnk4h7303wsYWhnO9DTT4sO91d8ce7izc2HGJJWJTnbaftJicr7jivLC8Iez9ZQJRu urstmoeWAgVr+ijXoS5qECtXDvgYc1J8SZqGr1N5uPzU4cyOq3WFkf2uOmxXNpoaxddM sBfg== X-Gm-Message-State: ACrzQf2bMCjIWwohmERuDzTkhK7NYdWqi4kFr1BN81mEQ6wWCrS1Ouug imS4fkkjzVYY17Jdd2TIZxq+BQ11YT8+TIr7ceriZM71irOcUu8groSzJ2LraIqjpkw4a0EIxPP jkdONXZwMNJolYIkK2XNzuONMXNe6BqBQ6T1GR3PleA3W80tIeFTsdDBapt6L8qtB X-Received: by 2002:a05:6214:242d:b0:4b1:862f:49e0 with SMTP id gy13-20020a056214242d00b004b1862f49e0mr10411674qvb.65.1664907878064; Tue, 04 Oct 2022 11:24:38 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4DVufVW3ehnQey8eIKTIn9T4R7oyyfVSBGpKdCbrPzQdV/UTuB3/mxFENOoAPJiZkGKGAQ/w== X-Received: by 2002:a05:6214:242d:b0:4b1:862f:49e0 with SMTP id gy13-20020a056214242d00b004b1862f49e0mr10411659qvb.65.1664907877809; Tue, 04 Oct 2022 11:24:37 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: "Daniel P . Berrange" , Leonardo Bras Soares Passos , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Subject: [PATCH v2 5/5] migration: Disable multifd explicitly with compression Date: Tue, 4 Oct 2022 14:24:30 -0400 Message-Id: <20221004182430.97638-6-peterx@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221004182430.97638-1-peterx@redhat.com> References: <20221004182430.97638-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: 1664908113526100001 Content-Type: text/plain; charset="utf-8" Multifd thread model does not work for compression, explicitly disable it. Note that previuosly even we can enable both of them, nothing will go wrong, because the compression code has higher priority so multifd feature will just be ignored. Now we'll fail even earlier at config time so the user should be aware of the consequence better. Note that there can be a slight chance of breaking existing users, but let's assume they're not majority and not serious users, or they should have found that multifd is not working already. With that, we can safely drop the check in ram_save_target_page() for using multifd, because when multifd=3Don then compression=3Doff, then the removed check on save_page_use_compression() will also always return false too. Signed-off-by: Peter Xu --- migration/migration.c | 7 +++++++ migration/ram.c | 11 +++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 844bca1ff6..ef00bff0b3 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1349,6 +1349,13 @@ static bool migrate_caps_check(bool *cap_list, } } =20 + if (cap_list[MIGRATION_CAPABILITY_MULTIFD]) { + if (cap_list[MIGRATION_CAPABILITY_COMPRESS]) { + error_setg(errp, "Multifd is not compatible with compress"); + return false; + } + } + return true; } =20 diff --git a/migration/ram.c b/migration/ram.c index 1d42414ecc..1338e47665 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2305,13 +2305,12 @@ static int ram_save_target_page(RAMState *rs, PageS= earchStatus *pss) } =20 /* - * Do not use multifd for: - * 1. Compression as the first page in the new block should be posted = out - * before sending the compressed page - * 2. In postcopy as one whole host page should be placed + * Do not use multifd in postcopy as one whole host page should be + * placed. Meanwhile postcopy requires atomic update of pages, so even + * if host page size =3D=3D guest page size the dest guest during run = may + * still see partially copied pages which is data corruption. */ - if (!save_page_use_compression(rs) && migrate_use_multifd() - && !migration_in_postcopy()) { + if (migrate_use_multifd() && !migration_in_postcopy()) { return ram_save_multifd_page(rs, block, offset); } =20 --=20 2.37.3