Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp346813imm; Thu, 11 Oct 2018 22:19:37 -0700 (PDT) X-Google-Smtp-Source: ACcGV61DakPWzC8y57PHPm9rcqYfqCeUVYBLQmsH11K/pEM9RDYGA/InlggoVZTzcnSEJqmhSR/R X-Received: by 2002:aa7:8643:: with SMTP id a3-v6mr4566591pfo.247.1539321577306; Thu, 11 Oct 2018 22:19:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539321577; cv=none; d=google.com; s=arc-20160816; b=C3LNHabnIsPX5mpMOzj03kpVw7GZGFnDG9e1m+KVbkcYmsH2GTsmKSrhMX8NxLFXc8 Mtf6q8KdoaYHEZOaFqbdChs1yFBjG3Hs289vSacPd7azite6K9Nc7LkVsTf3J8eIOKv+ K8N5GbNlM5W8vvrg+BoKQnNtNu8CmssWSuOvWH7jTPJN87+7phbyKA2/T9BWRtt7QavK 0UlzxGh1VPD1DmBd3Mkd0k4lLQBynwgvnqhxk0cO0AME6eKdmUMnOGP3Ew8tawMyQnuY 0H4WAlY1jlOB6GW4dBD/dvXgtnHGJZw8Noh2jzWYdwN8maN/T7M4rUl2U60QLRfkMKmO mrbg== 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=uzMDsjAYkzv7wwXX1Xq2DEw2o1Nekng5iqvLmF7AeBw=; b=HFL3/S3CpYR2R+ixI3lvz3jyvtgTQV0ILoDvzuZvvhcr6OG8lIovwgTWQKwul3sev7 kQu1JlvsF5gLwwy4bS0cEvDHQvCOVyt0+EqhGk/IN2Fx59JhrCf2weEuxpUYUoAJWJ65 gwB6w4aa06LibV3V4H4ZVWpHX4kOqGRC4VJBVuUpPUnjXd/T94LCUDFNwDr1vXPwMQaS LO54GH3EE0gJcPTaAJVa4dNnXrTvGwcFmFG5VtcgRJpjvHnla6/99pO91yHv+RAOZjdd 1jZzLG7d4GypgG9JcZR7bUYhCLZbXPqC6UcQLwnU2GUNbQc8fwgU9DOVJSysgxokEgyk V13w== 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 e1-v6si126829ple.195.2018.10.11.22.19.22; Thu, 11 Oct 2018 22:19:37 -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 S1727493AbeJLMtb (ORCPT + 99 others); Fri, 12 Oct 2018 08:49:31 -0400 Received: from mga11.intel.com ([192.55.52.93]:62493 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726969AbeJLMtb (ORCPT ); Fri, 12 Oct 2018 08:49:31 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Oct 2018 22:18:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,371,1534834800"; d="scan'208";a="80842227" Received: from allen-box.sh.intel.com ([10.239.161.122]) by orsmga008.jf.intel.com with ESMTP; 11 Oct 2018 22:18:48 -0700 From: Lu Baolu To: Joerg Roedel , David Woodhouse , Alex Williamson , Kirti Wankhede Cc: ashok.raj@intel.com, sanjay.k.kumar@intel.com, jacob.jun.pan@intel.com, kevin.tian@intel.com, Jean-Philippe Brucker , yi.l.liu@intel.com, yi.y.sun@intel.com, peterx@redhat.com, tiwei.bie@intel.com, iommu@lists.linux-foundation.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Lu Baolu , Jacob Pan Subject: [PATCH v3 3/8] iommu/vt-d: Enable/disable multiple domains per device Date: Fri, 12 Oct 2018 13:16:27 +0800 Message-Id: <20181012051632.26064-4-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181012051632.26064-1-baolu.lu@linux.intel.com> References: <20181012051632.26064-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 Add iommu ops for enabling and disabling multiple domains per device. Cc: Ashok Raj Cc: Jacob Pan Cc: Kevin Tian Cc: Liu Yi L Signed-off-by: Lu Baolu --- drivers/iommu/intel-iommu.c | 57 +++++++++++++++++++++++++++++++++++++ include/linux/intel-iommu.h | 1 + 2 files changed, 58 insertions(+) diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c index 3133216e5733..27beda7f9d88 100644 --- a/drivers/iommu/intel-iommu.c +++ b/drivers/iommu/intel-iommu.c @@ -2476,6 +2476,7 @@ static struct dmar_domain *dmar_insert_one_dev_info(struct intel_iommu *iommu, info->domain = domain; info->iommu = iommu; info->pasid_table = NULL; + info->auxd_enabled = 0; if (dev && dev_is_pci(dev)) { struct pci_dev *pdev = to_pci_dev(info->dev); @@ -5371,6 +5372,61 @@ static int intel_iommu_get_dev_attr(struct device *dev, return ret; } +static int intel_iommu_enable_auxd(struct device *dev) +{ + struct device_domain_info *info; + struct dmar_domain *domain; + unsigned long flags; + + if (!scalable_mode_support()) + return -ENODEV; + + domain = get_valid_domain_for_dev(dev); + if (!domain) + return -ENODEV; + + spin_lock_irqsave(&device_domain_lock, flags); + info = dev->archdata.iommu; + info->auxd_enabled = 1; + spin_unlock_irqrestore(&device_domain_lock, flags); + + return 0; +} + +static int intel_iommu_disable_auxd(struct device *dev) +{ + struct device_domain_info *info; + unsigned long flags; + + spin_lock_irqsave(&device_domain_lock, flags); + info = dev->archdata.iommu; + if (!WARN_ON(!info)) + info->auxd_enabled = 0; + spin_unlock_irqrestore(&device_domain_lock, flags); + + return 0; +} + +static int intel_iommu_set_dev_attr(struct device *dev, + enum iommu_dev_attr attr, void *data) +{ + int ret = 0; + + switch (attr) { + case IOMMU_DEV_ATTR_AUXD_ENABLE: + ret = intel_iommu_enable_auxd(dev); + break; + case IOMMU_DEV_ATTR_AUXD_DISABLE: + ret = intel_iommu_disable_auxd(dev); + break; + default: + ret = -EINVAL; + break; + } + + return ret; +} + const struct iommu_ops intel_iommu_ops = { .capable = intel_iommu_capable, .domain_alloc = intel_iommu_domain_alloc, @@ -5386,6 +5442,7 @@ const struct iommu_ops intel_iommu_ops = { .put_resv_regions = intel_iommu_put_resv_regions, .device_group = pci_device_group, .get_dev_attr = intel_iommu_get_dev_attr, + .set_dev_attr = intel_iommu_set_dev_attr, .pgsize_bitmap = INTEL_IOMMU_PGSIZES, }; diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h index d174724e131f..6b198e13e75e 100644 --- a/include/linux/intel-iommu.h +++ b/include/linux/intel-iommu.h @@ -552,6 +552,7 @@ struct device_domain_info { u8 pri_enabled:1; u8 ats_supported:1; u8 ats_enabled:1; + u8 auxd_enabled:1; /* Multiple domains per device */ u8 ats_qdep; struct device *dev; /* it's NULL for PCIe-to-PCI bridge */ struct intel_iommu *iommu; /* IOMMU used by this device */ -- 2.17.1