Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp1318579ybi; Fri, 24 May 2019 22:50:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqxhL+TEe7VxndXyT+QLDHcD0ISRLHyuc+xIlidGMUL8/m2sEusAvjRupnXqlGpalc7ay0gK X-Received: by 2002:a63:2f47:: with SMTP id v68mr25424656pgv.251.1558763445608; Fri, 24 May 2019 22:50:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558763445; cv=none; d=google.com; s=arc-20160816; b=wjXA7QRfS1CgGarJZ4PiYkO9ubo3vuKV96qWqB1NU6AvyfCwDyFIxwlvsMQX0bQ3yk EMcbxXr6e9UYAr5JEGMxHoblpGRD6sTaKex7Ax13d9TEkMHG8Uohe71v04VP1r8g3LBa 4ehDumrHP2rWaV88WKmAZlL1xgrWbbD7l1MwlnyHp+TjGuN7baR96mdvL890bD+XxUa/ pnNLuBQjcnPFhxRBkFUc+WQXm3JgxU/6wTB6EzWKvSjSCrtX7pf1Orwa6357xwS/GQjj rZUD2dwH6OgDh788zrsHbRePrK99ATkdCySZe9JC+aNAasCCCAMW0qfhD64qSBU/6XPx Y5kA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=om1S++gOyVUN7Wsut5/6XC0Deu7OsKbpjhHsMOnWXwM=; b=hkwc7fS/6dOZajkbiHDq3SfSIrjLb2rlY7m6r0wGosIACW7E4SS1RFLUzBly1XD25b 7M/6yjoPRlc7GNlVaKFK+hii6kuspeciop7S0Dq/UQXJD7ZB3gOUYF2ke3nzfDO3hA7U mUld6aujKj5pLvhlJAeLngnsPgY54LhYd5ewxMv/ZrRawLe+rGq2Q/Fb33nfyqlPTe/c T4dkKZl4miyNvVFR8chciFpOTd3i1fxwzcvJBUL3x8E/mTGRjO/DuqC/qDrXlJ8JKbSQ u/cYoHCy7uHoCdWrloTfGGqruvcFu5TGa+bh4jTHS30QEfVqQ1MPApWDkwEhLmcGoejp jVpA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e96si1416755plb.123.2019.05.24.22.50.30; Fri, 24 May 2019 22:50:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726951AbfEYFtJ (ORCPT + 99 others); Sat, 25 May 2019 01:49:09 -0400 Received: from mga05.intel.com ([192.55.52.43]:46780 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726255AbfEYFtJ (ORCPT ); Sat, 25 May 2019 01:49:09 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 May 2019 22:49:09 -0700 X-ExtLoop1: 1 Received: from allen-box.sh.intel.com ([10.239.159.136]) by fmsmga006.fm.intel.com with ESMTP; 24 May 2019 22:49:06 -0700 From: Lu Baolu To: David Woodhouse , Joerg Roedel Cc: ashok.raj@intel.com, jacob.jun.pan@intel.com, kevin.tian@intel.com, jamessewart@arista.com, tmurphy@arista.com, dima@arista.com, sai.praneeth.prakhya@intel.com, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v4 11/15] iommu/vt-d: Implement is_attach_deferred iommu ops entry Date: Sat, 25 May 2019 13:41:32 +0800 Message-Id: <20190525054136.27810-12-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190525054136.27810-1-baolu.lu@linux.intel.com> References: <20190525054136.27810-1-baolu.lu@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As a domain is now attached to a device earlier, we should implement the is_attach_deferred call-back and use it to defer the domain attach from iommu driver init to device driver init when iommu is pre-enabled in kdump kernel. Suggested-by: Tom Murphy Signed-off-by: Lu Baolu --- drivers/iommu/intel-iommu.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c index 7f9cf9188f5f..b93d328fcceb 100644 --- a/drivers/iommu/intel-iommu.c +++ b/drivers/iommu/intel-iommu.c @@ -352,6 +352,8 @@ static void domain_context_clear(struct intel_iommu *iommu, static int domain_detach_iommu(struct dmar_domain *domain, struct intel_iommu *iommu); static bool device_is_rmrr_locked(struct device *dev); +static int intel_iommu_attach_device(struct iommu_domain *domain, + struct device *dev); #ifdef CONFIG_INTEL_IOMMU_DEFAULT_ON int dmar_disabled = 0; @@ -381,6 +383,7 @@ int intel_iommu_gfx_mapped; EXPORT_SYMBOL_GPL(intel_iommu_gfx_mapped); #define DUMMY_DEVICE_DOMAIN_INFO ((struct device_domain_info *)(-1)) +#define DEFER_DEVICE_DOMAIN_INFO ((struct device_domain_info *)(-2)) static DEFINE_SPINLOCK(device_domain_lock); static LIST_HEAD(device_domain_list); @@ -2434,8 +2437,18 @@ static struct dmar_domain *find_domain(struct device *dev) { struct device_domain_info *info; + if (unlikely(dev->archdata.iommu == DEFER_DEVICE_DOMAIN_INFO)) { + struct iommu_domain *domain; + + dev->archdata.iommu = NULL; + domain = iommu_get_domain_for_dev(dev); + if (domain) + intel_iommu_attach_device(domain, dev); + } + /* No lock here, assumes no domain exit in normal case */ info = dev->archdata.iommu; + if (likely(info)) return info->domain; return NULL; @@ -5527,6 +5540,9 @@ static int intel_iommu_add_device(struct device *dev) iommu_device_link(&iommu->iommu, dev); + if (translation_pre_enabled(iommu)) + dev->archdata.iommu = DEFER_DEVICE_DOMAIN_INFO; + group = iommu_group_get_for_dev(dev); if (IS_ERR(group)) @@ -5869,6 +5885,12 @@ intel_iommu_aux_get_pasid(struct iommu_domain *domain, struct device *dev) dmar_domain->default_pasid : -EINVAL; } +static bool intel_iommu_is_attach_deferred(struct iommu_domain *domain, + struct device *dev) +{ + return dev->archdata.iommu == DEFER_DEVICE_DOMAIN_INFO; +} + const struct iommu_ops intel_iommu_ops = { .capable = intel_iommu_capable, .domain_alloc = intel_iommu_domain_alloc, @@ -5891,6 +5913,7 @@ const struct iommu_ops intel_iommu_ops = { .dev_feat_enabled = intel_iommu_dev_feat_enabled, .dev_enable_feat = intel_iommu_dev_enable_feat, .dev_disable_feat = intel_iommu_dev_disable_feat, + .is_attach_deferred = intel_iommu_is_attach_deferred, .pgsize_bitmap = INTEL_IOMMU_PGSIZES, }; -- 2.17.1