From nobody Fri Apr 4 21:31:10 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=1739953802; cv=none; d=zohomail.com; s=zohoarc; b=S3z0ZdOLhECMP96hMAUeNzEAzKakwsQeoK+JWXcfBbtec9vtImE+pCDXrrzXLtRhJbt9lEKT+1zXEqv0J7Sgt/KbNSvKwdlsnPRQ1x0aUZVSzSFXXhWO0H2OtrwkgHOyPNB91B2mv6IJZk+r8EvKl+pVawwY57a34mQw7wv3hE8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1739953802; 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=Ypqr5JFZHWoiu/J/4naDV30yKxgx+5L3idu8vH1mrlc=; b=NUhZ0vVfB0XjylZBpA3PQzGKENrm/sc9/i/N9djOXBdDUjHevfetaBIAcOx8mR3U1r7JBxY8I8Zpp6vjtRTTfWYsXxHY9yZNJhWyDSDj2hlzNH5IQbRNeg8mEi5PWKSIObFyDGO4TkqWwBZ4aUMB7MUJjPxLl4uknNcsJoAxMVk= 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 173995380242598.47335529848226; Wed, 19 Feb 2025 00:30:02 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tkfQo-0006Fr-Dx; Wed, 19 Feb 2025 03:27:46 -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 1tkfQR-0005tS-Ca for qemu-devel@nongnu.org; Wed, 19 Feb 2025 03:27:23 -0500 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 1tkfQN-0004eO-Pm for qemu-devel@nongnu.org; Wed, 19 Feb 2025 03:27:22 -0500 Received: from orviesa005.jf.intel.com ([10.64.159.145]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Feb 2025 00:27:19 -0800 Received: from spr-s2600bt.bj.intel.com ([10.240.192.127]) by orviesa005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Feb 2025 00:27:13 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1739953640; x=1771489640; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=e1ZoscbXzm2c5PiXufM2JI3ZULck95SCPA/nxqF9N3o=; b=F+E8ZtqXTjZB9F8nepYHLtMiupki9lFl3anZ0Fn0IxvYR2y1YSgFGLeJ 77ANMUiyA5RBE0B9k2pIT5vaz3YTLq7rISKQjGGCvx95p6h7CaqLZsbQG BjU5PdaCjGK9BCwspsGaaL4khyg8gJ5lr43aO6yE+XZH7MHL1SkeILGsm WRsf44LOQU2vixpQdGPNHJyK6piRiBlMcaLxEl96FdXAXsc/eWrcyat7d WWzNUoVAgwkL3mzNwBXGxI7kHDcmiJArLSQAp6CqAciqf+HOevZgLSYHO tlkWEX+VooB2vZxx7cTr0gHPh0WqvoDXN8gbvVfr3BQRgBa+LIaUN0Hve Q==; X-CSE-ConnectionGUID: TIAzrPTOT8eKzDmg+h/sQA== X-CSE-MsgGUID: +xZfryd/TqeR8CKydeOoCA== X-IronPort-AV: E=McAfee;i="6700,10204,11348"; a="40544269" X-IronPort-AV: E=Sophos;i="6.13,298,1732608000"; d="scan'208";a="40544269" X-CSE-ConnectionGUID: ShIrIk7VSU+LIMYgGF3efQ== X-CSE-MsgGUID: jcMoocxfTTm8iXKV3FEq8A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,224,1728975600"; d="scan'208";a="119851359" 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, 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 , Paolo Bonzini , Richard Henderson , Eduardo Habkost , Marcel Apfelbaum Subject: [PATCH rfcv2 15/20] intel_iommu: ERRATA_772415 workaround Date: Wed, 19 Feb 2025 16:22:23 +0800 Message-Id: <20250219082228.3303163-16-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250219082228.3303163-1-zhenzhong.duan@intel.com> References: <20250219082228.3303163-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: -47 X-Spam_score: -4.8 X-Spam_bar: ---- X-Spam_report: (-4.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.423, 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_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: 1739953804740019100 Content-Type: text/plain; charset="utf-8" On a system influenced by ERRATA_772415, IOMMU_HW_INFO_VTD_ERRATA_772415_SP= R17 is repored by IOMMU_DEVICE_GET_HW_INFO. Due to this errata, even the readon= ly range mapped on stage-2 page table could still be written. Reference from 4th Gen Intel Xeon Processor Scalable Family Specification Update, Errata Details, SPR17. [0] https://edc.intel.com/content/www/us/en/design/products-and-solutions/p= rocessors-and-chipsets/eagle-stream/sapphire-rapids-specification-update We utilize the new added IOMMUFD container/ioas/hwpt management framework in VTD. Add a check to create new VTDIOASContainer to hold RW-only mappings, then this VTDIOASContainer can be used as backend for device with ERRATA_772415. See below diagram for details: IntelIOMMUState | V .------------------. .------------------. .-------------------. | VTDIOASContainer |--->| VTDIOASContainer |--->| VTDIOASContainer |--= >... | (iommufd0,RW&RO) | | (iommufd1,RW&RO) | | (iommufd0,RW only)| .------------------. .------------------. .-------------------. | | | | .-->... | V V .-------------------. .-------------------. .------------= ---. | VTDS2Hwpt(CC) |--->| VTDS2Hwpt(non-CC) |-->... | VTDS2Hwpt(C= C) |-->... .-------------------. .-------------------. .------------= ---. | | | | | | | | .-----------. .-----------. .------------. .------------. | IOMMUFD | | IOMMUFD | | IOMMUFD | | IOMMUFD | | Device(CC)| | Device(CC)| | Device | | Device(CC) | | (iommufd0)| | (iommufd0)| | (non-CC) | | (errata) | | | | | | (iommufd0) | | (iommufd0) | .-----------. .-----------. .------------. .------------. Changed to pass VTDHostIOMMUDevice pointer to vtd_check_hdev() so errata could be saved. Suggested-by: Yi Liu Signed-off-by: Zhenzhong Duan --- hw/i386/intel_iommu_internal.h | 1 + include/hw/i386/intel_iommu.h | 1 + hw/i386/intel_iommu.c | 26 +++++++++++++++++++------- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index 23b7e236b0..8558781af8 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -654,5 +654,6 @@ typedef struct VTDHostIOMMUDevice { PCIBus *bus; uint8_t devfn; HostIOMMUDevice *hiod; + uint32_t errata; } VTDHostIOMMUDevice; #endif diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h index 594281c1d3..9b156dc32e 100644 --- a/include/hw/i386/intel_iommu.h +++ b/include/hw/i386/intel_iommu.h @@ -103,6 +103,7 @@ typedef struct VTDPASIDCacheEntry { typedef struct VTDIOASContainer { struct IOMMUFDBackend *iommufd; uint32_t ioas_id; + uint32_t errata; MemoryListener listener; QLIST_HEAD(, VTDS2Hwpt) s2_hwpt_list; QLIST_ENTRY(VTDIOASContainer) next; diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index e36ac44110..dae1716629 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -2443,7 +2443,8 @@ static void vtd_context_global_invalidate(IntelIOMMUS= tate *s) } =20 #ifdef CONFIG_IOMMUFD -static bool iommufd_listener_skipped_section(MemoryRegionSection *section) +static bool iommufd_listener_skipped_section(VTDIOASContainer *container, + MemoryRegionSection *section) { return !memory_region_is_ram(section->mr) || memory_region_is_protected(section->mr) || @@ -2453,7 +2454,8 @@ static bool iommufd_listener_skipped_section(MemoryRe= gionSection *section) * are never accessed by the CPU and beyond the address width of * some IOMMU hardware. TODO: VFIO should tell us the IOMMU wi= dth. */ - section->offset_within_address_space & (1ULL << 63); + section->offset_within_address_space & (1ULL << 63) || + (container->errata && section->readonly); } =20 static void iommufd_listener_region_add_s2domain(MemoryListener *listener, @@ -2469,7 +2471,7 @@ static void iommufd_listener_region_add_s2domain(Memo= ryListener *listener, Error *err =3D NULL; int ret; =20 - if (iommufd_listener_skipped_section(section)) { + if (iommufd_listener_skipped_section(container, section)) { return; } iova =3D REAL_HOST_PAGE_ALIGN(section->offset_within_address_space); @@ -2520,7 +2522,7 @@ static void iommufd_listener_region_del_s2domain(Memo= ryListener *listener, Int128 llend, llsize; int ret; =20 - if (iommufd_listener_skipped_section(section)) { + if (iommufd_listener_skipped_section(container, section)) { return; } iova =3D REAL_HOST_PAGE_ALIGN(section->offset_within_address_space); @@ -2776,7 +2778,8 @@ static int vtd_device_attach_iommufd(VTDHostIOMMUDevi= ce *vtd_hiod, =20 /* try to attach to an existing container in this space */ QLIST_FOREACH(container, &s->containers, next) { - if (container->iommufd !=3D iommufd) { + if (container->iommufd !=3D iommufd || + container->errata !=3D vtd_hiod->errata) { continue; } =20 @@ -2803,6 +2806,7 @@ static int vtd_device_attach_iommufd(VTDHostIOMMUDevi= ce *vtd_hiod, container =3D g_malloc0(sizeof(*container)); container->iommufd =3D iommufd; container->ioas_id =3D ioas_id; + container->errata =3D vtd_hiod->errata; QLIST_INIT(&container->s2_hwpt_list); =20 if (vtd_device_attach_container(vtd_hiod, container, pasid, pe, hwpt, @@ -5329,9 +5333,10 @@ VTDAddressSpace *vtd_find_add_as(IntelIOMMUState *s,= PCIBus *bus, return vtd_dev_as; } =20 -static bool vtd_check_hiod(IntelIOMMUState *s, HostIOMMUDevice *hiod, +static bool vtd_check_hiod(IntelIOMMUState *s, VTDHostIOMMUDevice *vtd_hio= d, Error **errp) { + HostIOMMUDevice *hiod =3D vtd_hiod->hiod; HostIOMMUDeviceClass *hiodc =3D HOST_IOMMU_DEVICE_GET_CLASS(hiod); int ret; =20 @@ -5388,6 +5393,12 @@ static bool vtd_check_hiod(IntelIOMMUState *s, HostI= OMMUDevice *hiod, return false; } =20 + ret =3D hiodc->get_cap(hiod, HOST_IOMMU_DEVICE_CAP_ERRATA, errp); + if (ret < 0) { + return false; + } + vtd_hiod->errata =3D ret; + error_setg(errp, "host device is uncompatible with stage-1 translation= "); return false; } @@ -5419,7 +5430,8 @@ static bool vtd_dev_set_iommu_device(PCIBus *bus, voi= d *opaque, int devfn, vtd_hiod->iommu_state =3D s; vtd_hiod->hiod =3D hiod; =20 - if (!vtd_check_hiod(s, hiod, errp)) { + if (!vtd_check_hiod(s, vtd_hiod, errp)) { + g_free(vtd_hiod); vtd_iommu_unlock(s); return false; } --=20 2.34.1