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 80FC6606A322 for ; Fri, 4 Dec 2026 07:40:03 +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=TwsASAx7 Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 17A2210E11B; Fri, 4 Dec 2026 07:39:58 +0000 (UTC) Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id 354FB10E11B; Fri, 4 Dec 2026 07:39:52 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id DA29C4464D; Fri, 4 Dec 2026 07:39:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9B2871F000CE; Fri, 4 Dec 2026 07:39:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796369991; bh=yQ+4qOpBnOfJA5g3dau1kyy1j32BqP1uGM0LuAMy+9w=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=TwsASAx7DmQlsNkQKIxCWNhlw7vitI6NxVI3DygqcTcz/7KeOl3Y32Plgy/cHg6Sj MyG1L3htnimLQQzV1zcdSEbkOGMqzGRRw9zO98E8NFznm10qWe4aBpih9r1TttIj0k LfdGNr3LFNh+4YYtmtf3isUA/Zxm1iUeDpkDu8tb7VNbm0cWwp7BU+oFjua4W6cCkd 1DljbtjH/+EuNzTUVcpRJ+8+yfwBjdP20VBaIx0STuqc7tkZkmmSeURXsy3IRL2D8U T5D7prFK3NIrG0sLVFcXPb+rGeVaYnZXirbkrd1OOMRYp9PQtvkv7jTDIysFLfCwvH HSVmB43BxuKYg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2 2/2] drm/gpusvm: Clear inline DMA mapping state on unmap To: "Arvind Yadav" , dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org In-Reply-To: <20261204065318.1785149-3-arvind.yadav@intel.com> References: <20261204065318.1785149-1-arvind.yadav@intel.com> <20261204065318.1785149-3-arvind.yadav@intel.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 07:39:51 +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=-11.2 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 2 potential issues to consider: - [High] drm/gpusvm: data race in drm_gpusvm_get_pages() against inline unmap clear - [Low] drm/gpusvm: stale inline-mapping comment in drm_gpusvm_get_pages() -- commit bab5781b359a68d1d19fa3199ce1021cc07be6b6 Author: Arvind Yadav drm/gpusvm: Clear inline DMA mapping state on unmap This commit clears inline_addr and flags.inline_dma_mapping in __drm_gpusvm_unmap_pages(), and updates the drm_gpusvm_pages_first_dma() documentation to require holding the notifier lock when resolving and copying an inline entry. > diff --git a/drivers/gpu/drm/drm_gpusvm.c b/drivers/gpu/drm/drm_gpusvm.c > index de2fa2684e846..1a61b13384a01 100644 > --- a/drivers/gpu/drm/drm_gpusvm.c > +++ b/drivers/gpu/drm/drm_gpusvm.c > @@ -1286,6 +1286,11 @@ static void __drm_gpusvm_unmap_pages(struct drm_gp= usvm *gpusvm, > i +=3D 1 << addr->order; > } > =20 > + if (flags.inline_dma_mapping) { > + svm_pages->inline_addr =3D (struct drm_pagemap_addr){}; > + flags.inline_dma_mapping =3D false; > + } > + > /* WRITE_ONCE pairs with READ_ONCE for opportunistic checks */ > flags.has_devmem_pages =3D false; > flags.has_dma_mapping =3D false; [Severity: High] Can clearing svm_pages->inline_addr here race with the unlocked dma_addr allocation loop in drm_gpusvm_get_pages()? When ctx->devmem_fn is set (for example, from Xe's prefetch_ranges()), drm_gpusvm_get_pages() bypasses the fast path even with a valid inline mapping and inspects and updates the union before taking gpusvm->notifier_lock: drivers/gpu/drm/drm_gpusvm.c:drm_gpusvm_get_pages() { ... if (map_dma) { for (p =3D 0; p < num_pages; ++p) { if (drm_gpusvm_pages_first_dma(&svm_pages[p], NULL)) continue; svm_pages[p].dma_addr =3D kvzalloc_objs(*svm_pages[p].dma_addr, npages); ... drm_gpusvm_notifier_lock(gpusvm); ... } __drm_gpusvm_unmap_pages() runs from MMU notifiers under gpusvm->notifier_lock without the driver lock, so the two paths share no locks here. Because svm_pages->inline_addr and svm_pages->flags.__flags are separate fields with no compiler or release barrier between the plain 16-byte clear and WRITE_ONCE(), the flag update can become visible first: CPU0 (drm_gpusvm_get_pages) CPU1 (MMU notifier) --------------------------- ------------------- down_write(&gpusvm->notifier_lock) __drm_gpusvm_unmap_pages() WRITE_ONCE(flags, ...) /* reordered */ drm_gpusvm_pages_first_dma() sees inline_dma_mapping =3D=3D 0 sees dma_addr =3D=3D NULL svm_pages[p].dma_addr =3D kvzalloc_objs(...) svm_pages->inline_addr =3D {} <-- clobbers dma_addr with NULL up_write(&gpusvm->notifier_lock) drm_gpusvm_notifier_lock() If inline_addr.addr was 0 (such as VRAM DPA 0) or the 16-byte clear is torn, the delayed zeroing can overwrite the newly allocated dma_addr pointer with NULL, permanently leaking the buffer, or tear the pointer and corrupt memory on a later kvfree(). Reading drm_gpusvm_pages_first_dma() outside notifier_lock also violates the updated locking contract documented by this patch. Since gpusvm->notifier_lock cannot wrap GFP_KERNEL allocations, could drm_gpusvm_get_pages() allocate into a temporary buffer outside the lock and inspect and install svm_pages[p].dma_addr under notifier_lock, freeing any unused buffer after unlocking? [Severity: Low] Does the comment above drm_gpusvm_pages_valid_unlocked() in drm_gpusvm_get_pages() now need an update? drivers/gpu/drm/drm_gpusvm.c:drm_gpusvm_get_pages() { ... /* * drm_gpusvm_pages_valid_unlocked() also resets any instance whose * mapping was invalidated, so it must run on the map_dma path even when * devmem_fn suppresses the fast path; otherwise a stale inline mapping * is later mistaken for a dma_addr array by drm_gpusvm_dma_map_pages(). */ ... } With __drm_gpusvm_unmap_pages() clearing inline_addr and flags.inline_dma_mapping on invalidation, invalidated entries no longer retain a stale inline mapping when drm_gpusvm_get_pages() runs. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204065318.1785= 149-1-arvind.yadav@intel.com?part=3D2