From nobody Sat Nov 15 08:35:14 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=1753781021; cv=none; d=zohomail.com; s=zohoarc; b=ewC09n5X0msBSCVKGHHc6IPcIhDYb73jN5evJp67nnzJ2uDyidd2HEUbcnolQ7YG8hStLUX/u+vIlgmibsT6misQLAvIuQ0Sz1WRcn4kSeW7bZ/FTZIO2m+bkXid14Twh2HtBHoOacn5aE9FIqKGsfvAxu6dXcDewgR26StImvA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1753781021; 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=tNnhDDpeXU/93q9dWG3xJVedp8WlGmk/sXdyNeeAgc0=; b=eO97T4oCPT+wQ0X9Kzw2pueuNeWJUtdol/9fwwJbmaqGWYh3QSQAx1yb8NDiHPtigQpcuAQiSUEYep7UYTdCzvPKJGFNSjExu+Nrk8UzqqnbwfvAY5nUCcYda0bmmWJoBhlU2yVGf4DLbP5pZzq4KuUstLXQHm9coT31fFrwZHM= 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 1753781021045192.66947074054497; Tue, 29 Jul 2025 02:23:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uggXj-0006ug-S5; Tue, 29 Jul 2025 05:22:44 -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 1uggXP-0005lb-G7 for qemu-devel@nongnu.org; Tue, 29 Jul 2025 05:22:27 -0400 Received: from mgamail.intel.com ([192.198.163.17]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uggXN-0002ij-BB for qemu-devel@nongnu.org; Tue, 29 Jul 2025 05:22:23 -0400 Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jul 2025 02:22:19 -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; 29 Jul 2025 02:22:16 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1753780941; x=1785316941; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZqNaiLy9WtG90PgSDVLRtT098jvrHMbsvoVUz3oH3/w=; b=jiFcnb1nJrNMVcq89sBVY9JLBjdO4rUuqHY6Obe2iEjiCNpNOnQ1JqTi LTfd0t4ZVvVpTtLl56FCRPqVIJfMoa8DwV0P11DFgKrwYkgj2awRmNtSS l13yklpdd2zLoE06my57UbqzTpdGr6FlceWwNUmyD4akMqmx7H/JDaLJ5 NkPUcxlcMAj7MxyT4XV1Z1P/x5hxwdX1XwYYBJEpgfaLG5RuUsc7Pyoqn 3aXMMc9O4t0LYg9eylIWmO9815koFuoHBxub8mFJ8Mg1+q66CEyKFGOOw yMP2UsK4yDytk1cr/Pf9IwyquD7MKTjNz0U8cXP1pbgOxZiuHGR4t18jc w==; X-CSE-ConnectionGUID: Sh6tHOK/SpiQcSwdi7b54A== X-CSE-MsgGUID: hdP9fpw+TXeg5g1zPQFdSQ== X-IronPort-AV: E=McAfee;i="6800,10657,11505"; a="55982015" X-IronPort-AV: E=Sophos;i="6.16,348,1744095600"; d="scan'208";a="55982015" X-CSE-ConnectionGUID: tBWBUycPRuWYUo+8AqbhHQ== X-CSE-MsgGUID: M88HKf4hTZev0SkFLqkcew== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,348,1744095600"; d="scan'208";a="162691463" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, jasowang@redhat.com, peterx@redhat.com, ddutile@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, shameerali.kolothum.thodi@huawei.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v4 18/20] vfio: Add a new element bypass_ro in VFIOContainerBase Date: Tue, 29 Jul 2025 05:20:40 -0400 Message-ID: <20250729092043.785836-19-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250729092043.785836-1-zhenzhong.duan@intel.com> References: <20250729092043.785836-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.17; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1753781022057116600 Content-Type: text/plain; charset="utf-8" When bypass_ro is true, read only memory section is bypassed from mapping in the container. This is a preparing patch to workaround Intel ERRATA_772415. Signed-off-by: Zhenzhong Duan --- include/hw/vfio/vfio-container-base.h | 1 + hw/vfio/listener.c | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-c= ontainer-base.h index bded6e993f..31fd784d76 100644 --- a/include/hw/vfio/vfio-container-base.h +++ b/include/hw/vfio/vfio-container-base.h @@ -51,6 +51,7 @@ typedef struct VFIOContainerBase { QLIST_HEAD(, VFIODevice) device_list; GList *iova_ranges; NotifierWithReturn cpr_reboot_notifier; + bool bypass_ro; } VFIOContainerBase; =20 typedef struct VFIOGuestIOMMU { diff --git a/hw/vfio/listener.c b/hw/vfio/listener.c index f498e23a93..c64aa4539e 100644 --- a/hw/vfio/listener.c +++ b/hw/vfio/listener.c @@ -364,7 +364,8 @@ static bool vfio_known_safe_misalignment(MemoryRegionSe= ction *section) return true; } =20 -static bool vfio_listener_valid_section(MemoryRegionSection *section, +static bool vfio_listener_valid_section(VFIOContainerBase *bcontainer, + MemoryRegionSection *section, const char *name) { if (vfio_listener_skipped_section(section)) { @@ -375,6 +376,10 @@ static bool vfio_listener_valid_section(MemoryRegionSe= ction *section, return false; } =20 + if (bcontainer && bcontainer->bypass_ro && section->readonly) { + return false; + } + if (unlikely((section->offset_within_address_space & ~qemu_real_host_page_mask()) !=3D (section->offset_within_region & ~qemu_real_host_page_mas= k()))) { @@ -494,7 +499,7 @@ void vfio_container_region_add(VFIOContainerBase *bcont= ainer, int ret; Error *err =3D NULL; =20 - if (!vfio_listener_valid_section(section, "region_add")) { + if (!vfio_listener_valid_section(bcontainer, section, "region_add")) { return; } =20 @@ -655,7 +660,7 @@ static void vfio_listener_region_del(MemoryListener *li= stener, int ret; bool try_unmap =3D true; =20 - if (!vfio_listener_valid_section(section, "region_del")) { + if (!vfio_listener_valid_section(bcontainer, section, "region_del")) { return; } =20 @@ -812,7 +817,7 @@ static void vfio_dirty_tracking_update(MemoryListener *= listener, container_of(listener, VFIODirtyRangesListener, listener); hwaddr iova, end; =20 - if (!vfio_listener_valid_section(section, "tracking_update") || + if (!vfio_listener_valid_section(NULL, section, "tracking_update") || !vfio_get_section_iova_range(dirty->bcontainer, section, &iova, &end, NULL)) { return; --=20 2.47.1