From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.173 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796452932; b=P6TPTESg86fWHDSuHOzbC9ZrDZcK9B49N90lPj5NX6fPfmSTrJJrGG6O2OKEkXY0497X kS2omCBgJlwtr4iFGrArDWbYC7fYWWbob9pb6pLF9Orjmh6OIK7olZTsuCNNRk6CdQblY cT6is+Em8qXliulDifXHsJZfJaFlzPVPSWKYyYbTFnAifexd7jK3DEBareDUM2eS+9KP7 Wa/To6fg69fS1PrGEfqd35M48ndAkGl5jU4K39XR1kjWbQArtqTOehLQYoQ7+kOk1VVn1 VIu7ysSXyCjgRppnB5ppGgaYv2+6ourya5hdBPEPH7UbDqt+WMthOej678dGhzcWnPQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796452932; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-Id:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=ic+PYiKpZYr13U2Xu75p/0Pvt9AZU3b87ZXr5iZzyU0=; b=CvzYUFpGh7oZ7yAq/NT5CUXokE7XiH12YsnDlUZP8QVHlLoRjDsZAOXwo6p6PyEZO9F3 VaD5lOa0X5AhBPzV4l3n1MbPJUhCmbEGMKSK4rR2FTcVAXd8yAvUpAPpcn5QT5j51kauM KzA2MjvE2Ip9noaimeSvQZLYNkezuuQeUhScEJV9F4Uq621edtwk670UNO4XK9dwP5yK0 fsZW87sUZS6HXdt1+wrxXhKEVi2tEf7s5k54tOQ1EaW16QflbUAA8QfMC5qHj24FO2siR GwenUPKnWb+suieyMkAGamlPGRVh/lUJ8Di3JXLSkGXeJ7ndouxTislrpv9kIGHE+9A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=NkQCJVIo; arc=none smtp.remote-ip=74.125.82.173 Received: from mail-dy1-f173.google.com (mail-dy1-f173.google.com [74.125.82.173]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A876606A322 for ; Sat, 5 Dec 2026 06:42:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9A876606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=NkQCJVIo Received: by mail-dy1-f173.google.com with SMTP id 5a478bee46e88-386ab9ab619so2763397eec.1 for ; Fri, 04 Dec 2026 22:42:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796452931; x=1797057731; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=ic+PYiKpZYr13U2Xu75p/0Pvt9AZU3b87ZXr5iZzyU0=; b=NkQCJVIoFPiJgaiO5bus5woookNYzJGw5zyQxMlbEXlX3d0HpO+WiI1z9GaCA2keq6 7xUlwEpREh7PuRV2ylTNB28bPGFnhAS0OkqV2qEz6sLfC+vY4DrMVvNdm+w+6YT7KBGB 3JvHoKVQi0ayBm5MmUqnV22ck42pY83Aqqtyy1vvaC7fH23jfeVBQ24cxd9yoMgCdEo3 x9oe67az1iciKo8TcLxfIWrR1ZtoZetg/qqExkC7CmBwmqBWIfyHVMbCvnVw0KfYGavk /tRTTj7HVazAB6X6eC8wpfCNOAO/H1lJYVUIFrknGeSo1oGjcIXb95wZEi7ECcOOxNN2 c0tQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796452931; x=1797057731; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=ic+PYiKpZYr13U2Xu75p/0Pvt9AZU3b87ZXr5iZzyU0=; b=qId24igZzQ3idyYoKf6hVDaUfdF3RZWF7/KwY8mPeOPn0oC45U0RilYZPRTESYeEmE xqq1OBQH4TynmqTxFFD2cQhDbXKUmDBH/Fyk8sk7FhF0sGbn4nIodF9YBDHXSqMz8iIP 61H8VYfQu9iuxXS+jZyRcPgyG0481rG731Udxb7VaT0dkV4aRTksiC85wAoOsQfzesYO BBPjzlkpqguSuVfbo5NZqoXsBUo5C0EQLgeP+Hoq3Fzx0YNxT7RFU8EFDQMkxJ31c6RK 09sPMMIhJrJP02fo9L5TIXVKZV7CcOJTZj1iTIAEKSjmrkoQsG+PEaZZUNaYF2VOtmpl ndYw== X-Forwarded-Encrypted: i=1; AL+hErFw2GKeWR9NqRMa01i+LWW3GpdUuSBIp4TQMllwnAmq+vBjTjXX3ZiNpkkcsQ0WVOAoFBtf6FzVJZ/LK0Q=@vger.kernel.org X-Gm-Message-State: AB4q+uFg1ZuvZ6RhABAK3/fgxnafRYG+JCIJ/YTZXgrH5MWABNzHh1NS XBGMh4poVRk3jU/zjbeeAIxVoah0uh0siBCiAFLXXQ9k4laz6GCj8LNe X-Gm-Gg: AZFdTZe83xvBSXuItRNOwWMdo8nGejcZGKauqIxkyYJy6JTlXlOj3itzWJGHwl9Mf/I v5JBD7fFbEjrRNOXUVL7EFt6PcuzI/o5JHy9TBVB3xBMPLRXxoTrxYOP0F2hA8vtkITYviz3ATx B7CPVCY0x6awbHKFnwwtWx5hf5N+xBAx1Oaw3m9KJNDYJNg0CRMtFcRz6mTsal5y8RT9yDYvknJ AMTmp5EW8P8j/b72CS5VJMmF+fxEk0aidxKPEtWmKbX9tjaLqgAYPx2q9IHVepskeFvbQGRaO6X dD4Ys0w4OEoJZyfzA9rnaxeRugPFy5JYns85HmgcXkqTDPI/Kq0pX1Yn03I+Y/6bLLaaakopaEM RYv7dC1f3DKYvyx39A+2gti/Prj7eI/S13LOmoBpfrErE2MSB81aBTGMEFvlt+wVF82f0gpklhJ OOO8rfqpQcuSb78kqP9K1uIAcApKw2lcVSOKhS1xzV4vgB6gcT6WR2a7AZfASRVhkuY7AEzMmk+ kG70zZM9h03frIRwQGnXzlEXJ1MEqRne+Yc5MqIGr5Cur+dR3NexfeK99iLMfK71ISLbUUSIvu3 jPNnG52oPZ/PY+/4XieI/NOUo9yDisDZPewHUjg3zVMT98ORcR8Rxwe9ECvVzBseQJ8= X-Received: by 2002:a05:7301:1a:b0:386:959c:11ac with SMTP id 5a478bee46e88-387520b1bb3mr4295271eec.6.1796452930635; Fri, 04 Dec 2026 22:42:10 -0800 (PST) Received: from localhost.localdomain (wood.seclab.cs.ucsb.edu. [128.111.49.37]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-387521bb368sm21651355eec.10.2026.12.04.22.42.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 22:42:10 -0800 (PST) From: Praneeth Balasubramanian To: Matthew Brost , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter Cc: Praneeth Balasubramanian , =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , Himal Prasad Ghimiray , Honglei Huang , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH] drm/gpusvm: reject device pages not owned by the caller Date: Fri, 4 Dec 2026 22:42:01 -0800 Message-Id: <20261205064202.2527445-1-praneethb2002@gmail.com> X-Mailer: git-send-email 2.25.1 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit drm_gpusvm_dma_map_pages() treats every device private and device coherent page returned by hmm_range_fault() as populated from a drm_pagemap. It calls drm_pagemap_page_to_dpagemap(), which reads zone_device_data as a struct drm_pagemap_zdd and dereferences zdd->devmem_allocation->dpagemap. That assumption does not hold for foreign pages. hmm_range_fault() filters non-present device private entries by owner. But a present device coherent page is reported as valid regardless of owner. A coherent VRAM page migrated by amdkfd SVM holds a struct svm_range_bo in zone_device_data, not a drm_pagemap_zdd. When such a page reaches drm_gpusvm_dma_map_pages() through drm_gpusvm_get_pages(), for example from the Xe userptr path which sets allow_mixed, drm_pagemap_page_to_dpagemap() misreads the object type and follows a bogus dpagemap pointer into drm_pagemap_get() and dpagemap->ops->device_map(). Compare page_pgmap(page)->owner against ctx->device_private_page_owner before interpreting zone_device_data. Fail with -EOPNOTSUPP on mismatch, the same error already used for unsupported page mixes. Device private pages keep working unchanged since hmm_range_fault() already filters them by that owner. This was found by an LLM-based audit that checks code against the rules stated in kernel comments. Signed-off-by: Praneeth Balasubramanian --- Notes: This was found by an LLM-based audit, part of research at UCSB SecLab. An LLM turned a kernel comment into a rule, and three LLM votes checked the code against it. The fix and changelog were drafted with GLM-5.3, then checked against the source and partly rewritten with Claude Opus 5.5. I reviewed the patch and take responsibility for it. Testing: builds without new warnings with W=1 (x86_64 allmodconfig), clang 23. checkpatch.pl is clean. Not runtime-tested, and there is no reproducer. I do not have this hardware. RFC: rejecting foreign device coherent pages is one option. Mapping them as plain system memory may be what you want instead. This needs a system with both an amdkfd coherent memory device and an Xe device, which I do not have. drivers/gpu/drm/drm_gpusvm.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/drm_gpusvm.c b/drivers/gpu/drm/drm_gpusvm.c index de2fa2684e84..a5fcf4de5549 100644 --- a/drivers/gpu/drm/drm_gpusvm.c +++ b/drivers/gpu/drm/drm_gpusvm.c @@ -1614,8 +1614,20 @@ static int drm_gpusvm_dma_map_pages(struct drm_gpusvm *gpusvm, order = drm_gpusvm_hmm_pfn_to_order(pfns[i], i, npages); if (is_device_private_page(page) || is_device_coherent_page(page)) { - struct drm_pagemap_zdd *__zdd = - drm_pagemap_page_zone_device_data(page); + struct drm_pagemap_zdd *__zdd; + + /* + * hmm_range_fault() reports present device coherent + * pages of any owner. Only pages of our owner come + * from a drm_pagemap and carry a drm_pagemap_zdd. + */ + if (page_pgmap(page)->owner != + ctx->device_private_page_owner) { + err = -EOPNOTSUPP; + goto err_unmap; + } + + __zdd = drm_pagemap_page_zone_device_data(page); if (!ctx->allow_mixed && zdd != __zdd && i > 0) { base-commit: 29beb21c21ada7207692b2d69fc58dcd15dab6e9 -- 2.25.1