From nobody Mon May 13 13:18:57 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=1710709137; cv=none; d=zohomail.com; s=zohoarc; b=GBdqDn0Ic/e6tdOpbM+uR5Ige2aY8+Q2yM28GuRKlBAGfwC2PvApDhj27VOJQB+weiS3v541Mgfg+xp6Y/aL57vDpAlY5fhy9JoOnG7oMlpELqq83nmvn9bna6fLW/BwjrpLr4FhblnZo+f/JeVBVptK2cXrhSS0NctJ5NDjqTo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710709137; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=MbTnciHLM6snyuE4srqwTppUYesQqhHUAcBa6gwlgSM=; b=Y5Q77vN2J7hstUVqb1hdkLzVb7W+rpvaEJRpAO3zHk91ucOMo5bV5WA9vRDV2ZTFEMNBhBohriF3DYL/PqnRBLwR9LW1jfqZGXet4bEuOJGj35zuc52SoI5nPmt+ev67P0pjY1ZrX1ScrViya02gf6fqScUfnBtQnNnp15BBYmU= 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 1710709137227141.47025287895895; Sun, 17 Mar 2024 13:58:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rlxaC-0002BX-EY; Sun, 17 Mar 2024 16:58:16 -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 1rlxaA-0002B8-ML for qemu-devel@nongnu.org; Sun, 17 Mar 2024 16:58:14 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rlxa8-0002Ye-T7 for qemu-devel@nongnu.org; Sun, 17 Mar 2024 16:58:14 -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_256_GCM_SHA384) id us-mta-610-kaKBa3-xOXGfWYj9T5aLAQ-1; Sun, 17 Mar 2024 16:58:09 -0400 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-430b4572a97so12822251cf.1 for ; Sun, 17 Mar 2024 13:58:09 -0700 (PDT) Received: from x1n.. ([99.254.121.117]) by smtp.gmail.com with ESMTPSA id ed8-20020ad44ea8000000b00691879d7a50sm2391566qvb.115.2024.03.17.13.58.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Mar 2024 13:58:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710709091; 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=MbTnciHLM6snyuE4srqwTppUYesQqhHUAcBa6gwlgSM=; b=KG072rqFFUgPjMD+peQ1xzQ//JZJR2FJI0UDZvK1I7s+BFN+ioC9Mf6taAeedQLLw1SDRx heMA0a3WjWtbFMk7rnuXVd5KZZT4dGC6VQWbsTiaDYxDJXSUh2/LmSQlfVqo7yqFCObnFX eFeNSA5BkTCoAPkR7StPtXsk2pqEjsM= X-MC-Unique: kaKBa3-xOXGfWYj9T5aLAQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710709089; x=1711313889; 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=MbTnciHLM6snyuE4srqwTppUYesQqhHUAcBa6gwlgSM=; b=sZea3u+unS65sxlU44IQCD/2etmqS3XZuVE0nMfd9i/TayRM+lHgYYFOVckleLmGub hj2taYMYlvwkjNjtxNVyvWjxw6DAfIW4D4MKHD2bigeuSPhN5zG9o/Tw8iNcwxOLRWGL NbtxjzbX8K7qXfY7brUR3NOPRbEyAp8Buqo4WyZDnYYHSoSbIK3wO7IRbiHxL1wjF1y1 3V+wdqkDGcyRq5dNBT+5zKfH7DPcPGaD7HIIMg9KuUy1jNR3cNfB/83bv4t7rgWqvpNt V9pHL0eoo0zHYG4JpPeVGYOi31Eq9sj5UTO4GQAaf8qT5Xaj+5NKfWKe8V6mnJwNXDCo kbIQ== X-Gm-Message-State: AOJu0YysBYOx3uBxwQ6PCVoLldQ8yWV6bKCQ8DX+GQWTbSkWdMu2um+8 ON/unyh8ypnfJUIk2g7ZM7fEwtQXAbPpAqdaIjYhNAhaAjqvIzWXmeTQTKDTmTPnGEUb9cuQDuV pBOA/V6mdMxyLjhO6sXmMIOwD3LVIRhAoKf7pvZyNsozQZ5nlM1hWnhG/MS7j7+XbVnkDrkNIPh sCKxP7PrQuf3Y+fWzIwsFBD9bxqEQR3ZLn6w== X-Received: by 2002:a05:6214:2c0a:b0:691:ca1:ce8a with SMTP id qq10-20020a0562142c0a00b006910ca1ce8amr8883214qvb.6.1710709088810; Sun, 17 Mar 2024 13:58:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFp0W3MZ3YXyHbOiPw9/LK7NYkTThLMeP+OylfAnrLosrxy4uQEO8S8lm8eRe4EotLqOG3/Fg== X-Received: by 2002:a05:6214:2c0a:b0:691:ca1:ce8a with SMTP id qq10-20020a0562142c0a00b006910ca1ce8amr8883192qvb.6.1710709088414; Sun, 17 Mar 2024 13:58:08 -0700 (PDT) From: peterx@redhat.com To: qemu-devel@nongnu.org, Peter Maydell Cc: Fabiano Rosas , Prasad Pandit , peterx@redhat.com, David Hildenbrand , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PULL 01/10] io: Introduce qio_channel_file_new_dupfd Date: Sun, 17 Mar 2024 16:57:54 -0400 Message-ID: <20240317205803.361163-2-peterx@redhat.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240317205803.361163-1-peterx@redhat.com> References: <20240317205803.361163-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.316, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_SORBS_WEB=1.5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1710709138452100003 From: Fabiano Rosas Add a new helper function for creating a QIOChannelFile channel with a duplicated file descriptor. This saves the calling code from having to do error checking on the dup() call. Suggested-by: "Daniel P. Berrang=C3=A9" Signed-off-by: Fabiano Rosas Reviewed-by: "Daniel P. Berrang=C3=A9" Link: https://lore.kernel.org/r/20240311233335.17299-2-farosas@suse.de Signed-off-by: Peter Xu --- include/io/channel-file.h | 18 ++++++++++++++++++ io/channel-file.c | 12 ++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/io/channel-file.h b/include/io/channel-file.h index 50e8eb1138..d373a4e44d 100644 --- a/include/io/channel-file.h +++ b/include/io/channel-file.h @@ -68,6 +68,24 @@ struct QIOChannelFile { QIOChannelFile * qio_channel_file_new_fd(int fd); =20 +/** + * qio_channel_file_new_dupfd: + * @fd: the file descriptor + * @errp: pointer to initialized error object + * + * Create a new IO channel object for a file represented by the @fd + * parameter. Like qio_channel_file_new_fd(), but the @fd is first + * duplicated with dup(). + * + * The channel will own the duplicated file descriptor and will take + * responsibility for closing it, the original FD is owned by the + * caller. + * + * Returns: the new channel object + */ +QIOChannelFile * +qio_channel_file_new_dupfd(int fd, Error **errp); + /** * qio_channel_file_new_path: * @path: the file path diff --git a/io/channel-file.c b/io/channel-file.c index a6ad7770c6..6436cfb6ae 100644 --- a/io/channel-file.c +++ b/io/channel-file.c @@ -45,6 +45,18 @@ qio_channel_file_new_fd(int fd) return ioc; } =20 +QIOChannelFile * +qio_channel_file_new_dupfd(int fd, Error **errp) +{ + int newfd =3D dup(fd); + + if (newfd < 0) { + error_setg_errno(errp, errno, "Could not dup FD %d", fd); + return NULL; + } + + return qio_channel_file_new_fd(newfd); +} =20 QIOChannelFile * qio_channel_file_new_path(const char *path, --=20 2.44.0 From nobody Mon May 13 13:18:57 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=1710709155; cv=none; d=zohomail.com; s=zohoarc; b=iQXudlge5jE/IWZY29YYm7RMAryMMSRl7WnwcDRJkSZKOz1uVcfbXH/g8bCoyB5RHxrwtQP53J48jCvJzK8RcLBI695x0DKAQqbe1cVXWW7ntdRfat/Gb0pkGTCKlaQGXyBeEqDO55ig2yY4GtLL5vNZErbZk7BjKA3r8jH1a5w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710709155; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=IMe8E26pD9FoMazJMsajFgDf38rg/H2KYQdjS+f1E6g=; b=hF36mDW2OelRf87WX4FQISa4UqnqCLBFFN2G95gInUWkytNfKZEPZe+hTeISmd77nX80yIObzNP5+Wrh4G9tiQBtgPJE0MSCmZVKW7sOmpp4vAPGpUI9Oa1/nkaEIiVAykWHCm8Fg8VnA+Sl9qCdPxMXNdEQPzZN0VqysWz181E= 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 1710709155919297.81470887817886; Sun, 17 Mar 2024 13:59:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rlxaE-0002CX-9I; Sun, 17 Mar 2024 16:58:18 -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 1rlxaC-0002Bc-L1 for qemu-devel@nongnu.org; Sun, 17 Mar 2024 16:58:16 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rlxaA-0002ZJ-Ld for qemu-devel@nongnu.org; Sun, 17 Mar 2024 16:58:16 -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_256_GCM_SHA384) id us-mta-331-tPndS4gYMs6I4ry2Y1hqtA-1; Sun, 17 Mar 2024 16:58:11 -0400 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-78315f4f5c2so120640185a.0 for ; Sun, 17 Mar 2024 13:58:11 -0700 (PDT) Received: from x1n.. ([99.254.121.117]) by smtp.gmail.com with ESMTPSA id ed8-20020ad44ea8000000b00691879d7a50sm2391566qvb.115.2024.03.17.13.58.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Mar 2024 13:58:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710709092; 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=IMe8E26pD9FoMazJMsajFgDf38rg/H2KYQdjS+f1E6g=; b=BO59lIBzuqrttBXCPSTLliu6jIT50/L0tvTrjYqwHXNYi2R9Y9EDiuMXwX+m2GcJfnhjf2 PI2iJNmkdG++LgjS6AgwYtSLi/ujScy9X8wZffJ6bPzBG43LZ37yvBszS7MMTe5/Ax/k4H plrVYLOQsCXNGlEZWc4M00AuvX7ch8g= X-MC-Unique: tPndS4gYMs6I4ry2Y1hqtA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710709090; x=1711313890; 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=IMe8E26pD9FoMazJMsajFgDf38rg/H2KYQdjS+f1E6g=; b=soJpHYNzKy7skwi31ajMjwpBmHYyOHHRSSg1LtD7X/IGN6HCH0L3mJHwHOAmwAm+7f xh21ii5afYJmvByRbogrx5VsQi8Dso9gASIIytW4py+A7nh3/hxY+sJGE3ktsm1N7w6O 5/mgcd0ornBPioh+/XglnRSfd+O99/bopafnWE837Rgea2Fh3cXmdZrLsQihxcTWn3TR A5LjMLySWcRLWwjkgD3G5Offrr+q+LXbORyrtRf9gC5KRVM0+CizEFpgDpc2WNKLHonm Fge2xttY2BowvicinAADIQFmnopQdWJjM0zRumgj6Aefzv3FjpjvMgruJKOZ0uatF4Ms V/9g== X-Gm-Message-State: AOJu0YwmIpmLB7crE6oRh6Xs6Ok/UtpVEDBCymtkMPZQ8YsUwnMlLJh/ DCsqwqtVnNfvaL5FeuWAx0oia4JSU7ARFjDKPSpPiLIIlKrGoUnkTsLooj6OH5v3us8Wn30NJuh vf0edkVb8lPkmBakjWis4crJ9/Easos36OrZvR03YriH94tD9GRYh+9U+5OA8b1UgxCLjvzy913 YVFi8ACmchesmQDPuPbGWgh9gHwfubaLs9vg== X-Received: by 2002:a05:6214:2b9d:b0:690:cdd5:ea47 with SMTP id kr29-20020a0562142b9d00b00690cdd5ea47mr12279967qvb.4.1710709090195; Sun, 17 Mar 2024 13:58:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFQZiv5gWBvvpDvr6dXloatQiTjUR7sercRv8Pl0iHMx9zO5+GpczT/N1BacS2YqQo79Iy5VQ== X-Received: by 2002:a05:6214:2b9d:b0:690:cdd5:ea47 with SMTP id kr29-20020a0562142b9d00b00690cdd5ea47mr12279945qvb.4.1710709089781; Sun, 17 Mar 2024 13:58:09 -0700 (PDT) From: peterx@redhat.com To: qemu-devel@nongnu.org, Peter Maydell Cc: Fabiano Rosas , Prasad Pandit , peterx@redhat.com, David Hildenbrand , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PULL 02/10] migration: Fix error handling after dup in file migration Date: Sun, 17 Mar 2024 16:57:55 -0400 Message-ID: <20240317205803.361163-3-peterx@redhat.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240317205803.361163-1-peterx@redhat.com> References: <20240317205803.361163-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.316, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1710709156338100001 From: Fabiano Rosas The file migration code was allowing a possible -1 from a failed call to dup() to propagate into the new QIOFileChannel::fd before checking for validity. Coverity doesn't like that, possibly due to the the lseek(-1, ...) call that would ensue before returning from the channel creation routine. Use the newly introduced qio_channel_file_dupfd() to properly check the return of dup() before proceeding. Fixes: CID 1539961 Fixes: CID 1539965 Fixes: CID 1539960 Fixes: 2dd7ee7a51 ("migration/multifd: Add incoming QIOChannelFile support") Fixes: decdc76772 ("migration/multifd: Add mapped-ram support to fd: URI") Reported-by: Peter Maydell Signed-off-by: Fabiano Rosas Reviewed-by: "Daniel P. Berrang=C3=A9" Link: https://lore.kernel.org/r/20240311233335.17299-3-farosas@suse.de Signed-off-by: Peter Xu --- migration/fd.c | 9 ++++----- migration/file.c | 14 +++++++------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/migration/fd.c b/migration/fd.c index d4ae72d132..4e2a63a73d 100644 --- a/migration/fd.c +++ b/migration/fd.c @@ -80,6 +80,7 @@ static gboolean fd_accept_incoming_migration(QIOChannel *= ioc, void fd_start_incoming_migration(const char *fdname, Error **errp) { QIOChannel *ioc; + QIOChannelFile *fioc; int fd =3D monitor_fd_param(monitor_cur(), fdname, errp); if (fd =3D=3D -1) { return; @@ -103,15 +104,13 @@ void fd_start_incoming_migration(const char *fdname, = Error **errp) int channels =3D migrate_multifd_channels(); =20 while (channels--) { - ioc =3D QIO_CHANNEL(qio_channel_file_new_fd(dup(fd))); - - if (QIO_CHANNEL_FILE(ioc)->fd =3D=3D -1) { - error_setg(errp, "Failed to duplicate fd %d", fd); + fioc =3D qio_channel_file_new_dupfd(fd, errp); + if (!fioc) { return; } =20 qio_channel_set_name(ioc, "migration-fd-incoming"); - qio_channel_add_watch_full(ioc, G_IO_IN, + qio_channel_add_watch_full(QIO_CHANNEL(fioc), G_IO_IN, fd_accept_incoming_migration, NULL, NULL, g_main_context_get_thread_default()= ); diff --git a/migration/file.c b/migration/file.c index b0b963e0ce..e56c5eb0a5 100644 --- a/migration/file.c +++ b/migration/file.c @@ -58,12 +58,13 @@ bool file_send_channel_create(gpointer opaque, Error **= errp) int fd =3D fd_args_get_fd(); =20 if (fd && fd !=3D -1) { - ioc =3D qio_channel_file_new_fd(dup(fd)); + ioc =3D qio_channel_file_new_dupfd(fd, errp); } else { ioc =3D qio_channel_file_new_path(outgoing_args.fname, flags, 0, e= rrp); - if (!ioc) { - goto out; - } + } + + if (!ioc) { + goto out; } =20 multifd_channel_connect(opaque, QIO_CHANNEL(ioc)); @@ -147,10 +148,9 @@ void file_start_incoming_migration(FileMigrationArgs *= file_args, Error **errp) NULL, NULL, g_main_context_get_thread_default()); =20 - fioc =3D qio_channel_file_new_fd(dup(fioc->fd)); + fioc =3D qio_channel_file_new_dupfd(fioc->fd, errp); =20 - if (!fioc || fioc->fd =3D=3D -1) { - error_setg(errp, "Error creating migration incoming channel"); + if (!fioc) { break; } } while (++i < channels); --=20 2.44.0 From nobody Mon May 13 13:18:57 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=1710709170; cv=none; d=zohomail.com; s=zohoarc; b=DRpDsZQNsH0Fx5TFnvWsYddX8qQUEUBiAEhAnH1EcTTNQS2GBj868zNXvEEyVci5Rs1Nq5vVG2vMvjEWyHniMB1fT9z1jAtiDPQc4PW3kyJB1oTipKArZT5hr6QsVqLL+RtOnIPhYVDJLORq7nEqZPQCFwJtOLPeNWNL3gV0uoo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710709170; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=XYUowG+n3GNsgXqb2DaoNPh3LIqkGmyhv13NH0L54Fw=; b=aq9hUVfK2Q/NCA5QdCdI4MAaVTxZjLpfa7/qO46IhjF0kHf3lCrNfG6sXhirVmMUc/pqEFdk0/PUto7EWfs+xzs6HtVBZeBWZmZ4UiXYEJW95es3Y8tXjHX1xAart8kV0Kg4hcmrYokFDAmP7VZ0iN2nE6Vll6shf035ssS5RZQ= 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 1710709170974508.882018267616; Sun, 17 Mar 2024 13:59:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rlxaE-0002D3-Ux; Sun, 17 Mar 2024 16:58:18 -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 1rlxaD-0002C3-4a for qemu-devel@nongnu.org; Sun, 17 Mar 2024 16:58:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rlxaB-0002a1-G7 for qemu-devel@nongnu.org; Sun, 17 Mar 2024 16:58:16 -0400 Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-549-VIVV1DZ1NwS9VYbWReMSyg-1; Sun, 17 Mar 2024 16:58:12 -0400 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-42f30752eb4so12381271cf.1 for ; Sun, 17 Mar 2024 13:58:12 -0700 (PDT) Received: from x1n.. ([99.254.121.117]) by smtp.gmail.com with ESMTPSA id ed8-20020ad44ea8000000b00691879d7a50sm2391566qvb.115.2024.03.17.13.58.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Mar 2024 13:58:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710709094; 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=XYUowG+n3GNsgXqb2DaoNPh3LIqkGmyhv13NH0L54Fw=; b=MeVV0+E4GmKZtzbuSkqAWyaScAkaBJGGeJRKFaopTblM+3qwW7NExS1YAqWuBV9I8IKqqM QohaZ1Rufwr0LN1qM5+vD2bzkLHM3VD2n8TtE95nBZ/BzLrnNfHnZ3xPBDIj/s3cY921cz oNCuj3itES+WizW5su6bCZ9X7DLvrq0= X-MC-Unique: VIVV1DZ1NwS9VYbWReMSyg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710709092; x=1711313892; 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=XYUowG+n3GNsgXqb2DaoNPh3LIqkGmyhv13NH0L54Fw=; b=NygyC4QlYAvFDARBi/Vz2rsJ6ubVMcYK5MR267ro83kWHX2upCERF1S61rqGj3jwEf tjpkeRqi+ZzIuEsuPO8qHBfTE4Eg/OAbnHf3kmXHeTm1kcAYwSCAqhUmE/H4Yuw4N75R /RUrkLgWpRK9Y3hdOmyu+4u2Pa/SdFGL/ZBAPIQDuDjGONojprkJ6CAEHIGsAS/CgKTp 7CHSo+Wl5UtlNZOnxkZPeVWWy/BFtoi5l/8oGM3JLs9YbTzFxDMFRtog6ZUPEUgHNUBn zzB4FpYtVYeP6gaBlIJhu6TmCAH7tMcMOeViSLF4JnwjTmddxNReYxzFrgXtDt5E/q4F Wcjw== X-Gm-Message-State: AOJu0YwykcfxljpqLR0gYke9OZyVwCP53tBQFkMvlnAgr2NtaohrUT3f a+tBU3cF0oM8YuRiPg85xI5harIwyoFz6Vs21l2mHLPKtxkmU/GHa4ZlPHJdxfvEUIEIAH0QPkc eAVepXTO3WHdRazAexeMSYaegrwFUmHuBRRTsjT8yZ3QUwTF2Emb5g/ZSVxHI5hD3PhGtPta73x BPUApeKEKHZZk4C/plpgKQmh/Nm7s/OyOFtA== X-Received: by 2002:a05:6214:3d9a:b0:691:456f:415a with SMTP id om26-20020a0562143d9a00b00691456f415amr12266596qvb.4.1710709091702; Sun, 17 Mar 2024 13:58:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGZSJinvIUlCV+HoP3OhPxtYoNF8P+oixWGF4tk64l5jNNcKe4wk1uiJ8DcIQYEPd311LE8PA== X-Received: by 2002:a05:6214:3d9a:b0:691:456f:415a with SMTP id om26-20020a0562143d9a00b00691456f415amr12266577qvb.4.1710709091248; Sun, 17 Mar 2024 13:58:11 -0700 (PDT) From: peterx@redhat.com To: qemu-devel@nongnu.org, Peter Maydell Cc: Fabiano Rosas , Prasad Pandit , peterx@redhat.com, David Hildenbrand , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson Subject: [PULL 03/10] physmem: Expose tlb_reset_dirty_range_all() Date: Sun, 17 Mar 2024 16:57:56 -0400 Message-ID: <20240317205803.361163-4-peterx@redhat.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240317205803.361163-1-peterx@redhat.com> References: <20240317205803.361163-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.316, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1710709172337100001 From: Philippe Mathieu-Daud=C3=A9 In order to call tlb_reset_dirty_range_all() outside of system/physmem.c, expose its prototype. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson Link: https://lore.kernel.org/r/20240312201458.79532-2-philmd@linaro.org Signed-off-by: Peter Xu --- include/exec/exec-all.h | 1 + system/physmem.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index ce36bb10d4..3e53501691 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -655,6 +655,7 @@ static inline void mmap_unlock(void) {} =20 void tlb_reset_dirty(CPUState *cpu, ram_addr_t start1, ram_addr_t length); void tlb_set_dirty(CPUState *cpu, vaddr addr); +void tlb_reset_dirty_range_all(ram_addr_t start, ram_addr_t length); =20 MemoryRegionSection * address_space_translate_for_iotlb(CPUState *cpu, int asidx, hwaddr addr, diff --git a/system/physmem.c b/system/physmem.c index 6cfb7a80ab..5441480ff0 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -819,7 +819,7 @@ found: return block; } =20 -static void tlb_reset_dirty_range_all(ram_addr_t start, ram_addr_t length) +void tlb_reset_dirty_range_all(ram_addr_t start, ram_addr_t length) { CPUState *cpu; ram_addr_t start1; --=20 2.44.0 From nobody Mon May 13 13:18:57 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=1710709178; cv=none; d=zohomail.com; s=zohoarc; b=nkQKJgU+veK8nHRIQ1FWiO+jW+TkTowO/pTKiaPGM6qmEg/rZjgIaARWjy4wlzybA1lWKuKbeLwatpSvyCFmWH5K7igsvF4cXTiDSW48lz9TVEYuMHXZb/bLzRiCEoPx1CFaDvn/YhjYevRgaP3CkpobmXHwjR2Zx+sb4keD2rA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710709178; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=rBrNqzZr7Hr6AbPSVoBq/JdhO106IzGnwVAYkki9vHs=; b=WH0K9rvlo+7qW9gf421b00pG9WCf0D+zKNgessyw4tDBe9uPr7qK8qEmxslAbrv+vVTARMA8zXF7paxZ241vUgx2G+1Ye1LIhvTnPIMquKX8okDHH+LG/XZpvEPZIsLENenZu6DJSiOvBq0KYAnDkN1mn2GWdWhwftgAZ0Sq4ng= 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 1710709178708478.6325109616714; Sun, 17 Mar 2024 13:59:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rlxaF-0002DC-Ja; Sun, 17 Mar 2024 16:58:19 -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 1rlxaD-0002CO-NP for qemu-devel@nongnu.org; Sun, 17 Mar 2024 16:58:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rlxaB-0002aR-S4 for qemu-devel@nongnu.org; Sun, 17 Mar 2024 16:58:17 -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_256_GCM_SHA384) id us-mta-622-dj2BnyOlOcmvkq08ABwK-g-1; Sun, 17 Mar 2024 16:58:13 -0400 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-430c76df729so3705081cf.0 for ; Sun, 17 Mar 2024 13:58:13 -0700 (PDT) Received: from x1n.. ([99.254.121.117]) by smtp.gmail.com with ESMTPSA id ed8-20020ad44ea8000000b00691879d7a50sm2391566qvb.115.2024.03.17.13.58.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Mar 2024 13:58:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710709095; 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=rBrNqzZr7Hr6AbPSVoBq/JdhO106IzGnwVAYkki9vHs=; b=b91thGd7VwN+ZKN2PbQbtcZrcUdxjpnchAaSaH/GXvF1Yxe0OsaGJhAHFcyEnbBakt5lIi eLr0eCfbCimtLshAtL0VMvlKzqgf6kWe4aAs3VZ5pD1dmDh5zxxdQlcuTiVLpM448b2v7L 08xDKJkbJWvlvTmiOaPDidoNFAx7yrk= X-MC-Unique: dj2BnyOlOcmvkq08ABwK-g-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710709093; x=1711313893; 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=rBrNqzZr7Hr6AbPSVoBq/JdhO106IzGnwVAYkki9vHs=; b=U/KPGp0vZ7m27GBgrTKsIISjMNklKbexEEYfMXUh5PIdqc/WCk71HO+A66puY1st9O WCI6c3lpOywupSK38Xfgaj4LAZo+IopksHjZEOZ7V28jtmEajG4S/aLeptQiEy/RRz6H JErUXRg7kFXNGNRxeyUNws5+HWo3556nCilrxAO6sIBxbb9GStB7jfip4nEcIfBrU/aT gjq17erp9DA3ahkUwr0y+Qm5VpxMfIBI+kYG3prRDIGazdtzdio21xWGMz8VQACD9w+V p7EcVJcaKVhNOtBPMyDLznyIOsCD1VNElVhQ7egQn4vnab+9jtTUyQYeoA2GfuNh+9lE W9gA== X-Gm-Message-State: AOJu0Yw60+AdyH5vX15SHY62zXC9/VlkZh3miC/wl8bsuFVkHEL8TEZ3 HMk0I16cipvrNeiiQk0tWf7MUjUiwZpJAcemFSCZIKJLSjYvwDFZF60K197no/vQjxlwrfsY9TD z2rTyPBdpcd23UcrLb0iEo0C6OdvLX+UOpO6mfmn1X8R5/dIBqlERBXW7JSW+dZiXQ4WWm0Daxm Eyz2j5dw8eg61YfoxkJDOHJTruj35puuO0Lg== X-Received: by 2002:a05:6214:5345:b0:690:3c85:c5b with SMTP id kv5-20020a056214534500b006903c850c5bmr8961136qvb.3.1710709093146; Sun, 17 Mar 2024 13:58:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF2GXGuZfEQ4KPnVk3RegospeQLPcJekWOLOy2ws/e+5Wn9HY6GSrFBn9Kj8LYmk1rFwfV7Sg== X-Received: by 2002:a05:6214:5345:b0:690:3c85:c5b with SMTP id kv5-20020a056214534500b006903c850c5bmr8961106qvb.3.1710709092510; Sun, 17 Mar 2024 13:58:12 -0700 (PDT) From: peterx@redhat.com To: qemu-devel@nongnu.org, Peter Maydell Cc: Fabiano Rosas , Prasad Pandit , peterx@redhat.com, David Hildenbrand , Paolo Bonzini , Nicholas Piggin , Thomas Huth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson Subject: [PULL 04/10] physmem: Factor cpu_physical_memory_dirty_bits_cleared() out Date: Sun, 17 Mar 2024 16:57:57 -0400 Message-ID: <20240317205803.361163-5-peterx@redhat.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240317205803.361163-1-peterx@redhat.com> References: <20240317205803.361163-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.316, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_SORBS_WEB=1.5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1710709180331100001 From: Nicholas Piggin Signed-off-by: Nicholas Piggin Tested-by: Thomas Huth Message-ID: <20240219061731.232570-1-npiggin@gmail.com> [PMD: Split patch in 2: part 1/2] Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson Link: https://lore.kernel.org/r/20240312201458.79532-3-philmd@linaro.org Signed-off-by: Peter Xu --- include/exec/ram_addr.h | 9 +++++++++ system/physmem.c | 8 +++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index 90676093f5..b060ea9176 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -25,6 +25,7 @@ #include "sysemu/tcg.h" #include "exec/ramlist.h" #include "exec/ramblock.h" +#include "exec/exec-all.h" =20 extern uint64_t total_dirty_pages; =20 @@ -443,6 +444,14 @@ uint64_t cpu_physical_memory_set_dirty_lebitmap(unsign= ed long *bitmap, } #endif /* not _WIN32 */ =20 +static inline void cpu_physical_memory_dirty_bits_cleared(ram_addr_t start, + ram_addr_t lengt= h) +{ + if (tcg_enabled()) { + tlb_reset_dirty_range_all(start, length); + } + +} bool cpu_physical_memory_test_and_clear_dirty(ram_addr_t start, ram_addr_t length, unsigned client); diff --git a/system/physmem.c b/system/physmem.c index 5441480ff0..a4fe3d2bf8 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -881,8 +881,8 @@ bool cpu_physical_memory_test_and_clear_dirty(ram_addr_= t start, memory_region_clear_dirty_bitmap(ramblock->mr, mr_offset, mr_size); } =20 - if (dirty && tcg_enabled()) { - tlb_reset_dirty_range_all(start, length); + if (dirty) { + cpu_physical_memory_dirty_bits_cleared(start, length); } =20 return dirty; @@ -929,9 +929,7 @@ DirtyBitmapSnapshot *cpu_physical_memory_snapshot_and_c= lear_dirty } } =20 - if (tcg_enabled()) { - tlb_reset_dirty_range_all(start, length); - } + cpu_physical_memory_dirty_bits_cleared(start, length); =20 memory_region_clear_dirty_bitmap(mr, offset, length); =20 --=20 2.44.0 From nobody Mon May 13 13:18:57 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=1710709137; cv=none; d=zohomail.com; s=zohoarc; b=ObxZqZ3ml0LZWUa4TKtVwGtkQCAE2tdY5BIHDae3kPjouHKYxmfpVqUQZ0R228C9GuFnShN7hNa6aK6G7ZkANPhKrs/0re1ofVDrKACYgNXNRasjrTcCcWJNqZcRCjm18Ikg+R3SICzbBbtxFj30ywLEWwuVJBbvH8qibEeaAYs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710709137; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=oTTgdRZi6XHKzRmdvfpmMl6ZUE3B1EhX+H7ELDCr2iQ=; b=LaiTJDFK+Ji4R/dcC44MUwaamBSssSbACZIrUn6GkzdZwJpmQzJpPGjKmJkyN90uWwp3fwrKViYNri1bxhdvwIl9E6t3HgEHaCmsUAVJcV6R+1jlDLEStZZggSwjBDUXp560AyjgXcEI7LNrCNzal2OuAJXYNkX8qdNinWNaFGw= 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 1710709137375105.8223367807592; Sun, 17 Mar 2024 13:58:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rlxaH-0002DT-Pe; Sun, 17 Mar 2024 16:58:21 -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 1rlxaE-0002D1-SV for qemu-devel@nongnu.org; Sun, 17 Mar 2024 16:58:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rlxaD-0002al-A0 for qemu-devel@nongnu.org; Sun, 17 Mar 2024 16:58:18 -0400 Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-557-DpU6isATPYaDmUCPN3GRyw-1; Sun, 17 Mar 2024 16:58:15 -0400 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-6912513fc7bso23803186d6.1 for ; Sun, 17 Mar 2024 13:58:15 -0700 (PDT) Received: from x1n.. ([99.254.121.117]) by smtp.gmail.com with ESMTPSA id ed8-20020ad44ea8000000b00691879d7a50sm2391566qvb.115.2024.03.17.13.58.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Mar 2024 13:58:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710709096; 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=oTTgdRZi6XHKzRmdvfpmMl6ZUE3B1EhX+H7ELDCr2iQ=; b=UhUIHq14eXUwMERE9P6DTmksPR6eHAGLfYqkUHqbLhIOwNsFrZHSfbDyqd8SQD/KlQ1v8S P933xkFuq5QD0JdeNj4eMhg4S176TNmBLGF8MwVUBmSo3YFbHZ76bf3JCl1MF1bLleZQvP ZYYaPPo7axfws0xY7tDUZgKJ8/13HeM= X-MC-Unique: DpU6isATPYaDmUCPN3GRyw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710709094; x=1711313894; 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=oTTgdRZi6XHKzRmdvfpmMl6ZUE3B1EhX+H7ELDCr2iQ=; b=IiHsuLRU4JlgukAdDsdOxMnEeRoaUFXurEyn0Tt91bTKNXIbGxkcuCeDKZhe/0bRQq 0tvfJvr7MyPHbldYwUR+rhtcDelj15W0bidIDZWvofruMhl4NTPyQfC3Sj30BW6MhMHH W8zVQ8pUWR+b0UfLfzxEKGBzwwiUJ5TJngfsUpUqVV1JLMrTOWGy4QDR3pbzVtLg0n7O 18nkGItHN5Z4DideIVlEX7xABdfNlUukESdo2zQjHAnStqTfcaiUDwCyq8/hmhozX5/h givkOP2DydBwYoNNDSwbe9OGBni5EORzRufy+rCt5dWZQdDm7Su06LqMJe/cslrYIJXY qVuA== X-Gm-Message-State: AOJu0YyLl6kYkPd87cEWCl1eMm//36vobszkYx2c8/r24jw8pjbW+0Qq q5zNpi58q67uXIFn9ND596cWdVA/WyiSrYaKCb1Ei8NRH4f9P16HEeA2kPT+dv8xKjxZkNhg/2x s9x3QQA9RRAl31Ybriu5ziT6lkXs9tXGj7qEYOusULF1A8V3AZkI/qXzPKy+4IKJzkKor+XR+Oa FRBpUVZmcwLEgiXLuN63JyesiAJ1L0pM8zkQ== X-Received: by 2002:a05:6214:459e:b0:68f:1c80:d78e with SMTP id op30-20020a056214459e00b0068f1c80d78emr12242768qvb.0.1710709094288; Sun, 17 Mar 2024 13:58:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGpH1c847CHfQKkcvLzdMrSe8fW1F+InzOB5L0yy/4SBbEfuurgSvcPP7IXTWnjIUmsEyZ92Q== X-Received: by 2002:a05:6214:459e:b0:68f:1c80:d78e with SMTP id op30-20020a056214459e00b0068f1c80d78emr12242747qvb.0.1710709093743; Sun, 17 Mar 2024 13:58:13 -0700 (PDT) From: peterx@redhat.com To: qemu-devel@nongnu.org, Peter Maydell Cc: Fabiano Rosas , Prasad Pandit , peterx@redhat.com, David Hildenbrand , Paolo Bonzini , Nicholas Piggin , Thomas Huth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson Subject: [PULL 05/10] physmem: Fix migration dirty bitmap coherency with TCG memory access Date: Sun, 17 Mar 2024 16:57:58 -0400 Message-ID: <20240317205803.361163-6-peterx@redhat.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240317205803.361163-1-peterx@redhat.com> References: <20240317205803.361163-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.316, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1710709138452100001 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=C3=A9 Reviewed-by: Richard Henderson Link: https://lore.kernel.org/r/20240312201458.79532-4-philmd@linaro.org Signed-off-by: Peter Xu --- 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); + } =20 if (rb->clear_bmap) { /* --=20 2.44.0 From nobody Mon May 13 13:18:57 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=1710709137; cv=none; d=zohomail.com; s=zohoarc; b=n2r1TvoSumsE9X9CEV6bh0LHtOFeklVTsa/O/P0MFLnQfMIEsNpCifl6A81jPbr27Wlcx5oxF4MvpeO4HeYDQKXnBYPQCfqBy302XIIF6Hu7/X4+iKwkIJmYbZfLpLJHpzewitjaQGFCE9Q+/W9LRU6EDnTo3LfezG0peDwUx+U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710709137; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=6UIjggYcWeZ8GItTuth3oRveQdzD9M6dVWkAHyLU+XM=; b=Sr519zAgg80Wu//owZ0VPQygH7thw0KHJXiXLe1iVK+0tmMAJE4K/1qjG+du6Gm+tuDxdItaq2RUWEJhhQGrdDn2sZckSN4+Y6e5HjGBxndCdileKXOqbaLTdjJpSTanJZ8EEBCJDDgZmE0lC2TQyzwawotU5iwNktqmbbrCZgY= 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 171070913714097.2859476890842; Sun, 17 Mar 2024 13:58:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rlxaJ-0002Ez-Ch; Sun, 17 Mar 2024 16:58:23 -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 1rlxaG-0002DY-VH for qemu-devel@nongnu.org; Sun, 17 Mar 2024 16:58:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rlxaE-0002bG-RP for qemu-devel@nongnu.org; Sun, 17 Mar 2024 16:58:20 -0400 Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-441-voq1F1fUNzqoZV9uFOWyqw-1; Sun, 17 Mar 2024 16:58:16 -0400 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-430c76df729so3705261cf.0 for ; Sun, 17 Mar 2024 13:58:16 -0700 (PDT) Received: from x1n.. ([99.254.121.117]) by smtp.gmail.com with ESMTPSA id ed8-20020ad44ea8000000b00691879d7a50sm2391566qvb.115.2024.03.17.13.58.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Mar 2024 13:58:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710709098; 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=6UIjggYcWeZ8GItTuth3oRveQdzD9M6dVWkAHyLU+XM=; b=d3b5z17tVdSvPHHmGRN7heLrIKSbMsygZci4WkVNoJqurA3FroGv30YAAj0lrTCBd8Ex5Q fe4mQFUz3jXiaw0ogACJdHOiNUePe5gJBgvgnvaindrgmG2uH7Nr9BiPw6KHFAmHHkIws7 7mYkrNL/2M6vG324hsrEydLyyUf7P88= X-MC-Unique: voq1F1fUNzqoZV9uFOWyqw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710709096; x=1711313896; 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=6UIjggYcWeZ8GItTuth3oRveQdzD9M6dVWkAHyLU+XM=; b=K4t5wlVReupjS95hhGP4kopxM2ql8+Nee63sAZPdsOO/nk7/zoR+8gBI2cPh58Q6Qa IMzbCSQAL+mEHYi06A4FzYMkBl6zDQVTAjzAoLMnONSKNj9VkB5GQABUsYD9YIBSsmcb PMHu+wzWVKgSK+JeSbYw8ssrJdWyPjgqzLKSxQ7f06ksOIsky5N+aNqXFT6Gor1Zc8zZ MSlo0MXEGutLJWmNna1IUSqNWdOipcKfJw69/DiL33X0pFLBjZsiU9kTZWqcDg03wEi2 YuBcw8NBN7vBwZIHMy66foHEjQSxEUloGJvx0tmsujFzlq6SK6EvV/PHVosZZH0wy7NW ndRA== X-Gm-Message-State: AOJu0YwvhfGqvbpaBZOGxqT77A7VBwEXP+siGhR1l1tjj7yddJQHaPvJ zaiRoc+6xPL3PjdVKolKAcTXNAM3PWo0/9HQEkDO2XM8FB3Lq3U2yzlP3z4BmgppxUv21Dzu7Jg 7tcg9/wilfPvUJiDBu24HqZq5nMOxRGJi6We+pP5MpmoqMgg4r56RhVPscVm7h7m9+Evz74M5PK eRcEj8WKGkPJqrCOn+0tUQPgxTx/uKrHxFOg== X-Received: by 2002:a05:6214:2c0a:b0:691:ca1:ce8a with SMTP id qq10-20020a0562142c0a00b006910ca1ce8amr8883382qvb.6.1710709095852; Sun, 17 Mar 2024 13:58:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGG6717Cl6wCmud2Cm8fiETPePyBDz6w5iAjimAta3jxtXtl1MNb5bacdFVyBemJ+3R08bnQA== X-Received: by 2002:a05:6214:2c0a:b0:691:ca1:ce8a with SMTP id qq10-20020a0562142c0a00b006910ca1ce8amr8883361qvb.6.1710709095312; Sun, 17 Mar 2024 13:58:15 -0700 (PDT) From: peterx@redhat.com To: qemu-devel@nongnu.org, Peter Maydell Cc: Fabiano Rosas , Prasad Pandit , peterx@redhat.com, David Hildenbrand , Paolo Bonzini , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Markus Armbruster , qemu-stable , Kevin Wolf , Stefan Hajnoczi Subject: [PULL 06/10] migration: Skip only empty block devices Date: Sun, 17 Mar 2024 16:57:59 -0400 Message-ID: <20240317205803.361163-7-peterx@redhat.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240317205803.361163-1-peterx@redhat.com> References: <20240317205803.361163-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.316, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_SORBS_WEB=1.5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1710709138452100002 From: C=C3=A9dric Le Goater The block .save_setup() handler calls a helper routine init_blk_migration() which builds a list of block devices to take into account for migration. When one device is found to be empty (sectors =3D=3D 0), the loop exits and all the remaining devices are ignored. This is a regression introduced when bdrv_iterate() was removed. Change that by skipping only empty devices. Cc: Markus Armbruster Cc: qemu-stable Suggested-by: Kevin Wolf Fixes: fea68bb6e9fa ("block: Eliminate bdrv_iterate(), use bdrv_next()") Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Stefan Hajnoczi Reviewed-by: Kevin Wolf Link: https://lore.kernel.org/r/20240312120431.550054-1-clg@redhat.com [peterx: fix "Suggested-by:"] Signed-off-by: Peter Xu --- migration/block.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/migration/block.c b/migration/block.c index 8c6ebafacc..2b9054889a 100644 --- a/migration/block.c +++ b/migration/block.c @@ -402,7 +402,10 @@ static int init_blk_migration(QEMUFile *f) } =20 sectors =3D bdrv_nb_sectors(bs); - if (sectors <=3D 0) { + if (sectors =3D=3D 0) { + continue; + } + if (sectors < 0) { ret =3D sectors; bdrv_next_cleanup(&it); goto out; --=20 2.44.0 From nobody Mon May 13 13:18:57 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=1710709166; cv=none; d=zohomail.com; s=zohoarc; b=cWjAmG5UYoegNzIhYi+gZaQSag4NymOQpwsJmqHgaplzSI+jgFgSmoMcUPudUeRYRr8F490ynns8nstNMMxdJujh7akhJsaOGn4NSatfw03c2cyl9pwEflUFVmNlyUFLmbTOreMmnJuePgniThGz4zqbIm/0P5kz8+cCJzuuKb4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710709166; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=4Zbw8biRkRCNaWvBEX3kRfgYXQbqsFbG3GajvMEGhTg=; b=NKREC09qF7jpNQKZvL0X0ZHWLbAL3NU510Oe7RT0qLKSY9v+h4yZELKd/ovjg08RqQ9AzVo4ugrvmt1RJH3XGoCOFlO0BsNGc60SfHdy/eu9zMjmthKO9AANfVaYEjOMmxWhtt3Ik+1CSZQJXBp9Ub7g70LaFflDnhTTqnmttJY= 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 1710709166031229.3068764886042; Sun, 17 Mar 2024 13:59:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rlxaK-0002FP-K8; Sun, 17 Mar 2024 16:58:24 -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 1rlxaI-0002EI-76 for qemu-devel@nongnu.org; Sun, 17 Mar 2024 16:58:22 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rlxaG-0002bn-A6 for qemu-devel@nongnu.org; Sun, 17 Mar 2024 16:58:21 -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_256_GCM_SHA384) id us-mta-312-QxcSPclsPCCA3pOj07GZRg-1; Sun, 17 Mar 2024 16:58:18 -0400 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-42f30752eb4so12381511cf.1 for ; Sun, 17 Mar 2024 13:58:18 -0700 (PDT) Received: from x1n.. ([99.254.121.117]) by smtp.gmail.com with ESMTPSA id ed8-20020ad44ea8000000b00691879d7a50sm2391566qvb.115.2024.03.17.13.58.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Mar 2024 13:58:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710709099; 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=4Zbw8biRkRCNaWvBEX3kRfgYXQbqsFbG3GajvMEGhTg=; b=OP7p5NUeEgHANowWLTOP24vqn0HTA0qYWb0Ii0X0+1X3FgXHlsuS99Oz1v9TUM5GhI4T21 YXzuZrl0aw5ViAHAvavhZ3GxDdZWk07zeYr3+14bQSu9cIEbLUXHOKLHrfvxbv3YuQ5PwT BLGsdHezPkyYLjWKESsccUgADLUSU0Q= X-MC-Unique: QxcSPclsPCCA3pOj07GZRg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710709097; x=1711313897; 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=4Zbw8biRkRCNaWvBEX3kRfgYXQbqsFbG3GajvMEGhTg=; b=ZqRHp7SwVMhd3V/uOjvHaQKRzh6u/HHG5+254H1KqpU5Lo+43iEgeewIRt28DqJ/8o lj/Qjmu2IfBs2/UMP8Cfml287yy4ijKHcUKlq4PHzdRJZO5TLaAkfBLSaRvsYFu8Unat DJ+kHn4Ra6gTt/P9EbEMZL30xkZceSQJy5Z/ODxwTxJsp9BXcMxBy4gywN280LY3uLGV jg/gg3POLsb/Ivv3n84GFn7PtjQLlLlypkreblM0J4OcLYyU9Wh+zMG+147AEKcNP5I0 gSqJ5PkGP2BpwSqlZkc0AxD2jJGbXYR0Mrf5IWI2kNhQV8O2gAF/v+HGYCDj4SLoafgz TLQA== X-Gm-Message-State: AOJu0YyvaANCuLCHIA967cYmhns5KGs2gHBhYcH47gB53U3dT/j7yVE9 SYGWTYujOKgRdH+MQz13tvRpMwQSZKw9tCPuAEfySAespcYCyLzEANhor2LJCqe8gcG5xoqjnRv J/iIHWNF+yDEGUJxgbPyxTdEd3MY6fUeD9h+aPg7aur/9NXuP1ZrTpP4Yv9eQQiQwReVsdNlVQq wk6it7cJwtM6HiUYrnQ8xegtjQ0wFxQQJxJA== X-Received: by 2002:a05:6214:2d42:b0:690:a71a:d381 with SMTP id na2-20020a0562142d4200b00690a71ad381mr11999334qvb.6.1710709097266; Sun, 17 Mar 2024 13:58:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFUlM9mFsY1L2Q7I0bhBrBvjJxHwIfvQhOwmr0mtE19T6XD/oeuPcANkW2nQ9XgtghdTO3Yvw== X-Received: by 2002:a05:6214:2d42:b0:690:a71a:d381 with SMTP id na2-20020a0562142d4200b00690a71ad381mr11999306qvb.6.1710709096758; Sun, 17 Mar 2024 13:58:16 -0700 (PDT) From: peterx@redhat.com To: qemu-devel@nongnu.org, Peter Maydell Cc: Fabiano Rosas , Prasad Pandit , peterx@redhat.com, David Hildenbrand , Paolo Bonzini , Steve Sistare , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 07/10] migration: cpr-reboot documentation Date: Sun, 17 Mar 2024 16:58:00 -0400 Message-ID: <20240317205803.361163-8-peterx@redhat.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240317205803.361163-1-peterx@redhat.com> References: <20240317205803.361163-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.316, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_SORBS_WEB=1.5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1710709166329100001 From: Steve Sistare Signed-off-by: Steve Sistare Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Fabiano Rosas Link: https://lore.kernel.org/r/1710338119-330923-1-git-send-email-steven.s= istare@oracle.com Signed-off-by: Peter Xu --- docs/devel/migration/CPR.rst | 147 ++++++++++++++++++++++++++++++ docs/devel/migration/features.rst | 1 + 2 files changed, 148 insertions(+) create mode 100644 docs/devel/migration/CPR.rst diff --git a/docs/devel/migration/CPR.rst b/docs/devel/migration/CPR.rst new file mode 100644 index 0000000000..63c36470cf --- /dev/null +++ b/docs/devel/migration/CPR.rst @@ -0,0 +1,147 @@ +CheckPoint and Restart (CPR) +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D + +CPR is the umbrella name for a set of migration modes in which the +VM is migrated to a new QEMU instance on the same host. It is +intended for use when the goal is to update host software components +that run the VM, such as QEMU or even the host kernel. At this time, +cpr-reboot is the only available mode. + +Because QEMU is restarted on the same host, with access to the same +local devices, CPR is allowed in certain cases where normal migration +would be blocked. However, the user must not modify the contents of +guest block devices between quitting old QEMU and starting new QEMU. + +CPR unconditionally stops VM execution before memory is saved, and +thus does not depend on any form of dirty page tracking. + +cpr-reboot mode +--------------- + +In this mode, QEMU stops the VM, and writes VM state to the migration +URI, which will typically be a file. After quitting QEMU, the user +resumes by running QEMU with the ``-incoming`` option. Because the +old and new QEMU instances are not active concurrently, the URI cannot +be a type that streams data from one instance to the other. + +Guest RAM can be saved in place if backed by shared memory, or can be +copied to a file. The former is more efficient and is therefore +preferred. + +After state and memory are saved, the user may update userland host +software before restarting QEMU and resuming the VM. Further, if +the RAM is backed by persistent shared memory, such as a DAX device, +then the user may reboot to a new host kernel before restarting QEMU. + +This mode supports VFIO devices provided the user first puts the +guest in the suspended runstate, such as by issuing the +``guest-suspend-ram`` command to the QEMU guest agent. The agent +must be pre-installed in the guest, and the guest must support +suspend to RAM. Beware that suspension can take a few seconds, so +the user should poll to see the suspended state before proceeding +with the CPR operation. + +Usage +^^^^^ + +It is recommended that guest RAM be backed with some type of shared +memory, such as ``memory-backend-file,share=3Don``, and that the +``x-ignore-shared`` capability be set. This combination allows memory +to be saved in place. Otherwise, after QEMU stops the VM, all guest +RAM is copied to the migration URI. + +Outgoing: + * Set the migration mode parameter to ``cpr-reboot``. + * Set the ``x-ignore-shared`` capability if desired. + * Issue the ``migrate`` command. It is recommended the the URI be a + ``file`` type, but one can use other types such as ``exec``, + provided the command captures all the data from the outgoing side, + and provides all the data to the incoming side. + * Quit when QEMU reaches the postmigrate state. + +Incoming: + * Start QEMU with the ``-incoming defer`` option. + * Set the migration mode parameter to ``cpr-reboot``. + * Set the ``x-ignore-shared`` capability if desired. + * Issue the ``migrate-incoming`` command. + * If the VM was running when the outgoing ``migrate`` command was + issued, then QEMU automatically resumes VM execution. + +Example 1 +^^^^^^^^^ +:: + + # qemu-kvm -monitor stdio + -object memory-backend-file,id=3Dram0,size=3D4G,mem-path=3D/dev/dax0.0,a= lign=3D2M,share=3Don -m 4G + ... + + (qemu) info status + VM status: running + (qemu) migrate_set_parameter mode cpr-reboot + (qemu) migrate_set_capability x-ignore-shared on + (qemu) migrate -d file:vm.state + (qemu) info status + VM status: paused (postmigrate) + (qemu) quit + + ### optionally update kernel and reboot + # systemctl kexec + kexec_core: Starting new kernel + ... + + # qemu-kvm ... -incoming defer + (qemu) info status + VM status: paused (inmigrate) + (qemu) migrate_set_parameter mode cpr-reboot + (qemu) migrate_set_capability x-ignore-shared on + (qemu) migrate_incoming file:vm.state + (qemu) info status + VM status: running + +Example 2: VFIO +^^^^^^^^^^^^^^^ +:: + + # qemu-kvm -monitor stdio + -object memory-backend-file,id=3Dram0,size=3D4G,mem-path=3D/dev/dax0.0,a= lign=3D2M,share=3Don -m 4G + -device vfio-pci, ... + -chardev socket,id=3Dqga0,path=3Dqga.sock,server=3Don,wait=3Doff + -device virtserialport,chardev=3Dqga0,name=3Dorg.qemu.guest_agent.0 + ... + + (qemu) info status + VM status: running + + # echo '{"execute":"guest-suspend-ram"}' | ncat --send-only -U qga.sock + + (qemu) info status + VM status: paused (suspended) + (qemu) migrate_set_parameter mode cpr-reboot + (qemu) migrate_set_capability x-ignore-shared on + (qemu) migrate -d file:vm.state + (qemu) info status + VM status: paused (postmigrate) + (qemu) quit + + ### optionally update kernel and reboot + # systemctl kexec + kexec_core: Starting new kernel + ... + + # qemu-kvm ... -incoming defer + (qemu) info status + VM status: paused (inmigrate) + (qemu) migrate_set_parameter mode cpr-reboot + (qemu) migrate_set_capability x-ignore-shared on + (qemu) migrate_incoming file:vm.state + (qemu) info status + VM status: paused (suspended) + (qemu) system_wakeup + (qemu) info status + VM status: running + +Caveats +^^^^^^^ + +cpr-reboot mode may not be used with postcopy, background-snapshot, +or COLO. diff --git a/docs/devel/migration/features.rst b/docs/devel/migration/featu= res.rst index 9d1abd2587..d5ca7b86d5 100644 --- a/docs/devel/migration/features.rst +++ b/docs/devel/migration/features.rst @@ -11,3 +11,4 @@ Migration has plenty of features to support different use= cases. vfio virtio mapped-ram + CPR --=20 2.44.0 From nobody Mon May 13 13:18:57 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=1710709188; cv=none; d=zohomail.com; s=zohoarc; b=l8Uc0u/b2z3rx7iGd1yHG649dDNcruE9J2z/uZMEi4Mjtyc0kTa/+iBagijUi+HBv2DQvEMSn3U7VVuAYFZjTcL1iHHKrm+xBNix1i65kA14cOAyUTfEUNcoJ73I4HjflchmCVvrqtThTx8Vn4i5xv8CstQkdBmMdCLSYQPlRDw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710709188; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=2jCIs6kDNXpzb96UsCwUy6eatdgo/oXMCneO7owVbBs=; b=e9z3QatbW6Nt7nNmg8hcODsVhFoWQS7934bx4JqpqbmiUH5b3FGibQ5dab+Q0z8gTK0DX4Bh+48EqEev3hu+wjdFtXlfPlBZLVFa8IbcxwOi8MUu2ino5UzLi65gWafAWVB5v79/ODSAJkicAuJXPzR2GFGf/miritdwgK9lak0= 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 171070918888570.3608091489723; Sun, 17 Mar 2024 13:59:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rlxaM-0002Fr-RW; Sun, 17 Mar 2024 16:58:27 -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 1rlxaK-0002FL-5P for qemu-devel@nongnu.org; Sun, 17 Mar 2024 16:58:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rlxaI-0002dq-A5 for qemu-devel@nongnu.org; Sun, 17 Mar 2024 16:58:23 -0400 Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-499-Gjelsqd9MWS6lytSCIANbw-1; Sun, 17 Mar 2024 16:58:19 -0400 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-42f30752eb4so12381631cf.1 for ; Sun, 17 Mar 2024 13:58:19 -0700 (PDT) Received: from x1n.. ([99.254.121.117]) by smtp.gmail.com with ESMTPSA id ed8-20020ad44ea8000000b00691879d7a50sm2391566qvb.115.2024.03.17.13.58.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Mar 2024 13:58:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710709101; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2jCIs6kDNXpzb96UsCwUy6eatdgo/oXMCneO7owVbBs=; b=PcJeXUiFKbC49nFinmG7R0D7vS1y2z5DL0cbGbEhFrt9R7SpNp5UQJ/dzWzgz1BPs6Pk3K XdwNu/mIiuSQ+FvDLybOwL5FHDI4pRaoGlkhynSFlfkkKRjQB90+rvEwWVAEKNTqKhFGFo f6C1xjRO2vg/eU+UWgPkEip7W+jfSrk= X-MC-Unique: Gjelsqd9MWS6lytSCIANbw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710709098; x=1711313898; 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=2jCIs6kDNXpzb96UsCwUy6eatdgo/oXMCneO7owVbBs=; b=bfYocP/UVh7fi1XtB7IYGtqbmnd/0XQHlBnmr8rqzTp0KYSWhWs5o/luOOozCzt6+F vY6SsQ8rd27jpfJhiNSQj496Y4acq0oQChvYev5CWHjmMvkdnpDIptbf/INwzI3hWoS6 r7hM22G3o+LhILv7cpXE4rprXJVkkaQcUXgxM1E1jPFw4mS19kn6BYDywFsa7ojWBbFl TGLD0r0YBlPEYpx4ccdwvwlfrCf5R1wkl14D//gjPOcsDQy4TMxs2bc7Ih5l8Q1vq43G hyl79b+uZD0EZRDSQpSneZevT8JorqLqTXPJ8g1mRGZuXQNK0UVn5H8O6ohNWcGwV2GC 2cVw== X-Gm-Message-State: AOJu0Yw1eC7q2eYpqqUgz03NqwHQVZW8HSkAqc3c94Q1BPLLMINKCk04 0cZknkXCoi+PQMKShtTYepSvtzljKP8GTTwWGDvY1WCO3Dazi+EH9G+VEGLmifI6WhI/2sSc1c8 4sLj09S+D49Fk16TA6T2Hqu0QaWo15SX+uIo3dZaSAMDBLP6SZDjrWqERpQw7Ct8x4Xaro8AsYR xo3Rqd3vuF2P/MFjIW9lDdXakgsSdF0vph6w== X-Received: by 2002:a05:6214:3d9a:b0:691:456f:415a with SMTP id om26-20020a0562143d9a00b00691456f415amr12266759qvb.4.1710709098194; Sun, 17 Mar 2024 13:58:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGveN+v5Zb66b+uDk4qKwUjcp2MUKH2M4q80bLOvJRperog77Y1+yzEgssHSoGLjB6kd+FdQg== X-Received: by 2002:a05:6214:3d9a:b0:691:456f:415a with SMTP id om26-20020a0562143d9a00b00691456f415amr12266742qvb.4.1710709097729; Sun, 17 Mar 2024 13:58:17 -0700 (PDT) From: peterx@redhat.com To: qemu-devel@nongnu.org, Peter Maydell Cc: Fabiano Rosas , Prasad Pandit , peterx@redhat.com, David Hildenbrand , Paolo Bonzini Subject: [PULL 08/10] migration: Fix iocs leaks during file and fd migration Date: Sun, 17 Mar 2024 16:58:01 -0400 Message-ID: <20240317205803.361163-9-peterx@redhat.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240317205803.361163-1-peterx@redhat.com> References: <20240317205803.361163-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: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.316, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1710709190370100001 Content-Type: text/plain; charset="utf-8" From: Fabiano Rosas The memory for the io channels is being leaked in three different ways during file migration: 1) if the offset check fails we never drop the ioc reference; 2) we allocate an extra channel for no reason; 3) if multifd is enabled but channel creation fails when calling dup(), we leave the previous channels around along with the glib polling; Fix all issues by restructuring the code to first allocate the channels and only register the watches when all channels have been created. For multifd, the file and fd migrations can share code because both are backed by a QIOChannelFile. For the non-multifd case, the fd needs to be separate because it is backed by a QIOChannelSocket. Fixes: 2dd7ee7a51 ("migration/multifd: Add incoming QIOChannelFile support") Fixes: decdc76772 ("migration/multifd: Add mapped-ram support to fd: URI") Reported-by: Peter Xu Signed-off-by: Fabiano Rosas Link: https://lore.kernel.org/r/20240313212824.16974-2-farosas@suse.de Signed-off-by: Peter Xu --- migration/file.h | 1 + migration/fd.c | 29 +++++++----------------- migration/file.c | 58 ++++++++++++++++++++++++++++++------------------ 3 files changed, 46 insertions(+), 42 deletions(-) diff --git a/migration/file.h b/migration/file.h index 9f71e87f74..7699c04677 100644 --- a/migration/file.h +++ b/migration/file.h @@ -20,6 +20,7 @@ void file_start_outgoing_migration(MigrationState *s, int file_parse_offset(char *filespec, uint64_t *offsetp, Error **errp); void file_cleanup_outgoing_migration(void); bool file_send_channel_create(gpointer opaque, Error **errp); +void file_create_incoming_channels(QIOChannel *ioc, Error **errp); int file_write_ramblock_iov(QIOChannel *ioc, const struct iovec *iov, int niov, RAMBlock *block, Error **errp); int multifd_file_recv_data(MultiFDRecvParams *p, Error **errp); diff --git a/migration/fd.c b/migration/fd.c index 4e2a63a73d..39a52e5c90 100644 --- a/migration/fd.c +++ b/migration/fd.c @@ -18,6 +18,7 @@ #include "qapi/error.h" #include "channel.h" #include "fd.h" +#include "file.h" #include "migration.h" #include "monitor/monitor.h" #include "io/channel-file.h" @@ -80,7 +81,6 @@ static gboolean fd_accept_incoming_migration(QIOChannel *= ioc, void fd_start_incoming_migration(const char *fdname, Error **errp) { QIOChannel *ioc; - QIOChannelFile *fioc; int fd =3D monitor_fd_param(monitor_cur(), fdname, errp); if (fd =3D=3D -1) { return; @@ -94,26 +94,13 @@ void fd_start_incoming_migration(const char *fdname, Er= ror **errp) return; } =20 - qio_channel_set_name(ioc, "migration-fd-incoming"); - qio_channel_add_watch_full(ioc, G_IO_IN, - fd_accept_incoming_migration, - NULL, NULL, - g_main_context_get_thread_default()); - if (migrate_multifd()) { - int channels =3D migrate_multifd_channels(); - - while (channels--) { - fioc =3D qio_channel_file_new_dupfd(fd, errp); - if (!fioc) { - return; - } - - qio_channel_set_name(ioc, "migration-fd-incoming"); - qio_channel_add_watch_full(QIO_CHANNEL(fioc), G_IO_IN, - fd_accept_incoming_migration, - NULL, NULL, - g_main_context_get_thread_default()= ); - } + file_create_incoming_channels(ioc, errp); + } else { + qio_channel_set_name(ioc, "migration-fd-incoming"); + qio_channel_add_watch_full(ioc, G_IO_IN, + fd_accept_incoming_migration, + NULL, NULL, + g_main_context_get_thread_default()); } } diff --git a/migration/file.c b/migration/file.c index e56c5eb0a5..ddde0ca818 100644 --- a/migration/file.c +++ b/migration/file.c @@ -115,13 +115,46 @@ static gboolean file_accept_incoming_migration(QIOCha= nnel *ioc, return G_SOURCE_REMOVE; } =20 +void file_create_incoming_channels(QIOChannel *ioc, Error **errp) +{ + int i, fd, channels =3D 1; + g_autofree QIOChannel **iocs =3D NULL; + + if (migrate_multifd()) { + channels +=3D migrate_multifd_channels(); + } + + iocs =3D g_new0(QIOChannel *, channels); + fd =3D QIO_CHANNEL_FILE(ioc)->fd; + iocs[0] =3D ioc; + + for (i =3D 1; i < channels; i++) { + QIOChannelFile *fioc =3D qio_channel_file_new_dupfd(fd, errp); + + if (!fioc) { + while (i) { + object_unref(iocs[--i]); + } + return; + } + + iocs[i] =3D QIO_CHANNEL(fioc); + } + + for (i =3D 0; i < channels; i++) { + qio_channel_set_name(iocs[i], "migration-file-incoming"); + qio_channel_add_watch_full(iocs[i], G_IO_IN, + file_accept_incoming_migration, + NULL, NULL, + g_main_context_get_thread_default()); + } +} + void file_start_incoming_migration(FileMigrationArgs *file_args, Error **e= rrp) { g_autofree char *filename =3D g_strdup(file_args->filename); QIOChannelFile *fioc =3D NULL; uint64_t offset =3D file_args->offset; - int channels =3D 1; - int i =3D 0; =20 trace_migration_file_incoming(filename); =20 @@ -132,28 +165,11 @@ void file_start_incoming_migration(FileMigrationArgs = *file_args, Error **errp) =20 if (offset && qio_channel_io_seek(QIO_CHANNEL(fioc), offset, SEEK_SET, errp) < 0= ) { + object_unref(OBJECT(fioc)); return; } =20 - if (migrate_multifd()) { - channels +=3D migrate_multifd_channels(); - } - - do { - QIOChannel *ioc =3D QIO_CHANNEL(fioc); - - qio_channel_set_name(ioc, "migration-file-incoming"); - qio_channel_add_watch_full(ioc, G_IO_IN, - file_accept_incoming_migration, - NULL, NULL, - g_main_context_get_thread_default()); - - fioc =3D qio_channel_file_new_dupfd(fioc->fd, errp); - - if (!fioc) { - break; - } - } while (++i < channels); + file_create_incoming_channels(QIO_CHANNEL(fioc), errp); } =20 int file_write_ramblock_iov(QIOChannel *ioc, const struct iovec *iov, --=20 2.44.0 From nobody Mon May 13 13:18:57 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=1710709199; cv=none; d=zohomail.com; s=zohoarc; b=NbtTw+ik8972LRv2ASuxzyAxws2QIXxQ6Cd5VRZgopf7pR98eCCBlVKVChGYVTIl0EghlT9F0ToTrIX1LKYf1UsvVI4KmMU3LYuuKnaq8XQfsEhQx1XXR0QdTnejtMJ/qFNg1QZGHmPl3WTrRID6310AKwruAEvkSW5xb8XQalw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710709199; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=nz8vhY0nyugAeRv9MWQlmYdsswd/VLGriTQno8XhX7U=; b=iM5+6ueM92iMGlNNXG0F0Ui8sljszLtC40dARbpU6Da00sDiU1YaHLGoiIB779N53RcoCvM+wDZB8QCRMmq7Z77s6GOjrTljzwUq1S3Z0S6wnPRuyeQPoIbW2pcO+smDBIlaqSuoW7Iq+J+6Tw7wwjjfH68E3/KyGA1wMs2zMKY= 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 1710709199051355.90638838031305; Sun, 17 Mar 2024 13:59:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rlxaL-0002Fp-84; Sun, 17 Mar 2024 16:58:25 -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 1rlxaJ-0002F6-N7 for qemu-devel@nongnu.org; Sun, 17 Mar 2024 16:58:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rlxaI-0002do-5m for qemu-devel@nongnu.org; Sun, 17 Mar 2024 16:58:23 -0400 Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-589-xHFKda0IOzijUt9iLfLtWw-1; Sun, 17 Mar 2024 16:58:20 -0400 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-430d45c66acso372621cf.1 for ; Sun, 17 Mar 2024 13:58:20 -0700 (PDT) Received: from x1n.. ([99.254.121.117]) by smtp.gmail.com with ESMTPSA id ed8-20020ad44ea8000000b00691879d7a50sm2391566qvb.115.2024.03.17.13.58.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Mar 2024 13:58:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710709101; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nz8vhY0nyugAeRv9MWQlmYdsswd/VLGriTQno8XhX7U=; b=UKENncML9wKXjtQFF3dsDWULEhd9iVIqPcwa0c/KbR0su+QOIVsrX8pPrNLZWuSl8WbHGA uB9+Bd/FZ/3+ERxaTx6mW5p92O5+J0WOvrgVFKp0bKW5C6EduYV5QiYpMpbFhLJtY6aZ3K 8CiAS17sQifsTgj4Sn/xKJHW7aFSsHw= X-MC-Unique: xHFKda0IOzijUt9iLfLtWw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710709099; x=1711313899; 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=nz8vhY0nyugAeRv9MWQlmYdsswd/VLGriTQno8XhX7U=; b=b0zA0wHKA7MOvytQCLUhQNv0XWezgdHCpzY9AeQMPAn+HpjON6VDaZ81q7N/YzzSRB zDISVoFOQQEoBcccEkU3SqP462jiY3iTlkV4rP/rKhM5kETWJTbyvszrDHefM/2nXxqF XAeieXnUwTJa8eDo7y+o/uV+SSecumoOl3A/DuilYHoihewm1eBuIdm0O6n0d2QBsaaD /yeHufdmtkmz1M2LiwcocbYjrRJ9HlvHeJniy915oUgCsr7oJnpnHjf6n6MXskSVcQA8 j/txdkhuqmBxgvAIDsqQ9BzdFrqAUvevgNbHreigcj2MN96FsDSl0iemjSqxLGwjp6T5 KIZQ== X-Gm-Message-State: AOJu0YwlTgwC9dTe8KSkcSwgRdPJl6WWV5iTRxtVBSKfwUh/PBtAtsci WjSaHyXZ7HHnOyXuvEiri/cz8k6BCUFxcqt/zK6YcQuQwYdub3M/lV8ryJUAm/mLl1wto5eFqJ6 JefL+OuucDClyJXLf93vVGvpHKOO5wsTekAGlt/DtH1huAxppGbGPy2wLXIIMIi4ptA0NGEjNYz xkV26G5f5xZU4QY1A13n4vIfg5NGst7GZxmg== X-Received: by 2002:ad4:41cc:0:b0:691:87dd:f836 with SMTP id a12-20020ad441cc000000b0069187ddf836mr6382254qvq.5.1710709099164; Sun, 17 Mar 2024 13:58:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE0hAPoh8PVF19JyzM3bDv5NCa9eyF5V5INCZ/GqxFjfehjwVscBnYO8Eozt1fUPIOGGXpCsw== X-Received: by 2002:ad4:41cc:0:b0:691:87dd:f836 with SMTP id a12-20020ad441cc000000b0069187ddf836mr6382223qvq.5.1710709098636; Sun, 17 Mar 2024 13:58:18 -0700 (PDT) From: peterx@redhat.com To: qemu-devel@nongnu.org, Peter Maydell Cc: Fabiano Rosas , Prasad Pandit , peterx@redhat.com, David Hildenbrand , Paolo Bonzini Subject: [PULL 09/10] migration/multifd: Ensure we're not given a socket for file migration Date: Sun, 17 Mar 2024 16:58:02 -0400 Message-ID: <20240317205803.361163-10-peterx@redhat.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240317205803.361163-1-peterx@redhat.com> References: <20240317205803.361163-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: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.316, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_SORBS_WEB=1.5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1710709200391100001 Content-Type: text/plain; charset="utf-8" From: Fabiano Rosas When doing migration using the fd: URI, QEMU will fetch the file descriptor passed in via the monitor at fd_start_outgoing|incoming_migration(), which means the checks at migration_channels_and_transport_compatible() happen too soon and we don't know at that point whether the FD refers to a plain file or a socket. For this reason, we've been allowing a migration channel of type SOCKET_ADDRESS_TYPE_FD to pass the initial verifications in scenarios where the socket migration is not supported, such as with fd + multifd. The commit decdc76772 ("migration/multifd: Add mapped-ram support to fd: URI") was supposed to add a second check prior to starting migration to make sure a socket fd is not passed instead of a file fd, but failed to do so. Add the missing verification and update the comment explaining this situation which is currently incorrect. Fixes: decdc76772 ("migration/multifd: Add mapped-ram support to fd: URI") Signed-off-by: Fabiano Rosas Reviewed-by: Peter Xu Link: https://lore.kernel.org/r/20240315032040.7974-2-farosas@suse.de Signed-off-by: Peter Xu --- migration/fd.c | 8 ++++++++ migration/file.c | 7 +++++++ migration/migration.c | 6 +++--- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/migration/fd.c b/migration/fd.c index 39a52e5c90..c07030f715 100644 --- a/migration/fd.c +++ b/migration/fd.c @@ -22,6 +22,7 @@ #include "migration.h" #include "monitor/monitor.h" #include "io/channel-file.h" +#include "io/channel-socket.h" #include "io/channel-util.h" #include "options.h" #include "trace.h" @@ -95,6 +96,13 @@ void fd_start_incoming_migration(const char *fdname, Err= or **errp) } =20 if (migrate_multifd()) { + if (fd_is_socket(fd)) { + error_setg(errp, + "Multifd migration to a socket FD is not supported"= ); + object_unref(ioc); + return; + } + file_create_incoming_channels(ioc, errp); } else { qio_channel_set_name(ioc, "migration-fd-incoming"); diff --git a/migration/file.c b/migration/file.c index ddde0ca818..b6e8ba13f2 100644 --- a/migration/file.c +++ b/migration/file.c @@ -15,6 +15,7 @@ #include "file.h" #include "migration.h" #include "io/channel-file.h" +#include "io/channel-socket.h" #include "io/channel-util.h" #include "options.h" #include "trace.h" @@ -58,6 +59,12 @@ bool file_send_channel_create(gpointer opaque, Error **e= rrp) int fd =3D fd_args_get_fd(); =20 if (fd && fd !=3D -1) { + if (fd_is_socket(fd)) { + error_setg(errp, + "Multifd migration to a socket FD is not supported"= ); + goto out; + } + ioc =3D qio_channel_file_new_dupfd(fd, errp); } else { ioc =3D qio_channel_file_new_path(outgoing_args.fname, flags, 0, e= rrp); diff --git a/migration/migration.c b/migration/migration.c index 644e073b7d..f60bd371e3 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -166,9 +166,9 @@ static bool transport_supports_seeking(MigrationAddress= *addr) } =20 /* - * At this point, the user might not yet have passed the file - * descriptor to QEMU, so we cannot know for sure whether it - * refers to a plain file or a socket. Let it through anyway. + * At this point QEMU has not yet fetched the fd passed in by the + * user, so we cannot know for sure whether it refers to a plain + * file or a socket. Let it through anyway and check at fd.c. */ if (addr->transport =3D=3D MIGRATION_ADDRESS_TYPE_SOCKET) { return addr->u.socket.type =3D=3D SOCKET_ADDRESS_TYPE_FD; --=20 2.44.0 From nobody Mon May 13 13:18:57 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=1710709174; cv=none; d=zohomail.com; s=zohoarc; b=kEsWaDd5Pizr5qgW9hSSab4NEopsB9ywXh/13dBhs/5TLo8ZHarzNdhuPXtQhONk/8Un+WsXsq1fOEF3UUadshuiFUrpfaj53FVFgY40Ao7yEZ+8H3TRpbfW1H/SGbL7aSjFSmG48KgGUKz+Yhle4wbqYsFYe2Qkfy4OMidPo5M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710709174; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=2/dYvsDyDFOzN5fd9fyhA5B4S0ZtJhXWR0ak14NU83A=; b=AB+JejzhIgh8vlFzA8oZX67eGIndoV4Ok/6lA/3392lyYFqZFSbbhgggQChUtdOUYCSevsTUJIV7f3FyvenUmLTr3bJ32NVQ+MIpkVDDsytZYOSbM4ipRA0JXj0Cr4i4S5inKE2NqO5n5zE9bG2gceQWaWoqTaDFr6oQ00Ozhjg= 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 1710709174571147.5758680274888; Sun, 17 Mar 2024 13:59:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rlxaN-0002Fs-Uj; Sun, 17 Mar 2024 16:58:28 -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 1rlxaK-0002FU-L0 for qemu-devel@nongnu.org; Sun, 17 Mar 2024 16:58:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rlxaJ-0002eB-3o for qemu-devel@nongnu.org; Sun, 17 Mar 2024 16:58:24 -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_256_GCM_SHA384) id us-mta-515-DR4brby5MneDeA9lfEib8g-1; Sun, 17 Mar 2024 16:58:20 -0400 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-430b9ee6bfbso4063311cf.0 for ; Sun, 17 Mar 2024 13:58:20 -0700 (PDT) Received: from x1n.. ([99.254.121.117]) by smtp.gmail.com with ESMTPSA id ed8-20020ad44ea8000000b00691879d7a50sm2391566qvb.115.2024.03.17.13.58.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Mar 2024 13:58:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710709102; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2/dYvsDyDFOzN5fd9fyhA5B4S0ZtJhXWR0ak14NU83A=; b=K6UaqosRW7DFw0IagjLsJYYAEry2PgUEQxlaATD6azyP4rST8GUD3MlZ3SQG3ceZ6nH9tv I4yxJ2PFberQ2h4uayJJYIteLOGw6eOLifVMQXkOOLmadvwnjKUfAUj4H97bAySP1IfAQU KOfi5+66+kDhyDrHwVpupHAcij0oWYc= X-MC-Unique: DR4brby5MneDeA9lfEib8g-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710709100; x=1711313900; 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=2/dYvsDyDFOzN5fd9fyhA5B4S0ZtJhXWR0ak14NU83A=; b=FW1e6+5y/7mwG3S/ylbtWvotXHykbeYc+lJ9B5bDkwh6bnyYOnXLAVkOy63TXnebtb zKC7jlv72MvAKMiZNHKJ1bvNfDFPoutB1Lk6gZKNqVtGVWjdMOm7D8gGmgAiGj7sKHsI K808/H8dQH82AqSCP+xrr+hWj4gawB1uNxqE5KY/1c4m3FaXDdLkNxxl9Lf+dplLcsWO qxK/W5kElvC52plX2yXY/jquAZ3L4jTctDOaw0L0N3bdF0TRhBECHeahrFzL5Gez876t +dP0JCjxHQl5AiGY4Vs26aSG089GYx/ZmQLHM6I7jod5apuAZ07Nf85pZMiadFZbENU7 z+5w== X-Gm-Message-State: AOJu0YzckwzhV39F/2I1+eedgh0fgJ9kVX3QpZPvJcqo2+j+HT+mBSPM bnFMJEm70Yy9PWZ99MhBBis7OcJ/EiTVCqJX4zjnJon4eyRueR3io3v9QlxSEn8Zu2qLHsP5LLV C7pKn4e2zRM2z/ajGWoXO+qxPzbm1etnsYeZPuwOXGQetjm8JUdd7Czd4dHOtwZNHNGsn/2gTl2 r1rTalIx60l2e2CXchkA6yRx7eDnryRsPt+g== X-Received: by 2002:a05:6214:3d9a:b0:691:456f:415a with SMTP id om26-20020a0562143d9a00b00691456f415amr12266806qvb.4.1710709100095; Sun, 17 Mar 2024 13:58:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHATVsL922WTpVpieM6CBIj9hhmoIIY7wU/do2vt1iq6/Y/zKNh54++8r6oTSjtt+c05el91Q== X-Received: by 2002:a05:6214:3d9a:b0:691:456f:415a with SMTP id om26-20020a0562143d9a00b00691456f415amr12266788qvb.4.1710709099599; Sun, 17 Mar 2024 13:58:19 -0700 (PDT) From: peterx@redhat.com To: qemu-devel@nongnu.org, Peter Maydell Cc: Fabiano Rosas , Prasad Pandit , peterx@redhat.com, David Hildenbrand , Paolo Bonzini Subject: [PULL 10/10] migration/multifd: Duplicate the fd for the outgoing_args Date: Sun, 17 Mar 2024 16:58:03 -0400 Message-ID: <20240317205803.361163-11-peterx@redhat.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240317205803.361163-1-peterx@redhat.com> References: <20240317205803.361163-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: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.316, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1710709176333100001 Content-Type: text/plain; charset="utf-8" From: Fabiano Rosas We currently store the file descriptor used during the main outgoing channel creation to use it again when creating the multifd channels. Since this fd is used for the first iochannel, there's risk that the QIOChannel gets freed and the fd closed while outgoing_args.fd still has it available. This could lead to an fd-reuse bug. Duplicate the outgoing_args fd to avoid this issue. Suggested-by: Peter Xu Signed-off-by: Fabiano Rosas Reviewed-by: Peter Xu Link: https://lore.kernel.org/r/20240315032040.7974-3-farosas@suse.de Signed-off-by: Peter Xu --- migration/fd.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/migration/fd.c b/migration/fd.c index c07030f715..fe0d096abd 100644 --- a/migration/fd.c +++ b/migration/fd.c @@ -49,8 +49,7 @@ void fd_start_outgoing_migration(MigrationState *s, const= char *fdname, Error ** { QIOChannel *ioc; int fd =3D monitor_get_fd(monitor_cur(), fdname, errp); - - outgoing_args.fd =3D -1; + int newfd; =20 if (fd =3D=3D -1) { return; @@ -63,7 +62,17 @@ void fd_start_outgoing_migration(MigrationState *s, cons= t char *fdname, Error ** return; } =20 - outgoing_args.fd =3D fd; + /* + * This is dup()ed just to avoid referencing an fd that might + * be already closed by the iochannel. + */ + newfd =3D dup(fd); + if (newfd =3D=3D -1) { + error_setg_errno(errp, errno, "Could not dup FD %d", fd); + object_unref(ioc); + return; + } + outgoing_args.fd =3D newfd; =20 qio_channel_set_name(ioc, "migration-fd-outgoing"); migration_channel_connect(s, ioc, NULL, NULL); --=20 2.44.0