From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A2109606A322 for ; Fri, 4 Dec 2026 00:03:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=LxgQZmy7 Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 691E410EB90; Fri, 4 Dec 2026 00:03:45 +0000 (UTC) Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by gabe.freedesktop.org (Postfix) with ESMTPS id DB95B10EB90 for ; Fri, 4 Dec 2026 00:03:38 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id DAA15611EE; Fri, 4 Dec 2026 00:03:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 834DC1F000CE; Fri, 4 Dec 2026 00:03:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796342617; bh=zJ5FqrYWFXSU3ye0a6pYLt3Qf6OWvSHU+OCbxJoLU+A=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=LxgQZmy7vUx0RLj6D+tST4op/RXfHh0e9WFzo8kkMfqZisSu4FNOr0T5xypHKJ9bA IVJYJsDbjtoLi7QOtBttTLGYkaEZoAXaQUa9/gVK7OycUO09ATa0YqCMe3Hd8H/dbj 4bSplb/KHRcmAmTrwbvz98MXywKkXn1Fk/6iJHN/WfFtJOqzrlp3BIZIhIkNcvsCRi oBcrzLptXOLtnh67l6D3eVji0gLyPs8Vbr1Q2/u4m6kGaZWn6FPrFH7NZPKvEypLDk hmHWUZMXBox2doRBjQUIsViWlpdBHgLovmHt+fTr1ewY3hJUHaSKBMZYuT7M8z2vJP QZDnSXKLJ3S0Q== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 2/2] drm/xe: Work around media 52-bit limitation on CRI To: "Stuart Summers" Cc: intel-xe@lists.freedesktop.org In-Reply-To: <20261203232859.321380-6-stuart.summers@intel.com> References: <20261203232859.321380-4-stuart.summers@intel.com> <20261203232859.321380-6-stuart.summers@intel.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 00:03:37 +0000 X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sashiko-reviews@lists.linux.dev Sender: "Intel-xe" X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: Thank you for your contribution! Sashiko AI review found 6 potential issues to consider: - [Medium] drm/xe: xe_sysctrl_media_resume() skips media disable on reset or power loss - [Medium] drm/xe: xe_sysctrl_media_resume() omits media_verx100 check for absent media - [Medium] drm/xe: host_max_phys_addr() misuses MAX_PHYSMEM_BITS for 46-bit DMA check - [Medium] drm/xe: sticky media defeature in xe_sysctrl_media_probe() breaks reload - [Medium] drm/xe: xe_sysctrl_media_probe() skips media ATS disable for SR-IOV VFs - [Medium] drm/xe: sysctrl_media_defeature() ignores resp.flags firmware status -- commit 7d17b36bd7bfeabd2f18b1bba4f21be143424af7 Author: Stuart Summers drm/xe: Work around media 52-bit limitation on CRI This commit disables media by default on CRI, clamps the device DMA mask to 46 bits when media is enabled on systems whose DMA stays within 46 bits, and adds System Controller mailbox commands to power down media or disable media address translation at probe and resume. > diff --git a/drivers/gpu/drm/xe/xe_pci.c b/drivers/gpu/drm/xe/xe_pci.c > index 4e464ba3bbee8..12fd78137beab 100644 > --- a/drivers/gpu/drm/xe/xe_pci.c > +++ b/drivers/gpu/drm/xe/xe_pci.c [ ... ] > @@ -789,6 +792,54 @@ static int xe_probe_info_early(struct xe_device *xe, > return 0; > } > =20 > +/* > + * Number of address bits media is able to reach on CRI, where it has no > + * address translation of its own. > + */ > +#define XE_CRI_MEDIA_ADDR_BITS 46 > + > +static bool device_iommu_iova_backed(struct device *dev) > +{ > + struct iommu_domain *domain =3D iommu_get_domain_for_dev(dev); > + > + return domain && domain->type !=3D IOMMU_DOMAIN_IDENTITY; > +} > + > +/* Highest architectural physical address the host can produce */ > +static u64 host_max_phys_addr(void) > +{ > +#ifdef MAX_PHYSMEM_BITS > + return DMA_BIT_MASK(MAX_PHYSMEM_BITS); > +#else > + return (phys_addr_t)-1; > +#endif > +} > + > +/* > + * Decide whether media can be used on CRI. Media there cannot translate > + * addresses, so it is only usable if device DMA is guaranteed to stay w= ithin > + * XE_CRI_MEDIA_ADDR_BITS. The IOMMU guarantees that by allocating IOVAs > + * below the device dma mask. Without it, DMA addresses are host physic= al > + * addresses, so media is only usable when the host cannot produce an ad= dress > + * wider than media can reach. > + */ > +static bool cri_media_addressable(struct xe_device *xe) > +{ > + u64 host_max_addr =3D host_max_phys_addr(); > + > + if (device_iommu_iova_backed(xe->drm.dev)) > + return true; > + > + if (host_max_addr <=3D DMA_BIT_MASK(XE_CRI_MEDIA_ADDR_BITS)) > + return true; > + > + drm_info(&xe->drm, > + "IOMMU is not translating device DMA and the host can produce %u bit = physical addresses, media is limited to %u\n", > + fls64(host_max_addr), XE_CRI_MEDIA_ADDR_BITS); > + > + return false; > +} [Severity: Medium] Is MAX_PHYSMEM_BITS a safe proxy for the highest DMA address the host can produce without a translating IOMMU? On x86-64 with 4-level paging, MAX_PHYSMEM_BITS is 46 (the direct-map RAM ceiling) even when boot_cpu_data.x86_phys_bits is 48 or 52, AMD SME places the encryption bit above bit 46, or dev->dma_range_map applies an offset. When cri_media_addressable() falsely returns true, xe_info_init_early() clamps the device DMA mask to 46 bits. On a 4-level paging AMD SME host without IOMMU translation, force_dma_unencrypted() then returns true and bounces system-RAM BOs through SWIOTLB, which breaks xe_tt_map_sg() because xe passes DMA_ATTR_SKIP_CPU_SYNC. Peer MMIO BARs above 46 bits also fail dma_capable() in dma_direct_map_phys(). Conversely, when CONFIG_SPARSEMEM is disabled (such as 32-bit PAE with CONFIG_FLATMEM), MAX_PHYSMEM_BITS is undefined and host_max_phys_addr() falls back to (phys_addr_t)-1, spuriously disabling media. Checking actual physical and DMA bounds (such as iomem_resource.end, SME encryption, and dev->dma_range_map) would avoid both issues. > diff --git a/drivers/gpu/drm/xe/xe_sysctrl.c b/drivers/gpu/drm/xe/xe_sysc= trl.c > index d362e8156fca2..2fc4e35f3e25d 100644 > --- a/drivers/gpu/drm/xe/xe_sysctrl.c > +++ b/drivers/gpu/drm/xe/xe_sysctrl.c [ ... ] > @@ -249,3 +254,162 @@ int xe_sysctrl_sdk_api_version(struct xe_device *xe= , u16 *version) > =20 > return 0; > } > + > +static int sysctrl_media_defeature(struct xe_device *xe, u8 feature) > +{ > + struct xe_sysctrl_media_defeature_req req =3D { .feature =3D feature }; > + struct xe_sysctrl_media_defeature_resp resp =3D {}; > + struct xe_sysctrl_mailbox_command cmd =3D {}; > + size_t out_len =3D 0; > + int ret; > + > + xe_sysctrl_create_command(&cmd, XE_SYSCTRL_GROUP_RUNTIME, > + XE_SYSCTRL_CMD_MEDIA_DEFEATURE, > + &req, sizeof(req), &resp, sizeof(resp)); > + > + ret =3D xe_sysctrl_send_command(&xe->sc, &cmd, &out_len); > + if (ret) > + return ret; > + > + if (out_len !=3D sizeof(resp)) { > + xe_err(xe, "sysctrl: unexpected media defeature response length %zu (e= xpected %zu)\n", > + out_len, sizeof(resp)); > + return -EPROTO; > + } > + > + return 0; > +} [Severity: Medium] Should sysctrl_media_defeature() validate resp.flags before returning 0? struct xe_sysctrl_media_defeature_resp defines u32 flags as firmware status flags, and sysctrl_receive_frames() only checks the transport header result (XE_SYSCTRL_HDR_RESULT(hdr) =3D=3D 0), leaving payload status fields to callers as xe_sysctrl_check_app_status() and xe_ras.c do. If firmware reports a command-level failure in resp.flags, xe_sysctrl_media_probe() skips sysctrl_media_drop() and brings up the media GT with ATS still enabled. [ ... ] > +/* Whether this platform needs the media defeature workaround at all */ > +static bool sysctrl_media_defeature_needed(struct xe_device *xe) > +{ > + return XE_DEVICE_WA(xe, 14028632488) && > + xe->info.has_soc_remapper_sysctrl && > + xe->info.has_sysctrl && > + xe->sc.has_media_feature_disable; > +} [Severity: Medium] Should sysctrl_media_defeature_needed() (or xe_sysctrl_media_resume()) also check xe->info.media_verx100? xe_info_init_early() sets xe->info.media_allowed before handle_gmdid() probes hardware, and xe_info_init() leaves media_allowed true when media is fused off (media_verx100 =3D=3D 0). xe_sysctrl_media_probe() returns ea= rly on !xe->info.media_verx100 without checking firmware support or clearing has_media_feature_disable. On a CRI SKU with fused-off media, enable_media=3D1, and ATS enabled, xe_sysctrl_media_resume() will still send XE_SYSCTRL_MEDIA_DEFEATURE_ATS_DISABLE on resume, and any firmware error will abort xe_pm_runtime_resume() or xe_device_resume(). > +/** > + * xe_sysctrl_media_resume() - Restore media address translation defeatu= re > + * @xe: xe device instance > + * > + * The media address translation defeature does not survive a power loss= , so > + * it must be requested again on resume from D3cold or system suspend wh= enever > + * media is in use and ATS is enabled. The media defeature sent at prob= e when > + * media is not in use persists until a secondary bus reset, which cannot > + * happen while the driver is bound, so it is not resent here. > + * > + * Return: 0 on success, error code on failure > + */ > +int xe_sysctrl_media_resume(struct xe_device *xe) > +{ > + if (!sysctrl_media_defeature_needed(xe) || > + !xe_device_media_allowed(xe) || !sysctrl_ats_enabled(xe)) > + return 0; > + > + return sysctrl_media_defeature_send(xe, XE_SYSCTRL_MEDIA_DEFEATURE_ATS_= DISABLE); > +} [Severity: Medium] Can a secondary bus reset or full power loss happen while the driver stays bound, leaving media powered on after resume? PCI core executes secondary bus resets without unbinding the driver (pci_reset_function() -> pci_reset_bus_function() -> xe_pci_reset_done() -> xe_device_resume(xe, true)), and runtime D3cold, S3 suspend, and S4 hibernation also remove power and resume via xe_pm_runtime_resume() or xe_device_resume() instead of re-running xe_sysctrl_media_probe(). Because xe_sysctrl_media_resume() returns early whenever !xe_device_media_allowed(xe), XE_SYSCTRL_MEDIA_DEFEATURE_DISABLE is never re-sent in the default CRI configuration, leaving unused media powered on. [ ... ] > +void xe_sysctrl_media_probe(struct xe_device *xe) > +{ > + bool media_allowed =3D xe_device_media_allowed(xe); > + int ret; > + > + if (!sysctrl_media_defeature_needed(xe) || !xe->info.media_verx100) > + return; > + > + if (media_allowed) { > + if (!sysctrl_ats_enabled(xe)) > + return; > + > + if (!sysctrl_media_defeature_send(xe, XE_SYSCTRL_MEDIA_DEFEATURE_ATS_D= ISABLE)) { > + xe_dbg(xe, "sysctrl: media address translation defeatured\n"); > + return; > + } > + } [Severity: Medium] Can SR-IOV VFs enable ATS while PCI_ATS_CTRL_ENABLE is clear on the PF, bypassing media ATS disable? When the PF is attached to an identity IOMMU domain (for example iommu=3Dpt in Intel VT-d legacy mode or ARM SMMUv3) on a 4-level paging host with enable_media=3D1, pci_prepare_ats() programs ats_stu on the PF while leaving PCI_ATS_CTRL_ENABLE clear, so sysctrl_ats_enabled() returns false in both xe_sysctrl_media_probe() and xe_sysctrl_media_resume(). VFs created later and attached to translating domains (such as VFIO) enable ATS via pci_enable_ats(), which only requires the PF's ats_stu to match. Since xe_info_init() clears has_sysctrl on VFs, they cannot send XE_SYSCTRL_MEDIA_DEFEATURE_ATS_DISABLE themselves and hit ATS translation errors and media GuC load failures. > + ret =3D sysctrl_media_defeature_send(xe, XE_SYSCTRL_MEDIA_DEFEATURE_DIS= ABLE); > + if (ret) > + xe->sc.has_media_feature_disable =3D false; > + else > + xe_dbg(xe, "sysctrl: media defeatured\n"); [Severity: Medium] Does sending XE_SYSCTRL_MEDIA_DEFEATURE_DISABLE by default break reloading the driver or rebinding via configfs with media enabled? Neither xe_pci_remove() nor xe_driver_flr_fini() performs a secondary bus reset and there is no re-enable command, so media stays defeatured across unload or unbind. Reloading with enable_media=3D1 (or rebinding with gt_types_allowed=3Dprimary,media) then either fails probe on media GT forcewake in xe_gt_init_early() if GMD_ID still reports media, or silently probes without media if GMD_ID reads 0 while leaving dma_mask_size clamped to 46 bits. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203232859.3213= 80-4-stuart.summers@intel.com?part=3D2