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=1796068422; b=UL3SRaajePAeie8fzoEqpMJ+pNB7uqJqT705NvcR2ZRskVXog4GAeUsKZ8NAIBJFg/sH RdrAK1mJLB9Hzy0YLwT64sFu7VNtIvVou7/Ort7nEfJSzBVTWQZbZ1a+ashNydYCpahMl yuSgCpVW9myZEbfz7cv5XugOBLYJvbkXLiR6Nxw8WjkupFv9CxnHd5Z6ftJxAgK3+lfvQ hJaS+fOZ/t+SrXPJiypo8qqygza3zDmhY1CgxfNPC4+Ws9Y0MjbJRg55coVo0Ht5VU5OP 1lgswNhFit58eaoM5u4+U0NnGQrDfH+CcUsDWxVDyBGgKCSM7NqlKoZTjCDgSAnCPAA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796068422; 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=oxGmvr9eYN5CrBlU4lgD3LfLMjyx6+qecreX4xwFr44=; b=fCEKMovPNmfiPsPQML7DPuaTYZK4BwstSX6ZX2ln2iPDdR3bVqTXNQI4Vbk5hOJPQhCO 2H80sNnZusi+X9BHKm2qj7TbJtIL3j3X7QlUs0IF18gom1YppM9GytO5zXvFgmwZHs1ab XLnvd62MG9gZCzoxw3j7rFHACIa8jmOaui4LDr34oomHkXFhUJMOUkneAlG/upAVAO7Dx wMbFngNw3nbyLthde+ejQSNl85Gbdno7WPCEP7wQGGWCyBovbsU0i+hERz1PJ+OSGuVzs TUeU0EMvcDdUgWxRbwiJJyWgxE1i/edrUfFDzwjN8ryjzgg2GKsMttW7nx/3TI1pvHw== 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=U2D2LcXc; 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 991E9606A320; Mon, 30 Nov 2026 19:53:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 991E9606A320 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, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=U2D2LcXc DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796068421; x=1827604421; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=oxGmvr9eYN5CrBlU4lgD3LfLMjyx6+qecreX4xwFr44=; b=U2D2LcXcI6K3ss5Sq3He20848zHt5YxiVNx74iBVF5bkg2qH/Xbdurw5 tKeHuM5QkU6h4j82amqIokbhLw9nVeGx1bFQZc0urq5rSvCe1Bswqp9jf K7Q0+yUbA8OuNHJGjoXZw0Co/fdr8vJx4gMm7jGYW8Au5fHKEfFcoZ9Hw obTgOhZvyiuJiHlQI74Y5WndpUtB3GphHJ/Btn4DMFAgeHeSA5Q9EFVtT Nwp3vqxwdW5VU83YSMd75McHBOHh2APC0qC/Q+Ssr+jzNTojeGVHP3ApR e3ESNm0so5ZwEZO0hl0cwTWJteY5z/mTaLE/GdVX4CG0VR5gnwaZDW8cB Q==; X-CSE-ConnectionGUID: IzYvUJGbT72k8NH3h8S7+g== X-CSE-MsgGUID: wXx9YfPKSr6CKzp6QBVYRQ== X-IronPort-AV: E=McAfee;i="6800,10657,11982"; a="4805758" X-IronPort-AV: E=Sophos;i="6.27,243,1787036400"; d="scan'208";a="4805758" 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:40 -0800 X-CSE-ConnectionGUID: Cttp+15fRgKa6ZTdIdVPDQ== X-CSE-MsgGUID: t3gRRHPsTXekrgtmUcwf7Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,243,1787036400"; d="scan'208";a="13036614" 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 02/10] dmaengine: idxd: detach the user fault workqueue under the event log lock Date: Mon, 30 Nov 2026 11:47:13 -0800 Message-ID: <20261130194721.1900266-3-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 event log walk tests wq->wq and queues fault work on it, and the drain of a closing context's PASID tests it and drains it, both under evl->lock. The user driver's remove destroyed the workqueue without that lock, so a walk could queue on a workqueue being destroyed. The probe's error path destroyed it without clearing the pointer, so a later drain found a dangling one. That happens when a context's file stays open across an unbind, a rebind's probe fails after it created the workqueue, and the file then closes. Detach and destroy the workqueue under evl->lock, in one helper that the remove and the probe error path share, and clear the pointer in both. A walk or a drain that finds it gone knows that the fault work it would have waited for has run. The probe attaches the workqueue and sets the type under the same lock, so that a walk sees them together. Fixes: c40bd7d9737b ("dmaengine: idxd: process user page faults for completion record") Cc: stable@vger.kernel.org # 6.4+ Signed-off-by: Daniel Byrne --- v2: idxd_user_drv_probe() creates the workqueue into a local and stores wq->wq and the IDXD_WQT_USER type together under evl->lock, the lock they are detached under, so that a walk sees the two together; the message gives the sequence that leaves a drain with the dangling pointer (a file kept open across an unbind, a rebind whose probe fails after it created the workqueue, then the close) and no longer says that a walk finds it; Fixes and Cc: stable tags added. drivers/dma/idxd/cdev.c | 42 ++++++++++++++++++++++++++++++++++------- drivers/dma/idxd/irq.c | 5 ++++- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/drivers/dma/idxd/cdev.c b/drivers/dma/idxd/cdev.c index 82b07cf942ef..50cd2e3f342d 100644 --- a/drivers/dma/idxd/cdev.c +++ b/drivers/dma/idxd/cdev.c @@ -592,11 +592,33 @@ void idxd_wq_del_cdev(struct idxd_wq *wq) put_device(cdev_dev(idxd_cdev)); } +/* + * The event log walk tests the fault workqueue and queues on it, and the + * drain of a closing context's PASID tests it and drains it, both under + * the log's lock, which neither the probe nor the remove otherwise takes. + * The workqueue is therefore detached and destroyed under that lock. A + * walk or a drain that finds it gone knows that its work has run. + */ +static void idxd_user_wq_destroy_fault_wq(struct idxd_wq *wq) +{ + struct idxd_evl *evl = wq->idxd->evl; + + if (evl) + mutex_lock(&evl->lock); + wq->type = IDXD_WQT_NONE; + destroy_workqueue(wq->wq); + wq->wq = NULL; + if (evl) + mutex_unlock(&evl->lock); +} + static int idxd_user_drv_probe(struct idxd_dev *idxd_dev) { struct device *dev = &idxd_dev->conf_dev; struct idxd_wq *wq = idxd_dev_to_wq(idxd_dev); struct idxd_device *idxd = wq->idxd; + struct idxd_evl *evl = idxd->evl; + struct workqueue_struct *fwq; int rc; if (idxd->state != IDXD_DEV_ENABLED) @@ -629,13 +651,22 @@ static int idxd_user_drv_probe(struct idxd_dev *idxd_dev) goto wq_err; } - wq->wq = create_workqueue(dev_name(wq_confdev(wq))); - if (!wq->wq) { + fwq = create_workqueue(dev_name(wq_confdev(wq))); + if (!fwq) { rc = -ENOMEM; goto wq_err; } + /* + * Attached under the lock it is detached under, so that a walk sees + * the workqueue and the type together. + */ + if (evl) + mutex_lock(&evl->lock); + wq->wq = fwq; wq->type = IDXD_WQT_USER; + if (evl) + mutex_unlock(&evl->lock); rc = idxd_drv_enable_wq(wq); if (rc < 0) goto err; @@ -653,8 +684,7 @@ static int idxd_user_drv_probe(struct idxd_dev *idxd_dev) err_cdev: idxd_drv_disable_wq(wq); err: - destroy_workqueue(wq->wq); - wq->type = IDXD_WQT_NONE; + idxd_user_wq_destroy_fault_wq(wq); wq_err: mutex_unlock(&wq->wq_lock); return rc; @@ -667,9 +697,7 @@ static void idxd_user_drv_remove(struct idxd_dev *idxd_dev) mutex_lock(&wq->wq_lock); idxd_wq_del_cdev(wq); idxd_drv_disable_wq(wq); - wq->type = IDXD_WQT_NONE; - destroy_workqueue(wq->wq); - wq->wq = NULL; + idxd_user_wq_destroy_fault_wq(wq); mutex_unlock(&wq->wq_lock); } diff --git a/drivers/dma/idxd/irq.c b/drivers/dma/idxd/irq.c index 7ae73bb39548..65f3e389113c 100644 --- a/drivers/dma/idxd/irq.c +++ b/drivers/dma/idxd/irq.c @@ -339,7 +339,10 @@ static void process_evl_entry(struct idxd_device *idxd, * alone. A kernel WQ, or a user WQ whose cdev driver * is not bound, has no cdev workqueue and no user * contexts, so queueing could only warn and drop the - * record. Note it and move on. + * record. Note it and move on. The user driver + * detaches the workqueue under evl->lock, which this + * walk holds, so the one tested here is the one + * queued on. */ if (!is_idxd_wq_user(wq) || !wq->wq) { dev_warn_ratelimited(dev, -- 2.43.0