From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.11 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796068424; b=QnI4CZUWoVfEwqNasRyivYsO3rfDTZ9uOmXohqxtj8DZIs7uweTjOiWDnYEb+9FnEY6S ECq7FIjPR4BrNuUwTtk7mXiLD3/Nuv7eq0f3hi0DgJ+Yg/rOlab11jKambiZkQr3yOS5f O5pGrbMItzbTWJbYMnAM7ElJ6CBM8DOfwEq0GEr+DZ//02LgrN9S5pXzDIs/Ce5qeKAKf pbkphhKqY+AKqGqgTX2pCVEHLgSDcrBnHeGiKMrDKWxvi7LWVZU/fUTZfKKxRQrqdeDHv DAGffaDmVN8c5CQaL/4yWwNuLbpkkeRqraxfNp3wepJvYADSSgflfn6dAS16auvZ2cQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796068424; 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-Transfer-Encoding; bh=jqi5cItFW9sRXuPYDS8tyMuhiyWpv6JqOzJrfw9iRqM=; b=Z/8U/o0zk7TU550DA8vh0CgJcOmgZO7MIpD1sOnnfUn8UthTHBSgIV3TinN1YxfGLw4X 8/dNAMmUF2mcCkyETrkTC1IChHXjd0sBZRLdQ+tXxoJSmqaIPav2PxdqqeUOvI4qxNbAy 24UF7dYehtFL6eQjfTEDBP12rjEkjANKXi8NlKWbYIfQMk3qdiPuugJ91ENca9m/L/pFR R2wUduAmrn074d0RA4LndsTH9fBVBW4Z60YAuuPzZ4WEz73P4hBV61tsVKMzRGemuCIkZ 15IGK69LvbHz+X5VSiY/WWS2uYRbsvM32OsYRZfTD64xI3/Yva7qOe6Zhgr1tCwTSjA== 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=jXkcW0qy; arc=none smtp.remote-ip=198.175.65.11 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 7B61C606A68C; Mon, 30 Nov 2026 19:53:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7B61C606A68C 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=jXkcW0qy DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796068424; x=1827604424; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jqi5cItFW9sRXuPYDS8tyMuhiyWpv6JqOzJrfw9iRqM=; b=jXkcW0qyLKWyyz09vZAoWGJHdJiypJELcYm59rSjaDMkJnKvDB4ojgt/ dlysJrwnam4wexEJnDhXiAYu8HcOhfoLL/+t5W6q2Yg/M9JCo83DYe7kZ gju1S38rZWbbwjbB2wrQV8qViPaz+QSUKkHrH7FekBV7vTzIFZYuD3IgA LdbwNOra208ZrIZ3KEj2GIrWFnVWOXixLrmD+jKenec7aeKTdePrHl0jv uFppLTOq2QgTJoGwVFu5SY5TOEy7x65k8Q5kjPysXIj6zAd0L/H0ztp5e FtpiJB/4DU8F/E1ekiD03PQte/PGR9z0xpPOnKtQTQMwY2wP/e7hHwwE6 g==; X-CSE-ConnectionGUID: Zu0GMLLFTQmCyvc6/LkZdg== X-CSE-MsgGUID: fowceOnJQfSCJs1bXfLRzA== X-IronPort-AV: E=McAfee;i="6800,10657,11982"; a="4805768" X-IronPort-AV: E=Sophos;i="6.27,243,1787036400"; d="scan'208";a="4805768" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2026 11:53:41 -0800 X-CSE-ConnectionGUID: 2k0SKQfZRsmUCzJiV5AmNA== X-CSE-MsgGUID: v9sC5fcdRI+QPObkX7ol4w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,243,1787036400"; d="scan'208";a="13036623" Received: from jf5300-15a101203tc.jf.intel.com (HELO meta-crater2c.jf.intel.com) ([10.54.113.49]) by orviesa002.jf.intel.com with ESMTP; 30 Nov 2026 11:53:40 -0800 From: Daniel Byrne To: Vinod Koul , dmaengine@vger.kernel.org Cc: Vinicius Costa Gomes , Dave Jiang , Frank Li , Fenghua Yu , Dan Williams , linux-kernel@vger.kernel.org, Daniel Byrne , stable@vger.kernel.org Subject: [PATCH v2 05/10] dmaengine: idxd: take an mm_users reference for the completion record copy Date: Mon, 30 Nov 2026 11:47:16 -0800 Message-ID: <20261130194721.1900266-6-daniel1.byrne@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261130194721.1900266-1-daniel1.byrne@intel.com> References: <20261130194721.1900266-1-daniel1.byrne@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-Transfer-Encoding: 8bit The user context records the opener's mm without a users reference. On exit, exit_mm() runs before the files are closed, so the context's release, which removes it from the work queue's PASID xarray, runs after the address space is torn down, and the drain the release issues completes the context's in-flight descriptors. A completion record write of one of them faults, and the event log fault work finds the context in the xarray and calls kthread_use_mm() on an mm whose users count is zero to copy the record into it. The mm_struct itself is kept by the SVA binding, but an address space in that state must not be used. The copy normally fails, and when it races with exit_mmap() it can install page table entries that free_pgtables() abandons. Take a users reference for the copy with mmget_not_zero(), and skip the copy when the address space is gone, which counts as a failed copy. Remove the context from the xarray before unbinding the SVA handle, so that the mm_struct is alive whenever the fault work can find the context. Fixes: b022f59725f0 ("dmaengine: idxd: add idxd_copy_cr() to copy user completion record during page fault handling") Cc: stable@vger.kernel.org # 6.4+ Signed-off-by: Daniel Byrne --- New in v2. drivers/dma/idxd/cdev.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/dma/idxd/cdev.c b/drivers/dma/idxd/cdev.c index 50cd2e3f342d..542d0b275a71 100644 --- a/drivers/dma/idxd/cdev.c +++ b/drivers/dma/idxd/cdev.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -140,8 +141,13 @@ static void idxd_file_dev_release(struct device *dev) if (ctx->sva) { idxd_cdev_evl_drain_pasid(wq, ctx->pasid); - iommu_sva_unbind_device(ctx->sva); + /* + * Once the context is no longer in the xarray no fault work + * can find it. The SVA binding keeps its mm_struct alive + * until then. + */ idxd_xa_pasid_remove(ctx); + iommu_sva_unbind_device(ctx->sva); } kfree(ctx); mutex_lock(&wq->wq_lock); @@ -774,7 +780,16 @@ int idxd_copy_cr(struct idxd_wq *wq, ioasid_t pasid, unsigned long addr, goto out; } + /* + * The context records the opener's mm without a users reference of + * its own. The file's release, which removes the context from the + * xarray, runs after exit_mm() when the opener exits. Take one for + * the copy, and skip it if the address space is already gone. + */ mm = ctx->mm; + if (!mmget_not_zero(mm)) + goto out; + /* * The completion record fault handling work is running in kernel * thread context. It temporarily switches to the mm to copy cr @@ -805,6 +820,7 @@ int idxd_copy_cr(struct idxd_wq *wq, ioasid_t pasid, unsigned long addr, left += status_size; } kthread_unuse_mm(mm); + mmput(mm); out: mutex_unlock(&wq->uc_lock); -- 2.43.0