From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7766C678D4 for ; Fri, 3 Mar 2023 01:20:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229613AbjCCBUr (ORCPT ); Thu, 2 Mar 2023 20:20:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229453AbjCCBUq (ORCPT ); Thu, 2 Mar 2023 20:20:46 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DFCC34028; Thu, 2 Mar 2023 17:20:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1677806445; x=1709342445; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=j7AIYuX5Qe9oeFbiQyOPvZ4yDa2qH0qd90k8dXQlpAg=; b=GAbJR1fSGvdKEAEQQoMYyBfkcvKVX1zvLcpPr2fBTN6fJc3VnAkssyAp MvfeoS+QVVnvxjOMq6wixq5XdMSEUGcUM6LuCuAOlrUtW4f70/Lbk/NeT mx/6vYAQ/tzJk7oB73gLlyzSkxmP/ic+J/MYHDgTrK1Y26YtpZECrYdPe Kt7J3mlPUpodiszdP7mU8AMsYaq+vH6eELIq/WoFgqoYrSoPpvrHp8Iad hb9GamMJOYim2s5aPFQUPC2hqn4HUEmXraADmBU9tdR0lXCDhKGDj8cSO tMOC4vSHyM41Y0t7UbRg0Z8306D7UcWOgQny2gztviJnvSL9sUMcbxxXO A==; X-IronPort-AV: E=McAfee;i="6500,9779,10637"; a="333638990" X-IronPort-AV: E=Sophos;i="5.98,229,1673942400"; d="scan'208";a="333638990" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Mar 2023 17:20:45 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10637"; a="920939118" X-IronPort-AV: E=Sophos;i="5.98,229,1673942400"; d="scan'208";a="920939118" Received: from allen-box.sh.intel.com (HELO [10.239.159.48]) ([10.239.159.48]) by fmsmga006.fm.intel.com with ESMTP; 02 Mar 2023 17:20:41 -0800 Message-ID: <063ed735-b8d1-1b44-67d7-78c3adb34074@linux.intel.com> Date: Fri, 3 Mar 2023 09:19:48 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Cc: baolu.lu@linux.intel.com, Robin Murphy , Will Deacon , David Woodhouse , Raj Ashok , "Tian, Kevin" , Yi Liu , "Yu, Fenghua" , Dave Jiang , Tony Luck , "Zanussi, Tom" Subject: Re: [PATCH 4/4] dmaengine/idxd: Re-enable kernel workqueue under DMA API Content-Language: en-US To: Jacob Pan , LKML , iommu@lists.linux.dev, Jason Gunthorpe , Joerg Roedel , dmaengine@vger.kernel.org, vkoul@kernel.org References: <20230302005959.2695267-1-jacob.jun.pan@linux.intel.com> <20230302005959.2695267-5-jacob.jun.pan@linux.intel.com> From: Baolu Lu In-Reply-To: <20230302005959.2695267-5-jacob.jun.pan@linux.intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org On 3/2/23 8:59 AM, Jacob Pan wrote: > diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c > index f30eef701970..dadc908318aa 100644 > --- a/drivers/dma/idxd/init.c > +++ b/drivers/dma/idxd/init.c > @@ -501,14 +501,52 @@ static struct idxd_device *idxd_alloc(struct pci_dev *pdev, struct idxd_driver_d > > static int idxd_enable_system_pasid(struct idxd_device *idxd) > { > - return -EOPNOTSUPP; > + struct pci_dev *pdev = idxd->pdev; > + struct device *dev = &pdev->dev; > + struct iommu_domain *domain; > + union gencfg_reg gencfg; > + ioasid_t pasid; > + int ret; > + > + domain = iommu_get_domain_for_dev(dev); > + if (!domain || domain->type == IOMMU_DOMAIN_BLOCKED) > + return -EPERM; The idxd driver has claimed the DMA ownership of this device. Unless the idxd driver itself attached another domain, iommu_get_domain_for_dev() should never return a blocking domain. "domain == NULL" happens when CONFIG_IOMMU_API is not set. Furthermore, iommu_get_domain_for_dev() doesn't hold any refcount from the domain, so in theory it's not safe here because it possibly causes use-after-release case. I would say iommu_get_dma_domain() or something similar is more suitable for use here. It directly returns the device's default domain and the iommu core guarantees that default domain will always valid during the life cycle of any device driver. Best regards, baolu