From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.15 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796367215; b=uV71n2OFuNxG9s5/c+M+fw2lVSXpQLVPDpsCjoOzG4AXhWMKPYS2seDngtjigTxUCNv6 uXw/L6FbP+HIF0rJsMo/gAISXodGMOdUnWfsQl3JcRgnlJ7BVFvPXf0dwMsTaApNgSugj orb0h8kKm/mg08WBgn6+Lpvzt9PErJ4kbE0aiwn2jivDZiKDl2PKEhBvaX7mZCLGeXT9h 1Ks/ttRFtG0bcbE6Ahw7JaSaOK+1R6HS6sbsiYZ2F8EmrfsfawxTV6a5mVj5deIVcZNfm wuMp2EMZk/N55jvnncZbwDNPhl+OCXehLfsvNtJLVpX2ljfQONgwJM0yIot+dC7klpQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796367215; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Type:Content-Transfer-Encoding; bh=wLh1SyOf6LIqIHm6bM6IjXAC78o9h0lsq891BS2mcbE=; b=VVumOtuchyeRoRMInrlqiFTodwbslI8NKmb6TTdN3GZFGgDx2YUaDUGQeQUP/jXrjy9S KqszdMfGvpz5VHls3tgoRhjkKm0W3rXuTcjBcdFLbZoXmmKHi3bwnZySsxK82iKPgdaSS zGJiFjxzf+7jEAyw9a7FkC9+tqnl9mKBR2f8fmK2z/B+vdYsT+jVPqMj50lJ8QscQJtVy gMZfMfRg7uokIKv2jZIVbI2ZUJI1SIuf05zB7nqT8/a/+gTPXWgIWbCaEjQtvVQhiECv+ 8QyfD7jz5vEgq9H2/UgF//b08rXVl6//8EWSBDU5HFXF54Nc9T6c67vtEaAPnW+Wfaw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=OmJ4wBTf; arc=none smtp.remote-ip=198.175.65.15 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 297E4606A33B for ; Fri, 4 Dec 2026 06:53:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 297E4606A33B Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=OmJ4wBTf DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796367215; x=1827903215; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wLh1SyOf6LIqIHm6bM6IjXAC78o9h0lsq891BS2mcbE=; b=OmJ4wBTfk2wVuETLCZAm7jCVNja0aFegvvrx5EYcS7xlk+c7eBA+3EjP iIoVYVnwU9wS2Q3FlXuM6OcPfMrl1QQg1ge+GL0FfGyWDl6wr0LDF4noG BaUEK6G9Lex1XyLvlWw45yinVhsBDxnlpXaXJGzb5EjKv1ge51Vfb8s7b /wCqbWY5vGxzuyOJhjHZFzHca1c4SoL8w1TEJ3ScunsL9afnxaFhIVTlZ mivKbaGihhGZzCQGXE0GthRJPUtXc94HXiAj7ZjkJL/73PXLrSqaZfVif 0tzFq9iQtV8O5HIRiD3axkbmK5ETaiBCN5i5M6RG2qiL5QKrkAYlPgHYv A==; X-CSE-ConnectionGUID: QiDAG/oaQHqjlSHvvgV5dg== X-CSE-MsgGUID: VSQgrv1GR/2iYS/Y1gfD/w== X-IronPort-AV: E=McAfee;i="6800,10657,11985"; a="5341223" X-IronPort-AV: E=Sophos;i="6.29,77,1794902400"; d="scan'208";a="5341223" Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 22:53:35 -0800 X-CSE-ConnectionGUID: 9fsZpMrLSjahnlHHXyLcVw== X-CSE-MsgGUID: r0SgTuD+TeuBks2eI5SgZA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,77,1794902400"; d="scan'208";a="13917115" Received: from varungup-desk.iind.intel.com ([10.190.238.71]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 22:53:33 -0800 From: Arvind Yadav To: dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: matthew.brost@intel.com, thomas.hellstrom@linux.intel.com, maarten.lankhorst@linux.intel.com, mripard@kernel.org, tzimmermann@suse.de, airlied@gmail.com, simona@ffwll.ch, himal.prasad.ghimiray@intel.com Subject: [PATCH v2 2/2] drm/gpusvm: Clear inline DMA mapping state on unmap Date: Fri, 4 Dec 2026 12:23:18 +0530 Message-ID: <20261204065318.1785149-3-arvind.yadav@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261204065318.1785149-1-arvind.yadav@intel.com> References: <20261204065318.1785149-1-arvind.yadav@intel.com> 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-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Unmap clears has_dma_mapping but leaves the inline DMA address and inline_dma_mapping flag intact. When a devmem callback is present, get_pages() continues through HMM even with a valid DMA mapping. Invalidation during HMM can leave stale inline state while HMM refreshes notifier_seq. The later sequence check can then pass, but DMA array allocation is skipped. The mapper treats the stored DMA address as an array pointer. BUG: KASAN: user-memory-access in drm_gpusvm_get_pages+0xe12/0x1380 [drm_gpusvm_helper] Write of size 16 at addr 000000027abfd000 by task kworker/u64:71/693678 Workqueue: xe_prefetch_work_queue prefetch_work_func [xe] Clear the inline address and flag during unmap so the allocation pass after HMM can allocate a DMA array. Update the helper documentation to describe the inline entry's lifetime. v2: - Clear inline DMA mapping state in __drm_gpusvm_unmap_pages() instead of adding a retry in drm_gpusvm_get_pages() (Matt). - Update the inline DMA helper's lifetime documentation. (Sashiko) Fixes: 8d242e452ed7 ("drm/gpusvm: keep a single DMA mapping inline for THP") Cc: Matthew Brost Cc: Thomas Hellström Cc: Himal Prasad Ghimiray Suggested-by: Matthew Brost Signed-off-by: Arvind Yadav --- drivers/gpu/drm/drm_gpusvm.c | 5 +++++ include/drm/drm_gpusvm.h | 14 ++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/drm_gpusvm.c b/drivers/gpu/drm/drm_gpusvm.c index de2fa2684e84..1a61b13384a0 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_gpusvm *gpusvm, i += 1 << addr->order; } + if (flags.inline_dma_mapping) { + svm_pages->inline_addr = (struct drm_pagemap_addr){}; + flags.inline_dma_mapping = false; + } + /* WRITE_ONCE pairs with READ_ONCE for opportunistic checks */ flags.has_devmem_pages = false; flags.has_dma_mapping = false; diff --git a/include/drm/drm_gpusvm.h b/include/drm/drm_gpusvm.h index b43432af5637..9d55c34ffbb8 100644 --- a/include/drm/drm_gpusvm.h +++ b/include/drm/drm_gpusvm.h @@ -428,12 +428,14 @@ drm_gpusvm_pages_read_retry(struct drm_gpusvm *gpusvm, * from the order. The order still states what one PTE may cover: the range * length for a huge page, PAGE_SIZE for an IOVA mapped range of single pages. * - * Only get_pages() and the free path switch between the two union members. - * Both hold the notifier lock for read, so taking that lock does not stop - * them; callers need the driver lock that does, which every reader of the - * addresses holds anyway. The notifier never touches the union, so the - * pointer returned here stays good and can then be used under the notifier - * lock. + * Callers must hold the driver lock that serializes get_pages() and the + * free path. Invalidation can clear inline storage under the notifier + * lock, so callers must also hold that lock while resolving and copying + * an inline entry. + * + * To use an inline entry after releasing the notifier lock, copy it while + * holding the lock and use the copy. The copy does not keep the DMA mapping + * valid. Callers must still validate it before committing GPU access. * * Return: Pointer to the first device address, NULL if none is populated. */ -- 2.43.0