From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.8 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796058802; b=iMxweQpyqtgT5dbi699B3D5ipb0VFEshZ/VhCmQdtNurF2PGoBLhVFKfrh1y/O/OeQ/Q RT2vc+Xz/zz+7IkAfM4kKNZEcEVhwKLFqT/t3ATLA3OJlMoNLCYU6qpjm6ydgSXRxpo4D dthhZhIK+b+g3yCHg5fn5w1iSYErNle05GIqaetyQL10VHP8wiVu+geEKDVnGnQlol/IT EO1OXCnmIkCZn7H1XcVFHYLKI/E2ZQ8qcD1nb6KP8U/sxCB6smsXMzGV3m9uA9GhdDux8 zJYqQuSC+26KqCqKk4edVsKu4pBVDDmO2MMqBVTSn6RknlEp0tV25W57yabVN5gueOw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796058802; 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:Message-ID:Date: MIME-Version:User-Agent:Subject:To:Cc:References:From: Content-Language:In-Reply-To:Content-Type:Content-Transfer-Encoding; bh=ajpuX4ycwHXyAle/y1XX6pQ4cZolw0oSWQssOh2n+aQ=; b=FyIyIGs3jHAP02iEtnONKO4uAZ70RNnbreIw4/hDk3IjEDxTRKQBu0DB3tLthDFNNcGL Klat0c5SW8GeIJItI/6HA8I6td271nkn2kVyFiK15874WAcEN3AgjFnueaEZ8yU12PDhp txTV+AEsCZ7TKm83F8hk85JLPmtRkTftv9G/C6kxJiPiZlTG11OHIyVGZxE8KKyK4dmw5 Bol0qUXEOhXH+oNvdqSeqpISvvYguRgf7cIP39POJghMsRVOSyYpBqwAWYfJIB/Vh7Bly gP5T2fneJAo/x557Cd6X1tshkB3Ls9RvZHf/gI099aMh7qkhffB8E4pKsoEo5TgBWxg== 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=Qj8C6pxU; arc=none smtp.remote-ip=192.198.163.8 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (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 5E17E606A31C; Mon, 30 Nov 2026 17:13:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5E17E606A31C 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=Qj8C6pxU DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796058802; x=1827594802; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=ajpuX4ycwHXyAle/y1XX6pQ4cZolw0oSWQssOh2n+aQ=; b=Qj8C6pxUZa7MK/lo0vQ6hj5F7+XdnkL+OCY5pOAFNE1+qvo/tGcq3CzS jcUHT8dr+/fEYiUw3fhQWX5+HmqwBodaXB0cPO87lIlgV3iO/sT4pMzyR SZJiAljRzdEdrVCaIYi62lIOnKxiuhokwM3Y5YEaTsl3AapHx7VP3p93B HETNYHAOgQR0Ly1GxLF0HqXfHFyA4a4lENJL68Ak63Fqj1eBFNbJoUugY 8usz9VeDcWBhVyA7Ey+7TNt1+UVGS4xqbhkDymm6yy1YXf6rXnlHVPPZ4 OwsoGz6wgQ9bj/e6P4SY9bzRfGa8c1CTJ9p0sfE+3/I8HVYyQ2UWGHUu+ A==; X-CSE-ConnectionGUID: 4czdjfJvSUmKELKHrjCJww== X-CSE-MsgGUID: 1qT6KiI6T6GVkr9VUNA8ew== X-IronPort-AV: E=McAfee;i="6800,10657,11982"; a="4782928" X-IronPort-AV: E=Sophos;i="6.27,243,1787036400"; d="scan'208";a="4782928" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2026 09:13:21 -0800 X-CSE-ConnectionGUID: PWbIwnqtSruddb3hDBgYxQ== X-CSE-MsgGUID: 1xlCdi+3TumYRkyyMU9oGA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,243,1787036400"; d="scan'208";a="12790406" Received: from cooperst-gp92.amr.corp.intel.com (HELO [10.125.110.218]) ([10.125.110.218]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2026 09:13:20 -0800 Message-ID: Date: Mon, 30 Nov 2026 10:13:17 -0700 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 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 5/8] dmaengine: idxd: Fix error handling in idxd_cdev_open() To: Vinicius Costa Gomes , Vinod Koul , Frank Li , Fenghua Yu , Shuai Xue Cc: dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org References: <20261125-wt-idxd-fixes-v2-0-25a4691dfb9e@intel.com> <20261125-wt-idxd-fixes-v2-5-25a4691dfb9e@intel.com> From: Dave Jiang Content-Language: en-US In-Reply-To: <20261125-wt-idxd-fixes-v2-5-25a4691dfb9e@intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 11/25/26 4:49 PM, Vinicius Costa Gomes wrote: > Three error paths of idxd_cdev_open() are wrong: > > - An ida_alloc() failure jumps to failed_ida without setting rc. The > open usually returns 0 after freeing its context, and the release of > the file then uses the freed filp->private_data. > > - xa_insert() errors other than -EBUSY are ignored. The open succeeds > without the context in the xarray, and the completion records of its > page faults are dropped. > > - On a dedicated WQ, the failed_ida path doesn't undo > idxd_wq_set_pasid(). The WQ keeps the PASID of an SVA bind that is > released right after. > > Set rc on the ida_alloc() failure. Fail the open on xa_insert() errors > other than -EBUSY, and fix the "exist -> exists" typo in its warning. > Disable the PASID of a dedicated WQ on the failed_ida path, as > idxd_file_dev_release() does. > > Fixes: e6fd6d7e5f0f ("dmaengine: idxd: add a device to represent the file opened") > Fixes: b022f59725f0 ("dmaengine: idxd: add idxd_copy_cr() to copy user completion record during page fault handling") > Signed-off-by: Vinicius Costa Gomes Reviewed-by: Dave Jiang > --- > drivers/dma/idxd/cdev.c | 12 ++++++++++-- > 1 file changed, 10 insertions(+), 2 deletions(-) > > diff --git a/drivers/dma/idxd/cdev.c b/drivers/dma/idxd/cdev.c > index f1af7f0d25d3..9343deb2e858 100644 > --- a/drivers/dma/idxd/cdev.c > +++ b/drivers/dma/idxd/cdev.c > @@ -264,8 +264,12 @@ static int idxd_cdev_open(struct inode *inode, struct file *filp) > mutex_lock(&wq->uc_lock); > rc = xa_insert(&wq->upasid_xa, pasid, ctx, GFP_KERNEL); > mutex_unlock(&wq->uc_lock); > - if (rc < 0) > - dev_warn(dev, "PASID entry already exist in xarray.\n"); > + if (rc == -EBUSY) { > + /* Another open of this WQ by the same mm added it */ > + dev_warn(dev, "PASID entry already exists in xarray.\n"); > + } else if (rc < 0) { > + goto failed_get_pasid; > + } > > if (wq_dedicated(wq)) { > rc = idxd_wq_set_pasid(wq, pasid); > @@ -279,6 +283,7 @@ static int idxd_cdev_open(struct inode *inode, struct file *filp) > idxd_cdev = wq->idxd_cdev; > ctx->id = ida_alloc(&file_ida, GFP_KERNEL); > if (ctx->id < 0) { > + rc = ctx->id; > dev_warn(dev, "ida alloc failure\n"); > goto failed_ida; > } > @@ -311,6 +316,9 @@ static int idxd_cdev_open(struct inode *inode, struct file *filp) > put_device(fdev); > return rc; > failed_ida: > + if (device_user_pasid_enabled(idxd) && wq_dedicated(wq) && > + idxd_wq_disable_pasid(wq) < 0) > + dev_err(dev, "wq disable pasid failed.\n"); > failed_set_pasid: > if (device_user_pasid_enabled(idxd)) > idxd_xa_pasid_remove(ctx); >