From nobody Sun Sep 28 15:27:18 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; 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=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1759049827; cv=none; d=zohomail.com; s=zohoarc; b=e4tk9F6V/TWwUJLGqV68y2dm+NlechCO3H2oy8s8XeDpayxjgR0QETnia478h3TFhRyJVfbxXyI+Jgj7xmwhs5rJlYWC02b6r0VuwhjcZinTpAhDY4eMqjhbMC6Ke7xEL8ReCIJDf3l/w/1qsq6KTRjZ4EBgnujqR9e2buefbng= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1759049827; 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=FZP89ow6Eb78Jm0grnyFXhqkEXmEueOw+OjDOhRNyKc=; b=DBtx3fJVC0zcOZi2XSjq0/lQd0/Mm4KU+26dZclist0EEdDBau239X9F5ytTo05ZH+eNGC+jALXzGOYNU0ZJnOANeQ2zxj87r1x17YCxgrhxleKIqQ6fSlzQCGTRp/iriil5UqgixnFWRMfcbdPg6yIvPpHrg6sa6TqFad1Tg8A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; 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 1759049827841314.25777694392775; Sun, 28 Sep 2025 01:57:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v2nC5-0006SE-QG; Sun, 28 Sep 2025 04:55:45 -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 1v2nC3-0006RN-1z for qemu-devel@nongnu.org; Sun, 28 Sep 2025 04:55:43 -0400 Received: from mgamail.intel.com ([192.198.163.12]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v2nBo-00044v-4v for qemu-devel@nongnu.org; Sun, 28 Sep 2025 04:55:40 -0400 Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2025 01:55:18 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by orviesa007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2025 01:55:17 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1759049728; x=1790585728; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UIx34YIzlFINwWTFJwGZ4PbgVaTVtQLZb+iSo6vAuUY=; b=jmjJ+4NdiCnYhvHkB2beNFA8vl3h3JbRm/4l9RmqiHLgMRCc0pWbneJW IXHu74F+Wl33PAugAK1/6CflInHZyxptZ3QIwCwAM0AVEjeoUXWWzUJFM m2NDx170In2m7g/5/CX5yg6C7TLwZlaV9heAneiT6nZLWcNDQ3eaNdJGg CaTAcn7Sk5Q0d5L9G3fR/TNzQVHOX8asYh9++9Bq2YLzNVqv1kREntPJD pskUk/rsSLlsnWymDL3+FMCKyZcovAjlvIY6+U7uz9kyHGqZo7iGoJNVV wT36uRwQOL6UfbFeXsUYAJn+94df9HuQreLzznCffXhJITRcVsPkYj4TC A==; X-CSE-ConnectionGUID: vuQHoRlMRv2/kUXX3cm5BA== X-CSE-MsgGUID: ULeKB+42Syaq41mh7L2hiA== X-IronPort-AV: E=McAfee;i="6800,10657,11566"; a="65167428" X-IronPort-AV: E=Sophos;i="6.18,299,1751266800"; d="scan'208";a="65167428" X-CSE-ConnectionGUID: p4czyY+1S12c4QaXq/DZNA== X-CSE-MsgGUID: nV8iaFQMSkqZGeyH+Vducw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.18,299,1751266800"; d="scan'208";a="177810798" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, steven.sistare@oracle.com, Zhenzhong Duan , David Hildenbrand Subject: [PATCH v2 1/6] vfio/container: Remap only populated parts in a section Date: Sun, 28 Sep 2025 04:54:27 -0400 Message-ID: <20250928085432.40107-2-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250928085432.40107-1-zhenzhong.duan@intel.com> References: <20250928085432.40107-1-zhenzhong.duan@intel.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=192.198.163.12; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1759049830598116600 Content-Type: text/plain; charset="utf-8" If there are multiple containers and unmap-all fails for some of them, we need to remap vaddr for the other containers for which unmap-all succeeded. When ram discard is enabled, we should only remap populated parts in a section instead of the whole section. Fixes: eba1f657cbb1 ("vfio/container: recover from unmap-all-vaddr failure") Signed-off-by: Zhenzhong Duan Reviewed-by: Steven Sistare Reviewed-by: David Hildenbrand --- include/hw/vfio/vfio-cpr.h | 2 +- hw/vfio/cpr-legacy.c | 20 +++++++++++++++----- hw/vfio/listener.c | 4 ++-- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/include/hw/vfio/vfio-cpr.h b/include/hw/vfio/vfio-cpr.h index 26ee0c4fe1..56fa226f35 100644 --- a/include/hw/vfio/vfio-cpr.h +++ b/include/hw/vfio/vfio-cpr.h @@ -68,7 +68,7 @@ bool vfio_cpr_container_match(struct VFIOLegacyContainer = *container, void vfio_cpr_giommu_remap(struct VFIOContainer *bcontainer, MemoryRegionSection *section); =20 -bool vfio_cpr_ram_discard_register_listener( +bool vfio_cpr_ram_discard_replay_populated( struct VFIOContainer *bcontainer, MemoryRegionSection *section); =20 void vfio_cpr_save_vector_fd(struct VFIOPCIDevice *vdev, const char *name, diff --git a/hw/vfio/cpr-legacy.c b/hw/vfio/cpr-legacy.c index bbf7a0d35f..9a37e8c604 100644 --- a/hw/vfio/cpr-legacy.c +++ b/hw/vfio/cpr-legacy.c @@ -227,22 +227,32 @@ void vfio_cpr_giommu_remap(VFIOContainer *bcontainer, memory_region_iommu_replay(giommu->iommu_mr, &giommu->n); } =20 +static int vfio_cpr_rdm_remap(MemoryRegionSection *section, void *opaque) +{ + RamDiscardListener *rdl =3D opaque; + + return rdl->notify_populate(rdl, section); +} + /* * In old QEMU, VFIO_DMA_UNMAP_FLAG_VADDR may fail on some mapping after * succeeding for others, so the latter have lost their vaddr. Call this - * to restore vaddr for a section with a RamDiscardManager. + * to restore vaddr for populated parts in a section with a RamDiscardMana= ger. * - * The ram discard listener already exists. Call its populate function + * The ram discard listener already exists. Call its replay_populated fun= ction * directly, which calls vfio_legacy_cpr_dma_map. */ -bool vfio_cpr_ram_discard_register_listener(VFIOContainer *bcontainer, - MemoryRegionSection *section) +bool vfio_cpr_ram_discard_replay_populated(VFIOContainer *bcontainer, + MemoryRegionSection *section) { + RamDiscardManager *rdm =3D memory_region_get_ram_discard_manager(secti= on->mr); VFIORamDiscardListener *vrdl =3D vfio_find_ram_discard_listener(bcontainer, section); =20 g_assert(vrdl); - return vrdl->listener.notify_populate(&vrdl->listener, section) =3D=3D= 0; + return ram_discard_manager_replay_populated(rdm, section, + vfio_cpr_rdm_remap, + &vrdl->listener) =3D=3D 0; } =20 int vfio_cpr_group_get_device_fd(int d, const char *name) diff --git a/hw/vfio/listener.c b/hw/vfio/listener.c index 3b6f17f0c3..04c64874fa 100644 --- a/hw/vfio/listener.c +++ b/hw/vfio/listener.c @@ -577,8 +577,8 @@ void vfio_container_region_add(VFIOContainer *bcontaine= r, if (!vfio_ram_discard_register_listener(bcontainer, section, &= err)) { goto fail; } - } else if (!vfio_cpr_ram_discard_register_listener(bcontainer, - section)) { + } else if (!vfio_cpr_ram_discard_replay_populated(bcontainer, + section)) { error_setg(&err, "vfio_cpr_ram_discard_register_listener for %s fail= ed", memory_region_name(section->mr)); --=20 2.47.1