From nobody Mon Feb 9 14:50:19 2026 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1769491030; cv=none; d=zohomail.com; s=zohoarc; b=fo+1+uB72zCEnpez4y5PGUXVSgqvS6L4R6oJL90F4nCFVS6+by0kLuh1AYcBqivU70afAOXruBY9VoGDxH/ojfbhJR7nYNIn/+HNiSgwb3f+VJhdNWqMThAm/NSMsNXVO4IsP50vVH/v0tGpsmwvpI4bCw5GaGsn2Ljw/wI2i3Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1769491030; 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=/m58jsrTIZK0luSPJaSrEgjDGlXyqLhzlqk7ugFZnAI=; b=fys7kdX6ICfqvCEck3fGY+wyKQnQ6pnE+SNdFejPkp1xH1SCZsEUvqI/81oMNYoPME7iNeMDD4YaieK0hZJE9Eo9QNUhhCl/RykdAapBLicGOOjYRpdcqeh2pzWea1TvVunNHEEG8yR2d+opng5xrBh8kPRG+T1JRaqiElaJztk= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1769491030513362.80904340680104; Mon, 26 Jan 2026 21:17:10 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vkbRb-0006ht-RO; Tue, 27 Jan 2026 00:16:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vkbRa-0006h3-7H for qemu-devel@nongnu.org; Tue, 27 Jan 2026 00:16:50 -0500 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 1vkbRY-0008JN-RH for qemu-devel@nongnu.org; Tue, 27 Jan 2026 00:16:50 -0500 Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-70-4C_0RT6bMU-8ABJbnDqsBg-1; Tue, 27 Jan 2026 00:16:45 -0500 Received: by mail-pg1-f197.google.com with SMTP id 41be03b00d2f7-b6ce1b57b9cso2554370a12.1 for ; Mon, 26 Jan 2026 21:16:45 -0800 (PST) Received: from rhel9-box.lan ([122.163.48.79]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-353f6230d5dsm1110925a91.17.2026.01.26.21.16.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jan 2026 21:16:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1769491008; 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=/m58jsrTIZK0luSPJaSrEgjDGlXyqLhzlqk7ugFZnAI=; b=ILMkzuDLNJUJ9e+RPDEqCuvmaVltaV3OZWkFYdN369BRdKzSqkidDtOCTS6SO2lKPIOyZG nxF3CZYaSybi5qOHTJvpenSUkmmkL0TbvouKOJf91873MgL0sSPcLRUdBZg6aWm9S/RWSO NaZuRGDL38Bw19WzP6TDvixoMzFwyGU= X-MC-Unique: 4C_0RT6bMU-8ABJbnDqsBg-1 X-Mimecast-MFC-AGG-ID: 4C_0RT6bMU-8ABJbnDqsBg_1769491004 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1769491004; x=1770095804; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/m58jsrTIZK0luSPJaSrEgjDGlXyqLhzlqk7ugFZnAI=; b=rGg7dSx01shZj0N6ntVqQQcVhMlsbVR+pMRkjwS5xc4TbCdyxcjZbQzg5LxxyhtdHj xOPtUuBjUl/D3V4VPopOwmYOraCVGeyoGuVXx38dG3R5gljgH5qsuLv/snaYh9YXFLCU 0brH21ckTa6lFc7bctidcM0V6KUp85yOHV1YGOOeh9BMfTZa6UMLJ+ek/hGO7Thsb/B9 lDuoDd9xL8LXHG6ZEpDeZ+H7V4/ebXNazBIK60r2NB400z7orJfizYXuvMXCpfyfgqNh y0NUJ5+NMFYbrUEl+TOmjXWqJYluelIWYuBSmv5sl81jVuBpTYgVTVWWEMTbbFDehzWo xFPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769491004; x=1770095804; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=/m58jsrTIZK0luSPJaSrEgjDGlXyqLhzlqk7ugFZnAI=; b=FVgrCQAAHBUAIMq1k2KpegxcmdQU47NxuGrWlnlLBONV1lxD4TjsH81UToqXDlJ3HS ns2hvkDancrVglwtBf726JWkmB+VswOO7Q63xuClDBLJx1Af0HKJbYUg0xaEJOWJ0F7L +QwmYW2eUU/OGUui7PziFa5D/FkRnwNChiPDLK87f3d1ScHQbY27pnKOlxWbMNCdpVOz WXNikHDZwDQBSr729Ae94KuAvWogAp+6lWvqG51/gTCbCDlUk8egL4d4r9zeloEw+7l4 pe04WUL7ZR56j8CZJvxSHm4BZnqvKSFdEXKKL7Ki3hknyz6lVdOiB8r0pR7jiIjepPfj W5SA== X-Forwarded-Encrypted: i=1; AJvYcCXHxJsvA+x5NRVKx2Te58TPag8SqoAw5JLfz8bA08nYRCU0XxjZAzpvxAcJ5yQS4iCUmRTMtD69UVJC@nongnu.org X-Gm-Message-State: AOJu0YzSKm19Qz0tsCQu6paPd/QZM1vgySJ2zQEnsikpbBMPvkDBqYCa OUb2d2Qx97blBzq9gt12lv5lXgHiZeyqs6/iLEFXCqXaw/CYZUARyCkNGvQGjtfQYuUhc0+HOkQ E8HqfvLQeoxcMU1e2ny6A3b6+0ZBjaVK4Lq6Y6xi2OuDDzJBB8CM9M+Fa X-Gm-Gg: AZuq6aIaeeSJDEQ7j5cXN3P6JKOwVpHQp4J/FSIYlgUgLhG+t7mbyae0rJ+uop0lLwB OKklCQVY1k/21H/Y4yKiu3jYczdT7e/nmIqRDe98Aj1o7jamZSa3xScZ3k/BCwrH/NUXr9Cb2kx kz4eWaIWEgOYqkub4x97fsz51YSd6MNJXzJLlhx41aHj50L/vCL8DUqEq+6XvsWuUgBy3B1fZRs plG9g1uXc0E9uCcXvRZQEM0u0QHybwGWEVrnzDor2BcDfBUh+foZygCle/Mim+Rsz4+Vn1PwHNY iVxMfXL9TWB97XhlTUlE9Qf6j7yWxUM9ZMYeycfKhHM8a0MYDAEaEhyxYN+2b/G+STzS6xE//A4 uYhWzdCcZV/xUgeQmp7p1dEl+Vgv00vWNqDGT2eFsPg== X-Received: by 2002:a05:6a21:62c3:b0:38e:9c27:72e8 with SMTP id adf61e73a8af0-38ec6279239mr485150637.4.1769491004094; Mon, 26 Jan 2026 21:16:44 -0800 (PST) X-Received: by 2002:a05:6a21:62c3:b0:38e:9c27:72e8 with SMTP id adf61e73a8af0-38ec6279239mr485136637.4.1769491003723; Mon, 26 Jan 2026 21:16:43 -0800 (PST) From: Ani Sinha To: Paolo Bonzini , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: kraxel@redhat.com, Ani Sinha , qemu-devel@nongnu.org Subject: [PATCH v3 04/33] system/physmem: add helper to reattach existing memory after KVM VM fd change Date: Tue, 27 Jan 2026 10:45:32 +0530 Message-ID: <20260127051612.219475-5-anisinha@redhat.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20260127051612.219475-1-anisinha@redhat.com> References: <20260127051612.219475-1-anisinha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=anisinha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development 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: 1769491034328158500 Content-Type: text/plain; charset="utf-8" After the guest KVM file descriptor has changed as a part of the process of confidential guest reset mechanism, existing memory needs to be reattached = to the new file descriptor. This change adds a helper function ram_block_rebin= d() for this purpose. The next patch will make use of this function. Signed-off-by: Ani Sinha --- include/system/physmem.h | 1 + system/physmem.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/include/system/physmem.h b/include/system/physmem.h index 7bb7d3e154..da91b77bd9 100644 --- a/include/system/physmem.h +++ b/include/system/physmem.h @@ -51,5 +51,6 @@ physical_memory_snapshot_and_clear_dirty(MemoryRegion *mr= , hwaddr offset, bool physical_memory_snapshot_get_dirty(DirtyBitmapSnapshot *snap, ram_addr_t start, ram_addr_t length); +int ram_block_rebind(Error **errp); =20 #endif diff --git a/system/physmem.c b/system/physmem.c index 9a7aba9521..6755d85319 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -2857,6 +2857,34 @@ found: return block; } =20 +/* + * Creates new guest memfd for the ramblocks and closes the + * existing memfd. + */ +int ram_block_rebind(Error **errp) +{ + RAMBlock *block; + + qemu_mutex_lock_ramlist(); + + RAMBLOCK_FOREACH(block) { + if (block->flags & RAM_GUEST_MEMFD) { + if (block->guest_memfd >=3D 0) { + close(block->guest_memfd); + } + block->guest_memfd =3D kvm_create_guest_memfd(block->max_lengt= h, + 0, errp); + if (block->guest_memfd < 0) { + qemu_mutex_unlock_ramlist(); + return -1; + } + + } + } + qemu_mutex_unlock_ramlist(); + return 0; +} + /* * Finds the named RAMBlock * --=20 2.42.0