From patchwork Tue Dec 12 02:21:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rex Zhang X-Patchwork-Id: 13488325 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ToSqclYt" Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFEABE5 for ; Mon, 11 Dec 2023 18:22:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702347725; x=1733883725; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SsZ0Cj1VCqg3K4TCYEE+ZPILHx6tGaNBNDo3BJFIN2o=; b=ToSqclYt//pmFTmf4y3M7unLhaijl8+UXh2iX+VcrydCfXESEDO8XiH6 BZ8ViPCLxvyQhvHz0OUAnXFKS1EjCyf9T8qV9MMTlzmrZ0rCRk7KVcOYz mQkdM1Xee+ahIZ+2W+8hDJwmO9Xd7LyGijJIh12Uw2uU9AHaa7SHuA0bL WbPS1204OW3TKrnLkS+xsV+n/2BvyLPCQrFtnhGyAts7u/S9t4F2mA3dv emZEymBHUPpNTtyPKI2AnEfYv7i2Oa8N5bQtuW1EbxOALGqvAyY28+6CO MjDT8OKbSPOhDnUxeJFIGcLxt2Z1B1fdg7lTERrXnyPu3XGDn/7RVWMu0 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10921"; a="461217916" X-IronPort-AV: E=Sophos;i="6.04,269,1695711600"; d="scan'208";a="461217916" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Dec 2023 18:22:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10921"; a="807556783" X-IronPort-AV: E=Sophos;i="6.04,269,1695711600"; d="scan'208";a="807556783" Received: from rex-z390-aorus-pro.sh.intel.com ([10.239.161.21]) by orsmga001.jf.intel.com with ESMTP; 11 Dec 2023 18:22:03 -0800 From: Rex Zhang To: vkoul@kernel.org, dmaengine@vger.kernel.org Cc: dave.jiang@intel.com, fenghua.yu@intel.com, rex.zhang@intel.com Subject: [PATCH] dmaengine: idxd: Move dma_free_coherent() out of spinlocked context Date: Tue, 12 Dec 2023 10:21:58 +0800 Message-Id: <20231212022158.358619-2-rex.zhang@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231212022158.358619-1-rex.zhang@intel.com> References: <20231212022158.358619-1-rex.zhang@intel.com> Precedence: bulk X-Mailing-List: dmaengine@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Task may be rescheduled within dma_free_coherent(). So dma_free_coherent() can't be called between spin_lock() and spin_unlock() to avoid Call Trace: Call Trace: dump_stack_lvl+0x37/0x50 __might_resched+0x16a/0x1c0 vunmap+0x2c/0x70 __iommu_dma_free+0x96/0x100 idxd_device_evl_free+0xd5/0x100 [idxd] device_release_driver_internal+0x197/0x200 unbind_store+0xa1/0xb0 kernfs_fop_write_iter+0x120/0x1c0 vfs_write+0x2d3/0x400 ksys_write+0x63/0xe0 do_syscall_64+0x44/0xa0 entry_SYSCALL_64_after_hwframe+0x6e/0xd8 Move it out of the context. Fixes: 244da66cda35 ("dmaengine: idxd: setup event log configuration") Signed-off-by: Rex Zhang Reviewed-by: Dave Jiang Reviewed-by: Fenghua Yu --- drivers/dma/idxd/device.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/dma/idxd/device.c b/drivers/dma/idxd/device.c index 8f754f922217..fa0f880beae6 100644 --- a/drivers/dma/idxd/device.c +++ b/drivers/dma/idxd/device.c @@ -802,6 +802,9 @@ static int idxd_device_evl_setup(struct idxd_device *idxd) static void idxd_device_evl_free(struct idxd_device *idxd) { + void *evl_log; + unsigned int evl_log_size; + dma_addr_t evl_dma; union gencfg_reg gencfg; union genctrl_reg genctrl; struct device *dev = &idxd->pdev->dev; @@ -822,11 +825,15 @@ static void idxd_device_evl_free(struct idxd_device *idxd) iowrite64(0, idxd->reg_base + IDXD_EVLCFG_OFFSET); iowrite64(0, idxd->reg_base + IDXD_EVLCFG_OFFSET + 8); - dma_free_coherent(dev, evl->log_size, evl->log, evl->dma); bitmap_free(evl->bmap); + evl_log = evl->log; + evl_log_size = evl->log_size; + evl_dma = evl->dma; evl->log = NULL; evl->size = IDXD_EVL_SIZE_MIN; spin_unlock(&evl->lock); + + dma_free_coherent(dev, evl_log_size, evl_log, evl_dma); } static void idxd_group_config_write(struct idxd_group *group)